@canonmsg/agent-sdk 4.0.0 → 5.0.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 +343 -41
- package/dist/auth.d.ts +22 -0
- package/dist/auth.js +73 -0
- package/dist/canon-agent.d.ts +195 -0
- package/dist/canon-agent.js +2052 -0
- package/dist/debouncer.d.ts +15 -0
- package/dist/debouncer.js +98 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +2 -6
- package/dist/policy-history.d.ts +10 -0
- package/dist/policy-history.js +11 -0
- package/dist/realtime.d.ts +55 -0
- package/dist/realtime.js +194 -0
- package/dist/runtime-card.d.ts +29 -0
- package/dist/runtime-card.js +22 -0
- package/dist/turn-filter.d.ts +9 -0
- package/dist/turn-filter.js +25 -0
- package/dist/types.d.ts +321 -0
- package/dist/types.js +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { type AddMemberResult, type CanonContact, type CanonConversation, type CreateConversationResult, type CanonRuntimeActivityItem, type CanonRuntimeCommandDescriptor, type CanonRuntimeFact, type CanonRuntimePrimitiveId, type ContactCardPayload, type ClearRuntimeActivityOptions, type CreateContactRequestResult } from '@canonmsg/core';
|
|
2
|
+
import type { CanonAgentOptions, ContactAddedHandler, ContactRemovedHandler, CreateConversationOptions, MessageHandler, MessageUpdatedHandler, ReachOutOptions, ReachOutResult, ContactRequestHandler, RuntimeSignalHandler, RuntimePrimitiveHandler } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Contact-graph operations exposed under `agent.contacts`. Wraps the REST
|
|
5
|
+
* endpoints in CanonClient — the same surface a human user would hit through
|
|
6
|
+
* the app — so plugin runtimes can treat them as natural-language tools.
|
|
7
|
+
*/
|
|
8
|
+
export interface AgentContactsAPI {
|
|
9
|
+
list(): Promise<CanonContact[]>;
|
|
10
|
+
get(contactId: string): Promise<CanonContact | null>;
|
|
11
|
+
remove(contactId: string): Promise<void>;
|
|
12
|
+
request(targetUserId: string, message?: string | null): Promise<CreateContactRequestResult>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* User-level moderation actions exposed under `agent.users`.
|
|
16
|
+
*/
|
|
17
|
+
export interface AgentUsersAPI {
|
|
18
|
+
block(userId: string): Promise<void>;
|
|
19
|
+
unblock(userId: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export interface AgentConversationsAPI {
|
|
22
|
+
list(options?: {
|
|
23
|
+
targetUserId?: string;
|
|
24
|
+
}): Promise<CanonConversation[]>;
|
|
25
|
+
}
|
|
26
|
+
export declare class CanonAgent {
|
|
27
|
+
private options;
|
|
28
|
+
private apiClient;
|
|
29
|
+
private authManager;
|
|
30
|
+
private debouncer;
|
|
31
|
+
private realtimeManager;
|
|
32
|
+
private sessionManager;
|
|
33
|
+
private handler;
|
|
34
|
+
private contactRequestHandler;
|
|
35
|
+
private contactApprovedHandler;
|
|
36
|
+
private contactAddedHandler;
|
|
37
|
+
private contactRemovedHandler;
|
|
38
|
+
private messageUpdatedHandler;
|
|
39
|
+
private interruptHandler;
|
|
40
|
+
private stopAndDropHandler;
|
|
41
|
+
private newSessionHandler;
|
|
42
|
+
private readonly primitiveHandlers;
|
|
43
|
+
private primitiveFallbackHandler;
|
|
44
|
+
/** Contact-graph operations (`agent.contacts.*`). Initialized in the constructor. */
|
|
45
|
+
readonly contacts: AgentContactsAPI;
|
|
46
|
+
/** Block/unblock operations (`agent.users.*`). Initialized in the constructor. */
|
|
47
|
+
readonly users: AgentUsersAPI;
|
|
48
|
+
/** Conversation discovery for choosing existing sessions intentionally. */
|
|
49
|
+
readonly conversations: AgentConversationsAPI;
|
|
50
|
+
private readonly reachOutInFlight;
|
|
51
|
+
private agentId;
|
|
52
|
+
private agentContext;
|
|
53
|
+
private approvalManager;
|
|
54
|
+
private approvalManagerAgentId;
|
|
55
|
+
private approvalManagerOwnerId;
|
|
56
|
+
private cachedConversationIds;
|
|
57
|
+
private running;
|
|
58
|
+
private runtimeHeartbeatTimer;
|
|
59
|
+
private rtdbHandle;
|
|
60
|
+
private controlPoller;
|
|
61
|
+
private readonly activeAbortControllers;
|
|
62
|
+
private readonly activeTurns;
|
|
63
|
+
private readonly conversationMemberIds;
|
|
64
|
+
private readonly pendingMembershipChanges;
|
|
65
|
+
private readonly typingSignals;
|
|
66
|
+
private sseConnectedLogged;
|
|
67
|
+
constructor(options: CanonAgentOptions);
|
|
68
|
+
private ensureApprovalManager;
|
|
69
|
+
private filterApprovalReplyMessages;
|
|
70
|
+
on(event: 'message', handler: MessageHandler): void;
|
|
71
|
+
on(event: 'messageUpdated', handler: MessageUpdatedHandler): void;
|
|
72
|
+
on(event: 'contactRequest', handler: ContactRequestHandler): void;
|
|
73
|
+
on(event: 'contactApproved', handler: ContactRequestHandler): void;
|
|
74
|
+
on(event: 'contactAdded', handler: ContactAddedHandler): void;
|
|
75
|
+
on(event: 'contactRemoved', handler: ContactRemovedHandler): void;
|
|
76
|
+
on(event: 'interrupt', handler: RuntimeSignalHandler): void;
|
|
77
|
+
on(event: 'stopAndDrop', handler: RuntimeSignalHandler): void;
|
|
78
|
+
on(event: 'newSession', handler: RuntimeSignalHandler): void;
|
|
79
|
+
onPrimitive(primitive: CanonRuntimePrimitiveId | '*', handler: RuntimePrimitiveHandler): void;
|
|
80
|
+
describeCommands(_provider?: string): ReadonlyArray<CanonRuntimeCommandDescriptor>;
|
|
81
|
+
publishRuntimeFacts(conversationId: string, facts: ReadonlyArray<CanonRuntimeFact>): Promise<void>;
|
|
82
|
+
publishRuntimeActivity(conversationId: string, item: CanonRuntimeActivityItem): Promise<void>;
|
|
83
|
+
clearRuntimeActivity(conversationId: string, options?: ClearRuntimeActivityOptions): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Resolve admission live for a target user (typically read off a shared
|
|
86
|
+
* contact card) and route into either an immediate message or a contact
|
|
87
|
+
* request. Never reads `card.accessLevel` — that snapshot is stale by the
|
|
88
|
+
* time an LLM acts on it. Instead defers to `resolveAdmission` so the
|
|
89
|
+
* answer reflects the target's *current* inbound policy.
|
|
90
|
+
*/
|
|
91
|
+
reachOut(card: ContactCardPayload, options?: ReachOutOptions): Promise<ReachOutResult>;
|
|
92
|
+
private executeReachOut;
|
|
93
|
+
start(): Promise<void>;
|
|
94
|
+
createConversation(options: CreateConversationOptions): Promise<CreateConversationResult>;
|
|
95
|
+
updateTopic(conversationId: string, topic: string): Promise<void>;
|
|
96
|
+
leaveConversation(conversationId: string): Promise<void>;
|
|
97
|
+
updateConversationName(conversationId: string, name: string): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Add a member to a group conversation.
|
|
100
|
+
*
|
|
101
|
+
* Outcome depends on the target's `groupJoinPolicy` and the relationship
|
|
102
|
+
* graph:
|
|
103
|
+
* - `{ status: 'added' }` — the member was added immediately.
|
|
104
|
+
* - `{ status: 'pending', requestId }` — the target requires approval; the
|
|
105
|
+
* server created a contact-request (kind: 'group_invite') routed to the
|
|
106
|
+
* approver. The actual group join happens when that request is approved
|
|
107
|
+
* (you can listen for `contact.approved` SSE events to know when).
|
|
108
|
+
*
|
|
109
|
+
* Throws `CanonApiError` for hard failures (block, inactive, owner-only,
|
|
110
|
+
* member cap, requester not authorized).
|
|
111
|
+
*/
|
|
112
|
+
addMember(conversationId: string, userId: string): Promise<AddMemberResult>;
|
|
113
|
+
removeMember(conversationId: string, userId: string): Promise<void>;
|
|
114
|
+
uploadMedia(conversationId: string, data: string, mimeType: string, fileName?: string): Promise<{
|
|
115
|
+
url: string;
|
|
116
|
+
attachment: import('@canonmsg/core').MediaAttachment;
|
|
117
|
+
}>;
|
|
118
|
+
private handleContactRequestEvent;
|
|
119
|
+
private handleContactGraphEvent;
|
|
120
|
+
private handleMessageUpdatedEvent;
|
|
121
|
+
stop(): Promise<void>;
|
|
122
|
+
private hasInterruptSupport;
|
|
123
|
+
private hasStopAndDropSupport;
|
|
124
|
+
private hasNewSessionSupport;
|
|
125
|
+
private hasRuntimeSignalSupport;
|
|
126
|
+
private hasRuntimePrimitiveSupport;
|
|
127
|
+
private hasRuntimeControlSupport;
|
|
128
|
+
private supportsInputInterrupt;
|
|
129
|
+
private buildRuntimeDescriptor;
|
|
130
|
+
private buildRuntimeCapabilities;
|
|
131
|
+
private publishAgentRuntime;
|
|
132
|
+
private startRuntimeHeartbeat;
|
|
133
|
+
private stopRuntimeHeartbeat;
|
|
134
|
+
private clearAgentRuntime;
|
|
135
|
+
private rememberConversationId;
|
|
136
|
+
private rememberConversationMembers;
|
|
137
|
+
private handleConversationUpdated;
|
|
138
|
+
private buildGroupContext;
|
|
139
|
+
/**
|
|
140
|
+
* Shared `/control` channel poller, configured to the agent-sdk host
|
|
141
|
+
* profile pinned by core's characterization tests: flat 2s single-flight
|
|
142
|
+
* cadence, parallel conversations, signal + primitive keys (no session),
|
|
143
|
+
* eager signal baseline, and TTL'd primitive dedupe released on successful
|
|
144
|
+
* consume. The poller talks only to the scoped RTDB handle captured in
|
|
145
|
+
* start() — never the module-global default client.
|
|
146
|
+
*/
|
|
147
|
+
private ensureControlPoller;
|
|
148
|
+
private baselineRuntimeControlSignals;
|
|
149
|
+
private startRuntimeControlPolling;
|
|
150
|
+
private stopRuntimeControlPolling;
|
|
151
|
+
private handleRuntimePrimitiveEvent;
|
|
152
|
+
private handleRuntimeSignalEvent;
|
|
153
|
+
private firstActiveTurn;
|
|
154
|
+
private publishAcceptedRuntimeSignal;
|
|
155
|
+
private abortActiveTurns;
|
|
156
|
+
private resolveBatchDeliveryIntent;
|
|
157
|
+
private markQueuedMessagesAccepted;
|
|
158
|
+
private notifyMessageInterrupt;
|
|
159
|
+
/**
|
|
160
|
+
* Builds a runtime-state publisher bound to this agent's scoped RTDB
|
|
161
|
+
* handle (captured in start()). Threading the handle keeps every
|
|
162
|
+
* publish on this agent's own credentials — without it the publisher
|
|
163
|
+
* would fall back to core's deprecated module-global RTDB client,
|
|
164
|
+
* where the last-started agent's token wins in multi-agent processes.
|
|
165
|
+
*/
|
|
166
|
+
private createRuntimeStatePublisher;
|
|
167
|
+
private requireRuntimeStatePublisher;
|
|
168
|
+
private handleMessages;
|
|
169
|
+
private executeHandler;
|
|
170
|
+
static register(options: {
|
|
171
|
+
name: string;
|
|
172
|
+
description: string;
|
|
173
|
+
ownerPhone: string;
|
|
174
|
+
developerInfo: string;
|
|
175
|
+
avatarUrl?: string;
|
|
176
|
+
baseUrl?: string;
|
|
177
|
+
}): Promise<{
|
|
178
|
+
requestId: string;
|
|
179
|
+
pollToken?: string;
|
|
180
|
+
}>;
|
|
181
|
+
static checkStatus(requestId: string, options?: string | {
|
|
182
|
+
baseUrl?: string;
|
|
183
|
+
pollToken?: string;
|
|
184
|
+
}): Promise<{
|
|
185
|
+
status: string;
|
|
186
|
+
agentName: string;
|
|
187
|
+
agentId?: string;
|
|
188
|
+
apiKey?: string;
|
|
189
|
+
apiKeyDelivered?: boolean;
|
|
190
|
+
}>;
|
|
191
|
+
static ackStatus(requestId: string, options?: string | {
|
|
192
|
+
baseUrl?: string;
|
|
193
|
+
pollToken?: string;
|
|
194
|
+
}): Promise<void>;
|
|
195
|
+
}
|