@canonmsg/agent-sdk 11.2.1 → 12.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.
Files changed (181) hide show
  1. package/README.md +248 -523
  2. package/dist/chunks/chunk-7N6OPPW4.js +5430 -0
  3. package/dist/chunks/chunk-N722GWCP.js +4897 -0
  4. package/dist/chunks/chunk-QZ4PPRQW.js +14247 -0
  5. package/dist/chunks/mls-crypto-LMNQZOS6.js +10 -0
  6. package/dist/cli.js +572 -0
  7. package/dist/drivers/claude.d.ts +42 -0
  8. package/dist/drivers/code.d.ts +18 -0
  9. package/dist/drivers/codex.d.ts +46 -0
  10. package/dist/drivers/connector.d.ts +34 -0
  11. package/dist/index.d.ts +20 -25
  12. package/dist/index.js +91 -13
  13. package/dist/internal/backend-contracts/agentBehaviorPolicy.d.ts +122 -0
  14. package/dist/internal/backend-contracts/agentDirectory.d.ts +32 -0
  15. package/dist/internal/backend-contracts/agentOrigin.d.ts +23 -0
  16. package/dist/internal/backend-contracts/agentSearch.d.ts +17 -0
  17. package/dist/internal/backend-contracts/api-origins.generated.d.ts +4 -0
  18. package/dist/internal/backend-contracts/apiErrors.d.ts +1 -0
  19. package/dist/internal/backend-contracts/artifactActions.d.ts +8 -0
  20. package/dist/internal/backend-contracts/artifacts.d.ts +386 -0
  21. package/dist/internal/backend-contracts/clientFloor.d.ts +41 -0
  22. package/dist/internal/backend-contracts/communication.d.ts +146 -0
  23. package/dist/internal/backend-contracts/connectorRelay.d.ts +179 -0
  24. package/dist/internal/backend-contracts/conversationMembership.d.ts +28 -0
  25. package/dist/internal/backend-contracts/deliveryObservation.d.ts +23 -0
  26. package/dist/internal/backend-contracts/diffRedaction.d.ts +6 -0
  27. package/dist/internal/backend-contracts/endpoint-unread.d.ts +4 -0
  28. package/dist/internal/backend-contracts/endpoint.d.ts +120 -0
  29. package/dist/internal/backend-contracts/endpointContentPolicy.d.ts +48 -0
  30. package/dist/internal/backend-contracts/environment.d.ts +20 -0
  31. package/dist/internal/backend-contracts/externalInbound.d.ts +24 -0
  32. package/dist/internal/backend-contracts/firestoreValues.d.ts +9 -0
  33. package/dist/internal/backend-contracts/index.d.ts +54 -0
  34. package/dist/internal/backend-contracts/media-url.d.ts +20 -0
  35. package/dist/internal/backend-contracts/media.d.ts +51 -0
  36. package/dist/internal/backend-contracts/mediaDelivery.d.ts +46 -0
  37. package/dist/internal/backend-contracts/mediaTransferProtocol.d.ts +17 -0
  38. package/dist/internal/backend-contracts/membershipChange.d.ts +21 -0
  39. package/dist/internal/backend-contracts/message.d.ts +86 -0
  40. package/dist/internal/backend-contracts/messageText.d.ts +6 -0
  41. package/dist/internal/backend-contracts/mlsDevApplication.d.ts +161 -0
  42. package/dist/internal/backend-contracts/mlsDevCredential.d.ts +78 -0
  43. package/dist/internal/backend-contracts/mlsDevCredentialReconciliation.d.ts +45 -0
  44. package/dist/internal/backend-contracts/mlsDevDeviceCustody.d.ts +52 -0
  45. package/dist/internal/backend-contracts/mlsDevEnrollment.d.ts +75 -0
  46. package/dist/internal/backend-contracts/mlsDevFeedReceipt.d.ts +43 -0
  47. package/dist/internal/backend-contracts/mlsDevGroup.d.ts +321 -0
  48. package/dist/internal/backend-contracts/mlsDevGroupFeed.d.ts +51 -0
  49. package/dist/internal/backend-contracts/mlsDevInteraction.d.ts +159 -0
  50. package/dist/internal/backend-contracts/mlsDevKeyPackage.d.ts +42 -0
  51. package/dist/internal/backend-contracts/mlsDevKeyPackages.d.ts +55 -0
  52. package/dist/internal/backend-contracts/mlsEnvironment.d.ts +35 -0
  53. package/dist/internal/backend-contracts/mlsPrincipalAlias.d.ts +23 -0
  54. package/dist/internal/backend-contracts/moderation.d.ts +7 -0
  55. package/dist/internal/backend-contracts/plaintextProcessors.d.ts +63 -0
  56. package/dist/internal/backend-contracts/preparedContent.d.ts +54 -0
  57. package/dist/internal/backend-contracts/replyAuthority.d.ts +14 -0
  58. package/dist/internal/backend-contracts/runtimeCardFields.d.ts +66 -0
  59. package/dist/internal/backend-contracts/runtimeCardStorage.d.ts +3 -0
  60. package/dist/internal/backend-contracts/runtimeDescriptor.d.ts +88 -0
  61. package/dist/internal/backend-contracts/selfContext.d.ts +9 -0
  62. package/dist/internal/backend-contracts/turnProtocol.d.ts +43 -0
  63. package/dist/internal/backend-contracts/upload-mime-types.d.ts +17 -0
  64. package/dist/internal/backend-contracts/verbContract.d.ts +856 -0
  65. package/dist/internal/backend-contracts/verbSchemas.d.ts +1717 -0
  66. package/dist/internal/backend-contracts/verbWire.d.ts +493 -0
  67. package/dist/internal/backend-contracts/webAuth.d.ts +8 -0
  68. package/dist/internal/core/agent-profiles.d.ts +65 -0
  69. package/dist/internal/core/approval-format.d.ts +22 -0
  70. package/dist/internal/core/approval-manager.d.ts +43 -0
  71. package/dist/internal/core/approval-types.d.ts +73 -0
  72. package/dist/internal/core/base-url.d.ts +1 -0
  73. package/dist/internal/core/cli-metadata.d.ts +13 -0
  74. package/dist/internal/core/client.d.ts +432 -0
  75. package/dist/internal/core/completed-output-journal.d.ts +39 -0
  76. package/dist/internal/core/constants.d.ts +1 -0
  77. package/dist/internal/core/endpoint-client.d.ts +56 -0
  78. package/dist/internal/core/execution-environment-mode.d.ts +6 -0
  79. package/dist/internal/core/gifs.d.ts +29 -0
  80. package/dist/internal/core/host-runtime.d.ts +53 -0
  81. package/dist/internal/core/index.d.ts +68 -0
  82. package/dist/internal/core/node-media.d.ts +6 -0
  83. package/dist/internal/core/policy.d.ts +2 -0
  84. package/dist/internal/core/registration-profile.d.ts +10 -0
  85. package/dist/internal/core/registration-session.d.ts +55 -0
  86. package/dist/internal/core/registration.d.ts +5 -0
  87. package/dist/internal/core/retry.d.ts +113 -0
  88. package/dist/internal/core/rtdb-rest.d.ts +141 -0
  89. package/dist/internal/core/runtime-cards.d.ts +286 -0
  90. package/dist/internal/core/runtime-descriptor.d.ts +16 -0
  91. package/dist/internal/core/runtime-endpoints.d.ts +26 -0
  92. package/dist/internal/core/runtime-heartbeat.d.ts +29 -0
  93. package/dist/internal/core/runtime-presentation.d.ts +9 -0
  94. package/dist/internal/core/runtime-request-manager.d.ts +283 -0
  95. package/dist/internal/core/runtime-state-publisher.d.ts +42 -0
  96. package/dist/internal/core/self-context.d.ts +22 -0
  97. package/dist/internal/core/silent-turn.d.ts +49 -0
  98. package/dist/internal/core/stream.d.ts +78 -0
  99. package/dist/internal/core/turn-protocol.d.ts +28 -0
  100. package/dist/internal/core/turn-verbosity.d.ts +85 -0
  101. package/dist/internal/core/types.d.ts +964 -0
  102. package/dist/internal/core/unified-diff.d.ts +35 -0
  103. package/dist/internal/endpoint/artifact-images.d.ts +60 -0
  104. package/dist/internal/endpoint/artifact-reducer.d.ts +35 -0
  105. package/dist/internal/endpoint/artifact-views.d.ts +113 -0
  106. package/dist/internal/endpoint/artifacts.d.ts +75 -0
  107. package/dist/internal/endpoint/delivery.d.ts +47 -0
  108. package/dist/internal/endpoint/engine.d.ts +249 -0
  109. package/dist/internal/endpoint/ephemeral.d.ts +8 -0
  110. package/dist/internal/endpoint/events.d.ts +32 -0
  111. package/dist/internal/endpoint/external-inbound.d.ts +36 -0
  112. package/dist/internal/endpoint/handoff.d.ts +50 -0
  113. package/dist/internal/endpoint/history.d.ts +22 -0
  114. package/dist/internal/endpoint/image-generation-errors.d.ts +2 -0
  115. package/dist/internal/endpoint/inbound.d.ts +29 -0
  116. package/dist/internal/endpoint/index.d.ts +32 -0
  117. package/dist/internal/endpoint/media.d.ts +177 -0
  118. package/dist/internal/endpoint/migration.d.ts +50 -0
  119. package/dist/internal/endpoint/mls-crypto.d.ts +32 -0
  120. package/dist/internal/endpoint/mls-dev-client.d.ts +52 -0
  121. package/dist/internal/endpoint/mls-dev-device.d.ts +69 -0
  122. package/dist/internal/endpoint/mls-dev-groups.d.ts +174 -0
  123. package/dist/internal/endpoint/mls-dev-interactions.d.ts +99 -0
  124. package/dist/internal/endpoint/mls-dev-key-package-service.d.ts +46 -0
  125. package/dist/internal/endpoint/mls-dev-key-packages.d.ts +62 -0
  126. package/dist/internal/endpoint/mls-dev-text.d.ts +67 -0
  127. package/dist/internal/endpoint/mls-dev-transport.d.ts +38 -0
  128. package/dist/internal/endpoint/node-mls-custody-protocol.d.ts +29 -0
  129. package/dist/internal/endpoint/node-mls-custody.d.ts +15 -0
  130. package/dist/internal/endpoint/node.d.ts +7 -0
  131. package/dist/internal/endpoint/observe-query.d.ts +17 -0
  132. package/dist/internal/endpoint/portable-node-mls-custody.d.ts +23 -0
  133. package/dist/internal/endpoint/queue.d.ts +22 -0
  134. package/dist/internal/endpoint/recovery.d.ts +27 -0
  135. package/dist/internal/endpoint/retention.d.ts +7 -0
  136. package/dist/internal/endpoint/store.d.ts +22 -0
  137. package/dist/internal/endpoint/sync.d.ts +33 -0
  138. package/dist/internal/endpoint/transient-publisher.d.ts +8 -0
  139. package/dist/internal/endpoint/transport.d.ts +63 -0
  140. package/dist/media.d.ts +1 -1
  141. package/dist/media.js +42 -541
  142. package/dist/runner/errands.d.ts +118 -0
  143. package/dist/runner/mls.d.ts +97 -0
  144. package/dist/runner/relay.d.ts +87 -0
  145. package/dist/runner/runner.d.ts +98 -0
  146. package/dist/runner/types.d.ts +215 -0
  147. package/package.json +18 -5
  148. package/dist/attached-session.d.ts +0 -58
  149. package/dist/attached-session.js +0 -638
  150. package/dist/bounded-file-read.d.ts +0 -14
  151. package/dist/bounded-file-read.js +0 -34
  152. package/dist/canon-agent.d.ts +0 -236
  153. package/dist/canon-agent.js +0 -2531
  154. package/dist/debouncer.d.ts +0 -18
  155. package/dist/debouncer.js +0 -133
  156. package/dist/inbound-handoff.d.ts +0 -6
  157. package/dist/inbound-handoff.js +0 -17
  158. package/dist/managed-session-host.d.ts +0 -27
  159. package/dist/managed-session-host.js +0 -195
  160. package/dist/managed-session-setup.d.ts +0 -99
  161. package/dist/managed-session-setup.js +0 -234
  162. package/dist/realtime.d.ts +0 -62
  163. package/dist/realtime.js +0 -193
  164. package/dist/runtime-card.d.ts +0 -48
  165. package/dist/runtime-card.js +0 -64
  166. package/dist/session-manager.d.ts +0 -77
  167. package/dist/session-manager.js +0 -285
  168. package/dist/turn-streaming-request.d.ts +0 -17
  169. package/dist/turn-streaming-request.js +0 -22
  170. package/dist/turn-verbosity-option.d.ts +0 -33
  171. package/dist/turn-verbosity-option.js +0 -23
  172. package/dist/types.d.ts +0 -387
  173. package/dist/types.js +0 -1
  174. package/dist/work-session-coordination.d.ts +0 -21
  175. package/dist/work-session-coordination.js +0 -53
  176. package/dist/work-session-host.d.ts +0 -31
  177. package/dist/work-session-host.js +0 -617
  178. package/dist/work-session-interactions.d.ts +0 -12
  179. package/dist/work-session-interactions.js +0 -173
  180. package/dist/work-session-state.d.ts +0 -36
  181. package/dist/work-session-state.js +0 -62
package/dist/types.d.ts DELETED
@@ -1,387 +0,0 @@
1
- export type { AddMemberResult, AgentClientType, CanonGroupContext, CanonRuntimeActivityItem, CanonRuntimeActivityKind, CanonRuntimeActivityStatus, CanonRuntimeDescriptor, CanonRuntimeFact, CanonRuntimeFactGroup, CanonRuntimePrimitiveId, CanonRuntimeProvenance, CanonTurnContextV2, CanonMessage, CanonConversation, CommunicateInput, CommunicateResult, CanonReplyContext, CanonContact, CanonResolveAdmissionResult, ContactAddedPayload, ContactRemovedPayload, ContactSource, AgentContext, ResolveAdmissionTargetInput, ResolvedAdmissionState, ResolvedAdmissionTargetSummary, ResolvedTargetAdmissionPayload, CanonSelfContext, CreateGroupOptions, CreateGroupResult, SendMessageOptions, TurnLifecycleState, TurnOutputBlock, TurnOutputBlockInput, ApprovalNativeRequestMetadata, ApprovalRequestCategory, ApprovalRequestDetail, ApprovalRequestMetadata, ApprovalRisk, ApprovalReplyMetadata, ApprovalOutcomeMetadata, RuntimeInputChoice, RuntimeInputAnswers, RuntimeInputKind, RuntimeInputNativeMetadata, RuntimeInputQuestion, RuntimePlanRequestPayload, RuntimePlanRequestResult, RuntimeCardNativeMetadata, RuntimeCardV1, ResumableMediaUploadResult, MediaAttachment, VideoProcessingStatus, VideoProcessingErrorCode, SessionRule, ApprovalResult, } from '@canonmsg/core';
2
- import type { AddMemberResult, CanonGroupContext, CanonMessage, CanonConversation, CommunicateInput, CommunicateResult, CanonReplyContext, CanonRuntimeActionDispatch, CanonRuntimePrimitiveId, CanonRuntimeProvenance, CanonTurnContextV2, ApprovalNativeRequestMetadata, ApprovalRequestCategory, ApprovalRequestDetail, ApprovalResult, ApprovalRisk, RuntimeInputChoice, RuntimeInputAnswers, RuntimeInputKind, RuntimeInputNativeMetadata, RuntimeInputQuestion, RuntimePlanRequestPayload, RuntimePlanRequestResult, RuntimeCardNativeMetadata, RuntimeCardV1, ResumableMediaUploadResult, SendMessageOptions, TurnOutputBlock, TurnOutputBlockInput } from '@canonmsg/core';
3
- import type { MaterializeMediaOptions, MaterializedCanonAttachment, ReplyWithFileOptions, UploadMediaFileOptions } from './media.js';
4
- export interface ProgressMessageOptions extends SendMessageOptions {
5
- /**
6
- * Persist the progress update to Firestore.
7
- * By default, progress stays ephemeral and only updates the live RTDB turn state.
8
- */
9
- durable?: boolean;
10
- }
11
- /**
12
- * Result of a durable reply.
13
- *
14
- * Text over Canon's 4 KB (UTF-8) message limit is delivered as ordered chunks
15
- * rather than refused, so one `replyFinal` can land as more than one message.
16
- * `messageId` is the last one — the message carrying `turn_complete` and the
17
- * turn trail — and `messageIds` lists every part in order (a single entry when
18
- * the text fit, which is the common case).
19
- */
20
- export interface FinalMessageResult {
21
- messageId: string;
22
- messageIds: string[];
23
- }
24
- export type ProgressMessageResult = {
25
- turnId: string;
26
- durable: false;
27
- messageId: null;
28
- } | {
29
- turnId: string;
30
- durable: true;
31
- messageId: string;
32
- /**
33
- * Every message the update landed as, in order. A durable update over
34
- * Canon's 4 KB (UTF-8) limit is split into ordered parts rather than
35
- * refused; `messageId` is the last of them. One entry when the text fit,
36
- * which is the common case.
37
- */
38
- messageIds: string[];
39
- };
40
- export interface SessionInfo {
41
- /** Session ID (= conversationId) */
42
- id: string;
43
- /** All accumulated messages for this conversation (within the context limit), oldest first */
44
- messages: CanonMessage[];
45
- /** Arbitrary per-session state the agent can read/write across handler calls */
46
- metadata: Record<string, unknown>;
47
- queueDepth?: number;
48
- }
49
- export interface TurnController {
50
- id: string;
51
- state: import('@canonmsg/core').TurnLifecycleState;
52
- setThinking: (text?: string) => Promise<void>;
53
- setStreaming: (text: string) => Promise<void>;
54
- appendDelta: (delta: string) => void;
55
- appendBlock: (block: string) => void;
56
- appendTextSegmentDelta: (id: string, delta: string) => void;
57
- replaceTextSegmentSnapshot: (id: string, text: string) => void;
58
- addBlock: (block: TurnOutputBlockInput) => Promise<TurnOutputBlock>;
59
- updateBlock: (id: string, patch: Partial<Omit<TurnOutputBlockInput, 'id' | 'sequence'>>) => Promise<TurnOutputBlock | null>;
60
- completeBlock: (id: string, patch?: Partial<Omit<TurnOutputBlockInput, 'id' | 'sequence' | 'status'>>) => Promise<TurnOutputBlock | null>;
61
- failBlock: (id: string, patch?: Partial<Omit<TurnOutputBlockInput, 'id' | 'sequence' | 'status'>>) => Promise<TurnOutputBlock | null>;
62
- replaceSnapshot: (text: string) => Promise<void>;
63
- flush: () => Promise<void>;
64
- clear: () => Promise<void>;
65
- /**
66
- * End this turn without posting anything (`canon.verbs.v1` `no_reply`). The
67
- * live bubble is blanked and removed instead of being salvaged into a durable
68
- * message, so nothing is rendered and no other member or agent is triggered —
69
- * the agent-turn trigger is message-driven.
70
- *
71
- * `reason` is private: the text never leaves the process. Only its presence
72
- * is reported (a fixed sentinel on the wire), so the durable silence record
73
- * can set `hasReason` — the text itself is never sent and never rendered.
74
- *
75
- * Unlike the model-driven runtimes, this does NOT gate `replyFinal`. Calling
76
- * both is two explicit decisions by the same author, so the text still lands;
77
- * call `noReply` when the handler has decided not to answer at all.
78
- */
79
- noReply: (reason?: string) => Promise<void>;
80
- setTool: (text: string) => Promise<void>;
81
- setWaitingInput: (text?: string) => Promise<void>;
82
- }
83
- export interface RuntimeApprovalRequest {
84
- /** Native runtime/tool/action name that is asking for permission. */
85
- toolName: string;
86
- /** Structured native input. Raw values are summarized/redacted before storage. */
87
- toolInput?: Record<string, unknown>;
88
- /** Optional pre-redacted summary when a runtime already has user-facing copy. */
89
- toolSummary?: string;
90
- category?: ApprovalRequestCategory;
91
- risk?: ApprovalRisk;
92
- riskLevel?: 'normal' | 'destructive';
93
- runtimeId?: string;
94
- turnId?: string;
95
- native?: ApprovalNativeRequestMetadata;
96
- details?: ApprovalRequestDetail[];
97
- /** Human conversation member who should answer. Defaults to the triggering human. */
98
- responseUserId?: string;
99
- /** Aborts the Canon approval request and withdraws its pending card. */
100
- signal?: AbortSignal;
101
- /**
102
- * Ignore in-memory session rules for this approval request. Useful when the
103
- * action was triggered by someone other than the agent owner.
104
- */
105
- ignoreSessionRules?: boolean;
106
- /** Whether an approval reply may set an in-memory session rule. */
107
- allowSessionRule?: boolean;
108
- }
109
- export interface RuntimeInputRequest {
110
- kind: RuntimeInputKind;
111
- title: string;
112
- prompt: string;
113
- choices?: RuntimeInputChoice[];
114
- questions?: RuntimeInputQuestion[];
115
- secretName?: string;
116
- sensitive?: boolean;
117
- runtimeId?: string;
118
- turnId?: string;
119
- native?: RuntimeInputNativeMetadata;
120
- inputId?: string;
121
- timeoutMs?: number;
122
- /** Aborts the pending input request without waiting for the enclosing turn to stop. */
123
- signal?: AbortSignal;
124
- /** Human conversation member who should answer. Secret and sudo prompts remain owner-only. */
125
- responseUserId?: string;
126
- }
127
- export interface RuntimeInputResult {
128
- status: 'submitted' | 'cancelled' | 'timeout';
129
- value?: string;
130
- answers?: RuntimeInputAnswers;
131
- inputId: string;
132
- }
133
- /** Native Canon plan-review card backed by Core's existing runtime-plan interaction. */
134
- export interface RuntimePlanReviewRequest extends RuntimePlanRequestPayload {
135
- planId?: string;
136
- timeoutMs?: number;
137
- /** Aborts the pending plan review without waiting for the enclosing turn to stop. */
138
- signal?: AbortSignal;
139
- }
140
- export type RuntimePlanReviewResult = RuntimePlanRequestResult;
141
- export interface RuntimeCardRequest {
142
- card: RuntimeCardV1;
143
- cardId?: string;
144
- expiresAt?: string | number | Date;
145
- /** Human conversation member who should answer. Defaults to the triggering human. */
146
- responseUserId?: string;
147
- timeoutMs?: number;
148
- runtimeId?: string;
149
- turnId?: string;
150
- native?: RuntimeCardNativeMetadata;
151
- }
152
- export interface RuntimeCardResult {
153
- status: 'submitted' | 'cancelled' | 'timeout' | 'displayed';
154
- cardId: string;
155
- actionId?: string;
156
- values?: Record<string, unknown>;
157
- /** Canon-authenticated human who submitted this card response. */
158
- respondedBy?: string;
159
- }
160
- export interface MessageHandlerContext {
161
- messages: CanonMessage[];
162
- history: CanonMessage[];
163
- /** Resolved message/media content for the latest swipe-reply target, if any. */
164
- replyContext: CanonReplyContext | null;
165
- conversationId: string;
166
- conversation: CanonConversation;
167
- /** Lightweight group awareness, present for group conversations. */
168
- groupContext?: CanonGroupContext;
169
- replyFinal: (text: string, options?: SendMessageOptions, delivery?: {
170
- operationId?: string;
171
- replacesOperationId?: string;
172
- }) => Promise<FinalMessageResult>;
173
- /** Inspect a prior reply before renewing media or recording product completion. */
174
- getReplyOperation: (messageId: string, delivery?: {
175
- operationId?: string;
176
- }) => Promise<import('@canonmsg/core').CanonMessageOperation | undefined>;
177
- /** Reconcile every part of a journaled reply without rebuilding its content. */
178
- waitForReply: (operationId: string) => Promise<FinalMessageResult>;
179
- replyProgress: (text: string, options?: ProgressMessageOptions) => Promise<ProgressMessageResult>;
180
- /** Soft-delete a message (agent must be the sender) */
181
- deleteMessage: (messageId: string) => Promise<void>;
182
- /** Mark conversation as read */
183
- markAsRead: () => Promise<void>;
184
- /** Leave this conversation */
185
- leave: () => Promise<void>;
186
- /** Toggle emoji reaction on a message */
187
- react: (messageId: string, emoji: string) => Promise<void>;
188
- /**
189
- * Add a member to this conversation (requires owner/admin role).
190
- * Returns `{ status: 'added' }` on immediate add, or
191
- * `{ status: 'pending', requestId }` if the target requires approval —
192
- * a contact-request (kind: 'group_invite') is created and the join
193
- * lands when the approver accepts.
194
- */
195
- addMember: (userId: string) => Promise<AddMemberResult>;
196
- /** Remove a member from this conversation (requires owner/admin role) */
197
- removeMember: (userId: string) => Promise<void>;
198
- /** Message an existing Canon conversation or start/continue a direct one. */
199
- communicate: (input: CommunicateInput) => Promise<CommunicateResult>;
200
- /** Trusted agent identity & access context */
201
- agent: import('@canonmsg/core').AgentContext;
202
- /** Active private self-context to continue for this turn, if Canon supplied one. */
203
- activeSelfContextId: string | null;
204
- /** Canon-provided private context explaining this agent's cross-session actions. */
205
- selfContexts?: import('@canonmsg/core').CanonSelfContext[];
206
- /** Trusted Canon provenance for the latest inbound message in this handler batch. */
207
- provenance: CanonRuntimeProvenance;
208
- /** Compact structured Canon turn context for the latest inbound message in this handler batch. */
209
- turnContext: CanonTurnContextV2;
210
- /**
211
- * Each batched input's own shared-work references (the version it was
212
- * about, `origin` and any selection), in batch order. Malformed references
213
- * are dropped; an input with none is omitted.
214
- */
215
- artifactContexts: Array<{
216
- messageId: string;
217
- context: import('@canonmsg/core').ArtifactContext;
218
- }>;
219
- /**
220
- * Shared work in this handler's conversation (chess, forms, images): exactly
221
- * `CanonClient.artifacts(conversationId)`. Changes are made against the state
222
- * this agent last read or wrote (across turns), so a person's newer edit is
223
- * reported as a `CanonArtifactError` conflict instead of being overwritten:
224
- * `describe()` before `update()` (or pass `basedOnRevisionId`); with no read
225
- * yet, `update()` rejects with `NOT_READ`. Arrival reads nothing on the
226
- * handler's behalf. Dev-only preview; other environments reject with
227
- * `ARTIFACTS_UNAVAILABLE`.
228
- */
229
- readonly artifacts: import('@canonmsg/core').CanonConversationArtifacts;
230
- /** Runtime turn mode requested by the sender for this inbound turn, if any. */
231
- requestedTurnMode: string | null;
232
- /**
233
- * How much of this turn's middle the reader sees, already resolved from
234
- * `CanonAgentOptions.turnVerbosity` and the conversation type — groups are
235
- * quiet by default, DMs verbose. In `'quiet'` the SDK publishes no
236
- * `/streaming` narration and attaches no turn trail to the final, so a
237
- * handler can skip building either. It stays fixed for the whole turn.
238
- */
239
- turnVerbosity: import('@canonmsg/core').TurnVerbosity;
240
- /**
241
- * Ask the triggering human to approve a native runtime action. This only
242
- * renders Canon's inline approval card; runtimes must explicitly wait for
243
- * and enforce the returned decision in their own approval hook.
244
- */
245
- requestApproval: (request: RuntimeApprovalRequest) => Promise<ApprovalResult>;
246
- /**
247
- * Ask the triggering human for runtime input. Secret and sudo prompts remain
248
- * owner-only. Sensitive values are returned only to the calling runtime and
249
- * are never persisted in Canon message metadata.
250
- */
251
- requestRuntimeInput: (request: RuntimeInputRequest) => Promise<RuntimeInputResult>;
252
- /**
253
- * Present a native Canon plan-review card and wait for approve, revise,
254
- * reject, cancellation, or timeout. Canon owns presentation and response
255
- * routing; the runtime remains responsible for enforcing the decision.
256
- */
257
- requestPlanReview: (request: RuntimePlanReviewRequest) => Promise<RuntimePlanReviewResult>;
258
- /**
259
- * Ask the triggering human to review/respond to a generic rich card. The
260
- * visible card document is redacted for presentation; raw response values
261
- * return only to the calling runtime through Canon's control path.
262
- */
263
- requestCard: (request: RuntimeCardRequest) => Promise<RuntimeCardResult>;
264
- /**
265
- * Post a fire-and-forget display/report card and return immediately with
266
- * `{ status: 'displayed' }` — no waiting-input lifecycle. Use requestCard for
267
- * cards that expect a response. (requestCard also auto-detects action-less
268
- * cards and delegates here.)
269
- */
270
- sendCard: (request: RuntimeCardRequest) => Promise<RuntimeCardResult>;
271
- /** Canon-managed local media access for the current conversation. */
272
- media: {
273
- materialize: (message?: CanonMessage, options?: Omit<MaterializeMediaOptions, 'agentId' | 'conversationId' | 'messageId'>) => Promise<MaterializedCanonAttachment[]>;
274
- uploadFile: (filePath: string, options?: UploadMediaFileOptions) => Promise<ResumableMediaUploadResult>;
275
- replyWithFile: (filePath: string, text?: string, options?: ReplyWithFileOptions) => Promise<{
276
- messageId: string;
277
- }>;
278
- };
279
- /** Per-conversation session state. Present when sessions are enabled. */
280
- session?: SessionInfo;
281
- /** Turn lifecycle helpers for live-work rendering and progress reporting. */
282
- turn?: TurnController;
283
- /** Aborted when Canon sends an interrupt/stop signal for this active turn. */
284
- abortSignal: AbortSignal;
285
- }
286
- export type MessageHandler = (ctx: MessageHandlerContext) => Promise<void>;
287
- export type MessageUpdatedHandler = (payload: import('@canonmsg/core').MessageUpdatedPayload) => void | Promise<void>;
288
- export interface SessionOptions {
289
- /** Enable per-conversation session management (default: false) */
290
- enabled: boolean;
291
- /** Max messages retained per session (default: 50) */
292
- contextLimit?: number;
293
- /** Max sessions processing concurrently (default: 10) */
294
- concurrency?: number;
295
- /** Evict idle sessions after this many ms (default: 3600000 = 1h) */
296
- idleTimeoutMs?: number;
297
- }
298
- export type DeliveryMode = 'auto' | 'sse';
299
- export type RuntimeSignalType = Extract<CanonRuntimeActionDispatch, {
300
- kind: 'signal';
301
- }>['signal'];
302
- export interface RuntimeSignalContext {
303
- conversationId: string;
304
- signal: RuntimeSignalType;
305
- updatedAt?: number;
306
- abortSignal?: AbortSignal;
307
- droppedMessageIds: string[];
308
- }
309
- export type RuntimeSignalHandler = (context: RuntimeSignalContext) => void | Promise<void>;
310
- export interface RuntimeControlHandlers {
311
- onInterrupt?: RuntimeSignalHandler;
312
- onStopAndDrop?: RuntimeSignalHandler;
313
- onNewSession?: RuntimeSignalHandler;
314
- }
315
- export type RuntimeControlSurface = 'agent' | 'host';
316
- export interface RuntimePrimitiveContext {
317
- conversationId: string;
318
- primitive: CanonRuntimePrimitiveId;
319
- args: Record<string, string | boolean>;
320
- rawText?: string;
321
- alias?: string;
322
- requestId?: string;
323
- updatedAt?: number;
324
- }
325
- export type RuntimePrimitiveHandler = (context: RuntimePrimitiveContext) => void | Promise<void>;
326
- export type RuntimePrimitiveHandlers = Partial<Record<CanonRuntimePrimitiveId, RuntimePrimitiveHandler>> & {
327
- '*'?: RuntimePrimitiveHandler;
328
- };
329
- export interface CanonAgentConnectionOptions {
330
- /** Canon trust domain for API, stream, RTDB, and future cryptographic state. */
331
- environmentId: import('@canonmsg/core').CanonEnvironmentId;
332
- baseUrl?: string;
333
- streamUrl?: string;
334
- rtdbUrl?: string;
335
- /** Legacy Firebase connection option; endpoint-backed runtime state does not use it. */
336
- firebaseApiKey?: string;
337
- }
338
- export interface CanonAgentOptions extends CanonAgentConnectionOptions {
339
- /** Shared durable engine or persistent installation profile for this runtime. */
340
- endpoint?: import('@canonmsg/core').CanonClientEndpointOptions;
341
- apiKey: string;
342
- /** `auto` resolves to SSE. */
343
- deliveryMode?: DeliveryMode;
344
- debounceMs?: number;
345
- historyLimit?: number;
346
- /** Automatically mark conversations as read when handling messages (default: true) */
347
- autoMarkRead?: boolean;
348
- /** Per-conversation session management */
349
- sessions?: SessionOptions;
350
- /** Agent client type for capability detection. Defaults to 'generic'. */
351
- clientType?: import('@canonmsg/core').AgentClientType;
352
- /** Optional runtime descriptor published to Canon for setup/live UI rendering. */
353
- runtimeDescriptor?: import('@canonmsg/core').CanonRuntimeDescriptor;
354
- /** Optional Canon runtime signal handlers. Enables interrupt controls when provided. */
355
- runtimeControls?: RuntimeControlHandlers;
356
- /** Runtime publishing surface. Use `host` when this agent owns live runtime controls. */
357
- runtimeControlSurface?: RuntimeControlSurface;
358
- /** Optional typed runtime primitive handlers. Enables descriptor-backed command controls when provided. */
359
- runtimePrimitives?: RuntimePrimitiveHandlers;
360
- /**
361
- * Enable canonical agent-session state reporting. Off by default.
362
- * Turn-state reporting is automatic while handlers run.
363
- */
364
- sessionState?: boolean;
365
- /**
366
- * How much of a turn's middle the reader sees. Unset (or `'auto'`) resolves
367
- * per turn from the conversation type: DMs verbose, groups quiet. A scalar
368
- * overrides everywhere; the object form overrides one conversation type and
369
- * leaves the other on its default.
370
- *
371
- * `'quiet'` drops the live `/streaming` narration and the final's margin
372
- * turn trail. It never touches the typing indicator, the turn state, the
373
- * final message, failure notices, or interaction cards and their receipts —
374
- * and an explicit `ctx.replyProgress(text, { durable: true })` still posts,
375
- * because a developer's explicit send is not runtime narration.
376
- */
377
- turnVerbosity?: import('./turn-verbosity-option.js').CanonAgentTurnVerbosityOption;
378
- }
379
- export type ContactAddedHandler = (contact: import('@canonmsg/core').ContactAddedPayload) => void | Promise<void>;
380
- export type ContactRemovedHandler = (payload: import('@canonmsg/core').ContactRemovedPayload) => void | Promise<void>;
381
- /**
382
- * Observe-only notice that the participation gate suppressed a turn this
383
- * agent would otherwise have been dispatched (cap reached, mention required,
384
- * agent-to-agent disabled). Never run a turn off this event — it exists so a
385
- * benched agent can tell deliberate participation policy from a dead stream.
386
- */
387
- export type ParticipationSuppressedHandler = (payload: import('@canonmsg/core').ParticipationSuppressedPayload) => void | Promise<void>;
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,21 +0,0 @@
1
- import { CanonClient, type WorkSessionCatalog, type WorkSessionCompletion, type WorkSessionRequest, type WorkSessionRuntimeAuth, type WorkSessionRuntimeState } from '@canonmsg/core';
2
- import type { WorkSessionJournal } from './work-session-state.js';
3
- /** The same request identity is used by native creation and managed setup recovery. */
4
- export declare function fingerprintWorkSessionRequest(request: WorkSessionRequest): string;
5
- /** Shared broker authority; each host retains its own delivery and request dispatch loop. */
6
- export declare function createWorkSessionAuthority(options: {
7
- client: CanonClient;
8
- hostId: string;
9
- runtimeEpoch: string;
10
- displayName: string;
11
- isStopped(): boolean;
12
- }): {
13
- auth: () => WorkSessionRuntimeAuth;
14
- fence: () => void;
15
- retain: (state: WorkSessionRuntimeState) => WorkSessionRuntimeState;
16
- register: (catalog: WorkSessionCatalog) => Promise<WorkSessionRuntimeState>;
17
- heartbeat: (catalog: WorkSessionCatalog) => Promise<WorkSessionRuntimeState>;
18
- claim: (requestId?: string) => Promise<import("@canonmsg/backend-contracts").WorkSessionClaimResult>;
19
- acknowledge: (journal: WorkSessionJournal, requestId: string, result: WorkSessionCompletion) => Promise<WorkSessionRequest>;
20
- state: () => WorkSessionRuntimeState | undefined;
21
- };
@@ -1,53 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- /** The same request identity is used by native creation and managed setup recovery. */
3
- export function fingerprintWorkSessionRequest(request) {
4
- return createHash('sha256').update(JSON.stringify([
5
- request.agentId, request.conversationId, request.requestId, request.hostId,
6
- request.runtimeEpoch, request.catalogRevision, request.selection, request.requestedBy,
7
- ])).digest('hex');
8
- }
9
- /** Shared broker authority; each host retains its own delivery and request dispatch loop. */
10
- export function createWorkSessionAuthority(options) {
11
- let current;
12
- function auth() {
13
- if (!current)
14
- throw new Error('Work-session runtime is not registered.');
15
- return { hostId: options.hostId, runtimeEpoch: options.runtimeEpoch,
16
- leaseToken: current.lease.leaseToken };
17
- }
18
- function fence() {
19
- if (options.isStopped() || !current || current.lease.expiresAt - Date.now() < 5_000)
20
- throw new Error('Work-session runtime no longer has a fresh lease.');
21
- }
22
- function retain(state) {
23
- if (state.lease.hostId !== options.hostId || state.lease.runtimeEpoch !== options.runtimeEpoch
24
- || (current && current.ownerId !== state.ownerId))
25
- throw new Error('Work-session runtime identity changed.');
26
- current = state;
27
- return state;
28
- }
29
- async function register(catalog) {
30
- return retain(await options.client.registerWorkSessionRuntime({ hostId: options.hostId,
31
- runtimeEpoch: options.runtimeEpoch, displayName: options.displayName, catalog }));
32
- }
33
- async function heartbeat(catalog) {
34
- fence();
35
- return retain(await options.client.heartbeatWorkSessionRuntime({ ...auth(), catalog }));
36
- }
37
- function claim(requestId) {
38
- fence();
39
- return options.client.claimWorkSessionRequest({ ...auth(), ...(requestId ? { requestId } : {}) });
40
- }
41
- async function acknowledge(journal, requestId, result) {
42
- fence();
43
- const completed = await options.client.completeWorkSessionRequest({ ...auth(), requestId, result });
44
- if (completed.status !== result.status)
45
- throw new Error('Canon did not acknowledge the requested work-session outcome.');
46
- await journal.mutate((state) => {
47
- state.operations.find((entry) => entry.request.requestId === requestId).acknowledged = true;
48
- });
49
- return completed;
50
- }
51
- return { auth, fence, retain, register, heartbeat, claim, acknowledge,
52
- state: () => current };
53
- }
@@ -1,31 +0,0 @@
1
- import { type AttachedSessionBinding, type AttachedSessionStore, type NativeWorkSessionProvider } from '@canonmsg/core';
2
- import { type CanonAttachedSessionConnection, type CanonAttachedSessionStatus } from './attached-session.js';
3
- import { type WorkSessionHostStore } from './work-session-state.js';
4
- export interface CanonWorkSessionHostOptions {
5
- connection: CanonAttachedSessionConnection;
6
- /** Stable installation identity. A new random runtime epoch is used each start. */
7
- hostId: string;
8
- displayName: string;
9
- provider: NativeWorkSessionProvider;
10
- store: WorkSessionHostStore;
11
- createSessionStore(binding: AttachedSessionBinding): AttachedSessionStore;
12
- /** Process-wide native audience lock, shared with any standalone attachment CLI. */
13
- acquireNativeSession(binding: AttachedSessionBinding): (() => void) | Promise<() => void>;
14
- onStatus?: (event: {
15
- status: 'available' | 'stopped' | 'session';
16
- conversationId?: string;
17
- session?: CanonAttachedSessionStatus;
18
- }) => void;
19
- onError?: (error: unknown, operation: string) => void;
20
- pollIntervalMs?: number;
21
- heartbeatIntervalMs?: number;
22
- connectTimeoutMs?: number;
23
- }
24
- export interface CanonWorkSessionHost {
25
- start(): Promise<void>;
26
- stop(): Promise<void>;
27
- /** Refresh discovery and process one durable request; serialized with the poll loop. */
28
- reconcile(): Promise<void>;
29
- }
30
- /** One authenticated transport and liveness publisher, with durable per-room native routes. */
31
- export declare function createCanonWorkSessionHost(options: CanonWorkSessionHostOptions): CanonWorkSessionHost;