@canonmsg/agent-sdk 12.0.0 → 12.1.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.
Files changed (99) hide show
  1. package/README.md +97 -7
  2. package/dist/chunks/{chunk-FPQFTTND.js → chunk-7N6OPPW4.js} +1616 -1085
  3. package/dist/chunks/chunk-N722GWCP.js +4897 -0
  4. package/dist/chunks/{chunk-OLJ7H4E2.js → chunk-QZ4PPRQW.js} +6462 -6920
  5. package/dist/chunks/{mls-crypto-NZDNSPAO.js → mls-crypto-LMNQZOS6.js} +3 -3
  6. package/dist/cli.js +403 -29
  7. package/dist/drivers/claude.d.ts +8 -2
  8. package/dist/drivers/codex.d.ts +11 -2
  9. package/dist/drivers/connector.d.ts +34 -0
  10. package/dist/index.d.ts +10 -2
  11. package/dist/index.js +26 -4
  12. package/dist/internal/backend-contracts/artifactActions.d.ts +0 -151
  13. package/dist/internal/backend-contracts/clientFloor.d.ts +41 -0
  14. package/dist/internal/backend-contracts/communication.d.ts +15 -0
  15. package/dist/internal/backend-contracts/connectorRelay.d.ts +179 -0
  16. package/dist/internal/backend-contracts/endpoint.d.ts +17 -0
  17. package/dist/internal/backend-contracts/endpointContentPolicy.d.ts +15 -4
  18. package/dist/internal/backend-contracts/index.d.ts +7 -1
  19. package/dist/internal/backend-contracts/media-url.d.ts +14 -0
  20. package/dist/internal/backend-contracts/message.d.ts +1 -1
  21. package/dist/internal/backend-contracts/mlsDevApplication.d.ts +90 -2
  22. package/dist/internal/backend-contracts/mlsDevCredential.d.ts +5 -2
  23. package/dist/internal/backend-contracts/mlsDevDeviceCustody.d.ts +2 -1
  24. package/dist/internal/backend-contracts/mlsDevEnrollment.d.ts +3 -2
  25. package/dist/internal/backend-contracts/mlsDevFeedReceipt.d.ts +43 -0
  26. package/dist/internal/backend-contracts/mlsDevGroup.d.ts +129 -5
  27. package/dist/internal/backend-contracts/mlsDevGroupFeed.d.ts +6 -2
  28. package/dist/internal/backend-contracts/mlsDevInteraction.d.ts +159 -0
  29. package/dist/internal/backend-contracts/mlsEnvironment.d.ts +35 -0
  30. package/dist/internal/backend-contracts/mlsPrincipalAlias.d.ts +23 -0
  31. package/dist/internal/backend-contracts/runtimeCardFields.d.ts +2 -2
  32. package/dist/internal/backend-contracts/upload-mime-types.d.ts +17 -0
  33. package/dist/internal/backend-contracts/verbContract.d.ts +15 -7
  34. package/dist/internal/backend-contracts/verbSchemas.d.ts +35 -25
  35. package/dist/internal/core/agent-profiles.d.ts +0 -4
  36. package/dist/internal/core/approval-format.d.ts +1 -5
  37. package/dist/internal/core/approval-types.d.ts +1 -2
  38. package/dist/internal/core/client.d.ts +2 -56
  39. package/dist/internal/core/constants.d.ts +0 -3
  40. package/dist/internal/core/endpoint-client.d.ts +14 -1
  41. package/dist/internal/core/execution-environment-mode.d.ts +0 -2
  42. package/dist/internal/core/gifs.d.ts +0 -6
  43. package/dist/internal/core/host-runtime.d.ts +2 -206
  44. package/dist/internal/core/index.d.ts +21 -60
  45. package/dist/internal/core/registration.d.ts +1 -17
  46. package/dist/internal/core/retry.d.ts +0 -9
  47. package/dist/internal/core/rtdb-rest.d.ts +0 -4
  48. package/dist/internal/core/runtime-cards.d.ts +0 -45
  49. package/dist/internal/core/runtime-descriptor.d.ts +1 -60
  50. package/dist/internal/core/runtime-presentation.d.ts +1 -27
  51. package/dist/internal/core/runtime-request-manager.d.ts +0 -1
  52. package/dist/internal/core/self-context.d.ts +0 -39
  53. package/dist/internal/core/silent-turn.d.ts +1 -38
  54. package/dist/internal/core/stream.d.ts +2 -1
  55. package/dist/internal/core/turn-protocol.d.ts +0 -5
  56. package/dist/internal/core/turn-verbosity.d.ts +0 -12
  57. package/dist/internal/core/types.d.ts +0 -111
  58. package/dist/internal/endpoint/engine.d.ts +31 -1
  59. package/dist/internal/endpoint/index.d.ts +1 -1
  60. package/dist/internal/endpoint/media.d.ts +5 -0
  61. package/dist/internal/endpoint/mls-crypto.d.ts +12 -5
  62. package/dist/internal/endpoint/mls-dev-client.d.ts +9 -1
  63. package/dist/internal/endpoint/mls-dev-device.d.ts +2 -0
  64. package/dist/internal/endpoint/mls-dev-groups.d.ts +65 -5
  65. package/dist/internal/endpoint/mls-dev-interactions.d.ts +99 -0
  66. package/dist/internal/endpoint/mls-dev-key-package-service.d.ts +13 -0
  67. package/dist/internal/endpoint/mls-dev-key-packages.d.ts +23 -3
  68. package/dist/internal/endpoint/mls-dev-text.d.ts +67 -0
  69. package/dist/internal/endpoint/mls-dev-transport.d.ts +2 -1
  70. package/dist/internal/endpoint/node-mls-custody-protocol.d.ts +5 -0
  71. package/dist/internal/endpoint/transport.d.ts +6 -1
  72. package/dist/media.js +2 -2
  73. package/dist/runner/errands.d.ts +118 -0
  74. package/dist/runner/mls.d.ts +97 -0
  75. package/dist/runner/relay.d.ts +87 -0
  76. package/dist/runner/runner.d.ts +61 -0
  77. package/dist/runner/types.d.ts +51 -4
  78. package/package.json +1 -1
  79. package/dist/chunks/chunk-6VK4UZHJ.js +0 -2806
  80. package/dist/internal/backend-contracts/workSessions.d.ts +0 -205
  81. package/dist/internal/core/agent-resolver.d.ts +0 -49
  82. package/dist/internal/core/agent-session.d.ts +0 -12
  83. package/dist/internal/core/artifacts.d.ts +0 -262
  84. package/dist/internal/core/attached-native-session.d.ts +0 -174
  85. package/dist/internal/core/attached-session-file-store.d.ts +0 -3
  86. package/dist/internal/core/control-poller.d.ts +0 -221
  87. package/dist/internal/core/exclusive-json-file-store.d.ts +0 -7
  88. package/dist/internal/core/execution-environment.d.ts +0 -55
  89. package/dist/internal/core/group-context.d.ts +0 -25
  90. package/dist/internal/core/inbound-frame.d.ts +0 -64
  91. package/dist/internal/core/local-runtime-catalog.d.ts +0 -131
  92. package/dist/internal/core/message-format.d.ts +0 -13
  93. package/dist/internal/core/native-session-interaction.d.ts +0 -44
  94. package/dist/internal/core/provenance.d.ts +0 -31
  95. package/dist/internal/core/registration-cli.d.ts +0 -40
  96. package/dist/internal/core/turn-output-controller.d.ts +0 -69
  97. package/dist/internal/core/typing-status-publisher.d.ts +0 -14
  98. package/dist/internal/core/work-session-provider.d.ts +0 -29
  99. package/dist/internal/core/workspace-discovery.d.ts +0 -17
@@ -1,205 +0,0 @@
1
- /** Private owner/operator workflow. None of this catalog belongs in public runtime descriptors. */
2
- export declare const WORK_SESSION_SCHEMA: "canon.work-sessions.v1";
3
- export declare const WORK_SESSION_LEASE_MS = 90000;
4
- export declare const WORK_SESSION_REQUEST_TTL_MS: number;
5
- export interface WorkSessionChoice {
6
- id: string;
7
- label: string;
8
- description?: string;
9
- }
10
- export interface WorkSessionModelChoice extends WorkSessionChoice {
11
- reasoningEfforts?: WorkSessionChoice[];
12
- defaultReasoningEffort?: string;
13
- }
14
- export interface WorkSessionSettings {
15
- projectId?: string;
16
- modelId?: string;
17
- reasoningEffort?: string;
18
- permissionMode?: string;
19
- executionMode?: string;
20
- }
21
- export type WorkSessionSelection = ({
22
- mode: 'create';
23
- projectId: string;
24
- } & Omit<WorkSessionSettings, 'projectId'>) | ({
25
- mode: 'configure';
26
- projectId: string;
27
- } & Omit<WorkSessionSettings, 'projectId'>) | {
28
- mode: 'attach';
29
- sessionId: string;
30
- };
31
- export interface WorkSessionLoadedSession {
32
- id: string;
33
- title: string;
34
- status: 'idle' | 'running';
35
- settings: WorkSessionSettings;
36
- projectLabel?: string;
37
- modelLabel?: string;
38
- }
39
- export interface WorkSessionCatalog {
40
- revision: string;
41
- provider: string;
42
- canCreate: boolean;
43
- canAttach: boolean;
44
- projects: WorkSessionChoice[];
45
- models?: WorkSessionModelChoice[];
46
- reasoningEfforts?: WorkSessionChoice[];
47
- permissionModes?: WorkSessionChoice[];
48
- executionModes?: WorkSessionChoice[];
49
- defaults?: WorkSessionSettings;
50
- sessions: WorkSessionLoadedSession[];
51
- /** Opt-in extension. Older runtimes may still create or attach native sessions. */
52
- managedSetup?: {
53
- version: 1;
54
- };
55
- }
56
- export interface WorkSessionRuntimeIdentity {
57
- hostId: string;
58
- runtimeEpoch: string;
59
- }
60
- export interface WorkSessionRuntimeLease extends WorkSessionRuntimeIdentity {
61
- /** Agent-only fencing credential. Never expose in the owner catalog or request status. */
62
- leaseToken: string;
63
- expiresAt: number;
64
- }
65
- export interface WorkSessionRuntimeRegistration extends WorkSessionRuntimeIdentity {
66
- displayName: string;
67
- catalog: WorkSessionCatalog;
68
- }
69
- interface WorkSessionBindingBase {
70
- workSessionId: string;
71
- conversationId: string;
72
- hostId: string;
73
- provider: string;
74
- settings: WorkSessionSettings;
75
- createdAt: number;
76
- }
77
- export type WorkSessionBinding = (WorkSessionBindingBase & {
78
- kind?: 'native';
79
- nativeSessionId: string;
80
- }) | (WorkSessionBindingBase & {
81
- kind: 'managed';
82
- nativeSessionId?: never;
83
- });
84
- export interface WorkSessionRuntimeState {
85
- ownerId: string;
86
- lease: WorkSessionRuntimeLease;
87
- bindings: WorkSessionBinding[];
88
- }
89
- export interface WorkSessionCatalogResult {
90
- status: 'available' | 'offline' | 'unavailable';
91
- agentId: string;
92
- hostId?: string;
93
- runtimeEpoch?: string;
94
- displayName?: string;
95
- expiresAt?: number;
96
- catalog?: WorkSessionCatalog;
97
- bindings: WorkSessionBinding[];
98
- }
99
- export interface RequestWorkSessionInput extends WorkSessionRuntimeIdentity {
100
- agentId: string;
101
- conversationId: string;
102
- requestId: string;
103
- catalogRevision: string;
104
- selection: WorkSessionSelection;
105
- }
106
- export type WorkSessionRequestStatus = 'pending' | 'claimed' | 'attached' | 'configured' | 'failed' | 'uncertain' | 'expired';
107
- export interface WorkSessionRequest extends RequestWorkSessionInput {
108
- schema: typeof WORK_SESSION_SCHEMA;
109
- requestedBy: string;
110
- status: WorkSessionRequestStatus;
111
- createdAt: number;
112
- updatedAt: number;
113
- expiresAt: number;
114
- binding?: WorkSessionBinding;
115
- error?: {
116
- code: string;
117
- message: string;
118
- };
119
- }
120
- export type WorkSessionCompletion = {
121
- status: 'attached';
122
- nativeSessionId: string;
123
- settings: WorkSessionSettings;
124
- } | {
125
- status: 'configured';
126
- settings: WorkSessionSettings;
127
- } | {
128
- status: 'failed' | 'uncertain';
129
- error: {
130
- code: string;
131
- message: string;
132
- };
133
- };
134
- export type WorkSessionRuntimeAuth = Pick<WorkSessionRuntimeLease, 'hostId' | 'runtimeEpoch' | 'leaseToken'>;
135
- export interface WorkSessionClaimInput extends WorkSessionRuntimeAuth {
136
- requestId?: string;
137
- }
138
- export interface WorkSessionClaimResult {
139
- request: WorkSessionRequest | null;
140
- /** Previously claimed: reconcile the durable host journal, never blindly execute again. */
141
- replayed: boolean;
142
- }
143
- export interface CompleteWorkSessionInput extends WorkSessionRuntimeAuth {
144
- requestId: string;
145
- result: WorkSessionCompletion;
146
- }
147
- export interface WorkSessionHeartbeatInput extends WorkSessionRuntimeAuth {
148
- catalog?: WorkSessionCatalog;
149
- }
150
- export interface ReleaseWorkSessionBindingInput extends WorkSessionRuntimeAuth {
151
- conversationId: string;
152
- workSessionId: string;
153
- }
154
- export interface ResolveWorkSessionRequestInput {
155
- agentId: string;
156
- requestId: string;
157
- }
158
- export interface GetWorkSessionRequestInput {
159
- agentId: string;
160
- /** Exactly one selector. Conversation lookup recovers the latest operation after reload. */
161
- requestId?: string;
162
- conversationId?: string;
163
- }
164
- export interface GetWorkSessionDetailsInput {
165
- agentId: string;
166
- conversationId: string;
167
- }
168
- export type WorkSessionDetailField = keyof WorkSessionSettings | 'projectLabel' | 'workingDirectory' | 'branch' | 'worktreePath' | 'sandbox' | 'approvalPolicy' | 'nativeThreadBehavior';
169
- export interface WorkSessionDetailValue {
170
- value: string;
171
- provenance: 'configured' | 'observed';
172
- }
173
- export type WorkSessionDetailFields = Partial<Record<WorkSessionDetailField, WorkSessionDetailValue>>;
174
- /** Host supplied private facts. The server stamps reportedAt and checks the current lease and membership. */
175
- export interface WorkSessionReportInput extends WorkSessionRuntimeAuth {
176
- conversationId: string;
177
- workSessionId?: string;
178
- setupState?: 'configured' | 'attached';
179
- fields: WorkSessionDetailFields;
180
- }
181
- export interface WorkSessionDetailsResult {
182
- status: 'available' | 'offline' | 'unavailable';
183
- agentId: string;
184
- conversationId: string;
185
- setupState: 'unconfigured' | 'pending' | 'configured' | 'attached' | 'failed' | 'uncertain';
186
- hostId?: string;
187
- displayName?: string;
188
- expiresAt?: number;
189
- binding?: WorkSessionBinding;
190
- selection?: WorkSessionSelection;
191
- fields: WorkSessionDetailFields;
192
- reportedAt?: number;
193
- }
194
- export declare function workSessionId(value: unknown, label?: string): string;
195
- export declare function parseWorkSessionSettings(value: unknown): WorkSessionSettings;
196
- export declare function parseWorkSessionCatalog(value: unknown): WorkSessionCatalog;
197
- export declare function parseWorkSessionSelection(value: unknown): WorkSessionSelection;
198
- export declare function assertWorkSessionSelectionAvailable(selection: WorkSessionSelection, catalog: WorkSessionCatalog): void;
199
- export declare function parseWorkSessionRuntimeRegistration(value: unknown): WorkSessionRuntimeRegistration;
200
- export declare function parseWorkSessionRuntimeAuth(value: unknown, extraKeys?: string[]): WorkSessionRuntimeAuth;
201
- export declare function parseRequestWorkSessionInput(value: unknown): RequestWorkSessionInput;
202
- export declare function parseWorkSessionCompletion(value: unknown): WorkSessionCompletion;
203
- export declare function parseWorkSessionDetailFields(value: unknown): WorkSessionDetailFields;
204
- export declare function parseWorkSessionReportInput(value: unknown): WorkSessionReportInput;
205
- export {};
@@ -1,49 +0,0 @@
1
- /**
2
- * Unified agent resolution — resolves Canon agent credentials from
3
- * environment variables or ~/.canon/agents.json profiles.
4
- *
5
- * Used by the Claude Code plugin (host.ts, server.ts) and available
6
- * for any future agent integration.
7
- *
8
- * Resolution order:
9
- * 1. CANON_API_KEY env var (highest priority, no lock)
10
- * 2. CANON_AGENT env var (named profile with lock)
11
- * 3. Auto-select from profiles (first unlocked, with lock)
12
- */
13
- import { type ProfileLockHandle } from './agent-profiles.js';
14
- import type { CanonEnvironmentId } from '../backend-contracts/index.js';
15
- import type { AgentClientType } from './types.js';
16
- export interface ResolvedAgent {
17
- apiKey: string;
18
- agentId?: string;
19
- profile: string | null;
20
- agentName?: string;
21
- clientType?: AgentClientType;
22
- environmentId: CanonEnvironmentId;
23
- baseUrl: string;
24
- streamUrl: string;
25
- rtdbUrl: string;
26
- firebaseApiKey: string;
27
- lockHandle?: ProfileLockHandle;
28
- }
29
- export declare function verifyResolvedAgentEnvironment(resolved: ResolvedAgent): Promise<void>;
30
- /** Get the currently locked profile name (for cleanup on shutdown). */
31
- export declare function getActiveProfile(): string | null;
32
- export declare function getActiveProfileLock(): ProfileLockHandle | null;
33
- export declare function resolveCanonProfile(name: string, opts?: {
34
- logPrefix?: string;
35
- lock?: boolean;
36
- expectedClientType?: AgentClientType;
37
- }): ResolvedAgent;
38
- /**
39
- * Resolve Canon agent credentials.
40
- *
41
- * @param opts.logPrefix - Log prefix for console messages (default: '[canon]')
42
- * @returns Resolved agent with API key, optional agentId, and profile name
43
- * @throws Error if no agent can be resolved
44
- */
45
- export declare function resolveCanonAgent(opts?: {
46
- logPrefix?: string;
47
- expectedClientType?: AgentClientType;
48
- lock?: boolean;
49
- }): ResolvedAgent;
@@ -1,12 +0,0 @@
1
- import type { AgentRuntime, AgentSessionSnapshot, SessionState } from './types.js';
2
- import type { TurnState } from './turn-protocol.js';
3
- export interface BuildAgentSessionSnapshotInput {
4
- conversationId: string;
5
- agentId: string;
6
- runtime?: AgentRuntime | null;
7
- sessionState?: SessionState | null;
8
- turnState?: TurnState | null;
9
- lastHeartbeatAt?: number | null;
10
- updatedAt?: number | null;
11
- }
12
- export declare function buildAgentSessionSnapshot(input: BuildAgentSessionSnapshotInput): AgentSessionSnapshot;
@@ -1,262 +0,0 @@
1
- import { type ArtifactActionValue, type ArtifactAsset, type ArtifactCommandBody, type ArtifactCreateAction, type ArtifactDomainOutcome, type ArtifactFormValue, type ArtifactGenerateImageAction, type ArtifactKind, type ArtifactSnapshot, type ArtifactUpdateAction as ArtifactUpdateActionContract, type MediaAttachment } from '../backend-contracts/index.js';
2
- import { ArtifactRejectedError, type ArtifactClient, type ArtifactImageClient, type ArtifactImageVariantView, type ArtifactImageView, type ArtifactLibrary, type ArtifactPrincipalView, type ArtifactView } from '../endpoint/index.js';
3
- import type { CanonMessage } from './types.js';
4
- import type { CanonClient } from './client.js';
5
- /** Form input: numeric text ("12.50") for number fields and "true"/"false" for checkboxes is converted. */
6
- export type ArtifactInputValue = ArtifactActionValue;
7
- /** An `update` action: the shared contract's `ArtifactUpdateAction`. */
8
- export type ArtifactUpdateAction = ArtifactUpdateActionContract;
9
- /**
10
- * A `create` input: the shared contract's flat `ArtifactCreateAction`.
11
- * `playAs` seats this agent; `opponent` (a participant ID) takes the other
12
- * seat. No `playAs` makes an open board.
13
- */
14
- export type ArtifactCreateInput = ArtifactCreateAction;
15
- export interface ArtifactListItem {
16
- artifactId: string;
17
- kind: ArtifactKind;
18
- title: string;
19
- summary: string;
20
- archived: boolean;
21
- updatedAt: string;
22
- }
23
- /** `unavailable` includes `NO_DEFINITION` work and `ARTIFACT_LOADING` work whose long history is still replaying (list again shortly). */
24
- export interface ArtifactList {
25
- items: ArtifactListItem[];
26
- unavailable: ArtifactLibrary['unavailable'];
27
- }
28
- /**
29
- * `delivery: 'queued'`: the durable outbox is still delivering the change and
30
- * the view is a prediction; do not resend. (Not `status`: a chess view's
31
- * `status` is the game's.) `alreadyApplied`: this identical change was already
32
- * made for the same request; nothing new was applied. The view shows the work
33
- * as it is now, with what others changed, but it does not move the base: the
34
- * next change is still judged against what this client saw before.
35
- */
36
- export type ArtifactWriteView<V extends ArtifactView = ArtifactView> = V & {
37
- delivery: 'accepted' | 'queued';
38
- alreadyApplied?: true;
39
- };
40
- export type ArtifactUpdateResult = ArtifactWriteView & {
41
- addedRowIds?: string[];
42
- };
43
- /** The shared contract's generate action (`from` 'current' is the work's current version) plus call options. */
44
- export interface ArtifactGenerateImageInput extends ArtifactGenerateImageAction {
45
- /** Repeating a call with the same key and input collects the same generation. */
46
- requestKey?: string;
47
- /** Cancels the wait. A job already submitted keeps running: the result is `generating`. */
48
- signal?: AbortSignal;
49
- timeoutMs?: number;
50
- }
51
- export type ArtifactGenerateImageResult = {
52
- status: 'added';
53
- view: ArtifactWriteView<ArtifactImageView>;
54
- variant: ArtifactImageVariantView;
55
- attachment: MediaAttachment;
56
- } | {
57
- status: 'generating';
58
- requestId: string;
59
- };
60
- /** Exactly one source: a local JPEG/PNG file, a retained Canon upload, or an image attached to a message. */
61
- export interface ArtifactAddImageInput {
62
- label: string;
63
- prompt?: string;
64
- sourceVariantId?: string;
65
- /** Default true: the version becomes current (an image the work already holds is made current again). */
66
- select?: boolean;
67
- filePath?: string;
68
- assetId?: string;
69
- messageId?: string;
70
- /** Index into the message's attachments; defaults to its first image. */
71
- attachmentIndex?: number;
72
- /**
73
- * With `messageId` and no `attachmentIndex`: the message whose image is used
74
- * when `messageId`'s message has none (for example the message it replies to).
75
- */
76
- fallbackMessageId?: string;
77
- requestKey?: string;
78
- signal?: AbortSignal;
79
- }
80
- export interface ArtifactAddImageResult {
81
- view: ArtifactWriteView<ArtifactImageView>;
82
- variant: ArtifactImageVariantView;
83
- }
84
- export interface ArtifactConflictView {
85
- path: string[];
86
- label: string;
87
- expected: ArtifactFormValue;
88
- current: ArtifactFormValue;
89
- currentBy?: ArtifactPrincipalView;
90
- }
91
- export type CanonArtifactErrorCode = ArtifactRejectedError['code'] | 'NOT_READ' | 'NOT_FOUND' | 'MESSAGE_NOT_FOUND' | 'INVALID_INPUT';
92
- /**
93
- * A change the shared rules (or local input checks) refused. Nothing new was
94
- * accepted. For a rejection evaluated against the current work, `view` is that
95
- * fresh state (with `changesSinceLastView`). Only a `CONFLICT` makes it the
96
- * new last-seen base (decide again); any other rejection leaves the base where
97
- * it was. Form conflicts are listed in `conflicts`.
98
- */
99
- export declare class CanonArtifactError extends Error {
100
- readonly code: CanonArtifactErrorCode;
101
- readonly outcome?: ArtifactDomainOutcome;
102
- readonly conflicts?: ArtifactConflictView[];
103
- readonly view?: ArtifactView;
104
- constructor(message: string, options: {
105
- code: CanonArtifactErrorCode;
106
- outcome?: ArtifactDomainOutcome;
107
- conflicts?: ArtifactConflictView[];
108
- view?: ArtifactView;
109
- cause?: unknown;
110
- });
111
- }
112
- /** Shared work in one conversation (SDK `ctx.artifacts`). */
113
- export interface CanonConversationArtifacts {
114
- readonly conversationId: string;
115
- list(): Promise<ArtifactList>;
116
- /** The current state (records it as last seen), or an earlier revision (read-only, not recorded). */
117
- describe(artifactId: string, options?: {
118
- revisionId?: string;
119
- }): Promise<ArtifactView>;
120
- /**
121
- * One viewer-relative line about the current state. Chess and image work
122
- * become the base of the next change (the line shows enough to act on), but
123
- * not "read": the next `describe` still lists the changes since the last
124
- * read or write. A form never becomes the base here (its values are not in
125
- * the line), so a change to it still needs a read.
126
- */
127
- summarize(artifactId: string, options?: {
128
- signal?: AbortSignal;
129
- }): Promise<string>;
130
- create(input: ArtifactCreateInput, options?: {
131
- requestKey?: string;
132
- }): Promise<ArtifactWriteView>;
133
- update(artifactId: string, action: ArtifactUpdateAction, options?: {
134
- basedOnRevisionId?: string;
135
- requestKey?: string;
136
- }): Promise<ArtifactUpdateResult>;
137
- generateImage(artifactId: string, input: ArtifactGenerateImageInput): Promise<ArtifactGenerateImageResult>;
138
- addImage(artifactId: string, input: ArtifactAddImageInput): Promise<ArtifactAddImageResult>;
139
- getAsset(artifactId: string, assetId: string): Promise<ArtifactAsset>;
140
- /** Live views of one work (each recorded as last seen). */
141
- observe(artifactId: string, listener: (view: ArtifactView) => void, onError?: (error: unknown) => void): () => void;
142
- observeList(listener: (list: ArtifactList) => void, onError?: (error: unknown) => void): () => void;
143
- }
144
- /** Declared MIME types an image version may have (JPEG or PNG), lower case. */
145
- export declare const ARTIFACT_IMAGE_MIME_TYPES: ReadonlySet<string>;
146
- /** The image type from the bytes themselves (PNG or JPEG signature); anything else is undefined. */
147
- export declare function sniffArtifactImageType(bytes: Uint8Array): 'image/jpeg' | 'image/png' | undefined;
148
- type ArtifactIntent = {
149
- commandId: string;
150
- command: ArtifactCommandBody;
151
- addedRowIds: string[];
152
- resultRevisionId: string;
153
- }
154
- /** `attempts` rejected sends so far; the next deliberate repeat uses a fresh command ID. */
155
- | {
156
- commandId: string;
157
- rejected: true;
158
- attempts: number;
159
- };
160
- /**
161
- * Per-client memory: per conversation's work, the base of the next change and
162
- * the last snapshot shown in full (what changesSinceLastView is relative to);
163
- * keyed intents; and participant names. Keys are local only, never sent.
164
- */
165
- export declare class ArtifactMemory {
166
- private readonly seen;
167
- private ticks;
168
- private readonly rooms;
169
- /** Keyed changes this client issued: what each one led to. */
170
- private readonly intents;
171
- /** Generations still running, by what was asked (not by turn): a later call with the same arguments collects them. */
172
- private readonly generating;
173
- /** Terminal generation failures per request and arguments: a repeat starts a fresh generation. */
174
- private readonly generationFailures;
175
- intent(key: string): ArtifactIntent | undefined;
176
- rememberIntent(key: string, intent: ArtifactIntent): void;
177
- pendingGeneration(key: string): string | undefined;
178
- /** `undefined` once the generation was collected or failed. */
179
- rememberGeneration(key: string, requestId: string | undefined): void;
180
- generationAttempts(key: string): number;
181
- recordGenerationFailure(key: string): void;
182
- /** The base of the next change. */
183
- lastSeen(conversationId: string, artifactId: string): ArtifactSnapshot | undefined;
184
- /** The last full view (read, write, conflict or observation): what diffs are relative to. */
185
- lastShown(conversationId: string, artifactId: string): ArtifactSnapshot | undefined;
186
- /** Taken when an operation begins; pass it to `remember` with the operation's result. */
187
- mark(): number;
188
- /**
189
- * Record what this client last showed of the work. A newer sequence always
190
- * wins. An older one wins only for an operation (`since` = its `mark()`)
191
- * that began after the last record: a fresh read then replaces a queued
192
- * write's prediction that never landed, or a log that was replaced, while a
193
- * slow read that raced a newer write cannot regress the base. Observer
194
- * deliveries (no `since`) never move back. `baseOnly` (a prompt summary)
195
- * moves the base but keeps the diff baseline.
196
- */
197
- remember(snapshot: ArtifactSnapshot, since?: number, options?: {
198
- baseOnly?: boolean;
199
- }): void;
200
- room(conversationId: string): {
201
- names: Map<string, string>;
202
- refreshedAt: number;
203
- };
204
- rememberNames(conversationId: string, names: Record<string, string | null | undefined>): void;
205
- }
206
- /** What a room object needs from its CanonClient (injected for tests). */
207
- export interface ArtifactRoomHost {
208
- artifacts(): Promise<ArtifactClient>;
209
- images(): Promise<ArtifactImageClient>;
210
- principalId(): Promise<string>;
211
- /** Upload a local image as a prepared (not yet sent) Canon attachment. */
212
- prepareImageUpload(input: {
213
- conversationId: string;
214
- attachmentId: string;
215
- source: string;
216
- mimeType: string;
217
- sizeBytes: number;
218
- fileName: string;
219
- signal?: AbortSignal;
220
- }): Promise<MediaAttachment>;
221
- getMessage(conversationId: string, messageId: string): Promise<CanonMessage | null>;
222
- /** Recent messages, for participant names. */
223
- recentMessages(conversationId: string): Promise<CanonMessage[]>;
224
- memory: ArtifactMemory;
225
- now?: () => number;
226
- }
227
- /** Keyed identity derivation (the endpoint's per-installation secret): what `artifactCommandId` and `artifactRequestUuid` need. */
228
- export type ArtifactIdDerivation = Pick<ArtifactClient, 'deriveCommandId' | 'deriveRequestId'>;
229
- /**
230
- * Command ID for one deliberate change: the same principal, request (turn)
231
- * and action give the same command, so a repeated call never applies twice.
232
- * The principal keeps agents that handle the same message apart.
233
- * `baseRevisionId` distinguishes a deliberate repeat after the work moved on;
234
- * `attempt` a repeat after a rejected send (whose ID keeps its rejection).
235
- * Keyed with this installation's secret: the server can never test a guess of
236
- * the action against it.
237
- */
238
- export declare function artifactCommandId(ids: Pick<ArtifactIdDerivation, 'deriveCommandId'>, parts: {
239
- conversationId: string;
240
- artifactId: string;
241
- principalId: string;
242
- requestKey: string;
243
- action: unknown;
244
- baseRevisionId?: string;
245
- attempt?: number;
246
- }): Promise<string>;
247
- /** A stable, keyed, RFC 4122-shaped ID (image request and upload attachment IDs) for `material`. */
248
- export declare function artifactRequestUuid(ids: Pick<ArtifactIdDerivation, 'deriveRequestId'>, material: unknown[]): Promise<string>;
249
- export declare function createConversationArtifacts(host: ArtifactRoomHost, conversationId: string): CanonConversationArtifacts;
250
- /**
251
- * One-line summaries "as of message arrival" for the work a message reports
252
- * activity on (`origin: 'activity'`), keyed by artifact ID, for the prompt.
253
- * Lenient: a malformed context, a failed read, the timeout or `signal` omits
254
- * the line (a read cancelled by `signal` records nothing). `names` (for
255
- * example the sender) seeds participant names.
256
- */
257
- export declare function summarizeArtifactReferences(client: Pick<CanonClient, 'artifacts'> & Partial<Pick<CanonClient, 'rememberParticipantNames'>>, conversationId: string, context: unknown, options?: {
258
- timeoutMs?: number;
259
- names?: Record<string, string | null | undefined>;
260
- signal?: AbortSignal;
261
- }): Promise<Record<string, string>>;
262
- export {};