From 97e05a5fc0af01686b893bee6f7e7defb830f70e Mon Sep 17 00:00:00 2001 From: Hiten Shah Date: Mon, 23 Mar 2026 08:49:26 -0700 Subject: [PATCH] feat(agent-bridge): add editV2 method with correct field names Fixes #22 The editV2() method was missing from the agent bridge client, and there was a field name mismatch between what developers might expect and what the server actually accepts. Server expects: - baseRevision (number) - operations (array of ops) This adds: - EditV2Input interface with correct field names - EditV2BlockOp union type covering all 6 operation types - editV2() client method that POSTs to /documents/:slug/edit/v2 - Idempotency-Key header support (automatically set from input.idempotencyKey) All field names now match the server implementation in server/agent-edit-v2.ts. --- packages/agent-bridge/src/index.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/agent-bridge/src/index.ts b/packages/agent-bridge/src/index.ts index 6c3ea31..5357253 100644 --- a/packages/agent-bridge/src/index.ts +++ b/packages/agent-bridge/src/index.ts @@ -48,6 +48,21 @@ export interface AgentBridgePresenceInput { avatar?: string; } +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 AgentProviderMessage { role: 'system' | 'user' | 'assistant' | 'tool'; content: string; @@ -267,6 +282,16 @@ 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), + headers: { + ...(input.idempotencyKey ? { 'Idempotency-Key': input.idempotencyKey } : {}), + }, + ...options, + }); + }, }; }