@canonmsg/backend-contracts 1.9.0 → 2.1.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.
- package/dist/agentBehaviorPolicy.d.ts +45 -86
- package/dist/agentBehaviorPolicy.js +0 -53
- package/dist/cjs/agentBehaviorPolicy.js +1 -54
- package/dist/cjs/contactRequest.js +0 -30
- package/dist/cjs/diffRedaction.js +73 -0
- package/dist/cjs/index.js +1 -8
- package/dist/cjs/media.js +0 -13
- package/dist/cjs/message.js +44 -65
- package/dist/cjs/runtimeCardFields.js +1 -58
- package/dist/cjs/turnProtocol.js +1 -41
- package/dist/contactRequest.d.ts +23 -42
- package/dist/contactRequest.js +0 -29
- package/dist/diffRedaction.d.ts +6 -0
- package/dist/diffRedaction.js +68 -0
- package/dist/index.d.ts +1 -8
- package/dist/index.js +1 -8
- package/dist/media.d.ts +11 -24
- package/dist/media.js +0 -12
- package/dist/message.d.ts +79 -132
- package/dist/message.js +45 -65
- package/dist/runtimeCardFields.d.ts +39 -112
- package/dist/runtimeCardFields.js +0 -57
- package/dist/turnProtocol.d.ts +24 -91
- package/dist/turnProtocol.js +0 -40
- package/package.json +5 -8
- package/dist/bridgeLocal.d.ts +0 -1871
- package/dist/bridgeLocal.js +0 -744
- package/dist/cjs/bridgeLocal.js +0 -747
- package/dist/cjs/controlSignals.js +0 -44
- package/dist/cjs/endpointRegistry.js +0 -264
- package/dist/cjs/hitl.js +0 -171
- package/dist/cjs/inboundFrame.js +0 -92
- package/dist/cjs/restEndpoints.js +0 -237
- package/dist/cjs/sendContextual.js +0 -92
- package/dist/cjs/sseEvents.js +0 -281
- package/dist/controlSignals.d.ts +0 -55
- package/dist/controlSignals.js +0 -41
- package/dist/endpointRegistry.d.ts +0 -13
- package/dist/endpointRegistry.js +0 -261
- package/dist/hitl.d.ts +0 -303
- package/dist/hitl.js +0 -168
- package/dist/inboundFrame.d.ts +0 -229
- package/dist/inboundFrame.js +0 -89
- package/dist/restEndpoints.d.ts +0 -531
- package/dist/restEndpoints.js +0 -234
- package/dist/schemas/agent-behavior-settings-record.schema.json +0 -48
- package/dist/schemas/bridge-connection-state-notification.schema.json +0 -19
- package/dist/schemas/bridge-get-attachment-params.schema.json +0 -24
- package/dist/schemas/bridge-get-attachment-result.schema.json +0 -20
- package/dist/schemas/bridge-hello-params.schema.json +0 -42
- package/dist/schemas/bridge-hello-result.schema.json +0 -105
- package/dist/schemas/bridge-hitl-state.schema.json +0 -38
- package/dist/schemas/bridge-ok-result.schema.json +0 -15
- package/dist/schemas/bridge-publish-streaming-event-params.schema.json +0 -138
- package/dist/schemas/bridge-ready-notification.schema.json +0 -79
- package/dist/schemas/bridge-resync-reason.schema.json +0 -9
- package/dist/schemas/bridge-resync.schema.json +0 -18
- package/dist/schemas/bridge-rpc-error.schema.json +0 -19
- package/dist/schemas/bridge-rpc-id.schema.json +0 -12
- package/dist/schemas/bridge-rpc-notification.schema.json +0 -20
- package/dist/schemas/bridge-rpc-request.schema.json +0 -31
- package/dist/schemas/bridge-rpc-response.schema.json +0 -81
- package/dist/schemas/bridge-status-result.schema.json +0 -76
- package/dist/schemas/bridge-stream-clear-event.schema.json +0 -15
- package/dist/schemas/bridge-stream-event.schema.json +0 -112
- package/dist/schemas/bridge-stream-final-event.schema.json +0 -19
- package/dist/schemas/bridge-stream-text-event.schema.json +0 -31
- package/dist/schemas/bridge-stream-thinking-event.schema.json +0 -15
- package/dist/schemas/bridge-stream-tool-event.schema.json +0 -36
- package/dist/schemas/bridge-upload-media-params.schema.json +0 -28
- package/dist/schemas/bridge-upstream-state.schema.json +0 -10
- package/dist/schemas/contacts-response.schema.json +0 -52
- package/dist/schemas/control-channel-key.schema.json +0 -10
- package/dist/schemas/control-primitive-event.schema.json +0 -30
- package/dist/schemas/control-primitive-map.schema.json +0 -15
- package/dist/schemas/control-session-event.schema.json +0 -26
- package/dist/schemas/control-session-node.schema.json +0 -11
- package/dist/schemas/control-signal-event.schema.json +0 -35
- package/dist/schemas/control-signal-node.schema.json +0 -22
- package/dist/schemas/control-signal-type.schema.json +0 -10
- package/dist/schemas/conversations-response.schema.json +0 -167
- package/dist/schemas/create-contact-request-request.schema.json +0 -17
- package/dist/schemas/create-contact-request-response.schema.json +0 -51
- package/dist/schemas/create-conversation-request.schema.json +0 -82
- package/dist/schemas/create-conversation-response.schema.json +0 -29
- package/dist/schemas/delete-message-response.schema.json +0 -11
- package/dist/schemas/delivery-intent.schema.json +0 -11
- package/dist/schemas/forward-message-request.schema.json +0 -25
- package/dist/schemas/forward-message-response.schema.json +0 -35
- package/dist/schemas/forwarded-from.schema.json +0 -18
- package/dist/schemas/get-messages-query.schema.json +0 -17
- package/dist/schemas/hitl-approval-category.schema.json +0 -15
- package/dist/schemas/hitl-approval-detail.schema.json +0 -21
- package/dist/schemas/hitl-approval-outcome-record.schema.json +0 -33
- package/dist/schemas/hitl-approval-reply-record.schema.json +0 -57
- package/dist/schemas/hitl-approval-request-record.schema.json +0 -105
- package/dist/schemas/hitl-approval-risk.schema.json +0 -11
- package/dist/schemas/hitl-card-outcome-record.schema.json +0 -48
- package/dist/schemas/hitl-card-reply-record.schema.json +0 -46
- package/dist/schemas/hitl-card-request-record.schema.json +0 -73
- package/dist/schemas/hitl-input-answers.schema.json +0 -23
- package/dist/schemas/hitl-input-kind.schema.json +0 -10
- package/dist/schemas/hitl-input-outcome-record.schema.json +0 -46
- package/dist/schemas/hitl-input-question.schema.json +0 -54
- package/dist/schemas/hitl-input-reply-record.schema.json +0 -44
- package/dist/schemas/hitl-input-request-record.schema.json +0 -134
- package/dist/schemas/hitl-pending.schema.json +0 -31
- package/dist/schemas/hitl-request-accepted.schema.json +0 -18
- package/dist/schemas/hitl-request-kind.schema.json +0 -10
- package/dist/schemas/hitl-resolution-status.schema.json +0 -10
- package/dist/schemas/hitl-resolution.schema.json +0 -38
- package/dist/schemas/hitl-session-rule.schema.json +0 -32
- package/dist/schemas/inbound-disposition.schema.json +0 -13
- package/dist/schemas/inbound-frame-attachment-v1.schema.json +0 -94
- package/dist/schemas/inbound-frame-contact-card-v1.schema.json +0 -59
- package/dist/schemas/inbound-frame-group-context-v1.schema.json +0 -96
- package/dist/schemas/inbound-frame-reply-context-v1.schema.json +0 -261
- package/dist/schemas/inbound-frame-shape-v1.schema.json +0 -12
- package/dist/schemas/inbound-frame-v1.schema.json +0 -506
- package/dist/schemas/mark-read-response.schema.json +0 -11
- package/dist/schemas/media-attachment-kind.schema.json +0 -11
- package/dist/schemas/media-attachment.schema.json +0 -42
- package/dist/schemas/messages-page-response.schema.json +0 -290
- package/dist/schemas/participation-decision-input.schema.json +0 -44
- package/dist/schemas/participation-history-message.schema.json +0 -23
- package/dist/schemas/participation-history-snapshot.schema.json +0 -37
- package/dist/schemas/participation-style.schema.json +0 -13
- package/dist/schemas/react-request.schema.json +0 -22
- package/dist/schemas/react-response.schema.json +0 -35
- package/dist/schemas/resolve-admission-request.schema.json +0 -30
- package/dist/schemas/resolve-admission-response.schema.json +0 -129
- package/dist/schemas/resolved-agent-behavior-policy-record.schema.json +0 -81
- package/dist/schemas/rest-contact.schema.json +0 -40
- package/dist/schemas/rest-conversation-last-message.schema.json +0 -77
- package/dist/schemas/rest-conversation.schema.json +0 -155
- package/dist/schemas/rest-message.schema.json +0 -252
- package/dist/schemas/rest-ok-response.schema.json +0 -11
- package/dist/schemas/rest-session-selection.schema.json +0 -40
- package/dist/schemas/runtime-card-field-choice.schema.json +0 -23
- package/dist/schemas/runtime-card-field-type.schema.json +0 -17
- package/dist/schemas/runtime-card-field.schema.json +0 -180
- package/dist/schemas/runtime-card-line-item-column-type.schema.json +0 -12
- package/dist/schemas/runtime-card-line-item-column.schema.json +0 -74
- package/dist/schemas/send-contextual-deferred-response.schema.json +0 -39
- package/dist/schemas/send-contextual-messaged-response.schema.json +0 -42
- package/dist/schemas/send-contextual-request.schema.json +0 -103
- package/dist/schemas/send-contextual-response.schema.json +0 -105
- package/dist/schemas/send-contextual-self-context.schema.json +0 -19
- package/dist/schemas/send-contextual-state-response.schema.json +0 -24
- package/dist/schemas/send-message-request.schema.json +0 -106
- package/dist/schemas/send-message-response.schema.json +0 -14
- package/dist/schemas/sender-type.schema.json +0 -9
- package/dist/schemas/serialize-message-input.schema.json +0 -29
- package/dist/schemas/serialized-agent-client-type.schema.json +0 -12
- package/dist/schemas/serialized-contact-card.schema.json +0 -65
- package/dist/schemas/serialized-contact-request-status.schema.json +0 -11
- package/dist/schemas/serialized-contact-request.schema.json +0 -157
- package/dist/schemas/serialized-content-type.schema.json +0 -13
- package/dist/schemas/serialized-message.schema.json +0 -249
- package/dist/schemas/serialized-reactions.schema.json +0 -14
- package/dist/schemas/serialized-sender-type.schema.json +0 -9
- package/dist/schemas/set-streaming-request.schema.json +0 -67
- package/dist/schemas/set-typing-request.schema.json +0 -25
- package/dist/schemas/sse-access-policy.schema.json +0 -10
- package/dist/schemas/sse-agent-context-payload.schema.json +0 -57
- package/dist/schemas/sse-connected-payload.schema.json +0 -18
- package/dist/schemas/sse-contact-payload.schema.json +0 -40
- package/dist/schemas/sse-contact-removed-payload.schema.json +0 -14
- package/dist/schemas/sse-contact-request-payload.schema.json +0 -157
- package/dist/schemas/sse-conversation-updated-payload.schema.json +0 -48
- package/dist/schemas/sse-error-payload.schema.json +0 -23
- package/dist/schemas/sse-event-envelope.schema.json +0 -40
- package/dist/schemas/sse-event-family.schema.json +0 -12
- package/dist/schemas/sse-event-type.schema.json +0 -26
- package/dist/schemas/sse-heartbeat-payload.schema.json +0 -14
- package/dist/schemas/sse-membership-change.schema.json +0 -28
- package/dist/schemas/sse-message-created-payload.schema.json +0 -414
- package/dist/schemas/sse-message-deleted-payload.schema.json +0 -18
- package/dist/schemas/sse-message-updated-payload.schema.json +0 -46
- package/dist/schemas/sse-presence-payload.schema.json +0 -21
- package/dist/schemas/sse-provenance.schema.json +0 -64
- package/dist/schemas/sse-replay-expired-payload.schema.json +0 -21
- package/dist/schemas/sse-runtime-control-kind.schema.json +0 -13
- package/dist/schemas/sse-runtime-control-payload.schema.json +0 -44
- package/dist/schemas/sse-self-context.schema.json +0 -45
- package/dist/schemas/sse-turn-dispatch.schema.json +0 -29
- package/dist/schemas/sse-typing-payload.schema.json +0 -32
- package/dist/schemas/sse-voice-session-event-payload.schema.json +0 -170
- package/dist/schemas/sse-voice-session.schema.json +0 -157
- package/dist/schemas/trigger-decision.schema.json +0 -27
- package/dist/schemas/turn-lifecycle-state.schema.json +0 -14
- package/dist/schemas/turn-message-semantics.schema.json +0 -10
- package/dist/schemas/turn-metadata.schema.json +0 -56
- package/dist/schemas/turn-state-like.schema.json +0 -39
- package/dist/schemas/update-disposition-request.schema.json +0 -22
- package/dist/schemas/upload-media-request.schema.json +0 -25
- package/dist/schemas/upload-media-response.schema.json +0 -55
- package/dist/sendContextual.d.ts +0 -114
- package/dist/sendContextual.js +0 -89
- package/dist/sseEvents.d.ts +0 -474
- package/dist/sseEvents.js +0 -278
package/dist/sseEvents.js
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
// Wire contract v1 — SSE event envelope + per-family payload schemas.
|
|
2
|
-
//
|
|
3
|
-
// Grounded in what stream-service ACTUALLY emits (stream-service/src/stream.ts
|
|
4
|
-
// + listeners.ts) and what @canonmsg/core's CanonStream consumes — not in
|
|
5
|
-
// design-doc prose. Payload slots that stream-service passes through opaquely
|
|
6
|
-
// (behavior policies, runtime snapshots, raw RTDB values) stay loose objects;
|
|
7
|
-
// slots stream-service constructs field-by-field are closed.
|
|
8
|
-
//
|
|
9
|
-
// The golden fixtures in @canonmsg/test-fixtures parse under these schemas;
|
|
10
|
-
// the future Python framework must pass the same fixtures.
|
|
11
|
-
import { z } from 'zod';
|
|
12
|
-
import { SerializedContactRequestSchema } from './contactRequest.js';
|
|
13
|
-
import { SerializedMessageSchema, SerializedReactionsSchema } from './message.js';
|
|
14
|
-
export const SseAccessPolicySchema = z.enum(['open', 'approval-required', 'owner-only']);
|
|
15
|
-
// ── Lifecycle events ───────────────────────────────────────────────────
|
|
16
|
-
export const SseConnectedPayloadSchema = z.object({
|
|
17
|
-
connectionId: z.string(),
|
|
18
|
-
agentId: z.string(),
|
|
19
|
-
});
|
|
20
|
-
/** Trusted, server-injected identity & access info (stream.ts `agent.context`). */
|
|
21
|
-
export const SseAgentContextPayloadSchema = z.looseObject({
|
|
22
|
-
agentId: z.string(),
|
|
23
|
-
canonContactId: z.string().optional(),
|
|
24
|
-
clientType: z.string().optional(),
|
|
25
|
-
ownerId: z.string(),
|
|
26
|
-
ownerName: z.string(),
|
|
27
|
-
/** Resolved agent behavior policy — passed through opaquely. */
|
|
28
|
-
defaultBehavior: z.record(z.string(), z.unknown()).optional(),
|
|
29
|
-
inboundPolicy: SseAccessPolicySchema,
|
|
30
|
-
groupJoinPolicy: SseAccessPolicySchema,
|
|
31
|
-
discoverable: z.boolean(),
|
|
32
|
-
});
|
|
33
|
-
export const SseHeartbeatPayloadSchema = z.object({
|
|
34
|
-
timestamp: z.string(),
|
|
35
|
-
});
|
|
36
|
-
export const SseReplayExpiredPayloadSchema = z.looseObject({
|
|
37
|
-
lastAvailableId: z.string().nullable().optional(),
|
|
38
|
-
message: z.string().optional(),
|
|
39
|
-
});
|
|
40
|
-
export const SseErrorPayloadSchema = z.looseObject({
|
|
41
|
-
code: z.string().optional(),
|
|
42
|
-
message: z.string().optional(),
|
|
43
|
-
retryAfterMs: z.number().optional(),
|
|
44
|
-
activeConnections: z.number().optional(),
|
|
45
|
-
maxConnections: z.number().optional(),
|
|
46
|
-
});
|
|
47
|
-
// ── Messages family ────────────────────────────────────────────────────
|
|
48
|
-
export const SseSelfContextSchema = z.object({
|
|
49
|
-
id: z.string(),
|
|
50
|
-
type: z.literal('cross_session'),
|
|
51
|
-
context: z.string(),
|
|
52
|
-
createdAt: z.string().nullable(),
|
|
53
|
-
updatedAt: z.string().nullable(),
|
|
54
|
-
});
|
|
55
|
-
export const SseTurnDispatchSchema = z.looseObject({
|
|
56
|
-
kind: z.enum(['run_turn', 'observe_only']),
|
|
57
|
-
reason: z.string(),
|
|
58
|
-
addressed: z.boolean(),
|
|
59
|
-
policyVersion: z.string().optional(),
|
|
60
|
-
});
|
|
61
|
-
export const SseProvenanceSchema = z.looseObject({
|
|
62
|
-
conversation: z.looseObject({
|
|
63
|
-
id: z.string(),
|
|
64
|
-
type: z.enum(['direct', 'group', 'unknown']),
|
|
65
|
-
}),
|
|
66
|
-
sender: z.looseObject({
|
|
67
|
-
id: z.string(),
|
|
68
|
-
name: z.string().optional(),
|
|
69
|
-
type: z.enum(['human', 'ai_agent']),
|
|
70
|
-
isOwner: z.boolean(),
|
|
71
|
-
}),
|
|
72
|
-
mentionedAgent: z.boolean(),
|
|
73
|
-
});
|
|
74
|
-
/**
|
|
75
|
-
* `message.created` — the inbound message envelope. `message` is exactly the
|
|
76
|
-
* SerializedMessage the shared serializer emits (the E2EE S1 slot).
|
|
77
|
-
*/
|
|
78
|
-
export const SseMessageCreatedPayloadSchema = z.looseObject({
|
|
79
|
-
conversationId: z.string(),
|
|
80
|
-
/** Resolved agent behavior policy — passed through opaquely. */
|
|
81
|
-
behavior: z.record(z.string(), z.unknown()).optional(),
|
|
82
|
-
activeSelfContextId: z.string().nullable().optional(),
|
|
83
|
-
selfContexts: z.array(SseSelfContextSchema).optional(),
|
|
84
|
-
provenance: SseProvenanceSchema.optional(),
|
|
85
|
-
turnDispatch: SseTurnDispatchSchema.optional(),
|
|
86
|
-
message: SerializedMessageSchema,
|
|
87
|
-
});
|
|
88
|
-
export const SseMessageUpdatedPayloadSchema = z.object({
|
|
89
|
-
conversationId: z.string(),
|
|
90
|
-
messageId: z.string(),
|
|
91
|
-
actorId: z.string().optional(),
|
|
92
|
-
updatedAt: z.string().optional(),
|
|
93
|
-
changes: z.looseObject({
|
|
94
|
-
reactions: SerializedReactionsSchema,
|
|
95
|
-
}),
|
|
96
|
-
});
|
|
97
|
-
export const SseMessageDeletedPayloadSchema = z.object({
|
|
98
|
-
conversationId: z.string(),
|
|
99
|
-
messageId: z.string(),
|
|
100
|
-
});
|
|
101
|
-
export const SseMembershipChangeSchema = z.object({
|
|
102
|
-
addedMemberIds: z.array(z.string()),
|
|
103
|
-
removedMemberIds: z.array(z.string()),
|
|
104
|
-
memberCount: z.number(),
|
|
105
|
-
});
|
|
106
|
-
export const SseConversationUpdatedPayloadSchema = z.object({
|
|
107
|
-
conversationId: z.string(),
|
|
108
|
-
changes: z.record(z.string(), z.unknown()),
|
|
109
|
-
membershipChange: SseMembershipChangeSchema.optional(),
|
|
110
|
-
});
|
|
111
|
-
// ── Contacts family ────────────────────────────────────────────────────
|
|
112
|
-
/** `contact.request` / `contact.approved` carry the serialized contact request. */
|
|
113
|
-
export const SseContactRequestPayloadSchema = SerializedContactRequestSchema;
|
|
114
|
-
/**
|
|
115
|
-
* `contact.added` / `contact.updated`. `source` is a pass-through string —
|
|
116
|
-
* canonical values today: direct_add, phone_book, contact_request, link, qr,
|
|
117
|
-
* group, open_inbound_message, unknown.
|
|
118
|
-
*/
|
|
119
|
-
export const SseContactPayloadSchema = z.object({
|
|
120
|
-
id: z.string(),
|
|
121
|
-
source: z.string(),
|
|
122
|
-
addedAt: z.string().nullable(),
|
|
123
|
-
displayNameOverride: z.string().nullable(),
|
|
124
|
-
});
|
|
125
|
-
export const SseContactRemovedPayloadSchema = z.object({
|
|
126
|
-
id: z.string(),
|
|
127
|
-
});
|
|
128
|
-
// ── Typing / presence family ───────────────────────────────────────────
|
|
129
|
-
export const SseTypingPayloadSchema = z.object({
|
|
130
|
-
conversationId: z.string(),
|
|
131
|
-
userId: z.string(),
|
|
132
|
-
isTyping: z.boolean(),
|
|
133
|
-
status: z.enum(['thinking', 'typing']).optional(),
|
|
134
|
-
timestamp: z.number().optional(),
|
|
135
|
-
});
|
|
136
|
-
export const SsePresencePayloadSchema = z.object({
|
|
137
|
-
userId: z.string(),
|
|
138
|
-
online: z.boolean(),
|
|
139
|
-
lastSeen: z.string().optional(),
|
|
140
|
-
});
|
|
141
|
-
// ── Runtime / turn family ──────────────────────────────────────────────
|
|
142
|
-
// `runtime.updated` / `turn.updated` were retired 2026-07 (zero consumers;
|
|
143
|
-
// the bridge reads RTDB directly). `runtime.control` remains — it is the
|
|
144
|
-
// planned event-push control transport (housecleaning plan §6 W2-A2).
|
|
145
|
-
export const SseRuntimeControlKindSchema = z.enum([
|
|
146
|
-
'session',
|
|
147
|
-
'signal',
|
|
148
|
-
'primitive',
|
|
149
|
-
'runtimeInput',
|
|
150
|
-
'runtimeCard',
|
|
151
|
-
'runtimeApproval',
|
|
152
|
-
]);
|
|
153
|
-
export const SseRuntimeControlPayloadSchema = z.object({
|
|
154
|
-
conversationId: z.string(),
|
|
155
|
-
agentId: z.string(),
|
|
156
|
-
kind: SseRuntimeControlKindSchema,
|
|
157
|
-
requestId: z.string().optional(),
|
|
158
|
-
updatedAt: z.number().optional(),
|
|
159
|
-
value: z.record(z.string(), z.unknown()),
|
|
160
|
-
});
|
|
161
|
-
// ── Voice family ───────────────────────────────────────────────────────
|
|
162
|
-
export const SseVoiceSessionSchema = z.looseObject({
|
|
163
|
-
id: z.string(),
|
|
164
|
-
conversationId: z.string(),
|
|
165
|
-
roomName: z.string(),
|
|
166
|
-
mode: z.enum(['human', 'runtime_voice']),
|
|
167
|
-
status: z.enum(['active', 'ended', 'error']),
|
|
168
|
-
createdBy: z.string(),
|
|
169
|
-
participantIds: z.array(z.string()),
|
|
170
|
-
participants: z.array(z.looseObject({
|
|
171
|
-
userId: z.string(),
|
|
172
|
-
userType: z.enum(['human', 'ai_agent', 'system']),
|
|
173
|
-
displayName: z.string().nullable(),
|
|
174
|
-
joinedAt: z.string().nullable(),
|
|
175
|
-
leftAt: z.string().nullable(),
|
|
176
|
-
})).optional(),
|
|
177
|
-
targetAgentId: z.string().nullable().optional(),
|
|
178
|
-
createdAt: z.string().nullable().optional(),
|
|
179
|
-
updatedAt: z.string().nullable().optional(),
|
|
180
|
-
endedAt: z.string().nullable().optional(),
|
|
181
|
-
error: z.string().nullable().optional(),
|
|
182
|
-
});
|
|
183
|
-
export const SseVoiceSessionEventPayloadSchema = z.object({
|
|
184
|
-
conversationId: z.string(),
|
|
185
|
-
session: SseVoiceSessionSchema,
|
|
186
|
-
});
|
|
187
|
-
// ── Envelope + registry ────────────────────────────────────────────────
|
|
188
|
-
/**
|
|
189
|
-
* Every SSE `event:` name stream-service emits today (stream.ts + listeners.ts;
|
|
190
|
-
* mirrored by CanonStream's dispatch switch in core). NOTE: `contact.updated`
|
|
191
|
-
* is emitted by stream-service but not yet consumed by CanonStream.
|
|
192
|
-
*/
|
|
193
|
-
export const SSE_EVENT_TYPES = [
|
|
194
|
-
'connected',
|
|
195
|
-
'agent.context',
|
|
196
|
-
'heartbeat',
|
|
197
|
-
'message.created',
|
|
198
|
-
'message.updated',
|
|
199
|
-
'message.deleted',
|
|
200
|
-
'conversation.updated',
|
|
201
|
-
'contact.request',
|
|
202
|
-
'contact.approved',
|
|
203
|
-
'contact.added',
|
|
204
|
-
'contact.updated',
|
|
205
|
-
'contact.removed',
|
|
206
|
-
'typing',
|
|
207
|
-
'presence',
|
|
208
|
-
'runtime.control',
|
|
209
|
-
'voice.session.started',
|
|
210
|
-
'voice.session.ended',
|
|
211
|
-
'replay.expired',
|
|
212
|
-
'error',
|
|
213
|
-
];
|
|
214
|
-
export const SseEventTypeSchema = z.enum(SSE_EVENT_TYPES);
|
|
215
|
-
/** Payload schema for every event type — the machine-readable event registry. */
|
|
216
|
-
export const SSE_EVENT_PAYLOAD_SCHEMAS = {
|
|
217
|
-
'connected': SseConnectedPayloadSchema,
|
|
218
|
-
'agent.context': SseAgentContextPayloadSchema,
|
|
219
|
-
'heartbeat': SseHeartbeatPayloadSchema,
|
|
220
|
-
'message.created': SseMessageCreatedPayloadSchema,
|
|
221
|
-
'message.updated': SseMessageUpdatedPayloadSchema,
|
|
222
|
-
'message.deleted': SseMessageDeletedPayloadSchema,
|
|
223
|
-
'conversation.updated': SseConversationUpdatedPayloadSchema,
|
|
224
|
-
'contact.request': SseContactRequestPayloadSchema,
|
|
225
|
-
'contact.approved': SseContactRequestPayloadSchema,
|
|
226
|
-
'contact.added': SseContactPayloadSchema,
|
|
227
|
-
'contact.updated': SseContactPayloadSchema,
|
|
228
|
-
'contact.removed': SseContactRemovedPayloadSchema,
|
|
229
|
-
'typing': SseTypingPayloadSchema,
|
|
230
|
-
'presence': SsePresencePayloadSchema,
|
|
231
|
-
'runtime.control': SseRuntimeControlPayloadSchema,
|
|
232
|
-
'voice.session.started': SseVoiceSessionEventPayloadSchema,
|
|
233
|
-
'voice.session.ended': SseVoiceSessionEventPayloadSchema,
|
|
234
|
-
'replay.expired': SseReplayExpiredPayloadSchema,
|
|
235
|
-
'error': SseErrorPayloadSchema,
|
|
236
|
-
};
|
|
237
|
-
/**
|
|
238
|
-
* Subscription families (`?events=` filter). Lifecycle events (`connected`,
|
|
239
|
-
* `agent.context`, `heartbeat`, `replay.expired`, `error`) are always sent.
|
|
240
|
-
*/
|
|
241
|
-
export const SSE_EVENT_FAMILIES = [
|
|
242
|
-
'messages',
|
|
243
|
-
'contacts',
|
|
244
|
-
'typing_presence',
|
|
245
|
-
'runtime_turn',
|
|
246
|
-
'voice',
|
|
247
|
-
];
|
|
248
|
-
export const SseEventFamilySchema = z.enum(SSE_EVENT_FAMILIES);
|
|
249
|
-
export const SSE_EVENT_FAMILY_BY_TYPE = {
|
|
250
|
-
'connected': 'lifecycle',
|
|
251
|
-
'agent.context': 'lifecycle',
|
|
252
|
-
'heartbeat': 'lifecycle',
|
|
253
|
-
'message.created': 'messages',
|
|
254
|
-
'message.updated': 'messages',
|
|
255
|
-
'message.deleted': 'messages',
|
|
256
|
-
'conversation.updated': 'messages',
|
|
257
|
-
'contact.request': 'contacts',
|
|
258
|
-
'contact.approved': 'contacts',
|
|
259
|
-
'contact.added': 'contacts',
|
|
260
|
-
'contact.updated': 'contacts',
|
|
261
|
-
'contact.removed': 'contacts',
|
|
262
|
-
'typing': 'typing_presence',
|
|
263
|
-
'presence': 'typing_presence',
|
|
264
|
-
'runtime.control': 'runtime_turn',
|
|
265
|
-
'voice.session.started': 'voice',
|
|
266
|
-
'voice.session.ended': 'voice',
|
|
267
|
-
'replay.expired': 'lifecycle',
|
|
268
|
-
'error': 'lifecycle',
|
|
269
|
-
};
|
|
270
|
-
/**
|
|
271
|
-
* A parsed SSE frame: `id:` (replay cursor), `event:`, and the JSON-decoded
|
|
272
|
-
* `data:` payload. Validate `data` with SSE_EVENT_PAYLOAD_SCHEMAS[event].
|
|
273
|
-
*/
|
|
274
|
-
export const SseEventEnvelopeSchema = z.object({
|
|
275
|
-
id: z.string().optional(),
|
|
276
|
-
event: SseEventTypeSchema,
|
|
277
|
-
data: z.unknown(),
|
|
278
|
-
});
|