@canonmsg/agent-sdk 13.1.0 → 13.2.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.
@@ -2,20 +2,20 @@ import {
2
2
  WASM_HOST_CONFIGURE,
3
3
  WASM_HOST_PROVISION,
4
4
  keyFile
5
- } from "./chunks/chunk-DTAWEQCM.js";
5
+ } from "./chunks/chunk-POBMFS2K.js";
6
6
  import {
7
7
  MAX_INPUT,
8
8
  NodeMlsDevCustodyError,
9
9
  parseFrame,
10
10
  rejected,
11
11
  requireValue
12
- } from "./chunks/chunk-YJUPKU47.js";
12
+ } from "./chunks/chunk-BPSFHEAA.js";
13
13
  import {
14
14
  __name,
15
15
  canonicalEndpointJson,
16
16
  isMlsDevReceiptClockSkew,
17
17
  parseMlsDevDeviceContext
18
- } from "./chunks/chunk-5WPAB5MB.js";
18
+ } from "./chunks/chunk-VIS5WXNH.js";
19
19
 
20
20
  // src/mls-wasm-host.ts
21
21
  import { createHash } from "node:crypto";
@@ -95,8 +95,8 @@ export declare function awaitErrand(directory: string, command: Pick<ErrandComma
95
95
  accepted: boolean;
96
96
  }>;
97
97
  export interface ErrandHandler {
98
- /** The command was taken already (its record or its journaled output exists): its file is only removed. */
99
- taken(id: string): boolean;
98
+ /** The command was taken already (its record or its saved output exists): its file is only removed. */
99
+ taken(id: string): boolean | Promise<boolean>;
100
100
  /**
101
101
  * The command, or why its file is refused. True once its effect (or refusal) is journaled, so the file may go; false
102
102
  * leaves it for the next scan. A throw is logged once per command and reason, and also leaves it.
@@ -102,7 +102,12 @@ export interface Runner {
102
102
  start(): Promise<void>;
103
103
  /** Stops intake, releases unsubmitted input, lets running turns finish within the shutdown grace. */
104
104
  stop(): Promise<void>;
105
- /** A proactive send outside any turn (cron): the `communicate` tool's handler, under the runner's identity. */
105
+ /**
106
+ * A proactive send outside any turn (cron), under the runner's identity, with the `communicate` tool's input. Text to a
107
+ * conversation is encrypted for the members it has now, journaled first and sent once, even across a restart; a new
108
+ * conversation is founded encrypted by this device. `messageId` makes a retry the same message or start. Other actions
109
+ * go to Canon as they are.
110
+ */
106
111
  communicate(input: CommunicateInput): Promise<CommunicateResult>;
107
112
  /** What the runner has in hand now, for a host's idle policy (agent-wake.md). Only between start and stop. */
108
113
  activity(): Promise<RunnerActivity>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonmsg/agent-sdk",
3
- "version": "13.1.0",
3
+ "version": "13.2.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",
@@ -31,8 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@modelcontextprotocol/sdk": "^1.30.0",
34
- "@noble/curves": "2.4.0",
35
- "chess.js": "1.4.0"
34
+ "@noble/curves": "2.4.0"
36
35
  },
37
36
  "peerDependencies": {
38
37
  "@anthropic-ai/claude-agent-sdk": "^0.3.289"
@@ -1,34 +0,0 @@
1
- /**
2
- * A runtime's finished turn output, saved before it is published so a host that
3
- * dies between the native result and Canon delivery replays exactly that
4
- * output on restart instead of losing it, and never runs the turn again.
5
- */
6
- export interface CompletedOutputRecordBase {
7
- version: 1;
8
- turnId: string;
9
- conversationId: string;
10
- createdAt: string;
11
- /** Who could read the conversation when the output was produced. */
12
- audience: {
13
- memberIds: string[];
14
- membershipRevision?: number;
15
- } | null;
16
- }
17
- export interface CompletedOutputJournal<T extends CompletedOutputRecordBase> {
18
- /** Durably save a record; saving the identical record again is a no-op, a different one is refused. */
19
- save(record: T): void;
20
- /** Every saved record, oldest first, after recovering writes a crash interrupted. */
21
- list(): T[];
22
- remove(turnId: string): void;
23
- }
24
- /**
25
- * Atomic, fsynced, one file per turn under a folder keyed by `scope` (runtime,
26
- * environment, principal, ownership generation, installation), so a transferred
27
- * agent or another installation never sees these plaintext records.
28
- */
29
- export declare function createCompletedOutputJournal<T extends CompletedOutputRecordBase>(directory: string, scope: unknown, options: {
30
- /** Names the runtime in errors, e.g. `Codex`. */
31
- label: string;
32
- /** Runtime-specific shape check beyond the base fields; false is an invalid record. */
33
- validate?: (record: T) => boolean;
34
- }): CompletedOutputJournal<T>;
@@ -1,60 +0,0 @@
1
- import { type ArtifactImageRegion, type ArtifactImageVariant, type MediaAttachment } from '../backend-contracts/index.js';
2
- import type { Endpoint } from './engine.js';
3
- import { type ArtifactClient, type ArtifactWriteResult } from './artifacts.js';
4
- import { isTerminalImageGenerationError } from './image-generation-errors.js';
5
- export { isTerminalImageGenerationError };
6
- export type { ArtifactImageRegion };
7
- export interface ArtifactImageGenerateInput {
8
- prompt: string;
9
- label: string;
10
- /** 'current' edits the current version (or generates new when there is none). */
11
- from: 'current' | 'new' | {
12
- variantId: string;
13
- };
14
- /** Fractions of the source image, origin top-left. */
15
- region?: ArtifactImageRegion;
16
- /** UUID for one deliberate generation; reuse it to collect the same result. */
17
- requestId: string;
18
- /** Cancels the wait. Once the job is submitted, the result is `generating` and nothing is published. */
19
- signal?: AbortSignal;
20
- /** How long to wait for the provider before returning `generating` (default 180 s). */
21
- timeoutMs?: number;
22
- }
23
- export type ArtifactImageGenerateResult = {
24
- status: 'added';
25
- variant: ArtifactImageVariant;
26
- result: ArtifactWriteResult;
27
- attachment: MediaAttachment;
28
- } | {
29
- status: 'generating';
30
- requestId: string;
31
- };
32
- export interface ArtifactImageAddInput {
33
- assetId: string;
34
- label: string;
35
- prompt?: string;
36
- sourceVariantId?: string;
37
- select?: boolean;
38
- }
39
- export interface ArtifactImageClient {
40
- generate(conversationId: string, artifactId: string, input: ArtifactImageGenerateInput): Promise<ArtifactImageGenerateResult>;
41
- add(conversationId: string, artifactId: string, input: ArtifactImageAddInput): Promise<{
42
- variant: ArtifactImageVariant;
43
- result: ArtifactWriteResult;
44
- }>;
45
- }
46
- /** Test hooks; production uses the defaults. */
47
- export interface ArtifactImageClientOptions {
48
- pollIntervalMs?: number;
49
- /** A job may not be visible yet while its request is still being delivered. */
50
- notFoundGraceMs?: number;
51
- now?: () => number;
52
- sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
53
- }
54
- /**
55
- * The provider runs on the server under a durable `image-generation:<requestId>`
56
- * operation; this client only waits for its result, retains it, and adds it as
57
- * the current version. Repeating a call with the same requestId collects the
58
- * same image and never starts a second generation.
59
- */
60
- export declare function createArtifactImageClient(endpoint: Endpoint, artifacts?: ArtifactClient, options?: ArtifactImageClientOptions): ArtifactImageClient;
@@ -1,35 +0,0 @@
1
- import { type ArtifactCommandRecord, type ArtifactFormValue, type ArtifactReadResult, type ArtifactSnapshot } from '../backend-contracts/index.js';
2
- /**
3
- * Integrity failures halt replay: a sequence gap, a changed artifact identity,
4
- * an unsupported codec, or an envelope written by a newer Canon. Nothing else does.
5
- */
6
- export declare class ArtifactReplayError extends Error {
7
- readonly code: 'UNSUPPORTED_VERSION' | 'ARTIFACT_LOG_INVALID';
8
- constructor(code: 'UNSUPPORTED_VERSION' | 'ARTIFACT_LOG_INVALID', message: string);
9
- }
10
- /** FEN without the half-move and full-move clocks. */
11
- export declare const chessPositionKey: (fen: string) => string;
12
- /** A form value that changed since the author looked. */
13
- export interface ArtifactConflict {
14
- path: string[];
15
- label: string;
16
- expected: ArtifactFormValue;
17
- current: ArtifactFormValue;
18
- currentBy?: string;
19
- }
20
- /** Structured conflicts of a form command (form.set or form.fields) against the snapshot it was judged on. */
21
- export declare function artifactCommandConflicts(snapshot: ArtifactSnapshot, command: unknown): ArtifactConflict[];
22
- /** Structured conflicts of form.set changes against the snapshot they were judged on. */
23
- export declare function artifactFormConflicts(snapshot: ArtifactSnapshot, changes: unknown): ArtifactConflict[];
24
- /** Pure reduction of one relay record. Throws only for integrity halts. */
25
- export declare function reduceArtifactRecord(previous: ArtifactReadResult, record: ArtifactCommandRecord, conversationId: string): ArtifactReadResult;
26
- export interface ArtifactReplayPage {
27
- previous: ArtifactReadResult;
28
- commands: ArtifactCommandRecord[];
29
- conversationId: string;
30
- artifactId: string;
31
- /** Stop once this revision is reached (historical read). */
32
- revisionId?: string;
33
- }
34
- /** In-process replay of one log page. Built-in rules only: bounded and synchronous. */
35
- export declare function replayArtifactPage(page: ArtifactReplayPage): ArtifactReadResult;
@@ -1,113 +0,0 @@
1
- import { type ArtifactChessState, type ArtifactFormColumn, type ArtifactFormFieldType, type ArtifactFormRow, type ArtifactFormValue, type ArtifactKind, type ArtifactSnapshot } from '../backend-contracts/index.js';
2
- /** Readable projections of shared work for agents, prompts and compact UI. */
3
- export interface ArtifactPrincipalView {
4
- id: string;
5
- name?: string;
6
- isYou?: boolean;
7
- }
8
- export interface ArtifactViewOptions {
9
- /** The principal reading the view (marks `isYou`, seats and turn). */
10
- viewerId?: string;
11
- names?: Record<string, string>;
12
- /** The snapshot this viewer saw last; adds `changesSinceLastView`. */
13
- previous?: ArtifactSnapshot;
14
- }
15
- export interface ArtifactViewBase {
16
- artifactId: string;
17
- kind: ArtifactKind;
18
- title: string;
19
- revisionId: string;
20
- archived: boolean;
21
- createdBy: ArtifactPrincipalView;
22
- updatedBy: ArtifactPrincipalView;
23
- updatedAt: string;
24
- }
25
- export interface ArtifactChessMoveView {
26
- ply: number;
27
- notation: string;
28
- san: string;
29
- by: ArtifactPrincipalView;
30
- }
31
- export interface ArtifactChessView extends ArtifactViewBase {
32
- kind: 'chess';
33
- fen: string;
34
- /** ASCII, rank 8 first, uppercase White, with file and rank labels. */
35
- board: string;
36
- turn: 'white' | 'black';
37
- /** Full-move number. */
38
- moveNumber: number;
39
- /** e.g. "1. e4 e5 2. Nf3". */
40
- moveList: string;
41
- lastMove?: ArtifactChessMoveView;
42
- players: {
43
- white?: ArtifactPrincipalView;
44
- black?: ArtifactPrincipalView;
45
- };
46
- yourColor?: 'white' | 'black';
47
- yourTurn: boolean;
48
- status: ArtifactChessState['status'];
49
- result?: ArtifactChessState['result'];
50
- resignedBy?: ArtifactPrincipalView;
51
- check: boolean;
52
- /** SAN, while the game is active. */
53
- legalMoves?: string[];
54
- /** Moves since the previous view. */
55
- changesSinceLastView?: ArtifactChessMoveView[];
56
- }
57
- export interface ArtifactFormFieldView {
58
- id: string;
59
- label: string;
60
- type: ArtifactFormFieldType;
61
- value: ArtifactFormValue;
62
- required?: boolean;
63
- options?: string[];
64
- placeholder?: string;
65
- help?: string;
66
- decimals?: number;
67
- }
68
- export interface ArtifactFormChangeView {
69
- label: string;
70
- path: string[];
71
- before: ArtifactFormValue | Record<string, ArtifactFormValue>;
72
- after: ArtifactFormValue | Record<string, ArtifactFormValue>;
73
- }
74
- export interface ArtifactFormView extends ArtifactViewBase {
75
- kind: 'form';
76
- fields: ArtifactFormFieldView[];
77
- /** Labels of required fields that are empty. */
78
- missingRequired: string[];
79
- /**
80
- * `sums` holds each summed column's total, rounded to the column's decimals.
81
- * Form numbers are bounded, so a total is always finite; a total that is not
82
- * (state written outside the shared rules) reads as null instead of failing.
83
- */
84
- table?: {
85
- label?: string;
86
- columns: ArtifactFormColumn[];
87
- rows: ArtifactFormRow[];
88
- sums: Record<string, number | null>;
89
- };
90
- changesSinceLastView?: ArtifactFormChangeView[];
91
- }
92
- export interface ArtifactImageVariantView {
93
- id: string;
94
- label: string;
95
- prompt?: string;
96
- by: ArtifactPrincipalView;
97
- at: string;
98
- sourceVariantId?: string;
99
- assetId: string;
100
- current: boolean;
101
- }
102
- export interface ArtifactImageView extends ArtifactViewBase {
103
- kind: 'image';
104
- variants: ArtifactImageVariantView[];
105
- currentVariantId?: string;
106
- /** Versions added since the previous view. */
107
- changesSinceLastView?: ArtifactImageVariantView[];
108
- }
109
- export type ArtifactView = ArtifactChessView | ArtifactFormView | ArtifactImageView;
110
- export declare function chessBoardAscii(fen: string): string;
111
- export declare function describeArtifact(snapshot: ArtifactSnapshot, options?: ArtifactViewOptions): ArtifactView;
112
- /** One line, viewer-relative: "Chess “Game”: move 12, Black to move (you play Black). Your move. Last: 11...Nf6 by Alice." */
113
- export declare function summarizeArtifact(snapshot: ArtifactSnapshot, options?: Omit<ArtifactViewOptions, 'previous'>): string;
@@ -1,75 +0,0 @@
1
- import { type ArtifactAsset, type ArtifactCommand, type ArtifactCommandBody, type ArtifactDefinition, type ArtifactDomainOutcome, type ArtifactOutcomeCode, type ArtifactReadResult, type ArtifactSnapshot } from '../backend-contracts/index.js';
2
- import type { Endpoint } from './engine.js';
3
- import { type ArtifactConflict } from './artifact-reducer.js';
4
- /** The command was rejected by the shared rules; nothing new was accepted. */
5
- export declare class ArtifactRejectedError extends Error {
6
- readonly code: ArtifactOutcomeCode | 'UNSUPPORTED_VERSION';
7
- readonly outcome?: ArtifactDomainOutcome;
8
- readonly conflicts?: ArtifactConflict[];
9
- /** The projection the command was evaluated against: the author's fresh state. */
10
- readonly current?: ArtifactReadResult;
11
- constructor(message: string, options: {
12
- code: ArtifactOutcomeCode | 'UNSUPPORTED_VERSION';
13
- outcome?: ArtifactDomainOutcome;
14
- conflicts?: ArtifactConflict[];
15
- current?: ArtifactReadResult;
16
- });
17
- }
18
- /**
19
- * `accepted`: the relay stored the command and the shared rules accepted it.
20
- * `queued`: the durable outbox keeps retrying delivery; snapshot and outcome
21
- * are a local prediction. Callers must not resend.
22
- */
23
- export interface ArtifactWriteResult extends ArtifactReadResult {
24
- outcome: ArtifactDomainOutcome;
25
- status: 'accepted' | 'queued';
26
- }
27
- /** `unavailable` codes include NO_DEFINITION and ARTIFACT_LOADING (a long log still replaying; a later listing has it). */
28
- export interface ArtifactLibrary {
29
- artifacts: ArtifactSnapshot[];
30
- unavailable: Array<{
31
- artifactId: string;
32
- code: string;
33
- message: string;
34
- }>;
35
- }
36
- /** The client stamps the schema; a caller-supplied schema must match it. */
37
- export type ArtifactCommandInput = ArtifactCommandBody | ArtifactCommand;
38
- export interface ArtifactWriteOptions {
39
- commandId?: string;
40
- waitMs?: number;
41
- }
42
- export interface ArtifactCreateOptions {
43
- artifactId?: string;
44
- commandId?: string;
45
- waitMs?: number;
46
- }
47
- export interface ArtifactClientOptions {
48
- encoding?: 'json' | 'mls';
49
- /** How long a listing waits for one work before reporting it as still loading (default 4 s). */
50
- listItemWaitMs?: number;
51
- }
52
- export interface ArtifactClient {
53
- list(conversationId: string): Promise<ArtifactLibrary>;
54
- read(conversationId: string, artifactId: string, options?: {
55
- revisionId?: string;
56
- }): Promise<ArtifactReadResult>;
57
- create(conversationId: string, definition: ArtifactDefinition, options?: ArtifactCreateOptions): Promise<ArtifactWriteResult>;
58
- apply(conversationId: string, artifactId: string, command: ArtifactCommandInput, options?: ArtifactWriteOptions): Promise<ArtifactWriteResult>;
59
- retainAsset(conversationId: string, artifactId: string, assetId: string): Promise<ArtifactAsset>;
60
- getAsset(conversationId: string, artifactId: string, assetId: string): Promise<ArtifactAsset>;
61
- /** Polls the log head only; reads (and replays) when it moves. */
62
- observe(conversationId: string, artifactId: string, listener: (value: ArtifactReadResult) => void, onError?: (error: unknown) => void): () => void;
63
- observeList(conversationId: string, listener: (value: ArtifactLibrary) => void, onError?: (error: unknown) => void): () => void;
64
- /**
65
- * An opaque command ID for one deliberate request: `cmd-` and 40 hex
66
- * characters of an HMAC-SHA256 over the canonical JSON of `material`, keyed
67
- * by this installation's secret. Stable for retries on this installation,
68
- * unrelated elsewhere, and never a server-testable hash of its content.
69
- * Throws PREPARATION_INSTALLATION_FENCED on an endpoint another logout fenced.
70
- */
71
- deriveCommandId(material: unknown[]): Promise<string>;
72
- /** The same derivation (separate domain) as an RFC 4122-shaped UUID, for image request IDs. */
73
- deriveRequestId(material: unknown[]): Promise<string>;
74
- }
75
- export declare function createArtifactClient(endpoint: Endpoint, options?: ArtifactClientOptions): ArtifactClient;