@humain/humain-code 0.4.14 → 0.4.17
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 +93 -0
- package/README.md +1 -1
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/anthropic-messages-TSNY5MWH.js +67 -0
- package/dist/bundle/chunks/azure-openai-responses-Z4DCXO2G.js +15 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +59 -42
- package/dist/bundle/chunks/{chunk-HDA2IGKA.js → chunk-4NFYTS4C.js} +8 -8
- package/dist/bundle/chunks/{chunk-MF2NEHP4.js → chunk-4XU7TDAL.js} +939 -560
- package/dist/bundle/chunks/{chunk-LUL775V7.js → chunk-5K5RFXXO.js} +4 -4
- package/dist/bundle/chunks/chunk-65U7MPF4.js +1790 -0
- package/dist/bundle/chunks/{chunk-AIXI6RIE.js → chunk-7PRU6YW3.js} +114 -82
- package/dist/bundle/chunks/{chunk-KA7K6ECX.js → chunk-AOL6QG6L.js} +2254 -2416
- package/dist/bundle/chunks/chunk-AWCJWXGD.js +212 -0
- package/dist/bundle/chunks/{chunk-NNKA2PAP.js → chunk-FHVNUUBF.js} +1 -1
- package/dist/bundle/chunks/chunk-FZUJXM6D.js +816 -0
- package/dist/bundle/chunks/chunk-IJYVMOB4.js +6 -0
- package/dist/bundle/chunks/chunk-LG2PJ6JN.js +131 -0
- package/dist/bundle/chunks/chunk-NCQ6WAQK.js +125 -0
- package/dist/bundle/chunks/{chunk-Z74ZYQPX.js → chunk-OKALNPTJ.js} +80 -210
- package/dist/bundle/chunks/{chunk-OX2IBCCA.js → chunk-PTP2ZHFQ.js} +88 -82
- package/dist/bundle/chunks/chunk-PY7SOXCA.js +10 -0
- package/dist/bundle/chunks/chunk-Q7VXYXY3.js +7 -0
- package/dist/bundle/chunks/{chunk-COF5P635.js → chunk-QEF72EIZ.js} +13 -13
- package/dist/bundle/chunks/{chunk-EYIYBQAR.js → chunk-RXOCQRBG.js} +1 -1
- package/dist/bundle/chunks/{chunk-BVHXWQLD.js → chunk-SCBU5WOP.js} +1 -1
- package/dist/bundle/chunks/{chunk-UDVC7A5S.js → chunk-TIFFHHW6.js} +16 -14
- package/dist/bundle/chunks/{chunk-L3J4P5JR.js → chunk-UGJAAWNC.js} +1 -1
- package/dist/bundle/chunks/chunk-V76YPIMT.js +48 -0
- package/dist/bundle/chunks/{chunk-Y3RFGBG2.js → chunk-X3O5MCKJ.js} +1 -1
- package/dist/bundle/chunks/{chunk-KK3KUUMM.js → chunk-X6OTEVGA.js} +71 -66
- package/dist/bundle/chunks/chunk-Y26OS23T.js +80 -0
- package/dist/bundle/chunks/chunk-YDBNMIA3.js +34 -0
- package/dist/bundle/chunks/{chunk-UHLW4KJ7.js → chunk-ZRGFX6T6.js} +92 -89
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-JGN7NZCV.js → cloudflare-workers-ai-system-one-MUJQ6LT2.js} +1 -1
- package/dist/bundle/chunks/{compat-OQMUE3QD.js → compat-ARQPWKBQ.js} +8 -8
- package/dist/bundle/chunks/{dist-65YQEF26.js → dist-D7M52E3X.js} +1733 -1053
- package/dist/bundle/chunks/dist-LKDZAEUQ.js +7 -0
- package/dist/bundle/chunks/{dist-JXEXN6S2.js → dist-XVXV2CL4.js} +1 -1
- package/dist/bundle/chunks/dist-cjs-AXBW3N4F.js +182 -0
- package/dist/bundle/chunks/{easter-egg-3d-ZJ2JUFOA.js → easter-egg-3d-4SUPLBUF.js} +1 -1
- package/dist/bundle/chunks/{execute-LRTXH4YJ.js → execute-NTO3U76E.js} +10 -9
- package/dist/bundle/chunks/{extract-OZW5JHG6.js → extract-BKBHK4AK.js} +14 -13
- package/dist/bundle/chunks/github-copilot.js +34 -47
- package/dist/bundle/chunks/{google-generative-ai-YXXFSTX7.js → google-generative-ai-SJ4JO2MY.js} +2 -2
- package/dist/bundle/chunks/{google-vertex-3IVWLYJ5.js → google-vertex-KNLNNDET.js} +2 -2
- package/dist/bundle/chunks/host-63SNKK5Y.js +2 -0
- package/dist/bundle/chunks/jiti-static-loader-7OZNBOCI.js +2 -0
- package/dist/bundle/chunks/{mistral-conversations-Y7GWO3QB.js → mistral-conversations-G3GN6CMT.js} +20 -20
- package/dist/bundle/chunks/{node-SPBTZUUS.js → node-DZCAT4Q6.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-NSXWHIDT.js → openai-codex-responses-FJFDAWHI.js} +17 -17
- package/dist/bundle/chunks/openai-completions-IC7WRLTI.js +82 -0
- package/dist/bundle/chunks/{openai-decisions-QWEISDVO.js → openai-decisions-HESOHYZB.js} +1 -1
- package/dist/bundle/chunks/openai-responses-XXCYDFSM.js +24 -0
- package/dist/bundle/chunks/{openrouter-images-BMVMAROU.js → openrouter-images-DT2HMZNO.js} +1 -1
- package/dist/bundle/chunks/pdfjs-EK6K7CXX.js +3593 -0
- package/dist/bundle/chunks/{pi-messages-XNEG23NU.js → pi-messages-SAOV3JNW.js} +1 -1
- package/dist/bundle/chunks/{typesafe-system-one-62YHYXZV.js → typesafe-system-one-HCMGHK6A.js} +1 -1
- package/dist/bundle/chunks/{undici-7EW63V4X.js → undici-N4LWJ3S3.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-LP2ULVLW.js +5 -0
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/cli.js +2 -2
- package/dist/bundle/flow/package.json +6 -5
- package/dist/bundle/index.js +8 -8
- package/dist/bundle/rpc-entry.js +3 -3
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +4 -4
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/coordination/adapter/index.d.ts.map +1 -1
- package/dist/coordination/adapter/index.js +1 -1
- package/dist/coordination/adapter/index.js.map +1 -1
- package/dist/coordination/adapter/integration-notices.d.ts +1 -1
- package/dist/coordination/adapter/integration-notices.d.ts.map +1 -1
- package/dist/coordination/adapter/integration-notices.js +5 -2
- package/dist/coordination/adapter/integration-notices.js.map +1 -1
- package/dist/coordination/broker/extension-state.js +3 -3
- package/dist/coordination/broker/extension-state.js.map +1 -1
- package/dist/coordination/transport/framing.d.ts.map +1 -1
- package/dist/coordination/transport/framing.js +2 -1
- package/dist/coordination/transport/framing.js.map +1 -1
- package/dist/core/account-reporting.d.ts +3 -1
- package/dist/core/account-reporting.d.ts.map +1 -1
- package/dist/core/account-reporting.js +12 -2
- package/dist/core/account-reporting.js.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +39 -36
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +4 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +5 -4
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/codex-usage.d.ts +11 -2
- package/dist/core/codex-usage.d.ts.map +1 -1
- package/dist/core/codex-usage.js +74 -2
- package/dist/core/codex-usage.js.map +1 -1
- package/dist/core/export-html/template.js +21 -16
- package/dist/core/model-config.d.ts +33 -8
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +22 -4
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.d.ts +56 -43
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +256 -361
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +6 -3
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +19 -5
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +7 -2
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/oauth-account-pool.d.ts +9 -1
- package/dist/core/oauth-account-pool.d.ts.map +1 -1
- package/dist/core/oauth-account-pool.js +63 -12
- package/dist/core/oauth-account-pool.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +7 -2
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +2 -0
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +2 -0
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +11 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +4 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +8 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/slash-commands.js +1 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +2 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +21 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/renderers/read.d.ts.map +1 -1
- package/dist/core/tools/renderers/read.js +7 -10
- package/dist/core/tools/renderers/read.js.map +1 -1
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +4 -7
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/core/trace/redaction.d.ts.map +1 -1
- package/dist/core/trace/redaction.js +3 -1
- package/dist/core/trace/redaction.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +12 -0
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/index.d.ts.map +1 -1
- package/dist/extensions/codemode/index.js +5 -0
- package/dist/extensions/codemode/index.js.map +1 -1
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +74 -20
- package/dist/humain/flow-accounts-host.d.ts.map +1 -1
- package/dist/humain/flow-accounts-host.js +3 -0
- package/dist/humain/flow-accounts-host.js.map +1 -1
- package/dist/humain/flow-command.d.ts +1 -1
- package/dist/humain/flow-command.d.ts.map +1 -1
- package/dist/humain/flow-command.js +8 -1
- package/dist/humain/flow-command.js.map +1 -1
- package/dist/humain/flow-loader.js +1 -1
- package/dist/humain/flow-loader.js.map +1 -1
- package/dist/humain/node-provider.d.ts.map +1 -1
- package/dist/humain/node-provider.js +2 -0
- package/dist/humain/node-provider.js.map +1 -1
- package/dist/humain/trace-capture/index.js +3 -3
- package/dist/humain/trace-capture/index.js.map +1 -1
- package/dist/humain/web-access/vendor/credential-source.d.ts +2 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/credential-source.js +50 -4
- package/dist/humain/web-access/vendor/credential-source.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.js +3 -1
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.js +2 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
- package/dist/humain/web-access/vendor/deepseek.d.ts +4 -0
- package/dist/humain/web-access/vendor/deepseek.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/deepseek.js +201 -0
- package/dist/humain/web-access/vendor/deepseek.js.map +1 -0
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +4 -2
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-adc.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-adc.js +49 -5
- package/dist/humain/web-access/vendor/gemini-adc.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.d.ts +3 -3
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +11 -4
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +16 -1
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/page-query.js +12 -6
- package/dist/humain/web-access/vendor/page-query.js.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.js +11 -4
- package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -1
- package/dist/humain/web-access/vendor/searxng.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/searxng.js +2 -1
- package/dist/humain/web-access/vendor/searxng.js.map +1 -1
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ssrf-protection.js +10 -0
- package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.js +17 -6
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
- package/dist/humain/web-access/vendor/utils.d.ts +2 -0
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +18 -0
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.d.ts +2 -0
- package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +10 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +5 -0
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +27 -2
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +2 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +4 -2
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +2 -9
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +28 -14
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/oauth-account-format.d.ts +4 -4
- package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
- package/dist/modes/interactive/oauth-account-format.js +5 -2
- package/dist/modes/interactive/oauth-account-format.js.map +1 -1
- package/dist/modes/interactive/session-share.d.ts.map +1 -1
- package/dist/modes/interactive/session-share.js +9 -2
- package/dist/modes/interactive/session-share.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +16 -4
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +2 -1
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/cli.md +3 -3
- package/docs/codemode.md +3 -1
- package/docs/coordination.md +6 -0
- package/docs/docs.json +4 -0
- package/docs/environment-variables.md +4 -0
- package/docs/flow.md +20 -2
- package/docs/humain-code-forge-flow-walkthrough.md +1 -1
- package/docs/humain-code.md +2 -4
- package/docs/json.md +2 -2
- package/docs/llama-cpp.md +1 -1
- package/docs/nvidia-rtx-llama-cpp.md +96 -0
- package/docs/rpc-commands.md +1 -1
- package/docs/rpc.md +9 -1
- package/docs/sessions.md +1 -1
- package/docs/settings.md +2 -0
- package/docs/trace.md +4 -0
- package/docs/usage.md +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +16 -6
- package/examples/extensions/custom-provider-anthropic/package.json +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +16 -16
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/minimal-mode.ts +4 -4
- package/examples/extensions/sandbox/package-lock.json +6 -6
- package/examples/extensions/sandbox/package.json +2 -2
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/package.json +2 -2
- package/examples/rpc-subagent-progress-host.ts +6 -2
- package/npm-shrinkwrap.json +129 -171
- package/package.json +19 -19
- package/schemas/models.schema.json +9 -5
- package/schemas/settings.schema.json +32 -0
- package/src/coordination/UPSTREAM.md +31 -1
- package/src/coordination/upstream.json +3 -3
- package/src/humain/adhd/UPSTREAM.md +8 -0
- package/src/humain/caveman/UPSTREAM.md +19 -3
- package/src/humain/caveman/upstream.json +2 -2
- package/src/humain/ponytail/UPSTREAM.md +23 -2
- package/src/humain/ponytail/upstream.json +8 -8
- package/src/humain/ponytail/vendor/skills/ponytail/SKILL.md +1 -1
- package/src/humain/ponytail/vendor/skills/ponytail-debt/SKILL.md +1 -2
- package/src/humain/ponytail/vendor/skills/ponytail-gain/SKILL.md +0 -1
- package/src/humain/web-access/UPSTREAM.md +45 -1
- package/src/humain/web-access/upstream.json +4 -4
- package/dist/bundle/chunks/anthropic-messages-YSAHA7QM.js +0 -67
- package/dist/bundle/chunks/azure-openai-responses-Z5XYDPHS.js +0 -15
- package/dist/bundle/chunks/chunk-2TTB6GIB.js +0 -47
- package/dist/bundle/chunks/chunk-4DXXZHY2.js +0 -540
- package/dist/bundle/chunks/chunk-A7QKOI62.js +0 -572
- package/dist/bundle/chunks/chunk-FRUFMISJ.js +0 -505
- package/dist/bundle/chunks/chunk-IUKCPYKD.js +0 -1786
- package/dist/bundle/chunks/chunk-MG5PX4KU.js +0 -31
- package/dist/bundle/chunks/chunk-RYC5BYVE.js +0 -5
- package/dist/bundle/chunks/chunk-YJ3NQWES.js +0 -9
- package/dist/bundle/chunks/dist-MNSGVI4C.js +0 -7
- package/dist/bundle/chunks/dist-cjs-4BMVQ74V.js +0 -179
- package/dist/bundle/chunks/host-2RMBOGA7.js +0 -2
- package/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +0 -2
- package/dist/bundle/chunks/openai-completions-WGBQHTYA.js +0 -79
- package/dist/bundle/chunks/openai-responses-OKGCSIEY.js +0 -23
- package/dist/bundle/chunks/pdfjs-6UVU6XFX.js +0 -3564
- package/dist/bundle/chunks/virtual-modules-5KW36RPG.js +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models-store.d.ts","sourceRoot":"","sources":["../../src/core/models-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"models-store.d.ts","sourceRoot":"","sources":["../../src/core/models-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AA8BxG,qBAAa,8BAA+B,YAAW,WAAW;IACjE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAEzD,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAI3G;IAEK,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAG7G;IAEK,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAGrF;CACD;AAED,8EAA8E;AAC9E,qBAAa,eAAgB,YAAW,WAAW;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAEhD,YAAY,IAAI,GAAE,MAAiD,EAQlE;IAED,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,iBAAiB;YAWX,UAAU;IAsClB,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAI3G;IAEK,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAS7G;IAEK,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CASrF;CACD"}
|
|
@@ -4,6 +4,11 @@ import { raceWithAbortSignal } from "../utils/abort.js";
|
|
|
4
4
|
import { getFileRevision, normalizePath } from "../utils/paths.js";
|
|
5
5
|
import { stripBom } from "../utils/text.js";
|
|
6
6
|
import { FileAuthStorageBackend } from "./auth-storage.js";
|
|
7
|
+
/** Return no write when the locked file already contains the same serialized catalog. */
|
|
8
|
+
function changedContent(content, data) {
|
|
9
|
+
const next = JSON.stringify(data, null, 2);
|
|
10
|
+
return next === content ? undefined : next;
|
|
11
|
+
}
|
|
7
12
|
// Optimize the common path without retaining an unbounded set of custom paths.
|
|
8
13
|
let sharedModelsFileReadState;
|
|
9
14
|
export class InMemoryCodingAgentModelsStore {
|
|
@@ -95,7 +100,7 @@ export class FileModelsStore {
|
|
|
95
100
|
const current = this.parse(content);
|
|
96
101
|
current[providerId] = structuredClone(entry);
|
|
97
102
|
latest = current;
|
|
98
|
-
return { result: undefined, next:
|
|
103
|
+
return { result: undefined, next: changedContent(content, current) };
|
|
99
104
|
}, options);
|
|
100
105
|
if (latest)
|
|
101
106
|
this.updateReadState(this.readState, latest);
|
|
@@ -106,7 +111,7 @@ export class FileModelsStore {
|
|
|
106
111
|
const current = this.parse(content);
|
|
107
112
|
delete current[providerId];
|
|
108
113
|
latest = current;
|
|
109
|
-
return { result: undefined, next:
|
|
114
|
+
return { result: undefined, next: changedContent(content, current) };
|
|
110
115
|
}, options);
|
|
111
116
|
if (latest)
|
|
112
117
|
this.updateReadState(this.readState, latest);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models-store.js","sourceRoot":"","sources":["../../src/core/models-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAA2B,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAgBpF,+EAA+E;AAC/E,IAAI,yBAAuF,CAAC;AAE5F,MAAM,OAAO,8BAA8B;IACzB,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IAE/D,KAAK,CAAC,IAAI,CAAC,UAAkB,EAAE,OAAqC;QACnE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC3C,OAAO,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,UAAkB,EAAE,KAAuB,EAAE,OAAqC;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AM,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;QACtE,CAAC,EAAE,OAAO,CAAC,CAAC;QACZ,IAAI,MAAM;YAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,UAAkB,EAAE,OAAqC;QACrE,IAAI,MAAgC,CAAC;QACrC,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAClD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACpC,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;YAC3B,MAAM,GAAG,OAAO,CAAC;YACjB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;QACtE,CAAC,EAAE,OAAO,CAAC,CAAC;QACZ,IAAI,MAAM;YAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;CACD","sourcesContent":["import { join } from \"node:path\";\nimport type { ModelsStore, ModelsStoreEntry, ModelsStoreOperationOptions } from \"@earendil-works/pi-ai\";\nimport { getAgentDir } from \"../config.ts\";\nimport { raceWithAbortSignal } from \"../utils/abort.ts\";\nimport { getFileRevision, normalizePath } from \"../utils/paths.ts\";\nimport { stripBom } from \"../utils/text.ts\";\nimport { type AuthStorageBackend, FileAuthStorageBackend } from \"./auth-storage.ts\";\n\ntype StoredModels = Record<string, ModelsStoreEntry>;\n\ntype ModelsFileReload = {\n\tcontroller: AbortController;\n\tpromise: Promise<StoredModels>;\n\treaders: number;\n};\n\ntype ModelsFileReadState = {\n\tdata: StoredModels;\n\trevision?: string;\n\treload?: ModelsFileReload;\n};\n\n// Optimize the common path without retaining an unbounded set of custom paths.\nlet sharedModelsFileReadState: { path: string; readState: ModelsFileReadState } | undefined;\n\nexport class InMemoryCodingAgentModelsStore implements ModelsStore {\n\tprivate readonly entries = new Map<string, ModelsStoreEntry>();\n\n\tasync read(providerId: string, options?: ModelsStoreOperationOptions): Promise<ModelsStoreEntry | undefined> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst entry = this.entries.get(providerId);\n\t\treturn entry ? structuredClone(entry) : undefined;\n\t}\n\n\tasync write(providerId: string, entry: ModelsStoreEntry, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.entries.set(providerId, structuredClone(entry));\n\t}\n\n\tasync delete(providerId: string, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.entries.delete(providerId);\n\t}\n}\n\n/** Locked JSON-backed storage for dynamically refreshed provider catalogs. */\nexport class FileModelsStore implements ModelsStore {\n\tprivate readonly storage: AuthStorageBackend;\n\tprivate readonly path: string;\n\tprivate readonly readState: ModelsFileReadState;\n\n\tconstructor(path: string = join(getAgentDir(), \"models-store.json\")) {\n\t\tthis.path = normalizePath(path);\n\t\tthis.storage = new FileAuthStorageBackend(this.path);\n\t\tthis.readState =\n\t\t\tsharedModelsFileReadState?.path === this.path ? sharedModelsFileReadState.readState : { data: {} };\n\t\tif (!sharedModelsFileReadState) {\n\t\t\tsharedModelsFileReadState = { path: this.path, readState: this.readState };\n\t\t}\n\t}\n\n\tprivate parse(content: string | undefined): StoredModels {\n\t\treturn content ? (JSON.parse(stripBom(content)) as StoredModels) : {};\n\t}\n\n\tprivate updateReadState(readState: ModelsFileReadState, data: StoredModels, revision?: string): void {\n\t\treadState.data = data;\n\t\treadState.revision = revision;\n\t}\n\n\tprivate reloadFromStorage(\n\t\treadState: ModelsFileReadState,\n\t\toptions?: ModelsStoreOperationOptions,\n\t): Promise<StoredModels> {\n\t\treturn this.storage.withLockAsync(async (content) => {\n\t\t\tconst data = this.parse(content);\n\t\t\tthis.updateReadState(readState, data, getFileRevision(this.path));\n\t\t\treturn { result: data };\n\t\t}, options);\n\t}\n\n\tprivate async readLatest(\n\t\treadState: ModelsFileReadState,\n\t\toptions?: ModelsStoreOperationOptions,\n\t): Promise<StoredModels> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst revision = getFileRevision(this.path);\n\t\tif (revision !== undefined && revision === readState.revision) return readState.data;\n\t\tif (!readState.reload) {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst reload: ModelsFileReload = {\n\t\t\t\tcontroller,\n\t\t\t\tpromise: this.reloadFromStorage(readState, { signal: controller.signal }),\n\t\t\t\treaders: 0,\n\t\t\t};\n\t\t\treadState.reload = reload;\n\t\t\tvoid reload.promise.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (readState.reload === reload) readState.reload = undefined;\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tif (readState.reload === reload) readState.reload = undefined;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst reload = readState.reload;\n\t\treload.readers++;\n\t\ttry {\n\t\t\treturn await raceWithAbortSignal(reload.promise, options?.signal);\n\t\t} finally {\n\t\t\treload.readers--;\n\t\t\tif (reload.readers === 0 && readState.reload === reload) {\n\t\t\t\treadState.reload = undefined;\n\t\t\t\treload.controller.abort();\n\t\t\t}\n\t\t}\n\t}\n\n\tasync read(providerId: string, options?: ModelsStoreOperationOptions): Promise<ModelsStoreEntry | undefined> {\n\t\tconst entry = (await this.readLatest(this.readState, options))[providerId];\n\t\toptions?.signal?.throwIfAborted();\n\t\treturn entry ? structuredClone(entry) : undefined;\n\t}\n\n\tasync write(providerId: string, entry: ModelsStoreEntry, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\tlet latest: StoredModels | undefined;\n\t\tawait this.storage.withLockAsync(async (content) => {\n\t\t\tconst current = this.parse(content);\n\t\t\tcurrent[providerId] = structuredClone(entry);\n\t\t\tlatest = current;\n\t\t\treturn { result: undefined, next: JSON.stringify(current, null, 2) };\n\t\t}, options);\n\t\tif (latest) this.updateReadState(this.readState, latest);\n\t}\n\n\tasync delete(providerId: string, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\tlet latest: StoredModels | undefined;\n\t\tawait this.storage.withLockAsync(async (content) => {\n\t\t\tconst current = this.parse(content);\n\t\t\tdelete current[providerId];\n\t\t\tlatest = current;\n\t\t\treturn { result: undefined, next: JSON.stringify(current, null, 2) };\n\t\t}, options);\n\t\tif (latest) this.updateReadState(this.readState, latest);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"models-store.js","sourceRoot":"","sources":["../../src/core/models-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAA2B,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAgBpF,yFAAyF;AACzF,SAAS,cAAc,CAAC,OAA2B,EAAE,IAAkB;IACtE,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,OAAO,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5C,CAAC;AAED,+EAA+E;AAC/E,IAAI,yBAAuF,CAAC;AAE5F,MAAM,OAAO,8BAA8B;IACzB,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IAE/D,KAAK,CAAC,IAAI,CAAC,UAAkB,EAAE,OAAqC;QACnE,OAAO,EAAE,MAAM,EA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AC;QACrC,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAClD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACpC,OAAO,CAAC,UAAU,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,GAAG,OAAO,CAAC;YACjB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;QACtE,CAAC,EAAE,OAAO,CAAC,CAAC;QACZ,IAAI,MAAM;YAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,UAAkB,EAAE,OAAqC;QACrE,IAAI,MAAgC,CAAC;QACrC,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAClD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACpC,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;YAC3B,MAAM,GAAG,OAAO,CAAC;YACjB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;QACtE,CAAC,EAAE,OAAO,CAAC,CAAC;QACZ,IAAI,MAAM;YAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;CACD","sourcesContent":["import { join } from \"node:path\";\nimport type { ModelsStore, ModelsStoreEntry, ModelsStoreOperationOptions } from \"@earendil-works/pi-ai\";\nimport { getAgentDir } from \"../config.ts\";\nimport { raceWithAbortSignal } from \"../utils/abort.ts\";\nimport { getFileRevision, normalizePath } from \"../utils/paths.ts\";\nimport { stripBom } from \"../utils/text.ts\";\nimport { type AuthStorageBackend, FileAuthStorageBackend } from \"./auth-storage.ts\";\n\ntype StoredModels = Record<string, ModelsStoreEntry>;\n\ntype ModelsFileReload = {\n\tcontroller: AbortController;\n\tpromise: Promise<StoredModels>;\n\treaders: number;\n};\n\ntype ModelsFileReadState = {\n\tdata: StoredModels;\n\trevision?: string;\n\treload?: ModelsFileReload;\n};\n\n/** Return no write when the locked file already contains the same serialized catalog. */\nfunction changedContent(content: string | undefined, data: StoredModels): string | undefined {\n\tconst next = JSON.stringify(data, null, 2);\n\treturn next === content ? undefined : next;\n}\n\n// Optimize the common path without retaining an unbounded set of custom paths.\nlet sharedModelsFileReadState: { path: string; readState: ModelsFileReadState } | undefined;\n\nexport class InMemoryCodingAgentModelsStore implements ModelsStore {\n\tprivate readonly entries = new Map<string, ModelsStoreEntry>();\n\n\tasync read(providerId: string, options?: ModelsStoreOperationOptions): Promise<ModelsStoreEntry | undefined> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst entry = this.entries.get(providerId);\n\t\treturn entry ? structuredClone(entry) : undefined;\n\t}\n\n\tasync write(providerId: string, entry: ModelsStoreEntry, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.entries.set(providerId, structuredClone(entry));\n\t}\n\n\tasync delete(providerId: string, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.entries.delete(providerId);\n\t}\n}\n\n/** Locked JSON-backed storage for dynamically refreshed provider catalogs. */\nexport class FileModelsStore implements ModelsStore {\n\tprivate readonly storage: AuthStorageBackend;\n\tprivate readonly path: string;\n\tprivate readonly readState: ModelsFileReadState;\n\n\tconstructor(path: string = join(getAgentDir(), \"models-store.json\")) {\n\t\tthis.path = normalizePath(path);\n\t\tthis.storage = new FileAuthStorageBackend(this.path);\n\t\tthis.readState =\n\t\t\tsharedModelsFileReadState?.path === this.path ? sharedModelsFileReadState.readState : { data: {} };\n\t\tif (!sharedModelsFileReadState) {\n\t\t\tsharedModelsFileReadState = { path: this.path, readState: this.readState };\n\t\t}\n\t}\n\n\tprivate parse(content: string | undefined): StoredModels {\n\t\treturn content ? (JSON.parse(stripBom(content)) as StoredModels) : {};\n\t}\n\n\tprivate updateReadState(readState: ModelsFileReadState, data: StoredModels, revision?: string): void {\n\t\treadState.data = data;\n\t\treadState.revision = revision;\n\t}\n\n\tprivate reloadFromStorage(\n\t\treadState: ModelsFileReadState,\n\t\toptions?: ModelsStoreOperationOptions,\n\t): Promise<StoredModels> {\n\t\treturn this.storage.withLockAsync(async (content) => {\n\t\t\tconst data = this.parse(content);\n\t\t\tthis.updateReadState(readState, data, getFileRevision(this.path));\n\t\t\treturn { result: data };\n\t\t}, options);\n\t}\n\n\tprivate async readLatest(\n\t\treadState: ModelsFileReadState,\n\t\toptions?: ModelsStoreOperationOptions,\n\t): Promise<StoredModels> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst revision = getFileRevision(this.path);\n\t\tif (revision !== undefined && revision === readState.revision) return readState.data;\n\t\tif (!readState.reload) {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst reload: ModelsFileReload = {\n\t\t\t\tcontroller,\n\t\t\t\tpromise: this.reloadFromStorage(readState, { signal: controller.signal }),\n\t\t\t\treaders: 0,\n\t\t\t};\n\t\t\treadState.reload = reload;\n\t\t\tvoid reload.promise.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (readState.reload === reload) readState.reload = undefined;\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tif (readState.reload === reload) readState.reload = undefined;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst reload = readState.reload;\n\t\treload.readers++;\n\t\ttry {\n\t\t\treturn await raceWithAbortSignal(reload.promise, options?.signal);\n\t\t} finally {\n\t\t\treload.readers--;\n\t\t\tif (reload.readers === 0 && readState.reload === reload) {\n\t\t\t\treadState.reload = undefined;\n\t\t\t\treload.controller.abort();\n\t\t\t}\n\t\t}\n\t}\n\n\tasync read(providerId: string, options?: ModelsStoreOperationOptions): Promise<ModelsStoreEntry | undefined> {\n\t\tconst entry = (await this.readLatest(this.readState, options))[providerId];\n\t\toptions?.signal?.throwIfAborted();\n\t\treturn entry ? structuredClone(entry) : undefined;\n\t}\n\n\tasync write(providerId: string, entry: ModelsStoreEntry, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\tlet latest: StoredModels | undefined;\n\t\tawait this.storage.withLockAsync(async (content) => {\n\t\t\tconst current = this.parse(content);\n\t\t\tcurrent[providerId] = structuredClone(entry);\n\t\t\tlatest = current;\n\t\t\treturn { result: undefined, next: changedContent(content, current) };\n\t\t}, options);\n\t\tif (latest) this.updateReadState(this.readState, latest);\n\t}\n\n\tasync delete(providerId: string, options?: ModelsStoreOperationOptions): Promise<void> {\n\t\tlet latest: StoredModels | undefined;\n\t\tawait this.storage.withLockAsync(async (content) => {\n\t\t\tconst current = this.parse(content);\n\t\t\tdelete current[providerId];\n\t\t\tlatest = current;\n\t\t\treturn { result: undefined, next: changedContent(content, current) };\n\t\t}, options);\n\t\tif (latest) this.updateReadState(this.readState, latest);\n\t}\n}\n"]}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* `remove`, `failover`, `adoptCurrent`) first sync the auth.json credential back into the pool
|
|
12
12
|
* (pi-ai may have refreshed it), then write the pool file and, when the active account changed,
|
|
13
13
|
* the new active credential into auth.json. All of this happens under one pool-file lock.
|
|
14
|
+
* `clearExhaustion` only clears matching stored quota markers, rechecking auth and merging its changes only in cache.
|
|
14
15
|
*/
|
|
15
16
|
import type { AssistantMessage, AuthOperationOptions, Credential, CredentialDeleteOptions, CredentialStore, OAuthCredential } from "@earendil-works/pi-ai";
|
|
16
17
|
import { type AuthStorageBackend } from "./auth-storage.ts";
|
|
@@ -28,6 +29,10 @@ export interface PoolAccount<T extends Credential = Credential> {
|
|
|
28
29
|
credential: T;
|
|
29
30
|
/** Epoch ms until which the account is treated as out of quota. */
|
|
30
31
|
exhaustedUntil?: number;
|
|
32
|
+
/** Observed failure count, used for bounded cooldown backoff. */
|
|
33
|
+
quotaFailures?: number;
|
|
34
|
+
/** Monotonic cooldown observation revision; absent legacy values mean zero. */
|
|
35
|
+
cooldownRevision?: number;
|
|
31
36
|
active: boolean;
|
|
32
37
|
}
|
|
33
38
|
export type OAuthAccount = PoolAccount<OAuthCredential>;
|
|
@@ -265,6 +270,8 @@ export declare class OAuthAccountPool {
|
|
|
265
270
|
* its key for non-Codex providers. Call before an operation that replaces the auth.json credential.
|
|
266
271
|
*/
|
|
267
272
|
adoptCurrent(providerId: string, options?: AuthOperationOptions): Promise<OAuthAccount | undefined>;
|
|
273
|
+
/** Clear only a still-current cooldown observation; never select credentials or persist auth.json changes. */
|
|
274
|
+
clearExhaustion(providerId: string, expected: OAuthAccount, options?: AuthOperationOptions): Promise<boolean>;
|
|
268
275
|
/** Generalized storage view. Credentials are sensitive; UI must display only keys, labels and markers. */
|
|
269
276
|
listAccounts(providerId: string, options?: AuthOperationOptions): Promise<PoolAccount[]>;
|
|
270
277
|
getCurrentAccount(providerId: string, options?: AuthOperationOptions): Promise<PoolAccount | undefined>;
|
|
@@ -331,7 +338,8 @@ export declare class OAuthAccountPool {
|
|
|
331
338
|
* the auth.json lock (even when auth.json needs no change); otherwise auth.json is not overwritten. The caller's
|
|
332
339
|
* abort signal is honoured, including while waiting for the auth.json lock, until the commit point (just before
|
|
333
340
|
* auth.json is changed) and ignored afterwards so the pool file write is never skipped once auth.json changed. The
|
|
334
|
-
* cache is published only after the operation succeeded.
|
|
341
|
+
* cache is published only after the operation succeeded. `poolOnly` rechecks auth and merges it only into cache;
|
|
342
|
+
* it never persists auth changes, activates credentials, or normalizes stored account metadata.
|
|
335
343
|
*/
|
|
336
344
|
private run;
|
|
337
345
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-account-pool.d.ts","sourceRoot":"","sources":["../../src/core/oauth-account-pool.ts"],"names":[],"mappings":"AA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C,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC;KAC9D,GACC,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CA8BlC;IAED;;;;;OAKG;IACG,sBAAsB,CAC3B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,iCAAiC,GACxC,OAAO,CAAC,gCAAgC,GAAG,SAAS,CAAC,CA2CvD;IAED,4FAA4F;IAC5F,OAAO,CAAC,gBAAgB;IA4FxB;;;;;;;;;;;;;OAaG;YACW,GAAG;CA2PjB"}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* `remove`, `failover`, `adoptCurrent`) first sync the auth.json credential back into the pool
|
|
12
12
|
* (pi-ai may have refreshed it), then write the pool file and, when the active account changed,
|
|
13
13
|
* the new active credential into auth.json. All of this happens under one pool-file lock.
|
|
14
|
+
* `clearExhaustion` only clears matching stored quota markers, rechecking auth and merging its changes only in cache.
|
|
14
15
|
*/
|
|
15
16
|
import { getOpenAICodexTokenIdentity } from "@earendil-works/pi-ai";
|
|
16
17
|
import { randomUUID } from "crypto";
|
|
@@ -267,6 +268,10 @@ function parsePoolData(content) {
|
|
|
267
268
|
!Number.isSafeInteger(account.quotaFailures) ||
|
|
268
269
|
account.quotaFailures < 0 ||
|
|
269
270
|
account.quotaFailures > 31)) ||
|
|
271
|
+
(account.cooldownRevision !== undefined &&
|
|
272
|
+
(typeof account.cooldownRevision !== "number" ||
|
|
273
|
+
!Number.isSafeInteger(account.cooldownRevision) ||
|
|
274
|
+
account.cooldownRevision < 0)) ||
|
|
270
275
|
(account.exhaustedUntil !== undefined &&
|
|
271
276
|
(typeof account.exhaustedUntil !== "number" || !Number.isFinite(account.exhaustedUntil)))) {
|
|
272
277
|
throw new Error("invalid account entry");
|
|
@@ -287,6 +292,8 @@ function toPoolAccount(pool, key) {
|
|
|
287
292
|
label: stored.label,
|
|
288
293
|
credential: structuredClone(stored.credential),
|
|
289
294
|
exhaustedUntil: stored.exhaustedUntil,
|
|
295
|
+
...(stored.quotaFailures !== undefined ? { quotaFailures: stored.quotaFailures } : {}),
|
|
296
|
+
...(stored.cooldownRevision !== undefined ? { cooldownRevision: stored.cooldownRevision } : {}),
|
|
290
297
|
active: pool.active === key,
|
|
291
298
|
};
|
|
292
299
|
}
|
|
@@ -461,6 +468,29 @@ export class OAuthAccountPool {
|
|
|
461
468
|
async adoptCurrent(providerId, options) {
|
|
462
469
|
return this.run(providerId, "write", options, (pool, context) => context.currentKey !== undefined ? toAccount(pool, context.currentKey) : undefined);
|
|
463
470
|
}
|
|
471
|
+
/** Clear only a still-current cooldown observation; never select credentials or persist auth.json changes. */
|
|
472
|
+
async clearExhaustion(providerId, expected, options) {
|
|
473
|
+
return ((await this.run(providerId, "write", options, (pool, context) => {
|
|
474
|
+
if (!Object.hasOwn(pool.accounts, expected.key))
|
|
475
|
+
return undefined;
|
|
476
|
+
const account = pool.accounts[expected.key];
|
|
477
|
+
if (expected.exhaustedUntil === undefined ||
|
|
478
|
+
!Number.isFinite(expected.exhaustedUntil) ||
|
|
479
|
+
expected.exhaustedUntil <= Date.now() ||
|
|
480
|
+
account.exhaustedUntil !== expected.exhaustedUntil ||
|
|
481
|
+
account.quotaFailures !== expected.quotaFailures ||
|
|
482
|
+
(account.cooldownRevision ?? 0) !== (expected.cooldownRevision ?? 0) ||
|
|
483
|
+
// A saturated revision cannot distinguish another failure with the same reset time.
|
|
484
|
+
account.cooldownRevision === Number.MAX_SAFE_INTEGER ||
|
|
485
|
+
!sameCredential(account.credential, expected.credential) ||
|
|
486
|
+
(context.currentKey === expected.key &&
|
|
487
|
+
!sameCredential(context.currentCredential, expected.credential)))
|
|
488
|
+
return undefined;
|
|
489
|
+
delete account.exhaustedUntil;
|
|
490
|
+
delete account.quotaFailures;
|
|
491
|
+
return true;
|
|
492
|
+
}, undefined, true, false, undefined, undefined, true)) ?? false);
|
|
493
|
+
}
|
|
464
494
|
/** Generalized storage view. Credentials are sensitive; UI must display only keys, labels and markers. */
|
|
465
495
|
async listAccounts(providerId, options) {
|
|
466
496
|
return ((await this.run(providerId, "read", options, (pool) => toPoolAccounts(pool), undefined, false, true)) ?? []);
|
|
@@ -520,6 +550,7 @@ export class OAuthAccountPool {
|
|
|
520
550
|
label,
|
|
521
551
|
exhaustedUntil: existing?.exhaustedUntil,
|
|
522
552
|
quotaFailures: existing?.quotaFailures,
|
|
553
|
+
cooldownRevision: existing?.cooldownRevision,
|
|
523
554
|
};
|
|
524
555
|
delete pool.returnTo;
|
|
525
556
|
pool.active = key;
|
|
@@ -574,6 +605,7 @@ export class OAuthAccountPool {
|
|
|
574
605
|
label: existing?.label ?? identity?.label ?? local?.label ?? key,
|
|
575
606
|
exhaustedUntil: existing?.exhaustedUntil,
|
|
576
607
|
quotaFailures: existing?.quotaFailures,
|
|
608
|
+
cooldownRevision: existing?.cooldownRevision,
|
|
577
609
|
};
|
|
578
610
|
delete pool.returnTo;
|
|
579
611
|
pool.active = key;
|
|
@@ -676,8 +708,10 @@ export class OAuthAccountPool {
|
|
|
676
708
|
? now +
|
|
677
709
|
Math.min(ACCOUNT_RETURN_MAX_COOLDOWN_MS, ACCOUNT_RETURN_COOLDOWN_MS * 2 ** ((source.quotaFailures ?? 1) - 1))
|
|
678
710
|
: undefined);
|
|
679
|
-
if (reset !== undefined && markExhausted)
|
|
711
|
+
if (reset !== undefined && markExhausted) {
|
|
680
712
|
source.exhaustedUntil = reset;
|
|
713
|
+
source.cooldownRevision = Math.min(Number.MAX_SAFE_INTEGER, (source.cooldownRevision ?? 0) + 1);
|
|
714
|
+
}
|
|
681
715
|
const usable = (key) => key !== expectedActiveKey && !skipKeys?.has(key) && isOAuthAccountUsable(pool.accounts[key], now);
|
|
682
716
|
const sameType = source.credential.type === "oauth" || allowApiKeyRotation === true;
|
|
683
717
|
const ordered = candidateKeys
|
|
@@ -791,6 +825,7 @@ export class OAuthAccountPool {
|
|
|
791
825
|
label: existing?.label ?? `Account ${Object.keys(pool.accounts).length + 1}`,
|
|
792
826
|
exhaustedUntil: existing?.exhaustedUntil,
|
|
793
827
|
quotaFailures: existing?.quotaFailures,
|
|
828
|
+
cooldownRevision: existing?.cooldownRevision,
|
|
794
829
|
};
|
|
795
830
|
return key;
|
|
796
831
|
}
|
|
@@ -843,6 +878,7 @@ export class OAuthAccountPool {
|
|
|
843
878
|
label: existing?.label ?? identity.label,
|
|
844
879
|
exhaustedUntil: existing?.exhaustedUntil,
|
|
845
880
|
quotaFailures: existing?.quotaFailures,
|
|
881
|
+
cooldownRevision: existing?.cooldownRevision,
|
|
846
882
|
};
|
|
847
883
|
return identity.key;
|
|
848
884
|
}
|
|
@@ -857,9 +893,10 @@ export class OAuthAccountPool {
|
|
|
857
893
|
* the auth.json lock (even when auth.json needs no change); otherwise auth.json is not overwritten. The caller's
|
|
858
894
|
* abort signal is honoured, including while waiting for the auth.json lock, until the commit point (just before
|
|
859
895
|
* auth.json is changed) and ignored afterwards so the pool file write is never skipped once auth.json changed. The
|
|
860
|
-
* cache is published only after the operation succeeded.
|
|
896
|
+
* cache is published only after the operation succeeded. `poolOnly` rechecks auth and merges it only into cache;
|
|
897
|
+
* it never persists auth changes, activates credentials, or normalizes stored account metadata.
|
|
861
898
|
*/
|
|
862
|
-
async run(providerId, mode, callerOptions, operation, expectedKey, recheckAuth = false, includeApiKeys = false, observation, canActivate) {
|
|
899
|
+
async run(providerId, mode, callerOptions, operation, expectedKey, recheckAuth = false, includeApiKeys = false, observation, canActivate, poolOnly = false) {
|
|
863
900
|
let observationChanged = false;
|
|
864
901
|
const credentials = observation
|
|
865
902
|
? getAccountCredentialStore(this.credentials, (current) => {
|
|
@@ -939,7 +976,7 @@ export class OAuthAccountPool {
|
|
|
939
976
|
const before = JSON.stringify(stored);
|
|
940
977
|
/** Applies `operation` to a copy of the stored pool as if auth.json held `credential`. */
|
|
941
978
|
const plan = (credential) => {
|
|
942
|
-
|
|
979
|
+
let pool = stored ? structuredClone(stored) : { active: "", accounts: {} };
|
|
943
980
|
const currentKey = this.upsertCredential(pool, credential, providerId, pool.active, includeApiKeys);
|
|
944
981
|
if (providerId !== "openai-codex")
|
|
945
982
|
reserveLocalAccountKeys(pool);
|
|
@@ -947,13 +984,20 @@ export class OAuthAccountPool {
|
|
|
947
984
|
pool.active = currentKey;
|
|
948
985
|
/** The pool before the operation, holding the source tokens auth.json may stop holding. */
|
|
949
986
|
const source = structuredClone(pool);
|
|
950
|
-
const context = {
|
|
987
|
+
const context = {
|
|
988
|
+
currentKey,
|
|
989
|
+
currentCredential: currentKey === undefined ? undefined : pool.accounts[currentKey].credential,
|
|
990
|
+
};
|
|
991
|
+
// Marker-only mutations validate against auth.json but must not persist its unrelated changes.
|
|
992
|
+
if (poolOnly)
|
|
993
|
+
pool = stored ? structuredClone(stored) : { active: "", accounts: {} };
|
|
951
994
|
const result = operation(pool, context);
|
|
952
995
|
const keys = Object.keys(pool.accounts);
|
|
953
|
-
if (!Object.hasOwn(pool.accounts, pool.active))
|
|
996
|
+
if (!poolOnly && !Object.hasOwn(pool.accounts, pool.active))
|
|
954
997
|
pool.active = "";
|
|
955
998
|
const active = pool.accounts[pool.active];
|
|
956
|
-
if (
|
|
999
|
+
if (!poolOnly &&
|
|
1000
|
+
active?.credential.type === "api_key" &&
|
|
957
1001
|
(active.credential.key?.includes("$") || active.credential.key?.startsWith("!"))) {
|
|
958
1002
|
const stamped = { ...active.credential, accountKey: pool.active };
|
|
959
1003
|
active.credential = stamped;
|
|
@@ -984,7 +1028,7 @@ export class OAuthAccountPool {
|
|
|
984
1028
|
/** Re-applies the operation when auth.json no longer holds the credential `next` was planned for. */
|
|
985
1029
|
let planned = current;
|
|
986
1030
|
const replan = (latest) => {
|
|
987
|
-
if (!sameCredential(latest, planned)) {
|
|
1031
|
+
if (poolOnly || !sameCredential(latest, planned)) {
|
|
988
1032
|
next = plan(latest);
|
|
989
1033
|
planned = latest;
|
|
990
1034
|
}
|
|
@@ -996,7 +1040,8 @@ export class OAuthAccountPool {
|
|
|
996
1040
|
if (expectedKey !== undefined && currentKey !== expectedKey) {
|
|
997
1041
|
// The operation declined to act (active_changed): no auth.json write; only the sync is persisted.
|
|
998
1042
|
}
|
|
999
|
-
else if (
|
|
1043
|
+
else if (poolOnly ||
|
|
1044
|
+
(!next.empty && (currentKey !== undefined || next.context.activate)) ||
|
|
1000
1045
|
(recheckAuth && currentKey === undefined)) {
|
|
1001
1046
|
const authChange = !next.empty && !sameCredential(next.pool.accounts[next.pool.active].credential, current);
|
|
1002
1047
|
if (authChange || expectedKey !== undefined || recheckAuth) {
|
|
@@ -1005,7 +1050,8 @@ export class OAuthAccountPool {
|
|
|
1005
1050
|
authLink.options?.signal?.throwIfAborted();
|
|
1006
1051
|
const { pool, source, context, result, empty } = replan(latest);
|
|
1007
1052
|
// Declined, or adoption/removal facing a credential it must not replace (non-OAuth or unmatched).
|
|
1008
|
-
if (
|
|
1053
|
+
if (poolOnly ||
|
|
1054
|
+
result === undefined ||
|
|
1009
1055
|
(expectedKey !== undefined && context.currentKey !== expectedKey) ||
|
|
1010
1056
|
(context.currentKey === undefined && !context.activate)) {
|
|
1011
1057
|
return undefined;
|
|
@@ -1037,7 +1083,7 @@ export class OAuthAccountPool {
|
|
|
1037
1083
|
return { result: observation.changed };
|
|
1038
1084
|
}
|
|
1039
1085
|
}
|
|
1040
|
-
if (next.result !== undefined && next.empty && next.context.currentKey !== undefined) {
|
|
1086
|
+
if (!poolOnly && next.result !== undefined && next.empty && next.context.currentKey !== undefined) {
|
|
1041
1087
|
// The last account was removed (by the first plan or a re-plan above): delete the auth.json credential
|
|
1042
1088
|
// only while, under the auth.json lock, it still belongs to a removed account. An API key, another
|
|
1043
1089
|
// account (adopted by the re-plan), or an unmatched credential stays.
|
|
@@ -1068,7 +1114,12 @@ export class OAuthAccountPool {
|
|
|
1068
1114
|
writable: true,
|
|
1069
1115
|
});
|
|
1070
1116
|
const view = structuredClone(pool);
|
|
1071
|
-
if (
|
|
1117
|
+
if (poolOnly) {
|
|
1118
|
+
const currentKey = this.upsertCredential(view, next.context.currentCredential ?? planned, providerId, view.active, true);
|
|
1119
|
+
if (currentKey !== undefined)
|
|
1120
|
+
view.active = currentKey;
|
|
1121
|
+
}
|
|
1122
|
+
if (!poolOnly && !includeApiKeys && planned?.type === "api_key" && !next.context.activate)
|
|
1072
1123
|
this.upsertCredential(view, planned, providerId, view.active, true);
|
|
1073
1124
|
published.view = toPoolAccounts(view);
|
|
1074
1125
|
const changed = !corrupt && JSON.stringify(data[providerId]) !== persisted;
|