@foldrun/core 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 +27 -10
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/src/account.d.ts +45 -0
- package/dist/src/account.js +130 -0
- package/dist/src/api-tools.d.ts +8 -0
- package/dist/src/api-tools.js +22 -4
- package/dist/src/approvals.d.ts +104 -1
- package/dist/src/approvals.js +192 -2
- package/dist/src/browser-pod.d.ts +129 -0
- package/dist/src/browser-pod.js +284 -0
- package/dist/src/budget.d.ts +32 -0
- package/dist/src/budget.js +177 -0
- package/dist/src/catalog.js +3 -1
- package/dist/src/clock.d.ts +49 -0
- package/dist/src/clock.js +121 -0
- package/dist/src/completions.js +17 -8
- package/dist/src/confine.d.ts +22 -0
- package/dist/src/confine.js +224 -4
- package/dist/src/deploy.d.ts +33 -0
- package/dist/src/deploy.js +145 -6
- package/dist/src/egress.d.ts +26 -2
- package/dist/src/egress.js +8 -1
- package/dist/src/eol.d.ts +2 -0
- package/dist/src/eol.js +7 -0
- package/dist/src/evals.d.ts +9 -0
- package/dist/src/evals.js +26 -13
- package/dist/src/flow-lint.d.ts +12 -0
- package/dist/src/flow-lint.js +331 -1
- package/dist/src/flow-patterns.d.ts +141 -0
- package/dist/src/flow-patterns.js +568 -0
- package/dist/src/gitrepo.d.ts +18 -0
- package/dist/src/gitrepo.js +49 -0
- package/dist/src/host-env.d.ts +8 -0
- package/dist/src/host-env.js +48 -0
- package/dist/src/json-schema.d.ts +12 -0
- package/dist/src/json-schema.js +202 -0
- package/dist/src/kinds.js +1 -1
- package/dist/src/language.d.ts +17 -0
- package/dist/src/language.js +55 -0
- package/dist/src/layout.d.ts +69 -0
- package/dist/src/layout.js +200 -0
- package/dist/src/library.d.ts +9 -0
- package/dist/src/library.js +43 -4
- package/dist/src/limits.d.ts +84 -0
- package/dist/src/limits.js +287 -0
- package/dist/src/locale.d.ts +47 -0
- package/dist/src/locale.js +177 -0
- package/dist/src/mail.d.ts +88 -0
- package/dist/src/mail.js +245 -0
- package/dist/src/model-probe.d.ts +3 -0
- package/dist/src/model-probe.js +1 -0
- package/dist/src/notify.d.ts +132 -8
- package/dist/src/notify.js +360 -58
- package/dist/src/openapi.js +5 -3
- package/dist/src/operator.d.ts +201 -0
- package/dist/src/operator.js +251 -0
- package/dist/src/paths.d.ts +33 -0
- package/dist/src/paths.js +87 -0
- package/dist/src/platform.d.ts +144 -4
- package/dist/src/platform.js +27 -3
- package/dist/src/provider-health.d.ts +55 -0
- package/dist/src/provider-health.js +233 -0
- package/dist/src/providers.d.ts +481 -0
- package/dist/src/providers.js +1105 -6
- package/dist/src/refusal.d.ts +83 -0
- package/dist/src/refusal.js +281 -0
- package/dist/src/run-container.d.ts +206 -17
- package/dist/src/run-container.js +547 -80
- package/dist/src/runner.d.ts +179 -10
- package/dist/src/runner.js +1423 -169
- package/dist/src/runtime.d.ts +52 -0
- package/dist/src/runtime.js +493 -58
- package/dist/src/script-tools.d.ts +15 -2
- package/dist/src/script-tools.js +44 -4
- package/dist/src/secret-files.d.ts +6 -5
- package/dist/src/secret-files.js +24 -11
- package/dist/src/secret-health.d.ts +83 -0
- package/dist/src/secret-health.js +177 -0
- package/dist/src/secrets.d.ts +38 -1
- package/dist/src/secrets.js +197 -96
- package/dist/src/starter.d.ts +9 -0
- package/dist/src/starter.js +95 -11
- package/dist/src/step-exec.d.ts +106 -1
- package/dist/src/step-exec.js +558 -85
- package/dist/src/step-removal.d.ts +15 -0
- package/dist/src/step-removal.js +49 -0
- package/dist/src/storage.d.ts +23 -4
- package/dist/src/storage.js +125 -23
- package/dist/src/store.d.ts +492 -38
- package/dist/src/store.js +882 -69
- package/dist/src/subagents.d.ts +75 -0
- package/dist/src/subagents.js +149 -0
- package/dist/src/tar.js +2 -1
- package/dist/src/test-mode.d.ts +111 -0
- package/dist/src/test-mode.js +285 -0
- package/dist/src/tool-names.d.ts +13 -1
- package/dist/src/tool-names.js +38 -11
- package/dist/src/tool-programs.d.ts +26 -0
- package/dist/src/tool-programs.js +172 -0
- package/dist/src/tool-test.js +152 -33
- package/dist/src/translator.d.ts +8 -2
- package/dist/src/translator.js +71 -24
- package/dist/src/trigger-log.d.ts +43 -0
- package/dist/src/trigger-log.js +122 -0
- package/dist/src/triggers.d.ts +23 -0
- package/dist/src/triggers.js +101 -12
- package/dist/src/untrusted-fetch.d.ts +11 -0
- package/dist/src/untrusted-fetch.js +77 -0
- package/dist/src/web-actions.d.ts +91 -0
- package/dist/src/web-actions.js +199 -0
- package/dist/src/webhook.d.ts +19 -3
- package/dist/src/webhook.js +50 -11
- package/index.ts +3 -0
- package/package.json +5 -5
- package/src/account.ts +149 -0
- package/src/api-tools.ts +32 -4
- package/src/approvals.ts +253 -2
- package/src/browser-pod.ts +313 -0
- package/src/budget.ts +178 -0
- package/src/catalog.ts +3 -1
- package/src/clock.ts +149 -0
- package/src/completions.ts +17 -8
- package/src/confine.ts +224 -4
- package/src/deploy.ts +137 -6
- package/src/egress.ts +32 -4
- package/src/eol.ts +7 -0
- package/src/evals.ts +36 -11
- package/src/flow-lint.ts +371 -1
- package/src/flow-patterns.ts +597 -0
- package/src/gitrepo.ts +48 -0
- package/src/host-env.ts +51 -0
- package/src/json-schema.ts +184 -0
- package/src/kinds.ts +1 -1
- package/src/language.ts +62 -0
- package/src/layout.ts +228 -0
- package/src/library.ts +50 -4
- package/src/limits.ts +290 -0
- package/src/locale.ts +217 -0
- package/src/mail.ts +316 -0
- package/src/model-probe.ts +4 -0
- package/src/notify.ts +391 -44
- package/src/openapi.ts +5 -3
- package/src/operator.ts +300 -0
- package/src/paths.ts +83 -0
- package/src/platform.ts +158 -5
- package/src/provider-health.ts +275 -0
- package/src/providers.ts +1368 -6
- package/src/refusal.ts +320 -0
- package/src/run-container.ts +611 -76
- package/src/runner.ts +1463 -165
- package/src/runtime.ts +487 -55
- package/src/script-tools.ts +55 -6
- package/src/secret-files.ts +22 -10
- package/src/secret-health.ts +230 -0
- package/src/secrets.ts +191 -95
- package/src/starter.ts +96 -11
- package/src/step-exec.ts +548 -41
- package/src/step-removal.ts +59 -0
- package/src/storage.ts +149 -24
- package/src/store.ts +1227 -74
- package/src/subagents.ts +189 -0
- package/src/tar.ts +2 -1
- package/src/test-mode.ts +311 -0
- package/src/tool-names.ts +40 -11
- package/src/tool-programs.ts +179 -0
- package/src/tool-test.ts +159 -32
- package/src/translator.ts +74 -23
- package/src/trigger-log.ts +160 -0
- package/src/triggers.ts +102 -12
- package/src/untrusted-fetch.ts +88 -0
- package/src/web-actions.ts +237 -0
- package/src/webhook.ts +58 -11
- package/templates/hello/agents/curator/agent.md +1 -1
- package/templates/hello/agents/notetaker/agent.md +1 -1
package/dist/src/step-exec.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { McpServerConfig } from "@anthropic-ai/claude-agent-sdk";
|
|
2
2
|
import type { Effort } from "./store.ts";
|
|
3
|
+
import type { TestEffect } from "./test-mode.ts";
|
|
4
|
+
import type { OperatorEvent } from "./operator.ts";
|
|
5
|
+
import { type SubagentSpec } from "./subagents.ts";
|
|
6
|
+
import { type Limits } from "./limits.ts";
|
|
7
|
+
import { type BrowserPodOutcome, type ClassifyContext } from "./browser-pod.ts";
|
|
3
8
|
export interface ExecOutcome {
|
|
4
9
|
status: "completed" | "failed";
|
|
5
10
|
result: string | null;
|
|
@@ -19,6 +24,20 @@ export interface ExecOutcome {
|
|
|
19
24
|
inputTokens: number;
|
|
20
25
|
outputTokens: number;
|
|
21
26
|
} | null;
|
|
27
|
+
/** Set only when some turns ran on a different model from the step's — a
|
|
28
|
+
* sub-agent with its own `model:`. The sum of every turn, each priced at
|
|
29
|
+
* its own model. `usage` above is one lump and cannot be repriced at the
|
|
30
|
+
* step's model without charging the sub-agent's turns at the wrong rate;
|
|
31
|
+
* the runner reads this instead (repriced in runner.ts). */
|
|
32
|
+
turnsCostUsd?: number;
|
|
33
|
+
/** Why the model's last turn ended, as the SDK's result message says:
|
|
34
|
+
* end_turn, max_tokens, stop_sequence, tool_use, pause_turn, refusal or
|
|
35
|
+
* model_context_window_exceeded. Null when no result arrived. */
|
|
36
|
+
stopReason?: string | null;
|
|
37
|
+
/** Set when the step browsed through the account's browser pod from the
|
|
38
|
+
* slim image (ExecOptions.browserPod): its reconnects, and — when the pod
|
|
39
|
+
* was lost — why, and what the step had written by then. */
|
|
40
|
+
browserPod?: BrowserPodOutcome;
|
|
22
41
|
}
|
|
23
42
|
export interface ExecOptions {
|
|
24
43
|
agentDir: string;
|
|
@@ -43,6 +62,9 @@ export interface ExecOptions {
|
|
|
43
62
|
* The runner derives it from the flow's `budget:` and what the run has
|
|
44
63
|
* already spent; absent means no ceiling on this step. */
|
|
45
64
|
budgetUsd?: number | null;
|
|
65
|
+
/** Which line set the ceiling, for the error that names it — "budget: in
|
|
66
|
+
* the flow file" or "budget: on the <agent> agent". */
|
|
67
|
+
budgetNote?: string;
|
|
46
68
|
/** Price per token for the model, when the catalogue knows it, so spend
|
|
47
69
|
* can be counted turn by turn instead of learned at the end. Without it
|
|
48
70
|
* the step prices its turns from the SDK's own running total. */
|
|
@@ -58,17 +80,77 @@ export interface ExecOptions {
|
|
|
58
80
|
/** `output: json` — the reply must carry one JSON value; extracting it is
|
|
59
81
|
* part of finishing the step, and failing to is failing the step. */
|
|
60
82
|
output?: "json";
|
|
83
|
+
/** `schema:` — what that value must look like; a value that does not fit
|
|
84
|
+
* fails the step naming the field. See json-schema.ts. */
|
|
85
|
+
schema?: Record<string, unknown> | boolean;
|
|
86
|
+
/** `max_turns:` — the most model turns before the step is stopped. The
|
|
87
|
+
* SDK enforces it; the step reads the result's reason and says so. */
|
|
88
|
+
maxTurns?: number;
|
|
61
89
|
/** false when the caller is already an isolation boundary (a run
|
|
62
90
|
* container): the SDK's bash sandbox is then redundant and would block
|
|
63
91
|
* declared network use. Default (undefined/true) keeps it on. */
|
|
64
92
|
sandboxBash?: boolean;
|
|
93
|
+
/** Has a person asked for the run to stop? Polled every couple of
|
|
94
|
+
* seconds while the model loop runs; true interrupts it. The in-process
|
|
95
|
+
* runner answers from the run record (stopRun writes there from another
|
|
96
|
+
* process); a container has a sandbox that is destroyed instead. */
|
|
97
|
+
stopRequested?: () => boolean;
|
|
98
|
+
/** Reads the run's inbox (operator.ts inboxReader): what a person wrote
|
|
99
|
+
* in while the step runs, handed to the model after its next tool call.
|
|
100
|
+
* Absent where nobody can write in (no egress proxy). */
|
|
101
|
+
inbox?: () => Promise<string | null>;
|
|
102
|
+
/** `subagents:` — colleagues the model may delegate to, each with its own
|
|
103
|
+
* context and tools no wider than this step's (subagents.ts). Absent or
|
|
104
|
+
* empty: no Agent tool, as before. */
|
|
105
|
+
subagents?: SubagentSpec[];
|
|
106
|
+
/** `limits:` — the most calls this step may make, per tool and in all,
|
|
107
|
+
* resolved host-side (account, workspace, agent, step: nearest wins per
|
|
108
|
+
* key). Counted in the PreToolUse hook below; see limits.ts. */
|
|
109
|
+
limits?: Limits;
|
|
110
|
+
/** SDK tool name → the foldrun name it counts under, for the tools whose
|
|
111
|
+
* SDK name does not say (limits.ts toolOwners). */
|
|
112
|
+
toolOwners?: Record<string, string>;
|
|
113
|
+
/** The step runs on the slim image and browses through the account's
|
|
114
|
+
* browser pod (browser-pod.ts). `events` is the file the web tool writes
|
|
115
|
+
* its reconnects to; the classify context says which API operations and
|
|
116
|
+
* web actions are writes. A lost pod stops the step, and the outcome
|
|
117
|
+
* says what it had written, so the runner can re-run it or fail it. */
|
|
118
|
+
browserPod?: {
|
|
119
|
+
events: string;
|
|
120
|
+
} & ClassifyContext;
|
|
65
121
|
emit: (type: "text" | "tool" | "info" | "error", text: string, extra?: EventExtra) => void;
|
|
66
122
|
}
|
|
123
|
+
/** How often the stop flag is read while a step runs. */
|
|
124
|
+
export declare const STOP_POLL_MS = 2000;
|
|
125
|
+
/** The least a `verify:` gets when the step used up most of its `timeout:` —
|
|
126
|
+
* capped by the timeout itself, so the step and its check together never
|
|
127
|
+
* run past timeout + this. Under the isolated path's backstop (+60 s). */
|
|
128
|
+
export declare const VERIFY_FLOOR_MS = 30000;
|
|
129
|
+
/** How long a `verify:` may run: what is left of the step's `timeout:`,
|
|
130
|
+
* with a floor. Null when the flow set no timeout — `timeout:` is the only
|
|
131
|
+
* clock there is, and a stop still ends the check. */
|
|
132
|
+
export declare function verifyBudgetMs(timeoutSec: number | undefined, elapsedMs: number): number | null;
|
|
133
|
+
/** After an interrupt is asked for, how long the model loop gets to wind
|
|
134
|
+
* down on its own before the query is aborted outright. */
|
|
135
|
+
export declare const INTERRUPT_GRACE_MS = 10000;
|
|
136
|
+
/** The model loop, as executeStep needs it — the SDK's `query`, or a test's
|
|
137
|
+
* stand-in. Only the shape the loop reads. */
|
|
138
|
+
export type QueryLike = AsyncIterable<unknown> & {
|
|
139
|
+
interrupt(): Promise<unknown>;
|
|
140
|
+
};
|
|
141
|
+
export type QueryFn = (args: {
|
|
142
|
+
prompt: string;
|
|
143
|
+
options: Record<string, unknown>;
|
|
144
|
+
}) => QueryLike;
|
|
67
145
|
/** The pairing fields on a tool event — see RunEvent in store.ts. */
|
|
68
146
|
export type EventExtra = {
|
|
69
147
|
call?: string;
|
|
70
148
|
ms?: number;
|
|
71
149
|
err?: boolean;
|
|
150
|
+
effect?: TestEffect;
|
|
151
|
+
operator?: OperatorEvent;
|
|
152
|
+
subagent?: string;
|
|
153
|
+
check?: boolean;
|
|
72
154
|
};
|
|
73
155
|
/** Conservative per-token rates for a model nothing else can price — an
|
|
74
156
|
* unknown id on a gateway with no catalogue. Opus-class, so a ceiling
|
|
@@ -101,7 +183,27 @@ export declare function priceTurn(u: Record<string, number | undefined>, price:
|
|
|
101
183
|
* over the cap however many steps it fans out to. No budget, no ceiling.
|
|
102
184
|
*/
|
|
103
185
|
export declare function stepCeiling(budgetUsd: number | null | undefined, spentUsd: number, launching: number): number | null;
|
|
104
|
-
|
|
186
|
+
/**
|
|
187
|
+
* The ceiling a step actually runs under, and which line set it.
|
|
188
|
+
*
|
|
189
|
+
* Two caps can apply to one step: the flow's `budget:` gives it an equal
|
|
190
|
+
* share of what the run has left; the agent's own `budget:` is the most that
|
|
191
|
+
* agent may spend in one run, less what its steps in this run have cost or
|
|
192
|
+
* may still cost, shared across `sharing` — this step and the agent's steps
|
|
193
|
+
* launched with it that have not started yet. Without the share, twenty
|
|
194
|
+
* fan-out copies of one agent each got the whole remainder, because none of
|
|
195
|
+
* them has recorded a cent when the next one starts.
|
|
196
|
+
* The tighter one wins, and the note says which, because "over budget" with
|
|
197
|
+
* no line to go and raise is a message that sends someone to the wrong file.
|
|
198
|
+
*/
|
|
199
|
+
export declare function stepCeilingFor(flowShareUsd: number | null, agentBudgetUsd: number | null | undefined, agentSpentUsd: number, agent: string, sharing?: number): {
|
|
200
|
+
ceilingUsd: number | null;
|
|
201
|
+
note: string;
|
|
202
|
+
};
|
|
203
|
+
export declare function executeStep(opts: ExecOptions,
|
|
204
|
+
/** The model loop. Injected so the clock and the stop can be tested
|
|
205
|
+
* without a model; production passes nothing and gets the SDK. */
|
|
206
|
+
runQuery?: QueryFn): Promise<ExecOutcome>;
|
|
105
207
|
/**
|
|
106
208
|
* The one JSON value a reply carries. A ```json fence wins — it is what the
|
|
107
209
|
* step was asked to write — and the LAST one at that, because a model that
|
|
@@ -143,4 +245,7 @@ export declare function checkVerify(agentDir: string, verify: string, ctx: {
|
|
|
143
245
|
/** The step's own model environment, for `judge:` — it grades on the
|
|
144
246
|
* fast tier through the same credential the step rode. */
|
|
145
247
|
modelEnv?: Record<string, string | undefined>;
|
|
248
|
+
/** Ends a shell check or a judge mid-way: the step's clock ran out, or a
|
|
249
|
+
* person asked the run to stop. */
|
|
250
|
+
signal?: AbortSignal;
|
|
146
251
|
}): Promise<VerifyVerdict>;
|