@parcha/agentrun-serve 0.1.0-beta.56 → 0.1.0-beta.57
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 +229 -0
- package/README.md +201 -52
- package/dist/acp-package.d.ts +2 -0
- package/dist/adapters.d.ts +15 -3
- package/dist/adapters.js +17 -6
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +17 -8
- package/dist/api-keys.d.ts +76 -0
- package/dist/api-keys.js +217 -0
- package/dist/api-only.d.ts +17 -5
- package/dist/api-only.js +34 -8
- package/dist/browser-hold.d.ts +23 -0
- package/dist/browser-hold.js +48 -0
- package/dist/browser-person.d.ts +3 -0
- package/dist/browser-person.js +4 -1
- package/dist/chatgpt-plan.d.ts +18 -8
- package/dist/chatgpt-plan.js +91 -34
- package/dist/claude-login.d.ts +74 -16
- package/dist/claude-login.js +215 -56
- package/dist/claude-sign-in.d.ts +17 -6
- package/dist/claude-sign-in.js +42 -39
- package/dist/cli.js +63 -6
- package/dist/composio-made.d.ts +4 -0
- package/dist/composio-made.js +4 -0
- package/dist/composio-preset.d.ts +43 -2
- package/dist/composio-preset.js +92 -4
- package/dist/computer-held-routes.d.ts +5 -4
- package/dist/computer-held-routes.js +29 -8
- package/dist/computer-held.d.ts +6 -1
- package/dist/computer-held.js +14 -0
- package/dist/computer-record.js +4 -2
- package/dist/computer-viewer.js +4 -1
- package/dist/console/assets/{backend-Boh7tC4i.js → backend-DVhHzJX2.js} +19 -19
- package/dist/console/assets/index-Bwn1oTem.css +1 -0
- package/dist/console/assets/index-okP-y8PK.js +747 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +1 -1
- package/dist/docker-host-addresses.d.ts +22 -11
- package/dist/docker-host-addresses.js +38 -26
- package/dist/env-switch.d.ts +10 -0
- package/dist/env-switch.js +33 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +58 -20
- package/dist/fal-price.js +341 -82
- package/dist/handed-values.d.ts +43 -1
- package/dist/handed-values.js +119 -2
- package/dist/harness-archive.d.ts +13 -10
- package/dist/harness-archive.js +60 -34
- package/dist/harness-check.d.ts +3 -1
- package/dist/harness-check.js +25 -46
- package/dist/harness-keys.d.ts +73 -27
- package/dist/harness-keys.js +194 -61
- package/dist/harness-recipe-entry.d.ts +8 -7
- package/dist/harness-recipe-entry.js +21 -32
- package/dist/harness-recipe.d.ts +38 -25
- package/dist/harness-recipe.js +49 -36
- package/dist/harness-sign-in.js +12 -23
- package/dist/harness-table.d.ts +10 -3
- package/dist/harness-table.js +26 -21
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +17 -5
- package/dist/hosted-search.d.ts +1 -1
- package/dist/hosted-search.js +1 -2
- package/dist/import-worker.d.ts +4 -2
- package/dist/import-worker.js +9 -2
- package/dist/in-flight.d.ts +26 -0
- package/dist/in-flight.js +52 -0
- package/dist/key-refusal.d.ts +9 -4
- package/dist/key-refusal.js +107 -25
- package/dist/learn/secrets.d.ts +13 -3
- package/dist/learn/secrets.js +118 -17
- package/dist/learning-cost.d.ts +6 -3
- package/dist/learning-cost.js +4 -2
- package/dist/link-check.js +1 -1
- package/dist/llms.txt +1 -1
- package/dist/marketplace.d.ts +77 -0
- package/dist/marketplace.js +224 -0
- package/dist/mcp-api-only-origins.d.ts +30 -0
- package/dist/mcp-api-only-origins.js +57 -0
- package/dist/mcp-gateway.d.ts +7 -5
- package/dist/mcp-gateway.js +9 -12
- package/dist/mcp-secret-writes.js +5 -3
- package/dist/mcp-servers-store.d.ts +28 -6
- package/dist/mcp-servers-store.js +53 -4
- package/dist/media-duration.d.ts +3 -0
- package/dist/media-duration.js +90 -9
- package/dist/model-form.d.ts +5 -4
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +5 -2
- package/dist/model.js +9 -5
- package/dist/ollama-provider.d.ts +7 -1
- package/dist/ollama-provider.js +14 -2
- package/dist/openapi.js +178 -27
- package/dist/otel/genai.d.ts +65 -0
- package/dist/otel/genai.js +116 -0
- package/dist/otel/tracer.d.ts +55 -0
- package/dist/otel/tracer.js +308 -0
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -1
- package/dist/paid-calls.d.ts +1 -32
- package/dist/paid-calls.js +4 -39
- package/dist/provider.d.ts +9 -0
- package/dist/provider.js +50 -3
- package/dist/redact/match.d.ts +30 -3
- package/dist/redact/match.js +422 -41
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +11 -0
- package/dist/run-census.d.ts +67 -0
- package/dist/run-census.js +240 -0
- package/dist/run-computer.d.ts +6 -3
- package/dist/run-computer.js +4 -1
- package/dist/run-cut.d.ts +15 -6
- package/dist/run-cut.js +30 -9
- package/dist/run-files.d.ts +3 -0
- package/dist/run-files.js +3 -0
- package/dist/run-launch.d.ts +12 -1
- package/dist/run-launch.js +9 -10
- package/dist/run-learning-served.d.ts +2 -0
- package/dist/run-model-key.d.ts +8 -0
- package/dist/run-model-key.js +31 -1
- package/dist/run-reads-over-store.d.ts +24 -6
- package/dist/run-reads-over-store.js +67 -23
- package/dist/run-recordings.d.ts +5 -1
- package/dist/run-recordings.js +39 -14
- package/dist/run-timeline-served.d.ts +2 -0
- package/dist/run-timeline-served.js +2 -2
- package/dist/run-usage.d.ts +1 -0
- package/dist/runnable.d.ts +10 -1
- package/dist/runnable.js +20 -8
- package/dist/runner/adapter-loop.d.ts +11 -0
- package/dist/runner/adapter-loop.js +55 -10
- package/dist/runner/adapter-run-spec.d.ts +45 -8
- package/dist/runner/adapter-run-spec.js +150 -28
- package/dist/runner/adapters/pi.js +25 -3
- package/dist/runner/beside.js +4 -3
- package/dist/runner/big-writes.js +1 -10
- package/dist/runner/claim-secrets.d.ts +18 -3
- package/dist/runner/claim-secrets.js +35 -6
- package/dist/runner/cli-run-spec.d.ts +6 -0
- package/dist/runner/cli-run-spec.js +82 -35
- package/dist/runner/computer-journal.d.ts +9 -1
- package/dist/runner/computer-journal.js +26 -0
- package/dist/runner/conformance/harness.js +1 -1
- package/dist/runner/feedback-round.js +3 -0
- package/dist/runner/harness-loops.d.ts +6 -5
- package/dist/runner/harness-loops.js +7 -7
- package/dist/runner/held.d.ts +11 -5
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/journal-kinds.js +5 -0
- package/dist/runner/main.js +7 -2
- package/dist/runner/mcp-claim.js +30 -3
- package/dist/runner/mcp-run.d.ts +12 -0
- package/dist/runner/mcp-run.js +12 -5
- package/dist/runner/model-route.d.ts +17 -0
- package/dist/runner/model-route.js +120 -2
- package/dist/runner/run-child-host.d.ts +3 -0
- package/dist/runner/run-child-host.js +69 -28
- package/dist/runner/run-child.js +5 -2
- package/dist/runner/runner.d.ts +14 -3
- package/dist/runner/runner.js +129 -33
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +6 -0
- package/dist/runner/store-secrets.js +49 -7
- package/dist/runner/subagent.js +4 -40
- package/dist/runner/workflow-first.d.ts +11 -4
- package/dist/runner/workflow-first.js +14 -8
- package/dist/runner/workflow-spec.js +3 -2
- package/dist/runs-over-store.d.ts +15 -6
- package/dist/runs-over-store.js +33 -21
- package/dist/scrub-command.d.ts +73 -0
- package/dist/scrub-command.js +307 -0
- package/dist/secret-cut.d.ts +73 -0
- package/dist/secret-cut.js +291 -4
- package/dist/secret-rules.d.ts +143 -0
- package/dist/secret-rules.js +2564 -0
- package/dist/secrets.d.ts +7 -0
- package/dist/secrets.js +20 -0
- package/dist/server-keys.d.ts +20 -0
- package/dist/server-keys.js +25 -6
- package/dist/server.d.ts +52 -11
- package/dist/server.js +345 -118
- package/dist/skills/agentrun-serve/SKILL.md +4 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +1 -1
- package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
- package/dist/store/schema.d.ts +6 -0
- package/dist/store/schema.js +11 -1
- package/dist/store/seal.d.ts +6 -1
- package/dist/store/seal.js +5 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +24 -13
- package/dist/store/sqlite/run-patch.d.ts +1 -1
- package/dist/store/sqlite/run-patch.js +13 -4
- package/dist/store/sqlite/store.js +34 -4
- package/dist/store/store.d.ts +43 -2
- package/dist/store/store.js +20 -0
- package/dist/store-reads/learning.d.ts +6 -3
- package/dist/store-reads/learning.js +22 -7
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +3 -3
- package/dist/suggestions.js +3 -2
- package/dist/template-eval.d.ts +20 -9
- package/dist/template-eval.js +115 -33
- package/dist/template-import.d.ts +10 -0
- package/dist/template-import.js +16 -7
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +28 -8
- package/dist/timeline/labels.d.ts +6 -4
- package/dist/timeline/labels.js +18 -6
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +14 -8
- package/dist/timeline/util.js +1 -1
- package/dist/timeline/web-calls.d.ts +26 -9
- package/dist/timeline/web-calls.js +124 -37
- package/dist/tool-gate.d.ts +42 -3
- package/dist/tool-gate.js +66 -5
- package/dist/tool-keys-store.d.ts +2 -4
- package/dist/tool-keys-store.js +5 -21
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-keys.js +2 -2
- package/dist/tool-list.js +1 -1
- package/dist/tool-plane.d.ts +2 -2
- package/dist/tool-plane.js +35 -33
- package/dist/tools.js +13 -7
- package/dist/trigger-targets.d.ts +4 -0
- package/dist/trigger-targets.js +9 -2
- package/dist/triggers.d.ts +67 -4
- package/dist/triggers.js +171 -22
- package/dist/until.d.ts +3 -0
- package/dist/until.js +11 -0
- package/dist/web-fake.d.ts +1 -3
- package/dist/web-fake.js +7 -18
- package/dist/web-fetch.d.ts +6 -72
- package/dist/web-fetch.js +11 -265
- package/dist/web-run.d.ts +31 -0
- package/dist/web-run.js +90 -0
- package/dist/web-save.d.ts +6 -4
- package/dist/web-save.js +9 -12
- package/dist/web-search.d.ts +9 -127
- package/dist/web-search.js +23 -259
- package/dist/wires.d.ts +13 -0
- package/dist/wires.js +11 -0
- package/dist/workflow-run.d.ts +5 -4
- package/dist/workflow-run.js +5 -4
- package/dist/workspace/computer-deps.d.ts +2 -1
- package/dist/workspace/computer-deps.js +9 -2
- package/dist/workspace/computer-for-claim.d.ts +12 -1
- package/dist/workspace/computer-for-claim.js +77 -8
- package/dist/workspace/computer-kept.d.ts +3 -0
- package/dist/workspace/computer-kept.js +11 -2
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/kind-skills.d.ts +4 -0
- package/dist/workspace/kind-skills.js +9 -0
- package/dist/workspace/synced-folder.js +3 -4
- package/dist/wrapped.d.ts +13 -5
- package/dist/wrapped.js +52 -26
- package/package.json +17 -11
- package/skills/agentrun-serve/SKILL.md +4 -0
- package/templates/README.md +30 -8
- package/dist/console/assets/index-CQ3cJRzI.js +0 -746
- package/dist/console/assets/index-DKkaS3a0.css +0 -1
- package/dist/exa-keyless.d.ts +0 -34
- package/dist/exa-keyless.js +0 -118
- package/dist/firecrawl-keyless.d.ts +0 -41
- package/dist/firecrawl-keyless.js +0 -152
- package/dist/keyless-mcp.d.ts +0 -36
- package/dist/keyless-mcp.js +0 -127
- package/dist/text-urls.d.ts +0 -38
- package/dist/text-urls.js +0 -170
- package/dist/web-fetch-direct.d.ts +0 -119
- package/dist/web-fetch-direct.js +0 -190
package/dist/web-search.d.ts
CHANGED
|
@@ -1,137 +1,19 @@
|
|
|
1
1
|
import type { TSchema } from "typebox";
|
|
2
2
|
import type { JsonValue } from "@earendil-works/chord/json";
|
|
3
3
|
import { type ToolRegistration } from "@earendil-works/pi-durable";
|
|
4
|
-
import { type
|
|
5
|
-
import { type
|
|
6
|
-
|
|
4
|
+
import { type Search, type SearchBounds } from "@parcha/agentrun-web";
|
|
5
|
+
import { type SearchOn } from "./web-run.js";
|
|
6
|
+
export type { SearchOn };
|
|
7
7
|
export declare const WEB_SEARCH_TOOL = "web_search";
|
|
8
8
|
/** The tools that reach the web, each through the provider its run's plane resolves it to. */
|
|
9
9
|
export declare const WEB_TOOLS: readonly string[];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export declare const RESULTS_MAX = 25;
|
|
13
|
-
/** The most of a result's text its snippet keeps; Parallel is asked for as much of each result's excerpts. */
|
|
14
|
-
export declare const SNIPPET_MAX = 3000;
|
|
15
|
-
/** The most of the provider's own short answer (`text`) a search keeps (hosted-search.ts). */
|
|
16
|
-
export declare const ANSWER_MAX = 4000;
|
|
17
|
-
/** The most characters a search's answer takes, its citing line included: about RESULTS_MAX results with whole snippets,
|
|
18
|
-
* under the host's result bound (HOST_RESULT_MAX_CHARS), which the host-bounds test holds it to. */
|
|
19
|
-
export declare const SEARCH_MAX_CHARS = 100000;
|
|
20
|
-
/** What every later web_search call of a run answers once its provider said the run is out of quota (a Limit of kind
|
|
21
|
-
* quota): the provider is not asked again in that run. */
|
|
22
|
-
export declare const SEARCH_UNAVAILABLE = "search is unavailable for the rest of this run; answer from what you have";
|
|
23
|
-
/** What a call answers while a rate limit's wait holds, `seconds` of it left. */
|
|
24
|
-
export declare const searchBusy: (seconds: number) => string;
|
|
25
|
-
export type Hit = {
|
|
26
|
-
url: string;
|
|
27
|
-
title: string;
|
|
28
|
-
snippet: string;
|
|
29
|
-
published?: string;
|
|
30
|
-
};
|
|
31
|
-
export type Search = {
|
|
32
|
-
provider: "native" | "firecrawl-keyless" | "exa-keyless" | "parallel";
|
|
33
|
-
query: string;
|
|
34
|
-
results: Hit[];
|
|
35
|
-
text?: string;
|
|
36
|
-
omitted?: number;
|
|
37
|
-
} | {
|
|
38
|
-
error: string;
|
|
39
|
-
};
|
|
40
|
-
/** What a provider's failure said of the run's search: out of quota, or rate-limited, with the wait it named as it
|
|
41
|
-
* handed it back (a Retry-After header's value, delta-seconds or an HTTP date, or Exa's seconds). `repeatIsQuota`, the
|
|
42
|
-
* server's mark on keyless Exa's limit naming no wait alone (exaLimitOf): Exa answers its daily count running out as
|
|
43
|
-
* that limit, so the same answer again once a wait has passed is that count (searchBreaker). */
|
|
44
|
-
export type Limit = {
|
|
45
|
-
kind: "quota";
|
|
46
|
-
} | {
|
|
47
|
-
kind: "rate";
|
|
48
|
-
retryAfter?: string | number;
|
|
49
|
-
repeatIsQuota?: true;
|
|
50
|
-
};
|
|
51
|
-
/** A Search, and the limit its provider answered, if any: the run's breaker reads `limit` (searchBreaker), the model the
|
|
52
|
-
* Search alone. */
|
|
53
|
-
export type Searched = {
|
|
54
|
-
answer: Search;
|
|
55
|
-
limit?: Limit;
|
|
56
|
-
};
|
|
57
|
-
/** The wait `retryAfter` names, in ms from `nowMs`: delta-seconds, an HTTP date, or Exa's seconds. None, or words that
|
|
58
|
-
* read as neither, 60 s; a date already passed, none; never more than 15 minutes (MAX_WAIT_MS). */
|
|
59
|
-
export declare function waitOf(retryAfter: string | number | undefined, nowMs: number): number;
|
|
60
|
-
/** A run's breaker on its web_search, read at `now`. `held` is what a call answers unsent while it holds: SEARCH_UNAVAILABLE
|
|
61
|
-
* for the rest of the run once a quota answer came, or searchBusy with the seconds left of a rate limit's wait (rounded
|
|
62
|
-
* up, so at least 1); else undefined, and the call asks the provider. `read` takes a search's own answer and its limit:
|
|
63
|
-
* a quota answer turns search off for good, a rate limit holds search for its wait from now, or for the wait already
|
|
64
|
-
* open when that ends later (two calls in flight: a short wait never shrinks a long one), anything else leaves it as it
|
|
65
|
-
* is. A rate limit marked repeatIsQuota (keyless Exa's, naming no wait) after an earlier marked one whose wait has
|
|
66
|
-
* passed counts as a quota answer: off for the run, and that call answers SEARCH_UNAVAILABLE in place of its own words
|
|
67
|
-
* (Exa's "try again in a minute"). A quota answer keeps the call's own answer, which names no retry. One that comes
|
|
68
|
-
* while a wait is open (in flight with the first) only holds it, and a search that succeeds in between resets the
|
|
69
|
-
* count: once Exa's daily count is spent every keyless call is limited, so a success means it is not. A failed search
|
|
70
|
-
* that is no limit resets nothing. */
|
|
71
|
-
export type Breaker = {
|
|
72
|
-
held(): Search | undefined;
|
|
73
|
-
read(searched: Searched): Search;
|
|
74
|
-
off(): boolean;
|
|
75
|
-
left(): number;
|
|
76
|
-
};
|
|
77
|
-
export declare function searchBreaker(now?: () => number): Breaker;
|
|
78
|
-
/** The line that ends a search's answer to the model, as Claude Code's WebSearch ends its own. */
|
|
79
|
-
export declare const CITE = "Cite the URL of each result you rely on.";
|
|
80
|
-
/** `answer` within SEARCH_MAX_CHARS, as searchText writes it: whole when it fits, else without its least relevant results
|
|
81
|
-
* (the last), as many as it takes, `omitted` counting them. */
|
|
82
|
-
export declare function fitSearch(answer: Search): Search;
|
|
83
|
-
/** A search as the model reads it: its JSON (fitSearch), then the line asking it to cite the URLs it relies on; an
|
|
84
|
-
* error's JSON alone. */
|
|
85
|
-
export declare function searchText(answer: Search): string;
|
|
86
|
-
/** A result's text as its snippet: links reduced to their text, whitespace collapsed, cut at SNIPPET_MAX on a word. */
|
|
87
|
-
export declare function snippetOf(raw: string): string;
|
|
88
|
-
/** `{query, n?}` as every provider takes it: the query trimmed and cut at QUERY_MAX, n 1 to RESULTS_MAX. */
|
|
89
|
-
export declare const searchArgs: (args: Record<string, unknown>) => {
|
|
90
|
-
query: string;
|
|
91
|
-
n: number;
|
|
92
|
-
};
|
|
93
|
-
/** `{query, n?}` searched through `parallel` (null: the run holds no key), as a Search. */
|
|
94
|
-
export declare function webSearch(args: Record<string, unknown>, parallel: Extract | null, signal?: AbortSignal): Promise<Search>;
|
|
95
|
-
/** The run's models a native search goes through, asked when a search runs (the runner's: the session's port, up once
|
|
96
|
-
* the session is open): ToolHost.search, EffectRun.search. */
|
|
97
|
-
export type SearchOn = () => Promise<SearchModels | undefined>;
|
|
98
|
-
/** `{query, n?}` searched by the provider the run's plane resolves web_search to, as a Search. `models`: the run's own
|
|
99
|
-
* models a native search goes through (none: a native search has no model to search on). */
|
|
10
|
+
/** `args` searched as the run's web_search, on fresh breakers: a call node's search falls to the next backend as the
|
|
11
|
+
* agent's does, and holds nothing after. */
|
|
100
12
|
export declare function searchFor(env: NodeJS.ProcessEnv, args: Record<string, unknown>, signal?: AbortSignal, models?: SearchOn): Promise<Search>;
|
|
101
|
-
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
|
|
105
|
-
name: string;
|
|
106
|
-
ask(deadline: AbortSignal): Promise<Searched>;
|
|
107
|
-
};
|
|
108
|
-
/** The most one call of web_search spends across its keyless backends together: Firecrawl's failing or timing out
|
|
109
|
-
* leaves Exa what is left of it, never a fresh bound. Firecrawl's own bound inside it (FIRECRAWL_MS, 30 s) leaves Exa
|
|
110
|
-
* at least the rest. */
|
|
111
|
-
export declare const KEYLESS_SEARCH_MS = 60000;
|
|
112
|
-
/** A call's bounds, a test's: `searchMs`, its one deadline (KEYLESS_SEARCH_MS); `firecrawlMs`, Firecrawl's own inside it
|
|
113
|
-
* (FIRECRAWL_MS). */
|
|
114
|
-
export type SearchBounds = {
|
|
115
|
-
searchMs?: number;
|
|
116
|
-
firecrawlMs?: number;
|
|
117
|
-
};
|
|
118
|
-
/** A call's search through `backends` in turn, each through its breaker (`breakerOf`, by its name) and all under one
|
|
119
|
-
* deadline, `boundMs` from the call's start or the caller's `signal`: the first that answers results is the answer,
|
|
120
|
-
* and one that fails or that its breaker holds passes the call to the next, unless the deadline is spent: no backend
|
|
121
|
-
* starts on a spent one. None left:
|
|
122
|
-
* SEARCH_UNAVAILABLE where every backend is off (a lone backend's own answer where it was asked, as its breaker reads
|
|
123
|
-
* it), else the last failure, else searchBusy for the shortest wait. */
|
|
124
|
-
export declare function searchInTurn(backends: readonly Backend[], breakerOf: (name: string) => Breaker, signal?: AbortSignal, boundMs?: number): Promise<Search>;
|
|
125
|
-
/** Keyless Exa's refusal as the run's breaker reads it: a rate limit, with the wait it named. One naming no wait (its MCP
|
|
126
|
-
* notice, as its daily count running out answers) is marked repeatIsQuota, so a second one past a wait is that count; a
|
|
127
|
-
* 429 with Retry-After is a timed limit, unmarked. A refused connection is no limit (a 403 no wait lifts). */
|
|
128
|
-
export declare function exaLimitOf(found: ExaLimited): Limit | undefined;
|
|
129
|
-
/** The agent's tool: the Search as JSON text. A run whose web_search resolves to Parallel reads its key as the tool is
|
|
130
|
-
* made, when the run opens; one that resolves native searches through `models`, the run's own (ToolHost.search).
|
|
131
|
-
* `fake`: what answers each search in the provider's place (a template eval's web fake, web-fake.ts), the provider
|
|
132
|
-
* the run's plane names given it, the tool otherwise the same. `now`: the breakers' clock (a test's); `bounds`: a call's
|
|
133
|
-
* deadline across its keyless backends and Firecrawl's own inside it (a test's; SearchBounds). */
|
|
13
|
+
/** The agent's tool. The run's Web is made as the tool is bound, so a run whose web_search resolves to Parallel reads its
|
|
14
|
+
* key when the run opens. `fake`: what answers each search in the provider's place (a template eval's web fake,
|
|
15
|
+
* web-fake.ts). `now` and `bounds`: a test's breaker clock and this binding's search deadlines, held by its calls
|
|
16
|
+
* alone. */
|
|
134
17
|
export declare function webSearchTool(env: NodeJS.ProcessEnv, models?: SearchOn, fake?: (args: Record<string, unknown>, provider: Exclude<Search, {
|
|
135
18
|
error: string;
|
|
136
19
|
}>["provider"]) => Search, now?: () => number, bounds?: SearchBounds): ToolRegistration<TSchema, JsonValue>;
|
|
137
|
-
export {};
|
package/dist/web-search.js
CHANGED
|
@@ -1,276 +1,40 @@
|
|
|
1
1
|
import { defineTool } from "@earendil-works/pi-durable";
|
|
2
|
-
import {
|
|
2
|
+
import { breakers, fitSearch, QUERY_MAX, RESULTS_DEFAULT, RESULTS_MAX, searchArgs, searchText } from "@parcha/agentrun-web";
|
|
3
3
|
import { forModel } from "./result.js";
|
|
4
|
-
import { fauxFetch } from "./decisions.js";
|
|
5
|
-
import { FAUX_ENV } from "./model.js";
|
|
6
|
-
import { exaSearch, FAUX_EXA_ENV } from "./exa-keyless.js";
|
|
7
|
-
import { FAUX_FIRECRAWL_ENV, firecrawlSearch } from "./firecrawl-keyless.js";
|
|
8
|
-
import { hostedSearched } from "./hosted-search.js";
|
|
9
|
-
import { PaidRefused } from "./paid-calls.js";
|
|
10
4
|
import { planeOf, whyUnavailable } from "./tool-plane.js";
|
|
11
|
-
import {
|
|
5
|
+
import { WEB_FETCH_TOOL } from "./web-fetch.js";
|
|
6
|
+
import { ordersOf, searchingOn, webOf } from "./web-run.js";
|
|
12
7
|
export const WEB_SEARCH_TOOL = "web_search";
|
|
13
8
|
/** The tools that reach the web, each through the provider its run's plane resolves it to. */
|
|
14
9
|
export const WEB_TOOLS = [WEB_FETCH_TOOL, WEB_SEARCH_TOOL];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export const RESULTS_MAX = 25;
|
|
18
|
-
const RESULTS_DEFAULT = 10;
|
|
19
|
-
/** The most of a result's text its snippet keeps; Parallel is asked for as much of each result's excerpts. */
|
|
20
|
-
export const SNIPPET_MAX = 3_000;
|
|
21
|
-
/** The most of the provider's own short answer (`text`) a search keeps (hosted-search.ts). */
|
|
22
|
-
export const ANSWER_MAX = 4_000;
|
|
23
|
-
/** The most characters a search's answer takes, its citing line included: about RESULTS_MAX results with whole snippets,
|
|
24
|
-
* under the host's result bound (HOST_RESULT_MAX_CHARS), which the host-bounds test holds it to. */
|
|
25
|
-
export const SEARCH_MAX_CHARS = 100_000;
|
|
26
|
-
const REFUSED = "Parallel refused this run's key (401 or 403): it is not asked again in this run";
|
|
27
|
-
/** What every later web_search call of a run answers once its provider said the run is out of quota (a Limit of kind
|
|
28
|
-
* quota): the provider is not asked again in that run. */
|
|
29
|
-
export const SEARCH_UNAVAILABLE = "search is unavailable for the rest of this run; answer from what you have";
|
|
30
|
-
/** What a call answers while a rate limit's wait holds, `seconds` of it left. */
|
|
31
|
-
export const searchBusy = (seconds) => `search is busy; try again in ${seconds} s, or answer from what you have`;
|
|
32
|
-
/** The wait a rate limit holds a run's search for when no Retry-After reaches here. */
|
|
33
|
-
const DEFAULT_WAIT_MS = 60_000;
|
|
34
|
-
/** The longest wait a Retry-After holds a run's search for: 15 minutes. A provider naming hours, or a date far off (a
|
|
35
|
-
* clock that is wrong), would stop a long run's search as a quota answer does; past 15 minutes the next call asks. */
|
|
36
|
-
const MAX_WAIT_MS = 15 * 60_000;
|
|
37
|
-
/** The wait `retryAfter` names, in ms from `nowMs`: delta-seconds, an HTTP date, or Exa's seconds. None, or words that
|
|
38
|
-
* read as neither, 60 s; a date already passed, none; never more than 15 minutes (MAX_WAIT_MS). */
|
|
39
|
-
export function waitOf(retryAfter, nowMs) {
|
|
40
|
-
const said = typeof retryAfter === "string" ? retryAfter.trim() : retryAfter;
|
|
41
|
-
const ms = typeof said === "number" ? said * 1_000 : said && /^\d+$/.test(said) ? Number(said) * 1_000 : said ? Date.parse(said) - nowMs : Number.NaN;
|
|
42
|
-
return Number.isFinite(ms) ? Math.min(Math.max(ms, 0), MAX_WAIT_MS) : DEFAULT_WAIT_MS;
|
|
43
|
-
}
|
|
44
|
-
/** `ms` of a wait as searchBusy's seconds: rounded up, at least 1. */
|
|
45
|
-
const busyFor = (ms) => ({ error: searchBusy(Math.max(1, Math.ceil(ms / 1_000))) });
|
|
46
|
-
export function searchBreaker(now = Date.now) {
|
|
47
|
-
let off = false;
|
|
48
|
-
let until = 0;
|
|
49
|
-
// A marked rate limit (keyless Exa's) has opened a wait in this run, with no search succeeding since.
|
|
50
|
-
let marked = false;
|
|
51
|
-
return {
|
|
52
|
-
held() {
|
|
53
|
-
if (off)
|
|
54
|
-
return { error: SEARCH_UNAVAILABLE };
|
|
55
|
-
const left = until - now();
|
|
56
|
-
return left > 0 ? busyFor(left) : undefined;
|
|
57
|
-
},
|
|
58
|
-
off: () => off,
|
|
59
|
-
left: () => Math.max(0, until - now()),
|
|
60
|
-
read({ answer, limit }) {
|
|
61
|
-
if (!("error" in answer))
|
|
62
|
-
marked = false;
|
|
63
|
-
if (limit?.kind === "quota")
|
|
64
|
-
off = true;
|
|
65
|
-
else if (limit) {
|
|
66
|
-
const at = now();
|
|
67
|
-
// The call that turns search off answers so itself, never its limit's "try again" words.
|
|
68
|
-
if (limit.repeatIsQuota && marked && at >= until) {
|
|
69
|
-
off = true;
|
|
70
|
-
return { error: SEARCH_UNAVAILABLE };
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
if (limit.repeatIsQuota)
|
|
74
|
-
marked = true;
|
|
75
|
-
until = Math.max(until, at + waitOf(limit.retryAfter, at));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return answer;
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/** The line that ends a search's answer to the model, as Claude Code's WebSearch ends its own. */
|
|
83
|
-
export const CITE = "Cite the URL of each result you rely on.";
|
|
84
|
-
/** `answer` within SEARCH_MAX_CHARS, as searchText writes it: whole when it fits, else without its least relevant results
|
|
85
|
-
* (the last), as many as it takes, `omitted` counting them. */
|
|
86
|
-
export function fitSearch(answer) {
|
|
87
|
-
if ("error" in answer)
|
|
88
|
-
return answer;
|
|
89
|
-
const room = SEARCH_MAX_CHARS - CITE.length - 1;
|
|
90
|
-
let fitted = answer;
|
|
91
|
-
for (let kept = answer.results.length; JSON.stringify(fitted).length > room && kept > 0;) {
|
|
92
|
-
kept -= 1;
|
|
93
|
-
fitted = { ...answer, results: answer.results.slice(0, kept), omitted: answer.results.length - kept };
|
|
94
|
-
}
|
|
95
|
-
return fitted;
|
|
96
|
-
}
|
|
97
|
-
/** A search as the model reads it: its JSON (fitSearch), then the line asking it to cite the URLs it relies on; an
|
|
98
|
-
* error's JSON alone. */
|
|
99
|
-
export function searchText(answer) {
|
|
100
|
-
const fitted = fitSearch(answer);
|
|
101
|
-
return "error" in fitted ? JSON.stringify(fitted) : `${JSON.stringify(fitted)}\n${CITE}`;
|
|
102
|
-
}
|
|
103
|
-
/** A result's text as its snippet: links reduced to their text, whitespace collapsed, cut at SNIPPET_MAX on a word. */
|
|
104
|
-
export function snippetOf(raw) {
|
|
105
|
-
const text = raw.replace(/!?\[([^\]]*)\]\([^)\s]*\)/g, "$1").replace(/\s+/g, " ").trim();
|
|
106
|
-
if (text.length <= SNIPPET_MAX)
|
|
107
|
-
return text;
|
|
108
|
-
const cut = text.slice(0, SNIPPET_MAX - 1);
|
|
109
|
-
const space = cut.lastIndexOf(" ");
|
|
110
|
-
return `${(space > SNIPPET_MAX / 2 ? cut.slice(0, space) : cut).trimEnd()}…`;
|
|
111
|
-
}
|
|
112
|
-
/** `{query, n?}` as every provider takes it: the query trimmed and cut at QUERY_MAX, n 1 to RESULTS_MAX. */
|
|
113
|
-
export const searchArgs = (args) => ({
|
|
114
|
-
query: typeof args.query === "string" ? args.query.trim().slice(0, QUERY_MAX) : "",
|
|
115
|
-
n: Math.max(1, Math.min(RESULTS_MAX, Math.floor(Number(args.n) || RESULTS_DEFAULT))),
|
|
116
|
-
});
|
|
117
|
-
/** What a Parallel answer's status says of the run's search: out of credit (402), or rate-limited (429) for its
|
|
118
|
-
* Retry-After. */
|
|
119
|
-
const parallelLimit = (response) => {
|
|
120
|
-
if (response.status === 402)
|
|
121
|
-
return { kind: "quota" };
|
|
122
|
-
const retryAfter = response.headers.get("retry-after");
|
|
123
|
-
return response.status === 429 ? { kind: "rate", ...(retryAfter ? { retryAfter } : {}) } : undefined;
|
|
124
|
-
};
|
|
125
|
-
/** `{query, n?}` searched through `parallel` (null: the run holds no key), as a Search. */
|
|
126
|
-
export async function webSearch(args, parallel, signal) {
|
|
127
|
-
return (await parallelSearched(args, parallel, signal)).answer;
|
|
128
|
-
}
|
|
129
|
-
/** webSearch, and the limit Parallel answered for the run's key, if any. */
|
|
130
|
-
async function parallelSearched(args, parallel, signal) {
|
|
131
|
-
const answer = (search) => ({ answer: search });
|
|
132
|
-
const { query, n } = searchArgs(args);
|
|
133
|
-
if (!query)
|
|
134
|
-
return answer({ error: "web_search needs a query" });
|
|
135
|
-
if (!parallel)
|
|
136
|
-
return answer({ error: "web_search searches through Parallel, and this run holds no Parallel key (PARALLEL_API_KEY)" });
|
|
137
|
-
if (!parallel.live())
|
|
138
|
-
return answer({ error: REFUSED });
|
|
139
|
-
try {
|
|
140
|
-
const response = await parallel.post(PARALLEL_SEARCH_URL, { objective: query, search_queries: [query], mode: "fast", advanced_settings: { max_results: n, excerpt_settings: { max_chars_per_result: SNIPPET_MAX } } }, signal);
|
|
141
|
-
if (!response.ok) {
|
|
142
|
-
await response.body?.cancel().catch(() => undefined);
|
|
143
|
-
const limit = parallelLimit(response);
|
|
144
|
-
return parallel.live() ? { answer: { error: `Parallel's search answered ${response.status}` }, ...(limit ? { limit } : {}) } : answer({ error: REFUSED });
|
|
145
|
-
}
|
|
146
|
-
const { results } = (await response.json());
|
|
147
|
-
const hits = (Array.isArray(results) ? results : []).flatMap((row) => {
|
|
148
|
-
if (typeof row?.url !== "string")
|
|
149
|
-
return [];
|
|
150
|
-
const excerpts = Array.isArray(row.excerpts) ? row.excerpts.filter((text) => typeof text === "string") : [];
|
|
151
|
-
return [{ url: row.url, title: typeof row.title === "string" ? clip(row.title, TITLE_CAP) : "", snippet: snippetOf(excerpts.join(" … ")), ...(typeof row.publish_date === "string" ? { published: row.publish_date } : {}) }];
|
|
152
|
-
});
|
|
153
|
-
return answer({ provider: "parallel", query, results: hits.slice(0, n) });
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
if (error instanceof PaidRefused)
|
|
157
|
-
return answer({ error: error.message });
|
|
158
|
-
return answer({ error: error?.name === "TimeoutError" ? "Parallel's search did not answer within 60 s" : `Parallel's search failed: ${error?.message ?? String(error)}` });
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/** `{query, n?}` searched by the provider the run's plane resolves web_search to, as a Search. `models`: the run's own
|
|
162
|
-
* models a native search goes through (none: a native search has no model to search on). */
|
|
10
|
+
/** `args` searched as the run's web_search, on fresh breakers: a call node's search falls to the next backend as the
|
|
11
|
+
* agent's does, and holds nothing after. */
|
|
163
12
|
export async function searchFor(env, args, signal, models) {
|
|
164
|
-
// One call's breakers: a call node's search falls to the next backend as the agent's does, and holds nothing after.
|
|
165
13
|
return searched(env, args, breakers(), signal, models);
|
|
166
14
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
/** The backends a call searching `query` asks in turn, by the provider the run's plane resolves web_search to (with
|
|
172
|
-
* keyless Firecrawl, keyless Exa behind it), or why it asks none. Under --faux, Firecrawl is the fake's URL
|
|
173
|
-
* (FAUX_FIRECRAWL_ENV) and Exa the faux module's: one the server names none of is not asked, so a test never reaches
|
|
174
|
-
* the network. */
|
|
175
|
-
async function backendsOf(env, args, signal, models, firecrawlMs) {
|
|
176
|
-
const plane = planeOf(env);
|
|
177
|
-
const resolved = plane.web_search;
|
|
178
|
-
if (resolved === "parallel")
|
|
179
|
-
return [{ name: "parallel", ask: () => parallelSearched(args, parallelOf(env), signal) }];
|
|
180
|
-
if (resolved !== "native" && resolved !== "exa-keyless" && resolved !== "firecrawl-keyless")
|
|
181
|
-
return `web_search does not run here: ${resolved === undefined ? "no provider was resolved for it" : whyUnavailable(resolved)}`;
|
|
15
|
+
async function searched(env, args, breakerOf, signal, models, bounds) {
|
|
16
|
+
const resolved = planeOf(env).web_search;
|
|
17
|
+
if (resolved !== "parallel" && resolved !== "native" && resolved !== "exa-keyless" && resolved !== "firecrawl-keyless")
|
|
18
|
+
return { error: `web_search does not run here: ${resolved === undefined ? "no provider was resolved for it" : whyUnavailable(resolved)}` };
|
|
182
19
|
const { query, n } = searchArgs(args);
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const backends = [];
|
|
189
|
-
const fakeFirecrawl = faux ? env[FAUX_FIRECRAWL_ENV] : undefined;
|
|
190
|
-
if (resolved === "firecrawl-keyless" && (!faux || fakeFirecrawl)) {
|
|
191
|
-
backends.push({ name: "firecrawl-keyless", ask: async (deadline) => {
|
|
192
|
-
const found = await firecrawlSearch(query, n, { ...(fakeFirecrawl ? { endpoint: fakeFirecrawl } : {}), signal: deadline, ...(firecrawlMs === undefined ? {} : { timeoutMs: firecrawlMs }) });
|
|
193
|
-
// Which limit Firecrawl met is the server's to read, never the model's: it reads the error alone.
|
|
194
|
-
if (!("error" in found))
|
|
195
|
-
return { answer: found };
|
|
196
|
-
return { answer: { error: found.error }, ...("limit" in found && found.limit ? { limit: found.limit } : {}) };
|
|
197
|
-
} });
|
|
198
|
-
}
|
|
199
|
-
const fakeExa = await fauxFetch(env, FAUX_EXA_ENV);
|
|
200
|
-
if (!faux || fakeExa) {
|
|
201
|
-
backends.push({ name: "exa-keyless", ask: async (deadline) => {
|
|
202
|
-
const found = await exaSearch(query, n, { ...(fakeExa ? { send: fakeExa } : {}), signal: deadline });
|
|
203
|
-
if (!("limit" in found))
|
|
204
|
-
return { answer: found };
|
|
205
|
-
const limit = exaLimitOf(found);
|
|
206
|
-
return { answer: { error: found.error }, ...(limit ? { limit } : {}) };
|
|
207
|
-
} });
|
|
20
|
+
if (resolved !== "parallel") {
|
|
21
|
+
if (!query)
|
|
22
|
+
return { error: "web_search needs a query" };
|
|
23
|
+
if (!ordersOf(env).search.length)
|
|
24
|
+
return { error: "web_search: under --faux, the keyless search endpoints are fakes', and this server names none" };
|
|
208
25
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
/** A call's search through `backends` in turn, each through its breaker (`breakerOf`, by its name) and all under one
|
|
212
|
-
* deadline, `boundMs` from the call's start or the caller's `signal`: the first that answers results is the answer,
|
|
213
|
-
* and one that fails or that its breaker holds passes the call to the next, unless the deadline is spent: no backend
|
|
214
|
-
* starts on a spent one. None left:
|
|
215
|
-
* SEARCH_UNAVAILABLE where every backend is off (a lone backend's own answer where it was asked, as its breaker reads
|
|
216
|
-
* it), else the last failure, else searchBusy for the shortest wait. */
|
|
217
|
-
export async function searchInTurn(backends, breakerOf, signal, boundMs = KEYLESS_SEARCH_MS) {
|
|
218
|
-
const deadline = AbortSignal.any([AbortSignal.timeout(boundMs), ...(signal ? [signal] : [])]);
|
|
219
|
-
let last;
|
|
220
|
-
for (const backend of backends) {
|
|
221
|
-
const breaker = breakerOf(backend.name);
|
|
222
|
-
if (breaker.held())
|
|
223
|
-
continue;
|
|
224
|
-
if (last && deadline.aborted)
|
|
225
|
-
break;
|
|
226
|
-
const answer = breaker.read(await backend.ask(deadline));
|
|
227
|
-
if (!("error" in answer))
|
|
228
|
-
return answer;
|
|
229
|
-
last = answer;
|
|
230
|
-
}
|
|
231
|
-
const breakers = backends.map((backend) => breakerOf(backend.name));
|
|
232
|
-
if (breakers.every((breaker) => breaker.off()))
|
|
233
|
-
return backends.length === 1 && last ? last : { error: SEARCH_UNAVAILABLE };
|
|
234
|
-
// A backend that turned off in this call while another only waits: the run's search is not off, so it waits.
|
|
235
|
-
if (last && !("error" in last && last.error === SEARCH_UNAVAILABLE))
|
|
236
|
-
return last;
|
|
237
|
-
return busyFor(Math.min(...breakers.filter((breaker) => !breaker.off()).map((breaker) => breaker.left())));
|
|
238
|
-
}
|
|
239
|
-
/** Breakers by backend name, made at first use: one run's (webSearchTool), or one call's (searchFor). */
|
|
240
|
-
const breakers = (now = Date.now) => {
|
|
241
|
-
const made = new Map();
|
|
242
|
-
return (name) => {
|
|
243
|
-
let breaker = made.get(name);
|
|
244
|
-
if (!breaker)
|
|
245
|
-
made.set(name, (breaker = searchBreaker(now)));
|
|
246
|
-
return breaker;
|
|
247
|
-
};
|
|
248
|
-
};
|
|
249
|
-
/** searchFor through `breakerOf`: an error with no backend to ask, else searchInTurn. */
|
|
250
|
-
async function searched(env, args, breakerOf, signal, models, bounds = {}) {
|
|
251
|
-
const backends = await backendsOf(env, args, signal, models, bounds.firecrawlMs);
|
|
252
|
-
return typeof backends === "string" ? { error: backends } : searchInTurn(backends, breakerOf, signal, bounds.searchMs);
|
|
253
|
-
}
|
|
254
|
-
/** Keyless Exa's refusal as the run's breaker reads it: a rate limit, with the wait it named. One naming no wait (its MCP
|
|
255
|
-
* notice, as its daily count running out answers) is marked repeatIsQuota, so a second one past a wait is that count; a
|
|
256
|
-
* 429 with Retry-After is a timed limit, unmarked. A refused connection is no limit (a 403 no wait lifts). */
|
|
257
|
-
export function exaLimitOf(found) {
|
|
258
|
-
if (found.limit !== "rate_limited")
|
|
259
|
-
return undefined;
|
|
260
|
-
return found.retryAfterS === undefined ? { kind: "rate", repeatIsQuota: true } : { kind: "rate", retryAfter: found.retryAfterS };
|
|
26
|
+
const { answer } = await searchingOn.run(models, () => webOf(env).search(query, { n, breakers: breakerOf, ...(signal ? { signal } : {}), ...(bounds ? { bounds } : {}) }));
|
|
27
|
+
return answer;
|
|
261
28
|
}
|
|
262
|
-
/** The agent's tool
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
* deadline across its keyless backends and Firecrawl's own inside it (a test's; SearchBounds). */
|
|
29
|
+
/** The agent's tool. The run's Web is made as the tool is bound, so a run whose web_search resolves to Parallel reads its
|
|
30
|
+
* key when the run opens. `fake`: what answers each search in the provider's place (a template eval's web fake,
|
|
31
|
+
* web-fake.ts). `now` and `bounds`: a test's breaker clock and this binding's search deadlines, held by its calls
|
|
32
|
+
* alone. */
|
|
267
33
|
export function webSearchTool(env, models, fake, now = Date.now, bounds) {
|
|
268
34
|
const provider = planeOf(env).web_search;
|
|
269
35
|
const parallel = provider === "parallel";
|
|
270
|
-
if (
|
|
271
|
-
|
|
272
|
-
// The run's breakers, one a backend, made with the tool as the run binds it, so they are this run's alone: a call
|
|
273
|
-
// every backend's breaker holds answers its words unsent (searchInTurn).
|
|
36
|
+
if (!fake)
|
|
37
|
+
webOf(env);
|
|
274
38
|
const breakerOf = breakers(now);
|
|
275
39
|
const named = provider === "native" || provider === "parallel" || provider === "exa-keyless" ? provider : "firecrawl-keyless";
|
|
276
40
|
return defineTool({
|
|
@@ -287,7 +51,7 @@ export function webSearchTool(env, models, fake, now = Date.now, bounds) {
|
|
|
287
51
|
},
|
|
288
52
|
replay: "safe",
|
|
289
53
|
execute: async (args, _api, context) => {
|
|
290
|
-
const answer =
|
|
54
|
+
const answer = fake ? fitSearch(fake(args, named)) : await searched(env, args, breakerOf, context?.abortSignal, models, bounds);
|
|
291
55
|
return forModel(searchText(answer), { details: answer });
|
|
292
56
|
},
|
|
293
57
|
});
|
package/dist/wires.d.ts
CHANGED
|
@@ -14,3 +14,16 @@ export declare const WIRES: Readonly<Record<Wire, {
|
|
|
14
14
|
export declare const modelWire: (wire: HarnessWire) => wire is Wire;
|
|
15
15
|
/** A harness's wire's settings, or undefined for one billed to its own plan (modelWire). */
|
|
16
16
|
export declare const wireOf: (wire: HarnessWire) => (typeof WIRES)[Wire] | undefined;
|
|
17
|
+
/** The providers whose models the runner's model route translates onto a wire, each with the wires it translates them
|
|
18
|
+
* onto (runner/model-route.ts routeOf, its own fetch: messagesFetch): an Ollama model of this machine (ollama-provider.ts)
|
|
19
|
+
* onto Anthropic's Messages. Every harness on such a wire is offered those models and runs them through the route, at
|
|
20
|
+
* their price, whatever harness it is: the wire decides, never a harness's id. A leaf's data: provider ids by name. */
|
|
21
|
+
export declare const TRANSLATED: Readonly<Record<string, readonly Wire[]>>;
|
|
22
|
+
/** Whether `model`'s requests on a harness of `wire` go through the route's translation (TRANSLATED). */
|
|
23
|
+
export declare const routed: (wire: HarnessWire, model: {
|
|
24
|
+
readonly provider: string;
|
|
25
|
+
}) => boolean;
|
|
26
|
+
/** routed, for a model named `provider/model-id`. */
|
|
27
|
+
export declare const routedId: (wire: HarnessWire, id: string) => boolean;
|
|
28
|
+
/** Whether the route translates any provider's models onto `wire` (TRANSLATED): a harness on it may run on one with no key. */
|
|
29
|
+
export declare const translatesOnto: (wire: HarnessWire) => boolean;
|
package/dist/wires.js
CHANGED
|
@@ -10,3 +10,14 @@ export const WIRES = Object.freeze({
|
|
|
10
10
|
export const modelWire = (wire) => wire !== "plan";
|
|
11
11
|
/** A harness's wire's settings, or undefined for one billed to its own plan (modelWire). */
|
|
12
12
|
export const wireOf = (wire) => (modelWire(wire) ? WIRES[wire] : undefined);
|
|
13
|
+
/** The providers whose models the runner's model route translates onto a wire, each with the wires it translates them
|
|
14
|
+
* onto (runner/model-route.ts routeOf, its own fetch: messagesFetch): an Ollama model of this machine (ollama-provider.ts)
|
|
15
|
+
* onto Anthropic's Messages. Every harness on such a wire is offered those models and runs them through the route, at
|
|
16
|
+
* their price, whatever harness it is: the wire decides, never a harness's id. A leaf's data: provider ids by name. */
|
|
17
|
+
export const TRANSLATED = Object.freeze({ ollama: Object.freeze(["anthropic-messages"]) });
|
|
18
|
+
/** Whether `model`'s requests on a harness of `wire` go through the route's translation (TRANSLATED). */
|
|
19
|
+
export const routed = (wire, model) => Object.hasOwn(TRANSLATED, model.provider) && TRANSLATED[model.provider].includes(wire);
|
|
20
|
+
/** routed, for a model named `provider/model-id`. */
|
|
21
|
+
export const routedId = (wire, id) => id.indexOf("/") > 0 && routed(wire, { provider: id.slice(0, id.indexOf("/")) });
|
|
22
|
+
/** Whether the route translates any provider's models onto `wire` (TRANSLATED): a harness on it may run on one with no key. */
|
|
23
|
+
export const translatesOnto = (wire) => Object.values(TRANSLATED).some((wires) => wires.includes(wire));
|
package/dist/workflow-run.d.ts
CHANGED
|
@@ -36,10 +36,11 @@ export type WorkflowIssue = {
|
|
|
36
36
|
message: string;
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
|
-
* Every issue
|
|
40
|
-
* structural validation (code not run, no input), a call node `via: "tool"` whose tool is not in
|
|
41
|
-
* (`TOOL_NOT_LISTED`; `tools` undefined lists every tool), and what the durable runner refuses before any step
|
|
42
|
-
* once the DSL found nothing).
|
|
39
|
+
* Every issue POST /workflows/validate lists for `workflow` as a workflow revision listing `tools`, and the DSL's
|
|
40
|
+
* warnings: the DSL's structural validation (code not run, no input), a call node `via: "tool"` whose tool is not in
|
|
41
|
+
* `tools` (`TOOL_NOT_LISTED`; `tools` undefined lists every tool), and what the durable runner refuses before any step
|
|
42
|
+
* (only once the DSL found nothing). A save asks with no `tools`: its run binds a call node's tool listed or not
|
|
43
|
+
* (tools.ts grantedTools). It writes nothing.
|
|
43
44
|
*/
|
|
44
45
|
export declare function workflowIssues(workflow: unknown, tools?: readonly string[]): Promise<{
|
|
45
46
|
issues: WorkflowIssue[];
|
package/dist/workflow-run.js
CHANGED
|
@@ -7,10 +7,11 @@ export class WorkflowRunUnread extends Error {
|
|
|
7
7
|
}
|
|
8
8
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9
9
|
/**
|
|
10
|
-
* Every issue
|
|
11
|
-
* structural validation (code not run, no input), a call node `via: "tool"` whose tool is not in
|
|
12
|
-
* (`TOOL_NOT_LISTED`; `tools` undefined lists every tool), and what the durable runner refuses before any step
|
|
13
|
-
* once the DSL found nothing).
|
|
10
|
+
* Every issue POST /workflows/validate lists for `workflow` as a workflow revision listing `tools`, and the DSL's
|
|
11
|
+
* warnings: the DSL's structural validation (code not run, no input), a call node `via: "tool"` whose tool is not in
|
|
12
|
+
* `tools` (`TOOL_NOT_LISTED`; `tools` undefined lists every tool), and what the durable runner refuses before any step
|
|
13
|
+
* (only once the DSL found nothing). A save asks with no `tools`: its run binds a call node's tool listed or not
|
|
14
|
+
* (tools.ts grantedTools). It writes nothing.
|
|
14
15
|
*/
|
|
15
16
|
export async function workflowIssues(workflow, tools) {
|
|
16
17
|
if (!isRecord(workflow))
|
|
@@ -111,7 +111,8 @@ export declare const computerStartingWords: ({ provider, kind }: Pick<ComputerSa
|
|
|
111
111
|
* server's stop, a park: the words fit each), and, where the run's folder is on Archil and mounted in it
|
|
112
112
|
* (`folderKept`), that the folder is kept. The one kept through the run's park (`kept`) says it is the same; a new one
|
|
113
113
|
* after a kept one's time passed (`replaced.lapsed`) says why first, as does one after a kept one pinned to a runner
|
|
114
|
-
* that was gone by the resume (`replaced.lost`, computerLostWords)
|
|
114
|
+
* that was gone by the resume (`replaced.lost`, computerLostWords), and one after the kept one's provider refused to
|
|
115
|
+
* attach it again (`replaced.refused`, in the provider's words). */
|
|
115
116
|
export declare const computerReadyWords: ({ provider, kind, hello, replaced, kept }: ComputerSaid) => string;
|
|
116
117
|
/** The run's timeline phase as its run parks with its computer kept (ClaimComputer.keeps), such as "The desktop is kept
|
|
117
118
|
* for 10 minutes while you decide." */
|
|
@@ -206,14 +206,21 @@ export const computerStartingWords = ({ provider, kind }) => `Starting a ${kind}
|
|
|
206
206
|
* server's stop, a park: the words fit each), and, where the run's folder is on Archil and mounted in it
|
|
207
207
|
* (`folderKept`), that the folder is kept. The one kept through the run's park (`kept`) says it is the same; a new one
|
|
208
208
|
* after a kept one's time passed (`replaced.lapsed`) says why first, as does one after a kept one pinned to a runner
|
|
209
|
-
* that was gone by the resume (`replaced.lost`, computerLostWords)
|
|
209
|
+
* that was gone by the resume (`replaced.lost`, computerLostWords), and one after the kept one's provider refused to
|
|
210
|
+
* attach it again (`replaced.refused`, in the provider's words). */
|
|
210
211
|
export const computerReadyWords = ({ provider, kind, hello, replaced, kept }) => {
|
|
211
212
|
const ready = `The ${kind} is ready: ${[OS_NAMES[hello.os] ?? hello.os, hello.osVersion].filter(Boolean).join(" ")} (${hello.arch}), from ${provider}.`;
|
|
212
213
|
if (kept)
|
|
213
214
|
return `${ready} It's the same ${kind}, as the wait left it.`;
|
|
214
215
|
if (!replaced)
|
|
215
216
|
return ready;
|
|
216
|
-
const why = replaced.
|
|
217
|
+
const why = replaced.refused
|
|
218
|
+
? ` The ${kind} kept before could not be taken back: ${replaced.refused.replace(/[.!?]+$/, "")}.`
|
|
219
|
+
: replaced.lost
|
|
220
|
+
? ` ${computerLostWords(kind)}`
|
|
221
|
+
: replaced.lapsed
|
|
222
|
+
? ` ${computerLapsedWords(kind)}`
|
|
223
|
+
: "";
|
|
217
224
|
return `${ready}${why} It's a new ${kind}: the one before is gone, with what was on it.${replaced.folderKept ? " The run folder is kept." : ""}`;
|
|
218
225
|
};
|
|
219
226
|
/** The run's timeline phase as its run parks with its computer kept (ClaimComputer.keeps), such as "The desktop is kept
|
|
@@ -173,6 +173,10 @@ export interface ComputerForClaimDeps {
|
|
|
173
173
|
* claim's Archil mount credential (Mode 2): the credential is this claim's to remove now (archil-claim.ts inherit),
|
|
174
174
|
* since this claim mints none. Absent: nothing was minted (Mode 1). */
|
|
175
175
|
readonly inheritMount?: () => void;
|
|
176
|
+
/** The kind of the run's computer an earlier claim's deny turned off for the run (runner/computer-journal.ts
|
|
177
|
+
* computerTurnedOff): this claim starts none, says so, and ends at once the one a park kept, its mount with it.
|
|
178
|
+
* Absent: the computer is on. */
|
|
179
|
+
readonly turnedOff?: string;
|
|
176
180
|
/** The clock a kept computer's time is read by (computer-kept.ts), and its computers' intervals are written on
|
|
177
181
|
* (computer-intervals.ts). Default Date.now. */
|
|
178
182
|
readonly now?: () => number;
|
|
@@ -196,6 +200,10 @@ export interface ComputerForClaimDeps {
|
|
|
196
200
|
* owner's view let go, then the computer. */
|
|
197
201
|
export interface ClaimComputer {
|
|
198
202
|
readonly computer?: RunComputer;
|
|
203
|
+
/** The agent's computer was not started: every tool it serves the run is set to deny (tool-gate.ts computerDenied), or
|
|
204
|
+
* an earlier claim's deny turned it off for the run (ComputerForClaimDeps.turnedOff). The run goes on without it, and
|
|
205
|
+
* its kind's skill is not named to the model. */
|
|
206
|
+
readonly off?: true;
|
|
199
207
|
readonly hold?: RunHold;
|
|
200
208
|
readonly held?: HeldComputer;
|
|
201
209
|
/** The computer is a new one that replaced an earlier claim's (Replaced): what was on that one is gone. Absent: the
|
|
@@ -229,12 +237,15 @@ export type KeptKind = Kept["kind"];
|
|
|
229
237
|
/** A computer the claim made fresh in place of an earlier claim's: its kind, and `folderKept`, the run's folder is on
|
|
230
238
|
* Archil (Mode 2) and mounted in it, so the folder is kept. `lapsed`: the earlier one was kept at a park, and its time
|
|
231
239
|
* (KEEP_MS) passed before this claim. `lost`: the earlier one was kept at a park pinned to another runner (or another
|
|
232
|
-
* process of this runner's name), that runner was gone by this claim, and this claim could not reach it.
|
|
240
|
+
* process of this runner's name), that runner was gone by this claim, and this claim could not reach it. `refused`: the
|
|
241
|
+
* earlier one was kept at a park, and its provider refused to attach it again, in these words (a Docker computer made
|
|
242
|
+
* before its egress bridge). */
|
|
233
243
|
export type Replaced = {
|
|
234
244
|
readonly kind: MadeKind;
|
|
235
245
|
readonly folderKept: boolean;
|
|
236
246
|
readonly lapsed?: true;
|
|
237
247
|
readonly lost?: true;
|
|
248
|
+
readonly refused?: string;
|
|
238
249
|
};
|
|
239
250
|
/** The agent's computer setting: the launch's, else its revision's (computer, else place), else the launch's place. The
|
|
240
251
|
* run's end reads it the same way (run-end-computers.ts). */
|