@parcha/agentrun-serve 0.1.0-beta.56 → 0.1.0-beta.58
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 +281 -0
- package/README.md +246 -66
- 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 +15 -5
- package/dist/api-only.js +32 -8
- package/dist/box-paths.d.ts +4 -3
- package/dist/box-paths.js +7 -4
- 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-token.d.ts +117 -0
- package/dist/claude-login-token.js +737 -0
- package/dist/claude-login.d.ts +120 -22
- package/dist/claude-login.js +347 -63
- package/dist/claude-sign-in.d.ts +17 -6
- package/dist/claude-sign-in.js +42 -39
- package/dist/cli.js +33 -10
- 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-attach.d.ts +35 -17
- package/dist/computer-attach.js +301 -49
- 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/computers.d.ts +10 -10
- package/dist/computers.js +5 -5
- package/dist/console/assets/{backend-Boh7tC4i.js → backend-CSAWUqtZ.js} +19 -19
- package/dist/console/assets/index-Bwn1oTem.css +1 -0
- package/dist/console/assets/index-DPh29cyz.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/dial-relay.d.ts +25 -4
- package/dist/dial-relay.js +129 -1
- package/dist/docker-host-addresses.d.ts +22 -11
- package/dist/docker-host-addresses.js +38 -26
- package/dist/env-switch.d.ts +8 -0
- package/dist/env-switch.js +31 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +56 -20
- package/dist/fal-price.js +400 -90
- 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/ledger.d.ts +170 -0
- package/dist/learn/ledger.js +218 -0
- package/dist/learn/promote.d.ts +3 -3
- package/dist/learn/promote.js +1 -1
- package/dist/learn/secrets.d.ts +13 -3
- package/dist/learn/secrets.js +118 -17
- package/dist/learning-cost.d.ts +28 -23
- package/dist/learning-cost.js +19 -23
- package/dist/link-check.js +1 -1
- package/dist/live-reach.d.ts +2 -0
- package/dist/live-reach.js +2 -0
- 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 +35 -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/micro.d.ts +2 -0
- package/dist/micro.js +2 -0
- package/dist/model-form.d.ts +5 -4
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +10 -6
- package/dist/model.js +16 -11
- package/dist/monid.d.ts +14 -1
- package/dist/monid.js +103 -26
- package/dist/ollama-provider.d.ts +7 -1
- package/dist/ollama-provider.js +14 -2
- package/dist/openapi.js +210 -37
- 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/place-offers.d.ts +4 -0
- package/dist/place-offers.js +7 -4
- package/dist/provider.d.ts +11 -2
- package/dist/provider.js +59 -8
- 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 +4 -2
- 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/run-view.d.ts +1 -2
- package/dist/run-view.js +2 -1
- 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 +58 -26
- package/dist/runner/adapter-run-spec.d.ts +55 -11
- package/dist/runner/adapter-run-spec.js +183 -52
- package/dist/runner/adapters/pi.js +25 -3
- package/dist/runner/beside.d.ts +9 -2
- package/dist/runner/beside.js +27 -9
- package/dist/runner/big-writes.js +1 -10
- package/dist/runner/claim-secrets.d.ts +27 -10
- package/dist/runner/claim-secrets.js +49 -22
- package/dist/runner/cli-run-spec.d.ts +6 -0
- package/dist/runner/cli-run-spec.js +97 -38
- 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 +24 -6
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/journal-kinds.js +5 -0
- package/dist/runner/main.d.ts +11 -6
- package/dist/runner/main.js +19 -9
- package/dist/runner/mcp-claim.js +31 -3
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +11 -5
- package/dist/runner/model-route.d.ts +17 -0
- package/dist/runner/model-route.js +120 -2
- package/dist/runner/presence.d.ts +11 -1
- package/dist/runner/presence.js +7 -0
- package/dist/runner/reflect-hook.js +1 -1
- package/dist/runner/run-child-host.d.ts +22 -8
- package/dist/runner/run-child-host.js +128 -41
- package/dist/runner/run-child.js +5 -2
- package/dist/runner/runner.d.ts +17 -3
- package/dist/runner/runner.js +130 -34
- package/dist/runner/save-slots.js +2 -1
- 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.d.ts +11 -0
- package/dist/runner/subagent.js +16 -38
- package/dist/runner/workflow-first.d.ts +35 -15
- package/dist/runner/workflow-first.js +38 -25
- package/dist/runner/workflow-spec.js +4 -3
- 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 +65 -13
- package/dist/server.js +470 -157
- package/dist/skills/agentrun-serve/SKILL.md +4 -0
- package/dist/slots.d.ts +9 -0
- package/dist/slots.js +45 -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/postgres/migrations/0028_learning_ledger.sql +44 -0
- package/dist/store/schema.d.ts +23 -0
- package/dist/store/schema.js +58 -2
- 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 +12 -2
- package/dist/store/sqlite/run-patch.js +42 -5
- package/dist/store/sqlite/store.js +105 -12
- package/dist/store/store.d.ts +57 -2
- package/dist/store/store.js +20 -0
- package/dist/store-reads/learning.d.ts +84 -124
- package/dist/store-reads/learning.js +210 -274
- 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 +39 -9
- package/dist/template-eval.js +191 -60
- package/dist/template-import.js +6 -2
- 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 +22 -7
- package/dist/timeline/web-calls.js +106 -35
- 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 +10 -13
- package/dist/web-save.js +13 -55
- 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/attached-computers.d.ts +32 -9
- package/dist/workspace/attached-computers.js +77 -13
- package/dist/workspace/computer-deps.d.ts +8 -2
- package/dist/workspace/computer-deps.js +10 -3
- package/dist/workspace/computer-for-claim.d.ts +12 -1
- package/dist/workspace/computer-for-claim.js +83 -11
- 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/paired-route.d.ts +91 -0
- package/dist/workspace/paired-route.js +153 -0
- package/dist/workspace/synced-folder.js +3 -4
- package/dist/wrapped.d.ts +20 -6
- package/dist/wrapped.js +66 -25
- package/package.json +17 -11
- package/skills/agentrun-serve/SKILL.md +4 -0
- package/templates/README.md +32 -10
- 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/monid.js
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
// At the save (server.ts saveable, the one check of a create, an edit and an inline run): each grant is read against
|
|
6
6
|
// monid's listing (a provider's wildcard: every endpoint it lists, GET /v1/endpoints; one endpoint: POST /v1/inspect),
|
|
7
7
|
// and the pin is stamped on the revision, a grant its current revision made too carried unread. A grant monid does not
|
|
8
|
-
// list is refused in words, so is one that cannot be read now (no key, monid unreachable). A
|
|
8
|
+
// list is refused in words, so is one that cannot be read now (no key, monid unreachable). A read monid refuses for its
|
|
9
|
+
// rate, fails (5xx) or leaves unanswered past its limit is sent again inside the save's time (READ_BUDGET_MS, from the
|
|
10
|
+
// save's start), and one server's saves share each read (monidReads): saves that arrive together read the listing once,
|
|
11
|
+
// each waiting on it no longer than its own time. A run reads only its pin.
|
|
9
12
|
//
|
|
10
13
|
// An endpoint priced by usage (per result, per unit, metered, a matrix or tier with a usage part) is pinned too, with no
|
|
11
14
|
// fixed price, and the save's warnings name it (usageWords): monid can't cap what such a call charges. Its maxCost
|
|
@@ -25,7 +28,7 @@
|
|
|
25
28
|
// provider answers 202 with a run id, read again every POLL_MS until it ends, for at most WAIT_MS in all; a run the
|
|
26
29
|
// caller stops, or one that outlasts the wait, is asked to stop. Every answer reaches the model as JSON, cut at CLIP
|
|
27
30
|
// characters, the whole of it then filed under the run's work/evidence/monid/.
|
|
28
|
-
import { randomUUID } from "node:crypto";
|
|
31
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
29
32
|
import { workspaceErrorWords } from "./workspace/index.js";
|
|
30
33
|
import { wireName } from "./catalog.js";
|
|
31
34
|
import { formatToolName, monidNameOf, parseToolName, sameWireWords } from "./tool-names.js";
|
|
@@ -45,10 +48,20 @@ const TERMINAL = ["COMPLETED", "FAILED", "BLOCKED", "STOPPED", "TIMED_OUT"];
|
|
|
45
48
|
const MIN_READ_MS = 100;
|
|
46
49
|
/** How many inspects a save has out at once. */
|
|
47
50
|
const INSPECTS_AT_ONCE = 8;
|
|
48
|
-
/** A save's read of the listing or an inspect, refused for the rate (429)
|
|
49
|
-
* what monid says to wait (Retry-After, 2 s when it says nothing, at
|
|
50
|
-
|
|
51
|
+
/** A save's read of the listing or an inspect, refused for the rate (429), failed by monid (5xx) or not answered in
|
|
52
|
+
* time, is sent again after what monid says to wait (Retry-After, 2 s when it says nothing, at least READ_WAIT_MIN_MS
|
|
53
|
+
* and at most READ_WAIT_MS), at most READ_RESENDS times, while that read's waits add up to at most READ_WAITS_MS and
|
|
54
|
+
* the save is inside READ_BUDGET_MS of its start: a burst of saves on one key waits out monid's rate inside the save's
|
|
55
|
+
* own time, and only then is refused. */
|
|
56
|
+
const READ_WAIT_MIN_MS = 250;
|
|
51
57
|
const READ_WAIT_MS = 10_000;
|
|
58
|
+
const READ_WAITS_MS = 20_000;
|
|
59
|
+
const READ_RESENDS = 20;
|
|
60
|
+
const READ_BUDGET_MS = 45_000;
|
|
61
|
+
/** Why a save's read is not sent, or not waited on, past its time (READ_BUDGET_MS). */
|
|
62
|
+
const OUT_OF_TIME = "no answer within the save's time";
|
|
63
|
+
/** How long one server's saves share a read of monid's listing or an inspect that answered (monidReads). */
|
|
64
|
+
const SHARED_READ_MS = 60_000;
|
|
52
65
|
/** On an answer monid charged nothing for: the run never ran (refused as sent), was blocked or stopped, or the provider
|
|
53
66
|
* failed. A symbol, so the model never reads it. */
|
|
54
67
|
const UNCHARGED = Symbol("monid.uncharged");
|
|
@@ -137,17 +150,27 @@ export function monidClient(options) {
|
|
|
137
150
|
return { status: res.status, body: isObject(json) ? json : { message: text.slice(0, 500) }, ...(retryAfter >= 0 ? { retryAfter } : {}) };
|
|
138
151
|
}
|
|
139
152
|
catch (error) {
|
|
140
|
-
|
|
153
|
+
const timedOut = !signal?.aborted && limit.aborted;
|
|
154
|
+
return { status: 0, body: { message: signal?.aborted ? "stopped by the caller" : timedOut ? `no answer in ${ms / 1000} s` : String(error?.message ?? error) }, ...(timedOut ? { timedOut: true } : {}) };
|
|
141
155
|
}
|
|
142
156
|
};
|
|
143
157
|
const answer = (res) => (res.status >= 200 && res.status < 300 ? res.body : failure(res.status, res.body));
|
|
144
|
-
/**
|
|
158
|
+
/** When this client's reads stop being sent (READ_BUDGET_MS after its first, unless given). */
|
|
159
|
+
let readsEnd = options.readsEnd;
|
|
160
|
+
/** A save's read, safe to repeat (READ_WAITS_MS, READ_BUDGET_MS); any other refusal (401, 403, 404), or monid out of
|
|
161
|
+
* reach (a request that failed before its limit), is its answer. */
|
|
145
162
|
const read = async (method, path, body, signal) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
163
|
+
const end = (readsEnd ??= Date.now() + READ_BUDGET_MS);
|
|
164
|
+
if (Date.now() >= end)
|
|
165
|
+
return { status: 0, body: { message: OUT_OF_TIME } };
|
|
166
|
+
for (let waited = 0, resends = 0;; resends++) {
|
|
167
|
+
const res = await call(method, path, body, signal, Math.min(requestMs, Math.max(MIN_READ_MS, end - Date.now())));
|
|
168
|
+
const wait = Math.min(READ_WAIT_MS, Math.max(READ_WAIT_MIN_MS, (res.retryAfter ?? 2) * 1000));
|
|
169
|
+
const again = res.status === 429 || res.status >= 500 || res.timedOut === true;
|
|
170
|
+
if (!again || signal?.aborted || resends >= READ_RESENDS || waited + wait > READ_WAITS_MS || Date.now() + wait >= end)
|
|
149
171
|
return res;
|
|
150
|
-
|
|
172
|
+
waited += wait;
|
|
173
|
+
await sleep(wait, signal);
|
|
151
174
|
}
|
|
152
175
|
};
|
|
153
176
|
const stop = async (runId, why) => {
|
|
@@ -280,12 +303,54 @@ function inputSchema(input) {
|
|
|
280
303
|
}
|
|
281
304
|
return { type: "object", additionalProperties: false, properties, ...(required.length ? { required } : {}) };
|
|
282
305
|
}
|
|
306
|
+
/** The reads one server's saves share, by key and what is read: a read out now is joined, not sent again, and one that
|
|
307
|
+
* answered is reused for SHARED_READ_MS. One that failed is dropped once it ends: the next save reads anew. */
|
|
308
|
+
export const monidReads = () => new Map();
|
|
309
|
+
/** `read`'s answer, shared through `reads` under `id` (monidReads): joined while it is out, kept while `kept` says it
|
|
310
|
+
* answered. A save that joins a read another started waits on it until its own `end` at most, then has `late()`.
|
|
311
|
+
* Without `reads`, read alone. */
|
|
312
|
+
function sharedRead(reads, id, read, kept, end, late) {
|
|
313
|
+
if (!reads)
|
|
314
|
+
return read();
|
|
315
|
+
const now = Date.now();
|
|
316
|
+
for (const [one, entry] of reads)
|
|
317
|
+
if (entry.at !== undefined && now - entry.at >= SHARED_READ_MS)
|
|
318
|
+
reads.delete(one);
|
|
319
|
+
const had = reads.get(id);
|
|
320
|
+
if (had) {
|
|
321
|
+
if (had.at !== undefined)
|
|
322
|
+
return had.answer;
|
|
323
|
+
let timer;
|
|
324
|
+
const lateness = new Promise((resolve) => (timer = setTimeout(() => resolve(late()), Math.max(0, end - now))));
|
|
325
|
+
return Promise.race([had.answer, lateness]).finally(() => clearTimeout(timer));
|
|
326
|
+
}
|
|
327
|
+
const entry = {
|
|
328
|
+
answer: read().then((answer) => {
|
|
329
|
+
if (reads.get(id) !== entry)
|
|
330
|
+
return answer;
|
|
331
|
+
if (kept(answer))
|
|
332
|
+
entry.at = Date.now();
|
|
333
|
+
else
|
|
334
|
+
reads.delete(id);
|
|
335
|
+
return answer;
|
|
336
|
+
}, (error) => {
|
|
337
|
+
if (reads.get(id) === entry)
|
|
338
|
+
reads.delete(id);
|
|
339
|
+
throw error;
|
|
340
|
+
}),
|
|
341
|
+
};
|
|
342
|
+
reads.set(id, entry);
|
|
343
|
+
return entry.answer;
|
|
344
|
+
}
|
|
283
345
|
/** The monid grants among `grants` pinned against monid's listing on `key` (pinned at a save, never at a run): each
|
|
284
346
|
* provider's wildcard read as the endpoints monid lists for it now (at most MONID_WILDCARD_MAX), each endpoint inspected
|
|
285
347
|
* for its description, input and price; a grant `previous` made too carries its pin, unread (as server.ts mcpListingOf).
|
|
286
348
|
* A grant monid lists nothing for is refused, as is every grant to read with no key or monid unreadable. An endpoint
|
|
287
|
-
* with no fixed price (fixedUsd) is pinned with none, and warned of (usageWords). Undefined when no grant is monid's.
|
|
349
|
+
* with no fixed price (fixedUsd) is pinned with none, and warned of (usageWords). Undefined when no grant is monid's.
|
|
350
|
+
* With `shared` (monidReads), the listing and each inspect are read once for the saves that ask at once. */
|
|
288
351
|
export async function pinMonid(grants, options) {
|
|
352
|
+
// The save's reads stop READ_BUDGET_MS (or `budgetMs`) after it starts, a wait on another save's read included.
|
|
353
|
+
const readsEnd = Date.now() + (options.budgetMs ?? READ_BUDGET_MS);
|
|
289
354
|
const pin = {};
|
|
290
355
|
const before = options.previous;
|
|
291
356
|
const named = grants.flatMap((tool) => {
|
|
@@ -304,7 +369,7 @@ export async function pinMonid(grants, options) {
|
|
|
304
369
|
const reads = named.filter((grant) => grant.read && !(grant.parsed.kind === "monid" && pin[grant.tool]));
|
|
305
370
|
if (reads.length && !options.key)
|
|
306
371
|
return { refused: reads.map(({ tool }) => ({ tool, message: `${tool} is pinned to what monid lists when the agent is saved, and there is no monid key here to read it with: save the monid key in Settings → API Keys first.` })) };
|
|
307
|
-
const refused = reads.length ? await readPins(reads, pin, { ...options, key: options.key }) : [];
|
|
372
|
+
const refused = reads.length ? await readPins(reads, pin, { ...options, key: options.key, readsEnd }) : [];
|
|
308
373
|
// Two endpoints the harnesses would call by one name (wireName folds `.` and `/`): neither could be told apart.
|
|
309
374
|
const wires = new Map();
|
|
310
375
|
for (const tool of Object.keys(pin).sort()) {
|
|
@@ -322,28 +387,40 @@ export async function pinMonid(grants, options) {
|
|
|
322
387
|
}
|
|
323
388
|
/** The grants `reads` read against monid's listing into `pin`; why each that could not be is refused. */
|
|
324
389
|
async function readPins(named, pin, options) {
|
|
325
|
-
const
|
|
390
|
+
const { readsEnd } = options;
|
|
391
|
+
const client = monidClient({ key: options.key, readsEnd, ...(options.fetch ? { fetch: options.fetch } : {}), ...(options.sleep ? { sleep: options.sleep } : {}) });
|
|
326
392
|
// monid's own words, which a save's refusal returns to its caller: the key they were read with cut from them, in
|
|
327
393
|
// every form a run's error is redacted of (key-refusal.ts redacted).
|
|
328
394
|
const key = options.key;
|
|
329
395
|
const said = (error) => redacted(String(error), [key]);
|
|
396
|
+
// The shared reads are told apart by a digest of the key they were read with, never the key.
|
|
397
|
+
const keyId = createHash("sha256").update(key).digest("hex");
|
|
330
398
|
const refused = [];
|
|
331
399
|
// Each endpoint to pin, by catalog name: each wildcard's provider's as monid lists them, then the grants' own.
|
|
332
400
|
const wanted = new Map();
|
|
333
401
|
const providers = new Set(named.flatMap(({ parsed }) => (parsed.kind === "monid-provider" ? [parsed.provider] : [])));
|
|
334
402
|
if (providers.size) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
403
|
+
// Every provider's endpoints, every page, a bounded number of them: monid's listing is not filtered by provider.
|
|
404
|
+
const listing = await sharedRead(options.shared, `${keyId} listing`, async () => {
|
|
405
|
+
const listed = new Map();
|
|
406
|
+
for (let cursor, page = 0; (page === 0 || cursor) && page < 500; page++) {
|
|
407
|
+
const res = await client.endpoints(cursor, options.signal);
|
|
408
|
+
if (res.error !== undefined)
|
|
409
|
+
return { error: res.error };
|
|
410
|
+
for (const item of Array.isArray(res.items) ? res.items : []) {
|
|
411
|
+
if (isObject(item) && typeof item.provider === "string" && typeof item.endpoint === "string") {
|
|
412
|
+
const endpoints = listed.get(item.provider) ?? [];
|
|
413
|
+
listed.set(item.provider, endpoints);
|
|
414
|
+
endpoints.push(item.endpoint);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
cursor = typeof res.cursor === "string" && res.cursor ? res.cursor : undefined;
|
|
344
418
|
}
|
|
345
|
-
|
|
346
|
-
}
|
|
419
|
+
return { listed };
|
|
420
|
+
}, (answer) => "listed" in answer, readsEnd, () => ({ error: OUT_OF_TIME }));
|
|
421
|
+
if ("error" in listing)
|
|
422
|
+
return named.map(({ tool }) => ({ tool, message: `${tool} could not be pinned: monid's listing could not be read (${said(listing.error)}).` }));
|
|
423
|
+
const { listed } = listing;
|
|
347
424
|
for (const { tool, parsed } of named) {
|
|
348
425
|
if (parsed.kind !== "monid-provider")
|
|
349
426
|
continue;
|
|
@@ -365,7 +442,7 @@ async function readPins(named, pin, options) {
|
|
|
365
442
|
const inspectOne = async () => {
|
|
366
443
|
for (let next = queue.shift(); next; next = queue.shift()) {
|
|
367
444
|
const [tool, at] = next;
|
|
368
|
-
const res = await client.inspect(at, options.signal);
|
|
445
|
+
const res = await sharedRead(options.shared, `${keyId} inspect ${JSON.stringify([at.provider, at.endpoint])}`, () => client.inspect(at, options.signal), (answer) => answer.error === undefined, readsEnd, () => ({ error: OUT_OF_TIME }));
|
|
369
446
|
if (res.status === 404)
|
|
370
447
|
refused.push({ tool, message: `monid lists no endpoint ${at.endpoint} of a provider ${at.provider}.` });
|
|
371
448
|
else if (res.error !== undefined)
|
|
@@ -27,6 +27,11 @@ export declare function ollamaClock(clock?: () => number): void;
|
|
|
27
27
|
/** The listing under way for the Ollama `env` names (one a stale answer started behind its caller), or undefined: for a
|
|
28
28
|
* test to await what a refresh brings. */
|
|
29
29
|
export declare function ollamaAsking(env: NodeJS.ProcessEnv): Promise<readonly OllamaListed[]> | undefined;
|
|
30
|
+
/** `read` as a reading no run waits on: the offers and the server's model needs, made again at each key save
|
|
31
|
+
* (harness.ts harnessOffers, server.ts needsOf). Inside it, ollamaShown answers from the kept listing at any age, which
|
|
32
|
+
* is the listing the offers are made from, and asks Ollama nothing when one is kept. So a save never waits on one
|
|
33
|
+
* /api/show per model of a stuck Ollama. A run's own choice is never made inside it. */
|
|
34
|
+
export declare const ollamaReading: <T>(read: () => Promise<T>) => Promise<T>;
|
|
30
35
|
/** A test process's switch, read from its own environment (process.env), never from the `env` a caller passes: set, no
|
|
31
36
|
* Ollama is asked, whatever address that `env` names or leaves to the default. A test hook's name (model.ts FAUX_PREFIX),
|
|
32
37
|
* so a server never hands it on to its runs. The test suites set it (test/support.mjs); a test of Ollama clears it. */
|
|
@@ -59,7 +64,8 @@ export declare const OLLAMA_SHOW_TIMEOUT_MS = 10000;
|
|
|
59
64
|
/** Model `tag` of the Ollama `env` names, for a run that names it (`ollama/<tag>`): from its address's kept listing while
|
|
60
65
|
* that is fresh (OLLAMA_TTL_MS), else its own /api/show within `timeoutMs`, never /api/tags, so a run never waits on a
|
|
61
66
|
* whole listing and never runs on a model's context from before it was pulled again. Undefined where it is not there,
|
|
62
|
-
* does not answer, is a cloud model or OLLAMA_HOST is refused. Nothing kept: the listing is the kept one.
|
|
67
|
+
* does not answer, is a cloud model or OLLAMA_HOST is refused. Nothing kept: the listing is the kept one. Inside
|
|
68
|
+
* ollamaReading, the kept listing at any age, and nothing asked when one is kept. */
|
|
63
69
|
export declare function ollamaShown(env: NodeJS.ProcessEnv, tag: string, { fetch: send, timeoutMs }?: {
|
|
64
70
|
fetch?: typeof fetch;
|
|
65
71
|
timeoutMs?: number;
|
package/dist/ollama-provider.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Ollama as a model provider: the models the Ollama on this machine (or the one OLLAMA_HOST names) has pulled, listed live
|
|
2
|
-
// from its own API, run by pi
|
|
2
|
+
// from its own API, run by pi and by every harness on a wire the route translates (wires.ts TRANSLATED), at $0, on
|
|
3
|
+
// Ollama's native chat API. No key: Ollama has none.
|
|
3
4
|
// Where: OLLAMA_HOST, Ollama's own variable, read as the ollama CLI reads it (ollamaBase), from the server's environment,
|
|
4
5
|
// never from a provider's auth context, so it is never a held secret. Unset, the server names the default address
|
|
5
6
|
// itself only on one owner's own machine (ollamaHostOf); unset anywhere else, no Ollama is asked. Plain http only to this machine (provider.ts
|
|
@@ -13,6 +14,7 @@
|
|
|
13
14
|
// (OLLAMA_NUM_CTX), and the model's window here is that same number.
|
|
14
15
|
// Listing never stalls a caller: one short deadline for the whole listing, no redirects, and a down, hung or refused Ollama
|
|
15
16
|
// lists no models and throws nothing. Each address's answer is kept (OLLAMA_TTL_MS) and refreshed behind the caller.
|
|
17
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
16
18
|
import { calculateCost, collapseSystemMessages, createAssistantMessageEventStream, getCurrentSystemPrompt, getCurrentTools } from "@earendil-works/pi-ai";
|
|
17
19
|
import { transformMessages } from "@earendil-works/pi-ai/api/transform-messages";
|
|
18
20
|
import { createProvider } from "@earendil-works/pi-ai/models";
|
|
@@ -85,6 +87,13 @@ export function ollamaAsking(env) {
|
|
|
85
87
|
const base = baseOf(env);
|
|
86
88
|
return base === undefined ? undefined : asking.get(base);
|
|
87
89
|
}
|
|
90
|
+
/** Set inside ollamaReading: a reading no run waits on. */
|
|
91
|
+
const reading = new AsyncLocalStorage();
|
|
92
|
+
/** `read` as a reading no run waits on: the offers and the server's model needs, made again at each key save
|
|
93
|
+
* (harness.ts harnessOffers, server.ts needsOf). Inside it, ollamaShown answers from the kept listing at any age, which
|
|
94
|
+
* is the listing the offers are made from, and asks Ollama nothing when one is kept. So a save never waits on one
|
|
95
|
+
* /api/show per model of a stuck Ollama. A run's own choice is never made inside it. */
|
|
96
|
+
export const ollamaReading = (read) => reading.run(true, read);
|
|
88
97
|
/** Whether an /api/tags or /api/show entry is a cloud model's. Its prompts leave this machine, so it is never listed: the
|
|
89
98
|
* models here are local, $0 and uncounted, and a cloud model is none of those. */
|
|
90
99
|
const remote = (entry) => entry?.remote_host !== undefined || entry?.remote_model !== undefined;
|
|
@@ -181,12 +190,15 @@ export const OLLAMA_SHOW_TIMEOUT_MS = 10_000;
|
|
|
181
190
|
/** Model `tag` of the Ollama `env` names, for a run that names it (`ollama/<tag>`): from its address's kept listing while
|
|
182
191
|
* that is fresh (OLLAMA_TTL_MS), else its own /api/show within `timeoutMs`, never /api/tags, so a run never waits on a
|
|
183
192
|
* whole listing and never runs on a model's context from before it was pulled again. Undefined where it is not there,
|
|
184
|
-
* does not answer, is a cloud model or OLLAMA_HOST is refused. Nothing kept: the listing is the kept one.
|
|
193
|
+
* does not answer, is a cloud model or OLLAMA_HOST is refused. Nothing kept: the listing is the kept one. Inside
|
|
194
|
+
* ollamaReading, the kept listing at any age, and nothing asked when one is kept. */
|
|
185
195
|
export async function ollamaShown(env, tag, { fetch: send = globalThis.fetch, timeoutMs = OLLAMA_SHOW_TIMEOUT_MS } = {}) {
|
|
186
196
|
const base = baseOf(env);
|
|
187
197
|
if (base === undefined)
|
|
188
198
|
return undefined;
|
|
189
199
|
const known = kept.get(base);
|
|
200
|
+
if (known && reading.getStore())
|
|
201
|
+
return known.models.find((model) => model.name === tag);
|
|
190
202
|
const fresh = known && now() - known.at < OLLAMA_TTL_MS ? known.models.find((model) => model.name === tag) : undefined;
|
|
191
203
|
return fresh ?? shownOf(askerOf(base, send, AbortSignal.timeout(timeoutMs)), tag);
|
|
192
204
|
}
|