@canonmsg/agent-sdk 1.1.0 → 1.1.1
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/canon-agent.d.ts +0 -1
- package/dist/canon-agent.js +4 -38
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
package/dist/canon-agent.d.ts
CHANGED
|
@@ -62,7 +62,6 @@ export declare class CanonAgent {
|
|
|
62
62
|
*/
|
|
63
63
|
reachOut(card: ContactCardPayload, options?: ReachOutOptions): Promise<ReachOutResult>;
|
|
64
64
|
private executeReachOut;
|
|
65
|
-
private openConversationAndMaybeMessage;
|
|
66
65
|
start(): Promise<void>;
|
|
67
66
|
createConversation(options: CreateConversationOptions): Promise<{
|
|
68
67
|
conversationId: string;
|
package/dist/canon-agent.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CanonClient, createRuntimeStatePublisher, FINAL_MESSAGE_HANDOFF_MS, initRTDBAuth, rtdbRead, rtdbWrite, mergeWorkSessionContexts, normalizeTurnMetadata, } from '@canonmsg/core';
|
|
1
|
+
import { CanonClient, createRuntimeStatePublisher, FINAL_MESSAGE_HANDOFF_MS, initRTDBAuth, rtdbRead, rtdbWrite, mergeWorkSessionContexts, normalizeTurnMetadata, reachOutToCanonContact, } from '@canonmsg/core';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { AuthManager } from './auth.js';
|
|
4
4
|
import { Debouncer } from './debouncer.js';
|
|
@@ -163,45 +163,11 @@ export class CanonAgent {
|
|
|
163
163
|
return promise;
|
|
164
164
|
}
|
|
165
165
|
async executeReachOut(targetUserId, options) {
|
|
166
|
-
|
|
167
|
-
if (admission.state === 'allowed' && admission.canMessage) {
|
|
168
|
-
return this.openConversationAndMaybeMessage(targetUserId, options);
|
|
169
|
-
}
|
|
170
|
-
if (admission.state === 'pending-outbound') {
|
|
171
|
-
return { status: 'pending', requestId: admission.pendingRequestId ?? null };
|
|
172
|
-
}
|
|
173
|
-
if (admission.state === 'request-required' && admission.canRequestContact) {
|
|
174
|
-
const result = await this.apiClient.createContactRequest(targetUserId, options?.requestMessage ?? null);
|
|
175
|
-
// The server may report 'open' if the target's policy flipped between
|
|
176
|
-
// the resolveAdmission call and the request. No request doc was
|
|
177
|
-
// written — fall through to the messaging path so the caller's intent
|
|
178
|
-
// ("reach this user") is honored end-to-end. Without this, the caller
|
|
179
|
-
// would get { status: 'requested' } despite no request existing.
|
|
180
|
-
if (result.status === 'open') {
|
|
181
|
-
return this.openConversationAndMaybeMessage(targetUserId, options);
|
|
182
|
-
}
|
|
183
|
-
// 'duplicate' means a pending request already existed; surface as
|
|
184
|
-
// 'pending'. 'created' is the normal "request just landed" path.
|
|
185
|
-
if (result.status === 'duplicate') {
|
|
186
|
-
return { status: 'pending', requestId: result.requestId };
|
|
187
|
-
}
|
|
188
|
-
return { status: 'requested', requestId: result.requestId };
|
|
189
|
-
}
|
|
190
|
-
if (admission.state === 'blocked') {
|
|
191
|
-
return { status: 'blocked', reason: 'blocked' };
|
|
192
|
-
}
|
|
193
|
-
return { status: 'unavailable', reason: admission.state };
|
|
194
|
-
}
|
|
195
|
-
async openConversationAndMaybeMessage(targetUserId, options) {
|
|
196
|
-
const { conversationId } = await this.apiClient.createConversation({
|
|
197
|
-
type: 'direct',
|
|
166
|
+
return reachOutToCanonContact(this.apiClient, {
|
|
198
167
|
targetUserId,
|
|
168
|
+
text: options?.text ?? null,
|
|
169
|
+
requestMessage: options?.requestMessage ?? null,
|
|
199
170
|
});
|
|
200
|
-
if (options?.text) {
|
|
201
|
-
const { messageId } = await this.apiClient.sendMessage(conversationId, options.text);
|
|
202
|
-
return { status: 'messaged', conversationId, messageId };
|
|
203
|
-
}
|
|
204
|
-
return { status: 'messaged', conversationId };
|
|
205
171
|
}
|
|
206
172
|
async start() {
|
|
207
173
|
if (this.running)
|
package/dist/types.d.ts
CHANGED
|
@@ -172,6 +172,6 @@ export type ReachOutResult = {
|
|
|
172
172
|
export interface ReachOutOptions {
|
|
173
173
|
/** Optional first message to send when admission is `allowed`. */
|
|
174
174
|
text?: string;
|
|
175
|
-
/** Optional
|
|
175
|
+
/** Optional contact-request note. Defaults to `text` when admission is `request-required`. */
|
|
176
176
|
requestMessage?: string;
|
|
177
177
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonmsg/agent-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
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": "^0.15.
|
|
31
|
+
"@canonmsg/core": "^0.15.3"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|