@di-code/coding-agent 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +5 -0
  2. package/dist/core/session/session-manager.d.ts +18 -1
  3. package/dist/core/session/session-manager.d.ts.map +1 -1
  4. package/dist/core/session/session-manager.js +90 -1
  5. package/dist/core/session/session-manager.js.map +1 -1
  6. package/dist/core/session/session-storage.d.ts +2 -0
  7. package/dist/core/session/session-storage.d.ts.map +1 -1
  8. package/dist/core/session/session-storage.js +22 -1
  9. package/dist/core/session/session-storage.js.map +1 -1
  10. package/dist/core/session/types.d.ts +16 -1
  11. package/dist/core/session/types.d.ts.map +1 -1
  12. package/dist/core/session/types.js.map +1 -1
  13. package/dist/core/session.d.ts +27 -2
  14. package/dist/core/session.d.ts.map +1 -1
  15. package/dist/core/session.js +59 -0
  16. package/dist/core/session.js.map +1 -1
  17. package/dist/entry.js +1 -1
  18. package/dist/entry.js.map +1 -1
  19. package/dist/i18n.js +4 -4
  20. package/dist/i18n.js.map +1 -1
  21. package/dist/interactive-host-entry.d.ts.map +1 -1
  22. package/dist/interactive-host-entry.js +107 -12
  23. package/dist/interactive-host-entry.js.map +1 -1
  24. package/dist/main.d.ts.map +1 -1
  25. package/dist/main.js +3 -0
  26. package/dist/main.js.map +1 -1
  27. package/dist/modes/interactive-components.d.ts +8 -0
  28. package/dist/modes/interactive-components.d.ts.map +1 -1
  29. package/dist/modes/interactive-components.js +7 -2
  30. package/dist/modes/interactive-components.js.map +1 -1
  31. package/dist/modes/interactive.d.ts +4 -0
  32. package/dist/modes/interactive.d.ts.map +1 -1
  33. package/dist/modes/interactive.js +69 -0
  34. package/dist/modes/interactive.js.map +1 -1
  35. package/dist/modes/tree-selector.d.ts.map +1 -1
  36. package/dist/modes/tree-selector.js +4 -0
  37. package/dist/modes/tree-selector.js.map +1 -1
  38. package/dist/rpc/client.d.ts +2 -0
  39. package/dist/rpc/client.d.ts.map +1 -1
  40. package/dist/rpc/client.js +3 -0
  41. package/dist/rpc/client.js.map +1 -1
  42. package/dist/rpc/dispatcher.d.ts +14 -0
  43. package/dist/rpc/dispatcher.d.ts.map +1 -1
  44. package/dist/rpc/dispatcher.js +222 -7
  45. package/dist/rpc/dispatcher.js.map +1 -1
  46. package/dist/rpc/protocol.d.ts +12 -5
  47. package/dist/rpc/protocol.d.ts.map +1 -1
  48. package/dist/rpc/protocol.js +34 -0
  49. package/dist/rpc/protocol.js.map +1 -1
  50. package/dist/rpc/server.d.ts +5 -0
  51. package/dist/rpc/server.d.ts.map +1 -1
  52. package/dist/rpc/server.js +4 -0
  53. package/dist/rpc/server.js.map +1 -1
  54. package/dist/rpc-server-entry.d.ts.map +1 -1
  55. package/dist/rpc-server-entry.js +15 -1
  56. package/dist/rpc-server-entry.js.map +1 -1
  57. package/dist/runtime/product-host.d.ts +7 -0
  58. package/dist/runtime/product-host.d.ts.map +1 -1
  59. package/dist/runtime/product-host.js +29 -9
  60. package/dist/runtime/product-host.js.map +1 -1
  61. package/dist/runtime/session-factory.d.ts +18 -2
  62. package/dist/runtime/session-factory.d.ts.map +1 -1
  63. package/dist/runtime/session-factory.js +286 -24
  64. package/dist/runtime/session-factory.js.map +1 -1
  65. package/dist/runtime/session-host.d.ts +46 -1
  66. package/dist/runtime/session-host.d.ts.map +1 -1
  67. package/dist/runtime/session-host.js +38 -6
  68. package/dist/runtime/session-host.js.map +1 -1
  69. package/dist/ui-host.d.ts.map +1 -1
  70. package/dist/ui-host.js +3 -0
  71. package/dist/ui-host.js.map +1 -1
  72. package/dist/web/assets/index-C2SOU925.css +1 -0
  73. package/dist/web/assets/index-knXkInvO.js +41 -0
  74. package/dist/web/assets/index-knXkInvO.js.map +1 -0
  75. package/dist/web/index.html +2 -2
  76. package/dist/web-command.d.ts.map +1 -1
  77. package/dist/web-command.js +8 -1
  78. package/dist/web-command.js.map +1 -1
  79. package/dist/webui-entry.js +9 -1
  80. package/dist/webui-entry.js.map +1 -1
  81. package/dist/webui.d.ts +10 -0
  82. package/dist/webui.d.ts.map +1 -1
  83. package/dist/webui.js +21 -0
  84. package/dist/webui.js.map +1 -1
  85. package/package.json +11 -9
  86. package/dist/web/assets/index-C-NyCPxd.css +0 -1
  87. package/dist/web/assets/index-DgyxuNNG.js +0 -41
  88. package/dist/web/assets/index-DgyxuNNG.js.map +0 -1
@@ -62,6 +62,7 @@ export const RPC_METHODS = [
62
62
  "set_plugin_enabled",
63
63
  "create_attachment",
64
64
  "approve_tool",
65
+ "respond_interaction",
65
66
  ];
66
67
  const RPC_ERROR_CODES = new Set([
67
68
  "PARSE_ERROR",
@@ -78,6 +79,7 @@ const RPC_ERROR_CODES = new Set([
78
79
  "UNAUTHORIZED",
79
80
  "INTERNAL_ERROR",
80
81
  "PROCESS_EXIT",
82
+ "INTERACTION_UNAVAILABLE",
81
83
  ]);
82
84
  const LEGACY_EVENT_TYPES = new Set([
83
85
  "agent_start",
@@ -100,7 +102,9 @@ const EXTENDED_EVENT_TYPES = new Set([
100
102
  "operation_update",
101
103
  "session_changed",
102
104
  "tool_approval",
105
+ "interaction_request",
103
106
  "product_audit",
107
+ "projection",
104
108
  ]);
105
109
  const EXTENDED_EVENT_NAMES = new Set([
106
110
  "sequence",
@@ -108,7 +112,9 @@ const EXTENDED_EVENT_NAMES = new Set([
108
112
  "snapshot_required",
109
113
  "session_changed",
110
114
  "tool_approval",
115
+ "interaction_request",
111
116
  "product_audit",
117
+ "projection",
112
118
  ]);
113
119
  const ASSISTANT_STOP_REASONS = new Set(["stop", "length", "tool_use", "error", "aborted"]);
114
120
  export class RpcProtocolError extends Error {
@@ -333,6 +339,17 @@ export function parseRpcRequest(line) {
333
339
  stringParam(params, "approvalId", id);
334
340
  booleanParam(params, "approved", id);
335
341
  break;
342
+ case "respond_interaction":
343
+ stringParam(params, "requestId", id);
344
+ if (typeof params.status !== "string" || !["answered", "cancelled", "timeout"].includes(params.status))
345
+ throw new RpcProtocolError("INVALID_PARAMS", "respond_interaction.status is invalid.", id);
346
+ if (params.approved !== undefined && typeof params.approved !== "boolean")
347
+ throw new RpcProtocolError("INVALID_PARAMS", "respond_interaction.approved must be boolean.", id);
348
+ if (params.value !== undefined)
349
+ stringParam(params, "value", id, true);
350
+ if (params.feedback !== undefined)
351
+ stringParam(params, "feedback", id, true);
352
+ break;
336
353
  }
337
354
  return { version: RPC_PROTOCOL_VERSION, kind: "request", id, method, params };
338
355
  }
@@ -480,6 +497,7 @@ function assertSuccessResult(result) {
480
497
  case "set_locale":
481
498
  case "set_permission_mode":
482
499
  case "configure_custom_provider":
500
+ case "respond_interaction":
483
501
  return;
484
502
  }
485
503
  }
@@ -573,6 +591,13 @@ function assertEvent(event, type) {
573
591
  throw new RpcProtocolError("INVALID_REQUEST", "RPC tool_approval event is invalid.");
574
592
  return;
575
593
  }
594
+ if (type === "interaction_request") {
595
+ if (typeof event.interactionRequestId !== "string" ||
596
+ typeof event.kind !== "string" ||
597
+ typeof event.prompt !== "string")
598
+ throw new RpcProtocolError("INVALID_REQUEST", "RPC interaction_request event is invalid.");
599
+ return;
600
+ }
576
601
  if (type === "product_audit") {
577
602
  if (typeof event.action !== "string" ||
578
603
  ![
@@ -588,6 +613,15 @@ function assertEvent(event, type) {
588
613
  throw new RpcProtocolError("INVALID_REQUEST", "RPC product_audit event is invalid.");
589
614
  return;
590
615
  }
616
+ if (type === "projection") {
617
+ if (typeof event.namespace !== "string" ||
618
+ typeof event.projectionName !== "string" ||
619
+ !Number.isSafeInteger(event.version) ||
620
+ event.version < 0 ||
621
+ !("state" in event))
622
+ throw new RpcProtocolError("INVALID_REQUEST", "RPC projection event is invalid.");
623
+ return;
624
+ }
591
625
  if (type === "tool_execution_start") {
592
626
  if (typeof event.toolCallId !== "string" || typeof event.toolName !== "string" || !objectRecord(event.arguments))
593
627
  throw new RpcProtocolError("INVALID_REQUEST", "RPC tool event is invalid.");
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":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AAC;gBAC3B,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACzC,YAAY,GAAG,CAAC;gBAChB,YAAY,IAAI,6BAA6B,CAC7C,CAAC;QACH,CAAC,CAAC;QACF,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ;QACpC,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;QACjC,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC;QACnC,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ;QACtC,CAAC,sBAAsB,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC;QAE/C,MAAM,IAAI,gBAAgB,CAAC,iBAAiB,EAAE,6CAA6C,CAAC,CAAC;AAC/F,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,KAAuB;IACvD,OAAO;QACN,OAAO,EAAE,oBAAoB;QAC7B,IAAI,EAAE,UAAU;QAChB,GAAG,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;QACjE,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;KACnD,CAAC;AACH,CAAC","sourcesContent":["import type { AssistantMessage } from \"@di-code/ai\";\nimport { validateWebManifest } from \"@di-code/plugin-runtime\";\nimport type { AgentSessionEvent } from \"../core/session.ts\";\n\nexport const RPC_PROTOCOL_VERSION = 1 as const;\nexport const RPC_MAX_ID_LENGTH = 128;\nexport const RPC_MAX_PROMPT_LENGTH = 1_000_000;\nexport const RPC_MAX_ATTACHMENTS_PER_REQUEST = 4;\nexport const RPC_MAX_ATTACHMENT_BYTES = 5 * 1024 * 1024;\nconst RPC_MAX_ASSISTANT_IMAGE_BYTES = 5 * 1024 * 1024;\n/** Allows one JSONL user entry containing a maximum-sized base64 image to be read in a single transcript page. */\nexport const RPC_MAX_TRANSCRIPT_BYTES = 8 * 1024 * 1024;\nconst RPC_MAX_ATTACHMENT_BASE64_LENGTH = Math.ceil(RPC_MAX_ATTACHMENT_BYTES / 3) * 4;\n\n/** v1 grows only by methods and optional fields. Clients must negotiate extended events first. */\nexport const RPC_METHODS = [\n\t\"prompt\",\n\t\"cancel\",\n\t\"get_state\",\n\t\"get_capabilities\",\n\t\"resume_events\",\n\t\"list_sessions\",\n\t\"new_session\",\n\t\"open_session\",\n\t\"inspect_session\",\n\t\"rename_session\",\n\t\"delete_session\",\n\t\"branch_session\",\n\t\"get_transcript\",\n\t\"get_tree\",\n\t\"navigate_tree\",\n\t\"steer\",\n\t\"retry\",\n\t\"get_operation\",\n\t\"get_models\",\n\t\"set_model\",\n\t\"get_runtime\",\n\t\"set_runtime\",\n\t\"set_thinking_level\",\n\t\"compact\",\n\t\"set_compaction_enabled\",\n\t\"get_usage\",\n\t\"list_skills\",\n\t\"get_resources\",\n\t\"get_product_state\",\n\t\"list_providers\",\n\t\"get_settings\",\n\t\"set_default_provider\",\n\t\"set_default_model\",\n\t\"set_locale\",\n\t\"set_permission_mode\",\n\t\"configure_custom_provider\",\n\t\"login\",\n\t\"logout\",\n\t\"get_project_trust\",\n\t\"set_project_trust\",\n\t\"list_context_files\",\n\t\"list_mcp_servers\",\n\t\"configure_mcp_server\",\n\t\"remove_mcp_server\",\n\t\"reconnect_mcp_server\",\n\t\"list_plugins\",\n\t\"list_web_contributions\",\n\t\"list_commands\",\n\t\"run_command\",\n\t\"set_plugin_enabled\",\n\t\"create_attachment\",\n\t\"approve_tool\",\n] as const;\nexport type RpcMethod = (typeof RPC_METHODS)[number];\n\nexport interface RpcRequest {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"request\";\n\treadonly id: string;\n\treadonly method: RpcMethod;\n\treadonly params: Record<string, unknown>;\n}\n\nexport interface RpcSessionState {\n\treadonly sessionId: string;\n\treadonly modelId: string;\n\treadonly isStreaming: boolean;\n\treadonly messageCount: number;\n\treadonly sequence?: number;\n}\n\n/** Metadata for an opaque attachment handle kept only by its live RPC actor. */\nexport interface RpcAttachmentInfo {\n\treadonly id: string;\n\treadonly name: string;\n\treadonly contentType: \"image/png\" | \"image/jpeg\" | \"image/webp\" | \"image/gif\";\n\treadonly bytes: number;\n}\n\nexport interface RpcCapabilities {\n\treadonly methods: readonly RpcMethod[];\n\treadonly events: readonly RpcExtendedEventName[];\n\treadonly eventBufferSize: number;\n}\n\nexport type RpcExtendedEventName =\n\t| \"sequence\"\n\t| \"operation_update\"\n\t| \"snapshot_required\"\n\t| \"session_changed\"\n\t| \"tool_approval\"\n\t| \"product_audit\";\n\nexport interface RpcProductState {\n\treadonly projectTrusted: boolean;\n}\n\nexport interface RpcProviderSummary {\n\treadonly id: string;\n\treadonly name: string;\n\treadonly models: readonly {\n\t\treadonly id: string;\n\t\treadonly name: string;\n\t\treadonly input: readonly string[];\n\t\t/** Omitted when the model does not expose selectable reasoning levels. */\n\t\treadonly reasoningEfforts?: readonly (\"low\" | \"medium\" | \"high\" | \"max\")[];\n\t}[];\n\treadonly configured: boolean;\n}\n\nexport interface RpcSettingsSnapshot {\n\treadonly providers: readonly (RpcProviderSummary & {\n\t\treadonly api: string;\n\t\treadonly baseUrl?: string;\n\t\treadonly apiKeySource: \"environment\" | \"settings\" | \"missing\";\n\t})[];\n\treadonly defaults: { readonly providerId?: string; readonly modelId?: string };\n\treadonly runtime: { readonly providerId: string; readonly modelId: string; readonly thinkingLevel?: string };\n\treadonly locale?: \"en\" | \"zh-CN\";\n\treadonly permissionMode: \"ask\" | \"allow\" | \"deny\";\n\treadonly sources: Readonly<Record<string, \"environment\" | \"settings\" | \"default\" | \"runtime\">>;\n}\n\nexport interface RpcContextFileInfo {\n\treadonly path: string;\n\treadonly scope: string;\n\treadonly bytes: number;\n}\n\n/** A user-invocable command projected from the active composition or Skill catalog. */\nexport interface RpcCommandInfo {\n\treadonly name: string;\n\treadonly description: string;\n\treadonly kind: \"command\" | \"skill\";\n}\n\n/** A WebUI operation requested by a registered command. */\nexport interface RpcCommandAction {\n\treadonly command: string;\n\treadonly args: string;\n}\n\nexport interface RpcMcpServerInfo {\n\treadonly id: string;\n\treadonly scope?: string;\n\treadonly state: \"configured\" | \"connected\" | \"failed\" | \"disconnected\";\n\treadonly tools: number;\n\treadonly resources: number;\n\treadonly prompts: number;\n\treadonly diagnostic?: string;\n}\n\nexport type OperationStatus = \"queued\" | \"running\" | \"completed\" | \"failed\" | \"cancelled\" | \"crashed\";\nexport interface OperationState {\n\treadonly requestId: string;\n\treadonly kind: RpcMethod;\n\treadonly status: OperationStatus;\n\treadonly sessionId?: string;\n\treadonly message?: AssistantMessage;\n\treadonly error?: { readonly code: RpcErrorCode; readonly message: string };\n}\n\n/** Method-specific result fields are validated at the wire boundary. */\nexport type RpcSuccessResult = { readonly method: RpcMethod; readonly [key: string]: unknown };\n\nexport type RpcErrorCode =\n\t| \"PARSE_ERROR\"\n\t| \"INVALID_REQUEST\"\n\t| \"UNSUPPORTED_VERSION\"\n\t| \"METHOD_NOT_FOUND\"\n\t| \"INVALID_PARAMS\"\n\t| \"BUSY\"\n\t| \"NOT_FOUND\"\n\t| \"CANCELLED\"\n\t| \"DISPOSED\"\n\t| \"SESSION_IN_USE\"\n\t| \"INVALID_WORKSPACE\"\n\t| \"UNAUTHORIZED\"\n\t| \"INTERNAL_ERROR\"\n\t| \"PROCESS_EXIT\";\n\nconst RPC_ERROR_CODES: ReadonlySet<RpcErrorCode> = new Set([\n\t\"PARSE_ERROR\",\n\t\"INVALID_REQUEST\",\n\t\"UNSUPPORTED_VERSION\",\n\t\"METHOD_NOT_FOUND\",\n\t\"INVALID_PARAMS\",\n\t\"BUSY\",\n\t\"NOT_FOUND\",\n\t\"CANCELLED\",\n\t\"DISPOSED\",\n\t\"SESSION_IN_USE\",\n\t\"INVALID_WORKSPACE\",\n\t\"UNAUTHORIZED\",\n\t\"INTERNAL_ERROR\",\n\t\"PROCESS_EXIT\",\n]);\nconst LEGACY_EVENT_TYPES: ReadonlySet<AgentSessionEvent[\"type\"]> = new Set([\n\t\"agent_start\",\n\t\"turn_start\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"turn_end\",\n\t\"tool_execution_start\",\n\t\"tool_execution_end\",\n\t\"agent_end\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"queue_update\",\n\t\"tree_navigated\",\n\t\"usage_update\",\n]);\nconst EXTENDED_EVENT_TYPES = new Set([\n\t\"snapshot_required\",\n\t\"operation_update\",\n\t\"session_changed\",\n\t\"tool_approval\",\n\t\"product_audit\",\n]);\nconst EXTENDED_EVENT_NAMES: ReadonlySet<RpcExtendedEventName> = new Set([\n\t\"sequence\",\n\t\"operation_update\",\n\t\"snapshot_required\",\n\t\"session_changed\",\n\t\"tool_approval\",\n\t\"product_audit\",\n]);\nconst ASSISTANT_STOP_REASONS = new Set([\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\"]);\n\nexport interface RpcSuccessResponse {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"response\";\n\treadonly id: string;\n\treadonly ok: true;\n\treadonly result: RpcSuccessResult;\n}\nexport interface RpcErrorResponse {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"response\";\n\treadonly id?: string;\n\treadonly ok: false;\n\treadonly error: { readonly code: RpcErrorCode; readonly message: string };\n}\nexport interface RpcEventRecord {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"event\";\n\treadonly requestId: string;\n\treadonly event:\n\t\t| AgentSessionEvent\n\t\t| {\n\t\t\t\treadonly type: \"product_audit\";\n\t\t\t\treadonly action:\n\t\t\t\t\t| \"login\"\n\t\t\t\t\t| \"logout\"\n\t\t\t\t\t| \"set_project_trust\"\n\t\t\t\t\t| \"configure_mcp_server\"\n\t\t\t\t\t| \"remove_mcp_server\"\n\t\t\t\t\t| \"reconnect_mcp_server\";\n\t\t\t\treadonly target?: string;\n\t\t\t\treadonly projectTrusted?: boolean;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type: \"snapshot_required\" | \"operation_update\" | \"session_changed\" | \"tool_approval\";\n\t\t\t\treadonly [key: string]: unknown;\n\t\t };\n\treadonly sessionId?: string;\n\treadonly sequence?: number;\n}\nexport type RpcResponse = RpcSuccessResponse | RpcErrorResponse;\nexport type RpcServerMessage = RpcResponse | RpcEventRecord;\n\nexport class RpcProtocolError extends Error {\n\treadonly code: RpcErrorCode;\n\treadonly requestId?: string;\n\n\tconstructor(code: RpcErrorCode, message: string, requestId?: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RpcProtocolError\";\n\t\tthis.code = code;\n\t\tthis.requestId = requestId;\n\t}\n}\n\nfunction objectRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)\n\t\t: undefined;\n}\nfunction requiredId(value: unknown, field: string, requestId?: string): string {\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > RPC_MAX_ID_LENGTH)\n\t\tthrow new RpcProtocolError(\n\t\t\t\"INVALID_REQUEST\",\n\t\t\t`${field} must be a non-empty string of at most ${RPC_MAX_ID_LENGTH} characters.`,\n\t\t\trequestId,\n\t\t);\n\treturn value;\n}\nfunction parseJsonObject(line: string): Record<string, unknown> {\n\ttry {\n\t\tconst result = objectRecord(JSON.parse(line));\n\t\tif (!result) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC input must be a JSON object.\");\n\t\treturn result;\n\t} catch (cause) {\n\t\tif (cause instanceof RpcProtocolError) throw cause;\n\t\tthrow new RpcProtocolError(\"PARSE_ERROR\", \"RPC input must be valid JSON.\");\n\t}\n}\nfunction assertVersion(record: Record<string, unknown>, requestId?: string): void {\n\tif (record.version !== RPC_PROTOCOL_VERSION)\n\t\tthrow new RpcProtocolError(\n\t\t\t\"UNSUPPORTED_VERSION\",\n\t\t\t`Unsupported RPC protocol version; expected ${RPC_PROTOCOL_VERSION}.`,\n\t\t\trequestId,\n\t\t);\n}\nfunction stringParam(params: Record<string, unknown>, name: string, id: string, optional = false): void {\n\tconst value = params[name];\n\tif (optional && value === undefined) return;\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > RPC_MAX_PROMPT_LENGTH)\n\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", `${name} must be a non-empty string.`, id);\n}\nfunction booleanParam(params: Record<string, unknown>, name: string, id: string): void {\n\tif (typeof params[name] !== \"boolean\") throw new RpcProtocolError(\"INVALID_PARAMS\", `${name} must be a boolean.`, id);\n}\nfunction attachmentIdsParam(params: Record<string, unknown>, id: string): void {\n\tif (params.attachmentIds === undefined) return;\n\tif (\n\t\t!Array.isArray(params.attachmentIds) ||\n\t\tparams.attachmentIds.length > RPC_MAX_ATTACHMENTS_PER_REQUEST ||\n\t\t!params.attachmentIds.every(\n\t\t\t(value) => typeof value === \"string\" && value.length > 0 && value.length <= RPC_MAX_ID_LENGTH,\n\t\t)\n\t)\n\t\tthrow new RpcProtocolError(\n\t\t\t\"INVALID_PARAMS\",\n\t\t\t`attachmentIds must contain at most ${RPC_MAX_ATTACHMENTS_PER_REQUEST} attachment IDs.`,\n\t\t\tid,\n\t\t);\n}\nfunction attachmentDataParam(params: Record<string, unknown>, id: string): void {\n\tconst data = params.data;\n\tif (typeof data !== \"string\" || data.length === 0 || data.length > RPC_MAX_ATTACHMENT_BASE64_LENGTH)\n\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"Attachment data exceeds the permitted size.\", id);\n}\n\n/** Parses every public v1 method before any dispatcher or transport observes it. */\nexport function parseRpcRequest(line: string): RpcRequest {\n\tconst record = parseJsonObject(line);\n\tconst candidateId = typeof record.id === \"string\" ? record.id : undefined;\n\tassertVersion(record, candidateId);\n\tif (record.kind !== \"request\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", 'RPC request kind must be \"request\".', candidateId);\n\tconst id = requiredId(record.id, \"id\", candidateId);\n\tconst params = objectRecord(record.params);\n\tif (!params) throw new RpcProtocolError(\"INVALID_PARAMS\", \"RPC params must be an object.\", id);\n\tif (typeof record.method !== \"string\" || !RPC_METHODS.includes(record.method as RpcMethod))\n\t\tthrow new RpcProtocolError(\"METHOD_NOT_FOUND\", \"Unknown RPC method.\", id);\n\tconst method = record.method as RpcMethod;\n\tswitch (method) {\n\t\tcase \"prompt\":\n\t\tcase \"steer\":\n\t\t\tstringParam(params, \"message\", id);\n\t\t\tattachmentIdsParam(params, id);\n\t\t\tbreak;\n\t\tcase \"cancel\":\n\t\tcase \"get_operation\":\n\t\tcase \"open_session\":\n\t\tcase \"inspect_session\":\n\t\tcase \"rename_session\":\n\t\tcase \"delete_session\":\n\t\tcase \"navigate_tree\":\n\t\tcase \"set_model\":\n\t\tcase \"logout\":\n\t\tcase \"reconnect_mcp_server\":\n\t\t\tstringParam(\n\t\t\t\tparams,\n\t\t\t\tmethod === \"cancel\" || method === \"get_operation\"\n\t\t\t\t\t? \"requestId\"\n\t\t\t\t\t: method === \"open_session\"\n\t\t\t\t\t\t? \"sessionId\"\n\t\t\t\t\t\t: method === \"inspect_session\" || method === \"rename_session\" || method === \"delete_session\"\n\t\t\t\t\t\t\t? \"sessionId\"\n\t\t\t\t\t\t\t: method === \"navigate_tree\"\n\t\t\t\t\t\t\t\t? \"entryId\"\n\t\t\t\t\t\t\t\t: method === \"set_model\"\n\t\t\t\t\t\t\t\t\t? \"modelId\"\n\t\t\t\t\t\t\t\t\t: method === \"logout\"\n\t\t\t\t\t\t\t\t\t\t? \"providerId\"\n\t\t\t\t\t\t\t\t\t\t: \"serverId\",\n\t\t\t\tid,\n\t\t\t);\n\t\t\tif (method === \"rename_session\") stringParam(params, \"label\", id);\n\t\t\tif (method === \"delete_session\") stringParam(params, \"confirmation\", id);\n\t\t\tbreak;\n\t\tcase \"branch_session\":\n\t\t\tif (params.sessionId !== undefined) stringParam(params, \"sessionId\", id, true);\n\t\t\tif (params.entryId !== undefined) stringParam(params, \"entryId\", id, true);\n\t\t\tbreak;\n\t\tcase \"set_runtime\":\n\t\t\tstringParam(params, \"providerId\", id);\n\t\t\tstringParam(params, \"modelId\", id);\n\t\t\tbreak;\n\t\tcase \"run_command\":\n\t\t\tstringParam(params, \"name\", id);\n\t\t\tif (!/^[a-z][a-z0-9-]*(?::[a-z][a-z0-9-]*)?$/.test(params.name as string))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"run_command.name is invalid.\", id);\n\t\t\tif (params.args !== undefined && (typeof params.args !== \"string\" || params.args.length > RPC_MAX_PROMPT_LENGTH))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"args must be a string of at most 1,000,000 characters.\", id);\n\t\t\tbreak;\n\t\tcase \"set_default_provider\":\n\t\tcase \"set_default_model\":\n\t\tcase \"set_locale\":\n\t\tcase \"set_permission_mode\":\n\t\t\tstringParam(\n\t\t\t\tparams,\n\t\t\t\tmethod === \"set_default_provider\"\n\t\t\t\t\t? \"providerId\"\n\t\t\t\t\t: method === \"set_default_model\"\n\t\t\t\t\t\t? \"modelId\"\n\t\t\t\t\t\t: method === \"set_locale\"\n\t\t\t\t\t\t\t? \"locale\"\n\t\t\t\t\t\t\t: \"permissionMode\",\n\t\t\t\tid,\n\t\t\t);\n\t\t\tif (method === \"set_locale\" && params.locale !== \"en\" && params.locale !== \"zh-CN\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"locale must be en or zh-CN.\", id);\n\t\t\tif (\n\t\t\t\tmethod === \"set_permission_mode\" &&\n\t\t\t\tparams.permissionMode !== \"ask\" &&\n\t\t\t\tparams.permissionMode !== \"allow\" &&\n\t\t\t\tparams.permissionMode !== \"deny\"\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"permissionMode must be ask, allow, or deny.\", id);\n\t\t\tbreak;\n\t\tcase \"configure_custom_provider\":\n\t\t\tfor (const name of [\"api\", \"baseUrl\", \"apiKey\", \"modelId\"]) stringParam(params, name, id);\n\t\t\tif (![\"openai-responses\", \"openai-chat-completions\", \"anthropic-messages\"].includes(params.api as string))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"Unsupported custom Provider API.\", id);\n\t\t\tbreak;\n\t\tcase \"set_thinking_level\":\n\t\t\tif (\n\t\t\t\tparams.level !== undefined &&\n\t\t\t\tparams.level !== \"low\" &&\n\t\t\t\tparams.level !== \"medium\" &&\n\t\t\t\tparams.level !== \"high\" &&\n\t\t\t\tparams.level !== \"max\"\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"set_thinking_level.level must be a valid thinking level.\", id);\n\t\t\tbreak;\n\t\tcase \"retry\":\n\t\t\tstringParam(params, \"targetRequestId\", id);\n\t\t\tbreak;\n\t\tcase \"login\":\n\t\t\tstringParam(params, \"providerId\", id);\n\t\t\tstringParam(params, \"apiKey\", id);\n\t\t\tif (params.modelId !== undefined) stringParam(params, \"modelId\", id, true);\n\t\t\tif (params.api !== undefined) stringParam(params, \"api\", id, true);\n\t\t\tbreak;\n\t\tcase \"configure_mcp_server\":\n\t\t\tstringParam(params, \"serverId\", id);\n\t\t\tstringParam(params, \"scope\", id);\n\t\t\tif (!objectRecord(params.config)) throw new RpcProtocolError(\"INVALID_PARAMS\", \"config must be an object.\", id);\n\t\t\tbreak;\n\t\tcase \"remove_mcp_server\":\n\t\t\tstringParam(params, \"serverId\", id);\n\t\t\tif (params.scope !== undefined) stringParam(params, \"scope\", id, true);\n\t\t\tbreak;\n\t\tcase \"set_plugin_enabled\":\n\t\t\tstringParam(params, \"pluginId\", id);\n\t\t\tbooleanParam(params, \"enabled\", id);\n\t\t\tbreak;\n\t\tcase \"set_compaction_enabled\":\n\t\tcase \"set_project_trust\":\n\t\t\tbooleanParam(params, method === \"set_compaction_enabled\" ? \"enabled\" : \"trusted\", id);\n\t\t\tbreak;\n\t\tcase \"get_capabilities\":\n\t\t\tif (\n\t\t\t\tparams.events !== undefined &&\n\t\t\t\t(!Array.isArray(params.events) || !params.events.every((item) => typeof item === \"string\"))\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"get_capabilities.events must be a string array.\", id);\n\t\t\tbreak;\n\t\tcase \"resume_events\":\n\t\t\tif (\n\t\t\t\tparams.lastSequence !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(params.lastSequence) || (params.lastSequence as number) < 0)\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"resume_events.lastSequence must be a non-negative integer.\", id);\n\t\t\tbreak;\n\t\tcase \"create_attachment\":\n\t\t\tstringParam(params, \"name\", id);\n\t\t\tstringParam(params, \"contentType\", id);\n\t\t\tattachmentDataParam(params, id);\n\t\t\tif (![\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"].includes(params.contentType as string))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"Attachment contentType is unsupported.\", id);\n\t\t\tbreak;\n\t\tcase \"get_transcript\":\n\t\t\tif (params.pageToken !== undefined) stringParam(params, \"pageToken\", id, true);\n\t\t\tif (\n\t\t\t\tparams.pageSize !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(params.pageSize) || (params.pageSize as number) < 1 || (params.pageSize as number) > 200)\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"pageSize must be an integer between 1 and 200.\", id);\n\t\t\tif (\n\t\t\t\tparams.maxBytes !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(params.maxBytes) ||\n\t\t\t\t\t(params.maxBytes as number) < 1024 ||\n\t\t\t\t\t(params.maxBytes as number) > RPC_MAX_TRANSCRIPT_BYTES)\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\n\t\t\t\t\t\"INVALID_PARAMS\",\n\t\t\t\t\t`maxBytes must be between 1024 and ${RPC_MAX_TRANSCRIPT_BYTES}.`,\n\t\t\t\t\tid,\n\t\t\t\t);\n\t\t\tbreak;\n\t\tcase \"approve_tool\":\n\t\t\tstringParam(params, \"approvalId\", id);\n\t\t\tbooleanParam(params, \"approved\", id);\n\t\t\tbreak;\n\t}\n\treturn { version: RPC_PROTOCOL_VERSION, kind: \"request\", id, method, params };\n}\n\nexport function parseRpcServerMessage(line: string): RpcServerMessage {\n\tconst record = parseJsonObject(line);\n\tassertVersion(record);\n\tif (record.kind === \"event\") {\n\t\trequiredId(record.requestId, \"requestId\");\n\t\tconst event = objectRecord(record.event);\n\t\tconst type = event?.type;\n\t\tif (\n\t\t\ttypeof type !== \"string\" ||\n\t\t\t(!LEGACY_EVENT_TYPES.has(type as AgentSessionEvent[\"type\"]) && !EXTENDED_EVENT_TYPES.has(type))\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC event must contain a typed event object.\");\n\t\tif (!event) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC event must contain a typed event object.\");\n\t\tif (record.sequence !== undefined && (!Number.isSafeInteger(record.sequence) || (record.sequence as number) < 0))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC event sequence is invalid.\");\n\t\tassertEvent(event, type);\n\t\treturn record as unknown as RpcEventRecord;\n\t}\n\tif (record.kind !== \"response\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", 'RPC server message kind must be \"response\" or \"event\".');\n\tif (record.ok === false) {\n\t\tconst error = objectRecord(record.error);\n\t\tif (\n\t\t\t!error ||\n\t\t\ttypeof error.code !== \"string\" ||\n\t\t\t!RPC_ERROR_CODES.has(error.code as RpcErrorCode) ||\n\t\t\ttypeof error.message !== \"string\"\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC error response has an invalid error object.\");\n\t\tif (record.id !== undefined) requiredId(record.id, \"id\");\n\t\treturn record as unknown as RpcErrorResponse;\n\t}\n\tif (record.ok !== true) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC response ok must be a boolean.\");\n\trequiredId(record.id, \"id\");\n\tconst result = objectRecord(record.result);\n\tif (!result || typeof result.method !== \"string\" || !RPC_METHODS.includes(result.method as RpcMethod))\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC success response has an unknown method.\");\n\tassertSuccessResult(result);\n\treturn record as unknown as RpcSuccessResponse;\n}\nfunction assertSuccessResult(result: Record<string, unknown>): void {\n\tswitch (result.method as RpcMethod) {\n\t\tcase \"prompt\":\n\t\tcase \"retry\":\n\t\t\tassertAssistantMessage(result.message);\n\t\t\treturn;\n\t\tcase \"cancel\":\n\t\t\tif (typeof result.cancelled !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC cancel result is invalid.\");\n\t\t\treturn;\n\t\tcase \"get_state\":\n\t\t\tassertState(result.state);\n\t\t\treturn;\n\t\tcase \"get_capabilities\":\n\t\t\tassertCapabilities(result);\n\t\t\treturn;\n\t\tcase \"resume_events\":\n\t\t\tif (typeof result.snapshotRequired !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC resume_events result is invalid.\");\n\t\t\treturn;\n\t\tcase \"get_operation\":\n\t\t\tassertOperationState(result.operation);\n\t\t\treturn;\n\t\tcase \"create_attachment\":\n\t\t\tassertAttachmentInfo(result.attachment);\n\t\t\treturn;\n\t\tcase \"get_product_state\":\n\t\t\tassertProductState(result.state);\n\t\t\treturn;\n\t\tcase \"get_project_trust\":\n\t\t\tif (typeof result.trusted !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC get_project_trust result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_sessions\":\n\t\t\tif (!Array.isArray(result.sessions))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC list_sessions result is invalid.\");\n\t\t\tfor (const session of result.sessions) assertSessionInfo(session);\n\t\t\treturn;\n\t\tcase \"new_session\":\n\t\tcase \"open_session\":\n\t\tcase \"rename_session\":\n\t\tcase \"branch_session\":\n\t\t\tassertSessionInfo(result.session);\n\t\t\treturn;\n\t\tcase \"inspect_session\":\n\t\t\tif (!objectRecord(result.snapshot))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Session snapshot is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_providers\":\n\t\t\tif (!Array.isArray(result.providers))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC providers result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_context_files\":\n\t\t\tif (!Array.isArray(result.files))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC context files result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_mcp_servers\":\n\t\t\tif (!Array.isArray(result.servers)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC MCP result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_web_contributions\":\n\t\t\t{\n\t\t\t\tconst manifest = objectRecord(result.manifest);\n\t\t\t\tif (!manifest || !validateWebManifest(manifest))\n\t\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Web contribution manifest is invalid.\");\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"list_commands\":\n\t\t\tif (!Array.isArray(result.commands))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC commands result is invalid.\");\n\t\t\tfor (const command of result.commands) assertCommandInfo(command);\n\t\t\treturn;\n\t\tcase \"run_command\":\n\t\t\tif (typeof result.command !== \"string\" || !result.command)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC command result is invalid.\");\n\t\t\tif (result.action !== undefined) assertCommandAction(result.action);\n\t\t\treturn;\n\t\tcase \"configure_mcp_server\":\n\t\tcase \"reconnect_mcp_server\":\n\t\t\tif (!objectRecord(result.server)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC MCP result is invalid.\");\n\t\t\treturn;\n\t\tcase \"login\":\n\t\t\tif (!objectRecord(result.provider)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC login result is invalid.\");\n\t\t\treturn;\n\t\tcase \"set_project_trust\":\n\t\t\tif (typeof result.trusted !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC trust result is invalid.\");\n\t\t\treturn;\n\t\tcase \"logout\":\n\t\tcase \"remove_mcp_server\":\n\t\t\treturn;\n\t\tcase \"get_settings\":\n\t\t\tif (!objectRecord(result.settings))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC settings result is invalid.\");\n\t\t\treturn;\n\t\tcase \"set_default_provider\":\n\t\tcase \"set_default_model\":\n\t\tcase \"set_locale\":\n\t\tcase \"set_permission_mode\":\n\t\tcase \"configure_custom_provider\":\n\t\t\treturn;\n\t}\n}\nfunction assertCapabilities(result: Record<string, unknown>): void {\n\tif (\n\t\t!Array.isArray(result.methods) ||\n\t\t!result.methods.every((method) => typeof method === \"string\" && RPC_METHODS.includes(method as RpcMethod)) ||\n\t\t!Array.isArray(result.events) ||\n\t\t!result.events.every(\n\t\t\t(event) => typeof event === \"string\" && EXTENDED_EVENT_NAMES.has(event as RpcExtendedEventName),\n\t\t) ||\n\t\t!Number.isSafeInteger(result.eventBufferSize) ||\n\t\t(result.eventBufferSize as number) < 0\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC get_capabilities result is invalid.\");\n}\nfunction assertSessionInfo(value: unknown): void {\n\tconst session = objectRecord(value);\n\tif (!session || typeof session.id !== \"string\" || !session.id || typeof session.label !== \"string\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Session result is invalid.\");\n\tif (session.modifiedAt !== undefined && !Number.isFinite(session.modifiedAt))\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Session modifiedAt is invalid.\");\n}\nfunction assertCommandInfo(value: unknown): void {\n\tconst command = objectRecord(value);\n\tif (\n\t\t!command ||\n\t\ttypeof command.name !== \"string\" ||\n\t\t!command.name ||\n\t\ttypeof command.description !== \"string\" ||\n\t\t(command.kind !== \"command\" && command.kind !== \"skill\")\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC command info is invalid.\");\n}\nfunction assertCommandAction(value: unknown): void {\n\tconst action = objectRecord(value);\n\tif (!action || typeof action.command !== \"string\" || !action.command || typeof action.args !== \"string\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC command action is invalid.\");\n}\nfunction assertOperationState(value: unknown): void {\n\tconst operation = objectRecord(value);\n\tif (\n\t\t!operation ||\n\t\ttypeof operation.requestId !== \"string\" ||\n\t\t!operation.requestId ||\n\t\ttypeof operation.kind !== \"string\" ||\n\t\t!RPC_METHODS.includes(operation.kind as RpcMethod) ||\n\t\ttypeof operation.status !== \"string\" ||\n\t\t![\"queued\", \"running\", \"completed\", \"failed\", \"cancelled\", \"crashed\"].includes(operation.status)\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC operation state is invalid.\");\n\tif (operation.sessionId !== undefined && typeof operation.sessionId !== \"string\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC operation session ID is invalid.\");\n\tif (operation.message !== undefined) assertAssistantMessage(operation.message);\n\tif (operation.error !== undefined) assertError(operation.error);\n}\nfunction assertAttachmentInfo(value: unknown): void {\n\tconst attachment = objectRecord(value);\n\tif (\n\t\t!attachment ||\n\t\ttypeof attachment.id !== \"string\" ||\n\t\t!attachment.id ||\n\t\ttypeof attachment.name !== \"string\" ||\n\t\t!attachment.name ||\n\t\ttypeof attachment.contentType !== \"string\" ||\n\t\t![\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"].includes(attachment.contentType) ||\n\t\t!Number.isSafeInteger(attachment.bytes) ||\n\t\t(attachment.bytes as number) < 0\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC attachment result is invalid.\");\n}\nfunction assertProductState(value: unknown): void {\n\tconst state = objectRecord(value);\n\tif (!state || typeof state.projectTrusted !== \"boolean\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC product state is invalid.\");\n}\nfunction assertError(value: unknown): void {\n\tconst error = objectRecord(value);\n\tif (\n\t\t!error ||\n\t\ttypeof error.code !== \"string\" ||\n\t\t!RPC_ERROR_CODES.has(error.code as RpcErrorCode) ||\n\t\ttypeof error.message !== \"string\"\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC error result is invalid.\");\n}\nfunction assertEvent(event: Record<string, unknown>, type: string): void {\n\tif (type === \"operation_update\") {\n\t\tassertOperationState(event.operation);\n\t\treturn;\n\t}\n\tif (type === \"session_changed\") {\n\t\tif (event.session !== undefined) assertSessionInfo(event.session);\n\t\treturn;\n\t}\n\tif (type === \"snapshot_required\") return;\n\tif (type === \"tool_approval\") {\n\t\tif (typeof event.approvalId !== \"string\")\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tool_approval event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"product_audit\") {\n\t\tif (\n\t\t\ttypeof event.action !== \"string\" ||\n\t\t\t![\n\t\t\t\t\"login\",\n\t\t\t\t\"logout\",\n\t\t\t\t\"set_project_trust\",\n\t\t\t\t\"configure_mcp_server\",\n\t\t\t\t\"remove_mcp_server\",\n\t\t\t\t\"reconnect_mcp_server\",\n\t\t\t].includes(event.action) ||\n\t\t\t(event.target !== undefined && typeof event.target !== \"string\") ||\n\t\t\t(event.projectTrusted !== undefined && typeof event.projectTrusted !== \"boolean\")\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC product_audit event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"tool_execution_start\") {\n\t\tif (typeof event.toolCallId !== \"string\" || typeof event.toolName !== \"string\" || !objectRecord(event.arguments))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tool event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"tool_execution_end\") {\n\t\tif (typeof event.toolCallId !== \"string\" || typeof event.toolName !== \"string\" || !objectRecord(event.result))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tool event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"message_start\" || type === \"message_end\") {\n\t\tif (!objectRecord(event.message)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC message event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"message_update\") {\n\t\tconst update = objectRecord(event.event);\n\t\tif (!update || typeof update.type !== \"string\")\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC message update event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"turn_end\") {\n\t\tif (!objectRecord(event.message) || !Array.isArray(event.toolResults))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC turn event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"agent_end\") {\n\t\tif (!Array.isArray(event.messages)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC agent event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"compaction_start\") {\n\t\tif (event.reason !== \"threshold\" && event.reason !== \"manual\")\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC compaction event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"compaction_end\") {\n\t\tif (\n\t\t\t(event.reason !== \"threshold\" && event.reason !== \"manual\") ||\n\t\t\ttypeof event.success !== \"boolean\" ||\n\t\t\t(event.errorMessage !== undefined && typeof event.errorMessage !== \"string\")\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC compaction event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"queue_update\") {\n\t\tif (!Array.isArray(event.steering) || !event.steering.every((item) => typeof item === \"string\"))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC queue event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"tree_navigated\") {\n\t\tif (\n\t\t\ttypeof event.oldLeafId !== \"string\" ||\n\t\t\ttypeof event.newLeafId !== \"string\" ||\n\t\t\ttypeof event.selectedEntryId !== \"string\" ||\n\t\t\ttypeof event.restoredEditorText !== \"boolean\"\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tree event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"usage_update\" && !objectRecord(event.usage)) {\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC usage event is invalid.\");\n\t}\n}\nfunction assertState(value: unknown): void {\n\tconst state = objectRecord(value);\n\tif (\n\t\t!state ||\n\t\ttypeof state.sessionId !== \"string\" ||\n\t\t!state.sessionId ||\n\t\ttypeof state.modelId !== \"string\" ||\n\t\t!state.modelId ||\n\t\ttypeof state.isStreaming !== \"boolean\" ||\n\t\t!Number.isInteger(state.messageCount) ||\n\t\t(state.messageCount as number) < 0\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC get_state response has an invalid state.\");\n}\nfunction assertAssistantMessage(value: unknown): void {\n\tconst message = objectRecord(value);\n\tif (\n\t\t!message ||\n\t\tmessage.role !== \"assistant\" ||\n\t\t!Array.isArray(message.content) ||\n\t\t!message.content.every((content) => {\n\t\t\tconst block = objectRecord(content);\n\t\t\tif (!block || typeof block.type !== \"string\") return false;\n\t\t\tif (block.type === \"text\") return typeof block.text === \"string\";\n\t\t\tif (block.type === \"thinking\") return typeof block.thinking === \"string\";\n\t\t\tif (block.type === \"tool_call\")\n\t\t\t\treturn typeof block.id === \"string\" && typeof block.name === \"string\" && objectRecord(block.arguments);\n\t\t\tif (block.type !== \"image\" || typeof block.data !== \"string\" || typeof block.mimeType !== \"string\") return false;\n\t\t\tconst padding = block.data.endsWith(\"==\") ? 2 : block.data.endsWith(\"=\") ? 1 : 0;\n\t\t\tconst decodedBytes = Math.floor((block.data.length * 3) / 4) - padding;\n\t\t\treturn (\n\t\t\t\t/^image\\/[A-Za-z0-9.+-]+$/.test(block.mimeType) &&\n\t\t\t\tblock.data.length > 0 &&\n\t\t\t\tblock.data.length % 4 === 0 &&\n\t\t\t\t/^[A-Za-z0-9+/]*={0,2}$/.test(block.data) &&\n\t\t\t\tdecodedBytes > 0 &&\n\t\t\t\tdecodedBytes <= RPC_MAX_ASSISTANT_IMAGE_BYTES\n\t\t\t);\n\t\t}) ||\n\t\ttypeof message.provider !== \"string\" ||\n\t\ttypeof message.model !== \"string\" ||\n\t\t!Number.isFinite(message.timestamp) ||\n\t\ttypeof message.stopReason !== \"string\" ||\n\t\t!ASSISTANT_STOP_REASONS.has(message.stopReason)\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC prompt response has an invalid message.\");\n}\nexport function rpcErrorResponse(error: RpcProtocolError): RpcErrorResponse {\n\treturn {\n\t\tversion: RPC_PROTOCOL_VERSION,\n\t\tkind: \"response\",\n\t\t...(error.requestId === undefined ? {} : { id: error.requestId }),\n\t\tok: false,\n\t\terror: { code: error.code, message: error.message },\n\t};\n}\n"]}
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/rpc/protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAU,CAAC;AAC/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AACrC,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,CAAC;AAC/C,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACxD,MAAM,6BAA6B,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACtD,kHAAkH;AAClH,MAA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AAK,KAAK,QAAQ;QACjC,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC;QACnC,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ;QACtC,CAAC,sBAAsB,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC;QAE/C,MAAM,IAAI,gBAAgB,CAAC,iBAAiB,EAAE,6CAA6C,CAAC,CAAC;AAC/F,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,KAAuB;IACvD,OAAO;QACN,OAAO,EAAE,oBAAoB;QAC7B,IAAI,EAAE,UAAU;QAChB,GAAG,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;QACjE,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;KACnD,CAAC;AACH,CAAC","sourcesContent":["import type { AssistantMessage } from \"@di-code/ai\";\nimport { validateWebManifest } from \"@di-code/plugin-runtime\";\nimport type { AgentSessionEvent } from \"../core/session.ts\";\n\nexport const RPC_PROTOCOL_VERSION = 1 as const;\nexport const RPC_MAX_ID_LENGTH = 128;\nexport const RPC_MAX_PROMPT_LENGTH = 1_000_000;\nexport const RPC_MAX_ATTACHMENTS_PER_REQUEST = 4;\nexport const RPC_MAX_ATTACHMENT_BYTES = 5 * 1024 * 1024;\nconst RPC_MAX_ASSISTANT_IMAGE_BYTES = 5 * 1024 * 1024;\n/** Allows one JSONL user entry containing a maximum-sized base64 image to be read in a single transcript page. */\nexport const RPC_MAX_TRANSCRIPT_BYTES = 8 * 1024 * 1024;\nconst RPC_MAX_ATTACHMENT_BASE64_LENGTH = Math.ceil(RPC_MAX_ATTACHMENT_BYTES / 3) * 4;\n\n/** v1 grows only by methods and optional fields. Clients must negotiate extended events first. */\nexport const RPC_METHODS = [\n\t\"prompt\",\n\t\"cancel\",\n\t\"get_state\",\n\t\"get_capabilities\",\n\t\"resume_events\",\n\t\"list_sessions\",\n\t\"new_session\",\n\t\"open_session\",\n\t\"inspect_session\",\n\t\"rename_session\",\n\t\"delete_session\",\n\t\"branch_session\",\n\t\"get_transcript\",\n\t\"get_tree\",\n\t\"navigate_tree\",\n\t\"steer\",\n\t\"retry\",\n\t\"get_operation\",\n\t\"get_models\",\n\t\"set_model\",\n\t\"get_runtime\",\n\t\"set_runtime\",\n\t\"set_thinking_level\",\n\t\"compact\",\n\t\"set_compaction_enabled\",\n\t\"get_usage\",\n\t\"list_skills\",\n\t\"get_resources\",\n\t\"get_product_state\",\n\t\"list_providers\",\n\t\"get_settings\",\n\t\"set_default_provider\",\n\t\"set_default_model\",\n\t\"set_locale\",\n\t\"set_permission_mode\",\n\t\"configure_custom_provider\",\n\t\"login\",\n\t\"logout\",\n\t\"get_project_trust\",\n\t\"set_project_trust\",\n\t\"list_context_files\",\n\t\"list_mcp_servers\",\n\t\"configure_mcp_server\",\n\t\"remove_mcp_server\",\n\t\"reconnect_mcp_server\",\n\t\"list_plugins\",\n\t\"list_web_contributions\",\n\t\"list_commands\",\n\t\"run_command\",\n\t\"set_plugin_enabled\",\n\t\"create_attachment\",\n\t\"approve_tool\",\n\t\"respond_interaction\",\n] as const;\nexport type RpcMethod = (typeof RPC_METHODS)[number];\n\nexport interface RpcRequest {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"request\";\n\treadonly id: string;\n\treadonly method: RpcMethod;\n\treadonly params: Record<string, unknown>;\n}\n\nexport interface RpcSessionState {\n\treadonly sessionId: string;\n\treadonly modelId: string;\n\treadonly isStreaming: boolean;\n\treadonly messageCount: number;\n\treadonly sequence?: number;\n}\n\n/** Metadata for an opaque attachment handle kept only by its live RPC actor. */\nexport interface RpcAttachmentInfo {\n\treadonly id: string;\n\treadonly name: string;\n\treadonly contentType: \"image/png\" | \"image/jpeg\" | \"image/webp\" | \"image/gif\";\n\treadonly bytes: number;\n}\n\nexport interface RpcCapabilities {\n\treadonly methods: readonly RpcMethod[];\n\treadonly events: readonly RpcExtendedEventName[];\n\treadonly eventBufferSize: number;\n}\n\nexport type RpcExtendedEventName =\n\t| \"sequence\"\n\t| \"operation_update\"\n\t| \"snapshot_required\"\n\t| \"session_changed\"\n\t| \"tool_approval\"\n\t| \"interaction_request\"\n\t| \"product_audit\"\n\t| \"projection\";\n\nexport interface RpcProjectionEvent {\n\treadonly type: \"projection\";\n\treadonly namespace: string;\n\treadonly projectionName: string;\n\treadonly version: number;\n\treadonly state: unknown;\n}\n\nexport interface RpcProductState {\n\treadonly projectTrusted: boolean;\n}\n\nexport interface RpcProviderSummary {\n\treadonly id: string;\n\treadonly name: string;\n\treadonly models: readonly {\n\t\treadonly id: string;\n\t\treadonly name: string;\n\t\treadonly input: readonly string[];\n\t\t/** Omitted when the model does not expose selectable reasoning levels. */\n\t\treadonly reasoningEfforts?: readonly (\"low\" | \"medium\" | \"high\" | \"max\")[];\n\t}[];\n\treadonly configured: boolean;\n}\n\nexport interface RpcSettingsSnapshot {\n\treadonly providers: readonly (RpcProviderSummary & {\n\t\treadonly api: string;\n\t\treadonly baseUrl?: string;\n\t\treadonly apiKeySource: \"environment\" | \"settings\" | \"missing\";\n\t})[];\n\treadonly defaults: { readonly providerId?: string; readonly modelId?: string };\n\treadonly runtime: { readonly providerId: string; readonly modelId: string; readonly thinkingLevel?: string };\n\treadonly locale?: \"en\" | \"zh-CN\";\n\treadonly permissionMode: \"ask\" | \"allow\" | \"deny\";\n\treadonly sources: Readonly<Record<string, \"environment\" | \"settings\" | \"default\" | \"runtime\">>;\n}\n\nexport interface RpcContextFileInfo {\n\treadonly path: string;\n\treadonly scope: string;\n\treadonly bytes: number;\n}\n\n/** A user-invocable command projected from the active composition or Skill catalog. */\nexport interface RpcCommandInfo {\n\treadonly name: string;\n\treadonly description: string;\n\treadonly kind: \"command\" | \"skill\";\n}\n\n/** A WebUI operation requested by a registered command. */\nexport interface RpcCommandAction {\n\treadonly command: string;\n\treadonly args: string;\n}\n\nexport interface RpcMcpServerInfo {\n\treadonly id: string;\n\treadonly scope?: string;\n\treadonly state: \"configured\" | \"connected\" | \"failed\" | \"disconnected\";\n\treadonly tools: number;\n\treadonly resources: number;\n\treadonly prompts: number;\n\treadonly diagnostic?: string;\n}\n\nexport type OperationStatus = \"queued\" | \"running\" | \"completed\" | \"failed\" | \"cancelled\" | \"crashed\";\nexport interface OperationState {\n\treadonly requestId: string;\n\treadonly kind: RpcMethod;\n\treadonly status: OperationStatus;\n\treadonly sessionId?: string;\n\treadonly message?: AssistantMessage;\n\treadonly error?: { readonly code: RpcErrorCode; readonly message: string };\n}\n\n/** Method-specific result fields are validated at the wire boundary. */\nexport type RpcSuccessResult = { readonly method: RpcMethod; readonly [key: string]: unknown };\n\nexport type RpcErrorCode =\n\t| \"PARSE_ERROR\"\n\t| \"INVALID_REQUEST\"\n\t| \"UNSUPPORTED_VERSION\"\n\t| \"METHOD_NOT_FOUND\"\n\t| \"INVALID_PARAMS\"\n\t| \"BUSY\"\n\t| \"NOT_FOUND\"\n\t| \"CANCELLED\"\n\t| \"DISPOSED\"\n\t| \"SESSION_IN_USE\"\n\t| \"INVALID_WORKSPACE\"\n\t| \"UNAUTHORIZED\"\n\t| \"INTERNAL_ERROR\"\n\t| \"PROCESS_EXIT\"\n\t| \"INTERACTION_UNAVAILABLE\";\n\nconst RPC_ERROR_CODES: ReadonlySet<RpcErrorCode> = new Set([\n\t\"PARSE_ERROR\",\n\t\"INVALID_REQUEST\",\n\t\"UNSUPPORTED_VERSION\",\n\t\"METHOD_NOT_FOUND\",\n\t\"INVALID_PARAMS\",\n\t\"BUSY\",\n\t\"NOT_FOUND\",\n\t\"CANCELLED\",\n\t\"DISPOSED\",\n\t\"SESSION_IN_USE\",\n\t\"INVALID_WORKSPACE\",\n\t\"UNAUTHORIZED\",\n\t\"INTERNAL_ERROR\",\n\t\"PROCESS_EXIT\",\n\t\"INTERACTION_UNAVAILABLE\",\n]);\nconst LEGACY_EVENT_TYPES: ReadonlySet<AgentSessionEvent[\"type\"]> = new Set([\n\t\"agent_start\",\n\t\"turn_start\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"turn_end\",\n\t\"tool_execution_start\",\n\t\"tool_execution_end\",\n\t\"agent_end\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"queue_update\",\n\t\"tree_navigated\",\n\t\"usage_update\",\n]);\nconst EXTENDED_EVENT_TYPES = new Set([\n\t\"snapshot_required\",\n\t\"operation_update\",\n\t\"session_changed\",\n\t\"tool_approval\",\n\t\"interaction_request\",\n\t\"product_audit\",\n\t\"projection\",\n]);\nconst EXTENDED_EVENT_NAMES: ReadonlySet<RpcExtendedEventName> = new Set([\n\t\"sequence\",\n\t\"operation_update\",\n\t\"snapshot_required\",\n\t\"session_changed\",\n\t\"tool_approval\",\n\t\"interaction_request\",\n\t\"product_audit\",\n\t\"projection\",\n]);\nconst ASSISTANT_STOP_REASONS = new Set([\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\"]);\n\nexport interface RpcSuccessResponse {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"response\";\n\treadonly id: string;\n\treadonly ok: true;\n\treadonly result: RpcSuccessResult;\n}\nexport interface RpcErrorResponse {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"response\";\n\treadonly id?: string;\n\treadonly ok: false;\n\treadonly error: { readonly code: RpcErrorCode; readonly message: string };\n}\nexport interface RpcEventRecord {\n\treadonly version: typeof RPC_PROTOCOL_VERSION;\n\treadonly kind: \"event\";\n\treadonly requestId: string;\n\treadonly event:\n\t\t| AgentSessionEvent\n\t\t| {\n\t\t\t\treadonly type: \"product_audit\";\n\t\t\t\treadonly action:\n\t\t\t\t\t| \"login\"\n\t\t\t\t\t| \"logout\"\n\t\t\t\t\t| \"set_project_trust\"\n\t\t\t\t\t| \"configure_mcp_server\"\n\t\t\t\t\t| \"remove_mcp_server\"\n\t\t\t\t\t| \"reconnect_mcp_server\";\n\t\t\t\treadonly target?: string;\n\t\t\t\treadonly projectTrusted?: boolean;\n\t\t }\n\t\t| {\n\t\t\t\treadonly type:\n\t\t\t\t\t| \"snapshot_required\"\n\t\t\t\t\t| \"operation_update\"\n\t\t\t\t\t| \"session_changed\"\n\t\t\t\t\t| \"tool_approval\"\n\t\t\t\t\t| \"interaction_request\";\n\t\t\t\treadonly [key: string]: unknown;\n\t\t }\n\t\t| RpcProjectionEvent;\n\treadonly sessionId?: string;\n\treadonly sequence?: number;\n}\nexport type RpcResponse = RpcSuccessResponse | RpcErrorResponse;\nexport type RpcServerMessage = RpcResponse | RpcEventRecord;\n\nexport class RpcProtocolError extends Error {\n\treadonly code: RpcErrorCode;\n\treadonly requestId?: string;\n\n\tconstructor(code: RpcErrorCode, message: string, requestId?: string) {\n\t\tsuper(message);\n\t\tthis.name = \"RpcProtocolError\";\n\t\tthis.code = code;\n\t\tthis.requestId = requestId;\n\t}\n}\n\nfunction objectRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)\n\t\t: undefined;\n}\nfunction requiredId(value: unknown, field: string, requestId?: string): string {\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > RPC_MAX_ID_LENGTH)\n\t\tthrow new RpcProtocolError(\n\t\t\t\"INVALID_REQUEST\",\n\t\t\t`${field} must be a non-empty string of at most ${RPC_MAX_ID_LENGTH} characters.`,\n\t\t\trequestId,\n\t\t);\n\treturn value;\n}\nfunction parseJsonObject(line: string): Record<string, unknown> {\n\ttry {\n\t\tconst result = objectRecord(JSON.parse(line));\n\t\tif (!result) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC input must be a JSON object.\");\n\t\treturn result;\n\t} catch (cause) {\n\t\tif (cause instanceof RpcProtocolError) throw cause;\n\t\tthrow new RpcProtocolError(\"PARSE_ERROR\", \"RPC input must be valid JSON.\");\n\t}\n}\nfunction assertVersion(record: Record<string, unknown>, requestId?: string): void {\n\tif (record.version !== RPC_PROTOCOL_VERSION)\n\t\tthrow new RpcProtocolError(\n\t\t\t\"UNSUPPORTED_VERSION\",\n\t\t\t`Unsupported RPC protocol version; expected ${RPC_PROTOCOL_VERSION}.`,\n\t\t\trequestId,\n\t\t);\n}\nfunction stringParam(params: Record<string, unknown>, name: string, id: string, optional = false): void {\n\tconst value = params[name];\n\tif (optional && value === undefined) return;\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > RPC_MAX_PROMPT_LENGTH)\n\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", `${name} must be a non-empty string.`, id);\n}\nfunction booleanParam(params: Record<string, unknown>, name: string, id: string): void {\n\tif (typeof params[name] !== \"boolean\") throw new RpcProtocolError(\"INVALID_PARAMS\", `${name} must be a boolean.`, id);\n}\nfunction attachmentIdsParam(params: Record<string, unknown>, id: string): void {\n\tif (params.attachmentIds === undefined) return;\n\tif (\n\t\t!Array.isArray(params.attachmentIds) ||\n\t\tparams.attachmentIds.length > RPC_MAX_ATTACHMENTS_PER_REQUEST ||\n\t\t!params.attachmentIds.every(\n\t\t\t(value) => typeof value === \"string\" && value.length > 0 && value.length <= RPC_MAX_ID_LENGTH,\n\t\t)\n\t)\n\t\tthrow new RpcProtocolError(\n\t\t\t\"INVALID_PARAMS\",\n\t\t\t`attachmentIds must contain at most ${RPC_MAX_ATTACHMENTS_PER_REQUEST} attachment IDs.`,\n\t\t\tid,\n\t\t);\n}\nfunction attachmentDataParam(params: Record<string, unknown>, id: string): void {\n\tconst data = params.data;\n\tif (typeof data !== \"string\" || data.length === 0 || data.length > RPC_MAX_ATTACHMENT_BASE64_LENGTH)\n\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"Attachment data exceeds the permitted size.\", id);\n}\n\n/** Parses every public v1 method before any dispatcher or transport observes it. */\nexport function parseRpcRequest(line: string): RpcRequest {\n\tconst record = parseJsonObject(line);\n\tconst candidateId = typeof record.id === \"string\" ? record.id : undefined;\n\tassertVersion(record, candidateId);\n\tif (record.kind !== \"request\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", 'RPC request kind must be \"request\".', candidateId);\n\tconst id = requiredId(record.id, \"id\", candidateId);\n\tconst params = objectRecord(record.params);\n\tif (!params) throw new RpcProtocolError(\"INVALID_PARAMS\", \"RPC params must be an object.\", id);\n\tif (typeof record.method !== \"string\" || !RPC_METHODS.includes(record.method as RpcMethod))\n\t\tthrow new RpcProtocolError(\"METHOD_NOT_FOUND\", \"Unknown RPC method.\", id);\n\tconst method = record.method as RpcMethod;\n\tswitch (method) {\n\t\tcase \"prompt\":\n\t\tcase \"steer\":\n\t\t\tstringParam(params, \"message\", id);\n\t\t\tattachmentIdsParam(params, id);\n\t\t\tbreak;\n\t\tcase \"cancel\":\n\t\tcase \"get_operation\":\n\t\tcase \"open_session\":\n\t\tcase \"inspect_session\":\n\t\tcase \"rename_session\":\n\t\tcase \"delete_session\":\n\t\tcase \"navigate_tree\":\n\t\tcase \"set_model\":\n\t\tcase \"logout\":\n\t\tcase \"reconnect_mcp_server\":\n\t\t\tstringParam(\n\t\t\t\tparams,\n\t\t\t\tmethod === \"cancel\" || method === \"get_operation\"\n\t\t\t\t\t? \"requestId\"\n\t\t\t\t\t: method === \"open_session\"\n\t\t\t\t\t\t? \"sessionId\"\n\t\t\t\t\t\t: method === \"inspect_session\" || method === \"rename_session\" || method === \"delete_session\"\n\t\t\t\t\t\t\t? \"sessionId\"\n\t\t\t\t\t\t\t: method === \"navigate_tree\"\n\t\t\t\t\t\t\t\t? \"entryId\"\n\t\t\t\t\t\t\t\t: method === \"set_model\"\n\t\t\t\t\t\t\t\t\t? \"modelId\"\n\t\t\t\t\t\t\t\t\t: method === \"logout\"\n\t\t\t\t\t\t\t\t\t\t? \"providerId\"\n\t\t\t\t\t\t\t\t\t\t: \"serverId\",\n\t\t\t\tid,\n\t\t\t);\n\t\t\tif (method === \"rename_session\") stringParam(params, \"label\", id);\n\t\t\tif (method === \"delete_session\") stringParam(params, \"confirmation\", id);\n\t\t\tbreak;\n\t\tcase \"branch_session\":\n\t\t\tif (params.sessionId !== undefined) stringParam(params, \"sessionId\", id, true);\n\t\t\tif (params.entryId !== undefined) stringParam(params, \"entryId\", id, true);\n\t\t\tbreak;\n\t\tcase \"set_runtime\":\n\t\t\tstringParam(params, \"providerId\", id);\n\t\t\tstringParam(params, \"modelId\", id);\n\t\t\tbreak;\n\t\tcase \"run_command\":\n\t\t\tstringParam(params, \"name\", id);\n\t\t\tif (!/^[a-z][a-z0-9-]*(?::[a-z][a-z0-9-]*)?$/.test(params.name as string))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"run_command.name is invalid.\", id);\n\t\t\tif (params.args !== undefined && (typeof params.args !== \"string\" || params.args.length > RPC_MAX_PROMPT_LENGTH))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"args must be a string of at most 1,000,000 characters.\", id);\n\t\t\tbreak;\n\t\tcase \"set_default_provider\":\n\t\tcase \"set_default_model\":\n\t\tcase \"set_locale\":\n\t\tcase \"set_permission_mode\":\n\t\t\tstringParam(\n\t\t\t\tparams,\n\t\t\t\tmethod === \"set_default_provider\"\n\t\t\t\t\t? \"providerId\"\n\t\t\t\t\t: method === \"set_default_model\"\n\t\t\t\t\t\t? \"modelId\"\n\t\t\t\t\t\t: method === \"set_locale\"\n\t\t\t\t\t\t\t? \"locale\"\n\t\t\t\t\t\t\t: \"permissionMode\",\n\t\t\t\tid,\n\t\t\t);\n\t\t\tif (method === \"set_locale\" && params.locale !== \"en\" && params.locale !== \"zh-CN\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"locale must be en or zh-CN.\", id);\n\t\t\tif (\n\t\t\t\tmethod === \"set_permission_mode\" &&\n\t\t\t\tparams.permissionMode !== \"ask\" &&\n\t\t\t\tparams.permissionMode !== \"allow\" &&\n\t\t\t\tparams.permissionMode !== \"deny\"\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"permissionMode must be ask, allow, or deny.\", id);\n\t\t\tbreak;\n\t\tcase \"configure_custom_provider\":\n\t\t\tfor (const name of [\"api\", \"baseUrl\", \"apiKey\", \"modelId\"]) stringParam(params, name, id);\n\t\t\tif (![\"openai-responses\", \"openai-chat-completions\", \"anthropic-messages\"].includes(params.api as string))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"Unsupported custom Provider API.\", id);\n\t\t\tbreak;\n\t\tcase \"set_thinking_level\":\n\t\t\tif (\n\t\t\t\tparams.level !== undefined &&\n\t\t\t\tparams.level !== \"low\" &&\n\t\t\t\tparams.level !== \"medium\" &&\n\t\t\t\tparams.level !== \"high\" &&\n\t\t\t\tparams.level !== \"max\"\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"set_thinking_level.level must be a valid thinking level.\", id);\n\t\t\tbreak;\n\t\tcase \"retry\":\n\t\t\tstringParam(params, \"targetRequestId\", id);\n\t\t\tbreak;\n\t\tcase \"login\":\n\t\t\tstringParam(params, \"providerId\", id);\n\t\t\tstringParam(params, \"apiKey\", id);\n\t\t\tif (params.modelId !== undefined) stringParam(params, \"modelId\", id, true);\n\t\t\tif (params.api !== undefined) stringParam(params, \"api\", id, true);\n\t\t\tbreak;\n\t\tcase \"configure_mcp_server\":\n\t\t\tstringParam(params, \"serverId\", id);\n\t\t\tstringParam(params, \"scope\", id);\n\t\t\tif (!objectRecord(params.config)) throw new RpcProtocolError(\"INVALID_PARAMS\", \"config must be an object.\", id);\n\t\t\tbreak;\n\t\tcase \"remove_mcp_server\":\n\t\t\tstringParam(params, \"serverId\", id);\n\t\t\tif (params.scope !== undefined) stringParam(params, \"scope\", id, true);\n\t\t\tbreak;\n\t\tcase \"set_plugin_enabled\":\n\t\t\tstringParam(params, \"pluginId\", id);\n\t\t\tbooleanParam(params, \"enabled\", id);\n\t\t\tbreak;\n\t\tcase \"set_compaction_enabled\":\n\t\tcase \"set_project_trust\":\n\t\t\tbooleanParam(params, method === \"set_compaction_enabled\" ? \"enabled\" : \"trusted\", id);\n\t\t\tbreak;\n\t\tcase \"get_capabilities\":\n\t\t\tif (\n\t\t\t\tparams.events !== undefined &&\n\t\t\t\t(!Array.isArray(params.events) || !params.events.every((item) => typeof item === \"string\"))\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"get_capabilities.events must be a string array.\", id);\n\t\t\tbreak;\n\t\tcase \"resume_events\":\n\t\t\tif (\n\t\t\t\tparams.lastSequence !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(params.lastSequence) || (params.lastSequence as number) < 0)\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"resume_events.lastSequence must be a non-negative integer.\", id);\n\t\t\tbreak;\n\t\tcase \"create_attachment\":\n\t\t\tstringParam(params, \"name\", id);\n\t\t\tstringParam(params, \"contentType\", id);\n\t\t\tattachmentDataParam(params, id);\n\t\t\tif (![\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"].includes(params.contentType as string))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"Attachment contentType is unsupported.\", id);\n\t\t\tbreak;\n\t\tcase \"get_transcript\":\n\t\t\tif (params.pageToken !== undefined) stringParam(params, \"pageToken\", id, true);\n\t\t\tif (\n\t\t\t\tparams.pageSize !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(params.pageSize) || (params.pageSize as number) < 1 || (params.pageSize as number) > 200)\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"pageSize must be an integer between 1 and 200.\", id);\n\t\t\tif (\n\t\t\t\tparams.maxBytes !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(params.maxBytes) ||\n\t\t\t\t\t(params.maxBytes as number) < 1024 ||\n\t\t\t\t\t(params.maxBytes as number) > RPC_MAX_TRANSCRIPT_BYTES)\n\t\t\t)\n\t\t\t\tthrow new RpcProtocolError(\n\t\t\t\t\t\"INVALID_PARAMS\",\n\t\t\t\t\t`maxBytes must be between 1024 and ${RPC_MAX_TRANSCRIPT_BYTES}.`,\n\t\t\t\t\tid,\n\t\t\t\t);\n\t\t\tbreak;\n\t\tcase \"approve_tool\":\n\t\t\tstringParam(params, \"approvalId\", id);\n\t\t\tbooleanParam(params, \"approved\", id);\n\t\t\tbreak;\n\t\tcase \"respond_interaction\":\n\t\t\tstringParam(params, \"requestId\", id);\n\t\t\tif (typeof params.status !== \"string\" || ![\"answered\", \"cancelled\", \"timeout\"].includes(params.status))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"respond_interaction.status is invalid.\", id);\n\t\t\tif (params.approved !== undefined && typeof params.approved !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_PARAMS\", \"respond_interaction.approved must be boolean.\", id);\n\t\t\tif (params.value !== undefined) stringParam(params, \"value\", id, true);\n\t\t\tif (params.feedback !== undefined) stringParam(params, \"feedback\", id, true);\n\t\t\tbreak;\n\t}\n\treturn { version: RPC_PROTOCOL_VERSION, kind: \"request\", id, method, params };\n}\n\nexport function parseRpcServerMessage(line: string): RpcServerMessage {\n\tconst record = parseJsonObject(line);\n\tassertVersion(record);\n\tif (record.kind === \"event\") {\n\t\trequiredId(record.requestId, \"requestId\");\n\t\tconst event = objectRecord(record.event);\n\t\tconst type = event?.type;\n\t\tif (\n\t\t\ttypeof type !== \"string\" ||\n\t\t\t(!LEGACY_EVENT_TYPES.has(type as AgentSessionEvent[\"type\"]) && !EXTENDED_EVENT_TYPES.has(type))\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC event must contain a typed event object.\");\n\t\tif (!event) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC event must contain a typed event object.\");\n\t\tif (record.sequence !== undefined && (!Number.isSafeInteger(record.sequence) || (record.sequence as number) < 0))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC event sequence is invalid.\");\n\t\tassertEvent(event, type);\n\t\treturn record as unknown as RpcEventRecord;\n\t}\n\tif (record.kind !== \"response\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", 'RPC server message kind must be \"response\" or \"event\".');\n\tif (record.ok === false) {\n\t\tconst error = objectRecord(record.error);\n\t\tif (\n\t\t\t!error ||\n\t\t\ttypeof error.code !== \"string\" ||\n\t\t\t!RPC_ERROR_CODES.has(error.code as RpcErrorCode) ||\n\t\t\ttypeof error.message !== \"string\"\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC error response has an invalid error object.\");\n\t\tif (record.id !== undefined) requiredId(record.id, \"id\");\n\t\treturn record as unknown as RpcErrorResponse;\n\t}\n\tif (record.ok !== true) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC response ok must be a boolean.\");\n\trequiredId(record.id, \"id\");\n\tconst result = objectRecord(record.result);\n\tif (!result || typeof result.method !== \"string\" || !RPC_METHODS.includes(result.method as RpcMethod))\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC success response has an unknown method.\");\n\tassertSuccessResult(result);\n\treturn record as unknown as RpcSuccessResponse;\n}\nfunction assertSuccessResult(result: Record<string, unknown>): void {\n\tswitch (result.method as RpcMethod) {\n\t\tcase \"prompt\":\n\t\tcase \"retry\":\n\t\t\tassertAssistantMessage(result.message);\n\t\t\treturn;\n\t\tcase \"cancel\":\n\t\t\tif (typeof result.cancelled !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC cancel result is invalid.\");\n\t\t\treturn;\n\t\tcase \"get_state\":\n\t\t\tassertState(result.state);\n\t\t\treturn;\n\t\tcase \"get_capabilities\":\n\t\t\tassertCapabilities(result);\n\t\t\treturn;\n\t\tcase \"resume_events\":\n\t\t\tif (typeof result.snapshotRequired !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC resume_events result is invalid.\");\n\t\t\treturn;\n\t\tcase \"get_operation\":\n\t\t\tassertOperationState(result.operation);\n\t\t\treturn;\n\t\tcase \"create_attachment\":\n\t\t\tassertAttachmentInfo(result.attachment);\n\t\t\treturn;\n\t\tcase \"get_product_state\":\n\t\t\tassertProductState(result.state);\n\t\t\treturn;\n\t\tcase \"get_project_trust\":\n\t\t\tif (typeof result.trusted !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC get_project_trust result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_sessions\":\n\t\t\tif (!Array.isArray(result.sessions))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC list_sessions result is invalid.\");\n\t\t\tfor (const session of result.sessions) assertSessionInfo(session);\n\t\t\treturn;\n\t\tcase \"new_session\":\n\t\tcase \"open_session\":\n\t\tcase \"rename_session\":\n\t\tcase \"branch_session\":\n\t\t\tassertSessionInfo(result.session);\n\t\t\treturn;\n\t\tcase \"inspect_session\":\n\t\t\tif (!objectRecord(result.snapshot))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Session snapshot is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_providers\":\n\t\t\tif (!Array.isArray(result.providers))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC providers result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_context_files\":\n\t\t\tif (!Array.isArray(result.files))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC context files result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_mcp_servers\":\n\t\t\tif (!Array.isArray(result.servers)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC MCP result is invalid.\");\n\t\t\treturn;\n\t\tcase \"list_web_contributions\":\n\t\t\t{\n\t\t\t\tconst manifest = objectRecord(result.manifest);\n\t\t\t\tif (!manifest || !validateWebManifest(manifest))\n\t\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Web contribution manifest is invalid.\");\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"list_commands\":\n\t\t\tif (!Array.isArray(result.commands))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC commands result is invalid.\");\n\t\t\tfor (const command of result.commands) assertCommandInfo(command);\n\t\t\treturn;\n\t\tcase \"run_command\":\n\t\t\tif (typeof result.command !== \"string\" || !result.command)\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC command result is invalid.\");\n\t\t\tif (result.action !== undefined) assertCommandAction(result.action);\n\t\t\treturn;\n\t\tcase \"configure_mcp_server\":\n\t\tcase \"reconnect_mcp_server\":\n\t\t\tif (!objectRecord(result.server)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC MCP result is invalid.\");\n\t\t\treturn;\n\t\tcase \"login\":\n\t\t\tif (!objectRecord(result.provider)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC login result is invalid.\");\n\t\t\treturn;\n\t\tcase \"set_project_trust\":\n\t\t\tif (typeof result.trusted !== \"boolean\")\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC trust result is invalid.\");\n\t\t\treturn;\n\t\tcase \"logout\":\n\t\tcase \"remove_mcp_server\":\n\t\t\treturn;\n\t\tcase \"get_settings\":\n\t\t\tif (!objectRecord(result.settings))\n\t\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC settings result is invalid.\");\n\t\t\treturn;\n\t\tcase \"set_default_provider\":\n\t\tcase \"set_default_model\":\n\t\tcase \"set_locale\":\n\t\tcase \"set_permission_mode\":\n\t\tcase \"configure_custom_provider\":\n\t\tcase \"respond_interaction\":\n\t\t\treturn;\n\t}\n}\nfunction assertCapabilities(result: Record<string, unknown>): void {\n\tif (\n\t\t!Array.isArray(result.methods) ||\n\t\t!result.methods.every((method) => typeof method === \"string\" && RPC_METHODS.includes(method as RpcMethod)) ||\n\t\t!Array.isArray(result.events) ||\n\t\t!result.events.every(\n\t\t\t(event) => typeof event === \"string\" && EXTENDED_EVENT_NAMES.has(event as RpcExtendedEventName),\n\t\t) ||\n\t\t!Number.isSafeInteger(result.eventBufferSize) ||\n\t\t(result.eventBufferSize as number) < 0\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC get_capabilities result is invalid.\");\n}\nfunction assertSessionInfo(value: unknown): void {\n\tconst session = objectRecord(value);\n\tif (!session || typeof session.id !== \"string\" || !session.id || typeof session.label !== \"string\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Session result is invalid.\");\n\tif (session.modifiedAt !== undefined && !Number.isFinite(session.modifiedAt))\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC Session modifiedAt is invalid.\");\n}\nfunction assertCommandInfo(value: unknown): void {\n\tconst command = objectRecord(value);\n\tif (\n\t\t!command ||\n\t\ttypeof command.name !== \"string\" ||\n\t\t!command.name ||\n\t\ttypeof command.description !== \"string\" ||\n\t\t(command.kind !== \"command\" && command.kind !== \"skill\")\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC command info is invalid.\");\n}\nfunction assertCommandAction(value: unknown): void {\n\tconst action = objectRecord(value);\n\tif (!action || typeof action.command !== \"string\" || !action.command || typeof action.args !== \"string\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC command action is invalid.\");\n}\nfunction assertOperationState(value: unknown): void {\n\tconst operation = objectRecord(value);\n\tif (\n\t\t!operation ||\n\t\ttypeof operation.requestId !== \"string\" ||\n\t\t!operation.requestId ||\n\t\ttypeof operation.kind !== \"string\" ||\n\t\t!RPC_METHODS.includes(operation.kind as RpcMethod) ||\n\t\ttypeof operation.status !== \"string\" ||\n\t\t![\"queued\", \"running\", \"completed\", \"failed\", \"cancelled\", \"crashed\"].includes(operation.status)\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC operation state is invalid.\");\n\tif (operation.sessionId !== undefined && typeof operation.sessionId !== \"string\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC operation session ID is invalid.\");\n\tif (operation.message !== undefined) assertAssistantMessage(operation.message);\n\tif (operation.error !== undefined) assertError(operation.error);\n}\nfunction assertAttachmentInfo(value: unknown): void {\n\tconst attachment = objectRecord(value);\n\tif (\n\t\t!attachment ||\n\t\ttypeof attachment.id !== \"string\" ||\n\t\t!attachment.id ||\n\t\ttypeof attachment.name !== \"string\" ||\n\t\t!attachment.name ||\n\t\ttypeof attachment.contentType !== \"string\" ||\n\t\t![\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"].includes(attachment.contentType) ||\n\t\t!Number.isSafeInteger(attachment.bytes) ||\n\t\t(attachment.bytes as number) < 0\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC attachment result is invalid.\");\n}\nfunction assertProductState(value: unknown): void {\n\tconst state = objectRecord(value);\n\tif (!state || typeof state.projectTrusted !== \"boolean\")\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC product state is invalid.\");\n}\nfunction assertError(value: unknown): void {\n\tconst error = objectRecord(value);\n\tif (\n\t\t!error ||\n\t\ttypeof error.code !== \"string\" ||\n\t\t!RPC_ERROR_CODES.has(error.code as RpcErrorCode) ||\n\t\ttypeof error.message !== \"string\"\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC error result is invalid.\");\n}\nfunction assertEvent(event: Record<string, unknown>, type: string): void {\n\tif (type === \"operation_update\") {\n\t\tassertOperationState(event.operation);\n\t\treturn;\n\t}\n\tif (type === \"session_changed\") {\n\t\tif (event.session !== undefined) assertSessionInfo(event.session);\n\t\treturn;\n\t}\n\tif (type === \"snapshot_required\") return;\n\tif (type === \"tool_approval\") {\n\t\tif (typeof event.approvalId !== \"string\")\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tool_approval event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"interaction_request\") {\n\t\tif (\n\t\t\ttypeof event.interactionRequestId !== \"string\" ||\n\t\t\ttypeof event.kind !== \"string\" ||\n\t\t\ttypeof event.prompt !== \"string\"\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC interaction_request event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"product_audit\") {\n\t\tif (\n\t\t\ttypeof event.action !== \"string\" ||\n\t\t\t![\n\t\t\t\t\"login\",\n\t\t\t\t\"logout\",\n\t\t\t\t\"set_project_trust\",\n\t\t\t\t\"configure_mcp_server\",\n\t\t\t\t\"remove_mcp_server\",\n\t\t\t\t\"reconnect_mcp_server\",\n\t\t\t].includes(event.action) ||\n\t\t\t(event.target !== undefined && typeof event.target !== \"string\") ||\n\t\t\t(event.projectTrusted !== undefined && typeof event.projectTrusted !== \"boolean\")\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC product_audit event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"projection\") {\n\t\tif (\n\t\t\ttypeof event.namespace !== \"string\" ||\n\t\t\ttypeof event.projectionName !== \"string\" ||\n\t\t\t!Number.isSafeInteger(event.version) ||\n\t\t\t(event.version as number) < 0 ||\n\t\t\t!(\"state\" in event)\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC projection event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"tool_execution_start\") {\n\t\tif (typeof event.toolCallId !== \"string\" || typeof event.toolName !== \"string\" || !objectRecord(event.arguments))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tool event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"tool_execution_end\") {\n\t\tif (typeof event.toolCallId !== \"string\" || typeof event.toolName !== \"string\" || !objectRecord(event.result))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tool event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"message_start\" || type === \"message_end\") {\n\t\tif (!objectRecord(event.message)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC message event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"message_update\") {\n\t\tconst update = objectRecord(event.event);\n\t\tif (!update || typeof update.type !== \"string\")\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC message update event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"turn_end\") {\n\t\tif (!objectRecord(event.message) || !Array.isArray(event.toolResults))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC turn event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"agent_end\") {\n\t\tif (!Array.isArray(event.messages)) throw new RpcProtocolError(\"INVALID_REQUEST\", \"RPC agent event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"compaction_start\") {\n\t\tif (event.reason !== \"threshold\" && event.reason !== \"manual\")\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC compaction event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"compaction_end\") {\n\t\tif (\n\t\t\t(event.reason !== \"threshold\" && event.reason !== \"manual\") ||\n\t\t\ttypeof event.success !== \"boolean\" ||\n\t\t\t(event.errorMessage !== undefined && typeof event.errorMessage !== \"string\")\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC compaction event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"queue_update\") {\n\t\tif (!Array.isArray(event.steering) || !event.steering.every((item) => typeof item === \"string\"))\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC queue event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"tree_navigated\") {\n\t\tif (\n\t\t\ttypeof event.oldLeafId !== \"string\" ||\n\t\t\ttypeof event.newLeafId !== \"string\" ||\n\t\t\ttypeof event.selectedEntryId !== \"string\" ||\n\t\t\ttypeof event.restoredEditorText !== \"boolean\"\n\t\t)\n\t\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC tree event is invalid.\");\n\t\treturn;\n\t}\n\tif (type === \"usage_update\" && !objectRecord(event.usage)) {\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC usage event is invalid.\");\n\t}\n}\nfunction assertState(value: unknown): void {\n\tconst state = objectRecord(value);\n\tif (\n\t\t!state ||\n\t\ttypeof state.sessionId !== \"string\" ||\n\t\t!state.sessionId ||\n\t\ttypeof state.modelId !== \"string\" ||\n\t\t!state.modelId ||\n\t\ttypeof state.isStreaming !== \"boolean\" ||\n\t\t!Number.isInteger(state.messageCount) ||\n\t\t(state.messageCount as number) < 0\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC get_state response has an invalid state.\");\n}\nfunction assertAssistantMessage(value: unknown): void {\n\tconst message = objectRecord(value);\n\tif (\n\t\t!message ||\n\t\tmessage.role !== \"assistant\" ||\n\t\t!Array.isArray(message.content) ||\n\t\t!message.content.every((content) => {\n\t\t\tconst block = objectRecord(content);\n\t\t\tif (!block || typeof block.type !== \"string\") return false;\n\t\t\tif (block.type === \"text\") return typeof block.text === \"string\";\n\t\t\tif (block.type === \"thinking\") return typeof block.thinking === \"string\";\n\t\t\tif (block.type === \"tool_call\")\n\t\t\t\treturn typeof block.id === \"string\" && typeof block.name === \"string\" && objectRecord(block.arguments);\n\t\t\tif (block.type !== \"image\" || typeof block.data !== \"string\" || typeof block.mimeType !== \"string\") return false;\n\t\t\tconst padding = block.data.endsWith(\"==\") ? 2 : block.data.endsWith(\"=\") ? 1 : 0;\n\t\t\tconst decodedBytes = Math.floor((block.data.length * 3) / 4) - padding;\n\t\t\treturn (\n\t\t\t\t/^image\\/[A-Za-z0-9.+-]+$/.test(block.mimeType) &&\n\t\t\t\tblock.data.length > 0 &&\n\t\t\t\tblock.data.length % 4 === 0 &&\n\t\t\t\t/^[A-Za-z0-9+/]*={0,2}$/.test(block.data) &&\n\t\t\t\tdecodedBytes > 0 &&\n\t\t\t\tdecodedBytes <= RPC_MAX_ASSISTANT_IMAGE_BYTES\n\t\t\t);\n\t\t}) ||\n\t\ttypeof message.provider !== \"string\" ||\n\t\ttypeof message.model !== \"string\" ||\n\t\t!Number.isFinite(message.timestamp) ||\n\t\ttypeof message.stopReason !== \"string\" ||\n\t\t!ASSISTANT_STOP_REASONS.has(message.stopReason)\n\t)\n\t\tthrow new RpcProtocolError(\"INVALID_REQUEST\", \"RPC prompt response has an invalid message.\");\n}\nexport function rpcErrorResponse(error: RpcProtocolError): RpcErrorResponse {\n\treturn {\n\t\tversion: RPC_PROTOCOL_VERSION,\n\t\tkind: \"response\",\n\t\t...(error.requestId === undefined ? {} : { id: error.requestId }),\n\t\tok: false,\n\t\terror: { code: error.code, message: error.message },\n\t};\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { Readable, Writable } from "node:stream";
2
+ import type { UserInteractionInput, UserInteractionResult } from "@di-code/plugin-sdk";
2
3
  import { type RpcDispatcherOptions } from "./dispatcher.ts";
3
4
  export type { RpcMethodCatalog, RpcSession } from "./dispatcher.ts";
4
5
  /** JSONL process adapter. Protocol dispatch belongs to RpcDispatcher and is transport independent. */
@@ -23,6 +24,10 @@ export declare class RpcServer {
23
24
  private writeChain;
24
25
  constructor(options: RpcServerOptions);
25
26
  finished(): Promise<void>;
27
+ /** Forwards a structured interaction request to the negotiated RPC client. */
28
+ requestInteraction(input: Omit<UserInteractionInput, "requestId"> & {
29
+ readonly requestId?: string;
30
+ }, signal?: AbortSignal): Promise<UserInteractionResult>;
26
31
  start(): void;
27
32
  stop(): void;
28
33
  shutdown(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/rpc/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACt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B,CACjB,KAAK,EAAE,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,GAAG;QAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,EAChF,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,qBAAqB,CAAC;IAGjC,KAAK,IAAI,IAAI;IAUb,IAAI,IAAI,IAAI;IAGZ,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;YAYX,cAAc;IAU5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CASzB;IACF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAOxB;IACF,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAG/B;IACF,OAAO,CAAC,UAAU;IAoBlB,OAAO,CAAC,UAAU;IAGlB,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,KAAK;CAKb"}
@@ -31,6 +31,10 @@ export class RpcServer {
31
31
  finished() {
32
32
  return this.finishedPromise;
33
33
  }
34
+ /** Forwards a structured interaction request to the negotiated RPC client. */
35
+ requestInteraction(input, signal) {
36
+ return this.dispatcher.requestInteraction(input, signal);
37
+ }
34
38
  start() {
35
39
  if (this.started)
36
40
  throw new Error("RPC server is already started.");
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/rpc/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAA6B,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAyB,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAW3G,SAAS,SAAS,CAAC,KAAc;IAChC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,OAAO,SAAS;IACJ,KAAK,CAAW;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,CAAC,OAAyB;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CACjC,GAAG,EAAE,CACJ,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAC7F,CACF,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC;IACd,CAAC;IACO,KAAK;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAC1B,GAAG,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAC7G,CAAC;IACH,CAAC;CACD","sourcesContent":["import type { Readable, Writable } from \"node:stream\";\nimport { RpcDispatcher, type RpcDispatcherOptions } from \"./dispatcher.ts\";\nimport { JsonlLineDecoder, serializeJsonLine } from \"./jsonl.ts\";\nimport { parseRpcRequest, RpcProtocolError, type RpcServerMessage, rpcErrorResponse } from \"./protocol.ts\";\n\nexport type { RpcMethodCatalog, RpcSession } from \"./dispatcher.ts\";\n\n/** JSONL process adapter. Protocol dispatch belongs to RpcDispatcher and is transport independent. */\nexport interface RpcServerOptions extends RpcDispatcherOptions {\n\treadonly input: Readable;\n\treadonly output: Writable;\n\treadonly maxLineBytes?: number;\n}\n\nfunction errorFrom(cause: unknown): Error {\n\treturn cause instanceof Error ? cause : new Error(String(cause));\n}\n\nexport class RpcServer {\n\tprivate readonly input: Readable;\n\tprivate readonly output: Writable;\n\tprivate readonly onError: (error: Error) => void;\n\tprivate readonly decoder: JsonlLineDecoder;\n\tprivate readonly dispatcher: RpcDispatcher;\n\tprivate readonly requests = new Set<Promise<void>>();\n\tprivate readonly finishedPromise: Promise<void>;\n\tprivate resolveFinished?: () => void;\n\tprivate unsubscribe?: () => void;\n\tprivate shutdownPromise?: Promise<void>;\n\tprivate started = false;\n\tprivate shuttingDown = false;\n\tprivate writeChain = Promise.resolve();\n\n\tconstructor(options: RpcServerOptions) {\n\t\tthis.input = options.input;\n\t\tthis.output = options.output;\n\t\tthis.onError = options.onError ?? (() => undefined);\n\t\tthis.dispatcher = new RpcDispatcher(options);\n\t\tthis.decoder = new JsonlLineDecoder((line) => this.acceptLine(line), { maxLineBytes: options.maxLineBytes });\n\t\tthis.finishedPromise = new Promise((resolve) => {\n\t\t\tthis.resolveFinished = resolve;\n\t\t});\n\t}\n\n\tfinished(): Promise<void> {\n\t\treturn this.finishedPromise;\n\t}\n\tstart(): void {\n\t\tif (this.started) throw new Error(\"RPC server is already started.\");\n\t\tthis.started = true;\n\t\tthis.unsubscribe = this.dispatcher.subscribe((message) => {\n\t\t\tif (!this.shuttingDown) void this.write(message).catch(this.onError);\n\t\t});\n\t\tthis.input.on(\"data\", this.handleData);\n\t\tthis.input.once(\"end\", this.handleEnd);\n\t\tthis.input.once(\"error\", this.handleInputError);\n\t}\n\tstop(): void {\n\t\tvoid this.shutdown().catch(this.onError);\n\t}\n\tshutdown(): Promise<void> {\n\t\tif (this.shutdownPromise) return this.shutdownPromise;\n\t\tthis.shuttingDown = true;\n\t\tthis.started = false;\n\t\tthis.input.off(\"data\", this.handleData);\n\t\tthis.input.off(\"end\", this.handleEnd);\n\t\tthis.input.off(\"error\", this.handleInputError);\n\t\tthis.unsubscribe?.();\n\t\tthis.unsubscribe = undefined;\n\t\tthis.shutdownPromise = this.finishShutdown();\n\t\treturn this.shutdownPromise;\n\t}\n\tprivate async finishShutdown(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.dispatcher.dispose();\n\t\t\tawait Promise.allSettled([...this.requests]);\n\t\t\tawait this.flush();\n\t\t} finally {\n\t\t\tthis.resolveFinished?.();\n\t\t\tthis.resolveFinished = undefined;\n\t\t}\n\t}\n\tprivate readonly handleData = (chunk: string | Buffer): void => {\n\t\ttry {\n\t\t\tthis.decoder.push(chunk);\n\t\t} catch (cause) {\n\t\t\tconst error = errorFrom(cause);\n\t\t\tthis.onError(error);\n\t\t\tvoid this.writeError(undefined, \"INVALID_REQUEST\", error.message);\n\t\t\tthis.stop();\n\t\t}\n\t};\n\tprivate readonly handleEnd = (): void => {\n\t\ttry {\n\t\t\tthis.decoder.end();\n\t\t} catch (cause) {\n\t\t\tthis.onError(errorFrom(cause));\n\t\t}\n\t\tvoid this.shutdown().catch(this.onError);\n\t};\n\tprivate readonly handleInputError = (cause: Error): void => {\n\t\tthis.onError(cause);\n\t\tvoid this.shutdown().catch(this.onError);\n\t};\n\tprivate acceptLine(line: string): void {\n\t\tif (this.shuttingDown) return;\n\t\tlet request: import(\"./protocol.ts\").RpcRequest;\n\t\ttry {\n\t\t\trequest = parseRpcRequest(line);\n\t\t} catch (cause) {\n\t\t\tconst error =\n\t\t\t\tcause instanceof RpcProtocolError\n\t\t\t\t\t? cause\n\t\t\t\t\t: new RpcProtocolError(\"INVALID_REQUEST\", \"RPC request validation failed.\");\n\t\t\tvoid this.write(rpcErrorResponse(error)).catch(this.onError);\n\t\t\treturn;\n\t\t}\n\t\tconst work = this.dispatcher\n\t\t\t.dispatch(request)\n\t\t\t.then((response) => this.write(response))\n\t\t\t.catch((cause) => this.onError(errorFrom(cause)))\n\t\t\t.finally(() => this.requests.delete(work));\n\t\tthis.requests.add(work);\n\t}\n\tprivate writeError(id: string | undefined, code: \"INVALID_REQUEST\", message: string): Promise<void> {\n\t\treturn this.write({ version: 1, kind: \"response\", ...(id ? { id } : {}), ok: false, error: { code, message } });\n\t}\n\tprivate write(message: RpcServerMessage): Promise<void> {\n\t\tconst write = this.writeChain.then(\n\t\t\t() =>\n\t\t\t\tnew Promise<void>((resolve, reject) =>\n\t\t\t\t\tthis.output.write(serializeJsonLine(message), (error) => (error ? reject(error) : resolve())),\n\t\t\t\t),\n\t\t);\n\t\tthis.writeChain = write.catch(() => undefined);\n\t\treturn write;\n\t}\n\tprivate flush(): Promise<void> {\n\t\treturn this.writeChain.then(\n\t\t\t() => new Promise((resolve, reject) => this.output.write(\"\", (error) => (error ? reject(error) : resolve()))),\n\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/rpc/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAA6B,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAyB,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAW3G,SAAS,SAAS,CAAC,KAAc;IAChC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,OAAO,SAAS;IACJ,KAAK,CAAW;IAChB,MAAM,CAAW;IACjB,OAAO,CAAyB;IAChC,OAAO,CAAmB;IAC1B,UAAU,CAAgB;IAC1B,QAAQ,GAAG,IAAI,GAAG,EAAiB,CAAC;IACpC,eAAe,CAAgB;IACxC,eAAe,CAAc;IAC7B,WAAW,CAAc;IACzB,eAAe,CAAiB;IAChC,OAAO,GAAG,KAAK,CAAC;IAChB,YAAY,GAAG,KAAK,CAAC;IACrB,UAAU,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAEvC,YAAY,OAAyB;QACpC,IAAI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,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAC7F,CACF,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC;IACd,CAAC;IACO,KAAK;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAC1B,GAAG,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAC7G,CAAC;IACH,CAAC;CACD","sourcesContent":["import type { Readable, Writable } from \"node:stream\";\nimport type { UserInteractionInput, UserInteractionResult } from \"@di-code/plugin-sdk\";\nimport { RpcDispatcher, type RpcDispatcherOptions } from \"./dispatcher.ts\";\nimport { JsonlLineDecoder, serializeJsonLine } from \"./jsonl.ts\";\nimport { parseRpcRequest, RpcProtocolError, type RpcServerMessage, rpcErrorResponse } from \"./protocol.ts\";\n\nexport type { RpcMethodCatalog, RpcSession } from \"./dispatcher.ts\";\n\n/** JSONL process adapter. Protocol dispatch belongs to RpcDispatcher and is transport independent. */\nexport interface RpcServerOptions extends RpcDispatcherOptions {\n\treadonly input: Readable;\n\treadonly output: Writable;\n\treadonly maxLineBytes?: number;\n}\n\nfunction errorFrom(cause: unknown): Error {\n\treturn cause instanceof Error ? cause : new Error(String(cause));\n}\n\nexport class RpcServer {\n\tprivate readonly input: Readable;\n\tprivate readonly output: Writable;\n\tprivate readonly onError: (error: Error) => void;\n\tprivate readonly decoder: JsonlLineDecoder;\n\tprivate readonly dispatcher: RpcDispatcher;\n\tprivate readonly requests = new Set<Promise<void>>();\n\tprivate readonly finishedPromise: Promise<void>;\n\tprivate resolveFinished?: () => void;\n\tprivate unsubscribe?: () => void;\n\tprivate shutdownPromise?: Promise<void>;\n\tprivate started = false;\n\tprivate shuttingDown = false;\n\tprivate writeChain = Promise.resolve();\n\n\tconstructor(options: RpcServerOptions) {\n\t\tthis.input = options.input;\n\t\tthis.output = options.output;\n\t\tthis.onError = options.onError ?? (() => undefined);\n\t\tthis.dispatcher = new RpcDispatcher(options);\n\t\tthis.decoder = new JsonlLineDecoder((line) => this.acceptLine(line), { maxLineBytes: options.maxLineBytes });\n\t\tthis.finishedPromise = new Promise((resolve) => {\n\t\t\tthis.resolveFinished = resolve;\n\t\t});\n\t}\n\n\tfinished(): Promise<void> {\n\t\treturn this.finishedPromise;\n\t}\n\t/** Forwards a structured interaction request to the negotiated RPC client. */\n\trequestInteraction(\n\t\tinput: Omit<UserInteractionInput, \"requestId\"> & { readonly requestId?: string },\n\t\tsignal?: AbortSignal,\n\t): Promise<UserInteractionResult> {\n\t\treturn this.dispatcher.requestInteraction(input, signal);\n\t}\n\tstart(): void {\n\t\tif (this.started) throw new Error(\"RPC server is already started.\");\n\t\tthis.started = true;\n\t\tthis.unsubscribe = this.dispatcher.subscribe((message) => {\n\t\t\tif (!this.shuttingDown) void this.write(message).catch(this.onError);\n\t\t});\n\t\tthis.input.on(\"data\", this.handleData);\n\t\tthis.input.once(\"end\", this.handleEnd);\n\t\tthis.input.once(\"error\", this.handleInputError);\n\t}\n\tstop(): void {\n\t\tvoid this.shutdown().catch(this.onError);\n\t}\n\tshutdown(): Promise<void> {\n\t\tif (this.shutdownPromise) return this.shutdownPromise;\n\t\tthis.shuttingDown = true;\n\t\tthis.started = false;\n\t\tthis.input.off(\"data\", this.handleData);\n\t\tthis.input.off(\"end\", this.handleEnd);\n\t\tthis.input.off(\"error\", this.handleInputError);\n\t\tthis.unsubscribe?.();\n\t\tthis.unsubscribe = undefined;\n\t\tthis.shutdownPromise = this.finishShutdown();\n\t\treturn this.shutdownPromise;\n\t}\n\tprivate async finishShutdown(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.dispatcher.dispose();\n\t\t\tawait Promise.allSettled([...this.requests]);\n\t\t\tawait this.flush();\n\t\t} finally {\n\t\t\tthis.resolveFinished?.();\n\t\t\tthis.resolveFinished = undefined;\n\t\t}\n\t}\n\tprivate readonly handleData = (chunk: string | Buffer): void => {\n\t\ttry {\n\t\t\tthis.decoder.push(chunk);\n\t\t} catch (cause) {\n\t\t\tconst error = errorFrom(cause);\n\t\t\tthis.onError(error);\n\t\t\tvoid this.writeError(undefined, \"INVALID_REQUEST\", error.message);\n\t\t\tthis.stop();\n\t\t}\n\t};\n\tprivate readonly handleEnd = (): void => {\n\t\ttry {\n\t\t\tthis.decoder.end();\n\t\t} catch (cause) {\n\t\t\tthis.onError(errorFrom(cause));\n\t\t}\n\t\tvoid this.shutdown().catch(this.onError);\n\t};\n\tprivate readonly handleInputError = (cause: Error): void => {\n\t\tthis.onError(cause);\n\t\tvoid this.shutdown().catch(this.onError);\n\t};\n\tprivate acceptLine(line: string): void {\n\t\tif (this.shuttingDown) return;\n\t\tlet request: import(\"./protocol.ts\").RpcRequest;\n\t\ttry {\n\t\t\trequest = parseRpcRequest(line);\n\t\t} catch (cause) {\n\t\t\tconst error =\n\t\t\t\tcause instanceof RpcProtocolError\n\t\t\t\t\t? cause\n\t\t\t\t\t: new RpcProtocolError(\"INVALID_REQUEST\", \"RPC request validation failed.\");\n\t\t\tvoid this.write(rpcErrorResponse(error)).catch(this.onError);\n\t\t\treturn;\n\t\t}\n\t\tconst work = this.dispatcher\n\t\t\t.dispatch(request)\n\t\t\t.then((response) => this.write(response))\n\t\t\t.catch((cause) => this.onError(errorFrom(cause)))\n\t\t\t.finally(() => this.requests.delete(work));\n\t\tthis.requests.add(work);\n\t}\n\tprivate writeError(id: string | undefined, code: \"INVALID_REQUEST\", message: string): Promise<void> {\n\t\treturn this.write({ version: 1, kind: \"response\", ...(id ? { id } : {}), ok: false, error: { code, message } });\n\t}\n\tprivate write(message: RpcServerMessage): Promise<void> {\n\t\tconst write = this.writeChain.then(\n\t\t\t() =>\n\t\t\t\tnew Promise<void>((resolve, reject) =>\n\t\t\t\t\tthis.output.write(serializeJsonLine(message), (error) => (error ? reject(error) : resolve())),\n\t\t\t\t),\n\t\t);\n\t\tthis.writeChain = write.catch(() => undefined);\n\t\treturn write;\n\t}\n\tprivate flush(): Promise<void> {\n\t\treturn this.writeChain.then(\n\t\t\t() => new Promise((resolve, reject) => this.output.write(\"\", (error) => (error ? reject(error) : resolve()))),\n\t\t);\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-server-entry.d.ts","sourceRoot":"","sources":["../src/rpc-server-entry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOhE,OAAO,EAAE,KAAK,gBAAgB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE9E,qGAAqG;AACrG,eAAO,MAAM,UAAU,EAAG,CAAU,CAAC;AACrC,eAAO,MAAM,IAAI,eAAe,CAAC;AACjC,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAwD3C,CAAC"}
1
+ {"version":3,"file":"rpc-server-entry.d.ts","sourceRoot":"","sources":["../src/rpc-server-entry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAQhE,OAAO,EAAE,KAAK,gBAAgB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE9E,qGAAqG;AACrG,eAAO,MAAM,UAAU,EAAG,CAAU,CAAC;AACrC,eAAO,MAAM,IAAI,eAAe,CAAC;AACjC,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAoE3C,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { homedir } from "node:os";
2
2
  import { join } from "node:path";
3
3
  import { modeRegistryKey, rpcMethodRegistryKey, runtimeSelectionKey, workspaceCapabilityKey } from "@di-code/builtins";
4
+ import { createUserInteraction } from "@di-code/plugin-sdk";
4
5
  import { RpcServer } from "./rpc/server.js";
5
6
  import { rpcServerKey } from "./rpc/server-service.js";
6
7
  import { createProductHost } from "./runtime/product-host.js";
@@ -13,11 +14,23 @@ export const name = "rpc-server";
13
14
  export const version = "0.1.7";
14
15
  export const apply = async (context, _config, fiber) => {
15
16
  const selection = context.require(runtimeSelectionKey).selected();
17
+ let server;
18
+ const interaction = createUserInteraction({
19
+ request: async (input, signal) => {
20
+ if (!server)
21
+ throw new Error("RPC server is not ready.");
22
+ return await server.requestInteraction(input, signal);
23
+ },
24
+ });
16
25
  const session = await createSessionHost(context, {
17
26
  cwd: context.require(workspaceCapabilityKey).allowedRoot,
18
27
  agentDir: join(homedir(), ".di-code"),
19
28
  provider: selection.provider,
20
29
  model: selection.model,
30
+ planMode: {
31
+ section: "You are in plan mode. Explore and design before presenting the complete plan through exit_plan_mode.",
32
+ },
33
+ interaction,
21
34
  });
22
35
  const product = createProductHost({
23
36
  context,
@@ -47,7 +60,7 @@ export const apply = async (context, _config, fiber) => {
47
60
  });
48
61
  if (!session.state().activeSession)
49
62
  await session.createSession();
50
- const server = new RpcServer({
63
+ server = new RpcServer({
51
64
  session,
52
65
  methods: context.require(rpcMethodRegistryKey),
53
66
  productState: { projectTrusted: context.capabilities.trustedProject },
@@ -60,6 +73,7 @@ export const apply = async (context, _config, fiber) => {
60
73
  context.set(rpcServerKey, { shutdown: () => server.shutdown(), finished: () => server.finished() });
61
74
  fiber.addDisposer(async () => {
62
75
  await server.shutdown();
76
+ await interaction.dispose();
63
77
  await product.dispose();
64
78
  await session.dispose();
65
79
  });
@@ -1 +1 @@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CAAC,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { modeRegistryKey, rpcMethodRegistryKey, runtimeSelectionKey, workspaceCapabilityKey } from \"@di-code/builtins\";\nimport type { PluginDefinition } from \"@di-code/plugin-runtime\";\nimport { RpcServer } from \"./rpc/server.ts\";\nimport { rpcServerKey } from \"./rpc/server-service.ts\";\nimport { createProductHost } from \"./runtime/product-host.ts\";\nimport { createSessionHost } from \"./runtime/session-host.ts\";\nimport { loadStartupConfiguration, resolveStartupRuntime } from \"./startup.ts\";\n\nexport { type RpcServerService, rpcServerKey } from \"./rpc/server-service.ts\";\n\n/** Creates the process RPC server from composition services and releases it with its owner Fiber. */\nexport const apiVersion = 1 as const;\nexport const name = \"rpc-server\";\nexport const version = \"0.1.7\";\nexport const apply: PluginDefinition[\"apply\"] = async (context, _config, fiber) => {\n\tconst selection = context.require(runtimeSelectionKey).selected();\n\tconst session = await createSessionHost(context, {\n\t\tcwd: context.require(workspaceCapabilityKey).allowedRoot,\n\t\tagentDir: join(homedir(), \".di-code\"),\n\t\tprovider: selection.provider,\n\t\tmodel: selection.model,\n\t});\n\tconst product = createProductHost({\n\t\tcontext,\n\t\tcwd: context.require(workspaceCapabilityKey).allowedRoot,\n\t\tagentDir: join(homedir(), \".di-code\"),\n\t\tprojectTrusted: context.capabilities.trustedProject,\n\t\tprovider: selection.provider,\n\t\tmodel: selection.model,\n\t\truntimeSnapshot: () => {\n\t\t\tconst ui = session.ui();\n\t\t\treturn {\n\t\t\t\tproviderId: ui.providerId,\n\t\t\t\tmodelId: ui.modelId,\n\t\t\t\t...(ui.thinkingLevel ? { thinkingLevel: ui.thinkingLevel } : {}),\n\t\t\t};\n\t\t},\n\t\treloadRuntime: async () => {\n\t\t\tconst cwd = context.require(workspaceCapabilityKey).allowedRoot;\n\t\t\tconst agentDir = join(homedir(), \".di-code\");\n\t\t\tconst configuration = await loadStartupConfiguration(cwd, process.env, agentDir);\n\t\t\tconst runtime = resolveStartupRuntime(configuration.environment, configuration.providers, configuration.defaults);\n\t\t\tsession.setRuntimeValue(runtime.provider, runtime.model);\n\t\t\treturn configuration;\n\t\t},\n\t\treloadConfiguration: () =>\n\t\t\tloadStartupConfiguration(\n\t\t\t\tcontext.require(workspaceCapabilityKey).allowedRoot,\n\t\t\t\tprocess.env,\n\t\t\t\tjoin(homedir(), \".di-code\"),\n\t\t\t),\n\t\trefreshResources: (projectTrusted) => session.refreshResources(projectTrusted),\n\t});\n\tif (!session.state().activeSession) await session.createSession();\n\tconst server = new RpcServer({\n\t\tsession,\n\t\tmethods: context.require(rpcMethodRegistryKey),\n\t\tproductState: { projectTrusted: context.capabilities.trustedProject },\n\t\tproductHost: product,\n\t\tinput: process.stdin,\n\t\toutput: process.stdout,\n\t\tonError: (error) => process.stderr.write(`${error.message}\\n`),\n\t});\n\tawait context.require(modeRegistryKey).execute(\"rpc\", { run: () => server.start() });\n\tcontext.set(rpcServerKey, { shutdown: () => server.shutdown(), finished: () => server.finished() });\n\tfiber.addDisposer(async () => {\n\t\tawait server.shutdown();\n\t\tawait product.dispose();\n\t\tawait session.dispose();\n\t});\n};\n"]}
1
+ {"version":3,"file":"rpc-server-entry.js","sourceRoot":"","sources":["../src/rpc-server-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEvH,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,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["import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { modeRegistryKey, rpcMethodRegistryKey, runtimeSelectionKey, workspaceCapabilityKey } from \"@di-code/builtins\";\nimport type { PluginDefinition } from \"@di-code/plugin-runtime\";\nimport { createUserInteraction } from \"@di-code/plugin-sdk\";\nimport { RpcServer } from \"./rpc/server.ts\";\nimport { rpcServerKey } from \"./rpc/server-service.ts\";\nimport { createProductHost } from \"./runtime/product-host.ts\";\nimport { createSessionHost } from \"./runtime/session-host.ts\";\nimport { loadStartupConfiguration, resolveStartupRuntime } from \"./startup.ts\";\n\nexport { type RpcServerService, rpcServerKey } from \"./rpc/server-service.ts\";\n\n/** Creates the process RPC server from composition services and releases it with its owner Fiber. */\nexport const apiVersion = 1 as const;\nexport const name = \"rpc-server\";\nexport const version = \"0.1.7\";\nexport const apply: PluginDefinition[\"apply\"] = async (context, _config, fiber) => {\n\tconst selection = context.require(runtimeSelectionKey).selected();\n\tlet server: RpcServer | undefined;\n\tconst interaction = createUserInteraction({\n\t\trequest: async (input, signal) => {\n\t\t\tif (!server) throw new Error(\"RPC server is not ready.\");\n\t\t\treturn await server.requestInteraction(input, signal);\n\t\t},\n\t});\n\tconst session = await createSessionHost(context, {\n\t\tcwd: context.require(workspaceCapabilityKey).allowedRoot,\n\t\tagentDir: join(homedir(), \".di-code\"),\n\t\tprovider: selection.provider,\n\t\tmodel: selection.model,\n\t\tplanMode: {\n\t\t\tsection: \"You are in plan mode. Explore and design before presenting the complete plan through exit_plan_mode.\",\n\t\t},\n\t\tinteraction,\n\t});\n\tconst product = createProductHost({\n\t\tcontext,\n\t\tcwd: context.require(workspaceCapabilityKey).allowedRoot,\n\t\tagentDir: join(homedir(), \".di-code\"),\n\t\tprojectTrusted: context.capabilities.trustedProject,\n\t\tprovider: selection.provider,\n\t\tmodel: selection.model,\n\t\truntimeSnapshot: () => {\n\t\t\tconst ui = session.ui();\n\t\t\treturn {\n\t\t\t\tproviderId: ui.providerId,\n\t\t\t\tmodelId: ui.modelId,\n\t\t\t\t...(ui.thinkingLevel ? { thinkingLevel: ui.thinkingLevel } : {}),\n\t\t\t};\n\t\t},\n\t\treloadRuntime: async () => {\n\t\t\tconst cwd = context.require(workspaceCapabilityKey).allowedRoot;\n\t\t\tconst agentDir = join(homedir(), \".di-code\");\n\t\t\tconst configuration = await loadStartupConfiguration(cwd, process.env, agentDir);\n\t\t\tconst runtime = resolveStartupRuntime(configuration.environment, configuration.providers, configuration.defaults);\n\t\t\tsession.setRuntimeValue(runtime.provider, runtime.model);\n\t\t\treturn configuration;\n\t\t},\n\t\treloadConfiguration: () =>\n\t\t\tloadStartupConfiguration(\n\t\t\t\tcontext.require(workspaceCapabilityKey).allowedRoot,\n\t\t\t\tprocess.env,\n\t\t\t\tjoin(homedir(), \".di-code\"),\n\t\t\t),\n\t\trefreshResources: (projectTrusted) => session.refreshResources(projectTrusted),\n\t});\n\tif (!session.state().activeSession) await session.createSession();\n\tserver = new RpcServer({\n\t\tsession,\n\t\tmethods: context.require(rpcMethodRegistryKey),\n\t\tproductState: { projectTrusted: context.capabilities.trustedProject },\n\t\tproductHost: product,\n\t\tinput: process.stdin,\n\t\toutput: process.stdout,\n\t\tonError: (error) => process.stderr.write(`${error.message}\\n`),\n\t});\n\tawait context.require(modeRegistryKey).execute(\"rpc\", { run: () => server.start() });\n\tcontext.set(rpcServerKey, { shutdown: () => server.shutdown(), finished: () => server.finished() });\n\tfiber.addDisposer(async () => {\n\t\tawait server.shutdown();\n\t\tawait interaction.dispose();\n\t\tawait product.dispose();\n\t\tawait session.dispose();\n\t});\n};\n"]}