@canonmsg/agent-sdk 0.5.0 → 0.6.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.
@@ -1,4 +1,4 @@
1
- import { CanonClient, FINAL_MESSAGE_HANDOFF_MS, initRTDBAuth, rtdbWrite, writeSessionState, clearSessionState, writeTurnState, clearTurnState, } from '@canonmsg/core';
1
+ import { CanonClient, FINAL_MESSAGE_HANDOFF_MS, initRTDBAuth, mergeWorkSessionContexts, rtdbWrite, writeSessionState, clearSessionState, writeTurnState, clearTurnState, } from '@canonmsg/core';
2
2
  import { randomUUID } from 'node:crypto';
3
3
  import { AuthManager } from './auth.js';
4
4
  import { Debouncer } from './debouncer.js';
@@ -274,8 +274,9 @@ export class CanonAgent {
274
274
  }
275
275
  }, 3500);
276
276
  try {
277
- // Fetch history from API
278
- const history = await this.apiClient.getMessages(conversationId, this.options.historyLimit);
277
+ // Fetch hydrated history/context from API
278
+ const page = await this.apiClient.getMessagesPage(conversationId, this.options.historyLimit);
279
+ const history = page.messages;
279
280
  // If sessions enabled, seed the session with fetched history
280
281
  if (this.sessionManager && session) {
281
282
  this.sessionManager.seedHistory(conversationId, history);
@@ -331,6 +332,11 @@ export class CanonAgent {
331
332
  m.isOwner = m.senderId === ownerId;
332
333
  }
333
334
  }
335
+ const explicitWorkSession = messages.find((message) => message.workSession)?.workSession
336
+ ?? history.find((message) => message.workSession)?.workSession
337
+ ?? null;
338
+ const activeWorkSessions = mergeWorkSessionContexts(explicitWorkSession, page.workSessions ?? []);
339
+ const workSession = explicitWorkSession;
334
340
  // Build agent context (fallback to minimal if not yet received)
335
341
  const agent = this.agentContext ?? {
336
342
  agentId: this.agentId,
@@ -345,6 +351,23 @@ export class CanonAgent {
345
351
  const react = (messageId, emoji) => this.apiClient.react(conversationId, messageId, emoji);
346
352
  const addMember = (userId) => this.apiClient.addMember(conversationId, userId);
347
353
  const removeMember = (userId) => this.apiClient.removeMember(conversationId, userId);
354
+ const createWorkSession = (options) => this.apiClient.createWorkSession({
355
+ conversationId,
356
+ ...(options ?? {}),
357
+ });
358
+ const getWorkSession = (workSessionId, targetConversationId = conversationId) => this.apiClient.getWorkSession(workSessionId, targetConversationId);
359
+ const updateWorkSessionContext = (workSessionId, options) => this.apiClient.upsertWorkSessionConversation(workSessionId, conversationId, options);
360
+ const sendLinkedMessage = (targetConversationId, text, options) => {
361
+ if (!options?.workSessionId && !options?.createWorkSession) {
362
+ throw new Error('sendLinkedMessage requires workSessionId or createWorkSession');
363
+ }
364
+ return this.apiClient.sendLinkedMessage({
365
+ sourceConversationId: conversationId,
366
+ targetConversationId,
367
+ text,
368
+ ...options,
369
+ });
370
+ };
348
371
  // Invoke handler
349
372
  await this.handler({
350
373
  messages,
@@ -360,7 +383,13 @@ export class CanonAgent {
360
383
  react,
361
384
  addMember,
362
385
  removeMember,
386
+ createWorkSession,
387
+ getWorkSession,
388
+ updateWorkSessionContext,
389
+ sendLinkedMessage,
363
390
  agent,
391
+ workSession,
392
+ activeWorkSessions,
364
393
  session: session
365
394
  ? {
366
395
  id: session.id,
package/dist/index.d.ts CHANGED
@@ -2,5 +2,5 @@ export { CanonAgent } from './canon-agent.js';
2
2
  export { CanonApiError } from '@canonmsg/core';
3
3
  export { SessionManager } from './session-manager.js';
4
4
  export type { SessionConfig, Session } from './session-manager.js';
5
- export type { AgentContext, CanonMessage, CanonConversation, SendMessageOptions, CreateConversationOptions, } from '@canonmsg/core';
5
+ export type { AgentContext, CanonMessage, CanonConversation, CanonResolvedWorkSession, CanonWorkSession, CanonWorkSessionContext, CanonWorkSessionConversationRole, CanonWorkSessionDisclosureMode, CanonWorkSessionParticipant, CanonWorkSessionStatus, CreateWorkSessionOptions, SendLinkedMessageOptions, SendLinkedMessageResult, SendMessageOptions, CreateConversationOptions, UpdateWorkSessionConversationOptions, } from '@canonmsg/core';
6
6
  export type { SDKMessage, SDKConversation, CanonAgentOptions, MessageHandler, MessageHandlerContext, ProgressMessageOptions, ProgressMessageResult, SessionInfo, SessionOptions, DeliveryMode, } from './types.js';
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type { AgentClientType, CanonMessage, CanonConversation, AgentContext, SendMessageOptions, CreateConversationOptions, TurnLifecycleState, } from '@canonmsg/core';
2
- import type { CanonMessage, CanonConversation, SendMessageOptions } from '@canonmsg/core';
1
+ export type { AgentClientType, CanonMessage, CanonConversation, AgentContext, CanonResolvedWorkSession, CanonWorkSession, CanonWorkSessionContext, CanonWorkSessionConversationRole, CanonWorkSessionDisclosureMode, CanonWorkSessionParticipant, CanonWorkSessionStatus, CreateWorkSessionOptions, SendLinkedMessageOptions, SendLinkedMessageResult, SendMessageOptions, CreateConversationOptions, TurnLifecycleState, UpdateWorkSessionConversationOptions, } from '@canonmsg/core';
2
+ import type { CanonMessage, CanonConversation, CreateWorkSessionOptions, SendMessageOptions, UpdateWorkSessionConversationOptions } from '@canonmsg/core';
3
3
  export type SDKMessage = CanonMessage;
4
4
  export type SDKConversation = CanonConversation;
5
5
  export interface ProgressMessageOptions extends SendMessageOptions {
@@ -59,8 +59,20 @@ export interface MessageHandlerContext {
59
59
  addMember: (userId: string) => Promise<void>;
60
60
  /** Remove a member from this conversation (requires owner/admin role) */
61
61
  removeMember: (userId: string) => Promise<void>;
62
+ /** Create a Canon work session rooted in this conversation. */
63
+ createWorkSession: (options?: Omit<CreateWorkSessionOptions, 'conversationId'>) => Promise<import('@canonmsg/core').CanonResolvedWorkSession>;
64
+ /** Load this conversation's scoped view of a Canon work session. */
65
+ getWorkSession: (workSessionId: string, conversationId?: string) => Promise<import('@canonmsg/core').CanonResolvedWorkSession>;
66
+ /** Update or attach this conversation's scoped work-session context. */
67
+ updateWorkSessionContext: (workSessionId: string, options?: UpdateWorkSessionConversationOptions) => Promise<import('@canonmsg/core').CanonResolvedWorkSession>;
68
+ /** Send into another conversation under an existing or lazily created Canon work session. */
69
+ sendLinkedMessage: (targetConversationId: string, text: string, options?: Omit<import('@canonmsg/core').SendLinkedMessageOptions, 'sourceConversationId' | 'targetConversationId' | 'text'>) => Promise<import('@canonmsg/core').SendLinkedMessageResult>;
62
70
  /** Trusted agent identity & access context */
63
71
  agent: import('@canonmsg/core').AgentContext;
72
+ /** Canon-provided shared task context for this turn, when attached to inbound messages. */
73
+ workSession?: import('@canonmsg/core').CanonWorkSessionContext | null;
74
+ /** All active Canon work sessions currently linked to this conversation. */
75
+ activeWorkSessions?: import('@canonmsg/core').CanonWorkSessionContext[];
64
76
  /** Per-conversation session state. Present when sessions are enabled. */
65
77
  session?: SessionInfo;
66
78
  /** Turn lifecycle helpers for live-work rendering and progress reporting. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonmsg/agent-sdk",
3
- "version": "0.5.0",
3
+ "version": "0.6.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",
@@ -23,7 +23,7 @@
23
23
  "node": ">=18.0.0"
24
24
  },
25
25
  "dependencies": {
26
- "@canonmsg/core": "^0.5.0"
26
+ "@canonmsg/core": "^0.6.0"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"