runwarden 0.3.0 → 0.5.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 CHANGED
@@ -196,6 +196,20 @@ a tool behind human approval, add
196
196
  [full quickstart](examples/quickstart/README.md) walks through that flow
197
197
  end to end.
198
198
 
199
+ For input-dependent approval, provide a synchronous predicate instead:
200
+
201
+ ```ts
202
+ policies: {
203
+ requireApproval: ({ toolName, input }) =>
204
+ toolName === 'billing__refund' &&
205
+ typeof input === 'object' && input !== null &&
206
+ 'amount' in input && typeof input.amount === 'number' && input.amount > 50,
207
+ }
208
+ ```
209
+
210
+ The predicate also receives `scope`. Return `true` to require approval; a
211
+ thrown error fails the invocation.
212
+
199
213
  ## The full quickstart (from the repo)
200
214
 
201
215
  ### Requirements
@@ -243,7 +257,7 @@ real model provider), see [examples/durable](examples/durable/README.md).
243
257
  5. Every ruling lands in `policy_decisions`, a call's latest dispatch state
244
258
  lands in `tool_call_audits`, and invocation state lands in `invocations`.
245
259
  Tool audits are latest-state records, not a history of every attempt.
246
- 6. If a proposed call is listed in `requireApproval`, the invocation
260
+ 6. If a proposed call requires approval under `requireApproval`, the invocation
247
261
  parks in `awaiting_approval` instead of failing. Your app resolves it
248
262
  with `approveInvocation` or `rejectInvocation`. Approval reruns the
249
263
  whole invocation; rejection cancels it.
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as createDb, t as initDb } from "./init-Dm_qLwix.js";
2
+ import { n as createDb, t as initDb } from "./init-BO3OjyhV.js";
3
3
  // src/cli.ts
4
4
  const [command] = process.argv.slice(2);
5
5
  if (command !== "init") {
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";
@@ -36,7 +36,11 @@ interface RuntimePolicies {
36
36
  maxToolCallsPerInvocation?: number;
37
37
  maxDurationMs?: number;
38
38
  toolAllowlist?: string[] | ((scope: string) => string[] | undefined);
39
- requireApproval?: string[];
39
+ requireApproval?: string[] | ((call: {
40
+ scope: string;
41
+ toolName: string;
42
+ input: unknown;
43
+ }) => boolean);
40
44
  maxToolResultBytes?: number;
41
45
  }
42
46
  type AgentRuntimeErrorKind = 'timeout' | 'failure';
@@ -60,6 +64,7 @@ interface InvocationResult {
60
64
  invocationId: string;
61
65
  runId: string;
62
66
  text: string;
67
+ messages: NeutralMessage[];
63
68
  provider?: string;
64
69
  model?: string;
65
70
  }
@@ -80,10 +85,53 @@ interface InvocationRecord extends InvocationInput {
80
85
  completedAt?: Date;
81
86
  }
82
87
  type InvocationSettledListener = (invocation: InvocationRecord) => void | Promise<void>;
83
- interface NeutralMessage {
84
- role: 'user' | 'assistant' | 'system';
85
- content: string;
88
+ interface NeutralTextPart {
89
+ type: 'text';
90
+ text: string;
86
91
  }
92
+ interface NeutralToolCallPart {
93
+ type: 'tool-call';
94
+ toolCallId: string;
95
+ toolName: string;
96
+ input: unknown;
97
+ }
98
+ type NeutralToolResultOutput = {
99
+ type: 'text';
100
+ value: string;
101
+ } | {
102
+ type: 'json';
103
+ value: JSONValue;
104
+ } | {
105
+ type: 'error-text';
106
+ value: string;
107
+ } | {
108
+ type: 'error-json';
109
+ value: JSONValue;
110
+ } | {
111
+ type: 'execution-denied';
112
+ reason?: string;
113
+ };
114
+ interface NeutralToolResultPart {
115
+ type: 'tool-result';
116
+ toolCallId: string;
117
+ toolName: string;
118
+ output: NeutralToolResultOutput;
119
+ }
120
+ type NeutralContentPart = NeutralTextPart | NeutralToolCallPart;
121
+ /**
122
+ * A plain text message (the original shape) is still a valid NeutralMessage, so
123
+ * existing history loaders and callers compile and behave unchanged.
124
+ */
125
+ type NeutralMessage = {
126
+ role: 'user' | 'system';
127
+ content: string;
128
+ } | {
129
+ role: 'assistant';
130
+ content: string | readonly NeutralContentPart[];
131
+ } | {
132
+ role: 'tool';
133
+ content: readonly NeutralToolResultPart[];
134
+ };
87
135
  type RuntimeInvocationInput = InvocationInput & {
88
136
  invocationId: string;
89
137
  runId: string;
@@ -281,6 +329,25 @@ declare const invocations: import("drizzle-orm/pg-core").PgTableWithColumns<{
281
329
  identity: undefined;
282
330
  generated: undefined;
283
331
  }, {}, {}>;
332
+ resultMessages: import("drizzle-orm/pg-core").PgColumn<{
333
+ name: "result_messages";
334
+ tableName: "invocations";
335
+ dataType: "json";
336
+ columnType: "PgJsonb";
337
+ data: NeutralMessage[];
338
+ driverParam: unknown;
339
+ notNull: false;
340
+ hasDefault: false;
341
+ isPrimaryKey: false;
342
+ isAutoincrement: false;
343
+ hasRuntimeDefault: false;
344
+ enumValues: undefined;
345
+ baseColumn: never;
346
+ identity: undefined;
347
+ generated: undefined;
348
+ }, {}, {
349
+ $type: NeutralMessage[];
350
+ }>;
284
351
  idempotencyKey: import("drizzle-orm/pg-core").PgColumn<{
285
352
  name: "idempotency_key";
286
353
  tableName: "invocations";
@@ -1235,4 +1302,4 @@ export declare class FakeAgentRuntime implements AgentRuntime {
1235
1302
  export declare const RUNTIME_NAME = "runwarden";
1236
1303
  export declare const RUN_ID_HEADER = "X-Runwarden-Run-Id";
1237
1304
  export declare const ERROR_CATEGORY_META_KEY = "runwarden/error-category";
1238
- 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 };
1305
+ export type { AgentRuntime, AgentRuntimeErrorKind, ApprovalActionOptions, DatabaseHandle, DefineRuntimeOptions, HistoryLoader, InitOptions, InitResult, InvocationInput, InvocationRecord, InvocationResult, InvocationSettledListener, InvocationStatus, InvokeOptions, McpServerConfig, McpToolClient, McpToolSession, NativeMcpClientConfig, NeutralContentPart, NeutralMessage, NeutralTextPart, NeutralToolCallPart, NeutralToolResultOutput, NeutralToolResultPart, OpenAiCompatibleModelConfig, PendingToolCall, PolicyDecision, PolicyDecisionKind, PolicyRule, RunWorkerOptions, Runtime, RuntimeInvocationInput, RuntimeMetrics, RuntimePolicies, SystemPromptLoader, ToolCallAuditEvent, ToolCallAuditSink, ToolDefinition, WorkerHandle };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as createDb, r as policyDecisions, t as initDb } from "./init-Dm_qLwix.js";
1
+ import { n as createDb, r as policyDecisions, t as initDb } from "./init-BO3OjyhV.js";
2
2
  import { createHash, randomUUID } from "node:crypto";
3
3
  import { sql } from "drizzle-orm";
4
4
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
@@ -27,6 +27,7 @@ function mapRow(raw) {
27
27
  orderingKey: raw.ordering_key ?? null,
28
28
  input: raw.input,
29
29
  resultText: raw.result_text ?? null,
30
+ resultMessages: raw.result_messages ?? null,
30
31
  idempotencyKey: raw.idempotency_key ?? null,
31
32
  status: raw.status,
32
33
  attemptCount: Number(raw.attempt_count),
@@ -203,6 +204,7 @@ async function markInvocationSucceeded(db, id, workerId, runId, result) {
203
204
  update agent_runtime.invocations
204
205
  set status = 'succeeded',
205
206
  result_text = ${result.resultText},
207
+ result_messages = ${result.resultMessages ? JSON.stringify(result.resultMessages) : null}::jsonb,
206
208
  provider = ${result.provider ?? null},
207
209
  model = ${result.model ?? null},
208
210
  pending_tool_call = null,
@@ -468,7 +470,7 @@ var PolicyEngine = class {
468
470
  reason: "The correction must call the same tool with corrected arguments."
469
471
  };
470
472
  }
471
- const requiresApproval = this.policies.requireApproval?.includes(input.toolName);
473
+ const requiresApproval = this.isApprovalRequired(input.scope, input.toolName, input.toolInput);
472
474
  const matchesApproval = this.approvedToolCall !== void 0 && isSameToolCall(this.approvedToolCall, input.toolName, input.toolInput);
473
475
  if (requiresApproval && !matchesApproval) {
474
476
  this.pendingApproval ??= {
@@ -519,6 +521,17 @@ var PolicyEngine = class {
519
521
  afterStep(toolCalls) {
520
522
  if (this.terminal) return;
521
523
  if (this.pendingCorrection) {
524
+ if (toolCalls.length === 0) {
525
+ if (this.pendingCorrection.correctionsUsed >= this.correctionBudget) this.exhaustCorrection(toolCalls);
526
+ else {
527
+ this.pendingCorrection.correctionsUsed += 1;
528
+ this.record({
529
+ rule: this.pendingCorrection.kind === "multi-call" ? "exactly_one" : "input_validation",
530
+ decision: "correction_issued"
531
+ });
532
+ }
533
+ return;
534
+ }
522
535
  const only = toolCalls.length === 1 ? toolCalls[0] : void 0;
523
536
  if (only && !only.invalid) {
524
537
  this.pendingCorrection = void 0;
@@ -592,6 +605,14 @@ var PolicyEngine = class {
592
605
  });
593
606
  this.terminal = new AgentRuntimeError("failure", toolCalls.length === 0 ? "Provider did not return a corrected tool call" : toolCalls.length > 1 ? "Provider returned multiple tool calls" : "Provider returned invalid tool input", toolCalls.length > 1 ? { code: "multiple_tool_calls" } : void 0);
594
607
  }
608
+ isApprovalRequired(scope, toolName, input) {
609
+ const policy = this.policies.requireApproval;
610
+ return typeof policy === "function" ? policy({
611
+ scope,
612
+ toolName,
613
+ input
614
+ }) : policy?.includes(toolName) ?? false;
615
+ }
595
616
  record(decision) {
596
617
  try {
597
618
  this.hooks.onDecision?.(decision);
@@ -658,15 +679,120 @@ function dropBlankOptionalStringArguments(rawArguments, inputShape) {
658
679
  }
659
680
  return normalized;
660
681
  }
661
- function modelMessages(history, input) {
662
- return [...history.map((message) => ({
663
- role: message.role,
664
- content: message.content
665
- })), {
682
+ const DEFAULT_MAX_TOOL_RESULT_BYTES = 32768;
683
+ function toolResultOutputBytes(output) {
684
+ switch (output.type) {
685
+ case "text":
686
+ case "error-text": return Buffer.byteLength(output.value, "utf8");
687
+ case "json":
688
+ case "error-json": return Buffer.byteLength(JSON.stringify(output.value) ?? "", "utf8");
689
+ case "execution-denied": return Buffer.byteLength(output.reason ?? "", "utf8");
690
+ }
691
+ }
692
+ function toModelToolResultPart(part, maxToolResultBytes) {
693
+ if (toolResultOutputBytes(part.output) > maxToolResultBytes) throw new AgentRuntimeError("failure", "MCP tool result exceeded limit");
694
+ return {
695
+ type: "tool-result",
696
+ toolCallId: part.toolCallId,
697
+ toolName: part.toolName,
698
+ output: part.output
699
+ };
700
+ }
701
+ function toModelContentPart(part) {
702
+ switch (part.type) {
703
+ case "text": return {
704
+ type: "text",
705
+ text: part.text
706
+ };
707
+ case "tool-call": return {
708
+ type: "tool-call",
709
+ toolCallId: part.toolCallId,
710
+ toolName: part.toolName,
711
+ input: part.input
712
+ };
713
+ }
714
+ }
715
+ function toModelMessage(message, maxToolResultBytes) {
716
+ switch (message.role) {
717
+ case "user":
718
+ case "system": return {
719
+ role: message.role,
720
+ content: message.content
721
+ };
722
+ case "assistant": return {
723
+ role: "assistant",
724
+ content: typeof message.content === "string" ? message.content : message.content.map((part) => toModelContentPart(part))
725
+ };
726
+ case "tool": return {
727
+ role: "tool",
728
+ content: message.content.map((part) => toModelToolResultPart(part, maxToolResultBytes))
729
+ };
730
+ }
731
+ }
732
+ function modelMessages(history, input, maxToolResultBytes = DEFAULT_MAX_TOOL_RESULT_BYTES) {
733
+ return [...history.map((message) => toModelMessage(message, maxToolResultBytes)), {
666
734
  role: "user",
667
735
  content: input.prompt
668
736
  }];
669
737
  }
738
+ function toNeutralToolResultOutput(output) {
739
+ if (output.type === "content") return {
740
+ type: "text",
741
+ value: output.value.filter((part) => part.type === "text").map((part) => part.text).join("")
742
+ };
743
+ return output;
744
+ }
745
+ function toNeutralToolResultPart(part) {
746
+ return {
747
+ type: "tool-result",
748
+ toolCallId: part.toolCallId,
749
+ toolName: part.toolName,
750
+ output: toNeutralToolResultOutput(part.output)
751
+ };
752
+ }
753
+ function toNeutralContentPart(part) {
754
+ switch (part.type) {
755
+ case "text": return {
756
+ type: "text",
757
+ text: part.text
758
+ };
759
+ case "tool-call": return {
760
+ type: "tool-call",
761
+ toolCallId: part.toolCallId,
762
+ toolName: part.toolName,
763
+ input: part.input
764
+ };
765
+ default: return;
766
+ }
767
+ }
768
+ function toNeutralToolContentPart(part) {
769
+ return part.type === "tool-result" ? toNeutralToolResultPart(part) : void 0;
770
+ }
771
+ function toNeutralMessage(message) {
772
+ switch (message.role) {
773
+ case "assistant": {
774
+ if (typeof message.content === "string") return message.content.length > 0 ? {
775
+ role: "assistant",
776
+ content: message.content
777
+ } : void 0;
778
+ const parts = message.content.map(toNeutralContentPart).filter((part) => part !== void 0);
779
+ return parts.length > 0 ? {
780
+ role: "assistant",
781
+ content: parts
782
+ } : void 0;
783
+ }
784
+ case "tool": {
785
+ const parts = message.content.map(toNeutralToolContentPart).filter((part) => part !== void 0);
786
+ return parts.length > 0 ? {
787
+ role: "tool",
788
+ content: parts
789
+ } : void 0;
790
+ }
791
+ }
792
+ }
793
+ function producedNeutralMessages(messages) {
794
+ return messages.map(toNeutralMessage).filter((message) => message !== void 0);
795
+ }
670
796
  var AiSdkNativeRuntime = class {
671
797
  options;
672
798
  now;
@@ -696,6 +822,7 @@ var AiSdkNativeRuntime = class {
696
822
  correctionForInvalidCall: (call) => this.correctionFor(call),
697
823
  approvedToolCall: input.approvedToolCall
698
824
  });
825
+ let approvalError;
699
826
  try {
700
827
  const systemPrompt = this.options.loadSystemPrompt ? await this.options.loadSystemPrompt(input) : "";
701
828
  const contextLoadedAt = this.now();
@@ -703,7 +830,7 @@ var AiSdkNativeRuntime = class {
703
830
  const historyLoadedAt = this.now();
704
831
  const baseInstructions = [systemPrompt, this.options.policies?.exactlyOneToolCallPerStep ?? true ? TOOL_EXECUTION_CONTRACT : ""].filter((part) => part.length > 0).join("\n\n");
705
832
  const tools = this.createTools(input, startedAt, state, policy);
706
- const result = await new ToolLoopAgent({
833
+ const agent = new ToolLoopAgent({
707
834
  model: this.options.model,
708
835
  tools,
709
836
  instructions: baseInstructions,
@@ -716,21 +843,39 @@ var AiSdkNativeRuntime = class {
716
843
  onLanguageModelCallEnd: (event) => {
717
844
  state.currentProposalCount = event.content.filter((part) => part.type === "tool-call").length;
718
845
  },
719
- toolApproval: ({ toolCall }) => policy.approvalFor({
720
- toolName: toolCall.toolName,
721
- toolCallId: toolCall.toolCallId,
722
- toolInput: toolCall.input,
723
- proposalCount: state.currentProposalCount,
724
- scope: input.scope
725
- }),
846
+ toolApproval: ({ toolCall }) => {
847
+ try {
848
+ return policy.approvalFor({
849
+ toolName: toolCall.toolName,
850
+ toolCallId: toolCall.toolCallId,
851
+ toolInput: toolCall.input,
852
+ proposalCount: state.currentProposalCount,
853
+ scope: input.scope
854
+ });
855
+ } catch (error) {
856
+ approvalError = { error };
857
+ throw error;
858
+ }
859
+ },
726
860
  onStepEnd: (step) => {
727
861
  policy.afterStep(step.toolCalls);
728
862
  },
729
863
  stopWhen: () => policy.terminalError != null
730
- }).generate({
731
- messages: modelMessages(history, input),
864
+ });
865
+ const messages = modelMessages(history, input, this.options.policies?.maxToolResultBytes);
866
+ let result = await agent.generate({
867
+ messages,
732
868
  timeout: this.remaining(startedAt)
733
869
  });
870
+ const steps = [...result.steps];
871
+ while (!policy.terminalError && policy.correctionInstruction()) {
872
+ messages.push(...result.response.messages);
873
+ result = await agent.generate({
874
+ messages,
875
+ timeout: this.remaining(startedAt)
876
+ });
877
+ steps.push(...result.steps);
878
+ }
734
879
  if (policy.terminalError) throw policy.terminalError;
735
880
  const text = result.text.trim();
736
881
  const provider = normalizeProviderName(result.finalStep.model.provider);
@@ -745,17 +890,22 @@ var AiSdkNativeRuntime = class {
745
890
  contextLoadMs: contextLoadedAt - startedAt,
746
891
  historyLoadMs: historyLoadedAt - contextLoadedAt,
747
892
  toolCallCount: state.toolCallCount,
748
- ...aggregateStepTimings(result.steps),
893
+ ...aggregateStepTimings(steps),
749
894
  totalMs: completedAt - startedAt
750
895
  });
751
896
  return {
752
897
  invocationId: input.invocationId,
753
898
  runId: input.runId,
754
899
  text,
900
+ messages: [{
901
+ role: "user",
902
+ content: input.prompt
903
+ }, ...steps.flatMap((step) => producedNeutralMessages(step.response.messages))],
755
904
  provider,
756
905
  model
757
906
  };
758
907
  } catch (error) {
908
+ if (approvalError) throw approvalError.error;
759
909
  const runtimeError = findAgentRuntimeError(error);
760
910
  if (runtimeError) throw runtimeError;
761
911
  if (isTimeoutFailure(error)) throw new AgentRuntimeError("timeout", "Native runtime timed out");
@@ -1006,6 +1156,7 @@ function defineRuntime(options) {
1006
1156
  invocationId,
1007
1157
  runId: row.activeRunId,
1008
1158
  text: row.resultText ?? "",
1159
+ messages: row.resultMessages ?? [],
1009
1160
  provider: row.provider ?? void 0,
1010
1161
  model: row.model ?? void 0
1011
1162
  };
@@ -1245,6 +1396,7 @@ function runWorker(options) {
1245
1396
  if (lease.isLost) return;
1246
1397
  if (await markInvocationSucceeded(db, row.id, workerId, row.activeRunId, {
1247
1398
  resultText: result.text,
1399
+ resultMessages: result.messages,
1248
1400
  provider: result.provider,
1249
1401
  model: result.model
1250
1402
  })) {
@@ -1338,10 +1490,19 @@ var FakeAgentRuntime = class {
1338
1490
  async invoke(input) {
1339
1491
  const invocationIndex = this.invocations.push(input);
1340
1492
  if (typeof this.result === "function") return this.result(input, invocationIndex);
1341
- return this.result ?? {
1493
+ if (this.result) return this.result;
1494
+ const text = `Fake runtime response to: ${input.prompt}`;
1495
+ return {
1342
1496
  invocationId: input.invocationId,
1343
1497
  runId: input.runId,
1344
- text: `Fake runtime response to: ${input.prompt}`,
1498
+ text,
1499
+ messages: [{
1500
+ role: "user",
1501
+ content: input.prompt
1502
+ }, {
1503
+ role: "assistant",
1504
+ content: text
1505
+ }],
1345
1506
  provider: "fake",
1346
1507
  model: "fake-agent-runtime"
1347
1508
  };
@@ -49,6 +49,7 @@ const invocations = runtimeSchema.table("invocations", {
49
49
  orderingKey: text("ordering_key"),
50
50
  input: jsonb("input").$type().notNull(),
51
51
  resultText: text("result_text"),
52
+ resultMessages: jsonb("result_messages").$type(),
52
53
  idempotencyKey: text("idempotency_key"),
53
54
  status: invocationStatusEnum("status").notNull().default("pending").$type(),
54
55
  attemptCount: integer("attempt_count").notNull().default(0),
@@ -0,0 +1 @@
1
+ ALTER TABLE "agent_runtime"."invocations" ADD COLUMN "result_messages" jsonb;
@@ -0,0 +1,726 @@
1
+ {
2
+ "id": "0f20ea46-9458-48db-9e27-176f7f13e19d",
3
+ "prevId": "ccda8d23-bb0e-4828-8930-dbe70db5ab2d",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "agent_runtime.invocations": {
8
+ "name": "invocations",
9
+ "schema": "agent_runtime",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "bigint",
14
+ "primaryKey": true,
15
+ "notNull": true,
16
+ "identity": {
17
+ "type": "always",
18
+ "name": "invocations_id_seq",
19
+ "schema": "agent_runtime",
20
+ "increment": "1",
21
+ "startWith": "1",
22
+ "minValue": "1",
23
+ "maxValue": "9223372036854775807",
24
+ "cache": "1",
25
+ "cycle": false
26
+ }
27
+ },
28
+ "scope": {
29
+ "name": "scope",
30
+ "type": "text",
31
+ "primaryKey": false,
32
+ "notNull": true
33
+ },
34
+ "conversation_id": {
35
+ "name": "conversation_id",
36
+ "type": "text",
37
+ "primaryKey": false,
38
+ "notNull": false
39
+ },
40
+ "ordering_key": {
41
+ "name": "ordering_key",
42
+ "type": "text",
43
+ "primaryKey": false,
44
+ "notNull": false
45
+ },
46
+ "input": {
47
+ "name": "input",
48
+ "type": "jsonb",
49
+ "primaryKey": false,
50
+ "notNull": true
51
+ },
52
+ "result_text": {
53
+ "name": "result_text",
54
+ "type": "text",
55
+ "primaryKey": false,
56
+ "notNull": false
57
+ },
58
+ "result_messages": {
59
+ "name": "result_messages",
60
+ "type": "jsonb",
61
+ "primaryKey": false,
62
+ "notNull": false
63
+ },
64
+ "idempotency_key": {
65
+ "name": "idempotency_key",
66
+ "type": "text",
67
+ "primaryKey": false,
68
+ "notNull": false
69
+ },
70
+ "status": {
71
+ "name": "status",
72
+ "type": "invocation_status",
73
+ "typeSchema": "agent_runtime",
74
+ "primaryKey": false,
75
+ "notNull": true,
76
+ "default": "'pending'"
77
+ },
78
+ "attempt_count": {
79
+ "name": "attempt_count",
80
+ "type": "integer",
81
+ "primaryKey": false,
82
+ "notNull": true,
83
+ "default": 0
84
+ },
85
+ "max_attempts": {
86
+ "name": "max_attempts",
87
+ "type": "integer",
88
+ "primaryKey": false,
89
+ "notNull": true,
90
+ "default": 3
91
+ },
92
+ "next_attempt_at": {
93
+ "name": "next_attempt_at",
94
+ "type": "timestamp with time zone",
95
+ "primaryKey": false,
96
+ "notNull": true,
97
+ "default": "now()"
98
+ },
99
+ "claimed_at": {
100
+ "name": "claimed_at",
101
+ "type": "timestamp with time zone",
102
+ "primaryKey": false,
103
+ "notNull": false
104
+ },
105
+ "claimed_by": {
106
+ "name": "claimed_by",
107
+ "type": "text",
108
+ "primaryKey": false,
109
+ "notNull": false
110
+ },
111
+ "lease_heartbeat_at": {
112
+ "name": "lease_heartbeat_at",
113
+ "type": "timestamp with time zone",
114
+ "primaryKey": false,
115
+ "notNull": false
116
+ },
117
+ "lease_expires_at": {
118
+ "name": "lease_expires_at",
119
+ "type": "timestamp with time zone",
120
+ "primaryKey": false,
121
+ "notNull": false
122
+ },
123
+ "active_run_id": {
124
+ "name": "active_run_id",
125
+ "type": "uuid",
126
+ "primaryKey": false,
127
+ "notNull": false
128
+ },
129
+ "active_run_registered_at": {
130
+ "name": "active_run_registered_at",
131
+ "type": "timestamp with time zone",
132
+ "primaryKey": false,
133
+ "notNull": false
134
+ },
135
+ "pending_tool_call": {
136
+ "name": "pending_tool_call",
137
+ "type": "jsonb",
138
+ "primaryKey": false,
139
+ "notNull": false
140
+ },
141
+ "started_at": {
142
+ "name": "started_at",
143
+ "type": "timestamp with time zone",
144
+ "primaryKey": false,
145
+ "notNull": false
146
+ },
147
+ "completed_at": {
148
+ "name": "completed_at",
149
+ "type": "timestamp with time zone",
150
+ "primaryKey": false,
151
+ "notNull": false
152
+ },
153
+ "failed_at": {
154
+ "name": "failed_at",
155
+ "type": "timestamp with time zone",
156
+ "primaryKey": false,
157
+ "notNull": false
158
+ },
159
+ "provider": {
160
+ "name": "provider",
161
+ "type": "text",
162
+ "primaryKey": false,
163
+ "notNull": false
164
+ },
165
+ "model": {
166
+ "name": "model",
167
+ "type": "text",
168
+ "primaryKey": false,
169
+ "notNull": false
170
+ },
171
+ "last_error_code": {
172
+ "name": "last_error_code",
173
+ "type": "text",
174
+ "primaryKey": false,
175
+ "notNull": false
176
+ },
177
+ "last_error_message": {
178
+ "name": "last_error_message",
179
+ "type": "text",
180
+ "primaryKey": false,
181
+ "notNull": false
182
+ },
183
+ "metadata": {
184
+ "name": "metadata",
185
+ "type": "jsonb",
186
+ "primaryKey": false,
187
+ "notNull": false
188
+ },
189
+ "created_at": {
190
+ "name": "created_at",
191
+ "type": "timestamp with time zone",
192
+ "primaryKey": false,
193
+ "notNull": true,
194
+ "default": "now()"
195
+ },
196
+ "updated_at": {
197
+ "name": "updated_at",
198
+ "type": "timestamp with time zone",
199
+ "primaryKey": false,
200
+ "notNull": true,
201
+ "default": "now()"
202
+ }
203
+ },
204
+ "indexes": {
205
+ "invocations_scope_idempotency_key_unique": {
206
+ "name": "invocations_scope_idempotency_key_unique",
207
+ "columns": [
208
+ {
209
+ "expression": "scope",
210
+ "isExpression": false,
211
+ "asc": true,
212
+ "nulls": "last"
213
+ },
214
+ {
215
+ "expression": "idempotency_key",
216
+ "isExpression": false,
217
+ "asc": true,
218
+ "nulls": "last"
219
+ }
220
+ ],
221
+ "isUnique": true,
222
+ "where": "\"agent_runtime\".\"invocations\".\"idempotency_key\" is not null",
223
+ "concurrently": false,
224
+ "method": "btree",
225
+ "with": {}
226
+ },
227
+ "invocations_active_run_id_unique": {
228
+ "name": "invocations_active_run_id_unique",
229
+ "columns": [
230
+ {
231
+ "expression": "active_run_id",
232
+ "isExpression": false,
233
+ "asc": true,
234
+ "nulls": "last"
235
+ }
236
+ ],
237
+ "isUnique": true,
238
+ "where": "\"agent_runtime\".\"invocations\".\"active_run_id\" is not null",
239
+ "concurrently": false,
240
+ "method": "btree",
241
+ "with": {}
242
+ },
243
+ "invocations_status_next_attempt_idx": {
244
+ "name": "invocations_status_next_attempt_idx",
245
+ "columns": [
246
+ {
247
+ "expression": "status",
248
+ "isExpression": false,
249
+ "asc": true,
250
+ "nulls": "last"
251
+ },
252
+ {
253
+ "expression": "next_attempt_at",
254
+ "isExpression": false,
255
+ "asc": true,
256
+ "nulls": "last"
257
+ }
258
+ ],
259
+ "isUnique": false,
260
+ "concurrently": false,
261
+ "method": "btree",
262
+ "with": {}
263
+ },
264
+ "invocations_status_lease_expires_idx": {
265
+ "name": "invocations_status_lease_expires_idx",
266
+ "columns": [
267
+ {
268
+ "expression": "status",
269
+ "isExpression": false,
270
+ "asc": true,
271
+ "nulls": "last"
272
+ },
273
+ {
274
+ "expression": "lease_expires_at",
275
+ "isExpression": false,
276
+ "asc": true,
277
+ "nulls": "last"
278
+ }
279
+ ],
280
+ "isUnique": false,
281
+ "concurrently": false,
282
+ "method": "btree",
283
+ "with": {}
284
+ },
285
+ "invocations_scope_status_next_attempt_idx": {
286
+ "name": "invocations_scope_status_next_attempt_idx",
287
+ "columns": [
288
+ {
289
+ "expression": "scope",
290
+ "isExpression": false,
291
+ "asc": true,
292
+ "nulls": "last"
293
+ },
294
+ {
295
+ "expression": "status",
296
+ "isExpression": false,
297
+ "asc": true,
298
+ "nulls": "last"
299
+ },
300
+ {
301
+ "expression": "next_attempt_at",
302
+ "isExpression": false,
303
+ "asc": true,
304
+ "nulls": "last"
305
+ }
306
+ ],
307
+ "isUnique": false,
308
+ "concurrently": false,
309
+ "method": "btree",
310
+ "with": {}
311
+ },
312
+ "invocations_scope_created_idx": {
313
+ "name": "invocations_scope_created_idx",
314
+ "columns": [
315
+ {
316
+ "expression": "scope",
317
+ "isExpression": false,
318
+ "asc": true,
319
+ "nulls": "last"
320
+ },
321
+ {
322
+ "expression": "created_at",
323
+ "isExpression": false,
324
+ "asc": true,
325
+ "nulls": "last"
326
+ }
327
+ ],
328
+ "isUnique": false,
329
+ "concurrently": false,
330
+ "method": "btree",
331
+ "with": {}
332
+ }
333
+ },
334
+ "foreignKeys": {},
335
+ "compositePrimaryKeys": {},
336
+ "uniqueConstraints": {},
337
+ "policies": {},
338
+ "checkConstraints": {},
339
+ "isRLSEnabled": false
340
+ },
341
+ "agent_runtime.policy_decisions": {
342
+ "name": "policy_decisions",
343
+ "schema": "agent_runtime",
344
+ "columns": {
345
+ "id": {
346
+ "name": "id",
347
+ "type": "bigint",
348
+ "primaryKey": true,
349
+ "notNull": true,
350
+ "identity": {
351
+ "type": "always",
352
+ "name": "policy_decisions_id_seq",
353
+ "schema": "agent_runtime",
354
+ "increment": "1",
355
+ "startWith": "1",
356
+ "minValue": "1",
357
+ "maxValue": "9223372036854775807",
358
+ "cache": "1",
359
+ "cycle": false
360
+ }
361
+ },
362
+ "scope": {
363
+ "name": "scope",
364
+ "type": "text",
365
+ "primaryKey": false,
366
+ "notNull": true
367
+ },
368
+ "invocation_id": {
369
+ "name": "invocation_id",
370
+ "type": "bigint",
371
+ "primaryKey": false,
372
+ "notNull": true
373
+ },
374
+ "run_id": {
375
+ "name": "run_id",
376
+ "type": "uuid",
377
+ "primaryKey": false,
378
+ "notNull": true
379
+ },
380
+ "tool_name": {
381
+ "name": "tool_name",
382
+ "type": "text",
383
+ "primaryKey": false,
384
+ "notNull": false
385
+ },
386
+ "rule": {
387
+ "name": "rule",
388
+ "type": "text",
389
+ "primaryKey": false,
390
+ "notNull": true
391
+ },
392
+ "decision": {
393
+ "name": "decision",
394
+ "type": "text",
395
+ "primaryKey": false,
396
+ "notNull": true
397
+ },
398
+ "detail": {
399
+ "name": "detail",
400
+ "type": "jsonb",
401
+ "primaryKey": false,
402
+ "notNull": false
403
+ },
404
+ "created_at": {
405
+ "name": "created_at",
406
+ "type": "timestamp with time zone",
407
+ "primaryKey": false,
408
+ "notNull": true,
409
+ "default": "now()"
410
+ }
411
+ },
412
+ "indexes": {
413
+ "policy_decisions_invocation_idx": {
414
+ "name": "policy_decisions_invocation_idx",
415
+ "columns": [
416
+ {
417
+ "expression": "invocation_id",
418
+ "isExpression": false,
419
+ "asc": true,
420
+ "nulls": "last"
421
+ }
422
+ ],
423
+ "isUnique": false,
424
+ "concurrently": false,
425
+ "method": "btree",
426
+ "with": {}
427
+ },
428
+ "policy_decisions_run_idx": {
429
+ "name": "policy_decisions_run_idx",
430
+ "columns": [
431
+ {
432
+ "expression": "run_id",
433
+ "isExpression": false,
434
+ "asc": true,
435
+ "nulls": "last"
436
+ }
437
+ ],
438
+ "isUnique": false,
439
+ "concurrently": false,
440
+ "method": "btree",
441
+ "with": {}
442
+ }
443
+ },
444
+ "foreignKeys": {
445
+ "policy_decisions_invocation_id_invocations_id_fk": {
446
+ "name": "policy_decisions_invocation_id_invocations_id_fk",
447
+ "tableFrom": "policy_decisions",
448
+ "tableTo": "invocations",
449
+ "schemaTo": "agent_runtime",
450
+ "columnsFrom": [
451
+ "invocation_id"
452
+ ],
453
+ "columnsTo": [
454
+ "id"
455
+ ],
456
+ "onDelete": "no action",
457
+ "onUpdate": "no action"
458
+ }
459
+ },
460
+ "compositePrimaryKeys": {},
461
+ "uniqueConstraints": {},
462
+ "policies": {},
463
+ "checkConstraints": {},
464
+ "isRLSEnabled": false
465
+ },
466
+ "agent_runtime.tool_call_audits": {
467
+ "name": "tool_call_audits",
468
+ "schema": "agent_runtime",
469
+ "columns": {
470
+ "id": {
471
+ "name": "id",
472
+ "type": "bigint",
473
+ "primaryKey": true,
474
+ "notNull": true,
475
+ "identity": {
476
+ "type": "always",
477
+ "name": "tool_call_audits_id_seq",
478
+ "schema": "agent_runtime",
479
+ "increment": "1",
480
+ "startWith": "1",
481
+ "minValue": "1",
482
+ "maxValue": "9223372036854775807",
483
+ "cache": "1",
484
+ "cycle": false
485
+ }
486
+ },
487
+ "invocation_id": {
488
+ "name": "invocation_id",
489
+ "type": "bigint",
490
+ "primaryKey": false,
491
+ "notNull": true
492
+ },
493
+ "scope": {
494
+ "name": "scope",
495
+ "type": "text",
496
+ "primaryKey": false,
497
+ "notNull": true
498
+ },
499
+ "run_id": {
500
+ "name": "run_id",
501
+ "type": "uuid",
502
+ "primaryKey": false,
503
+ "notNull": false
504
+ },
505
+ "tool_name": {
506
+ "name": "tool_name",
507
+ "type": "text",
508
+ "primaryKey": false,
509
+ "notNull": true
510
+ },
511
+ "idempotency_key": {
512
+ "name": "idempotency_key",
513
+ "type": "text",
514
+ "primaryKey": false,
515
+ "notNull": false
516
+ },
517
+ "status": {
518
+ "name": "status",
519
+ "type": "tool_call_status",
520
+ "typeSchema": "agent_runtime",
521
+ "primaryKey": false,
522
+ "notNull": true
523
+ },
524
+ "requested_at": {
525
+ "name": "requested_at",
526
+ "type": "timestamp with time zone",
527
+ "primaryKey": false,
528
+ "notNull": true,
529
+ "default": "now()"
530
+ },
531
+ "completed_at": {
532
+ "name": "completed_at",
533
+ "type": "timestamp with time zone",
534
+ "primaryKey": false,
535
+ "notNull": false
536
+ },
537
+ "error_code": {
538
+ "name": "error_code",
539
+ "type": "text",
540
+ "primaryKey": false,
541
+ "notNull": false
542
+ },
543
+ "request_snapshot": {
544
+ "name": "request_snapshot",
545
+ "type": "jsonb",
546
+ "primaryKey": false,
547
+ "notNull": false
548
+ },
549
+ "metadata": {
550
+ "name": "metadata",
551
+ "type": "jsonb",
552
+ "primaryKey": false,
553
+ "notNull": false
554
+ },
555
+ "created_at": {
556
+ "name": "created_at",
557
+ "type": "timestamp with time zone",
558
+ "primaryKey": false,
559
+ "notNull": true,
560
+ "default": "now()"
561
+ }
562
+ },
563
+ "indexes": {
564
+ "tool_call_audits_scope_tool_idempotency_unique": {
565
+ "name": "tool_call_audits_scope_tool_idempotency_unique",
566
+ "columns": [
567
+ {
568
+ "expression": "scope",
569
+ "isExpression": false,
570
+ "asc": true,
571
+ "nulls": "last"
572
+ },
573
+ {
574
+ "expression": "tool_name",
575
+ "isExpression": false,
576
+ "asc": true,
577
+ "nulls": "last"
578
+ },
579
+ {
580
+ "expression": "idempotency_key",
581
+ "isExpression": false,
582
+ "asc": true,
583
+ "nulls": "last"
584
+ }
585
+ ],
586
+ "isUnique": true,
587
+ "where": "\"agent_runtime\".\"tool_call_audits\".\"idempotency_key\" is not null",
588
+ "concurrently": false,
589
+ "method": "btree",
590
+ "with": {}
591
+ },
592
+ "tool_call_audits_invocation_idx": {
593
+ "name": "tool_call_audits_invocation_idx",
594
+ "columns": [
595
+ {
596
+ "expression": "invocation_id",
597
+ "isExpression": false,
598
+ "asc": true,
599
+ "nulls": "last"
600
+ }
601
+ ],
602
+ "isUnique": false,
603
+ "concurrently": false,
604
+ "method": "btree",
605
+ "with": {}
606
+ },
607
+ "tool_call_audits_run_idx": {
608
+ "name": "tool_call_audits_run_idx",
609
+ "columns": [
610
+ {
611
+ "expression": "run_id",
612
+ "isExpression": false,
613
+ "asc": true,
614
+ "nulls": "last"
615
+ }
616
+ ],
617
+ "isUnique": false,
618
+ "concurrently": false,
619
+ "method": "btree",
620
+ "with": {}
621
+ }
622
+ },
623
+ "foreignKeys": {
624
+ "tool_call_audits_invocation_id_invocations_id_fk": {
625
+ "name": "tool_call_audits_invocation_id_invocations_id_fk",
626
+ "tableFrom": "tool_call_audits",
627
+ "tableTo": "invocations",
628
+ "schemaTo": "agent_runtime",
629
+ "columnsFrom": [
630
+ "invocation_id"
631
+ ],
632
+ "columnsTo": [
633
+ "id"
634
+ ],
635
+ "onDelete": "no action",
636
+ "onUpdate": "no action"
637
+ }
638
+ },
639
+ "compositePrimaryKeys": {},
640
+ "uniqueConstraints": {},
641
+ "policies": {},
642
+ "checkConstraints": {},
643
+ "isRLSEnabled": false
644
+ },
645
+ "agent_runtime.worker_leases": {
646
+ "name": "worker_leases",
647
+ "schema": "agent_runtime",
648
+ "columns": {
649
+ "name": {
650
+ "name": "name",
651
+ "type": "text",
652
+ "primaryKey": true,
653
+ "notNull": true
654
+ },
655
+ "holder_id": {
656
+ "name": "holder_id",
657
+ "type": "text",
658
+ "primaryKey": false,
659
+ "notNull": true
660
+ },
661
+ "acquired_at": {
662
+ "name": "acquired_at",
663
+ "type": "timestamp with time zone",
664
+ "primaryKey": false,
665
+ "notNull": true,
666
+ "default": "now()"
667
+ },
668
+ "heartbeat_at": {
669
+ "name": "heartbeat_at",
670
+ "type": "timestamp with time zone",
671
+ "primaryKey": false,
672
+ "notNull": true,
673
+ "default": "now()"
674
+ },
675
+ "expires_at": {
676
+ "name": "expires_at",
677
+ "type": "timestamp with time zone",
678
+ "primaryKey": false,
679
+ "notNull": true
680
+ }
681
+ },
682
+ "indexes": {},
683
+ "foreignKeys": {},
684
+ "compositePrimaryKeys": {},
685
+ "uniqueConstraints": {},
686
+ "policies": {},
687
+ "checkConstraints": {},
688
+ "isRLSEnabled": false
689
+ }
690
+ },
691
+ "enums": {
692
+ "agent_runtime.invocation_status": {
693
+ "name": "invocation_status",
694
+ "schema": "agent_runtime",
695
+ "values": [
696
+ "pending",
697
+ "running",
698
+ "awaiting_approval",
699
+ "succeeded",
700
+ "failed",
701
+ "cancelled"
702
+ ]
703
+ },
704
+ "agent_runtime.tool_call_status": {
705
+ "name": "tool_call_status",
706
+ "schema": "agent_runtime",
707
+ "values": [
708
+ "started",
709
+ "succeeded",
710
+ "failed"
711
+ ]
712
+ }
713
+ },
714
+ "schemas": {
715
+ "agent_runtime": "agent_runtime"
716
+ },
717
+ "sequences": {},
718
+ "roles": {},
719
+ "policies": {},
720
+ "views": {},
721
+ "_meta": {
722
+ "columns": {},
723
+ "schemas": {},
724
+ "tables": {}
725
+ }
726
+ }
@@ -8,6 +8,13 @@
8
8
  "when": 1793177509604,
9
9
  "tag": "0000_init",
10
10
  "breakpoints": true
11
+ },
12
+ {
13
+ "idx": 1,
14
+ "version": "7",
15
+ "when": 1794812633156,
16
+ "tag": "0001_invocation_result_messages",
17
+ "breakpoints": true
11
18
  }
12
19
  ]
13
20
  }
package/package.json CHANGED
@@ -57,18 +57,6 @@
57
57
  "main": "./dist/index.js",
58
58
  "name": "runwarden",
59
59
  "packageManager": "pnpm@10.34.9",
60
- "pnpm": {
61
- "onlyBuiltDependencies": [
62
- "@embedded-postgres/darwin-arm64",
63
- "@embedded-postgres/darwin-x64",
64
- "@embedded-postgres/linux-arm",
65
- "@embedded-postgres/linux-arm64",
66
- "@embedded-postgres/linux-ia32",
67
- "@embedded-postgres/linux-ppc64",
68
- "@embedded-postgres/linux-x64",
69
- "@embedded-postgres/windows-x64"
70
- ]
71
- },
72
60
  "prettier": {
73
61
  "importOrder": [
74
62
  "<BUILTIN_MODULES>",
@@ -103,5 +91,5 @@
103
91
  "sideEffects": false,
104
92
  "type": "module",
105
93
  "types": "./dist/index.d.ts",
106
- "version": "0.3.0"
94
+ "version": "0.5.0"
107
95
  }