@parcha/agentrun-serve 0.1.0-beta.57 → 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 +376 -0
- package/README.md +393 -118
- 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/api-only.d.ts +2 -4
- package/dist/api-only.js +2 -4
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +7 -5
- package/dist/box-paths.js +12 -8
- 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 +121 -0
- package/dist/claude-login-token.js +797 -0
- package/dist/claude-login.d.ts +119 -34
- package/dist/claude-login.js +551 -79
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli.js +325 -328
- 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 +40 -19
- package/dist/computer-attach.js +326 -62
- 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 +12 -11
- package/dist/computers.js +11 -8
- 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.d.ts +25 -4
- package/dist/dial-relay.js +139 -5
- 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 +13 -5
- package/dist/env-switch.js +24 -6
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +12 -4
- package/dist/fal-price.js +110 -26
- 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 +173 -0
- package/dist/learn/ledger.js +225 -0
- package/dist/learn/promote.d.ts +82 -39
- package/dist/learn/promote.js +61 -66
- 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 +40 -21
- package/dist/learning-cost.js +30 -21
- 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 +9 -0
- package/dist/live-reach.js +9 -0
- package/dist/mcp-api-only-origins.d.ts +23 -3
- package/dist/mcp-api-only-origins.js +57 -17
- 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/micro.d.ts +2 -0
- package/dist/micro.js +2 -0
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/model.d.ts +5 -4
- package/dist/model.js +7 -6
- package/dist/monid.d.ts +14 -1
- package/dist/monid.js +103 -26
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +234 -61
- 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 +59 -34
- package/dist/place-offers.js +100 -58
- package/dist/place.d.ts +13 -14
- package/dist/place.js +56 -41
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +5 -4
- package/dist/provider.js +26 -13
- 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-learning-served.d.ts +2 -2
- 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/run-view.d.ts +1 -2
- package/dist/run-view.js +2 -1
- package/dist/runnable.js +2 -2
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +97 -63
- package/dist/runner/adapter-run-spec.d.ts +34 -14
- package/dist/runner/adapter-run-spec.js +120 -75
- 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.d.ts +9 -2
- package/dist/runner/beside.js +29 -13
- package/dist/runner/claim-secrets.d.ts +27 -18
- package/dist/runner/claim-secrets.js +61 -47
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +93 -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 +19 -4
- 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.d.ts +11 -6
- package/dist/runner/main.js +24 -18
- package/dist/runner/mcp-claim.js +24 -7
- package/dist/runner/mcp-run.d.ts +3 -6
- package/dist/runner/mcp-run.js +3 -4
- 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 +11 -4
- package/dist/runner/presence.js +11 -6
- 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/reflect-hook.js +1 -1
- 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 +38 -12
- package/dist/runner/run-child-host.js +231 -83
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +5 -3
- package/dist/runner/runner.js +14 -10
- package/dist/runner/save-slots.js +2 -1
- 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/subagent.d.ts +11 -0
- package/dist/runner/subagent.js +17 -3
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +138 -37
- package/dist/runner/workflow-first.js +230 -99
- package/dist/runner/workflow-spec.js +2 -2
- 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 +33 -10
- package/dist/server.js +454 -136
- 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/slots.d.ts +9 -0
- package/dist/slots.js +45 -0
- 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/0028_learning_ledger.sql +44 -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 +44 -4
- package/dist/store/schema.js +111 -11
- 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 +19 -2
- package/dist/store/sqlite/run-patch.js +67 -2
- package/dist/store/sqlite/store.d.ts +3 -0
- package/dist/store/sqlite/store.js +177 -32
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +74 -25
- 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 +102 -136
- package/dist/store-reads/learning.js +251 -302
- 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 +91 -9
- package/dist/template-eval.js +448 -105
- package/dist/template-import.d.ts +0 -10
- package/dist/template-import.js +5 -10
- 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 +14 -14
- package/dist/timeline/web-calls.js +18 -30
- 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.d.ts +4 -9
- package/dist/web-save.js +27 -55
- 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 +38 -11
- package/dist/workspace/attached-computers.js +81 -16
- package/dist/workspace/computer-deps.d.ts +29 -7
- package/dist/workspace/computer-deps.js +36 -18
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +166 -57
- 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.d.ts +91 -0
- package/dist/workspace/paired-route.js +152 -0
- 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/dist/wrapped.d.ts +8 -2
- package/dist/wrapped.js +21 -6
- package/package.json +12 -13
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +25 -9
- package/dist/console/assets/backend-DVhHzJX2.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-okP-y8PK.js +0 -747
package/dist/browser-cost.js
CHANGED
|
@@ -39,6 +39,21 @@ export function browserPrice(provider, env) {
|
|
|
39
39
|
/** Up to the millionth of a dollar, so the cap's words name a figure never below the hold. */
|
|
40
40
|
const microUsd = (usd) => Math.ceil(Math.round(usd * 1e12) / 1e6) / 1e6;
|
|
41
41
|
export { BROWSER_CHARGED };
|
|
42
|
+
/** Each browser step that is owed, by name: booked and held past the cap's rule (kernel/cap port.ts), for money its
|
|
43
|
+
* provider is already owed outside any call. The one place this file sets owed (owed-pin.test.mjs pins the list and
|
|
44
|
+
* each name's one use): a new owed step is named here, and reviewed there. */
|
|
45
|
+
const OWED = {
|
|
46
|
+
/** A charge's time, as charged (bookOnLedger): under no call too (a release, its top-up). */
|
|
47
|
+
charge: { owed: true },
|
|
48
|
+
/** A kept session's reserve, held from the reopen (its time since its last charge and its next stretch). */
|
|
49
|
+
reopenReserve: { owed: true },
|
|
50
|
+
/** That reserve held again at one stretch once its charge booked the time before it. */
|
|
51
|
+
reserveAgain: { owed: true },
|
|
52
|
+
/** A delayed release's hold, until its release is billed. */
|
|
53
|
+
delayedRelease: { owed: true },
|
|
54
|
+
/** A person's carried time, until the session's next charge books it. */
|
|
55
|
+
personTime: { owed: true },
|
|
56
|
+
};
|
|
42
57
|
/** The tool a browser step on the run's one ledger names (main's charge's `tool`, the timeline's BROWSER_CHARGE): the run
|
|
43
58
|
* view folds its charge into its call's row, as main's. */
|
|
44
59
|
const BROWSER_TOOL = "browser";
|
|
@@ -62,13 +77,16 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
62
77
|
* it held being booked by the session's own charge). `admitted`: the ledger's answer (refused in the cap's words when
|
|
63
78
|
* it has no room; refused with no ledger, where nothing is held). `owed`: time its provider is already owed, run
|
|
64
79
|
* outside any call (a person's carried time, a session held from a reopen, a delayed release): never refused. A fresh
|
|
65
|
-
* session's reserve and a person's time to come (personTime) are not owed: the cap may refuse them.
|
|
80
|
+
* session's reserve and a person's time to come (personTime) are not owed: the cap may refuse them. `after`: the hold
|
|
81
|
+
* this one takes the place of, given back (its drop's promise): this one is asked only once that has landed, so the
|
|
82
|
+
* ledger never judges the two side by side, whatever order it books them in. */
|
|
66
83
|
const holdOf = (name, usd, basis, options = {}) => {
|
|
67
84
|
if (!paid)
|
|
68
85
|
return { hold: { usd, drop: () => { } }, admitted: Promise.resolve({ refused: unbookedRefusal(name) }) };
|
|
69
86
|
const booking = paid;
|
|
70
87
|
const id = `browser:${name}#${(ledgerSeq += 1)}`;
|
|
71
|
-
const
|
|
88
|
+
const ask = () => booking.admit({ id, name, holdUsd: usd, basis, chargedBy: provider, tool: BROWSER_TOOL, hold: true, ...(options.tag ? { tag: options.tag } : {}), ...(options.owed ? { owed: true } : {}) });
|
|
89
|
+
const admitted = (options.after ? options.after.then(ask, ask) : ask()).then(() => ({}), (error) => {
|
|
72
90
|
const capped = error?.code === "spend_cap_reached";
|
|
73
91
|
const refused = capped ? String(error.message) : `${name} could not be held: ${String(error?.message ?? error)}`;
|
|
74
92
|
// The cap's own refusal, as the run's pause reads it (a room refusal's figures; a refusal for good).
|
|
@@ -78,17 +96,18 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
78
96
|
});
|
|
79
97
|
pending.add(admitted);
|
|
80
98
|
void admitted.finally(() => pending.delete(admitted));
|
|
81
|
-
let
|
|
99
|
+
let settled;
|
|
82
100
|
const hold = {
|
|
83
101
|
usd,
|
|
84
102
|
drop: () => {
|
|
85
|
-
if (
|
|
86
|
-
return;
|
|
87
|
-
dropped = true;
|
|
103
|
+
if (settled)
|
|
104
|
+
return settled;
|
|
88
105
|
// Given back: a hold is no charge (its time, when it ran, is booked by the session's own charge), never a $0 one.
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
106
|
+
const giving = admitted.then((answer) => (answer.refused === undefined ? booking.settle(id, 0, { givenBack: true }) : undefined)).then(() => undefined, () => undefined);
|
|
107
|
+
settled = giving;
|
|
108
|
+
pending.add(giving);
|
|
109
|
+
void giving.finally(() => pending.delete(giving));
|
|
110
|
+
return giving;
|
|
92
111
|
},
|
|
93
112
|
};
|
|
94
113
|
return { hold, admitted };
|
|
@@ -138,9 +157,36 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
138
157
|
const carriedSince = (tag, since, now) => (carried.get(tag) ?? []).reduce((sum, { from, to }) => sum + usdOf(Math.max(0, to - Math.max(from, since)) / 1000), 0) +
|
|
139
158
|
// A person who has the browser now: what of their held time has run is held already, as carried time is.
|
|
140
159
|
[...(active.get(tag) ?? [])].reduce((sum, { from, to }) => sum + usdOf(Math.max(0, Math.min(to, now) - Math.max(from, since)) / 1000), 0);
|
|
141
|
-
/** Each call under way, by its id: its conversation
|
|
160
|
+
/** Each call under way, by its id: its conversation, its hold, `givenBack` (settles once its hold on the run's ledger
|
|
161
|
+
* is given back) and `reserves`, the reserves of the sessions it opened, each asked on the ledger once that has landed
|
|
162
|
+
* (the call returns only once they are held, or refused and acted on). */
|
|
142
163
|
const calls = new Map();
|
|
143
164
|
const take = (hold, usd) => void (hold && (hold.usd = Math.max(0, hold.usd - usd)));
|
|
165
|
+
/** Session `tag`'s reserve, one stretch, asked of the cap and not owed: a new session's, or one whose reserve the cap
|
|
166
|
+
* refused before, asked again. Under `call` it is asked once the call's hold is given back (after), in the room that
|
|
167
|
+
* hold kept for it, and the call returns only once it is held, or refused and acted on (reserves): until then the
|
|
168
|
+
* call's own hold covers the session. Refused, its next stretch is held nowhere: that is said, and the cap's own
|
|
169
|
+
* refusal pauses the run, as an ask's refused time does (personTime), so its next request is refused in the cap's words
|
|
170
|
+
* and it parks for a raise. The session is then marked (Open.refused) while this is still its reserve, so its next
|
|
171
|
+
* charge asks again, and once the cap is raised its next stretch is held. A refusal that is not the cap's (a lost
|
|
172
|
+
* claim's) marks nothing: no raise mends it, and the next claim's reopen holds the session. */
|
|
173
|
+
const askReserve = (tag, basis, call) => {
|
|
174
|
+
const reserve = holdOf("this browser session's reserve", stretch, basis, { tag, ...(call ? { after: call.givenBack } : {}) });
|
|
175
|
+
const acted = reserve.admitted.then(async (answer) => {
|
|
176
|
+
if (answer.refused === undefined)
|
|
177
|
+
return;
|
|
178
|
+
const open = sessions.get(tag);
|
|
179
|
+
if (answer.refusal && open?.reserve === reserve.hold)
|
|
180
|
+
open.refused = true;
|
|
181
|
+
log(logLine("browser_reserve_refused", { said: `the reserve of browser session ${tag} was not held on the run's ledger (${answer.refused.slice(0, 200)}): its next stretch is held nowhere` }));
|
|
182
|
+
if (answer.refusal && ledger.pause)
|
|
183
|
+
await ledger.pause(answer.refusal);
|
|
184
|
+
}).catch((error) => void log(logLine("browser_reserve_refused", { said: `the run could not be paused on the refused reserve of browser session ${tag} (${String(error?.message ?? error).slice(0, 200)})` })));
|
|
185
|
+
pending.add(acted);
|
|
186
|
+
void acted.finally(() => pending.delete(acted));
|
|
187
|
+
call?.reserves.push(acted);
|
|
188
|
+
return reserve.hold;
|
|
189
|
+
};
|
|
144
190
|
/** Recorded in the commit that bills it: a BROWSER_CHARGED under the call that ran it (a release's, under its session's
|
|
145
191
|
* last call), its money the ledger step's (booked), what it cost or null when its time has no price, and the seconds it
|
|
146
192
|
* was for, with what `booked` needs. A free provider's time books nothing and holds nothing. */
|
|
@@ -161,7 +207,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
161
207
|
// Held at its charge (known: it was billed): a claim lost before its settle leaves it booked at that, never unknown
|
|
162
208
|
// (the kernel's bookCut books an owed step at its hold). A charge of an unknown amount holds nothing.
|
|
163
209
|
const owes = typeof data.usd === "number" && Number.isFinite(data.usd) && data.usd > 0 ? data.usd : 0;
|
|
164
|
-
const step = paidStep(booking, data.call ?? undefined, { name: "this browser session's time", holdUsd: owes, basis: `${provider}'s session time, billed as it was charged`, by: data.charged_by, tool: BROWSER_TOOL, tag: data.tag,
|
|
210
|
+
const step = paidStep(booking, data.call ?? undefined, { name: "this browser session's time", holdUsd: owes, basis: `${provider}'s session time, billed as it was charged`, by: data.charged_by, tool: BROWSER_TOOL, tag: data.tag, ...OWED.charge, ref: chargeRef(data) }, async () => undefined, () => data.usd).then((stepped) => void ("refused" in stepped && log(logLine("browser_spend_unbooked", { said: `a browser charge of ${data.tag} was not booked on the run's ledger (${stepped.refused.slice(0, 200)}): the next claim's reopen books it` }))), (error) => void log(logLine("browser_spend_unbooked", { said: `a browser charge of ${data.tag} was not booked on the run's ledger (${String(error?.message ?? error).slice(0, 200)}): the next claim's reopen books it` })));
|
|
165
211
|
pending.add(step);
|
|
166
212
|
void step.finally(() => pending.delete(step));
|
|
167
213
|
return step;
|
|
@@ -194,13 +240,33 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
194
240
|
}
|
|
195
241
|
else if (session) {
|
|
196
242
|
take(data.call === null ? undefined : calls.get(data.call)?.hold, Math.max(0, usd - personBooked));
|
|
197
|
-
// Its reserve is one stretch again: a kept session's held what it ran before this
|
|
198
|
-
|
|
243
|
+
// Its reserve is one stretch again: a kept session's (a reopen's, a delayed release's) held what it ran before this
|
|
244
|
+
// charge, which booked it. On the run's ledger too, where a hold keeps the figure it was admitted at: that hold is
|
|
245
|
+
// given back for one of a stretch, so the time this charge booked is never held beside it. Owed, as the reserve it
|
|
246
|
+
// takes the place of was: the session is open and its provider bills its time whatever the cap says, so a refusal
|
|
247
|
+
// would only leave that time unheld (a new session's reserve is the cap's to refuse: its room is its call's hold's).
|
|
248
|
+
// Asked once the old one is given back on the ledger (after), so the two are never held side by side there.
|
|
249
|
+
// A session whose reserve the cap refused holds nothing on the ledger: its reserve is asked again (askReserve), not
|
|
250
|
+
// owed, as a new session's is, so a raise since holds its next stretch, and a cap still full refuses it again.
|
|
251
|
+
if (session.refused) {
|
|
252
|
+
session.refused = false;
|
|
253
|
+
session.reserve = askReserve(data.tag, `${provider}'s next stretch of session time, asked again once the cap refused it`, data.call === null ? undefined : calls.get(data.call));
|
|
254
|
+
}
|
|
255
|
+
else if (session.reserve.usd !== stretch) {
|
|
256
|
+
const givenBack = session.reserve.drop();
|
|
257
|
+
session.reserve = holdOf("this browser session's reserve", stretch, `${provider}'s next stretch of session time, held again once its charge booked the time before it`, { ...OWED.reserveAgain, tag: data.tag, after: givenBack }).hold;
|
|
258
|
+
}
|
|
199
259
|
Object.assign(session, { at: through, call: data.call ?? session.call });
|
|
200
260
|
}
|
|
201
261
|
else {
|
|
202
|
-
|
|
203
|
-
|
|
262
|
+
const call = data.call === null ? undefined : calls.get(data.call);
|
|
263
|
+
take(call?.hold, usd + stretch);
|
|
264
|
+
// Its call's hold is two stretches, one of them for this reserve, but on the run's ledger that hold keeps its
|
|
265
|
+
// admitted figure until the call returns: asked beside it, the reserve would be judged twice and refused for room
|
|
266
|
+
// the run has. So it is asked once the call's hold is given back, in the room that hold kept for it (askReserve). A
|
|
267
|
+
// charge under no call still running asks at once. A new session's reserve is the cap's to refuse (starting a
|
|
268
|
+
// session is a choice).
|
|
269
|
+
sessions.set(data.tag, { cid: data.conversation, reserve: askReserve(data.tag, `${provider}'s next stretch of session time, held until its release is booked`, call), at: through, call: data.call });
|
|
204
270
|
}
|
|
205
271
|
}
|
|
206
272
|
/** The one booking a charge names on the ledger: its session, its time, and whether it was the session's last. */
|
|
@@ -244,7 +310,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
244
310
|
continue;
|
|
245
311
|
// Its reserve carries the down time, so its calls count what it runs from here (`at` now), not the down time again.
|
|
246
312
|
const now = Date.now();
|
|
247
|
-
sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's reserve", stretch + usdOf(Math.max(0, now - at) / 1000), `${provider}'s session time since its last charge and its next stretch, held from the reopen`, {
|
|
313
|
+
sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's reserve", stretch + usdOf(Math.max(0, now - at) / 1000), `${provider}'s session time since its last charge and its next stretch, held from the reopen`, { ...OWED.reopenReserve, tag: row.tag }).hold, at: now, call: null });
|
|
248
314
|
}
|
|
249
315
|
}
|
|
250
316
|
/** The open-session inventory as committed: a session it no longer holds lets go of its reserve (released, billed or
|
|
@@ -263,7 +329,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
263
329
|
continue;
|
|
264
330
|
const usd = usdOf(CREATE_DEADLINE_S + stretchS);
|
|
265
331
|
take([...calls.values()].find((c) => c.cid === row.conversationId)?.hold, usd);
|
|
266
|
-
sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's delayed release", usd, `${provider}'s session time for its create's deadline and a stretch, until its release is billed`, {
|
|
332
|
+
sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's delayed release", usd, `${provider}'s session time for its create's deadline and a stretch, until its release is billed`, { ...OWED.delayedRelease, tag: row.tag }).hold, at: Date.now(), call: null });
|
|
267
333
|
}
|
|
268
334
|
}
|
|
269
335
|
/** Applies each browser charge `harness` commits, and each change of pi-browser's inventory (the document of kind
|
|
@@ -327,13 +393,21 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
327
393
|
const basis = `${provider}'s session time at $${rate} an hour: the ${Math.round(ranS)} s its session ran since its last charge, and twice the next stretch of ${stretchS} s (its ${price.minimumS} s minimum, the ${idleS} s idle window and ${RELEASE_ALLOWANCE_S} s for its release)`;
|
|
328
394
|
// One hold-only step, held at that figure and given back when the call returns (or its claim is lost): the call's
|
|
329
395
|
// charges are each their own step (booked).
|
|
330
|
-
|
|
396
|
+
let landed;
|
|
397
|
+
const entry = { cid: api.conversationId, hold: { usd, drop: () => { } }, givenBack: new Promise((resolve) => (landed = resolve)), reserves: [] };
|
|
398
|
+
calls.set(api.callId, entry);
|
|
331
399
|
try {
|
|
332
400
|
// A provider whose time has no price is held at no figure: the cap's rule refuses it for good, as main does.
|
|
333
401
|
// One refused for room pauses the run (ledger.pause, the run's own: a native tool task runs in no host tool
|
|
334
402
|
// call's ledger), in the cap's words and figures, as an ask's person time does: its next request is refused
|
|
335
403
|
// and the run parks for a raise.
|
|
336
|
-
|
|
404
|
+
// paidStep returns once the call's hold is given back on the ledger (its settle): the reserves of the sessions
|
|
405
|
+
// the call opened are asked then, and the call returns once they are held, so nothing the run does next is judged
|
|
406
|
+
// while the session is held nowhere.
|
|
407
|
+
const stepped = await paidStep(paid, api.callId, { name: "this browser call", holdUsd: rate === null ? Number.NaN : usd, basis, by: provider, tool: BROWSER_TOOL, hold: true }, () => tool.execute(args, api, context), () => 0, ledger.pause).finally(async () => {
|
|
408
|
+
landed();
|
|
409
|
+
await Promise.all(entry.reserves);
|
|
410
|
+
});
|
|
337
411
|
return "refused" in stepped ? await refuse(stepped.refused, api, context) : stepped.result;
|
|
338
412
|
}
|
|
339
413
|
finally {
|
|
@@ -408,7 +482,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
408
482
|
if (!(to > from))
|
|
409
483
|
return;
|
|
410
484
|
// Spent at the provider already: held on the run's ledger until a charge books it.
|
|
411
|
-
const { hold } = holdOf("a person's time in the browser", microUsd(usdOf((to - from) / 1000)), `${provider}'s session time a person used, until the session's next charge books it`, {
|
|
485
|
+
const { hold } = holdOf("a person's time in the browser", microUsd(usdOf((to - from) / 1000)), `${provider}'s session time a person used, until the session's next charge books it`, { ...OWED.personTime, tag });
|
|
412
486
|
carried.set(tag, [...(carried.get(tag) ?? []), { hold, from, to }]);
|
|
413
487
|
}
|
|
414
488
|
/** Once every ledger step of a charge under no call is written. */
|
package/dist/capacity.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Runners } from "./store/store.js";
|
|
2
2
|
/** The hand-back window when none is asked, in minutes. */
|
|
3
3
|
export declare const CAPACITY_WINDOW_MINUTES = 15;
|
|
4
4
|
/** The longest window, in minutes: the hand-backs the store keeps (schema.ts HAND_BACKS_KEPT_MS). */
|
package/dist/capacity.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// GET /v2/capacity: what an operator, or an autoscaler, reads to size the runners. Read from the store alone, so a server
|
|
2
2
|
// with no runner beside it (--no-runner, the API-only profile) answers for every runner on its store: the runs waiting for
|
|
3
|
-
// a runner and the runs a claim holds, each live runner (its row seen within
|
|
3
|
+
// a runner and the runs a claim holds, each live runner (its row seen within RUNNER_STALE_MS) with its version, its
|
|
4
4
|
// slots and how many are free, and the hand-backs within a window. Counts, runner names and versions only: no run id,
|
|
5
5
|
// agent, prompt, address or customer's word. Behind the server's token, as every route but capabilities and health.
|
|
6
6
|
import { ApiError } from "./errors.js";
|
|
7
|
-
import {
|
|
7
|
+
import { RUNNER_STALE_MS } from "./store/store.js";
|
|
8
8
|
/** The hand-back window when none is asked, in minutes. */
|
|
9
9
|
export const CAPACITY_WINDOW_MINUTES = 15;
|
|
10
10
|
/** The longest window, in minutes: the hand-backs the store keeps (schema.ts HAND_BACKS_KEPT_MS). */
|
|
@@ -21,7 +21,7 @@ export function capacityWindowOf(url) {
|
|
|
21
21
|
return minutes;
|
|
22
22
|
}
|
|
23
23
|
/** The capacity read over `runners` (the store's), with hand-backs over the last `windowMinutes`. */
|
|
24
|
-
export async function capacityOverStore(runners, windowMinutes, staleMs =
|
|
24
|
+
export async function capacityOverStore(runners, windowMinutes, staleMs = RUNNER_STALE_MS) {
|
|
25
25
|
const [counts, live] = await Promise.all([runners.capacity(windowMinutes * 60_000), runners.live(staleMs)]);
|
|
26
26
|
const shown = live.map((row) => {
|
|
27
27
|
const executing = counts.held.get(row.runner) ?? 0;
|
package/dist/chatgpt-plan.d.ts
CHANGED
|
@@ -96,6 +96,11 @@ export declare class ChatGPTPlan implements PlanReader {
|
|
|
96
96
|
private read;
|
|
97
97
|
/** The row as sealed now, opened, with the bytes it was read as (what a compare-and-set on it compares). */
|
|
98
98
|
private readSealed;
|
|
99
|
+
/** The row as sealed now (readSealed), taken as the snapshot unless a write moved the snapshot while the read was out:
|
|
100
|
+
* a load or token() that read the row before a sign-in was kept, or before a sign-out removed it, leaves their state. */
|
|
101
|
+
private readTaken;
|
|
102
|
+
/** `row` as the snapshot, by a write that knows it is the row's latest (a sign-in kept, a renewal, a sign-out). */
|
|
103
|
+
private wrote;
|
|
99
104
|
/** The row sealed as `bytes`, opened (its tokens held for redaction); none when they do not open. */
|
|
100
105
|
private open;
|
|
101
106
|
/** `row` sealed as the store keeps it: fresh bytes at each seal. */
|
package/dist/chatgpt-plan.js
CHANGED
|
@@ -179,6 +179,9 @@ const flights = new Map();
|
|
|
179
179
|
* never shows a token when logged. */
|
|
180
180
|
export class ChatGPTPlan {
|
|
181
181
|
#snapshot;
|
|
182
|
+
/** Moved on by each write of the snapshot (wrote: a sign-in kept, a renewal, an expiry, a sign-out): a read of the row
|
|
183
|
+
* that was out across one never takes its row over it (readTaken). */
|
|
184
|
+
#writes = 0;
|
|
182
185
|
#pending;
|
|
183
186
|
/** An access token OpenAI refused (refused): token() renews rather than send it again. */
|
|
184
187
|
#refusedAccess;
|
|
@@ -248,6 +251,20 @@ export class ChatGPTPlan {
|
|
|
248
251
|
const row = this.open(bytes);
|
|
249
252
|
return row ? { row, bytes } : undefined;
|
|
250
253
|
}
|
|
254
|
+
/** The row as sealed now (readSealed), taken as the snapshot unless a write moved the snapshot while the read was out:
|
|
255
|
+
* a load or token() that read the row before a sign-in was kept, or before a sign-out removed it, leaves their state. */
|
|
256
|
+
async readTaken() {
|
|
257
|
+
const writes = this.#writes;
|
|
258
|
+
const read = await this.readSealed();
|
|
259
|
+
if (this.#writes === writes)
|
|
260
|
+
this.#snapshot = read?.row;
|
|
261
|
+
return read;
|
|
262
|
+
}
|
|
263
|
+
/** `row` as the snapshot, by a write that knows it is the row's latest (a sign-in kept, a renewal, a sign-out). */
|
|
264
|
+
wrote(row) {
|
|
265
|
+
this.#snapshot = row;
|
|
266
|
+
this.#writes += 1;
|
|
267
|
+
}
|
|
251
268
|
/** The row sealed as `bytes`, opened (its tokens held for redaction); none when they do not open. */
|
|
252
269
|
open(bytes) {
|
|
253
270
|
try {
|
|
@@ -273,7 +290,7 @@ export class ChatGPTPlan {
|
|
|
273
290
|
}
|
|
274
291
|
/** Reads the sealed row into the state a reader sees. Returns this. */
|
|
275
292
|
async load() {
|
|
276
|
-
|
|
293
|
+
await this.readTaken();
|
|
277
294
|
return this;
|
|
278
295
|
}
|
|
279
296
|
view() {
|
|
@@ -460,7 +477,7 @@ export class ChatGPTPlan {
|
|
|
460
477
|
if (await this.swap(was, row))
|
|
461
478
|
break;
|
|
462
479
|
}
|
|
463
|
-
this
|
|
480
|
+
this.wrote(row);
|
|
464
481
|
this.#problem = undefined;
|
|
465
482
|
this.#deps.log?.({ chatgpt: "signed_in", ...(previousRevoked === undefined ? {} : { previous_revoked: String(previousRevoked) }) });
|
|
466
483
|
// Saved: no longer waiting, so it reads signed in while the server takes the change (`saved`, the sign-in's settle).
|
|
@@ -519,8 +536,7 @@ export class ChatGPTPlan {
|
|
|
519
536
|
/** The access token to send now: the sealed one, renewed first when it ends within 5 minutes. Throws PlanUnavailable,
|
|
520
537
|
* in words, when there is none. */
|
|
521
538
|
async token() {
|
|
522
|
-
const row = await this.
|
|
523
|
-
this.#snapshot = row;
|
|
539
|
+
const row = (await this.readTaken())?.row;
|
|
524
540
|
if (!row)
|
|
525
541
|
throw new PlanUnavailable(SIGNED_OUT);
|
|
526
542
|
if (row.state === "expired")
|
|
@@ -558,11 +574,10 @@ export class ChatGPTPlan {
|
|
|
558
574
|
const holder = randomUUID();
|
|
559
575
|
const giveUp = this.now() + REFRESH_LEASE_MS + REFRESH_CALL_MS;
|
|
560
576
|
for (;;) {
|
|
561
|
-
const read = await this.
|
|
577
|
+
const read = await this.readTaken();
|
|
562
578
|
if (!read)
|
|
563
579
|
throw new PlanUnavailable(SIGNED_OUT);
|
|
564
580
|
const { row, bytes } = read;
|
|
565
|
-
this.#snapshot = row;
|
|
566
581
|
if (row.state === "expired")
|
|
567
582
|
throw new PlanUnavailable(EXPIRED);
|
|
568
583
|
// A peer renewed it since: its pair is the row's now.
|
|
@@ -605,7 +620,7 @@ export class ChatGPTPlan {
|
|
|
605
620
|
}
|
|
606
621
|
const expired = { ...bare, state: "expired" };
|
|
607
622
|
if (await this.swap(bytes, expired)) {
|
|
608
|
-
this
|
|
623
|
+
this.wrote(expired);
|
|
609
624
|
this.#deps.log?.({ chatgpt: "expired" });
|
|
610
625
|
await this.tellChanged();
|
|
611
626
|
throw new PlanUnavailable(EXPIRED);
|
|
@@ -615,7 +630,7 @@ export class ChatGPTPlan {
|
|
|
615
630
|
const renewed = { ...bare, credential: { ...bare.credential, ...next } };
|
|
616
631
|
this.hold(renewed.credential);
|
|
617
632
|
if (await this.swap(bytes, renewed)) {
|
|
618
|
-
this
|
|
633
|
+
this.wrote(renewed);
|
|
619
634
|
return renewed.credential.access;
|
|
620
635
|
}
|
|
621
636
|
// The owner signed out or in again while OpenAI renewed it: the new pair is the sign-in's no longer, and no one
|
|
@@ -626,8 +641,7 @@ export class ChatGPTPlan {
|
|
|
626
641
|
/** After a renewal whose write back lost its compare-and-set (the owner signed out or in again meanwhile): its result
|
|
627
642
|
* is dropped, and the row's state wins. */
|
|
628
643
|
async adopt() {
|
|
629
|
-
const now = await this.
|
|
630
|
-
this.#snapshot = now;
|
|
644
|
+
const now = (await this.readTaken())?.row;
|
|
631
645
|
if (!now)
|
|
632
646
|
throw new PlanUnavailable(SIGNED_OUT);
|
|
633
647
|
if (now.state === "expired")
|
|
@@ -665,7 +679,7 @@ export class ChatGPTPlan {
|
|
|
665
679
|
revoked = revoked && removed;
|
|
666
680
|
break;
|
|
667
681
|
}
|
|
668
|
-
this
|
|
682
|
+
this.wrote(undefined);
|
|
669
683
|
this.#deps.log?.({ chatgpt: "signed_out", revoked: String(revoked) });
|
|
670
684
|
await this.tellChanged();
|
|
671
685
|
return { revoked };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { ClaudeAgentLogin, ClaudeLoginToken } from "@parcha/agentrun-harness-claude";
|
|
2
|
+
import { type Runners } from "./store/index.js";
|
|
3
|
+
/** The pinned CLI's credentials file in its credentials directory (CLAUDE_SECURESTORAGE_CONFIG_DIR). */
|
|
4
|
+
export declare const LOGIN_FILE = ".credentials.json";
|
|
5
|
+
/** The least a token handed to a run has left: the pinned CLI's own margin before it calls a token expired (its
|
|
6
|
+
* `n+300000>=e`), and when the runner renews it. */
|
|
7
|
+
export declare const LOGIN_MARGIN_MS: number;
|
|
8
|
+
/** The longest one renewal request may take: the runner gives it up then (chatgpt-plan.ts's own). */
|
|
9
|
+
export declare const REFRESH_CALL_MS = 15000;
|
|
10
|
+
/** How long an ask waits while another holder (the CLI, another runner) holds the login's refresh lock: the CLI's own
|
|
11
|
+
* request timeout (30 s) and its write back. Then it refuses, having posted nothing. */
|
|
12
|
+
export declare const LOCK_WAIT_MS = 35000;
|
|
13
|
+
/** The words a run gets when the login's token has less than the margin left and the runner could not renew it. */
|
|
14
|
+
export declare const LOGIN_RUNNING_OUT = "Claude Code's login on this machine runs out in less than 5 minutes, and the runner could not renew it: open Claude Code on this login once to renew it, or sign in again under Settings \u2192 Model keys, then start the run again.";
|
|
15
|
+
/** The words a run gets when Anthropic refused the login's token (the run's CLI's 401), whatever time it had left, and
|
|
16
|
+
* the runner could not renew it. */
|
|
17
|
+
export declare const LOGIN_REFUSED_NOT_RENEWED = "Claude refused this login and it could not be renewed; open Claude Code once to sign in again.";
|
|
18
|
+
/** The words a run gets when the runner renewed the login but could not write the renewal to the login's file, and the
|
|
19
|
+
* renewed token it holds in memory has less than the margin left: Anthropic took the file's refresh token, so only that
|
|
20
|
+
* held pair can be renewed, and the runner renews only from the file. */
|
|
21
|
+
export declare const LOGIN_NOT_SAVED = "Claude Code's login on this machine was renewed, but the runner could not save the renewal to the login's file, and the renewed token runs out in less than 5 minutes: make room on the disk (or fix the login folder's permissions) and start the run again; if the runner restarted meanwhile, sign in again under Settings \u2192 Model keys.";
|
|
22
|
+
/** The words a run gets when the login is kept in a form this runner does not read (not the pinned CLI's plaintext file). */
|
|
23
|
+
export declare const LOGIN_SEALED = "Claude Code's login on this machine is kept in a form this runner cannot hand to a run of its own user: set AGENTRUN_RUN_USER=same, or give the run a model_key.";
|
|
24
|
+
/** What a renewal hands back: the token it got and its end, for the one ask whose re-read still finds the old token (a
|
|
25
|
+
* write back that did not land); the file's own read wins otherwise. */
|
|
26
|
+
export type Renewed = {
|
|
27
|
+
readonly access: string;
|
|
28
|
+
readonly expiresAt: number;
|
|
29
|
+
};
|
|
30
|
+
/** Renews `login` in its own file, the one whose access token was read as `seen`, unless the file holds another by then
|
|
31
|
+
* (another holder renewed it: nothing to do). Throws when it could not. `refused`: the token Anthropic refused (the
|
|
32
|
+
* run's CLI's 401), when there is one: a held pair holding it is renewed once saved, never handed again. */
|
|
33
|
+
export type Renew = (login: ClaudeAgentLogin, seen: string, refused?: string) => Promise<Renewed | undefined>;
|
|
34
|
+
export interface LoginTokensOptions {
|
|
35
|
+
/** The login's directories (claude-login.ts loginAt): its file is LOGIN_FILE in `dir`. */
|
|
36
|
+
readonly login: ClaudeAgentLogin;
|
|
37
|
+
readonly now?: () => number;
|
|
38
|
+
/** The renewal. Default: the pinned CLI's own (renewLogin), with `fetch`, `now` and `log` below. */
|
|
39
|
+
readonly renew?: Renew;
|
|
40
|
+
/** What the default renewal posts with (a test's fake endpoint). Default: the global fetch, as it is at the post. */
|
|
41
|
+
readonly fetch?: typeof fetch;
|
|
42
|
+
/** Told each renewal's outcome, in fields that hold no token. */
|
|
43
|
+
readonly log?: (fields: Record<string, string>) => void;
|
|
44
|
+
}
|
|
45
|
+
/** The runner's reader of one login's access token, and its renewer. */
|
|
46
|
+
export declare class LoginTokens {
|
|
47
|
+
#private;
|
|
48
|
+
constructor(options: LoginTokensOptions);
|
|
49
|
+
/** Tells `listener` each token as it is handed, for a redactor. */
|
|
50
|
+
watch(listener: (tokens: string[]) => void): void;
|
|
51
|
+
/** The login's access token, read from its file now, with at least LOGIN_MARGIN_MS left: renewed first (once) when
|
|
52
|
+
* it has less, or when Anthropic refused it (refused). Else it throws in words (signed out, a form not read here, or
|
|
53
|
+
* near its end and not renewed), never with a value of the file in them. */
|
|
54
|
+
token(): Promise<string>;
|
|
55
|
+
/** Anthropic refused `sent` (the run's CLI's 401): the next ask renews it, unless the file holds another token by
|
|
56
|
+
* then (another holder renewed it, and that one is handed). */
|
|
57
|
+
refused(sent: string): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
export interface RenewLoginOptions {
|
|
60
|
+
/** What it posts with. Default: the global fetch, as it is at the post. */
|
|
61
|
+
readonly fetch?: typeof fetch;
|
|
62
|
+
/** The clock a renewed token's end is counted on (the reader's). A lock's age is the wall clock's, as the CLI's. */
|
|
63
|
+
readonly now?: () => number;
|
|
64
|
+
readonly log?: (fields: Record<string, string>) => void;
|
|
65
|
+
/** Default REFRESH_CALL_MS. */
|
|
66
|
+
readonly callMs?: number;
|
|
67
|
+
/** Default LOCK_WAIT_MS. */
|
|
68
|
+
readonly lockWaitMs?: number;
|
|
69
|
+
/** The renewal's file operations: its refresh locks', and its reads of the login's file. Each one not given is
|
|
70
|
+
* fs/promises' own (a test's watches, pauses or fails one on cue). */
|
|
71
|
+
readonly lockFs?: Partial<LockFs>;
|
|
72
|
+
/** How often a held lock is read and touched (its heartbeat). Default: the pinned CLI's (`update:5000`). */
|
|
73
|
+
readonly lockUpdateMs?: number;
|
|
74
|
+
}
|
|
75
|
+
/** The pinned CLI's renewal of a login (the adapter's login-refresh.ts), as the runner does it in the CLI's place. */
|
|
76
|
+
export declare function renewLogin(options?: RenewLoginOptions): Renew;
|
|
77
|
+
/** The file operations a renewal makes: a refresh lock taken, touched and released, and the login's file read as text.
|
|
78
|
+
* fs/promises' own, or a test's that watches, pauses or fails them (RenewLoginOptions.lockFs). */
|
|
79
|
+
export interface LockFs {
|
|
80
|
+
mkdir(path: string): Promise<unknown>;
|
|
81
|
+
stat(path: string): Promise<LockIdentity>;
|
|
82
|
+
utimes(path: string, atime: Date, mtime: Date): Promise<void>;
|
|
83
|
+
rm(path: string, options: {
|
|
84
|
+
readonly recursive: boolean;
|
|
85
|
+
readonly force: boolean;
|
|
86
|
+
}): Promise<void>;
|
|
87
|
+
readFile(path: string): Promise<string>;
|
|
88
|
+
}
|
|
89
|
+
/** A lock directory as read: which directory it is (its device and inode) and its mtime. */
|
|
90
|
+
type LockIdentity = {
|
|
91
|
+
readonly dev: number;
|
|
92
|
+
readonly ino: number;
|
|
93
|
+
readonly mtimeMs: number;
|
|
94
|
+
};
|
|
95
|
+
/** Whether `login` is AgentRun's own login folder in `data` (claude-login.ts agentRunLoginDir), the one login a run
|
|
96
|
+
* under a user of its own is handed a token of; this machine's own Claude Code login is not. */
|
|
97
|
+
export declare const agentRunLogin: (login: ClaudeAgentLogin, data: string) => boolean;
|
|
98
|
+
export declare function loginTokensFor(login: ClaudeAgentLogin, log: (fields: Record<string, string>) => void): LoginTokens;
|
|
99
|
+
/** The words a run's start is refused in by its runner (held.ts claudeLogin) when its claim read Claude Code's login and
|
|
100
|
+
* the runner's second read of the setting, at the start, names none or another folder: the run is put on no login its
|
|
101
|
+
* start did not read, and never falls to a model key it was not claimed on. They name no folder. */
|
|
102
|
+
export declare const LOGIN_CHANGED_SINCE_CLAIM = "This run's runner handed it no Claude Code login: the login was turned off or moved to another folder since this run's claim, and a run claimed on the login does not fall back to the model keys. Start the run again to run it as the login is now, or give it a model_key.";
|
|
103
|
+
/** A run's own process's login (held.ts claudeLogin's reader): each token it reads held by `hold` (the run's redactors)
|
|
104
|
+
* and this process's own (secrets.ts holdSecret) before the run's CLI is handed it, and a token Anthropic refused told
|
|
105
|
+
* to the runner, which renews it at the next ask. A process its runner hands no reader runs on no login (cli-run-spec.ts):
|
|
106
|
+
* its claim read the login as off for it, or its run brought its own model key. */
|
|
107
|
+
export declare function heldTokenLogin(reader: {
|
|
108
|
+
token(): Promise<string>;
|
|
109
|
+
refused?(sent: string): Promise<void>;
|
|
110
|
+
}, hold: (values: string[]) => void): ClaudeLoginToken;
|
|
111
|
+
/** Where the runners on a data folder say whether their runs on the login stay in their own process: one file per
|
|
112
|
+
* runner, named by the sha256 of its whole name, so two names never share a file and no name is a folder (`.`,
|
|
113
|
+
* `..`). The file holds the name itself, which loginRunnerInProcess reads. */
|
|
114
|
+
export declare const loginRunnersDir: (data: string) => string;
|
|
115
|
+
/** Runner `runner` says, at its start, how its runs on the login run: `process` (in its own process, its CLI on the
|
|
116
|
+
* login folder), or `uid` (each a user of its own, on a token), which takes back what an earlier start of that name said. */
|
|
117
|
+
export declare function sayLoginRunner(data: string, runner: string, isolation: "uid" | "process"): void;
|
|
118
|
+
/** The name of a runner on data folder `data` whose runs on the login stay in its own process, and whose word in the
|
|
119
|
+
* store is fresh (presence.ts); none when there is no such runner. */
|
|
120
|
+
export declare function loginRunnerInProcess(data: string, runners: Pick<Runners, "live">): Promise<string | undefined>;
|
|
121
|
+
export {};
|