@vercel/agent-runs 1.0.0-rc.2 → 1.0.0-rc.4
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/CHANGELOG.md +10 -5
- package/README.md +22 -2
- package/dist/src/adapters/otel.d.ts.map +1 -1
- package/dist/src/adapters/otel.js +4 -0
- package/dist/src/adapters/otel.js.map +1 -1
- package/dist/src/agent-run.d.ts +19 -2
- package/dist/src/agent-run.d.ts.map +1 -1
- package/dist/src/agent-run.js +28 -1
- package/dist/src/agent-run.js.map +1 -1
- package/dist/src/core/scopes.d.ts.map +1 -1
- package/dist/src/core/scopes.js +2 -10
- package/dist/src/core/scopes.js.map +1 -1
- package/dist/src/core/snapshot.d.ts.map +1 -1
- package/dist/src/core/snapshot.js +5 -1
- package/dist/src/core/snapshot.js.map +1 -1
- package/dist/src/core/span-kinds.d.ts.map +1 -1
- package/dist/src/core/span-kinds.js +29 -4
- package/dist/src/core/span-kinds.js.map +1 -1
- package/dist/src/core/types.d.ts +28 -7
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/operations.d.ts +13 -4
- package/dist/src/operations.d.ts.map +1 -1
- package/dist/src/operations.js +6 -8
- package/dist/src/operations.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/otel.ts +4 -0
- package/src/agent-run.ts +54 -2
- package/src/core/scopes.ts +3 -10
- package/src/core/snapshot.ts +9 -1
- package/src/core/span-kinds.ts +32 -4
- package/src/core/types.ts +26 -9
- package/src/index.ts +3 -0
- package/src/operations.ts +24 -17
package/src/core/types.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type SpanType =
|
|
|
22
22
|
| "tool"
|
|
23
23
|
| "approval"
|
|
24
24
|
| "memory"
|
|
25
|
+
| "decision"
|
|
25
26
|
| "channelRequest"
|
|
26
27
|
| "mcp";
|
|
27
28
|
export type SpanKind = "INTERNAL" | "CLIENT" | "SERVER" | "PRODUCER" | "CONSUMER";
|
|
@@ -85,6 +86,11 @@ export interface AgentTelemetry {
|
|
|
85
86
|
): SpanWriter;
|
|
86
87
|
/** Returns the operation active in the current execution context. */
|
|
87
88
|
active(): ActiveOperation | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Returns the span active in `context`, or the current execution context, including spans
|
|
91
|
+
* the host started itself. Lets a decision nest under the host's span inside an operation.
|
|
92
|
+
*/
|
|
93
|
+
activeSpan?(context?: ExecutionContext): TraceReference | undefined;
|
|
88
94
|
/** Runs `execute` with `operation` as the active trace context. */
|
|
89
95
|
run<T>(operation: ActiveOperation, execute: () => T, context?: ExecutionContext): T;
|
|
90
96
|
/** Runs `execute` without creating spans. */
|
|
@@ -196,26 +202,37 @@ export interface ModelOptions {
|
|
|
196
202
|
readonly tools?: unknown;
|
|
197
203
|
readonly runtimeContext?: Readonly<Record<string, unknown>>;
|
|
198
204
|
}
|
|
205
|
+
export interface DecisionOptions {
|
|
206
|
+
readonly provider?: string;
|
|
207
|
+
readonly modelId: string;
|
|
208
|
+
}
|
|
199
209
|
export interface ToolOptions {
|
|
200
210
|
readonly callId: string;
|
|
201
211
|
readonly name: string;
|
|
202
212
|
readonly kind?: ToolKind;
|
|
203
213
|
readonly arguments?: unknown;
|
|
204
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* A wait on a person. Under a tool call it names that call; under a turn it has no call, such
|
|
217
|
+
* as a budget prompt or a sign-in the turn needs before it can run.
|
|
218
|
+
*/
|
|
219
|
+
export interface ApprovalOptions {
|
|
220
|
+
readonly requestId: string;
|
|
221
|
+
readonly request?: unknown;
|
|
222
|
+
/** What the person is asked, recorded as `agent.approval.kind`. Defaults to `tool-approval`. */
|
|
223
|
+
readonly kind?: string;
|
|
224
|
+
/** The connection a sign-in is for, recorded as `agent.connection.name`. */
|
|
225
|
+
readonly connectionName?: string;
|
|
226
|
+
readonly callId?: string;
|
|
227
|
+
readonly toolName?: string;
|
|
228
|
+
}
|
|
205
229
|
export type ScopeData =
|
|
206
230
|
| { readonly type: "activation"; readonly options: TurnMetadata }
|
|
207
231
|
| { readonly type: "step"; readonly options: StepOptions }
|
|
208
232
|
| { readonly type: "model"; readonly options: ModelOptions }
|
|
209
233
|
| { readonly type: "tool"; readonly options: ToolOptions }
|
|
210
|
-
| {
|
|
211
|
-
|
|
212
|
-
readonly options: {
|
|
213
|
-
requestId: string;
|
|
214
|
-
request?: unknown;
|
|
215
|
-
callId: string;
|
|
216
|
-
toolName: string;
|
|
217
|
-
};
|
|
218
|
-
}
|
|
234
|
+
| { readonly type: "approval"; readonly options: ApprovalOptions }
|
|
235
|
+
| { readonly type: "decision"; readonly options: DecisionOptions }
|
|
219
236
|
| {
|
|
220
237
|
readonly type: "memory";
|
|
221
238
|
readonly options: {
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export {
|
|
|
3
3
|
type AgentRun,
|
|
4
4
|
type AgentRunOptions,
|
|
5
5
|
type AgentMemoryTracing,
|
|
6
|
+
type DecisionInput,
|
|
6
7
|
type TurnInput,
|
|
7
8
|
type ResumeInput,
|
|
8
9
|
} from "./agent-run.js";
|
|
@@ -16,8 +17,10 @@ export type {
|
|
|
16
17
|
ToolInput,
|
|
17
18
|
ModelOperation,
|
|
18
19
|
ToolOperation,
|
|
20
|
+
ApprovalInput,
|
|
19
21
|
ApprovalOperation,
|
|
20
22
|
MemoryOperation,
|
|
23
|
+
DecisionOperation,
|
|
21
24
|
ModelCallReturn,
|
|
22
25
|
ModelStreamReturn,
|
|
23
26
|
} from "./operations.js";
|
package/src/operations.ts
CHANGED
|
@@ -52,6 +52,17 @@ export interface TurnOperation extends Operation {
|
|
|
52
52
|
/** Replaces the turn's links before its deferred span is exported. */
|
|
53
53
|
links(links: readonly TraceLink[]): void;
|
|
54
54
|
memory: WrappedOperation<MemoryInput, MemoryOperation>;
|
|
55
|
+
/** A wait on a person that no tool call owns, such as a budget prompt or a sign-in. */
|
|
56
|
+
approval: WrappedOperation<ApprovalInput, ApprovalOperation>;
|
|
57
|
+
/** Returns an open turn-level approval without starting one. Durable turns only. */
|
|
58
|
+
findApproval(requestId: string): ApprovalOperation | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** What a person is asked. `kind` defaults to `tool-approval`. */
|
|
61
|
+
export interface ApprovalInput {
|
|
62
|
+
readonly requestId: string;
|
|
63
|
+
readonly request?: unknown;
|
|
64
|
+
readonly kind?: string;
|
|
65
|
+
readonly connectionName?: string;
|
|
55
66
|
}
|
|
56
67
|
/**
|
|
57
68
|
* One tool call. In a durable turn, calling `tool` again with the same `callId`
|
|
@@ -77,7 +88,7 @@ export interface AttemptOperation extends Operation {
|
|
|
77
88
|
memory: WrappedOperation<MemoryInput, MemoryOperation>;
|
|
78
89
|
}
|
|
79
90
|
export interface ToolOperation extends Operation {
|
|
80
|
-
approval: WrappedOperation<
|
|
91
|
+
approval: WrappedOperation<ApprovalInput, ApprovalOperation>;
|
|
81
92
|
/** Returns an open approval without starting one. Durable turns only. */
|
|
82
93
|
findApproval(requestId: string): ApprovalOperation | undefined;
|
|
83
94
|
/** A tool call made while this tool runs, such as a connector's nested call. */
|
|
@@ -87,6 +98,7 @@ export interface ToolOperation extends Operation {
|
|
|
87
98
|
export type ModelOperation = Operation;
|
|
88
99
|
export type ApprovalOperation = Operation;
|
|
89
100
|
export type MemoryOperation = Operation;
|
|
101
|
+
export type DecisionOperation = Operation;
|
|
90
102
|
export interface ModelCallReturn<T> extends ModelResult {
|
|
91
103
|
readonly result: T;
|
|
92
104
|
}
|
|
@@ -200,10 +212,20 @@ export function operationHandle(
|
|
|
200
212
|
undefined,
|
|
201
213
|
onError,
|
|
202
214
|
);
|
|
215
|
+
const approvals = (call?: { callId: string; toolName: string }) => ({
|
|
216
|
+
findApproval: (requestId: string) =>
|
|
217
|
+
found<ApprovalOperation>(runtime.find({ type: "approval", options: { requestId, ...call } })),
|
|
218
|
+
approval: wrappedOperation(
|
|
219
|
+
async (input: ApprovalInput) => child({ type: "approval", options: { ...input, ...call } }),
|
|
220
|
+
{ outcome: "ignored" },
|
|
221
|
+
onError,
|
|
222
|
+
),
|
|
223
|
+
});
|
|
203
224
|
if (data.type === "activation")
|
|
204
225
|
return live({
|
|
205
226
|
...common,
|
|
206
227
|
memory,
|
|
228
|
+
...approvals(),
|
|
207
229
|
links: (links: readonly TraceLink[]) => runtime.update({ links }),
|
|
208
230
|
findAttempt: (input: { stepIndex: number; attempt: number }) =>
|
|
209
231
|
found<AttemptOperation>(
|
|
@@ -309,22 +331,7 @@ export function operationHandle(
|
|
|
309
331
|
...common,
|
|
310
332
|
memory,
|
|
311
333
|
tool,
|
|
312
|
-
|
|
313
|
-
found<ApprovalOperation>(
|
|
314
|
-
runtime.find({
|
|
315
|
-
type: "approval",
|
|
316
|
-
options: { requestId, callId: data.options.callId, toolName: data.options.name },
|
|
317
|
-
}),
|
|
318
|
-
),
|
|
319
|
-
approval: wrappedOperation(
|
|
320
|
-
async (input: { requestId: string; request?: unknown }) =>
|
|
321
|
-
child({
|
|
322
|
-
type: "approval",
|
|
323
|
-
options: { ...input, callId: data.options.callId, toolName: data.options.name },
|
|
324
|
-
}),
|
|
325
|
-
{ outcome: "ignored" },
|
|
326
|
-
onError,
|
|
327
|
-
),
|
|
334
|
+
...approvals({ callId: data.options.callId, toolName: data.options.name }),
|
|
328
335
|
} as ToolOperation);
|
|
329
336
|
return common;
|
|
330
337
|
}
|