@canonmsg/agent-sdk 1.3.1 → 1.4.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 { type AddMemberResult, type CanonContact, type CanonRuntimePrimitiveId, type ContactCardPayload, type CreateContactRequestResult } from '@canonmsg/core';
1
+ import { type AddMemberResult, type CanonContact, type CanonRuntimeActivityItem, type CanonRuntimeCommandDescriptor, type CanonRuntimeFact, type CanonRuntimePrimitiveId, type ContactCardPayload, type ClearRuntimeActivityOptions, type CreateContactRequestResult } from '@canonmsg/core';
2
2
  import type { CanonAgentOptions, ContactAddedHandler, ContactRemovedHandler, CreateConversationOptions, MessageHandler, ReachOutOptions, ReachOutResult, ContactRequestHandler, RuntimeSignalHandler, RuntimePrimitiveHandler } from './types.js';
3
3
  /**
4
4
  * Contact-graph operations exposed under `agent.contacts`. Wraps the REST
@@ -61,6 +61,10 @@ export declare class CanonAgent {
61
61
  on(event: 'stopAndDrop', handler: RuntimeSignalHandler): void;
62
62
  on(event: 'newSession', handler: RuntimeSignalHandler): void;
63
63
  onPrimitive(primitive: CanonRuntimePrimitiveId | '*', handler: RuntimePrimitiveHandler): void;
64
+ describeCommands(_provider?: string): ReadonlyArray<CanonRuntimeCommandDescriptor>;
65
+ publishRuntimeFacts(conversationId: string, facts: ReadonlyArray<CanonRuntimeFact>): Promise<void>;
66
+ publishRuntimeActivity(conversationId: string, item: CanonRuntimeActivityItem): Promise<void>;
67
+ clearRuntimeActivity(conversationId: string, options?: ClearRuntimeActivityOptions): Promise<void>;
64
68
  /**
65
69
  * Resolve admission live for a target user (typically read off a shared
66
70
  * contact card) and route into either an immediate message or a contact
@@ -128,6 +132,7 @@ export declare class CanonAgent {
128
132
  private resolveBatchDeliveryIntent;
129
133
  private notifyMessageInterrupt;
130
134
  private createRuntimeStatePublisher;
135
+ private requireRuntimeStatePublisher;
131
136
  private handleMessages;
132
137
  private executeHandler;
133
138
  static register(options: {
@@ -147,6 +147,27 @@ function normalizePrimitiveArgs(value) {
147
147
  }
148
148
  return args;
149
149
  }
150
+ function normalizeRuntimeFact(fact) {
151
+ const id = fact.id.trim();
152
+ const label = fact.label.trim();
153
+ const value = fact.value.trim();
154
+ if (!id || !label || !value)
155
+ return null;
156
+ return {
157
+ ...fact,
158
+ id,
159
+ label,
160
+ value,
161
+ };
162
+ }
163
+ function normalizeRuntimeActivityItem(item) {
164
+ return {
165
+ ...item,
166
+ id: item.id.trim(),
167
+ title: item.title.trim() || item.kind,
168
+ updatedAt: item.updatedAt || Date.now(),
169
+ };
170
+ }
150
171
  export class CanonAgent {
151
172
  options;
152
173
  apiClient;
@@ -283,6 +304,32 @@ export class CanonAgent {
283
304
  }
284
305
  void this.publishAgentRuntime().catch(() => { });
285
306
  }
307
+ describeCommands(_provider) {
308
+ return this.buildRuntimeDescriptor().commands ?? [];
309
+ }
310
+ async publishRuntimeFacts(conversationId, facts) {
311
+ this.rememberConversationId(conversationId);
312
+ const publisher = this.requireRuntimeStatePublisher();
313
+ const normalizedFacts = facts
314
+ .map(normalizeRuntimeFact)
315
+ .filter((fact) => Boolean(fact));
316
+ await publisher.patchRuntimeInfo(conversationId, {
317
+ descriptor: this.buildRuntimeDescriptor(),
318
+ facts: normalizedFacts,
319
+ });
320
+ }
321
+ async publishRuntimeActivity(conversationId, item) {
322
+ this.rememberConversationId(conversationId);
323
+ const normalized = normalizeRuntimeActivityItem(item);
324
+ if (!normalized.id) {
325
+ throw new Error('Runtime activity item id is required.');
326
+ }
327
+ await this.requireRuntimeStatePublisher().writeRuntimeActivity(conversationId, normalized);
328
+ }
329
+ async clearRuntimeActivity(conversationId, options) {
330
+ this.rememberConversationId(conversationId);
331
+ await this.requireRuntimeStatePublisher().clearRuntimeActivity(conversationId, options);
332
+ }
286
333
  /**
287
334
  * Resolve admission live for a target user (typically read off a shared
288
335
  * contact card) and route into either an immediate message or a contact
@@ -844,6 +891,13 @@ export class CanonAgent {
844
891
  hostMode: false,
845
892
  });
846
893
  }
894
+ requireRuntimeStatePublisher() {
895
+ const publisher = this.createRuntimeStatePublisher();
896
+ if (!publisher) {
897
+ throw new Error('Canon agent must be started before publishing runtime operations.');
898
+ }
899
+ return publisher;
900
+ }
847
901
  async handleMessages(conversationId, messages) {
848
902
  if (!this.handler) {
849
903
  console.warn(`[canon-sdk] No message handler registered — messages for ${conversationId} dropped. Call agent.on('message', handler) before starting.`);
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { CanonAgent } from './canon-agent.js';
2
2
  export type { AgentContactsAPI, AgentUsersAPI } from './canon-agent.js';
3
3
  export { CanonApiError, HOST_ADMISSION_ACTION_CAPABILITIES, HOST_ADMISSION_ACTIONS_DISABLED, } from '@canonmsg/core';
4
- export type { CanonContact, CanonResolveAdmissionResult, ContactAddedPayload, ContactCardPayload, ContactRemovedPayload, ContactSource, HostAdmissionActionCapabilities, ResolvedAdmissionState, ResolvedAdmissionTargetSummary, ResolvedTargetAdmissionPayload, } from '@canonmsg/core';
4
+ export type { CanonContact, CanonRuntimeActivityItem, CanonRuntimeActivityKind, CanonRuntimeActivityStatus, CanonRuntimeFact, CanonRuntimeFactGroup, CanonResolveAdmissionResult, ContactAddedPayload, ContactCardPayload, ContactRemovedPayload, ContactSource, HostAdmissionActionCapabilities, ResolvedAdmissionState, ResolvedAdmissionTargetSummary, ResolvedTargetAdmissionPayload, } from '@canonmsg/core';
5
5
  export { SessionManager } from './session-manager.js';
6
6
  export { DEFAULT_MEDIA_CACHE_DIR, getCodexImagePath, getMessageAttachments, inferUploadMimeType, isAnthropicImageAttachment, materializeAttachment, materializeMessageMedia, resolveAttachmentMimeType, sendMediaFileMessage, toAnthropicImageBlock, uploadMediaFile, } from './media.js';
7
7
  export type { AnthropicImageBlock, AnthropicImageMimeType, MaterializeMediaOptions, MaterializedCanonAttachment, ReplyWithFileOptions, UploadMediaFileOptions, } from './media.js';
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { AddMemberResult, AgentClientType, CanonGroupContext, CanonRuntimeDescriptor, CanonRuntimePrimitiveId, CanonMessage, CanonConversation, CanonContact, CanonContactRequest, CanonResolveAdmissionResult, ContactAddedPayload, ContactRemovedPayload, ContactSource, AgentContext, ResolvedAdmissionState, ResolvedAdmissionTargetSummary, ResolvedTargetAdmissionPayload, CanonSelfContext, SendContextualMessageOptions, SendContextualMessageResult, SendContextualSelfContextInput, SendMessageOptions, SessionConfig, CreateConversationOptions, TurnLifecycleState, } from '@canonmsg/core';
1
+ export type { AddMemberResult, AgentClientType, CanonGroupContext, CanonRuntimeActivityItem, CanonRuntimeActivityKind, CanonRuntimeActivityStatus, CanonRuntimeDescriptor, CanonRuntimeFact, CanonRuntimeFactGroup, CanonRuntimePrimitiveId, CanonMessage, CanonConversation, CanonContact, CanonContactRequest, CanonResolveAdmissionResult, ContactAddedPayload, ContactRemovedPayload, ContactSource, AgentContext, ResolvedAdmissionState, ResolvedAdmissionTargetSummary, ResolvedTargetAdmissionPayload, CanonSelfContext, SendContextualMessageOptions, SendContextualMessageResult, SendContextualSelfContextInput, SendMessageOptions, SessionConfig, CreateConversationOptions, TurnLifecycleState, } from '@canonmsg/core';
2
2
  import type { AddMemberResult, CanonGroupContext, CanonMessage, CanonConversation, ContactCardPayload, CanonRuntimeActionDispatch, CanonRuntimePrimitiveId, SendMessageOptions, SendContextualSelfContextInput, SessionConfig } from '@canonmsg/core';
3
3
  import type { MaterializeMediaOptions, MaterializedCanonAttachment, ReplyWithFileOptions, UploadMediaFileOptions } from './media.js';
4
4
  export interface ProgressMessageOptions extends SendMessageOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonmsg/agent-sdk",
3
- "version": "1.3.1",
3
+ "version": "1.4.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": "^0.17.2"
31
+ "@canonmsg/core": "^0.18.0"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"