@parcha/agentrun-kernel 0.1.0-beta.34 → 0.1.0-beta.35
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 +33 -0
- package/dist/host/index.d.ts +3 -3
- package/dist/host/index.js +2 -2
- package/dist/host/overhead.d.ts +75 -4
- package/dist/host/overhead.js +220 -10
- package/dist/host/proxy.d.ts +40 -4
- package/dist/host/proxy.js +73 -2
- package/dist/kernel/cap/index.d.ts +1 -1
- package/dist/kernel/cap/index.js +1 -1
- package/dist/kernel/cap/port.d.ts +3 -2
- package/dist/kernel/cap/port.js +2 -2
- package/dist/kernel/cap/price.js +5 -2
- package/dist/kernel/cap/run-cap.d.ts +2 -2
- package/dist/kernel/cap/run-cap.js +1 -1
- package/dist/kernel/cap/types.d.ts +7 -0
- package/dist/kernel/cap/words.js +1 -1
- package/dist/process/tools.d.ts +9 -0
- package/dist/process/tools.js +19 -6
- package/dist/runner.d.ts +8 -0
- package/dist/runner.js +3 -3
- package/dist/testing.d.ts +9 -2
- package/dist/testing.js +63 -18
- package/dist/types.d.ts +13 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.35 (2026-11-11)
|
|
6
|
+
|
|
7
|
+
- On the runner, a learned workflow node that names a tier (`fast`, `strong`) now runs on the host's model of that tier (`AGENT_MODEL_FAST`, `AGENT_MODEL_STRONG`) instead of the run's own model. Its requests take the run's one route and stay under the run's cap, and each is booked at its own model's price. A tier the host names no model of still runs on the run's own model. A tier whose model can't be reached fails the workflow call and names why; it never runs on another model. This holds on every harness: pi, Claude Agent, Codex and OpenCode. On a CLI harness the tier's requests go through a proxy of their own beside the CLI session's, never through the CLI. A tier's model key saved in Settings → Model keys is opened for that tier's requests alone. It never goes into a tool's environment. A tier whose model has the same id as the run's model is still held and booked at the tier's own price. `AdapterSession.port` and the run ledger's `models` take an optional `tier`. The kernel's `ModelRequest`, `ModelProxyOptions` and in-flight records carry an optional `route`, and the cap's `modelOf(id, route)` prices a request by model and route.
|
|
8
|
+
Who breaks: a host that already sets `AGENT_MODEL_FAST` or `AGENT_MODEL_STRONG` changes with no action. Its learned workflows' nodes of that tier now run on that model and at its price, and when that model can't be reached the learned_workflow call fails where it used to run on the run's own model.
|
|
9
|
+
Upgrading: a host whose `AGENT_MODEL_FAST` or `AGENT_MODEL_STRONG` names a model it can't reach should unset it or make the model reachable; learned tier nodes now run on it.
|
|
10
|
+
- A capped run straight to Anthropic is no longer paused by a cap it could work under. Before each answer request on a route to `https://api.anthropic.com` (pi and claude-agent), the model proxy asks Anthropic's free token count (`POST /v1/messages/count_tokens`). It sends only the credential and version headers, and never goes through a gateway or any other base. The request's input bound is then that count plus the tool-use prompt, where before it was the body's bytes (about two to three times the tokens billed). A count that fails, says nothing or takes over 3 seconds leaves the byte bound, and the request goes on. Through OpenRouter or any other gateway the bound stays the bytes, so the cap still never passes.
|
|
11
|
+
|
|
12
|
+
The serve README's spend-cap section now states the smallest cap that works, by cap mode, measured on a pi desktop run on Sonnet. In `strict` mode (and in `expected`, the default, until the runner prices a step from the previous request's cache, #2504) it is $0.05 for the first request and $0.11 for a five-step run through a gateway, and $0.03 and $0.09 straight to Anthropic. The console's cap fields say it in a line, with a link. A cap below these still pauses with `Not sent: ... the next step needs at least $X`. A policy may count a request through `ProviderPolicy.countInput` (`InputCounter`, `countedInputOf` in the kernel host).
|
|
13
|
+
- A Claude Code or Codex call that needs approval shows on the run's timeline while it waits, and the test harness for those CLIs asks the tool gate before each call, as the real ones do:
|
|
14
|
+
- serve: a CLI call the tool gate asks about goes on the run's record as it parks, its start marked parked, the way an MCP call parked at its door already did. Before, the timeline showed the approval card with no call row above it until the call ran. An allowed call then runs under that one start; a stop withdraws it and its row reads "Not run: the run was stopped while it waited".
|
|
15
|
+
- kernel: `askGate(gate, call, signal)` (`process/tools.ts`) is the gate step every tool bridge takes first: undefined for an allow, the refusal for a deny, and a park holds the call until the signal aborts. The faux harness in `@parcha/agentrun-kernel/testing` now asks it before each call: a deny is the call's answer, recorded so it is never asked again, and a park holds the turn. A recovered turn first runs the calls its last request left with no intent and no result (a parked one), under their own ids, as a real CLI's resume does. A test that scripts a faux CLI call to a tool set to ask (a `monid.` or MCP catalog tool by default) now sees the run park on it.
|
|
16
|
+
- Runs on the runner behave as before the cutover in four places a person could hit:
|
|
17
|
+
- A run keeps the files it was started with. The server holds each of a run's `file_ids` for it at the start, so a file deleted between the start and the runner's claim is still copied into the run's `inputs/`. The hold goes once the copy is made, or when the run ends without one.
|
|
18
|
+
- A copy of a run's files that fails ends the run failed with "The run's files could not be copied into its workspace: <why>", instead of the bare error.
|
|
19
|
+
- A message sent while a turn works is answered before the run ends. The runner hands a turn's end every message it has not handed on yet, rather than at its next poll half a second later, so the run's end no longer refuses one the API took. On pi, a message placed as the turn answered was answered after the run's end was written: the run read completed, then wrote another answer.
|
|
20
|
+
- A claude-agent run's rows name a file it wrote or read by its name in the workspace (`Wrote hello.md`, `Saved hello.md`), not by the absolute path the Claude CLI sends, which named a folder on the runner's machine. The call's input preview keeps the path as sent.
|
|
21
|
+
- The test kit's faux adapter tells its script the session's working directory (`script(spec, { cwd })`), as a real CLI builds its absolute paths from it.
|
|
22
|
+
- A tool call the runner runs again after a crash meets the run's gate again. Before, a replay-safe call (web_search, web_fetch) that pi reran after a crash skipped the gate: a deny set since its first attempt didn't stop it, and a tool set to ask since ran it with no one's approval. Now a deny or a pin refuses the rerun in words saying the earlier attempt may have taken effect ("whether it took effect is not known"), never "nothing was sent", and a tool set to ask parks the run on it, the owner's answer then acting on it. A stop that lands while the rerun is asked wins over a permission that comes after it: the call never starts. Codex and Claude Code reruns say the same.
|
|
23
|
+
- A capped run that reads screenshots is no longer refused at its cap after the first one. A model request's input bound counted an image's base64 as one token per byte, and then the image's billed maximum on top. A 1280x720 screenshot (about a megabyte of base64) read as some 1.3 million input tokens, so a Sonnet step under a $1.50 cap "needed at least $4.83" when Claude bills it a few cents.
|
|
24
|
+
|
|
25
|
+
Each image, in every turn, now counts at what the routed model's provider can bill it as, in place of its data's bytes, whatever API carries it. The size comes from the image's own header (PNG, JPEG, GIF or WebP):
|
|
26
|
+
- Anthropic: its 28-pixel patches or its area at 750 pixels a token, whichever is more, at most 4,784.
|
|
27
|
+
- OpenAI: its 512-pixel tiles after resizing (85 + 170 each; 85 at detail low), or for a patch-billed mini or nano model its 32-pixel patches at that model's multiplier when more, at most 73,800.
|
|
28
|
+
- Google: 258 per 768-pixel tile, at least 1,120.
|
|
29
|
+
- Any other provider: the most of the three.
|
|
30
|
+
An image whose size can't be read counts at its provider's per-image maximum, never at its bytes. An image-shaped object outside where the API reads images (a tool call's arguments) is counted at its bytes, as text.
|
|
31
|
+
|
|
32
|
+
`InputShape.images` (the kernel host's `providerInputOverhead`) is now a list of images, each with the bytes its data takes and its size when known; `InputShape.model` names the routed model; the figure can be below 0, and so can a policy's `serverInputOverhead`, never past the body's bytes. Upgrading: pass `images: [{ bytes, width?, height? }]`, built with `imageInputOf`, `messagesImagesIn` or `responsesImagesIn`, and the model, in place of a count.
|
|
33
|
+
- A paid call the cap refused for room pauses the run with the run's spend as it is when the pause lands, and never refuses a person's answer to a question the same turn ended on:
|
|
34
|
+
- The budget card (and its words) count what calls beside the refused one charged before the model's next request, not the spend at the refusal. A call that would now fit (one beside it settled for less than it held) pauses nothing.
|
|
35
|
+
- A turn that ends on a question to the person (ask_person) with no next model request drops the refused call's pending pause, so the person's answer reaches the model and is never refused in that call's words, on this claim or the next.
|
|
36
|
+
- The kernel cap's refusal for a paid call names the call (`figures.step`: its name, hold and basis), and `paidRefusal` is exported, so a host can say a refusal again with the run's spend later.
|
|
37
|
+
|
|
5
38
|
## 0.1.0-beta.34 (2026-11-11)
|
|
6
39
|
|
|
7
40
|
- The server checks a harness's pinned binary (claude-agent's CLI, Codex, OpenCode: its sha256, then the version it reports) without holding its event loop, so requests, timers and store answers go on while a binary of hundreds of MiB is hashed and run. Before, the first check in a process held every request for one to several seconds (GET /v2/capabilities, a server's start, an adapter made for a run). The binary is now hashed off the loop a chunk at a time and run as a child the loop does not wait on. A pass is kept for the adapter's own check, which then reads nothing, and two checks of one binary at once read it once. New: `checkedOnceAsync` and `sha256OfFileAsync` (kernel host), `verifyClaudeAgentCliAsync` (claude-agent), and `verifyCodexAsync` and `verifyCodexBinaryAsync` (Codex). Who breaks: a program that calls the kernel's `checkedOnce` with its own check. A check is now a `BinaryCheck`, a generator that yields each probe (`{ kind: "sha256", path }` or `{ kind: "run", path, args, env, timeoutMs }`) and is given back its answer, so one check runs either way.
|
package/dist/host/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { ANTHROPIC_IMAGE_TOKENS_MAX, ANTHROPIC_TOOL_USE_SYSTEM_PROMPT_TOKENS, ASSUMED_TOOL_PROMPT_TOKENS, INPUT_OVERHEAD_APIS, OPENAI_IMAGE_TOKENS_MAX, providerInputOverhead, type InputShape } from "./overhead.js";
|
|
2
|
-
export { hostHeaderProblems, ProxyRefusal, sameKey, startModelProxy } from "./proxy.js";
|
|
3
|
-
export type { ModelProxy, ModelProxyHooks, ModelProxyOptions, ModelUsageReport, ProviderPolicy, ProxyRequest, ProxyRequestContext, ProxyRoute, ProxyUsage } from "./proxy.js";
|
|
1
|
+
export { ANTHROPIC_IMAGE_TOKENS_MAX, ANTHROPIC_TOOL_USE_SYSTEM_PROMPT_TOKENS, ASSUMED_TOOL_PROMPT_TOKENS, anthropicImageTokens, GEMINI_HIGH_RESOLUTION_TOKENS, geminiImageTokens, imageInputOf, imageProviderOf, imageSizeOf, imageTokens, INPUT_OVERHEAD_APIS, messagesImagesIn, OPENAI_IMAGE_TOKENS_MAX, openaiImageTokens, openaiPatchMultiplier, providerInputOverhead, responsesImagesIn, type ImageInput, type InputShape } from "./overhead.js";
|
|
2
|
+
export { COUNT_TIMEOUT_MS, countedInputOf, hostHeaderProblems, ProxyRefusal, sameKey, startModelProxy } from "./proxy.js";
|
|
3
|
+
export type { InputCounter, ModelProxy, ModelProxyHooks, ModelProxyOptions, ModelUsageReport, ProviderPolicy, ProxyRequest, ProxyRequestContext, ProxyRoute, ProxyUsage } from "./proxy.js";
|
|
4
4
|
export { mcpRoute } from "./mcp-route.js";
|
|
5
5
|
export type { McpHandler, McpRouteOptions } from "./mcp-route.js";
|
|
6
6
|
export { processAlive } from "./alive.js";
|
package/dist/host/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// What a harness adapter runs beside its harness on the host: the session's model proxy, provider-neutral, with each
|
|
2
2
|
// provider's rules in a `ProviderPolicy`. Written for AgentRun.
|
|
3
|
-
export { ANTHROPIC_IMAGE_TOKENS_MAX, ANTHROPIC_TOOL_USE_SYSTEM_PROMPT_TOKENS, ASSUMED_TOOL_PROMPT_TOKENS, INPUT_OVERHEAD_APIS, OPENAI_IMAGE_TOKENS_MAX, providerInputOverhead } from "./overhead.js";
|
|
4
|
-
export { hostHeaderProblems, ProxyRefusal, sameKey, startModelProxy } from "./proxy.js";
|
|
3
|
+
export { ANTHROPIC_IMAGE_TOKENS_MAX, ANTHROPIC_TOOL_USE_SYSTEM_PROMPT_TOKENS, ASSUMED_TOOL_PROMPT_TOKENS, anthropicImageTokens, GEMINI_HIGH_RESOLUTION_TOKENS, geminiImageTokens, imageInputOf, imageProviderOf, imageSizeOf, imageTokens, INPUT_OVERHEAD_APIS, messagesImagesIn, OPENAI_IMAGE_TOKENS_MAX, openaiImageTokens, openaiPatchMultiplier, providerInputOverhead, responsesImagesIn } from "./overhead.js";
|
|
4
|
+
export { COUNT_TIMEOUT_MS, countedInputOf, hostHeaderProblems, ProxyRefusal, sameKey, startModelProxy } from "./proxy.js";
|
|
5
5
|
export { mcpRoute } from "./mcp-route.js";
|
|
6
6
|
export { processAlive } from "./alive.js";
|
|
7
7
|
export { serialWriter } from "./serial.js";
|
package/dist/host/overhead.d.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
|
+
/** One image a request carries: the bytes its data takes in the body (its base64, or its data URL; 0 for an image the
|
|
2
|
+
* provider fetches by URL), which are counted at the image's billed size instead, and its pixel size when its data's own
|
|
3
|
+
* header says it (PNG, JPEG, GIF, WebP). */
|
|
4
|
+
export interface ImageInput {
|
|
5
|
+
readonly bytes: number;
|
|
6
|
+
readonly width?: number;
|
|
7
|
+
readonly height?: number;
|
|
8
|
+
/** The detail it asks for, where the API takes one (OpenAI's `low`, `high` or `auto`). */
|
|
9
|
+
readonly detail?: string;
|
|
10
|
+
}
|
|
1
11
|
/** What of a request decides what its provider adds: whether it offers tools, how it asks for them, and its images. */
|
|
2
12
|
export interface InputShape {
|
|
3
13
|
/** The request offers at least one tool. */
|
|
4
14
|
tools: boolean;
|
|
5
15
|
/** Its tool_choice, as Anthropic names them; absent for the provider's default. */
|
|
6
16
|
toolChoice?: "auto" | "none" | "any" | "tool";
|
|
7
|
-
/** Its image inputs, at any depth (a tool's result included). */
|
|
8
|
-
images:
|
|
17
|
+
/** Its image inputs, at any depth (earlier turns' and a tool's result included). */
|
|
18
|
+
images: readonly ImageInput[];
|
|
19
|
+
/** The model it is routed to, as the session names it (`anthropic/claude-sonnet-5.5` through a gateway): its provider's
|
|
20
|
+
* rule bills its images (`imageTokens`). Absent or unknown: the most any known rule bills each one as. */
|
|
21
|
+
model?: string;
|
|
9
22
|
}
|
|
10
23
|
/**
|
|
11
24
|
* The tool-use system prompt the Messages API adds to a request with tools, in tokens, by tool_choice. Documented per
|
|
@@ -45,9 +58,67 @@ export declare const ASSUMED_TOOL_PROMPT_TOKENS = 2048;
|
|
|
45
58
|
* image.
|
|
46
59
|
*/
|
|
47
60
|
export declare const INPUT_OVERHEAD_APIS: readonly string[];
|
|
61
|
+
/**
|
|
62
|
+
* The most tokens Claude bills an image of `width` x `height` pixels as: its count of 28 px patches (the
|
|
63
|
+
* high-resolution tier) or its area at 750 pixels a token (the standard tier), whichever is more, at most
|
|
64
|
+
* `ANTHROPIC_IMAGE_TOKENS_MAX`. Claude only ever shrinks an image before it counts it ("Resolution and token cost",
|
|
65
|
+
* https://platform.claude.com/docs/en/build-with-claude/vision), so the image as sent is the most it can be billed as.
|
|
66
|
+
*/
|
|
67
|
+
export declare function anthropicImageTokens(width: number, height: number): number;
|
|
48
68
|
/**
|
|
49
69
|
* The input tokens a provider bills for a request of `shape` beyond its body's bytes, on the API `api` (pi's names:
|
|
50
|
-
* "anthropic-messages", "openai-responses", ...)
|
|
51
|
-
*
|
|
70
|
+
* "anthropic-messages", "openai-responses", ...): its tool prompt, and each image at what it can be billed as in place of
|
|
71
|
+
* the bytes its data takes in the body (so the figure is below 0 for a request whose images' data is larger than they
|
|
72
|
+
* are billed as; the body's bytes and this together are its bound). A documented API gets its documented figures; any
|
|
73
|
+
* other gets the general figure (`INPUT_OVERHEAD_APIS`). Never undefined: an input that cannot be measured is the
|
|
74
|
+
* body's, not the API's.
|
|
52
75
|
*/
|
|
53
76
|
export declare function providerInputOverhead(api: string, shape: InputShape): number;
|
|
77
|
+
/** The provider whose image rule a model id is billed by, by the id as the session names it (a gateway's
|
|
78
|
+
* `vendor/model`, or the vendor's own): undefined for one the rules do not know. */
|
|
79
|
+
export declare function imageProviderOf(model: string | undefined): "anthropic" | "openai" | "google" | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* The most tokens OpenAI bills an image of `width` x `height` as, by its "Calculating costs" rules
|
|
82
|
+
* (https://developers.openai.com/api/docs/guides/images-vision):
|
|
83
|
+
* - the tile rule, for every model: at detail "low", 85 tokens; otherwise (high, or auto, which may choose high) the
|
|
84
|
+
* image fit within 2048 x 2048, then its shorter side brought to 768 (up as well as down, the dearer reading for a
|
|
85
|
+
* small image), each 512 px tile 170 tokens beside a base of 85. A gpt-4o-mini model bills 2,833 and 5,667 a tile;
|
|
86
|
+
* - the patch rule, for the models it lists as billed by 32 px patches (`openaiPatchMultiplier`): its patches at the
|
|
87
|
+
* model's multiplier, when that is more.
|
|
88
|
+
* At most `OPENAI_IMAGE_TOKENS_MAX`. With no model named, every rule at its dearest: gpt-4o-mini's tiles and the patches
|
|
89
|
+
* at the largest multiplier, 2.46.
|
|
90
|
+
*/
|
|
91
|
+
export declare function openaiImageTokens(width: number, height: number, model?: string, detail?: string): number;
|
|
92
|
+
/** The multiplier OpenAI bills a patch-billed model's 32 px patches at: 2.46 for a nano model, 1.72 for o4-mini (and
|
|
93
|
+
* codex-mini, built on it), 1.62 for another mini model (gpt-4o-mini excepted: it bills tiles); 0 for a tile-billed
|
|
94
|
+
* model; 2.46, the largest, for a model not named. */
|
|
95
|
+
export declare function openaiPatchMultiplier(model: string | undefined): number;
|
|
96
|
+
/** What Gemini bills a picture as at the most ("Media resolution" and "Image understanding" in its API docs): 258 tokens
|
|
97
|
+
* an image at most 384 px on each side, else 258 for each 768 px tile; and a picture at Gemini 3's high media resolution
|
|
98
|
+
* 1,120 tokens. The more of the two. */
|
|
99
|
+
export declare const GEMINI_HIGH_RESOLUTION_TOKENS = 1120;
|
|
100
|
+
export declare function geminiImageTokens(width: number, height: number): number;
|
|
101
|
+
/**
|
|
102
|
+
* The most tokens `image` is billed as by the routed `model`'s provider: Anthropic's, OpenAI's or Google's rule by its
|
|
103
|
+
* size; for a model of another provider, or of none known, the most any of the three rules bills it as. An image whose
|
|
104
|
+
* size cannot be read counts at the largest per-image maximum documented, `OPENAI_IMAGE_TOKENS_MAX` (Anthropic's own,
|
|
105
|
+
* `ANTHROPIC_IMAGE_TOKENS_MAX`, on a Claude model), never at its bytes.
|
|
106
|
+
*/
|
|
107
|
+
export declare function imageTokens(model: string | undefined, image: ImageInput): number;
|
|
108
|
+
/** The pixel size an image's base64 `data` says in its own header (PNG, JPEG, GIF or WebP), or undefined: another format,
|
|
109
|
+
* or a header that cannot be read. Only its start is decoded (a JPEG's frame header within its first 256 KiB). */
|
|
110
|
+
export declare function imageSizeOf(data: string): {
|
|
111
|
+
width: number;
|
|
112
|
+
height: number;
|
|
113
|
+
} | undefined;
|
|
114
|
+
/** A Messages body's images, only where the API reads one as an image: a block of a message's content, or of a
|
|
115
|
+
* tool_result's content, in every turn. Each is a base64 source's data, or a URL's (no bytes). An image-shaped object
|
|
116
|
+
* anywhere else (a tool call's arguments) is text to the provider: its bytes stay counted as they are. */
|
|
117
|
+
export declare function messagesImagesIn(messages: unknown): ImageInput[];
|
|
118
|
+
/** A Responses body's images, only where the API reads one as an image: an `input_image` item, a part of an item's
|
|
119
|
+
* content, or a part of a function call's output, in every turn. Each is a data URL's, or a URL's or file id's (no
|
|
120
|
+
* bytes). An image-shaped object anywhere else is text to the provider: its bytes stay counted as they are. */
|
|
121
|
+
export declare function responsesImagesIn(input: unknown): ImageInput[];
|
|
122
|
+
/** The image a body's `data` (base64, or a data URL) carries: the bytes it takes, and its size when its header says it.
|
|
123
|
+
* Anything else (an http URL, a file id): no bytes, no size. */
|
|
124
|
+
export declare function imageInputOf(data: unknown): ImageInput;
|
package/dist/host/overhead.js
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
//
|
|
5
5
|
// A request's input can never be more tokens than its body's UTF-8 bytes (`inputTokensMaxOf`), except for what the
|
|
6
6
|
// provider adds or bills by another measure: a prompt it adds itself when tools are present, and images, which it bills by
|
|
7
|
-
// their area after it resizes them, not by their bytes.
|
|
8
|
-
//
|
|
7
|
+
// their area after it resizes them, not by their bytes. An image is counted at what the routed model's provider bills it
|
|
8
|
+
// as by its size (Anthropic's, OpenAI's or Google's rule; the most of the three for another provider), in place of the
|
|
9
|
+
// bytes its data takes in the body: a screenshot's base64 is a megabyte, and Claude bills it as some 1,200 tokens. Each
|
|
10
|
+
// figure is the largest the provider documents for any current model, so no model is undercounted.
|
|
9
11
|
/**
|
|
10
12
|
* The tool-use system prompt the Messages API adds to a request with tools, in tokens, by tool_choice. Documented per
|
|
11
13
|
* model under "Pricing" in https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview, and taken at the largest
|
|
@@ -57,19 +59,227 @@ export const ASSUMED_TOOL_PROMPT_TOKENS = 2_048;
|
|
|
57
59
|
export const INPUT_OVERHEAD_APIS = Object.freeze(["anthropic-messages", "openai-responses", "azure-openai-responses", "openai-codex-responses", CHAT_COMPLETIONS]);
|
|
58
60
|
/** The tool-use prompt Anthropic adds for a request of `shape`: none without tools. */
|
|
59
61
|
const anthropicToolPrompt = (shape) => (!shape.tools ? 0 : shape.toolChoice === "any" || shape.toolChoice === "tool" ? ANTHROPIC_TOOL_USE_SYSTEM_PROMPT_TOKENS.anyOrTool : ANTHROPIC_TOOL_USE_SYSTEM_PROMPT_TOKENS.autoOrNone);
|
|
62
|
+
/**
|
|
63
|
+
* The most tokens Claude bills an image of `width` x `height` pixels as: its count of 28 px patches (the
|
|
64
|
+
* high-resolution tier) or its area at 750 pixels a token (the standard tier), whichever is more, at most
|
|
65
|
+
* `ANTHROPIC_IMAGE_TOKENS_MAX`. Claude only ever shrinks an image before it counts it ("Resolution and token cost",
|
|
66
|
+
* https://platform.claude.com/docs/en/build-with-claude/vision), so the image as sent is the most it can be billed as.
|
|
67
|
+
*/
|
|
68
|
+
export function anthropicImageTokens(width, height) {
|
|
69
|
+
return Math.min(ANTHROPIC_IMAGE_TOKENS_MAX, Math.max(Math.ceil(width / 28) * Math.ceil(height / 28), Math.ceil((width * height) / 750)));
|
|
70
|
+
}
|
|
71
|
+
/** Whether `image` is a figure the bounds can read: whole bytes, and a size of whole positive pixels or none. */
|
|
72
|
+
function checkedImage(image) {
|
|
73
|
+
const pixels = (n) => n === undefined || (Number.isSafeInteger(n) && n > 0);
|
|
74
|
+
if (!image || !Number.isSafeInteger(image.bytes) || image.bytes < 0 || !pixels(image.width) || !pixels(image.height) || (image.width === undefined) !== (image.height === undefined)) {
|
|
75
|
+
throw new Error(`not an image's bytes and size: ${JSON.stringify(image).slice(0, 80)}`);
|
|
76
|
+
}
|
|
77
|
+
return image;
|
|
78
|
+
}
|
|
60
79
|
/**
|
|
61
80
|
* The input tokens a provider bills for a request of `shape` beyond its body's bytes, on the API `api` (pi's names:
|
|
62
|
-
* "anthropic-messages", "openai-responses", ...)
|
|
63
|
-
*
|
|
81
|
+
* "anthropic-messages", "openai-responses", ...): its tool prompt, and each image at what it can be billed as in place of
|
|
82
|
+
* the bytes its data takes in the body (so the figure is below 0 for a request whose images' data is larger than they
|
|
83
|
+
* are billed as; the body's bytes and this together are its bound). A documented API gets its documented figures; any
|
|
84
|
+
* other gets the general figure (`INPUT_OVERHEAD_APIS`). Never undefined: an input that cannot be measured is the
|
|
85
|
+
* body's, not the API's.
|
|
64
86
|
*/
|
|
65
87
|
export function providerInputOverhead(api, shape) {
|
|
66
|
-
if (!
|
|
67
|
-
throw new Error(`not
|
|
88
|
+
if (!Array.isArray(shape.images))
|
|
89
|
+
throw new Error(`not a list of images: ${String(shape.images).slice(0, 40)}`);
|
|
90
|
+
const images = shape.images.map(checkedImage);
|
|
91
|
+
// Each image at what the routed model's provider bills it as (imageTokens), whatever API carries it: a gateway speaks
|
|
92
|
+
// one API for every provider it routes to.
|
|
93
|
+
const imagesNet = images.reduce((sum, image) => sum + imageTokens(shape.model, image) - image.bytes, 0);
|
|
68
94
|
if (api === "anthropic-messages")
|
|
69
|
-
return anthropicToolPrompt(shape) +
|
|
95
|
+
return anthropicToolPrompt(shape) + imagesNet;
|
|
70
96
|
if (api === CHAT_COMPLETIONS)
|
|
71
|
-
return (shape.tools ? ANTHROPIC_TOOL_USE_SYSTEM_PROMPT_TOKENS.anyOrTool : 0) +
|
|
97
|
+
return (shape.tools ? ANTHROPIC_TOOL_USE_SYSTEM_PROMPT_TOKENS.anyOrTool : 0) + imagesNet;
|
|
72
98
|
if (INPUT_OVERHEAD_APIS.includes(api))
|
|
73
|
-
return
|
|
74
|
-
return (shape.tools ? ASSUMED_TOOL_PROMPT_TOKENS : 0) +
|
|
99
|
+
return imagesNet;
|
|
100
|
+
return (shape.tools ? ASSUMED_TOOL_PROMPT_TOKENS : 0) + imagesNet;
|
|
101
|
+
}
|
|
102
|
+
/** The provider whose image rule a model id is billed by, by the id as the session names it (a gateway's
|
|
103
|
+
* `vendor/model`, or the vendor's own): undefined for one the rules do not know. */
|
|
104
|
+
export function imageProviderOf(model) {
|
|
105
|
+
if (!model)
|
|
106
|
+
return undefined;
|
|
107
|
+
if (/^anthropic\/|(^|\/)claude/i.test(model))
|
|
108
|
+
return "anthropic";
|
|
109
|
+
if (/^openai\/|(^|\/)(gpt|chatgpt|codex|o\d)/i.test(model))
|
|
110
|
+
return "openai";
|
|
111
|
+
if (/^google\/|(^|\/)gemini/i.test(model))
|
|
112
|
+
return "google";
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The most tokens OpenAI bills an image of `width` x `height` as, by its "Calculating costs" rules
|
|
117
|
+
* (https://developers.openai.com/api/docs/guides/images-vision):
|
|
118
|
+
* - the tile rule, for every model: at detail "low", 85 tokens; otherwise (high, or auto, which may choose high) the
|
|
119
|
+
* image fit within 2048 x 2048, then its shorter side brought to 768 (up as well as down, the dearer reading for a
|
|
120
|
+
* small image), each 512 px tile 170 tokens beside a base of 85. A gpt-4o-mini model bills 2,833 and 5,667 a tile;
|
|
121
|
+
* - the patch rule, for the models it lists as billed by 32 px patches (`openaiPatchMultiplier`): its patches at the
|
|
122
|
+
* model's multiplier, when that is more.
|
|
123
|
+
* At most `OPENAI_IMAGE_TOKENS_MAX`. With no model named, every rule at its dearest: gpt-4o-mini's tiles and the patches
|
|
124
|
+
* at the largest multiplier, 2.46.
|
|
125
|
+
*/
|
|
126
|
+
export function openaiImageTokens(width, height, model, detail) {
|
|
127
|
+
// gpt-4o-mini's tile rates are the dearest: a model not named (a gateway's alias may be one) is held to them.
|
|
128
|
+
const mini = model === undefined || /4o-mini/i.test(model);
|
|
129
|
+
let tiled;
|
|
130
|
+
if (detail === "low")
|
|
131
|
+
tiled = mini ? 2_833 : 85;
|
|
132
|
+
else {
|
|
133
|
+
const fit = Math.min(1, 2048 / Math.max(width, height));
|
|
134
|
+
const short = 768 / Math.min(width * fit, height * fit);
|
|
135
|
+
const tiles = Math.ceil((width * fit * short) / 512) * Math.ceil((height * fit * short) / 512);
|
|
136
|
+
tiled = mini ? 2_833 + 5_667 * tiles : 85 + 170 * tiles;
|
|
137
|
+
}
|
|
138
|
+
const multiplier = openaiPatchMultiplier(model);
|
|
139
|
+
const patched = multiplier > 0 ? Math.ceil(Math.ceil(width / 32) * Math.ceil(height / 32) * multiplier) : 0;
|
|
140
|
+
return Math.min(OPENAI_IMAGE_TOKENS_MAX, Math.max(tiled, patched));
|
|
141
|
+
}
|
|
142
|
+
/** The multiplier OpenAI bills a patch-billed model's 32 px patches at: 2.46 for a nano model, 1.72 for o4-mini (and
|
|
143
|
+
* codex-mini, built on it), 1.62 for another mini model (gpt-4o-mini excepted: it bills tiles); 0 for a tile-billed
|
|
144
|
+
* model; 2.46, the largest, for a model not named. */
|
|
145
|
+
export function openaiPatchMultiplier(model) {
|
|
146
|
+
if (model === undefined)
|
|
147
|
+
return 2.46;
|
|
148
|
+
if (/nano/i.test(model))
|
|
149
|
+
return 2.46;
|
|
150
|
+
if (/o4-mini|codex-mini/i.test(model))
|
|
151
|
+
return 1.72;
|
|
152
|
+
if (/mini/i.test(model) && !/4o-mini/i.test(model))
|
|
153
|
+
return 1.62;
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
/** What Gemini bills a picture as at the most ("Media resolution" and "Image understanding" in its API docs): 258 tokens
|
|
157
|
+
* an image at most 384 px on each side, else 258 for each 768 px tile; and a picture at Gemini 3's high media resolution
|
|
158
|
+
* 1,120 tokens. The more of the two. */
|
|
159
|
+
export const GEMINI_HIGH_RESOLUTION_TOKENS = 1_120;
|
|
160
|
+
export function geminiImageTokens(width, height) {
|
|
161
|
+
const tiled = width <= 384 && height <= 384 ? 258 : 258 * Math.ceil(width / 768) * Math.ceil(height / 768);
|
|
162
|
+
return Math.max(tiled, GEMINI_HIGH_RESOLUTION_TOKENS);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The most tokens `image` is billed as by the routed `model`'s provider: Anthropic's, OpenAI's or Google's rule by its
|
|
166
|
+
* size; for a model of another provider, or of none known, the most any of the three rules bills it as. An image whose
|
|
167
|
+
* size cannot be read counts at the largest per-image maximum documented, `OPENAI_IMAGE_TOKENS_MAX` (Anthropic's own,
|
|
168
|
+
* `ANTHROPIC_IMAGE_TOKENS_MAX`, on a Claude model), never at its bytes.
|
|
169
|
+
*/
|
|
170
|
+
export function imageTokens(model, image) {
|
|
171
|
+
const provider = imageProviderOf(model);
|
|
172
|
+
if (image.width === undefined || image.height === undefined)
|
|
173
|
+
return provider === "anthropic" ? ANTHROPIC_IMAGE_TOKENS_MAX : OPENAI_IMAGE_TOKENS_MAX;
|
|
174
|
+
const { width, height } = image;
|
|
175
|
+
if (provider === "anthropic")
|
|
176
|
+
return anthropicImageTokens(width, height);
|
|
177
|
+
if (provider === "openai")
|
|
178
|
+
return openaiImageTokens(width, height, model, image.detail);
|
|
179
|
+
if (provider === "google")
|
|
180
|
+
return geminiImageTokens(width, height);
|
|
181
|
+
// Of no provider known: every OpenAI rule (no model named), beside Anthropic's and Google's.
|
|
182
|
+
return Math.max(anthropicImageTokens(width, height), openaiImageTokens(width, height), geminiImageTokens(width, height));
|
|
183
|
+
}
|
|
184
|
+
/** The pixel size an image's base64 `data` says in its own header (PNG, JPEG, GIF or WebP), or undefined: another format,
|
|
185
|
+
* or a header that cannot be read. Only its start is decoded (a JPEG's frame header within its first 256 KiB). */
|
|
186
|
+
export function imageSizeOf(data) {
|
|
187
|
+
const head = Buffer.from(data.slice(0, 349_528), "base64");
|
|
188
|
+
const sized = (width, height) => (width > 0 && height > 0 ? { width, height } : undefined);
|
|
189
|
+
if (head.length >= 24 && head.readUInt32BE(0) === 0x89504e47 && head.toString("latin1", 12, 16) === "IHDR")
|
|
190
|
+
return sized(head.readUInt32BE(16), head.readUInt32BE(20));
|
|
191
|
+
if (head.length >= 10 && head.toString("latin1", 0, 4) === "GIF8")
|
|
192
|
+
return sized(head.readUInt16LE(6), head.readUInt16LE(8));
|
|
193
|
+
if (head.length >= 30 && head.toString("latin1", 0, 4) === "RIFF" && head.toString("latin1", 8, 12) === "WEBP") {
|
|
194
|
+
const kind = head.toString("latin1", 12, 16);
|
|
195
|
+
if (kind === "VP8X")
|
|
196
|
+
return sized(1 + head.readUIntLE(24, 3), 1 + head.readUIntLE(27, 3));
|
|
197
|
+
if (kind === "VP8L") {
|
|
198
|
+
const bits = head.readUInt32LE(21);
|
|
199
|
+
return sized(1 + (bits & 0x3fff), 1 + ((bits >>> 14) & 0x3fff));
|
|
200
|
+
}
|
|
201
|
+
if (kind === "VP8 ")
|
|
202
|
+
return sized(head.readUInt16LE(26) & 0x3fff, head.readUInt16LE(28) & 0x3fff);
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
if (head.length >= 4 && head[0] === 0xff && head[1] === 0xd8) {
|
|
206
|
+
// Walk the segments to a start-of-frame marker (SOF0-SOF15, but not DHT, JPG or DAC), which holds the height then width.
|
|
207
|
+
for (let at = 2; at + 9 <= head.length;) {
|
|
208
|
+
if (head[at] !== 0xff)
|
|
209
|
+
return undefined;
|
|
210
|
+
const marker = head[at + 1];
|
|
211
|
+
if (marker === 0xff) {
|
|
212
|
+
at += 1;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (marker === 0xd8 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) {
|
|
216
|
+
at += 2;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc)
|
|
220
|
+
return sized(head.readUInt16BE(at + 7), head.readUInt16BE(at + 5));
|
|
221
|
+
at += 2 + head.readUInt16BE(at + 2);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
const plain = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
227
|
+
const list = (value) => (Array.isArray(value) ? value : []);
|
|
228
|
+
/** A Messages body's images, only where the API reads one as an image: a block of a message's content, or of a
|
|
229
|
+
* tool_result's content, in every turn. Each is a base64 source's data, or a URL's (no bytes). An image-shaped object
|
|
230
|
+
* anywhere else (a tool call's arguments) is text to the provider: its bytes stay counted as they are. */
|
|
231
|
+
export function messagesImagesIn(messages) {
|
|
232
|
+
const out = [];
|
|
233
|
+
const image = (block) => {
|
|
234
|
+
if (plain(block) && block.type === "image")
|
|
235
|
+
out.push(plain(block.source) && block.source.type === "base64" ? imageInputOf(block.source.data) : { bytes: 0 });
|
|
236
|
+
};
|
|
237
|
+
for (const message of list(messages)) {
|
|
238
|
+
if (!plain(message))
|
|
239
|
+
continue;
|
|
240
|
+
for (const block of list(message.content)) {
|
|
241
|
+
image(block);
|
|
242
|
+
if (plain(block) && block.type === "tool_result")
|
|
243
|
+
for (const inner of list(block.content))
|
|
244
|
+
image(inner);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return out;
|
|
248
|
+
}
|
|
249
|
+
/** A Responses body's images, only where the API reads one as an image: an `input_image` item, a part of an item's
|
|
250
|
+
* content, or a part of a function call's output, in every turn. Each is a data URL's, or a URL's or file id's (no
|
|
251
|
+
* bytes). An image-shaped object anywhere else is text to the provider: its bytes stay counted as they are. */
|
|
252
|
+
export function responsesImagesIn(input) {
|
|
253
|
+
const out = [];
|
|
254
|
+
const image = (part) => {
|
|
255
|
+
if (plain(part) && part.type === "input_image")
|
|
256
|
+
out.push({ ...imageInputOf(part.image_url), ...(typeof part.detail === "string" ? { detail: part.detail } : {}) });
|
|
257
|
+
};
|
|
258
|
+
for (const item of list(input)) {
|
|
259
|
+
if (!plain(item))
|
|
260
|
+
continue;
|
|
261
|
+
image(item);
|
|
262
|
+
for (const part of list(item.content))
|
|
263
|
+
image(part);
|
|
264
|
+
if (item.type === "function_call_output")
|
|
265
|
+
for (const part of list(item.output))
|
|
266
|
+
image(part);
|
|
267
|
+
}
|
|
268
|
+
return out;
|
|
269
|
+
}
|
|
270
|
+
/** The image a body's `data` (base64, or a data URL) carries: the bytes it takes, and its size when its header says it.
|
|
271
|
+
* Anything else (an http URL, a file id): no bytes, no size. */
|
|
272
|
+
export function imageInputOf(data) {
|
|
273
|
+
if (typeof data !== "string")
|
|
274
|
+
return { bytes: 0 };
|
|
275
|
+
const base64 = /^data:[^,]*;base64,/i.exec(data);
|
|
276
|
+
if (data.startsWith("data:") && !base64)
|
|
277
|
+
return { bytes: 0 };
|
|
278
|
+
const payload = base64 ? data.slice(base64[0].length) : data;
|
|
279
|
+
// A URL the provider fetches is billed by the image it finds, and only its own bytes are in the body.
|
|
280
|
+
if (!base64 && /^[a-z][a-z0-9+.-]*:\/\//i.test(data))
|
|
281
|
+
return { bytes: 0 };
|
|
282
|
+
const size = imageSizeOf(payload);
|
|
283
|
+
// Its whole string, once JSON writes it: base64 and a data URL's prefix need no escaping.
|
|
284
|
+
return { bytes: Buffer.byteLength(JSON.stringify(data), "utf8") - 2, ...(size ?? {}) };
|
|
75
285
|
}
|
package/dist/host/proxy.d.ts
CHANGED
|
@@ -70,14 +70,20 @@ export interface ProviderPolicy {
|
|
|
70
70
|
* smaller one for a client's background calls). The runner is asked about, and the price taken for, that model.
|
|
71
71
|
* Absent, or undefined for a body: the session's model. */
|
|
72
72
|
modelOf?(body: Record<string, unknown>): string | undefined;
|
|
73
|
-
/** The input tokens the provider bills for the body `apply` returned
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
73
|
+
/** The input tokens the provider bills for the body `apply` returned beyond its bytes: a prompt it adds itself, such as
|
|
74
|
+
* a tool-use system prompt, and each image at what it is billed as in place of the bytes its data takes in the body
|
|
75
|
+
* (`providerInputOverhead`), which can make it less than 0. Added to the body's bytes for `inputTokensMax`; the sum
|
|
76
|
+
* below 0 is no bound (unmeasured). Undefined: the body has no input bound the policy can state (a hosted tool that
|
|
77
|
+
* reads pages into the input), so `inputTokensMax` is undefined, never 0 or the body's bytes alone. Absent: none. */
|
|
77
78
|
serverInputOverhead?(body: Record<string, unknown>): number | undefined;
|
|
78
79
|
/** The output tokens the body `apply` returned asks for at most (its own limit, as `apply` shaped it). Absent or
|
|
79
80
|
* undefined: the body does not say. */
|
|
80
81
|
outputAsked?(body: Record<string, unknown>): number | undefined;
|
|
82
|
+
/** The provider's own count of a request's input tokens (Anthropic's free count_tokens), which the proxy asks before
|
|
83
|
+
* each of the session's answer requests (`countedInputOf`) when its upstream is exactly `origin`, the provider's own: never
|
|
84
|
+
* through a gateway or any other base, so the key and the request go nowhere the request itself would not. Its count,
|
|
85
|
+
* plus `margin`, is that request's input bound when it is below the byte bound. Absent: never counted. */
|
|
86
|
+
countInput?: InputCounter;
|
|
81
87
|
/** The least output the body may be limited to and still answer: 1,024 tokens for the answer, plus the least thinking
|
|
82
88
|
* its provider takes when it thinks. Absent: 1,024. */
|
|
83
89
|
outputLeast?(body: Record<string, unknown>): number;
|
|
@@ -178,6 +184,9 @@ export interface ProxyRequest {
|
|
|
178
184
|
noted?: true;
|
|
179
185
|
/** The label of the side key it came under (ModelProxy.sideKey): the host's own request, beside the harness's. */
|
|
180
186
|
host?: string;
|
|
187
|
+
/** Its `inputTokensMax` is its provider's count (ProviderPolicy.countInput), not its bytes: a host that compares one
|
|
188
|
+
* request's bound with another's (how far a conversation grew) pairs a counted bound only with a counted one. */
|
|
189
|
+
inputTokensCounted?: true;
|
|
181
190
|
}
|
|
182
191
|
export interface ModelProxyHooks {
|
|
183
192
|
/** Before a paid request leaves; a throw refuses it. What it returns (a ticket) is handed back to this request's
|
|
@@ -200,6 +209,10 @@ export interface ModelProxyOptions {
|
|
|
200
209
|
hooks: ModelProxyHooks;
|
|
201
210
|
/** The session's model, as the runner names it to `beforeRequest`. The policy fixes the body's model. */
|
|
202
211
|
model: string;
|
|
212
|
+
/** This proxy's route among the session's, told to `beforeRequest` with each request (ModelRequest.route) so the host
|
|
213
|
+
* prices it at this proxy's price: a proxy beside the session's for another tier's model names its tier. Absent: the
|
|
214
|
+
* session's own. */
|
|
215
|
+
route?: string;
|
|
203
216
|
/** The provider's base: its origin and, for a gateway that serves the API under a path, that path
|
|
204
217
|
* (`https://api.example.com`, `https://gateway.example/api`). A route's path is appended to it. A base with userinfo, a
|
|
205
218
|
* query or a fragment is refused, so the key goes only where the base reads. */
|
|
@@ -293,6 +306,29 @@ export declare function matchRoute(routes: readonly ProxyRoute[], method: string
|
|
|
293
306
|
export declare function parseStrict(text: string): unknown;
|
|
294
307
|
/** Whether `given` is `key`, in time that does not depend on where they differ. */
|
|
295
308
|
export declare const sameKey: (given: string, key: string) => boolean;
|
|
309
|
+
/** A provider's endpoint that counts a request's input tokens (ProviderPolicy.countInput). */
|
|
310
|
+
export interface InputCounter {
|
|
311
|
+
/** The provider's own base (`https://api.anthropic.com`): counted only when the session's upstream is exactly it. */
|
|
312
|
+
readonly origin: string;
|
|
313
|
+
/** The counting endpoint's path under it (`/v1/messages/count_tokens`). */
|
|
314
|
+
readonly path: string;
|
|
315
|
+
/** The body to count, from the request's (the fields the endpoint takes). */
|
|
316
|
+
body(body: Record<string, unknown>): Record<string, unknown>;
|
|
317
|
+
/** The headers to send it, from the request's as the proxy sends them (its credential and version headers among them). */
|
|
318
|
+
headers(sent: Record<string, string>): Record<string, string>;
|
|
319
|
+
/** The input tokens its answer says, or undefined when it says none. */
|
|
320
|
+
tokensOf(answer: unknown): number | undefined;
|
|
321
|
+
/** What the provider bills beside the count, which the count may leave out (a tool-use system prompt): added to it. */
|
|
322
|
+
margin?(body: Record<string, unknown>): number;
|
|
323
|
+
}
|
|
324
|
+
/** How long a count may take before the request goes on its byte bound: a count never holds a request up for long. */
|
|
325
|
+
export declare const COUNT_TIMEOUT_MS = 3000;
|
|
326
|
+
/**
|
|
327
|
+
* The exact input tokens of a request with body `body`, by its provider's own count (`policy.countInput`), plus its
|
|
328
|
+
* margin; undefined (the request keeps its byte bound) when the policy has no counter, the upstream `origin` is not
|
|
329
|
+
* the counter's own, or the count fails, times out or says no count. Never throws: a count is only ever a tighter bound.
|
|
330
|
+
*/
|
|
331
|
+
export declare function countedInputOf(policy: ProviderPolicy, origin: string, body: Record<string, unknown>, headers: Record<string, string>, fetch: typeof globalThis.fetch, say?: (message: string, detail?: Record<string, unknown>) => void, timeoutMs?: number, signal?: AbortSignal): Promise<number | undefined>;
|
|
296
332
|
/** Start a session's model proxy on the loopback interface, admitting `key`. */
|
|
297
333
|
/**
|
|
298
334
|
* The most input tokens a request with body `sent` (the body `apply` returned, as it is sent) can be billed for: its UTF-8
|
package/dist/host/proxy.js
CHANGED
|
@@ -582,6 +582,41 @@ function baseOf(base) {
|
|
|
582
582
|
throw new Error("agentrun-kernel: a model proxy's base is an origin and a path, with no userinfo, query, fragment or backslash");
|
|
583
583
|
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
584
584
|
}
|
|
585
|
+
/** How long a count may take before the request goes on its byte bound: a count never holds a request up for long. */
|
|
586
|
+
export const COUNT_TIMEOUT_MS = 3_000;
|
|
587
|
+
/**
|
|
588
|
+
* The exact input tokens of a request with body `body`, by its provider's own count (`policy.countInput`), plus its
|
|
589
|
+
* margin; undefined (the request keeps its byte bound) when the policy has no counter, the upstream `origin` is not
|
|
590
|
+
* the counter's own, or the count fails, times out or says no count. Never throws: a count is only ever a tighter bound.
|
|
591
|
+
*/
|
|
592
|
+
export async function countedInputOf(policy, origin, body, headers, fetch, say = () => { }, timeoutMs = COUNT_TIMEOUT_MS, signal) {
|
|
593
|
+
const counter = policy.countInput;
|
|
594
|
+
if (!counter)
|
|
595
|
+
return undefined;
|
|
596
|
+
try {
|
|
597
|
+
if (baseOf(counter.origin) !== origin)
|
|
598
|
+
return undefined;
|
|
599
|
+
// Cut at its timeout, or when `signal` aborts (its client went).
|
|
600
|
+
const cut = signal ? AbortSignal.any([AbortSignal.timeout(timeoutMs), signal]) : AbortSignal.timeout(timeoutMs);
|
|
601
|
+
const response = await fetch(`${origin}${counter.path}`, { method: "POST", headers: { ...counter.headers(headers), "content-type": "application/json" }, body: JSON.stringify(counter.body(body)), signal: cut });
|
|
602
|
+
if (!response.ok) {
|
|
603
|
+
await response.body?.cancel().catch(() => undefined);
|
|
604
|
+
say(`model proxy (${policy.id}): the provider's token count answered ${response.status}; the request keeps its byte bound`);
|
|
605
|
+
return undefined;
|
|
606
|
+
}
|
|
607
|
+
const tokens = counter.tokensOf(await response.json());
|
|
608
|
+
const margin = counter.margin ? counter.margin(body) : 0;
|
|
609
|
+
if (!Number.isSafeInteger(tokens) || tokens < 0 || !Number.isSafeInteger(margin) || margin < 0) {
|
|
610
|
+
say(`model proxy (${policy.id}): the provider's token count said no count; the request keeps its byte bound`);
|
|
611
|
+
return undefined;
|
|
612
|
+
}
|
|
613
|
+
return tokens + margin;
|
|
614
|
+
}
|
|
615
|
+
catch (error) {
|
|
616
|
+
say(`model proxy (${policy.id}): the provider's token count failed; the request keeps its byte bound`, { error: String(error?.message ?? error).slice(0, 200) });
|
|
617
|
+
return undefined;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
585
620
|
/** Start a session's model proxy on the loopback interface, admitting `key`. */
|
|
586
621
|
/**
|
|
587
622
|
* The most input tokens a request with body `sent` (the body `apply` returned, as it is sent) can be billed for: its UTF-8
|
|
@@ -598,9 +633,13 @@ export function inputTokensMaxOf(policy, body, sent, say = () => { }) {
|
|
|
598
633
|
const overhead = policy.serverInputOverhead ? policy.serverInputOverhead(body) : 0;
|
|
599
634
|
if (overhead === undefined)
|
|
600
635
|
return undefined;
|
|
601
|
-
if (typeof overhead !== "number" || !Number.isSafeInteger(overhead)
|
|
636
|
+
if (typeof overhead !== "number" || !Number.isSafeInteger(overhead))
|
|
602
637
|
throw new Error(`not a token count: ${String(overhead).slice(0, 40)}`);
|
|
603
|
-
|
|
638
|
+
// Below 0 only by images' data the body carries (counted at what they are billed as instead): never past the bytes.
|
|
639
|
+
const bound = Buffer.byteLength(sent, "utf8") + overhead;
|
|
640
|
+
if (bound < 0)
|
|
641
|
+
throw new Error(`the policy counted ${-overhead} more bytes as billed apart than the body's ${Buffer.byteLength(sent, "utf8")}`);
|
|
642
|
+
return bound;
|
|
604
643
|
}
|
|
605
644
|
catch (error) {
|
|
606
645
|
say(`model proxy (${policy.id}): the policy could not say what the provider adds to the body's input; its input is unmeasured`, { error: String(error?.message ?? error).slice(0, 200) });
|
|
@@ -856,6 +895,36 @@ export async function startModelProxy(options, key) {
|
|
|
856
895
|
// admitted or booked, until the harness opens its next turn.
|
|
857
896
|
if (answering && !route.free && stopTold !== undefined)
|
|
858
897
|
return refuse(res, refusedStatus, `refused: the turn's answer was ${stopTold}, and the turn ends there`, req);
|
|
898
|
+
// An answer request on an upstream that is its provider's own (policy.countInput): its input bound is the provider's
|
|
899
|
+
// exact count when that is below its bytes, so a small cap admits a first turn its bytes would not. Each answer request
|
|
900
|
+
// is counted, not only the first: the cap prices a step by the last one's tokens plus how far its bound grew, so a
|
|
901
|
+
// counted bound beside a byte bound would read the bytes as growth. A count that fails or times out leaves the byte
|
|
902
|
+
// bound, and never holds the request up for long. A noted request is counted with its note, which bounds it without
|
|
903
|
+
// the note too (the note only adds).
|
|
904
|
+
// Only a bound that is a number is lowered: an unmeasured one (a fee with no bound, a hosted tool's reads) stays so.
|
|
905
|
+
let inputTokensCounted = false;
|
|
906
|
+
if (answering && !route.free && host === undefined && inputTokensMax !== undefined && policy.countInput) {
|
|
907
|
+
// A client that goes while its request is counted is gone before anything is admitted: the count is cut, and the
|
|
908
|
+
// request is neither admitted nor sent (nothing is booked, and no paid answer starts for no one).
|
|
909
|
+
const gone = new AbortController();
|
|
910
|
+
const onGone = () => gone.abort(new Error("the client went while its request was counted"));
|
|
911
|
+
res.once("close", onGone);
|
|
912
|
+
let counted;
|
|
913
|
+
try {
|
|
914
|
+
counted = await countedInputOf(policy, origin, body, headers, forward, say, COUNT_TIMEOUT_MS, gone.signal);
|
|
915
|
+
}
|
|
916
|
+
finally {
|
|
917
|
+
res.off("close", onGone);
|
|
918
|
+
}
|
|
919
|
+
if (gone.signal.aborted || res.destroyed)
|
|
920
|
+
return;
|
|
921
|
+
if (counted !== undefined && inputTokensMax !== undefined && counted < inputTokensMax) {
|
|
922
|
+
inputTokensMax = counted;
|
|
923
|
+
inputTokensCounted = true;
|
|
924
|
+
if (inputTokensMaxWithoutNote !== undefined)
|
|
925
|
+
inputTokensMaxWithoutNote = Math.min(inputTokensMaxWithoutNote, counted);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
859
928
|
// This request's own admission, handed back to its booking (requests may be in flight together).
|
|
860
929
|
let ticket;
|
|
861
930
|
try {
|
|
@@ -867,6 +936,8 @@ export async function startModelProxy(options, key) {
|
|
|
867
936
|
...(outputTokensAsked === undefined ? {} : { outputTokensAsked }),
|
|
868
937
|
...(outputTokensLeast === undefined ? {} : { outputTokensLeast }),
|
|
869
938
|
...(host === undefined ? {} : { host }),
|
|
939
|
+
...(inputTokensCounted ? { inputTokensCounted: true } : {}),
|
|
940
|
+
...(options.route === undefined ? {} : { route: options.route }),
|
|
870
941
|
});
|
|
871
942
|
}
|
|
872
943
|
catch (error) {
|
|
@@ -3,7 +3,7 @@ export { capRule, noteFor, type Judged, type JudgeState, type NoteState } from "
|
|
|
3
3
|
export { beforeRequestOf, type BeforeRequestOptions } from "./port.js";
|
|
4
4
|
export { DECISION_SESSION, overCapOf, paidCalls, runCap, TOOL_SESSION, type RunCap, type RunCapOptions, type RunDecisions, type RunTools } from "./run-cap.js";
|
|
5
5
|
export { ANSWER_TOKENS_LEAST, CACHE_WARM_MS, CAP_TOLERANCE, FIT_TOLERANCE, STOP_ALLOWANCE_TOKENS, THINKING_BUDGET_LEAST, expectedInput, inputBound, mostOutput, pricingOf, ratesFor, requestPrice } from "./price.js";
|
|
6
|
-
export { CAP_REFUSAL_CODE, SPEND_CAP_REACHED, SUGGESTED_RAISE_FACTOR, centsMoney, leastMoney, money, OVER_CAP_END, overCapEnd, overCapMessage, overCapWords, raiseFigure, raiseTo, suggestedRaise } from "./words.js";
|
|
6
|
+
export { CAP_REFUSAL_CODE, SPEND_CAP_REACHED, SUGGESTED_RAISE_FACTOR, centsMoney, leastMoney, money, OVER_CAP_END, overCapEnd, overCapMessage, overCapWords, paidRefusal, raiseFigure, raiseTo, suggestedRaise } from "./words.js";
|
|
7
7
|
export { checkRaise, followUpOf, parkOf, takeRaises, type BudgetPending, type Park, type RaiseCheck, type RaiseState } from "./park.js";
|
|
8
8
|
export { WRAP_UP_FACTOR, WRAP_UP_LEAST_FACTOR, WRAP_UP_STEP0_ANSWER_TOKENS, typicalCost, wrapUpDue, wrapUpWords } from "./wrap-up.js";
|
|
9
9
|
export { CapStop, createStepWaits, type StepWaits } from "./steps.js";
|
package/dist/kernel/cap/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export { capRule, noteFor } from "./rule.js";
|
|
|
5
5
|
export { beforeRequestOf } from "./port.js";
|
|
6
6
|
export { DECISION_SESSION, overCapOf, paidCalls, runCap, TOOL_SESSION } from "./run-cap.js";
|
|
7
7
|
export { ANSWER_TOKENS_LEAST, CACHE_WARM_MS, CAP_TOLERANCE, FIT_TOLERANCE, STOP_ALLOWANCE_TOKENS, THINKING_BUDGET_LEAST, expectedInput, inputBound, mostOutput, pricingOf, ratesFor, requestPrice } from "./price.js";
|
|
8
|
-
export { CAP_REFUSAL_CODE, SPEND_CAP_REACHED, SUGGESTED_RAISE_FACTOR, centsMoney, leastMoney, money, OVER_CAP_END, overCapEnd, overCapMessage, overCapWords, raiseFigure, raiseTo, suggestedRaise } from "./words.js";
|
|
8
|
+
export { CAP_REFUSAL_CODE, SPEND_CAP_REACHED, SUGGESTED_RAISE_FACTOR, centsMoney, leastMoney, money, OVER_CAP_END, overCapEnd, overCapMessage, overCapWords, paidRefusal, raiseFigure, raiseTo, suggestedRaise } from "./words.js";
|
|
9
9
|
export { checkRaise, followUpOf, parkOf, takeRaises } from "./park.js";
|
|
10
10
|
export { WRAP_UP_FACTOR, WRAP_UP_LEAST_FACTOR, WRAP_UP_STEP0_ANSWER_TOKENS, typicalCost, wrapUpDue, wrapUpWords } from "./wrap-up.js";
|
|
11
11
|
export { CapStop, createStepWaits } from "./steps.js";
|
|
@@ -3,8 +3,9 @@ import type { CapMode, CapModel, Previous } from "./types.js";
|
|
|
3
3
|
export interface BeforeRequestOptions {
|
|
4
4
|
/** The run's cap, read before every request. Undefined: no cap, nothing refused. */
|
|
5
5
|
capUsd(): number | undefined;
|
|
6
|
-
/** A model as the cap prices it, by its id
|
|
7
|
-
|
|
6
|
+
/** A model as the cap prices it, by its id and the route its request came by (ModelRequest.route; absent, the
|
|
7
|
+
* session's own): one id two routes price apart is priced as its route books it. Undefined: a model with no price here. */
|
|
8
|
+
modelOf(id: string, route?: string): CapModel | undefined;
|
|
8
9
|
/** The session's previous request on a model, as its usage reported it: none prices the input uncached. */
|
|
9
10
|
previousOf?(model: string): Previous | undefined;
|
|
10
11
|
/** What the run spent beside the session's model requests, which the runner's booking does not hold: its priced tools'
|
package/dist/kernel/cap/port.js
CHANGED
|
@@ -20,7 +20,7 @@ export function beforeRequestOf(options) {
|
|
|
20
20
|
// any paid step, so every refusable step after it sees it. Only a figure is money: one that is not goes to the rule.
|
|
21
21
|
if (request.paid?.owed && isFigure(request.feeUsd ?? 0))
|
|
22
22
|
return { holdUsd: request.feeUsd ?? 0 };
|
|
23
|
-
const model = options.modelOf(request.model) ?? unpriced(request.model);
|
|
23
|
+
const model = options.modelOf(request.model, request.route) ?? unpriced(request.model);
|
|
24
24
|
// A request the host sends beside the harness's own (its host label: a learned workflow's node) is another
|
|
25
25
|
// conversation's prompt: nothing of the session's cache is read for it, so it is priced as a cache miss.
|
|
26
26
|
const previous = request.host === undefined ? options.previousOf?.(request.model) : undefined;
|
|
@@ -39,7 +39,7 @@ export function beforeRequestOf(options) {
|
|
|
39
39
|
// neither (no hold, no price or no measure) cannot be kept within the cap: refused for good, as an unmeasured input.
|
|
40
40
|
let inFlight = 0;
|
|
41
41
|
for (const flight of request.inFlight) {
|
|
42
|
-
const figure = isFigure(flight.holdUsd) ? flight.holdUsd : worstOf(options.modelOf(flight.model), flight.inputTokensMax, flight.outputTokensMax);
|
|
42
|
+
const figure = isFigure(flight.holdUsd) ? flight.holdUsd : worstOf(options.modelOf(flight.model, flight.route), flight.inputTokensMax, flight.outputTokensMax);
|
|
43
43
|
if (figure === undefined)
|
|
44
44
|
return { refuse: unmeasured(capUsd), code: SPEND_CAP_REACHED };
|
|
45
45
|
inFlight += figure;
|
package/dist/kernel/cap/price.js
CHANGED
|
@@ -70,8 +70,11 @@ export function inputBound(request) {
|
|
|
70
70
|
const measured = request.inputTokens;
|
|
71
71
|
if (typeof measured !== "number" || !Number.isFinite(measured) || measured < 0)
|
|
72
72
|
return undefined;
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
// Below 0 only by images' data counted at their billed size instead; a shape that says more such bytes than were
|
|
74
|
+
// measured is no bound.
|
|
75
|
+
const added = request.shape ? providerInputOverhead(request.model.api, { model: request.model.id, ...request.shape }) : 0;
|
|
76
|
+
const bound = measured + added + (request.extraInputTokens ?? 0);
|
|
77
|
+
return bound < 0 ? undefined : bound;
|
|
75
78
|
}
|
|
76
79
|
/** The output a request is sent with at most: what it asks (its model's ceiling when it says none), and its thinking budget
|
|
77
80
|
* on an API whose thinking takes one, within the ceiling. Undefined: no ceiling and none asked. */
|
|
@@ -11,8 +11,8 @@ export interface RunCapOptions {
|
|
|
11
11
|
capUsd(): number | undefined;
|
|
12
12
|
readonly mode?: CapMode;
|
|
13
13
|
readonly now?: () => number;
|
|
14
|
-
/** The run's model requests' models (its decisions' are the cap's own). */
|
|
15
|
-
modelOf(id: string): CapModel | undefined;
|
|
14
|
+
/** The run's model requests' models, by id and route (BeforeRequestOptions.modelOf; its decisions' are the cap's own). */
|
|
15
|
+
modelOf(id: string, route?: string): CapModel | undefined;
|
|
16
16
|
previousOf?(model: string): Previous | undefined;
|
|
17
17
|
/** The run's priced tools' charges and holds beside its requests (beforeRequestOf's), when it has any. */
|
|
18
18
|
spentUsd?(): number | null;
|
|
@@ -40,7 +40,7 @@ export function runCap(options) {
|
|
|
40
40
|
capUsd: options.capUsd,
|
|
41
41
|
mode,
|
|
42
42
|
...(options.now ? { now: options.now } : {}),
|
|
43
|
-
modelOf: (id) => deciding.get(id) ?? options.modelOf(id),
|
|
43
|
+
modelOf: (id, route) => deciding.get(id) ?? options.modelOf(id, route),
|
|
44
44
|
...(options.previousOf ? { previousOf: (model) => (deciding.has(model) ? undefined : options.previousOf(model)) } : {}),
|
|
45
45
|
...(options.spentUsd ? { spentUsd: options.spentUsd } : {}),
|
|
46
46
|
...(options.heldUsd ? { heldUsd: options.heldUsd } : {}),
|
|
@@ -111,6 +111,13 @@ export interface RefusalFigures {
|
|
|
111
111
|
readonly needsUsd: number;
|
|
112
112
|
readonly leastCapUsd: number;
|
|
113
113
|
readonly boundUsd?: number;
|
|
114
|
+
/** A paid call's refusal: the call (its name, hold and basis), so a pause that lands after the refusal can say it again
|
|
115
|
+
* with the run's spend as it is then (paidRefusal). */
|
|
116
|
+
readonly step?: {
|
|
117
|
+
readonly name: string;
|
|
118
|
+
readonly holdUsd: number;
|
|
119
|
+
readonly basis: string;
|
|
120
|
+
};
|
|
114
121
|
}
|
|
115
122
|
/** How a step ended, for settle: a model request's as booking.ts reads it; a paid call's charge (null: it did not say). */
|
|
116
123
|
export type Settled = Ended | {
|
package/dist/kernel/cap/words.js
CHANGED
|
@@ -53,7 +53,7 @@ export function paidRefusal(cap, spent, held, name, holdUsd, basis) {
|
|
|
53
53
|
const leastCapUsd = raiseFigure(cap, spent + held + holdUsd);
|
|
54
54
|
return {
|
|
55
55
|
text: `${SPEND_CAP_REACHED}: Not sent: this run has ${spentOf(spent, held, cap)}, and the next step, ${name}, could cost up to ${money(holdUsd)} (${basis}). Raise the cap to at least $${leastCapUsd.toFixed(2)} to continue.`,
|
|
56
|
-
figures: { spentUsd: spent + held, needsUsd: holdUsd, leastCapUsd },
|
|
56
|
+
figures: { spentUsd: spent + held, needsUsd: holdUsd, leastCapUsd, step: { name, holdUsd, basis } },
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
/** An amount rounded up to the cent, so "at most" holds. */
|
package/dist/process/tools.d.ts
CHANGED
|
@@ -82,6 +82,15 @@ export declare class Mutex {
|
|
|
82
82
|
}
|
|
83
83
|
/** The memo key of a tool call. */
|
|
84
84
|
export declare const toolKey: (callId: string) => string;
|
|
85
|
+
/**
|
|
86
|
+
* The host's gate, asked about a call before anything of it is written: the first step of every harness's tool bridge
|
|
87
|
+
* (this one's, and the faux harness's, run-adapters/testing). Undefined when it allows the call; the refusal for a deny,
|
|
88
|
+
* whose words are the call's answer; a park holds the call until `signal` is aborted (the run parked and this process
|
|
89
|
+
* lets go of it), then rejects, so the harness is never handed a result for it.
|
|
90
|
+
*/
|
|
91
|
+
export declare function askGate(gate: (call: GateCall) => Promise<GateAnswer>, call: GateCall, signal: AbortSignal): Promise<{
|
|
92
|
+
deny: string;
|
|
93
|
+
} | undefined>;
|
|
85
94
|
/**
|
|
86
95
|
* Build the bridge for one drive. The calls' effects are this drive's: build
|
|
87
96
|
* a new bridge per `drive(ctx)`.
|
package/dist/process/tools.js
CHANGED
|
@@ -24,6 +24,20 @@ function parkedUntilAborted(signal, tool) {
|
|
|
24
24
|
signal.addEventListener('abort', parked, { once: true });
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* The host's gate, asked about a call before anything of it is written: the first step of every harness's tool bridge
|
|
29
|
+
* (this one's, and the faux harness's, run-adapters/testing). Undefined when it allows the call; the refusal for a deny,
|
|
30
|
+
* whose words are the call's answer; a park holds the call until `signal` is aborted (the run parked and this process
|
|
31
|
+
* lets go of it), then rejects, so the harness is never handed a result for it.
|
|
32
|
+
*/
|
|
33
|
+
export async function askGate(gate, call, signal) {
|
|
34
|
+
const answer = await gate(call);
|
|
35
|
+
if (answer === 'allow')
|
|
36
|
+
return undefined;
|
|
37
|
+
if ('deny' in answer)
|
|
38
|
+
return answer;
|
|
39
|
+
return parkedUntilAborted(signal, call.tool);
|
|
40
|
+
}
|
|
27
41
|
/**
|
|
28
42
|
* Build the bridge for one drive. The calls' effects are this drive's: build
|
|
29
43
|
* a new bridge per `drive(ctx)`.
|
|
@@ -45,12 +59,11 @@ export function toolBridge(ctx, tools, options = {}) {
|
|
|
45
59
|
const fresh = !ctx.isMemoized(key);
|
|
46
60
|
// The gate first: before the flush and the intent, so a refused or parked call leaves nothing in the log.
|
|
47
61
|
if (fresh && options.gate) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
62
|
+
// An earlier attempt's start in the log (a replay-safe call a crash cut): it may have been sent, and the gate says so.
|
|
63
|
+
const replayed = ctx.state().effects.has(key);
|
|
64
|
+
const refused = await askGate(options.gate, { callId, tool: tool.name, args: (args ?? {}), ...(replayed ? { replayed: true } : {}) }, signal ? AbortSignal.any([signal, ctx.signal]) : ctx.signal);
|
|
65
|
+
if (refused)
|
|
66
|
+
return { text: refused.deny, isError: true };
|
|
54
67
|
}
|
|
55
68
|
if (fresh && tool.replay === 'never')
|
|
56
69
|
await options.beforeNever?.({ name: tool.name, callId, args });
|
package/dist/runner.d.ts
CHANGED
|
@@ -71,6 +71,8 @@ export type BeforeRequest = (request: {
|
|
|
71
71
|
/** The label of a request the host sent beside the harness's own (ModelRequest.host): a learned workflow's model node,
|
|
72
72
|
* under the same check as the harness's own. */
|
|
73
73
|
host?: string;
|
|
74
|
+
/** The route it came by (ModelRequest.route), absent for the session's own: the host prices it by model and route. */
|
|
75
|
+
route?: string;
|
|
74
76
|
/** This session's paid requests admitted and not yet answered (in this process), oldest first, each with its own
|
|
75
77
|
* `inputTokensMax`, the output limit it was admitted with (`outputTokensMax`) and what its host held for it
|
|
76
78
|
* (`holdUsd`): a budget holds each one until it answers, since `spentUsd` counts answered requests only. Requests are
|
|
@@ -88,6 +90,11 @@ export type Refusal = {
|
|
|
88
90
|
needsUsd: number;
|
|
89
91
|
leastCapUsd: number;
|
|
90
92
|
boundUsd?: number;
|
|
93
|
+
step?: {
|
|
94
|
+
name: string;
|
|
95
|
+
holdUsd: number;
|
|
96
|
+
basis: string;
|
|
97
|
+
};
|
|
91
98
|
};
|
|
92
99
|
/** The refusal's code, from a host that gives one (a spend cap's: `spend_cap_reached`): carried on the error that ends
|
|
93
100
|
* the node (HarnessRunError.refusal), so a reader knows the refusal by it, never by its words. */
|
|
@@ -102,6 +109,7 @@ export type InFlight = {
|
|
|
102
109
|
outputTokensMax?: number;
|
|
103
110
|
holdUsd?: number;
|
|
104
111
|
host?: string;
|
|
112
|
+
route?: string;
|
|
105
113
|
};
|
|
106
114
|
/** A host's admission: what it holds for the request (`holdUsd`), and the most output tokens, thinking included, it may
|
|
107
115
|
* be sent with (`outputTokensMax`, what is left of a cap can buy), which its ticket carries to the model proxy. A
|
package/dist/runner.js
CHANGED
|
@@ -179,7 +179,7 @@ function bookingFor(writer, options) {
|
|
|
179
179
|
// A paid request whose cost couldn't be recorded stops the booking itself, whether or not the host gave it a stop.
|
|
180
180
|
let failed;
|
|
181
181
|
const end = (reason, message, code) => options.stop ? options.stop(reason, message, code) : new HarnessRunError(reason, turns, 0, { maxTurns: limit, ...(message === undefined ? {} : { message }), ...(code === undefined ? {} : { refusal: code }) });
|
|
182
|
-
const admit = async ({ model, inputTokensMax: measured, outputTokensAsked, outputTokensLeast, feeUsd, paid, side, noted, inputTokensMaxWithoutNote, host }) => {
|
|
182
|
+
const admit = async ({ model, inputTokensMax: measured, outputTokensAsked, outputTokensLeast, feeUsd, paid, side, noted, inputTokensMaxWithoutNote, host, route }) => {
|
|
183
183
|
let inputTokensMax = measured;
|
|
184
184
|
const stopped = options.stopped?.(host === undefined ? {} : { host }) ?? failed;
|
|
185
185
|
if (stopped)
|
|
@@ -190,7 +190,7 @@ function bookingFor(writer, options) {
|
|
|
190
190
|
if (limit !== null && turns >= limit)
|
|
191
191
|
throw end("turn_limit");
|
|
192
192
|
const verdict = await options.beforeRequest?.({ ...node, model, turn: turns + 1, maxTurns: limit, ...(options.budgetUsd === undefined ? {} : { budgetUsd: options.budgetUsd }), spentUsd, inFlight: open.map((f) => ({ ...f })), inputTokensMax,
|
|
193
|
-
...(outputTokensAsked === undefined ? {} : { outputTokensAsked }), ...(outputTokensLeast === undefined ? {} : { outputTokensLeast }), ...(feeUsd === undefined ? {} : { feeUsd }), ...(paid ? { paid } : {}), ...(side ? { side } : {}), ...(noted ? { noted, ...(inputTokensMaxWithoutNote === undefined ? {} : { inputTokensMaxWithoutNote }) } : {}), ...(host === undefined ? {} : { host }) });
|
|
193
|
+
...(outputTokensAsked === undefined ? {} : { outputTokensAsked }), ...(outputTokensLeast === undefined ? {} : { outputTokensLeast }), ...(feeUsd === undefined ? {} : { feeUsd }), ...(paid ? { paid } : {}), ...(side ? { side } : {}), ...(noted ? { noted, ...(inputTokensMaxWithoutNote === undefined ? {} : { inputTokensMaxWithoutNote }) } : {}), ...(host === undefined ? {} : { host }), ...(route === undefined ? {} : { route }) });
|
|
194
194
|
if (verdict && "refuse" in verdict)
|
|
195
195
|
throw end("refused", verdict.refuse, typeof verdict.code === "string" ? verdict.code : undefined);
|
|
196
196
|
const hold = verdict && "holdUsd" in verdict ? heldFigure(verdict.holdUsd) : undefined;
|
|
@@ -257,7 +257,7 @@ function bookingFor(writer, options) {
|
|
|
257
257
|
emit({ type: "request_end", turn, usage: { input: 0, output: 0, cacheRead: 0, usd: 0 }, ...(host === undefined ? {} : { host }), ended: { end: "nothing", label: "never_left" } });
|
|
258
258
|
throw stoppedLate;
|
|
259
259
|
}
|
|
260
|
-
open.push({ turn, model, inputTokensMax, ...(limited === undefined ? {} : { outputTokensMax: limited }), ...(hold === undefined ? {} : { holdUsd: hold }), ...(host === undefined ? {} : { host }) });
|
|
260
|
+
open.push({ turn, model, inputTokensMax, ...(limited === undefined ? {} : { outputTokensMax: limited }), ...(hold === undefined ? {} : { holdUsd: hold }), ...(host === undefined ? {} : { host }), ...(route === undefined ? {} : { route }) });
|
|
261
261
|
return { turn, ...(limited === undefined ? {} : { outputTokensMax: limited }), ...(withoutNote ? { noteDropped: true } : {}) };
|
|
262
262
|
};
|
|
263
263
|
const models = {
|
package/dist/testing.d.ts
CHANGED
|
@@ -111,8 +111,12 @@ export type FauxAction = ({
|
|
|
111
111
|
};
|
|
112
112
|
/** `note`: a note its host had for the request (ModelPort.note, the spend cap's wrap-up), as a real adapter's model proxy
|
|
113
113
|
* would add it to the body: filed with its text, for a test to see. */
|
|
114
|
+
/** `answered`: a request whose reply asks for calls came back (its `until` let go), so its calls are the model's to run.
|
|
115
|
+
* `said`: a call's own text (its `say`) was streamed, so a recovered turn never says it again. */
|
|
114
116
|
export declare const FAUX_RECORDS: {
|
|
115
117
|
readonly request: "faux.request";
|
|
118
|
+
readonly answered: "faux.answered";
|
|
119
|
+
readonly said: "faux.said";
|
|
116
120
|
readonly user: "faux.user";
|
|
117
121
|
readonly turn: "faux.turn";
|
|
118
122
|
readonly turnEnd: "faux.turn_end";
|
|
@@ -121,8 +125,11 @@ export declare const FAUX_RECORDS: {
|
|
|
121
125
|
readonly note: "faux.note";
|
|
122
126
|
};
|
|
123
127
|
export interface FauxOptions {
|
|
124
|
-
/** The session's model replies, in order, by its spec: one action per paid request.
|
|
125
|
-
|
|
128
|
+
/** The session's model replies, in order, by its spec: one action per paid request. `cwd`: the session's working
|
|
129
|
+
* directory when its host gives one (SessionIO.cwd), which a real CLI builds its absolute paths from. */
|
|
130
|
+
script: (spec: SessionSpec, session: {
|
|
131
|
+
readonly cwd?: string;
|
|
132
|
+
}) => FauxAction[];
|
|
126
133
|
/** Problems `check` reports for a spec. */
|
|
127
134
|
refuse?: (spec: SessionSpec) => string[];
|
|
128
135
|
/** How long `open` takes, ignoring the session's signal, as a slow harness start does (default 0). */
|
package/dist/testing.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// Test kit: a session store in memory, and a scripted harness with no model and no network. The faux harness keeps its
|
|
2
2
|
// own records in the store as a real adapter does (the requests it made, each tool call's intent and outcome, its turns),
|
|
3
3
|
// so a later process resumes from them: a request already made is not made again, and a call a crash cut off is
|
|
4
|
-
// answered interrupted, never run again.
|
|
4
|
+
// answered interrupted, never run again. Each call asks the host's gate first, as a real harness's tool bridge does
|
|
5
|
+
// (process/tools.ts askGate): a deny is the call's answer, and a park holds the turn; a recovered turn runs the calls its
|
|
6
|
+
// last request asked for that never started (a parked one), under their own ids, as a real CLI's resume does.
|
|
5
7
|
import { SessionFenced } from "./errors.js";
|
|
6
8
|
import { abortedOutcome, SessionHalt } from "./kernel/halt.js";
|
|
7
9
|
import { startModelProxy } from "./host/proxy.js";
|
|
10
|
+
import { askGate } from "./process/tools.js";
|
|
8
11
|
import { randomBytes } from "node:crypto";
|
|
9
12
|
export { SCHEMA_CHECK_CASES } from "./schema-check-cases.js";
|
|
10
13
|
/** The model proxy's own parts, for tests of a provider policy and of the proxy: the host API (./host) keeps only what a
|
|
@@ -38,7 +41,9 @@ export function memorySessionStore() {
|
|
|
38
41
|
}
|
|
39
42
|
/** `note`: a note its host had for the request (ModelPort.note, the spend cap's wrap-up), as a real adapter's model proxy
|
|
40
43
|
* would add it to the body: filed with its text, for a test to see. */
|
|
41
|
-
|
|
44
|
+
/** `answered`: a request whose reply asks for calls came back (its `until` let go), so its calls are the model's to run.
|
|
45
|
+
* `said`: a call's own text (its `say`) was streamed, so a recovered turn never says it again. */
|
|
46
|
+
export const FAUX_RECORDS = { request: "faux.request", answered: "faux.answered", said: "faux.said", user: "faux.user", turn: "faux.turn", turnEnd: "faux.turn_end", call: "faux.call", result: "faux.result", note: "faux.note" };
|
|
42
47
|
export function fauxAdapter(options) {
|
|
43
48
|
const stats = { requests: 0, calls: [], opened: [], closed: [] };
|
|
44
49
|
const adapter = {
|
|
@@ -55,7 +60,7 @@ export function fauxAdapter(options) {
|
|
|
55
60
|
async open(spec, io) {
|
|
56
61
|
if (options.openDelayMs)
|
|
57
62
|
await new Promise((resolve) => setTimeout(resolve, options.openDelayMs));
|
|
58
|
-
const script = options.script(spec);
|
|
63
|
+
const script = options.script(spec, io.cwd === undefined ? {} : { cwd: io.cwd });
|
|
59
64
|
const records = await io.writer.read();
|
|
60
65
|
// The session's model proxy, when the faux harness is given one: up for the session's life, its key never used here.
|
|
61
66
|
const proxy = options.proxy ? await startModelProxy({ ...options.proxy.options, hooks: io.models }, randomBytes(32).toString("base64url")) : undefined;
|
|
@@ -79,6 +84,24 @@ export function fauxAdapter(options) {
|
|
|
79
84
|
await append(FAUX_RECORDS.result, { callId, interrupted: true });
|
|
80
85
|
}
|
|
81
86
|
const tools = new Map(spec.tools.map((tool) => [tool.name, tool]));
|
|
87
|
+
/** The calls an action asks for, under their ids: a response's several calls, one call, or a submission. */
|
|
88
|
+
const callsOf = (action, index) => !action ? [] : "calls" in action ? action.calls.map((c, n) => ({ name: c.call, args: c.args ?? {}, callId: `${spec.key}:${index}.${n}`, ...(c.say ? { say: c.say } : {}) }))
|
|
89
|
+
: "call" in action ? [{ name: action.call, args: action.args ?? {}, callId: `${spec.key}:${index}` }]
|
|
90
|
+
: "submit" in action ? [{ name: "submit", args: { value: action.submit }, callId: `${spec.key}:${index}` }] : [];
|
|
91
|
+
// The calls the session's last request asked for that never started (no intent, no answer): the gate parked them, or
|
|
92
|
+
// the process ended before they ran. A recovered turn runs them first, as a real CLI's resume runs the calls left
|
|
93
|
+
// dangling in its transcript; a turn settled or a new one sent leaves them. Only once that request was answered
|
|
94
|
+
// (FAUX_RECORDS.answered): one cut off before its reply came (held at its `until`) asked for nothing yet, so none of
|
|
95
|
+
// its calls runs on the recovery: the turn goes on with the script's next request, as a cut request's always has.
|
|
96
|
+
const begun = new Set(records.filter((r) => r.kind === FAUX_RECORDS.call || r.kind === FAUX_RECORDS.result).map((r) => r.data.callId));
|
|
97
|
+
const answered = new Set(records.filter((r) => r.kind === FAUX_RECORDS.answered).map((r) => r.data.index));
|
|
98
|
+
// Each keeps its action's resultWhen: its outcome is told only once that file exists, as on its first try; and its own
|
|
99
|
+
// text (`say`) unless it was said already (FAUX_RECORDS.said: the call that parked said its text before its gate).
|
|
100
|
+
const resultWhenOf = (action) => (action && "resultWhen" in action && typeof action.resultWhen === "string" ? action.resultWhen : undefined);
|
|
101
|
+
const saidAlready = new Set(records.filter((r) => r.kind === FAUX_RECORDS.said).map((r) => r.data.callId));
|
|
102
|
+
let dangling = state === "open_turn" && answered.has(cursor - 1)
|
|
103
|
+
? callsOf(script[cursor - 1], cursor - 1).filter((call) => !begun.has(call.callId)).map(({ say, ...call }) => ({ ...call, ...(say && !saidAlready.has(call.callId) ? { say } : {}), resultWhen: resultWhenOf(script[cursor - 1]) }))
|
|
104
|
+
: [];
|
|
82
105
|
/** What the session has been sent, as a model would be prompted with it. */
|
|
83
106
|
const prompt = records.filter((r) => r.kind === FAUX_RECORDS.user).map((r) => r.data.text);
|
|
84
107
|
let ending;
|
|
@@ -109,10 +132,39 @@ export function fauxAdapter(options) {
|
|
|
109
132
|
else
|
|
110
133
|
signal.addEventListener("abort", () => reject(signal.reason), { once: true });
|
|
111
134
|
});
|
|
135
|
+
/** One call of the model's: the host's gate first, before anything of it is written (a deny is its answer, in the
|
|
136
|
+
* gate's words, recorded so it is never asked again; a park holds the turn until it is stopped), then its intent,
|
|
137
|
+
* the tool, and its outcome. `resultWhen`: its outcome is told only once that file exists. */
|
|
138
|
+
const runCall = async (name, args, callId, signal, resultWhen) => {
|
|
139
|
+
const tool = tools.get(name);
|
|
140
|
+
const refused = tool && io.gate ? await askGate((call) => io.gate(call), { callId, tool: name, args: (args ?? {}) }, signal) : undefined;
|
|
141
|
+
if (refused)
|
|
142
|
+
return void (await append(FAUX_RECORDS.result, { callId, isError: true, refused: true }));
|
|
143
|
+
await append(FAUX_RECORDS.call, { callId, name });
|
|
144
|
+
io.onEvent({ type: "tool_start", callId, name, args });
|
|
145
|
+
const result = tool ? await tool.call(args, { callId, signal }).catch((error) => ({ text: error.message, isError: true })) : { text: `unknown tool ${name}`, isError: true };
|
|
146
|
+
if (tool)
|
|
147
|
+
stats.calls.push(name);
|
|
148
|
+
if (resultWhen)
|
|
149
|
+
await untilExists(resultWhen, signal);
|
|
150
|
+
await append(FAUX_RECORDS.result, { callId, isError: result.isError === true });
|
|
151
|
+
io.onEvent({ type: "tool_end", callId, name, isError: result.isError === true });
|
|
152
|
+
};
|
|
153
|
+
/** A call's own text, streamed before the call, then noted said (FAUX_RECORDS.said), so a recovered turn says it once. */
|
|
154
|
+
const saying = async (callId, say) => {
|
|
155
|
+
io.onEvent({ type: "text", delta: say });
|
|
156
|
+
await append(FAUX_RECORDS.said, { callId });
|
|
157
|
+
};
|
|
112
158
|
/** The turn's model loop: one scripted action per paid request, until one ends the turn. */
|
|
113
159
|
const run = async () => {
|
|
114
160
|
const signal = AbortSignal.any([io.signal, (turnSignal = new AbortController()).signal]);
|
|
115
161
|
try {
|
|
162
|
+
// A recovered turn: the calls its last request left dangling run first, then the model goes on.
|
|
163
|
+
for (const { name, args, callId, say, resultWhen } of dangling.splice(0)) {
|
|
164
|
+
if (say)
|
|
165
|
+
await saying(callId, say);
|
|
166
|
+
await runCall(name, args, callId, signal, resultWhen);
|
|
167
|
+
}
|
|
116
168
|
for (;;) {
|
|
117
169
|
const action = script[cursor];
|
|
118
170
|
if (!action)
|
|
@@ -191,6 +243,9 @@ export function fauxAdapter(options) {
|
|
|
191
243
|
// Held in flight, admitted and not answered, until the file it waits for exists (or the turn is stopped).
|
|
192
244
|
if ("until" in action && typeof action.until === "string")
|
|
193
245
|
await untilExists(action.until, signal);
|
|
246
|
+
// Its reply is in: the calls it asks for are the model's now, and a recovered turn runs any left unstarted.
|
|
247
|
+
if (callsOf(action, index).length)
|
|
248
|
+
await append(FAUX_RECORDS.answered, { index });
|
|
194
249
|
const tokens = "tokens" in action && action.tokens ? action.tokens : { input: 10, output: 5 };
|
|
195
250
|
const usd = action.usd === undefined ? 0.001 : action.usd;
|
|
196
251
|
const book = () => io.models.afterRequest({ ...tokens, usd }, ticket || undefined, { end: "answered", usd });
|
|
@@ -204,27 +259,15 @@ export function fauxAdapter(options) {
|
|
|
204
259
|
else if ("end" in action)
|
|
205
260
|
return await end(action.turn ?? "completed");
|
|
206
261
|
else {
|
|
207
|
-
|
|
208
|
-
: [{ name: "call" in action ? action.call : "submit", args: "call" in action ? action.args ?? {} : { value: action.submit } }];
|
|
209
|
-
for (const [n, { name, args, say }] of asked.entries()) {
|
|
262
|
+
for (const [n, { name, args, callId, say }] of callsOf(action, index).entries()) {
|
|
210
263
|
if (say)
|
|
211
|
-
|
|
264
|
+
await saying(callId, say);
|
|
212
265
|
// A side call (a title, a summary) admitted and answered while this request still streams: two in flight.
|
|
213
266
|
if (n === 0 && "sideDuring" in action && action.sideDuring) {
|
|
214
267
|
const side = await io.models.beforeRequest({ model: "faux-small", side: true, inputTokensMax: 100 });
|
|
215
268
|
await io.models.afterRequest({ input: 10, output: 5, usd: action.sideDuring.usd }, side || undefined);
|
|
216
269
|
}
|
|
217
|
-
|
|
218
|
-
const tool = tools.get(name);
|
|
219
|
-
await append(FAUX_RECORDS.call, { callId, name });
|
|
220
|
-
io.onEvent({ type: "tool_start", callId, name, args });
|
|
221
|
-
const result = tool ? await tool.call(args, { callId, signal }).catch((error) => ({ text: error.message, isError: true })) : { text: `unknown tool ${name}`, isError: true };
|
|
222
|
-
if (tool)
|
|
223
|
-
stats.calls.push(name);
|
|
224
|
-
if ("resultWhen" in action && typeof action.resultWhen === "string")
|
|
225
|
-
await untilExists(action.resultWhen, signal);
|
|
226
|
-
await append(FAUX_RECORDS.result, { callId, isError: result.isError === true });
|
|
227
|
-
io.onEvent({ type: "tool_end", callId, name, isError: result.isError === true });
|
|
270
|
+
await runCall(name, args, callId, signal, resultWhenOf(action));
|
|
228
271
|
}
|
|
229
272
|
if (bookAfter)
|
|
230
273
|
await book();
|
|
@@ -252,6 +295,7 @@ export function fauxAdapter(options) {
|
|
|
252
295
|
get state() { return state; },
|
|
253
296
|
async send(text) {
|
|
254
297
|
state = "idle";
|
|
298
|
+
dangling = [];
|
|
255
299
|
await append(FAUX_RECORDS.user, { text });
|
|
256
300
|
prompt.push(text);
|
|
257
301
|
await append(FAUX_RECORDS.turn, { n: turnsStarted + 1 });
|
|
@@ -265,6 +309,7 @@ export function fauxAdapter(options) {
|
|
|
265
309
|
throw new Error("faux: there is no turn to settle");
|
|
266
310
|
await append(FAUX_RECORDS.turnEnd, { status: abortedOutcome(AbortSignal.abort(new SessionHalt("interrupted"))).status });
|
|
267
311
|
state = "idle";
|
|
312
|
+
dangling = [];
|
|
268
313
|
},
|
|
269
314
|
turnEnd: () => ending ? ending.promise : Promise.resolve({ status: "completed" }),
|
|
270
315
|
async interrupt() { turnSignal?.abort(new SessionHalt("interrupted")); },
|
package/dist/types.d.ts
CHANGED
|
@@ -145,6 +145,8 @@ export interface ModelRequest {
|
|
|
145
145
|
/** The most input tokens the request can be billed for (the model proxy's `inputTokensMaxOf`: the body's UTF-8 bytes
|
|
146
146
|
* plus what the provider adds), undefined when it was not measured. */
|
|
147
147
|
inputTokensMax?: number;
|
|
148
|
+
/** Its `inputTokensMax` is its provider's count, not its bytes (ProxyRequest.inputTokensCounted). */
|
|
149
|
+
inputTokensCounted?: true;
|
|
148
150
|
/** The most output tokens the request asks for, when its body says (the proxy's policy reads it). */
|
|
149
151
|
outputTokensAsked?: number;
|
|
150
152
|
/** The least output it may be limited to and still answer: its answer's 1,024 tokens, plus the least thinking its
|
|
@@ -184,6 +186,10 @@ export interface ModelRequest {
|
|
|
184
186
|
* the proxy minted for this label: ModelProxy.sideKey): a learned workflow's model node, say. The harness's own
|
|
185
187
|
* requests carry none, and it cannot send one that does: it holds only the session's key. */
|
|
186
188
|
host?: string;
|
|
189
|
+
/** Which of the session's routes it came by, when the session has more than one (ModelProxyOptions.route: a proxy beside
|
|
190
|
+
* the session's, for a model of another tier): the host prices it by its model and this route, so one model id two
|
|
191
|
+
* routes price apart is held at the price its route books it at. Absent: the session's own route. */
|
|
192
|
+
route?: string;
|
|
187
193
|
}
|
|
188
194
|
/** What a paid request cost, once it completed. */
|
|
189
195
|
export interface ModelUsage {
|
|
@@ -283,6 +289,9 @@ export interface GateCall {
|
|
|
283
289
|
readonly callId: string;
|
|
284
290
|
readonly tool: string;
|
|
285
291
|
readonly args: Record<string, unknown>;
|
|
292
|
+
/** The call runs again after an earlier attempt whose start the log holds (a replay-safe call a crash cut): that
|
|
293
|
+
* attempt may have been sent, so a refusal never says nothing was. */
|
|
294
|
+
readonly replayed?: true;
|
|
286
295
|
}
|
|
287
296
|
/** The host's answer before a call's intent: run it, refuse it in these words, or park the run on it. */
|
|
288
297
|
export type GateAnswer = "allow" | {
|
|
@@ -393,8 +402,10 @@ export interface AdapterSession {
|
|
|
393
402
|
/** The session's own model route, for a request the host sends beside the harness's own (a learned workflow's model
|
|
394
403
|
* node): its model proxy's address with a side key minted for `label` (ModelProxy.sideKey), the model its policy
|
|
395
404
|
* takes and the API it speaks. Undefined while no proxy is up (no turn has attached one yet). Every model request of
|
|
396
|
-
* a session goes through that one proxy: the same policy, origin, credential, price and booking.
|
|
397
|
-
|
|
405
|
+
* a session goes through that one proxy: the same policy, origin, credential, price and booking. `tier`: the run's
|
|
406
|
+
* model of that tier instead (a learned workflow's node of a tier), on a proxy of its own beside the session's, with
|
|
407
|
+
* that model's origin, credential and price and the session's booking; undefined when the session has none for it. */
|
|
408
|
+
port?(label: string, tier?: string): SessionPort | undefined;
|
|
398
409
|
}
|
|
399
410
|
/** The API a harness's model proxy speaks: what its provider, its keys and its catalog follow from. */
|
|
400
411
|
export type Wire = "anthropic-messages" | "openai-responses";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-kernel",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.35",
|
|
4
4
|
"description": "Agent harnesses other than Pi, starting with Codex, behind one seam: a DSL node's runNode and an AgentRun run on a harness adapter, durable in AgentRun's own store.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentrun",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "Parcha Labs, Inc.",
|
|
15
15
|
"engines": {
|
|
16
|
-
"node": ">=24.
|
|
16
|
+
"node": ">=24.22.3"
|
|
17
17
|
},
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"test": "node --test --test-concurrency=8 'test/*.test.mjs'"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@parcha/agentrun-dsl": "0.1.0-beta.
|
|
63
|
+
"@parcha/agentrun-dsl": "0.1.0-beta.35",
|
|
64
64
|
"ajv": "8.18.0",
|
|
65
65
|
"typebox": "1.3.27"
|
|
66
66
|
},
|