@parcha/agentrun-decisions 0.1.0-beta.58 → 0.1.0-beta.59

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 CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 0.1.0-beta.59 (2026-11-25)
6
+
7
+ - `anthropicProvider()`: a prompted Claude model (Haiku 5.5 by default, through `ANTHROPIC_BASE_URL`) as a `DecisionProvider`, answering noul and choice questions held to a JSON schema, at Anthropic's published price (`ANTHROPIC_PUBLISHED_PRICING`). It is the control arm for the web classifier step in `@parcha/agentrun-web`: `WebConfig.decider` (`deciderFrom(provider, { price })`) sifts each search's results and judges each fetched part in passages before the model reads them, each request held to the run's cap. Without a decider, every answer and receipt is byte-identical to a web with no step. <!-- changes/web-classifier-step.md -->
8
+ - Requests that carry a provider's key never follow a redirect. That covers Exa, Firecrawl, Parallel's search and extract, and the Anthropic, Parallel and OpenRouter deciders: a redirect fails the request, so the key never reaches another address. <!-- changes/web-keyed-redirect.md -->
9
+
5
10
  ## 0.1.0-beta.41 (2026-11-16)
6
11
 
7
12
  - Model requests AgentRun sends to OpenRouter carry OpenRouter's app attribution headers: `HTTP-Referer: https://github.com/Parcha-ai/agentrun`, `X-OpenRouter-Title: AgentRun` and `X-OpenRouter-Categories: cloud-agent,personal-agent`. Usage then counts toward AgentRun's page on OpenRouter (openrouter.ai/apps?url=https://github.com/Parcha-ai/agentrun), including a self-hosted server's usage on its owner's own key. Set `AGENTRUN_OPENROUTER_ATTRIBUTION=off` where AgentRun starts to send none.
package/README.md CHANGED
@@ -55,6 +55,29 @@ The key is `OPENROUTER_API_KEY`, read by name when a request is made, or `apiKey
55
55
  - **Replay.** As Parallel: `replay: "never"`. A request is sent again only when it never reached OpenRouter, or on a 429 with `Retry-After` (up to `maxAttempts`, default 3). A 408, a 5xx, a connection lost after sending or a deadline in flight is `outcome_unknown` at an unknown cost.
56
56
  - **Images (experimental).** OpenRouter takes JSON only, so a request's images go in the body as `assets` (`{ type: "image", format, data_base64 }`) with the `TypeSafe-Danger-Zone-Images` header, and only to a model the public catalog (`/v1/models?output_modalities=decisions`) lists with image input (`takesImages` overrides the catalog). Jev reads an image token anywhere in the state or a question, and refuses an image over 1568 px on a side, which the provider refuses before sending. Every other model reads an image only as a top-level item of an array state: an object state whose tokens are whole top-level values goes as `[{ the other fields, image_fields }, "<token>", ...]`, where `image_fields` names, in order, the field each image stood in (`{ invoice: "<i1>", receipt: "<i2>" }` goes as `[{ image_fields: ["invoice", "receipt"] }, "<i1>", "<i2>"]`), and a token anywhere else is refused before sending. A request waits for that image check only within its own deadline and cancel. The catalog read behind the check is shared by every request and is not cut with one: it goes on under its own 10 s timeout, and its answer serves the requests after it (a read that fails is tried again by the next one). OpenRouter documents image assets as alpha, so the provider lists `image` under `experimental.inputs`.
57
57
 
58
+ ## A prompted Claude model
59
+
60
+ `anthropicProvider()` asks a Claude model through the Messages API (`POST {base}/v1/messages`), Claude Haiku 5.5 by
61
+ default: the System One request (`{ state, questions }`) as the user message, under a short system prompt
62
+ (`ANTHROPIC_SYSTEM`) that states the task and nothing else, with the answers held to a JSON schema built from the
63
+ questions. It is the prompted-LLM control for a decision model: the same request, answered by a general model.
64
+
65
+ The key is `ANTHROPIC_API_KEY` and the root `ANTHROPIC_BASE_URL` (default `https://api.anthropic.com`), both read when a
66
+ request is made, or `apiKey` and `baseURL`.
67
+
68
+ - **Types.** `noul` and `choice`. A choice's probabilities are read per option and normalized; its `choice` is the
69
+ likeliest. Probabilities are the model's own (`probability: "self_reported"`).
70
+ - **Sampling.** One table decides, by model, what is sent (`temperatureFor`, `takesEffort`): temperature 0 to a model
71
+ that takes one, none to Opus 4.7 and later, the Claude 5 family, Fable or Mythos, which refuse it; low effort to a
72
+ model that takes effort (not Haiku 4.5 or Sonnet 4.5). No top_p or top_k. The outcome carries `temperature_sent` and
73
+ `temperature_applied`: true direct to Anthropic, "unknown" through any other root (a proxy may drop the field),
74
+ false when none was sent.
75
+ - **Refusal.** `stop_reason: "refusal"` refuses every question, booked at its cost.
76
+ - **Cost.** Usage at Anthropic's published price (`ANTHROPIC_PUBLISHED_PRICING`), as an estimate; long-prompt rates past
77
+ 100,000 input tokens. A model it lists no price for costs null (unknown) unless `pricing` is given.
78
+ - **Replay and errors.** As OpenRouter's: `replay: "never"`, the same error codes, and an answer that is cut at
79
+ `max_tokens`, is not JSON, or does not match the questions is `invalid_response`, booked at its cost.
80
+
58
81
  `@parcha/agentrun-decisions/testing/faux-system-one` is a fake System One endpoint for a host's tests: its answers are made up but stable (drawn from a hash of the model, the question and the state), it lists a small Decisions catalog, and it reads images as OpenRouter does. No request leaves the process.
59
82
 
60
83
  ## Tests
@@ -0,0 +1,49 @@
1
+ import type { DecisionContext, DecisionOutcome, DecisionProvider, DecisionRequest } from "@parcha/agentrun-dsl";
2
+ import { type TemperatureRecord } from "./claude-models.js";
3
+ /** USD per million tokens; past `longPromptTokens` input tokens a request is billed at the long rates. */
4
+ export type AnthropicPrice = {
5
+ inputUsdPerMillionTokens: number;
6
+ outputUsdPerMillionTokens: number;
7
+ longPromptTokens?: number;
8
+ longInputUsdPerMillionTokens?: number;
9
+ longOutputUsdPerMillionTokens?: number;
10
+ };
11
+ /** Anthropic's published list prices (platform.claude.com pricing), by model. */
12
+ export declare const ANTHROPIC_PUBLISHED_PRICING: Readonly<Record<string, AnthropicPrice>>;
13
+ /** The task alone: what to answer is the questions' own words, the same a decision model is sent. */
14
+ export declare const ANTHROPIC_SYSTEM: string;
15
+ /** A request's price as web's classifier step holds it (deciderFrom's `price`), at the most it may cost: its input
16
+ * tokens bounded by twice its bytes (the JSON schema the answers are held to adds about as many again) with the system
17
+ * prompt, its output by max_tokens. Undefined for a model with no price here and none given. */
18
+ export declare function anthropicDecisionPrice(model?: string, pricing?: AnthropicPrice): {
19
+ maxOutputTokens: number;
20
+ inputTokensPerByte: number;
21
+ extraInputTokens: number;
22
+ inputUsdPerMillionTokens: number;
23
+ outputUsdPerMillionTokens: number;
24
+ longPromptTokens?: number;
25
+ longInputUsdPerMillionTokens?: number;
26
+ longOutputUsdPerMillionTokens?: number;
27
+ };
28
+ export interface AnthropicOptions {
29
+ /** The key; otherwise ANTHROPIC_API_KEY, read when a request is made. */
30
+ apiKey?: string;
31
+ /** API root, without /v1/messages; otherwise ANTHROPIC_BASE_URL, read when a request is made, else Anthropic's. */
32
+ baseURL?: string;
33
+ fetch?: typeof fetch;
34
+ /** The model for a request that names none (default claude-haiku-5-5). */
35
+ model?: string;
36
+ /** The price of `model` when ANTHROPIC_PUBLISHED_PRICING lists none; without either, the cost is unknown. */
37
+ pricing?: AnthropicPrice;
38
+ /** The longest one request may take, every attempt included (default 30 s); a shorter deadline from the host wins. */
39
+ timeoutMs?: number;
40
+ maxAttempts?: number;
41
+ retryBaseMs?: number;
42
+ retryMaxMs?: number;
43
+ }
44
+ /** An outcome, and the temperature its request carried (temperatureFor) with whether the model applied it. */
45
+ export type AnthropicOutcome = DecisionOutcome & TemperatureRecord;
46
+ export type AnthropicProvider = DecisionProvider & {
47
+ decide(request: DecisionRequest, ctx: DecisionContext): Promise<AnthropicOutcome>;
48
+ };
49
+ export declare function anthropicProvider(options?: AnthropicOptions): AnthropicProvider;
@@ -0,0 +1,229 @@
1
+ // A prompted Claude model (POST {base}/v1/messages) as a DecisionProvider: the System One request ({ state, questions })
2
+ // as the user message, the answers held to a JSON schema. A request is paid once sent, so it is sent again only when it
3
+ // provably never reached the API or was refused with a time to retry (a 429 with Retry-After).
4
+ import { setTimeout as sleep } from "node:timers/promises";
5
+ import { checkCapabilities, DecisionProviderError } from "@parcha/agentrun-dsl";
6
+ import { takesEffort, temperatureFor, temperatureRecord } from "./claude-models.js";
7
+ const KEY_VARIABLE = "ANTHROPIC_API_KEY";
8
+ const BASE_VARIABLE = "ANTHROPIC_BASE_URL";
9
+ const BASE_URL = "https://api.anthropic.com";
10
+ const API_VERSION = "2023-06-01";
11
+ const MODEL = "claude-haiku-5-5";
12
+ const MAX_TOKENS = 8192;
13
+ /** Anthropic's published list prices (platform.claude.com pricing), by model. */
14
+ export const ANTHROPIC_PUBLISHED_PRICING = {
15
+ "claude-haiku-5-5": { inputUsdPerMillionTokens: 0.1, outputUsdPerMillionTokens: 0.5, longPromptTokens: 100_000, longInputUsdPerMillionTokens: 0.5, longOutputUsdPerMillionTokens: 2.5 },
16
+ };
17
+ /** The task alone: what to answer is the questions' own words, the same a decision model is sent. */
18
+ export const ANTHROPIC_SYSTEM = [
19
+ "You are a decision model. The user message is JSON: a state, and questions about it by id.",
20
+ "Answer every question from the state alone.",
21
+ "For a noul question (true or false, with criteria for each), give the probability, from 0 to 1, that its answer is true.",
22
+ "For a choice question, give each option the probability, from 0 to 1, that it is the one that fits; they sum to 1.",
23
+ "Reply with the JSON object the schema describes, keyed by question id, and nothing else.",
24
+ ].join("\n");
25
+ /** A request's price as web's classifier step holds it (deciderFrom's `price`), at the most it may cost: its input
26
+ * tokens bounded by twice its bytes (the JSON schema the answers are held to adds about as many again) with the system
27
+ * prompt, its output by max_tokens. Undefined for a model with no price here and none given. */
28
+ export function anthropicDecisionPrice(model = MODEL, pricing) {
29
+ const price = ANTHROPIC_PUBLISHED_PRICING[model] ?? pricing;
30
+ return price && { ...price, maxOutputTokens: MAX_TOKENS, inputTokensPerByte: 2, extraInputTokens: Buffer.byteLength(ANTHROPIC_SYSTEM) + 1024 };
31
+ }
32
+ const isRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
33
+ const isCount = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
34
+ const isUnit = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 1;
35
+ /** Failures a request meets before it is sent: no DNS answer, no connection, no TLS handshake. Any other is after. */
36
+ const BEFORE_SENDING = new Set(["ENOTFOUND", "EAI_AGAIN", "ECONNREFUSED", "ENETUNREACH", "EHOSTUNREACH", "UND_ERR_CONNECT_TIMEOUT",
37
+ "CERT_HAS_EXPIRED", "DEPTH_ZERO_SELF_SIGNED_CERT", "SELF_SIGNED_CERT_IN_CHAIN", "UNABLE_TO_VERIFY_LEAF_SIGNATURE", "ERR_TLS_CERT_ALTNAME_INVALID"]);
38
+ const neverSent = (error) => {
39
+ for (let cause = error, depth = 0; (isRecord(cause) || cause instanceof Error) && depth <= 4; cause = cause.cause, depth++) {
40
+ const code = cause.code;
41
+ if (typeof code === "string" && BEFORE_SENDING.has(code))
42
+ return true;
43
+ }
44
+ return false;
45
+ };
46
+ function retryAfterMs(response) {
47
+ const value = response.headers.get("retry-after")?.trim();
48
+ if (!value)
49
+ return undefined;
50
+ if (/^\d+(?:\.\d+)?$/.test(value))
51
+ return Math.round(Number(value) * 1000);
52
+ const at = Date.parse(value);
53
+ return Number.isFinite(at) ? Math.max(0, at - Date.now()) : undefined;
54
+ }
55
+ const optionsOf = (question) => (question.type === "choice" ? Object.keys(question.criteria) : []);
56
+ /** The answers' schema: a noul a number, a choice an object of a number per option, every question required. */
57
+ function schemaOf(questions) {
58
+ const properties = Object.fromEntries(Object.entries(questions).map(([id, question]) => {
59
+ if (question.type !== "choice")
60
+ return [id, { type: "number" }];
61
+ const options = optionsOf(question);
62
+ return [id, { type: "object", additionalProperties: false, required: options, properties: Object.fromEntries(options.map((option) => [option, { type: "number" }])) }];
63
+ }));
64
+ return { type: "object", additionalProperties: false, required: Object.keys(questions), properties };
65
+ }
66
+ function costOf(usage, price) {
67
+ if (!price)
68
+ return null;
69
+ const long = price.longPromptTokens !== undefined && usage.input_tokens > price.longPromptTokens;
70
+ const input = long ? price.longInputUsdPerMillionTokens ?? price.inputUsdPerMillionTokens : price.inputUsdPerMillionTokens;
71
+ const output = long ? price.longOutputUsdPerMillionTokens ?? price.outputUsdPerMillionTokens : price.outputUsdPerMillionTokens;
72
+ return (usage.input_tokens * input + usage.output_tokens * output) / 1e6;
73
+ }
74
+ /** The model's answers read against the questions asked: every one answered, none unasked, each probability in range. */
75
+ function answersOf(text, questions) {
76
+ let given;
77
+ try {
78
+ given = JSON.parse(text);
79
+ }
80
+ catch {
81
+ return "an answer that is not JSON";
82
+ }
83
+ if (!isRecord(given))
84
+ return "an answer that is not a JSON object";
85
+ const ids = Object.keys(questions);
86
+ if (Object.keys(given).length !== ids.length || Object.keys(given).some((id) => !Object.hasOwn(questions, id)))
87
+ return "answers that do not match the questions asked";
88
+ // Built from entries (Object.fromEntries defines each key as its own): a question may be named __proto__, which an
89
+ // assignment on a plain object would take as its prototype.
90
+ const answers = [];
91
+ for (const id of ids) {
92
+ const question = questions[id];
93
+ const value = given[id];
94
+ if (question.type === "noul") {
95
+ if (!isUnit(value))
96
+ return `no probability for "${id}"`;
97
+ answers.push([id, { type: "noul", noul: value }]);
98
+ continue;
99
+ }
100
+ const options = optionsOf(question);
101
+ if (!isRecord(value) || Object.keys(value).length !== options.length || !options.every((option) => isUnit(value[option])))
102
+ return `no probability per option for "${id}"`;
103
+ const sum = options.reduce((total, option) => total + value[option], 0);
104
+ if (!(sum > 0))
105
+ return `probabilities that sum to 0 for "${id}"`;
106
+ const probabilities = Object.fromEntries(options.map((option) => [option, Math.abs(sum - 1) < 1e-9 ? value[option] : value[option] / sum]));
107
+ const choice = options.reduce((best, option) => (probabilities[option] > probabilities[best] ? option : best), options[0]);
108
+ answers.push([id, { type: "choice", choice, probabilities }]);
109
+ }
110
+ return Object.fromEntries(answers);
111
+ }
112
+ export function anthropicProvider(options = {}) {
113
+ const capabilities = {
114
+ types: ["noul", "choice"], inputs: ["text", "json"], evidence: "none", probability: "self_reported", grounding: false,
115
+ replay: "never", maxQuestions: null, maxStateBytes: null,
116
+ };
117
+ const timeoutMs = options.timeoutMs ?? 30_000;
118
+ const maxAttempts = options.maxAttempts ?? 3;
119
+ const retryBaseMs = options.retryBaseMs ?? 500;
120
+ const retryMaxMs = options.retryMaxMs ?? 5_000;
121
+ const fetcher = options.fetch ?? fetch;
122
+ return {
123
+ id: "anthropic", needs: [KEY_VARIABLE], capabilities,
124
+ async decide(request, ctx) {
125
+ checkCapabilities(capabilities, request);
126
+ const key = options.apiKey ?? process.env[KEY_VARIABLE];
127
+ if (typeof key !== "string" || !key.trim())
128
+ throw new DecisionProviderError("configuration", `${KEY_VARIABLE} is not set.`);
129
+ const root = (options.baseURL ?? process.env[BASE_VARIABLE] ?? BASE_URL).replace(/\/+$/, "");
130
+ const model = request.model ?? options.model ?? MODEL;
131
+ const price = ANTHROPIC_PUBLISHED_PRICING[model] ?? options.pricing;
132
+ const temperature = temperatureFor(model);
133
+ const format = { type: "json_schema", schema: schemaOf(request.questions) };
134
+ const body = JSON.stringify({
135
+ model,
136
+ max_tokens: MAX_TOKENS,
137
+ system: ANTHROPIC_SYSTEM,
138
+ messages: [{ role: "user", content: JSON.stringify({ state: request.state ?? null, questions: request.questions }) }],
139
+ temperature,
140
+ output_config: takesEffort(model) ? { effort: "low", format } : { format },
141
+ });
142
+ const sampled = temperatureRecord(temperature, root === BASE_URL);
143
+ const headers = { "content-type": "application/json", "anthropic-version": API_VERSION, "x-api-key": key };
144
+ const budgetMs = Math.min(timeoutMs, ctx.deadlineMs ?? Infinity);
145
+ const deadlineAt = Date.now() + budgetMs;
146
+ const signal = AbortSignal.any([ctx.signal, AbortSignal.timeout(budgetMs)]);
147
+ const stopped = (attempts) => new DecisionProviderError("aborted", "The Anthropic request was cancelled.", { attempts });
148
+ // Sent and lost: it may have been answered and billed, so it is never sent again, at an unknown cost.
149
+ const lost = (attempts, what, status) => new DecisionProviderError("outcome_unknown", `Anthropic ${what} after the request was sent; it may have been answered, and is not sent again.`, { attempts, ...(status === undefined ? {} : { status }), costUsd: null, costBasis: "unknown" });
150
+ for (let attempt = 1;; attempt++) {
151
+ let response;
152
+ try {
153
+ // It carries the key: a redirect is an error, never followed to an address the key was not meant for.
154
+ response = await fetcher(`${root}/v1/messages`, { method: "POST", headers, body, signal, redirect: "error" });
155
+ }
156
+ catch (error) {
157
+ if (signal.aborted)
158
+ throw ctx.signal.aborted ? stopped(attempt) : lost(attempt, "passed its deadline");
159
+ if (!neverSent(error))
160
+ throw lost(attempt, "lost the connection");
161
+ if (attempt >= maxAttempts)
162
+ throw new DecisionProviderError("connection", "Anthropic could not be reached.", { attempts: attempt });
163
+ const unreached = () => { throw ctx.signal.aborted ? stopped(attempt) : new DecisionProviderError("timeout", "Anthropic could not be reached before the deadline.", { attempts: attempt }); };
164
+ await sleep(Math.min(retryMaxMs, retryBaseMs * 2 ** (attempt - 1)), undefined, { signal }).catch(unreached);
165
+ continue;
166
+ }
167
+ if (response.ok) {
168
+ let text;
169
+ try {
170
+ text = await response.text();
171
+ }
172
+ catch {
173
+ throw ctx.signal.aborted ? stopped(attempt) : lost(attempt, signal.aborted ? "passed its deadline" : "lost the connection while the answer was read");
174
+ }
175
+ return { ...readMessage(text, request.questions, price, attempt), ...sampled };
176
+ }
177
+ const status = response.status;
178
+ if (status === 408 || (status >= 500 && status <= 599)) {
179
+ void response.body?.cancel().catch(() => { });
180
+ throw lost(attempt, `answered HTTP ${status}`, status);
181
+ }
182
+ const wait = status === 429 ? retryAfterMs(response) : undefined;
183
+ void response.body?.cancel().catch(() => { });
184
+ if (wait !== undefined && attempt < maxAttempts && wait < deadlineAt - Date.now()) {
185
+ const limited = () => { throw ctx.signal.aborted ? stopped(attempt) : new DecisionProviderError("rate_limited", `Anthropic rate-limited the request after ${attempt} attempts.`, { status, attempts: attempt }); };
186
+ await sleep(wait, undefined, { signal }).catch(limited);
187
+ continue;
188
+ }
189
+ const details = { status, attempts: attempt };
190
+ if (status === 401 || status === 403)
191
+ throw new DecisionProviderError("auth", `Anthropic refused the key (HTTP ${status}).`, details);
192
+ if (status === 400 || status === 404 || status === 413 || status === 422)
193
+ throw new DecisionProviderError("invalid_request", `Anthropic refused the request (HTTP ${status}).`, details);
194
+ if (status === 429)
195
+ throw new DecisionProviderError("rate_limited", `Anthropic rate-limited the request after ${attempt} attempts.`, details);
196
+ throw new DecisionProviderError("http", `Anthropic answered HTTP ${status}.`, details);
197
+ }
198
+ },
199
+ };
200
+ }
201
+ /** A 200's message as the outcome. Anthropic answered, so the request was billed: what this rejects is booked at its cost. */
202
+ function readMessage(text, questions, price, attempts) {
203
+ let message;
204
+ try {
205
+ message = JSON.parse(text);
206
+ }
207
+ catch {
208
+ throw new DecisionProviderError("invalid_response", "Anthropic returned a body that is not JSON.", { attempts, costUsd: null, costBasis: "unknown" });
209
+ }
210
+ const raw = isRecord(message) && isRecord(message.usage) ? message.usage : undefined;
211
+ const usage = raw && isCount(raw.input_tokens) && isCount(raw.output_tokens) ? { input_tokens: raw.input_tokens, output_tokens: raw.output_tokens } : null;
212
+ const cost = usage ? costOf(usage, price) : null;
213
+ const booked = { cost_usd: cost, cost_basis: cost === null ? "unknown" : "estimate" };
214
+ const invalid = (why) => new DecisionProviderError("invalid_response", `Anthropic returned ${why}.`, { attempts, costUsd: cost, costBasis: booked.cost_basis });
215
+ if (!isRecord(message))
216
+ throw invalid("no message");
217
+ const outcome = { evidence: [], model: typeof message.model === "string" && message.model ? message.model : null, usage, ...booked, provider_request_id: typeof message.id === "string" ? message.id : null };
218
+ if (message.stop_reason === "refusal")
219
+ return { answers: Object.fromEntries(Object.keys(questions).map((id) => [id, { type: "refusal" }])), ...outcome };
220
+ if (message.stop_reason === "max_tokens")
221
+ throw invalid("an answer cut at max_tokens");
222
+ const block = Array.isArray(message.content) ? message.content.find((part) => isRecord(part) && part.type === "text") : undefined;
223
+ if (!isRecord(block) || typeof block.text !== "string")
224
+ throw invalid("no text answer");
225
+ const answers = answersOf(block.text, questions);
226
+ if (typeof answers === "string")
227
+ throw invalid(answers);
228
+ return { answers, ...outcome };
229
+ }
@@ -0,0 +1,9 @@
1
+ /** The temperature to send `model`: 0 where it takes one, none where it refuses one. */
2
+ export declare const temperatureFor: (model: string) => 0 | undefined;
3
+ export declare const takesEffort: (model: string) => boolean;
4
+ export type TemperatureRecord = {
5
+ temperature_sent: number | null;
6
+ temperature_applied: boolean | "unknown";
7
+ };
8
+ /** `direct`: the request went to Anthropic itself. A proxy may drop the field silently, so through one it is unknown. */
9
+ export declare const temperatureRecord: (sent: number | undefined, direct: boolean) => TemperatureRecord;
@@ -0,0 +1,13 @@
1
+ // Matched anywhere in the id, so a Bedrock, Vertex or OpenRouter name ("us.anthropic.claude-haiku-5-5-v1:0") reads as its model.
2
+ /** Opus 4.7 and later, the Claude 5 family, Fable and Mythos: a request with a (non-default) temperature is a 400. */
3
+ const REFUSES_TEMPERATURE = /claude-(?:fable|mythos|(?:opus|sonnet|haiku)-5|opus-4-[7-9])(?![0-9])/;
4
+ /** Opus 4.5 and later, Sonnet 4.6 and later, the Claude 5 family, Fable and Mythos. */
5
+ const TAKES_EFFORT = /claude-(?:fable|mythos|(?:opus|sonnet|haiku)-5|opus-4-[5-9]|sonnet-4-[6-9])(?![0-9])/;
6
+ /** The temperature to send `model`: 0 where it takes one, none where it refuses one. */
7
+ export const temperatureFor = (model) => (REFUSES_TEMPERATURE.test(model) ? undefined : 0);
8
+ export const takesEffort = (model) => TAKES_EFFORT.test(model);
9
+ /** `direct`: the request went to Anthropic itself. A proxy may drop the field silently, so through one it is unknown. */
10
+ export const temperatureRecord = (sent, direct) => ({
11
+ temperature_sent: sent ?? null,
12
+ temperature_applied: sent === undefined ? false : direct ? true : "unknown",
13
+ });
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- export { parallelProvider, PARALLEL_LIST_PRICE_USD, PARALLEL_MODES, type ParallelOptions } from "./parallel.js";
1
+ export { ANTHROPIC_PUBLISHED_PRICING, ANTHROPIC_SYSTEM, anthropicDecisionPrice, type AnthropicOptions, type AnthropicOutcome, type AnthropicPrice, type AnthropicProvider, anthropicProvider } from "./anthropic.js";
2
+ export { takesEffort, temperatureFor, type TemperatureRecord, temperatureRecord } from "./claude-models.js";
3
+ export { parallelProvider, PARALLEL_DECISION_PRICE, PARALLEL_LIST_PRICE_USD, PARALLEL_MODES, type ParallelOptions } from "./parallel.js";
2
4
  export { openrouterProvider, type OpenRouterOptions, type ExperimentalInputs, type DecisionModelPrice, type PricedModels, CatalogUnreadable } from "./openrouter.js";
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
- export { parallelProvider, PARALLEL_LIST_PRICE_USD, PARALLEL_MODES } from "./parallel.js";
1
+ export { ANTHROPIC_PUBLISHED_PRICING, ANTHROPIC_SYSTEM, anthropicDecisionPrice, anthropicProvider } from "./anthropic.js";
2
+ export { takesEffort, temperatureFor, temperatureRecord } from "./claude-models.js";
3
+ export { parallelProvider, PARALLEL_DECISION_PRICE, PARALLEL_LIST_PRICE_USD, PARALLEL_MODES } from "./parallel.js";
2
4
  export { openrouterProvider, CatalogUnreadable } from "./openrouter.js";
@@ -266,7 +266,8 @@ export function openrouterProvider(options = {}) {
266
266
  const { body, headers } = bodyOf(payload, images);
267
267
  let response;
268
268
  try {
269
- response = await fetcher(url, { method: "POST", headers: { ...headers, ...app, authorization: `Bearer ${key}` }, body, signal });
269
+ // It carries the key: a redirect is an error, never followed to an address the key was not meant for.
270
+ response = await fetcher(url, { method: "POST", headers: { ...headers, ...app, authorization: `Bearer ${key}` }, body, signal, redirect: "error" });
270
271
  }
271
272
  catch (error) {
272
273
  if (signal.aborted)
@@ -3,6 +3,10 @@ import { type OpenRouterOptions } from "./openrouter.js";
3
3
  /** Parallel's list price for one `fast` decision request, up to 100 questions: $1 per 1,000 requests
4
4
  * (https://docs.parallel.ai/resources/pricing, read 2026-11-20). */
5
5
  export declare const PARALLEL_LIST_PRICE_USD = 0.001;
6
+ /** Parallel's price as web's classifier step holds a request to it (deciderFrom's `price`): its list price, whatever the size. */
7
+ export declare const PARALLEL_DECISION_PRICE: Readonly<{
8
+ requestUsd: 0.001;
9
+ }>;
6
10
  /** The modes Parallel Decisions takes, as its API reference lists them (2026-10-30: `fast` only, a const). A node pins
7
11
  * one as `parallel-<mode>`, the name an answer's model reads; a node that pins none asks the first. */
8
12
  export declare const PARALLEL_MODES: readonly string[];
package/dist/parallel.js CHANGED
@@ -11,6 +11,8 @@ import { openrouterProvider } from "./openrouter.js";
11
11
  /** Parallel's list price for one `fast` decision request, up to 100 questions: $1 per 1,000 requests
12
12
  * (https://docs.parallel.ai/resources/pricing, read 2026-11-20). */
13
13
  export const PARALLEL_LIST_PRICE_USD = 0.001;
14
+ /** Parallel's price as web's classifier step holds a request to it (deciderFrom's `price`): its list price, whatever the size. */
15
+ export const PARALLEL_DECISION_PRICE = Object.freeze({ requestUsd: PARALLEL_LIST_PRICE_USD });
14
16
  const KEY_VARIABLE = "PARALLEL_API_KEY";
15
17
  const BASE_URL = "https://api.parallel.ai";
16
18
  /** Parallel's documented limits: options per choice, levels per score, and characters per rendered question. */
@@ -146,7 +148,8 @@ export function parallelProvider(options = {}) {
146
148
  for (let attempt = 1;; attempt++) {
147
149
  let response;
148
150
  try {
149
- response = await fetcher(url, { method: "POST", headers: { "content-type": "application/json", "x-api-key": key }, body, signal });
151
+ // It carries the key: a redirect is an error, never followed to an address the key was not meant for.
152
+ response = await fetcher(url, { method: "POST", headers: { "content-type": "application/json", "x-api-key": key }, body, signal, redirect: "error" });
150
153
  }
151
154
  catch (error) {
152
155
  // A deadline that ends a request in flight may have ended it after Parallel answered: only the host's cancel is not a lost outcome.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-decisions",
3
- "version": "0.1.0-beta.58",
3
+ "version": "0.1.0-beta.59",
4
4
  "description": "Third-party decision models as DecisionProviders for the AgentRun DSL: Parallel Decisions (typed questions grounded in live web evidence) and OpenRouter's Decisions models (any of them by name), behind the DSL's runJudge seam.",
5
5
  "keywords": [
6
6
  "agentrun",
@@ -44,7 +44,7 @@
44
44
  "test": "node --test --test-concurrency=8 'test/*.test.mjs'"
45
45
  },
46
46
  "dependencies": {
47
- "@parcha/agentrun-dsl": "0.1.0-beta.58"
47
+ "@parcha/agentrun-dsl": "0.1.0-beta.59"
48
48
  },
49
49
  "repository": {
50
50
  "type": "git",