From 5d8c1418ccda2e3ce8b48251c689674a9558e58a Mon Sep 17 00:00:00 2001 From: Matt Galligan Date: Mon, 16 Mar 2026 13:42:48 -0400 Subject: [PATCH 1/2] fix: add editV2 types and method to agent-bridge client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bridge client was missing editV2 support entirely. Adds: - EditV2BlockOp union type matching server's operation types - EditV2Input interface with correct field names (baseRevision, operations) matching server/agent-edit-v2.ts - editV2() method on the bridge client Closes #22 🤘🏻 In-collaboration-with: [Claude Code](https://claude.com/claude-code) --- packages/agent-bridge/src/index.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/agent-bridge/src/index.ts b/packages/agent-bridge/src/index.ts index 6c3ea31..887f05b 100644 --- a/packages/agent-bridge/src/index.ts +++ b/packages/agent-bridge/src/index.ts @@ -38,6 +38,21 @@ export interface AgentBridgeCommentInput { selector?: Record; } +export type EditV2BlockOp = + | { op: 'replace_block'; ref: string; block: { markdown: string } } + | { op: 'insert_after'; ref: string; blocks: Array<{ markdown: string }> } + | { op: 'insert_before'; ref: string; blocks: Array<{ markdown: string }> } + | { op: 'delete_block'; ref: string } + | { op: 'replace_range'; fromRef: string; toRef: string; blocks: Array<{ markdown: string }> } + | { op: 'find_replace_in_block'; ref: string; find: string; replace: string; occurrence?: 'first' | 'all' }; + +export interface EditV2Input { + by: string; + baseRevision: number; + operations: EditV2BlockOp[]; + idempotencyKey?: string; +} + export interface AgentBridgePresenceInput { status: string; agentId?: string; @@ -187,6 +202,13 @@ export function createAgentBridgeClient(config: AgentBridgeClientConfig) { ...options, }); }, + editV2(slug: string, input: EditV2Input, options: AgentBridgeRequestOptions = {}): Promise { + return requestJson(config, `${documentBasePath(slug)}/edit/v2`, { + method: 'POST', + body: JSON.stringify(input), + ...options, + }); + }, rewrite(slug: string, input: Record, options: AgentBridgeRequestOptions = {}): Promise { return requestJson(config, buildBridgePath(slug, '/rewrite'), { method: 'POST', From ef33f1c6728aaec951018254f5f7454c1b2a53b0 Mon Sep 17 00:00:00 2001 From: Matt Galligan Date: Mon, 16 Mar 2026 17:38:41 -0400 Subject: [PATCH 2/2] fix: send editV2 idempotency key as request header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The server reads idempotency keys from the Idempotency-Key header, not from the request body. Extract idempotencyKey from EditV2Input and send it as a header so the server's idempotency flow works correctly when IDEMPOTENCY_KEY_REQUIRED is enabled. 🤘🏻 In-collaboration-with: [Claude Code](https://claude.com/claude-code) --- packages/agent-bridge/src/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/agent-bridge/src/index.ts b/packages/agent-bridge/src/index.ts index 887f05b..36ea5c4 100644 --- a/packages/agent-bridge/src/index.ts +++ b/packages/agent-bridge/src/index.ts @@ -203,10 +203,15 @@ export function createAgentBridgeClient(config: AgentBridgeClientConfig) { }); }, editV2(slug: string, input: EditV2Input, options: AgentBridgeRequestOptions = {}): Promise { + const { idempotencyKey, ...body } = input; + const headers: Record = { ...(options.headers ?? {}) }; + if (idempotencyKey) { + headers['Idempotency-Key'] = idempotencyKey; + } return requestJson(config, `${documentBasePath(slug)}/edit/v2`, { method: 'POST', - body: JSON.stringify(input), - ...options, + body: JSON.stringify(body), + headers, }); }, rewrite(slug: string, input: Record, options: AgentBridgeRequestOptions = {}): Promise {