@tangle-network/agent-interface 0.44.0 → 0.46.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.
- package/README.md +1 -1
- package/dist/agent-candidate-code-schema.d.ts +1 -0
- package/dist/agent-candidate-execution-plan-schema.d.ts +8 -6
- package/dist/agent-candidate-profile-schema.d.ts +3 -2
- package/dist/agent-candidate-promotion-schema.d.ts +59 -42
- package/dist/agent-candidate-receipt-schema.d.ts +5 -4
- package/dist/agent-candidate-schema-common.js +1 -1
- package/dist/agent-candidate-schema.d.ts +4 -2
- package/dist/agent-execution-preparation.d.ts +27 -26
- package/dist/agent-profile.d.ts +10 -3
- package/dist/agent-profile.js +45 -22
- package/dist/backend-message.d.ts +14 -0
- package/dist/backend-message.js +1 -0
- package/dist/contract-limits.d.ts +26 -0
- package/dist/contract-limits.js +175 -0
- package/dist/environment-exact-process.d.ts +161 -0
- package/dist/environment-exact-process.js +1 -0
- package/dist/environment-profile-capabilities.d.ts +26 -0
- package/dist/environment-profile-capabilities.js +34 -0
- package/dist/environment-provider.d.ts +3 -730
- package/dist/environment-provider.js +3 -245
- package/dist/environment-requests.d.ts +70 -0
- package/dist/environment-requests.js +1 -0
- package/dist/environment-runtime.d.ts +834 -0
- package/dist/environment-runtime.js +228 -0
- package/dist/execution-types.d.ts +47 -0
- package/dist/execution-types.js +1 -0
- package/dist/harness-capabilities.js +5 -0
- package/dist/harness.d.ts +6 -1
- package/dist/harness.js +1 -0
- package/dist/host-services.d.ts +91 -0
- package/dist/host-services.js +1 -0
- package/dist/index.d.ts +10 -617
- package/dist/index.js +10 -125
- package/dist/interaction-answer-validation.d.ts +13 -0
- package/dist/interaction-answer-validation.js +149 -0
- package/dist/interaction-data.d.ts +22 -0
- package/dist/interaction-data.js +46 -0
- package/dist/interaction-envelope.d.ts +258 -0
- package/dist/interaction-envelope.js +245 -0
- package/dist/interaction-fields.d.ts +130 -0
- package/dist/interaction-fields.js +227 -0
- package/dist/interaction-permissions.d.ts +28 -0
- package/dist/interaction-permissions.js +57 -0
- package/dist/interaction-resolution-validation.d.ts +9 -0
- package/dist/interaction-resolution-validation.js +50 -0
- package/dist/interaction-response-validation.d.ts +17 -0
- package/dist/interaction-response-validation.js +102 -0
- package/dist/interaction.d.ts +6 -397
- package/dist/interaction.js +6 -603
- package/dist/mcp.d.ts +38 -0
- package/dist/mcp.js +1 -0
- package/dist/parts.d.ts +104 -0
- package/dist/parts.js +55 -0
- package/dist/portable-context-base.d.ts +82 -0
- package/dist/portable-context-base.js +63 -0
- package/dist/portable-context-continuation.d.ts +168 -0
- package/dist/portable-context-continuation.js +194 -0
- package/dist/portable-context-plan-request.d.ts +86 -0
- package/dist/portable-context-plan-request.js +102 -0
- package/dist/portable-context-plan.d.ts +229 -0
- package/dist/portable-context-plan.js +241 -0
- package/dist/portable-context-shared.d.ts +36 -0
- package/dist/portable-context-shared.js +46 -0
- package/dist/portable-context-transfer.d.ts +319 -0
- package/dist/portable-context-transfer.js +206 -0
- package/dist/portable-context.d.ts +5 -753
- package/dist/portable-context.js +5 -754
- package/dist/profile-diff.js +56 -47
- package/dist/profile-schema.d.ts +1 -0
- package/dist/provider-adapter.d.ts +45 -0
- package/dist/provider-adapter.js +1 -0
- package/dist/provider-config.d.ts +58 -0
- package/dist/provider-config.js +42 -0
- package/dist/runtime-control.d.ts +87 -10
- package/dist/runtime-control.js +159 -38
- package/dist/stream-events.d.ts +55 -0
- package/dist/stream-events.js +1 -0
- package/dist/workspace-branching-shared.d.ts +7 -0
- package/dist/workspace-branching-shared.js +20 -0
- package/dist/workspace-branching.d.ts +4 -254
- package/dist/workspace-branching.js +4 -400
- package/dist/workspace-checkpoint.d.ts +99 -0
- package/dist/workspace-checkpoint.js +169 -0
- package/dist/workspace-cleanup.d.ts +85 -0
- package/dist/workspace-cleanup.js +156 -0
- package/dist/workspace-confidentiality.d.ts +59 -0
- package/dist/workspace-confidentiality.js +123 -0
- package/dist/workspace-fork.d.ts +182 -0
- package/dist/workspace-fork.js +267 -0
- package/package.json +1 -1
package/dist/parts.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/** Base fields shared by all parts. */
|
|
2
|
+
export type PartBase = {
|
|
3
|
+
id: string;
|
|
4
|
+
sessionID: string;
|
|
5
|
+
messageID: string;
|
|
6
|
+
};
|
|
7
|
+
export type TextPart = PartBase & {
|
|
8
|
+
type: "text";
|
|
9
|
+
text: string;
|
|
10
|
+
};
|
|
11
|
+
export type ToolStatePending = {
|
|
12
|
+
status: "pending";
|
|
13
|
+
input: Record<string, unknown>;
|
|
14
|
+
raw?: string;
|
|
15
|
+
};
|
|
16
|
+
export type ToolStateRunning = {
|
|
17
|
+
status: "running";
|
|
18
|
+
input: Record<string, unknown>;
|
|
19
|
+
title?: string;
|
|
20
|
+
metadata?: Record<string, unknown>;
|
|
21
|
+
time?: {
|
|
22
|
+
start: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type ToolStateCompleted = {
|
|
26
|
+
status: "completed";
|
|
27
|
+
input: Record<string, unknown>;
|
|
28
|
+
output: unknown;
|
|
29
|
+
title?: string;
|
|
30
|
+
metadata?: Record<string, unknown>;
|
|
31
|
+
time?: {
|
|
32
|
+
start: number;
|
|
33
|
+
end: number;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type ToolStateError = {
|
|
37
|
+
status: "error" | "failed";
|
|
38
|
+
input: Record<string, unknown>;
|
|
39
|
+
error?: string;
|
|
40
|
+
output?: unknown;
|
|
41
|
+
metadata?: Record<string, unknown>;
|
|
42
|
+
time?: {
|
|
43
|
+
start: number;
|
|
44
|
+
end?: number;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type ToolState = ToolStatePending | ToolStateRunning | ToolStateCompleted | ToolStateError;
|
|
48
|
+
export type ToolPart = PartBase & {
|
|
49
|
+
type: "tool";
|
|
50
|
+
callID?: string;
|
|
51
|
+
tool: string;
|
|
52
|
+
state: ToolState;
|
|
53
|
+
metadata?: Record<string, unknown>;
|
|
54
|
+
};
|
|
55
|
+
export type ReasoningPart = PartBase & {
|
|
56
|
+
type: "reasoning";
|
|
57
|
+
text: string;
|
|
58
|
+
};
|
|
59
|
+
export type FilePart = PartBase & {
|
|
60
|
+
type: "file";
|
|
61
|
+
filename?: string;
|
|
62
|
+
mediaType?: string;
|
|
63
|
+
url?: string;
|
|
64
|
+
};
|
|
65
|
+
export type SubtaskPart = PartBase & {
|
|
66
|
+
type: "subtask";
|
|
67
|
+
prompt: string;
|
|
68
|
+
description: string;
|
|
69
|
+
agent: string;
|
|
70
|
+
};
|
|
71
|
+
export type Part = TextPart | ToolPart | ReasoningPart | FilePart | SubtaskPart;
|
|
72
|
+
export declare function isTextPart(part: Part): part is TextPart;
|
|
73
|
+
export declare function isToolPart(part: Part): part is ToolPart;
|
|
74
|
+
export declare function isReasoningPart(part: Part): part is ReasoningPart;
|
|
75
|
+
export declare function isFilePart(part: Part): part is FilePart;
|
|
76
|
+
export declare function isSubtaskPart(part: Part): part is SubtaskPart;
|
|
77
|
+
export type InputTextPart = {
|
|
78
|
+
type: "text";
|
|
79
|
+
text: string;
|
|
80
|
+
};
|
|
81
|
+
export type InputFilePart = {
|
|
82
|
+
type: "file";
|
|
83
|
+
filename?: string;
|
|
84
|
+
mediaType?: string;
|
|
85
|
+
url?: string;
|
|
86
|
+
path?: string;
|
|
87
|
+
content?: string;
|
|
88
|
+
};
|
|
89
|
+
export type InputImagePart = {
|
|
90
|
+
type: "image";
|
|
91
|
+
filename?: string;
|
|
92
|
+
mediaType?: string;
|
|
93
|
+
url?: string;
|
|
94
|
+
path?: string;
|
|
95
|
+
};
|
|
96
|
+
export type InputPart = InputTextPart | InputFilePart | InputImagePart;
|
|
97
|
+
export declare function isInputTextPart(part: InputPart): part is InputTextPart;
|
|
98
|
+
export declare function isInputFilePart(part: InputPart): part is InputFilePart;
|
|
99
|
+
export declare function isInputImagePart(part: InputPart): part is InputImagePart;
|
|
100
|
+
export declare function normalizeInputParts(input: {
|
|
101
|
+
message?: string;
|
|
102
|
+
parts?: InputPart[];
|
|
103
|
+
}): InputPart[];
|
|
104
|
+
export declare function renderInputPartsAsText(parts: InputPart[]): string;
|
package/dist/parts.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export function isTextPart(part) {
|
|
2
|
+
return part.type === "text";
|
|
3
|
+
}
|
|
4
|
+
export function isToolPart(part) {
|
|
5
|
+
return part.type === "tool";
|
|
6
|
+
}
|
|
7
|
+
export function isReasoningPart(part) {
|
|
8
|
+
return part.type === "reasoning";
|
|
9
|
+
}
|
|
10
|
+
export function isFilePart(part) {
|
|
11
|
+
return part.type === "file";
|
|
12
|
+
}
|
|
13
|
+
export function isSubtaskPart(part) {
|
|
14
|
+
return part.type === "subtask";
|
|
15
|
+
}
|
|
16
|
+
export function isInputTextPart(part) {
|
|
17
|
+
return part.type === "text";
|
|
18
|
+
}
|
|
19
|
+
export function isInputFilePart(part) {
|
|
20
|
+
return part.type === "file";
|
|
21
|
+
}
|
|
22
|
+
export function isInputImagePart(part) {
|
|
23
|
+
return part.type === "image";
|
|
24
|
+
}
|
|
25
|
+
export function normalizeInputParts(input) {
|
|
26
|
+
if (Array.isArray(input.parts) && input.parts.length > 0) {
|
|
27
|
+
return input.parts;
|
|
28
|
+
}
|
|
29
|
+
if (typeof input.message === "string" && input.message.length > 0) {
|
|
30
|
+
return [{ type: "text", text: input.message }];
|
|
31
|
+
}
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
export function renderInputPartsAsText(parts) {
|
|
35
|
+
const textParts = [];
|
|
36
|
+
const attachmentRefs = [];
|
|
37
|
+
for (const part of parts) {
|
|
38
|
+
if (part.type === "text") {
|
|
39
|
+
if (part.text)
|
|
40
|
+
textParts.push(part.text);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const label = part.path ||
|
|
44
|
+
part.filename ||
|
|
45
|
+
part.url ||
|
|
46
|
+
(part.type === "image" ? "image attachment" : "file attachment");
|
|
47
|
+
attachmentRefs.push(`[${part.type === "image" ? "Image" : "File"}: ${label}]`);
|
|
48
|
+
}
|
|
49
|
+
if (attachmentRefs.length === 0) {
|
|
50
|
+
return textParts.join("\n\n").trim();
|
|
51
|
+
}
|
|
52
|
+
const text = textParts.join("\n\n").trim();
|
|
53
|
+
const attachmentBlock = `Attached files:\n${attachmentRefs.join("\n")}`;
|
|
54
|
+
return text ? `${text}\n\n${attachmentBlock}` : attachmentBlock;
|
|
55
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Sha256Digest } from "./agent-candidate.js";
|
|
3
|
+
import type { BackendMessage } from "./backend-message.js";
|
|
4
|
+
export interface PortableContextSourceBoundary {
|
|
5
|
+
runId: string;
|
|
6
|
+
messageId: string;
|
|
7
|
+
provider: string;
|
|
8
|
+
environmentId: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
executionId: string;
|
|
11
|
+
requestDigest: Sha256Digest;
|
|
12
|
+
branchId?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const PortableContextSourceBoundarySchema: z.ZodObject<{
|
|
15
|
+
runId: z.ZodString;
|
|
16
|
+
messageId: z.ZodString;
|
|
17
|
+
provider: z.ZodString;
|
|
18
|
+
environmentId: z.ZodString;
|
|
19
|
+
sessionId: z.ZodString;
|
|
20
|
+
executionId: z.ZodString;
|
|
21
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
22
|
+
branchId: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
export interface PortableContextAttachmentRef {
|
|
25
|
+
messageId: string;
|
|
26
|
+
partIndex: number;
|
|
27
|
+
digest: Sha256Digest;
|
|
28
|
+
name?: string;
|
|
29
|
+
mediaType?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare const PortableContextAttachmentRefSchema: z.ZodObject<{
|
|
32
|
+
messageId: z.ZodString;
|
|
33
|
+
partIndex: z.ZodNumber;
|
|
34
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
35
|
+
name: z.ZodOptional<z.ZodString>;
|
|
36
|
+
mediaType: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
export interface PortableConversationContext {
|
|
39
|
+
source: PortableContextSourceBoundary;
|
|
40
|
+
completeness: "complete" | "partial";
|
|
41
|
+
messages: BackendMessage[];
|
|
42
|
+
attachments: PortableContextAttachmentRef[];
|
|
43
|
+
digest: Sha256Digest;
|
|
44
|
+
}
|
|
45
|
+
type PortableConversationContextMaterial = Omit<PortableConversationContext, "digest">;
|
|
46
|
+
export declare function portableConversationContextDigest(context: PortableConversationContextMaterial): Sha256Digest;
|
|
47
|
+
export declare const PortableConversationContextSchema: z.ZodObject<{
|
|
48
|
+
source: z.ZodObject<{
|
|
49
|
+
runId: z.ZodString;
|
|
50
|
+
messageId: z.ZodString;
|
|
51
|
+
provider: z.ZodString;
|
|
52
|
+
environmentId: z.ZodString;
|
|
53
|
+
sessionId: z.ZodString;
|
|
54
|
+
executionId: z.ZodString;
|
|
55
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
56
|
+
branchId: z.ZodOptional<z.ZodString>;
|
|
57
|
+
}, z.core.$strict>;
|
|
58
|
+
completeness: z.ZodEnum<{
|
|
59
|
+
complete: "complete";
|
|
60
|
+
partial: "partial";
|
|
61
|
+
}>;
|
|
62
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
63
|
+
id: z.ZodString;
|
|
64
|
+
role: z.ZodEnum<{
|
|
65
|
+
user: "user";
|
|
66
|
+
assistant: "assistant";
|
|
67
|
+
system: "system";
|
|
68
|
+
}>;
|
|
69
|
+
parts: z.ZodArray<z.ZodCustom<unknown, unknown>>;
|
|
70
|
+
timestamp: z.ZodISODateTime;
|
|
71
|
+
metadata: z.ZodOptional<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
|
|
72
|
+
}, z.core.$strict>>;
|
|
73
|
+
attachments: z.ZodArray<z.ZodObject<{
|
|
74
|
+
messageId: z.ZodString;
|
|
75
|
+
partIndex: z.ZodNumber;
|
|
76
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
77
|
+
name: z.ZodOptional<z.ZodString>;
|
|
78
|
+
mediaType: z.ZodOptional<z.ZodString>;
|
|
79
|
+
}, z.core.$strict>>;
|
|
80
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
81
|
+
}, z.core.$strict>;
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BackendMessageSchema, idSchema, sha256DigestSchema, wireDigest, } from "./portable-context-shared.js";
|
|
3
|
+
export const PortableContextSourceBoundarySchema = z.strictObject({
|
|
4
|
+
runId: idSchema,
|
|
5
|
+
messageId: idSchema,
|
|
6
|
+
provider: idSchema,
|
|
7
|
+
environmentId: idSchema,
|
|
8
|
+
sessionId: idSchema,
|
|
9
|
+
executionId: idSchema,
|
|
10
|
+
requestDigest: sha256DigestSchema,
|
|
11
|
+
branchId: idSchema.optional(),
|
|
12
|
+
});
|
|
13
|
+
export const PortableContextAttachmentRefSchema = z.strictObject({
|
|
14
|
+
messageId: idSchema,
|
|
15
|
+
partIndex: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
16
|
+
digest: sha256DigestSchema,
|
|
17
|
+
name: idSchema.optional(),
|
|
18
|
+
mediaType: idSchema.optional(),
|
|
19
|
+
});
|
|
20
|
+
export function portableConversationContextDigest(context) {
|
|
21
|
+
return wireDigest(context);
|
|
22
|
+
}
|
|
23
|
+
export const PortableConversationContextSchema = z
|
|
24
|
+
.strictObject({
|
|
25
|
+
source: PortableContextSourceBoundarySchema,
|
|
26
|
+
completeness: z.enum(["complete", "partial"]),
|
|
27
|
+
messages: z.array(BackendMessageSchema).max(1_024),
|
|
28
|
+
attachments: z.array(PortableContextAttachmentRefSchema).max(1_024),
|
|
29
|
+
digest: sha256DigestSchema,
|
|
30
|
+
})
|
|
31
|
+
.superRefine((context, refinement) => {
|
|
32
|
+
const messageIds = context.messages.map((message) => message.id);
|
|
33
|
+
if (new Set(messageIds).size !== messageIds.length) {
|
|
34
|
+
refinement.addIssue({
|
|
35
|
+
code: "custom",
|
|
36
|
+
path: ["messages"],
|
|
37
|
+
message: "portable context message ids must be unique",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
for (const attachment of context.attachments) {
|
|
41
|
+
const message = context.messages.find((candidate) => candidate.id === attachment.messageId);
|
|
42
|
+
if (!message || attachment.partIndex >= message.parts.length) {
|
|
43
|
+
refinement.addIssue({
|
|
44
|
+
code: "custom",
|
|
45
|
+
path: ["attachments"],
|
|
46
|
+
message: "attachment must reference a part in the portable context",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (context.digest !==
|
|
51
|
+
portableConversationContextDigest({
|
|
52
|
+
source: context.source,
|
|
53
|
+
completeness: context.completeness,
|
|
54
|
+
messages: context.messages,
|
|
55
|
+
attachments: context.attachments,
|
|
56
|
+
})) {
|
|
57
|
+
refinement.addIssue({
|
|
58
|
+
code: "custom",
|
|
59
|
+
path: ["digest"],
|
|
60
|
+
message: "portable context digest does not match its content",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Sha256Digest } from "./agent-candidate.js";
|
|
3
|
+
import { type AgentExactRunControlRef } from "./runtime-control.js";
|
|
4
|
+
export declare const NativeContextBoundarySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
5
|
+
kind: z.ZodLiteral<"token">;
|
|
6
|
+
token: z.ZodString;
|
|
7
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
8
|
+
kind: z.ZodLiteral<"revision">;
|
|
9
|
+
revision: z.ZodString;
|
|
10
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
11
|
+
kind: z.ZodLiteral<"digest">;
|
|
12
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
13
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
14
|
+
kind: z.ZodLiteral<"messages">;
|
|
15
|
+
messageIds: z.ZodArray<z.ZodString>;
|
|
16
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
17
|
+
}, z.core.$strict>], "kind">;
|
|
18
|
+
export type NativeContextBoundary = z.infer<typeof NativeContextBoundarySchema>;
|
|
19
|
+
export declare const NativeContextBoundaryProofSchema: z.ZodObject<{
|
|
20
|
+
runId: z.ZodString;
|
|
21
|
+
provider: z.ZodString;
|
|
22
|
+
environmentId: z.ZodString;
|
|
23
|
+
sessionId: z.ZodString;
|
|
24
|
+
executionId: z.ZodString;
|
|
25
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
26
|
+
boundary: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
27
|
+
kind: z.ZodLiteral<"token">;
|
|
28
|
+
token: z.ZodString;
|
|
29
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
30
|
+
kind: z.ZodLiteral<"revision">;
|
|
31
|
+
revision: z.ZodString;
|
|
32
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
33
|
+
kind: z.ZodLiteral<"digest">;
|
|
34
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
35
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
36
|
+
kind: z.ZodLiteral<"messages">;
|
|
37
|
+
messageIds: z.ZodArray<z.ZodString>;
|
|
38
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
39
|
+
}, z.core.$strict>], "kind">;
|
|
40
|
+
observedAt: z.ZodISODateTime;
|
|
41
|
+
}, z.core.$strict>;
|
|
42
|
+
export type NativeContextBoundaryProof = z.infer<typeof NativeContextBoundaryProofSchema>;
|
|
43
|
+
export interface NativeContextContinuationRequest {
|
|
44
|
+
operationId: string;
|
|
45
|
+
requestDigest: Sha256Digest;
|
|
46
|
+
turnDigest: Sha256Digest;
|
|
47
|
+
run: AgentExactRunControlRef;
|
|
48
|
+
expectedBoundary: NativeContextBoundaryProof;
|
|
49
|
+
}
|
|
50
|
+
export interface NativeContextContinuationRequestMaterial {
|
|
51
|
+
operationId: string;
|
|
52
|
+
turnDigest: Sha256Digest;
|
|
53
|
+
run: AgentExactRunControlRef;
|
|
54
|
+
expectedBoundary: NativeContextBoundaryProof;
|
|
55
|
+
}
|
|
56
|
+
/** JSON-stable user turn admitted by a native same-session continuation. */
|
|
57
|
+
export interface NativeContextContinuationTurn {
|
|
58
|
+
prompt?: string;
|
|
59
|
+
parts?: import("./parts.js").InputPart[];
|
|
60
|
+
model?: string;
|
|
61
|
+
context?: Record<string, unknown>;
|
|
62
|
+
providerOptions?: Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
export declare const NativeContextContinuationTurnSchema: z.ZodObject<{
|
|
65
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
66
|
+
parts: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
67
|
+
type: z.ZodLiteral<"text">;
|
|
68
|
+
text: z.ZodString;
|
|
69
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
70
|
+
type: z.ZodLiteral<"file">;
|
|
71
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
72
|
+
mediaType: z.ZodOptional<z.ZodString>;
|
|
73
|
+
url: z.ZodOptional<z.ZodString>;
|
|
74
|
+
path: z.ZodOptional<z.ZodString>;
|
|
75
|
+
content: z.ZodOptional<z.ZodString>;
|
|
76
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
77
|
+
type: z.ZodLiteral<"image">;
|
|
78
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
79
|
+
mediaType: z.ZodOptional<z.ZodString>;
|
|
80
|
+
url: z.ZodOptional<z.ZodString>;
|
|
81
|
+
path: z.ZodOptional<z.ZodString>;
|
|
82
|
+
}, z.core.$strict>], "type">>>;
|
|
83
|
+
model: z.ZodOptional<z.ZodString>;
|
|
84
|
+
context: z.ZodOptional<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
|
|
85
|
+
providerOptions: z.ZodOptional<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
|
|
86
|
+
}, z.core.$strict>;
|
|
87
|
+
/** Bind retry identity to the exact new user turn. */
|
|
88
|
+
export declare function nativeContextContinuationTurnDigest(turn: NativeContextContinuationTurn): Sha256Digest;
|
|
89
|
+
export declare function nativeContextContinuationRequestDigest(request: NativeContextContinuationRequestMaterial): Sha256Digest;
|
|
90
|
+
export declare const NativeContextContinuationRequestSchema: z.ZodObject<{
|
|
91
|
+
operationId: z.ZodString;
|
|
92
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
93
|
+
turnDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
94
|
+
run: z.ZodObject<{
|
|
95
|
+
runId: z.ZodString;
|
|
96
|
+
provider: z.ZodString;
|
|
97
|
+
environmentId: z.ZodString;
|
|
98
|
+
sessionId: z.ZodString;
|
|
99
|
+
executionId: z.ZodString;
|
|
100
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
101
|
+
}, z.core.$strict>;
|
|
102
|
+
expectedBoundary: z.ZodObject<{
|
|
103
|
+
runId: z.ZodString;
|
|
104
|
+
provider: z.ZodString;
|
|
105
|
+
environmentId: z.ZodString;
|
|
106
|
+
sessionId: z.ZodString;
|
|
107
|
+
executionId: z.ZodString;
|
|
108
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
109
|
+
boundary: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
110
|
+
kind: z.ZodLiteral<"token">;
|
|
111
|
+
token: z.ZodString;
|
|
112
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
113
|
+
kind: z.ZodLiteral<"revision">;
|
|
114
|
+
revision: z.ZodString;
|
|
115
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
116
|
+
kind: z.ZodLiteral<"digest">;
|
|
117
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
118
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
119
|
+
kind: z.ZodLiteral<"messages">;
|
|
120
|
+
messageIds: z.ZodArray<z.ZodString>;
|
|
121
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
122
|
+
}, z.core.$strict>], "kind">;
|
|
123
|
+
observedAt: z.ZodISODateTime;
|
|
124
|
+
}, z.core.$strict>;
|
|
125
|
+
}, z.core.$strict>;
|
|
126
|
+
export declare const NativeContextContinuationAcknowledgementSchema: z.ZodObject<{
|
|
127
|
+
operationId: z.ZodString;
|
|
128
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
129
|
+
status: z.ZodEnum<{
|
|
130
|
+
conflict: "conflict";
|
|
131
|
+
accepted: "accepted";
|
|
132
|
+
transport_failure: "transport_failure";
|
|
133
|
+
replayed: "replayed";
|
|
134
|
+
boundary_mismatch: "boundary_mismatch";
|
|
135
|
+
unverified: "unverified";
|
|
136
|
+
unknown_session: "unknown_session";
|
|
137
|
+
}>;
|
|
138
|
+
historyMessagesSent: z.ZodNumber;
|
|
139
|
+
existingRequestDigest: z.ZodOptional<z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>>;
|
|
140
|
+
actualBoundary: z.ZodOptional<z.ZodObject<{
|
|
141
|
+
runId: z.ZodString;
|
|
142
|
+
provider: z.ZodString;
|
|
143
|
+
environmentId: z.ZodString;
|
|
144
|
+
sessionId: z.ZodString;
|
|
145
|
+
executionId: z.ZodString;
|
|
146
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
147
|
+
boundary: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
148
|
+
kind: z.ZodLiteral<"token">;
|
|
149
|
+
token: z.ZodString;
|
|
150
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
151
|
+
kind: z.ZodLiteral<"revision">;
|
|
152
|
+
revision: z.ZodString;
|
|
153
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
154
|
+
kind: z.ZodLiteral<"digest">;
|
|
155
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
156
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
157
|
+
kind: z.ZodLiteral<"messages">;
|
|
158
|
+
messageIds: z.ZodArray<z.ZodString>;
|
|
159
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
160
|
+
}, z.core.$strict>], "kind">;
|
|
161
|
+
observedAt: z.ZodISODateTime;
|
|
162
|
+
}, z.core.$strict>>;
|
|
163
|
+
message: z.ZodOptional<z.ZodString>;
|
|
164
|
+
retryable: z.ZodOptional<z.ZodBoolean>;
|
|
165
|
+
}, z.core.$strict>;
|
|
166
|
+
export type NativeContextContinuationAcknowledgement = z.infer<typeof NativeContextContinuationAcknowledgementSchema>;
|
|
167
|
+
/** Exact cross-check required before accepting a native continuation result. */
|
|
168
|
+
export declare function nativeContextContinuationAcknowledgementMatches(request: NativeContextContinuationRequest, acknowledgement: NativeContextContinuationAcknowledgement): boolean;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AgentExactRunControlRefSchema, } from "./runtime-control.js";
|
|
3
|
+
import { idSchema, InputPartSchema, jsonRecordSchema, sha256DigestSchema, wireDigest } from "./portable-context-shared.js";
|
|
4
|
+
import { boundedStringSchema, CONTRACT_MAX_ARRAY_LENGTH } from "./contract-limits.js";
|
|
5
|
+
export const NativeContextBoundarySchema = z
|
|
6
|
+
.discriminatedUnion("kind", [
|
|
7
|
+
z.strictObject({ kind: z.literal("token"), token: idSchema }),
|
|
8
|
+
z.strictObject({ kind: z.literal("revision"), revision: idSchema }),
|
|
9
|
+
z.strictObject({ kind: z.literal("digest"), digest: sha256DigestSchema }),
|
|
10
|
+
z.strictObject({
|
|
11
|
+
kind: z.literal("messages"),
|
|
12
|
+
messageIds: z.array(idSchema).max(CONTRACT_MAX_ARRAY_LENGTH),
|
|
13
|
+
digest: sha256DigestSchema,
|
|
14
|
+
}),
|
|
15
|
+
])
|
|
16
|
+
.superRefine((boundary, refinement) => {
|
|
17
|
+
if (boundary.kind === "messages" &&
|
|
18
|
+
new Set(boundary.messageIds).size !== boundary.messageIds.length) {
|
|
19
|
+
refinement.addIssue({
|
|
20
|
+
code: "custom",
|
|
21
|
+
path: ["messageIds"],
|
|
22
|
+
message: "native context boundary message ids must be unique",
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
export const NativeContextBoundaryProofSchema = z.strictObject({
|
|
27
|
+
runId: idSchema,
|
|
28
|
+
provider: idSchema,
|
|
29
|
+
environmentId: idSchema,
|
|
30
|
+
sessionId: idSchema,
|
|
31
|
+
executionId: idSchema,
|
|
32
|
+
requestDigest: sha256DigestSchema,
|
|
33
|
+
boundary: NativeContextBoundarySchema,
|
|
34
|
+
observedAt: z.iso.datetime().max(64),
|
|
35
|
+
});
|
|
36
|
+
const NativeContextContinuationRequestMaterialSchema = z.strictObject({
|
|
37
|
+
operationId: idSchema,
|
|
38
|
+
turnDigest: sha256DigestSchema,
|
|
39
|
+
run: AgentExactRunControlRefSchema,
|
|
40
|
+
expectedBoundary: NativeContextBoundaryProofSchema,
|
|
41
|
+
});
|
|
42
|
+
export const NativeContextContinuationTurnSchema = z.strictObject({
|
|
43
|
+
prompt: boundedStringSchema.optional(),
|
|
44
|
+
parts: z.array(InputPartSchema).max(CONTRACT_MAX_ARRAY_LENGTH).optional(),
|
|
45
|
+
model: idSchema.optional(),
|
|
46
|
+
context: jsonRecordSchema.optional(),
|
|
47
|
+
providerOptions: jsonRecordSchema.optional(),
|
|
48
|
+
});
|
|
49
|
+
/** Bind retry identity to the exact new user turn. */
|
|
50
|
+
export function nativeContextContinuationTurnDigest(turn) {
|
|
51
|
+
return wireDigest(NativeContextContinuationTurnSchema.parse(turn));
|
|
52
|
+
}
|
|
53
|
+
export function nativeContextContinuationRequestDigest(request) {
|
|
54
|
+
const parsed = NativeContextContinuationRequestMaterialSchema.parse(request);
|
|
55
|
+
return wireDigest({
|
|
56
|
+
turnDigest: parsed.turnDigest,
|
|
57
|
+
operationId: parsed.operationId,
|
|
58
|
+
run: parsed.run,
|
|
59
|
+
expectedBoundary: parsed.expectedBoundary,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export const NativeContextContinuationRequestSchema = z
|
|
63
|
+
.strictObject({
|
|
64
|
+
operationId: idSchema,
|
|
65
|
+
requestDigest: sha256DigestSchema,
|
|
66
|
+
turnDigest: sha256DigestSchema,
|
|
67
|
+
run: AgentExactRunControlRefSchema,
|
|
68
|
+
expectedBoundary: NativeContextBoundaryProofSchema,
|
|
69
|
+
})
|
|
70
|
+
.superRefine((request, refinement) => {
|
|
71
|
+
const proof = request.expectedBoundary;
|
|
72
|
+
if (request.run.runId !== proof.runId ||
|
|
73
|
+
request.run.provider !== proof.provider ||
|
|
74
|
+
request.run.environmentId !== proof.environmentId ||
|
|
75
|
+
request.run.sessionId !== proof.sessionId ||
|
|
76
|
+
request.run.executionId !== proof.executionId ||
|
|
77
|
+
request.run.requestDigest !== proof.requestDigest) {
|
|
78
|
+
refinement.addIssue({
|
|
79
|
+
code: "custom",
|
|
80
|
+
path: ["expectedBoundary"],
|
|
81
|
+
message: "boundary proof must match the continued run",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const { requestDigest: _requestDigest, ...material } = request;
|
|
85
|
+
if (request.requestDigest !== nativeContextContinuationRequestDigest(material)) {
|
|
86
|
+
refinement.addIssue({
|
|
87
|
+
code: "custom",
|
|
88
|
+
path: ["requestDigest"],
|
|
89
|
+
message: "native continuation request digest does not match its content",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
export const NativeContextContinuationAcknowledgementSchema = z
|
|
94
|
+
.strictObject({
|
|
95
|
+
operationId: idSchema,
|
|
96
|
+
requestDigest: sha256DigestSchema,
|
|
97
|
+
status: z.enum([
|
|
98
|
+
"accepted",
|
|
99
|
+
"replayed",
|
|
100
|
+
"conflict",
|
|
101
|
+
"boundary_mismatch",
|
|
102
|
+
"unverified",
|
|
103
|
+
"unknown_session",
|
|
104
|
+
"transport_failure",
|
|
105
|
+
]),
|
|
106
|
+
historyMessagesSent: z.number().int().nonnegative().max(CONTRACT_MAX_ARRAY_LENGTH),
|
|
107
|
+
existingRequestDigest: sha256DigestSchema.optional(),
|
|
108
|
+
actualBoundary: NativeContextBoundaryProofSchema.optional(),
|
|
109
|
+
message: boundedStringSchema.min(1).optional(),
|
|
110
|
+
retryable: z.boolean().optional(),
|
|
111
|
+
})
|
|
112
|
+
.superRefine((acknowledgement, refinement) => {
|
|
113
|
+
if (acknowledgement.status === "conflict" &&
|
|
114
|
+
acknowledgement.existingRequestDigest === undefined) {
|
|
115
|
+
refinement.addIssue({
|
|
116
|
+
code: "custom",
|
|
117
|
+
path: ["existingRequestDigest"],
|
|
118
|
+
message: "a continuation conflict must include the existing digest",
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (acknowledgement.status === "conflict" &&
|
|
122
|
+
acknowledgement.existingRequestDigest === acknowledgement.requestDigest) {
|
|
123
|
+
refinement.addIssue({
|
|
124
|
+
code: "custom",
|
|
125
|
+
path: ["existingRequestDigest"],
|
|
126
|
+
message: "a continuation conflict must identify a different request",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (acknowledgement.status !== "conflict" &&
|
|
130
|
+
acknowledgement.existingRequestDigest !== undefined) {
|
|
131
|
+
refinement.addIssue({
|
|
132
|
+
code: "custom",
|
|
133
|
+
path: ["existingRequestDigest"],
|
|
134
|
+
message: "only a continuation conflict may include an existing digest",
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (acknowledgement.status === "transport_failure" &&
|
|
138
|
+
acknowledgement.message === undefined) {
|
|
139
|
+
refinement.addIssue({
|
|
140
|
+
code: "custom",
|
|
141
|
+
path: ["message"],
|
|
142
|
+
message: "a continuation transport failure must include a message",
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
if (acknowledgement.status === "transport_failure" &&
|
|
146
|
+
acknowledgement.retryable === undefined) {
|
|
147
|
+
refinement.addIssue({
|
|
148
|
+
code: "custom",
|
|
149
|
+
path: ["retryable"],
|
|
150
|
+
message: "a continuation transport failure must state whether retry is safe",
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (["accepted", "replayed", "boundary_mismatch"].includes(acknowledgement.status) &&
|
|
154
|
+
acknowledgement.actualBoundary === undefined) {
|
|
155
|
+
refinement.addIssue({
|
|
156
|
+
code: "custom",
|
|
157
|
+
path: ["actualBoundary"],
|
|
158
|
+
message: `${acknowledgement.status} must include the observed boundary`,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
/** Exact cross-check required before accepting a native continuation result. */
|
|
163
|
+
export function nativeContextContinuationAcknowledgementMatches(request, acknowledgement) {
|
|
164
|
+
const parsedRequest = NativeContextContinuationRequestSchema.safeParse(request);
|
|
165
|
+
const parsedAcknowledgement = NativeContextContinuationAcknowledgementSchema.safeParse(acknowledgement);
|
|
166
|
+
if (!parsedRequest.success || !parsedAcknowledgement.success)
|
|
167
|
+
return false;
|
|
168
|
+
const exactRequest = parsedRequest.data;
|
|
169
|
+
const exactAcknowledgement = parsedAcknowledgement.data;
|
|
170
|
+
if (exactAcknowledgement.operationId !== exactRequest.operationId ||
|
|
171
|
+
exactAcknowledgement.requestDigest !== exactRequest.requestDigest ||
|
|
172
|
+
exactAcknowledgement.historyMessagesSent !== 0 ||
|
|
173
|
+
(exactAcknowledgement.status !== "accepted" &&
|
|
174
|
+
exactAcknowledgement.status !== "replayed")) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
const actual = exactAcknowledgement.actualBoundary;
|
|
178
|
+
if (actual !== undefined && !boundaryProofMatchesRun(exactRequest.run, actual)) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
return (actual !== undefined &&
|
|
182
|
+
Date.parse(actual.observedAt) >=
|
|
183
|
+
Date.parse(exactRequest.expectedBoundary.observedAt) &&
|
|
184
|
+
wireDigest(actual.boundary) ===
|
|
185
|
+
wireDigest(exactRequest.expectedBoundary.boundary));
|
|
186
|
+
}
|
|
187
|
+
function boundaryProofMatchesRun(run, proof) {
|
|
188
|
+
return (proof.runId === run.runId &&
|
|
189
|
+
proof.provider === run.provider &&
|
|
190
|
+
proof.environmentId === run.environmentId &&
|
|
191
|
+
proof.sessionId === run.sessionId &&
|
|
192
|
+
proof.executionId === run.executionId &&
|
|
193
|
+
proof.requestDigest === run.requestDigest);
|
|
194
|
+
}
|