@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
package/dist/index.js
CHANGED
|
@@ -1,132 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
export
|
|
1
|
+
/** Shared types and interfaces for SDK provider adapters. */
|
|
2
|
+
export * from "./parts.js";
|
|
3
|
+
export * from "./stream-events.js";
|
|
4
|
+
export * from "./execution-types.js";
|
|
5
|
+
export * from "./backend-message.js";
|
|
6
|
+
export * from "./provider-config.js";
|
|
7
|
+
export * from "./host-services.js";
|
|
8
|
+
export * from "./mcp.js";
|
|
9
|
+
export * from "./provider-adapter.js";
|
|
10
|
+
export { AgentEnvironmentCapabilitiesSchema, AgentNativeContextContinuationResultSchema, AgentTurnInputSchema, AgentTurnResultSchema, agentNativeContextContinuationResultMatchesRequest, } from "./environment-provider.js";
|
|
8
11
|
export * from "./plan.js";
|
|
9
12
|
export * from "./runtime-control.js";
|
|
10
13
|
export * from "./portable-context.js";
|
|
11
14
|
export * from "./workspace-branching.js";
|
|
12
|
-
/** Helper to check part type */
|
|
13
|
-
export function isTextPart(part) {
|
|
14
|
-
return part.type === "text";
|
|
15
|
-
}
|
|
16
|
-
export function isToolPart(part) {
|
|
17
|
-
return part.type === "tool";
|
|
18
|
-
}
|
|
19
|
-
export function isReasoningPart(part) {
|
|
20
|
-
return part.type === "reasoning";
|
|
21
|
-
}
|
|
22
|
-
export function isFilePart(part) {
|
|
23
|
-
return part.type === "file";
|
|
24
|
-
}
|
|
25
|
-
export function isSubtaskPart(part) {
|
|
26
|
-
return part.type === "subtask";
|
|
27
|
-
}
|
|
28
|
-
export function isInputTextPart(part) {
|
|
29
|
-
return part.type === "text";
|
|
30
|
-
}
|
|
31
|
-
export function isInputFilePart(part) {
|
|
32
|
-
return part.type === "file";
|
|
33
|
-
}
|
|
34
|
-
export function isInputImagePart(part) {
|
|
35
|
-
return part.type === "image";
|
|
36
|
-
}
|
|
37
|
-
export function normalizeInputParts(input) {
|
|
38
|
-
if (Array.isArray(input.parts) && input.parts.length > 0) {
|
|
39
|
-
return input.parts;
|
|
40
|
-
}
|
|
41
|
-
if (typeof input.message === "string" && input.message.length > 0) {
|
|
42
|
-
return [{ type: "text", text: input.message }];
|
|
43
|
-
}
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
export function renderInputPartsAsText(parts) {
|
|
47
|
-
const textParts = [];
|
|
48
|
-
const attachmentRefs = [];
|
|
49
|
-
for (const part of parts) {
|
|
50
|
-
if (part.type === "text") {
|
|
51
|
-
if (part.text)
|
|
52
|
-
textParts.push(part.text);
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
const label = part.path ||
|
|
56
|
-
part.filename ||
|
|
57
|
-
part.url ||
|
|
58
|
-
(part.type === "image" ? "image attachment" : "file attachment");
|
|
59
|
-
attachmentRefs.push(`[${part.type === "image" ? "Image" : "File"}: ${label}]`);
|
|
60
|
-
}
|
|
61
|
-
if (attachmentRefs.length === 0) {
|
|
62
|
-
return textParts.join("\n\n").trim();
|
|
63
|
-
}
|
|
64
|
-
const text = textParts.join("\n\n").trim();
|
|
65
|
-
const attachmentBlock = `Attached files:\n${attachmentRefs.join("\n")}`;
|
|
66
|
-
return text ? `${text}\n\n${attachmentBlock}` : attachmentBlock;
|
|
67
|
-
}
|
|
68
|
-
export const TANGLE_ROUTER_DEFAULT_ROOT_URL = "https://router.tangle.tools";
|
|
69
|
-
export const TANGLE_ROUTER_DEFAULT_MODEL = "zai/glm-4.7";
|
|
70
|
-
/**
|
|
71
|
-
* Normalizes an OpenAI-compatible base URL for SDKs that append
|
|
72
|
-
* `/chat/completions` to the configured base. Existing `/vN` suffixes are
|
|
73
|
-
* preserved so explicit `/v2` endpoints do not become `/v2/v1`.
|
|
74
|
-
*/
|
|
75
|
-
export function normalizeOpenAiCompatibleBaseUrl(baseUrl) {
|
|
76
|
-
const trimmed = baseUrl.replace(/\/+$/, "");
|
|
77
|
-
return /\/v\d+$/.test(trimmed) ? trimmed : `${trimmed}/v1`;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Returns the platform model gateway defaults. Env overrides are read here so
|
|
81
|
-
* every harness adapter shares the same dynamic seam.
|
|
82
|
-
*/
|
|
83
|
-
export function resolveTangleRouterDefaults(env = process.env) {
|
|
84
|
-
const rootUrl = env.TANGLE_ROUTER_URL || TANGLE_ROUTER_DEFAULT_ROOT_URL;
|
|
85
|
-
return {
|
|
86
|
-
provider: "openai-compat",
|
|
87
|
-
name: env.TANGLE_ROUTER_PROVIDER_NAME || "Tangle Router",
|
|
88
|
-
rootUrl,
|
|
89
|
-
baseUrl: normalizeOpenAiCompatibleBaseUrl(env.TANGLE_ROUTER_BASE_URL || rootUrl),
|
|
90
|
-
model: env.TANGLE_ROUTER_MODEL || TANGLE_ROUTER_DEFAULT_MODEL,
|
|
91
|
-
apiKeyEnvVar: env.TANGLE_ROUTER_API_KEY_ENV || "OPENCODE_MODEL_API_KEY",
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Applies gateway defaults to a provider model config. Existing fields win.
|
|
96
|
-
*/
|
|
97
|
-
export function withModelGatewayDefaults(model, defaults = resolveTangleRouterDefaults()) {
|
|
98
|
-
return {
|
|
99
|
-
...model,
|
|
100
|
-
provider: model.provider || defaults.provider,
|
|
101
|
-
model: model.model || defaults.model,
|
|
102
|
-
baseUrl: model.baseUrl || defaults.baseUrl,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
// Canonical and per-harness spellings collapse to these, separator/case-insensitive.
|
|
106
|
-
const nativeWebSearchKeys = new Set(["websearch"]);
|
|
107
|
-
const nativeWebFetchKeys = new Set(["webfetch", "fetch"]);
|
|
108
|
-
/**
|
|
109
|
-
* Map an AgentProfile `tools` map to a {@link NativeWebToolPosture}. Accepts
|
|
110
|
-
* the canonical `web_search`/`web_fetch` as well as each harness's native
|
|
111
|
-
* spelling (`WebSearch`, `webfetch`, …) — keys are normalized by stripping
|
|
112
|
-
* non-alphanumerics and lowercasing, so a single directive works everywhere.
|
|
113
|
-
* Non-boolean and unrelated tool entries are ignored.
|
|
114
|
-
*/
|
|
115
|
-
export function resolveNativeWebTools(tools) {
|
|
116
|
-
if (!tools)
|
|
117
|
-
return {};
|
|
118
|
-
const posture = {};
|
|
119
|
-
for (const [key, value] of Object.entries(tools)) {
|
|
120
|
-
if (typeof value !== "boolean")
|
|
121
|
-
continue;
|
|
122
|
-
const normalized = key.replace(/[^a-z0-9]/gi, "").toLowerCase();
|
|
123
|
-
if (nativeWebSearchKeys.has(normalized))
|
|
124
|
-
posture.search = value;
|
|
125
|
-
else if (nativeWebFetchKeys.has(normalized))
|
|
126
|
-
posture.fetch = value;
|
|
127
|
-
}
|
|
128
|
-
return posture;
|
|
129
|
-
}
|
|
130
15
|
export * from "./interaction.js";
|
|
131
16
|
export * from "./agent-candidate.js";
|
|
132
17
|
export * from "./agent-candidate-schema.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type InteractionAnswerSpec } from "./interaction-fields.js";
|
|
2
|
+
import type { InteractionData } from "./interaction-data.js";
|
|
3
|
+
export type InteractionValidation = {
|
|
4
|
+
ok: true;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
errors: string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Validate an accepted answer against its spec. Used by the broker before a
|
|
11
|
+
* response reaches the adapter, so malformed answers are rejected centrally.
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateInteractionAnswer(spec: InteractionAnswerSpec, data: InteractionData | undefined): InteractionValidation;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { InteractionAnswerSpecSchema, } from "./interaction-fields.js";
|
|
2
|
+
import { boundedIdentifierSchema, CONTRACT_MAX_ARRAY_LENGTH, CONTRACT_MAX_MAP_ENTRIES, CONTRACT_MAX_STRING_LENGTH, } from "./contract-limits.js";
|
|
3
|
+
/**
|
|
4
|
+
* Validate an accepted answer against its spec. Used by the broker before a
|
|
5
|
+
* response reaches the adapter, so malformed answers are rejected centrally.
|
|
6
|
+
*/
|
|
7
|
+
export function validateInteractionAnswer(spec, data) {
|
|
8
|
+
const errors = [];
|
|
9
|
+
const parsedSpec = InteractionAnswerSpecSchema.safeParse(spec);
|
|
10
|
+
if (!parsedSpec.success) {
|
|
11
|
+
return {
|
|
12
|
+
ok: false,
|
|
13
|
+
errors: parsedSpec.error.issues.map((issue) => issue.message),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (data !== undefined &&
|
|
17
|
+
(!data || typeof data !== "object" || Array.isArray(data))) {
|
|
18
|
+
return { ok: false, errors: ["interaction data must be an object"] };
|
|
19
|
+
}
|
|
20
|
+
const d = data ?? Object.create(null);
|
|
21
|
+
const prototype = Object.getPrototypeOf(d);
|
|
22
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
23
|
+
return { ok: false, errors: ["interaction data must be a plain object"] };
|
|
24
|
+
}
|
|
25
|
+
if (Object.keys(d).length > CONTRACT_MAX_MAP_ENTRIES) {
|
|
26
|
+
return { ok: false, errors: ["interaction data has too many fields"] };
|
|
27
|
+
}
|
|
28
|
+
const exactSpec = parsedSpec.data;
|
|
29
|
+
const knownFields = new Set(exactSpec.fields.map((field) => field.name));
|
|
30
|
+
for (const fieldName of Object.keys(d)) {
|
|
31
|
+
if (fieldName.length > 512) {
|
|
32
|
+
errors.push(`unknown field "${fieldName}"`);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const rawValue = d[fieldName];
|
|
36
|
+
if (typeof rawValue === "string" && rawValue.length > CONTRACT_MAX_STRING_LENGTH) {
|
|
37
|
+
errors.push(`field "${fieldName}" exceeds the contract string bound`);
|
|
38
|
+
}
|
|
39
|
+
else if (Array.isArray(rawValue)) {
|
|
40
|
+
if (rawValue.length > CONTRACT_MAX_ARRAY_LENGTH) {
|
|
41
|
+
errors.push(`field "${fieldName}" has too many values`);
|
|
42
|
+
}
|
|
43
|
+
for (const entry of rawValue) {
|
|
44
|
+
if (typeof entry !== "string" || entry.length > CONTRACT_MAX_STRING_LENGTH) {
|
|
45
|
+
errors.push(`field "${fieldName}" contains an invalid bounded value`);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else if (rawValue && typeof rawValue === "object") {
|
|
51
|
+
const valuePrototype = Object.getPrototypeOf(rawValue);
|
|
52
|
+
if ((valuePrototype !== Object.prototype && valuePrototype !== null) ||
|
|
53
|
+
Object.keys(rawValue).length > 3) {
|
|
54
|
+
errors.push(`field "${fieldName}" contains an invalid object value`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (!knownFields.has(fieldName)) {
|
|
58
|
+
errors.push(`unknown field "${fieldName}"`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
for (const field of exactSpec.fields) {
|
|
62
|
+
const hasValue = Object.hasOwn(d, field.name);
|
|
63
|
+
const v = hasValue ? d[field.name] : undefined;
|
|
64
|
+
const present = hasValue && v !== undefined && v !== null && !(typeof v === "string" && v === "");
|
|
65
|
+
if (!present) {
|
|
66
|
+
if (field.required)
|
|
67
|
+
errors.push(`missing required field "${field.name}"`);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
switch (field.type) {
|
|
71
|
+
case "text":
|
|
72
|
+
if (typeof v !== "string") {
|
|
73
|
+
errors.push(`field "${field.name}" must be a string`);
|
|
74
|
+
}
|
|
75
|
+
else if (field.maxLength !== undefined && v.length > field.maxLength) {
|
|
76
|
+
errors.push(`field "${field.name}" exceeds maxLength ${field.maxLength}`);
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case "secret": {
|
|
80
|
+
const isHandle = typeof v === "object" &&
|
|
81
|
+
v !== null &&
|
|
82
|
+
!Array.isArray(v) &&
|
|
83
|
+
Object.keys(v).length === 3 &&
|
|
84
|
+
(Object.getPrototypeOf(v) === Object.prototype ||
|
|
85
|
+
Object.getPrototypeOf(v) === null) &&
|
|
86
|
+
Object.hasOwn(v, "kind") &&
|
|
87
|
+
Object.hasOwn(v, "handleId") &&
|
|
88
|
+
Object.hasOwn(v, "oneUse") &&
|
|
89
|
+
v.kind === "secret_handle" &&
|
|
90
|
+
v.oneUse === true &&
|
|
91
|
+
boundedIdentifierSchema.safeParse(v.handleId)
|
|
92
|
+
.success;
|
|
93
|
+
if (typeof v !== "string" && !isHandle) {
|
|
94
|
+
errors.push(`field "${field.name}" must be a string or one-use secret handle`);
|
|
95
|
+
}
|
|
96
|
+
else if (typeof v === "string" &&
|
|
97
|
+
field.maxLength !== undefined &&
|
|
98
|
+
v.length > field.maxLength) {
|
|
99
|
+
errors.push(`field "${field.name}" exceeds maxLength ${field.maxLength}`);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case "number":
|
|
104
|
+
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
105
|
+
errors.push(`field "${field.name}" must be a finite number`);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if (field.min !== undefined && v < field.min)
|
|
109
|
+
errors.push(`field "${field.name}" below min ${field.min}`);
|
|
110
|
+
if (field.max !== undefined && v > field.max)
|
|
111
|
+
errors.push(`field "${field.name}" above max ${field.max}`);
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
case "boolean":
|
|
115
|
+
if (typeof v !== "boolean")
|
|
116
|
+
errors.push(`field "${field.name}" must be a boolean`);
|
|
117
|
+
break;
|
|
118
|
+
case "select": {
|
|
119
|
+
if (!Array.isArray(v)) {
|
|
120
|
+
errors.push(`field "${field.name}" must be an array of option values`);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
if (v.length > CONTRACT_MAX_ARRAY_LENGTH) {
|
|
124
|
+
errors.push(`field "${field.name}" has too many option values`);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
if (!field.multi && v.length > 1)
|
|
128
|
+
errors.push(`field "${field.name}" accepts a single value`);
|
|
129
|
+
if (field.required && v.length === 0)
|
|
130
|
+
errors.push(`field "${field.name}" requires a selection`);
|
|
131
|
+
const allowed = new Set(field.options.map((o) => o.value));
|
|
132
|
+
for (const choice of v) {
|
|
133
|
+
if (allowed.has(choice))
|
|
134
|
+
continue;
|
|
135
|
+
if (field.allowCustom === true) {
|
|
136
|
+
// Write-ins are open but stay fail-closed on shape: string, non-blank.
|
|
137
|
+
if (typeof choice !== "string" || choice.trim() === "") {
|
|
138
|
+
errors.push(`field "${field.name}" has blank write-in value`);
|
|
139
|
+
}
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
errors.push(`field "${field.name}" has invalid option "${choice}"`);
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return errors.length === 0 ? { ok: true } : { ok: false, errors };
|
|
149
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const InteractionSecretReferenceSchema: z.ZodObject<{
|
|
3
|
+
kind: z.ZodLiteral<"secret_handle">;
|
|
4
|
+
handleId: z.ZodString;
|
|
5
|
+
oneUse: z.ZodLiteral<true>;
|
|
6
|
+
}, z.core.$strict>;
|
|
7
|
+
export type InteractionSecretReference = z.infer<typeof InteractionSecretReferenceSchema>;
|
|
8
|
+
export type InteractionDataValue = string | number | boolean | string[] | InteractionSecretReference;
|
|
9
|
+
/** Field values keyed by InteractionField.name. */
|
|
10
|
+
export declare const InteractionDataSchema: z.ZodType<Record<string, InteractionDataValue>>;
|
|
11
|
+
export type InteractionData = Record<string, InteractionDataValue>;
|
|
12
|
+
export declare const InteractionResolutionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
13
|
+
outcome: z.ZodLiteral<"accepted">;
|
|
14
|
+
data: z.ZodOptional<z.ZodType<Record<string, InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, InteractionDataValue>, unknown>>>;
|
|
15
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
16
|
+
outcome: z.ZodLiteral<"declined">;
|
|
17
|
+
data: z.ZodOptional<z.ZodType<Record<string, InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, InteractionDataValue>, unknown>>>;
|
|
18
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
19
|
+
outcome: z.ZodLiteral<"cancelled">;
|
|
20
|
+
data: z.ZodOptional<z.ZodType<Record<string, InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, InteractionDataValue>, unknown>>>;
|
|
21
|
+
}, z.core.$strict>], "outcome">;
|
|
22
|
+
export type InteractionResolution = z.infer<typeof InteractionResolutionSchema>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { boundedIdentifierSchema, boundedStringSchema, CONTRACT_MAX_ARRAY_LENGTH, CONTRACT_MAX_MAP_ENTRIES, } from "./contract-limits.js";
|
|
3
|
+
import { InteractionFieldNameSchema } from "./interaction-fields.js";
|
|
4
|
+
export const InteractionSecretReferenceSchema = z.strictObject({
|
|
5
|
+
kind: z.literal("secret_handle"),
|
|
6
|
+
handleId: boundedIdentifierSchema,
|
|
7
|
+
oneUse: z.literal(true),
|
|
8
|
+
});
|
|
9
|
+
const InteractionDataValueSchema = z.union([
|
|
10
|
+
boundedStringSchema,
|
|
11
|
+
z.number().finite(),
|
|
12
|
+
z.boolean(),
|
|
13
|
+
z.array(boundedStringSchema).max(CONTRACT_MAX_ARRAY_LENGTH),
|
|
14
|
+
InteractionSecretReferenceSchema,
|
|
15
|
+
]);
|
|
16
|
+
/** Field values keyed by InteractionField.name. */
|
|
17
|
+
export const InteractionDataSchema = z
|
|
18
|
+
.record(InteractionFieldNameSchema, InteractionDataValueSchema)
|
|
19
|
+
.superRefine((data, refinement) => {
|
|
20
|
+
if (Object.keys(data).length > CONTRACT_MAX_MAP_ENTRIES) {
|
|
21
|
+
refinement.addIssue({
|
|
22
|
+
code: "custom",
|
|
23
|
+
message: "interaction data has too many fields",
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
.transform((data) => {
|
|
28
|
+
const safe = Object.create(null);
|
|
29
|
+
for (const key of Object.keys(data))
|
|
30
|
+
safe[key] = data[key];
|
|
31
|
+
return safe;
|
|
32
|
+
});
|
|
33
|
+
export const InteractionResolutionSchema = z.discriminatedUnion("outcome", [
|
|
34
|
+
z.strictObject({
|
|
35
|
+
outcome: z.literal("accepted"),
|
|
36
|
+
data: InteractionDataSchema.optional(),
|
|
37
|
+
}),
|
|
38
|
+
z.strictObject({
|
|
39
|
+
outcome: z.literal("declined"),
|
|
40
|
+
data: InteractionDataSchema.optional(),
|
|
41
|
+
}),
|
|
42
|
+
z.strictObject({
|
|
43
|
+
outcome: z.literal("cancelled"),
|
|
44
|
+
data: InteractionDataSchema.optional(),
|
|
45
|
+
}),
|
|
46
|
+
]);
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Sha256Digest } from "./agent-candidate.js";
|
|
3
|
+
import { type InteractionResolution } from "./interaction-data.js";
|
|
4
|
+
import { InteractionAnswerSpecSchema, InteractionResponseScopeSchema } from "./interaction-fields.js";
|
|
5
|
+
export { InteractionDataSchema, InteractionResolutionSchema, InteractionSecretReferenceSchema, } from "./interaction-data.js";
|
|
6
|
+
export type { InteractionData, InteractionDataValue, InteractionResolution, InteractionSecretReference, } from "./interaction-data.js";
|
|
7
|
+
export declare const InteractionSubjectSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
8
|
+
type: z.ZodLiteral<"tool">;
|
|
9
|
+
toolName: z.ZodString;
|
|
10
|
+
input: z.ZodOptional<z.ZodCustom<unknown, unknown>>;
|
|
11
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
12
|
+
type: z.ZodLiteral<"command">;
|
|
13
|
+
command: z.ZodString;
|
|
14
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
15
|
+
type: z.ZodLiteral<"file">;
|
|
16
|
+
path: z.ZodString;
|
|
17
|
+
preview: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
19
|
+
type: z.ZodLiteral<"resource">;
|
|
20
|
+
uri: z.ZodString;
|
|
21
|
+
}, z.core.$strict>], "type">;
|
|
22
|
+
export type InteractionSubject = z.infer<typeof InteractionSubjectSchema>;
|
|
23
|
+
export declare const InteractionOutcomeSchema: z.ZodEnum<{
|
|
24
|
+
cancelled: "cancelled";
|
|
25
|
+
accepted: "accepted";
|
|
26
|
+
declined: "declined";
|
|
27
|
+
}>;
|
|
28
|
+
export type InteractionOutcome = z.infer<typeof InteractionOutcomeSchema>;
|
|
29
|
+
export declare const InteractionRequestBindingSchema: z.ZodObject<{
|
|
30
|
+
runId: z.ZodString;
|
|
31
|
+
provider: z.ZodString;
|
|
32
|
+
environmentId: z.ZodString;
|
|
33
|
+
sessionId: z.ZodString;
|
|
34
|
+
executionId: z.ZodString;
|
|
35
|
+
interactionId: z.ZodString;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
export type InteractionRequestBinding = z.infer<typeof InteractionRequestBindingSchema>;
|
|
38
|
+
/** Exact execution coordinates shared by every interaction from one provider turn. */
|
|
39
|
+
export declare const InteractionExecutionBindingSchema: z.ZodObject<{
|
|
40
|
+
provider: z.ZodString;
|
|
41
|
+
executionId: z.ZodString;
|
|
42
|
+
runId: z.ZodString;
|
|
43
|
+
environmentId: z.ZodString;
|
|
44
|
+
sessionId: z.ZodString;
|
|
45
|
+
}, z.core.$strict>;
|
|
46
|
+
export type InteractionExecutionBinding = z.infer<typeof InteractionExecutionBindingSchema>;
|
|
47
|
+
/** Binding carried by a response command and acknowledgement. */
|
|
48
|
+
export declare const InteractionBindingSchema: z.ZodObject<{
|
|
49
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
50
|
+
runId: z.ZodString;
|
|
51
|
+
provider: z.ZodString;
|
|
52
|
+
environmentId: z.ZodString;
|
|
53
|
+
sessionId: z.ZodString;
|
|
54
|
+
executionId: z.ZodString;
|
|
55
|
+
interactionId: z.ZodString;
|
|
56
|
+
}, z.core.$strict>;
|
|
57
|
+
export type InteractionBinding = z.infer<typeof InteractionBindingSchema>;
|
|
58
|
+
export interface InteractionRequestMaterial {
|
|
59
|
+
id: string;
|
|
60
|
+
kind: string;
|
|
61
|
+
title: string;
|
|
62
|
+
body?: string;
|
|
63
|
+
subject?: InteractionSubject;
|
|
64
|
+
answerSpec: z.infer<typeof InteractionAnswerSpecSchema>;
|
|
65
|
+
responseScopes?: z.infer<typeof InteractionResponseScopeSchema>[];
|
|
66
|
+
allowedOutcomes?: InteractionOutcome[];
|
|
67
|
+
default?: InteractionResolution;
|
|
68
|
+
timeoutMs?: number;
|
|
69
|
+
onTimeout?: "default" | "fail" | "wait";
|
|
70
|
+
binding: InteractionRequestBinding;
|
|
71
|
+
}
|
|
72
|
+
export interface InteractionRequest extends InteractionRequestMaterial {
|
|
73
|
+
requestDigest: Sha256Digest;
|
|
74
|
+
}
|
|
75
|
+
export declare function interactionRequestDigest(request: InteractionRequestMaterial): Sha256Digest;
|
|
76
|
+
export declare const InteractionRequestSchema: z.ZodObject<{
|
|
77
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
kind: z.ZodString;
|
|
80
|
+
title: z.ZodString;
|
|
81
|
+
body: z.ZodOptional<z.ZodString>;
|
|
82
|
+
subject: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
83
|
+
type: z.ZodLiteral<"tool">;
|
|
84
|
+
toolName: z.ZodString;
|
|
85
|
+
input: z.ZodOptional<z.ZodCustom<unknown, unknown>>;
|
|
86
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
87
|
+
type: z.ZodLiteral<"command">;
|
|
88
|
+
command: z.ZodString;
|
|
89
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
90
|
+
type: z.ZodLiteral<"file">;
|
|
91
|
+
path: z.ZodString;
|
|
92
|
+
preview: z.ZodOptional<z.ZodString>;
|
|
93
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
94
|
+
type: z.ZodLiteral<"resource">;
|
|
95
|
+
uri: z.ZodString;
|
|
96
|
+
}, z.core.$strict>], "type">>;
|
|
97
|
+
answerSpec: z.ZodObject<{
|
|
98
|
+
fields: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
99
|
+
type: z.ZodLiteral<"text">;
|
|
100
|
+
multiline: z.ZodOptional<z.ZodBoolean>;
|
|
101
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
102
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
103
|
+
default: z.ZodOptional<z.ZodString>;
|
|
104
|
+
name: z.ZodString;
|
|
105
|
+
label: z.ZodString;
|
|
106
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
107
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
108
|
+
type: z.ZodLiteral<"number">;
|
|
109
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
110
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
111
|
+
default: z.ZodOptional<z.ZodNumber>;
|
|
112
|
+
name: z.ZodString;
|
|
113
|
+
label: z.ZodString;
|
|
114
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
115
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
116
|
+
type: z.ZodLiteral<"boolean">;
|
|
117
|
+
default: z.ZodOptional<z.ZodBoolean>;
|
|
118
|
+
name: z.ZodString;
|
|
119
|
+
label: z.ZodString;
|
|
120
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
121
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
122
|
+
type: z.ZodLiteral<"select">;
|
|
123
|
+
options: z.ZodArray<z.ZodObject<{
|
|
124
|
+
value: z.ZodString;
|
|
125
|
+
label: z.ZodString;
|
|
126
|
+
description: z.ZodOptional<z.ZodString>;
|
|
127
|
+
}, z.core.$strict>>;
|
|
128
|
+
multi: z.ZodOptional<z.ZodBoolean>;
|
|
129
|
+
allowCustom: z.ZodOptional<z.ZodBoolean>;
|
|
130
|
+
default: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
131
|
+
name: z.ZodString;
|
|
132
|
+
label: z.ZodString;
|
|
133
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
134
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
135
|
+
type: z.ZodLiteral<"secret">;
|
|
136
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
137
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
138
|
+
name: z.ZodString;
|
|
139
|
+
label: z.ZodString;
|
|
140
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
141
|
+
}, z.core.$strict>], "type">>;
|
|
142
|
+
}, z.core.$strict>;
|
|
143
|
+
responseScopes: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
144
|
+
interaction: "interaction";
|
|
145
|
+
session: "session";
|
|
146
|
+
persistent: "persistent";
|
|
147
|
+
}>>>;
|
|
148
|
+
allowedOutcomes: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
149
|
+
cancelled: "cancelled";
|
|
150
|
+
accepted: "accepted";
|
|
151
|
+
declined: "declined";
|
|
152
|
+
}>>>;
|
|
153
|
+
default: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
154
|
+
outcome: z.ZodLiteral<"accepted">;
|
|
155
|
+
data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
|
|
156
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
157
|
+
outcome: z.ZodLiteral<"declined">;
|
|
158
|
+
data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
|
|
159
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
160
|
+
outcome: z.ZodLiteral<"cancelled">;
|
|
161
|
+
data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
|
|
162
|
+
}, z.core.$strict>], "outcome">>;
|
|
163
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
164
|
+
onTimeout: z.ZodOptional<z.ZodEnum<{
|
|
165
|
+
default: "default";
|
|
166
|
+
fail: "fail";
|
|
167
|
+
wait: "wait";
|
|
168
|
+
}>>;
|
|
169
|
+
binding: z.ZodObject<{
|
|
170
|
+
runId: z.ZodString;
|
|
171
|
+
provider: z.ZodString;
|
|
172
|
+
environmentId: z.ZodString;
|
|
173
|
+
sessionId: z.ZodString;
|
|
174
|
+
executionId: z.ZodString;
|
|
175
|
+
interactionId: z.ZodString;
|
|
176
|
+
}, z.core.$strict>;
|
|
177
|
+
}, z.core.$strict>;
|
|
178
|
+
export declare const InteractionResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
179
|
+
id: z.ZodString;
|
|
180
|
+
outcome: z.ZodLiteral<"accepted">;
|
|
181
|
+
data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
|
|
182
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
183
|
+
id: z.ZodString;
|
|
184
|
+
outcome: z.ZodLiteral<"declined">;
|
|
185
|
+
data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
|
|
186
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
187
|
+
id: z.ZodString;
|
|
188
|
+
outcome: z.ZodLiteral<"cancelled">;
|
|
189
|
+
data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
|
|
190
|
+
}, z.core.$strict>], "outcome">;
|
|
191
|
+
export type InteractionResponse = z.infer<typeof InteractionResponseSchema>;
|
|
192
|
+
export interface InteractionResponseCommandMaterial {
|
|
193
|
+
binding: InteractionBinding;
|
|
194
|
+
response: InteractionResponse;
|
|
195
|
+
}
|
|
196
|
+
/** Digest the exact binding and response carried by a retryable command. */
|
|
197
|
+
export declare function interactionResponseCommandDigest(material: InteractionResponseCommandMaterial): Sha256Digest;
|
|
198
|
+
/** Retryable command sent to an environment or retained session. */
|
|
199
|
+
export declare const InteractionResponseCommandSchema: z.ZodObject<{
|
|
200
|
+
operationId: z.ZodString;
|
|
201
|
+
binding: z.ZodObject<{
|
|
202
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
203
|
+
runId: z.ZodString;
|
|
204
|
+
provider: z.ZodString;
|
|
205
|
+
environmentId: z.ZodString;
|
|
206
|
+
sessionId: z.ZodString;
|
|
207
|
+
executionId: z.ZodString;
|
|
208
|
+
interactionId: z.ZodString;
|
|
209
|
+
}, z.core.$strict>;
|
|
210
|
+
commandDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
211
|
+
response: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
212
|
+
id: z.ZodString;
|
|
213
|
+
outcome: z.ZodLiteral<"accepted">;
|
|
214
|
+
data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
|
|
215
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
216
|
+
id: z.ZodString;
|
|
217
|
+
outcome: z.ZodLiteral<"declined">;
|
|
218
|
+
data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
|
|
219
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
220
|
+
id: z.ZodString;
|
|
221
|
+
outcome: z.ZodLiteral<"cancelled">;
|
|
222
|
+
data: z.ZodOptional<z.ZodType<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown, z.core.$ZodTypeInternals<Record<string, import("./interaction-data.js").InteractionDataValue>, unknown>>>;
|
|
223
|
+
}, z.core.$strict>], "outcome">;
|
|
224
|
+
}, z.core.$strict>;
|
|
225
|
+
export type InteractionResponseCommand = z.infer<typeof InteractionResponseCommandSchema>;
|
|
226
|
+
export declare const InteractionAcknowledgementStatusSchema: z.ZodEnum<{
|
|
227
|
+
cancelled: "cancelled";
|
|
228
|
+
expired: "expired";
|
|
229
|
+
accepted: "accepted";
|
|
230
|
+
already_resolved_same: "already_resolved_same";
|
|
231
|
+
already_resolved_different: "already_resolved_different";
|
|
232
|
+
unknown_interaction: "unknown_interaction";
|
|
233
|
+
unknown_run: "unknown_run";
|
|
234
|
+
binding_mismatch: "binding_mismatch";
|
|
235
|
+
invalid_response: "invalid_response";
|
|
236
|
+
transport_failure: "transport_failure";
|
|
237
|
+
}>;
|
|
238
|
+
export type InteractionAcknowledgementStatus = z.infer<typeof InteractionAcknowledgementStatusSchema>;
|
|
239
|
+
/** Durable result of one interaction response operation. */
|
|
240
|
+
export declare const InteractionAcknowledgementSchema: z.ZodObject<{
|
|
241
|
+
operationId: z.ZodString;
|
|
242
|
+
binding: z.ZodObject<{
|
|
243
|
+
requestDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
244
|
+
runId: z.ZodString;
|
|
245
|
+
provider: z.ZodString;
|
|
246
|
+
environmentId: z.ZodString;
|
|
247
|
+
sessionId: z.ZodString;
|
|
248
|
+
executionId: z.ZodString;
|
|
249
|
+
interactionId: z.ZodString;
|
|
250
|
+
}, z.core.$strict>;
|
|
251
|
+
commandDigest: z.ZodType<`sha256:${string}`, unknown, z.core.$ZodTypeInternals<`sha256:${string}`, unknown>>;
|
|
252
|
+
status: z.ZodEnum<{
|
|
253
|
+
cancelled: "cancelled";
|
|
254
|
+
expired: "expired";
|
|
255
|
+
accepted: "accepted";
|
|
256
|
+
already_resolved_same: "already_resolved_same";
|
|
257
|
+
already_resolved_different: "already_resolved_different";
|
|
258
|
+
unknown_interaction: "unknown_interaction";
|
|
259
|
+
unknown_run: "unknown_run";
|
|
260
|
+
binding_mismatch: "binding_mismatch";
|
|
261
|
+
invalid_response: "invalid_response";
|
|
262
|
+
transport_failure: "transport_failure";
|
|
263
|
+
}>;
|
|
264
|
+
message: z.ZodOptional<z.ZodString>;
|
|
265
|
+
retryable: z.ZodOptional<z.ZodBoolean>;
|
|
266
|
+
}, z.core.$strict>;
|
|
267
|
+
export type InteractionAcknowledgement = z.infer<typeof InteractionAcknowledgementSchema>;
|