@humain/humain-code 0.8.0 → 0.8.2
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 +46 -0
- package/dist/bundle/chunks/{anthropic-messages-UZB5HJE3.js → anthropic-messages-XFCDMGD6.js} +4 -4
- package/dist/bundle/chunks/{azure-openai-responses-J3LCMWPQ.js → azure-openai-responses-F4KQM3NK.js} +3 -3
- package/dist/bundle/chunks/{chunk-7EONJCBE.js → chunk-2JNJJ6SZ.js} +1 -1
- package/dist/bundle/chunks/{chunk-3CGMVKHA.js → chunk-3E37CJCE.js} +1 -1
- package/dist/bundle/chunks/{chunk-SQ7NTRLJ.js → chunk-3PJ7NPWN.js} +20 -17
- package/dist/bundle/chunks/{chunk-WRYGY5XG.js → chunk-4MKATHT2.js} +1 -1
- package/dist/bundle/chunks/{chunk-ATFZAFMS.js → chunk-65FLSKDA.js} +1 -1
- package/dist/bundle/chunks/{chunk-P2Y2H7SD.js → chunk-6JTCRCNF.js} +2 -2
- package/dist/bundle/chunks/{chunk-CET2MXXN.js → chunk-6P6MMQUH.js} +1 -1
- package/dist/bundle/chunks/{chunk-APNPBT7Y.js → chunk-BRSLXHED.js} +1 -1
- package/dist/bundle/chunks/{chunk-KONLZKPL.js → chunk-E4VUW4RI.js} +1 -1
- package/dist/bundle/chunks/{chunk-R3VDXQW2.js → chunk-EFY2QPVP.js} +6 -6
- package/dist/bundle/chunks/{chunk-4EV7CK26.js → chunk-F2H47FRF.js} +1 -1
- package/dist/bundle/chunks/{chunk-KQXXBQ57.js → chunk-G2QMON4O.js} +382 -331
- package/dist/bundle/chunks/{chunk-TYN46EVI.js → chunk-GPLWWO5Q.js} +1 -1
- package/dist/bundle/chunks/{chunk-JV7VHOAY.js → chunk-H2B3WLIM.js} +2 -2
- package/dist/bundle/chunks/chunk-H7UPU2SH.js +2093 -0
- package/dist/bundle/chunks/{chunk-NNWNIBLG.js → chunk-JKX5EGOT.js} +1 -1
- package/dist/bundle/chunks/{chunk-4SFWYKL5.js → chunk-JQBZUFH7.js} +467 -440
- package/dist/bundle/chunks/{chunk-D3KYOSQY.js → chunk-JSHKS7VH.js} +1 -1
- package/dist/bundle/chunks/{chunk-C4DHVDYT.js → chunk-JX6YIPNK.js} +1 -1
- package/dist/bundle/chunks/{chunk-Z5UFSRO4.js → chunk-KI7CHPWC.js} +1 -1
- package/dist/bundle/chunks/{chunk-VKQNYZUA.js → chunk-KRBELWQH.js} +1 -1
- package/dist/bundle/chunks/{chunk-AI7EHDAX.js → chunk-LSRXA7OS.js} +1 -1
- package/dist/bundle/chunks/{chunk-WBSGWISD.js → chunk-M5TVWJ5T.js} +5 -4
- package/dist/bundle/chunks/{chunk-XVIQYONJ.js → chunk-MIAXMK5F.js} +1 -1
- package/dist/bundle/chunks/{chunk-WGXMYMPE.js → chunk-PFBAIRCY.js} +2 -2
- package/dist/bundle/chunks/{chunk-CU6KU7JK.js → chunk-PJXBU6CR.js} +47 -44
- package/dist/bundle/chunks/{chunk-OVDMYBIT.js → chunk-PWFM6AQQ.js} +1 -1
- package/dist/bundle/chunks/{chunk-PGVDL4KB.js → chunk-QFDZEUFU.js} +2 -2
- package/dist/bundle/chunks/{chunk-DD5UT56Y.js → chunk-R2KD2HFT.js} +67 -66
- package/dist/bundle/chunks/{chunk-EMBIUIQ2.js → chunk-T2ZGMEMV.js} +46 -45
- package/dist/bundle/chunks/{chunk-IOLLZXQN.js → chunk-U4EAJPMO.js} +138 -126
- package/dist/bundle/chunks/chunk-UZOIHLNU.js +23 -0
- package/dist/bundle/chunks/{chunk-QRYDGY5I.js → chunk-ZSWU5KKA.js} +1 -1
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-ETKC6B2S.js → cloudflare-workers-ai-system-one-JEZVYITT.js} +1 -1
- package/dist/bundle/chunks/{compat-HS4ARZK3.js → compat-ELBUCH6U.js} +6 -6
- package/dist/bundle/chunks/{curator-server-TC7RVVN2.js → curator-server-QB4GITGS.js} +1 -1
- package/dist/bundle/chunks/{dist-NMEXYUP3.js → dist-CBODG4CA.js} +5 -5
- package/dist/bundle/chunks/{dist-5AQPJ2TI.js → dist-NERIS6SW.js} +1 -1
- package/dist/bundle/chunks/{dist-DYB3AR7C.js → dist-QSYDYE3Y.js} +7 -7
- package/dist/bundle/chunks/{easter-egg-3d-VVUF3C3X.js → easter-egg-3d-VZC5WOYV.js} +1 -1
- package/dist/bundle/chunks/{execute-I3WGGPWL.js → execute-6MEJJF2T.js} +2 -2
- package/dist/bundle/chunks/{extract-QHZTEVJP.js → extract-L373D6O7.js} +2 -2
- package/dist/bundle/chunks/{flow-implementer-QMN3HKE2.js → flow-implementer-3P3BHQ7E.js} +4 -4
- package/dist/bundle/chunks/github-copilot.js +53 -56
- package/dist/bundle/chunks/{google-generative-ai-ZND73WDQ.js → google-generative-ai-WIASMWS3.js} +2 -2
- package/dist/bundle/chunks/{google-vertex-YAH62YRM.js → google-vertex-WSPHRZIZ.js} +3 -3
- package/dist/bundle/chunks/{host-Q565BCXB.js → host-WOLZCWQQ.js} +1 -1
- package/dist/bundle/chunks/{inprocess-453SLFL5.js → inprocess-3PDJKE5F.js} +5 -5
- package/dist/bundle/chunks/interactive-mode-SDUO5OLD.js +5 -0
- package/dist/bundle/chunks/{llama-cpp-classify-Z4GZY4GC.js → llama-cpp-classify-KYZT532X.js} +1 -1
- package/dist/bundle/chunks/{mistral-conversations-7I5JURDP.js → mistral-conversations-7JYDDRUT.js} +2 -2
- package/dist/bundle/chunks/{node-IMSYVRPL.js → node-N7TPBUJB.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-LTHOMN37.js → openai-codex-responses-7PAML4NF.js} +3 -3
- package/dist/bundle/chunks/{openai-completions-W2X635EE.js → openai-completions-UJDAIGTK.js} +3 -3
- package/dist/bundle/chunks/{openai-decisions-TN2GNOYI.js → openai-decisions-JMSDGR7K.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-DVY4QXOG.js → openai-responses-2WNCE6AY.js} +3 -3
- package/dist/bundle/chunks/{openrouter-images-SE2JMS44.js → openrouter-images-V3UCCO6X.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-WAS6Z5L5.js → pi-messages-TQ7LJUNQ.js} +2 -2
- package/dist/bundle/chunks/{session-picker-XNVLSJ22.js → session-picker-EYKCMFQR.js} +1 -1
- package/dist/bundle/chunks/{startup-ui-3TCT465D.js → startup-ui-7ODOR34R.js} +2 -2
- package/dist/bundle/chunks/{trace-command-7ORDQ3JS.js → trace-command-VM7FBWPE.js} +4 -4
- package/dist/bundle/chunks/{typesafe-system-one-AAZH6S3I.js → typesafe-system-one-YP7GGN4C.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-CIVXCEAN.js → virtual-modules-IU5KWB2C.js} +10 -10
- package/dist/bundle/cli-runtime.js +5 -5
- package/dist/bundle/index.js +8 -8
- package/dist/bundle/rpc-entry.js +4 -4
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +16 -1
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/setup.d.ts +1 -1
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +3 -2
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +3 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +11 -2
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/keybindings.d.ts +24 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +3 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +12 -1
- 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 +13 -9
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +11 -2
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +23 -6
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/oauth-account-pool.d.ts +4 -0
- package/dist/core/oauth-account-pool.d.ts.map +1 -1
- package/dist/core/oauth-account-pool.js +104 -20
- package/dist/core/oauth-account-pool.js.map +1 -1
- package/dist/core/sdk.js +2 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +17 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +2 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +10 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/extensions/usage/confirmation.d.ts.map +1 -1
- package/dist/extensions/usage/confirmation.js +1 -1
- package/dist/extensions/usage/confirmation.js.map +1 -1
- package/dist/extensions/usage/index.js +6 -6
- package/dist/extensions/usage/index.js.map +1 -1
- package/dist/extensions/usage/panes.d.ts +5 -0
- package/dist/extensions/usage/panes.d.ts.map +1 -0
- package/dist/extensions/usage/panes.js +10 -0
- package/dist/extensions/usage/panes.js.map +1 -0
- package/dist/extensions/usage/popup.d.ts.map +1 -1
- package/dist/extensions/usage/popup.js +9 -18
- package/dist/extensions/usage/popup.js.map +1 -1
- package/dist/humain/gateway/client.d.ts.map +1 -1
- package/dist/humain/gateway/client.js +36 -9
- package/dist/humain/gateway/client.js.map +1 -1
- package/dist/humain/gateway/http.d.ts.map +1 -1
- package/dist/humain/gateway/http.js +26 -6
- package/dist/humain/gateway/http.js.map +1 -1
- package/dist/humain/gateway/provider.d.ts.map +1 -1
- package/dist/humain/gateway/provider.js +9 -2
- package/dist/humain/gateway/provider.js.map +1 -1
- package/dist/humain/hcode/contracts.d.ts +15 -0
- package/dist/humain/hcode/contracts.d.ts.map +1 -1
- package/dist/humain/hcode/contracts.js +85 -10
- package/dist/humain/hcode/contracts.js.map +1 -1
- package/dist/humain/hcode/environment.d.ts.map +1 -1
- package/dist/humain/hcode/environment.js +4 -2
- package/dist/humain/hcode/environment.js.map +1 -1
- package/dist/humain/hcode/facade.d.ts +12 -1
- package/dist/humain/hcode/facade.d.ts.map +1 -1
- package/dist/humain/hcode/facade.js +35 -8
- package/dist/humain/hcode/facade.js.map +1 -1
- package/dist/humain/hcode/images.d.ts.map +1 -1
- package/dist/humain/hcode/images.js +4 -2
- package/dist/humain/hcode/images.js.map +1 -1
- package/dist/humain/hcode/login-copy.d.ts.map +1 -1
- package/dist/humain/hcode/login-copy.js +11 -1
- package/dist/humain/hcode/login-copy.js.map +1 -1
- package/dist/humain/hcode/notices.d.ts +22 -1
- package/dist/humain/hcode/notices.d.ts.map +1 -1
- package/dist/humain/hcode/notices.js +34 -3
- package/dist/humain/hcode/notices.js.map +1 -1
- package/dist/humain/hcode/provider.d.ts +3 -1
- package/dist/humain/hcode/provider.d.ts.map +1 -1
- package/dist/humain/hcode/provider.js +126 -46
- package/dist/humain/hcode/provider.js.map +1 -1
- package/dist/humain/hcode/run-credential.d.ts +21 -0
- package/dist/humain/hcode/run-credential.d.ts.map +1 -0
- package/dist/humain/hcode/run-credential.js +140 -0
- package/dist/humain/hcode/run-credential.js.map +1 -0
- package/dist/humain/hcode/sandbox.d.ts +6 -0
- package/dist/humain/hcode/sandbox.d.ts.map +1 -0
- package/dist/humain/hcode/sandbox.js +139 -0
- package/dist/humain/hcode/sandbox.js.map +1 -0
- package/dist/humain/hcode/selection.d.ts +7 -2
- package/dist/humain/hcode/selection.d.ts.map +1 -1
- package/dist/humain/hcode/selection.js +29 -5
- package/dist/humain/hcode/selection.js.map +1 -1
- package/dist/humain/hcode/transport.d.ts +3 -2
- package/dist/humain/hcode/transport.d.ts.map +1 -1
- package/dist/humain/hcode/transport.js +22 -7
- package/dist/humain/hcode/transport.js.map +1 -1
- package/dist/humain/remote/broker.d.ts +84 -0
- package/dist/humain/remote/broker.d.ts.map +1 -0
- package/dist/humain/remote/broker.js +427 -0
- package/dist/humain/remote/broker.js.map +1 -0
- package/dist/humain/remote/deny-store.d.ts +12 -0
- package/dist/humain/remote/deny-store.d.ts.map +1 -0
- package/dist/humain/remote/deny-store.js +164 -0
- package/dist/humain/remote/deny-store.js.map +1 -0
- package/dist/humain/remote/enablement.d.ts +5 -0
- package/dist/humain/remote/enablement.d.ts.map +1 -0
- package/dist/humain/remote/enablement.js +8 -0
- package/dist/humain/remote/enablement.js.map +1 -0
- package/dist/humain/remote/environment.d.ts +11 -0
- package/dist/humain/remote/environment.d.ts.map +1 -0
- package/dist/humain/remote/environment.js +19 -0
- package/dist/humain/remote/environment.js.map +1 -0
- package/dist/humain/remote/host-watch.d.ts +21 -0
- package/dist/humain/remote/host-watch.d.ts.map +1 -0
- package/dist/humain/remote/host-watch.js +186 -0
- package/dist/humain/remote/host-watch.js.map +1 -0
- package/dist/humain/remote/ipc-posix.d.ts +5 -0
- package/dist/humain/remote/ipc-posix.d.ts.map +1 -0
- package/dist/humain/remote/ipc-posix.js +29 -0
- package/dist/humain/remote/ipc-posix.js.map +1 -0
- package/dist/humain/remote/ipc-windows.d.ts +3 -0
- package/dist/humain/remote/ipc-windows.d.ts.map +1 -0
- package/dist/humain/remote/ipc-windows.js +5 -0
- package/dist/humain/remote/ipc-windows.js.map +1 -0
- package/dist/humain/remote/ipc.d.ts +10 -0
- package/dist/humain/remote/ipc.d.ts.map +1 -0
- package/dist/humain/remote/ipc.js +19 -0
- package/dist/humain/remote/ipc.js.map +1 -0
- package/dist/humain/remote/protocol.d.ts +43 -0
- package/dist/humain/remote/protocol.d.ts.map +1 -0
- package/dist/humain/remote/protocol.js +76 -0
- package/dist/humain/remote/protocol.js.map +1 -0
- package/dist/humain/remote/relay-socket.d.ts +30 -0
- package/dist/humain/remote/relay-socket.d.ts.map +1 -0
- package/dist/humain/remote/relay-socket.js +137 -0
- package/dist/humain/remote/relay-socket.js.map +1 -0
- package/dist/humain/remote/secure-channel.d.ts +10 -0
- package/dist/humain/remote/secure-channel.d.ts.map +1 -0
- package/dist/humain/remote/secure-channel.js +5 -0
- package/dist/humain/remote/secure-channel.js.map +1 -0
- package/dist/humain/remote/terminal.d.ts +48 -0
- package/dist/humain/remote/terminal.d.ts.map +1 -0
- package/dist/humain/remote/terminal.js +119 -0
- package/dist/humain/remote/terminal.js.map +1 -0
- package/dist/humain/remote/tickets.d.ts +35 -0
- package/dist/humain/remote/tickets.d.ts.map +1 -0
- package/dist/humain/remote/tickets.js +132 -0
- package/dist/humain/remote/tickets.js.map +1 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +13 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/account-picker.d.ts +31 -0
- package/dist/modes/interactive/components/account-picker.d.ts.map +1 -0
- package/dist/modes/interactive/components/account-picker.js +150 -0
- package/dist/modes/interactive/components/account-picker.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +6 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +26 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +35 -1
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +179 -3
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/working-indicator-engine.d.ts +32 -0
- package/dist/modes/interactive/components/working-indicator-engine.d.ts.map +1 -0
- package/dist/modes/interactive/components/working-indicator-engine.js +112 -0
- package/dist/modes/interactive/components/working-indicator-engine.js.map +1 -0
- package/dist/modes/interactive/fullscreen.d.ts +13 -0
- package/dist/modes/interactive/fullscreen.d.ts.map +1 -0
- package/dist/modes/interactive/fullscreen.js +25 -0
- package/dist/modes/interactive/fullscreen.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +19 -3
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +341 -54
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/oauth-account-format.d.ts +9 -0
- package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
- package/dist/modes/interactive/oauth-account-format.js +31 -22
- package/dist/modes/interactive/oauth-account-format.js.map +1 -1
- package/dist/modes/interactive/theme/humain-dark.json +5 -4
- package/dist/modes/interactive/theme/humain-light.json +6 -5
- package/docs/cli.md +1 -1
- package/docs/development.md +7 -0
- package/docs/forge-run-bootstrap.md +46 -0
- package/docs/humain-code.md +2 -2
- package/docs/index.md +2 -1
- package/docs/keybindings.md +10 -0
- package/docs/providers.md +16 -6
- package/docs/quickstart.md +16 -2
- package/docs/settings.md +20 -0
- package/docs/slash-commands.md +4 -2
- package/docs/usage.md +2 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/schemas/keybindings.schema.json +12 -0
- package/schemas/settings.schema.json +29 -0
- package/dist/bundle/chunks/chunk-IXQYPQRQ.js +0 -2079
- package/dist/bundle/chunks/chunk-J5TSAJGC.js +0 -22
- package/dist/bundle/chunks/chunk-YPZPCHNV.js +0 -3
- package/dist/bundle/chunks/interactive-mode-MVZOJ5OU.js +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popup.js","sourceRoot":"","sources":["../../../src/extensions/usage/popup.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,OAAO,EAIN,sBAAsB,EAGtB,eAAe,EACf,YAAY,EACZ,gBAAgB,GAChB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,wDAAwD,CAAC;AAGvF,OAAO,EAAqD,gBAAgB,EAAE,MAAM,eAAe,CAAC;AA2BpG,MAAM,SAAS,GAAG,EAAE,CA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;iBACzC,CAAC,CAAC;YACJ,CAAC;YACD,MAAM,UAAU,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC;YACnC,IAAI,CAAC,IAAI,CACR,KAAK;gBACJ,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,UAAU;gBACpG,CAAC,CAAC,WAAW;oBACZ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;oBACrB,CAAC,CAAC,UAAU,CACd,CAAC;QACH,CAAC;QACD,mDAAmD;QACnD,OAAO,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;aAC3F,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC;aAChB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC1G,CAAC;CACD","sourcesContent":["// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit a6df6a2c; modified for HUMAIN Code CLI.\nimport {\n\ttype Component,\n\ttype Focusable,\n\ttype Keybinding,\n\tstripTerminalSequences,\n\ttype TuiMouseEvent,\n\ttype TuiMouseEventResult,\n\ttruncateToWidth,\n\tvisibleWidth,\n\twrapTextWithAnsi,\n} from \"@earendil-works/pi-tui\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport { formatKeyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { HcodeOverview } from \"./hcode-overview.ts\";\nimport { type UsageBar, type UsageLine, type UsageOverview, usageDisplayText } from \"./overview.ts\";\n\nexport interface UsageTab {\n\tid: string;\n\tlabel: string;\n\toverview: UsageOverview | HcodeOverview;\n\tactive?: boolean;\n\tresetAction?: string;\n\tresetDisabled?: boolean;\n\tusageActions?: { reconnect: boolean; refreshing?: boolean };\n}\n\nexport type UsageAction = \"reset\" | \"billing\" | \"refresh\" | \"reconnect\";\ntype UsageView = \"accounts\" | \"session\";\ninterface DetailRow {\n\ttext: string;\n\trecent?: boolean;\n\taction?: UsageAction;\n\tdisabled?: boolean;\n}\ninterface HitRegion {\n\tx: number;\n\ty: number;\n\twidth: number;\n\tactivate: () => void;\n}\n\nconst BAR_WIDTH = 24;\nconst MIN_BAR_WIDTH = 8;\n\nconst TONE_COLOR = {\n\taccent: \"accent\",\n\twarning: \"warning\",\n\terror: \"error\",\n\tsuccess: \"success\",\n} as const;\n\nfunction renderBar(theme: Theme, bar: UsageBar, width: number): string {\n\tconst frac = bar.total && bar.total > 0 ? Math.min(1, Math.max(0, bar.used / bar.total)) : 0;\n\tconst filled = Math.round(frac * width);\n\tconst fill = theme.fg(TONE_COLOR[bar.tone], \"█\".repeat(filled));\n\tconst empty = theme.fg(\"muted\", \"░\".repeat(width - filled));\n\treturn `${fill}${empty}`;\n}\n\nfunction providerLabel(providerId: string): string {\n\treturn providerId === \"openai-codex\"\n\t\t? \"Codex\"\n\t\t: providerId === \"anthropic\"\n\t\t\t? \"Claude\"\n\t\t\t: providerId === \"humain-code-account\"\n\t\t\t\t? \"HUMAIN Code account\"\n\t\t\t\t: usageDisplayText(providerId);\n}\n\n/** Account selection inspects usage only; actions delegate side effects to the caller. */\nexport class UsagePopupComponent implements Component, Focusable {\n\tfocused = false;\n\n\tprivate readonly theme: Theme;\n\tprivate readonly keybindings: KeybindingsManager;\n\tprivate readonly tabs: readonly UsageTab[];\n\tprivate readonly onClose: () => void;\n\tprivate readonly requestRender: () => void;\n\tprivate readonly getHeight: () => number;\n\tprivate readonly onAction?: (tab: UsageTab, action: UsageAction) => void;\n\tprivate disposed = false;\n\tprivate view: UsageView;\n\tprivate detailFocus = false;\n\tprivate expanded = false;\n\tprivate jumpToRecent = false;\n\tprivate selectedId: string | undefined;\n\tprivate scrollTop = 0;\n\tprivate viewportHeight = 1;\n\tprivate maxScrollTop = 0;\n\tprivate regions: HitRegion[] = [];\n\tprivate renderedWidth = 0;\n\tprivate listWidth = 0;\n\n\tconstructor(\n\t\ttheme: Theme,\n\t\tkeybindings: KeybindingsManager,\n\t\ttabs: readonly UsageTab[],\n\t\tonClose: () => void,\n\t\trequestRender: () => void,\n\t\tgetHeight: () => number = () => 24,\n\t\tonAction?: (tab: UsageTab, action: UsageAction) => void,\n\t) {\n\t\tthis.theme = theme;\n\t\tthis.keybindings = keybindings;\n\t\tthis.tabs = tabs;\n\t\tthis.onClose = onClose;\n\t\tthis.requestRender = requestRender;\n\t\tthis.getHeight = getHeight;\n\t\tthis.onAction = onAction;\n\t\tthis.selectedId = this.accounts[0]?.id;\n\t\tthis.view = this.selectedId ? \"accounts\" : \"session\";\n\t}\n\n\tprivate get accounts(): UsageTab[] {\n\t\tconst providers = new Map<string, UsageTab[]>();\n\t\tfor (const tab of this.tabs) {\n\t\t\tif (tab.id === \"session\") continue;\n\t\t\tconst group = providers.get(tab.overview.providerId) ?? [];\n\t\t\tgroup.push(tab);\n\t\t\tproviders.set(tab.overview.providerId, group);\n\t\t}\n\t\treturn [...providers.values()].flat();\n\t}\n\n\tprivate get selectedAccount(): UsageTab | undefined {\n\t\tconst accounts = this.accounts;\n\t\treturn accounts.find((tab) => tab.id === this.selectedId) ?? accounts[0];\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tthis.regions = [];\n\t\tthis.onClose();\n\t}\n\n\tprivate showView(view: UsageView): void {\n\t\tthis.expanded = false;\n\t\tthis.view = view;\n\t\tthis.detailFocus = view === \"session\";\n\t\tthis.scrollTop = 0;\n\t\tthis.regions = [];\n\t\tthis.requestRender();\n\t}\n\n\tprivate selectAccount(id: string): void {\n\t\tif (id !== this.selectedAccount?.id) {\n\t\t\tthis.scrollTop = 0;\n\t\t\tthis.expanded = false;\n\t\t}\n\t\tthis.selectedId = id;\n\t\tthis.regions = [];\n\t\tthis.requestRender();\n\t}\n\n\tprivate moveAccount(delta: number, wrap = false): boolean {\n\t\tconst accounts = this.accounts;\n\t\tif (this.view !== \"accounts\" || accounts.length === 0) return false;\n\t\tconst current = accounts.findIndex((tab) => tab.id === this.selectedAccount?.id);\n\t\tconst next = wrap\n\t\t\t? (current + delta + accounts.length) % accounts.length\n\t\t\t: Math.max(0, Math.min(accounts.length - 1, current + delta));\n\t\tif (next === current) return false;\n\t\tthis.selectAccount(accounts[next].id);\n\t\treturn true;\n\t}\n\n\tprivate scrollBy(delta: number): boolean {\n\t\tconst next = Math.max(0, Math.min(this.maxScrollTop, this.scrollTop + delta));\n\t\tif (next === this.scrollTop) return false;\n\t\tthis.scrollTop = next;\n\t\tthis.regions = [];\n\t\tthis.requestRender();\n\t\treturn true;\n\t}\n\n\tprivate invokeAction(action: UsageAction): void {\n\t\tconst tab = this.selectedAccount;\n\t\tif (this.view !== \"accounts\" || !tab || !this.onAction) return;\n\t\tif (tab.overview.providerId === \"humain-code-account\") return;\n\t\tif (action === \"reset\" && (!tab.resetAction || tab.resetDisabled)) return;\n\t\tif (action === \"refresh\" || action === \"reconnect\") {\n\t\t\tif (!tab.usageActions || tab.usageActions.refreshing) return;\n\t\t\tif (action === \"reconnect\" && !tab.usageActions.reconnect) return;\n\t\t}\n\t\tthis.onAction(tab, action);\n\t\tthis.requestRender();\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (this.disposed) return;\n\t\tconst kb = this.keybindings;\n\t\tconst actions = this.view === \"accounts\" && this.onAction ? this.selectedAccount?.usageActions : undefined;\n\t\tif (kb.matches(data, \"app.clear\")) this.dispose();\n\t\telse if (kb.matches(data, \"tui.select.cancel\")) {\n\t\t\tif (this.view === \"accounts\" && this.detailFocus) {\n\t\t\t\tthis.expanded = false;\n\t\t\t\tthis.scrollTop = 0;\n\t\t\t\tthis.detailFocus = false;\n\t\t\t\tthis.regions = [];\n\t\t\t\tthis.requestRender();\n\t\t\t} else this.dispose();\n\t\t} else if (kb.matches(data, \"app.usage.showAccounts\")) this.showView(\"accounts\");\n\t\telse if (kb.matches(data, \"app.usage.showSession\")) this.showView(\"session\");\n\t\telse if (kb.matches(data, \"app.usage.reset\")) this.invokeAction(\"reset\");\n\t\telse if (kb.matches(data, \"app.usage.billing\")) this.invokeAction(\"billing\");\n\t\telse if (actions && !actions.refreshing && kb.matches(data, \"app.usage.refresh\")) this.invokeAction(\"refresh\");\n\t\telse if (actions?.reconnect && !actions.refreshing && kb.matches(data, \"app.usage.reconnect\"))\n\t\t\tthis.invokeAction(\"reconnect\");\n\t\telse if (kb.matches(data, \"app.usage.nextTab\")) this.moveAccount(1, true);\n\t\telse if (kb.matches(data, \"app.usage.previousTab\")) this.moveAccount(-1, true);\n\t\telse if (kb.matches(data, \"app.usage.toggleDetails\")) {\n\t\t\tconst tab = this.selectedAccount;\n\t\t\tif (this.view !== \"accounts\" || !tab || !(\"kind\" in tab.overview) || !tab.overview.details.length) return;\n\t\t\tthis.expanded = !this.expanded;\n\t\t\tthis.detailFocus = true;\n\t\t\tthis.jumpToRecent = this.expanded;\n\t\t\tthis.scrollTop = 0;\n\t\t\tthis.regions = [];\n\t\t\tthis.requestRender();\n\t\t} else if (kb.matches(data, \"tui.select.confirm\") && this.view === \"accounts\" && this.selectedAccount) {\n\t\t\tthis.detailFocus = true;\n\t\t\tthis.regions = [];\n\t\t\tthis.requestRender();\n\t\t} else {\n\t\t\tlet delta = 0;\n\t\t\tif (kb.matches(data, \"tui.select.up\")) delta = -1;\n\t\t\telse if (kb.matches(data, \"tui.select.down\")) delta = 1;\n\t\t\telse if (kb.matches(data, \"tui.select.pageUp\")) delta = -this.viewportHeight;\n\t\t\telse if (kb.matches(data, \"tui.select.pageDown\")) delta = this.viewportHeight;\n\t\t\tif (delta) {\n\t\t\t\tif (this.view === \"accounts\" && !this.detailFocus) this.moveAccount(delta);\n\t\t\t\telse this.scrollBy(delta);\n\t\t\t}\n\t\t}\n\t}\n\n\thandleMouse(event: TuiMouseEvent): TuiMouseEventResult {\n\t\tif (this.disposed) return { handled: true, render: false };\n\t\tconst inBody = event.x >= 0 && event.x < this.renderedWidth && event.y >= 3 && event.y < 3 + this.viewportHeight;\n\t\tif (event.type === \"wheel\" && inBody) {\n\t\t\tconst inList = this.view === \"accounts\" && (this.listWidth > 0 ? event.x < this.listWidth : !this.detailFocus);\n\t\t\tconst delta = event.wheelDelta ?? 0;\n\t\t\tif (!delta) return { handled: true, render: false };\n\t\t\tconst focusChanged = this.detailFocus === inList;\n\t\t\tthis.detailFocus = !inList;\n\t\t\tconst changed = inList ? this.moveAccount(delta) : this.scrollBy(delta);\n\t\t\tif (focusChanged && !changed) this.requestRender();\n\t\t\treturn { handled: true, render: changed || focusChanged, focus: true };\n\t\t}\n\t\tif (event.type !== \"click\" || event.button !== \"left\") return { handled: true, render: false };\n\t\tconst region = this.regions.find(\n\t\t\t(item) => event.y === item.y && event.x >= item.x && event.x < item.x + item.width,\n\t\t);\n\t\tif (region) {\n\t\t\tregion.activate();\n\t\t\treturn { handled: true, render: true, focus: true };\n\t\t}\n\t\tif (inBody && this.view === \"accounts\" && this.listWidth > 0 && event.x > this.listWidth + 2) {\n\t\t\tthis.detailFocus = true;\n\t\t\tthis.requestRender();\n\t\t\treturn { handled: true, render: true, focus: true };\n\t\t}\n\t\treturn { handled: true, render: false };\n\t}\n\n\tinvalidate(): void {\n\t\tthis.regions = [];\n\t}\n\n\tprivate key(action: Keybinding): string {\n\t\tconst key = this.keybindings.getKeys(action)[0];\n\t\treturn key ? formatKeyText(key) : \"\";\n\t}\n\n\tprivate detailRows(tab: UsageTab, width: number): DetailRow[] {\n\t\tconst theme = this.theme;\n\t\tconst { providerId, modelId, bars, lines, notes } = tab.overview;\n\t\tconst session = this.view === \"session\";\n\t\tconst out: DetailRow[] = [];\n\t\tconst add = (text: string, action?: UsageAction, disabled?: boolean): void => {\n\t\t\tfor (const wrapped of wrapTextWithAnsi(text, width)) out.push({ text: wrapped, action, disabled });\n\t\t};\n\t\tconst row = (line: UsageLine): void => {\n\t\t\tconst label = usageDisplayText(line.label);\n\t\t\tconst padded = label + \" \".repeat(Math.max(0, 13 - visibleWidth(label)));\n\t\t\tconst text = usageDisplayText(line.value);\n\t\t\tconst value = line.tone ? theme.fg(TONE_COLOR[line.tone], text) : text;\n\t\t\tadd(` ${theme.fg(\"dim\", padded)} ${value}`);\n\t\t};\n\t\tconst addBars = (bars: UsageBar[]): void => {\n\t\t\tif (bars.length === 0) return;\n\t\t\tbars = bars.map((bar) => ({\n\t\t\t\t...bar,\n\t\t\t\tlabel: usageDisplayText(bar.label),\n\t\t\t\tdisplay: usageDisplayText(bar.display),\n\t\t\t\tnote: bar.note ? usageDisplayText(bar.note) : undefined,\n\t\t\t}));\n\t\t\t// Keep compact bars when they fit; stack and wrap details instead of truncating limits on narrow screens.\n\t\t\tconst displayWidth = Math.max(...bars.map((bar) => visibleWidth(bar.display)));\n\t\t\tconst labelWidth = Math.min(\n\t\t\t\tMath.max(...bars.map((bar) => visibleWidth(bar.label))),\n\t\t\t\tMath.max(0, width - 2 - MIN_BAR_WIDTH - 3 - displayWidth),\n\t\t\t);\n\t\t\tconst barWidth = Math.max(MIN_BAR_WIDTH, Math.min(BAR_WIDTH, width - 2 - labelWidth - 3 - displayWidth));\n\t\t\tfor (const bar of bars) {\n\t\t\t\tconst label = bar.label + \" \".repeat(Math.max(0, labelWidth - visibleWidth(bar.label)));\n\t\t\t\tconst head = ` ${theme.fg(\"dim\", label)} ${renderBar(theme, bar, barWidth)} ${theme.fg(\"dim\", bar.display)}`;\n\t\t\t\tconst note = bar.note ? theme.fg(\"dim\", bar.note) : undefined;\n\t\t\t\tif (visibleWidth(head) > width) {\n\t\t\t\t\tadd(` ${theme.fg(\"dim\", `${bar.label} · ${bar.display}`)}`);\n\t\t\t\t\tadd(renderBar(theme, bar, Math.min(BAR_WIDTH, width)));\n\t\t\t\t\tif (note) add(` ${note}`);\n\t\t\t\t} else if (note && visibleWidth(head) + 2 + visibleWidth(note) <= width) add(`${head} ${note}`);\n\t\t\t\telse {\n\t\t\t\t\tadd(head);\n\t\t\t\t\tif (note) add(` ${note}`);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tif (\"kind\" in tab.overview) {\n\t\t\tadd(theme.bold(usageDisplayText(modelId)));\n\t\t\tfor (const line of lines) {\n\t\t\t\tif (line.label === \"Resets\") addBars(bars);\n\t\t\t\tconst value = usageDisplayText(line.value);\n\t\t\t\tconst text = line.label ? `${theme.fg(\"dim\", `${usageDisplayText(line.label)}:`)} ${value}` : value;\n\t\t\t\tadd(line.tone ? theme.fg(TONE_COLOR[line.tone], text) : text);\n\t\t\t}\n\t\t\tfor (const note of notes) add(theme.fg(\"dim\", usageDisplayText(note)));\n\t\t\tif (this.expanded && tab.overview.details.length) {\n\t\t\t\tadd(\"\");\n\t\t\t\tout.push({ text: truncateToWidth(theme.bold(\"Recent requests\"), width, \"…\"), recent: true });\n\t\t\t\tfor (const detail of tab.overview.details) add(usageDisplayText(detail));\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tadd(\n\t\t\ttheme.bold(session ? \"This session\" : usageDisplayText(tab.label)) +\n\t\t\t\t(!session && tab.active ? ` ${theme.fg(\"success\", \"In use\")}` : \"\"),\n\t\t);\n\t\tadd(theme.fg(\"dim\", usageDisplayText(`${providerId} · ${modelId}`)));\n\t\tadd(\"\");\n\t\tif (!session) add(theme.bold(\"INCLUDED USAGE\"));\n\t\tconst includedBars = session ? bars : bars.filter((bar) => !bar.section);\n\t\taddBars(includedBars);\n\t\tfor (const line of lines) if (session || !line.section) row(line);\n\t\tif (tab.usageActions && this.onAction) {\n\t\t\tconst { refreshing, reconnect } = tab.usageActions;\n\t\t\tfor (const [action, label] of [\n\t\t\t\t[\"refresh\", refreshing ? \"Refreshing…\" : \"Refresh\"],\n\t\t\t\t...(reconnect ? ([[\"reconnect\", \"Reconnect\"]] as const) : []),\n\t\t\t] as const) {\n\t\t\t\tconst key = this.key(`app.usage.${action}`);\n\t\t\t\tadd(theme.fg(refreshing ? \"muted\" : \"accent\", `[${key ? `${key} ` : \"\"}${label}]`), action, refreshing);\n\t\t\t}\n\t\t}\n\t\tif (!session) {\n\t\t\tif (includedBars.length === 0 && !lines.some((line) => !line.section))\n\t\t\t\tadd(theme.fg(\"muted\", \" Usage not reported.\"));\n\t\t\tfor (const [section, title] of [\n\t\t\t\t[\"resets\", \"SAVED RESETS\"],\n\t\t\t\t[\"paid\", \"PAID USAGE\"],\n\t\t\t] as const) {\n\t\t\t\tadd(\"\");\n\t\t\t\tadd(theme.bold(title));\n\t\t\t\tconst sectionBars = bars.filter((bar) => bar.section === section);\n\t\t\t\taddBars(sectionBars);\n\t\t\t\tconst sectionLines = lines.filter((line) => line.section === section);\n\t\t\t\tfor (const line of sectionLines) row(line);\n\t\t\t\tif (sectionBars.length === 0 && sectionLines.length === 0) add(theme.fg(\"muted\", \" Not reported.\"));\n\t\t\t\tconst action = section === \"resets\" ? \"reset\" : \"billing\";\n\t\t\t\tconst label = section === \"resets\" ? tab.resetAction : this.onAction ? \"Open billing settings\" : undefined;\n\t\t\t\tif (label) {\n\t\t\t\t\tconst key = this.key(`app.usage.${action}`);\n\t\t\t\t\tconst disabled = !this.onAction || (action === \"reset\" && tab.resetDisabled === true);\n\t\t\t\t\tconst text = `[${key ? `${key} ` : \"\"}${usageDisplayText(label)}]${disabled ? \" (disabled)\" : \"\"}`;\n\t\t\t\t\tadd(theme.fg(disabled ? \"muted\" : \"accent\", text), action, disabled);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (notes.length > 0) {\n\t\t\tadd(\"\");\n\t\t\tfor (const note of notes) add(theme.fg(\"warning\", usageDisplayText(note)));\n\t\t}\n\t\treturn out;\n\t}\n\n\tprivate accountRows(width: number, height: number): string[] {\n\t\tconst accounts = this.accounts;\n\t\tconst selected = this.selectedAccount;\n\t\tconst all: { text: string; provider: string; account?: UsageTab }[] = [];\n\t\tlet provider: string | undefined;\n\t\tfor (const account of accounts) {\n\t\t\tif (provider !== account.overview.providerId) {\n\t\t\t\tprovider = account.overview.providerId;\n\t\t\t\tall.push({ text: this.theme.fg(\"muted\", this.theme.bold(providerLabel(provider))), provider });\n\t\t\t}\n\t\t\tconst marker = account.id === selected?.id ? \"> \" : \" \";\n\t\t\tconst status = account.active ? this.theme.fg(\"success\", \" In use\") : \"\";\n\t\t\tconst label = truncateToWidth(\n\t\t\t\tusageDisplayText(account.label),\n\t\t\t\tMath.max(0, width - 2 - visibleWidth(status)),\n\t\t\t\t\"…\",\n\t\t\t);\n\t\t\tconst text = `${marker}${label}`;\n\t\t\tall.push({\n\t\t\t\ttext: (account.id === selected?.id ? this.theme.fg(\"accent\", this.theme.bold(text)) : text) + status,\n\t\t\t\tprovider: account.overview.providerId,\n\t\t\t\taccount,\n\t\t\t});\n\t\t}\n\t\tif (all.length === 0) return wrapTextWithAnsi(\"No saved accounts. Run /login.\", width).slice(0, height);\n\t\tconst selectedRow = all.findIndex((row) => row.account?.id === selected?.id);\n\t\tlet start = Math.max(0, Math.min(selectedRow - Math.floor((height - 1) / 2), all.length - height));\n\t\tconst sticky = start > 0 && all[start].account && height > 1;\n\t\tif (sticky && selectedRow >= start + height - 1) start = selectedRow - height + 2;\n\t\tconst visible = all.slice(start, start + height - (sticky ? 1 : 0));\n\t\tconst output: string[] = [];\n\t\tif (sticky) output.push(this.theme.fg(\"muted\", this.theme.bold(providerLabel(all[start].provider))));\n\t\tfor (const row of visible) {\n\t\t\tif (row.account) {\n\t\t\t\tconst id = row.account.id;\n\t\t\t\tthis.regions.push({\n\t\t\t\t\tx: 0,\n\t\t\t\t\ty: 3 + output.length,\n\t\t\t\t\twidth,\n\t\t\t\t\tactivate: () => {\n\t\t\t\t\t\tthis.detailFocus = this.listWidth === 0;\n\t\t\t\t\t\tthis.selectAccount(id);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\toutput.push(truncateToWidth(row.text, width, \"…\"));\n\t\t}\n\t\treturn output;\n\t}\n\n\trender(width: number): string[] {\n\t\tthis.regions = [];\n\t\tif (this.disposed || width < 1) return [];\n\t\tconst theme = this.theme;\n\t\tthis.renderedWidth = width;\n\t\tconst accounts = this.accounts;\n\t\tconst selected = this.selectedAccount;\n\t\tthis.listWidth = this.view === \"accounts\" && width >= 76 ? Math.min(32, Math.floor(width / 3)) : 0;\n\t\tconst split = this.listWidth > 0;\n\t\tconst showingList = this.view === \"accounts\" && !this.detailFocus;\n\t\tconst detailWidth = split ? width - this.listWidth - 3 : width;\n\t\tconst tab = this.view === \"session\" ? this.tabs.find((item) => item.id === \"session\") : selected;\n\t\tconst details: DetailRow[] = tab ? this.detailRows(tab, detailWidth) : [{ text: \"No usage data available.\" }];\n\t\tconst controls = (\n\t\t\t[\n\t\t\t\t[\"accounts\", \"app.usage.showAccounts\", \"Accounts\"],\n\t\t\t\t[\"session\", \"app.usage.showSession\", \"Session\"],\n\t\t\t] as const\n\t\t).map(([view, action, label]) => {\n\t\t\tconst key = this.key(action);\n\t\t\treturn { view, text: `[${key ? `${key} ` : \"\"}${label}]` };\n\t\t});\n\t\tconst stackedControls = controls.reduce((sum, control) => sum + visibleWidth(control.text), 2) > width;\n\t\tlet controlX = 0;\n\t\tconst navigation = controls.map(({ view, text }, index) => {\n\t\t\tconst x = stackedControls ? 0 : controlX;\n\t\t\tthis.regions.push({\n\t\t\t\tx,\n\t\t\t\ty: stackedControls ? index : 1,\n\t\t\t\twidth: Math.min(visibleWidth(text), width - x),\n\t\t\t\tactivate: () => this.showView(view),\n\t\t\t});\n\t\t\tcontrolX += visibleWidth(text) + 2;\n\t\t\treturn this.view === view ? theme.fg(\"accent\", theme.bold(text)) : theme.fg(\"muted\", text);\n\t\t});\n\t\tconst header = stackedControls ? navigation : [theme.bold(\"Usage\"), navigation.join(\" \")];\n\t\tconst selectKeys = [this.key(\"tui.select.up\"), this.key(\"tui.select.down\")].filter(Boolean).join(\"/\");\n\t\tconst confirm = showingList && selected ? this.key(\"tui.select.confirm\") : \"\";\n\t\tconst cycleKeys =\n\t\t\tthis.view === \"accounts\"\n\t\t\t\t? [this.key(\"app.usage.nextTab\"), this.key(\"app.usage.previousTab\")].filter(Boolean).join(\"/\")\n\t\t\t\t: \"\";\n\t\tconst cancel = this.key(\"tui.select.cancel\");\n\t\tconst footerParts = [\n\t\t\tselectKeys ? `${selectKeys} ${showingList ? \"select\" : \"scroll\"}` : \"\",\n\t\t\tconfirm ? `${confirm} details` : \"\",\n\t\t];\n\t\tif (cycleKeys && width >= 60) footerParts.push(`${cycleKeys} cycle`);\n\t\tconst actionHints: string[] = [];\n\t\tif (\n\t\t\tthis.view === \"accounts\" &&\n\t\t\tselected &&\n\t\t\tselected.overview.providerId !== \"humain-code-account\" &&\n\t\t\tthis.onAction\n\t\t) {\n\t\t\tfor (const [action, label, enabled] of [\n\t\t\t\t[\"reset\", \"saved reset\", selected.resetAction && !selected.resetDisabled],\n\t\t\t\t[\"billing\", \"billing settings\", true],\n\t\t\t\t[\"refresh\", \"Refresh\", selected.usageActions && !selected.usageActions.refreshing],\n\t\t\t\t[\"reconnect\", \"Reconnect\", selected.usageActions?.reconnect && !selected.usageActions.refreshing],\n\t\t\t] as const) {\n\t\t\t\tconst key = this.key(`app.usage.${action}`);\n\t\t\t\tif (key && enabled) actionHints.push(theme.fg(\"accent\", `${key} ${label}`));\n\t\t\t}\n\t\t}\n\t\tif (this.view === \"accounts\" && selected && \"kind\" in selected.overview && selected.overview.details.length) {\n\t\t\tconst key = this.key(\"app.usage.toggleDetails\");\n\t\t\tif (key) actionHints.push(`${key} ${this.expanded ? \"hide details\" : \"details\"}`);\n\t\t}\n\t\tconst footer = [\n\t\t\t...wrapTextWithAnsi(footerParts.filter(Boolean).join(\" · \"), width),\n\t\t\t...wrapTextWithAnsi(\n\t\t\t\t[\n\t\t\t\t\tcancel ? `${cancel} ${this.view === \"accounts\" && this.detailFocus ? \"accounts\" : \"close\"}` : \"\",\n\t\t\t\t\t...actionHints,\n\t\t\t\t]\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(\" · \"),\n\t\t\t\twidth,\n\t\t\t),\n\t\t];\n\t\t// The editor dock measures render() at its natural height; leave room for the transcript, spacer, and footer.\n\t\tconst height = Math.max(1, Math.floor(this.getHeight()) - 5);\n\t\tconst visibleFooter = footer.slice(0, Math.max(0, height - 4));\n\t\tthis.viewportHeight = Math.max(1, height - 3 - visibleFooter.length);\n\t\tthis.maxScrollTop = Math.max(0, details.length - this.viewportHeight);\n\t\tif (this.jumpToRecent) {\n\t\t\tthis.scrollTop = Math.max(\n\t\t\t\t0,\n\t\t\t\tdetails.findIndex((row) => row.recent),\n\t\t\t);\n\t\t\tthis.jumpToRecent = false;\n\t\t}\n\t\tthis.scrollTop = Math.min(this.scrollTop, this.maxScrollTop);\n\t\tconst accountHeading = `Accounts ${selected ? accounts.findIndex((item) => item.id === selected.id) + 1 : 0}/${accounts.length}`;\n\t\tconst detailHeading = `${this.view === \"session\" ? \"Session\" : \"Details\"}${this.detailFocus ? \" (focused)\" : \"\"} ${this.scrollTop + 1}/${this.maxScrollTop + 1}`;\n\t\tconst heading = split\n\t\t\t? truncateToWidth(theme.bold(accountHeading), this.listWidth, \"…\", true) +\n\t\t\t\ttheme.fg(\"dim\", \" │ \") +\n\t\t\t\ttheme.bold(detailHeading)\n\t\t\t: theme.bold(showingList ? accountHeading : detailHeading);\n\t\tconst list =\n\t\t\tthis.view === \"accounts\" && (split || showingList)\n\t\t\t\t? this.accountRows(split ? this.listWidth : width, this.viewportHeight)\n\t\t\t\t: [];\n\t\tconst body: string[] = [];\n\t\tfor (let index = 0; index < this.viewportHeight; index++) {\n\t\t\tconst row = details[this.scrollTop + index];\n\t\t\tif (row?.action && !row.disabled && (!showingList || split)) {\n\t\t\t\tconst action = row.action;\n\t\t\t\tthis.regions.push({\n\t\t\t\t\tx: split ? this.listWidth + 3 : 0,\n\t\t\t\t\ty: 3 + index,\n\t\t\t\t\twidth: visibleWidth(row.text),\n\t\t\t\t\tactivate: () => this.invokeAction(action),\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst detailText = row?.text ?? \"\";\n\t\t\tbody.push(\n\t\t\t\tsplit\n\t\t\t\t\t? truncateToWidth(list[index] ?? \"\", this.listWidth, \"\", true) + theme.fg(\"dim\", \" │ \") + detailText\n\t\t\t\t\t: showingList\n\t\t\t\t\t\t? (list[index] ?? \"\")\n\t\t\t\t\t\t: detailText,\n\t\t\t);\n\t\t}\n\t\t// A line wider than the terminal aborts rendering.\n\t\treturn [...header, heading, ...body, ...visibleFooter.map((line) => theme.fg(\"muted\", line))]\n\t\t\t.slice(0, height)\n\t\t\t.map((line) => truncateToWidth(process.env.NO_COLOR ? stripTerminalSequences(line) : line, width, \"…\"));\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"popup.js","sourceRoot":"","sources":["../../../src/extensions/usage/popup.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,OAAO,EAIN,sBAAsB,EAGtB,eAAe,EACf,YAAY,EACZ,gBAAgB,GAChB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,wDAAwD,CAAC;AAGvF,OAAO,EAAqD,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACpG,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA2B1D,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB,MAAM,UAAU,GAAG;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO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T, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit a6df6a2c; modified for HUMAIN Code CLI.\nimport {\n\ttype Component,\n\ttype Focusable,\n\ttype Keybinding,\n\tstripTerminalSequences,\n\ttype TuiMouseEvent,\n\ttype TuiMouseEventResult,\n\ttruncateToWidth,\n\tvisibleWidth,\n\twrapTextWithAnsi,\n} from \"@earendil-works/pi-tui\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport { formatKeyText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { HcodeOverview } from \"./hcode-overview.ts\";\nimport { type UsageBar, type UsageLine, type UsageOverview, usageDisplayText } from \"./overview.ts\";\nimport { renderUsageBar, usagePaneRow } from \"./panes.ts\";\n\nexport interface UsageTab {\n\tid: string;\n\tlabel: string;\n\toverview: UsageOverview | HcodeOverview;\n\tactive?: boolean;\n\tresetAction?: string;\n\tresetDisabled?: boolean;\n\tusageActions?: { reconnect: boolean; refreshing?: boolean };\n}\n\nexport type UsageAction = \"reset\" | \"billing\" | \"refresh\" | \"reconnect\";\ntype UsageView = \"accounts\" | \"session\";\ninterface DetailRow {\n\ttext: string;\n\trecent?: boolean;\n\taction?: UsageAction;\n\tdisabled?: boolean;\n}\ninterface HitRegion {\n\tx: number;\n\ty: number;\n\twidth: number;\n\tactivate: () => void;\n}\n\nconst BAR_WIDTH = 24;\nconst MIN_BAR_WIDTH = 8;\n\nconst TONE_COLOR = {\n\taccent: \"accent\",\n\twarning: \"warning\",\n\terror: \"error\",\n\tsuccess: \"success\",\n} as const;\n\nfunction providerLabel(providerId: string): string {\n\treturn providerId === \"openai-codex\"\n\t\t? \"Codex\"\n\t\t: providerId === \"anthropic\"\n\t\t\t? \"Claude\"\n\t\t\t: providerId === \"humain-code-account\"\n\t\t\t\t? \"HUMAIN Code account\"\n\t\t\t\t: usageDisplayText(providerId);\n}\n\n/** Account selection inspects usage only; actions delegate side effects to the caller. */\nexport class UsagePopupComponent implements Component, Focusable {\n\tfocused = false;\n\n\tprivate readonly theme: Theme;\n\tprivate readonly keybindings: KeybindingsManager;\n\tprivate readonly tabs: readonly UsageTab[];\n\tprivate readonly onClose: () => void;\n\tprivate readonly requestRender: () => void;\n\tprivate readonly getHeight: () => number;\n\tprivate readonly onAction?: (tab: UsageTab, action: UsageAction) => void;\n\tprivate disposed = false;\n\tprivate view: UsageView;\n\tprivate detailFocus = false;\n\tprivate expanded = false;\n\tprivate jumpToRecent = false;\n\tprivate selectedId: string | undefined;\n\tprivate scrollTop = 0;\n\tprivate viewportHeight = 1;\n\tprivate maxScrollTop = 0;\n\tprivate regions: HitRegion[] = [];\n\tprivate renderedWidth = 0;\n\tprivate listWidth = 0;\n\n\tconstructor(\n\t\ttheme: Theme,\n\t\tkeybindings: KeybindingsManager,\n\t\ttabs: readonly UsageTab[],\n\t\tonClose: () => void,\n\t\trequestRender: () => void,\n\t\tgetHeight: () => number = () => 24,\n\t\tonAction?: (tab: UsageTab, action: UsageAction) => void,\n\t) {\n\t\tthis.theme = theme;\n\t\tthis.keybindings = keybindings;\n\t\tthis.tabs = tabs;\n\t\tthis.onClose = onClose;\n\t\tthis.requestRender = requestRender;\n\t\tthis.getHeight = getHeight;\n\t\tthis.onAction = onAction;\n\t\tthis.selectedId = this.accounts[0]?.id;\n\t\tthis.view = this.selectedId ? \"accounts\" : \"session\";\n\t}\n\n\tprivate get accounts(): UsageTab[] {\n\t\tconst providers = new Map<string, UsageTab[]>();\n\t\tfor (const tab of this.tabs) {\n\t\t\tif (tab.id === \"session\") continue;\n\t\t\tconst group = providers.get(tab.overview.providerId) ?? [];\n\t\t\tgroup.push(tab);\n\t\t\tproviders.set(tab.overview.providerId, group);\n\t\t}\n\t\treturn [...providers.values()].flat();\n\t}\n\n\tprivate get selectedAccount(): UsageTab | undefined {\n\t\tconst accounts = this.accounts;\n\t\treturn accounts.find((tab) => tab.id === this.selectedId) ?? accounts[0];\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tthis.regions = [];\n\t\tthis.onClose();\n\t}\n\n\tprivate showView(view: UsageView): void {\n\t\tthis.expanded = false;\n\t\tthis.view = view;\n\t\tthis.detailFocus = view === \"session\";\n\t\tthis.scrollTop = 0;\n\t\tthis.regions = [];\n\t\tthis.requestRender();\n\t}\n\n\tprivate selectAccount(id: string): void {\n\t\tif (id !== this.selectedAccount?.id) {\n\t\t\tthis.scrollTop = 0;\n\t\t\tthis.expanded = false;\n\t\t}\n\t\tthis.selectedId = id;\n\t\tthis.regions = [];\n\t\tthis.requestRender();\n\t}\n\n\tprivate moveAccount(delta: number, wrap = false): boolean {\n\t\tconst accounts = this.accounts;\n\t\tif (this.view !== \"accounts\" || accounts.length === 0) return false;\n\t\tconst current = accounts.findIndex((tab) => tab.id === this.selectedAccount?.id);\n\t\tconst next = wrap\n\t\t\t? (current + delta + accounts.length) % accounts.length\n\t\t\t: Math.max(0, Math.min(accounts.length - 1, current + delta));\n\t\tif (next === current) return false;\n\t\tthis.selectAccount(accounts[next].id);\n\t\treturn true;\n\t}\n\n\tprivate scrollBy(delta: number): boolean {\n\t\tconst next = Math.max(0, Math.min(this.maxScrollTop, this.scrollTop + delta));\n\t\tif (next === this.scrollTop) return false;\n\t\tthis.scrollTop = next;\n\t\tthis.regions = [];\n\t\tthis.requestRender();\n\t\treturn true;\n\t}\n\n\tprivate invokeAction(action: UsageAction): void {\n\t\tconst tab = this.selectedAccount;\n\t\tif (this.view !== \"accounts\" || !tab || !this.onAction) return;\n\t\tif (tab.overview.providerId === \"humain-code-account\") return;\n\t\tif (action === \"reset\" && (!tab.resetAction || tab.resetDisabled)) return;\n\t\tif (action === \"refresh\" || action === \"reconnect\") {\n\t\t\tif (!tab.usageActions || tab.usageActions.refreshing) return;\n\t\t\tif (action === \"reconnect\" && !tab.usageActions.reconnect) return;\n\t\t}\n\t\tthis.onAction(tab, action);\n\t\tthis.requestRender();\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (this.disposed) return;\n\t\tconst kb = this.keybindings;\n\t\tconst actions = this.view === \"accounts\" && this.onAction ? this.selectedAccount?.usageActions : undefined;\n\t\tif (kb.matches(data, \"app.clear\")) this.dispose();\n\t\telse if (kb.matches(data, \"tui.select.cancel\")) {\n\t\t\tif (this.view === \"accounts\" && this.detailFocus) {\n\t\t\t\tthis.expanded = false;\n\t\t\t\tthis.scrollTop = 0;\n\t\t\t\tthis.detailFocus = false;\n\t\t\t\tthis.regions = [];\n\t\t\t\tthis.requestRender();\n\t\t\t} else this.dispose();\n\t\t} else if (kb.matches(data, \"app.usage.showAccounts\")) this.showView(\"accounts\");\n\t\telse if (kb.matches(data, \"app.usage.showSession\")) this.showView(\"session\");\n\t\telse if (kb.matches(data, \"app.usage.reset\")) this.invokeAction(\"reset\");\n\t\telse if (kb.matches(data, \"app.usage.billing\")) this.invokeAction(\"billing\");\n\t\telse if (actions && !actions.refreshing && kb.matches(data, \"app.usage.refresh\")) this.invokeAction(\"refresh\");\n\t\telse if (actions?.reconnect && !actions.refreshing && kb.matches(data, \"app.usage.reconnect\"))\n\t\t\tthis.invokeAction(\"reconnect\");\n\t\telse if (kb.matches(data, \"app.usage.nextTab\")) this.moveAccount(1, true);\n\t\telse if (kb.matches(data, \"app.usage.previousTab\")) this.moveAccount(-1, true);\n\t\telse if (kb.matches(data, \"app.usage.toggleDetails\")) {\n\t\t\tconst tab = this.selectedAccount;\n\t\t\tif (this.view !== \"accounts\" || !tab || !(\"kind\" in tab.overview) || !tab.overview.details.length) return;\n\t\t\tthis.expanded = !this.expanded;\n\t\t\tthis.detailFocus = true;\n\t\t\tthis.jumpToRecent = this.expanded;\n\t\t\tthis.scrollTop = 0;\n\t\t\tthis.regions = [];\n\t\t\tthis.requestRender();\n\t\t} else if (kb.matches(data, \"tui.select.confirm\") && this.view === \"accounts\" && this.selectedAccount) {\n\t\t\tthis.detailFocus = true;\n\t\t\tthis.regions = [];\n\t\t\tthis.requestRender();\n\t\t} else {\n\t\t\tlet delta = 0;\n\t\t\tif (kb.matches(data, \"tui.select.up\")) delta = -1;\n\t\t\telse if (kb.matches(data, \"tui.select.down\")) delta = 1;\n\t\t\telse if (kb.matches(data, \"tui.select.pageUp\")) delta = -this.viewportHeight;\n\t\t\telse if (kb.matches(data, \"tui.select.pageDown\")) delta = this.viewportHeight;\n\t\t\tif (delta) {\n\t\t\t\tif (this.view === \"accounts\" && !this.detailFocus) this.moveAccount(delta);\n\t\t\t\telse this.scrollBy(delta);\n\t\t\t}\n\t\t}\n\t}\n\n\thandleMouse(event: TuiMouseEvent): TuiMouseEventResult {\n\t\tif (this.disposed) return { handled: true, render: false };\n\t\tconst inBody = event.x >= 0 && event.x < this.renderedWidth && event.y >= 3 && event.y < 3 + this.viewportHeight;\n\t\tif (event.type === \"wheel\" && inBody) {\n\t\t\tconst inList = this.view === \"accounts\" && (this.listWidth > 0 ? event.x < this.listWidth : !this.detailFocus);\n\t\t\tconst delta = event.wheelDelta ?? 0;\n\t\t\tif (!delta) return { handled: true, render: false };\n\t\t\tconst focusChanged = this.detailFocus === inList;\n\t\t\tthis.detailFocus = !inList;\n\t\t\tconst changed = inList ? this.moveAccount(delta) : this.scrollBy(delta);\n\t\t\tif (focusChanged && !changed) this.requestRender();\n\t\t\treturn { handled: true, render: changed || focusChanged, focus: true };\n\t\t}\n\t\tif (event.type !== \"click\" || event.button !== \"left\") return { handled: true, render: false };\n\t\tconst region = this.regions.find(\n\t\t\t(item) => event.y === item.y && event.x >= item.x && event.x < item.x + item.width,\n\t\t);\n\t\tif (region) {\n\t\t\tregion.activate();\n\t\t\treturn { handled: true, render: true, focus: true };\n\t\t}\n\t\tif (inBody && this.view === \"accounts\" && this.listWidth > 0 && event.x > this.listWidth + 2) {\n\t\t\tthis.detailFocus = true;\n\t\t\tthis.requestRender();\n\t\t\treturn { handled: true, render: true, focus: true };\n\t\t}\n\t\treturn { handled: true, render: false };\n\t}\n\n\tinvalidate(): void {\n\t\tthis.regions = [];\n\t}\n\n\tprivate key(action: Keybinding): string {\n\t\tconst key = this.keybindings.getKeys(action)[0];\n\t\treturn key ? formatKeyText(key) : \"\";\n\t}\n\n\tprivate detailRows(tab: UsageTab, width: number): DetailRow[] {\n\t\tconst theme = this.theme;\n\t\tconst { providerId, modelId, bars, lines, notes } = tab.overview;\n\t\tconst session = this.view === \"session\";\n\t\tconst out: DetailRow[] = [];\n\t\tconst add = (text: string, action?: UsageAction, disabled?: boolean): void => {\n\t\t\tfor (const wrapped of wrapTextWithAnsi(text, width)) out.push({ text: wrapped, action, disabled });\n\t\t};\n\t\tconst row = (line: UsageLine): void => {\n\t\t\tconst label = usageDisplayText(line.label);\n\t\t\tconst padded = label + \" \".repeat(Math.max(0, 13 - visibleWidth(label)));\n\t\t\tconst text = usageDisplayText(line.value);\n\t\t\tconst value = line.tone ? theme.fg(TONE_COLOR[line.tone], text) : text;\n\t\t\tadd(` ${theme.fg(\"dim\", padded)} ${value}`);\n\t\t};\n\t\tconst addBars = (bars: UsageBar[]): void => {\n\t\t\tif (bars.length === 0) return;\n\t\t\tbars = bars.map((bar) => ({\n\t\t\t\t...bar,\n\t\t\t\tlabel: usageDisplayText(bar.label),\n\t\t\t\tdisplay: usageDisplayText(bar.display),\n\t\t\t\tnote: bar.note ? usageDisplayText(bar.note) : undefined,\n\t\t\t}));\n\t\t\t// Keep compact bars when they fit; stack and wrap details instead of truncating limits on narrow screens.\n\t\t\tconst displayWidth = Math.max(...bars.map((bar) => visibleWidth(bar.display)));\n\t\t\tconst labelWidth = Math.min(\n\t\t\t\tMath.max(...bars.map((bar) => visibleWidth(bar.label))),\n\t\t\t\tMath.max(0, width - 2 - MIN_BAR_WIDTH - 3 - displayWidth),\n\t\t\t);\n\t\t\tconst barWidth = Math.max(MIN_BAR_WIDTH, Math.min(BAR_WIDTH, width - 2 - labelWidth - 3 - displayWidth));\n\t\t\tfor (const bar of bars) {\n\t\t\t\tconst label = bar.label + \" \".repeat(Math.max(0, labelWidth - visibleWidth(bar.label)));\n\t\t\t\tconst head = ` ${theme.fg(\"dim\", label)} ${renderUsageBar(theme, bar, barWidth)} ${theme.fg(\"dim\", bar.display)}`;\n\t\t\t\tconst note = bar.note ? theme.fg(\"dim\", bar.note) : undefined;\n\t\t\t\tif (visibleWidth(head) > width) {\n\t\t\t\t\tadd(` ${theme.fg(\"dim\", `${bar.label} · ${bar.display}`)}`);\n\t\t\t\t\tadd(renderUsageBar(theme, bar, Math.min(BAR_WIDTH, width)));\n\t\t\t\t\tif (note) add(` ${note}`);\n\t\t\t\t} else if (note && visibleWidth(head) + 2 + visibleWidth(note) <= width) add(`${head} ${note}`);\n\t\t\t\telse {\n\t\t\t\t\tadd(head);\n\t\t\t\t\tif (note) add(` ${note}`);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tif (\"kind\" in tab.overview) {\n\t\t\tadd(theme.bold(usageDisplayText(modelId)));\n\t\t\tfor (const line of lines) {\n\t\t\t\tif (line.label === \"Resets\") addBars(bars);\n\t\t\t\tconst value = usageDisplayText(line.value);\n\t\t\t\tconst text = line.label ? `${theme.fg(\"dim\", `${usageDisplayText(line.label)}:`)} ${value}` : value;\n\t\t\t\tadd(line.tone ? theme.fg(TONE_COLOR[line.tone], text) : text);\n\t\t\t}\n\t\t\tfor (const note of notes) add(theme.fg(\"dim\", usageDisplayText(note)));\n\t\t\tif (this.expanded && tab.overview.details.length) {\n\t\t\t\tadd(\"\");\n\t\t\t\tout.push({ text: truncateToWidth(theme.bold(\"Recent requests\"), width, \"…\"), recent: true });\n\t\t\t\tfor (const detail of tab.overview.details) add(usageDisplayText(detail));\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tadd(\n\t\t\ttheme.bold(session ? \"This session\" : usageDisplayText(tab.label)) +\n\t\t\t\t(!session && tab.active ? ` ${theme.fg(\"success\", \"In use\")}` : \"\"),\n\t\t);\n\t\tadd(theme.fg(\"dim\", usageDisplayText(`${providerId} · ${modelId}`)));\n\t\tadd(\"\");\n\t\tif (!session) add(theme.bold(\"INCLUDED USAGE\"));\n\t\tconst includedBars = session ? bars : bars.filter((bar) => !bar.section);\n\t\taddBars(includedBars);\n\t\tfor (const line of lines) if (session || !line.section) row(line);\n\t\tif (tab.usageActions && this.onAction) {\n\t\t\tconst { refreshing, reconnect } = tab.usageActions;\n\t\t\tfor (const [action, label] of [\n\t\t\t\t[\"refresh\", refreshing ? \"Refreshing…\" : \"Refresh\"],\n\t\t\t\t...(reconnect ? ([[\"reconnect\", \"Reconnect\"]] as const) : []),\n\t\t\t] as const) {\n\t\t\t\tconst key = this.key(`app.usage.${action}`);\n\t\t\t\tadd(theme.fg(refreshing ? \"muted\" : \"accent\", `[${key ? `${key} ` : \"\"}${label}]`), action, refreshing);\n\t\t\t}\n\t\t}\n\t\tif (!session) {\n\t\t\tif (includedBars.length === 0 && !lines.some((line) => !line.section))\n\t\t\t\tadd(theme.fg(\"muted\", \" Usage not reported.\"));\n\t\t\tfor (const [section, title] of [\n\t\t\t\t[\"resets\", \"SAVED RESETS\"],\n\t\t\t\t[\"paid\", \"PAID USAGE\"],\n\t\t\t] as const) {\n\t\t\t\tadd(\"\");\n\t\t\t\tadd(theme.bold(title));\n\t\t\t\tconst sectionBars = bars.filter((bar) => bar.section === section);\n\t\t\t\taddBars(sectionBars);\n\t\t\t\tconst sectionLines = lines.filter((line) => line.section === section);\n\t\t\t\tfor (const line of sectionLines) row(line);\n\t\t\t\tif (sectionBars.length === 0 && sectionLines.length === 0) add(theme.fg(\"muted\", \" Not reported.\"));\n\t\t\t\tconst action = section === \"resets\" ? \"reset\" : \"billing\";\n\t\t\t\tconst label = section === \"resets\" ? tab.resetAction : this.onAction ? \"Open billing settings\" : undefined;\n\t\t\t\tif (label) {\n\t\t\t\t\tconst key = this.key(`app.usage.${action}`);\n\t\t\t\t\tconst disabled = !this.onAction || (action === \"reset\" && tab.resetDisabled === true);\n\t\t\t\t\tconst text = `[${key ? `${key} ` : \"\"}${usageDisplayText(label)}]${disabled ? \" (disabled)\" : \"\"}`;\n\t\t\t\t\tadd(theme.fg(disabled ? \"muted\" : \"accent\", text), action, disabled);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (notes.length > 0) {\n\t\t\tadd(\"\");\n\t\t\tfor (const note of notes) add(theme.fg(\"warning\", usageDisplayText(note)));\n\t\t}\n\t\treturn out;\n\t}\n\n\tprivate accountRows(width: number, height: number): string[] {\n\t\tconst accounts = this.accounts;\n\t\tconst selected = this.selectedAccount;\n\t\tconst all: { text: string; provider: string; account?: UsageTab }[] = [];\n\t\tlet provider: string | undefined;\n\t\tfor (const account of accounts) {\n\t\t\tif (provider !== account.overview.providerId) {\n\t\t\t\tprovider = account.overview.providerId;\n\t\t\t\tall.push({ text: this.theme.fg(\"muted\", this.theme.bold(providerLabel(provider))), provider });\n\t\t\t}\n\t\t\tconst marker = account.id === selected?.id ? \"> \" : \" \";\n\t\t\tconst label = truncateToWidth(usageDisplayText(account.label), Math.max(0, width - 2), \"…\");\n\t\t\tconst status = account.active && visibleWidth(label) + 9 <= width ? this.theme.fg(\"success\", \" In use\") : \"\";\n\t\t\tconst text = `${marker}${label}`;\n\t\t\tall.push({\n\t\t\t\ttext: (account.id === selected?.id ? this.theme.fg(\"accent\", this.theme.bold(text)) : text) + status,\n\t\t\t\tprovider: account.overview.providerId,\n\t\t\t\taccount,\n\t\t\t});\n\t\t}\n\t\tif (all.length === 0) return wrapTextWithAnsi(\"No saved accounts. Run /login.\", width).slice(0, height);\n\t\tconst selectedRow = all.findIndex((row) => row.account?.id === selected?.id);\n\t\tlet start = Math.max(0, Math.min(selectedRow - Math.floor((height - 1) / 2), all.length - height));\n\t\tconst sticky = start > 0 && all[start].account && height > 1;\n\t\tif (sticky && selectedRow >= start + height - 1) start = selectedRow - height + 2;\n\t\tconst visible = all.slice(start, start + height - (sticky ? 1 : 0));\n\t\tconst output: string[] = [];\n\t\tif (sticky) output.push(this.theme.fg(\"muted\", this.theme.bold(providerLabel(all[start].provider))));\n\t\tfor (const row of visible) {\n\t\t\tif (row.account) {\n\t\t\t\tconst id = row.account.id;\n\t\t\t\tthis.regions.push({\n\t\t\t\t\tx: 0,\n\t\t\t\t\ty: 3 + output.length,\n\t\t\t\t\twidth,\n\t\t\t\t\tactivate: () => {\n\t\t\t\t\t\tthis.detailFocus = this.listWidth === 0;\n\t\t\t\t\t\tthis.selectAccount(id);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\toutput.push(truncateToWidth(row.text, width, \"…\"));\n\t\t}\n\t\treturn output;\n\t}\n\n\trender(width: number): string[] {\n\t\tthis.regions = [];\n\t\tif (this.disposed || width < 1) return [];\n\t\tconst theme = this.theme;\n\t\tthis.renderedWidth = width;\n\t\tconst accounts = this.accounts;\n\t\tconst selected = this.selectedAccount;\n\t\tthis.listWidth = this.view === \"accounts\" && width >= 76 ? Math.min(46, Math.floor(width / 2)) : 0;\n\t\tconst split = this.listWidth > 0;\n\t\tconst showingList = this.view === \"accounts\" && !this.detailFocus;\n\t\tconst detailWidth = split ? width - this.listWidth - 3 : width;\n\t\tconst tab = this.view === \"session\" ? this.tabs.find((item) => item.id === \"session\") : selected;\n\t\tconst details: DetailRow[] = tab ? this.detailRows(tab, detailWidth) : [{ text: \"No usage data available.\" }];\n\t\tconst controls = (\n\t\t\t[\n\t\t\t\t[\"accounts\", \"app.usage.showAccounts\", \"Accounts\"],\n\t\t\t\t[\"session\", \"app.usage.showSession\", \"Session\"],\n\t\t\t] as const\n\t\t).map(([view, action, label]) => {\n\t\t\tconst key = this.key(action);\n\t\t\treturn { view, text: `[${key ? `${key} ` : \"\"}${label}]` };\n\t\t});\n\t\tconst stackedControls = controls.reduce((sum, control) => sum + visibleWidth(control.text), 2) > width;\n\t\tlet controlX = 0;\n\t\tconst navigation = controls.map(({ view, text }, index) => {\n\t\t\tconst x = stackedControls ? 0 : controlX;\n\t\t\tthis.regions.push({\n\t\t\t\tx,\n\t\t\t\ty: stackedControls ? index : 1,\n\t\t\t\twidth: Math.min(visibleWidth(text), width - x),\n\t\t\t\tactivate: () => this.showView(view),\n\t\t\t});\n\t\t\tcontrolX += visibleWidth(text) + 2;\n\t\t\treturn this.view === view ? theme.fg(\"accent\", theme.bold(text)) : theme.fg(\"muted\", text);\n\t\t});\n\t\tconst header = stackedControls ? navigation : [theme.bold(\"Usage\"), navigation.join(\" \")];\n\t\tconst selectKeys = [this.key(\"tui.select.up\"), this.key(\"tui.select.down\")].filter(Boolean).join(\"/\");\n\t\tconst confirm = showingList && selected ? this.key(\"tui.select.confirm\") : \"\";\n\t\tconst cycleKeys =\n\t\t\tthis.view === \"accounts\"\n\t\t\t\t? [this.key(\"app.usage.nextTab\"), this.key(\"app.usage.previousTab\")].filter(Boolean).join(\"/\")\n\t\t\t\t: \"\";\n\t\tconst cancel = this.key(\"tui.select.cancel\");\n\t\tconst footerParts = [\n\t\t\tselectKeys ? `${selectKeys} ${showingList ? \"select\" : \"scroll\"}` : \"\",\n\t\t\tconfirm ? `${confirm} details` : \"\",\n\t\t];\n\t\tif (cycleKeys && width >= 60) footerParts.push(`${cycleKeys} cycle`);\n\t\tconst actionHints: string[] = [];\n\t\tif (\n\t\t\tthis.view === \"accounts\" &&\n\t\t\tselected &&\n\t\t\tselected.overview.providerId !== \"humain-code-account\" &&\n\t\t\tthis.onAction\n\t\t) {\n\t\t\tfor (const [action, label, enabled] of [\n\t\t\t\t[\"reset\", \"saved reset\", selected.resetAction && !selected.resetDisabled],\n\t\t\t\t[\"billing\", \"billing settings\", true],\n\t\t\t\t[\"refresh\", \"Refresh\", selected.usageActions && !selected.usageActions.refreshing],\n\t\t\t\t[\"reconnect\", \"Reconnect\", selected.usageActions?.reconnect && !selected.usageActions.refreshing],\n\t\t\t] as const) {\n\t\t\t\tconst key = this.key(`app.usage.${action}`);\n\t\t\t\tif (key && enabled) actionHints.push(theme.fg(\"accent\", `${key} ${label}`));\n\t\t\t}\n\t\t}\n\t\tif (this.view === \"accounts\" && selected && \"kind\" in selected.overview && selected.overview.details.length) {\n\t\t\tconst key = this.key(\"app.usage.toggleDetails\");\n\t\t\tif (key) actionHints.push(`${key} ${this.expanded ? \"hide details\" : \"details\"}`);\n\t\t}\n\t\tconst footer = [\n\t\t\t...wrapTextWithAnsi(footerParts.filter(Boolean).join(\" · \"), width),\n\t\t\t...wrapTextWithAnsi(\n\t\t\t\t[\n\t\t\t\t\tcancel ? `${cancel} ${this.view === \"accounts\" && this.detailFocus ? \"accounts\" : \"close\"}` : \"\",\n\t\t\t\t\t...actionHints,\n\t\t\t\t]\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.join(\" · \"),\n\t\t\t\twidth,\n\t\t\t),\n\t\t];\n\t\tconst height = Math.max(1, Math.floor(this.getHeight()));\n\t\tconst visibleFooter = footer.slice(0, Math.max(0, height - 4));\n\t\tthis.viewportHeight = Math.max(1, height - 3 - visibleFooter.length);\n\t\tthis.maxScrollTop = Math.max(0, details.length - this.viewportHeight);\n\t\tif (this.jumpToRecent) {\n\t\t\tthis.scrollTop = Math.max(\n\t\t\t\t0,\n\t\t\t\tdetails.findIndex((row) => row.recent),\n\t\t\t);\n\t\t\tthis.jumpToRecent = false;\n\t\t}\n\t\tthis.scrollTop = Math.min(this.scrollTop, this.maxScrollTop);\n\t\tconst accountHeading = `Accounts ${selected ? accounts.findIndex((item) => item.id === selected.id) + 1 : 0}/${accounts.length}`;\n\t\tconst detailHeading = `${this.view === \"session\" ? \"Session\" : \"Details\"}${this.detailFocus ? \" (focused)\" : \"\"} ${this.scrollTop + 1}/${this.maxScrollTop + 1}`;\n\t\tconst heading = split\n\t\t\t? usagePaneRow(theme, theme.bold(accountHeading), theme.bold(detailHeading), this.listWidth)\n\t\t\t: theme.bold(showingList ? accountHeading : detailHeading);\n\t\tconst list =\n\t\t\tthis.view === \"accounts\" && (split || showingList)\n\t\t\t\t? this.accountRows(split ? this.listWidth : width, this.viewportHeight)\n\t\t\t\t: [];\n\t\tconst body: string[] = [];\n\t\tfor (let index = 0; index < this.viewportHeight; index++) {\n\t\t\tconst row = details[this.scrollTop + index];\n\t\t\tif (row?.action && !row.disabled && (!showingList || split)) {\n\t\t\t\tconst action = row.action;\n\t\t\t\tthis.regions.push({\n\t\t\t\t\tx: split ? this.listWidth + 3 : 0,\n\t\t\t\t\ty: 3 + index,\n\t\t\t\t\twidth: visibleWidth(row.text),\n\t\t\t\t\tactivate: () => this.invokeAction(action),\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst detailText = row?.text ?? \"\";\n\t\t\tbody.push(\n\t\t\t\tsplit\n\t\t\t\t\t? usagePaneRow(theme, list[index] ?? \"\", detailText, this.listWidth)\n\t\t\t\t\t: showingList\n\t\t\t\t\t\t? (list[index] ?? \"\")\n\t\t\t\t\t\t: detailText,\n\t\t\t);\n\t\t}\n\t\t// A line wider than the terminal aborts rendering.\n\t\treturn [...header, heading, ...body, ...visibleFooter.map((line) => theme.fg(\"muted\", line))]\n\t\t\t.slice(0, height)\n\t\t\t.map((line) => truncateToWidth(process.env.NO_COLOR ? stripTerminalSequences(line) : line, width, \"…\"));\n\t}\n}\n"]}
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/humain/gateway/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAI1E,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,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElG,KAAK,iBAAiB,GAAG,cAAc,GAAG,QAAQ,GAA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AsB,mBAAmB,CACxC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EACxD,OAAO,EAAE,qBAAqB,GAC5B,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,eAAe,CAAA;CAAE,CAAC,CAgDvD;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;AA0CD,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"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SafeCredentialError } from "../../core/safe-credential-error.js";
|
|
2
|
+
import { sleep } from "../../utils/sleep.js";
|
|
2
3
|
import { GATEWAY_TOKEN_PATTERN, GATEWAY_USER_AGENT } from "./constants.js";
|
|
3
4
|
const LOGIN_MESSAGES = {
|
|
4
5
|
"invalid-request": "HUMAIN Gateway rejected the sign-in exchange request.",
|
|
@@ -36,7 +37,9 @@ export class GatewayMalformedResponseError extends SafeCredentialError {
|
|
|
36
37
|
export class GatewayRequestError extends SafeCredentialError {
|
|
37
38
|
status;
|
|
38
39
|
constructor(status) {
|
|
39
|
-
super(
|
|
40
|
+
super(status >= 500 && status < 600
|
|
41
|
+
? `HUMAIN Gateway is temporarily unavailable (${status}); your saved sign-in is unchanged. Wait and retry /model.`
|
|
42
|
+
: `HUMAIN Gateway request failed with status ${status}.`);
|
|
40
43
|
this.name = "GatewayRequestError";
|
|
41
44
|
this.status = status;
|
|
42
45
|
}
|
|
@@ -93,8 +96,9 @@ export async function exchangeHandoffCode(base, input, options) {
|
|
|
93
96
|
}
|
|
94
97
|
if (response.status === 405)
|
|
95
98
|
throw new GatewayLoginError("method-not-allowed");
|
|
96
|
-
if (response.status
|
|
97
|
-
throw new GatewayLoginError("unavailable");
|
|
99
|
+
if (response.status >= 500 && response.status < 600) {
|
|
100
|
+
throw new GatewayLoginError("unavailable", `HUMAIN Gateway is temporarily unavailable (${response.status}); no new session was saved. Try /login again.`);
|
|
101
|
+
}
|
|
98
102
|
if (response.status === 400) {
|
|
99
103
|
const text = (await response.text().catch(() => "")).trim();
|
|
100
104
|
throw new GatewayLoginError(text === "invalid exchange request" ? "invalid-request" : "invalid-code");
|
|
@@ -135,12 +139,21 @@ export async function revokeSession(base, token, options) {
|
|
|
135
139
|
}
|
|
136
140
|
async function authedGet(base, path, token, options) {
|
|
137
141
|
const doFetch = options.fetch ?? fetch;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
let response;
|
|
143
|
+
for (let attempt = 0;; attempt++) {
|
|
144
|
+
options.signal.throwIfAborted();
|
|
145
|
+
response = await doFetch(`${base}${path}`, {
|
|
146
|
+
method: "GET",
|
|
147
|
+
redirect: "error",
|
|
148
|
+
signal: options.signal,
|
|
149
|
+
headers: baseHeaders(token),
|
|
150
|
+
});
|
|
151
|
+
const delay = discoveryRetryDelay(response, attempt);
|
|
152
|
+
if (delay === undefined)
|
|
153
|
+
break;
|
|
154
|
+
await response.body?.cancel().catch(() => undefined);
|
|
155
|
+
await sleep(delay, options.signal);
|
|
156
|
+
}
|
|
144
157
|
if (response.status === 401)
|
|
145
158
|
throw new GatewaySessionUnavailableError();
|
|
146
159
|
if (response.status === 429) {
|
|
@@ -154,6 +167,20 @@ async function authedGet(base, path, token, options) {
|
|
|
154
167
|
throw new GatewayRequestError(response.status);
|
|
155
168
|
return readJson(response);
|
|
156
169
|
}
|
|
170
|
+
/** Only discovery GETs are replayable; exchange codes and billed model requests are not. */
|
|
171
|
+
function discoveryRetryDelay(response, attempt) {
|
|
172
|
+
if (attempt >= 2 || ![500, 502, 503, 504].includes(response.status))
|
|
173
|
+
return undefined;
|
|
174
|
+
if (response.headers.get("x-should-retry") === "false")
|
|
175
|
+
return undefined;
|
|
176
|
+
const backoff = 500 * 2 ** attempt;
|
|
177
|
+
const retryAfter = response.headers.get("retry-after");
|
|
178
|
+
if (retryAfter === null)
|
|
179
|
+
return backoff;
|
|
180
|
+
const delay = /^\d+$/u.test(retryAfter.trim()) ? Number(retryAfter) * 1000 : Date.parse(retryAfter) - Date.now();
|
|
181
|
+
// As in Node discovery, fail rather than wait indefinitely or retry before the server permits it.
|
|
182
|
+
return Number.isFinite(delay) && delay <= 2000 ? Math.max(backoff, delay) : undefined;
|
|
183
|
+
}
|
|
157
184
|
export async function fetchGatewayModels(base, token, options) {
|
|
158
185
|
const body = await authedGet(base, "/v1/models", token, options);
|
|
159
186
|
if (!isObject(body) || !Array.isArray(body.data))
|
|
@@ -1 +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;AAgC3E,MAAM,cAAc,GAA0C;IAC7D,iBAAiB,EAAE,uDAAuD;IAC1E,cAAc,EAAE,mEAAmE;IACnF,oBAAoB,EAAE,4DAA4D;IAClF,WAAW,EAAE,2EAA2E;IACxF,oBAAoB,EAAE,yDAAyD;CAC/E,CAAC;AAEF,MAAM,OAAO,iBAAkB,SAAQ,mBAAmB;IAChD,IAAI,CAAwB;IACrC,YAAY,IAA2B,EA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AAI,GAAG,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACnC,OAAO;QACN,UAAU,EAAE,IAAI,KAAK,SAAS,IAAI,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,IAA0B,CAAC,CAAC,CAAC,SAAS;QACvG,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,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 =\n\t| \"invalid-request\"\n\t| \"invalid-code\"\n\t| \"method-not-allowed\"\n\t| \"unavailable\"\n\t| \"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\"method-not-allowed\": \"HUMAIN Gateway did not accept the sign-in exchange method.\",\n\tunavailable: \"HUMAIN Gateway sign-in is temporarily unavailable. Start a fresh sign-in.\",\n\t\"malformed-response\": \"HUMAIN Gateway returned an unexpected sign-in response.\",\n};\n\nexport class GatewayLoginError extends SafeCredentialError {\n\treadonly kind: GatewayLoginErrorKind;\n\tconstructor(kind: GatewayLoginErrorKind, message = LOGIN_MESSAGES[kind]) {\n\t\tsuper(message);\n\t\tthis.name = \"GatewayLoginError\";\n\t\tthis.kind = kind;\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; verifier: 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: \"humain-code\",\n\t\tcode_verifier: input.verifier,\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 === 405) throw new GatewayLoginError(\"method-not-allowed\");\n\tif (response.status === 503) throw new GatewayLoginError(\"unavailable\");\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"]}
|
|
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,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAgC3E,MAAM,cAAc,GAA0C;IAC7D,iBAAiB,EAAE,uDAAuD;IAC1E,cAAc,EAAE,mEAAmE;IACnF,oBAAoB,EAAE,4DAA4D;IAClF,WAAW,EAAE,2EAA2E;IACxF,oBAAoB,EAAE,yDAAyD;CAC/E,CAAC;AAEF,MAAM,OAAO,iBAAkB,SAAQ,mBAAmB;IAChD,IAAI,CAAwB;IACrC,YAAY,IAA2B,EAAE,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC;QACtE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAED,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IACrD,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC3C,CAAC;CACD;AAED,MAAM,OAAO,8BAA+B,SAAQ,mBAAmB;IACtE;QACC,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC9C,CAAC;CACD;AAED,MAAM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AC,CAAE,IAA0B,CAAC,CAAC,CAAC,SAAS;QACvG,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,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 { sleep } from \"../../utils/sleep.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 =\n\t| \"invalid-request\"\n\t| \"invalid-code\"\n\t| \"method-not-allowed\"\n\t| \"unavailable\"\n\t| \"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\"method-not-allowed\": \"HUMAIN Gateway did not accept the sign-in exchange method.\",\n\tunavailable: \"HUMAIN Gateway sign-in is temporarily unavailable. Start a fresh sign-in.\",\n\t\"malformed-response\": \"HUMAIN Gateway returned an unexpected sign-in response.\",\n};\n\nexport class GatewayLoginError extends SafeCredentialError {\n\treadonly kind: GatewayLoginErrorKind;\n\tconstructor(kind: GatewayLoginErrorKind, message = LOGIN_MESSAGES[kind]) {\n\t\tsuper(message);\n\t\tthis.name = \"GatewayLoginError\";\n\t\tthis.kind = kind;\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(\n\t\t\tstatus >= 500 && status < 600\n\t\t\t\t? `HUMAIN Gateway is temporarily unavailable (${status}); your saved sign-in is unchanged. Wait and retry /model.`\n\t\t\t\t: `HUMAIN Gateway request failed with status ${status}.`,\n\t\t);\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; verifier: 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: \"humain-code\",\n\t\tcode_verifier: input.verifier,\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 === 405) throw new GatewayLoginError(\"method-not-allowed\");\n\tif (response.status >= 500 && response.status < 600) {\n\t\tthrow new GatewayLoginError(\n\t\t\t\"unavailable\",\n\t\t\t`HUMAIN Gateway is temporarily unavailable (${response.status}); no new session was saved. Try /login again.`,\n\t\t);\n\t}\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\tlet response: Response;\n\tfor (let attempt = 0; ; attempt++) {\n\t\toptions.signal.throwIfAborted();\n\t\tresponse = await doFetch(`${base}${path}`, {\n\t\t\tmethod: \"GET\",\n\t\t\tredirect: \"error\",\n\t\t\tsignal: options.signal,\n\t\t\theaders: baseHeaders(token),\n\t\t});\n\t\tconst delay = discoveryRetryDelay(response, attempt);\n\t\tif (delay === undefined) break;\n\t\tawait response.body?.cancel().catch(() => undefined);\n\t\tawait sleep(delay, options.signal);\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\n/** Only discovery GETs are replayable; exchange codes and billed model requests are not. */\nfunction discoveryRetryDelay(response: Response, attempt: number): number | undefined {\n\tif (attempt >= 2 || ![500, 502, 503, 504].includes(response.status)) return undefined;\n\tif (response.headers.get(\"x-should-retry\") === \"false\") return undefined;\n\tconst backoff = 500 * 2 ** attempt;\n\tconst retryAfter = response.headers.get(\"retry-after\");\n\tif (retryAfter === null) return backoff;\n\tconst delay = /^\\d+$/u.test(retryAfter.trim()) ? Number(retryAfter) * 1000 : Date.parse(retryAfter) - Date.now();\n\t// As in Node discovery, fail rather than wait indefinitely or retry before the server permits it.\n\treturn Number.isFinite(delay) && delay <= 2000 ? Math.max(backoff, delay) : undefined;\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"]}
|
|
@@ -1 +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;
|
|
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;AAgB/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;AA+BD;;;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,CAsLvG"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { lazyStream, } from "@earendil-works/pi-ai";
|
|
2
|
+
import { truncateErrorText } from "@earendil-works/pi-ai/utils/error-body";
|
|
2
3
|
import { sleep } from "../../utils/sleep.js";
|
|
3
4
|
import { redactAssistantMessage } from "../redact-assistant-message.js";
|
|
4
5
|
import { isObject } from "./client.js";
|
|
@@ -11,7 +12,7 @@ const MAX_ERROR_BODY_BYTES = 65_536;
|
|
|
11
12
|
const OVERSIZE_MESSAGE = "Request is larger than HUMAIN Gateway's 20 MiB limit.";
|
|
12
13
|
const REQUEST_CEILING_MS = 900_000;
|
|
13
14
|
const CEILING_MESSAGE = "HUMAIN Gateway request exceeded the 900-second limit.";
|
|
14
|
-
/**
|
|
15
|
+
/** Reads at most MAX_ERROR_BODY_BYTES as JSON or plain proxy text; larger or unreadable bodies yield `undefined`. */
|
|
15
16
|
async function readErrorBody(response) {
|
|
16
17
|
if (Number(response.headers.get("content-length")) > MAX_ERROR_BODY_BYTES)
|
|
17
18
|
return undefined;
|
|
@@ -38,11 +39,12 @@ async function readErrorBody(response) {
|
|
|
38
39
|
// Stops the clone's tee from buffering the rest of the body.
|
|
39
40
|
reader.cancel().catch(() => undefined);
|
|
40
41
|
}
|
|
42
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
41
43
|
try {
|
|
42
|
-
return JSON.parse(
|
|
44
|
+
return JSON.parse(text);
|
|
43
45
|
}
|
|
44
46
|
catch {
|
|
45
|
-
return
|
|
47
|
+
return text;
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
@@ -174,6 +176,14 @@ export function withHumainGatewayHttp(api, deps = {}) {
|
|
|
174
176
|
if (!decision.retry || attempt + 1 >= MAX_ATTEMPTS) {
|
|
175
177
|
httpError.status = response.status;
|
|
176
178
|
const error = isObject(responseBody) ? responseBody.error : undefined;
|
|
179
|
+
if (response.status >= 500 && response.status <= 599) {
|
|
180
|
+
const upstream = isObject(error) ? error.message : (error ?? responseBody);
|
|
181
|
+
if (typeof upstream === "string") {
|
|
182
|
+
// Sanitize the whole upstream text before extracting/bounding a reset reason.
|
|
183
|
+
const safe = truncateErrorText(key ? upstream.replaceAll(key, "[REDACTED]") : upstream, MAX_ERROR_BODY_BYTES);
|
|
184
|
+
httpError.reason = truncateErrorText(`HTTP ${response.status}: ${safe.match(/\breset reason:[^\r\n]*/iu)?.[0] ?? safe}`, 120).replace(/\s+/gu, " ");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
177
187
|
const code = isObject(error) ? (error.code ?? error.type) : undefined;
|
|
178
188
|
if (typeof code === "string")
|
|
179
189
|
httpError.code = key ? code.replaceAll(key, "[redacted]") : code;
|
|
@@ -209,11 +219,21 @@ export function withHumainGatewayHttp(api, deps = {}) {
|
|
|
209
219
|
event.reason = "error";
|
|
210
220
|
event.error.stopReason = "error";
|
|
211
221
|
}
|
|
222
|
+
const status = httpError.status;
|
|
223
|
+
const unavailable = typeof status === "number" &&
|
|
224
|
+
status >= 500 &&
|
|
225
|
+
status <= 599 &&
|
|
226
|
+
event.reason !== "aborted" &&
|
|
227
|
+
!options?.signal?.aborted;
|
|
212
228
|
const requestId = httpError.requestId;
|
|
213
229
|
event.error.errorMessage = [
|
|
214
|
-
failure ??
|
|
215
|
-
|
|
216
|
-
|
|
230
|
+
failure ??
|
|
231
|
+
(unavailable
|
|
232
|
+
? `HUMAIN Gateway is temporarily unavailable (HTTP ${status}). Try again in a moment.`
|
|
233
|
+
: event.error.errorMessage) ??
|
|
234
|
+
"HUMAIN Gateway request failed",
|
|
235
|
+
!unavailable && typeof httpError.code === "string" && `code: ${httpError.code}`,
|
|
236
|
+
!unavailable && typeof requestId === "string" && `x-litellm-call-id: ${requestId}`,
|
|
217
237
|
]
|
|
218
238
|
.filter(Boolean)
|
|
219
239
|
.join("; ");
|