diff --git a/packages/agent-bridge/src/index.ts b/packages/agent-bridge/src/index.ts index 6c3ea31..36ea5c4 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,18 @@ export function createAgentBridgeClient(config: AgentBridgeClientConfig) { ...options, }); }, + 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(body), + headers, + }); + }, rewrite(slug: string, input: Record, options: AgentBridgeRequestOptions = {}): Promise { return requestJson(config, buildBridgePath(slug, '/rewrite'), { method: 'POST',