@humain/humain-code 0.4.18 → 0.5.3
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 +284 -1
- package/README.md +3 -1
- package/dist/agent-monitor/client.d.ts +2 -2
- package/dist/agent-monitor/client.d.ts.map +1 -1
- package/dist/agent-monitor/client.js +3 -2
- package/dist/agent-monitor/client.js.map +1 -1
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/anthropic-messages-ZP5KUK52.js +67 -0
- package/dist/bundle/chunks/anthropic.js +10 -9
- package/dist/bundle/chunks/azure-openai-responses-QJFYQ3DF.js +15 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +152 -200
- package/dist/bundle/chunks/chunk-2GCMACT4.js +1956 -0
- package/dist/bundle/chunks/{chunk-QEF72EIZ.js → chunk-A6B2QMA7.js} +40 -96
- package/dist/bundle/chunks/{chunk-YMBXWW36.js → chunk-AO6FF5JL.js} +9 -8
- package/dist/bundle/chunks/{chunk-OWLBGSXY.js → chunk-CN3Q5UNB.js} +388 -310
- package/dist/bundle/chunks/{chunk-SCIGZFN5.js → chunk-DNGJMRJW.js} +11 -11
- package/dist/bundle/chunks/chunk-DU6POZ7E.js +10 -0
- package/dist/bundle/chunks/chunk-EY3LZOUP.js +1963 -0
- package/dist/bundle/chunks/{chunk-G6ABHCPB.js → chunk-FO2NYB6O.js} +655 -663
- package/dist/bundle/chunks/{chunk-RXOCQRBG.js → chunk-GEISZXXH.js} +1 -1
- package/dist/bundle/chunks/{chunk-OKALNPTJ.js → chunk-HIZWUSPN.js} +24 -24
- package/dist/bundle/chunks/{chunk-MVYV6MJY.js → chunk-HT5YN3LX.js} +1 -1
- package/dist/bundle/chunks/chunk-IDU5BNNI.js +15 -0
- package/dist/bundle/chunks/{chunk-TIFFHHW6.js → chunk-JCXXRCP6.js} +5 -5
- package/dist/bundle/chunks/{chunk-QYCOHSI7.js → chunk-KKCMWB63.js} +8 -7
- package/dist/bundle/chunks/{chunk-L5OUCJ7N.js → chunk-L2VKM23Q.js} +87 -13
- package/dist/bundle/chunks/{chunk-SCBU5WOP.js → chunk-M74U5X4S.js} +30 -23
- package/dist/bundle/chunks/{chunk-AWCJWXGD.js → chunk-MIJHJNNQ.js} +3 -2
- package/dist/bundle/chunks/{chunk-Y26OS23T.js → chunk-N7CQ3UV3.js} +4 -4
- package/dist/bundle/chunks/{chunk-XQZG5HPT.js → chunk-O4DO5RWS.js} +11 -6
- package/dist/bundle/chunks/{chunk-P4UKLIQB.js → chunk-ODJUBJK2.js} +4 -4
- package/dist/bundle/chunks/chunk-OR25QDSS.js +365 -0
- package/dist/bundle/chunks/{chunk-7PRU6YW3.js → chunk-OZNC2W4B.js} +306 -286
- package/dist/bundle/chunks/{chunk-Z33NNMNB.js → chunk-PH7UP57J.js} +1 -1
- package/dist/bundle/chunks/{chunk-HPSQKIWK.js → chunk-PS7DGA7B.js} +1 -1
- package/dist/bundle/chunks/chunk-QW6PTCAB.js +10 -0
- package/dist/bundle/chunks/{chunk-5CDES42D.js → chunk-QWXPGBAG.js} +1 -1
- package/dist/bundle/chunks/{chunk-NCQ6WAQK.js → chunk-ROZV2IYD.js} +1 -1
- package/dist/bundle/chunks/{chunk-3XDL5ZE4.js → chunk-RTXDU3AA.js} +148 -122
- package/dist/bundle/chunks/{chunk-FZUJXM6D.js → chunk-UDB6NI4G.js} +309 -240
- package/dist/bundle/chunks/{chunk-3UXBFT4Q.js → chunk-UJLCKIMZ.js} +1906 -1661
- package/dist/bundle/chunks/chunk-UTNHGOFS.js +88 -0
- package/dist/bundle/chunks/{chunk-H2FY3PEV.js → chunk-V62QBESW.js} +4 -3
- package/dist/bundle/chunks/{chunk-NSMMDV3N.js → chunk-XA7CJAYH.js} +4 -3
- package/dist/bundle/chunks/chunk-XQX7S3GM.js +7 -0
- package/dist/bundle/chunks/{chunk-7VY5IL74.js → chunk-Y3OPKKDR.js} +3 -77
- package/dist/bundle/chunks/chunk-YFOLLX5D.js +23 -0
- package/dist/bundle/chunks/{chunk-YRCLNWFV.js → chunk-ZI7TK7HM.js} +1 -1
- package/dist/bundle/chunks/{chunk-V76YPIMT.js → chunk-ZR4GF4WU.js} +21 -15
- package/dist/bundle/chunks/{cli-2NKM2RNJ.js → cli-ENEFJH2B.js} +1 -1
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-T7TPP7SQ.js +4 -0
- package/dist/bundle/chunks/codemode-worker.js +27 -27
- package/dist/bundle/chunks/compat-CJBWWYHE.js +13 -0
- package/dist/bundle/chunks/{dist-XVXV2CL4.js → dist-IBUWEKEE.js} +3 -3
- package/dist/bundle/chunks/{dist-ZJIYY3GA.js → dist-RKNCFFGM.js} +452 -448
- package/dist/bundle/chunks/dist-YFMJEHPH.js +8 -0
- package/dist/bundle/chunks/{dist-cjs-AXBW3N4F.js → dist-cjs-HTASUQXQ.js} +82 -80
- package/dist/bundle/chunks/{easter-egg-3d-VGJ77XZQ.js → easter-egg-3d-YOPLCOVW.js} +2 -2
- package/dist/bundle/chunks/es-YEFEOGR3.js +1905 -0
- package/dist/bundle/chunks/{esm-GIR7QH65.js → esm-R6HJ4QEG.js} +5 -5
- package/dist/bundle/chunks/{event-streams-NXFTZDSF.js → event-streams-BR2IL6C5.js} +1 -1
- package/dist/bundle/chunks/{execute-ZBEZNJ4E.js → execute-2JXEKQ2X.js} +17 -8
- package/dist/bundle/chunks/{extract-RFWEHH6W.js → extract-OTCGZGTL.js} +50 -47
- package/dist/bundle/chunks/github-copilot.js +44 -40
- package/dist/bundle/chunks/google-generative-ai-HVPCGIZ6.js +21 -0
- package/dist/bundle/chunks/google-vertex-UM5MAALA.js +25 -0
- package/dist/bundle/chunks/host-ZHEL5XQW.js +2 -0
- package/dist/bundle/chunks/{https-proxy-agent-7CAXVAFH.js → https-proxy-agent-JQICCRPH.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-AGCW7HYN.js → llama-cpp-classify-B3G57LVR.js} +5 -5
- package/dist/bundle/chunks/{mistral-conversations-G3GN6CMT.js → mistral-conversations-AH72RLXK.js} +11 -11
- package/dist/bundle/chunks/{node-A6SZ3T7E.js → node-SJPZTR4K.js} +190 -190
- package/dist/bundle/chunks/{node-DZCAT4Q6.js → node-VSA4ZN7D.js} +1 -1
- package/dist/bundle/chunks/openai-chatgpt.js +2 -2
- package/dist/bundle/chunks/{openai-codex-responses-FJFDAWHI.js → openai-codex-responses-L366637C.js} +48 -47
- package/dist/bundle/chunks/openai-codex.js +10 -9
- package/dist/bundle/chunks/openai-completions-ZP62QXJX.js +83 -0
- package/dist/bundle/chunks/{openai-decisions-HESOHYZB.js → openai-decisions-WOWUC65P.js} +1 -1
- package/dist/bundle/chunks/openai-responses-DXUGSUTN.js +26 -0
- package/dist/bundle/chunks/openrouter-images-5K47HDAT.js +8 -0
- package/dist/bundle/chunks/openrouter.js +10 -9
- package/dist/bundle/chunks/{pi-messages-SAOV3JNW.js → pi-messages-MOQQDZBK.js} +5 -4
- package/dist/bundle/chunks/radius.js +9 -8
- package/dist/bundle/chunks/{runtime-HJEUOD4R.js → runtime-K3F2QDQP.js} +1 -1
- package/dist/bundle/chunks/typesafe-system-one-43OCHGKP.js +3 -0
- package/dist/bundle/chunks/{undici-4BK3MVJV.js → undici-EK3EUI2E.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-5D6QIJPN.js +5 -0
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/flow/package.json +4 -4
- package/dist/bundle/index.js +6 -6
- package/dist/bundle/rpc-entry.js +3 -3
- package/dist/cli/args.d.ts +6 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +11 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/coordination/adapter/tool.d.ts.map +1 -1
- package/dist/coordination/adapter/tool.js +3 -1
- package/dist/coordination/adapter/tool.js.map +1 -1
- package/dist/coordination/broker/broker.d.ts +6 -2
- package/dist/coordination/broker/broker.d.ts.map +1 -1
- package/dist/coordination/broker/broker.js +20 -8
- package/dist/coordination/broker/broker.js.map +1 -1
- package/dist/coordination/client/client.d.ts.map +1 -1
- package/dist/coordination/client/client.js +4 -2
- package/dist/coordination/client/client.js.map +1 -1
- package/dist/coordination/transport/discovery.d.ts +10 -3
- package/dist/coordination/transport/discovery.d.ts.map +1 -1
- package/dist/coordination/transport/discovery.js +18 -5
- package/dist/coordination/transport/discovery.js.map +1 -1
- package/dist/core/agent-session.d.ts +35 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +163 -40
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/anthropic-subscription-usage.d.ts +47 -0
- package/dist/core/anthropic-subscription-usage.d.ts.map +1 -0
- package/dist/core/anthropic-subscription-usage.js +170 -0
- package/dist/core/anthropic-subscription-usage.js.map +1 -0
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +7 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/client-identity.d.ts +13 -0
- package/dist/core/client-identity.d.ts.map +1 -0
- package/dist/core/client-identity.js +25 -0
- package/dist/core/client-identity.js.map +1 -0
- package/dist/core/codex-usage.d.ts +37 -1
- package/dist/core/codex-usage.d.ts.map +1 -1
- package/dist/core/codex-usage.js +104 -11
- package/dist/core/codex-usage.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +1 -2
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +2 -2
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +20 -15
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +2 -0
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.html +1 -0
- package/dist/core/export-html/template.js +2 -1
- package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/dist/core/export-html/vendor/marked.min.js +30 -29
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +3 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +14 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +86 -2
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +3 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/model-config.d.ts +920 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +48 -24
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +18 -0
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +20 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +33 -7
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +9 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +123 -14
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/output-guard.d.ts +13 -1
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/output-guard.js +101 -11
- package/dist/core/output-guard.js.map +1 -1
- package/dist/core/provider-composer.d.ts +2 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +7 -3
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +7 -2
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/safe-credential-error.d.ts +11 -0
- package/dist/core/safe-credential-error.d.ts.map +1 -0
- package/dist/core/safe-credential-error.js +14 -0
- package/dist/core/safe-credential-error.js.map +1 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +12 -10
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +4 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +242 -26
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +3 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +6 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/system-prompt.d.ts +6 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +93 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +3 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +37 -12
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +102 -24
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +3 -1
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +3 -2
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/extensions/usage/index.d.ts +15 -0
- package/dist/extensions/usage/index.d.ts.map +1 -0
- package/dist/extensions/usage/index.js +110 -0
- package/dist/extensions/usage/index.js.map +1 -0
- package/dist/extensions/usage/overview.d.ts +90 -0
- package/dist/extensions/usage/overview.d.ts.map +1 -0
- package/dist/extensions/usage/overview.js +215 -0
- package/dist/extensions/usage/overview.js.map +1 -0
- package/dist/extensions/usage/popup.d.ts +21 -0
- package/dist/extensions/usage/popup.d.ts.map +1 -0
- package/dist/extensions/usage/popup.js +98 -0
- package/dist/extensions/usage/popup.js.map +1 -0
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +21 -2
- package/dist/humain/bundled-extension-names.d.ts +6 -0
- package/dist/humain/bundled-extension-names.d.ts.map +1 -0
- package/dist/humain/bundled-extension-names.js +9 -0
- package/dist/humain/bundled-extension-names.js.map +1 -0
- package/dist/humain/gateway/catalog.d.ts +36 -0
- package/dist/humain/gateway/catalog.d.ts.map +1 -0
- package/dist/humain/gateway/catalog.js +74 -0
- package/dist/humain/gateway/catalog.js.map +1 -0
- package/dist/humain/gateway/client.d.ts +58 -0
- package/dist/humain/gateway/client.d.ts.map +1 -0
- package/dist/humain/gateway/client.js +212 -0
- package/dist/humain/gateway/client.js.map +1 -0
- package/dist/humain/gateway/constants.d.ts +23 -0
- package/dist/humain/gateway/constants.d.ts.map +1 -0
- package/dist/humain/gateway/constants.js +32 -0
- package/dist/humain/gateway/constants.js.map +1 -0
- package/dist/humain/gateway/http.d.ts +18 -0
- package/dist/humain/gateway/http.d.ts.map +1 -0
- package/dist/humain/gateway/http.js +274 -0
- package/dist/humain/gateway/http.js.map +1 -0
- package/dist/humain/gateway/login.d.ts +13 -0
- package/dist/humain/gateway/login.d.ts.map +1 -0
- package/dist/humain/gateway/login.js +121 -0
- package/dist/humain/gateway/login.js.map +1 -0
- package/dist/humain/gateway/provider.d.ts +34 -0
- package/dist/humain/gateway/provider.d.ts.map +1 -0
- package/dist/humain/gateway/provider.js +253 -0
- package/dist/humain/gateway/provider.js.map +1 -0
- package/dist/humain/gateway/secret-store.d.ts +19 -0
- package/dist/humain/gateway/secret-store.d.ts.map +1 -0
- package/dist/humain/gateway/secret-store.js +252 -0
- package/dist/humain/gateway/secret-store.js.map +1 -0
- package/dist/humain/gateway/session-store.d.ts +42 -0
- package/dist/humain/gateway/session-store.d.ts.map +1 -0
- package/dist/humain/gateway/session-store.js +175 -0
- package/dist/humain/gateway/session-store.js.map +1 -0
- package/dist/humain/index.d.ts +2 -2
- package/dist/humain/index.d.ts.map +1 -1
- package/dist/humain/index.js +5 -2
- package/dist/humain/index.js.map +1 -1
- package/dist/humain/login-menu.d.ts +14 -0
- package/dist/humain/login-menu.d.ts.map +1 -0
- package/dist/humain/login-menu.js +21 -0
- package/dist/humain/login-menu.js.map +1 -0
- package/dist/humain/node-http.d.ts.map +1 -1
- package/dist/humain/node-http.js +6 -31
- package/dist/humain/node-http.js.map +1 -1
- package/dist/humain/redact-assistant-message.d.ts +4 -0
- package/dist/humain/redact-assistant-message.d.ts.map +1 -0
- package/dist/humain/redact-assistant-message.js +34 -0
- package/dist/humain/redact-assistant-message.js.map +1 -0
- package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/anysearch.js +3 -3
- package/dist/humain/web-access/vendor/anysearch.js.map +1 -1
- package/dist/humain/web-access/vendor/bocha.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/bocha.js +3 -3
- package/dist/humain/web-access/vendor/bocha.js.map +1 -1
- package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/brightdata-unlocker.js +2 -2
- package/dist/humain/web-access/vendor/brightdata-unlocker.js.map +1 -1
- package/dist/humain/web-access/vendor/brightdata.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/brightdata.js +3 -3
- package/dist/humain/web-access/vendor/brightdata.js.map +1 -1
- package/dist/humain/web-access/vendor/ceramic.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ceramic.js +2 -2
- package/dist/humain/web-access/vendor/ceramic.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 +11 -1
- package/dist/humain/web-access/vendor/deepseek.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/deepseek.js +170 -5
- package/dist/humain/web-access/vendor/deepseek.js.map +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +63 -6
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.d.ts +5 -3
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +33 -7
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts +1 -0
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +18 -3
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/jina-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/jina-search.js +6 -4
- package/dist/humain/web-access/vendor/jina-search.js.map +1 -1
- package/dist/humain/web-access/vendor/kagi.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/kagi.js +4 -4
- package/dist/humain/web-access/vendor/kagi.js.map +1 -1
- package/dist/humain/web-access/vendor/keenable.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/keenable.js +2 -2
- package/dist/humain/web-access/vendor/keenable.js.map +1 -1
- package/dist/humain/web-access/vendor/linkup.d.ts +6 -0
- package/dist/humain/web-access/vendor/linkup.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/linkup.js +167 -0
- package/dist/humain/web-access/vendor/linkup.js.map +1 -0
- package/dist/humain/web-access/vendor/mistral-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/mistral-search.js +3 -3
- package/dist/humain/web-access/vendor/mistral-search.js.map +1 -1
- package/dist/humain/web-access/vendor/ollama.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ollama.js +4 -4
- package/dist/humain/web-access/vendor/ollama.js.map +1 -1
- package/dist/humain/web-access/vendor/parallel.js +6 -7
- package/dist/humain/web-access/vendor/parallel.js.map +1 -1
- package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/perplexity.js +4 -3
- package/dist/humain/web-access/vendor/perplexity.js.map +1 -1
- package/dist/humain/web-access/vendor/querit.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/querit.js +3 -3
- package/dist/humain/web-access/vendor/querit.js.map +1 -1
- package/dist/humain/web-access/vendor/search1api.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/search1api.js +3 -3
- package/dist/humain/web-access/vendor/search1api.js.map +1 -1
- package/dist/humain/web-access/vendor/searchinfinity.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/searchinfinity.js +3 -3
- package/dist/humain/web-access/vendor/searchinfinity.js.map +1 -1
- package/dist/humain/web-access/vendor/serpapi.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serpapi.js +6 -5
- package/dist/humain/web-access/vendor/serpapi.js.map +1 -1
- package/dist/humain/web-access/vendor/serpbase.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serpbase.js +4 -4
- package/dist/humain/web-access/vendor/serpbase.js.map +1 -1
- package/dist/humain/web-access/vendor/serpdive.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serpdive.js +3 -3
- package/dist/humain/web-access/vendor/serpdive.js.map +1 -1
- package/dist/humain/web-access/vendor/serper.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serper.js +5 -4
- package/dist/humain/web-access/vendor/serper.js.map +1 -1
- package/dist/humain/web-access/vendor/serply.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/serply.js +2 -2
- package/dist/humain/web-access/vendor/serply.js.map +1 -1
- package/dist/humain/web-access/vendor/utils.d.ts +3 -1
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +27 -2
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/humain/web-access/vendor/valyu.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/valyu.js +3 -3
- package/dist/humain/web-access/vendor/valyu.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 +3 -0
- package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
- package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/xai-search.js +51 -8
- package/dist/humain/web-access/vendor/xai-search.js.map +1 -1
- package/dist/humain/web-access/vendor/xcrawl.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/xcrawl.js +3 -3
- package/dist/humain/web-access/vendor/xcrawl.js.map +1 -1
- package/dist/humain/web-access/vendor/you.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/you.js +2 -2
- package/dist/humain/web-access/vendor/you.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +32 -6
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +14 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +62 -7
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +1 -1
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +2 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +6 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/easter-egg-3d.js +1 -1
- package/dist/modes/interactive/components/easter-egg-3d.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +10 -2
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +141 -66
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +3 -2
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
- package/dist/modes/interactive/components/mermaid.js +16 -3
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +11 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +17 -4
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/radius-login-selector.d.ts +5 -4
- package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/radius-login-selector.js +11 -9
- package/dist/modes/interactive/components/radius-login-selector.js.map +1 -1
- package/dist/modes/interactive/components/themed-text.d.ts.map +1 -1
- package/dist/modes/interactive/components/themed-text.js +3 -2
- package/dist/modes/interactive/components/themed-text.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +17 -6
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +3 -2
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.js +4 -2
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +15 -17
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +143 -158
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +2 -5
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +2 -3
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +2 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +3 -2
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js +3 -0
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +1 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js +3 -2
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +45 -13
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/sleep.d.ts +1 -1
- package/dist/utils/sleep.d.ts.map +1 -1
- package/dist/utils/sleep.js +10 -6
- package/dist/utils/sleep.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +4 -3
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/codemode.md +2 -2
- package/docs/compaction.md +3 -3
- package/docs/coordination.md +1 -1
- package/docs/custom-provider.md +53 -1
- package/docs/docs.json +4 -0
- package/docs/environment-variables.md +2 -0
- package/docs/extensions.md +133 -10
- package/docs/humain-code.md +13 -1
- package/docs/index.md +1 -1
- package/docs/models-configuration.md +197 -0
- package/docs/models.md +24 -6
- package/docs/providers.md +58 -2
- package/docs/quickstart.md +8 -1
- package/docs/settings.md +1 -1
- package/docs/slash-commands.md +10 -0
- package/docs/tui.md +70 -0
- package/docs/windows.md +16 -2
- 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 +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/package.json +2 -2
- package/npm-shrinkwrap.json +243 -219
- package/package.json +21 -20
- package/schemas/models.schema.json +84 -30
- package/schemas/settings.schema.json +19 -0
- package/src/coordination/UPSTREAM.md +36 -3
- package/src/coordination/upstream.json +3 -3
- package/src/humain/web-access/UPSTREAM.md +72 -1
- package/src/humain/web-access/upstream.json +5 -4
- package/dist/bundle/chunks/anthropic-messages-TSNY5MWH.js +0 -67
- package/dist/bundle/chunks/azure-openai-responses-Z4DCXO2G.js +0 -15
- package/dist/bundle/chunks/chunk-26EAEXO5.js +0 -167
- package/dist/bundle/chunks/chunk-2ZFUMXOZ.js +0 -1790
- package/dist/bundle/chunks/chunk-5K5RFXXO.js +0 -74
- package/dist/bundle/chunks/chunk-PY7SOXCA.js +0 -10
- package/dist/bundle/chunks/chunk-UGJAAWNC.js +0 -7
- package/dist/bundle/chunks/chunk-UGXYG7HN.js +0 -22
- package/dist/bundle/chunks/chunk-VEYTRNQC.js +0 -5
- package/dist/bundle/chunks/chunk-X3O5MCKJ.js +0 -7
- package/dist/bundle/chunks/chunk-YLYOJQQX.js +0 -1951
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-MUJQ6LT2.js +0 -4
- package/dist/bundle/chunks/compat-VDGEZSVM.js +0 -13
- package/dist/bundle/chunks/dist-LKDZAEUQ.js +0 -7
- package/dist/bundle/chunks/es-N6YFJOD7.js +0 -1901
- package/dist/bundle/chunks/google-generative-ai-4OVYRP24.js +0 -21
- package/dist/bundle/chunks/google-vertex-3WQAZJQD.js +0 -25
- package/dist/bundle/chunks/host-63SNKK5Y.js +0 -2
- package/dist/bundle/chunks/openai-completions-IC7WRLTI.js +0 -82
- package/dist/bundle/chunks/openai-responses-XXCYDFSM.js +0 -24
- package/dist/bundle/chunks/openrouter-images-DT2HMZNO.js +0 -8
- package/dist/bundle/chunks/typesafe-system-one-HCMGHK6A.js +0 -2
- package/dist/bundle/chunks/virtual-modules-CFJTDIXL.js +0 -5
- package/dist/core/provider-attribution.d.ts +0 -4
- package/dist/core/provider-attribution.d.ts.map +0 -1
- package/dist/core/provider-attribution.js +0 -85
- package/dist/core/provider-attribution.js.map +0 -1
- /package/dist/bundle/chunks/{chunk-WZMA7HAJ.js → chunk-XQRYOCHA.js} +0 -0
|
@@ -145,6 +145,17 @@ function appendAssistantMessageDiagnostic(message, diagnostic) {
|
|
|
145
145
|
message.diagnostics = [...message.diagnostics ?? [], diagnostic];
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
// packages/ai/src/utils/version.ts
|
|
149
|
+
var PI_AI_VERSION = "1.4.0";
|
|
150
|
+
|
|
151
|
+
// packages/ai/src/utils/identity.ts
|
|
152
|
+
function getClientVersion(identity) {
|
|
153
|
+
return identity?.version ?? PI_AI_VERSION;
|
|
154
|
+
}
|
|
155
|
+
function getClientProduct(identity) {
|
|
156
|
+
return identity?.product ?? "pi";
|
|
157
|
+
}
|
|
158
|
+
|
|
148
159
|
// packages/ai/src/utils/text.ts
|
|
149
160
|
function contentText(content, separator = "\n") {
|
|
150
161
|
if (typeof content === "string") return content;
|
|
@@ -1412,13 +1423,14 @@ function buildBaseOptions(model, context, options, apiKey) {
|
|
|
1412
1423
|
samplingParams,
|
|
1413
1424
|
maxTokens: clampMaxTokensToContext(model, context, options?.maxTokens ?? model.maxTokens),
|
|
1414
1425
|
signal: options?.signal,
|
|
1415
|
-
|
|
1426
|
+
telemetry: options?.telemetry,
|
|
1416
1427
|
apiKey: apiKey || options?.apiKey,
|
|
1417
1428
|
fetch: options?.fetch,
|
|
1418
1429
|
transport: options?.transport,
|
|
1419
1430
|
cacheRetention: options?.cacheRetention,
|
|
1420
1431
|
sessionId: options?.sessionId,
|
|
1421
1432
|
headers: options?.headers,
|
|
1433
|
+
identity: options?.identity,
|
|
1422
1434
|
onPayload: options?.onPayload,
|
|
1423
1435
|
onResponse: options?.onResponse,
|
|
1424
1436
|
onRequest: options?.onRequest,
|
|
@@ -1656,7 +1668,8 @@ var stream = (model, context, options = {}) => {
|
|
|
1656
1668
|
const blocks = output.content;
|
|
1657
1669
|
const optionsProfile = options.profile || options.env?.AWS_PROFILE;
|
|
1658
1670
|
const config = {
|
|
1659
|
-
profile: optionsProfile || getProviderEnvValue("AWS_PROFILE", options.env)
|
|
1671
|
+
profile: optionsProfile || getProviderEnvValue("AWS_PROFILE", options.env),
|
|
1672
|
+
customUserAgent: bedrockUserAgent(options.identity)
|
|
1660
1673
|
};
|
|
1661
1674
|
const configuredRegion = getConfiguredBedrockRegion(options);
|
|
1662
1675
|
const hasAmbientConfiguredProfile = Boolean(getProviderEnvValue("AWS_PROFILE"));
|
|
@@ -1891,6 +1904,12 @@ function isReservedHeader(key) {
|
|
|
1891
1904
|
const lower = key.toLowerCase();
|
|
1892
1905
|
return lower.startsWith("x-amz-") || RESERVED_HEADER_EXACT.has(lower);
|
|
1893
1906
|
}
|
|
1907
|
+
function bedrockUserAgent(identity) {
|
|
1908
|
+
const mode = identity?.userAgent ?? "detailed";
|
|
1909
|
+
if (typeof mode === "object") return mode.custom;
|
|
1910
|
+
const product = getClientProduct(identity);
|
|
1911
|
+
return mode === "short" ? [[product]] : [[product, getClientVersion(identity)]];
|
|
1912
|
+
}
|
|
1894
1913
|
function addCustomHeadersMiddleware(client, headers) {
|
|
1895
1914
|
const middleware = (next) => async (args) => {
|
|
1896
1915
|
const request = args.request;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Names of bundled extensions loaded as `<inline:name>`. */
|
|
2
|
+
export declare const HUMAIN_WEB_ACCESS_EXTENSION_NAME = "humain-web-access";
|
|
3
|
+
export declare const HUMAIN_TRACE_CAPTURE_EXTENSION_NAME = "humain-trace-capture";
|
|
4
|
+
/** Extension paths of bundled extensions whose `tool_call` handlers only observe, so early tool execution may pass them. */
|
|
5
|
+
export declare const HUMAIN_OBSERVER_EXTENSION_PATHS: readonly string[];
|
|
6
|
+
//# sourceMappingURL=bundled-extension-names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundled-extension-names.d.ts","sourceRoot":"","sources":["../../src/humain/bundled-extension-names.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,eAAO,MAAM,gCAAgC,sBAAsB,CAAC;AACpE,eAAO,MAAM,mCAAmC,yBAAyB,CAAC;AAE1E,4HAA4H;AAC5H,eAAO,MAAM,+BAA+B,EAAE,SAAS,MAAM,EAG5D,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Names of bundled extensions loaded as `<inline:name>`. */
|
|
2
|
+
export const HUMAIN_WEB_ACCESS_EXTENSION_NAME = "humain-web-access";
|
|
3
|
+
export const HUMAIN_TRACE_CAPTURE_EXTENSION_NAME = "humain-trace-capture";
|
|
4
|
+
/** Extension paths of bundled extensions whose `tool_call` handlers only observe, so early tool execution may pass them. */
|
|
5
|
+
export const HUMAIN_OBSERVER_EXTENSION_PATHS = [
|
|
6
|
+
`<inline:${HUMAIN_WEB_ACCESS_EXTENSION_NAME}>`,
|
|
7
|
+
`<inline:${HUMAIN_TRACE_CAPTURE_EXTENSION_NAME}>`,
|
|
8
|
+
];
|
|
9
|
+
//# sourceMappingURL=bundled-extension-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundled-extension-names.js","sourceRoot":"","sources":["../../src/humain/bundled-extension-names.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAAC;AACpE,MAAM,CAAC,MAAM,mCAAmC,GAAG,sBAAsB,CAAC;AAE1E,4HAA4H;AAC5H,MAAM,CAAC,MAAM,+BAA+B,GAAsB;IACjE,WAAW,gCAAgC,GAAG;IAC9C,WAAW,mCAAmC,GAAG;CACjD,CAAC","sourcesContent":["/** Names of bundled extensions loaded as `<inline:name>`. */\nexport const HUMAIN_WEB_ACCESS_EXTENSION_NAME = \"humain-web-access\";\nexport const HUMAIN_TRACE_CAPTURE_EXTENSION_NAME = \"humain-trace-capture\";\n\n/** Extension paths of bundled extensions whose `tool_call` handlers only observe, so early tool execution may pass them. */\nexport const HUMAIN_OBSERVER_EXTENSION_PATHS: readonly string[] = [\n\t`<inline:${HUMAIN_WEB_ACCESS_EXTENSION_NAME}>`,\n\t`<inline:${HUMAIN_TRACE_CAPTURE_EXTENSION_NAME}>`,\n];\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { GatewayAccess, GatewayModelEntry } from "./client.ts";
|
|
3
|
+
export declare const GATEWAY_SETUP_WARNING = "Your HUMAIN Gateway access is being set up; try again shortly.";
|
|
4
|
+
export declare const DEFAULT_BLOCK_REASON = "Blocked for HUMAIN Code by HUMAIN Gateway.";
|
|
5
|
+
type GatewayCatalogEntry = {
|
|
6
|
+
id: string;
|
|
7
|
+
contextWindow: number;
|
|
8
|
+
maxTokens: number;
|
|
9
|
+
};
|
|
10
|
+
interface GatewayCatalogInput {
|
|
11
|
+
models: GatewayModelEntry[];
|
|
12
|
+
access: GatewayAccess;
|
|
13
|
+
previouslyBlocked: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
interface GatewayCatalog {
|
|
16
|
+
eligible: GatewayCatalogEntry[];
|
|
17
|
+
blocked: Record<string, string>;
|
|
18
|
+
warnings: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare function deriveGatewayCatalog(input: GatewayCatalogInput): GatewayCatalog;
|
|
21
|
+
export declare function chooseGatewayFallback(eligible: readonly {
|
|
22
|
+
id: string;
|
|
23
|
+
}[]): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Replacement for a saved Gateway default that is no longer available: the Gateway fallback among
|
|
26
|
+
* `models` (other providers ignored), or no model when no Gateway model is available.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveSavedGatewayDefault(models: readonly Model<Api>[], saved: {
|
|
29
|
+
provider: string;
|
|
30
|
+
id: string;
|
|
31
|
+
}): {
|
|
32
|
+
model?: Model<Api>;
|
|
33
|
+
message: string;
|
|
34
|
+
};
|
|
35
|
+
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AC,GAAG,CAAC,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAczC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { GATEWAY_DEFAULT_LIMITS, GATEWAY_DEFAULT_MODEL, GATEWAY_KNOWN_LIMITS, HUMAIN_GATEWAY_PROVIDER, } from "./constants.js";
|
|
2
|
+
const HUMAIN_CODE_HARNESS_LABEL = "code";
|
|
3
|
+
export const GATEWAY_SETUP_WARNING = "Your HUMAIN Gateway access is being set up; try again shortly.";
|
|
4
|
+
export const DEFAULT_BLOCK_REASON = "Blocked for HUMAIN Code by HUMAIN Gateway.";
|
|
5
|
+
function byId(a, b) {
|
|
6
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
7
|
+
}
|
|
8
|
+
export function deriveGatewayCatalog(input) {
|
|
9
|
+
const { models, access, previouslyBlocked } = input;
|
|
10
|
+
const warnings = [];
|
|
11
|
+
if (access.accessKind === "unknown" || access.degraded !== null)
|
|
12
|
+
warnings.push(GATEWAY_SETUP_WARNING);
|
|
13
|
+
const labels = access.harnessLabels;
|
|
14
|
+
const code = labels !== null && Object.hasOwn(labels, HUMAIN_CODE_HARNESS_LABEL)
|
|
15
|
+
? labels[HUMAIN_CODE_HARNESS_LABEL]
|
|
16
|
+
: undefined;
|
|
17
|
+
let blocked = { ...previouslyBlocked };
|
|
18
|
+
if (code !== undefined) {
|
|
19
|
+
blocked = {};
|
|
20
|
+
for (const [model, row] of Object.entries(code)) {
|
|
21
|
+
if (row.label === "blocked")
|
|
22
|
+
blocked[model] = row.reason ?? DEFAULT_BLOCK_REASON;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const allowed = access.accessKind === "scoped" ? new Set(access.models) : undefined;
|
|
26
|
+
const eligible = [];
|
|
27
|
+
const seen = new Set();
|
|
28
|
+
for (const model of models) {
|
|
29
|
+
if (seen.has(model.id))
|
|
30
|
+
continue;
|
|
31
|
+
seen.add(model.id);
|
|
32
|
+
if (access.accessKind === "none")
|
|
33
|
+
continue;
|
|
34
|
+
if (allowed && !allowed.has(model.id))
|
|
35
|
+
continue;
|
|
36
|
+
const mode = Object.hasOwn(access.modelModes, model.id) ? access.modelModes[model.id] : undefined;
|
|
37
|
+
if (mode !== undefined && mode !== "chat")
|
|
38
|
+
continue;
|
|
39
|
+
if (Object.hasOwn(blocked, model.id))
|
|
40
|
+
continue;
|
|
41
|
+
const known = Object.hasOwn(GATEWAY_KNOWN_LIMITS, model.id) ? GATEWAY_KNOWN_LIMITS[model.id] : undefined;
|
|
42
|
+
eligible.push({
|
|
43
|
+
id: model.id,
|
|
44
|
+
contextWindow: model.maxInputTokens ?? known?.input ?? GATEWAY_DEFAULT_LIMITS.input,
|
|
45
|
+
maxTokens: model.maxOutputTokens ?? known?.output ?? GATEWAY_DEFAULT_LIMITS.output,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
eligible.sort(byId);
|
|
49
|
+
return { eligible, blocked, warnings };
|
|
50
|
+
}
|
|
51
|
+
export function chooseGatewayFallback(eligible) {
|
|
52
|
+
if (eligible.some((m) => m.id === GATEWAY_DEFAULT_MODEL))
|
|
53
|
+
return GATEWAY_DEFAULT_MODEL;
|
|
54
|
+
return [...eligible].sort(byId)[0]?.id;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Replacement for a saved Gateway default that is no longer available: the Gateway fallback among
|
|
58
|
+
* `models` (other providers ignored), or no model when no Gateway model is available.
|
|
59
|
+
*/
|
|
60
|
+
export function resolveSavedGatewayDefault(models, saved) {
|
|
61
|
+
const gatewayModels = models.filter((m) => m.provider === HUMAIN_GATEWAY_PROVIDER);
|
|
62
|
+
const fallbackId = chooseGatewayFallback(gatewayModels);
|
|
63
|
+
const model = gatewayModels.find((m) => m.id === fallbackId);
|
|
64
|
+
if (!model) {
|
|
65
|
+
return {
|
|
66
|
+
message: "Your saved HUMAIN Gateway model is unavailable and no HUMAIN Gateway models are available right now. Run /model to choose a model.",
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
model,
|
|
71
|
+
message: `Could not restore model ${saved.provider}/${saved.id} (model no longer exists). Using ${model.provider}/${model.id}.`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../src/humain/gateway/catalog.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,GACvB,MAAM,gBAAgB,CAAC;AAExB,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,gEAAgE,CAAC;AACtG,MAAM,CAAC,MAAM,oBAAoB,GAAG,4CAA4C,CAAC;AAgBjF,SAAS,IAAI,CAAC,CAAiB,EAAE,CAAiB;IACjD,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAA0B;IAC9D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,KAAK,CAAC;IACpD,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI;QAAE,QAAQ,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IAEtG,MAAM,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;IACpC,MAAM,IAAI,GACT,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC;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AAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC;IAC7D,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO;YACN,OAAO,EACN,oIAAoI;SACrI,CAAC;IACH,CAAC;IACD,OAAO;QACN,KAAK;QACL,OAAO,EAAE,2BAA2B,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,EAAE,oCAAoC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,EAAE,GAAG;KAC/H,CAAC;AACH,CAAC","sourcesContent":["import type { Api, Model } from \"@earendil-works/pi-ai\";\nimport type { GatewayAccess, GatewayModelEntry } from \"./client.ts\";\nimport {\n\tGATEWAY_DEFAULT_LIMITS,\n\tGATEWAY_DEFAULT_MODEL,\n\tGATEWAY_KNOWN_LIMITS,\n\tHUMAIN_GATEWAY_PROVIDER,\n} from \"./constants.ts\";\n\nconst HUMAIN_CODE_HARNESS_LABEL = \"code\";\n\nexport const GATEWAY_SETUP_WARNING = \"Your HUMAIN Gateway access is being set up; try again shortly.\";\nexport const DEFAULT_BLOCK_REASON = \"Blocked for HUMAIN Code by HUMAIN Gateway.\";\n\ntype GatewayCatalogEntry = { id: string; contextWindow: number; maxTokens: number };\n\ninterface GatewayCatalogInput {\n\tmodels: GatewayModelEntry[];\n\taccess: GatewayAccess;\n\tpreviouslyBlocked: Record<string, string>;\n}\n\ninterface GatewayCatalog {\n\teligible: GatewayCatalogEntry[];\n\tblocked: Record<string, string>;\n\twarnings: string[];\n}\n\nfunction byId(a: { id: string }, b: { id: string }): number {\n\treturn a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n}\n\nexport function deriveGatewayCatalog(input: GatewayCatalogInput): GatewayCatalog {\n\tconst { models, access, previouslyBlocked } = input;\n\tconst warnings: string[] = [];\n\tif (access.accessKind === \"unknown\" || access.degraded !== null) warnings.push(GATEWAY_SETUP_WARNING);\n\n\tconst labels = access.harnessLabels;\n\tconst code =\n\t\tlabels !== null && Object.hasOwn(labels, HUMAIN_CODE_HARNESS_LABEL)\n\t\t\t? labels[HUMAIN_CODE_HARNESS_LABEL]\n\t\t\t: undefined;\n\tlet blocked: Record<string, string> = { ...previouslyBlocked };\n\tif (code !== undefined) {\n\t\tblocked = {};\n\t\tfor (const [model, row] of Object.entries(code)) {\n\t\t\tif (row.label === \"blocked\") blocked[model] = row.reason ?? DEFAULT_BLOCK_REASON;\n\t\t}\n\t}\n\n\tconst allowed = access.accessKind === \"scoped\" ? new Set(access.models) : undefined;\n\tconst eligible: GatewayCatalogEntry[] = [];\n\tconst seen = new Set<string>();\n\tfor (const model of models) {\n\t\tif (seen.has(model.id)) continue;\n\t\tseen.add(model.id);\n\t\tif (access.accessKind === \"none\") continue;\n\t\tif (allowed && !allowed.has(model.id)) continue;\n\t\tconst mode = Object.hasOwn(access.modelModes, model.id) ? access.modelModes[model.id] : undefined;\n\t\tif (mode !== undefined && mode !== \"chat\") continue;\n\t\tif (Object.hasOwn(blocked, model.id)) continue;\n\t\tconst known = Object.hasOwn(GATEWAY_KNOWN_LIMITS, model.id) ? GATEWAY_KNOWN_LIMITS[model.id] : undefined;\n\t\teligible.push({\n\t\t\tid: model.id,\n\t\t\tcontextWindow: model.maxInputTokens ?? known?.input ?? GATEWAY_DEFAULT_LIMITS.input,\n\t\t\tmaxTokens: model.maxOutputTokens ?? known?.output ?? GATEWAY_DEFAULT_LIMITS.output,\n\t\t});\n\t}\n\teligible.sort(byId);\n\treturn { eligible, blocked, warnings };\n}\n\nexport function chooseGatewayFallback(eligible: readonly { id: string }[]): string | undefined {\n\tif (eligible.some((m) => m.id === GATEWAY_DEFAULT_MODEL)) return GATEWAY_DEFAULT_MODEL;\n\treturn [...eligible].sort(byId)[0]?.id;\n}\n\n/**\n * Replacement for a saved Gateway default that is no longer available: the Gateway fallback among\n * `models` (other providers ignored), or no model when no Gateway model is available.\n */\nexport function resolveSavedGatewayDefault(\n\tmodels: readonly Model<Api>[],\n\tsaved: { provider: string; id: string },\n): { model?: Model<Api>; message: string } {\n\tconst gatewayModels = models.filter((m) => m.provider === HUMAIN_GATEWAY_PROVIDER);\n\tconst fallbackId = chooseGatewayFallback(gatewayModels);\n\tconst model = gatewayModels.find((m) => m.id === fallbackId);\n\tif (!model) {\n\t\treturn {\n\t\t\tmessage:\n\t\t\t\t\"Your saved HUMAIN Gateway model is unavailable and no HUMAIN Gateway models are available right now. Run /model to choose a model.\",\n\t\t};\n\t}\n\treturn {\n\t\tmodel,\n\t\tmessage: `Could not restore model ${saved.provider}/${saved.id} (model no longer exists). Using ${model.provider}/${model.id}.`,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SafeCredentialError } from "../../core/safe-credential-error.ts";
|
|
2
|
+
interface GatewayIdentity {
|
|
3
|
+
email: string;
|
|
4
|
+
userId: string;
|
|
5
|
+
}
|
|
6
|
+
export type GatewayModelEntry = {
|
|
7
|
+
id: string;
|
|
8
|
+
maxInputTokens?: number;
|
|
9
|
+
maxOutputTokens?: number;
|
|
10
|
+
};
|
|
11
|
+
type GatewayAccessKind = "unrestricted" | "scoped" | "none" | "unknown";
|
|
12
|
+
export interface GatewayAccess {
|
|
13
|
+
accessKind: GatewayAccessKind;
|
|
14
|
+
models: string[];
|
|
15
|
+
modelModes: Record<string, string>;
|
|
16
|
+
harnessLabels: Record<string, Record<string, {
|
|
17
|
+
label: string;
|
|
18
|
+
reason: string | null;
|
|
19
|
+
}>> | null;
|
|
20
|
+
degraded: {
|
|
21
|
+
reason: string;
|
|
22
|
+
} | null;
|
|
23
|
+
}
|
|
24
|
+
interface GatewayRequestOptions {
|
|
25
|
+
fetch?: typeof fetch;
|
|
26
|
+
signal: AbortSignal;
|
|
27
|
+
}
|
|
28
|
+
type GatewayLoginErrorKind = "invalid-request" | "invalid-code" | "update-required" | "malformed-response";
|
|
29
|
+
export declare class GatewayLoginError extends SafeCredentialError {
|
|
30
|
+
constructor(kind: GatewayLoginErrorKind, message?: string);
|
|
31
|
+
}
|
|
32
|
+
export declare class GatewayBudgetExhaustedError extends Error {
|
|
33
|
+
constructor(message: string);
|
|
34
|
+
}
|
|
35
|
+
export declare class GatewaySessionUnavailableError extends SafeCredentialError {
|
|
36
|
+
constructor();
|
|
37
|
+
}
|
|
38
|
+
export declare class GatewayMalformedResponseError extends SafeCredentialError {
|
|
39
|
+
constructor();
|
|
40
|
+
}
|
|
41
|
+
export declare class GatewayRequestError extends SafeCredentialError {
|
|
42
|
+
readonly status: number;
|
|
43
|
+
constructor(status: number);
|
|
44
|
+
}
|
|
45
|
+
type UnknownRecord = Record<string, unknown>;
|
|
46
|
+
export declare function isObject(value: unknown): value is UnknownRecord;
|
|
47
|
+
export declare function exchangeHandoffCode(base: string, input: {
|
|
48
|
+
code: string;
|
|
49
|
+
state: string;
|
|
50
|
+
}, options: GatewayRequestOptions): Promise<{
|
|
51
|
+
token: string;
|
|
52
|
+
identity: GatewayIdentity;
|
|
53
|
+
}>;
|
|
54
|
+
export declare function revokeSession(base: string, token: string, options: GatewayRequestOptions): Promise<"revoked" | "unknown" | "unavailable">;
|
|
55
|
+
export declare function fetchGatewayModels(base: string, token: string, options: GatewayRequestOptions): Promise<GatewayModelEntry[]>;
|
|
56
|
+
export declare function fetchGatewayAccess(base: string, token: string, options: GatewayRequestOptions): Promise<GatewayAccess>;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/humain/gateway/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAG1E,UAAU,eAAe;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,E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KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAE/D;AAwBD,wBAAsB,mBAAmB,CACxC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EACtC,OAAO,EAAE,qBAAqB,GAC5B,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,eAAe,CAAA;CAAE,CAAC,CA0CvD;AAED,wBAAsB,aAAa,CAClC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,qBAAqB,GAC5B,OAAO,CAAC,SAAS,GAAG,SAAS,GAAG,aAAa,CAAC,CAehD;AAsBD,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,qBAAqB,GAC5B,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAc9B;AAoBD,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,qBAAqB,GAC5B,OAAO,CAAC,aAAa,CAAC,CAqBxB"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { SafeCredentialError } from "../../core/safe-credential-error.js";
|
|
2
|
+
import { GATEWAY_TOKEN_PATTERN, GATEWAY_USER_AGENT } from "./constants.js";
|
|
3
|
+
const LOGIN_MESSAGES = {
|
|
4
|
+
"invalid-request": "HUMAIN Gateway rejected the sign-in exchange request.",
|
|
5
|
+
"invalid-code": "HUMAIN Gateway sign-in code is invalid or expired. Sign in again.",
|
|
6
|
+
"update-required": "HUMAIN Gateway requires a newer HUMAIN Code CLI. Update and sign in again.",
|
|
7
|
+
"malformed-response": "HUMAIN Gateway returned an unexpected sign-in response.",
|
|
8
|
+
};
|
|
9
|
+
export class GatewayLoginError extends SafeCredentialError {
|
|
10
|
+
constructor(kind, message = LOGIN_MESSAGES[kind]) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "GatewayLoginError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class GatewayBudgetExhaustedError extends Error {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "GatewayBudgetExhaustedError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class GatewaySessionUnavailableError extends SafeCredentialError {
|
|
22
|
+
constructor() {
|
|
23
|
+
super("HUMAIN Gateway CLI session unavailable. Sign in again.");
|
|
24
|
+
this.name = "GatewaySessionUnavailableError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class GatewayMalformedResponseError extends SafeCredentialError {
|
|
28
|
+
constructor() {
|
|
29
|
+
super("HUMAIN Gateway returned an unexpected response.");
|
|
30
|
+
this.name = "GatewayMalformedResponseError";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class GatewayRequestError extends SafeCredentialError {
|
|
34
|
+
status;
|
|
35
|
+
constructor(status) {
|
|
36
|
+
super(`HUMAIN Gateway request failed with status ${status}.`);
|
|
37
|
+
this.name = "GatewayRequestError";
|
|
38
|
+
this.status = status;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function isObject(value) {
|
|
42
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43
|
+
}
|
|
44
|
+
function str(value) {
|
|
45
|
+
return typeof value === "string" ? value : undefined;
|
|
46
|
+
}
|
|
47
|
+
function positiveInt(value) {
|
|
48
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : undefined;
|
|
49
|
+
}
|
|
50
|
+
async function readJson(response) {
|
|
51
|
+
try {
|
|
52
|
+
return await response.json();
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function baseHeaders(token) {
|
|
59
|
+
const headers = { "User-Agent": GATEWAY_USER_AGENT };
|
|
60
|
+
if (token !== undefined)
|
|
61
|
+
headers.Authorization = `Bearer ${token}`;
|
|
62
|
+
return headers;
|
|
63
|
+
}
|
|
64
|
+
export async function exchangeHandoffCode(base, input, options) {
|
|
65
|
+
const doFetch = options.fetch ?? fetch;
|
|
66
|
+
const payload = JSON.stringify({
|
|
67
|
+
code: input.code,
|
|
68
|
+
state: input.state,
|
|
69
|
+
client: "cli",
|
|
70
|
+
cli_capability: "cli-session-v1",
|
|
71
|
+
});
|
|
72
|
+
// Gateway caps the exchange body at 4 KB; sending more would spend the one-time code on a rejected request.
|
|
73
|
+
if (Buffer.byteLength(payload) > 4096) {
|
|
74
|
+
throw new GatewayLoginError("invalid-request", "The pasted HUMAIN Gateway code is too long.");
|
|
75
|
+
}
|
|
76
|
+
let response;
|
|
77
|
+
try {
|
|
78
|
+
response = await doFetch(`${base}/handoff/exchange`, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
redirect: "error",
|
|
81
|
+
signal: options.signal,
|
|
82
|
+
headers: { ...baseHeaders(), "Content-Type": "application/json" },
|
|
83
|
+
body: payload,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (options.signal?.aborted)
|
|
88
|
+
throw error;
|
|
89
|
+
throw new SafeCredentialError("Could not reach HUMAIN Gateway to finish sign-in. Check your network and sign in again.");
|
|
90
|
+
}
|
|
91
|
+
if (response.status === 426)
|
|
92
|
+
throw new GatewayLoginError("update-required");
|
|
93
|
+
if (response.status === 400) {
|
|
94
|
+
const text = (await response.text().catch(() => "")).trim();
|
|
95
|
+
throw new GatewayLoginError(text === "invalid exchange request" ? "invalid-request" : "invalid-code");
|
|
96
|
+
}
|
|
97
|
+
if (!response.ok)
|
|
98
|
+
throw new GatewayRequestError(response.status);
|
|
99
|
+
const body = await readJson(response);
|
|
100
|
+
if (!isObject(body))
|
|
101
|
+
throw new GatewayLoginError("malformed-response");
|
|
102
|
+
const token = str(body.key);
|
|
103
|
+
const email = str(body.user_email) || str(body.email);
|
|
104
|
+
// Gateway may return an empty user_id; the email then identifies the account.
|
|
105
|
+
const userId = str(body.user_id) || email;
|
|
106
|
+
if (token === undefined || !GATEWAY_TOKEN_PATTERN.test(token))
|
|
107
|
+
throw new GatewayLoginError("malformed-response");
|
|
108
|
+
if (!userId || !email)
|
|
109
|
+
throw new GatewayLoginError("malformed-response");
|
|
110
|
+
return { token, identity: { email, userId } };
|
|
111
|
+
}
|
|
112
|
+
export async function revokeSession(base, token, options) {
|
|
113
|
+
const doFetch = options.fetch ?? fetch;
|
|
114
|
+
try {
|
|
115
|
+
const response = await doFetch(`${base}/api/cli/me/session`, {
|
|
116
|
+
method: "DELETE",
|
|
117
|
+
redirect: "error",
|
|
118
|
+
signal: options.signal,
|
|
119
|
+
headers: baseHeaders(token),
|
|
120
|
+
});
|
|
121
|
+
if (response.status === 204)
|
|
122
|
+
return "revoked";
|
|
123
|
+
if (response.status === 401)
|
|
124
|
+
return "unknown";
|
|
125
|
+
return "unavailable";
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return "unavailable";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function authedGet(base, path, token, options) {
|
|
132
|
+
const doFetch = options.fetch ?? fetch;
|
|
133
|
+
const response = await doFetch(`${base}${path}`, {
|
|
134
|
+
method: "GET",
|
|
135
|
+
redirect: "error",
|
|
136
|
+
signal: options.signal,
|
|
137
|
+
headers: baseHeaders(token),
|
|
138
|
+
});
|
|
139
|
+
if (response.status === 401)
|
|
140
|
+
throw new GatewaySessionUnavailableError();
|
|
141
|
+
if (response.status === 429) {
|
|
142
|
+
const body = await readJson(response);
|
|
143
|
+
const error = isObject(body) && isObject(body.error) ? body.error : undefined;
|
|
144
|
+
if (error?.type === "budget_exceeded" || error?.code === "gateway_budget_exhausted") {
|
|
145
|
+
throw new GatewayBudgetExhaustedError(str(error?.message) ?? "HUMAIN Gateway budget exhausted.");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!response.ok)
|
|
149
|
+
throw new GatewayRequestError(response.status);
|
|
150
|
+
return readJson(response);
|
|
151
|
+
}
|
|
152
|
+
export async function fetchGatewayModels(base, token, options) {
|
|
153
|
+
const body = await authedGet(base, "/v1/models", token, options);
|
|
154
|
+
if (!isObject(body) || !Array.isArray(body.data))
|
|
155
|
+
throw new GatewayMalformedResponseError();
|
|
156
|
+
const models = [];
|
|
157
|
+
for (const entry of body.data) {
|
|
158
|
+
if (!isObject(entry) || typeof entry.id !== "string" || entry.id === "")
|
|
159
|
+
continue;
|
|
160
|
+
const model = { id: entry.id };
|
|
161
|
+
const maxInputTokens = positiveInt(entry.max_input_tokens);
|
|
162
|
+
const maxOutputTokens = positiveInt(entry.max_output_tokens);
|
|
163
|
+
if (maxInputTokens !== undefined)
|
|
164
|
+
model.maxInputTokens = maxInputTokens;
|
|
165
|
+
if (maxOutputTokens !== undefined)
|
|
166
|
+
model.maxOutputTokens = maxOutputTokens;
|
|
167
|
+
models.push(model);
|
|
168
|
+
}
|
|
169
|
+
return models;
|
|
170
|
+
}
|
|
171
|
+
const ACCESS_KINDS = ["unrestricted", "scoped", "none"];
|
|
172
|
+
function parseHarnessLabels(value) {
|
|
173
|
+
if (!isObject(value))
|
|
174
|
+
return null;
|
|
175
|
+
const result = {};
|
|
176
|
+
for (const [harness, models] of Object.entries(value)) {
|
|
177
|
+
if (!isObject(models))
|
|
178
|
+
continue;
|
|
179
|
+
const inner = {};
|
|
180
|
+
for (const [model, info] of Object.entries(models)) {
|
|
181
|
+
if (isObject(info) && typeof info.label === "string") {
|
|
182
|
+
inner[model] = { label: info.label, reason: str(info.reason) ?? null };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
result[harness] = inner;
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
export async function fetchGatewayAccess(base, token, options) {
|
|
190
|
+
const body = await authedGet(base, "/api/cli/me/access", token, options);
|
|
191
|
+
if (!isObject(body))
|
|
192
|
+
throw new GatewayMalformedResponseError();
|
|
193
|
+
const modelModes = {};
|
|
194
|
+
if (isObject(body.model_modes)) {
|
|
195
|
+
for (const [model, mode] of Object.entries(body.model_modes)) {
|
|
196
|
+
if (typeof mode === "string")
|
|
197
|
+
modelModes[model] = mode;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const degraded = body.degraded === null || body.degraded === undefined || body.degraded === false
|
|
201
|
+
? null
|
|
202
|
+
: { reason: isObject(body.degraded) ? (str(body.degraded.reason) ?? "unknown") : "unknown" };
|
|
203
|
+
const kind = str(body.access_kind);
|
|
204
|
+
return {
|
|
205
|
+
accessKind: kind !== undefined && ACCESS_KINDS.includes(kind) ? kind : "unknown",
|
|
206
|
+
models: Array.isArray(body.models) ? body.models.filter((m) => typeof m === "string") : [],
|
|
207
|
+
modelModes,
|
|
208
|
+
harnessLabels: parseHarnessLabels(body.harness_labels),
|
|
209
|
+
degraded,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/humain/gateway/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AA2B3E,MAAM,cAAc,GAA0C;IAC7D,iBAAiB,EAAE,uDAAuD;IAC1E,cAAc,EAAE,mEAAmE;IACnF,iBAAiB,EAAE,4EAA4E;IAC/F,oBAAoB,EAAE,yDAAyD;CAC/E,CAAC;AAEF,MAAM,OAAO,iBAAkB,SAAQ,mBAAmB;IACzD,YAAY,IAA2B,EAAE,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC;QACtE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IACjC,CAAC;CACD;AAED,MAAM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CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE;QACvG,UAAU;QACV,aAAa,EAAE,kBAAkB,CAAC,IAAI,CAAC,cAAc,CAAC;QACtD,QAAQ;KACR,CAAC;AACH,CAAC","sourcesContent":["import { SafeCredentialError } from \"../../core/safe-credential-error.ts\";\nimport { GATEWAY_TOKEN_PATTERN, GATEWAY_USER_AGENT } from \"./constants.ts\";\n\ninterface GatewayIdentity {\n\temail: string;\n\tuserId: string;\n}\n\nexport type GatewayModelEntry = { id: string; maxInputTokens?: number; maxOutputTokens?: number };\n\ntype GatewayAccessKind = \"unrestricted\" | \"scoped\" | \"none\" | \"unknown\";\n\nexport interface GatewayAccess {\n\taccessKind: GatewayAccessKind;\n\tmodels: string[];\n\tmodelModes: Record<string, string>;\n\t// harness -> model id -> label (wire: harness_labels.code.<model id>)\n\tharnessLabels: Record<string, Record<string, { label: string; reason: string | null }>> | null;\n\tdegraded: { reason: string } | null;\n}\n\ninterface GatewayRequestOptions {\n\tfetch?: typeof fetch;\n\tsignal: AbortSignal;\n}\n\ntype GatewayLoginErrorKind = \"invalid-request\" | \"invalid-code\" | \"update-required\" | \"malformed-response\";\n\nconst LOGIN_MESSAGES: Record<GatewayLoginErrorKind, string> = {\n\t\"invalid-request\": \"HUMAIN Gateway rejected the sign-in exchange request.\",\n\t\"invalid-code\": \"HUMAIN Gateway sign-in code is invalid or expired. Sign in again.\",\n\t\"update-required\": \"HUMAIN Gateway requires a newer HUMAIN Code CLI. Update and sign in again.\",\n\t\"malformed-response\": \"HUMAIN Gateway returned an unexpected sign-in response.\",\n};\n\nexport class GatewayLoginError extends SafeCredentialError {\n\tconstructor(kind: GatewayLoginErrorKind, message = LOGIN_MESSAGES[kind]) {\n\t\tsuper(message);\n\t\tthis.name = \"GatewayLoginError\";\n\t}\n}\n\nexport class GatewayBudgetExhaustedError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"GatewayBudgetExhaustedError\";\n\t}\n}\n\nexport class GatewaySessionUnavailableError extends SafeCredentialError {\n\tconstructor() {\n\t\tsuper(\"HUMAIN Gateway CLI session unavailable. Sign in again.\");\n\t\tthis.name = \"GatewaySessionUnavailableError\";\n\t}\n}\n\nexport class GatewayMalformedResponseError extends SafeCredentialError {\n\tconstructor() {\n\t\tsuper(\"HUMAIN Gateway returned an unexpected response.\");\n\t\tthis.name = \"GatewayMalformedResponseError\";\n\t}\n}\n\nexport class GatewayRequestError extends SafeCredentialError {\n\treadonly status: number;\n\tconstructor(status: number) {\n\t\tsuper(`HUMAIN Gateway request failed with status ${status}.`);\n\t\tthis.name = \"GatewayRequestError\";\n\t\tthis.status = status;\n\t}\n}\n\ntype UnknownRecord = Record<string, unknown>;\n\nexport function isObject(value: unknown): value is UnknownRecord {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction str(value: unknown): string | undefined {\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction positiveInt(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value > 0 ? value : undefined;\n}\n\nasync function readJson(response: Response): Promise<unknown> {\n\ttry {\n\t\treturn await response.json();\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction baseHeaders(token?: string): Record<string, string> {\n\tconst headers: Record<string, string> = { \"User-Agent\": GATEWAY_USER_AGENT };\n\tif (token !== undefined) headers.Authorization = `Bearer ${token}`;\n\treturn headers;\n}\n\nexport async function exchangeHandoffCode(\n\tbase: string,\n\tinput: { code: string; state: string },\n\toptions: GatewayRequestOptions,\n): Promise<{ token: string; identity: GatewayIdentity }> {\n\tconst doFetch = options.fetch ?? fetch;\n\tconst payload = JSON.stringify({\n\t\tcode: input.code,\n\t\tstate: input.state,\n\t\tclient: \"cli\",\n\t\tcli_capability: \"cli-session-v1\",\n\t});\n\t// Gateway caps the exchange body at 4 KB; sending more would spend the one-time code on a rejected request.\n\tif (Buffer.byteLength(payload) > 4096) {\n\t\tthrow new GatewayLoginError(\"invalid-request\", \"The pasted HUMAIN Gateway code is too long.\");\n\t}\n\tlet response: Response;\n\ttry {\n\t\tresponse = await doFetch(`${base}/handoff/exchange`, {\n\t\t\tmethod: \"POST\",\n\t\t\tredirect: \"error\",\n\t\t\tsignal: options.signal,\n\t\t\theaders: { ...baseHeaders(), \"Content-Type\": \"application/json\" },\n\t\t\tbody: payload,\n\t\t});\n\t} catch (error) {\n\t\tif (options.signal?.aborted) throw error;\n\t\tthrow new SafeCredentialError(\n\t\t\t\"Could not reach HUMAIN Gateway to finish sign-in. Check your network and sign in again.\",\n\t\t);\n\t}\n\tif (response.status === 426) throw new GatewayLoginError(\"update-required\");\n\tif (response.status === 400) {\n\t\tconst text = (await response.text().catch(() => \"\")).trim();\n\t\tthrow new GatewayLoginError(text === \"invalid exchange request\" ? \"invalid-request\" : \"invalid-code\");\n\t}\n\tif (!response.ok) throw new GatewayRequestError(response.status);\n\tconst body = await readJson(response);\n\tif (!isObject(body)) throw new GatewayLoginError(\"malformed-response\");\n\tconst token = str(body.key);\n\tconst email = str(body.user_email) || str(body.email);\n\t// Gateway may return an empty user_id; the email then identifies the account.\n\tconst userId = str(body.user_id) || email;\n\tif (token === undefined || !GATEWAY_TOKEN_PATTERN.test(token)) throw new GatewayLoginError(\"malformed-response\");\n\tif (!userId || !email) throw new GatewayLoginError(\"malformed-response\");\n\treturn { token, identity: { email, userId } };\n}\n\nexport async function revokeSession(\n\tbase: string,\n\ttoken: string,\n\toptions: GatewayRequestOptions,\n): Promise<\"revoked\" | \"unknown\" | \"unavailable\"> {\n\tconst doFetch = options.fetch ?? fetch;\n\ttry {\n\t\tconst response = await doFetch(`${base}/api/cli/me/session`, {\n\t\t\tmethod: \"DELETE\",\n\t\t\tredirect: \"error\",\n\t\t\tsignal: options.signal,\n\t\t\theaders: baseHeaders(token),\n\t\t});\n\t\tif (response.status === 204) return \"revoked\";\n\t\tif (response.status === 401) return \"unknown\";\n\t\treturn \"unavailable\";\n\t} catch {\n\t\treturn \"unavailable\";\n\t}\n}\n\nasync function authedGet(base: string, path: string, token: string, options: GatewayRequestOptions): Promise<unknown> {\n\tconst doFetch = options.fetch ?? fetch;\n\tconst response = await doFetch(`${base}${path}`, {\n\t\tmethod: \"GET\",\n\t\tredirect: \"error\",\n\t\tsignal: options.signal,\n\t\theaders: baseHeaders(token),\n\t});\n\tif (response.status === 401) throw new GatewaySessionUnavailableError();\n\tif (response.status === 429) {\n\t\tconst body = await readJson(response);\n\t\tconst error = isObject(body) && isObject(body.error) ? body.error : undefined;\n\t\tif (error?.type === \"budget_exceeded\" || error?.code === \"gateway_budget_exhausted\") {\n\t\t\tthrow new GatewayBudgetExhaustedError(str(error?.message) ?? \"HUMAIN Gateway budget exhausted.\");\n\t\t}\n\t}\n\tif (!response.ok) throw new GatewayRequestError(response.status);\n\treturn readJson(response);\n}\n\nexport async function fetchGatewayModels(\n\tbase: string,\n\ttoken: string,\n\toptions: GatewayRequestOptions,\n): Promise<GatewayModelEntry[]> {\n\tconst body = await authedGet(base, \"/v1/models\", token, options);\n\tif (!isObject(body) || !Array.isArray(body.data)) throw new GatewayMalformedResponseError();\n\tconst models: GatewayModelEntry[] = [];\n\tfor (const entry of body.data) {\n\t\tif (!isObject(entry) || typeof entry.id !== \"string\" || entry.id === \"\") continue;\n\t\tconst model: GatewayModelEntry = { id: entry.id };\n\t\tconst maxInputTokens = positiveInt(entry.max_input_tokens);\n\t\tconst maxOutputTokens = positiveInt(entry.max_output_tokens);\n\t\tif (maxInputTokens !== undefined) model.maxInputTokens = maxInputTokens;\n\t\tif (maxOutputTokens !== undefined) model.maxOutputTokens = maxOutputTokens;\n\t\tmodels.push(model);\n\t}\n\treturn models;\n}\n\nconst ACCESS_KINDS: readonly string[] = [\"unrestricted\", \"scoped\", \"none\"];\n\nfunction parseHarnessLabels(value: unknown): GatewayAccess[\"harnessLabels\"] {\n\tif (!isObject(value)) return null;\n\tconst result: NonNullable<GatewayAccess[\"harnessLabels\"]> = {};\n\tfor (const [harness, models] of Object.entries(value)) {\n\t\tif (!isObject(models)) continue;\n\t\tconst inner: Record<string, { label: string; reason: string | null }> = {};\n\t\tfor (const [model, info] of Object.entries(models)) {\n\t\t\tif (isObject(info) && typeof info.label === \"string\") {\n\t\t\t\tinner[model] = { label: info.label, reason: str(info.reason) ?? null };\n\t\t\t}\n\t\t}\n\t\tresult[harness] = inner;\n\t}\n\treturn result;\n}\n\nexport async function fetchGatewayAccess(\n\tbase: string,\n\ttoken: string,\n\toptions: GatewayRequestOptions,\n): Promise<GatewayAccess> {\n\tconst body = await authedGet(base, \"/api/cli/me/access\", token, options);\n\tif (!isObject(body)) throw new GatewayMalformedResponseError();\n\tconst modelModes: Record<string, string> = {};\n\tif (isObject(body.model_modes)) {\n\t\tfor (const [model, mode] of Object.entries(body.model_modes)) {\n\t\t\tif (typeof mode === \"string\") modelModes[model] = mode;\n\t\t}\n\t}\n\tconst degraded =\n\t\tbody.degraded === null || body.degraded === undefined || body.degraded === false\n\t\t\t? null\n\t\t\t: { reason: isObject(body.degraded) ? (str(body.degraded.reason) ?? \"unknown\") : \"unknown\" };\n\tconst kind = str(body.access_kind);\n\treturn {\n\t\taccessKind: kind !== undefined && ACCESS_KINDS.includes(kind) ? (kind as GatewayAccessKind) : \"unknown\",\n\t\tmodels: Array.isArray(body.models) ? body.models.filter((m): m is string => typeof m === \"string\") : [],\n\t\tmodelModes,\n\t\tharnessLabels: parseHarnessLabels(body.harness_labels),\n\t\tdegraded,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const HUMAIN_GATEWAY_PROVIDER = "humain-gateway";
|
|
2
|
+
export type GatewayEnvironment = "staging" | "production";
|
|
3
|
+
export declare const GATEWAY_BASE_URLS: Record<GatewayEnvironment, string>;
|
|
4
|
+
export declare const GATEWAY_KNOWN_LIMITS: Record<string, {
|
|
5
|
+
input: number;
|
|
6
|
+
output: number;
|
|
7
|
+
}>;
|
|
8
|
+
/** Provisional client limits for models not in GATEWAY_KNOWN_LIMITS; not guaranteed server limits. */
|
|
9
|
+
export declare const GATEWAY_DEFAULT_LIMITS: {
|
|
10
|
+
input: number;
|
|
11
|
+
output: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const GATEWAY_DEFAULT_MODEL = "zai-org/GLM-5.3-Flash";
|
|
14
|
+
export declare const GATEWAY_USER_AGENT: string;
|
|
15
|
+
export declare const GATEWAY_TOKEN_PATTERN: RegExp;
|
|
16
|
+
/** Credential metadata keys stored in the (token-free) auth.json `env` map. */
|
|
17
|
+
export declare const GATEWAY_ENV_ENVIRONMENT = "HUMAIN_GATEWAY_ENVIRONMENT";
|
|
18
|
+
export declare const GATEWAY_ENV_SESSION_ID = "HUMAIN_GATEWAY_SESSION_ID";
|
|
19
|
+
export declare const GATEWAY_ENV_EMAIL = "HUMAIN_GATEWAY_EMAIL";
|
|
20
|
+
export declare const GATEWAY_ENV_USER_ID = "HUMAIN_GATEWAY_USER_ID";
|
|
21
|
+
/** `/accounts` label from token-free credential metadata; undefined when the environment is missing. */
|
|
22
|
+
export declare function describeGatewayCredential(env: Record<string, string> | undefined): string | undefined;
|
|
23
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/humain/gateway/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB,mBAAmB,CAAC;AAExD,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,YAAY,CAAC;AAE1D,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,kBAAkB,EAAE,MAAM,CAGhE,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAMlF,CAAC;AAEF,sGAAsG;AACtG,eAAO,MAAM,sBAAsB;IAAK,KAAK;IAAU,MAAM;CAAS,CAAC;AAEvE,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAE7D,eAAO,MAAM,kBAAkB,QAA2B,CAAC;AAE3D,eAAO,MAAM,qBAAqB,QAAwB,CAAC;AAE3D,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,+BAA+B,CAAC;AACpE,eAAO,MAAM,sBAAsB,8BAA8B,CAAC;AAClE,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AACxD,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAE5D,wGAAwG;AACxG,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKrG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { VERSION } from "../../config.js";
|
|
2
|
+
export const HUMAIN_GATEWAY_PROVIDER = "humain-gateway";
|
|
3
|
+
export const GATEWAY_BASE_URLS = {
|
|
4
|
+
staging: "https://gateway.stg.humain.services/ai-gateway",
|
|
5
|
+
production: "https://gateway.humain.services/ai-gateway",
|
|
6
|
+
};
|
|
7
|
+
export const GATEWAY_KNOWN_LIMITS = {
|
|
8
|
+
"moonshotai/Kimi-K3": { input: 1048576, output: 131072 },
|
|
9
|
+
"zai-org/GLM-5.3-Flash": { input: 1048576, output: 131072 },
|
|
10
|
+
"DeepSeek-V4.1-Flash": { input: 1048576, output: 131072 },
|
|
11
|
+
"Qwen3.8-Flash-Next": { input: 262144, output: 32768 },
|
|
12
|
+
"gpt-oss-120b": { input: 131072, output: 32768 },
|
|
13
|
+
};
|
|
14
|
+
/** Provisional client limits for models not in GATEWAY_KNOWN_LIMITS; not guaranteed server limits. */
|
|
15
|
+
export const GATEWAY_DEFAULT_LIMITS = { input: 131072, output: 16384 };
|
|
16
|
+
export const GATEWAY_DEFAULT_MODEL = "zai-org/GLM-5.3-Flash";
|
|
17
|
+
export const GATEWAY_USER_AGENT = `humain-code/${VERSION}`;
|
|
18
|
+
export const GATEWAY_TOKEN_PATTERN = /^hcli-[0-9a-f]{64}$/;
|
|
19
|
+
/** Credential metadata keys stored in the (token-free) auth.json `env` map. */
|
|
20
|
+
export const GATEWAY_ENV_ENVIRONMENT = "HUMAIN_GATEWAY_ENVIRONMENT";
|
|
21
|
+
export const GATEWAY_ENV_SESSION_ID = "HUMAIN_GATEWAY_SESSION_ID";
|
|
22
|
+
export const GATEWAY_ENV_EMAIL = "HUMAIN_GATEWAY_EMAIL";
|
|
23
|
+
export const GATEWAY_ENV_USER_ID = "HUMAIN_GATEWAY_USER_ID";
|
|
24
|
+
/** `/accounts` label from token-free credential metadata; undefined when the environment is missing. */
|
|
25
|
+
export function describeGatewayCredential(env) {
|
|
26
|
+
const environment = env?.[GATEWAY_ENV_ENVIRONMENT];
|
|
27
|
+
if (!environment)
|
|
28
|
+
return undefined;
|
|
29
|
+
const email = env[GATEWAY_ENV_EMAIL];
|
|
30
|
+
return `HUMAIN Gateway session (${email ? `${environment}, ${email}` : environment})`;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/humain/gateway/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,CAAC,MAAM,uBAAuB,GAAG,gBAAgB,CAAC;AAIxD,MAAM,CAAC,MAAM,iBAAiB,GAAuC;IACpE,OAAO,EAAE,gDAAgD;IACzD,UAAU,EAAE,4CAA4C;CACxD,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAsD;IACtF,oBAAoB,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE;IACxD,uBAAuB,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE;IAC3D,qBAAqB,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE;IACzD,oBAAoB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;IACtD,cAAc,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE;CAChD,CAAC;AAEF,sGAAsG;AACtG,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAEvE,MAAM,CAAC,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAE7D,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,OAAO,EAAE,CAAC;AAE3D,MAAM,CAAC,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAE3D,+EAA+E;AAC/E,MAAM,CAAC,MAAM,uBAAuB,GAAG,4BAA4B,CAAC;AACpE,MAAM,CAAC,MAAM,sBAAsB,GAAG,2BAA2B,CAAC;AAClE,MAAM,CAAC,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AACxD,MAAM,CAAC,MAAM,mBAAmB,GAAG,wBAAwB,CAAC;AAE5D,wGAAwG;AACxG,MAAM,UAAU,yBAAyB,CAAC,GAAuC;IAChF,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,uBAAuB,CAAC,CAAC;IACnD,IAAI,CAAC,WAAW;QAAE,OAAO,SAAS,CAAC;IACnC,MAAM,KAAK,GAAG,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACrC,OAAO,2BAA2B,KAAK,CAAC,CAAC,CAAC,GAAG,WAAW,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC;AACvF,CAAC","sourcesContent":["import { VERSION } from \"../../config.ts\";\n\nexport const HUMAIN_GATEWAY_PROVIDER = \"humain-gateway\";\n\nexport type GatewayEnvironment = \"staging\" | \"production\";\n\nexport const GATEWAY_BASE_URLS: Record<GatewayEnvironment, string> = {\n\tstaging: \"https://gateway.stg.humain.services/ai-gateway\",\n\tproduction: \"https://gateway.humain.services/ai-gateway\",\n};\n\nexport const GATEWAY_KNOWN_LIMITS: Record<string, { input: number; output: number }> = {\n\t\"moonshotai/Kimi-K3\": { input: 1048576, output: 131072 },\n\t\"zai-org/GLM-5.3-Flash\": { input: 1048576, output: 131072 },\n\t\"DeepSeek-V4.1-Flash\": { input: 1048576, output: 131072 },\n\t\"Qwen3.8-Flash-Next\": { input: 262144, output: 32768 },\n\t\"gpt-oss-120b\": { input: 131072, output: 32768 },\n};\n\n/** Provisional client limits for models not in GATEWAY_KNOWN_LIMITS; not guaranteed server limits. */\nexport const GATEWAY_DEFAULT_LIMITS = { input: 131072, output: 16384 };\n\nexport const GATEWAY_DEFAULT_MODEL = \"zai-org/GLM-5.3-Flash\";\n\nexport const GATEWAY_USER_AGENT = `humain-code/${VERSION}`;\n\nexport const GATEWAY_TOKEN_PATTERN = /^hcli-[0-9a-f]{64}$/;\n\n/** Credential metadata keys stored in the (token-free) auth.json `env` map. */\nexport const GATEWAY_ENV_ENVIRONMENT = \"HUMAIN_GATEWAY_ENVIRONMENT\";\nexport const GATEWAY_ENV_SESSION_ID = \"HUMAIN_GATEWAY_SESSION_ID\";\nexport const GATEWAY_ENV_EMAIL = \"HUMAIN_GATEWAY_EMAIL\";\nexport const GATEWAY_ENV_USER_ID = \"HUMAIN_GATEWAY_USER_ID\";\n\n/** `/accounts` label from token-free credential metadata; undefined when the environment is missing. */\nexport function describeGatewayCredential(env: Record<string, string> | undefined): string | undefined {\n\tconst environment = env?.[GATEWAY_ENV_ENVIRONMENT];\n\tif (!environment) return undefined;\n\tconst email = env[GATEWAY_ENV_EMAIL];\n\treturn `HUMAIN Gateway session (${email ? `${environment}, ${email}` : environment})`;\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ProviderStreams } from "@earendil-works/pi-ai";
|
|
2
|
+
interface GatewayHttpDeps {
|
|
3
|
+
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
4
|
+
random?: () => number;
|
|
5
|
+
/** Test hook; production always uses the 900-second ceiling. */
|
|
6
|
+
requestCeilingMs?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Decide whether a failed Gateway response is safe to resend. Only responses that prove the
|
|
10
|
+
* request never reached a billed model call qualify; everything else fails to avoid double billing.
|
|
11
|
+
*/
|
|
12
|
+
export declare function classifyGatewayRetry(status: number, body: unknown, headers: Headers, requestedModel: string): {
|
|
13
|
+
retry: boolean;
|
|
14
|
+
delayMs?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function withHumainGatewayHttp(api: ProviderStreams, deps?: GatewayHttpDeps): ProviderStreams;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/humain/gateway/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,KAAK,eAAe,EAGpB,MAAM,uBAAuB,CAAC;AAe/B,UAAU,eAAe;IACxB,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC;IACtB,gEAAgE;IAChE,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AA8BD;;;GAGG;AACH,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,GACpB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAgCtC;AAmBD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,GAAE,eAAoB,GAAG,eAAe,CA6JvG"}
|