@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/message.js
CHANGED
|
@@ -1,68 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MediaAttachmentSchema, normalizeStoredAttachments } from './media.js';
|
|
1
|
+
import { normalizeStoredAttachments } from './media.js';
|
|
3
2
|
import { decodeStoredRuntimeCard } from './runtimeCardStorage.js';
|
|
4
|
-
export const SerializedSenderTypeSchema = z.enum(['human', 'ai_agent']);
|
|
5
|
-
export const SerializedAgentClientTypeSchema = z.enum([
|
|
6
|
-
'claude-code',
|
|
7
|
-
'openclaw',
|
|
8
|
-
'codex',
|
|
9
|
-
'hermes',
|
|
10
|
-
'generic',
|
|
11
|
-
]);
|
|
12
|
-
export const SerializedContentTypeSchema = z.enum([
|
|
13
|
-
'text',
|
|
14
|
-
'image',
|
|
15
|
-
'audio',
|
|
16
|
-
'video',
|
|
17
|
-
'file',
|
|
18
|
-
'contact_card',
|
|
19
|
-
]);
|
|
20
|
-
export const ForwardedFromSchema = z.object({
|
|
21
|
-
sourceConversationId: z.string(),
|
|
22
|
-
messageId: z.string(),
|
|
23
|
-
});
|
|
24
|
-
export const SerializedReactionsSchema = z.record(z.string(), z.array(z.string()));
|
|
25
|
-
export const SerializedContactCardSchema = z.object({
|
|
26
|
-
userId: z.string(),
|
|
27
|
-
canonContactId: z.string().optional(),
|
|
28
|
-
displayName: z.string(),
|
|
29
|
-
avatarUrl: z.string().nullable(),
|
|
30
|
-
userType: SerializedSenderTypeSchema,
|
|
31
|
-
clientType: SerializedAgentClientTypeSchema.optional(),
|
|
32
|
-
about: z.string().optional(),
|
|
33
|
-
isActive: z.boolean().optional(),
|
|
34
|
-
ownerId: z.string().optional(),
|
|
35
|
-
ownerName: z.string().optional(),
|
|
36
|
-
lifecycleState: z.string().optional(),
|
|
37
|
-
});
|
|
38
|
-
export const SerializedMessageSchema = z.object({
|
|
39
|
-
id: z.string(),
|
|
40
|
-
senderId: z.string(),
|
|
41
|
-
senderName: z.string().optional(),
|
|
42
|
-
senderType: SerializedSenderTypeSchema,
|
|
43
|
-
isOwner: z.boolean(),
|
|
44
|
-
contentType: SerializedContentTypeSchema,
|
|
45
|
-
text: z.string().nullable(),
|
|
46
|
-
attachments: z.array(MediaAttachmentSchema),
|
|
47
|
-
mentions: z.array(z.string()),
|
|
48
|
-
replyTo: z.string().nullable(),
|
|
49
|
-
replyToPosition: z.number().nullable(),
|
|
50
|
-
forwarded: z.boolean().optional(),
|
|
51
|
-
forwardedFrom: ForwardedFromSchema.optional(),
|
|
52
|
-
status: z.enum(['sent', 'read']),
|
|
53
|
-
createdAt: z.string(),
|
|
54
|
-
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
55
|
-
contactCard: SerializedContactCardSchema.optional(),
|
|
56
|
-
/** Durable canon.card.v1 runtime card content, passed through opaquely. */
|
|
57
|
-
runtimeCard: z.record(z.string(), z.unknown()).optional(),
|
|
58
|
-
reactions: SerializedReactionsSchema.optional(),
|
|
59
|
-
});
|
|
60
|
-
export const SerializeMessageInputSchema = z.object({
|
|
61
|
-
id: z.string(),
|
|
62
|
-
data: z.record(z.string(), z.unknown()),
|
|
63
|
-
senderName: z.string().optional(),
|
|
64
|
-
isOwner: z.boolean(),
|
|
65
|
-
});
|
|
66
3
|
function isRecord(value) {
|
|
67
4
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
68
5
|
}
|
|
@@ -121,7 +58,8 @@ function normalizeContentType(value) {
|
|
|
121
58
|
|| value === 'audio'
|
|
122
59
|
|| value === 'video'
|
|
123
60
|
|| value === 'file'
|
|
124
|
-
|| value === 'contact_card'
|
|
61
|
+
|| value === 'contact_card'
|
|
62
|
+
|| value === 'interaction') {
|
|
125
63
|
return value;
|
|
126
64
|
}
|
|
127
65
|
throw new Error('Message is missing canonical contentType');
|
|
@@ -170,6 +108,41 @@ function normalizeContactCard(value) {
|
|
|
170
108
|
card.lifecycleState = value.lifecycleState;
|
|
171
109
|
return card;
|
|
172
110
|
}
|
|
111
|
+
const INTERACTION_KINDS = [
|
|
112
|
+
'contact', 'approval', 'input', 'plan', 'card',
|
|
113
|
+
];
|
|
114
|
+
function normalizeInteraction(value) {
|
|
115
|
+
if (!isRecord(value))
|
|
116
|
+
return undefined;
|
|
117
|
+
if (!INTERACTION_KINDS.includes(value.kind))
|
|
118
|
+
return undefined;
|
|
119
|
+
if (typeof value.requestId !== 'string' || value.requestId.length === 0)
|
|
120
|
+
return undefined;
|
|
121
|
+
const envelope = {
|
|
122
|
+
kind: value.kind,
|
|
123
|
+
requestId: value.requestId,
|
|
124
|
+
interactive: value.interactive === true,
|
|
125
|
+
};
|
|
126
|
+
if (typeof value.responseUserId === 'string')
|
|
127
|
+
envelope.responseUserId = value.responseUserId;
|
|
128
|
+
if (typeof value.expiresAt === 'string')
|
|
129
|
+
envelope.expiresAt = value.expiresAt;
|
|
130
|
+
if (typeof value.schemaVersion === 'string')
|
|
131
|
+
envelope.schemaVersion = value.schemaVersion;
|
|
132
|
+
if (isRecord(value.preview)) {
|
|
133
|
+
const preview = {};
|
|
134
|
+
if (typeof value.preview.title === 'string')
|
|
135
|
+
preview.title = value.preview.title;
|
|
136
|
+
if (Array.isArray(value.preview.blockKinds)) {
|
|
137
|
+
preview.blockKinds = value.preview.blockKinds.filter((entry) => typeof entry === 'string');
|
|
138
|
+
}
|
|
139
|
+
envelope.preview = preview;
|
|
140
|
+
}
|
|
141
|
+
if (isRecord(value.response)) {
|
|
142
|
+
envelope.response = value.response;
|
|
143
|
+
}
|
|
144
|
+
return envelope;
|
|
145
|
+
}
|
|
173
146
|
export function serializeStoredMessage(input) {
|
|
174
147
|
const { data } = input;
|
|
175
148
|
const attachments = data.attachments === undefined
|
|
@@ -213,6 +186,13 @@ export function serializeStoredMessage(input) {
|
|
|
213
186
|
if (runtimeCard) {
|
|
214
187
|
result.runtimeCard = runtimeCard;
|
|
215
188
|
}
|
|
189
|
+
const interaction = normalizeInteraction(data.interaction);
|
|
190
|
+
if (interaction) {
|
|
191
|
+
result.interaction = interaction;
|
|
192
|
+
}
|
|
193
|
+
if (typeof data.body === 'string') {
|
|
194
|
+
result.body = data.body;
|
|
195
|
+
}
|
|
216
196
|
const reactions = normalizeReactions(data.reactions);
|
|
217
197
|
if (reactions) {
|
|
218
198
|
result.reactions = reactions;
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const RuntimeCardFieldTypeSchema: z.ZodEnum<{
|
|
3
|
-
number: "number";
|
|
4
|
-
boolean: "boolean";
|
|
5
|
-
date: "date";
|
|
6
|
-
text: "text";
|
|
7
|
-
textarea: "textarea";
|
|
8
|
-
select: "select";
|
|
9
|
-
multiSelect: "multiSelect";
|
|
10
|
-
currency: "currency";
|
|
11
|
-
searchSelect: "searchSelect";
|
|
12
|
-
lineItems: "lineItems";
|
|
13
|
-
}>;
|
|
14
|
-
export type RuntimeCardFieldType = z.infer<typeof RuntimeCardFieldTypeSchema>;
|
|
1
|
+
export type RuntimeCardFieldType = 'text' | 'textarea' | 'select' | 'multiSelect' | 'boolean' | 'date' | 'number' | 'currency' | 'searchSelect' | 'lineItems';
|
|
15
2
|
/**
|
|
16
3
|
* Caps shared across runtime-card normalizers, response validation, and
|
|
17
4
|
* authoring tools. Keep these backend-safe so Functions can import them.
|
|
@@ -22,104 +9,44 @@ export declare const RUNTIME_CARD_LIMITS: {
|
|
|
22
9
|
readonly lineItemColumns: 8;
|
|
23
10
|
readonly searchSelectChoices: 100;
|
|
24
11
|
};
|
|
25
|
-
export
|
|
26
|
-
label:
|
|
27
|
-
value
|
|
28
|
-
description
|
|
29
|
-
preview
|
|
30
|
-
}
|
|
31
|
-
export type
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
choices
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}, z.core.$strip>;
|
|
64
|
-
export type RuntimeCardLineItemColumn = z.infer<typeof RuntimeCardLineItemColumnSchema>;
|
|
65
|
-
export declare const RuntimeCardFieldSchema: z.ZodObject<{
|
|
66
|
-
id: z.ZodString;
|
|
67
|
-
label: z.ZodString;
|
|
68
|
-
type: z.ZodEnum<{
|
|
69
|
-
number: "number";
|
|
70
|
-
boolean: "boolean";
|
|
71
|
-
date: "date";
|
|
72
|
-
text: "text";
|
|
73
|
-
textarea: "textarea";
|
|
74
|
-
select: "select";
|
|
75
|
-
multiSelect: "multiSelect";
|
|
76
|
-
currency: "currency";
|
|
77
|
-
searchSelect: "searchSelect";
|
|
78
|
-
lineItems: "lineItems";
|
|
79
|
-
}>;
|
|
80
|
-
required: z.ZodOptional<z.ZodBoolean>;
|
|
81
|
-
placeholder: z.ZodOptional<z.ZodString>;
|
|
82
|
-
choices: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
83
|
-
label: z.ZodString;
|
|
84
|
-
value: z.ZodOptional<z.ZodString>;
|
|
85
|
-
description: z.ZodOptional<z.ZodString>;
|
|
86
|
-
preview: z.ZodOptional<z.ZodString>;
|
|
87
|
-
}, z.core.$strip>>>;
|
|
88
|
-
allowOther: z.ZodOptional<z.ZodBoolean>;
|
|
89
|
-
sensitive: z.ZodOptional<z.ZodBoolean>;
|
|
90
|
-
min: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
91
|
-
max: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
92
|
-
step: z.ZodOptional<z.ZodNumber>;
|
|
93
|
-
precision: z.ZodOptional<z.ZodNumber>;
|
|
94
|
-
currencyCode: z.ZodOptional<z.ZodString>;
|
|
95
|
-
columns: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
96
|
-
id: z.ZodString;
|
|
97
|
-
label: z.ZodString;
|
|
98
|
-
type: z.ZodEnum<{
|
|
99
|
-
number: "number";
|
|
100
|
-
date: "date";
|
|
101
|
-
text: "text";
|
|
102
|
-
select: "select";
|
|
103
|
-
currency: "currency";
|
|
104
|
-
}>;
|
|
105
|
-
required: z.ZodOptional<z.ZodBoolean>;
|
|
106
|
-
choices: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
107
|
-
label: z.ZodString;
|
|
108
|
-
value: z.ZodOptional<z.ZodString>;
|
|
109
|
-
description: z.ZodOptional<z.ZodString>;
|
|
110
|
-
preview: z.ZodOptional<z.ZodString>;
|
|
111
|
-
}, z.core.$strip>>>;
|
|
112
|
-
min: z.ZodOptional<z.ZodNumber>;
|
|
113
|
-
max: z.ZodOptional<z.ZodNumber>;
|
|
114
|
-
step: z.ZodOptional<z.ZodNumber>;
|
|
115
|
-
precision: z.ZodOptional<z.ZodNumber>;
|
|
116
|
-
currencyCode: z.ZodOptional<z.ZodString>;
|
|
117
|
-
allowOther: z.ZodOptional<z.ZodBoolean>;
|
|
118
|
-
}, z.core.$strip>>>;
|
|
119
|
-
minRows: z.ZodOptional<z.ZodNumber>;
|
|
120
|
-
maxRows: z.ZodOptional<z.ZodNumber>;
|
|
121
|
-
}, z.core.$strip>;
|
|
122
|
-
export type RuntimeCardField = z.infer<typeof RuntimeCardFieldSchema>;
|
|
12
|
+
export interface RuntimeCardFieldChoice {
|
|
13
|
+
label: string;
|
|
14
|
+
value?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
preview?: string;
|
|
17
|
+
}
|
|
18
|
+
export type RuntimeCardLineItemColumnType = 'text' | 'number' | 'currency' | 'date' | 'select';
|
|
19
|
+
export interface RuntimeCardLineItemColumn {
|
|
20
|
+
id: string;
|
|
21
|
+
label: string;
|
|
22
|
+
type: RuntimeCardLineItemColumnType;
|
|
23
|
+
required?: boolean;
|
|
24
|
+
choices?: RuntimeCardFieldChoice[];
|
|
25
|
+
min?: number;
|
|
26
|
+
max?: number;
|
|
27
|
+
step?: number;
|
|
28
|
+
precision?: number;
|
|
29
|
+
currencyCode?: string;
|
|
30
|
+
allowOther?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface RuntimeCardField {
|
|
33
|
+
id: string;
|
|
34
|
+
label: string;
|
|
35
|
+
type: RuntimeCardFieldType;
|
|
36
|
+
required?: boolean;
|
|
37
|
+
placeholder?: string;
|
|
38
|
+
choices?: RuntimeCardFieldChoice[];
|
|
39
|
+
allowOther?: boolean;
|
|
40
|
+
sensitive?: boolean;
|
|
41
|
+
min?: number | string;
|
|
42
|
+
max?: number | string;
|
|
43
|
+
step?: number;
|
|
44
|
+
precision?: number;
|
|
45
|
+
currencyCode?: string;
|
|
46
|
+
columns?: RuntimeCardLineItemColumn[];
|
|
47
|
+
minRows?: number;
|
|
48
|
+
maxRows?: number;
|
|
49
|
+
}
|
|
123
50
|
export declare function validateRuntimeCardFieldValues(input: {
|
|
124
51
|
actionId: string | undefined;
|
|
125
52
|
actionFields: ReadonlyArray<RuntimeCardField> | undefined;
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export const RuntimeCardFieldTypeSchema = z.enum([
|
|
3
|
-
'text',
|
|
4
|
-
'textarea',
|
|
5
|
-
'select',
|
|
6
|
-
'multiSelect',
|
|
7
|
-
'boolean',
|
|
8
|
-
'date',
|
|
9
|
-
'number',
|
|
10
|
-
'currency',
|
|
11
|
-
'searchSelect',
|
|
12
|
-
'lineItems',
|
|
13
|
-
]);
|
|
14
1
|
/**
|
|
15
2
|
* Caps shared across runtime-card normalizers, response validation, and
|
|
16
3
|
* authoring tools. Keep these backend-safe so Functions can import them.
|
|
@@ -21,50 +8,6 @@ export const RUNTIME_CARD_LIMITS = {
|
|
|
21
8
|
lineItemColumns: 8,
|
|
22
9
|
searchSelectChoices: 100,
|
|
23
10
|
};
|
|
24
|
-
export const RuntimeCardFieldChoiceSchema = z.object({
|
|
25
|
-
label: z.string(),
|
|
26
|
-
value: z.string().optional(),
|
|
27
|
-
description: z.string().optional(),
|
|
28
|
-
preview: z.string().optional(),
|
|
29
|
-
});
|
|
30
|
-
export const RuntimeCardLineItemColumnTypeSchema = z.enum([
|
|
31
|
-
'text',
|
|
32
|
-
'number',
|
|
33
|
-
'currency',
|
|
34
|
-
'date',
|
|
35
|
-
'select',
|
|
36
|
-
]);
|
|
37
|
-
export const RuntimeCardLineItemColumnSchema = z.object({
|
|
38
|
-
id: z.string(),
|
|
39
|
-
label: z.string(),
|
|
40
|
-
type: RuntimeCardLineItemColumnTypeSchema,
|
|
41
|
-
required: z.boolean().optional(),
|
|
42
|
-
choices: z.array(RuntimeCardFieldChoiceSchema).optional(),
|
|
43
|
-
min: z.number().optional(),
|
|
44
|
-
max: z.number().optional(),
|
|
45
|
-
step: z.number().optional(),
|
|
46
|
-
precision: z.number().optional(),
|
|
47
|
-
currencyCode: z.string().optional(),
|
|
48
|
-
allowOther: z.boolean().optional(),
|
|
49
|
-
});
|
|
50
|
-
export const RuntimeCardFieldSchema = z.object({
|
|
51
|
-
id: z.string(),
|
|
52
|
-
label: z.string(),
|
|
53
|
-
type: RuntimeCardFieldTypeSchema,
|
|
54
|
-
required: z.boolean().optional(),
|
|
55
|
-
placeholder: z.string().optional(),
|
|
56
|
-
choices: z.array(RuntimeCardFieldChoiceSchema).optional(),
|
|
57
|
-
allowOther: z.boolean().optional(),
|
|
58
|
-
sensitive: z.boolean().optional(),
|
|
59
|
-
min: z.union([z.number(), z.string()]).optional(),
|
|
60
|
-
max: z.union([z.number(), z.string()]).optional(),
|
|
61
|
-
step: z.number().optional(),
|
|
62
|
-
precision: z.number().optional(),
|
|
63
|
-
currencyCode: z.string().optional(),
|
|
64
|
-
columns: z.array(RuntimeCardLineItemColumnSchema).optional(),
|
|
65
|
-
minRows: z.number().optional(),
|
|
66
|
-
maxRows: z.number().optional(),
|
|
67
|
-
});
|
|
68
11
|
const ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
69
12
|
function isRecord(value) {
|
|
70
13
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
package/dist/turnProtocol.d.ts
CHANGED
|
@@ -1,94 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
interrupt: "interrupt";
|
|
26
|
-
interleave: "interleave";
|
|
27
|
-
stop: "stop";
|
|
28
|
-
}>;
|
|
29
|
-
export type DeliveryIntent = z.infer<typeof DeliveryIntentSchema>;
|
|
30
|
-
export declare const InboundDispositionSchema: z.ZodEnum<{
|
|
31
|
-
queued: "queued";
|
|
32
|
-
accepted_now: "accepted_now";
|
|
33
|
-
interleaved: "interleaved";
|
|
34
|
-
trigger_suppressed: "trigger_suppressed";
|
|
35
|
-
rejected: "rejected";
|
|
36
|
-
cancelled: "cancelled";
|
|
37
|
-
}>;
|
|
38
|
-
export type InboundDisposition = z.infer<typeof InboundDispositionSchema>;
|
|
39
|
-
export declare const TurnMetadataSchema: z.ZodObject<{
|
|
40
|
-
turnId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
|
-
turnSemantics: z.ZodOptional<z.ZodEnum<{
|
|
42
|
-
progress: "progress";
|
|
43
|
-
turn_complete: "turn_complete";
|
|
44
|
-
control: "control";
|
|
45
|
-
}>>;
|
|
46
|
-
deliveryIntent: z.ZodOptional<z.ZodEnum<{
|
|
47
|
-
queue: "queue";
|
|
48
|
-
interrupt: "interrupt";
|
|
49
|
-
interleave: "interleave";
|
|
50
|
-
stop: "stop";
|
|
51
|
-
}>>;
|
|
52
|
-
replyBehavior: z.ZodOptional<z.ZodEnum<{
|
|
53
|
-
allow_auto_reply: "allow_auto_reply";
|
|
54
|
-
suppress_auto_reply: "suppress_auto_reply";
|
|
55
|
-
}>>;
|
|
56
|
-
inboundDisposition: z.ZodOptional<z.ZodEnum<{
|
|
57
|
-
queued: "queued";
|
|
58
|
-
accepted_now: "accepted_now";
|
|
59
|
-
interleaved: "interleaved";
|
|
60
|
-
trigger_suppressed: "trigger_suppressed";
|
|
61
|
-
rejected: "rejected";
|
|
62
|
-
cancelled: "cancelled";
|
|
63
|
-
}>>;
|
|
64
|
-
requestedTurnMode: z.ZodOptional<z.ZodString>;
|
|
65
|
-
}, z.core.$strip>;
|
|
66
|
-
export type TurnMetadata = z.infer<typeof TurnMetadataSchema>;
|
|
67
|
-
export declare const TriggerDecisionSchema: z.ZodObject<{
|
|
68
|
-
allow: z.ZodBoolean;
|
|
69
|
-
semantics: z.ZodEnum<{
|
|
70
|
-
progress: "progress";
|
|
71
|
-
turn_complete: "turn_complete";
|
|
72
|
-
control: "control";
|
|
73
|
-
}>;
|
|
74
|
-
reason: z.ZodString;
|
|
75
|
-
}, z.core.$strip>;
|
|
76
|
-
export type TriggerDecision = z.infer<typeof TriggerDecisionSchema>;
|
|
77
|
-
export declare const TurnStateLikeSchema: z.ZodObject<{
|
|
78
|
-
state: z.ZodEnum<{
|
|
79
|
-
idle: "idle";
|
|
80
|
-
thinking: "thinking";
|
|
81
|
-
streaming: "streaming";
|
|
82
|
-
tool: "tool";
|
|
83
|
-
waiting_input: "waiting_input";
|
|
84
|
-
completed: "completed";
|
|
85
|
-
interrupted: "interrupted";
|
|
86
|
-
}>;
|
|
87
|
-
openedAt: z.ZodOptional<z.ZodNumber>;
|
|
88
|
-
updatedAt: z.ZodOptional<z.ZodNumber>;
|
|
89
|
-
turnUpdatedAt: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
90
|
-
}, z.core.$strip>;
|
|
91
|
-
export type TurnStateLike = z.infer<typeof TurnStateLikeSchema>;
|
|
1
|
+
export type SenderType = 'human' | 'ai_agent';
|
|
2
|
+
export type TurnLifecycleState = 'idle' | 'thinking' | 'streaming' | 'tool' | 'waiting_input' | 'completed' | 'interrupted';
|
|
3
|
+
export type TurnMessageSemantics = 'progress' | 'turn_complete' | 'control';
|
|
4
|
+
export type DeliveryIntent = 'queue' | 'interrupt' | 'interleave' | 'stop';
|
|
5
|
+
export type InboundDisposition = 'queued' | 'accepted_now' | 'interleaved' | 'trigger_suppressed' | 'rejected' | 'cancelled';
|
|
6
|
+
export interface TurnMetadata {
|
|
7
|
+
turnId?: string | null;
|
|
8
|
+
turnSemantics?: TurnMessageSemantics;
|
|
9
|
+
deliveryIntent?: DeliveryIntent;
|
|
10
|
+
replyBehavior?: 'allow_auto_reply' | 'suppress_auto_reply';
|
|
11
|
+
inboundDisposition?: InboundDisposition;
|
|
12
|
+
requestedTurnMode?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface TriggerDecision {
|
|
15
|
+
allow: boolean;
|
|
16
|
+
semantics: TurnMessageSemantics;
|
|
17
|
+
reason: string;
|
|
18
|
+
}
|
|
19
|
+
export interface TurnStateLike {
|
|
20
|
+
state: TurnLifecycleState;
|
|
21
|
+
openedAt?: number;
|
|
22
|
+
updatedAt?: number;
|
|
23
|
+
turnUpdatedAt?: number | null;
|
|
24
|
+
}
|
|
92
25
|
export declare const ACTIVE_TURN_STALE_THRESHOLD_MS: number;
|
|
93
26
|
export declare const WAITING_INPUT_STALE_THRESHOLD_MS: number;
|
|
94
27
|
export declare function normalizeTurnMetadata(metadata: unknown): TurnMetadata | null;
|
package/dist/turnProtocol.js
CHANGED
|
@@ -1,43 +1,3 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export const SenderTypeSchema = z.enum(['human', 'ai_agent']);
|
|
3
|
-
export const TurnLifecycleStateSchema = z.enum([
|
|
4
|
-
'idle',
|
|
5
|
-
'thinking',
|
|
6
|
-
'streaming',
|
|
7
|
-
'tool',
|
|
8
|
-
'waiting_input',
|
|
9
|
-
'completed',
|
|
10
|
-
'interrupted',
|
|
11
|
-
]);
|
|
12
|
-
export const TurnMessageSemanticsSchema = z.enum(['progress', 'turn_complete', 'control']);
|
|
13
|
-
export const DeliveryIntentSchema = z.enum(['queue', 'interrupt', 'interleave', 'stop']);
|
|
14
|
-
export const InboundDispositionSchema = z.enum([
|
|
15
|
-
'queued',
|
|
16
|
-
'accepted_now',
|
|
17
|
-
'interleaved',
|
|
18
|
-
'trigger_suppressed',
|
|
19
|
-
'rejected',
|
|
20
|
-
'cancelled',
|
|
21
|
-
]);
|
|
22
|
-
export const TurnMetadataSchema = z.object({
|
|
23
|
-
turnId: z.string().nullable().optional(),
|
|
24
|
-
turnSemantics: TurnMessageSemanticsSchema.optional(),
|
|
25
|
-
deliveryIntent: DeliveryIntentSchema.optional(),
|
|
26
|
-
replyBehavior: z.enum(['allow_auto_reply', 'suppress_auto_reply']).optional(),
|
|
27
|
-
inboundDisposition: InboundDispositionSchema.optional(),
|
|
28
|
-
requestedTurnMode: z.string().optional(),
|
|
29
|
-
});
|
|
30
|
-
export const TriggerDecisionSchema = z.object({
|
|
31
|
-
allow: z.boolean(),
|
|
32
|
-
semantics: TurnMessageSemanticsSchema,
|
|
33
|
-
reason: z.string(),
|
|
34
|
-
});
|
|
35
|
-
export const TurnStateLikeSchema = z.object({
|
|
36
|
-
state: TurnLifecycleStateSchema,
|
|
37
|
-
openedAt: z.number().optional(),
|
|
38
|
-
updatedAt: z.number().optional(),
|
|
39
|
-
turnUpdatedAt: z.number().nullable().optional(),
|
|
40
|
-
});
|
|
41
1
|
export const ACTIVE_TURN_STALE_THRESHOLD_MS = 30 * 60 * 1000;
|
|
42
2
|
export const WAITING_INPUT_STALE_THRESHOLD_MS = 12 * 60 * 60 * 1000;
|
|
43
3
|
const TURN_SEMANTICS = [
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonmsg/backend-contracts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Canon backend contract helpers shared by Functions and stream-service",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
10
|
"import": "./dist/index.js",
|
|
12
|
-
"require": "./dist/cjs/index.js"
|
|
11
|
+
"require": "./dist/cjs/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node -e \"require('fs').mkdirSync('dist/cjs',{recursive:true}); require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'}))\"
|
|
19
|
+
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node -e \"require('fs').mkdirSync('dist/cjs',{recursive:true}); require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'}))\"",
|
|
20
20
|
"dev": "tsc -p tsconfig.json --watch",
|
|
21
21
|
"test": "vitest run",
|
|
22
22
|
"prepack": "npm run build"
|
|
@@ -44,8 +44,5 @@
|
|
|
44
44
|
"typescript": "~5.7.0",
|
|
45
45
|
"vitest": "^4.1.8"
|
|
46
46
|
},
|
|
47
|
-
"license": "MIT"
|
|
48
|
-
"dependencies": {
|
|
49
|
-
"zod": "^4.4.3"
|
|
50
|
-
}
|
|
47
|
+
"license": "MIT"
|
|
51
48
|
}
|