@canonmsg/backend-contracts 1.7.0 → 1.8.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 (192) hide show
  1. package/dist/agentBehaviorPolicy.d.ts +86 -45
  2. package/dist/agentBehaviorPolicy.js +53 -0
  3. package/dist/bridgeLocal.d.ts +1729 -0
  4. package/dist/bridgeLocal.js +673 -0
  5. package/dist/cjs/agentBehaviorPolicy.js +54 -1
  6. package/dist/cjs/bridgeLocal.js +676 -0
  7. package/dist/cjs/contactRequest.js +30 -0
  8. package/dist/cjs/controlSignals.js +44 -0
  9. package/dist/cjs/endpointRegistry.js +264 -0
  10. package/dist/cjs/hitl.js +171 -0
  11. package/dist/cjs/inboundFrame.js +92 -0
  12. package/dist/cjs/index.js +8 -0
  13. package/dist/cjs/media.js +13 -0
  14. package/dist/cjs/message.js +64 -0
  15. package/dist/cjs/restEndpoints.js +220 -0
  16. package/dist/cjs/runtimeCardFields.js +58 -1
  17. package/dist/cjs/sendContextual.js +92 -0
  18. package/dist/cjs/sseEvents.js +298 -0
  19. package/dist/cjs/turnProtocol.js +41 -2
  20. package/dist/contactRequest.d.ts +42 -23
  21. package/dist/contactRequest.js +29 -0
  22. package/dist/controlSignals.d.ts +55 -0
  23. package/dist/controlSignals.js +41 -0
  24. package/dist/endpointRegistry.d.ts +13 -0
  25. package/dist/endpointRegistry.js +261 -0
  26. package/dist/hitl.d.ts +303 -0
  27. package/dist/hitl.js +168 -0
  28. package/dist/inboundFrame.d.ts +229 -0
  29. package/dist/inboundFrame.js +89 -0
  30. package/dist/index.d.ts +8 -0
  31. package/dist/index.js +8 -0
  32. package/dist/media.d.ts +24 -11
  33. package/dist/media.js +12 -0
  34. package/dist/message.d.ts +133 -50
  35. package/dist/message.js +64 -1
  36. package/dist/restEndpoints.d.ts +496 -0
  37. package/dist/restEndpoints.js +217 -0
  38. package/dist/runtimeCardFields.d.ts +112 -39
  39. package/dist/runtimeCardFields.js +57 -0
  40. package/dist/schemas/agent-behavior-settings-record.schema.json +48 -0
  41. package/dist/schemas/bridge-connection-state-notification.schema.json +19 -0
  42. package/dist/schemas/bridge-get-attachment-params.schema.json +24 -0
  43. package/dist/schemas/bridge-get-attachment-result.schema.json +20 -0
  44. package/dist/schemas/bridge-hello-params.schema.json +42 -0
  45. package/dist/schemas/bridge-hello-result.schema.json +105 -0
  46. package/dist/schemas/bridge-hitl-state.schema.json +38 -0
  47. package/dist/schemas/bridge-ok-result.schema.json +15 -0
  48. package/dist/schemas/bridge-ready-notification.schema.json +79 -0
  49. package/dist/schemas/bridge-resync-reason.schema.json +9 -0
  50. package/dist/schemas/bridge-resync.schema.json +18 -0
  51. package/dist/schemas/bridge-rpc-error.schema.json +19 -0
  52. package/dist/schemas/bridge-rpc-id.schema.json +12 -0
  53. package/dist/schemas/bridge-rpc-notification.schema.json +20 -0
  54. package/dist/schemas/bridge-rpc-request.schema.json +31 -0
  55. package/dist/schemas/bridge-rpc-response.schema.json +81 -0
  56. package/dist/schemas/bridge-status-result.schema.json +76 -0
  57. package/dist/schemas/bridge-upload-media-params.schema.json +28 -0
  58. package/dist/schemas/bridge-upstream-state.schema.json +10 -0
  59. package/dist/schemas/contacts-response.schema.json +52 -0
  60. package/dist/schemas/control-channel-key.schema.json +10 -0
  61. package/dist/schemas/control-primitive-event.schema.json +30 -0
  62. package/dist/schemas/control-primitive-map.schema.json +15 -0
  63. package/dist/schemas/control-session-event.schema.json +26 -0
  64. package/dist/schemas/control-session-node.schema.json +11 -0
  65. package/dist/schemas/control-signal-event.schema.json +35 -0
  66. package/dist/schemas/control-signal-node.schema.json +22 -0
  67. package/dist/schemas/control-signal-type.schema.json +10 -0
  68. package/dist/schemas/conversations-response.schema.json +127 -0
  69. package/dist/schemas/create-contact-request-request.schema.json +17 -0
  70. package/dist/schemas/create-contact-request-response.schema.json +51 -0
  71. package/dist/schemas/create-conversation-request.schema.json +82 -0
  72. package/dist/schemas/create-conversation-response.schema.json +29 -0
  73. package/dist/schemas/delete-message-response.schema.json +11 -0
  74. package/dist/schemas/delivery-intent.schema.json +11 -0
  75. package/dist/schemas/forward-message-request.schema.json +25 -0
  76. package/dist/schemas/forward-message-response.schema.json +35 -0
  77. package/dist/schemas/forwarded-from.schema.json +18 -0
  78. package/dist/schemas/get-messages-query.schema.json +17 -0
  79. package/dist/schemas/hitl-approval-category.schema.json +15 -0
  80. package/dist/schemas/hitl-approval-detail.schema.json +21 -0
  81. package/dist/schemas/hitl-approval-outcome-record.schema.json +33 -0
  82. package/dist/schemas/hitl-approval-reply-record.schema.json +57 -0
  83. package/dist/schemas/hitl-approval-request-record.schema.json +105 -0
  84. package/dist/schemas/hitl-approval-risk.schema.json +11 -0
  85. package/dist/schemas/hitl-card-outcome-record.schema.json +48 -0
  86. package/dist/schemas/hitl-card-reply-record.schema.json +46 -0
  87. package/dist/schemas/hitl-card-request-record.schema.json +73 -0
  88. package/dist/schemas/hitl-input-answers.schema.json +23 -0
  89. package/dist/schemas/hitl-input-kind.schema.json +10 -0
  90. package/dist/schemas/hitl-input-outcome-record.schema.json +46 -0
  91. package/dist/schemas/hitl-input-question.schema.json +54 -0
  92. package/dist/schemas/hitl-input-reply-record.schema.json +44 -0
  93. package/dist/schemas/hitl-input-request-record.schema.json +134 -0
  94. package/dist/schemas/hitl-pending.schema.json +31 -0
  95. package/dist/schemas/hitl-request-accepted.schema.json +18 -0
  96. package/dist/schemas/hitl-request-kind.schema.json +10 -0
  97. package/dist/schemas/hitl-resolution-status.schema.json +10 -0
  98. package/dist/schemas/hitl-resolution.schema.json +38 -0
  99. package/dist/schemas/hitl-session-rule.schema.json +32 -0
  100. package/dist/schemas/inbound-disposition.schema.json +13 -0
  101. package/dist/schemas/inbound-frame-attachment-v1.schema.json +94 -0
  102. package/dist/schemas/inbound-frame-contact-card-v1.schema.json +59 -0
  103. package/dist/schemas/inbound-frame-group-context-v1.schema.json +96 -0
  104. package/dist/schemas/inbound-frame-reply-context-v1.schema.json +261 -0
  105. package/dist/schemas/inbound-frame-shape-v1.schema.json +12 -0
  106. package/dist/schemas/inbound-frame-v1.schema.json +506 -0
  107. package/dist/schemas/mark-read-response.schema.json +11 -0
  108. package/dist/schemas/media-attachment-kind.schema.json +11 -0
  109. package/dist/schemas/media-attachment.schema.json +42 -0
  110. package/dist/schemas/messages-page-response.schema.json +290 -0
  111. package/dist/schemas/participation-decision-input.schema.json +44 -0
  112. package/dist/schemas/participation-history-message.schema.json +23 -0
  113. package/dist/schemas/participation-history-snapshot.schema.json +37 -0
  114. package/dist/schemas/participation-style.schema.json +13 -0
  115. package/dist/schemas/react-request.schema.json +22 -0
  116. package/dist/schemas/react-response.schema.json +35 -0
  117. package/dist/schemas/resolve-admission-request.schema.json +30 -0
  118. package/dist/schemas/resolve-admission-response.schema.json +129 -0
  119. package/dist/schemas/resolved-agent-behavior-policy-record.schema.json +81 -0
  120. package/dist/schemas/rest-contact.schema.json +40 -0
  121. package/dist/schemas/rest-conversation.schema.json +115 -0
  122. package/dist/schemas/rest-message.schema.json +252 -0
  123. package/dist/schemas/rest-ok-response.schema.json +11 -0
  124. package/dist/schemas/rest-session-selection.schema.json +40 -0
  125. package/dist/schemas/runtime-card-field-choice.schema.json +23 -0
  126. package/dist/schemas/runtime-card-field-type.schema.json +17 -0
  127. package/dist/schemas/runtime-card-field.schema.json +180 -0
  128. package/dist/schemas/runtime-card-line-item-column-type.schema.json +12 -0
  129. package/dist/schemas/runtime-card-line-item-column.schema.json +74 -0
  130. package/dist/schemas/send-contextual-deferred-response.schema.json +39 -0
  131. package/dist/schemas/send-contextual-messaged-response.schema.json +42 -0
  132. package/dist/schemas/send-contextual-request.schema.json +103 -0
  133. package/dist/schemas/send-contextual-response.schema.json +105 -0
  134. package/dist/schemas/send-contextual-self-context.schema.json +19 -0
  135. package/dist/schemas/send-contextual-state-response.schema.json +24 -0
  136. package/dist/schemas/send-message-request.schema.json +106 -0
  137. package/dist/schemas/send-message-response.schema.json +14 -0
  138. package/dist/schemas/sender-type.schema.json +9 -0
  139. package/dist/schemas/serialize-message-input.schema.json +29 -0
  140. package/dist/schemas/serialized-agent-client-type.schema.json +12 -0
  141. package/dist/schemas/serialized-contact-card.schema.json +65 -0
  142. package/dist/schemas/serialized-contact-request-status.schema.json +11 -0
  143. package/dist/schemas/serialized-contact-request.schema.json +157 -0
  144. package/dist/schemas/serialized-content-type.schema.json +13 -0
  145. package/dist/schemas/serialized-message.schema.json +249 -0
  146. package/dist/schemas/serialized-reactions.schema.json +14 -0
  147. package/dist/schemas/serialized-sender-type.schema.json +9 -0
  148. package/dist/schemas/set-streaming-request.schema.json +67 -0
  149. package/dist/schemas/set-typing-request.schema.json +25 -0
  150. package/dist/schemas/sse-access-policy.schema.json +10 -0
  151. package/dist/schemas/sse-agent-context-payload.schema.json +57 -0
  152. package/dist/schemas/sse-connected-payload.schema.json +18 -0
  153. package/dist/schemas/sse-contact-payload.schema.json +40 -0
  154. package/dist/schemas/sse-contact-removed-payload.schema.json +14 -0
  155. package/dist/schemas/sse-contact-request-payload.schema.json +157 -0
  156. package/dist/schemas/sse-conversation-updated-payload.schema.json +48 -0
  157. package/dist/schemas/sse-error-payload.schema.json +23 -0
  158. package/dist/schemas/sse-event-envelope.schema.json +42 -0
  159. package/dist/schemas/sse-event-family.schema.json +12 -0
  160. package/dist/schemas/sse-event-type.schema.json +28 -0
  161. package/dist/schemas/sse-heartbeat-payload.schema.json +14 -0
  162. package/dist/schemas/sse-membership-change.schema.json +28 -0
  163. package/dist/schemas/sse-message-created-payload.schema.json +414 -0
  164. package/dist/schemas/sse-message-deleted-payload.schema.json +18 -0
  165. package/dist/schemas/sse-message-updated-payload.schema.json +46 -0
  166. package/dist/schemas/sse-presence-payload.schema.json +21 -0
  167. package/dist/schemas/sse-provenance.schema.json +64 -0
  168. package/dist/schemas/sse-replay-expired-payload.schema.json +21 -0
  169. package/dist/schemas/sse-runtime-control-kind.schema.json +13 -0
  170. package/dist/schemas/sse-runtime-control-payload.schema.json +44 -0
  171. package/dist/schemas/sse-runtime-updated-payload.schema.json +78 -0
  172. package/dist/schemas/sse-self-context.schema.json +45 -0
  173. package/dist/schemas/sse-turn-dispatch.schema.json +29 -0
  174. package/dist/schemas/sse-turn-updated-payload.schema.json +33 -0
  175. package/dist/schemas/sse-typing-payload.schema.json +32 -0
  176. package/dist/schemas/sse-voice-session-event-payload.schema.json +170 -0
  177. package/dist/schemas/sse-voice-session.schema.json +157 -0
  178. package/dist/schemas/trigger-decision.schema.json +27 -0
  179. package/dist/schemas/turn-lifecycle-state.schema.json +14 -0
  180. package/dist/schemas/turn-message-semantics.schema.json +10 -0
  181. package/dist/schemas/turn-metadata.schema.json +56 -0
  182. package/dist/schemas/turn-state-like.schema.json +39 -0
  183. package/dist/schemas/update-disposition-request.schema.json +22 -0
  184. package/dist/schemas/upload-media-request.schema.json +25 -0
  185. package/dist/schemas/upload-media-response.schema.json +55 -0
  186. package/dist/sendContextual.d.ts +114 -0
  187. package/dist/sendContextual.js +89 -0
  188. package/dist/sseEvents.d.ts +494 -0
  189. package/dist/sseEvents.js +295 -0
  190. package/dist/turnProtocol.d.ts +91 -24
  191. package/dist/turnProtocol.js +40 -1
  192. package/package.json +8 -5
package/dist/hitl.js ADDED
@@ -0,0 +1,168 @@
1
+ // Wire contract v1 — HITL (human-in-the-loop) request / resolution records.
2
+ //
3
+ // HITL is durable state, not a held request (bridge-local-api.md): the pending
4
+ // request is a persisted record (message metadata + RTDB node with expiresAt),
5
+ // and the resolution arrives later. These schemas ground the three record
6
+ // families as core's hosts publish/consume them today:
7
+ // approval — approval_request / approval_reply / approval_outcome
8
+ // input — runtime_input_request / runtime_input_reply / runtime_input_outcome
9
+ // card — runtime_card_request / runtime_card_reply / runtime_card_outcome
10
+ // plus the unified bridge-level resolution record (§C6 onHitlResolved).
11
+ import { z } from 'zod';
12
+ import { RuntimeCardFieldChoiceSchema } from './runtimeCardFields.js';
13
+ export const HitlRequestKindSchema = z.enum(['approval', 'input', 'card']);
14
+ export const HitlResolutionStatusSchema = z.enum(['submitted', 'cancelled', 'timeout']);
15
+ // ── Approval records ───────────────────────────────────────────────────
16
+ export const HitlApprovalRiskSchema = z.enum(['low', 'normal', 'high', 'destructive']);
17
+ export const HitlApprovalCategorySchema = z.enum([
18
+ 'command',
19
+ 'file',
20
+ 'network',
21
+ 'browser',
22
+ 'mcp',
23
+ 'plugin',
24
+ 'canon',
25
+ 'tool',
26
+ ]);
27
+ export const HitlApprovalDetailSchema = z.object({
28
+ label: z.string(),
29
+ value: z.string(),
30
+ monospace: z.boolean().optional(),
31
+ });
32
+ export const HitlSessionRuleSchema = z.object({
33
+ type: z.enum(['approve-all', 'approve-tool', 'deny-tool']),
34
+ toolPattern: z.string().optional(),
35
+ expiresAt: z.string().nullable().optional(),
36
+ });
37
+ export const HitlApprovalRequestRecordSchema = z.looseObject({
38
+ type: z.literal('approval_request'),
39
+ approvalId: z.string(),
40
+ responseUserId: z.string().optional(),
41
+ toolName: z.string(),
42
+ /** Pre-computed, redacted summary — raw tool input is never stored. */
43
+ toolSummary: z.string(),
44
+ category: HitlApprovalCategorySchema.optional(),
45
+ risk: HitlApprovalRiskSchema.optional(),
46
+ riskLevel: z.enum(['normal', 'destructive']).optional(),
47
+ runtimeId: z.string().optional(),
48
+ turnId: z.string().optional(),
49
+ /** Native runtime correlation handles — opaque pass-through. */
50
+ native: z.record(z.string(), z.unknown()).optional(),
51
+ details: z.array(HitlApprovalDetailSchema).optional(),
52
+ /** File-change preview (CanonUnifiedDiff) — opaque pass-through. */
53
+ diff: z.record(z.string(), z.unknown()).optional(),
54
+ expiresAt: z.string(),
55
+ });
56
+ export const HitlApprovalReplyRecordSchema = z.looseObject({
57
+ type: z.literal('approval_reply'),
58
+ approvalId: z.string(),
59
+ decision: z.enum(['allow', 'deny']),
60
+ sessionRule: HitlSessionRuleSchema.optional(),
61
+ });
62
+ export const HitlApprovalOutcomeRecordSchema = z.looseObject({
63
+ type: z.literal('approval_outcome'),
64
+ approvalId: z.string().optional(),
65
+ decision: z.enum(['allow', 'deny']).optional(),
66
+ reason: z.enum(['replied', 'timeout', 'session-rule']).optional(),
67
+ });
68
+ // ── Input records ──────────────────────────────────────────────────────
69
+ export const HitlInputKindSchema = z.enum(['clarify', 'sudo', 'secret']);
70
+ export const HitlInputQuestionSchema = z.object({
71
+ id: z.string(),
72
+ question: z.string(),
73
+ header: z.string().optional(),
74
+ choices: z.array(RuntimeCardFieldChoiceSchema).optional(),
75
+ allowOther: z.boolean().optional(),
76
+ isSecret: z.boolean().optional(),
77
+ multiSelect: z.boolean().optional(),
78
+ });
79
+ /** questionId → selected/typed answers. */
80
+ export const HitlInputAnswersSchema = z.record(z.string(), z.object({ answers: z.array(z.string()) }));
81
+ export const HitlInputRequestRecordSchema = z.looseObject({
82
+ type: z.literal('runtime_input_request'),
83
+ inputId: z.string(),
84
+ responseUserId: z.string().optional(),
85
+ kind: HitlInputKindSchema,
86
+ prompt: z.string(),
87
+ title: z.string().optional(),
88
+ choices: z.array(RuntimeCardFieldChoiceSchema).optional(),
89
+ questions: z.array(HitlInputQuestionSchema).optional(),
90
+ secretName: z.string().optional(),
91
+ native: z.record(z.string(), z.unknown()).optional(),
92
+ expiresAt: z.string(),
93
+ sensitive: z.boolean().optional(),
94
+ });
95
+ export const HitlInputReplyRecordSchema = z.looseObject({
96
+ type: z.literal('runtime_input_reply'),
97
+ inputId: z.string(),
98
+ kind: HitlInputKindSchema.optional(),
99
+ status: z.enum(['submitted', 'cancelled']),
100
+ answerSummary: z.string().optional(),
101
+ answersSummary: z.string().optional(),
102
+ sensitive: z.boolean().optional(),
103
+ });
104
+ export const HitlInputOutcomeRecordSchema = z.looseObject({
105
+ type: z.literal('runtime_input_outcome'),
106
+ inputId: z.string(),
107
+ kind: HitlInputKindSchema.optional(),
108
+ status: HitlResolutionStatusSchema,
109
+ reason: z.enum(['submitted', 'cancelled', 'timeout', 'expired', 'interrupted']).optional(),
110
+ });
111
+ // ── Card records ───────────────────────────────────────────────────────
112
+ export const HitlCardRequestRecordSchema = z.looseObject({
113
+ type: z.literal('runtime_card_request'),
114
+ cardId: z.string(),
115
+ cardKind: z.string(),
116
+ schemaVersion: z.literal('canon.card.v1'),
117
+ fallbackText: z.string(),
118
+ responseUserId: z.string().optional(),
119
+ expiresAt: z.string(),
120
+ runtimeId: z.string().optional(),
121
+ turnId: z.string().optional(),
122
+ native: z.record(z.string(), z.unknown()).optional(),
123
+ /** True when the card carries an actions block (agent waits for a response). */
124
+ interactive: z.boolean().optional(),
125
+ /** RuntimeCardPreview — opaque pass-through. */
126
+ cardPreview: z.record(z.string(), z.unknown()),
127
+ turnSemantics: z.literal('control'),
128
+ replyBehavior: z.literal('suppress_auto_reply'),
129
+ });
130
+ export const HitlCardReplyRecordSchema = z.looseObject({
131
+ type: z.literal('runtime_card_reply'),
132
+ cardId: z.string(),
133
+ status: z.enum(['submitted', 'cancelled']),
134
+ actionId: z.string().optional(),
135
+ answerSummary: z.string().optional(),
136
+ sensitive: z.boolean().optional(),
137
+ turnSemantics: z.literal('control'),
138
+ replyBehavior: z.literal('suppress_auto_reply'),
139
+ });
140
+ export const HitlCardOutcomeRecordSchema = z.looseObject({
141
+ type: z.literal('runtime_card_outcome'),
142
+ cardId: z.string(),
143
+ status: HitlResolutionStatusSchema,
144
+ reason: z.enum(['submitted', 'cancelled', 'timeout', 'expired', 'interrupted']).optional(),
145
+ turnSemantics: z.literal('control'),
146
+ replyBehavior: z.literal('suppress_auto_reply'),
147
+ });
148
+ // ── Unified bridge-level records (bridge-local-api §B7/§C6) ────────────
149
+ /** Immediate result of requestApproval/requestInput/requestCard. */
150
+ export const HitlRequestAcceptedSchema = z.object({
151
+ requestId: z.string(),
152
+ expiresAt: z.string(),
153
+ });
154
+ /** `onHitlResolved` — matches an earlier requestId. */
155
+ export const HitlResolutionSchema = z.object({
156
+ requestId: z.string(),
157
+ kind: HitlRequestKindSchema.optional(),
158
+ status: HitlResolutionStatusSchema,
159
+ /** Kind-specific answer payload (decision / answers / card action values). */
160
+ answer: z.record(z.string(), z.unknown()).optional(),
161
+ });
162
+ /** `onHitlPending` — replayed on reconnect for still-open requests. */
163
+ export const HitlPendingSchema = z.object({
164
+ requestId: z.string(),
165
+ kind: HitlRequestKindSchema,
166
+ conversationId: z.string(),
167
+ expiresAt: z.string(),
168
+ });
@@ -0,0 +1,229 @@
1
+ import { z } from 'zod';
2
+ export declare const INBOUND_FRAME_SCHEMA_V1: "canon.inbound_frame.v1";
3
+ export declare const InboundFrameShapeV1Schema: z.ZodEnum<{
4
+ unknown: "unknown";
5
+ group: "group";
6
+ direct_owner: "direct_owner";
7
+ direct_human: "direct_human";
8
+ direct_agent: "direct_agent";
9
+ }>;
10
+ export type InboundFrameShapeV1 = z.infer<typeof InboundFrameShapeV1Schema>;
11
+ export declare const InboundFrameAttachmentV1Schema: z.ZodObject<{
12
+ index: z.ZodNumber;
13
+ kind: z.ZodEnum<{
14
+ file: "file";
15
+ image: "image";
16
+ audio: "audio";
17
+ video: "video";
18
+ }>;
19
+ placeholder: z.ZodString;
20
+ fileName: z.ZodNullable<z.ZodString>;
21
+ mimeType: z.ZodNullable<z.ZodString>;
22
+ sizeBytes: z.ZodNullable<z.ZodNumber>;
23
+ width: z.ZodNullable<z.ZodNumber>;
24
+ height: z.ZodNullable<z.ZodNumber>;
25
+ durationMs: z.ZodNullable<z.ZodNumber>;
26
+ }, z.core.$strip>;
27
+ export type InboundFrameAttachmentV1 = z.infer<typeof InboundFrameAttachmentV1Schema>;
28
+ export declare const InboundFrameContactCardV1Schema: z.ZodObject<{
29
+ userId: z.ZodString;
30
+ canonContactId: z.ZodNullable<z.ZodString>;
31
+ displayName: z.ZodString;
32
+ userType: z.ZodEnum<{
33
+ human: "human";
34
+ ai_agent: "ai_agent";
35
+ }>;
36
+ ownerName: z.ZodNullable<z.ZodString>;
37
+ about: z.ZodNullable<z.ZodString>;
38
+ }, z.core.$strip>;
39
+ export type InboundFrameContactCardV1 = z.infer<typeof InboundFrameContactCardV1Schema>;
40
+ /** CanonTurnContextReplyContextV2 — the reply-to summary carried by the frame. */
41
+ export declare const InboundFrameReplyContextV1Schema: z.ZodObject<{
42
+ messageId: z.ZodString;
43
+ found: z.ZodBoolean;
44
+ senderId: z.ZodNullable<z.ZodString>;
45
+ senderName: z.ZodNullable<z.ZodString>;
46
+ senderType: z.ZodNullable<z.ZodEnum<{
47
+ human: "human";
48
+ ai_agent: "ai_agent";
49
+ }>>;
50
+ contentType: z.ZodNullable<z.ZodEnum<{
51
+ file: "file";
52
+ image: "image";
53
+ audio: "audio";
54
+ video: "video";
55
+ text: "text";
56
+ contact_card: "contact_card";
57
+ }>>;
58
+ text: z.ZodNullable<z.ZodString>;
59
+ body: z.ZodString;
60
+ replyToPosition: z.ZodNullable<z.ZodNumber>;
61
+ attachments: z.ZodArray<z.ZodObject<{
62
+ index: z.ZodNumber;
63
+ kind: z.ZodEnum<{
64
+ file: "file";
65
+ image: "image";
66
+ audio: "audio";
67
+ video: "video";
68
+ }>;
69
+ placeholder: z.ZodString;
70
+ fileName: z.ZodNullable<z.ZodString>;
71
+ mimeType: z.ZodNullable<z.ZodString>;
72
+ sizeBytes: z.ZodNullable<z.ZodNumber>;
73
+ width: z.ZodNullable<z.ZodNumber>;
74
+ height: z.ZodNullable<z.ZodNumber>;
75
+ durationMs: z.ZodNullable<z.ZodNumber>;
76
+ }, z.core.$strip>>;
77
+ contactCard: z.ZodNullable<z.ZodObject<{
78
+ userId: z.ZodString;
79
+ canonContactId: z.ZodNullable<z.ZodString>;
80
+ displayName: z.ZodString;
81
+ userType: z.ZodEnum<{
82
+ human: "human";
83
+ ai_agent: "ai_agent";
84
+ }>;
85
+ ownerName: z.ZodNullable<z.ZodString>;
86
+ about: z.ZodNullable<z.ZodString>;
87
+ }, z.core.$strip>>;
88
+ }, z.core.$strip>;
89
+ export type InboundFrameReplyContextV1 = z.infer<typeof InboundFrameReplyContextV1Schema>;
90
+ export declare const InboundFrameGroupContextV1Schema: z.ZodObject<{
91
+ memberCount: z.ZodNumber;
92
+ memberIds: z.ZodArray<z.ZodString>;
93
+ ownerId: z.ZodString;
94
+ ownerName: z.ZodString;
95
+ ownerPresent: z.ZodBoolean;
96
+ knownRecentParticipants: z.ZodArray<z.ZodObject<{
97
+ id: z.ZodString;
98
+ name: z.ZodString;
99
+ userType: z.ZodEnum<{
100
+ human: "human";
101
+ ai_agent: "ai_agent";
102
+ unknown: "unknown";
103
+ }>;
104
+ isOwner: z.ZodBoolean;
105
+ isSelf: z.ZodBoolean;
106
+ }, z.core.$strip>>;
107
+ membershipChange: z.ZodOptional<z.ZodObject<{
108
+ addedMemberIds: z.ZodArray<z.ZodString>;
109
+ removedMemberIds: z.ZodArray<z.ZodString>;
110
+ memberCount: z.ZodNumber;
111
+ }, z.core.$strip>>;
112
+ }, z.core.$strip>;
113
+ export type InboundFrameGroupContextV1 = z.infer<typeof InboundFrameGroupContextV1Schema>;
114
+ export declare const InboundFrameV1Schema: z.ZodObject<{
115
+ schema: z.ZodLiteral<"canon.inbound_frame.v1">;
116
+ shape: z.ZodEnum<{
117
+ unknown: "unknown";
118
+ group: "group";
119
+ direct_owner: "direct_owner";
120
+ direct_human: "direct_human";
121
+ direct_agent: "direct_agent";
122
+ }>;
123
+ sender: z.ZodObject<{
124
+ name: z.ZodString;
125
+ type: z.ZodEnum<{
126
+ human: "human";
127
+ ai_agent: "ai_agent";
128
+ }>;
129
+ isOwner: z.ZodBoolean;
130
+ }, z.core.$strip>;
131
+ conversation: z.ZodObject<{
132
+ type: z.ZodEnum<{
133
+ unknown: "unknown";
134
+ direct: "direct";
135
+ group: "group";
136
+ }>;
137
+ memberCount: z.ZodNullable<z.ZodNumber>;
138
+ }, z.core.$strip>;
139
+ addressed: z.ZodBoolean;
140
+ message: z.ZodObject<{
141
+ text: z.ZodString;
142
+ contentType: z.ZodNullable<z.ZodEnum<{
143
+ file: "file";
144
+ image: "image";
145
+ audio: "audio";
146
+ video: "video";
147
+ text: "text";
148
+ contact_card: "contact_card";
149
+ }>>;
150
+ }, z.core.$strip>;
151
+ replyContext: z.ZodNullable<z.ZodObject<{
152
+ messageId: z.ZodString;
153
+ found: z.ZodBoolean;
154
+ senderId: z.ZodNullable<z.ZodString>;
155
+ senderName: z.ZodNullable<z.ZodString>;
156
+ senderType: z.ZodNullable<z.ZodEnum<{
157
+ human: "human";
158
+ ai_agent: "ai_agent";
159
+ }>>;
160
+ contentType: z.ZodNullable<z.ZodEnum<{
161
+ file: "file";
162
+ image: "image";
163
+ audio: "audio";
164
+ video: "video";
165
+ text: "text";
166
+ contact_card: "contact_card";
167
+ }>>;
168
+ text: z.ZodNullable<z.ZodString>;
169
+ body: z.ZodString;
170
+ replyToPosition: z.ZodNullable<z.ZodNumber>;
171
+ attachments: z.ZodArray<z.ZodObject<{
172
+ index: z.ZodNumber;
173
+ kind: z.ZodEnum<{
174
+ file: "file";
175
+ image: "image";
176
+ audio: "audio";
177
+ video: "video";
178
+ }>;
179
+ placeholder: z.ZodString;
180
+ fileName: z.ZodNullable<z.ZodString>;
181
+ mimeType: z.ZodNullable<z.ZodString>;
182
+ sizeBytes: z.ZodNullable<z.ZodNumber>;
183
+ width: z.ZodNullable<z.ZodNumber>;
184
+ height: z.ZodNullable<z.ZodNumber>;
185
+ durationMs: z.ZodNullable<z.ZodNumber>;
186
+ }, z.core.$strip>>;
187
+ contactCard: z.ZodNullable<z.ZodObject<{
188
+ userId: z.ZodString;
189
+ canonContactId: z.ZodNullable<z.ZodString>;
190
+ displayName: z.ZodString;
191
+ userType: z.ZodEnum<{
192
+ human: "human";
193
+ ai_agent: "ai_agent";
194
+ }>;
195
+ ownerName: z.ZodNullable<z.ZodString>;
196
+ about: z.ZodNullable<z.ZodString>;
197
+ }, z.core.$strip>>;
198
+ }, z.core.$strip>>;
199
+ groupContext: z.ZodNullable<z.ZodObject<{
200
+ memberCount: z.ZodNumber;
201
+ memberIds: z.ZodArray<z.ZodString>;
202
+ ownerId: z.ZodString;
203
+ ownerName: z.ZodString;
204
+ ownerPresent: z.ZodBoolean;
205
+ knownRecentParticipants: z.ZodArray<z.ZodObject<{
206
+ id: z.ZodString;
207
+ name: z.ZodString;
208
+ userType: z.ZodEnum<{
209
+ human: "human";
210
+ ai_agent: "ai_agent";
211
+ unknown: "unknown";
212
+ }>;
213
+ isOwner: z.ZodBoolean;
214
+ isSelf: z.ZodBoolean;
215
+ }, z.core.$strip>>;
216
+ membershipChange: z.ZodOptional<z.ZodObject<{
217
+ addedMemberIds: z.ZodArray<z.ZodString>;
218
+ removedMemberIds: z.ZodArray<z.ZodString>;
219
+ memberCount: z.ZodNumber;
220
+ }, z.core.$strip>>;
221
+ }, z.core.$strip>>;
222
+ groupContextMode: z.ZodOptional<z.ZodEnum<{
223
+ initial: "initial";
224
+ membership_change: "membership_change";
225
+ }>>;
226
+ selfContexts: z.ZodArray<z.ZodString>;
227
+ behaviorInstructions: z.ZodArray<z.ZodString>;
228
+ }, z.core.$strip>;
229
+ export type InboundFrameV1 = z.infer<typeof InboundFrameV1Schema>;
@@ -0,0 +1,89 @@
1
+ // Wire contract v1 — the canon.inbound_frame.v1 schema.
2
+ //
3
+ // Mirrors @canonmsg/core's CanonInboundFrameV1 (core/src/inbound-frame.ts),
4
+ // the structured projection every host/adapter renders its inbound prompt
5
+ // from. core keeps building the frame; a follow-up (post-P2 merge) flips core
6
+ // to infer its type from this schema. A compile-time assignability guard
7
+ // between core's type and this schema lives in @canonmsg/test-fixtures.
8
+ import { z } from 'zod';
9
+ import { SerializedContentTypeSchema } from './message.js';
10
+ import { SseMembershipChangeSchema } from './sseEvents.js';
11
+ export const INBOUND_FRAME_SCHEMA_V1 = 'canon.inbound_frame.v1';
12
+ export const InboundFrameShapeV1Schema = z.enum([
13
+ 'direct_owner',
14
+ 'direct_human',
15
+ 'direct_agent',
16
+ 'group',
17
+ 'unknown',
18
+ ]);
19
+ export const InboundFrameAttachmentV1Schema = z.object({
20
+ index: z.number(),
21
+ kind: z.enum(['image', 'audio', 'video', 'file']),
22
+ placeholder: z.string(),
23
+ fileName: z.string().nullable(),
24
+ mimeType: z.string().nullable(),
25
+ sizeBytes: z.number().nullable(),
26
+ width: z.number().nullable(),
27
+ height: z.number().nullable(),
28
+ durationMs: z.number().nullable(),
29
+ });
30
+ export const InboundFrameContactCardV1Schema = z.object({
31
+ userId: z.string(),
32
+ canonContactId: z.string().nullable(),
33
+ displayName: z.string(),
34
+ userType: z.enum(['human', 'ai_agent']),
35
+ ownerName: z.string().nullable(),
36
+ about: z.string().nullable(),
37
+ });
38
+ /** CanonTurnContextReplyContextV2 — the reply-to summary carried by the frame. */
39
+ export const InboundFrameReplyContextV1Schema = z.object({
40
+ messageId: z.string(),
41
+ found: z.boolean(),
42
+ senderId: z.string().nullable(),
43
+ senderName: z.string().nullable(),
44
+ senderType: z.enum(['human', 'ai_agent']).nullable(),
45
+ contentType: SerializedContentTypeSchema.nullable(),
46
+ text: z.string().nullable(),
47
+ body: z.string(),
48
+ replyToPosition: z.number().nullable(),
49
+ attachments: z.array(InboundFrameAttachmentV1Schema),
50
+ contactCard: InboundFrameContactCardV1Schema.nullable(),
51
+ });
52
+ export const InboundFrameGroupContextV1Schema = z.object({
53
+ memberCount: z.number(),
54
+ memberIds: z.array(z.string()),
55
+ ownerId: z.string(),
56
+ ownerName: z.string(),
57
+ ownerPresent: z.boolean(),
58
+ knownRecentParticipants: z.array(z.object({
59
+ id: z.string(),
60
+ name: z.string(),
61
+ userType: z.enum(['human', 'ai_agent', 'unknown']),
62
+ isOwner: z.boolean(),
63
+ isSelf: z.boolean(),
64
+ })),
65
+ membershipChange: SseMembershipChangeSchema.optional(),
66
+ });
67
+ export const InboundFrameV1Schema = z.object({
68
+ schema: z.literal(INBOUND_FRAME_SCHEMA_V1),
69
+ shape: InboundFrameShapeV1Schema,
70
+ sender: z.object({
71
+ name: z.string(),
72
+ type: z.enum(['human', 'ai_agent']),
73
+ isOwner: z.boolean(),
74
+ }),
75
+ conversation: z.object({
76
+ type: z.enum(['direct', 'group', 'unknown']),
77
+ memberCount: z.number().nullable(),
78
+ }),
79
+ addressed: z.boolean(),
80
+ message: z.object({
81
+ text: z.string(),
82
+ contentType: SerializedContentTypeSchema.nullable(),
83
+ }),
84
+ replyContext: InboundFrameReplyContextV1Schema.nullable(),
85
+ groupContext: InboundFrameGroupContextV1Schema.nullable(),
86
+ groupContextMode: z.enum(['initial', 'membership_change']).optional(),
87
+ selfContexts: z.array(z.string()),
88
+ behaviorInstructions: z.array(z.string()),
89
+ });
package/dist/index.d.ts CHANGED
@@ -5,3 +5,11 @@ export * from './runtimeCardStorage.js';
5
5
  export * from './turnProtocol.js';
6
6
  export * from './agentBehaviorPolicy.js';
7
7
  export * from './contactRequest.js';
8
+ export * from './sseEvents.js';
9
+ export * from './controlSignals.js';
10
+ export * from './hitl.js';
11
+ export * from './inboundFrame.js';
12
+ export * from './restEndpoints.js';
13
+ export * from './sendContextual.js';
14
+ export * from './bridgeLocal.js';
15
+ export * from './endpointRegistry.js';
package/dist/index.js CHANGED
@@ -5,3 +5,11 @@ export * from './runtimeCardStorage.js';
5
5
  export * from './turnProtocol.js';
6
6
  export * from './agentBehaviorPolicy.js';
7
7
  export * from './contactRequest.js';
8
+ export * from './sseEvents.js';
9
+ export * from './controlSignals.js';
10
+ export * from './hitl.js';
11
+ export * from './inboundFrame.js';
12
+ export * from './restEndpoints.js';
13
+ export * from './sendContextual.js';
14
+ export * from './bridgeLocal.js';
15
+ export * from './endpointRegistry.js';
package/dist/media.d.ts CHANGED
@@ -1,14 +1,27 @@
1
- export type MediaAttachmentKind = 'image' | 'audio' | 'video' | 'file';
2
- export interface MediaAttachment {
3
- kind: MediaAttachmentKind;
4
- url: string;
5
- mimeType?: string;
6
- fileName?: string;
7
- sizeBytes?: number;
8
- width?: number;
9
- height?: number;
10
- durationMs?: number;
11
- }
1
+ import { z } from 'zod';
2
+ export declare const MediaAttachmentKindSchema: z.ZodEnum<{
3
+ file: "file";
4
+ image: "image";
5
+ audio: "audio";
6
+ video: "video";
7
+ }>;
8
+ export type MediaAttachmentKind = z.infer<typeof MediaAttachmentKindSchema>;
9
+ export declare const MediaAttachmentSchema: z.ZodObject<{
10
+ kind: z.ZodEnum<{
11
+ file: "file";
12
+ image: "image";
13
+ audio: "audio";
14
+ video: "video";
15
+ }>;
16
+ url: z.ZodString;
17
+ mimeType: z.ZodOptional<z.ZodString>;
18
+ fileName: z.ZodOptional<z.ZodString>;
19
+ sizeBytes: z.ZodOptional<z.ZodNumber>;
20
+ width: z.ZodOptional<z.ZodNumber>;
21
+ height: z.ZodOptional<z.ZodNumber>;
22
+ durationMs: z.ZodOptional<z.ZodNumber>;
23
+ }, z.core.$strip>;
24
+ export type MediaAttachment = z.infer<typeof MediaAttachmentSchema>;
12
25
  export declare function inferMediaAttachmentKind(mimeType: string): MediaAttachmentKind;
13
26
  export declare function getStoredFileExtension(input: {
14
27
  mimeType?: string | null;
package/dist/media.js CHANGED
@@ -1,3 +1,15 @@
1
+ import { z } from 'zod';
2
+ export const MediaAttachmentKindSchema = z.enum(['image', 'audio', 'video', 'file']);
3
+ export const MediaAttachmentSchema = z.object({
4
+ kind: MediaAttachmentKindSchema,
5
+ url: z.string(),
6
+ mimeType: z.string().optional(),
7
+ fileName: z.string().optional(),
8
+ sizeBytes: z.number().optional(),
9
+ width: z.number().optional(),
10
+ height: z.number().optional(),
11
+ durationMs: z.number().optional(),
12
+ });
1
13
  export function inferMediaAttachmentKind(mimeType) {
2
14
  if (mimeType.startsWith('image/'))
3
15
  return 'image';