@peer-agent/protocol 0.1.0-rc.4 → 0.1.0-rc.40

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 (86) hide show
  1. package/dist/acceptance-close-gate.d.ts +10 -1
  2. package/dist/acceptance-close-gate.js +12 -0
  3. package/dist/agent-supervision.d.ts +81 -0
  4. package/dist/agent-supervision.js +1 -0
  5. package/dist/attention.d.ts +44 -0
  6. package/dist/attention.js +1 -0
  7. package/dist/bot-access-policy.d.ts +29 -0
  8. package/dist/bot-access-policy.js +1 -0
  9. package/dist/bot-conversation-read.d.ts +25 -0
  10. package/dist/bot-conversation-read.js +9 -0
  11. package/dist/bot-model-selection.d.ts +13 -0
  12. package/dist/bot-model-selection.js +1 -0
  13. package/dist/browser-window.d.ts +48 -0
  14. package/dist/browser-window.js +23 -0
  15. package/dist/capability-admission.d.ts +20 -0
  16. package/dist/capability-admission.js +1 -0
  17. package/dist/delegation-coordination.d.ts +81 -0
  18. package/dist/delegation-coordination.js +1 -0
  19. package/dist/delegation.d.ts +203 -7
  20. package/dist/delegation.js +39 -39
  21. package/dist/document-reference.d.ts +83 -0
  22. package/dist/document-reference.js +1 -0
  23. package/dist/evidence-inspection.d.ts +64 -0
  24. package/dist/evidence-inspection.js +1 -0
  25. package/dist/goal.d.ts +50 -2
  26. package/dist/index.d.ts +56 -5
  27. package/dist/index.js +25 -0
  28. package/dist/input-prediction.d.ts +86 -0
  29. package/dist/input-prediction.js +48 -0
  30. package/dist/intent-coordination.d.ts +201 -0
  31. package/dist/intent-coordination.js +1 -0
  32. package/dist/interactive-result.d.ts +363 -0
  33. package/dist/interactive-result.js +215 -0
  34. package/dist/interactive-verification.d.ts +41 -0
  35. package/dist/interactive-verification.js +65 -0
  36. package/dist/local-git.d.ts +44 -0
  37. package/dist/local-git.js +3 -0
  38. package/dist/local-image.d.ts +53 -0
  39. package/dist/local-image.js +5 -0
  40. package/dist/model-reasoning.d.ts +13 -0
  41. package/dist/model-reasoning.js +18 -0
  42. package/dist/model-routing.d.ts +37 -3
  43. package/dist/model-routing.js +31 -5
  44. package/dist/project-agent-failure.d.ts +30 -0
  45. package/dist/project-agent-failure.js +44 -0
  46. package/dist/project-input-recovery.d.ts +65 -0
  47. package/dist/project-input-recovery.js +5 -0
  48. package/dist/project-recovery.d.ts +43 -0
  49. package/dist/project-recovery.js +1 -0
  50. package/dist/project.d.ts +63 -0
  51. package/dist/project.js +2 -5
  52. package/dist/remote-access.d.ts +15 -0
  53. package/dist/remote-access.js +1 -1
  54. package/dist/reply-delivery.d.ts +28 -0
  55. package/dist/reply-delivery.js +1 -0
  56. package/dist/resource-edit-execution.d.ts +68 -0
  57. package/dist/resource-edit-execution.js +96 -0
  58. package/dist/resource-edit.d.ts +237 -0
  59. package/dist/resource-edit.js +134 -0
  60. package/dist/resource-feedback-transport.d.ts +25 -0
  61. package/dist/resource-feedback-transport.js +93 -0
  62. package/dist/resource-feedback.d.ts +98 -0
  63. package/dist/resource-feedback.js +151 -0
  64. package/dist/resource-file-replace.d.ts +36 -0
  65. package/dist/resource-file-replace.js +40 -0
  66. package/dist/resource-reference-hints.d.ts +3 -0
  67. package/dist/resource-reference-hints.js +58 -0
  68. package/dist/resource-window.d.ts +217 -0
  69. package/dist/resource-window.js +245 -0
  70. package/dist/runtime-session-facts.d.ts +58 -0
  71. package/dist/runtime-session-facts.js +55 -0
  72. package/dist/session-control.d.ts +111 -0
  73. package/dist/session-control.js +34 -0
  74. package/dist/session-facts.d.ts +29 -0
  75. package/dist/session-facts.js +35 -0
  76. package/dist/system-context.d.ts +6 -0
  77. package/dist/task-overview.d.ts +90 -0
  78. package/dist/task-overview.js +322 -17
  79. package/dist/tool-activity-preview.d.ts +4 -0
  80. package/dist/tool-activity-preview.js +72 -0
  81. package/dist/usage-accounting.d.ts +1 -1
  82. package/dist/user-anchor.d.ts +17 -0
  83. package/dist/user-anchor.js +1 -0
  84. package/dist/work-coordination.d.ts +165 -0
  85. package/dist/work-coordination.js +1 -0
  86. package/package.json +1 -1
@@ -0,0 +1,363 @@
1
+ import type { DataLevel } from './index.ts';
2
+ import type { SessionExecutionIdentity } from './session-control.ts';
3
+ /** Host-neutral content and presentation contracts. References never grant access. */
4
+ export type InteractiveJSON = null | boolean | number | string | readonly InteractiveJSON[] | {
5
+ readonly [key: string]: InteractiveJSON;
6
+ };
7
+ export interface InteractiveOwner {
8
+ readonly workspaceId: string;
9
+ readonly conversationId: string;
10
+ }
11
+ export interface InteractiveResultReference {
12
+ readonly owner: InteractiveOwner;
13
+ readonly resultId: string;
14
+ readonly contentVersion: string;
15
+ }
16
+ export interface InteractivePublicationCallReference {
17
+ readonly owner: InteractiveOwner;
18
+ readonly conversationId: string;
19
+ readonly toolCallId: string;
20
+ }
21
+ export type InteractivePublicationIntent = {
22
+ readonly kind: 'create';
23
+ } | {
24
+ readonly kind: 'revise';
25
+ readonly base: InteractiveResultReference;
26
+ };
27
+ export type AdmittedMaterialReference = {
28
+ readonly kind: 'tool-result';
29
+ readonly conversationId: string;
30
+ readonly toolCallId: string;
31
+ readonly expectedContentVersion: string;
32
+ } | {
33
+ readonly kind: 'user-material';
34
+ readonly messageId: string;
35
+ readonly attachmentId: string;
36
+ readonly expectedContentVersion: string;
37
+ } | {
38
+ readonly kind: 'model-data';
39
+ readonly value: InteractiveJSON;
40
+ };
41
+ export interface BoundedDataSelector {
42
+ readonly path?: readonly string[];
43
+ readonly fields?: readonly string[];
44
+ readonly start?: number;
45
+ readonly limit?: number;
46
+ }
47
+ export interface InteractiveInputBinding {
48
+ readonly bindingId: string;
49
+ readonly source: AdmittedMaterialReference;
50
+ readonly selector?: BoundedDataSelector;
51
+ }
52
+ export interface InteractiveMaterialNotice {
53
+ readonly source: Exclude<AdmittedMaterialReference, {
54
+ readonly kind: 'model-data';
55
+ }>;
56
+ readonly format: 'peer-tool-observation-1' | 'peer-user-upload-1';
57
+ readonly selectorRoots: readonly string[];
58
+ readonly dataLevel: DataLevel;
59
+ readonly truncated: boolean;
60
+ readonly redacted: boolean;
61
+ }
62
+ /** Host-only Provider observation, attached non-enumerably to its actual Tool Result. */
63
+ export interface CanonicalToolMaterialObservation {
64
+ readonly schemaVersion: 1;
65
+ readonly toolCallId: string;
66
+ readonly capabilityId: string;
67
+ readonly evidenceId: string;
68
+ readonly payload: InteractiveJSON;
69
+ }
70
+ export interface InteractiveResultDraft {
71
+ readonly publication: InteractivePublicationIntent;
72
+ readonly title: string;
73
+ readonly textFallback: string;
74
+ readonly program: string;
75
+ readonly inputs: readonly InteractiveInputBinding[];
76
+ }
77
+ export interface InteractiveMaterialProvenance {
78
+ readonly bindingId: string;
79
+ readonly source: Exclude<AdmittedMaterialReference, {
80
+ readonly kind: 'model-data';
81
+ }> | {
82
+ readonly kind: 'model-data';
83
+ readonly contentDigest: string;
84
+ };
85
+ readonly contentVersion: string;
86
+ readonly selectedDigest: string;
87
+ readonly selector?: BoundedDataSelector;
88
+ readonly observedAt: string;
89
+ readonly capturedAt: string;
90
+ readonly truncated: boolean;
91
+ readonly redacted: boolean;
92
+ readonly dataLevel: DataLevel;
93
+ readonly evidenceRefs: readonly string[];
94
+ }
95
+ export type InteractiveStateValue = string | number | boolean;
96
+ export interface InteractiveStateField {
97
+ readonly type: 'string' | 'number' | 'boolean';
98
+ readonly min?: number;
99
+ readonly max?: number;
100
+ readonly options?: readonly string[];
101
+ }
102
+ export type InteractiveStateSchema = Readonly<Record<string, InteractiveStateField>>;
103
+ export type InteractiveStateValues = Readonly<Record<string, InteractiveStateValue>>;
104
+ export interface InteractiveStateSnapshot {
105
+ readonly result: InteractiveResultReference;
106
+ readonly specHash: string;
107
+ readonly stateSchemaHash: string;
108
+ readonly stateRevision: number;
109
+ readonly values: InteractiveStateValues;
110
+ readonly inputDrafts: Readonly<Record<string, string>>;
111
+ readonly stateDigest: string;
112
+ readonly updatedAt: string;
113
+ readonly requestId: string;
114
+ }
115
+ export interface InteractiveElement {
116
+ readonly type: 'element';
117
+ readonly typeName: string;
118
+ readonly statementId?: string;
119
+ readonly stateTarget?: string;
120
+ readonly props: Readonly<Record<string, unknown>>;
121
+ }
122
+ export interface InteractiveContent {
123
+ readonly schemaVersion: 1;
124
+ readonly engine: string;
125
+ readonly libraryVersion: string;
126
+ readonly specHash: string;
127
+ readonly title: string;
128
+ readonly textFallback: string;
129
+ readonly program: string;
130
+ readonly bindings: Readonly<Record<string, InteractiveJSON>>;
131
+ readonly initialValues: InteractiveStateValues;
132
+ readonly stateSchema: InteractiveStateSchema;
133
+ readonly stateSchemaHash: string;
134
+ readonly numberPolicy: string;
135
+ readonly tree?: InteractiveElement;
136
+ }
137
+ export interface InteractivePublishedResult {
138
+ readonly reference: InteractiveResultReference;
139
+ readonly content: InteractiveContent;
140
+ readonly source: SessionExecutionIdentity & {
141
+ readonly conversationId: string;
142
+ readonly workId?: string;
143
+ readonly toolCallId: string;
144
+ };
145
+ readonly provenance: readonly InteractiveMaterialProvenance[];
146
+ readonly predecessor?: InteractiveResultReference;
147
+ readonly evidenceRef: string;
148
+ readonly artifactRef: string;
149
+ readonly dataLevel: InteractiveMaterialProvenance['dataLevel'];
150
+ readonly createdAt: string;
151
+ }
152
+ export interface InteractivePublicationPermissionScope {
153
+ readonly kind: 'interactive-result';
154
+ readonly capabilityId: typeof INTERACTIVE_PUBLISH_CAPABILITY;
155
+ readonly owner: InteractiveOwner;
156
+ readonly source: InteractivePublishedResult['source'];
157
+ readonly parameterDigest: string;
158
+ readonly dataLevel: DataLevel;
159
+ }
160
+ export interface InteractiveUserArtifact {
161
+ readonly kind: 'interactive';
162
+ readonly ref: string;
163
+ readonly label: string;
164
+ readonly reference: InteractiveResultReference;
165
+ readonly specHash: string;
166
+ }
167
+ export type InteractivePublicationStatus = 'not_committed' | 'index_pending' | 'published' | 'unknown';
168
+ export interface InteractiveInspectRequest {
169
+ readonly target: {
170
+ readonly kind: 'result';
171
+ readonly reference: InteractiveResultReference;
172
+ } | {
173
+ readonly kind: 'publication';
174
+ readonly reference: InteractivePublicationCallReference;
175
+ };
176
+ readonly view: 'metadata' | 'text' | 'program' | 'data' | 'evaluate';
177
+ readonly bindingId?: string;
178
+ readonly selector?: BoundedDataSelector;
179
+ /** Only an explicitly admitted, immutable user selection; never the latest mutable state. */
180
+ readonly followupId?: string;
181
+ readonly offset?: number;
182
+ readonly limit?: number;
183
+ }
184
+ export interface InteractiveViewHandle {
185
+ readonly viewId: string;
186
+ readonly windowId: string;
187
+ readonly generation: string;
188
+ }
189
+ export interface InteractiveWriter {
190
+ readonly viewId: string;
191
+ readonly generation: string;
192
+ readonly token: string;
193
+ }
194
+ export interface InteractiveFollowup {
195
+ readonly followupId: string;
196
+ readonly recipient: InteractiveOwner;
197
+ readonly result: InteractiveResultReference;
198
+ readonly specHash: string;
199
+ readonly stateRevision: number;
200
+ readonly stateDigest: string;
201
+ readonly selectionDigest: string;
202
+ readonly values: InteractiveStateValues;
203
+ readonly dataLevel: DataLevel;
204
+ readonly capturedAt: string;
205
+ readonly excerpt: string;
206
+ }
207
+ export type InteractiveResultSummary = {
208
+ readonly reference: InteractiveResultReference;
209
+ readonly title: string;
210
+ readonly textFallback: string;
211
+ readonly dataLevel: DataLevel;
212
+ } & ({
213
+ readonly availability?: 'available';
214
+ readonly specHash: string;
215
+ readonly libraryVersion: string;
216
+ } | {
217
+ readonly availability: 'cleaned';
218
+ readonly cleanedAt: string;
219
+ readonly truncated: boolean;
220
+ });
221
+ export type InteractiveResult<T extends object = Record<never, never>> = ({
222
+ readonly ok: true;
223
+ } & T) | {
224
+ readonly ok: false;
225
+ readonly code: string;
226
+ readonly summary?: InteractiveResultSummary;
227
+ };
228
+ export interface InteractiveSourceIssue {
229
+ readonly bindingId: string;
230
+ readonly status: 'attachment_removed' | 'source_changed' | 'source_unavailable';
231
+ }
232
+ export interface InteractiveOpenView {
233
+ readonly handle: InteractiveViewHandle;
234
+ readonly result: InteractivePublishedResult;
235
+ readonly state: InteractiveStateSnapshot;
236
+ readonly sourceIssues?: readonly InteractiveSourceIssue[];
237
+ }
238
+ export interface InteractiveVersionNavigation {
239
+ readonly reference: InteractiveResultReference;
240
+ readonly head: InteractiveResultReference;
241
+ readonly predecessor?: InteractiveResultReference;
242
+ }
243
+ export type InteractiveSaveResult = {
244
+ readonly ok: true;
245
+ readonly state: InteractiveStateSnapshot;
246
+ readonly writerCurrent?: boolean;
247
+ } | {
248
+ readonly ok: false;
249
+ readonly code: 'interactive_owner_replaced';
250
+ readonly saveStatus?: 'committed' | 'not_committed';
251
+ } | {
252
+ readonly ok: false;
253
+ readonly code: string;
254
+ readonly saveStatus?: 'not_committed';
255
+ };
256
+ export interface InteractiveResultsApi {
257
+ open(request: {
258
+ readonly reference: InteractiveResultReference;
259
+ readonly requestId: string;
260
+ }): Promise<InteractiveResult<InteractiveOpenView>>;
261
+ cancelOpen?(request: {
262
+ readonly requestId: string;
263
+ }): Promise<InteractiveResult>;
264
+ readState(request: {
265
+ readonly handle: InteractiveViewHandle;
266
+ }): Promise<InteractiveResult<{
267
+ readonly state: InteractiveStateSnapshot;
268
+ }>>;
269
+ readVersions?(request: {
270
+ readonly handle: InteractiveViewHandle;
271
+ }): Promise<InteractiveResult<{
272
+ readonly versions: InteractiveVersionNavigation;
273
+ }>>;
274
+ openVersion?(request: {
275
+ readonly handle: InteractiveViewHandle;
276
+ readonly relation: 'head' | 'predecessor';
277
+ readonly expectedReference: InteractiveResultReference;
278
+ }): Promise<InteractiveResult<{
279
+ readonly reference: InteractiveResultReference;
280
+ }>>;
281
+ acquire(request: {
282
+ readonly handle: InteractiveViewHandle;
283
+ readonly expectedRevision: number;
284
+ readonly takeover?: boolean;
285
+ }): Promise<InteractiveResult<{
286
+ readonly writer: InteractiveWriter;
287
+ }>>;
288
+ save(request: {
289
+ readonly handle: InteractiveViewHandle;
290
+ readonly writer: InteractiveWriter;
291
+ readonly expectedRevision: number;
292
+ readonly requestId: string;
293
+ readonly values: InteractiveStateValues;
294
+ readonly inputDrafts: Readonly<Record<string, string>>;
295
+ }): Promise<InteractiveSaveResult>;
296
+ release(request: {
297
+ readonly handle: InteractiveViewHandle;
298
+ readonly writer?: InteractiveWriter;
299
+ }): Promise<InteractiveResult>;
300
+ prepareFollowup(request: {
301
+ readonly handle: InteractiveViewHandle;
302
+ readonly stateRevision: number;
303
+ readonly stateDigest: string;
304
+ readonly fields: readonly string[];
305
+ readonly requestId: string;
306
+ }): Promise<InteractiveResult<{
307
+ readonly followup: InteractiveFollowup;
308
+ }>>;
309
+ prepareDraft?(request: {
310
+ readonly handle: InteractiveViewHandle;
311
+ readonly followupId: string;
312
+ }): Promise<InteractiveResult<{
313
+ readonly followupId: string;
314
+ }>>;
315
+ }
316
+ export declare const INTERACTIVE_PUBLISH_CAPABILITY = "local.interactive.publish";
317
+ export declare const INTERACTIVE_INSPECT_CAPABILITY = "local.interactive.inspect";
318
+ export declare const INTERACTIVE_PUBLISH_TOOL = "publish_interactive_result";
319
+ export declare const INTERACTIVE_INSPECT_TOOL = "inspect_interactive_result";
320
+ export declare const INTERACTIVE_RESULT_SCHEMA_VERSION = 1;
321
+ export declare const INTERACTIVE_RESULT_LIMITS: Readonly<{
322
+ programBytes: number;
323
+ fallbackBytes: number;
324
+ inputBytes: number;
325
+ bindings: 16;
326
+ astNodes: 1000;
327
+ astDepth: 24;
328
+ expandedNodes: 300;
329
+ expandedDepth: 12;
330
+ stateFields: 64;
331
+ stateBytes: number;
332
+ collectionItems: 500;
333
+ textChars: 8192;
334
+ tablePageRows: 100;
335
+ tablePageCells: 1000;
336
+ chartSeries: 6;
337
+ chartPoints: 500;
338
+ evaluationSteps: 40000;
339
+ workerTimeoutMs: 2000;
340
+ resultsPerBot: 256;
341
+ storeBytes: number;
342
+ manifestBytes: number;
343
+ contentRepairs: 2;
344
+ localActionSteps: 16;
345
+ }>;
346
+ export declare const interactiveBindingId: (v: unknown) => v is string;
347
+ export declare const interactiveToken: (v: unknown) => v is string;
348
+ export declare const interactiveDigest: (v: unknown) => v is string;
349
+ export declare function normalizeInteractiveMaterialNotice(raw: unknown): InteractiveMaterialNotice | undefined;
350
+ export declare function normalizeInteractiveOwner(raw: unknown): InteractiveOwner | undefined;
351
+ export declare function normalizeInteractiveReference(raw: unknown): InteractiveResultReference | undefined;
352
+ /** Syntax and budget only. The host must match the actual immutable freeze receipt. */
353
+ export declare function normalizeInteractiveFollowup(raw: unknown): InteractiveFollowup | undefined;
354
+ export declare function normalizeInteractiveViewHandle(raw: unknown): InteractiveViewHandle | undefined;
355
+ export declare function normalizeInteractiveWriter(raw: unknown): InteractiveWriter | undefined;
356
+ export declare function normalizeInteractivePublicationReference(raw: unknown): InteractivePublicationCallReference | undefined;
357
+ export declare function normalizeInteractiveSelector(raw: unknown): BoundedDataSelector | undefined;
358
+ export declare function normalizeInteractiveDraft(raw: unknown): InteractiveResultDraft | undefined;
359
+ export declare function normalizeInteractiveInspect(raw: unknown): InteractiveInspectRequest | undefined;
360
+ /** An opaque, version-pinned locator. Hosts must revalidate the canonical publication receipt. */
361
+ export declare function interactiveArtifactRef(ref: InteractiveResultReference): string;
362
+ export declare function parseInteractiveArtifactRef(raw: unknown): InteractiveResultReference | undefined;
363
+ export declare function normalizeInteractiveUserArtifact(raw: unknown): InteractiveUserArtifact | undefined;
@@ -0,0 +1,215 @@
1
+ export const INTERACTIVE_PUBLISH_CAPABILITY = 'local.interactive.publish';
2
+ export const INTERACTIVE_INSPECT_CAPABILITY = 'local.interactive.inspect';
3
+ export const INTERACTIVE_PUBLISH_TOOL = 'publish_interactive_result';
4
+ export const INTERACTIVE_INSPECT_TOOL = 'inspect_interactive_result';
5
+ export const INTERACTIVE_RESULT_SCHEMA_VERSION = 1;
6
+ export const INTERACTIVE_RESULT_LIMITS = Object.freeze({
7
+ programBytes: 64 * 1024, fallbackBytes: 32 * 1024, inputBytes: 512 * 1024, bindings: 16,
8
+ astNodes: 1000, astDepth: 24, expandedNodes: 300, expandedDepth: 12, stateFields: 64,
9
+ stateBytes: 64 * 1024, collectionItems: 500, textChars: 8192, tablePageRows: 100,
10
+ tablePageCells: 1000, chartSeries: 6, chartPoints: 500, evaluationSteps: 40_000,
11
+ workerTimeoutMs: 2000, resultsPerBot: 256, storeBytes: 128 * 1024 * 1024,
12
+ manifestBytes: 2 * 1024 * 1024, contentRepairs: 2, localActionSteps: 16,
13
+ });
14
+ const object = (v) => !!v && typeof v === 'object' && !Array.isArray(v)
15
+ && [Object.prototype, null].includes(Object.getPrototypeOf(v))
16
+ && Object.values(Object.getOwnPropertyDescriptors(v)).every(d => 'value' in d);
17
+ const keys = (v, allowed) => Object.keys(v).every(key => allowed.includes(key));
18
+ const safeKey = (v) => typeof v === 'string' && /^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(v) && !['constructor', 'prototype', '__proto__'].includes(v);
19
+ export const interactiveBindingId = safeKey;
20
+ export const interactiveToken = (v) => typeof v === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,255}$/.test(v) && !v.includes('..');
21
+ export const interactiveDigest = (v) => typeof v === 'string' && /^sha256:[a-f0-9]{64}$/.test(v);
22
+ export function normalizeInteractiveMaterialNotice(raw) {
23
+ if (!object(raw) || !keys(raw, ['source', 'format', 'selectorRoots', 'dataLevel', 'truncated', 'redacted']) || !object(raw.source)
24
+ || !interactiveDigest(raw.source.expectedContentVersion) || typeof raw.truncated !== 'boolean' || typeof raw.redacted !== 'boolean'
25
+ || !['D0_public', 'D1_internal', 'D2_sensitive', 'D3_private', 'D4_regulated'].includes(raw.dataLevel))
26
+ return;
27
+ const source = raw.source;
28
+ let admitted;
29
+ if (source.kind === 'tool-result' && raw.format === 'peer-tool-observation-1' && keys(source, ['kind', 'conversationId', 'toolCallId', 'expectedContentVersion'])
30
+ && interactiveToken(source.conversationId) && interactiveToken(source.toolCallId))
31
+ admitted = { kind: source.kind, conversationId: source.conversationId, toolCallId: source.toolCallId, expectedContentVersion: source.expectedContentVersion };
32
+ else if (source.kind === 'user-material' && raw.format === 'peer-user-upload-1' && keys(source, ['kind', 'messageId', 'attachmentId', 'expectedContentVersion'])
33
+ && interactiveToken(source.messageId) && interactiveToken(source.attachmentId))
34
+ admitted = { kind: source.kind, messageId: source.messageId, attachmentId: source.attachmentId, expectedContentVersion: source.expectedContentVersion };
35
+ else
36
+ return;
37
+ const roots = raw.selectorRoots, allowed = source.kind === 'tool-result' ? ['payload', 'json'] : ['text', 'json'];
38
+ if (!Array.isArray(roots) || !roots.length || roots.length > 2 || roots.some(value => !allowed.includes(value)) || new Set(roots).size !== roots.length)
39
+ return;
40
+ return { source: admitted, format: raw.format, selectorRoots: [...roots],
41
+ dataLevel: raw.dataLevel, truncated: raw.truncated, redacted: raw.redacted };
42
+ }
43
+ const integer = (v, min = 0, max = Number.MAX_SAFE_INTEGER) => Number.isSafeInteger(v) && Number(v) >= min && Number(v) <= max;
44
+ const bytes = (v) => new TextEncoder().encode(v).byteLength;
45
+ const text = (v, max) => typeof v === 'string' && !!v.trim() && !v.includes('\0') && bytes(v) <= max;
46
+ export function normalizeInteractiveOwner(raw) {
47
+ if (!object(raw) || !keys(raw, ['workspaceId', 'conversationId']) || !interactiveToken(raw.workspaceId) || !interactiveToken(raw.conversationId))
48
+ return;
49
+ return { workspaceId: raw.workspaceId, conversationId: raw.conversationId };
50
+ }
51
+ export function normalizeInteractiveReference(raw) {
52
+ if (!object(raw) || !keys(raw, ['owner', 'resultId', 'contentVersion']) || !interactiveToken(raw.resultId) || !interactiveDigest(raw.contentVersion))
53
+ return;
54
+ const owner = normalizeInteractiveOwner(raw.owner);
55
+ return owner ? { owner, resultId: raw.resultId, contentVersion: raw.contentVersion } : undefined;
56
+ }
57
+ /** Syntax and budget only. The host must match the actual immutable freeze receipt. */
58
+ export function normalizeInteractiveFollowup(raw) {
59
+ if (!object(raw) || !keys(raw, ['followupId', 'recipient', 'result', 'specHash', 'stateRevision', 'stateDigest', 'selectionDigest', 'values', 'dataLevel', 'capturedAt', 'excerpt'])
60
+ || !interactiveToken(raw.followupId) || !interactiveDigest(raw.specHash) || !interactiveDigest(raw.stateDigest) || !interactiveDigest(raw.selectionDigest)
61
+ || !integer(raw.stateRevision) || !object(raw.values) || !Object.keys(raw.values).length || Object.keys(raw.values).length > INTERACTIVE_RESULT_LIMITS.stateFields
62
+ || Object.entries(raw.values).some(([key, value]) => !/^\$[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(key)
63
+ || !(typeof value === 'string' && value.length <= INTERACTIVE_RESULT_LIMITS.textChars && !value.includes('\0') || typeof value === 'boolean' || typeof value === 'number' && Number.isFinite(value)))
64
+ || !['D0_public', 'D1_internal', 'D2_sensitive', 'D3_private', 'D4_regulated'].includes(raw.dataLevel)
65
+ || typeof raw.capturedAt !== 'string' || raw.capturedAt.length > 40 || !Number.isFinite(Date.parse(raw.capturedAt)) || !text(raw.excerpt, 8192))
66
+ return;
67
+ const recipient = normalizeInteractiveOwner(raw.recipient), result = normalizeInteractiveReference(raw.result);
68
+ if (!recipient || !result || recipient.workspaceId !== result.owner.workspaceId || recipient.conversationId !== result.owner.conversationId)
69
+ return;
70
+ const value = { followupId: raw.followupId, recipient, result, specHash: raw.specHash, stateRevision: raw.stateRevision,
71
+ stateDigest: raw.stateDigest, selectionDigest: raw.selectionDigest, values: Object.fromEntries(Object.entries(raw.values).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)),
72
+ dataLevel: raw.dataLevel, capturedAt: new Date(raw.capturedAt).toISOString(), excerpt: raw.excerpt };
73
+ return bytes(JSON.stringify(value)) <= 32 * 1024 ? value : undefined;
74
+ }
75
+ export function normalizeInteractiveViewHandle(raw) {
76
+ if (!object(raw) || !keys(raw, ['viewId', 'windowId', 'generation']) || !interactiveToken(raw.viewId)
77
+ || !interactiveToken(raw.windowId) || !interactiveToken(raw.generation))
78
+ return;
79
+ return { viewId: raw.viewId, windowId: raw.windowId, generation: raw.generation };
80
+ }
81
+ export function normalizeInteractiveWriter(raw) {
82
+ if (!object(raw) || !keys(raw, ['viewId', 'generation', 'token']) || !interactiveToken(raw.viewId)
83
+ || !interactiveToken(raw.generation) || !interactiveToken(raw.token))
84
+ return;
85
+ return { viewId: raw.viewId, generation: raw.generation, token: raw.token };
86
+ }
87
+ export function normalizeInteractivePublicationReference(raw) {
88
+ if (!object(raw) || !keys(raw, ['owner', 'conversationId', 'toolCallId']) || !interactiveToken(raw.conversationId) || !interactiveToken(raw.toolCallId))
89
+ return;
90
+ const owner = normalizeInteractiveOwner(raw.owner);
91
+ return owner ? { owner, conversationId: raw.conversationId, toolCallId: raw.toolCallId } : undefined;
92
+ }
93
+ export function normalizeInteractiveSelector(raw) {
94
+ if (!object(raw) || !keys(raw, ['path', 'fields', 'start', 'limit']))
95
+ return;
96
+ for (const field of ['path', 'fields'])
97
+ if (raw[field] !== undefined && (!Array.isArray(raw[field]) || raw[field].length > (field === 'path' ? 8 : 32)
98
+ || !raw[field].every(safeKey) || new Set(raw[field]).size !== raw[field].length))
99
+ return;
100
+ if (raw.start !== undefined && !integer(raw.start, 0, 500) || raw.limit !== undefined && !integer(raw.limit, 1, 500))
101
+ return;
102
+ return { ...(raw.path ? { path: [...raw.path] } : {}), ...(raw.fields ? { fields: [...raw.fields] } : {}),
103
+ ...(raw.start !== undefined ? { start: raw.start } : {}), ...(raw.limit !== undefined ? { limit: raw.limit } : {}) };
104
+ }
105
+ function jsonValue(raw, depth = 0, active = new Set(), budget = { nodes: 0 }) {
106
+ if (depth > 16 || ++budget.nodes > INTERACTIVE_RESULT_LIMITS.evaluationSteps)
107
+ return false;
108
+ if (raw === null || typeof raw === 'boolean' || typeof raw === 'string' && raw.length <= 8192 || typeof raw === 'number' && Number.isFinite(raw))
109
+ return true;
110
+ if (!raw || typeof raw !== 'object' || active.has(raw))
111
+ return false;
112
+ active.add(raw);
113
+ const valid = Array.isArray(raw) ? raw.length <= 500 && raw.every(value => jsonValue(value, depth + 1, active, budget))
114
+ : object(raw) && Object.keys(raw).length <= 500 && Object.entries(raw).every(([key, value]) => !['__proto__', 'constructor', 'prototype'].includes(key) && jsonValue(value, depth + 1, active, budget));
115
+ active.delete(raw);
116
+ return valid;
117
+ }
118
+ export function normalizeInteractiveDraft(raw) {
119
+ if (!object(raw) || !keys(raw, ['publication', 'title', 'textFallback', 'program', 'inputs'])
120
+ || !text(raw.title, 640) || raw.title.length > 160 || !text(raw.textFallback, INTERACTIVE_RESULT_LIMITS.fallbackBytes)
121
+ || !text(raw.program, INTERACTIVE_RESULT_LIMITS.programBytes) || !object(raw.publication)
122
+ || !Array.isArray(raw.inputs) || raw.inputs.length > INTERACTIVE_RESULT_LIMITS.bindings)
123
+ return;
124
+ let publication;
125
+ if (raw.publication.kind === 'create' && keys(raw.publication, ['kind']))
126
+ publication = { kind: 'create' };
127
+ else if (raw.publication.kind === 'revise' && keys(raw.publication, ['kind', 'base'])) {
128
+ const base = normalizeInteractiveReference(raw.publication.base);
129
+ if (!base)
130
+ return;
131
+ publication = { kind: 'revise', base };
132
+ }
133
+ else
134
+ return;
135
+ const inputs = [];
136
+ for (const binding of raw.inputs) {
137
+ if (!object(binding) || !keys(binding, ['bindingId', 'source', 'selector']) || !safeKey(binding.bindingId) || !object(binding.source))
138
+ return;
139
+ const s = binding.source;
140
+ let source;
141
+ if (s.kind === 'tool-result' && keys(s, ['kind', 'conversationId', 'toolCallId', 'expectedContentVersion'])
142
+ && interactiveToken(s.conversationId) && interactiveToken(s.toolCallId) && interactiveDigest(s.expectedContentVersion)) {
143
+ source = { kind: 'tool-result', conversationId: s.conversationId, toolCallId: s.toolCallId, expectedContentVersion: s.expectedContentVersion };
144
+ }
145
+ else if (s.kind === 'user-material' && keys(s, ['kind', 'messageId', 'attachmentId', 'expectedContentVersion'])
146
+ && interactiveToken(s.messageId) && interactiveToken(s.attachmentId) && interactiveDigest(s.expectedContentVersion)) {
147
+ source = { kind: 'user-material', messageId: s.messageId, attachmentId: s.attachmentId, expectedContentVersion: s.expectedContentVersion };
148
+ }
149
+ else if (s.kind === 'model-data' && keys(s, ['kind', 'value']) && jsonValue(s.value)) {
150
+ source = { kind: 'model-data', value: JSON.parse(JSON.stringify(s.value)) };
151
+ }
152
+ else
153
+ return;
154
+ const selector = binding.selector === undefined ? undefined : normalizeInteractiveSelector(binding.selector);
155
+ if (binding.selector !== undefined && !selector)
156
+ return;
157
+ inputs.push({ bindingId: binding.bindingId, source, ...(selector ? { selector } : {}) });
158
+ }
159
+ if (new Set(inputs.map(row => row.bindingId)).size !== inputs.length || bytes(JSON.stringify(inputs)) > INTERACTIVE_RESULT_LIMITS.inputBytes)
160
+ return;
161
+ return { publication, title: raw.title.trim(), textFallback: raw.textFallback, program: raw.program, inputs };
162
+ }
163
+ export function normalizeInteractiveInspect(raw) {
164
+ if (!object(raw) || !keys(raw, ['target', 'view', 'bindingId', 'selector', 'followupId', 'offset', 'limit']) || !object(raw.target)
165
+ || !keys(raw.target, ['kind', 'reference']) || !['metadata', 'text', 'program', 'data', 'evaluate'].includes(raw.view))
166
+ return;
167
+ let target;
168
+ if (raw.target.kind === 'result') {
169
+ const reference = normalizeInteractiveReference(raw.target.reference);
170
+ if (!reference)
171
+ return;
172
+ target = { kind: 'result', reference };
173
+ }
174
+ else if (raw.target.kind === 'publication') {
175
+ const reference = normalizeInteractivePublicationReference(raw.target.reference);
176
+ if (!reference || raw.view !== 'metadata')
177
+ return;
178
+ target = { kind: 'publication', reference };
179
+ }
180
+ else
181
+ return;
182
+ if (raw.bindingId !== undefined && (!safeKey(raw.bindingId) || raw.view !== 'data') || raw.view === 'data' && !safeKey(raw.bindingId)
183
+ || raw.followupId !== undefined && (!interactiveToken(raw.followupId) || raw.view !== 'evaluate')
184
+ || raw.offset !== undefined && !integer(raw.offset, 0, INTERACTIVE_RESULT_LIMITS.inputBytes)
185
+ || raw.limit !== undefined && !integer(raw.limit, 1, 4000))
186
+ return;
187
+ const selector = raw.selector === undefined ? undefined : normalizeInteractiveSelector(raw.selector);
188
+ if (raw.selector !== undefined && (!selector || raw.view !== 'data'))
189
+ return;
190
+ return { target, view: raw.view, ...(raw.bindingId ? { bindingId: raw.bindingId } : {}),
191
+ ...(selector ? { selector } : {}), ...(raw.followupId ? { followupId: raw.followupId } : {}),
192
+ ...(raw.offset !== undefined ? { offset: raw.offset } : {}), ...(raw.limit !== undefined ? { limit: raw.limit } : {}) };
193
+ }
194
+ /** An opaque, version-pinned locator. Hosts must revalidate the canonical publication receipt. */
195
+ export function interactiveArtifactRef(ref) {
196
+ const value = normalizeInteractiveReference(ref);
197
+ if (!value)
198
+ throw new TypeError('invalid_interactive_reference');
199
+ return `interactive-result://${value.owner.workspaceId}/${value.owner.conversationId}/${value.resultId}/${value.contentVersion.slice(7)}`;
200
+ }
201
+ export function parseInteractiveArtifactRef(raw) {
202
+ if (typeof raw !== 'string' || raw.length > 1024)
203
+ return;
204
+ const match = /^interactive-result:\/\/([^/]+)\/([^/]+)\/([^/]+)\/([a-f0-9]{64})$/.exec(raw);
205
+ return match ? normalizeInteractiveReference({ owner: { workspaceId: match[1], conversationId: match[2] }, resultId: match[3], contentVersion: `sha256:${match[4]}` }) : undefined;
206
+ }
207
+ export function normalizeInteractiveUserArtifact(raw) {
208
+ if (!object(raw) || !keys(raw, ['kind', 'ref', 'label', 'reference', 'specHash']) || raw.kind !== 'interactive'
209
+ || !text(raw.label, 640) || raw.label.length > 160 || !interactiveDigest(raw.specHash))
210
+ return;
211
+ const reference = normalizeInteractiveReference(raw.reference);
212
+ if (!reference || raw.ref !== interactiveArtifactRef(reference))
213
+ return;
214
+ return { kind: 'interactive', ref: raw.ref, label: raw.label, reference, specHash: raw.specHash };
215
+ }
@@ -0,0 +1,41 @@
1
+ import { type InteractiveInspectRequest, type InteractiveOwner } from './interactive-result.ts';
2
+ import { type SessionExecutionIdentity } from './session-control.ts';
3
+ /** Opaque host-only lifetime binding; never model context or execution permission. */
4
+ export interface InteractiveReviewBinding {
5
+ readonly token: string;
6
+ }
7
+ export interface InteractiveInspectionReceipt {
8
+ readonly schemaVersion: 1;
9
+ readonly evidenceId: string;
10
+ readonly owner: InteractiveOwner;
11
+ readonly execution: SessionExecutionIdentity;
12
+ readonly conversationId: string;
13
+ readonly toolCallId: string;
14
+ readonly specHash: string;
15
+ readonly request: InteractiveInspectRequest;
16
+ readonly review: {
17
+ readonly verifierRunId: string;
18
+ readonly sourceRevision: string;
19
+ readonly targetsDigest: string;
20
+ };
21
+ readonly range?: {
22
+ readonly offset: number;
23
+ readonly returned: number;
24
+ readonly total: number;
25
+ readonly truncated: boolean;
26
+ };
27
+ readonly stateSource?: {
28
+ readonly kind: 'initial' | 'frozen-followup';
29
+ readonly stateDigest: string;
30
+ readonly followupId?: string;
31
+ readonly stateRevision?: number;
32
+ readonly selectionDigest?: string;
33
+ };
34
+ readonly computationTruncated?: boolean;
35
+ readonly outputDigest: string;
36
+ readonly observedAt: string;
37
+ }
38
+ export declare function normalizeInteractiveReviewBinding(raw: unknown): InteractiveReviewBinding | undefined;
39
+ export declare function interactiveInspectionEvidenceRef(evidenceId: string): string;
40
+ export declare function isInteractiveInspectionEvidenceRef(raw: unknown): raw is string;
41
+ export declare function normalizeInteractiveInspectionReceipt(raw: unknown): InteractiveInspectionReceipt | undefined;