@canonmsg/backend-contracts 1.9.0 → 2.0.0

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 (198) hide show
  1. package/dist/agentBehaviorPolicy.d.ts +45 -86
  2. package/dist/agentBehaviorPolicy.js +0 -53
  3. package/dist/cjs/agentBehaviorPolicy.js +1 -54
  4. package/dist/cjs/contactRequest.js +0 -30
  5. package/dist/cjs/index.js +0 -8
  6. package/dist/cjs/media.js +0 -13
  7. package/dist/cjs/message.js +0 -64
  8. package/dist/cjs/runtimeCardFields.js +1 -58
  9. package/dist/cjs/turnProtocol.js +1 -41
  10. package/dist/contactRequest.d.ts +23 -42
  11. package/dist/contactRequest.js +0 -29
  12. package/dist/index.d.ts +0 -8
  13. package/dist/index.js +0 -8
  14. package/dist/media.d.ts +11 -24
  15. package/dist/media.js +0 -12
  16. package/dist/message.d.ts +50 -133
  17. package/dist/message.js +1 -64
  18. package/dist/runtimeCardFields.d.ts +39 -112
  19. package/dist/runtimeCardFields.js +0 -57
  20. package/dist/turnProtocol.d.ts +24 -91
  21. package/dist/turnProtocol.js +0 -40
  22. package/package.json +5 -8
  23. package/dist/bridgeLocal.d.ts +0 -1871
  24. package/dist/bridgeLocal.js +0 -744
  25. package/dist/cjs/bridgeLocal.js +0 -747
  26. package/dist/cjs/controlSignals.js +0 -44
  27. package/dist/cjs/endpointRegistry.js +0 -264
  28. package/dist/cjs/hitl.js +0 -171
  29. package/dist/cjs/inboundFrame.js +0 -92
  30. package/dist/cjs/restEndpoints.js +0 -237
  31. package/dist/cjs/sendContextual.js +0 -92
  32. package/dist/cjs/sseEvents.js +0 -281
  33. package/dist/controlSignals.d.ts +0 -55
  34. package/dist/controlSignals.js +0 -41
  35. package/dist/endpointRegistry.d.ts +0 -13
  36. package/dist/endpointRegistry.js +0 -261
  37. package/dist/hitl.d.ts +0 -303
  38. package/dist/hitl.js +0 -168
  39. package/dist/inboundFrame.d.ts +0 -229
  40. package/dist/inboundFrame.js +0 -89
  41. package/dist/restEndpoints.d.ts +0 -531
  42. package/dist/restEndpoints.js +0 -234
  43. package/dist/schemas/agent-behavior-settings-record.schema.json +0 -48
  44. package/dist/schemas/bridge-connection-state-notification.schema.json +0 -19
  45. package/dist/schemas/bridge-get-attachment-params.schema.json +0 -24
  46. package/dist/schemas/bridge-get-attachment-result.schema.json +0 -20
  47. package/dist/schemas/bridge-hello-params.schema.json +0 -42
  48. package/dist/schemas/bridge-hello-result.schema.json +0 -105
  49. package/dist/schemas/bridge-hitl-state.schema.json +0 -38
  50. package/dist/schemas/bridge-ok-result.schema.json +0 -15
  51. package/dist/schemas/bridge-publish-streaming-event-params.schema.json +0 -138
  52. package/dist/schemas/bridge-ready-notification.schema.json +0 -79
  53. package/dist/schemas/bridge-resync-reason.schema.json +0 -9
  54. package/dist/schemas/bridge-resync.schema.json +0 -18
  55. package/dist/schemas/bridge-rpc-error.schema.json +0 -19
  56. package/dist/schemas/bridge-rpc-id.schema.json +0 -12
  57. package/dist/schemas/bridge-rpc-notification.schema.json +0 -20
  58. package/dist/schemas/bridge-rpc-request.schema.json +0 -31
  59. package/dist/schemas/bridge-rpc-response.schema.json +0 -81
  60. package/dist/schemas/bridge-status-result.schema.json +0 -76
  61. package/dist/schemas/bridge-stream-clear-event.schema.json +0 -15
  62. package/dist/schemas/bridge-stream-event.schema.json +0 -112
  63. package/dist/schemas/bridge-stream-final-event.schema.json +0 -19
  64. package/dist/schemas/bridge-stream-text-event.schema.json +0 -31
  65. package/dist/schemas/bridge-stream-thinking-event.schema.json +0 -15
  66. package/dist/schemas/bridge-stream-tool-event.schema.json +0 -36
  67. package/dist/schemas/bridge-upload-media-params.schema.json +0 -28
  68. package/dist/schemas/bridge-upstream-state.schema.json +0 -10
  69. package/dist/schemas/contacts-response.schema.json +0 -52
  70. package/dist/schemas/control-channel-key.schema.json +0 -10
  71. package/dist/schemas/control-primitive-event.schema.json +0 -30
  72. package/dist/schemas/control-primitive-map.schema.json +0 -15
  73. package/dist/schemas/control-session-event.schema.json +0 -26
  74. package/dist/schemas/control-session-node.schema.json +0 -11
  75. package/dist/schemas/control-signal-event.schema.json +0 -35
  76. package/dist/schemas/control-signal-node.schema.json +0 -22
  77. package/dist/schemas/control-signal-type.schema.json +0 -10
  78. package/dist/schemas/conversations-response.schema.json +0 -167
  79. package/dist/schemas/create-contact-request-request.schema.json +0 -17
  80. package/dist/schemas/create-contact-request-response.schema.json +0 -51
  81. package/dist/schemas/create-conversation-request.schema.json +0 -82
  82. package/dist/schemas/create-conversation-response.schema.json +0 -29
  83. package/dist/schemas/delete-message-response.schema.json +0 -11
  84. package/dist/schemas/delivery-intent.schema.json +0 -11
  85. package/dist/schemas/forward-message-request.schema.json +0 -25
  86. package/dist/schemas/forward-message-response.schema.json +0 -35
  87. package/dist/schemas/forwarded-from.schema.json +0 -18
  88. package/dist/schemas/get-messages-query.schema.json +0 -17
  89. package/dist/schemas/hitl-approval-category.schema.json +0 -15
  90. package/dist/schemas/hitl-approval-detail.schema.json +0 -21
  91. package/dist/schemas/hitl-approval-outcome-record.schema.json +0 -33
  92. package/dist/schemas/hitl-approval-reply-record.schema.json +0 -57
  93. package/dist/schemas/hitl-approval-request-record.schema.json +0 -105
  94. package/dist/schemas/hitl-approval-risk.schema.json +0 -11
  95. package/dist/schemas/hitl-card-outcome-record.schema.json +0 -48
  96. package/dist/schemas/hitl-card-reply-record.schema.json +0 -46
  97. package/dist/schemas/hitl-card-request-record.schema.json +0 -73
  98. package/dist/schemas/hitl-input-answers.schema.json +0 -23
  99. package/dist/schemas/hitl-input-kind.schema.json +0 -10
  100. package/dist/schemas/hitl-input-outcome-record.schema.json +0 -46
  101. package/dist/schemas/hitl-input-question.schema.json +0 -54
  102. package/dist/schemas/hitl-input-reply-record.schema.json +0 -44
  103. package/dist/schemas/hitl-input-request-record.schema.json +0 -134
  104. package/dist/schemas/hitl-pending.schema.json +0 -31
  105. package/dist/schemas/hitl-request-accepted.schema.json +0 -18
  106. package/dist/schemas/hitl-request-kind.schema.json +0 -10
  107. package/dist/schemas/hitl-resolution-status.schema.json +0 -10
  108. package/dist/schemas/hitl-resolution.schema.json +0 -38
  109. package/dist/schemas/hitl-session-rule.schema.json +0 -32
  110. package/dist/schemas/inbound-disposition.schema.json +0 -13
  111. package/dist/schemas/inbound-frame-attachment-v1.schema.json +0 -94
  112. package/dist/schemas/inbound-frame-contact-card-v1.schema.json +0 -59
  113. package/dist/schemas/inbound-frame-group-context-v1.schema.json +0 -96
  114. package/dist/schemas/inbound-frame-reply-context-v1.schema.json +0 -261
  115. package/dist/schemas/inbound-frame-shape-v1.schema.json +0 -12
  116. package/dist/schemas/inbound-frame-v1.schema.json +0 -506
  117. package/dist/schemas/mark-read-response.schema.json +0 -11
  118. package/dist/schemas/media-attachment-kind.schema.json +0 -11
  119. package/dist/schemas/media-attachment.schema.json +0 -42
  120. package/dist/schemas/messages-page-response.schema.json +0 -290
  121. package/dist/schemas/participation-decision-input.schema.json +0 -44
  122. package/dist/schemas/participation-history-message.schema.json +0 -23
  123. package/dist/schemas/participation-history-snapshot.schema.json +0 -37
  124. package/dist/schemas/participation-style.schema.json +0 -13
  125. package/dist/schemas/react-request.schema.json +0 -22
  126. package/dist/schemas/react-response.schema.json +0 -35
  127. package/dist/schemas/resolve-admission-request.schema.json +0 -30
  128. package/dist/schemas/resolve-admission-response.schema.json +0 -129
  129. package/dist/schemas/resolved-agent-behavior-policy-record.schema.json +0 -81
  130. package/dist/schemas/rest-contact.schema.json +0 -40
  131. package/dist/schemas/rest-conversation-last-message.schema.json +0 -77
  132. package/dist/schemas/rest-conversation.schema.json +0 -155
  133. package/dist/schemas/rest-message.schema.json +0 -252
  134. package/dist/schemas/rest-ok-response.schema.json +0 -11
  135. package/dist/schemas/rest-session-selection.schema.json +0 -40
  136. package/dist/schemas/runtime-card-field-choice.schema.json +0 -23
  137. package/dist/schemas/runtime-card-field-type.schema.json +0 -17
  138. package/dist/schemas/runtime-card-field.schema.json +0 -180
  139. package/dist/schemas/runtime-card-line-item-column-type.schema.json +0 -12
  140. package/dist/schemas/runtime-card-line-item-column.schema.json +0 -74
  141. package/dist/schemas/send-contextual-deferred-response.schema.json +0 -39
  142. package/dist/schemas/send-contextual-messaged-response.schema.json +0 -42
  143. package/dist/schemas/send-contextual-request.schema.json +0 -103
  144. package/dist/schemas/send-contextual-response.schema.json +0 -105
  145. package/dist/schemas/send-contextual-self-context.schema.json +0 -19
  146. package/dist/schemas/send-contextual-state-response.schema.json +0 -24
  147. package/dist/schemas/send-message-request.schema.json +0 -106
  148. package/dist/schemas/send-message-response.schema.json +0 -14
  149. package/dist/schemas/sender-type.schema.json +0 -9
  150. package/dist/schemas/serialize-message-input.schema.json +0 -29
  151. package/dist/schemas/serialized-agent-client-type.schema.json +0 -12
  152. package/dist/schemas/serialized-contact-card.schema.json +0 -65
  153. package/dist/schemas/serialized-contact-request-status.schema.json +0 -11
  154. package/dist/schemas/serialized-contact-request.schema.json +0 -157
  155. package/dist/schemas/serialized-content-type.schema.json +0 -13
  156. package/dist/schemas/serialized-message.schema.json +0 -249
  157. package/dist/schemas/serialized-reactions.schema.json +0 -14
  158. package/dist/schemas/serialized-sender-type.schema.json +0 -9
  159. package/dist/schemas/set-streaming-request.schema.json +0 -67
  160. package/dist/schemas/set-typing-request.schema.json +0 -25
  161. package/dist/schemas/sse-access-policy.schema.json +0 -10
  162. package/dist/schemas/sse-agent-context-payload.schema.json +0 -57
  163. package/dist/schemas/sse-connected-payload.schema.json +0 -18
  164. package/dist/schemas/sse-contact-payload.schema.json +0 -40
  165. package/dist/schemas/sse-contact-removed-payload.schema.json +0 -14
  166. package/dist/schemas/sse-contact-request-payload.schema.json +0 -157
  167. package/dist/schemas/sse-conversation-updated-payload.schema.json +0 -48
  168. package/dist/schemas/sse-error-payload.schema.json +0 -23
  169. package/dist/schemas/sse-event-envelope.schema.json +0 -40
  170. package/dist/schemas/sse-event-family.schema.json +0 -12
  171. package/dist/schemas/sse-event-type.schema.json +0 -26
  172. package/dist/schemas/sse-heartbeat-payload.schema.json +0 -14
  173. package/dist/schemas/sse-membership-change.schema.json +0 -28
  174. package/dist/schemas/sse-message-created-payload.schema.json +0 -414
  175. package/dist/schemas/sse-message-deleted-payload.schema.json +0 -18
  176. package/dist/schemas/sse-message-updated-payload.schema.json +0 -46
  177. package/dist/schemas/sse-presence-payload.schema.json +0 -21
  178. package/dist/schemas/sse-provenance.schema.json +0 -64
  179. package/dist/schemas/sse-replay-expired-payload.schema.json +0 -21
  180. package/dist/schemas/sse-runtime-control-kind.schema.json +0 -13
  181. package/dist/schemas/sse-runtime-control-payload.schema.json +0 -44
  182. package/dist/schemas/sse-self-context.schema.json +0 -45
  183. package/dist/schemas/sse-turn-dispatch.schema.json +0 -29
  184. package/dist/schemas/sse-typing-payload.schema.json +0 -32
  185. package/dist/schemas/sse-voice-session-event-payload.schema.json +0 -170
  186. package/dist/schemas/sse-voice-session.schema.json +0 -157
  187. package/dist/schemas/trigger-decision.schema.json +0 -27
  188. package/dist/schemas/turn-lifecycle-state.schema.json +0 -14
  189. package/dist/schemas/turn-message-semantics.schema.json +0 -10
  190. package/dist/schemas/turn-metadata.schema.json +0 -56
  191. package/dist/schemas/turn-state-like.schema.json +0 -39
  192. package/dist/schemas/update-disposition-request.schema.json +0 -22
  193. package/dist/schemas/upload-media-request.schema.json +0 -25
  194. package/dist/schemas/upload-media-response.schema.json +0 -55
  195. package/dist/sendContextual.d.ts +0 -114
  196. package/dist/sendContextual.js +0 -89
  197. package/dist/sseEvents.d.ts +0 -474
  198. package/dist/sseEvents.js +0 -278
@@ -1,747 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BridgeRpcResponseSchema = exports.BridgeRpcErrorSchema = exports.BridgeRpcNotificationSchema = exports.BridgeRpcRequestSchema = exports.BridgeRpcIdSchema = exports.BRIDGE_LOCAL_NOTIFICATION_FAMILIES = exports.BRIDGE_LOCAL_NOTIFICATION_NAMES = exports.BRIDGE_LOCAL_NOTIFICATIONS = exports.BRIDGE_LOCAL_METHOD_NAMES = exports.BRIDGE_LOCAL_METHODS = exports.BridgePublishStreamingEventParamsSchema = exports.BridgeStreamEventSchema = exports.BridgeStreamClearEventSchema = exports.BridgeStreamFinalEventSchema = exports.BridgeStreamThinkingEventSchema = exports.BridgeStreamTextEventSchema = exports.BridgeStreamToolEventSchema = exports.BridgeGetAttachmentResultSchema = exports.BridgeGetAttachmentParamsSchema = exports.BridgeUploadMediaParamsSchema = exports.BridgeHitlStateSchema = exports.BridgeStatusResultSchema = exports.BridgeConnectionStateNotificationSchema = exports.BridgeReadyNotificationSchema = exports.BridgeUpstreamStateSchema = exports.BridgeHelloResultSchema = exports.BRIDGE_EVENT_CURSOR_SHAPE = exports.BridgeResyncSchema = exports.BridgeResyncReasonSchema = exports.BridgeHelloParamsSchema = exports.BridgeOkResultSchema = exports.BRIDGE_LOCAL_PROTOCOL_VERSION = void 0;
4
- // Bridge ⇄ runtime-adapter LOCAL JSON-RPC contract v1 (types + schemas ONLY —
5
- // no runtime, no transport; Phase 4 builds the bridge against these).
6
- //
7
- // Source spec: docs/design/bridge-local-api.md §A–§C. Where that draft
8
- // conflicts with code-grounded wire shapes (event names, REST payloads), the
9
- // code-grounded schemas in this package win — payload slots below COMPOSE
10
- // restEndpoints.ts / hitl.ts / sseEvents.ts / controlSignals.ts so every
11
- // shape is defined once.
12
- //
13
- // Protocol: JSON-RPC 2.0 over one duplex channel (stdio pipe or unix
14
- // socket / named pipe), NDJSON framing. Requests adapter→bridge (replied),
15
- // notifications bridge→adapter (never awaited). `hello` carries
16
- // protocolVersion — the local contract is version-guarded from v1.
17
- const zod_1 = require("zod");
18
- const contactRequest_js_1 = require("./contactRequest.js");
19
- const turnProtocol_js_1 = require("./turnProtocol.js");
20
- const controlSignals_js_1 = require("./controlSignals.js");
21
- const hitl_js_1 = require("./hitl.js");
22
- const restEndpoints_js_1 = require("./restEndpoints.js");
23
- const sendContextual_js_1 = require("./sendContextual.js");
24
- const sseEvents_js_1 = require("./sseEvents.js");
25
- exports.BRIDGE_LOCAL_PROTOCOL_VERSION = 1;
26
- const OkResultSchema = zod_1.z.object({ ok: zod_1.z.literal(true) });
27
- exports.BridgeOkResultSchema = OkResultSchema;
28
- // ── §A Session lifecycle ───────────────────────────────────────────────
29
- exports.BridgeHelloParamsSchema = zod_1.z.object({
30
- protocolVersion: zod_1.z.number(),
31
- /** Adapter self-identification (claude-code | codex | openclaw | hermes | …). */
32
- clientType: zod_1.z.string(),
33
- /** Event families to deliver; [] = pure-request adapter, no C-notifications. */
34
- wantFamilies: zod_1.z.array(sseEvents_js_1.SseEventFamilySchema),
35
- /** Replay C-notifications missed while disconnected. */
36
- resumeCursor: zod_1.z.string().optional(),
37
- /** Publish the runtime descriptor in the same round trip. */
38
- runtimeDescriptor: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
39
- });
40
- // ── §G resume cursor / resync ───────────────────────────────────────────
41
- //
42
- // The bridge keeps a bounded, locally-sequenced event log. Every replayable
43
- // §C event notification carries the OPAQUE `cursor` token that produced it;
44
- // adapters persist the last cursor they fully processed and present it as
45
- // `hello.resumeCursor` on reconnect to replay exactly the gap. When the
46
- // cursor cannot be honored the hello result answers `sinceCursor: null`
47
- // PLUS a `resync` field — the adapter must treat the gap as lost locally and
48
- // recover out-of-band (REST backfill / state refresh). Never silent loss.
49
- exports.BridgeResyncReasonSchema = zod_1.z.enum([
50
- /** Cursor was valid but its events were evicted from the bounded log. */
51
- 'cursor-expired',
52
- /** Cursor was never issued by this bridge run (restart or corruption). */
53
- 'unknown-cursor',
54
- ]);
55
- exports.BridgeResyncSchema = zod_1.z.object({
56
- reason: exports.BridgeResyncReasonSchema,
57
- });
58
- /**
59
- * Shape mixin for replayable §C notification params (`.extend(...)` onto the
60
- * payload schema). `cursor` is optional in the schema for compatibility, but
61
- * the bridge always sends it on log-delivered notifications. `ready` and
62
- * `connectionState` are connection-scoped (never replayed) and carry none.
63
- */
64
- exports.BRIDGE_EVENT_CURSOR_SHAPE = {
65
- cursor: zod_1.z.string().optional(),
66
- };
67
- exports.BridgeHelloResultSchema = zod_1.z.object({
68
- protocolVersion: zod_1.z.number(),
69
- agentId: zod_1.z.string(),
70
- agentName: zod_1.z.string(),
71
- agentContext: sseEvents_js_1.SseAgentContextPayloadSchema,
72
- /** Cursor the delivered replay starts from; null = no replay. */
73
- sinceCursor: zod_1.z.string().nullable(),
74
- /**
75
- * Present when resumeCursor could not be honored (§G): delivery starts at
76
- * the live head and the adapter must recover the gap out-of-band.
77
- */
78
- resync: exports.BridgeResyncSchema.optional(),
79
- });
80
- exports.BridgeUpstreamStateSchema = zod_1.z.enum(['connected', 'reconnecting', 'down']);
81
- exports.BridgeReadyNotificationSchema = zod_1.z.object({
82
- agentId: zod_1.z.string(),
83
- agentContext: sseEvents_js_1.SseAgentContextPayloadSchema,
84
- upstreamState: exports.BridgeUpstreamStateSchema,
85
- });
86
- exports.BridgeConnectionStateNotificationSchema = zod_1.z.object({
87
- upstream: exports.BridgeUpstreamStateSchema,
88
- });
89
- /**
90
- * `status` result (B4.6 observability): a live snapshot of the daemon
91
- * process, its upstream health, and the B4.2 hub counters. Additive to
92
- * contract v1 — served by the daemon and rendered by `canon-bridge status`.
93
- */
94
- exports.BridgeStatusResultSchema = zod_1.z.object({
95
- /** Daemon process id. */
96
- pid: zod_1.z.number(),
97
- /** canon-bridge binary (package) version. */
98
- version: zod_1.z.string(),
99
- /** bridgeLocal contract version the daemon speaks. */
100
- protocolVersion: zod_1.z.number(),
101
- /** ISO timestamp of daemon start. */
102
- startedAt: zod_1.z.string(),
103
- uptimeMs: zod_1.z.number(),
104
- /** Lifecycle profile served (one identity per daemon). */
105
- profile: zod_1.z.string(),
106
- /** Socket / named-pipe path; null in stdio (spawned-child) mode. */
107
- socketPath: zod_1.z.string().nullable(),
108
- agentId: zod_1.z.string(),
109
- agentName: zod_1.z.string(),
110
- upstream: exports.BridgeUpstreamStateSchema,
111
- /** Adapter connections currently subscribed to the fan-out. */
112
- connectedClients: zod_1.z.number(),
113
- /** Non-zero B4.2 hub counters (upstream.* / fanout.*). */
114
- counters: zod_1.z.record(zod_1.z.string(), zod_1.z.number()),
115
- });
116
- // ── §B7 HITL state (durable; resolution arrives via onHitlResolved) ────
117
- exports.BridgeHitlStateSchema = zod_1.z.object({
118
- status: zod_1.z.union([zod_1.z.literal('pending'), hitl_js_1.HitlResolutionStatusSchema]),
119
- answer: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
120
- expiresAt: zod_1.z.string(),
121
- });
122
- // ── §B8 media (named schemas so the bridge + Framework share the types) ──
123
- //
124
- // Byte transfer is bridge-owned (adapter-interface §1): adapters hand the
125
- // bridge a {path} (streamed from disk — preferred for anything big) or
126
- // inline {bytes} (base64, size-capped so a frame never breaches the NDJSON
127
- // line limit). getAttachment returns the bridge-cached materialization.
128
- exports.BridgeUploadMediaParamsSchema = zod_1.z.object({
129
- /** Absolute file path — the bridge streams it (exactly one of path | bytes). */
130
- path: zod_1.z.string().optional(),
131
- /** Base64 bytes — size-capped by the bridge; prefer `path` for large files. */
132
- bytes: zod_1.z.string().optional(),
133
- mime: zod_1.z.string(),
134
- fileName: zod_1.z.string(),
135
- conversationId: zod_1.z.string(),
136
- });
137
- exports.BridgeGetAttachmentParamsSchema = zod_1.z.object({
138
- /** Storage download URL from a MediaAttachment (exactly one of url | attachmentId). */
139
- url: zod_1.z.string().optional(),
140
- attachmentId: zod_1.z.string().optional(),
141
- as: zod_1.z.enum(['path', 'bytes']),
142
- });
143
- exports.BridgeGetAttachmentResultSchema = zod_1.z.object({
144
- /** Stable bridge-cache path — present when as:'path'. */
145
- path: zod_1.z.string().optional(),
146
- /** Base64 — present when as:'bytes'; capped by the bridge's bytes ceiling. */
147
- bytes: zod_1.z.string().optional(),
148
- mime: zod_1.z.string(),
149
- });
150
- const conversationScoped = zod_1.z.object({ conversationId: zod_1.z.string() });
151
- const messageScoped = zod_1.z.object({ conversationId: zod_1.z.string(), messageId: zod_1.z.string() });
152
- /**
153
- * RTDB server-timestamp sentinel — code-grounded pass-through (hosts write
154
- * `{'.sv':'timestamp'}` for openedAt/completedAt today; the bridge forwards
155
- * it to the RTDB REST API untouched).
156
- */
157
- const ServerTimestampSentinelSchema = zod_1.z.object({ '.sv': zod_1.z.literal('timestamp') });
158
- const EpochOrServerTimestampSchema = zod_1.z.union([zod_1.z.number(), ServerTimestampSentinelSchema]);
159
- // ─────────────────────────────────────────────────────────────────────────
160
- // W2-A4 REGION START — bridge-owned streaming assembly (raw event surface).
161
- // ADDITIVE: `publishStreamingEvent` lets a channel adapter forward RAW turn
162
- // events (a text segment begin/append/replace, a tool-trail item, a thinking
163
- // tick, a final compose, or a clear). The BRIDGE owns snapshot assembly, the
164
- // single write cadence, thinking keepalive, final compose, and node clear —
165
- // so adapters stop reimplementing turn-output-controller + a keepalive loop
166
- // (T1: they also stop swallowing the write failure). The pre-existing
167
- // snapshot `publishStreaming` (below) is UNTOUCHED — coding hosts still call
168
- // it via agent-host/runtime-writers.
169
- // ─────────────────────────────────────────────────────────────────────────
170
- /** A single tool-trail item forwarded raw; the bridge folds it into `blocks`. */
171
- exports.BridgeStreamToolEventSchema = zod_1.z.object({
172
- kind: zod_1.z.literal('tool'),
173
- /** Stable block id (adapter-scoped, e.g. `tool:{turnId}`). */
174
- id: zod_1.z.string(),
175
- status: zod_1.z.enum(['running', 'completed', 'failed']).optional(),
176
- title: zod_1.z.string().optional(),
177
- summary: zod_1.z.string().optional(),
178
- detail: zod_1.z.string().optional(),
179
- });
180
- /**
181
- * A visible-text segment. `mode:'append'` concatenates onto the segment's
182
- * running text; `mode:'replace'` overwrites it (the adapter already holds the
183
- * full segment). The bridge rebuilds the bubble text from its text segments in
184
- * sequence order, exactly as the core turn-output-controller does today.
185
- */
186
- exports.BridgeStreamTextEventSchema = zod_1.z.object({
187
- kind: zod_1.z.literal('text'),
188
- /** Segment id (adapter-scoped, e.g. `text:{turnId}:{n}`). */
189
- id: zod_1.z.string(),
190
- mode: zod_1.z.enum(['append', 'replace']),
191
- text: zod_1.z.string(),
192
- });
193
- /** A thinking tick (onset or keepalive) — no content; keeps the bubble warm. */
194
- exports.BridgeStreamThinkingEventSchema = zod_1.z.object({
195
- kind: zod_1.z.literal('thinking'),
196
- });
197
- /**
198
- * Final compose: the assembled reply text is written one last time (status
199
- * settles to `streaming`) and the node is LEFT in place for the final-message
200
- * handoff. Clearing is a separate `clear` event / `clearStreaming`.
201
- */
202
- exports.BridgeStreamFinalEventSchema = zod_1.z.object({
203
- kind: zod_1.z.literal('final'),
204
- text: zod_1.z.string(),
205
- });
206
- /** Clear the streaming node (turn ended / interrupted). */
207
- exports.BridgeStreamClearEventSchema = zod_1.z.object({
208
- kind: zod_1.z.literal('clear'),
209
- });
210
- exports.BridgeStreamEventSchema = zod_1.z.discriminatedUnion('kind', [
211
- exports.BridgeStreamTextEventSchema,
212
- exports.BridgeStreamToolEventSchema,
213
- exports.BridgeStreamThinkingEventSchema,
214
- exports.BridgeStreamFinalEventSchema,
215
- exports.BridgeStreamClearEventSchema,
216
- ]);
217
- exports.BridgePublishStreamingEventParamsSchema = conversationScoped.extend({
218
- /** New turnId resets the bridge's accumulation for this conversation. */
219
- turnId: zod_1.z.string().nullable().optional(),
220
- messageId: zod_1.z.string().optional(),
221
- event: exports.BridgeStreamEventSchema,
222
- });
223
- // W2-A4 REGION END — bridge-owned streaming assembly.
224
- exports.BRIDGE_LOCAL_METHODS = {
225
- // §A lifecycle
226
- hello: { params: exports.BridgeHelloParamsSchema, result: exports.BridgeHelloResultSchema },
227
- /** Liveness probe — the bridge answers without touching upstream. */
228
- ping: { params: zod_1.z.object({}), result: OkResultSchema },
229
- shutdown: { params: zod_1.z.object({}), result: OkResultSchema },
230
- /** Daemon snapshot (B4.6): process, upstream health, hub counters. */
231
- status: { params: zod_1.z.object({}), result: exports.BridgeStatusResultSchema },
232
- // §B1 messaging (outbound)
233
- sendMessage: {
234
- params: restEndpoints_js_1.SendMessageRequestSchema,
235
- // B4.3 additive: the bridge chunks oversized text (core retry/chunking);
236
- // messageId is the FINAL chunk (carries the caller's metadata/turn
237
- // semantics), messageIds lists every part in send order.
238
- result: restEndpoints_js_1.SendMessageResponseSchema.extend({
239
- messageIds: zod_1.z.array(zod_1.z.string()).optional(),
240
- }),
241
- },
242
- sendContextualMessage: {
243
- params: sendContextual_js_1.SendContextualRequestSchema,
244
- result: sendContextual_js_1.SendContextualResponseSchema,
245
- },
246
- reactToMessage: { params: restEndpoints_js_1.ReactRequestSchema, result: restEndpoints_js_1.ReactResponseSchema },
247
- forwardMessage: { params: restEndpoints_js_1.ForwardMessageRequestSchema, result: restEndpoints_js_1.ForwardMessageResponseSchema },
248
- deleteMessage: { params: messageScoped, result: OkResultSchema },
249
- markRead: { params: conversationScoped, result: OkResultSchema },
250
- setDisposition: {
251
- params: messageScoped.extend(restEndpoints_js_1.UpdateDispositionRequestSchema.shape),
252
- result: OkResultSchema,
253
- },
254
- // §B2 reading / history
255
- getMessages: {
256
- params: zod_1.z.object({
257
- conversationId: zod_1.z.string(),
258
- limit: zod_1.z.number().optional(),
259
- before: zod_1.z.string().optional(),
260
- includeBehavior: zod_1.z.boolean().optional(),
261
- }),
262
- // B4.3 additive: nextCursor is the bridge-derived `before` token for the
263
- // next page (oldest returned message id), present when the page filled
264
- // the requested limit. The REST surface itself emits no cursor.
265
- result: restEndpoints_js_1.MessagesPageResponseSchema.extend({
266
- nextCursor: zod_1.z.string().optional(),
267
- }),
268
- },
269
- getConversations: { params: zod_1.z.object({}), result: restEndpoints_js_1.ConversationsResponseSchema },
270
- // §B3 conversation / group management
271
- createConversation: {
272
- params: restEndpoints_js_1.CreateConversationRequestSchema,
273
- result: restEndpoints_js_1.CreateConversationResponseSchema,
274
- },
275
- updateTopic: {
276
- params: conversationScoped.extend({ topic: zod_1.z.string() }),
277
- result: OkResultSchema,
278
- },
279
- updateName: {
280
- params: conversationScoped.extend({ name: zod_1.z.string() }),
281
- result: OkResultSchema,
282
- },
283
- updateAvatar: {
284
- params: conversationScoped.extend({ avatarUrl: zod_1.z.string().nullable().optional() }),
285
- result: OkResultSchema,
286
- },
287
- addMember: {
288
- params: conversationScoped.extend({ userId: zod_1.z.string() }),
289
- result: zod_1.z.union([
290
- zod_1.z.object({ status: zod_1.z.literal('added') }),
291
- zod_1.z.object({ status: zod_1.z.literal('pending'), requestId: zod_1.z.string() }),
292
- ]),
293
- },
294
- removeMember: {
295
- params: conversationScoped.extend({ userId: zod_1.z.string() }),
296
- result: OkResultSchema,
297
- },
298
- leaveConversation: { params: conversationScoped, result: OkResultSchema },
299
- muteConversation: {
300
- params: conversationScoped.extend({ until: zod_1.z.number().optional() }),
301
- result: OkResultSchema,
302
- },
303
- unmuteConversation: { params: conversationScoped, result: OkResultSchema },
304
- hideConversation: { params: conversationScoped, result: OkResultSchema },
305
- // §B4 contacts / admission / blocking
306
- createContactRequest: {
307
- params: restEndpoints_js_1.CreateContactRequestRequestSchema,
308
- result: restEndpoints_js_1.CreateContactRequestResponseSchema,
309
- },
310
- listContacts: { params: zod_1.z.object({}), result: restEndpoints_js_1.ContactsResponseSchema },
311
- getContact: {
312
- params: zod_1.z.object({ contactId: zod_1.z.string() }),
313
- result: restEndpoints_js_1.RestContactSchema.nullable(),
314
- },
315
- removeContact: { params: zod_1.z.object({ contactId: zod_1.z.string() }), result: OkResultSchema },
316
- listContactRequests: {
317
- params: zod_1.z.object({}),
318
- result: zod_1.z.object({ requests: zod_1.z.array(contactRequest_js_1.SerializedContactRequestSchema) }),
319
- },
320
- resolveAdmission: {
321
- params: restEndpoints_js_1.ResolveAdmissionRequestSchema,
322
- result: restEndpoints_js_1.ResolveAdmissionResponseSchema,
323
- },
324
- reachOut: {
325
- // B6.1 additive (P6 openclaw): the optional fields mirror core
326
- // reachOutToCanonContact options — contact-request message, agent
327
- // session config/selection, and SendMessageOptions passthrough — so
328
- // channel adapters keep today's reach-out fidelity through the bridge.
329
- params: zod_1.z.object({
330
- targetId: zod_1.z.string(),
331
- /**
332
- * Optional (B6.1): core reach-out treats a missing text as
333
- * "resolve/open the conversation only" — the openclaw media path
334
- * reaches out first and sends the uploaded attachment separately.
335
- */
336
- text: zod_1.z.string().optional(),
337
- selfContext: zod_1.z.string().optional(),
338
- /** Contact-request message when admission requires approval. */
339
- requestMessage: zod_1.z.string().optional(),
340
- /** Initial agent session config — opaque pass-through. */
341
- sessionConfig: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).nullable().optional(),
342
- /** Same union as the REST send surfaces (incl. mode: 'specific'). */
343
- sessionSelection: restEndpoints_js_1.RestSessionSelectionSchema.optional(),
344
- /** SendMessageOptions passthrough (replyTo, selfContextId, metadata, …). */
345
- sendMessageOptions: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
346
- }),
347
- result: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
348
- },
349
- blockUser: { params: zod_1.z.object({ userId: zod_1.z.string() }), result: OkResultSchema },
350
- unblockUser: { params: zod_1.z.object({ userId: zod_1.z.string() }), result: OkResultSchema },
351
- // §B5 live presence / streaming (bridge throttles internally)
352
- setTyping: {
353
- params: conversationScoped.extend({ state: zod_1.z.enum(['typing', 'thinking', 'clear']) }),
354
- result: OkResultSchema,
355
- },
356
- publishStreaming: {
357
- params: conversationScoped.extend({
358
- turnId: zod_1.z.string().nullable().optional(),
359
- messageId: zod_1.z.string().optional(),
360
- text: zod_1.z.string().optional(),
361
- delta: zod_1.z.string().optional(),
362
- /** TurnOutputBlock[] — opaque pass-through. */
363
- blocks: zod_1.z.array(zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())).optional(),
364
- /**
365
- * Explicit bubble/presentation status override (union of B6.1 openclaw
366
- * + P6 host surface): 'tool' / 'waiting_input' cannot be derived from
367
- * text/blocks. Omitted: the bridge derives thinking/streaming from
368
- * content as before.
369
- */
370
- status: zod_1.z.enum(['thinking', 'streaming', 'tool', 'waiting_input']).optional(),
371
- done: zod_1.z.boolean().optional(),
372
- }),
373
- result: OkResultSchema,
374
- },
375
- clearStreaming: { params: conversationScoped, result: OkResultSchema },
376
- // W2-A4 additive: raw streaming events (bridge owns assembly/cadence/
377
- // keepalive/final/clear). Coexists with the snapshot publishStreaming above.
378
- publishStreamingEvent: {
379
- params: exports.BridgePublishStreamingEventParamsSchema,
380
- result: OkResultSchema,
381
- },
382
- // §B6 runtime presentation (adapter owns content, bridge publishes)
383
- publishRuntimeDescriptor: {
384
- params: zod_1.z.object({
385
- descriptor: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
386
- /**
387
- * B6.1 additive (P6 openclaw): rides into the published /agent-runtime
388
- * payload — hosts and host-mode channel plugins publish hostMode: true
389
- * today and the field is app-visible. Latched for subsequent publishes;
390
- * defaults to false (bridge-adapter split is not a host process).
391
- */
392
- hostMode: zod_1.z.boolean().optional(),
393
- }),
394
- result: OkResultSchema,
395
- },
396
- publishRuntimeStatus: {
397
- // Code-grounded correction (B4.3): RTDB runtime-info lives per
398
- // conversation (/runtime-info/{convoId}/{agentId}), so the publish is
399
- // conversation-scoped. `presentation` carries the remaining
400
- // RuntimeInfoPayload fields (surfaceMode, facts, inventories, notes, …)
401
- // as an opaque pass-through.
402
- params: conversationScoped.extend({
403
- statusItems: zod_1.z.array(zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())).optional(),
404
- presentation: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
405
- }),
406
- result: OkResultSchema,
407
- },
408
- publishTurnState: {
409
- // B6.1 additive (P6 openclaw): the remaining CanonTurnStatePayload
410
- // fields hosts publish today. `completedAt: true` asks the bridge to
411
- // stamp the server timestamp (the RTDB sentinel is bridge-owned).
412
- params: conversationScoped.extend({
413
- turnId: zod_1.z.string().nullable().optional(),
414
- state: turnProtocol_js_1.TurnLifecycleStateSchema,
415
- queueDepth: zod_1.z.number().optional(),
416
- capabilities: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
417
- // Union of B6.1 (openclaw) + P6 host surface — the remaining
418
- // code-grounded TurnStatePayload fields (rtdb-rest.ts).
419
- currentSpeakerId: zod_1.z.string().nullable().optional(),
420
- lastAcceptedIntent: turnProtocol_js_1.DeliveryIntentSchema.nullable().optional(),
421
- activeMessageIds: zod_1.z.array(zod_1.z.string()).optional(),
422
- openedAt: EpochOrServerTimestampSchema.optional(),
423
- turnUpdatedAt: EpochOrServerTimestampSchema.nullable().optional(),
424
- // `true` (B6.1 openclaw) asks the bridge to stamp the server-timestamp
425
- // sentinel; hosts (P6) pass an epoch or the sentinel through directly.
426
- completedAt: zod_1.z
427
- .union([zod_1.z.boolean(), EpochOrServerTimestampSchema])
428
- .nullable()
429
- .optional(),
430
- }),
431
- result: OkResultSchema,
432
- },
433
- clearTurnState: { params: conversationScoped, result: OkResultSchema },
434
- publishActivity: {
435
- params: conversationScoped.extend({
436
- activityItems: zod_1.z.array(zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())),
437
- }),
438
- result: OkResultSchema,
439
- },
440
- clearActivity: {
441
- // B6.1 additive (P6 openclaw): remove activity blocks. `all` wipes the
442
- // conversation's node; `itemIds` removes specific blocks; neither falls
443
- // back to the publisher's terminal-only sweep semantics.
444
- params: conversationScoped.extend({
445
- all: zod_1.z.boolean().optional(),
446
- itemIds: zod_1.z.array(zod_1.z.string()).optional(),
447
- }),
448
- result: OkResultSchema,
449
- },
450
- /** B6.1 additive: clear the per-conversation runtime-info node. */
451
- clearRuntimeStatus: { params: conversationScoped, result: OkResultSchema },
452
- /**
453
- * B6.1 additive: clear /agent-runtime for this identity (preserves
454
- * descriptor-bearing payloads with updatedAt: 0, like hosts do today).
455
- */
456
- clearRuntimeDescriptor: { params: zod_1.z.object({}), result: OkResultSchema },
457
- // §B7 HITL (durable; returns requestId, resolves via onHitlResolved).
458
- //
459
- // P6 host surface (additive): process-executing hosts publish the SAME
460
- // rich records channel runtimes create today (approval cards with
461
- // diff/details/native handles, titled input cards, card ids the runtime
462
- // correlates on). All new fields are optional — the narrow Phase-4 shape
463
- // still parses. `requestId`/`inputId`/`cardId`-style explicit ids become
464
- // the bridge record's requestId so adapters keep their own correlation.
465
- // `responseUserId: null` means "let the server pick a reachable responder"
466
- // (codex cards today); absent keeps the Phase-4 default (agent owner).
467
- requestApproval: {
468
- // B6.1 additive (P6 openclaw): optional approval-card fidelity fields
469
- // (core createRuntimeApprovalRequest passthrough) so native runtime
470
- // approvals keep their tool name, detail rows, correlation handles and
471
- // allow-always affordance through the bridge.
472
- params: conversationScoped.extend({
473
- detail: zod_1.z.string(),
474
- risk: hitl_js_1.HitlApprovalRiskSchema,
475
- category: hitl_js_1.HitlApprovalCategorySchema,
476
- expiresAt: zod_1.z.string().optional(),
477
- approvalId: zod_1.z.string().optional(),
478
- /** Card header tool name; defaults to the category. */
479
- toolName: zod_1.z.string().optional(),
480
- riskLevel: zod_1.z.enum(['normal', 'destructive']).optional(),
481
- details: zod_1.z.array(hitl_js_1.HitlApprovalDetailSchema).optional(),
482
- /** File-change preview (CanonUnifiedDiff) — opaque pass-through. */
483
- diff: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
484
- /** Native runtime correlation handles — opaque pass-through. */
485
- native: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
486
- turnId: zod_1.z.string().optional(),
487
- runtimeId: zod_1.z.string().optional(),
488
- /** Offer the "always allow" session-rule affordance on the card. */
489
- allowSessionRule: zod_1.z.boolean().optional(),
490
- responseUserId: zod_1.z.string().nullable().optional(),
491
- }),
492
- result: hitl_js_1.HitlRequestAcceptedSchema,
493
- },
494
- requestInput: {
495
- params: conversationScoped.extend({
496
- questions: zod_1.z.array(hitl_js_1.HitlInputQuestionSchema),
497
- expiresAt: zod_1.z.string().optional(),
498
- inputId: zod_1.z.string().optional(),
499
- title: zod_1.z.string().optional(),
500
- prompt: zod_1.z.string().optional(),
501
- kind: hitl_js_1.HitlInputKindSchema.optional(),
502
- sensitive: zod_1.z.boolean().optional(),
503
- native: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
504
- turnId: zod_1.z.string().optional(),
505
- responseUserId: zod_1.z.string().nullable().optional(),
506
- }),
507
- result: hitl_js_1.HitlRequestAcceptedSchema,
508
- },
509
- requestCard: {
510
- params: conversationScoped.extend({
511
- /** canon.card.v1 content — opaque pass-through. */
512
- card: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
513
- expiresAt: zod_1.z.string().optional(),
514
- cardId: zod_1.z.string().optional(),
515
- native: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
516
- turnId: zod_1.z.string().optional(),
517
- responseUserId: zod_1.z.string().nullable().optional(),
518
- }),
519
- result: hitl_js_1.HitlRequestAcceptedSchema,
520
- },
521
- getHitlState: {
522
- params: zod_1.z.object({ requestId: zod_1.z.string() }),
523
- result: exports.BridgeHitlStateSchema,
524
- },
525
- cancelHitl: { params: zod_1.z.object({ requestId: zod_1.z.string() }), result: OkResultSchema },
526
- // §B8 media (named schemas above — the bridge + Framework share them)
527
- uploadMedia: {
528
- params: exports.BridgeUploadMediaParamsSchema,
529
- result: restEndpoints_js_1.UploadMediaResponseSchema,
530
- },
531
- getAttachment: {
532
- params: exports.BridgeGetAttachmentParamsSchema,
533
- result: exports.BridgeGetAttachmentResultSchema,
534
- },
535
- // §B9 voice (media stays client↔LiveKit; bridge brokers the token).
536
- // Code-grounded correction (B4.3): every /voice/sessions/:id REST op
537
- // requires the conversationId (body or query) — the session doc lives
538
- // under the conversation — so the session-scoped methods carry it too.
539
- createVoiceSession: {
540
- params: conversationScoped.extend({ targetAgentId: zod_1.z.string().optional() }),
541
- result: zod_1.z.looseObject({ sessionId: zod_1.z.string() }),
542
- },
543
- joinVoiceSession: {
544
- params: zod_1.z.object({ sessionId: zod_1.z.string(), conversationId: zod_1.z.string() }),
545
- result: zod_1.z.looseObject({ url: zod_1.z.string(), token: zod_1.z.string() }),
546
- },
547
- endVoiceSession: {
548
- params: zod_1.z.object({ sessionId: zod_1.z.string(), conversationId: zod_1.z.string() }),
549
- result: OkResultSchema,
550
- },
551
- getVoiceSession: {
552
- params: zod_1.z.object({ sessionId: zod_1.z.string(), conversationId: zod_1.z.string() }),
553
- result: sseEvents_js_1.SseVoiceSessionEventPayloadSchema,
554
- },
555
- // §B10 registration / identity
556
- getAgent: {
557
- params: zod_1.z.object({}),
558
- result: zod_1.z.object({
559
- agentId: zod_1.z.string(),
560
- agentName: zod_1.z.string(),
561
- context: sseEvents_js_1.SseAgentContextPayloadSchema,
562
- }),
563
- },
564
- register: {
565
- params: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
566
- // pollToken (when issued) authorizes subsequent status polls.
567
- result: zod_1.z.object({ requestId: zod_1.z.string(), pollToken: zod_1.z.string().optional() }),
568
- },
569
- getRegistrationStatus: {
570
- // `baseUrl` (B6.1 additive) supports the pre-identity bootstrap: the
571
- // registration statics are unauthenticated, so a stub-identity bridge
572
- // can serve them with an explicit endpoint.
573
- params: zod_1.z.object({
574
- requestId: zod_1.z.string(),
575
- pollToken: zod_1.z.string().optional(),
576
- baseUrl: zod_1.z.string().optional(),
577
- }),
578
- result: zod_1.z.looseObject({ status: zod_1.z.string() }),
579
- },
580
- /**
581
- * Acknowledge one-time API-key delivery after an approved registration
582
- * (POST /agents/status/:id/ack). Best-effort on the wire; failures surface
583
- * as upstream-band errors. Additive union of Phase 5 + P6 openclaw: the
584
- * Hermes port consumed it through the GENERIC Python escape hatch first
585
- * (a bridge-side method addition with zero framework-py release), and
586
- * `baseUrl` (B6.1) supports the wizard's per-call pre-identity bootstrap.
587
- */
588
- ackRegistrationStatus: {
589
- params: zod_1.z.object({
590
- requestId: zod_1.z.string(),
591
- pollToken: zod_1.z.string().optional(),
592
- baseUrl: zod_1.z.string().optional(),
593
- }),
594
- result: OkResultSchema,
595
- },
596
- // §5b host-profile surface (bridge-execution-plan Phase 4 step 5b) —
597
- // additive methods for process-executing (host-mode) adapters, beyond §B.
598
- // Shapes mirror @canonmsg/core host-runtime-wire.ts; runtime payloads are
599
- // opaque pass-through (AgentRuntime).
600
- publishHostAgentRuntime: {
601
- params: zod_1.z.object({
602
- /** Defaults to the hello clientType. */
603
- clientType: zod_1.z.string().optional(),
604
- /** AgentRuntime — opaque pass-through. */
605
- runtime: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
606
- }),
607
- result: OkResultSchema,
608
- },
609
- publishHostSessionSnapshots: {
610
- params: zod_1.z.object({
611
- conversationIds: zod_1.z.array(zod_1.z.string()),
612
- /** Defaults to the hello clientType. */
613
- clientType: zod_1.z.string().optional(),
614
- /** AgentRuntime — opaque pass-through. */
615
- runtime: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
616
- workspaceOptions: zod_1.z.array(zod_1.z.object({ id: zod_1.z.string(), cwd: zod_1.z.string() })).optional(),
617
- defaultCwd: zod_1.z.string().optional(),
618
- extraSessionConfigFields: zod_1.z.array(zod_1.z.string()).optional(),
619
- /** conversationId → live session-config overrides (JSON'd Map). */
620
- liveSessionConfigByConversation: zod_1.z
621
- .record(zod_1.z.string(), zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()))
622
- .optional(),
623
- }),
624
- result: OkResultSchema,
625
- },
626
- // §5b host-profile surface, P6 additions (bridge-execution-plan Phase 6) —
627
- // the remaining RTDB planes the process-executing hosts touched directly
628
- // until now: the per-conversation session-state node, its config read, and
629
- // the terminal clears. Payloads mirror @canonmsg/core rtdb-rest.ts shapes
630
- // as opaque pass-through; the bridge executes them through the core
631
- // runtime-state publisher (hostMode) over its single RTDB handle.
632
- getSessionConfig: {
633
- params: conversationScoped,
634
- /** Raw `/session-config/{convoId}/{agentId}` node; adapters parse locally. */
635
- result: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).nullable(),
636
- },
637
- publishSessionState: {
638
- params: conversationScoped.extend({
639
- /** SessionStatePayload minus updatedAt — opaque pass-through. */
640
- state: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
641
- }),
642
- result: OkResultSchema,
643
- },
644
- clearSessionState: { params: conversationScoped, result: OkResultSchema },
645
- // clearTurnState is defined once under §B6 above (both legs added it; the
646
- // clear is publisher-agnostic so channel adapters and hosts share it).
647
- /**
648
- * Terminal /agent-runtime clear through the HOST publisher. Same RTDB
649
- * effect as §B6.1 clearRuntimeDescriptor (preserve descriptor-bearing
650
- * payloads with updatedAt: 0) — kept as a distinct §5b name because host
651
- * consumers correlate it with the publishHostAgentRuntime plane.
652
- */
653
- clearAgentRuntime: { params: zod_1.z.object({}), result: OkResultSchema },
654
- };
655
- exports.BRIDGE_LOCAL_METHOD_NAMES = Object.keys(exports.BRIDGE_LOCAL_METHODS);
656
- // ── §C Notification registry (bridge → adapter, one-way) ───────────────
657
- exports.BRIDGE_LOCAL_NOTIFICATIONS = {
658
- // §A — connection-scoped, never replayed, no cursor
659
- ready: exports.BridgeReadyNotificationSchema,
660
- connectionState: exports.BridgeConnectionStateNotificationSchema,
661
- // §C1 inbound messages (pre-filtered: deduped, self/control stripped)
662
- onMessage: sseEvents_js_1.SseMessageCreatedPayloadSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
663
- onMessageUpdated: sseEvents_js_1.SseMessageUpdatedPayloadSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
664
- onMessageDeleted: sseEvents_js_1.SseMessageDeletedPayloadSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
665
- onConversationUpdated: sseEvents_js_1.SseConversationUpdatedPayloadSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
666
- // §C2 control (bridge consumed from RTDB — adapters never poll)
667
- onControlSignal: controlSignals_js_1.ControlSignalEventSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
668
- onSessionControl: controlSignals_js_1.ControlSessionEventSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
669
- // §C2 addition (P6, both legs): `/control/.../primitive` runtime command
670
- // dispatch (/status, /compact, …) consumed by the bridge poller — adapters
671
- // (openclaw handlers, codex compact) never poll RTDB themselves.
672
- onControlPrimitive: controlSignals_js_1.ControlPrimitiveEventSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
673
- // §C6 HITL resolution (durable; matches a §B7 requestId)
674
- onHitlResolved: hitl_js_1.HitlResolutionSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
675
- onHitlPending: hitl_js_1.HitlPendingSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
676
- /**
677
- * §C6 addition (P6 host surface): a stripped HITL control-reply message
678
- * (metadata.type approval_reply / plan_approval_reply) that matched NO
679
- * bridge-owned HITL record fans out here instead of being dropped —
680
- * process-executing hosts run reply flows the bridge did not raise
681
- * (claude plan approval is a plain sendMessage + metadata-reply waiter).
682
- * `message` is the serialized Canon message, opaque pass-through.
683
- */
684
- onControlReply: zod_1.z.object({
685
- conversationId: zod_1.z.string(),
686
- message: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
687
- }).extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
688
- // §C3 contacts
689
- onContactChanged: zod_1.z.object({
690
- kind: zod_1.z.enum(['request', 'approved', 'added', 'updated', 'removed']),
691
- contact: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
692
- }).extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
693
- // §C4 typing / presence
694
- onTyping: sseEvents_js_1.SseTypingPayloadSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
695
- onPresence: sseEvents_js_1.SsePresencePayloadSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
696
- // §C5 voice
697
- onVoiceSessionStarted: sseEvents_js_1.SseVoiceSessionEventPayloadSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
698
- onVoiceSessionEnded: sseEvents_js_1.SseVoiceSessionEventPayloadSchema.extend(exports.BRIDGE_EVENT_CURSOR_SHAPE),
699
- };
700
- exports.BRIDGE_LOCAL_NOTIFICATION_NAMES = Object.keys(exports.BRIDGE_LOCAL_NOTIFICATIONS);
701
- /**
702
- * Event family per §C notification, mirroring SSE_EVENT_FAMILY_BY_TYPE.
703
- * `lifecycle` notifications are connection-scoped and delivered to every
704
- * client; family notifications are filtered by `hello.wantFamilies`
705
- * (`wantFamilies: []` = pure-request adapter, no §C events at all).
706
- */
707
- exports.BRIDGE_LOCAL_NOTIFICATION_FAMILIES = {
708
- ready: 'lifecycle',
709
- connectionState: 'lifecycle',
710
- onMessage: 'messages',
711
- onMessageUpdated: 'messages',
712
- onMessageDeleted: 'messages',
713
- onConversationUpdated: 'messages',
714
- onControlSignal: 'runtime_turn',
715
- onSessionControl: 'runtime_turn',
716
- onControlPrimitive: 'runtime_turn',
717
- onHitlResolved: 'runtime_turn',
718
- onHitlPending: 'runtime_turn',
719
- onControlReply: 'runtime_turn',
720
- onContactChanged: 'contacts',
721
- onTyping: 'typing_presence',
722
- onPresence: 'typing_presence',
723
- onVoiceSessionStarted: 'voice',
724
- onVoiceSessionEnded: 'voice',
725
- };
726
- // ── JSON-RPC 2.0 framing ───────────────────────────────────────────────
727
- exports.BridgeRpcIdSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.number()]);
728
- exports.BridgeRpcRequestSchema = zod_1.z.object({
729
- jsonrpc: zod_1.z.literal('2.0'),
730
- id: exports.BridgeRpcIdSchema,
731
- method: zod_1.z.string(),
732
- params: zod_1.z.unknown().optional(),
733
- });
734
- exports.BridgeRpcNotificationSchema = zod_1.z.object({
735
- jsonrpc: zod_1.z.literal('2.0'),
736
- method: zod_1.z.string(),
737
- params: zod_1.z.unknown().optional(),
738
- });
739
- exports.BridgeRpcErrorSchema = zod_1.z.object({
740
- code: zod_1.z.number(),
741
- message: zod_1.z.string(),
742
- data: zod_1.z.unknown().optional(),
743
- });
744
- exports.BridgeRpcResponseSchema = zod_1.z.union([
745
- zod_1.z.object({ jsonrpc: zod_1.z.literal('2.0'), id: exports.BridgeRpcIdSchema, result: zod_1.z.unknown() }),
746
- zod_1.z.object({ jsonrpc: zod_1.z.literal('2.0'), id: exports.BridgeRpcIdSchema.nullable(), error: exports.BridgeRpcErrorSchema }),
747
- ]);