@zhivex-ai/core 0.19.0 → 1.0.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 +19 -1
- package/dist/agent-control-plane.d.ts +4 -1
- package/dist/agent-control-plane.d.ts.map +1 -1
- package/dist/agent-control-plane.js +61 -32
- package/dist/agent-control-plane.js.map +1 -1
- package/dist/agent-evaluation.d.ts +5 -1
- package/dist/agent-evaluation.d.ts.map +1 -1
- package/dist/agent-evaluation.js +17 -0
- package/dist/agent-evaluation.js.map +1 -1
- package/dist/agent-harness.d.ts +9 -0
- package/dist/agent-harness.d.ts.map +1 -0
- package/dist/agent-harness.js +66 -0
- package/dist/agent-harness.js.map +1 -0
- package/dist/agent-state.d.ts.map +1 -1
- package/dist/agent-state.js +112 -0
- package/dist/agent-state.js.map +1 -1
- package/dist/agent.d.ts +24 -15
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +692 -39
- package/dist/agent.js.map +1 -1
- package/dist/api-stability.d.ts.map +1 -1
- package/dist/api-stability.js +4 -0
- package/dist/api-stability.js.map +1 -1
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +10 -0
- package/dist/catalog.js.map +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/generate-object.d.ts.map +1 -1
- package/dist/generate-object.js +7 -2
- package/dist/generate-object.js.map +1 -1
- package/dist/generate-text.d.ts +5 -4
- package/dist/generate-text.d.ts.map +1 -1
- package/dist/generate-text.js +482 -70
- package/dist/generate-text.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +22 -3
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +164 -18
- package/dist/mcp.js.map +1 -1
- package/dist/messages.d.ts +5 -5
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js.map +1 -1
- package/dist/safety-policy.d.ts.map +1 -1
- package/dist/safety-policy.js +2 -3
- package/dist/safety-policy.js.map +1 -1
- package/dist/stream.d.ts +4 -0
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +29 -0
- package/dist/stream.js.map +1 -1
- package/dist/structured-output-prompt.d.ts +6 -0
- package/dist/structured-output-prompt.d.ts.map +1 -0
- package/dist/structured-output-prompt.js +26 -0
- package/dist/structured-output-prompt.js.map +1 -0
- package/dist/tool-execution-suspension.d.ts +8 -0
- package/dist/tool-execution-suspension.d.ts.map +1 -0
- package/dist/tool-execution-suspension.js +12 -0
- package/dist/tool-execution-suspension.js.map +1 -0
- package/dist/types.d.ts +335 -28
- package/dist/types.d.ts.map +1 -1
- package/dist/ui.d.ts +5 -1
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +68 -2
- package/dist/ui.js.map +1 -1
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -152,6 +152,119 @@ export interface ToolExecutionOptions {
|
|
|
152
152
|
timeoutMs?: number;
|
|
153
153
|
stopOnError?: boolean;
|
|
154
154
|
}
|
|
155
|
+
export type ToolApprovalMode = "policy" | "interrupt";
|
|
156
|
+
export interface ToolApprovalSigner {
|
|
157
|
+
sign(payload: string): string | Promise<string>;
|
|
158
|
+
verify?(payload: string, signature: string): boolean | Promise<boolean>;
|
|
159
|
+
}
|
|
160
|
+
export interface ToolGuardrailTrigger {
|
|
161
|
+
triggered: true;
|
|
162
|
+
reason?: string;
|
|
163
|
+
metadata?: Record<string, JsonValue>;
|
|
164
|
+
}
|
|
165
|
+
export interface ToolRuntimeContext<TContext = any> {
|
|
166
|
+
context?: TContext;
|
|
167
|
+
/** Durable run that owns this execution, when invoked by the agent runtime. */
|
|
168
|
+
runId?: string;
|
|
169
|
+
agentId?: string;
|
|
170
|
+
scope?: AgentStoreScope;
|
|
171
|
+
metadata?: Record<string, JsonValue>;
|
|
172
|
+
/** Acquired execution boundary for this run. Callbacks and secrets are never persisted. */
|
|
173
|
+
executionEnvironment?: AgentExecutionEnvironmentSession<TContext>;
|
|
174
|
+
}
|
|
175
|
+
export type AgentExecutionEnvironmentBackend = "host" | "process" | "container" | "microvm" | "remote" | "custom";
|
|
176
|
+
export interface AgentExecutionEnvironmentManifest {
|
|
177
|
+
schemaVersion: 1;
|
|
178
|
+
id: string;
|
|
179
|
+
version?: string;
|
|
180
|
+
backend: AgentExecutionEnvironmentBackend;
|
|
181
|
+
assurance: "best-effort" | "enforced";
|
|
182
|
+
isolation: "shared" | "per-run" | "per-tool-call";
|
|
183
|
+
workspace?: {
|
|
184
|
+
id?: string;
|
|
185
|
+
root: string;
|
|
186
|
+
cwd?: string;
|
|
187
|
+
access: "read-only" | "read-write";
|
|
188
|
+
followSymlinks?: boolean;
|
|
189
|
+
readablePaths?: string[];
|
|
190
|
+
writablePaths?: string[];
|
|
191
|
+
};
|
|
192
|
+
permissions?: {
|
|
193
|
+
undeclaredTools?: "allow" | "deny";
|
|
194
|
+
filesystem?: "deny" | "read-only" | "read-write";
|
|
195
|
+
network?: {
|
|
196
|
+
mode: "deny" | "allowlist";
|
|
197
|
+
allowedDomains?: string[];
|
|
198
|
+
allowedPorts?: number[];
|
|
199
|
+
allowPrivateNetworks?: boolean;
|
|
200
|
+
};
|
|
201
|
+
process?: {
|
|
202
|
+
shell: "deny" | "allowlist" | "allow";
|
|
203
|
+
allowedCommands?: string[];
|
|
204
|
+
};
|
|
205
|
+
environment?: {
|
|
206
|
+
inheritedVariables?: string[];
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
limits?: {
|
|
210
|
+
maxProcessRuntimeMs?: number;
|
|
211
|
+
maxProcessOutputBytes?: number;
|
|
212
|
+
maxConcurrentProcesses?: number;
|
|
213
|
+
maxMemoryMb?: number;
|
|
214
|
+
maxWorkspaceBytes?: number;
|
|
215
|
+
maxFileWriteBytes?: number;
|
|
216
|
+
maxNetworkRequests?: number;
|
|
217
|
+
maxNetworkBytes?: number;
|
|
218
|
+
};
|
|
219
|
+
metadata?: Record<string, JsonValue>;
|
|
220
|
+
}
|
|
221
|
+
export interface AgentExecutionEnvironmentBinding {
|
|
222
|
+
environmentId: string;
|
|
223
|
+
environmentVersion?: string;
|
|
224
|
+
fingerprint: string;
|
|
225
|
+
workspaceId?: string;
|
|
226
|
+
}
|
|
227
|
+
export interface AgentExecutionEnvironmentAcquireRequest<TContext = any> {
|
|
228
|
+
runId: string;
|
|
229
|
+
agentId?: string;
|
|
230
|
+
scope?: AgentStoreScope;
|
|
231
|
+
context?: TContext;
|
|
232
|
+
metadata?: Record<string, JsonValue>;
|
|
233
|
+
abortSignal?: AbortSignal;
|
|
234
|
+
}
|
|
235
|
+
export interface AgentExecutionAuthorizationRequest<TContext = any> {
|
|
236
|
+
manifest: AgentExecutionEnvironmentManifest;
|
|
237
|
+
binding: AgentExecutionEnvironmentBinding;
|
|
238
|
+
tool: ToolDefinition;
|
|
239
|
+
toolCall: ToolCall;
|
|
240
|
+
input: unknown;
|
|
241
|
+
context: ToolExecutionContext<TContext>;
|
|
242
|
+
phase: "preflight" | "execute";
|
|
243
|
+
}
|
|
244
|
+
export type AgentExecutionAuthorizationDecision = {
|
|
245
|
+
decision: "allow";
|
|
246
|
+
metadata?: Record<string, JsonValue>;
|
|
247
|
+
} | {
|
|
248
|
+
decision: "deny";
|
|
249
|
+
reason: string;
|
|
250
|
+
metadata?: Record<string, JsonValue>;
|
|
251
|
+
};
|
|
252
|
+
export interface AgentExecutionEnvironmentSession<TContext = any> {
|
|
253
|
+
readonly manifest: AgentExecutionEnvironmentManifest;
|
|
254
|
+
readonly binding: AgentExecutionEnvironmentBinding;
|
|
255
|
+
authorize(request: AgentExecutionAuthorizationRequest<TContext>): AgentExecutionAuthorizationDecision | Promise<AgentExecutionAuthorizationDecision>;
|
|
256
|
+
execute<TResult>(request: AgentExecutionAuthorizationRequest<TContext>, operation: () => TResult | Promise<TResult>): TResult | Promise<TResult>;
|
|
257
|
+
release?(result: {
|
|
258
|
+
status: AgentStatus;
|
|
259
|
+
error?: {
|
|
260
|
+
message: string;
|
|
261
|
+
};
|
|
262
|
+
}): void | Promise<void>;
|
|
263
|
+
}
|
|
264
|
+
export interface AgentExecutionEnvironment<TContext = any> {
|
|
265
|
+
readonly manifest: AgentExecutionEnvironmentManifest;
|
|
266
|
+
acquire(request: AgentExecutionEnvironmentAcquireRequest<TContext>): AgentExecutionEnvironmentSession<TContext> | Promise<AgentExecutionEnvironmentSession<TContext>>;
|
|
267
|
+
}
|
|
155
268
|
export interface StructuredOutputConfig<TSchema extends ZodTypeAny = ZodTypeAny> {
|
|
156
269
|
schema: TSchema;
|
|
157
270
|
mode: StructuredOutputMode;
|
|
@@ -177,6 +290,10 @@ export interface StreamToolResultEvent {
|
|
|
177
290
|
type: "tool-result";
|
|
178
291
|
toolResult: ToolExecutionResult;
|
|
179
292
|
}
|
|
293
|
+
export interface StreamToolApprovalRequestEvent {
|
|
294
|
+
type: "tool-approval-request";
|
|
295
|
+
approval: AgentApprovalRequest;
|
|
296
|
+
}
|
|
180
297
|
export interface StreamProviderDataEvent {
|
|
181
298
|
type: "provider-data";
|
|
182
299
|
provider: string;
|
|
@@ -201,7 +318,7 @@ export interface StreamErrorEvent {
|
|
|
201
318
|
type: "error";
|
|
202
319
|
error: Error;
|
|
203
320
|
}
|
|
204
|
-
export type StreamEvent = StreamTextDeltaEvent | StreamToolCallEvent | StreamToolResultEvent | StreamProviderDataEvent | StreamImageGenerationEvent | StreamFinishEvent | StreamErrorEvent;
|
|
321
|
+
export type StreamEvent = StreamTextDeltaEvent | StreamToolCallEvent | StreamToolResultEvent | StreamToolApprovalRequestEvent | StreamProviderDataEvent | StreamImageGenerationEvent | StreamFinishEvent | StreamErrorEvent;
|
|
205
322
|
export interface AgentRunStartEvent {
|
|
206
323
|
type: "agent-run-start";
|
|
207
324
|
currentStep: number;
|
|
@@ -223,12 +340,16 @@ export interface AgentApprovalResolvedEvent {
|
|
|
223
340
|
type: "agent-approval-resolved";
|
|
224
341
|
approval: AgentApprovalResponse;
|
|
225
342
|
}
|
|
343
|
+
export interface AgentCompactionEvent {
|
|
344
|
+
type: "agent-compaction";
|
|
345
|
+
compaction: AgentCompactionRecord;
|
|
346
|
+
}
|
|
226
347
|
export interface AgentRunFinishEvent {
|
|
227
348
|
type: "agent-run-finish";
|
|
228
349
|
status: AgentStatus;
|
|
229
350
|
state: AgentRunState;
|
|
230
351
|
}
|
|
231
|
-
export type AgentStreamEvent = StreamEvent | AgentRunStartEvent | AgentStepStartEvent | AgentStepFinishEvent | AgentApprovalRequestEvent | AgentApprovalResolvedEvent | AgentRunFinishEvent;
|
|
352
|
+
export type AgentStreamEvent = StreamEvent | AgentRunStartEvent | AgentStepStartEvent | AgentStepFinishEvent | AgentApprovalRequestEvent | AgentApprovalResolvedEvent | AgentCompactionEvent | AgentRunFinishEvent;
|
|
232
353
|
export interface StreamObjectDeltaEvent {
|
|
233
354
|
type: "object-delta";
|
|
234
355
|
textDelta: string;
|
|
@@ -896,26 +1017,46 @@ export interface ProviderAdapter {
|
|
|
896
1017
|
predictionModel?: (modelId: string) => PredictionModel;
|
|
897
1018
|
}
|
|
898
1019
|
export type CallableProviderAdapter = ProviderAdapter & ((modelId: string) => LanguageModel);
|
|
899
|
-
export interface ToolDefinition<TSchema extends ZodTypeAny =
|
|
1020
|
+
export interface ToolDefinition<TSchema extends ZodTypeAny = any, TResult = JsonValue, TContext = any> {
|
|
900
1021
|
name: string;
|
|
901
1022
|
description?: string;
|
|
902
1023
|
schema: TSchema;
|
|
903
1024
|
metadata?: Record<string, JsonValue>;
|
|
904
1025
|
requiresApproval?: boolean;
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
1026
|
+
/**
|
|
1027
|
+
* "policy" preserves the immediate allow/deny policy behavior. "interrupt"
|
|
1028
|
+
* creates a resumable local approval request before any tool side effect.
|
|
1029
|
+
*/
|
|
1030
|
+
approvalMode?: ToolApprovalMode;
|
|
1031
|
+
/** Bump when approval-relevant tool behavior changes so stale approvals cannot be replayed. */
|
|
1032
|
+
approvalVersion?: string;
|
|
1033
|
+
isEnabled?: (input: z.infer<TSchema>, context: ToolExecutionContext<TContext>) => boolean | Promise<boolean>;
|
|
1034
|
+
inputGuardrails?: ToolInputGuardrail<TSchema, TContext>[];
|
|
1035
|
+
outputGuardrails?: ToolOutputGuardrail<TSchema, TResult, TContext>[];
|
|
1036
|
+
onError?: ToolErrorHandler<TSchema, TResult, TContext>;
|
|
1037
|
+
execute: (input: z.infer<TSchema>, context?: ToolExecutionContext<TContext>) => Promise<TResult> | TResult;
|
|
1038
|
+
}
|
|
1039
|
+
export interface ToolExecutionContext<TContext = any> extends ToolRuntimeContext<TContext> {
|
|
908
1040
|
abortSignal?: AbortSignal;
|
|
909
1041
|
toolCall: ToolCall;
|
|
910
1042
|
step: number;
|
|
911
1043
|
model: LanguageModel | RealtimeModel;
|
|
912
|
-
/** Durable run that owns this execution, when invoked by the agent runtime. */
|
|
913
|
-
runId?: string;
|
|
914
1044
|
/** Forward this key to side-effecting APIs to make retries externally idempotent. */
|
|
915
1045
|
idempotencyKey?: string;
|
|
916
1046
|
request?: ModelGenerateInput;
|
|
917
1047
|
realtimeConfig?: RealtimeSessionConfig;
|
|
918
1048
|
}
|
|
1049
|
+
export interface ToolInputGuardrailRequest<TSchema extends ZodTypeAny = any, TContext = any> {
|
|
1050
|
+
tool: ToolDefinition;
|
|
1051
|
+
input: z.infer<TSchema>;
|
|
1052
|
+
context: ToolExecutionContext<TContext>;
|
|
1053
|
+
}
|
|
1054
|
+
export interface ToolOutputGuardrailRequest<TSchema extends ZodTypeAny = any, TResult = JsonValue, TContext = any> extends ToolInputGuardrailRequest<TSchema, TContext> {
|
|
1055
|
+
output: TResult;
|
|
1056
|
+
}
|
|
1057
|
+
export type ToolInputGuardrail<TSchema extends ZodTypeAny = any, TContext = any> = (request: ToolInputGuardrailRequest<TSchema, TContext>) => ToolGuardrailTrigger | void | Promise<ToolGuardrailTrigger | void>;
|
|
1058
|
+
export type ToolOutputGuardrail<TSchema extends ZodTypeAny = any, TResult = JsonValue, TContext = any> = (request: ToolOutputGuardrailRequest<TSchema, TResult, TContext>) => ToolGuardrailTrigger | void | Promise<ToolGuardrailTrigger | void>;
|
|
1059
|
+
export type ToolErrorHandler<TSchema extends ZodTypeAny = any, TResult = JsonValue, TContext = any> = (error: Error, request: ToolInputGuardrailRequest<TSchema, TContext>) => TResult | void | Promise<TResult | void>;
|
|
919
1060
|
export type HostedToolClass = "web-search" | "file-search" | "remote-mcp" | "computer-use" | "code-execution" | "shell" | "apply-patch" | "tool-search" | "web-extraction" | "skill" | "toolset" | "custom";
|
|
920
1061
|
export interface HostedToolDefinition<TConfig extends JsonValue = JsonValue> {
|
|
921
1062
|
kind: "hosted";
|
|
@@ -927,7 +1068,7 @@ export interface HostedToolDefinition<TConfig extends JsonValue = JsonValue> {
|
|
|
927
1068
|
requiresApproval?: boolean;
|
|
928
1069
|
metadata?: Record<string, JsonValue>;
|
|
929
1070
|
}
|
|
930
|
-
export type AnyToolDefinition = ToolDefinition | HostedToolDefinition;
|
|
1071
|
+
export type AnyToolDefinition = ToolDefinition<any, any, any> | HostedToolDefinition;
|
|
931
1072
|
export type ToolSet = Record<string, AnyToolDefinition>;
|
|
932
1073
|
export interface ToolRegistryLike {
|
|
933
1074
|
get(name: string): AnyToolDefinition | undefined;
|
|
@@ -936,17 +1077,20 @@ export interface ToolRegistryLike {
|
|
|
936
1077
|
toToolSet(): ToolSet;
|
|
937
1078
|
}
|
|
938
1079
|
export type ToolCollection = ToolSet | ToolRegistryLike;
|
|
939
|
-
export interface ToolApprovalRequest {
|
|
1080
|
+
export interface ToolApprovalRequest<TContext = any> {
|
|
940
1081
|
toolCall: ToolCall;
|
|
941
1082
|
tool: ToolDefinition;
|
|
942
1083
|
input: JsonValue;
|
|
943
1084
|
step: number;
|
|
944
1085
|
model: LanguageModel | RealtimeModel;
|
|
945
1086
|
request?: ModelGenerateInput;
|
|
1087
|
+
executionContext?: ToolExecutionContext<TContext>;
|
|
946
1088
|
realtimeConfig?: RealtimeSessionConfig;
|
|
947
1089
|
}
|
|
948
1090
|
export interface ToolApprovalDecision {
|
|
949
1091
|
approved: boolean;
|
|
1092
|
+
/** Requests resumable human approval instead of treating approved:false as a final denial. */
|
|
1093
|
+
approvalRequired?: boolean;
|
|
950
1094
|
reason?: string;
|
|
951
1095
|
metadata?: Record<string, JsonValue>;
|
|
952
1096
|
}
|
|
@@ -954,17 +1098,26 @@ export interface ToolApprovalEvent {
|
|
|
954
1098
|
request: ToolApprovalRequest;
|
|
955
1099
|
decision: ToolApprovalDecision;
|
|
956
1100
|
}
|
|
957
|
-
export type ToolApprovalPolicy = (request: ToolApprovalRequest) => ToolApprovalDecision | boolean | Promise<ToolApprovalDecision | boolean>;
|
|
1101
|
+
export type ToolApprovalPolicy<TContext = any> = (request: ToolApprovalRequest<TContext>) => ToolApprovalDecision | boolean | Promise<ToolApprovalDecision | boolean>;
|
|
958
1102
|
export type ToolApprovalObserver = (event: ToolApprovalEvent) => void | Promise<void>;
|
|
959
1103
|
export type ProviderOptionsOf<TModel extends LanguageModel> = TModel extends LanguageModel<infer TProviderOptions> ? TProviderOptions : ProviderOptions;
|
|
960
|
-
export type GenerateTextOptions<TModel extends LanguageModel = LanguageModel> = RetryOptions & GenerateInputSource & {
|
|
1104
|
+
export type GenerateTextOptions<TModel extends LanguageModel = LanguageModel, TContext = unknown> = RetryOptions & GenerateInputSource & {
|
|
961
1105
|
model: TModel;
|
|
962
1106
|
system?: string;
|
|
963
1107
|
tools?: ToolCollection;
|
|
964
1108
|
toolChoice?: ToolChoice;
|
|
965
1109
|
toolExecution?: ToolExecutionOptions;
|
|
966
|
-
toolApprovalPolicy?: ToolApprovalPolicy
|
|
1110
|
+
toolApprovalPolicy?: ToolApprovalPolicy<TContext>;
|
|
1111
|
+
toolApprovalSigner?: ToolApprovalSigner;
|
|
1112
|
+
/** Resolved local approvals supplied by a durable agent runtime. */
|
|
1113
|
+
toolApprovalResolutions?: AgentApprovalResolution[];
|
|
1114
|
+
toolContext?: ToolRuntimeContext<TContext>;
|
|
967
1115
|
onToolApprovalDecision?: ToolApprovalObserver;
|
|
1116
|
+
/** Durable runtimes may replace the active context before each provider request. */
|
|
1117
|
+
prepareModelMessages?: (context: {
|
|
1118
|
+
messages: readonly ModelMessage[];
|
|
1119
|
+
step: number;
|
|
1120
|
+
}) => ModelMessage[] | undefined | Promise<ModelMessage[] | undefined>;
|
|
968
1121
|
/** Called immediately before each model request. Throw to stop the loop. */
|
|
969
1122
|
onBeforeModelStep?: (context: {
|
|
970
1123
|
request: ModelGenerateInput;
|
|
@@ -982,6 +1135,7 @@ export type GenerateTextOptions<TModel extends LanguageModel = LanguageModel> =
|
|
|
982
1135
|
response: GenerateResult;
|
|
983
1136
|
step: number;
|
|
984
1137
|
toolCalls: ToolCall[];
|
|
1138
|
+
approvalRequests: AgentApprovalRequest[];
|
|
985
1139
|
}) => void | Promise<void>;
|
|
986
1140
|
/** Durable runtimes use this hook to checkpoint tool results before the next model request. */
|
|
987
1141
|
onToolExecutionComplete?: (context: {
|
|
@@ -1010,6 +1164,8 @@ export interface GenerateTextOutput {
|
|
|
1010
1164
|
steps: GenerateTextStep[];
|
|
1011
1165
|
messages: ModelMessage[];
|
|
1012
1166
|
toolResults: ToolExecutionResult[];
|
|
1167
|
+
/** Local resumable approval requests produced before any tool in the batch executes. */
|
|
1168
|
+
approvalRequests?: AgentApprovalRequest[];
|
|
1013
1169
|
}
|
|
1014
1170
|
export type AgentStatus = "queued" | "running" | "completed"
|
|
1015
1171
|
/**
|
|
@@ -1020,6 +1176,10 @@ export type AgentStepStatus = "running" | "completed" | "suspended" | "waiting_a
|
|
|
1020
1176
|
export interface AgentRunPolicy {
|
|
1021
1177
|
timeoutMs?: number;
|
|
1022
1178
|
onTimeout?: "fail" | "cancel-requested";
|
|
1179
|
+
/** Explicit migration escape hatch for pre-fingerprint durable states. */
|
|
1180
|
+
allowLegacyHarnessResume?: boolean;
|
|
1181
|
+
/** Explicit migration escape hatch for states created before environment binding. */
|
|
1182
|
+
allowLegacyExecutionEnvironmentResume?: boolean;
|
|
1023
1183
|
/** Disable only for stores that intentionally provide CAS without worker leases. */
|
|
1024
1184
|
leaseMode?: "required" | "disabled";
|
|
1025
1185
|
/** Duration of the exclusive worker lease. Defaults to 30 seconds. */
|
|
@@ -1043,6 +1203,57 @@ export interface AgentRunPolicy {
|
|
|
1043
1203
|
includeChildRuns?: boolean;
|
|
1044
1204
|
};
|
|
1045
1205
|
}
|
|
1206
|
+
export type AgentCompactionReason = "message-count" | "estimated-input-tokens";
|
|
1207
|
+
export interface AgentCompactionRequest<TContext = any> {
|
|
1208
|
+
runId: string;
|
|
1209
|
+
agentId?: string;
|
|
1210
|
+
scope?: AgentStoreScope;
|
|
1211
|
+
beforeStep: number;
|
|
1212
|
+
context?: TContext;
|
|
1213
|
+
/** Historical prefix being summarized. System messages are never included. */
|
|
1214
|
+
messages: ModelMessage[];
|
|
1215
|
+
/** Literal tail preserved after the summary. */
|
|
1216
|
+
retainedMessages: ModelMessage[];
|
|
1217
|
+
reasons: AgentCompactionReason[];
|
|
1218
|
+
estimatedTokensBefore: number;
|
|
1219
|
+
sourceDigest: string;
|
|
1220
|
+
idempotencyKey: string;
|
|
1221
|
+
metadata?: Record<string, JsonValue>;
|
|
1222
|
+
abortSignal?: AbortSignal;
|
|
1223
|
+
}
|
|
1224
|
+
export interface AgentCompactionResult {
|
|
1225
|
+
summary: string;
|
|
1226
|
+
usage?: TokenUsage;
|
|
1227
|
+
metadata?: Record<string, JsonValue>;
|
|
1228
|
+
}
|
|
1229
|
+
export type AgentCompactor<TContext = any> = (request: AgentCompactionRequest<TContext>) => AgentCompactionResult | Promise<AgentCompactionResult>;
|
|
1230
|
+
export interface AgentCompactionOptions<TContext = any> {
|
|
1231
|
+
/** Compaction runs when either configured threshold is exceeded. */
|
|
1232
|
+
maxMessages?: number;
|
|
1233
|
+
maxEstimatedInputTokens?: number;
|
|
1234
|
+
/** Literal non-system tail retained after compaction. Defaults to 8 messages. */
|
|
1235
|
+
keepRecentMessages?: number;
|
|
1236
|
+
estimateTokens?: (messages: readonly ModelMessage[]) => number;
|
|
1237
|
+
compactor: AgentCompactor<TContext>;
|
|
1238
|
+
}
|
|
1239
|
+
export interface AgentCompactionRecord {
|
|
1240
|
+
id: string;
|
|
1241
|
+
beforeStep: number;
|
|
1242
|
+
createdAt: number;
|
|
1243
|
+
reasons: AgentCompactionReason[];
|
|
1244
|
+
sourceDigest: string;
|
|
1245
|
+
resultDigest: string;
|
|
1246
|
+
summaryDigest: string;
|
|
1247
|
+
summary: string;
|
|
1248
|
+
messageCountBefore: number;
|
|
1249
|
+
messageCountAfter: number;
|
|
1250
|
+
compactedMessageCount: number;
|
|
1251
|
+
retainedMessageCount: number;
|
|
1252
|
+
estimatedTokensBefore: number;
|
|
1253
|
+
estimatedTokensAfter: number;
|
|
1254
|
+
usage?: TokenUsage;
|
|
1255
|
+
metadata?: Record<string, JsonValue>;
|
|
1256
|
+
}
|
|
1046
1257
|
export interface AgentStepRequest {
|
|
1047
1258
|
/** Index in the full conversation where this incremental snapshot begins. */
|
|
1048
1259
|
messageOffset?: number;
|
|
@@ -1081,6 +1292,7 @@ export interface AgentChildRun {
|
|
|
1081
1292
|
agentId?: string;
|
|
1082
1293
|
parentRunId?: string;
|
|
1083
1294
|
toolName?: string;
|
|
1295
|
+
toolCallId?: string;
|
|
1084
1296
|
status: AgentStatus;
|
|
1085
1297
|
outputText: string;
|
|
1086
1298
|
steps: number;
|
|
@@ -1093,6 +1305,15 @@ export interface AgentChildRun {
|
|
|
1093
1305
|
message: string;
|
|
1094
1306
|
};
|
|
1095
1307
|
metadata?: Record<string, JsonValue>;
|
|
1308
|
+
/** Durable child state retained only while the parent must resume a child approval. */
|
|
1309
|
+
resumeState?: AgentRunState;
|
|
1310
|
+
}
|
|
1311
|
+
export interface AgentHarnessBinding {
|
|
1312
|
+
schemaVersion: 1;
|
|
1313
|
+
id: string;
|
|
1314
|
+
version: string;
|
|
1315
|
+
fingerprint: string;
|
|
1316
|
+
algorithm: "sha256";
|
|
1096
1317
|
}
|
|
1097
1318
|
export interface AgentRunState {
|
|
1098
1319
|
schemaVersion: 1;
|
|
@@ -1109,6 +1330,8 @@ export interface AgentRunState {
|
|
|
1109
1330
|
parentRunId?: string;
|
|
1110
1331
|
provider: string;
|
|
1111
1332
|
modelId: string;
|
|
1333
|
+
harness?: AgentHarnessBinding;
|
|
1334
|
+
executionEnvironment?: AgentExecutionEnvironmentBinding;
|
|
1112
1335
|
status: AgentStatus;
|
|
1113
1336
|
messages: ModelMessage[];
|
|
1114
1337
|
steps: AgentStep[];
|
|
@@ -1116,11 +1339,15 @@ export interface AgentRunState {
|
|
|
1116
1339
|
currentStep: number;
|
|
1117
1340
|
maxSteps: number;
|
|
1118
1341
|
outputText: string;
|
|
1342
|
+
finalOutput?: JsonValue;
|
|
1343
|
+
outputMode?: Exclude<StructuredOutputMode, "auto">;
|
|
1119
1344
|
finishReason?: FinishReason;
|
|
1120
1345
|
providerFinishReason?: string;
|
|
1121
1346
|
usage?: TokenUsage;
|
|
1122
1347
|
pendingApprovals: AgentApprovalRequest[];
|
|
1348
|
+
approvalHistory?: AgentApprovalResolution[];
|
|
1123
1349
|
childRuns?: AgentChildRun[];
|
|
1350
|
+
compactions?: AgentCompactionRecord[];
|
|
1124
1351
|
metadata?: Record<string, JsonValue>;
|
|
1125
1352
|
handoff?: AgentHandoff;
|
|
1126
1353
|
startedAt?: number;
|
|
@@ -1360,22 +1587,24 @@ export interface AgentGuardrailTrigger {
|
|
|
1360
1587
|
reason?: string;
|
|
1361
1588
|
metadata?: Record<string, JsonValue>;
|
|
1362
1589
|
}
|
|
1363
|
-
export interface AgentInputGuardrailRequest {
|
|
1590
|
+
export interface AgentInputGuardrailRequest<TContext = any> {
|
|
1364
1591
|
runId: string;
|
|
1365
1592
|
agentId?: string;
|
|
1593
|
+
context?: TContext;
|
|
1366
1594
|
state: AgentRunState;
|
|
1367
1595
|
messages: ModelMessage[];
|
|
1368
1596
|
metadata?: Record<string, JsonValue>;
|
|
1369
1597
|
}
|
|
1370
|
-
export interface AgentOutputGuardrailRequest {
|
|
1598
|
+
export interface AgentOutputGuardrailRequest<TContext = any, TOutput = any> {
|
|
1371
1599
|
runId: string;
|
|
1372
1600
|
agentId?: string;
|
|
1601
|
+
context?: TContext;
|
|
1373
1602
|
state: AgentRunState;
|
|
1374
|
-
output: AgentRunOutput | LiveAgentRunOutput;
|
|
1603
|
+
output: AgentRunOutput<TOutput> | LiveAgentRunOutput;
|
|
1375
1604
|
metadata?: Record<string, JsonValue>;
|
|
1376
1605
|
}
|
|
1377
|
-
export type AgentInputGuardrail = (request: AgentInputGuardrailRequest) => AgentGuardrailTrigger | void | Promise<AgentGuardrailTrigger | void>;
|
|
1378
|
-
export type AgentOutputGuardrail = (request: AgentOutputGuardrailRequest) => AgentGuardrailTrigger | void | Promise<AgentGuardrailTrigger | void>;
|
|
1606
|
+
export type AgentInputGuardrail<TContext = any> = (request: AgentInputGuardrailRequest<TContext>) => AgentGuardrailTrigger | void | Promise<AgentGuardrailTrigger | void>;
|
|
1607
|
+
export type AgentOutputGuardrail<TContext = any, TOutput = any> = (request: AgentOutputGuardrailRequest<TContext, TOutput>) => AgentGuardrailTrigger | void | Promise<AgentGuardrailTrigger | void>;
|
|
1379
1608
|
export interface AgentTelemetryGuardrailTriggeredEvent {
|
|
1380
1609
|
type: "guardrail-triggered";
|
|
1381
1610
|
runId: string;
|
|
@@ -1432,21 +1661,31 @@ export interface AgentHookFailurePolicy {
|
|
|
1432
1661
|
memory?: AgentHookFailureMode;
|
|
1433
1662
|
onError?: (event: AgentOperationalError) => void | Promise<void>;
|
|
1434
1663
|
}
|
|
1435
|
-
export interface AgentDefinition<TModel extends LanguageModel = LanguageModel> {
|
|
1664
|
+
export interface AgentDefinition<TModel extends LanguageModel = LanguageModel, TContext = any, TOutput = any> {
|
|
1436
1665
|
id?: string;
|
|
1437
1666
|
model: TModel;
|
|
1438
1667
|
instructions?: string;
|
|
1668
|
+
contextSchema?: z.ZodType<TContext>;
|
|
1439
1669
|
tools?: ToolCollection;
|
|
1440
1670
|
maxSteps?: number;
|
|
1441
1671
|
temperature?: number;
|
|
1442
1672
|
maxTokens?: number;
|
|
1443
1673
|
reasoning?: ReasoningConfig;
|
|
1674
|
+
outputSchema?: z.ZodType<TOutput>;
|
|
1675
|
+
outputMode?: StructuredOutputMode;
|
|
1676
|
+
outputName?: string;
|
|
1677
|
+
outputDescription?: string;
|
|
1444
1678
|
toolExecution?: ToolExecutionOptions;
|
|
1445
|
-
toolApprovalPolicy?: ToolApprovalPolicy
|
|
1446
|
-
|
|
1447
|
-
|
|
1679
|
+
toolApprovalPolicy?: ToolApprovalPolicy<TContext>;
|
|
1680
|
+
toolApprovalSigner?: ToolApprovalSigner;
|
|
1681
|
+
inputGuardrails?: AgentInputGuardrail<TContext>[];
|
|
1682
|
+
outputGuardrails?: AgentOutputGuardrail<TContext, TOutput>[];
|
|
1448
1683
|
providerOptions?: ProviderOptionsOf<TModel>;
|
|
1449
1684
|
subagents?: AgentSubAgentDefinition[];
|
|
1685
|
+
/** Immutable identity of the capsule/spec that owns durable resume semantics. */
|
|
1686
|
+
harness?: AgentHarnessBinding;
|
|
1687
|
+
executionEnvironment?: AgentExecutionEnvironment<TContext>;
|
|
1688
|
+
compaction?: AgentCompactionOptions<TContext>;
|
|
1450
1689
|
policy?: AgentRunPolicy;
|
|
1451
1690
|
metadata?: Record<string, JsonValue>;
|
|
1452
1691
|
store?: AgentRunStore;
|
|
@@ -1471,11 +1710,21 @@ export interface LiveAgentDefinition<TModel extends RealtimeModel = RealtimeMode
|
|
|
1471
1710
|
onTelemetryEvent?: AgentTelemetryObserver;
|
|
1472
1711
|
}
|
|
1473
1712
|
export interface AgentApprovalRequest {
|
|
1713
|
+
/** Absent on legacy persisted states and treated as "provider". */
|
|
1714
|
+
kind?: "provider" | "local-tool" | "subagent";
|
|
1474
1715
|
provider: string;
|
|
1475
1716
|
id: string;
|
|
1476
1717
|
name: string;
|
|
1477
1718
|
arguments: string;
|
|
1478
1719
|
serverLabel?: string;
|
|
1720
|
+
toolCallId?: string;
|
|
1721
|
+
step?: number;
|
|
1722
|
+
inputDigest?: string;
|
|
1723
|
+
toolVersion?: string;
|
|
1724
|
+
signature?: string;
|
|
1725
|
+
childRunId?: string;
|
|
1726
|
+
childAgentId?: string;
|
|
1727
|
+
childApprovalRequestId?: string;
|
|
1479
1728
|
rawData: JsonValue;
|
|
1480
1729
|
}
|
|
1481
1730
|
export interface AgentApprovalResponse {
|
|
@@ -1485,11 +1734,29 @@ export interface AgentApprovalResponse {
|
|
|
1485
1734
|
id?: string;
|
|
1486
1735
|
reason?: string;
|
|
1487
1736
|
}
|
|
1488
|
-
export
|
|
1737
|
+
export interface AgentApprovalResolution {
|
|
1738
|
+
requestId: string;
|
|
1739
|
+
kind: "provider" | "local-tool" | "subagent";
|
|
1740
|
+
provider: string;
|
|
1741
|
+
approve: boolean;
|
|
1742
|
+
reason?: string;
|
|
1743
|
+
toolCallId?: string;
|
|
1744
|
+
step?: number;
|
|
1745
|
+
inputDigest?: string;
|
|
1746
|
+
toolVersion?: string;
|
|
1747
|
+
signature?: string;
|
|
1748
|
+
childRunId?: string;
|
|
1749
|
+
childAgentId?: string;
|
|
1750
|
+
childApprovalRequestId?: string;
|
|
1751
|
+
resolvedAt: number;
|
|
1752
|
+
}
|
|
1753
|
+
export type AgentRunInput<TModel extends LanguageModel = LanguageModel, TContext = any> = RetryOptions & GenerateInputSource & {
|
|
1489
1754
|
runId?: string;
|
|
1490
1755
|
/** Required isolation boundary for shared durable stores and memory. */
|
|
1491
1756
|
scope?: AgentStoreScope;
|
|
1492
1757
|
idempotencyKey?: string;
|
|
1758
|
+
/** Ephemeral application context. Callers must provide it again when resuming a run. */
|
|
1759
|
+
context?: TContext;
|
|
1493
1760
|
state?: AgentRunState;
|
|
1494
1761
|
approvals?: AgentApprovalResponse[];
|
|
1495
1762
|
handoff?: AgentHandoff;
|
|
@@ -1498,7 +1765,10 @@ export type AgentRunInput<TModel extends LanguageModel = LanguageModel> = RetryO
|
|
|
1498
1765
|
tools?: ToolCollection;
|
|
1499
1766
|
toolChoice?: ToolChoice;
|
|
1500
1767
|
toolExecution?: ToolExecutionOptions;
|
|
1501
|
-
toolApprovalPolicy?: ToolApprovalPolicy
|
|
1768
|
+
toolApprovalPolicy?: ToolApprovalPolicy<TContext>;
|
|
1769
|
+
executionEnvironment?: AgentExecutionEnvironment<TContext>;
|
|
1770
|
+
/** Pass false to disable the agent default for this invocation. */
|
|
1771
|
+
compaction?: AgentCompactionOptions<TContext> | false;
|
|
1502
1772
|
maxSteps?: number;
|
|
1503
1773
|
temperature?: number;
|
|
1504
1774
|
maxTokens?: number;
|
|
@@ -1507,9 +1777,10 @@ export type AgentRunInput<TModel extends LanguageModel = LanguageModel> = RetryO
|
|
|
1507
1777
|
policy?: AgentRunPolicy;
|
|
1508
1778
|
metadata?: Record<string, JsonValue>;
|
|
1509
1779
|
};
|
|
1510
|
-
export interface AgentRunOutput {
|
|
1780
|
+
export interface AgentRunOutput<TOutput = unknown> {
|
|
1511
1781
|
status: AgentStatus;
|
|
1512
1782
|
outputText: string;
|
|
1783
|
+
finalOutput?: TOutput;
|
|
1513
1784
|
finishReason?: FinishReason;
|
|
1514
1785
|
providerFinishReason?: string;
|
|
1515
1786
|
usage?: TokenUsage;
|
|
@@ -1575,6 +1846,8 @@ export interface PrepareSubagentsForAgentOptions {
|
|
|
1575
1846
|
onTelemetryEvent?: AgentTelemetryObserver;
|
|
1576
1847
|
toolApprovalPolicy?: ToolApprovalPolicy;
|
|
1577
1848
|
toolExecution?: ToolExecutionOptions;
|
|
1849
|
+
executionEnvironment?: AgentExecutionEnvironment;
|
|
1850
|
+
compaction?: AgentCompactionOptions;
|
|
1578
1851
|
metadata?: Record<string, JsonValue>;
|
|
1579
1852
|
}
|
|
1580
1853
|
export type LiveAgentRunInput = GenerateInputSource & RetryOptions & {
|
|
@@ -1599,10 +1872,10 @@ export interface LiveAgentRunOutput {
|
|
|
1599
1872
|
message: string;
|
|
1600
1873
|
};
|
|
1601
1874
|
}
|
|
1602
|
-
export interface AgentStreamResult {
|
|
1875
|
+
export interface AgentStreamResult<TOutput = unknown> {
|
|
1603
1876
|
eventStream: AsyncIterable<AgentStreamEvent>;
|
|
1604
1877
|
textStream: AsyncIterable<string>;
|
|
1605
|
-
collect: () => Promise<AgentRunOutput
|
|
1878
|
+
collect: () => Promise<AgentRunOutput<TOutput>>;
|
|
1606
1879
|
}
|
|
1607
1880
|
export type AgentLiveEvent = AgentStreamEvent | RealtimeEvent;
|
|
1608
1881
|
export interface AgentLiveStreamResult {
|
|
@@ -1930,6 +2203,12 @@ export interface UIMessageToolResultChunk {
|
|
|
1930
2203
|
role: "tool";
|
|
1931
2204
|
toolResult: ToolExecutionResult;
|
|
1932
2205
|
}
|
|
2206
|
+
export interface UIMessageToolApprovalRequestChunk {
|
|
2207
|
+
type: "tool-approval-request";
|
|
2208
|
+
messageId: string;
|
|
2209
|
+
role: "assistant";
|
|
2210
|
+
approval: AgentApprovalRequest;
|
|
2211
|
+
}
|
|
1933
2212
|
export interface UIMessageProviderDataChunk {
|
|
1934
2213
|
type: "provider-data";
|
|
1935
2214
|
messageId: string;
|
|
@@ -1937,6 +2216,25 @@ export interface UIMessageProviderDataChunk {
|
|
|
1937
2216
|
provider: string;
|
|
1938
2217
|
data: JsonValue;
|
|
1939
2218
|
}
|
|
2219
|
+
export interface UIMessageGeneratedMedia {
|
|
2220
|
+
data?: string;
|
|
2221
|
+
encoding?: "base64";
|
|
2222
|
+
uri?: string;
|
|
2223
|
+
mediaType: string;
|
|
2224
|
+
text?: string;
|
|
2225
|
+
providerMetadata?: Record<string, JsonValue>;
|
|
2226
|
+
}
|
|
2227
|
+
export interface UIMessageImageGenerationChunk {
|
|
2228
|
+
type: "image-generation";
|
|
2229
|
+
messageId: string;
|
|
2230
|
+
role: "assistant";
|
|
2231
|
+
provider: string;
|
|
2232
|
+
image: UIMessageGeneratedMedia;
|
|
2233
|
+
partial: boolean;
|
|
2234
|
+
id?: string;
|
|
2235
|
+
index?: number;
|
|
2236
|
+
providerMetadata?: Record<string, JsonValue>;
|
|
2237
|
+
}
|
|
1940
2238
|
export interface UIMessageFinishChunk {
|
|
1941
2239
|
type: "finish";
|
|
1942
2240
|
messageId: string;
|
|
@@ -1972,12 +2270,21 @@ export interface UIAgentApprovalResolvedChunk {
|
|
|
1972
2270
|
type: "agent-approval-resolved";
|
|
1973
2271
|
approval: AgentApprovalResponse;
|
|
1974
2272
|
}
|
|
2273
|
+
export interface UIAgentCompactionChunk {
|
|
2274
|
+
type: "agent-compaction";
|
|
2275
|
+
compaction: AgentCompactionRecord;
|
|
2276
|
+
}
|
|
1975
2277
|
export interface UIAgentRunFinishChunk {
|
|
1976
2278
|
type: "agent-run-finish";
|
|
1977
2279
|
status: AgentStatus;
|
|
1978
2280
|
state: AgentRunState;
|
|
1979
2281
|
}
|
|
1980
|
-
export
|
|
2282
|
+
export interface UISessionFinishChunk {
|
|
2283
|
+
type: "session-finish";
|
|
2284
|
+
sessionId: string;
|
|
2285
|
+
status: AgentStatus;
|
|
2286
|
+
}
|
|
2287
|
+
export type UIMessageChunk = UIMessageTextChunk | UIMessageToolCallChunk | UIMessageToolResultChunk | UIMessageToolApprovalRequestChunk | UIMessageProviderDataChunk | UIMessageImageGenerationChunk | UIMessageFinishChunk | UIMessageErrorChunk | UIAgentRunStartChunk | UIAgentStepStartChunk | UIAgentStepFinishChunk | UIAgentApprovalRequestChunk | UIAgentApprovalResolvedChunk | UIAgentCompactionChunk | UIAgentRunFinishChunk | UISessionFinishChunk;
|
|
1981
2288
|
export interface EmbedInput {
|
|
1982
2289
|
values: EmbedValue[];
|
|
1983
2290
|
}
|