@tangle-network/agent-interface 0.45.0 → 0.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/agent-candidate-profile-schema.d.ts +2 -2
- package/dist/agent-candidate-promotion-schema.d.ts +22 -22
- package/dist/agent-candidate-schema-common.js +1 -1
- package/dist/agent-candidate-schema.d.ts +2 -2
- package/dist/agent-execution-preparation.d.ts +26 -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 +50 -0
- package/dist/execution-types.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 +267 -0
- package/dist/interaction-envelope.js +247 -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/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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Sha256Digest } from "./agent-candidate.js";
|
|
3
|
+
import { sha256DigestSchema } from "./agent-candidate-schema-common.js";
|
|
4
|
+
export { sha256DigestSchema };
|
|
5
|
+
export declare const idSchema: z.ZodString;
|
|
6
|
+
export declare const jsonRecordSchema: z.ZodCustom<Record<string, unknown>, Record<string, unknown>>;
|
|
7
|
+
export declare function wireDigest(value: unknown): Sha256Digest;
|
|
8
|
+
export declare const InputPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
9
|
+
type: z.ZodLiteral<"text">;
|
|
10
|
+
text: z.ZodString;
|
|
11
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
12
|
+
type: z.ZodLiteral<"file">;
|
|
13
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
14
|
+
mediaType: z.ZodOptional<z.ZodString>;
|
|
15
|
+
url: z.ZodOptional<z.ZodString>;
|
|
16
|
+
path: z.ZodOptional<z.ZodString>;
|
|
17
|
+
content: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
19
|
+
type: z.ZodLiteral<"image">;
|
|
20
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
21
|
+
mediaType: z.ZodOptional<z.ZodString>;
|
|
22
|
+
url: z.ZodOptional<z.ZodString>;
|
|
23
|
+
path: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, z.core.$strict>], "type">;
|
|
25
|
+
export declare const BackendMessageSchema: z.ZodObject<{
|
|
26
|
+
id: z.ZodString;
|
|
27
|
+
role: z.ZodEnum<{
|
|
28
|
+
user: "user";
|
|
29
|
+
assistant: "assistant";
|
|
30
|
+
system: "system";
|
|
31
|
+
}>;
|
|
32
|
+
parts: z.ZodArray<z.ZodCustom<unknown, unknown>>;
|
|
33
|
+
timestamp: z.ZodISODateTime;
|
|
34
|
+
metadata: z.ZodOptional<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
export declare function sameStringSet(left: readonly string[], right: readonly string[]): boolean;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { canonicalCandidateDigest, sha256DigestSchema } from "./agent-candidate-schema-common.js";
|
|
3
|
+
import { assertBoundedJson, assertBoundedSerializedJson, boundedIdentifierSchema, boundedJsonSchema, boundedJsonRecordSchema, boundedStringSchema, CONTRACT_MAX_ARRAY_LENGTH, isBoundedJsonMaterial, } from "./contract-limits.js";
|
|
4
|
+
export { sha256DigestSchema };
|
|
5
|
+
export const idSchema = boundedIdentifierSchema;
|
|
6
|
+
export const jsonRecordSchema = boundedJsonRecordSchema;
|
|
7
|
+
export function wireDigest(value) {
|
|
8
|
+
if (!isBoundedJsonMaterial(value)) {
|
|
9
|
+
throw new Error("operation material exceeds the contract bounds");
|
|
10
|
+
}
|
|
11
|
+
const serialized = JSON.stringify(value);
|
|
12
|
+
if (serialized === undefined)
|
|
13
|
+
throw new Error("portable context material must be JSON serializable");
|
|
14
|
+
assertBoundedSerializedJson(serialized);
|
|
15
|
+
const normalized = JSON.parse(serialized);
|
|
16
|
+
assertBoundedJson(normalized);
|
|
17
|
+
return canonicalCandidateDigest(normalized);
|
|
18
|
+
}
|
|
19
|
+
export const InputPartSchema = z.discriminatedUnion("type", [
|
|
20
|
+
z.strictObject({ type: z.literal("text"), text: boundedStringSchema }),
|
|
21
|
+
z.strictObject({
|
|
22
|
+
type: z.literal("file"),
|
|
23
|
+
filename: boundedStringSchema.optional(),
|
|
24
|
+
mediaType: boundedStringSchema.optional(),
|
|
25
|
+
url: boundedStringSchema.optional(),
|
|
26
|
+
path: boundedStringSchema.optional(),
|
|
27
|
+
content: boundedStringSchema.optional(),
|
|
28
|
+
}),
|
|
29
|
+
z.strictObject({
|
|
30
|
+
type: z.literal("image"),
|
|
31
|
+
filename: boundedStringSchema.optional(),
|
|
32
|
+
mediaType: boundedStringSchema.optional(),
|
|
33
|
+
url: boundedStringSchema.optional(),
|
|
34
|
+
path: boundedStringSchema.optional(),
|
|
35
|
+
}),
|
|
36
|
+
]);
|
|
37
|
+
export const BackendMessageSchema = z.strictObject({
|
|
38
|
+
id: idSchema,
|
|
39
|
+
role: z.enum(["user", "assistant", "system"]),
|
|
40
|
+
parts: z.array(boundedJsonSchema).max(CONTRACT_MAX_ARRAY_LENGTH),
|
|
41
|
+
timestamp: z.iso.datetime().max(64),
|
|
42
|
+
metadata: jsonRecordSchema.optional(),
|
|
43
|
+
});
|
|
44
|
+
export function sameStringSet(left, right) {
|
|
45
|
+
return left.length === right.length && JSON.stringify([...left].sort()) === JSON.stringify([...right].sort());
|
|
46
|
+
}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Sha256Digest } from "./agent-candidate.js";
|
|
3
|
+
import { type PortableContextPlan } from "./portable-context-plan.js";
|
|
4
|
+
export declare const ContextPlanAcceptanceSchema: z.ZodObject<{
|
|
5
|
+
planDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
6
|
+
acceptedAt: z.ZodISODateTime;
|
|
7
|
+
acceptedBy: z.ZodEnum<{
|
|
8
|
+
policy: "policy";
|
|
9
|
+
user: "user";
|
|
10
|
+
system: "system";
|
|
11
|
+
}>;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
export type ContextPlanAcceptance = z.infer<typeof ContextPlanAcceptanceSchema>;
|
|
14
|
+
export interface ContextTransferRequestMaterial {
|
|
15
|
+
operationId: string;
|
|
16
|
+
plan: PortableContextPlan;
|
|
17
|
+
acceptance: ContextPlanAcceptance;
|
|
18
|
+
}
|
|
19
|
+
export declare function contextTransferRequestDigest(request: ContextTransferRequestMaterial): Sha256Digest;
|
|
20
|
+
export declare const ContextTransferRequestSchema: z.ZodObject<{
|
|
21
|
+
operationId: z.ZodString;
|
|
22
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
23
|
+
plan: z.ZodObject<{
|
|
24
|
+
planId: z.ZodString;
|
|
25
|
+
source: z.ZodObject<{
|
|
26
|
+
source: z.ZodObject<{
|
|
27
|
+
runId: z.ZodString;
|
|
28
|
+
messageId: z.ZodString;
|
|
29
|
+
provider: z.ZodString;
|
|
30
|
+
environmentId: z.ZodString;
|
|
31
|
+
sessionId: z.ZodString;
|
|
32
|
+
executionId: z.ZodString;
|
|
33
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
34
|
+
branchId: z.ZodOptional<z.ZodString>;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
completeness: z.ZodEnum<{
|
|
37
|
+
complete: "complete";
|
|
38
|
+
partial: "partial";
|
|
39
|
+
}>;
|
|
40
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
41
|
+
id: z.ZodString;
|
|
42
|
+
role: z.ZodEnum<{
|
|
43
|
+
user: "user";
|
|
44
|
+
assistant: "assistant";
|
|
45
|
+
system: "system";
|
|
46
|
+
}>;
|
|
47
|
+
parts: z.ZodArray<z.ZodCustom<unknown, unknown>>;
|
|
48
|
+
timestamp: z.ZodISODateTime;
|
|
49
|
+
metadata: z.ZodOptional<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
|
|
50
|
+
}, z.core.$strict>>;
|
|
51
|
+
attachments: z.ZodArray<z.ZodObject<{
|
|
52
|
+
messageId: z.ZodString;
|
|
53
|
+
partIndex: z.ZodNumber;
|
|
54
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
55
|
+
name: z.ZodOptional<z.ZodString>;
|
|
56
|
+
mediaType: z.ZodOptional<z.ZodString>;
|
|
57
|
+
}, z.core.$strict>>;
|
|
58
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
59
|
+
}, z.core.$strict>;
|
|
60
|
+
destination: z.ZodObject<{
|
|
61
|
+
runner: z.ZodString;
|
|
62
|
+
provider: z.ZodString;
|
|
63
|
+
environmentId: z.ZodString;
|
|
64
|
+
sessionId: z.ZodString;
|
|
65
|
+
runId: z.ZodString;
|
|
66
|
+
executionId: z.ZodString;
|
|
67
|
+
model: z.ZodOptional<z.ZodString>;
|
|
68
|
+
profileDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
69
|
+
}, z.core.$strict>;
|
|
70
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
71
|
+
messageId: z.ZodString;
|
|
72
|
+
action: z.ZodEnum<{
|
|
73
|
+
include: "include";
|
|
74
|
+
omit: "omit";
|
|
75
|
+
}>;
|
|
76
|
+
parts: z.ZodArray<z.ZodObject<{
|
|
77
|
+
partIndex: z.ZodNumber;
|
|
78
|
+
action: z.ZodEnum<{
|
|
79
|
+
transform: "transform";
|
|
80
|
+
include: "include";
|
|
81
|
+
omit: "omit";
|
|
82
|
+
}>;
|
|
83
|
+
output: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
84
|
+
type: z.ZodLiteral<"text">;
|
|
85
|
+
text: z.ZodString;
|
|
86
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
87
|
+
type: z.ZodLiteral<"file">;
|
|
88
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
89
|
+
mediaType: z.ZodOptional<z.ZodString>;
|
|
90
|
+
url: z.ZodOptional<z.ZodString>;
|
|
91
|
+
path: z.ZodOptional<z.ZodString>;
|
|
92
|
+
content: z.ZodOptional<z.ZodString>;
|
|
93
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
94
|
+
type: z.ZodLiteral<"image">;
|
|
95
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
96
|
+
mediaType: z.ZodOptional<z.ZodString>;
|
|
97
|
+
url: z.ZodOptional<z.ZodString>;
|
|
98
|
+
path: z.ZodOptional<z.ZodString>;
|
|
99
|
+
}, z.core.$strict>], "type">>;
|
|
100
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
101
|
+
}, z.core.$strict>>;
|
|
102
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
103
|
+
}, z.core.$strict>>;
|
|
104
|
+
context: z.ZodObject<{
|
|
105
|
+
source: z.ZodObject<{
|
|
106
|
+
runId: z.ZodString;
|
|
107
|
+
messageId: z.ZodString;
|
|
108
|
+
provider: z.ZodString;
|
|
109
|
+
environmentId: z.ZodString;
|
|
110
|
+
sessionId: z.ZodString;
|
|
111
|
+
executionId: z.ZodString;
|
|
112
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
113
|
+
branchId: z.ZodOptional<z.ZodString>;
|
|
114
|
+
}, z.core.$strict>;
|
|
115
|
+
completeness: z.ZodEnum<{
|
|
116
|
+
complete: "complete";
|
|
117
|
+
partial: "partial";
|
|
118
|
+
}>;
|
|
119
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
120
|
+
id: z.ZodString;
|
|
121
|
+
role: z.ZodEnum<{
|
|
122
|
+
user: "user";
|
|
123
|
+
assistant: "assistant";
|
|
124
|
+
system: "system";
|
|
125
|
+
}>;
|
|
126
|
+
parts: z.ZodArray<z.ZodCustom<unknown, unknown>>;
|
|
127
|
+
timestamp: z.ZodISODateTime;
|
|
128
|
+
metadata: z.ZodOptional<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
|
|
129
|
+
}, z.core.$strict>>;
|
|
130
|
+
attachments: z.ZodArray<z.ZodObject<{
|
|
131
|
+
messageId: z.ZodString;
|
|
132
|
+
partIndex: z.ZodNumber;
|
|
133
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
134
|
+
name: z.ZodOptional<z.ZodString>;
|
|
135
|
+
mediaType: z.ZodOptional<z.ZodString>;
|
|
136
|
+
}, z.core.$strict>>;
|
|
137
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
138
|
+
}, z.core.$strict>;
|
|
139
|
+
estimatedTokens: z.ZodOptional<z.ZodNumber>;
|
|
140
|
+
requiresAcceptance: z.ZodBoolean;
|
|
141
|
+
digest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
142
|
+
}, z.core.$strict>;
|
|
143
|
+
acceptance: z.ZodObject<{
|
|
144
|
+
planDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
145
|
+
acceptedAt: z.ZodISODateTime;
|
|
146
|
+
acceptedBy: z.ZodEnum<{
|
|
147
|
+
policy: "policy";
|
|
148
|
+
user: "user";
|
|
149
|
+
system: "system";
|
|
150
|
+
}>;
|
|
151
|
+
}, z.core.$strict>;
|
|
152
|
+
}, z.core.$strict>;
|
|
153
|
+
export type ContextTransferRequest = z.infer<typeof ContextTransferRequestSchema>;
|
|
154
|
+
export declare const ContextTransferReceiptSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
155
|
+
status: z.ZodLiteral<"accepted" | "replayed">;
|
|
156
|
+
operationId: z.ZodString;
|
|
157
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
158
|
+
planDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
159
|
+
contextDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
160
|
+
source: z.ZodObject<{
|
|
161
|
+
runId: z.ZodString;
|
|
162
|
+
messageId: z.ZodString;
|
|
163
|
+
provider: z.ZodString;
|
|
164
|
+
environmentId: z.ZodString;
|
|
165
|
+
sessionId: z.ZodString;
|
|
166
|
+
executionId: z.ZodString;
|
|
167
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
168
|
+
branchId: z.ZodOptional<z.ZodString>;
|
|
169
|
+
}, z.core.$strict>;
|
|
170
|
+
destination: z.ZodObject<{
|
|
171
|
+
runner: z.ZodString;
|
|
172
|
+
provider: z.ZodString;
|
|
173
|
+
environmentId: z.ZodString;
|
|
174
|
+
sessionId: z.ZodString;
|
|
175
|
+
runId: z.ZodString;
|
|
176
|
+
executionId: z.ZodString;
|
|
177
|
+
model: z.ZodOptional<z.ZodString>;
|
|
178
|
+
profileDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
179
|
+
}, z.core.$strict>;
|
|
180
|
+
provider: z.ZodString;
|
|
181
|
+
environmentId: z.ZodString;
|
|
182
|
+
sessionId: z.ZodString;
|
|
183
|
+
runId: z.ZodString;
|
|
184
|
+
executionId: z.ZodString;
|
|
185
|
+
sessionCreatedForOperationId: z.ZodString;
|
|
186
|
+
sessionCreatedAt: z.ZodISODateTime;
|
|
187
|
+
transferredMessageIds: z.ZodArray<z.ZodString>;
|
|
188
|
+
omittedMessageIds: z.ZodArray<z.ZodString>;
|
|
189
|
+
admittedAt: z.ZodISODateTime;
|
|
190
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
191
|
+
status: z.ZodLiteral<"accepted" | "replayed">;
|
|
192
|
+
operationId: z.ZodString;
|
|
193
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
194
|
+
planDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
195
|
+
contextDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
196
|
+
source: z.ZodObject<{
|
|
197
|
+
runId: z.ZodString;
|
|
198
|
+
messageId: z.ZodString;
|
|
199
|
+
provider: z.ZodString;
|
|
200
|
+
environmentId: z.ZodString;
|
|
201
|
+
sessionId: z.ZodString;
|
|
202
|
+
executionId: z.ZodString;
|
|
203
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
204
|
+
branchId: z.ZodOptional<z.ZodString>;
|
|
205
|
+
}, z.core.$strict>;
|
|
206
|
+
destination: z.ZodObject<{
|
|
207
|
+
runner: z.ZodString;
|
|
208
|
+
provider: z.ZodString;
|
|
209
|
+
environmentId: z.ZodString;
|
|
210
|
+
sessionId: z.ZodString;
|
|
211
|
+
runId: z.ZodString;
|
|
212
|
+
executionId: z.ZodString;
|
|
213
|
+
model: z.ZodOptional<z.ZodString>;
|
|
214
|
+
profileDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
215
|
+
}, z.core.$strict>;
|
|
216
|
+
provider: z.ZodString;
|
|
217
|
+
environmentId: z.ZodString;
|
|
218
|
+
sessionId: z.ZodString;
|
|
219
|
+
runId: z.ZodString;
|
|
220
|
+
executionId: z.ZodString;
|
|
221
|
+
sessionCreatedForOperationId: z.ZodString;
|
|
222
|
+
sessionCreatedAt: z.ZodISODateTime;
|
|
223
|
+
transferredMessageIds: z.ZodArray<z.ZodString>;
|
|
224
|
+
omittedMessageIds: z.ZodArray<z.ZodString>;
|
|
225
|
+
admittedAt: z.ZodISODateTime;
|
|
226
|
+
}, z.core.$strict>], "status">;
|
|
227
|
+
export type ContextTransferReceipt = z.infer<typeof ContextTransferReceiptSchema>;
|
|
228
|
+
/** Exact cross-check required before committing a transfer receipt. */
|
|
229
|
+
export declare function contextTransferReceiptMatches(request: ContextTransferRequest, receipt: ContextTransferReceipt): boolean;
|
|
230
|
+
export declare const ContextTransferResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
231
|
+
status: z.ZodLiteral<"accepted" | "replayed">;
|
|
232
|
+
operationId: z.ZodString;
|
|
233
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
234
|
+
planDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
235
|
+
contextDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
236
|
+
source: z.ZodObject<{
|
|
237
|
+
runId: z.ZodString;
|
|
238
|
+
messageId: z.ZodString;
|
|
239
|
+
provider: z.ZodString;
|
|
240
|
+
environmentId: z.ZodString;
|
|
241
|
+
sessionId: z.ZodString;
|
|
242
|
+
executionId: z.ZodString;
|
|
243
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
244
|
+
branchId: z.ZodOptional<z.ZodString>;
|
|
245
|
+
}, z.core.$strict>;
|
|
246
|
+
destination: z.ZodObject<{
|
|
247
|
+
runner: z.ZodString;
|
|
248
|
+
provider: z.ZodString;
|
|
249
|
+
environmentId: z.ZodString;
|
|
250
|
+
sessionId: z.ZodString;
|
|
251
|
+
runId: z.ZodString;
|
|
252
|
+
executionId: z.ZodString;
|
|
253
|
+
model: z.ZodOptional<z.ZodString>;
|
|
254
|
+
profileDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
255
|
+
}, z.core.$strict>;
|
|
256
|
+
provider: z.ZodString;
|
|
257
|
+
environmentId: z.ZodString;
|
|
258
|
+
sessionId: z.ZodString;
|
|
259
|
+
runId: z.ZodString;
|
|
260
|
+
executionId: z.ZodString;
|
|
261
|
+
sessionCreatedForOperationId: z.ZodString;
|
|
262
|
+
sessionCreatedAt: z.ZodISODateTime;
|
|
263
|
+
transferredMessageIds: z.ZodArray<z.ZodString>;
|
|
264
|
+
omittedMessageIds: z.ZodArray<z.ZodString>;
|
|
265
|
+
admittedAt: z.ZodISODateTime;
|
|
266
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
267
|
+
status: z.ZodLiteral<"accepted" | "replayed">;
|
|
268
|
+
operationId: z.ZodString;
|
|
269
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
270
|
+
planDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
271
|
+
contextDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
272
|
+
source: z.ZodObject<{
|
|
273
|
+
runId: z.ZodString;
|
|
274
|
+
messageId: z.ZodString;
|
|
275
|
+
provider: z.ZodString;
|
|
276
|
+
environmentId: z.ZodString;
|
|
277
|
+
sessionId: z.ZodString;
|
|
278
|
+
executionId: z.ZodString;
|
|
279
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
280
|
+
branchId: z.ZodOptional<z.ZodString>;
|
|
281
|
+
}, z.core.$strict>;
|
|
282
|
+
destination: z.ZodObject<{
|
|
283
|
+
runner: z.ZodString;
|
|
284
|
+
provider: z.ZodString;
|
|
285
|
+
environmentId: z.ZodString;
|
|
286
|
+
sessionId: z.ZodString;
|
|
287
|
+
runId: z.ZodString;
|
|
288
|
+
executionId: z.ZodString;
|
|
289
|
+
model: z.ZodOptional<z.ZodString>;
|
|
290
|
+
profileDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
291
|
+
}, z.core.$strict>;
|
|
292
|
+
provider: z.ZodString;
|
|
293
|
+
environmentId: z.ZodString;
|
|
294
|
+
sessionId: z.ZodString;
|
|
295
|
+
runId: z.ZodString;
|
|
296
|
+
executionId: z.ZodString;
|
|
297
|
+
sessionCreatedForOperationId: z.ZodString;
|
|
298
|
+
sessionCreatedAt: z.ZodISODateTime;
|
|
299
|
+
transferredMessageIds: z.ZodArray<z.ZodString>;
|
|
300
|
+
omittedMessageIds: z.ZodArray<z.ZodString>;
|
|
301
|
+
admittedAt: z.ZodISODateTime;
|
|
302
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
303
|
+
status: z.ZodLiteral<"conflict">;
|
|
304
|
+
operationId: z.ZodString;
|
|
305
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
306
|
+
existingRequestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
307
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
308
|
+
status: z.ZodEnum<{
|
|
309
|
+
unknown: "unknown";
|
|
310
|
+
transport_failure: "transport_failure";
|
|
311
|
+
}>;
|
|
312
|
+
operationId: z.ZodString;
|
|
313
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
314
|
+
message: z.ZodString;
|
|
315
|
+
retryable: z.ZodBoolean;
|
|
316
|
+
}, z.core.$strict>], "status">;
|
|
317
|
+
export type ContextTransferResult = z.infer<typeof ContextTransferResultSchema>;
|
|
318
|
+
/** Bind every transfer outcome to the exact operation before acting on it. */
|
|
319
|
+
export declare function contextTransferResultMatchesRequest(request: ContextTransferRequest, result: ContextTransferResult): boolean;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { boundedStringSchema, CONTRACT_MAX_ARRAY_LENGTH, } from "./contract-limits.js";
|
|
3
|
+
import { PortableContextSourceBoundarySchema, } from "./portable-context-base.js";
|
|
4
|
+
import { PortableContextDestinationSchema, PortableContextPlanSchema, } from "./portable-context-plan.js";
|
|
5
|
+
import { idSchema, sha256DigestSchema, wireDigest } from "./portable-context-shared.js";
|
|
6
|
+
export const ContextPlanAcceptanceSchema = z.strictObject({
|
|
7
|
+
planDigest: sha256DigestSchema,
|
|
8
|
+
acceptedAt: z.iso.datetime().max(64),
|
|
9
|
+
acceptedBy: z.enum(["user", "policy", "system"]),
|
|
10
|
+
});
|
|
11
|
+
const ContextTransferRequestMaterialSchema = z.strictObject({
|
|
12
|
+
operationId: idSchema,
|
|
13
|
+
plan: PortableContextPlanSchema,
|
|
14
|
+
acceptance: ContextPlanAcceptanceSchema,
|
|
15
|
+
});
|
|
16
|
+
export function contextTransferRequestDigest(request) {
|
|
17
|
+
const parsed = ContextTransferRequestMaterialSchema.parse(request);
|
|
18
|
+
return wireDigest({
|
|
19
|
+
operationId: parsed.operationId,
|
|
20
|
+
planDigest: parsed.plan.digest,
|
|
21
|
+
acceptance: parsed.acceptance,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export const ContextTransferRequestSchema = z
|
|
25
|
+
.strictObject({
|
|
26
|
+
operationId: idSchema,
|
|
27
|
+
requestDigest: sha256DigestSchema,
|
|
28
|
+
plan: PortableContextPlanSchema,
|
|
29
|
+
acceptance: ContextPlanAcceptanceSchema,
|
|
30
|
+
})
|
|
31
|
+
.superRefine((request, refinement) => {
|
|
32
|
+
if (request.acceptance.planDigest !== request.plan.digest) {
|
|
33
|
+
refinement.addIssue({
|
|
34
|
+
code: "custom",
|
|
35
|
+
path: ["acceptance", "planDigest"],
|
|
36
|
+
message: "accepted plan digest must match the executed plan",
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (request.requestDigest !==
|
|
40
|
+
contextTransferRequestDigest({
|
|
41
|
+
operationId: request.operationId,
|
|
42
|
+
plan: request.plan,
|
|
43
|
+
acceptance: request.acceptance,
|
|
44
|
+
})) {
|
|
45
|
+
refinement.addIssue({
|
|
46
|
+
code: "custom",
|
|
47
|
+
path: ["requestDigest"],
|
|
48
|
+
message: "context transfer request digest does not match its content",
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (request.plan.requiresAcceptance &&
|
|
52
|
+
request.acceptance.acceptedBy === "system") {
|
|
53
|
+
refinement.addIssue({
|
|
54
|
+
code: "custom",
|
|
55
|
+
path: ["acceptance", "acceptedBy"],
|
|
56
|
+
message: "a transformed or partial plan requires user or policy acceptance",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
function contextTransferReceiptVariant(status) {
|
|
61
|
+
return z
|
|
62
|
+
.strictObject({
|
|
63
|
+
status: z.literal(status),
|
|
64
|
+
operationId: idSchema,
|
|
65
|
+
requestDigest: sha256DigestSchema,
|
|
66
|
+
planDigest: sha256DigestSchema,
|
|
67
|
+
contextDigest: sha256DigestSchema,
|
|
68
|
+
source: PortableContextSourceBoundarySchema,
|
|
69
|
+
destination: PortableContextDestinationSchema,
|
|
70
|
+
provider: idSchema,
|
|
71
|
+
environmentId: idSchema,
|
|
72
|
+
sessionId: idSchema,
|
|
73
|
+
runId: idSchema,
|
|
74
|
+
executionId: idSchema,
|
|
75
|
+
sessionCreatedForOperationId: idSchema,
|
|
76
|
+
sessionCreatedAt: z.iso.datetime().max(64),
|
|
77
|
+
transferredMessageIds: z.array(idSchema).max(CONTRACT_MAX_ARRAY_LENGTH),
|
|
78
|
+
omittedMessageIds: z.array(idSchema).max(CONTRACT_MAX_ARRAY_LENGTH),
|
|
79
|
+
admittedAt: z.iso.datetime().max(64),
|
|
80
|
+
})
|
|
81
|
+
.superRefine((receipt, refinement) => {
|
|
82
|
+
const transferred = new Set(receipt.transferredMessageIds);
|
|
83
|
+
const omitted = new Set(receipt.omittedMessageIds);
|
|
84
|
+
if (transferred.size !== receipt.transferredMessageIds.length) {
|
|
85
|
+
refinement.addIssue({
|
|
86
|
+
code: "custom",
|
|
87
|
+
path: ["transferredMessageIds"],
|
|
88
|
+
message: "transferred message ids must be unique",
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (omitted.size !== receipt.omittedMessageIds.length) {
|
|
92
|
+
refinement.addIssue({
|
|
93
|
+
code: "custom",
|
|
94
|
+
path: ["omittedMessageIds"],
|
|
95
|
+
message: "omitted message ids must be unique",
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if ([...transferred].some((messageId) => omitted.has(messageId))) {
|
|
99
|
+
refinement.addIssue({
|
|
100
|
+
code: "custom",
|
|
101
|
+
path: ["omittedMessageIds"],
|
|
102
|
+
message: "a message cannot be both transferred and omitted",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (Date.parse(receipt.sessionCreatedAt) > Date.parse(receipt.admittedAt)) {
|
|
106
|
+
refinement.addIssue({
|
|
107
|
+
code: "custom",
|
|
108
|
+
path: ["sessionCreatedAt"],
|
|
109
|
+
message: "the destination session must exist before context admission",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
export const ContextTransferReceiptSchema = z.discriminatedUnion("status", [
|
|
115
|
+
contextTransferReceiptVariant("accepted"),
|
|
116
|
+
contextTransferReceiptVariant("replayed"),
|
|
117
|
+
]);
|
|
118
|
+
/** Exact cross-check required before committing a transfer receipt. */
|
|
119
|
+
export function contextTransferReceiptMatches(request, receipt) {
|
|
120
|
+
const parsedRequest = ContextTransferRequestSchema.safeParse(request);
|
|
121
|
+
const parsedReceipt = ContextTransferReceiptSchema.safeParse(receipt);
|
|
122
|
+
if (!parsedRequest.success || !parsedReceipt.success)
|
|
123
|
+
return false;
|
|
124
|
+
const exactRequest = parsedRequest.data;
|
|
125
|
+
const exactReceipt = parsedReceipt.data;
|
|
126
|
+
const included = exactRequest.plan.messages
|
|
127
|
+
.filter((message) => message.action === "include")
|
|
128
|
+
.map((message) => message.messageId)
|
|
129
|
+
.sort();
|
|
130
|
+
const omitted = exactRequest.plan.messages
|
|
131
|
+
.filter((message) => message.action === "omit")
|
|
132
|
+
.map((message) => message.messageId)
|
|
133
|
+
.sort();
|
|
134
|
+
const source = exactRequest.plan.source;
|
|
135
|
+
const destination = exactRequest.plan.destination;
|
|
136
|
+
const createdAt = Date.parse(exactReceipt.sessionCreatedAt);
|
|
137
|
+
const acceptedAt = Date.parse(exactRequest.acceptance.acceptedAt);
|
|
138
|
+
const admittedAt = Date.parse(exactReceipt.admittedAt);
|
|
139
|
+
return (createdAt >= acceptedAt &&
|
|
140
|
+
createdAt <= admittedAt &&
|
|
141
|
+
exactReceipt.operationId === exactRequest.operationId &&
|
|
142
|
+
exactReceipt.requestDigest === exactRequest.requestDigest &&
|
|
143
|
+
exactReceipt.planDigest === exactRequest.plan.digest &&
|
|
144
|
+
exactReceipt.contextDigest === exactRequest.plan.context.digest &&
|
|
145
|
+
wireDigest(exactReceipt.source) === wireDigest(source.source) &&
|
|
146
|
+
wireDigest(exactReceipt.destination) === wireDigest(destination) &&
|
|
147
|
+
exactReceipt.provider === destination.provider &&
|
|
148
|
+
exactReceipt.environmentId === destination.environmentId &&
|
|
149
|
+
exactReceipt.sessionId === destination.sessionId &&
|
|
150
|
+
exactReceipt.runId === destination.runId &&
|
|
151
|
+
exactReceipt.executionId === destination.executionId &&
|
|
152
|
+
exactReceipt.sessionCreatedForOperationId === exactRequest.operationId &&
|
|
153
|
+
exactReceipt.environmentId !== source.source.environmentId &&
|
|
154
|
+
exactReceipt.sessionId !== source.source.sessionId &&
|
|
155
|
+
exactReceipt.runId !== source.source.runId &&
|
|
156
|
+
exactReceipt.executionId !== source.source.executionId &&
|
|
157
|
+
JSON.stringify([...exactReceipt.transferredMessageIds].sort()) ===
|
|
158
|
+
JSON.stringify(included) &&
|
|
159
|
+
JSON.stringify([...exactReceipt.omittedMessageIds].sort()) ===
|
|
160
|
+
JSON.stringify(omitted));
|
|
161
|
+
}
|
|
162
|
+
export const ContextTransferResultSchema = z
|
|
163
|
+
.discriminatedUnion("status", [
|
|
164
|
+
contextTransferReceiptVariant("accepted"),
|
|
165
|
+
contextTransferReceiptVariant("replayed"),
|
|
166
|
+
z.strictObject({
|
|
167
|
+
status: z.literal("conflict"),
|
|
168
|
+
operationId: idSchema,
|
|
169
|
+
requestDigest: sha256DigestSchema,
|
|
170
|
+
existingRequestDigest: sha256DigestSchema,
|
|
171
|
+
}),
|
|
172
|
+
z.strictObject({
|
|
173
|
+
status: z.enum(["unknown", "transport_failure"]),
|
|
174
|
+
operationId: idSchema,
|
|
175
|
+
requestDigest: sha256DigestSchema,
|
|
176
|
+
message: boundedStringSchema.min(1),
|
|
177
|
+
retryable: z.boolean(),
|
|
178
|
+
}),
|
|
179
|
+
])
|
|
180
|
+
.superRefine((result, refinement) => {
|
|
181
|
+
if (result.status === "conflict" &&
|
|
182
|
+
result.existingRequestDigest === result.requestDigest) {
|
|
183
|
+
refinement.addIssue({
|
|
184
|
+
code: "custom",
|
|
185
|
+
path: ["existingRequestDigest"],
|
|
186
|
+
message: "a transfer conflict must identify a different request",
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
/** Bind every transfer outcome to the exact operation before acting on it. */
|
|
191
|
+
export function contextTransferResultMatchesRequest(request, result) {
|
|
192
|
+
const parsedRequest = ContextTransferRequestSchema.safeParse(request);
|
|
193
|
+
const parsedResult = ContextTransferResultSchema.safeParse(result);
|
|
194
|
+
if (!parsedRequest.success || !parsedResult.success)
|
|
195
|
+
return false;
|
|
196
|
+
const exactRequest = parsedRequest.data;
|
|
197
|
+
const exactResult = parsedResult.data;
|
|
198
|
+
if (exactResult.operationId !== exactRequest.operationId ||
|
|
199
|
+
exactResult.requestDigest !== exactRequest.requestDigest) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
if (exactResult.status === "accepted" || exactResult.status === "replayed") {
|
|
203
|
+
return contextTransferReceiptMatches(exactRequest, exactResult);
|
|
204
|
+
}
|
|
205
|
+
return true;
|
|
206
|
+
}
|