runwarden 0.4.0 → 0.6.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 +85 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +344 -10
- package/dist/index.js +884 -54
- package/dist/{init-Dm_qLwix.js → init-RSnueOdR.js} +15 -1
- package/migrations/0001_invocation_result_messages.sql +1 -0
- package/migrations/0002_invocation_usage.sql +7 -0
- package/migrations/0003_invocation_budget_approval.sql +2 -0
- package/migrations/meta/0001_snapshot.json +726 -0
- package/migrations/meta/0002_snapshot.json +768 -0
- package/migrations/meta/0003_snapshot.json +780 -0
- package/migrations/meta/_journal.json +21 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -210,6 +210,86 @@ policies: {
|
|
|
210
210
|
The predicate also receives `scope`. Return `true` to require approval; a
|
|
211
211
|
thrown error fails the invocation.
|
|
212
212
|
|
|
213
|
+
## Budgets
|
|
214
|
+
|
|
215
|
+
Add a per-execution budget when you want a runaway invocation to stop:
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
const runtime = defineRuntime({
|
|
219
|
+
// ...
|
|
220
|
+
policies: {
|
|
221
|
+
budget: {
|
|
222
|
+
maxCostUsd: 0.25,
|
|
223
|
+
maxTokens: 50_000,
|
|
224
|
+
onExceeded: 'approve', // or 'stop' / 'log'
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
onBudgetWarning: (warning) => {
|
|
228
|
+
console.warn('budget warning', warning);
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Budgets are checked after each completed step. This is a circuit breaker, not
|
|
234
|
+
an exact gate: the step that crosses a limit finishes, including its tool side
|
|
235
|
+
effects, and only the next model call is prevented. One call can therefore
|
|
236
|
+
overshoot the limit. A crossing on the final text step is recorded but the
|
|
237
|
+
answer is still returned.
|
|
238
|
+
|
|
239
|
+
`maxTokens` counts input, cache read, cache write, output, and reasoning
|
|
240
|
+
tokens. Known token counts are a lower bound when a provider omits usage.
|
|
241
|
+
`maxCostUsd` is enforced only when every step's cost is known and accounting is
|
|
242
|
+
complete; unknown cost is recorded as an incomplete decision and never treated
|
|
243
|
+
as zero. Set `onExceeded: 'log'` to record crossings without stopping.
|
|
244
|
+
|
|
245
|
+
Budgets emit an 80% warning and a 100% crossing decision. `onBudgetWarning` fires
|
|
246
|
+
once per limit per execution, and observer errors do not affect the invocation.
|
|
247
|
+
A `stop` outcome throws an `AgentRuntimeError` with kind `budget` and code
|
|
248
|
+
`budget_exceeded`, persists the usage accrued through the crossing step, and is
|
|
249
|
+
not retried.
|
|
250
|
+
|
|
251
|
+
### Approving a budget crossing
|
|
252
|
+
|
|
253
|
+
With `onExceeded: 'approve'`, a durable invocation parks in
|
|
254
|
+
`awaiting_approval` instead of failing. The pending record appears in
|
|
255
|
+
`listPendingApprovals(scope)` with `pendingApprovalKind: 'budget'` and a
|
|
256
|
+
`pendingBudgetRequest` holding the parked run ID (`requestId`), the crossed
|
|
257
|
+
limits, and the usage snapshot. It never reuses `pendingToolCall`.
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
const [request] = await runtime.listPendingApprovals('billing');
|
|
261
|
+
await runtime.approveInvocation(request.id, {
|
|
262
|
+
requestId: request.pendingBudgetRequest!.requestId,
|
|
263
|
+
grant: { maxTokens: 25_000 }, // additional quota, not a new limit
|
|
264
|
+
resolvedBy: 'quota-team',
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Approving requires `grant: { maxTokens?, maxCostUsd? }` and at least one
|
|
269
|
+
dimension. Grants add to the configured limit (`effective = configured +
|
|
270
|
+
accumulated grants`), only apply to dimensions that are configured, and are
|
|
271
|
+
rejected when empty, zero, negative, fractional, non-finite, or overflowing.
|
|
272
|
+
An omitted dimension is unchanged. Approving a tool park with a grant is an
|
|
273
|
+
error; a budget park must supply the `requestId` from the listing, and a stale
|
|
274
|
+
request ID leaves a newer park untouched. Grants stack across parks and ordinary
|
|
275
|
+
execution retries.
|
|
276
|
+
|
|
277
|
+
Resuming is a fresh whole-run execution with a new run ID: completed tool side
|
|
278
|
+
effects can repeat, and the invocation keeps its ordering key until it settles,
|
|
279
|
+
so later invocations with the same key stay blocked. The resumed run starts with
|
|
280
|
+
a fresh usage accumulator; the parked run's usage and request snapshot stay in
|
|
281
|
+
the `budget / approval_requested` policy decision. Invocation usage columns
|
|
282
|
+
remain a per-run snapshot that the next run overwrites.
|
|
283
|
+
|
|
284
|
+
Rejecting settles the invocation as `failed` with `budget_exceeded`, preserves
|
|
285
|
+
the park-time usage, and does not retry. If the park's audit write fails, no
|
|
286
|
+
park is published: the invocation fails closed with the crossing usage and does
|
|
287
|
+
not spend again.
|
|
288
|
+
|
|
289
|
+
`approve` needs the durable runtime because approvals live in Postgres. Direct
|
|
290
|
+
execution, including calling `runtime.engine.invoke` yourself, degrades to
|
|
291
|
+
`stop`: the caller gets `budget_exceeded` with the crossing usage and no park.
|
|
292
|
+
|
|
213
293
|
## The full quickstart (from the repo)
|
|
214
294
|
|
|
215
295
|
### Requirements
|
|
@@ -260,7 +340,9 @@ real model provider), see [examples/durable](examples/durable/README.md).
|
|
|
260
340
|
6. If a proposed call requires approval under `requireApproval`, the invocation
|
|
261
341
|
parks in `awaiting_approval` instead of failing. Your app resolves it
|
|
262
342
|
with `approveInvocation` or `rejectInvocation`. Approval reruns the
|
|
263
|
-
whole invocation; rejection cancels it.
|
|
343
|
+
whole invocation; rejection cancels it. A budget crossing with
|
|
344
|
+
`onExceeded: 'approve'` parks the same way, but approval takes a quota
|
|
345
|
+
grant and rejection fails with `budget_exceeded` instead.
|
|
264
346
|
7. When an invocation reaches a terminal state (succeeded, failed, or
|
|
265
347
|
cancelled), the optional `onInvocationSettled` callback from
|
|
266
348
|
`defineRuntime` fires with the final invocation record, so your app
|
|
@@ -296,6 +378,8 @@ erDiagram
|
|
|
296
378
|
uuid active_run_id
|
|
297
379
|
timestamptz active_run_registered_at
|
|
298
380
|
jsonb pending_tool_call
|
|
381
|
+
jsonb pending_budget_request
|
|
382
|
+
jsonb budget_grants
|
|
299
383
|
timestamptz started_at
|
|
300
384
|
timestamptz completed_at
|
|
301
385
|
timestamptz failed_at
|
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModel } from "ai";
|
|
1
|
+
import { JSONValue, LanguageModel } from "ai";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
4
|
import { Pool } from "pg";
|
|
@@ -19,8 +19,8 @@ interface McpServerConfig {
|
|
|
19
19
|
headers?: Record<string, string>;
|
|
20
20
|
tools?: string[];
|
|
21
21
|
}
|
|
22
|
-
type PolicyRule = 'exactly_one' | 'max_tool_calls' | 'allowlist' | 'require_approval' | 'input_validation' | 'correction_budget';
|
|
23
|
-
type PolicyDecisionKind = 'allow' | 'deny' | 'correction_issued' | 'approval_requested' | 'approved' | 'rejected';
|
|
22
|
+
type PolicyRule = 'exactly_one' | 'max_tool_calls' | 'allowlist' | 'require_approval' | 'input_validation' | 'correction_budget' | 'budget';
|
|
23
|
+
type PolicyDecisionKind = 'allow' | 'deny' | 'correction_issued' | 'approval_requested' | 'approved' | 'rejected' | 'warning' | 'exceeded' | 'incomplete';
|
|
24
24
|
interface PolicyDecision {
|
|
25
25
|
scope: string;
|
|
26
26
|
invocationId: string;
|
|
@@ -30,6 +30,36 @@ interface PolicyDecision {
|
|
|
30
30
|
toolName?: string;
|
|
31
31
|
detail?: Record<string, unknown>;
|
|
32
32
|
}
|
|
33
|
+
type BudgetLimitKind = 'costUsd' | 'tokens';
|
|
34
|
+
type BudgetCompleteness = 'complete' | 'lower_bound';
|
|
35
|
+
interface BudgetGrant {
|
|
36
|
+
maxCostUsd?: number;
|
|
37
|
+
maxTokens?: number;
|
|
38
|
+
}
|
|
39
|
+
interface RuntimeBudgetPolicy {
|
|
40
|
+
maxCostUsd?: number;
|
|
41
|
+
maxTokens?: number;
|
|
42
|
+
onExceeded?: 'stop' | 'log' | 'approve';
|
|
43
|
+
}
|
|
44
|
+
interface BudgetWarning {
|
|
45
|
+
scope: string;
|
|
46
|
+
invocationId: string;
|
|
47
|
+
runId: string;
|
|
48
|
+
limitKind: BudgetLimitKind;
|
|
49
|
+
accumulated: number;
|
|
50
|
+
limit: number;
|
|
51
|
+
threshold: 0.8;
|
|
52
|
+
stepNumber: number;
|
|
53
|
+
completeness: BudgetCompleteness;
|
|
54
|
+
}
|
|
55
|
+
type BudgetWarningEvent = Omit<BudgetWarning, 'scope' | 'invocationId' | 'runId'>;
|
|
56
|
+
interface BudgetExceededLimit {
|
|
57
|
+
limitKind: BudgetLimitKind;
|
|
58
|
+
accumulated: number;
|
|
59
|
+
limit: number;
|
|
60
|
+
stepNumber: number;
|
|
61
|
+
completeness: BudgetCompleteness;
|
|
62
|
+
}
|
|
33
63
|
interface RuntimePolicies {
|
|
34
64
|
exactlyOneToolCallPerStep?: boolean;
|
|
35
65
|
correctionBudget?: number;
|
|
@@ -42,12 +72,33 @@ interface RuntimePolicies {
|
|
|
42
72
|
input: unknown;
|
|
43
73
|
}) => boolean);
|
|
44
74
|
maxToolResultBytes?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Per-execution usage budget, checked after each completed step.
|
|
77
|
+
*
|
|
78
|
+
* Enforcement is a circuit breaker, not a precise gate: the step that crosses
|
|
79
|
+
* a limit completes (including its tool side effects), and only the next model
|
|
80
|
+
* call is prevented. A crossing on a final text step is recorded but still
|
|
81
|
+
* returns the answer. `maxCostUsd` is only enforceable when every step's cost
|
|
82
|
+
* is known; token limits use known token counts as a lower bound.
|
|
83
|
+
*
|
|
84
|
+
* `stop` fails the invocation with `budget_exceeded` and no retry. `log` only
|
|
85
|
+
* records crossings. `approve` parks a durable invocation in
|
|
86
|
+
* `awaiting_approval` so a human can grant additional quota; a resumed run
|
|
87
|
+
* executes again from the start (completed tool side effects can repeat) under
|
|
88
|
+
* `configured limit + accumulated grants`. Direct execution has no approval
|
|
89
|
+
* state machine and degrades `approve` to `stop`.
|
|
90
|
+
*/
|
|
91
|
+
budget?: RuntimeBudgetPolicy;
|
|
92
|
+
}
|
|
93
|
+
type AgentRuntimeErrorKind = 'timeout' | 'failure' | 'budget';
|
|
94
|
+
interface AgentRuntimeErrorOptions extends ErrorOptions {
|
|
95
|
+
usage?: InvocationUsage;
|
|
45
96
|
}
|
|
46
|
-
type AgentRuntimeErrorKind = 'timeout' | 'failure';
|
|
47
97
|
export declare class AgentRuntimeError extends Error {
|
|
48
98
|
readonly kind: AgentRuntimeErrorKind;
|
|
49
99
|
readonly diagnostics: Record<string, unknown>;
|
|
50
|
-
|
|
100
|
+
readonly usage?: InvocationUsage;
|
|
101
|
+
constructor(kind: AgentRuntimeErrorKind, message: string, diagnostics?: Record<string, unknown>, options?: AgentRuntimeErrorOptions);
|
|
51
102
|
}
|
|
52
103
|
interface InvocationInput {
|
|
53
104
|
scope: string;
|
|
@@ -60,10 +111,43 @@ interface InvocationInput {
|
|
|
60
111
|
maxAttempts?: number;
|
|
61
112
|
metadata?: Record<string, unknown>;
|
|
62
113
|
}
|
|
114
|
+
interface UsageTokenCounts {
|
|
115
|
+
inputTokens: number;
|
|
116
|
+
outputTokens: number;
|
|
117
|
+
cacheReadTokens: number;
|
|
118
|
+
cacheWriteTokens: number;
|
|
119
|
+
reasoningTokens: number;
|
|
120
|
+
}
|
|
121
|
+
interface UsageStep extends UsageTokenCounts {
|
|
122
|
+
provider?: string;
|
|
123
|
+
model: string;
|
|
124
|
+
usageKnown: boolean;
|
|
125
|
+
costUsd?: number;
|
|
126
|
+
costKnown: boolean;
|
|
127
|
+
}
|
|
128
|
+
interface InvocationUsage extends UsageTokenCounts {
|
|
129
|
+
costUsd?: number;
|
|
130
|
+
costIncomplete: boolean;
|
|
131
|
+
steps: UsageStep[];
|
|
132
|
+
}
|
|
133
|
+
interface UsagePriceOverride {
|
|
134
|
+
provider?: string;
|
|
135
|
+
model: string;
|
|
136
|
+
inputPerMillionTokens: number;
|
|
137
|
+
outputPerMillionTokens: number;
|
|
138
|
+
cacheReadPerMillionTokens?: number;
|
|
139
|
+
cacheWritePerMillionTokens?: number;
|
|
140
|
+
}
|
|
141
|
+
interface UsagePricingOptions {
|
|
142
|
+
providerId?: string;
|
|
143
|
+
overrides?: readonly UsagePriceOverride[];
|
|
144
|
+
}
|
|
63
145
|
interface InvocationResult {
|
|
64
146
|
invocationId: string;
|
|
65
147
|
runId: string;
|
|
66
148
|
text: string;
|
|
149
|
+
messages: NeutralMessage[];
|
|
150
|
+
usage: InvocationUsage;
|
|
67
151
|
provider?: string;
|
|
68
152
|
model?: string;
|
|
69
153
|
}
|
|
@@ -71,27 +155,93 @@ interface PendingToolCall {
|
|
|
71
155
|
toolName: string;
|
|
72
156
|
input: unknown;
|
|
73
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* A durable budget park. `requestId` is the parked run ID and must be supplied
|
|
160
|
+
* when the park is resolved so a stale decision cannot touch a newer park.
|
|
161
|
+
*/
|
|
162
|
+
interface BudgetRequest {
|
|
163
|
+
requestId: string;
|
|
164
|
+
limits: BudgetExceededLimit[];
|
|
165
|
+
usage: InvocationUsage;
|
|
166
|
+
}
|
|
167
|
+
type AwaitingApprovalRequest = {
|
|
168
|
+
kind: 'tool';
|
|
169
|
+
toolCall: PendingToolCall;
|
|
170
|
+
} | {
|
|
171
|
+
kind: 'budget';
|
|
172
|
+
budgetRequest: BudgetRequest;
|
|
173
|
+
};
|
|
74
174
|
type InvocationStatus = 'pending' | 'running' | 'awaiting_approval' | 'succeeded' | 'failed' | 'cancelled';
|
|
75
175
|
interface InvocationRecord extends InvocationInput {
|
|
76
176
|
id: string;
|
|
77
177
|
status: InvocationStatus;
|
|
78
178
|
attemptCount: number;
|
|
79
179
|
resultText?: string;
|
|
180
|
+
pendingApprovalKind?: 'tool' | 'budget';
|
|
80
181
|
pendingToolCall?: PendingToolCall;
|
|
182
|
+
pendingBudgetRequest?: BudgetRequest;
|
|
183
|
+
budgetGrants?: BudgetGrant;
|
|
81
184
|
lastErrorCode?: string;
|
|
82
185
|
lastErrorMessage?: string;
|
|
83
186
|
createdAt: Date;
|
|
84
187
|
completedAt?: Date;
|
|
85
188
|
}
|
|
86
189
|
type InvocationSettledListener = (invocation: InvocationRecord) => void | Promise<void>;
|
|
87
|
-
interface
|
|
88
|
-
|
|
89
|
-
|
|
190
|
+
interface NeutralTextPart {
|
|
191
|
+
type: 'text';
|
|
192
|
+
text: string;
|
|
90
193
|
}
|
|
194
|
+
interface NeutralToolCallPart {
|
|
195
|
+
type: 'tool-call';
|
|
196
|
+
toolCallId: string;
|
|
197
|
+
toolName: string;
|
|
198
|
+
input: unknown;
|
|
199
|
+
}
|
|
200
|
+
type NeutralToolResultOutput = {
|
|
201
|
+
type: 'text';
|
|
202
|
+
value: string;
|
|
203
|
+
} | {
|
|
204
|
+
type: 'json';
|
|
205
|
+
value: JSONValue;
|
|
206
|
+
} | {
|
|
207
|
+
type: 'error-text';
|
|
208
|
+
value: string;
|
|
209
|
+
} | {
|
|
210
|
+
type: 'error-json';
|
|
211
|
+
value: JSONValue;
|
|
212
|
+
} | {
|
|
213
|
+
type: 'execution-denied';
|
|
214
|
+
reason?: string;
|
|
215
|
+
};
|
|
216
|
+
interface NeutralToolResultPart {
|
|
217
|
+
type: 'tool-result';
|
|
218
|
+
toolCallId: string;
|
|
219
|
+
toolName: string;
|
|
220
|
+
output: NeutralToolResultOutput;
|
|
221
|
+
}
|
|
222
|
+
type NeutralContentPart = NeutralTextPart | NeutralToolCallPart;
|
|
223
|
+
/**
|
|
224
|
+
* A plain text message (the original shape) is still a valid NeutralMessage, so
|
|
225
|
+
* existing history loaders and callers compile and behave unchanged.
|
|
226
|
+
*/
|
|
227
|
+
type NeutralMessage = {
|
|
228
|
+
role: 'user' | 'system';
|
|
229
|
+
content: string;
|
|
230
|
+
} | {
|
|
231
|
+
role: 'assistant';
|
|
232
|
+
content: string | readonly NeutralContentPart[];
|
|
233
|
+
} | {
|
|
234
|
+
role: 'tool';
|
|
235
|
+
content: readonly NeutralToolResultPart[];
|
|
236
|
+
};
|
|
91
237
|
type RuntimeInvocationInput = InvocationInput & {
|
|
92
238
|
invocationId: string;
|
|
93
239
|
runId: string;
|
|
94
240
|
approvedToolCall?: PendingToolCall;
|
|
241
|
+
/** Accumulated quota granted through budget approvals for this invocation. */
|
|
242
|
+
budgetGrants?: BudgetGrant;
|
|
243
|
+
/** Set only on the durable execution path, where a park can be approved. */
|
|
244
|
+
budgetParkable?: boolean;
|
|
95
245
|
};
|
|
96
246
|
interface AgentRuntime {
|
|
97
247
|
invoke(input: RuntimeInvocationInput): Promise<InvocationResult>;
|
|
@@ -285,6 +435,146 @@ declare const invocations: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
285
435
|
identity: undefined;
|
|
286
436
|
generated: undefined;
|
|
287
437
|
}, {}, {}>;
|
|
438
|
+
resultMessages: import("drizzle-orm/pg-core").PgColumn<{
|
|
439
|
+
name: "result_messages";
|
|
440
|
+
tableName: "invocations";
|
|
441
|
+
dataType: "json";
|
|
442
|
+
columnType: "PgJsonb";
|
|
443
|
+
data: NeutralMessage[];
|
|
444
|
+
driverParam: unknown;
|
|
445
|
+
notNull: false;
|
|
446
|
+
hasDefault: false;
|
|
447
|
+
isPrimaryKey: false;
|
|
448
|
+
isAutoincrement: false;
|
|
449
|
+
hasRuntimeDefault: false;
|
|
450
|
+
enumValues: undefined;
|
|
451
|
+
baseColumn: never;
|
|
452
|
+
identity: undefined;
|
|
453
|
+
generated: undefined;
|
|
454
|
+
}, {}, {
|
|
455
|
+
$type: NeutralMessage[];
|
|
456
|
+
}>;
|
|
457
|
+
inputTokens: import("drizzle-orm/pg-core").PgColumn<{
|
|
458
|
+
name: "input_tokens";
|
|
459
|
+
tableName: "invocations";
|
|
460
|
+
dataType: "number";
|
|
461
|
+
columnType: "PgBigInt53";
|
|
462
|
+
data: number;
|
|
463
|
+
driverParam: string | number;
|
|
464
|
+
notNull: false;
|
|
465
|
+
hasDefault: false;
|
|
466
|
+
isPrimaryKey: false;
|
|
467
|
+
isAutoincrement: false;
|
|
468
|
+
hasRuntimeDefault: false;
|
|
469
|
+
enumValues: undefined;
|
|
470
|
+
baseColumn: never;
|
|
471
|
+
identity: undefined;
|
|
472
|
+
generated: undefined;
|
|
473
|
+
}, {}, {}>;
|
|
474
|
+
outputTokens: import("drizzle-orm/pg-core").PgColumn<{
|
|
475
|
+
name: "output_tokens";
|
|
476
|
+
tableName: "invocations";
|
|
477
|
+
dataType: "number";
|
|
478
|
+
columnType: "PgBigInt53";
|
|
479
|
+
data: number;
|
|
480
|
+
driverParam: string | number;
|
|
481
|
+
notNull: false;
|
|
482
|
+
hasDefault: false;
|
|
483
|
+
isPrimaryKey: false;
|
|
484
|
+
isAutoincrement: false;
|
|
485
|
+
hasRuntimeDefault: false;
|
|
486
|
+
enumValues: undefined;
|
|
487
|
+
baseColumn: never;
|
|
488
|
+
identity: undefined;
|
|
489
|
+
generated: undefined;
|
|
490
|
+
}, {}, {}>;
|
|
491
|
+
cacheReadTokens: import("drizzle-orm/pg-core").PgColumn<{
|
|
492
|
+
name: "cache_read_tokens";
|
|
493
|
+
tableName: "invocations";
|
|
494
|
+
dataType: "number";
|
|
495
|
+
columnType: "PgBigInt53";
|
|
496
|
+
data: number;
|
|
497
|
+
driverParam: string | number;
|
|
498
|
+
notNull: false;
|
|
499
|
+
hasDefault: false;
|
|
500
|
+
isPrimaryKey: false;
|
|
501
|
+
isAutoincrement: false;
|
|
502
|
+
hasRuntimeDefault: false;
|
|
503
|
+
enumValues: undefined;
|
|
504
|
+
baseColumn: never;
|
|
505
|
+
identity: undefined;
|
|
506
|
+
generated: undefined;
|
|
507
|
+
}, {}, {}>;
|
|
508
|
+
cacheWriteTokens: import("drizzle-orm/pg-core").PgColumn<{
|
|
509
|
+
name: "cache_write_tokens";
|
|
510
|
+
tableName: "invocations";
|
|
511
|
+
dataType: "number";
|
|
512
|
+
columnType: "PgBigInt53";
|
|
513
|
+
data: number;
|
|
514
|
+
driverParam: string | number;
|
|
515
|
+
notNull: false;
|
|
516
|
+
hasDefault: false;
|
|
517
|
+
isPrimaryKey: false;
|
|
518
|
+
isAutoincrement: false;
|
|
519
|
+
hasRuntimeDefault: false;
|
|
520
|
+
enumValues: undefined;
|
|
521
|
+
baseColumn: never;
|
|
522
|
+
identity: undefined;
|
|
523
|
+
generated: undefined;
|
|
524
|
+
}, {}, {}>;
|
|
525
|
+
reasoningTokens: import("drizzle-orm/pg-core").PgColumn<{
|
|
526
|
+
name: "reasoning_tokens";
|
|
527
|
+
tableName: "invocations";
|
|
528
|
+
dataType: "number";
|
|
529
|
+
columnType: "PgBigInt53";
|
|
530
|
+
data: number;
|
|
531
|
+
driverParam: string | number;
|
|
532
|
+
notNull: false;
|
|
533
|
+
hasDefault: false;
|
|
534
|
+
isPrimaryKey: false;
|
|
535
|
+
isAutoincrement: false;
|
|
536
|
+
hasRuntimeDefault: false;
|
|
537
|
+
enumValues: undefined;
|
|
538
|
+
baseColumn: never;
|
|
539
|
+
identity: undefined;
|
|
540
|
+
generated: undefined;
|
|
541
|
+
}, {}, {}>;
|
|
542
|
+
costUsd: import("drizzle-orm/pg-core").PgColumn<{
|
|
543
|
+
name: "cost_usd";
|
|
544
|
+
tableName: "invocations";
|
|
545
|
+
dataType: "number";
|
|
546
|
+
columnType: "PgNumericNumber";
|
|
547
|
+
data: number;
|
|
548
|
+
driverParam: string;
|
|
549
|
+
notNull: false;
|
|
550
|
+
hasDefault: false;
|
|
551
|
+
isPrimaryKey: false;
|
|
552
|
+
isAutoincrement: false;
|
|
553
|
+
hasRuntimeDefault: false;
|
|
554
|
+
enumValues: undefined;
|
|
555
|
+
baseColumn: never;
|
|
556
|
+
identity: undefined;
|
|
557
|
+
generated: undefined;
|
|
558
|
+
}, {}, {}>;
|
|
559
|
+
usageSteps: import("drizzle-orm/pg-core").PgColumn<{
|
|
560
|
+
name: "usage_steps";
|
|
561
|
+
tableName: "invocations";
|
|
562
|
+
dataType: "json";
|
|
563
|
+
columnType: "PgJsonb";
|
|
564
|
+
data: UsageStep[];
|
|
565
|
+
driverParam: unknown;
|
|
566
|
+
notNull: false;
|
|
567
|
+
hasDefault: false;
|
|
568
|
+
isPrimaryKey: false;
|
|
569
|
+
isAutoincrement: false;
|
|
570
|
+
hasRuntimeDefault: false;
|
|
571
|
+
enumValues: undefined;
|
|
572
|
+
baseColumn: never;
|
|
573
|
+
identity: undefined;
|
|
574
|
+
generated: undefined;
|
|
575
|
+
}, {}, {
|
|
576
|
+
$type: UsageStep[];
|
|
577
|
+
}>;
|
|
288
578
|
idempotencyKey: import("drizzle-orm/pg-core").PgColumn<{
|
|
289
579
|
name: "idempotency_key";
|
|
290
580
|
tableName: "invocations";
|
|
@@ -491,6 +781,44 @@ declare const invocations: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
491
781
|
identity: undefined;
|
|
492
782
|
generated: undefined;
|
|
493
783
|
}, {}, {}>;
|
|
784
|
+
pendingBudgetRequest: import("drizzle-orm/pg-core").PgColumn<{
|
|
785
|
+
name: "pending_budget_request";
|
|
786
|
+
tableName: "invocations";
|
|
787
|
+
dataType: "json";
|
|
788
|
+
columnType: "PgJsonb";
|
|
789
|
+
data: BudgetRequest;
|
|
790
|
+
driverParam: unknown;
|
|
791
|
+
notNull: false;
|
|
792
|
+
hasDefault: false;
|
|
793
|
+
isPrimaryKey: false;
|
|
794
|
+
isAutoincrement: false;
|
|
795
|
+
hasRuntimeDefault: false;
|
|
796
|
+
enumValues: undefined;
|
|
797
|
+
baseColumn: never;
|
|
798
|
+
identity: undefined;
|
|
799
|
+
generated: undefined;
|
|
800
|
+
}, {}, {
|
|
801
|
+
$type: BudgetRequest;
|
|
802
|
+
}>;
|
|
803
|
+
budgetGrants: import("drizzle-orm/pg-core").PgColumn<{
|
|
804
|
+
name: "budget_grants";
|
|
805
|
+
tableName: "invocations";
|
|
806
|
+
dataType: "json";
|
|
807
|
+
columnType: "PgJsonb";
|
|
808
|
+
data: BudgetGrant;
|
|
809
|
+
driverParam: unknown;
|
|
810
|
+
notNull: false;
|
|
811
|
+
hasDefault: false;
|
|
812
|
+
isPrimaryKey: false;
|
|
813
|
+
isAutoincrement: false;
|
|
814
|
+
hasRuntimeDefault: false;
|
|
815
|
+
enumValues: undefined;
|
|
816
|
+
baseColumn: never;
|
|
817
|
+
identity: undefined;
|
|
818
|
+
generated: undefined;
|
|
819
|
+
}, {}, {
|
|
820
|
+
$type: BudgetGrant;
|
|
821
|
+
}>;
|
|
494
822
|
startedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
495
823
|
name: "started_at";
|
|
496
824
|
tableName: "invocations";
|
|
@@ -1133,6 +1461,10 @@ export declare function createDb(connectionString: string): DatabaseHandle;
|
|
|
1133
1461
|
interface ApprovalResolutionOptions {
|
|
1134
1462
|
resolvedBy?: string;
|
|
1135
1463
|
note?: string;
|
|
1464
|
+
/** Additional quota for a budget approval. Rejected on tool approvals. */
|
|
1465
|
+
grant?: BudgetGrant;
|
|
1466
|
+
/** The parked run ID of the budget request being resolved. */
|
|
1467
|
+
requestId?: string;
|
|
1136
1468
|
}
|
|
1137
1469
|
interface OpenAiCompatibleModelConfig {
|
|
1138
1470
|
baseUrl: string;
|
|
@@ -1158,8 +1490,10 @@ interface DefineRuntimeOptions {
|
|
|
1158
1490
|
loadSystemPrompt?: SystemPromptLoader;
|
|
1159
1491
|
loadHistory?: HistoryLoader;
|
|
1160
1492
|
policies?: RuntimePolicies;
|
|
1493
|
+
pricing?: UsagePricingOptions;
|
|
1161
1494
|
onMetrics?: (metrics: RuntimeMetrics) => void;
|
|
1162
1495
|
onPolicyDecision?: (decision: PolicyDecision) => void;
|
|
1496
|
+
onBudgetWarning?: (warning: BudgetWarning) => void;
|
|
1163
1497
|
onToolCallAudit?: ToolCallAuditSink;
|
|
1164
1498
|
onInvocationSettled?: InvocationSettledListener;
|
|
1165
1499
|
generateRunId?: () => string;
|
|
@@ -1205,7 +1539,7 @@ interface RunWorkerOptions {
|
|
|
1205
1539
|
pollActiveMs?: number;
|
|
1206
1540
|
onSucceeded?: (invocation: InvocationRecord, result: InvocationResult) => Promise<void>;
|
|
1207
1541
|
onFailed?: (invocation: InvocationRecord, error: AgentRuntimeError) => Promise<void>;
|
|
1208
|
-
onAwaitingApproval?: (invocation: InvocationRecord,
|
|
1542
|
+
onAwaitingApproval?: (invocation: InvocationRecord, request: AwaitingApprovalRequest) => Promise<void>;
|
|
1209
1543
|
}
|
|
1210
1544
|
interface WorkerHandle {
|
|
1211
1545
|
stop(): Promise<void>;
|
|
@@ -1239,4 +1573,4 @@ export declare class FakeAgentRuntime implements AgentRuntime {
|
|
|
1239
1573
|
export declare const RUNTIME_NAME = "runwarden";
|
|
1240
1574
|
export declare const RUN_ID_HEADER = "X-Runwarden-Run-Id";
|
|
1241
1575
|
export declare const ERROR_CATEGORY_META_KEY = "runwarden/error-category";
|
|
1242
|
-
export type { AgentRuntime, AgentRuntimeErrorKind, ApprovalActionOptions, DatabaseHandle, DefineRuntimeOptions, HistoryLoader, InitOptions, InitResult, InvocationInput, InvocationRecord, InvocationResult, InvocationSettledListener, InvocationStatus, InvokeOptions, McpServerConfig, McpToolClient, McpToolSession, NativeMcpClientConfig, NeutralMessage, OpenAiCompatibleModelConfig, PendingToolCall, PolicyDecision, PolicyDecisionKind, PolicyRule, RunWorkerOptions, Runtime, RuntimeInvocationInput, RuntimeMetrics, RuntimePolicies, SystemPromptLoader, ToolCallAuditEvent, ToolCallAuditSink, ToolDefinition, WorkerHandle };
|
|
1576
|
+
export type { AgentRuntime, AgentRuntimeErrorKind, ApprovalActionOptions, AwaitingApprovalRequest, BudgetCompleteness, BudgetExceededLimit, BudgetGrant, BudgetLimitKind, BudgetRequest, BudgetWarning, BudgetWarningEvent, DatabaseHandle, DefineRuntimeOptions, HistoryLoader, InitOptions, InitResult, InvocationInput, InvocationRecord, InvocationResult, InvocationSettledListener, InvocationStatus, InvocationUsage, InvokeOptions, McpServerConfig, McpToolClient, McpToolSession, NativeMcpClientConfig, NeutralContentPart, NeutralMessage, NeutralTextPart, NeutralToolCallPart, NeutralToolResultOutput, NeutralToolResultPart, OpenAiCompatibleModelConfig, PendingToolCall, PolicyDecision, PolicyDecisionKind, PolicyRule, RunWorkerOptions, Runtime, RuntimeBudgetPolicy, RuntimeInvocationInput, RuntimeMetrics, RuntimePolicies, SystemPromptLoader, ToolCallAuditEvent, ToolCallAuditSink, ToolDefinition, UsagePriceOverride, UsagePricingOptions, UsageStep, UsageTokenCounts, WorkerHandle };
|