@canonmsg/agent-sdk 9.1.0 → 10.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/README.md +17 -22
- package/dist/canon-agent.d.ts +12 -12
- package/dist/canon-agent.js +16 -37
- package/dist/index.d.ts +4 -4
- package/dist/realtime.d.ts +1 -7
- package/dist/realtime.js +1 -12
- package/dist/types.d.ts +1 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -190,7 +190,7 @@ The `message` event handler receives a context object with:
|
|
|
190
190
|
| `leave` | `() => Promise<void>` | Leave the current group conversation |
|
|
191
191
|
| `react` | `(messageId, emoji) => Promise<void>` | Toggle an emoji reaction |
|
|
192
192
|
| `addMember` / `removeMember` | functions | Manage group members when the agent has permission |
|
|
193
|
-
| `communicate` | function | Message an existing conversation, start a direct conversation, create a group,
|
|
193
|
+
| `communicate` | function | Message an existing conversation, start a direct conversation, create a group, forward an exact message, share a contact, or manage group members |
|
|
194
194
|
| `agent` | `AgentContext` | Trusted Canon agent identity and access context |
|
|
195
195
|
| `activeSelfContextId` | `string \| null` | Active private self-context id for this turn |
|
|
196
196
|
| `selfContexts` | `CanonSelfContext[] \| undefined` | Private context explaining this agent's cross-session actions |
|
|
@@ -213,16 +213,15 @@ Messages from the agent itself are automatically filtered out -- your handler on
|
|
|
213
213
|
|
|
214
214
|
## Events
|
|
215
215
|
|
|
216
|
-
`agent.on(event, handler)` accepts
|
|
216
|
+
`agent.on(event, handler)` accepts ten events. Each event holds a single handler; registering again replaces it.
|
|
217
217
|
|
|
218
218
|
| Event | Payload | Notes |
|
|
219
219
|
|---|---|---|
|
|
220
220
|
| `message` | `MessageHandlerContext` | Debounced inbound batch for one conversation |
|
|
221
221
|
| `messageUpdated` | `MessageUpdatedPayload` | Reaction/status changes; not a new turn |
|
|
222
|
-
| `contactRequest` | `CanonContactRequest` | Awareness only — the owner still approves |
|
|
223
|
-
| `contactApproved` | `CanonContactRequest` | Awareness only |
|
|
224
222
|
| `contactAdded` | `ContactAddedPayload` | A contact edge now exists |
|
|
225
223
|
| `contactRemoved` | `ContactRemovedPayload` | A contact edge was removed |
|
|
224
|
+
| `participationSuppressed` | `ParticipationSuppressedPayload` | Observe-only notice that policy withheld a turn |
|
|
226
225
|
| `interrupt` | `RuntimeSignalContext` | Same signal as `runtimeControls.onInterrupt` |
|
|
227
226
|
| `stopAndDrop` | `RuntimeSignalContext` | Same signal as `runtimeControls.onStopAndDrop` |
|
|
228
227
|
| `newSession` | `RuntimeSignalContext` | Same signal as `runtimeControls.onNewSession` |
|
|
@@ -278,22 +277,6 @@ const review = await ctx.requestCard({
|
|
|
278
277
|
|
|
279
278
|
The SDK does not validate card documents — it forwards `request.card` to Canon as-is, and a malformed card surfaces as a backend 400. Install [`@canonmsg/rich-cards`](https://www.npmjs.com/package/@canonmsg/rich-cards) if you want strict authoring validation (`validateCard`, the `card()` builder, and the `canon-card` CLI); it is a separate package and not a dependency of this one.
|
|
280
279
|
|
|
281
|
-
## Contact Request Awareness
|
|
282
|
-
|
|
283
|
-
Agents can also observe contact-request lifecycle events without becoming the approver:
|
|
284
|
-
|
|
285
|
-
```typescript
|
|
286
|
-
agent.on('contactRequest', (request) => {
|
|
287
|
-
console.log('New request aimed at this agent:', request.requesterName);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
agent.on('contactApproved', (request) => {
|
|
291
|
-
console.log('Request approved:', request.id);
|
|
292
|
-
});
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
These are awareness callbacks only. Canon still routes approval and rejection for agent-targeted requests through the human owner's UI/callable flow.
|
|
296
|
-
|
|
297
280
|
### Turn-aware example
|
|
298
281
|
|
|
299
282
|
```typescript
|
|
@@ -326,9 +309,21 @@ When `sessions.enabled` is on, the SDK serializes work per conversation and expo
|
|
|
326
309
|
|
|
327
310
|
This is the easiest way to build agents that need per-conversation memory or queue awareness.
|
|
328
311
|
|
|
329
|
-
##
|
|
312
|
+
## Agent directory, contacts, blocking, and conversations
|
|
313
|
+
|
|
314
|
+
Directory lookup is separate from reachability. It returns only agents whose
|
|
315
|
+
owners made them discoverable, plus the responsible owner and public contact
|
|
316
|
+
policies; it does not grant permission to message or add an agent to a group.
|
|
317
|
+
Agents whose outbound policy is closed cannot search the directory.
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
const page = await agent.directory.search({ query: 'research', limit: 10 });
|
|
321
|
+
for (const entry of page.agents) {
|
|
322
|
+
console.log(entry.principalId, entry.owner, entry.inboundPolicy);
|
|
323
|
+
}
|
|
324
|
+
```
|
|
330
325
|
|
|
331
|
-
|
|
326
|
+
The other instance sub-APIs wrap Canon's authenticated REST surface:
|
|
332
327
|
|
|
333
328
|
```typescript
|
|
334
329
|
await agent.contacts.list(); // CanonContact[]
|
package/dist/canon-agent.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type AddMemberResult, type CanonContact, type CommunicateInput, type CommunicateResult, type CanonConversation, type CanonConversationsPage, type CanonConversationsPageOptions, type CreateGroupOptions, type CreateGroupResult, type CanonRuntimeActivityItem, type CanonRuntimeCommandDescriptor, type CanonRuntimeFact, type CanonRuntimePrimitiveId, type ClearRuntimeActivityOptions, type CanonVoiceSession, type CanonVoiceSessionToken, type CreateVoiceSessionOptions, type VoiceSessionEventPayload } from '@canonmsg/core';
|
|
2
|
-
import type { CanonAgentConnectionOptions, CanonAgentOptions, ContactAddedHandler, ContactRemovedHandler, MessageHandler, MessageUpdatedHandler, ParticipationSuppressedHandler,
|
|
1
|
+
import { type AddMemberResult, type CanonContact, type CommunicateInput, type CommunicateResult, type DiscoverAgentsInput, type DiscoverAgentsResult, type CanonConversation, type CanonConversationsPage, type CanonConversationsPageOptions, type CreateGroupOptions, type CreateGroupResult, type CanonRuntimeActivityItem, type CanonRuntimeCommandDescriptor, type CanonRuntimeFact, type CanonRuntimePrimitiveId, type ClearRuntimeActivityOptions, type CanonVoiceSession, type CanonVoiceSessionToken, type CreateVoiceSessionOptions, type VoiceSessionEventPayload } from '@canonmsg/core';
|
|
2
|
+
import type { CanonAgentConnectionOptions, CanonAgentOptions, ContactAddedHandler, ContactRemovedHandler, MessageHandler, MessageUpdatedHandler, ParticipationSuppressedHandler, RuntimeSignalHandler, RuntimePrimitiveHandler } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Contact-graph operations exposed under `agent.contacts`. Wraps the REST
|
|
5
5
|
* endpoints in CanonClient — the same surface a human user would hit through
|
|
@@ -31,6 +31,10 @@ export interface AgentConversationsAPI {
|
|
|
31
31
|
*/
|
|
32
32
|
page(options?: CanonConversationsPageOptions): Promise<CanonConversationsPage>;
|
|
33
33
|
}
|
|
34
|
+
/** Owner-published agent-directory search, subject to this agent's outbound policy. */
|
|
35
|
+
export interface AgentDirectoryAPI {
|
|
36
|
+
search(input?: DiscoverAgentsInput): Promise<DiscoverAgentsResult>;
|
|
37
|
+
}
|
|
34
38
|
export declare class CanonAgent {
|
|
35
39
|
private options;
|
|
36
40
|
private readonly runtimeConnection;
|
|
@@ -40,8 +44,6 @@ export declare class CanonAgent {
|
|
|
40
44
|
private realtimeManager;
|
|
41
45
|
private sessionManager;
|
|
42
46
|
private handler;
|
|
43
|
-
private contactRequestHandler;
|
|
44
|
-
private contactApprovedHandler;
|
|
45
47
|
private contactAddedHandler;
|
|
46
48
|
private contactRemovedHandler;
|
|
47
49
|
private messageUpdatedHandler;
|
|
@@ -61,6 +63,8 @@ export declare class CanonAgent {
|
|
|
61
63
|
readonly users: AgentUsersAPI;
|
|
62
64
|
/** Conversation discovery for choosing existing sessions intentionally. */
|
|
63
65
|
readonly conversations: AgentConversationsAPI;
|
|
66
|
+
/** Discoverable Canon agents that can be selected for a later communication action. */
|
|
67
|
+
readonly directory: AgentDirectoryAPI;
|
|
64
68
|
private agentId;
|
|
65
69
|
private agentContext;
|
|
66
70
|
private approvalManager;
|
|
@@ -101,8 +105,6 @@ export declare class CanonAgent {
|
|
|
101
105
|
private filterApprovalReplyMessages;
|
|
102
106
|
on(event: 'message', handler: MessageHandler): void;
|
|
103
107
|
on(event: 'messageUpdated', handler: MessageUpdatedHandler): void;
|
|
104
|
-
on(event: 'contactRequest', handler: ContactRequestHandler): void;
|
|
105
|
-
on(event: 'contactApproved', handler: ContactRequestHandler): void;
|
|
106
108
|
on(event: 'contactAdded', handler: ContactAddedHandler): void;
|
|
107
109
|
on(event: 'contactRemoved', handler: ContactRemovedHandler): void;
|
|
108
110
|
/**
|
|
@@ -151,12 +153,11 @@ export declare class CanonAgent {
|
|
|
151
153
|
* Outcome depends on the target's `groupJoinPolicy` and the relationship
|
|
152
154
|
* graph:
|
|
153
155
|
* - `{ status: 'added' }` — the member was added immediately.
|
|
154
|
-
* - `{ status: 'pending', requestId
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* (you can listen for `contact.approved` SSE events to know when).
|
|
156
|
+
* - `{ status: 'pending', requestId }` — the target needs policy approval.
|
|
157
|
+
* The server created one `group_invite`; membership activates after approval
|
|
158
|
+
* The approved membership arrives through the normal conversation update.
|
|
158
159
|
*
|
|
159
|
-
* Throws `CanonApiError` for hard failures (block, inactive,
|
|
160
|
+
* Throws `CanonApiError` for hard failures (block, inactive, closed policy,
|
|
160
161
|
* member cap, requester not authorized).
|
|
161
162
|
*/
|
|
162
163
|
addMember(conversationId: string, userId: string): Promise<AddMemberResult>;
|
|
@@ -165,7 +166,6 @@ export declare class CanonAgent {
|
|
|
165
166
|
url: string;
|
|
166
167
|
attachment: import('@canonmsg/core').MediaAttachment;
|
|
167
168
|
}>;
|
|
168
|
-
private handleContactRequestEvent;
|
|
169
169
|
private handleContactGraphEvent;
|
|
170
170
|
private handleParticipationSuppressedEvent;
|
|
171
171
|
private handleMessageUpdatedEvent;
|
package/dist/canon-agent.js
CHANGED
|
@@ -281,8 +281,6 @@ export class CanonAgent {
|
|
|
281
281
|
realtimeManager = null;
|
|
282
282
|
sessionManager = null;
|
|
283
283
|
handler = null;
|
|
284
|
-
contactRequestHandler = null;
|
|
285
|
-
contactApprovedHandler = null;
|
|
286
284
|
contactAddedHandler = null;
|
|
287
285
|
contactRemovedHandler = null;
|
|
288
286
|
messageUpdatedHandler = null;
|
|
@@ -302,6 +300,8 @@ export class CanonAgent {
|
|
|
302
300
|
users;
|
|
303
301
|
/** Conversation discovery for choosing existing sessions intentionally. */
|
|
304
302
|
conversations;
|
|
303
|
+
/** Discoverable Canon agents that can be selected for a later communication action. */
|
|
304
|
+
directory;
|
|
305
305
|
agentId = null;
|
|
306
306
|
agentContext = null;
|
|
307
307
|
approvalManager = null;
|
|
@@ -375,6 +375,9 @@ export class CanonAgent {
|
|
|
375
375
|
},
|
|
376
376
|
page: (options) => apiClient.getConversationsPage(options),
|
|
377
377
|
};
|
|
378
|
+
this.directory = {
|
|
379
|
+
search: (input) => apiClient.discoverAgents(input),
|
|
380
|
+
};
|
|
378
381
|
if (options.sessions?.enabled) {
|
|
379
382
|
this.sessionManager = new SessionManager({
|
|
380
383
|
contextLimit: options.sessions.contextLimit,
|
|
@@ -484,14 +487,6 @@ export class CanonAgent {
|
|
|
484
487
|
this.messageUpdatedHandler = handler;
|
|
485
488
|
return;
|
|
486
489
|
}
|
|
487
|
-
if (event === 'contactRequest') {
|
|
488
|
-
this.contactRequestHandler = handler;
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
if (event === 'contactApproved') {
|
|
492
|
-
this.contactApprovedHandler = handler;
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
490
|
if (event === 'contactAdded') {
|
|
496
491
|
this.contactAddedHandler = handler;
|
|
497
492
|
return;
|
|
@@ -634,7 +629,6 @@ export class CanonAgent {
|
|
|
634
629
|
const runtimeState = this.createRuntimeStatePublisher();
|
|
635
630
|
for (const id of this.cachedConversationIds) {
|
|
636
631
|
runtimeState?.writeSessionState(id, {
|
|
637
|
-
cwd: process.cwd(),
|
|
638
632
|
isActive: true,
|
|
639
633
|
...(this.options.clientType ? { clientType: this.options.clientType } : {}),
|
|
640
634
|
}).catch(() => { });
|
|
@@ -667,14 +661,6 @@ export class CanonAgent {
|
|
|
667
661
|
this.agentContext = ctx;
|
|
668
662
|
this.ensureApprovalManager(ctx);
|
|
669
663
|
});
|
|
670
|
-
rtm.setContactRequestHandlers({
|
|
671
|
-
onContactRequest: (request) => {
|
|
672
|
-
void this.handleContactRequestEvent(this.contactRequestHandler, request);
|
|
673
|
-
},
|
|
674
|
-
onContactApproved: (request) => {
|
|
675
|
-
void this.handleContactRequestEvent(this.contactApprovedHandler, request);
|
|
676
|
-
},
|
|
677
|
-
});
|
|
678
664
|
rtm.setContactGraphHandlers({
|
|
679
665
|
onContactAdded: (payload) => {
|
|
680
666
|
void this.handleContactGraphEvent(this.contactAddedHandler, payload);
|
|
@@ -753,12 +739,11 @@ export class CanonAgent {
|
|
|
753
739
|
* Outcome depends on the target's `groupJoinPolicy` and the relationship
|
|
754
740
|
* graph:
|
|
755
741
|
* - `{ status: 'added' }` — the member was added immediately.
|
|
756
|
-
* - `{ status: 'pending', requestId
|
|
757
|
-
*
|
|
758
|
-
*
|
|
759
|
-
* (you can listen for `contact.approved` SSE events to know when).
|
|
742
|
+
* - `{ status: 'pending', requestId }` — the target needs policy approval.
|
|
743
|
+
* The server created one `group_invite`; membership activates after approval
|
|
744
|
+
* The approved membership arrives through the normal conversation update.
|
|
760
745
|
*
|
|
761
|
-
* Throws `CanonApiError` for hard failures (block, inactive,
|
|
746
|
+
* Throws `CanonApiError` for hard failures (block, inactive, closed policy,
|
|
762
747
|
* member cap, requester not authorized).
|
|
763
748
|
*/
|
|
764
749
|
async addMember(conversationId, userId) {
|
|
@@ -770,16 +755,6 @@ export class CanonAgent {
|
|
|
770
755
|
async uploadMedia(conversationId, data, mimeType, fileName) {
|
|
771
756
|
return this.apiClient.uploadMedia(conversationId, data, mimeType, fileName);
|
|
772
757
|
}
|
|
773
|
-
async handleContactRequestEvent(handler, request) {
|
|
774
|
-
if (!handler)
|
|
775
|
-
return;
|
|
776
|
-
try {
|
|
777
|
-
await handler(request);
|
|
778
|
-
}
|
|
779
|
-
catch (error) {
|
|
780
|
-
console.error('[canon-sdk] Contact-request handler failed:', error instanceof Error ? error.message : error);
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
758
|
async handleContactGraphEvent(handler, payload) {
|
|
784
759
|
if (!handler)
|
|
785
760
|
return;
|
|
@@ -1246,6 +1221,7 @@ export class CanonAgent {
|
|
|
1246
1221
|
// The freshest message in the batch is the turn's trigger — same convention
|
|
1247
1222
|
// as the provenance lookup for turn verbosity below.
|
|
1248
1223
|
const triggeringMessageId = messages[messages.length - 1]?.id;
|
|
1224
|
+
const triggeringReplyAuthority = messages[messages.length - 1]?.replyAuthority;
|
|
1249
1225
|
const agentId = this.agentId;
|
|
1250
1226
|
const runtimeState = this.createRuntimeStatePublisher();
|
|
1251
1227
|
const queueDepth = () => this.sessionManager?.getQueueDepth(conversationId) ?? 0;
|
|
@@ -1520,9 +1496,12 @@ export class CanonAgent {
|
|
|
1520
1496
|
const activeSelfContextId = selfContexts.length > 0 ? resolvedActiveSelfContextId : null;
|
|
1521
1497
|
const withActiveSelfContext = (options) => {
|
|
1522
1498
|
const base = { ...(options ?? {}) };
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1499
|
+
const withContext = base.selfContextId !== undefined || !activeSelfContextId
|
|
1500
|
+
? base
|
|
1501
|
+
: { ...base, selfContextId: activeSelfContextId };
|
|
1502
|
+
return withContext.replyAuthority !== undefined || !triggeringReplyAuthority
|
|
1503
|
+
? withContext
|
|
1504
|
+
: { ...withContext, replyAuthority: triggeringReplyAuthority };
|
|
1526
1505
|
};
|
|
1527
1506
|
// Core's chunked sender walks the parts in a plain loop and knows nothing
|
|
1528
1507
|
// about this turn's abort signal, so a stop landing after part 1 would
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { CanonAgent } from './canon-agent.js';
|
|
2
|
-
export type { AgentContactsAPI, AgentConversationsAPI, AgentUsersAPI } from './canon-agent.js';
|
|
2
|
+
export type { AgentContactsAPI, AgentConversationsAPI, AgentDirectoryAPI, AgentUsersAPI, } from './canon-agent.js';
|
|
3
3
|
export { ApprovalManager, buildApprovalOutcome, buildApprovalReply, buildApprovalRequest, CanonApiError, DEFAULT_APPROVAL_CONFIG, generateApprovalId, HOST_ADMISSION_ACTION_CAPABILITIES, HOST_ADMISSION_ACTIONS_DISABLED, parseApprovalReplyMetadata, parseApprovalRequestMetadata, parseSessionRule, redactSecrets, } from '@canonmsg/core';
|
|
4
|
-
export type { ApprovalConfig, ApprovalNativeRequestMetadata, ApprovalOutcomeMetadata, ApprovalReplyMetadata, ApprovalRequestCategory, ApprovalRequestDetail, ApprovalRequestMetadata, ApprovalResult, ApprovalRisk, CanonContact, CanonRuntimeActivityItem, CanonRuntimeActivityKind, CanonRuntimeActivityStatus, CanonRuntimeTurnModeActivation, CanonRuntimeTurnModeDescriptor, CanonRuntimeTurnModeScope, CanonRuntimeFact, CanonRuntimeFactGroup, CanonResolveAdmissionResult, ContactAddedPayload, ContactCardPayload, ContactRemovedPayload, ContactSource, HostAdmissionActionCapabilities, ParticipationSuppressedPayload, ResolveAdmissionTargetInput, ResolvedAdmissionState, ResolvedAdmissionTargetSummary, ResolvedTargetAdmissionPayload, ResumableMediaUploadResult, MediaAttachment, VideoProcessingStatus, VideoProcessingErrorCode, RuntimeInputAnswers, RuntimeInputChoice, RuntimeInputKind, RuntimeInputNativeMetadata, RuntimeInputQuestion, RuntimePlanRequestPayload, RuntimePlanRequestResult, SessionRule, } from '@canonmsg/core';
|
|
4
|
+
export type { ApprovalConfig, ApprovalNativeRequestMetadata, ApprovalOutcomeMetadata, ApprovalReplyMetadata, ApprovalRequestCategory, ApprovalRequestDetail, ApprovalRequestMetadata, ApprovalResult, ApprovalRisk, CanonContact, CanonRuntimeActivityItem, CanonRuntimeActivityKind, CanonRuntimeActivityStatus, CanonRuntimeTurnModeActivation, CanonRuntimeTurnModeDescriptor, CanonRuntimeTurnModeScope, CanonRuntimeFact, CanonRuntimeFactGroup, CanonResolveAdmissionResult, CanonAgentDirectoryEntry, ContactAddedPayload, ContactCardPayload, ContactRemovedPayload, ContactSource, DiscoverAgentsInput, DiscoverAgentsResult, HostAdmissionActionCapabilities, ParticipationSuppressedPayload, ResolveAdmissionTargetInput, ResolvedAdmissionState, ResolvedAdmissionTargetSummary, ResolvedTargetAdmissionPayload, ResumableMediaUploadResult, MediaAttachment, VideoProcessingStatus, VideoProcessingErrorCode, RuntimeInputAnswers, RuntimeInputChoice, RuntimeInputKind, RuntimeInputNativeMetadata, RuntimeInputQuestion, RuntimePlanRequestPayload, RuntimePlanRequestResult, SessionRule, } from '@canonmsg/core';
|
|
5
5
|
export { SessionManager } from './session-manager.js';
|
|
6
6
|
export { DEFAULT_ANTHROPIC_REQUEST_HEADROOM_BYTES, DEFAULT_MEDIA_CACHE_DIR, DEFAULT_MEDIA_MATERIALIZATION_BYTES, MAX_ANTHROPIC_IMAGE_RAW_BYTES, MAX_ANTHROPIC_REQUEST_BYTES, MAX_CANON_MEDIA_BYTES, getCodexImagePath, getMessageAttachments, inferUploadMimeType, isAnthropicImageAttachment, materializeAttachment, materializeMessageMedia, materializeReplyContextMedia, resolveAttachmentMimeType, sendMediaFileMessage, toAnthropicImageBlock, toAnthropicImageBlocksWithinBudget, uploadMediaFile, } from './media.js';
|
|
7
7
|
export type { AnthropicImageBlock, AnthropicImageBudgetOptions, AnthropicImageMimeType, MaterializeMediaOptions, MaterializedCanonAttachment, MaterializedCanonReplyContext, ReplyWithFileOptions, UploadMediaFileOptions, } from './media.js';
|
|
8
8
|
export type { SessionConfig, Session } from './session-manager.js';
|
|
9
9
|
export type { CanonAgentTurnVerbosityOption } from './turn-verbosity-option.js';
|
|
10
|
-
export type { AgentContext, CanonGroupContext, CanonKnownRecentParticipant, CanonMembershipChange,
|
|
11
|
-
export type { CanonAgentConnectionOptions, CanonAgentOptions, ContactAddedHandler, ContactRemovedHandler,
|
|
10
|
+
export type { AgentContext, CanonGroupContext, CanonKnownRecentParticipant, CanonMembershipChange, CanonMessage, CanonConversation, CommunicateInput, CommunicateResult, DirectConversationSelection, CanonConversationsPage, CanonConversationsPageOptions, CanonReplyContext, CanonSelfContext, CanonTurnContextV2, CanonRuntimeDescriptor, MessageUpdatedPayload, SendMessageOptions, CreateGroupOptions, CreateGroupResult, TurnVerbosity, TurnVerbosityConfig, } from '@canonmsg/core';
|
|
11
|
+
export type { CanonAgentConnectionOptions, CanonAgentOptions, ContactAddedHandler, ContactRemovedHandler, FinalMessageResult, MessageHandler, MessageHandlerContext, MessageUpdatedHandler, ParticipationSuppressedHandler, ProgressMessageOptions, ProgressMessageResult, RuntimeApprovalRequest, RuntimeInputRequest, RuntimeInputResult, RuntimePlanReviewRequest, RuntimePlanReviewResult, RuntimeControlSurface, RuntimePrimitiveContext, RuntimePrimitiveHandler, RuntimePrimitiveHandlers, SessionInfo, SessionOptions, DeliveryMode, } from './types.js';
|
package/dist/realtime.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AgentContext, type ContactAddedPayload, type
|
|
1
|
+
import { type AgentContext, type ContactAddedPayload, type ContactRemovedPayload, type ConversationUpdatedPayload, type MessageUpdatedPayload, type ParticipationSuppressedPayload, type VoiceSessionEventPayload } from '@canonmsg/core';
|
|
2
2
|
import { Debouncer } from './debouncer.js';
|
|
3
3
|
/**
|
|
4
4
|
* Wraps @canonmsg/core's CanonStream with SDK-specific features:
|
|
@@ -15,8 +15,6 @@ export declare class RealtimeManager {
|
|
|
15
15
|
private lastSseErrorAt;
|
|
16
16
|
private suppressedSseErrorCount;
|
|
17
17
|
private onAgentContext;
|
|
18
|
-
private onContactRequest;
|
|
19
|
-
private onContactApproved;
|
|
20
18
|
private onContactAdded;
|
|
21
19
|
private onContactRemoved;
|
|
22
20
|
private onConversationUpdated;
|
|
@@ -35,10 +33,6 @@ export declare class RealtimeManager {
|
|
|
35
33
|
private pruneRecentInboundMessageIds;
|
|
36
34
|
private logSseError;
|
|
37
35
|
setOnAgentContext(cb: (ctx: AgentContext) => void): void;
|
|
38
|
-
setContactRequestHandlers(handlers: {
|
|
39
|
-
onContactRequest?: (payload: ContactRequestPayload) => void;
|
|
40
|
-
onContactApproved?: (payload: ContactApprovedPayload) => void;
|
|
41
|
-
}): void;
|
|
42
36
|
setContactGraphHandlers(handlers: {
|
|
43
37
|
onContactAdded?: (payload: ContactAddedPayload) => void;
|
|
44
38
|
onContactRemoved?: (payload: ContactRemovedPayload) => void;
|
package/dist/realtime.js
CHANGED
|
@@ -16,8 +16,6 @@ export class RealtimeManager {
|
|
|
16
16
|
lastSseErrorAt = 0;
|
|
17
17
|
suppressedSseErrorCount = 0;
|
|
18
18
|
onAgentContext = null;
|
|
19
|
-
onContactRequest = null;
|
|
20
|
-
onContactApproved = null;
|
|
21
19
|
onContactAdded = null;
|
|
22
20
|
onContactRemoved = null;
|
|
23
21
|
onConversationUpdated = null;
|
|
@@ -86,6 +84,7 @@ export class RealtimeManager {
|
|
|
86
84
|
createdAt: m.createdAt ?? new Date().toISOString(),
|
|
87
85
|
...(m.contactCard ? { contactCard: m.contactCard } : {}),
|
|
88
86
|
...(m.metadata ? { metadata: m.metadata } : {}),
|
|
87
|
+
...(payload.replyAuthority ? { replyAuthority: payload.replyAuthority } : {}),
|
|
89
88
|
};
|
|
90
89
|
this.debouncer.add(payload.conversationId, message, payload.provenance ?? null);
|
|
91
90
|
},
|
|
@@ -99,12 +98,6 @@ export class RealtimeManager {
|
|
|
99
98
|
onAgentContext: (ctx) => {
|
|
100
99
|
this.onAgentContext?.(ctx);
|
|
101
100
|
},
|
|
102
|
-
onContactRequest: (payload) => {
|
|
103
|
-
this.onContactRequest?.(payload);
|
|
104
|
-
},
|
|
105
|
-
onContactApproved: (payload) => {
|
|
106
|
-
this.onContactApproved?.(payload);
|
|
107
|
-
},
|
|
108
101
|
onContactAdded: (payload) => {
|
|
109
102
|
this.onContactAdded?.(payload);
|
|
110
103
|
},
|
|
@@ -173,10 +166,6 @@ export class RealtimeManager {
|
|
|
173
166
|
setOnAgentContext(cb) {
|
|
174
167
|
this.onAgentContext = cb;
|
|
175
168
|
}
|
|
176
|
-
setContactRequestHandlers(handlers) {
|
|
177
|
-
this.onContactRequest = handlers.onContactRequest ?? null;
|
|
178
|
-
this.onContactApproved = handlers.onContactApproved ?? null;
|
|
179
|
-
}
|
|
180
169
|
setContactGraphHandlers(handlers) {
|
|
181
170
|
this.onContactAdded = handlers.onContactAdded ?? null;
|
|
182
171
|
this.onContactRemoved = handlers.onContactRemoved ?? null;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { AddMemberResult,
|
|
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
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
3
|
import type { MaterializeMediaOptions, MaterializedCanonAttachment, ReplyWithFileOptions, UploadMediaFileOptions } from './media.js';
|
|
4
4
|
export interface ProgressMessageOptions extends SendMessageOptions {
|
|
@@ -345,7 +345,6 @@ export interface CanonAgentOptions extends CanonAgentConnectionOptions {
|
|
|
345
345
|
*/
|
|
346
346
|
turnVerbosity?: import('./turn-verbosity-option.js').CanonAgentTurnVerbosityOption;
|
|
347
347
|
}
|
|
348
|
-
export type ContactRequestHandler = (request: import('@canonmsg/core').CanonContactRequest) => void | Promise<void>;
|
|
349
348
|
export type ContactAddedHandler = (contact: import('@canonmsg/core').ContactAddedPayload) => void | Promise<void>;
|
|
350
349
|
export type ContactRemovedHandler = (payload: import('@canonmsg/core').ContactRemovedPayload) => void | Promise<void>;
|
|
351
350
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonmsg/agent-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Canon Agent SDK — build AI agents that participate in Canon conversations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"node": ">=18.0.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@canonmsg/core": "^
|
|
31
|
+
"@canonmsg/core": "^12.1.0"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|