@canonmsg/agent-sdk 0.10.0 → 0.10.2
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 +1 -0
- package/dist/canon-agent.js +25 -17
- package/package.json +2 -2
package/dist/canon-agent.d.ts
CHANGED
package/dist/canon-agent.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CanonClient, FINAL_MESSAGE_HANDOFF_MS, initRTDBAuth, mergeWorkSessionContexts,
|
|
1
|
+
import { CanonClient, createRuntimeStatePublisher, FINAL_MESSAGE_HANDOFF_MS, initRTDBAuth, mergeWorkSessionContexts, } from '@canonmsg/core';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { AuthManager } from './auth.js';
|
|
4
4
|
import { Debouncer } from './debouncer.js';
|
|
@@ -196,8 +196,9 @@ export class CanonAgent {
|
|
|
196
196
|
}
|
|
197
197
|
// 3c. Initialize RTDB session state reporting (opt-in)
|
|
198
198
|
if (this.options.sessionState) {
|
|
199
|
+
const runtimeState = this.createRuntimeStatePublisher();
|
|
199
200
|
for (const id of this.cachedConversationIds) {
|
|
200
|
-
writeSessionState(id,
|
|
201
|
+
runtimeState?.writeSessionState(id, {
|
|
201
202
|
cwd: process.cwd(),
|
|
202
203
|
isActive: true,
|
|
203
204
|
...(this.options.clientType ? { clientType: this.options.clientType } : {}),
|
|
@@ -304,14 +305,15 @@ export class CanonAgent {
|
|
|
304
305
|
return;
|
|
305
306
|
this.running = false;
|
|
306
307
|
// Clear session state if enabled (uses cached IDs — no network call during shutdown)
|
|
307
|
-
|
|
308
|
+
const runtimeState = this.createRuntimeStatePublisher();
|
|
309
|
+
if (this.options.sessionState && runtimeState) {
|
|
308
310
|
for (const id of this.cachedConversationIds) {
|
|
309
|
-
Promise.resolve(clearSessionState(id
|
|
311
|
+
Promise.resolve(runtimeState.clearSessionState(id)).catch(() => { });
|
|
310
312
|
}
|
|
311
313
|
}
|
|
312
|
-
if (
|
|
314
|
+
if (runtimeState) {
|
|
313
315
|
for (const id of this.cachedConversationIds) {
|
|
314
|
-
Promise.resolve(clearTurnState(id
|
|
316
|
+
Promise.resolve(runtimeState.clearTurnState(id)).catch(() => { });
|
|
315
317
|
}
|
|
316
318
|
}
|
|
317
319
|
await this.clearAgentRuntime();
|
|
@@ -323,13 +325,11 @@ export class CanonAgent {
|
|
|
323
325
|
console.log('[canon-sdk] Stopped');
|
|
324
326
|
}
|
|
325
327
|
async publishAgentRuntime() {
|
|
326
|
-
|
|
328
|
+
const publisher = this.createRuntimeStatePublisher();
|
|
329
|
+
if (!publisher)
|
|
327
330
|
return;
|
|
328
|
-
await
|
|
329
|
-
clientType: this.options.clientType ?? 'generic',
|
|
330
|
-
hostMode: false,
|
|
331
|
+
await publisher.publishAgentRuntime({
|
|
331
332
|
runtimeDescriptor: this.options.runtimeDescriptor ?? DEFAULT_SDK_RUNTIME_DESCRIPTOR,
|
|
332
|
-
updatedAt: { '.sv': 'timestamp' },
|
|
333
333
|
});
|
|
334
334
|
}
|
|
335
335
|
startRuntimeHeartbeat() {
|
|
@@ -349,9 +349,16 @@ export class CanonAgent {
|
|
|
349
349
|
void this.clearAgentRuntime();
|
|
350
350
|
}
|
|
351
351
|
async clearAgentRuntime() {
|
|
352
|
+
await Promise.resolve(this.createRuntimeStatePublisher()?.clearAgentRuntime()).catch(() => { });
|
|
353
|
+
}
|
|
354
|
+
createRuntimeStatePublisher() {
|
|
352
355
|
if (!this.agentId)
|
|
353
|
-
return;
|
|
354
|
-
|
|
356
|
+
return null;
|
|
357
|
+
return createRuntimeStatePublisher({
|
|
358
|
+
agentId: this.agentId,
|
|
359
|
+
clientType: this.options.clientType ?? 'generic',
|
|
360
|
+
hostMode: false,
|
|
361
|
+
});
|
|
355
362
|
}
|
|
356
363
|
async handleMessages(conversationId, messages) {
|
|
357
364
|
if (!this.handler) {
|
|
@@ -375,12 +382,13 @@ export class CanonAgent {
|
|
|
375
382
|
let turnState = 'thinking';
|
|
376
383
|
let shouldPersistTurnState = false;
|
|
377
384
|
const agentId = this.agentId;
|
|
385
|
+
const runtimeState = this.createRuntimeStatePublisher();
|
|
378
386
|
const queueDepth = () => this.sessionManager?.getQueueDepth(conversationId) ?? 0;
|
|
379
387
|
const writeTurn = async (state) => {
|
|
380
|
-
if (!agentId)
|
|
388
|
+
if (!runtimeState || !agentId)
|
|
381
389
|
return;
|
|
382
390
|
turnState = state;
|
|
383
|
-
await Promise.resolve(writeTurnState(conversationId,
|
|
391
|
+
await Promise.resolve(runtimeState.writeTurnState(conversationId, {
|
|
384
392
|
turnId,
|
|
385
393
|
state,
|
|
386
394
|
queueDepth: queueDepth(),
|
|
@@ -682,8 +690,8 @@ export class CanonAgent {
|
|
|
682
690
|
await this.apiClient.clearStreaming(conversationId);
|
|
683
691
|
}
|
|
684
692
|
catch { }
|
|
685
|
-
if (
|
|
686
|
-
await Promise.resolve(clearTurnState(conversationId
|
|
693
|
+
if (runtimeState && !shouldPersistTurnState) {
|
|
694
|
+
await Promise.resolve(runtimeState.clearTurnState(conversationId)).catch(() => { });
|
|
687
695
|
}
|
|
688
696
|
}
|
|
689
697
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonmsg/agent-sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
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.
|
|
31
|
+
"@canonmsg/core": "^0.14.0"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|