@parcha/agentrun-serve 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 +325 -1
- package/README.md +332 -88
- package/dist/acp-package.d.ts +5 -1
- package/dist/acp-package.js +19 -2
- package/dist/adapters.d.ts +23 -2
- package/dist/adapters.js +106 -33
- package/dist/agents-store.js +1 -1
- package/dist/answer-text.d.ts +3 -0
- package/dist/answer-text.js +22 -0
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +3 -2
- package/dist/box-paths.js +5 -4
- package/dist/browser-computer.d.ts +3 -8
- package/dist/browser-computer.js +12 -35
- package/dist/browser-cost.js +94 -20
- package/dist/capacity.d.ts +1 -1
- package/dist/capacity.js +3 -3
- package/dist/chatgpt-plan.d.ts +5 -0
- package/dist/chatgpt-plan.js +25 -11
- package/dist/claude-login-token.d.ts +15 -11
- package/dist/claude-login-token.js +167 -107
- package/dist/claude-login.d.ts +76 -31
- package/dist/claude-login.js +426 -79
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli.js +323 -292
- package/dist/composio-made.d.ts +1 -6
- package/dist/composio-made.js +1 -6
- package/dist/composio-owners.d.ts +26 -0
- package/dist/composio-owners.js +36 -0
- package/dist/composio-preset.d.ts +56 -23
- package/dist/composio-preset.js +173 -77
- package/dist/composio-triggers.d.ts +4 -4
- package/dist/composio-triggers.js +6 -7
- package/dist/compute-cost.js +11 -2
- package/dist/computer-attach.d.ts +6 -3
- package/dist/computer-attach.js +41 -29
- package/dist/computer-held-routes.d.ts +1 -1
- package/dist/computer-held-routes.js +9 -4
- package/dist/computer-keys.d.ts +11 -1
- package/dist/computer-keys.js +26 -1
- package/dist/computer-record.js +3 -1
- package/dist/computer-view.d.ts +5 -3
- package/dist/computer-view.js +10 -6
- package/dist/computer-viewer.js +36 -7
- package/dist/computers.d.ts +2 -1
- package/dist/computers.js +6 -3
- package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
- package/dist/console/assets/backend-BztxEAvb.js +166 -0
- package/dist/console/assets/index-LwNL4L9q.js +619 -0
- package/dist/console/assets/share-L84tlUDW.js +6 -0
- package/dist/console/assets/styles-CaRKlHke.js +291 -0
- package/dist/console/assets/styles-DQo8rzY-.css +1 -0
- package/dist/console/index.html +4 -3
- package/dist/console/share.html +17 -0
- package/dist/decisions.d.ts +17 -7
- package/dist/decisions.js +41 -15
- package/dist/dial-relay.js +10 -4
- package/dist/docker-daemon.js +4 -5
- package/dist/docker-host-addresses.js +29 -11
- package/dist/email/account.d.ts +6 -0
- package/dist/email/account.js +6 -0
- package/dist/email/authentication.d.ts +21 -0
- package/dist/email/authentication.js +106 -0
- package/dist/email/email-faux.d.ts +11 -2
- package/dist/email/email-faux.js +21 -5
- package/dist/email/mail.d.ts +25 -0
- package/dist/email/mail.js +58 -2
- package/dist/email/names.js +2 -2
- package/dist/email/tools.d.ts +9 -4
- package/dist/email/tools.js +95 -13
- package/dist/env-switch.d.ts +12 -2
- package/dist/env-switch.js +23 -3
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +11 -1
- package/dist/fal-price.js +33 -0
- package/dist/faux-computers.js +1 -1
- package/dist/filed-answer.d.ts +2 -2
- package/dist/filed-answer.js +2 -2
- package/dist/graph-served.d.ts +10 -5
- package/dist/graph-served.js +40 -10
- package/dist/handed-values.js +1 -2
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +45 -12
- package/dist/harness-keys.js +9 -6
- package/dist/harness-opencode/facts.js +2 -0
- package/dist/harness-recipe-entry.d.ts +9 -3
- package/dist/harness-recipe-entry.js +18 -9
- package/dist/harness-recipe.d.ts +21 -0
- package/dist/harness-recipe.js +25 -3
- package/dist/harness-table.d.ts +8 -0
- package/dist/harness-table.js +17 -6
- package/dist/helper-env.d.ts +4 -1
- package/dist/helper-env.js +4 -1
- package/dist/host-check.d.ts +2 -3
- package/dist/host-check.js +13 -7
- package/dist/hosted-search.js +1 -1
- package/dist/import.d.ts +11 -8
- package/dist/import.js +437 -186
- package/dist/key-refusal.d.ts +9 -2
- package/dist/key-refusal.js +86 -32
- package/dist/learn/audit.d.ts +8 -5
- package/dist/learn/audit.js +15 -7
- package/dist/learn/compile.d.ts +5 -2
- package/dist/learn/compile.js +45 -21
- package/dist/learn/field-check.d.ts +111 -0
- package/dist/learn/field-check.js +174 -0
- package/dist/learn/ledger.d.ts +32 -29
- package/dist/learn/ledger.js +26 -19
- package/dist/learn/promote.d.ts +79 -36
- package/dist/learn/promote.js +60 -65
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learned-nodes.d.ts +8 -5
- package/dist/learned-nodes.js +8 -5
- package/dist/learned-workflow.d.ts +2 -1
- package/dist/learned-workflow.js +13 -10
- package/dist/learning-cost.d.ts +25 -8
- package/dist/learning-cost.js +23 -8
- package/dist/learning-setting.d.ts +6 -0
- package/dist/learning-setting.js +11 -1
- package/dist/listen-first.d.ts +5 -4
- package/dist/listen-first.js +4 -5
- package/dist/live-reach.d.ts +7 -0
- package/dist/live-reach.js +7 -0
- package/dist/mcp-api-only-origins.d.ts +15 -0
- package/dist/mcp-api-only-origins.js +40 -0
- package/dist/mcp-gateway.d.ts +16 -2
- package/dist/mcp-gateway.js +41 -3
- package/dist/mcp-oauth.d.ts +1 -1
- package/dist/mcp-oauth.js +3 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +3 -0
- package/dist/mcp-secret-writes.d.ts +24 -2
- package/dist/mcp-secret-writes.js +30 -2
- package/dist/mcp-servers-store.d.ts +52 -14
- package/dist/mcp-servers-store.js +165 -61
- package/dist/mcp-sources.d.ts +1 -2
- package/dist/mcp-sources.js +1 -2
- package/dist/mcp-store.d.ts +5 -5
- package/dist/mcp-store.js +3 -3
- package/dist/mcp.js +1 -1
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +202 -51
- package/dist/otel/genai.d.ts +83 -7
- package/dist/otel/genai.js +69 -9
- package/dist/otel/tracer.d.ts +42 -13
- package/dist/otel/tracer.js +241 -56
- package/dist/page.d.ts +7 -1
- package/dist/page.js +76 -22
- package/dist/paid-calls.d.ts +6 -4
- package/dist/paid-calls.js +15 -7
- package/dist/place-offers.d.ts +55 -34
- package/dist/place-offers.js +93 -54
- package/dist/place.d.ts +13 -14
- package/dist/place.js +56 -41
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +3 -2
- package/dist/provider.js +17 -8
- package/dist/redact/match.d.ts +27 -9
- package/dist/redact/match.js +266 -57
- package/dist/run-census.d.ts +1 -1
- package/dist/run-census.js +4 -5
- package/dist/run-cut.js +4 -5
- package/dist/run-export-store.d.ts +15 -0
- package/dist/run-export-store.js +30 -0
- package/dist/run-export.d.ts +139 -0
- package/dist/run-export.js +379 -0
- package/dist/run-file-cut.d.ts +5 -0
- package/dist/run-file-cut.js +13 -0
- package/dist/run-launch.js +16 -3
- package/dist/run-model-key.d.ts +15 -6
- package/dist/run-model-key.js +30 -31
- package/dist/run-reads-over-store.js +4 -4
- package/dist/run-secrets.js +3 -5
- package/dist/run-timeline-served.js +3 -1
- package/dist/runnable.js +2 -2
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +94 -47
- package/dist/runner/adapter-run-spec.d.ts +14 -1
- package/dist/runner/adapter-run-spec.js +64 -28
- package/dist/runner/adapters/pi.js +4 -2
- package/dist/runner/audit.d.ts +8 -5
- package/dist/runner/audit.js +37 -17
- package/dist/runner/beside.js +5 -6
- package/dist/runner/claim-secrets.d.ts +10 -3
- package/dist/runner/claim-secrets.js +29 -13
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +81 -46
- package/dist/runner/compare-end.d.ts +2 -1
- package/dist/runner/compare-end.js +25 -10
- package/dist/runner/conformance/harness.js +2 -3
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/harness-loops.js +3 -3
- package/dist/runner/held.d.ts +5 -2
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +22 -4
- package/dist/runner/learned-first.js +20 -4
- package/dist/runner/learning-end.d.ts +2 -8
- package/dist/runner/learning-end.js +11 -19
- package/dist/runner/live-ticker.js +7 -5
- package/dist/runner/loop-contract.d.ts +0 -2
- package/dist/runner/loop.d.ts +7 -0
- package/dist/runner/loop.js +1 -0
- package/dist/runner/main.js +12 -11
- package/dist/runner/mcp-claim.js +21 -5
- package/dist/runner/meta-tools.js +3 -2
- package/dist/runner/metrics.d.ts +7 -0
- package/dist/runner/metrics.js +19 -0
- package/dist/runner/model-route.d.ts +10 -7
- package/dist/runner/model-route.js +79 -15
- package/dist/runner/native-loop.js +10 -8
- package/dist/runner/presence.d.ts +1 -4
- package/dist/runner/presence.js +6 -8
- package/dist/runner/promotion.d.ts +25 -13
- package/dist/runner/promotion.js +125 -50
- package/dist/runner/redact.d.ts +3 -1
- package/dist/runner/redact.js +5 -3
- package/dist/runner/responses-fetch.d.ts +36 -0
- package/dist/runner/responses-fetch.js +511 -0
- package/dist/runner/run-child-host.d.ts +20 -5
- package/dist/runner/run-child-host.js +179 -77
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +2 -3
- package/dist/runner/runner.js +13 -9
- package/dist/runner/sdk-loop.js +8 -8
- package/dist/runner/spec-holds.d.ts +8 -1
- package/dist/runner/spec-holds.js +9 -4
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +120 -32
- package/dist/runner/workflow-first.js +218 -94
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.js +8 -7
- package/dist/save-once.d.ts +14 -0
- package/dist/save-once.js +31 -0
- package/dist/scrub-command.d.ts +34 -31
- package/dist/scrub-command.js +116 -147
- package/dist/sdk/runs.d.ts +6 -0
- package/dist/sdk/runs.js +89 -10
- package/dist/seal-key.js +4 -4
- package/dist/secret-cut.d.ts +3 -0
- package/dist/secret-cut.js +7 -1
- package/dist/secret-rules.d.ts +8 -1
- package/dist/secret-rules.js +482 -53
- package/dist/secrets.d.ts +51 -9
- package/dist/secrets.js +311 -21
- package/dist/server-keys.d.ts +4 -3
- package/dist/server-keys.js +4 -3
- package/dist/server-secrets-store.js +2 -4
- package/dist/server.d.ts +15 -3
- package/dist/server.js +312 -80
- package/dist/share-context.d.ts +22 -0
- package/dist/share-context.js +76 -0
- package/dist/shell-lex.d.ts +105 -0
- package/dist/shell-lex.js +646 -0
- package/dist/sign-ins-store.d.ts +5 -7
- package/dist/sign-ins-store.js +12 -16
- package/dist/sign-ins.d.ts +7 -11
- package/dist/sign-ins.js +40 -41
- package/dist/skills/agentrun-serve/SKILL.md +5 -2
- package/dist/start-switches.d.ts +6 -5
- package/dist/start-switches.js +8 -4
- package/dist/stats.d.ts +5 -1
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/dialect.d.ts +4 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/mcp-record-keys.d.ts +10 -0
- package/dist/store/mcp-record-keys.js +13 -0
- package/dist/store/postgres/dialect.js +2 -0
- package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
- package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
- package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +33 -10
- package/dist/store/schema.js +70 -16
- package/dist/store/seal.d.ts +4 -1
- package/dist/store/sqlite/run-launch.d.ts +3 -10
- package/dist/store/sqlite/run-launch.js +12 -23
- package/dist/store/sqlite/run-patch.d.ts +17 -10
- package/dist/store/sqlite/run-patch.js +50 -13
- package/dist/store/sqlite/store.d.ts +3 -0
- package/dist/store/sqlite/store.js +116 -34
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +67 -32
- package/dist/store/store.js +14 -11
- package/dist/store-reads/analytics.d.ts +2 -1
- package/dist/store-reads/analytics.js +7 -5
- package/dist/store-reads/learning.d.ts +35 -26
- package/dist/store-reads/learning.js +120 -92
- package/dist/store-reads/stats.d.ts +2 -2
- package/dist/store-reads/stats.js +13 -7
- package/dist/store-view.js +10 -7
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.js +29 -13
- package/dist/template-eval.d.ts +72 -9
- package/dist/template-eval.js +358 -64
- package/dist/timeline/labels.d.ts +1 -1
- package/dist/timeline/labels.js +4 -3
- package/dist/timeline/timeline.d.ts +23 -11
- package/dist/timeline/timeline.js +115 -31
- package/dist/timeline/web-calls.d.ts +8 -6
- package/dist/timeline/web-calls.js +10 -6
- package/dist/tool-gate.d.ts +13 -1
- package/dist/tool-gate.js +43 -3
- package/dist/tool-keys-store.js +2 -4
- package/dist/tool-keys.d.ts +11 -0
- package/dist/tool-keys.js +16 -0
- package/dist/tool-plane.d.ts +50 -11
- package/dist/tool-plane.js +94 -30
- package/dist/tools.d.ts +5 -1
- package/dist/tools.js +7 -7
- package/dist/trigger-email.js +12 -6
- package/dist/triggers.d.ts +15 -34
- package/dist/triggers.js +119 -126
- package/dist/validate.d.ts +8 -1
- package/dist/validate.js +163 -23
- package/dist/web-fake.d.ts +2 -1
- package/dist/web-fake.js +8 -6
- package/dist/web-fetch.d.ts +8 -6
- package/dist/web-fetch.js +13 -11
- package/dist/web-holds.d.ts +32 -0
- package/dist/web-holds.js +86 -0
- package/dist/web-run.d.ts +32 -5
- package/dist/web-run.js +75 -28
- package/dist/web-save.js +23 -12
- package/dist/web-search.js +14 -25
- package/dist/wires.d.ts +4 -3
- package/dist/wires.js +5 -4
- package/dist/workspace/archil-claim.d.ts +12 -5
- package/dist/workspace/archil-claim.js +45 -5
- package/dist/workspace/attach.js +52 -19
- package/dist/workspace/attached-computers.d.ts +6 -2
- package/dist/workspace/attached-computers.js +5 -4
- package/dist/workspace/computer-deps.d.ts +23 -6
- package/dist/workspace/computer-deps.js +35 -17
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +160 -54
- package/dist/workspace/computer-intervals.d.ts +2 -0
- package/dist/workspace/computer-intervals.js +1 -1
- package/dist/workspace/computer-janitor.d.ts +48 -14
- package/dist/workspace/computer-janitor.js +153 -44
- package/dist/workspace/computer-kept.d.ts +158 -32
- package/dist/workspace/computer-kept.js +288 -63
- package/dist/workspace/computer-providers.d.ts +8 -3
- package/dist/workspace/computer-providers.js +12 -5
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/local.js +41 -1
- package/dist/workspace/mount-revoke-left.d.ts +31 -0
- package/dist/workspace/mount-revoke-left.js +72 -0
- package/dist/workspace/paired-route.js +4 -5
- package/dist/workspace/resolve-computer.d.ts +5 -2
- package/dist/workspace/resolve-computer.js +9 -3
- package/dist/workspace/run-end-computers.d.ts +11 -5
- package/dist/workspace/run-end-computers.js +153 -28
- package/dist/workspace/run-tools.d.ts +22 -3
- package/dist/workspace/run-tools.js +17 -5
- package/dist/workspace/run-workspace.d.ts +14 -1
- package/dist/workspace/run-workspace.js +34 -1
- package/dist/workspace/workspace.d.ts +6 -0
- package/package.json +12 -13
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +22 -6
- package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-DPh29cyz.js +0 -747
package/dist/validate.js
CHANGED
|
@@ -249,14 +249,135 @@ export function inputSchemaIssues(schema, at = "definition.input_schema") {
|
|
|
249
249
|
if (content !== undefined && !(isObject(content) && content.type === "string"))
|
|
250
250
|
return [issue(`${at}.properties.content`, "bad_format", `${at}.properties.content is {type: "string"}: content is reserved for the run's message`)];
|
|
251
251
|
const compiled = schemaCheck(schema);
|
|
252
|
-
|
|
252
|
+
if ("why" in compiled)
|
|
253
|
+
return [issue(at, "bad_format", `${at} ${compiled.why}`)];
|
|
254
|
+
// What a run's start checks, checked here: the schema in force, and its own fields' schema (X_OWN_FIELDS), whose
|
|
255
|
+
// propertyNames sees the schema's $defs and definitions alone. A reference that names anything else compiles to a
|
|
256
|
+
// schema that refuses every name, so every run that gives a field of its own would be refused.
|
|
257
|
+
const inForce = inputSchemaOf(schema);
|
|
258
|
+
const forced = schemaCheck(inForce);
|
|
259
|
+
if ("why" in forced)
|
|
260
|
+
return [issue(at, "bad_format", `${at} ${forced.why}`)];
|
|
261
|
+
const own = ownFieldsSchema(inForce);
|
|
262
|
+
if (own === undefined)
|
|
263
|
+
return [];
|
|
264
|
+
const names = `${at}.propertyNames`;
|
|
265
|
+
const said = `${names} is checked against the input's own fields beside the schema's $defs and definitions alone:`;
|
|
266
|
+
const lost = unresolvedRefs(own.propertyNames, own);
|
|
267
|
+
if (lost !== undefined)
|
|
268
|
+
return [issue(names, "bad_format", `${said} its $ref ${JSON.stringify(lost)} names nothing there`, `Move what ${lost} names under ${at}.$defs and refer to it as #/$defs/<name>.`)];
|
|
269
|
+
const ownCompiled = schemaCheck(own);
|
|
270
|
+
return "why" in ownCompiled ? [issue(names, "bad_format", `${said} ${ownCompiled.why}`)] : [];
|
|
271
|
+
}
|
|
272
|
+
/** The schema inputIssues checks an input's own fields against, content left out (X_OWN_FIELDS): the schema in force's
|
|
273
|
+
* maxProperties and propertyNames, beside what a reference in them may name: its definitions, its id and its dialect.
|
|
274
|
+
* Undefined when it has neither. */
|
|
275
|
+
function ownFieldsSchema(inForce) {
|
|
276
|
+
const own = inForce[X_OWN_FIELDS];
|
|
277
|
+
if (!isObject(own))
|
|
278
|
+
return undefined;
|
|
279
|
+
const targets = Object.fromEntries(Object.entries(inForce).filter(([key]) => key === "definitions" || (key.startsWith("$") && key !== "$ref")));
|
|
280
|
+
return { ...targets, type: "object", ...own };
|
|
281
|
+
}
|
|
282
|
+
/** The schemas a schema holds, by the keywords that hold one (a single schema, a list of them or a map of them); an
|
|
283
|
+
* annotation's value (`examples`, `default`, `const`, `enum`, an extension's own data) is data, never a schema. */
|
|
284
|
+
const ONE_SCHEMA = ["not", "if", "then", "else", "items", "additionalItems", "contains", "additionalProperties", "propertyNames", "unevaluatedItems", "unevaluatedProperties", "contentSchema"];
|
|
285
|
+
const SCHEMA_LISTS = ["allOf", "anyOf", "oneOf", "prefixItems", "items"];
|
|
286
|
+
const SCHEMA_MAPS = ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas", "dependencies"];
|
|
287
|
+
function subschemas(schema) {
|
|
288
|
+
const held = [];
|
|
289
|
+
for (const key of ONE_SCHEMA)
|
|
290
|
+
if (isObject(schema[key]))
|
|
291
|
+
held.push(schema[key]);
|
|
292
|
+
for (const key of SCHEMA_LISTS)
|
|
293
|
+
if (Array.isArray(schema[key]))
|
|
294
|
+
held.push(...schema[key]);
|
|
295
|
+
for (const key of SCHEMA_MAPS)
|
|
296
|
+
if (isObject(schema[key]))
|
|
297
|
+
held.push(...Object.values(schema[key]));
|
|
298
|
+
return held;
|
|
299
|
+
}
|
|
300
|
+
/** The subschemas that apply to an instance where `schema` does: all of them but its definitions (`$defs`,
|
|
301
|
+
* `definitions`), which apply only where a reference names them. */
|
|
302
|
+
const applied = (schema) => {
|
|
303
|
+
const { $defs: _defs, definitions: _definitions, ...rest } = schema;
|
|
304
|
+
return subschemas(rest);
|
|
305
|
+
};
|
|
306
|
+
/** The first `$ref` that `node` reaches and that names nothing in `doc` (undefined when each one names something): a
|
|
307
|
+
* JSON Pointer (`#/...`) that `doc` has no value at, an anchor (`#name`) no `$anchor` or `$dynamicAnchor` in it
|
|
308
|
+
* declares, or any other reference when no `$id` in it could give that reference a target. The compiler takes such a
|
|
309
|
+
* reference as the schema `false`. A reference that names something is followed into its target (once each: a cycle
|
|
310
|
+
* ends), so a target that refers on to something the doc lacks is found too. Only schemas are read, by the keywords
|
|
311
|
+
* that hold them (subschemas); a definition is reached only through a reference that names it, so one nothing names
|
|
312
|
+
* is never checked (applied). A part under an `$id` of its own is left to the compiler: its references resolve
|
|
313
|
+
* against that id. */
|
|
314
|
+
function unresolvedRefs(node, doc) {
|
|
315
|
+
const anchors = new Map();
|
|
316
|
+
let ids = false;
|
|
317
|
+
const scan = (value) => {
|
|
318
|
+
if (!isObject(value))
|
|
319
|
+
return;
|
|
320
|
+
for (const key of ["$anchor", "$dynamicAnchor"])
|
|
321
|
+
if (typeof value[key] === "string")
|
|
322
|
+
anchors.set(value[key], value);
|
|
323
|
+
if (typeof value.$id === "string")
|
|
324
|
+
ids = true;
|
|
325
|
+
subschemas(value).forEach(scan);
|
|
326
|
+
};
|
|
327
|
+
scan(doc);
|
|
328
|
+
const at = (pointer) => {
|
|
329
|
+
let here = doc;
|
|
330
|
+
for (const raw of pointer.split("/").slice(1)) {
|
|
331
|
+
const part = decodeURIComponent(raw).replace(/~1/g, "/").replace(/~0/g, "~");
|
|
332
|
+
if (Array.isArray(here) && /^(0|[1-9]\d*)$/.test(part) && Number(part) < here.length)
|
|
333
|
+
here = here[Number(part)];
|
|
334
|
+
else if (isObject(here) && Object.hasOwn(here, part))
|
|
335
|
+
here = here[part];
|
|
336
|
+
else
|
|
337
|
+
return { found: false };
|
|
338
|
+
}
|
|
339
|
+
return { found: true, value: here };
|
|
340
|
+
};
|
|
341
|
+
/** What `ref` names: found, with its target when this doc holds it (none for a reference an `$id` resolves). */
|
|
342
|
+
const target = (ref) => {
|
|
343
|
+
if (!ref.startsWith("#"))
|
|
344
|
+
return { found: ids };
|
|
345
|
+
const fragment = ref.slice(1);
|
|
346
|
+
if (fragment === "")
|
|
347
|
+
return { found: true, value: doc };
|
|
348
|
+
if (fragment.startsWith("/"))
|
|
349
|
+
return at(fragment);
|
|
350
|
+
return anchors.has(fragment) ? { found: true, value: anchors.get(fragment) } : { found: false };
|
|
351
|
+
};
|
|
352
|
+
const seen = new Set();
|
|
353
|
+
const walk = (value) => {
|
|
354
|
+
if (!isObject(value) || typeof value.$id === "string" || seen.has(value))
|
|
355
|
+
return undefined;
|
|
356
|
+
seen.add(value);
|
|
357
|
+
if (typeof value.$ref === "string") {
|
|
358
|
+
const named = target(value.$ref);
|
|
359
|
+
if (!named.found)
|
|
360
|
+
return value.$ref;
|
|
361
|
+
const lost = walk(named.value);
|
|
362
|
+
if (lost !== undefined)
|
|
363
|
+
return lost;
|
|
364
|
+
}
|
|
365
|
+
for (const item of applied(value)) {
|
|
366
|
+
const lost = walk(item);
|
|
367
|
+
if (lost !== undefined)
|
|
368
|
+
return lost;
|
|
369
|
+
}
|
|
370
|
+
return undefined;
|
|
371
|
+
};
|
|
372
|
+
return walk(node);
|
|
253
373
|
}
|
|
254
374
|
/**
|
|
255
375
|
* The input schema in force for an agentic revision whose definition has `schema` (none: DEFAULT_INPUT_SCHEMA). `content`
|
|
256
376
|
* is always taken, as text: a run's message, which a follow-up and a trigger's line add to. It is required when the
|
|
257
377
|
* schema has no field of its own, as an agent with no schema requires it. A schema whose own fields are all optional
|
|
258
378
|
* (a template's `pr_number`, given by hand and left out of a trigger's runs) leaves `required` empty: a run gives
|
|
259
|
-
* content or one of those fields, which inputIssues checks, so an input that says nothing is still refused.
|
|
379
|
+
* content or one of those fields, which inputIssues checks, so an input that says nothing is still refused. Neither the
|
|
380
|
+
* schema's maxProperties nor its propertyNames counts content (X_OWN_FIELDS).
|
|
260
381
|
*/
|
|
261
382
|
export function inputSchemaOf(schema) {
|
|
262
383
|
if (!isObject(schema))
|
|
@@ -264,12 +385,21 @@ export function inputSchemaOf(schema) {
|
|
|
264
385
|
const properties = isObject(schema.properties) ? schema.properties : {};
|
|
265
386
|
const required = Array.isArray(schema.required) ? schema.required.filter((key) => typeof key === "string") : [];
|
|
266
387
|
const ownOptional = required.length === 0 && Object.keys(properties).some((key) => key !== "content");
|
|
388
|
+
const { maxProperties, propertyNames, ...rest } = schema;
|
|
389
|
+
const own = { ...(maxProperties === undefined ? {} : { maxProperties }), ...(propertyNames === undefined ? {} : { propertyNames }) };
|
|
267
390
|
return {
|
|
268
|
-
...
|
|
391
|
+
...rest,
|
|
269
392
|
properties: { ...properties, content: properties.content ?? { type: "string" } },
|
|
270
393
|
required: required.some((key) => key !== "content") || ownOptional ? required : [...new Set([...required, "content"])],
|
|
394
|
+
...(Object.keys(own).length ? { [X_OWN_FIELDS]: own } : {}),
|
|
271
395
|
};
|
|
272
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* Where the schema in force keeps its schema's maxProperties and propertyNames (inputSchemaOf), which count and name the
|
|
399
|
+
* input's own fields: content is always taken (a trigger's line, its event and a schedule's last answer ride in it), so
|
|
400
|
+
* inputIssues checks these two against the input without it. A JSON Schema can't leave one property out of them.
|
|
401
|
+
*/
|
|
402
|
+
export const X_OWN_FIELDS = "x-own-fields";
|
|
273
403
|
/** Each JSON Schema keyword's issue reason (InputIssue.reason): a keyword not named here is `invalid`. */
|
|
274
404
|
const KEYWORD_REASON = {
|
|
275
405
|
type: "wrong_type", enum: "not_an_option", const: "not_an_option", pattern: "bad_format", format: "bad_format",
|
|
@@ -290,26 +420,36 @@ export function inputIssues(input, schema, at = "input") {
|
|
|
290
420
|
out.push(issue(path, reason, message, fix));
|
|
291
421
|
};
|
|
292
422
|
// The schema in force compiles: a save checks it (inputSchemaIssues).
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
423
|
+
const report = (against, value) => {
|
|
424
|
+
const compiled = schemaCheck(against);
|
|
425
|
+
if ("why" in compiled)
|
|
426
|
+
throw new Error(`the input schema ${compiled.why}`);
|
|
427
|
+
for (const error of compiled.validator.Errors(value)[1]) {
|
|
428
|
+
const where = [at, ...error.instancePath.split("/").slice(1).map((part) => part.replace(/~1/g, "/").replace(/~0/g, "~"))].join(".");
|
|
429
|
+
const params = error.params;
|
|
430
|
+
if (error.keyword === "required")
|
|
431
|
+
for (const key of params.requiredProperties ?? [])
|
|
432
|
+
add(`${where}.${key}`, "missing", `${where}.${key} is required`);
|
|
433
|
+
else if (error.keyword === "additionalProperties")
|
|
434
|
+
for (const key of params.additionalProperties ?? [])
|
|
435
|
+
add(`${where}.${key}`, "not_allowed", `${where} keeps no field ${key}`, `Remove ${where}.${key}.`);
|
|
436
|
+
// A closed object's own refusal of each extra property, said once above by its name.
|
|
437
|
+
else if (error.keyword === "boolean" && error.schemaPath.endsWith("/additionalProperties"))
|
|
438
|
+
continue;
|
|
439
|
+
// A required text sent empty is one left blank (a form sends it so): said as a missing one is, never as its length.
|
|
440
|
+
else if (error.keyword === "minLength" && emptyRequired(input, schema, error.instancePath, error.schemaPath))
|
|
441
|
+
add(where, "missing", `${where} is required`);
|
|
442
|
+
else
|
|
443
|
+
add(where, KEYWORD_REASON[error.keyword] ?? "invalid", `${where} ${error.message}`);
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
report(schema, input);
|
|
447
|
+
// Its maxProperties and propertyNames meet the input's own fields, content left out (X_OWN_FIELDS), beside what a
|
|
448
|
+
// reference in them may name: the schema's definitions, its id and its dialect.
|
|
449
|
+
const own = ownFieldsSchema(schema);
|
|
450
|
+
if (own !== undefined && isObject(input)) {
|
|
451
|
+
const { content: _content, ...ownFields } = input;
|
|
452
|
+
report(own, ownFields);
|
|
313
453
|
}
|
|
314
454
|
// A schema in force that requires nothing (inputSchemaOf: its own fields all optional) takes content or one of them:
|
|
315
455
|
// an input naming none says nothing, said at content, with the fields that would do instead.
|
package/dist/web-fake.d.ts
CHANGED
|
@@ -62,7 +62,8 @@ export type WebFixture = {
|
|
|
62
62
|
export type WebFake = "unavailable" | WebFixture;
|
|
63
63
|
/** `value` checked as a web fixture: the fixture, else each problem said through `bad`, `at` naming the file. */
|
|
64
64
|
export declare function webFixtureOf(value: unknown, at: string, bad: (message: string) => void): WebFixture | undefined;
|
|
65
|
-
/** `args` searched in `fake`, as the run's web_search answers: `provider`, the one the run's plane names.
|
|
65
|
+
/** `args` searched in `fake`, as the run's web_search answers: `provider`, the one the run's plane names. An answer's
|
|
66
|
+
* `query` pattern matches the search's objective or any of its queries. */
|
|
66
67
|
export declare function fakeSearch(fake: WebFake, args: Record<string, unknown>, provider: Exclude<Search, {
|
|
67
68
|
error: string;
|
|
68
69
|
}>["provider"]): Search;
|
package/dist/web-fake.js
CHANGED
|
@@ -66,18 +66,20 @@ export function webFixtureOf(value, at, bad) {
|
|
|
66
66
|
bad(problem);
|
|
67
67
|
return problems.length ? undefined : value;
|
|
68
68
|
}
|
|
69
|
-
/** `args` searched in `fake`, as the run's web_search answers: `provider`, the one the run's plane names.
|
|
69
|
+
/** `args` searched in `fake`, as the run's web_search answers: `provider`, the one the run's plane names. An answer's
|
|
70
|
+
* `query` pattern matches the search's objective or any of its queries. */
|
|
70
71
|
export function fakeSearch(fake, args, provider) {
|
|
71
|
-
const {
|
|
72
|
-
if (!
|
|
73
|
-
return { error: "web_search needs
|
|
72
|
+
const { objective, queries, n } = searchArgs(args);
|
|
73
|
+
if (!objective)
|
|
74
|
+
return { error: "web_search needs an objective" };
|
|
74
75
|
if (fake === "unavailable")
|
|
75
76
|
return { error: RATE_LIMITED };
|
|
76
|
-
const
|
|
77
|
+
const asked = [objective, ...queries];
|
|
78
|
+
const answer = fake.search.answers.find((one) => asked.some((text) => new RegExp(one.query, "i").test(text))) ?? fake.search.default;
|
|
77
79
|
if ("error" in answer)
|
|
78
80
|
return { error: answer.error };
|
|
79
81
|
const results = answer.results.slice(0, n).map((hit) => ({ url: hit.url, title: clip(hit.title, TITLE_CAP), snippet: snippetOf(hit.snippet), ...(hit.published === undefined ? {} : { published: hit.published }) }));
|
|
80
|
-
return { provider,
|
|
82
|
+
return { provider, objective, queries, results };
|
|
81
83
|
}
|
|
82
84
|
/** The part `part` names of the page at `url` in `fake`, as the run's web_fetch answers, through the guarded direct
|
|
83
85
|
* fetch's own path with the fake standing in for the network. */
|
package/dist/web-fetch.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { JsonValue } from "@earendil-works/chord/json";
|
|
2
2
|
import type { TSchema } from "typebox";
|
|
3
3
|
import { type ToolRegistration } from "@earendil-works/pi-durable";
|
|
4
|
-
import { type FetchOptions, type Page, type Part, type WebPage } from "@parcha/agentrun-web";
|
|
4
|
+
import { type FetchOptions, type FoundPage, type Page, type Part, type WebPage } from "@parcha/agentrun-web";
|
|
5
5
|
export declare const WEB_FETCH_TOOL = "web_fetch";
|
|
6
|
-
/** The part `options` names of the page at `url`, through the run's Web
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
/** The part `options` names of the page at `url`, through the run's Web (where `options.objective` is given and a
|
|
7
|
+
* decider runs, the page's likeliest chunks); a failed Page saying why where web_fetch does not run here. A part a
|
|
8
|
+
* call may not ask for is refused first. */
|
|
9
|
+
export declare function fetchFor(env: NodeJS.ProcessEnv, url: unknown, options?: FetchOptions): Promise<WebPage | Page | FoundPage>;
|
|
10
|
+
/** The agent's tool, named `name`. The run's Web is made as the tool is made, when the run opens: it reads the key of
|
|
11
|
+
* any keyed provider web_fetch asks, and writes the run's start line (webOf). `fake`: what reads each page in the
|
|
12
|
+
* provider's place (a template eval's web fake, web-fake.ts). */
|
|
11
13
|
export declare function webFetchTool(env: NodeJS.ProcessEnv, name?: string, fake?: (url: unknown, part: Part & {
|
|
12
14
|
signal?: AbortSignal;
|
|
13
15
|
}) => Promise<WebPage | Page>): ToolRegistration<TSchema, JsonValue>;
|
package/dist/web-fetch.js
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import { defineTool } from "@earendil-works/pi-durable";
|
|
2
|
-
import { askedUrl,
|
|
3
|
-
import { fetchOptions,
|
|
2
|
+
import { askedUrl, partProblem, WEB_FETCH_DESCRIPTION, WEB_FETCH_PARAMETERS, webFetchText } from "@parcha/agentrun-web";
|
|
3
|
+
import { fetchOptions, webOf } from "./web-run.js";
|
|
4
4
|
import { FAUX_ENV } from "./model.js";
|
|
5
5
|
import { forModel } from "./result.js";
|
|
6
6
|
import { isUnavailable, planeOf, whyUnavailable } from "./tool-plane.js";
|
|
7
7
|
export const WEB_FETCH_TOOL = "web_fetch";
|
|
8
|
-
/** The part `options` names of the page at `url`, through the run's Web
|
|
9
|
-
*
|
|
8
|
+
/** The part `options` names of the page at `url`, through the run's Web (where `options.objective` is given and a
|
|
9
|
+
* decider runs, the page's likeliest chunks); a failed Page saying why where web_fetch does not run here. A part a
|
|
10
|
+
* call may not ask for is refused first. */
|
|
10
11
|
export async function fetchFor(env, url, options = {}) {
|
|
11
12
|
const resolved = planeOf(env).web_fetch;
|
|
12
13
|
if (isUnavailable(resolved) && !partProblem(options))
|
|
13
14
|
return { ok: false, url: askedUrl(url), status: 0, title: "", text: "", links: [], error: `web_fetch does not run here: ${whyUnavailable(resolved)}` };
|
|
14
15
|
return (await webOf(env).fetch(url, options)).answer;
|
|
15
16
|
}
|
|
16
|
-
/** The agent's tool, named `name`.
|
|
17
|
-
*
|
|
17
|
+
/** The agent's tool, named `name`. The run's Web is made as the tool is made, when the run opens: it reads the key of
|
|
18
|
+
* any keyed provider web_fetch asks, and writes the run's start line (webOf). `fake`: what reads each page in the
|
|
19
|
+
* provider's place (a template eval's web fake, web-fake.ts). */
|
|
18
20
|
export function webFetchTool(env, name = WEB_FETCH_TOOL, fake) {
|
|
19
|
-
if (
|
|
21
|
+
if (!fake)
|
|
20
22
|
webOf(env);
|
|
21
23
|
return defineTool({
|
|
22
24
|
name,
|
|
23
|
-
description:
|
|
24
|
-
parameters:
|
|
25
|
+
description: WEB_FETCH_DESCRIPTION,
|
|
26
|
+
parameters: WEB_FETCH_PARAMETERS,
|
|
25
27
|
replay: "safe",
|
|
26
28
|
execute: async (args, _api, context) => {
|
|
27
|
-
const { url, offset, max_chars } = args;
|
|
29
|
+
const { url, offset, max_chars, objective } = args;
|
|
28
30
|
const signal = context?.abortSignal ? { signal: context.abortSignal } : {};
|
|
29
|
-
const page = fake ? await fake(url, { offset, maxChars: max_chars, ...signal }) : await fetchFor(env, url, { ...(await fetchOptions(env, FAUX_ENV)), offset, maxChars: max_chars, ...signal });
|
|
31
|
+
const page = fake ? await fake(url, { offset, maxChars: max_chars, ...signal }) : await fetchFor(env, url, { ...(await fetchOptions(env, FAUX_ENV)), offset, maxChars: max_chars, ...(typeof objective === "string" ? { objective } : {}), ...signal });
|
|
30
32
|
return forModel(webFetchText(page, name), { details: page });
|
|
31
33
|
},
|
|
32
34
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Hold, type ProviderId } from "@parcha/agentrun-web";
|
|
2
|
+
/** A hold as the server keeps it: always with an end. */
|
|
3
|
+
export type WebHold = Hold;
|
|
4
|
+
/** How long the server holds a keyless provider whose limit named no end (out of quota for the rest of a run): the
|
|
5
|
+
* first run after it pays at most one more refusal to learn it again. */
|
|
6
|
+
export declare const ENDLESS_HOLD_MS: number;
|
|
7
|
+
/** The variable a run's own process gets the server's holds in: JSON, an array of WebHold. */
|
|
8
|
+
export declare const WEB_HOLDS_ENV = "AGENTRUN_SERVE_WEB_HOLDS";
|
|
9
|
+
/** Keeps `value` (holdOf) as the host's hold on its provider's tool, unless one held already ends no earlier: the hold
|
|
10
|
+
* kept, or undefined when nothing changed. */
|
|
11
|
+
export declare function noteHold(value: unknown, now?: number): WebHold | undefined;
|
|
12
|
+
/** The holds not yet lifted at `now`. */
|
|
13
|
+
export declare function activeHolds(now?: number): WebHold[];
|
|
14
|
+
/** What a server restart does: every hold forgotten. */
|
|
15
|
+
export declare function forgetHolds(): void;
|
|
16
|
+
/** The holds at `now` as a run's spawn environment carries them; none, no variable. */
|
|
17
|
+
export declare function holdsEnv(now?: number): Record<string, string>;
|
|
18
|
+
/** The holds a run's spawn environment carries (holdsEnv), each read as noteHold reads one; anything else dropped. */
|
|
19
|
+
export declare function holdsFromEnv(env: NodeJS.ProcessEnv, now?: number): WebHold[];
|
|
20
|
+
export declare function reportHoldsTo(report: (hold: Hold) => void): void;
|
|
21
|
+
/** `hold`, a keyless provider's, handed to the server (reportHoldsTo); a keyed one stays the run's. */
|
|
22
|
+
export declare function reportHold(hold: Hold): void;
|
|
23
|
+
/** A held entry as GET /capabilities shows it on a web tool: the hold, its end as a date, and in words. */
|
|
24
|
+
export type HeldView = {
|
|
25
|
+
provider: ProviderId;
|
|
26
|
+
tool: Hold["tool"];
|
|
27
|
+
kind: Hold["kind"];
|
|
28
|
+
until: string;
|
|
29
|
+
words: string;
|
|
30
|
+
};
|
|
31
|
+
/** The holds at `now` on `providers`, a web tool's (`tool`), and on their keys. */
|
|
32
|
+
export declare function heldViewOf(tool: "search" | "fetch", providers: ReadonlySet<string>, now?: number): HeldView[];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// The server's keyless holds: a keyless provider's limit a run met holds that provider for the whole host (its allowance
|
|
2
|
+
// is the host's, not the run's), in the server's memory alone, until it lifts or the server restarts. Each new run's Web
|
|
3
|
+
// starts with them (webOf; a run's own process gets them in its spawn environment, holdsEnv: hold data alone, never a
|
|
4
|
+
// key), and GET /capabilities reads them live. A run's own process hands each hold it meets back over its channel
|
|
5
|
+
// (reportHold, run-child.ts); the server is their one writer. A keyed provider's hold stays the run's own.
|
|
6
|
+
import { holdingWords, isProviderId, providerOf } from "@parcha/agentrun-web";
|
|
7
|
+
/** How long the server holds a keyless provider whose limit named no end (out of quota for the rest of a run): the
|
|
8
|
+
* first run after it pays at most one more refusal to learn it again. */
|
|
9
|
+
export const ENDLESS_HOLD_MS = 60 * 60_000;
|
|
10
|
+
/** The variable a run's own process gets the server's holds in: JSON, an array of WebHold. */
|
|
11
|
+
export const WEB_HOLDS_ENV = "AGENTRUN_SERVE_WEB_HOLDS";
|
|
12
|
+
const TOOLS = new Set(["search", "fetch", "key"]);
|
|
13
|
+
const KINDS = new Set(["quota", "rate"]);
|
|
14
|
+
const FIELDS = ["provider", "tool", "kind", "until"];
|
|
15
|
+
// This process's holds, by provider and tool. Known limit: a runner in its own process (`agentrun-serve runner`) keeps
|
|
16
|
+
// its runs' holds here, in its memory: they hold that runner's next runs, and the server's GET /capabilities never sees
|
|
17
|
+
// them.
|
|
18
|
+
const holds = new Map();
|
|
19
|
+
/** `value` as a keyless provider's hold, its end `until` (epoch ms; null or Infinity: none named, read as ENDLESS_HOLD_MS
|
|
20
|
+
* from `now`), or undefined: a keyed or unknown provider, another field, or an end not after `now`. */
|
|
21
|
+
function holdOf(value, now) {
|
|
22
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
23
|
+
return undefined;
|
|
24
|
+
const { provider, tool, kind, until } = value;
|
|
25
|
+
if (Object.keys(value).some((field) => !FIELDS.includes(field)))
|
|
26
|
+
return undefined;
|
|
27
|
+
if (!isProviderId(provider) || !providerOf(provider).keyless)
|
|
28
|
+
return undefined;
|
|
29
|
+
if (typeof tool !== "string" || !TOOLS.has(tool) || typeof kind !== "string" || !KINDS.has(kind))
|
|
30
|
+
return undefined;
|
|
31
|
+
const end = until === null || until === Number.POSITIVE_INFINITY ? now + ENDLESS_HOLD_MS : typeof until === "number" && Number.isFinite(until) ? until : Number.NaN;
|
|
32
|
+
return end > now ? { provider, tool: tool, kind: kind, until: end } : undefined;
|
|
33
|
+
}
|
|
34
|
+
/** Keeps `value` (holdOf) as the host's hold on its provider's tool, unless one held already ends no earlier: the hold
|
|
35
|
+
* kept, or undefined when nothing changed. */
|
|
36
|
+
export function noteHold(value, now = Date.now()) {
|
|
37
|
+
const hold = holdOf(value, now);
|
|
38
|
+
if (!hold)
|
|
39
|
+
return undefined;
|
|
40
|
+
const at = `${hold.provider} ${hold.tool}`;
|
|
41
|
+
const held = holds.get(at);
|
|
42
|
+
if (held && held.until >= hold.until && held.until > now)
|
|
43
|
+
return undefined;
|
|
44
|
+
holds.set(at, hold);
|
|
45
|
+
return hold;
|
|
46
|
+
}
|
|
47
|
+
/** The holds not yet lifted at `now`. */
|
|
48
|
+
export function activeHolds(now = Date.now()) {
|
|
49
|
+
return [...holds.values()].filter((hold) => hold.until > now);
|
|
50
|
+
}
|
|
51
|
+
/** What a server restart does: every hold forgotten. */
|
|
52
|
+
export function forgetHolds() {
|
|
53
|
+
holds.clear();
|
|
54
|
+
}
|
|
55
|
+
/** The holds at `now` as a run's spawn environment carries them; none, no variable. */
|
|
56
|
+
export function holdsEnv(now = Date.now()) {
|
|
57
|
+
const active = activeHolds(now);
|
|
58
|
+
return active.length ? { [WEB_HOLDS_ENV]: JSON.stringify(active) } : {};
|
|
59
|
+
}
|
|
60
|
+
/** The holds a run's spawn environment carries (holdsEnv), each read as noteHold reads one; anything else dropped. */
|
|
61
|
+
export function holdsFromEnv(env, now = Date.now()) {
|
|
62
|
+
let given;
|
|
63
|
+
try {
|
|
64
|
+
given = JSON.parse(env[WEB_HOLDS_ENV] ?? "[]");
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
return Array.isArray(given) ? given.flatMap((one) => holdOf(one, now) ?? []) : [];
|
|
70
|
+
}
|
|
71
|
+
/** Where a hold a run meets goes: the server's own holds, or, in a run's own process, its channel to the runner. */
|
|
72
|
+
let reporter = (hold) => void noteHold(hold);
|
|
73
|
+
export function reportHoldsTo(report) {
|
|
74
|
+
reporter = report;
|
|
75
|
+
}
|
|
76
|
+
/** `hold`, a keyless provider's, handed to the server (reportHoldsTo); a keyed one stays the run's. */
|
|
77
|
+
export function reportHold(hold) {
|
|
78
|
+
if (providerOf(hold.provider).keyless)
|
|
79
|
+
reporter(hold);
|
|
80
|
+
}
|
|
81
|
+
/** The holds at `now` on `providers`, a web tool's (`tool`), and on their keys. */
|
|
82
|
+
export function heldViewOf(tool, providers, now = Date.now()) {
|
|
83
|
+
return activeHolds(now)
|
|
84
|
+
.filter((hold) => providers.has(hold.provider) && (hold.tool === tool || hold.tool === "key"))
|
|
85
|
+
.map((hold) => ({ provider: hold.provider, tool: hold.tool, kind: hold.kind, until: new Date(hold.until).toISOString(), words: holdingWords(hold) }));
|
|
86
|
+
}
|
package/dist/web-run.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import type { TSchema } from "typebox";
|
|
3
2
|
import type { PublicFetchOptions } from "@parcha/pi-browser";
|
|
4
|
-
import { type FetchProvider, type Guard, type SearchProvider, type Web } from "@parcha/agentrun-web";
|
|
3
|
+
import { type FetchProvider, type Guard, jevWebDecider, type SearchProvider, type Web, type WebClient } from "@parcha/agentrun-web";
|
|
5
4
|
import { type SearchModels } from "./hosted-search.js";
|
|
5
|
+
import { type HeldView } from "./web-holds.js";
|
|
6
6
|
/** pi-browser's guard and reader, loaded at the first fetch, so a run that never fetches never loads pi-browser. */
|
|
7
7
|
export declare const GUARD: Guard;
|
|
8
8
|
export declare const RATE_LIMITED = "Free web search is rate-limited right now. Try again in a minute; add the free Parallel Search server in Settings \u2192 MCP servers and grant the agent its web_search; or add a Parallel key in Settings \u2192 API Keys to search with a key.";
|
|
@@ -15,17 +15,44 @@ export declare const FAUX_EXA_ENV = "AGENTRUN_SERVE_FAUX_EXA";
|
|
|
15
15
|
export declare const FAUX_FIRECRAWL_ENV = "AGENTRUN_SERVE_FAUX_FIRECRAWL";
|
|
16
16
|
/** The fetch's resolver and transport: the faux module's under `--faux` with one named, else none. */
|
|
17
17
|
export declare function fetchOptions(env: NodeJS.ProcessEnv, fauxEnv: string): Promise<Omit<PublicFetchOptions, "maxBytes" | "signal">>;
|
|
18
|
-
|
|
18
|
+
/** What a provider that takes them is told of the run, made once for each run's Web (webOf): `model` (Parallel's
|
|
19
|
+
* client_model), the run's model as its bare id, the last segment of its name, lowercase, none where the run names none;
|
|
20
|
+
* and `session` (Parallel's session_id, one for a task's Search and Extract, as its guidance asks), 32 random hex
|
|
21
|
+
* characters, the same on every search and fetch of this Web and another for each other run's. The session is never
|
|
22
|
+
* the run's id or made from it, so nothing of the run reaches the provider. */
|
|
23
|
+
export declare function clientOf(env: NodeJS.ProcessEnv): WebClient;
|
|
19
24
|
/** The run's models a native search goes through, asked when a search runs: ToolHost.search, EffectRun.search. */
|
|
20
25
|
export type SearchOn = () => Promise<SearchModels | undefined>;
|
|
21
26
|
/** The models of the search in flight. */
|
|
22
27
|
export declare const searchingOn: AsyncLocalStorage<SearchOn | undefined>;
|
|
28
|
+
/** The search order a resolution of web_search names, under no --faux; none for one that runs no search. */
|
|
29
|
+
export declare const searchChainOf: (resolved: string | undefined) => readonly SearchProvider[];
|
|
30
|
+
/** The fetch order a resolution of web_fetch names, under no --faux: the guarded direct fetch alone for any other. */
|
|
31
|
+
export declare const fetchChainOf: (resolved: string | undefined) => readonly FetchProvider[];
|
|
32
|
+
/** `tools`, GET /capabilities' (cached), each web tool with `held`, read live: the server's holds at `now` on any provider
|
|
33
|
+
* it asks where it resolves on some harness, or on that provider's key (web-holds.ts). None held, no field. */
|
|
34
|
+
export declare function withHeld<T extends {
|
|
35
|
+
name: string;
|
|
36
|
+
resolves?: Readonly<Record<string, string>>;
|
|
37
|
+
}>(tools: readonly T[], now?: number): (T | (T & {
|
|
38
|
+
held: HeldView[];
|
|
39
|
+
}))[];
|
|
23
40
|
/** The providers each web tool asks where the run's plane resolves it. Under --faux, a keyless provider the server names
|
|
24
41
|
* no fake for is left out, so a test never reaches the network. */
|
|
25
42
|
export declare function ordersOf(env: NodeJS.ProcessEnv): {
|
|
26
43
|
search: SearchProvider[];
|
|
27
44
|
fetch: FetchProvider[];
|
|
28
45
|
};
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
46
|
+
/** Jev for the run's web tools (web's jevWebDecider: jev-1.14.0, rerank+label): on the TypeSafe key the claim handed
|
|
47
|
+
* it (handedKeyOf: in `env`, the claim's own environment, never process.env; decisions.ts' pipe path is dead), unless
|
|
48
|
+
* Jev is off, in the run's plane (the server's switch at launch, tool-plane.ts planeFor) or by AGENTRUN_WEB_JEV_OFF in
|
|
49
|
+
* `env`. None on an OpenRouter key: the web decider runs on TypeSafe's route alone. Its requests go through `env`'s
|
|
50
|
+
* faux Jev under --faux, priced at Jev's published price for the run's cap. */
|
|
51
|
+
export declare function jevWebOf(env: NodeJS.ProcessEnv): ReturnType<typeof jevWebDecider>;
|
|
52
|
+
/** The run's Web. Each keyed provider either web tool asks has its key read here, once, from the variable its registry
|
|
53
|
+
* entry names. It starts with the server's keyless holds (web-holds.ts: its spawn environment's, and the server's own
|
|
54
|
+
* where it runs in the server), and hands each hold it meets back (reportHold), each logged as web_provider_held. Made,
|
|
55
|
+
* it writes the run's one start line, web_destinations: each tool's order, keyed or keyless, any hold known then,
|
|
56
|
+
* and its classifier (Jev's model and policy, or off); never a key. A search's deadlines are its call's
|
|
57
|
+
* (web-search.ts), never the Web's. */
|
|
31
58
|
export declare function webOf(env: NodeJS.ProcessEnv): Web;
|