@humain/humain-code 0.8.4 → 0.8.7
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 +31 -0
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/{anthropic-messages-42CGJCSR.js → anthropic-messages-QMSJV4J5.js} +3 -3
- package/dist/bundle/chunks/{ask-VH7GNX75.js → ask-VVSJA5VG.js} +2 -2
- package/dist/bundle/chunks/{azure-openai-responses-DOKKMBUN.js → azure-openai-responses-P57ZD6XP.js} +3 -3
- package/dist/bundle/chunks/chunk-2QVKRSKH.js +4 -0
- package/dist/bundle/chunks/{chunk-OTVHRZ67.js → chunk-3BZUQ54Z.js} +1 -1
- package/dist/bundle/chunks/{chunk-XGOJCV6Z.js → chunk-4K6ISLTX.js} +1 -1
- package/dist/bundle/chunks/{chunk-BNZZJ4LO.js → chunk-4QVJYVS5.js} +1 -1
- package/dist/bundle/chunks/{chunk-MXF3KYLZ.js → chunk-4UXFF4IH.js} +1 -1
- package/dist/bundle/chunks/{chunk-J5YFXMTM.js → chunk-6PJEPQBW.js} +2 -2
- package/dist/bundle/chunks/{chunk-4SL6URR3.js → chunk-7X7QN6MX.js} +5 -3
- package/dist/bundle/chunks/{chunk-XGSJX23G.js → chunk-A7AH3VMJ.js} +69 -66
- package/dist/bundle/chunks/{chunk-H35P7ROY.js → chunk-B345VDHB.js} +9 -7
- package/dist/bundle/chunks/{chunk-A5ZMBTTM.js → chunk-B57IK7TV.js} +2 -2
- package/dist/bundle/chunks/{chunk-KJ3QRSSY.js → chunk-BVBEJBVY.js} +1 -1
- package/dist/bundle/chunks/{chunk-AER66CNP.js → chunk-BXDTDGHH.js} +1 -1
- package/dist/bundle/chunks/chunk-CDLUE6BJ.js +4 -0
- package/dist/bundle/chunks/{chunk-FLWO3H5J.js → chunk-DBC6XUKA.js} +1 -1
- package/dist/bundle/chunks/{chunk-HWXQCJDP.js → chunk-EB2ZJYOO.js} +295 -254
- package/dist/bundle/chunks/{chunk-4BNDLR6C.js → chunk-EK4QE622.js} +147 -37
- package/dist/bundle/chunks/{chunk-K5EFEIFP.js → chunk-H6CKS7HC.js} +1 -1
- package/dist/bundle/chunks/{chunk-UTRUALFN.js → chunk-HV25WMNO.js} +1 -1
- package/dist/bundle/chunks/{chunk-73YX5XGR.js → chunk-IP7R6BIN.js} +1079 -657
- package/dist/bundle/chunks/{chunk-HRNYDRL7.js → chunk-J5R2BQJS.js} +1 -1
- package/dist/bundle/chunks/{chunk-5C5K4EVJ.js → chunk-JNSFJADB.js} +1 -1
- package/dist/bundle/chunks/{chunk-CG43CMFH.js → chunk-KBIPIIKE.js} +1 -1
- package/dist/bundle/chunks/{chunk-CIAXW64K.js → chunk-MS3SLC2V.js} +10 -10
- package/dist/bundle/chunks/{chunk-WCKS2DPT.js → chunk-NO6T6CDO.js} +1 -1
- package/dist/bundle/chunks/{chunk-EVDQRT3I.js → chunk-NSSJ6OJK.js} +141 -225
- package/dist/bundle/chunks/{chunk-MZYHSWHX.js → chunk-OR3ORXP3.js} +2 -2
- package/dist/bundle/chunks/{chunk-MLOUZAVZ.js → chunk-PU7SKUJ6.js} +2 -2
- package/dist/bundle/chunks/{chunk-QZXLTW7V.js → chunk-RRGJHRKF.js} +1 -1
- package/dist/bundle/chunks/{chunk-625QJSFJ.js → chunk-SDPK3KZ3.js} +1 -1
- package/dist/bundle/chunks/{chunk-ZFFDBTG3.js → chunk-SPLJOIKL.js} +1 -1
- package/dist/bundle/chunks/{chunk-O44A4E4K.js → chunk-TNKPCYIM.js} +1 -1
- package/dist/bundle/chunks/{chunk-5KUCY54O.js → chunk-UY5TOBH2.js} +1 -1
- package/dist/bundle/chunks/{chunk-ARTF7ZMQ.js → chunk-VFPA5KPR.js} +1 -1
- package/dist/bundle/chunks/chunk-VP27C46J.js +23 -0
- package/dist/bundle/chunks/{chunk-B3FT6L6S.js → chunk-XZJT5U3V.js} +1 -1
- package/dist/bundle/chunks/{chunk-UOSJTMCL.js → chunk-YCGPXBJP.js} +1 -1
- package/dist/bundle/chunks/{chunk-52642TYH.js → chunk-YRSNKHEF.js} +389 -783
- package/dist/bundle/chunks/{chunk-MQYR4Q6X.js → chunk-YSRWNEZW.js} +1 -1
- package/dist/bundle/chunks/{chunk-SOE25WIS.js → chunk-ZAO4KC6J.js} +1054 -1069
- package/dist/bundle/chunks/{chunk-V2HTCZRF.js → chunk-ZXOTVZUX.js} +1 -1
- package/dist/bundle/chunks/{chunk-T5WECB2D.js → chunk-ZZNGVD5Q.js} +1 -1
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-ZAZW4M4B.js → cloudflare-workers-ai-system-one-4BO66KHO.js} +1 -1
- package/dist/bundle/chunks/{compat-7UJJAO4E.js → compat-EOHVO2W3.js} +4 -4
- package/dist/bundle/chunks/{curator-server-MW645JI3.js → curator-server-72V7LMHQ.js} +1 -1
- package/dist/bundle/chunks/{dist-7PCCEUQF.js → dist-FW7ELRQH.js} +1 -1
- package/dist/bundle/chunks/{dist-I53JI67E.js → dist-YEVRRTWL.js} +8 -8
- package/dist/bundle/chunks/{dist-VXQT3DQY.js → dist-ZRUKAVTU.js} +3 -3
- package/dist/bundle/chunks/{doctor-KJVAYG3F.js → doctor-HJKC434Y.js} +29 -28
- package/dist/bundle/chunks/{easter-egg-3d-Z24JLXD4.js → easter-egg-3d-M37PJBL5.js} +1 -1
- package/dist/bundle/chunks/entry-M5TRX7N4.js +2 -0
- package/dist/bundle/chunks/{execute-C4BZQRPQ.js → execute-MIXK3CFW.js} +2 -2
- package/dist/bundle/chunks/{extract-XVQCIS7D.js → extract-WB6Y6ISY.js} +2 -2
- package/dist/bundle/chunks/{flow-implementer-GE2ARQKR.js → flow-implementer-ZNK5KVOG.js} +5 -5
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/{google-generative-ai-P2P45MYP.js → google-generative-ai-B2BT7X4W.js} +3 -3
- package/dist/bundle/chunks/{google-vertex-SHY4IS5F.js → google-vertex-PCFDFRHY.js} +3 -3
- package/dist/bundle/chunks/{host-YESS2VAB.js → host-RF6R6GLZ.js} +1 -1
- package/dist/bundle/chunks/{inprocess-MGMVI6HN.js → inprocess-6MLIANGV.js} +6 -6
- package/dist/bundle/chunks/interactive-mode-QKREO5BH.js +6 -0
- package/dist/bundle/chunks/{llama-cpp-classify-RSRH4KV2.js → llama-cpp-classify-DMJSUUAD.js} +1 -1
- package/dist/bundle/chunks/{mistral-conversations-YTMJKHHI.js → mistral-conversations-OXWTIYWX.js} +2 -2
- package/dist/bundle/chunks/{openai-codex-responses-NUCJOJSZ.js → openai-codex-responses-YGXOZKWL.js} +3 -3
- package/dist/bundle/chunks/{openai-completions-E5NRJUHA.js → openai-completions-WDVOHMN6.js} +4 -4
- package/dist/bundle/chunks/{openai-decisions-342J5ZYG.js → openai-decisions-45LGQAD5.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-BN5Z4HFI.js → openai-responses-OZDPUN4M.js} +3 -3
- package/dist/bundle/chunks/{openrouter-images-7RNG3JVF.js → openrouter-images-2IKRVRTZ.js} +2 -2
- package/dist/bundle/chunks/{pi-messages-2L7FV5OK.js → pi-messages-VZOJLMWW.js} +2 -2
- package/dist/bundle/chunks/{questionnaire-session-XEVAK7JS.js → questionnaire-session-RSZE5I3P.js} +2 -2
- package/dist/bundle/chunks/{session-picker-666KJIVM.js → session-picker-EUPZJEFF.js} +2 -2
- package/dist/bundle/chunks/{startup-ui-INEVSNGK.js → startup-ui-RTSTUGUC.js} +2 -2
- package/dist/bundle/chunks/{typesafe-system-one-UJUNSZG4.js → typesafe-system-one-IVWD24CQ.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-UXSSFNV5.js → virtual-modules-LS3DOCYU.js} +8 -8
- package/dist/bundle/cli-runtime.js +5 -5
- package/dist/bundle/flow/package.json +1 -1
- package/dist/bundle/index.js +11 -11
- package/dist/bundle/rpc-entry.js +5 -5
- package/dist/coordination/adapter/delivery.d.ts +6 -0
- package/dist/coordination/adapter/delivery.d.ts.map +1 -1
- package/dist/coordination/adapter/delivery.js +39 -4
- package/dist/coordination/adapter/delivery.js.map +1 -1
- package/dist/coordination/adapter/index.d.ts +2 -0
- package/dist/coordination/adapter/index.d.ts.map +1 -1
- package/dist/coordination/adapter/index.js +26 -0
- package/dist/coordination/adapter/index.js.map +1 -1
- package/dist/coordination/adapter/tool.js +3 -3
- package/dist/coordination/adapter/tool.js.map +1 -1
- package/dist/core/bug-report.d.ts +24 -1
- package/dist/core/bug-report.d.ts.map +1 -1
- package/dist/core/bug-report.js +216 -19
- package/dist/core/bug-report.js.map +1 -1
- package/dist/core/extensions/containment.d.ts +26 -0
- package/dist/core/extensions/containment.d.ts.map +1 -0
- package/dist/core/extensions/containment.js +66 -0
- package/dist/core/extensions/containment.js.map +1 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +65 -7
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +2 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +55 -10
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +5 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +4 -1
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +2 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +4 -0
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/keybindings.d.ts +16 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +2 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +5 -0
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +2 -0
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager.d.ts +10 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +31 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +5 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +8 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/forge-build-token.d.ts +3 -0
- package/dist/forge-build-token.d.ts.map +1 -0
- package/dist/forge-build-token.js +17 -0
- package/dist/forge-build-token.js.map +1 -0
- package/dist/humain/checklist/vendor/commands.d.ts +7 -0
- package/dist/humain/checklist/vendor/commands.d.ts.map +1 -1
- package/dist/humain/checklist/vendor/commands.js +85 -21
- package/dist/humain/checklist/vendor/commands.js.map +1 -1
- package/dist/humain/checklist/vendor/index.d.ts.map +1 -1
- package/dist/humain/checklist/vendor/index.js +4 -3
- package/dist/humain/checklist/vendor/index.js.map +1 -1
- package/dist/humain/flow-loader.d.ts.map +1 -1
- package/dist/humain/flow-loader.js +31 -5
- package/dist/humain/flow-loader.js.map +1 -1
- package/dist/humain/hcode/build-token.d.ts +35 -0
- package/dist/humain/hcode/build-token.d.ts.map +1 -0
- package/dist/humain/hcode/build-token.js +406 -0
- package/dist/humain/hcode/build-token.js.map +1 -0
- package/dist/humain/hcode/contracts.d.ts +3 -1
- package/dist/humain/hcode/contracts.d.ts.map +1 -1
- package/dist/humain/hcode/contracts.js +7 -4
- package/dist/humain/hcode/contracts.js.map +1 -1
- package/dist/humain/hcode/notices.d.ts +5 -0
- package/dist/humain/hcode/notices.d.ts.map +1 -1
- package/dist/humain/hcode/notices.js +5 -0
- package/dist/humain/hcode/notices.js.map +1 -1
- package/dist/humain/hcode/provider.d.ts.map +1 -1
- package/dist/humain/hcode/provider.js +1 -1
- package/dist/humain/hcode/provider.js.map +1 -1
- package/dist/humain/hcode/run-credential.d.ts +3 -1
- package/dist/humain/hcode/run-credential.d.ts.map +1 -1
- package/dist/humain/hcode/run-credential.js +123 -19
- package/dist/humain/hcode/run-credential.js.map +1 -1
- package/dist/humain/hcode/sandbox.d.ts.map +1 -1
- package/dist/humain/hcode/sandbox.js +10 -4
- package/dist/humain/hcode/sandbox.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +11 -1
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/modes/interactive/bug-report.d.ts.map +1 -1
- package/dist/modes/interactive/bug-report.js +48 -12
- package/dist/modes/interactive/bug-report.js.map +1 -1
- package/dist/modes/interactive/chat-viewport.d.ts +4 -0
- package/dist/modes/interactive/chat-viewport.d.ts.map +1 -1
- package/dist/modes/interactive/chat-viewport.js +29 -5
- package/dist/modes/interactive/chat-viewport.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +2 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +29 -12
- package/dist/modes/interactive/components/footer.js.map +1 -1
- 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 +20 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-line.js +2 -2
- package/dist/modes/interactive/components/status-line.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +18 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +91 -3
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts +22 -0
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-group.js +117 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +15 -3
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +183 -52
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/sidebar/git-work.d.ts +18 -0
- package/dist/modes/interactive/sidebar/git-work.d.ts.map +1 -0
- package/dist/modes/interactive/sidebar/git-work.js +56 -0
- package/dist/modes/interactive/sidebar/git-work.js.map +1 -0
- package/dist/modes/interactive/sidebar/sidebar-component.d.ts +13 -0
- package/dist/modes/interactive/sidebar/sidebar-component.d.ts.map +1 -0
- package/dist/modes/interactive/sidebar/sidebar-component.js +61 -0
- package/dist/modes/interactive/sidebar/sidebar-component.js.map +1 -0
- package/dist/modes/interactive/sidebar/sidebar-model.d.ts +69 -0
- package/dist/modes/interactive/sidebar/sidebar-model.d.ts.map +1 -0
- package/dist/modes/interactive/sidebar/sidebar-model.js +217 -0
- package/dist/modes/interactive/sidebar/sidebar-model.js.map +1 -0
- package/dist/modes/interactive/tool-grouping.d.ts +11 -0
- package/dist/modes/interactive/tool-grouping.d.ts.map +1 -0
- package/dist/modes/interactive/tool-grouping.js +32 -0
- package/dist/modes/interactive/tool-grouping.js.map +1 -0
- package/docs/coordination.md +7 -3
- package/docs/environment-variables.md +14 -0
- package/docs/extensions.md +2 -0
- package/docs/flow.md +2 -0
- package/docs/forge-run-bootstrap.md +77 -42
- package/docs/humain-code.md +1 -1
- package/docs/keybindings.md +2 -0
- package/docs/providers.md +14 -0
- package/docs/settings.md +16 -1
- package/docs/slash-commands.md +3 -0
- package/examples/sdk/12-full-control.ts +1 -1
- package/npm-shrinkwrap.json +7 -6
- package/package.json +3 -2
- package/schemas/keybindings.schema.json +8 -0
- package/schemas/settings.schema.json +29 -0
- package/src/humain/caveman/UPSTREAM.md +15 -3
- package/src/humain/caveman/upstream.json +2 -2
- package/src/humain/web-access/UPSTREAM.md +8 -0
- package/dist/bundle/chunks/chunk-HWFAAGYK.js +0 -23
- package/dist/bundle/chunks/chunk-RP6MWUAP.js +0 -4
- package/dist/bundle/chunks/entry-3EL6GOWK.js +0 -2
- package/dist/bundle/chunks/interactive-mode-HHWOE4FD.js +0 -5
- /package/dist/bundle/chunks/{chunk-T7F2TEIS.js → chunk-3IX4NEXK.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notices.d.ts","sourceRoot":"","sources":["../../../src/humain/hcode/notices.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,KAAK,mBAAmB,EAA6C,MAAM,gBAAgB,CAAC;AAGrG,eAAO,MAAM,yBAAyB,kKAC0H,CAAC;AAEjK,eAAO,MAAM,sBAAsB,iJAC4G,CAAC;AAEhJ,eAAO,MAAM,mBAAmB,gDAAgD,CAAC;AAEjF,QAAA,MAAM,YAAY;aACjB,iBAAiB;aACjB,OAAO,EAAE,iEAAiE;aAC1E,SAAS,EAAE,iDAAiD;aAC5D,QAAQ,EAAE,+DAA+D;aACzE,IAAI,EAAE,iEAAiE;aACvE,KAAK,EAAE,kEAAkE;aACzE,SAAS,EAAE,mGAAmG;aAC9G,MAAM,EAAE,yEAAyE;aACjF,KAAK,EAAE,sDAAsD;aAC7D,KAAK,EAAE,wDAAwD;aAC/D,WAAW,EAAE,6DAA6D;aAC1E,MAAM,EAAE,6EAA6E;aACrF,SAAS,EAAE,0DAA0D;CAC5D,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,YAAY,CAAC;AAEzD,QAAA,MAAM,YAAY;aACjB,YAAY,YAAG,kBAAkB,EAAE,oEAAoE;aACvG,MAAM,YAAG,GAAG,EAAE,mDAAmD;aACjE,gBAAgB,YAAG,kBAAkB,EAAE,yCAAyC;aAChF,eAAe,YAAG,qBAAqB,EAAE,kDAAkD;aAC3F,aAAa,YAAG,qBAAqB,EAAE,gDAAgD;aACvF,kBAAkB,YAAG,qBAAqB,EAAE,sDAAsD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mDAAmD;aACnH,yBAAyB,YACxB,+CAA+C,EAC/C,+CAA+C;aAEhD,oBAAoB,YAAG,mCAAmC,EAAE,6CAA6C;aACzG,mBAAmB,YAAG,qBAAqB,EAAE,+CAA+C;aAC5F,mBAAmB,YAAG,qBAAqB,EAAE,2CAA2C;aACxF,gBAAgB,YAAG,SAAS,EAAE,iDAAiD;aAC/E,wBAAwB,YAAG,oBAAoB,EAAE,yCAAyC;CACjF,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,YAAY,CAAC;AA8BzD,qFAAqF;AACrF,eAAO,MAAM,4BAA4B;;;CAGuE,CAAC;AA0BjH,oGAAoG;AACpG,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAU7F;AAED,oFAAoF;AACpF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,yGAAyG;AACzG,wBAAgB,iBAAiB,CAChC,OAAO,EAAE,mBAAmB,EAC5B,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,OAAO,GACd;IACF,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAkDA;AAED,wGAAwG;AACxG,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAyBtF"}
|
|
@@ -5,6 +5,11 @@ export const HCODE_AMBIGUOUS_NOTICE = "HUMAIN Code couldn't confirm this request
|
|
|
5
5
|
export const BUILD_SESSION_ENDED = "Build session ended. Start a new Build run.";
|
|
6
6
|
const localReasons = {
|
|
7
7
|
buildSessionEnded: BUILD_SESSION_ENDED,
|
|
8
|
+
buildOutOfCredits: "Build stopped: out of credits.",
|
|
9
|
+
buildRefreshReused: "Build stopped: a refresh handle was reused. Ask the Build coordinator to investigate.",
|
|
10
|
+
buildRefreshInactive: "Build stopped: the run is no longer authorized to refresh inference credentials.",
|
|
11
|
+
buildRefreshUnavailable: "Build inference refresh is temporarily unavailable. The pending request is retained for bounded recovery.",
|
|
12
|
+
buildRefreshInvalid: "Build inference refresh configuration or private state is invalid. Ask the Build coordinator to recover the run.",
|
|
8
13
|
account: "The selected HUMAIN Code account or model is no longer current.",
|
|
9
14
|
transport: "HUMAIN Code only supports SSE for this request.",
|
|
10
15
|
envelope: "The CLI could not build a valid HUMAIN Code request envelope.",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notices.js","sourceRoot":"","sources":["../../../src/humain/hcode/notices.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6C,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AACrG,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,CAAC,MAAM,yBAAyB,GACrC,+JAA+J,CAAC;AAEjK,MAAM,CAAC,MAAM,sBAAsB,GAClC,8IAA8I,CAAC;AAEhJ,MAAM,CAAC,MAAM,mBAAmB,GAAG,6CAA6C,CAAC;AAEjF,MAAM,YAAY,GAAG;IACpB,iBAAiB,EAAE,mBAAmB;IACtC,OAAO,EAAE,iEAAiE;IAC1E,SAAS,EAAE,iDAAiD;IAC5D,QAAQ,EAAE,+DAA+D;IACzE,IAAI,EAAE,iEAAiE;IACvE,KAAK,EAAE,kEAAkE;IACzE,SAAS,EAAE,mGAAmG;IAC9G,MAAM,EAAE,yEAAyE;IACjF,KAAK,EAAE,sDAAsD;IAC7D,KAAK,EAAE,wDAAwD;IAC/D,WAAW,EAAE,6DAA6D;IAC1E,MAAM,EAAE,6EAA6E;IACrF,SAAS,EAAE,0DAA0D;CAC5D,CAAC;AAIX,MAAM,YAAY,GAAG;IACpB,YAAY,EAAE,CAAC,kBAAkB,EAAE,oEAAoE,CAAC;IACxG,MAAM,EAAE,CAAC,GAAG,EAAE,mDAAmD,CAAC;IAClE,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F,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;QACxB,MAAM,OAAO,GAAG,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC;QAC3C,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;YAClE,IAAI,CAAC;gBACJ,0GAA0G;gBAC1G,MAAM,MAAM,GAAG,iBAAiB,CAC/B,wBAAwB,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,EAClD,UAAW,CAAC,SAAS,EACrB,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAChD,CAAC;gBACF,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrD,CAAC;YAAC,MAAM,CAAC;gBACR,sFAAsF;YACvF,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,sBAAsB,CAAC;AAC/B,CAAC","sourcesContent":["// Local, typed presentation of managed refusal facts; never schedules a request or reads a later balance.\nimport type { AssistantMessage } from \"@earendil-works/pi-ai\";\nimport { type HcodeInferenceError, type HcodeValue, parseHcodeInferenceError } from \"./contracts.ts\";\nimport { HCODE_PROVIDER } from \"./http.ts\";\n\nexport const HCODE_PENDING_EXPLANATION =\n\t\"Pending usage is awaiting provider confirmation. It remains reserved until confirmed or reviewed by an admin. It is not a final charge and is not free usage.\";\n\nexport const HCODE_AMBIGUOUS_NOTICE =\n\t\"HUMAIN Code couldn't confirm this request's outcome. It may still be charged. No automatic retry was sent. Check /usage before trying again.\";\n\nexport const BUILD_SESSION_ENDED = \"Build session ended. Start a new Build run.\";\n\nconst localReasons = {\n\tbuildSessionEnded: BUILD_SESSION_ENDED,\n\taccount: \"The selected HUMAIN Code account or model is no longer current.\",\n\ttransport: \"HUMAIN Code only supports SSE for this request.\",\n\tenvelope: \"The CLI could not build a valid HUMAIN Code request envelope.\",\n\tsize: \"The request exceeds the HUMAIN Code model's request size limit.\",\n\tmodel: \"The request model does not match the selected HUMAIN Code model.\",\n\treasoning: \"The selected HUMAIN Code model does not support the requested thinking level or thinking history.\",\n\toutput: \"The requested output token limit exceeds the HUMAIN Code model's limit.\",\n\tcache: \"HUMAIN Code requires cache retention to be disabled.\",\n\ttools: \"The selected HUMAIN Code model does not support tools.\",\n\tstrictTools: \"HUMAIN Code does not support required strict tool sampling.\",\n\timages: \"An image is unsupported or exceeds the selected HUMAIN Code model's limits.\",\n\tcancelled: \"The HUMAIN Code request was cancelled before submission.\",\n} as const;\n\nexport type HcodeLocalReason = keyof typeof localReasons;\n\nconst localDetails = {\n\tmessageLimit: [\"context.messages\", \"History exceeds 512 messages; compact the session before retrying.\"],\n\tschema: [\"$\", \"Request structure failed local schema validation.\"],\n\t\"message.schema\": [\"context.messages\", \"History failed local schema validation.\"],\n\t\"system.schema\": [\"context.messages[*]\", \"A system message failed local schema validation.\"],\n\t\"user.schema\": [\"context.messages[*]\", \"A user message failed local schema validation.\"],\n\t\"assistant.schema\": [\"context.messages[*]\", \"An assistant message failed local schema validation.\"],\n\t\"assistant.deferred\": [\"context.messages[*]\", \"Assistant history contains a deferred response.\"],\n\t\"toolCall.schema\": [\"context.messages[*].content[*]\", \"A tool call failed local schema validation.\"],\n\t\"toolCall.orphan\": [\"context.messages[*].content[*]\", \"Tool-call history is missing a matching result.\"],\n\t\"toolCall.unknownTool\": [\"context.messages[*].content[*].name\", \"Tool-call history references an unavailable tool.\"],\n\t\"toolCall.argumentsError\": [\n\t\t\"context.messages[*].content[*].argumentsError\",\n\t\t\"Tool-call history contains invalid arguments.\",\n\t],\n\t\"toolCall.duplicate\": [\"context.messages[*].content[*].id\", \"Tool-call history contains a repeated call.\"],\n\t\"toolResult.schema\": [\"context.messages[*]\", \"A tool result failed local schema validation.\"],\n\t\"toolResult.orphan\": [\"context.messages[*]\", \"Tool-result history has no matching call.\"],\n\t\"options.schema\": [\"options\", \"Request options failed local schema validation.\"],\n\t\"toolChoice.unknownTool\": [\"options.toolChoice\", \"The current tool choice is unavailable.\"],\n} as const;\n\nexport type HcodeLocalDetail = keyof typeof localDetails;\n\n/** Forge's closed `x-hcode-model-unavailable-reason` values, in plain words. */\nconst modelUnavailableReasons = {\n\tcatalog_entry_unavailable: \"This model is no longer in your HUMAIN Code catalog.\",\n\tcredential_unavailable: \"HUMAIN Code has no usable provider key for this model.\",\n\texecution_credentials_unavailable: \"HUMAIN Code has no usable provider key for this model.\",\n\tprovider_quota_isolation_unverified: \"This model's provider key isn't dedicated to HUMAIN Code.\",\n\tquota_mapping_unavailable: \"This model's capacity isn't set up for HUMAIN Code yet.\",\n\tconfiguration_changed: \"An admin changed this model's configuration.\",\n\texecution_config_unavailable: \"HUMAIN Code couldn't load this model's configuration.\",\n\texecution_model_mismatch: \"HUMAIN Code's configuration for this model doesn't match its catalog entry.\",\n\texecution_endpoint_mismatch: \"HUMAIN Code's endpoint for this model doesn't match its catalog entry.\",\n\texecution_region_mismatch: \"HUMAIN Code's provider key is set to a region this model can't run in.\",\n} as const;\n\n/** Forge's closed `x-hcode-unsupported-capability-reason` values, in plain words. */\nconst unsupportedCapabilityReasons = {\n\treasoning: \"This model doesn't support the requested thinking level.\",\n\ttool_choice: \"This model can't force a tool call while thinking.\",\n\ttemperature: \"This model doesn't accept a temperature setting.\",\n\tcache_retention: \"This model doesn't support the requested prompt caching.\",\n\ttools: \"This model doesn't support tools.\",\n\tstrict_tools: \"This model doesn't support strict tool schemas.\",\n\tthinking_history: \"This model can't replay thinking from earlier turns of this conversation.\",\n\ttool_call_history: \"This model can't replay tool calls from earlier turns of this conversation.\",\n\timages: \"This model can't accept these images.\",\n\testimate: \"HUMAIN Code couldn't estimate this request's cost.\",\n} as const;\n\n/** Header names and closed reason values Forge sends with deterministic refusals. */\nexport const HCODE_REFUSAL_REASON_HEADERS = {\n\tmodel_unavailable: [\"x-hcode-model-unavailable-reason\", Object.keys(modelUnavailableReasons)],\n\tunsupported_capability: [\"x-hcode-unsupported-capability-reason\", Object.keys(unsupportedCapabilityReasons)],\n} as const satisfies Partial<Record<HcodeInferenceError[\"error\"][\"code\"], readonly [string, readonly string[]]>>;\n\n// Refusals Forge returns before any provider dispatch; each settles as not dispatched, so nothing is charged.\nconst predispatchCodes = new Set<HcodeInferenceError[\"error\"][\"code\"]>([\n\t\"unauthorized\",\n\t\"forbidden\",\n\t\"legal_acknowledgment_required\",\n\t\"auth_dependency_unavailable\",\n\t\"invalid_request\",\n\t\"unsupported_capability\",\n\t\"model_unavailable\",\n]);\nconst NOT_CHARGED =\n\t\"HUMAIN Code refused this request before running it, so nothing was charged. No automatic retry was sent.\";\n\nfunction refusalReason(code: HcodeInferenceError[\"error\"][\"code\"], reason: unknown): string | undefined {\n\tif (typeof reason !== \"string\") return undefined;\n\tconst table: Record<string, string> =\n\t\tcode === \"model_unavailable\"\n\t\t\t? modelUnavailableReasons\n\t\t\t: code === \"unsupported_capability\"\n\t\t\t\t? unsupportedCapabilityReasons\n\t\t\t\t: {};\n\treturn Object.hasOwn(table, reason) ? table[reason] : undefined;\n}\n\n/** Render a closed, non-reflecting reason for an inference that never reached the send boundary. */\nexport function formatHcodeLocalRefusal(reason: unknown, detail?: unknown): string | undefined {\n\tif (typeof reason !== \"string\" || !Object.hasOwn(localReasons, reason)) return undefined;\n\tif (reason === \"buildSessionEnded\") return BUILD_SESSION_ENDED;\n\t// Persisted diagnostics are untrusted: only closed detail codes may affect presentation.\n\tlet explanation = \"\";\n\tif (reason === \"envelope\" && typeof detail === \"string\" && Object.hasOwn(localDetails, detail)) {\n\t\tconst [path, message] = localDetails[detail as HcodeLocalDetail];\n\t\texplanation = ` ${message} [${detail} at ${path}]`;\n\t}\n\treturn `${localReasons[reason as HcodeLocalReason]}${explanation} No request was sent or charged.`;\n}\n\n/** Format the server's reset instant in UTC, independently of the host timezone. */\nexport function formatHcodeReset(resetAt: string): string {\n\treturn `Resets ${new Date(resetAt).toISOString().slice(0, 16).replace(\"T\", \" \")} UTC`;\n}\n\n/** Render schema-validated service facts without reading raw diagnostics or granting automatic retry. */\nexport function formatHcodeNotice(\n\tfailure: HcodeInferenceError,\n\treceivedAt: number,\n\treason?: unknown,\n): {\n\tmessage: string;\n\tlines: readonly string[];\n\tretryAfterMs?: number;\n} {\n\tconst error = failure.error;\n\tif (error.code === \"hcode_busy\") {\n\t\tconst retryAt = new Date(receivedAt + error.details.retryAfterMs);\n\t\t// A valid delay can exceed Date's range. Omit the time, not the no-dispatch fact.\n\t\tconst retryTime = Number.isNaN(retryAt.getTime())\n\t\t\t? undefined\n\t\t\t: retryAt.toISOString().split(\".\")[0].replace(\"T\", \" \");\n\t\treturn {\n\t\t\tmessage: error.message,\n\t\t\tlines: [\n\t\t\t\t...(retryTime ? [`Retry after ${retryTime} UTC.`] : []),\n\t\t\t\t\"No request was dispatched. No automatic retry was sent.\",\n\t\t\t],\n\t\t\tretryAfterMs: error.details.retryAfterMs,\n\t\t};\n\t}\n\tif (error.code === \"quota_exceeded\") {\n\t\tconst usage = error.details.usage;\n\t\tconst money = (value: HcodeValue | { kind: \"unlimited\" }) =>\n\t\t\tvalue.kind === \"known\"\n\t\t\t\t? `${value.value} ${usage.currency} ${usage.unit}${value.value === 1 ? \"\" : \"s\"}`\n\t\t\t\t: value.kind;\n\t\treturn {\n\t\t\tmessage: error.message,\n\t\t\tlines: [\n\t\t\t\t`Used${usage.costComplete ? \"\" : \" (known subtotal)\"} ${money(usage.actual)}`,\n\t\t\t\t`Pending ${money(usage.reserved)}`,\n\t\t\t\t`Remaining ${money(usage.remaining)}`,\n\t\t\t\tformatHcodeReset(usage.period.resetAt),\n\t\t\t\t\"No request was dispatched. No automatic retry was sent.\",\n\t\t\t],\n\t\t};\n\t}\n\tconst recovery =\n\t\terror.code === \"unauthorized\"\n\t\t\t? \"Sign in again with /login.\"\n\t\t\t: error.code === \"legal_acknowledgment_required\"\n\t\t\t\t? \"Accept terms in the web app, then try again.\"\n\t\t\t\t: error.code === \"model_unavailable\"\n\t\t\t\t\t? \"Choose another model with /model, or ask your admin.\"\n\t\t\t\t\t: error.code === \"unsupported_capability\"\n\t\t\t\t\t\t? \"Change the setting, start a new conversation with /new, or choose another model with /model.\"\n\t\t\t\t\t\t: undefined;\n\tif (!predispatchCodes.has(error.code)) return { message: error.message, lines: [HCODE_AMBIGUOUS_NOTICE] };\n\tconst detail = refusalReason(error.code, reason);\n\treturn {\n\t\tmessage: error.message,\n\t\tlines: [...(detail ? [detail] : []), ...(recovery ? [recovery] : []), NOT_CHARGED],\n\t};\n}\n\n/** Shared print/interactive boundary for validated refusals and separate uncertain-outcome warnings. */\nexport function formatHcodeMessageNotice(message: AssistantMessage): string | undefined {\n\tif (message.provider !== HCODE_PROVIDER) return undefined;\n\tif (message.stopReason === \"error\") {\n\t\tconst diagnostic = message.diagnostics?.findLast((entry) => entry.type === \"provider_http_error\");\n\t\tconst local = formatHcodeLocalRefusal(\n\t\t\tdiagnostic?.details?.hcodeLocalReason,\n\t\t\tdiagnostic?.details?.hcodeLocalDetail,\n\t\t);\n\t\tif (local) return local;\n\t\tconst refusal = diagnostic?.details?.hcode;\n\t\tif (refusal && typeof refusal === \"object\" && \"error\" in refusal) {\n\t\t\ttry {\n\t\t\t\t// Persisted diagnostics are untrusted. Revalidate only the closed service envelope, never raw error text.\n\t\t\t\tconst notice = formatHcodeNotice(\n\t\t\t\t\tparseHcodeInferenceError({ error: refusal.error }),\n\t\t\t\t\tdiagnostic!.timestamp,\n\t\t\t\t\t\"reason\" in refusal ? refusal.reason : undefined,\n\t\t\t\t);\n\t\t\t\treturn [notice.message, ...notice.lines].join(\"\\n\");\n\t\t\t} catch {\n\t\t\t\t// Malformed or ordinary-provider diagnostics retain their existing safe presentation.\n\t\t\t}\n\t\t}\n\t}\n\treturn HCODE_AMBIGUOUS_NOTICE;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"notices.js","sourceRoot":"","sources":["../../../src/humain/h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B,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,EAClD,UAAW,CAAC,SAAS,EACrB,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAChD,CAAC;gBACF,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrD,CAAC;YAAC,MAAM,CAAC;gBACR,sFAAsF;YACvF,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,sBAAsB,CAAC;AAC/B,CAAC","sourcesContent":["// Local, typed presentation of managed refusal facts; never schedules a request or reads a later balance.\nimport type { AssistantMessage } from \"@earendil-works/pi-ai\";\nimport { type HcodeInferenceError, type HcodeValue, parseHcodeInferenceError } from \"./contracts.ts\";\nimport { HCODE_PROVIDER } from \"./http.ts\";\n\nexport const HCODE_PENDING_EXPLANATION =\n\t\"Pending usage is awaiting provider confirmation. It remains reserved until confirmed or reviewed by an admin. It is not a final charge and is not free usage.\";\n\nexport const HCODE_AMBIGUOUS_NOTICE =\n\t\"HUMAIN Code couldn't confirm this request's outcome. It may still be charged. No automatic retry was sent. Check /usage before trying again.\";\n\nexport const BUILD_SESSION_ENDED = \"Build session ended. Start a new Build run.\";\n\nconst localReasons = {\n\tbuildSessionEnded: BUILD_SESSION_ENDED,\n\tbuildOutOfCredits: \"Build stopped: out of credits.\",\n\tbuildRefreshReused: \"Build stopped: a refresh handle was reused. Ask the Build coordinator to investigate.\",\n\tbuildRefreshInactive: \"Build stopped: the run is no longer authorized to refresh inference credentials.\",\n\tbuildRefreshUnavailable:\n\t\t\"Build inference refresh is temporarily unavailable. The pending request is retained for bounded recovery.\",\n\tbuildRefreshInvalid:\n\t\t\"Build inference refresh configuration or private state is invalid. Ask the Build coordinator to recover the run.\",\n\taccount: \"The selected HUMAIN Code account or model is no longer current.\",\n\ttransport: \"HUMAIN Code only supports SSE for this request.\",\n\tenvelope: \"The CLI could not build a valid HUMAIN Code request envelope.\",\n\tsize: \"The request exceeds the HUMAIN Code model's request size limit.\",\n\tmodel: \"The request model does not match the selected HUMAIN Code model.\",\n\treasoning: \"The selected HUMAIN Code model does not support the requested thinking level or thinking history.\",\n\toutput: \"The requested output token limit exceeds the HUMAIN Code model's limit.\",\n\tcache: \"HUMAIN Code requires cache retention to be disabled.\",\n\ttools: \"The selected HUMAIN Code model does not support tools.\",\n\tstrictTools: \"HUMAIN Code does not support required strict tool sampling.\",\n\timages: \"An image is unsupported or exceeds the selected HUMAIN Code model's limits.\",\n\tcancelled: \"The HUMAIN Code request was cancelled before submission.\",\n} as const;\n\nexport type HcodeLocalReason = keyof typeof localReasons;\n\nconst localDetails = {\n\tmessageLimit: [\"context.messages\", \"History exceeds 512 messages; compact the session before retrying.\"],\n\tschema: [\"$\", \"Request structure failed local schema validation.\"],\n\t\"message.schema\": [\"context.messages\", \"History failed local schema validation.\"],\n\t\"system.schema\": [\"context.messages[*]\", \"A system message failed local schema validation.\"],\n\t\"user.schema\": [\"context.messages[*]\", \"A user message failed local schema validation.\"],\n\t\"assistant.schema\": [\"context.messages[*]\", \"An assistant message failed local schema validation.\"],\n\t\"assistant.deferred\": [\"context.messages[*]\", \"Assistant history contains a deferred response.\"],\n\t\"toolCall.schema\": [\"context.messages[*].content[*]\", \"A tool call failed local schema validation.\"],\n\t\"toolCall.orphan\": [\"context.messages[*].content[*]\", \"Tool-call history is missing a matching result.\"],\n\t\"toolCall.unknownTool\": [\"context.messages[*].content[*].name\", \"Tool-call history references an unavailable tool.\"],\n\t\"toolCall.argumentsError\": [\n\t\t\"context.messages[*].content[*].argumentsError\",\n\t\t\"Tool-call history contains invalid arguments.\",\n\t],\n\t\"toolCall.duplicate\": [\"context.messages[*].content[*].id\", \"Tool-call history contains a repeated call.\"],\n\t\"toolResult.schema\": [\"context.messages[*]\", \"A tool result failed local schema validation.\"],\n\t\"toolResult.orphan\": [\"context.messages[*]\", \"Tool-result history has no matching call.\"],\n\t\"options.schema\": [\"options\", \"Request options failed local schema validation.\"],\n\t\"toolChoice.unknownTool\": [\"options.toolChoice\", \"The current tool choice is unavailable.\"],\n} as const;\n\nexport type HcodeLocalDetail = keyof typeof localDetails;\n\n/** Forge's closed `x-hcode-model-unavailable-reason` values, in plain words. */\nconst modelUnavailableReasons = {\n\tcatalog_entry_unavailable: \"This model is no longer in your HUMAIN Code catalog.\",\n\tcredential_unavailable: \"HUMAIN Code has no usable provider key for this model.\",\n\texecution_credentials_unavailable: \"HUMAIN Code has no usable provider key for this model.\",\n\tprovider_quota_isolation_unverified: \"This model's provider key isn't dedicated to HUMAIN Code.\",\n\tquota_mapping_unavailable: \"This model's capacity isn't set up for HUMAIN Code yet.\",\n\tconfiguration_changed: \"An admin changed this model's configuration.\",\n\texecution_config_unavailable: \"HUMAIN Code couldn't load this model's configuration.\",\n\texecution_model_mismatch: \"HUMAIN Code's configuration for this model doesn't match its catalog entry.\",\n\texecution_endpoint_mismatch: \"HUMAIN Code's endpoint for this model doesn't match its catalog entry.\",\n\texecution_region_mismatch: \"HUMAIN Code's provider key is set to a region this model can't run in.\",\n} as const;\n\n/** Forge's closed `x-hcode-unsupported-capability-reason` values, in plain words. */\nconst unsupportedCapabilityReasons = {\n\treasoning: \"This model doesn't support the requested thinking level.\",\n\ttool_choice: \"This model can't force a tool call while thinking.\",\n\ttemperature: \"This model doesn't accept a temperature setting.\",\n\tcache_retention: \"This model doesn't support the requested prompt caching.\",\n\ttools: \"This model doesn't support tools.\",\n\tstrict_tools: \"This model doesn't support strict tool schemas.\",\n\tthinking_history: \"This model can't replay thinking from earlier turns of this conversation.\",\n\ttool_call_history: \"This model can't replay tool calls from earlier turns of this conversation.\",\n\timages: \"This model can't accept these images.\",\n\testimate: \"HUMAIN Code couldn't estimate this request's cost.\",\n} as const;\n\n/** Header names and closed reason values Forge sends with deterministic refusals. */\nexport const HCODE_REFUSAL_REASON_HEADERS = {\n\tmodel_unavailable: [\"x-hcode-model-unavailable-reason\", Object.keys(modelUnavailableReasons)],\n\tunsupported_capability: [\"x-hcode-unsupported-capability-reason\", Object.keys(unsupportedCapabilityReasons)],\n} as const satisfies Partial<Record<HcodeInferenceError[\"error\"][\"code\"], readonly [string, readonly string[]]>>;\n\n// Refusals Forge returns before any provider dispatch; each settles as not dispatched, so nothing is charged.\nconst predispatchCodes = new Set<HcodeInferenceError[\"error\"][\"code\"]>([\n\t\"unauthorized\",\n\t\"forbidden\",\n\t\"legal_acknowledgment_required\",\n\t\"auth_dependency_unavailable\",\n\t\"invalid_request\",\n\t\"unsupported_capability\",\n\t\"model_unavailable\",\n]);\nconst NOT_CHARGED =\n\t\"HUMAIN Code refused this request before running it, so nothing was charged. No automatic retry was sent.\";\n\nfunction refusalReason(code: HcodeInferenceError[\"error\"][\"code\"], reason: unknown): string | undefined {\n\tif (typeof reason !== \"string\") return undefined;\n\tconst table: Record<string, string> =\n\t\tcode === \"model_unavailable\"\n\t\t\t? modelUnavailableReasons\n\t\t\t: code === \"unsupported_capability\"\n\t\t\t\t? unsupportedCapabilityReasons\n\t\t\t\t: {};\n\treturn Object.hasOwn(table, reason) ? table[reason] : undefined;\n}\n\n/** Render a closed, non-reflecting reason for an inference that never reached the send boundary. */\nexport function formatHcodeLocalRefusal(reason: unknown, detail?: unknown): string | undefined {\n\tif (typeof reason !== \"string\" || !Object.hasOwn(localReasons, reason)) return undefined;\n\tif (reason === \"buildSessionEnded\") return BUILD_SESSION_ENDED;\n\t// Persisted diagnostics are untrusted: only closed detail codes may affect presentation.\n\tlet explanation = \"\";\n\tif (reason === \"envelope\" && typeof detail === \"string\" && Object.hasOwn(localDetails, detail)) {\n\t\tconst [path, message] = localDetails[detail as HcodeLocalDetail];\n\t\texplanation = ` ${message} [${detail} at ${path}]`;\n\t}\n\treturn `${localReasons[reason as HcodeLocalReason]}${explanation} No request was sent or charged.`;\n}\n\n/** Format the server's reset instant in UTC, independently of the host timezone. */\nexport function formatHcodeReset(resetAt: string): string {\n\treturn `Resets ${new Date(resetAt).toISOString().slice(0, 16).replace(\"T\", \" \")} UTC`;\n}\n\n/** Render schema-validated service facts without reading raw diagnostics or granting automatic retry. */\nexport function formatHcodeNotice(\n\tfailure: HcodeInferenceError,\n\treceivedAt: number,\n\treason?: unknown,\n): {\n\tmessage: string;\n\tlines: readonly string[];\n\tretryAfterMs?: number;\n} {\n\tconst error = failure.error;\n\tif (error.code === \"hcode_busy\") {\n\t\tconst retryAt = new Date(receivedAt + error.details.retryAfterMs);\n\t\t// A valid delay can exceed Date's range. Omit the time, not the no-dispatch fact.\n\t\tconst retryTime = Number.isNaN(retryAt.getTime())\n\t\t\t? undefined\n\t\t\t: retryAt.toISOString().split(\".\")[0].replace(\"T\", \" \");\n\t\treturn {\n\t\t\tmessage: error.message,\n\t\t\tlines: [\n\t\t\t\t...(retryTime ? [`Retry after ${retryTime} UTC.`] : []),\n\t\t\t\t\"No request was dispatched. No automatic retry was sent.\",\n\t\t\t],\n\t\t\tretryAfterMs: error.details.retryAfterMs,\n\t\t};\n\t}\n\tif (error.code === \"quota_exceeded\") {\n\t\tconst usage = error.details.usage;\n\t\tconst money = (value: HcodeValue | { kind: \"unlimited\" }) =>\n\t\t\tvalue.kind === \"known\"\n\t\t\t\t? `${value.value} ${usage.currency} ${usage.unit}${value.value === 1 ? \"\" : \"s\"}`\n\t\t\t\t: value.kind;\n\t\treturn {\n\t\t\tmessage: error.message,\n\t\t\tlines: [\n\t\t\t\t`Used${usage.costComplete ? \"\" : \" (known subtotal)\"} ${money(usage.actual)}`,\n\t\t\t\t`Pending ${money(usage.reserved)}`,\n\t\t\t\t`Remaining ${money(usage.remaining)}`,\n\t\t\t\tformatHcodeReset(usage.period.resetAt),\n\t\t\t\t\"No request was dispatched. No automatic retry was sent.\",\n\t\t\t],\n\t\t};\n\t}\n\tconst recovery =\n\t\terror.code === \"unauthorized\"\n\t\t\t? \"Sign in again with /login.\"\n\t\t\t: error.code === \"legal_acknowledgment_required\"\n\t\t\t\t? \"Accept terms in the web app, then try again.\"\n\t\t\t\t: error.code === \"model_unavailable\"\n\t\t\t\t\t? \"Choose another model with /model, or ask your admin.\"\n\t\t\t\t\t: error.code === \"unsupported_capability\"\n\t\t\t\t\t\t? \"Change the setting, start a new conversation with /new, or choose another model with /model.\"\n\t\t\t\t\t\t: undefined;\n\tif (!predispatchCodes.has(error.code)) return { message: error.message, lines: [HCODE_AMBIGUOUS_NOTICE] };\n\tconst detail = refusalReason(error.code, reason);\n\treturn {\n\t\tmessage: error.message,\n\t\tlines: [...(detail ? [detail] : []), ...(recovery ? [recovery] : []), NOT_CHARGED],\n\t};\n}\n\n/** Shared print/interactive boundary for validated refusals and separate uncertain-outcome warnings. */\nexport function formatHcodeMessageNotice(message: AssistantMessage): string | undefined {\n\tif (message.provider !== HCODE_PROVIDER) return undefined;\n\tif (message.stopReason === \"error\") {\n\t\tconst diagnostic = message.diagnostics?.findLast((entry) => entry.type === \"provider_http_error\");\n\t\tconst local = formatHcodeLocalRefusal(\n\t\t\tdiagnostic?.details?.hcodeLocalReason,\n\t\t\tdiagnostic?.details?.hcodeLocalDetail,\n\t\t);\n\t\tif (local) return local;\n\t\tconst refusal = diagnostic?.details?.hcode;\n\t\tif (refusal && typeof refusal === \"object\" && \"error\" in refusal) {\n\t\t\ttry {\n\t\t\t\t// Persisted diagnostics are untrusted. Revalidate only the closed service envelope, never raw error text.\n\t\t\t\tconst notice = formatHcodeNotice(\n\t\t\t\t\tparseHcodeInferenceError({ error: refusal.error }),\n\t\t\t\t\tdiagnostic!.timestamp,\n\t\t\t\t\t\"reason\" in refusal ? refusal.reason : undefined,\n\t\t\t\t);\n\t\t\t\treturn [notice.message, ...notice.lines].join(\"\\n\");\n\t\t\t} catch {\n\t\t\t\t// Malformed or ordinary-provider diagnostics retain their existing safe presentation.\n\t\t\t}\n\t\t}\n\t}\n\treturn HCODE_AMBIGUOUS_NOTICE;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/humain/hcode/provider.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,GAAG,EACR,KAAK,gBAAgB,EAOrB,KAAK,KAAK,EACV,KAAK,QAAQ,EAGb,KAAK,iBAAiB,EACtB,MAAM,uBAAuB,CAAC;AAI/B,OAAO,EAGN,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAIhC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,gBAAgB,EAA6C,MAAM,kBAAkB,CAAC;AASpG,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIpE,oGAAoG;AACpG,MAAM,WAAW,aAAc,SAAQ,QAAQ,CAAC,aAAa,CAAC;IAC7D,iFAAiF;IACjF,OAAO,IAAI,IAAI,CAAC;IAChB,qFAAqF;IACrF,kBAAkB,IAAI,uBAAuB,GAAG,SAAS,CAAC;IAC1D,yGAAyG;IACzG,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,2BAA2B,GAAG,SAAS,CAAC;IACjF,6GAA6G;IAC7G,aAAa,IAAI,OAAO,CAAC;CACzB;AAED,uFAAuF;AACvF,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,eAAe,GAAG,gBAAgB,CAS/E;AAQD,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,iBAAiB,EAC1B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,WAAW,CAAC,GACzC,iBAAiB,CAwEnB;AAoBD,yGAAyG;AACzG,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,gBAAgB,EACzB,WAAW,GAAE,gBAA4C,GACvD,aAAa,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/humain/hcode/provider.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,GAAG,EACR,KAAK,gBAAgB,EAOrB,KAAK,KAAK,EACV,KAAK,QAAQ,EAGb,KAAK,iBAAiB,EACtB,MAAM,uBAAuB,CAAC;AAI/B,OAAO,EAGN,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAIhC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,gBAAgB,EAA6C,MAAM,kBAAkB,CAAC;AASpG,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIpE,oGAAoG;AACpG,MAAM,WAAW,aAAc,SAAQ,QAAQ,CAAC,aAAa,CAAC;IAC7D,iFAAiF;IACjF,OAAO,IAAI,IAAI,CAAC;IAChB,qFAAqF;IACrF,kBAAkB,IAAI,uBAAuB,GAAG,SAAS,CAAC;IAC1D,yGAAyG;IACzG,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,2BAA2B,GAAG,SAAS,CAAC;IACjF,6GAA6G;IAC7G,aAAa,IAAI,OAAO,CAAC;CACzB;AAED,uFAAuF;AACvF,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,eAAe,GAAG,gBAAgB,CAS/E;AAQD,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,iBAAiB,EAC1B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,WAAW,CAAC,GACzC,iBAAiB,CAwEnB;AAoBD,yGAAyG;AACzG,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,gBAAgB,EACzB,WAAW,GAAE,gBAA4C,GACvD,aAAa,CAgSf"}
|
|
@@ -360,7 +360,7 @@ export function createHcodeProvider(account, environment = resolveHcodeEnvironme
|
|
|
360
360
|
reason = parseHcodeCatalogEmptyReason(response.headers.get(HCODE_CATALOG_EMPTY_REASON_HEADER));
|
|
361
361
|
excluded = parseHcodeCatalogExclusions(response.headers.get(HCODE_CATALOG_EXCLUSIONS_HEADER));
|
|
362
362
|
return response;
|
|
363
|
-
}, `${environment.inferenceBaseUrl}/models`, { signal: context.signal })).data;
|
|
363
|
+
}, `${environment.inferenceBaseUrl}/models`, { signal: context.signal }), environment).data;
|
|
364
364
|
const next = deriveHcodeCatalog(entries, environment);
|
|
365
365
|
if (disposed || context.signal.aborted || !sameReference(account.status(expected.environmentId), expected))
|
|
366
366
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/humain/hcode/provider.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAKN,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,4BAA4B,GAM5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EACN,iCAAiC,EACjC,+BAA+B,EAG/B,4BAA4B,EAC5B,2BAA2B,EAC3B,mBAAmB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAyB,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EACN,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,2BAA2B,GAC3B,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACrH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAclC,uFAAuF;AACvF,MAAM,UAAU,wBAAwB,CAAC,GAAoB;IAC5D,OAAO;QACN,IAAI,EAAE,SAAS;QACf,GAAG,EAAE;YACJ,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CAAC,EACD,GAAG,WAAW,CAAC,gBAAgB,SAAS,EACxC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAC1B,CACD,CAAC,IAAI,CAAC;YACP,MAAM,IAAI,GAAG,kBAAkB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YACtD,IAAI,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC;gBACzG,OAAO;YACR,MAAM,OAAO,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,GAAG,EAAE;oBACZ,IACC,QAAQ;wBACR,OAAO,CAAC,MAAM,CAAC,OAAO;wBACtB,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC;wBAEhE,OAAO;oBACR,iFAAiF;oBACjF,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC;wBAAE,MAAM,GAAG,IAAI,CAAC;oBACvF,KAAK,GAAG,QAAQ,CAAC;oBACjB,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;oBAC/C,UAAU,GAAG,QAAQ,CAAC;gBACvB,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["// Managed account provider: reference-only auth and account-scoped pi-messages catalog.\nimport { createHash, randomUUID } from \"node:crypto\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport {\n\ttype Api,\n\ttype ApiKeyCredential,\n\ttype AssistantMessage,\n\ttype AssistantMessageEvent,\n\tcreateDelegatedFetch,\n\tcreateProvider,\n\tlazyStream,\n\tManagedAssistantMessageQueue,\n\ttype Model,\n\ttype Provider,\n\ttype SimpleStreamOptions,\n\ttype SystemMessage,\n\ttype TranscriptContext,\n} from \"@earendil-works/pi-ai\";\nimport { piMessagesApi } from \"@earendil-works/pi-ai/api/pi-messages.lazy\";\nimport { sameReference } from \"./account-store.ts\";\nimport { deriveHcodeCatalog } from \"./catalog.ts\";\nimport {\n\tHCODE_CATALOG_EMPTY_REASON_HEADER,\n\tHCODE_CATALOG_EXCLUSIONS_HEADER,\n\ttype HcodeCatalogEmptyReason,\n\ttype HcodeCatalogExclusionReason,\n\tparseHcodeCatalogEmptyReason,\n\tparseHcodeCatalogExclusions,\n\tparseHcodeModelList,\n} from \"./contracts.ts\";\nimport { type HcodeEnvironment, hcodeDisplayName, resolveHcodeEnvironment } from \"./environment.ts\";\nimport { HCODE_PROVIDER, hcodeJson } from \"./http.ts\";\nimport {\n\tfitHcodeRequestSize,\n\thcodeActivePrompts,\n\thcodeImagePayloadDraft,\n\treportHcodeImageSizeRefusal,\n} from \"./images.ts\";\nimport type { HcodeLocalReason } from \"./notices.ts\";\nimport type { HcodeAccountPort, HcodeAccountRef } from \"./ports.ts\";\nimport { createHcodeTransport, HcodeLocalRefusal, HcodeTransportError, parseHcodeRequestBody } from \"./transport.ts\";\nimport * as wire from \"./wire.ts\";\n\n/** Account-bound native provider whose owning runtime must dispose its subscription and catalog. */\nexport interface HcodeProvider extends Provider<\"pi-messages\"> {\n\t/** Release account observation and prevent further catalog/auth/request work. */\n\tdispose(): void;\n\t/** Forge's reason the current account's catalog is empty, if it sent a known one. */\n\tcatalogEmptyReason(): HcodeCatalogEmptyReason | undefined;\n\t/** Forge's reason the current account's catalog left out this exact model ID, if it sent a known one. */\n\tcatalogExclusionReason(modelId: string): HcodeCatalogExclusionReason | undefined;\n\t/** Whether this process has read the current account's catalog; a new process reads it when /model opens. */\n\tcatalogLoaded(): boolean;\n}\n\n/** Returns only the keyless local reference allowed in the generic credential pool. */\nexport function hcodeReferenceCredential(ref: HcodeAccountRef): ApiKeyCredential {\n\treturn {\n\t\ttype: \"api_key\",\n\t\tenv: {\n\t\t\tHCODE_ENVIRONMENT_ID: ref.environmentId,\n\t\t\tHCODE_ACCOUNT_ID: ref.accountId,\n\t\t\tHCODE_GENERATION: ref.generation,\n\t\t},\n\t};\n}\n\n// Forge replays tool call IDs only in this form; other providers' IDs (for example `call_…|fc_…`) are rewritten.\nconst replayableToolCallId = /^[A-Za-z0-9_-]{1,64}$/;\nconst foreignToolCallId = (id: string) =>\n\treplayableToolCallId.test(id) ? id : `call_${createHash(\"sha256\").update(id).digest(\"hex\").slice(0, 32)}`;\n\n// Project history for the destination model without changing the saved transcript.\nexport function projectHcodeContext(\n\tcontext: TranscriptContext,\n\tmodel: Pick<Model<Api>, \"id\" | \"reasoning\">,\n): TranscriptContext {\n\tconst messages: TranscriptContext[\"messages\"] = [];\n\tconst activeTools = new Set<string>();\n\tconst pending = new Map<string, { id: string; name: string; timestamp: number }>();\n\tconst closeTurn = () => {\n\t\tfor (const call of pending.values()) {\n\t\t\tmessages.push({\n\t\t\t\trole: \"toolResult\",\n\t\t\t\ttoolCallId: call.id,\n\t\t\t\ttoolName: call.name,\n\t\t\t\tcontent: [{ type: \"text\", text: \"No result provided\" }],\n\t\t\t\tisError: true,\n\t\t\t\ttimestamp: call.timestamp,\n\t\t\t});\n\t\t}\n\t\tpending.clear();\n\t};\n\tfor (const message of context.messages) {\n\t\tif (message.role === \"system\") {\n\t\t\t// Evaluate calls against the tools declared at their turn, not the final live loadout.\n\t\t\tfor (const tool of message.toolsRemoved ?? []) activeTools.delete(tool.name);\n\t\t\tfor (const tool of message.toolsAdded ?? []) activeTools.add(tool.name);\n\t\t\tmessages.push(projectHcodeSystemMessage(message));\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"toolResult\") {\n\t\t\tconst call = pending.get(message.toolCallId);\n\t\t\tif (!call || call.name !== message.toolName) continue;\n\t\t\tpending.delete(message.toolCallId);\n\t\t\t// Execution details and nested calls are session/UI bookkeeping, not model input.\n\t\t\tmessages.push({\n\t\t\t\trole: \"toolResult\",\n\t\t\t\ttoolCallId: call.id,\n\t\t\t\ttoolName: message.toolName,\n\t\t\t\tcontent: message.content,\n\t\t\t\tisError: message.isError,\n\t\t\t\ttimestamp: message.timestamp,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tcloseTurn();\n\t\tif (message.role === \"user\") {\n\t\t\tmessages.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\t// Incomplete turns were never replayable and may contain calls that never ran.\n\t\tif (message.stopReason === \"error\" || message.stopReason === \"aborted\" || message.stopReason === \"deferred\")\n\t\t\tcontinue;\n\t\tconst sameModel =\n\t\t\tmessage.provider === HCODE_PROVIDER && message.api === \"pi-messages\" && message.model === model.id;\n\t\tconst { deferred: _handle, providerThinkingLevel, ...assistant } = message;\n\t\tconst content = assistant.content.flatMap((block): AssistantMessage[\"content\"] => {\n\t\t\tif (block.type === \"thinking\") return sameModel && model.reasoning ? [block] : [];\n\t\t\tif (block.type === \"text\") return [sameModel ? block : { type: \"text\", text: block.text }];\n\t\t\tif (block.argumentsError !== undefined || !activeTools.has(block.name)) return [];\n\t\t\tconst id = sameModel ? block.id : foreignToolCallId(block.id);\n\t\t\tpending.set(block.id, { id, name: block.name, timestamp: message.timestamp });\n\t\t\tif (sameModel) return [block];\n\t\t\t// rawArguments is OpenAI Responses replay text and not part of the closed HUMAIN Code request contract.\n\t\t\tconst { thoughtSignature: _signature, rawArguments: _rawArguments, ...call } = block;\n\t\t\treturn [{ ...call, id }];\n\t\t});\n\t\tif (!content.length && (!sameModel || message.content.length)) continue;\n\t\tmessages.push({\n\t\t\t...assistant,\n\t\t\tcontent,\n\t\t\tstopReason: assistant.stopReason === \"toolUse\" && !pending.size ? \"stop\" : assistant.stopReason,\n\t\t\t...(sameModel && providerThinkingLevel !== undefined ? { providerThinkingLevel } : {}),\n\t\t});\n\t}\n\tcloseTurn();\n\treturn { ...context, messages };\n}\n\nfunction projectHcodeSystemMessage(message: SystemMessage): SystemMessage {\n\t// Catalog v1 qualifies ordinary JSON-schema tools, not provider-side constrained sampling.\n\tif (!message.toolsAdded?.some((tool) => tool.constrainedSampling)) return message;\n\treturn {\n\t\t...message,\n\t\ttoolsAdded: message.toolsAdded.map((tool) => {\n\t\t\tconst { constrainedSampling, ...ordinaryTool } = tool;\n\t\t\tif (\n\t\t\t\tconstrainedSampling &&\n\t\t\t\tconstrainedSampling.type === \"json_schema\" &&\n\t\t\t\tconstrainedSampling.strict === \"require\"\n\t\t\t)\n\t\t\t\tthrow new HcodeLocalRefusal(\"strictTools\");\n\t\t\treturn constrainedSampling ? ordinaryTool : tool;\n\t\t}),\n\t};\n}\n\n/** Creates the dormant provider; no registration-time credential reads, probes or network work occur. */\nexport function createHcodeProvider(\n\taccount: HcodeAccountPort,\n\tenvironment: HcodeEnvironment = resolveHcodeEnvironment(),\n): HcodeProvider {\n\tconst name = hcodeDisplayName(environment.id);\n\tlet disposed = false;\n\tlet scope: HcodeAccountRef | null = null;\n\tlet models: readonly Model<\"pi-messages\">[] = Object.freeze([]);\n\tlet emptyReason: HcodeCatalogEmptyReason | undefined;\n\tlet exclusions: ReadonlyMap<string, HcodeCatalogExclusionReason> = new Map();\n\tconst clear = () => {\n\t\tscope = null;\n\t\tmodels = Object.freeze([]);\n\t\temptyReason = undefined;\n\t\texclusions = new Map();\n\t};\n\tconst unsubscribe = account.subscribe(clear);\n\tconst current = () => !disposed && scope && sameReference(account.status(scope.environmentId), scope);\n\tconst getModels = () => {\n\t\tif (!current()) clear();\n\t\treturn models;\n\t};\n\tconst credentialReference = (credential: ApiKeyCredential | undefined): HcodeAccountRef | null => {\n\t\tif (disposed || !credential || credential.key !== undefined || !credential.env) return null;\n\t\ttry {\n\t\t\tconst env = credential.env;\n\t\t\tconst ref = {\n\t\t\t\tenvironmentId: wire.string(env.HCODE_ENVIRONMENT_ID),\n\t\t\t\taccountId: wire.string(env.HCODE_ACCOUNT_ID),\n\t\t\t\tgeneration: wire.string(env.HCODE_GENERATION, 36),\n\t\t\t};\n\t\t\treturn ref.environmentId === environment.id && sameReference(account.status(ref.environmentId), ref)\n\t\t\t\t? ref\n\t\t\t\t: null;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t};\n\tconst native = piMessagesApi();\n\tconst run = (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions: SimpleStreamOptions | undefined,\n\t\tmethod: \"stream\" | \"streamSimple\",\n\t) => {\n\t\t// Capture before lazy loading, auth resolution, callbacks or refresh can yield.\n\t\tconst expected = current() ? scope : null;\n\t\tconst canonical = models.find((entry) => entry.id === model.id);\n\t\tconst idempotencyKey = randomUUID();\n\t\tlet failure: HcodeTransportError | HcodeLocalRefusal | undefined;\n\t\tconst refuse = (reason: HcodeLocalReason): never => {\n\t\t\tfailure = new HcodeLocalRefusal(reason);\n\t\t\tthrow failure;\n\t\t};\n\t\tconst controller = new AbortController();\n\t\tconst signal = options?.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;\n\t\tconst queue = new ManagedAssistantMessageQueue(model, new HcodeTransportError().message, () =>\n\t\t\tcontroller.abort(),\n\t\t);\n\t\tconst source = lazyStream(\n\t\t\tmodel,\n\t\t\tasync () => {\n\t\t\t\tif (\n\t\t\t\t\t!expected ||\n\t\t\t\t\t!canonical ||\n\t\t\t\t\tdisposed ||\n\t\t\t\t\tmodel.provider !== HCODE_PROVIDER ||\n\t\t\t\t\tmodel.api !== \"pi-messages\" ||\n\t\t\t\t\t!sameReference(account.status(expected.environmentId), expected)\n\t\t\t\t)\n\t\t\t\t\treturn refuse(\"account\");\n\t\t\t\tif (options?.transport && options.transport !== \"sse\") return refuse(\"transport\");\n\t\t\t\tlet projected: TranscriptContext;\n\t\t\t\ttry {\n\t\t\t\t\tprojected = projectHcodeContext(context, canonical);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof HcodeLocalRefusal) failure = error;\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tconst active = new Set(\n\t\t\t\t\tprojected.messages.flatMap((message, index) =>\n\t\t\t\t\t\tArray.isArray(message.content) && hcodeActivePrompts.has(message.content) ? [index] : [],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tlet wireOmissions = 0;\n\t\t\t\tconst delegated = createHcodeTransport(\n\t\t\t\t\t{\n\t\t\t\t\t\t...account,\n\t\t\t\t\t\tstatus: (id) => (!disposed && models.includes(canonical) ? account.status(id) : null),\n\t\t\t\t\t},\n\t\t\t\t\tenvironment,\n\t\t\t\t\texpected,\n\t\t\t\t\tcanonical,\n\t\t\t\t\tidempotencyKey,\n\t\t\t\t\t() => wireOmissions,\n\t\t\t\t);\n\t\t\t\tconst safeOptions: SimpleStreamOptions & { managedQueue: ManagedAssistantMessageQueue } = {\n\t\t\t\t\tmanagedQueue: queue,\n\t\t\t\t\tsignal,\n\t\t\t\t\ttemperature: options?.temperature,\n\t\t\t\t\tmaxTokens: options?.maxTokens ?? Math.min(4096, canonical.maxTokens),\n\t\t\t\t\treasoning: options?.reasoning,\n\t\t\t\t\ttoolChoice: options?.toolChoice,\n\t\t\t\t\ttransport: \"sse\",\n\t\t\t\t\tcacheRetention: \"none\",\n\t\t\t\t\tmaxRetries: 0,\n\t\t\t\t\tonPayload: async (payload, nativeModel) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Native pi-messages constructs this envelope from the projected transcript.\n\t\t\t\t\t\t\tlet envelope = payload as { context: TranscriptContext };\n\t\t\t\t\t\t\tlet protectedMessages = active;\n\t\t\t\t\t\t\tif (options?.onPayload) {\n\t\t\t\t\t\t\t\tconst hook = hcodeImagePayloadDraft(envelope, active);\n\t\t\t\t\t\t\t\tconst changed = await options.onPayload(hook.draft, nativeModel);\n\t\t\t\t\t\t\t\t// The hook returns unknown; the strict parser below remains the final schema check.\n\t\t\t\t\t\t\t\tenvelope = changed === undefined ? hook.draft : (changed as typeof envelope);\n\t\t\t\t\t\t\t\tprotectedMessages = hook.protectedMessages(envelope.context.messages);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (Array.isArray(envelope.context.messages) && envelope.context.messages.length > 512) {\n\t\t\t\t\t\t\t\tthrow new HcodeLocalRefusal(\"envelope\", \"messageLimit\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst fitted = await fitHcodeRequestSize(\n\t\t\t\t\t\t\t\tcanonical,\n\t\t\t\t\t\t\t\tenvelope.context.messages,\n\t\t\t\t\t\t\t\tprotectedMessages,\n\t\t\t\t\t\t\t\t(messages) => JSON.stringify({ ...envelope, context: { ...envelope.context, messages } }),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (!fitted) {\n\t\t\t\t\t\t\t\tif (active.size && protectedMessages.size) reportHcodeImageSizeRefusal();\n\t\t\t\t\t\t\t\treturn refuse(\"size\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\twireOmissions = fitted.omitted;\n\t\t\t\t\t\t\treturn parseHcodeRequestBody(fitted.body);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (error instanceof HcodeLocalRefusal) {\n\t\t\t\t\t\t\t\tfailure = error;\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn refuse(\"envelope\");\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tonRequest: options?.onRequest,\n\t\t\t\t\tonResponse: options?.onResponse,\n\t\t\t\t\tonProviderStreamEvent: options?.onProviderStreamEvent,\n\t\t\t\t\tfetch: createDelegatedFetch(async (input, init) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn await delegated(input, init);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tfailure =\n\t\t\t\t\t\t\t\terror instanceof HcodeTransportError || error instanceof HcodeLocalRefusal ? error : undefined;\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t\treturn native[method](canonical, projected, safeOptions);\n\t\t\t},\n\t\t\tundefined,\n\t\t\tsignal,\n\t\t\tqueue,\n\t\t);\n\t\treturn lazyStream(\n\t\t\tmodel,\n\t\t\tasync () =>\n\t\t\t\t(async function* (): AsyncGenerator<AssistantMessageEvent> {\n\t\t\t\t\tfor await (const event of source) {\n\t\t\t\t\t\tif (event.type === \"error\") {\n\t\t\t\t\t\t\tevent.error.errorMessage = failure?.message ?? new HcodeTransportError().message;\n\t\t\t\t\t\t\tevent.error.diagnostics = [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"provider_http_error\",\n\t\t\t\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t\t\t\t...(failure instanceof HcodeLocalRefusal\n\t\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\t\thcodeLocalReason: failure.reason,\n\t\t\t\t\t\t\t\t\t\t\t\t\t...(failure.detail ? { hcodeLocalDetail: failure.detail } : {}),\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t: failure?.failure\n\t\t\t\t\t\t\t\t\t\t\t\t? { hcode: failure.diagnostics() }\n\t\t\t\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tyield event;\n\t\t\t\t\t}\n\t\t\t\t})(),\n\t\t\tundefined,\n\t\t\tsignal,\n\t\t\tqueue,\n\t\t);\n\t};\n\tconst base = createProvider<\"pi-messages\">({\n\t\tid: HCODE_PROVIDER,\n\t\tname,\n\t\tbaseUrl: environment.inferenceBaseUrl,\n\t\tmodels: [],\n\t\tauth: {\n\t\t\tapiKey: {\n\t\t\t\tname,\n\t\t\t\tlogin: async (interaction) => {\n\t\t\t\t\tif (disposed) throw new Error(\"HUMAIN Code account provider is disposed.\");\n\t\t\t\t\tconst reference = await account.login(interaction, interaction.signal);\n\t\t\t\t\tif (disposed) throw new Error(\"HUMAIN Code account provider is disposed.\");\n\t\t\t\t\treturn hcodeReferenceCredential(reference);\n\t\t\t\t},\n\t\t\t\tcheck: async ({ credential, signal }) => {\n\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\treturn credentialReference(credential) ? { type: \"api_key\", source: \"HUMAIN Code account\" } : undefined;\n\t\t\t\t},\n\t\t\t\tresolve: async ({ credential, signal }) => {\n\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\tconst ref = credentialReference(credential);\n\t\t\t\t\treturn ref\n\t\t\t\t\t\t? { auth: {}, env: hcodeReferenceCredential(ref).env, source: \"HUMAIN Code account\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tapi: {\n\t\t\tstream: (model, context, options) => run(model, context, options, \"stream\"),\n\t\t\tstreamSimple: (model, context, options) => run(model, context, options, \"streamSimple\"),\n\t\t},\n\t});\n\treturn {\n\t\t...base,\n\t\tdispose() {\n\t\t\tif (disposed) return;\n\t\t\tdisposed = true;\n\t\t\tunsubscribe();\n\t\t\tclear();\n\t\t},\n\t\tgetModels,\n\t\tgetAllModels: getModels,\n\t\tcatalogEmptyReason: () => (getModels().length ? undefined : emptyReason),\n\t\tcatalogExclusionReason: (modelId) => {\n\t\t\t// Match `/model` exact references, which compare IDs case-insensitively.\n\t\t\tconst normalized = modelId.toLowerCase();\n\t\t\tif (getModels().some((model) => model.id.toLowerCase() === normalized)) return undefined;\n\t\t\tconst exact = exclusions.get(modelId);\n\t\t\tif (exact) return exact;\n\t\t\tfor (const [id, reason] of exclusions) {\n\t\t\t\tif (id.toLowerCase() === normalized) return reason;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t},\n\t\tcatalogLoaded: () => !!current(),\n\t\tasync refreshModels(context) {\n\t\t\tconst expected = context.credential?.type === \"api_key\" ? credentialReference(context.credential) : null;\n\t\t\tif (!expected) {\n\t\t\t\tclear();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\tlet reason: HcodeCatalogEmptyReason | undefined;\n\t\t\tlet excluded: ReadonlyMap<string, HcodeCatalogExclusionReason> = new Map();\n\t\t\tconst entries = parseHcodeModelList(\n\t\t\t\tawait hcodeJson(\n\t\t\t\t\tasync (url, init) => {\n\t\t\t\t\t\tconst response = await account.authorizedFetch(expected, String(url), init ?? {});\n\t\t\t\t\t\treason = parseHcodeCatalogEmptyReason(response.headers.get(HCODE_CATALOG_EMPTY_REASON_HEADER));\n\t\t\t\t\t\texcluded = parseHcodeCatalogExclusions(response.headers.get(HCODE_CATALOG_EXCLUSIONS_HEADER));\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t},\n\t\t\t\t\t`${environment.inferenceBaseUrl}/models`,\n\t\t\t\t\t{ signal: context.signal },\n\t\t\t\t),\n\t\t\t).data;\n\t\t\tconst next = deriveHcodeCatalog(entries, environment);\n\t\t\tif (disposed || context.signal.aborted || !sameReference(account.status(expected.environmentId), expected))\n\t\t\t\treturn;\n\t\t\tawait context.publish({\n\t\t\t\tpersist: null,\n\t\t\t\tupdate: () => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tdisposed ||\n\t\t\t\t\t\tcontext.signal.aborted ||\n\t\t\t\t\t\t!sameReference(account.status(expected.environmentId), expected)\n\t\t\t\t\t)\n\t\t\t\t\t\treturn;\n\t\t\t\t\t// Unchanged approval must not invalidate a picker row or an in-flight selection.\n\t\t\t\t\tif (!sameReference(scope, expected) || !isDeepStrictEqual(models, next)) models = next;\n\t\t\t\t\tscope = expected;\n\t\t\t\t\temptyReason = next.length ? undefined : reason;\n\t\t\t\t\texclusions = excluded;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../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AM,CAAC,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC;gBACzG,OAAO;YACR,MAAM,OAAO,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,GAAG,EAAE;oBACZ,IACC,QAAQ;wBACR,OAAO,CAAC,MAAM,CAAC,OAAO;wBACtB,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC;wBAEhE,OAAO;oBACR,iFAAiF;oBACjF,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC;wBAAE,MAAM,GAAG,IAAI,CAAC;oBACvF,KAAK,GAAG,QAAQ,CAAC;oBACjB,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;oBAC/C,UAAU,GAAG,QAAQ,CAAC;gBACvB,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["// Managed account provider: reference-only auth and account-scoped pi-messages catalog.\nimport { createHash, randomUUID } from \"node:crypto\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport {\n\ttype Api,\n\ttype ApiKeyCredential,\n\ttype AssistantMessage,\n\ttype AssistantMessageEvent,\n\tcreateDelegatedFetch,\n\tcreateProvider,\n\tlazyStream,\n\tManagedAssistantMessageQueue,\n\ttype Model,\n\ttype Provider,\n\ttype SimpleStreamOptions,\n\ttype SystemMessage,\n\ttype TranscriptContext,\n} from \"@earendil-works/pi-ai\";\nimport { piMessagesApi } from \"@earendil-works/pi-ai/api/pi-messages.lazy\";\nimport { sameReference } from \"./account-store.ts\";\nimport { deriveHcodeCatalog } from \"./catalog.ts\";\nimport {\n\tHCODE_CATALOG_EMPTY_REASON_HEADER,\n\tHCODE_CATALOG_EXCLUSIONS_HEADER,\n\ttype HcodeCatalogEmptyReason,\n\ttype HcodeCatalogExclusionReason,\n\tparseHcodeCatalogEmptyReason,\n\tparseHcodeCatalogExclusions,\n\tparseHcodeModelList,\n} from \"./contracts.ts\";\nimport { type HcodeEnvironment, hcodeDisplayName, resolveHcodeEnvironment } from \"./environment.ts\";\nimport { HCODE_PROVIDER, hcodeJson } from \"./http.ts\";\nimport {\n\tfitHcodeRequestSize,\n\thcodeActivePrompts,\n\thcodeImagePayloadDraft,\n\treportHcodeImageSizeRefusal,\n} from \"./images.ts\";\nimport type { HcodeLocalReason } from \"./notices.ts\";\nimport type { HcodeAccountPort, HcodeAccountRef } from \"./ports.ts\";\nimport { createHcodeTransport, HcodeLocalRefusal, HcodeTransportError, parseHcodeRequestBody } from \"./transport.ts\";\nimport * as wire from \"./wire.ts\";\n\n/** Account-bound native provider whose owning runtime must dispose its subscription and catalog. */\nexport interface HcodeProvider extends Provider<\"pi-messages\"> {\n\t/** Release account observation and prevent further catalog/auth/request work. */\n\tdispose(): void;\n\t/** Forge's reason the current account's catalog is empty, if it sent a known one. */\n\tcatalogEmptyReason(): HcodeCatalogEmptyReason | undefined;\n\t/** Forge's reason the current account's catalog left out this exact model ID, if it sent a known one. */\n\tcatalogExclusionReason(modelId: string): HcodeCatalogExclusionReason | undefined;\n\t/** Whether this process has read the current account's catalog; a new process reads it when /model opens. */\n\tcatalogLoaded(): boolean;\n}\n\n/** Returns only the keyless local reference allowed in the generic credential pool. */\nexport function hcodeReferenceCredential(ref: HcodeAccountRef): ApiKeyCredential {\n\treturn {\n\t\ttype: \"api_key\",\n\t\tenv: {\n\t\t\tHCODE_ENVIRONMENT_ID: ref.environmentId,\n\t\t\tHCODE_ACCOUNT_ID: ref.accountId,\n\t\t\tHCODE_GENERATION: ref.generation,\n\t\t},\n\t};\n}\n\n// Forge replays tool call IDs only in this form; other providers' IDs (for example `call_…|fc_…`) are rewritten.\nconst replayableToolCallId = /^[A-Za-z0-9_-]{1,64}$/;\nconst foreignToolCallId = (id: string) =>\n\treplayableToolCallId.test(id) ? id : `call_${createHash(\"sha256\").update(id).digest(\"hex\").slice(0, 32)}`;\n\n// Project history for the destination model without changing the saved transcript.\nexport function projectHcodeContext(\n\tcontext: TranscriptContext,\n\tmodel: Pick<Model<Api>, \"id\" | \"reasoning\">,\n): TranscriptContext {\n\tconst messages: TranscriptContext[\"messages\"] = [];\n\tconst activeTools = new Set<string>();\n\tconst pending = new Map<string, { id: string; name: string; timestamp: number }>();\n\tconst closeTurn = () => {\n\t\tfor (const call of pending.values()) {\n\t\t\tmessages.push({\n\t\t\t\trole: \"toolResult\",\n\t\t\t\ttoolCallId: call.id,\n\t\t\t\ttoolName: call.name,\n\t\t\t\tcontent: [{ type: \"text\", text: \"No result provided\" }],\n\t\t\t\tisError: true,\n\t\t\t\ttimestamp: call.timestamp,\n\t\t\t});\n\t\t}\n\t\tpending.clear();\n\t};\n\tfor (const message of context.messages) {\n\t\tif (message.role === \"system\") {\n\t\t\t// Evaluate calls against the tools declared at their turn, not the final live loadout.\n\t\t\tfor (const tool of message.toolsRemoved ?? []) activeTools.delete(tool.name);\n\t\t\tfor (const tool of message.toolsAdded ?? []) activeTools.add(tool.name);\n\t\t\tmessages.push(projectHcodeSystemMessage(message));\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"toolResult\") {\n\t\t\tconst call = pending.get(message.toolCallId);\n\t\t\tif (!call || call.name !== message.toolName) continue;\n\t\t\tpending.delete(message.toolCallId);\n\t\t\t// Execution details and nested calls are session/UI bookkeeping, not model input.\n\t\t\tmessages.push({\n\t\t\t\trole: \"toolResult\",\n\t\t\t\ttoolCallId: call.id,\n\t\t\t\ttoolName: message.toolName,\n\t\t\t\tcontent: message.content,\n\t\t\t\tisError: message.isError,\n\t\t\t\ttimestamp: message.timestamp,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tcloseTurn();\n\t\tif (message.role === \"user\") {\n\t\t\tmessages.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\t// Incomplete turns were never replayable and may contain calls that never ran.\n\t\tif (message.stopReason === \"error\" || message.stopReason === \"aborted\" || message.stopReason === \"deferred\")\n\t\t\tcontinue;\n\t\tconst sameModel =\n\t\t\tmessage.provider === HCODE_PROVIDER && message.api === \"pi-messages\" && message.model === model.id;\n\t\tconst { deferred: _handle, providerThinkingLevel, ...assistant } = message;\n\t\tconst content = assistant.content.flatMap((block): AssistantMessage[\"content\"] => {\n\t\t\tif (block.type === \"thinking\") return sameModel && model.reasoning ? [block] : [];\n\t\t\tif (block.type === \"text\") return [sameModel ? block : { type: \"text\", text: block.text }];\n\t\t\tif (block.argumentsError !== undefined || !activeTools.has(block.name)) return [];\n\t\t\tconst id = sameModel ? block.id : foreignToolCallId(block.id);\n\t\t\tpending.set(block.id, { id, name: block.name, timestamp: message.timestamp });\n\t\t\tif (sameModel) return [block];\n\t\t\t// rawArguments is OpenAI Responses replay text and not part of the closed HUMAIN Code request contract.\n\t\t\tconst { thoughtSignature: _signature, rawArguments: _rawArguments, ...call } = block;\n\t\t\treturn [{ ...call, id }];\n\t\t});\n\t\tif (!content.length && (!sameModel || message.content.length)) continue;\n\t\tmessages.push({\n\t\t\t...assistant,\n\t\t\tcontent,\n\t\t\tstopReason: assistant.stopReason === \"toolUse\" && !pending.size ? \"stop\" : assistant.stopReason,\n\t\t\t...(sameModel && providerThinkingLevel !== undefined ? { providerThinkingLevel } : {}),\n\t\t});\n\t}\n\tcloseTurn();\n\treturn { ...context, messages };\n}\n\nfunction projectHcodeSystemMessage(message: SystemMessage): SystemMessage {\n\t// Catalog v1 qualifies ordinary JSON-schema tools, not provider-side constrained sampling.\n\tif (!message.toolsAdded?.some((tool) => tool.constrainedSampling)) return message;\n\treturn {\n\t\t...message,\n\t\ttoolsAdded: message.toolsAdded.map((tool) => {\n\t\t\tconst { constrainedSampling, ...ordinaryTool } = tool;\n\t\t\tif (\n\t\t\t\tconstrainedSampling &&\n\t\t\t\tconstrainedSampling.type === \"json_schema\" &&\n\t\t\t\tconstrainedSampling.strict === \"require\"\n\t\t\t)\n\t\t\t\tthrow new HcodeLocalRefusal(\"strictTools\");\n\t\t\treturn constrainedSampling ? ordinaryTool : tool;\n\t\t}),\n\t};\n}\n\n/** Creates the dormant provider; no registration-time credential reads, probes or network work occur. */\nexport function createHcodeProvider(\n\taccount: HcodeAccountPort,\n\tenvironment: HcodeEnvironment = resolveHcodeEnvironment(),\n): HcodeProvider {\n\tconst name = hcodeDisplayName(environment.id);\n\tlet disposed = false;\n\tlet scope: HcodeAccountRef | null = null;\n\tlet models: readonly Model<\"pi-messages\">[] = Object.freeze([]);\n\tlet emptyReason: HcodeCatalogEmptyReason | undefined;\n\tlet exclusions: ReadonlyMap<string, HcodeCatalogExclusionReason> = new Map();\n\tconst clear = () => {\n\t\tscope = null;\n\t\tmodels = Object.freeze([]);\n\t\temptyReason = undefined;\n\t\texclusions = new Map();\n\t};\n\tconst unsubscribe = account.subscribe(clear);\n\tconst current = () => !disposed && scope && sameReference(account.status(scope.environmentId), scope);\n\tconst getModels = () => {\n\t\tif (!current()) clear();\n\t\treturn models;\n\t};\n\tconst credentialReference = (credential: ApiKeyCredential | undefined): HcodeAccountRef | null => {\n\t\tif (disposed || !credential || credential.key !== undefined || !credential.env) return null;\n\t\ttry {\n\t\t\tconst env = credential.env;\n\t\t\tconst ref = {\n\t\t\t\tenvironmentId: wire.string(env.HCODE_ENVIRONMENT_ID),\n\t\t\t\taccountId: wire.string(env.HCODE_ACCOUNT_ID),\n\t\t\t\tgeneration: wire.string(env.HCODE_GENERATION, 36),\n\t\t\t};\n\t\t\treturn ref.environmentId === environment.id && sameReference(account.status(ref.environmentId), ref)\n\t\t\t\t? ref\n\t\t\t\t: null;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t};\n\tconst native = piMessagesApi();\n\tconst run = (\n\t\tmodel: Model<Api>,\n\t\tcontext: TranscriptContext,\n\t\toptions: SimpleStreamOptions | undefined,\n\t\tmethod: \"stream\" | \"streamSimple\",\n\t) => {\n\t\t// Capture before lazy loading, auth resolution, callbacks or refresh can yield.\n\t\tconst expected = current() ? scope : null;\n\t\tconst canonical = models.find((entry) => entry.id === model.id);\n\t\tconst idempotencyKey = randomUUID();\n\t\tlet failure: HcodeTransportError | HcodeLocalRefusal | undefined;\n\t\tconst refuse = (reason: HcodeLocalReason): never => {\n\t\t\tfailure = new HcodeLocalRefusal(reason);\n\t\t\tthrow failure;\n\t\t};\n\t\tconst controller = new AbortController();\n\t\tconst signal = options?.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;\n\t\tconst queue = new ManagedAssistantMessageQueue(model, new HcodeTransportError().message, () =>\n\t\t\tcontroller.abort(),\n\t\t);\n\t\tconst source = lazyStream(\n\t\t\tmodel,\n\t\t\tasync () => {\n\t\t\t\tif (\n\t\t\t\t\t!expected ||\n\t\t\t\t\t!canonical ||\n\t\t\t\t\tdisposed ||\n\t\t\t\t\tmodel.provider !== HCODE_PROVIDER ||\n\t\t\t\t\tmodel.api !== \"pi-messages\" ||\n\t\t\t\t\t!sameReference(account.status(expected.environmentId), expected)\n\t\t\t\t)\n\t\t\t\t\treturn refuse(\"account\");\n\t\t\t\tif (options?.transport && options.transport !== \"sse\") return refuse(\"transport\");\n\t\t\t\tlet projected: TranscriptContext;\n\t\t\t\ttry {\n\t\t\t\t\tprojected = projectHcodeContext(context, canonical);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof HcodeLocalRefusal) failure = error;\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tconst active = new Set(\n\t\t\t\t\tprojected.messages.flatMap((message, index) =>\n\t\t\t\t\t\tArray.isArray(message.content) && hcodeActivePrompts.has(message.content) ? [index] : [],\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tlet wireOmissions = 0;\n\t\t\t\tconst delegated = createHcodeTransport(\n\t\t\t\t\t{\n\t\t\t\t\t\t...account,\n\t\t\t\t\t\tstatus: (id) => (!disposed && models.includes(canonical) ? account.status(id) : null),\n\t\t\t\t\t},\n\t\t\t\t\tenvironment,\n\t\t\t\t\texpected,\n\t\t\t\t\tcanonical,\n\t\t\t\t\tidempotencyKey,\n\t\t\t\t\t() => wireOmissions,\n\t\t\t\t);\n\t\t\t\tconst safeOptions: SimpleStreamOptions & { managedQueue: ManagedAssistantMessageQueue } = {\n\t\t\t\t\tmanagedQueue: queue,\n\t\t\t\t\tsignal,\n\t\t\t\t\ttemperature: options?.temperature,\n\t\t\t\t\tmaxTokens: options?.maxTokens ?? Math.min(4096, canonical.maxTokens),\n\t\t\t\t\treasoning: options?.reasoning,\n\t\t\t\t\ttoolChoice: options?.toolChoice,\n\t\t\t\t\ttransport: \"sse\",\n\t\t\t\t\tcacheRetention: \"none\",\n\t\t\t\t\tmaxRetries: 0,\n\t\t\t\t\tonPayload: async (payload, nativeModel) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Native pi-messages constructs this envelope from the projected transcript.\n\t\t\t\t\t\t\tlet envelope = payload as { context: TranscriptContext };\n\t\t\t\t\t\t\tlet protectedMessages = active;\n\t\t\t\t\t\t\tif (options?.onPayload) {\n\t\t\t\t\t\t\t\tconst hook = hcodeImagePayloadDraft(envelope, active);\n\t\t\t\t\t\t\t\tconst changed = await options.onPayload(hook.draft, nativeModel);\n\t\t\t\t\t\t\t\t// The hook returns unknown; the strict parser below remains the final schema check.\n\t\t\t\t\t\t\t\tenvelope = changed === undefined ? hook.draft : (changed as typeof envelope);\n\t\t\t\t\t\t\t\tprotectedMessages = hook.protectedMessages(envelope.context.messages);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (Array.isArray(envelope.context.messages) && envelope.context.messages.length > 512) {\n\t\t\t\t\t\t\t\tthrow new HcodeLocalRefusal(\"envelope\", \"messageLimit\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst fitted = await fitHcodeRequestSize(\n\t\t\t\t\t\t\t\tcanonical,\n\t\t\t\t\t\t\t\tenvelope.context.messages,\n\t\t\t\t\t\t\t\tprotectedMessages,\n\t\t\t\t\t\t\t\t(messages) => JSON.stringify({ ...envelope, context: { ...envelope.context, messages } }),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (!fitted) {\n\t\t\t\t\t\t\t\tif (active.size && protectedMessages.size) reportHcodeImageSizeRefusal();\n\t\t\t\t\t\t\t\treturn refuse(\"size\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\twireOmissions = fitted.omitted;\n\t\t\t\t\t\t\treturn parseHcodeRequestBody(fitted.body);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (error instanceof HcodeLocalRefusal) {\n\t\t\t\t\t\t\t\tfailure = error;\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn refuse(\"envelope\");\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tonRequest: options?.onRequest,\n\t\t\t\t\tonResponse: options?.onResponse,\n\t\t\t\t\tonProviderStreamEvent: options?.onProviderStreamEvent,\n\t\t\t\t\tfetch: createDelegatedFetch(async (input, init) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn await delegated(input, init);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tfailure =\n\t\t\t\t\t\t\t\terror instanceof HcodeTransportError || error instanceof HcodeLocalRefusal ? error : undefined;\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t\treturn native[method](canonical, projected, safeOptions);\n\t\t\t},\n\t\t\tundefined,\n\t\t\tsignal,\n\t\t\tqueue,\n\t\t);\n\t\treturn lazyStream(\n\t\t\tmodel,\n\t\t\tasync () =>\n\t\t\t\t(async function* (): AsyncGenerator<AssistantMessageEvent> {\n\t\t\t\t\tfor await (const event of source) {\n\t\t\t\t\t\tif (event.type === \"error\") {\n\t\t\t\t\t\t\tevent.error.errorMessage = failure?.message ?? new HcodeTransportError().message;\n\t\t\t\t\t\t\tevent.error.diagnostics = [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"provider_http_error\",\n\t\t\t\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t\t\t\t...(failure instanceof HcodeLocalRefusal\n\t\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\t\thcodeLocalReason: failure.reason,\n\t\t\t\t\t\t\t\t\t\t\t\t\t...(failure.detail ? { hcodeLocalDetail: failure.detail } : {}),\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t: failure?.failure\n\t\t\t\t\t\t\t\t\t\t\t\t? { hcode: failure.diagnostics() }\n\t\t\t\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tyield event;\n\t\t\t\t\t}\n\t\t\t\t})(),\n\t\t\tundefined,\n\t\t\tsignal,\n\t\t\tqueue,\n\t\t);\n\t};\n\tconst base = createProvider<\"pi-messages\">({\n\t\tid: HCODE_PROVIDER,\n\t\tname,\n\t\tbaseUrl: environment.inferenceBaseUrl,\n\t\tmodels: [],\n\t\tauth: {\n\t\t\tapiKey: {\n\t\t\t\tname,\n\t\t\t\tlogin: async (interaction) => {\n\t\t\t\t\tif (disposed) throw new Error(\"HUMAIN Code account provider is disposed.\");\n\t\t\t\t\tconst reference = await account.login(interaction, interaction.signal);\n\t\t\t\t\tif (disposed) throw new Error(\"HUMAIN Code account provider is disposed.\");\n\t\t\t\t\treturn hcodeReferenceCredential(reference);\n\t\t\t\t},\n\t\t\t\tcheck: async ({ credential, signal }) => {\n\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\treturn credentialReference(credential) ? { type: \"api_key\", source: \"HUMAIN Code account\" } : undefined;\n\t\t\t\t},\n\t\t\t\tresolve: async ({ credential, signal }) => {\n\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\tconst ref = credentialReference(credential);\n\t\t\t\t\treturn ref\n\t\t\t\t\t\t? { auth: {}, env: hcodeReferenceCredential(ref).env, source: \"HUMAIN Code account\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tapi: {\n\t\t\tstream: (model, context, options) => run(model, context, options, \"stream\"),\n\t\t\tstreamSimple: (model, context, options) => run(model, context, options, \"streamSimple\"),\n\t\t},\n\t});\n\treturn {\n\t\t...base,\n\t\tdispose() {\n\t\t\tif (disposed) return;\n\t\t\tdisposed = true;\n\t\t\tunsubscribe();\n\t\t\tclear();\n\t\t},\n\t\tgetModels,\n\t\tgetAllModels: getModels,\n\t\tcatalogEmptyReason: () => (getModels().length ? undefined : emptyReason),\n\t\tcatalogExclusionReason: (modelId) => {\n\t\t\t// Match `/model` exact references, which compare IDs case-insensitively.\n\t\t\tconst normalized = modelId.toLowerCase();\n\t\t\tif (getModels().some((model) => model.id.toLowerCase() === normalized)) return undefined;\n\t\t\tconst exact = exclusions.get(modelId);\n\t\t\tif (exact) return exact;\n\t\t\tfor (const [id, reason] of exclusions) {\n\t\t\t\tif (id.toLowerCase() === normalized) return reason;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t},\n\t\tcatalogLoaded: () => !!current(),\n\t\tasync refreshModels(context) {\n\t\t\tconst expected = context.credential?.type === \"api_key\" ? credentialReference(context.credential) : null;\n\t\t\tif (!expected) {\n\t\t\t\tclear();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\tlet reason: HcodeCatalogEmptyReason | undefined;\n\t\t\tlet excluded: ReadonlyMap<string, HcodeCatalogExclusionReason> = new Map();\n\t\t\tconst entries = parseHcodeModelList(\n\t\t\t\tawait hcodeJson(\n\t\t\t\t\tasync (url, init) => {\n\t\t\t\t\t\tconst response = await account.authorizedFetch(expected, String(url), init ?? {});\n\t\t\t\t\t\treason = parseHcodeCatalogEmptyReason(response.headers.get(HCODE_CATALOG_EMPTY_REASON_HEADER));\n\t\t\t\t\t\texcluded = parseHcodeCatalogExclusions(response.headers.get(HCODE_CATALOG_EXCLUSIONS_HEADER));\n\t\t\t\t\t\treturn response;\n\t\t\t\t\t},\n\t\t\t\t\t`${environment.inferenceBaseUrl}/models`,\n\t\t\t\t\t{ signal: context.signal },\n\t\t\t\t),\n\t\t\t\tenvironment,\n\t\t\t).data;\n\t\t\tconst next = deriveHcodeCatalog(entries, environment);\n\t\t\tif (disposed || context.signal.aborted || !sameReference(account.status(expected.environmentId), expected))\n\t\t\t\treturn;\n\t\t\tawait context.publish({\n\t\t\t\tpersist: null,\n\t\t\t\tupdate: () => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tdisposed ||\n\t\t\t\t\t\tcontext.signal.aborted ||\n\t\t\t\t\t\t!sameReference(account.status(expected.environmentId), expected)\n\t\t\t\t\t)\n\t\t\t\t\t\treturn;\n\t\t\t\t\t// Unchanged approval must not invalidate a picker row or an in-flight selection.\n\t\t\t\t\tif (!sameReference(scope, expected) || !isDeepStrictEqual(models, next)) models = next;\n\t\t\t\t\tscope = expected;\n\t\t\t\t\temptyReason = next.length ? undefined : reason;\n\t\t\t\t\texclusions = excluded;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { HcodeEnvironment } from "./environment.ts";
|
|
2
2
|
import type { HcodeFacade } from "./facade.ts";
|
|
3
3
|
import type { HcodeAccountRef } from "./ports.ts";
|
|
4
4
|
export type HcodeRunBootstrap = {
|
|
@@ -16,6 +16,8 @@ export type HcodeRunFacade = Omit<HcodeFacade, "metadata"> & {
|
|
|
16
16
|
readonly reference: HcodeAccountRef;
|
|
17
17
|
/** True once Forge answered 401: the Build token is expired or revoked. */
|
|
18
18
|
tokenRejected(): boolean;
|
|
19
|
+
/** Sanitized local refresh failure for startup/JSON stderr; never includes wire input. */
|
|
20
|
+
refreshFailure?(): string | undefined;
|
|
19
21
|
};
|
|
20
22
|
/** Capture once, before parsing args or starting code that can load resources or fork. */
|
|
21
23
|
export declare function takeHcodeRunBootstrap(env: NodeJS.ProcessEnv): HcodeRunBootstrap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-credential.d.ts","sourceRoot":"","sources":["../../../src/humain/hcode/run-credential.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-credential.d.ts","sourceRoot":"","sources":["../../../src/humain/hcode/run-credential.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,YAAY,CAAC;AASpE,MAAM,MAAM,iBAAiB,GAC1B;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,sBAAsB,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,WAAW,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,cAAc,CAAA;CAAE,CAAC;AAE9E,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,GAAG;IAC5D,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IACpC,2EAA2E;IAC3E,aAAa,IAAI,OAAO,CAAC;IACzB,0FAA0F;IAC1F,cAAc,CAAC,IAAI,MAAM,GAAG,SAAS,CAAC;CACtC,CAAC;AAEF,0FAA0F;AAC1F,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,iBAAiB,CAkD/E"}
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
// Forge owns the launch credential; only the native inference provider gets its send authority.
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { BuildInferenceError, resolveBuildInferenceEnvironment } from "@humain/humain-code-contracts/build-inference";
|
|
3
4
|
import { sameReference } from "./account-store.js";
|
|
4
|
-
import {
|
|
5
|
+
import { assertBuildRefreshEnvironment, BuildTokenError, createBuildTokenSource, parseBuildRefreshConfiguration, } from "./build-token.js";
|
|
6
|
+
import { readHcodeJson } from "./http.js";
|
|
5
7
|
import { createHcodeProvider } from "./provider.js";
|
|
6
8
|
import { HcodeLocalRefusal } from "./transport.js";
|
|
7
9
|
const ORIGIN_ENV = "HUMAIN_CODE_FORGE_ORIGIN";
|
|
8
10
|
const TOKEN_ENV = "HUMAIN_CODE_RUN_TOKEN";
|
|
11
|
+
const REFRESH_ENV = "HUMAIN_CODE_BUILD_REFRESH";
|
|
9
12
|
const UNAVAILABLE = "Forge run inference is unavailable.";
|
|
10
13
|
/** Capture once, before parsing args or starting code that can load resources or fork. */
|
|
11
14
|
export function takeHcodeRunBootstrap(env) {
|
|
12
15
|
const origin = env[ORIGIN_ENV];
|
|
13
16
|
const token = env[TOKEN_ENV];
|
|
17
|
+
const refreshInput = env[REFRESH_ENV];
|
|
14
18
|
let present = false;
|
|
15
19
|
let ambiguous = false;
|
|
16
20
|
for (const key of Object.keys(env)) {
|
|
17
21
|
const name = key.toUpperCase();
|
|
18
|
-
if (name !== TOKEN_ENV && name !== ORIGIN_ENV)
|
|
22
|
+
if (name !== TOKEN_ENV && name !== ORIGIN_ENV && name !== REFRESH_ENV)
|
|
19
23
|
continue;
|
|
20
24
|
present = true;
|
|
21
25
|
ambiguous ||= key !== name;
|
|
@@ -23,21 +27,36 @@ export function takeHcodeRunBootstrap(env) {
|
|
|
23
27
|
}
|
|
24
28
|
if (!present)
|
|
25
29
|
return { kind: "desktop" };
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
// Node loaded the launch CA at startup. Remove its env input before any tool, MCP or app child
|
|
31
|
+
// inherits process.env; this does not remove the CLI process's already-loaded trust anchors.
|
|
32
|
+
for (const key of Object.keys(env)) {
|
|
33
|
+
if (key.toUpperCase() === "NODE_EXTRA_CA_CERTS")
|
|
34
|
+
delete env[key];
|
|
35
|
+
}
|
|
36
|
+
let environment;
|
|
37
|
+
try {
|
|
38
|
+
// Native refresh reuses this exact captured resolver; ambient overrides never choose its origin.
|
|
39
|
+
environment = resolveBuildInferenceEnvironment(origin ?? "", token);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (!(error instanceof BuildInferenceError))
|
|
43
|
+
throw error;
|
|
44
|
+
return error.code === "forge_origin_invalid" ? { kind: "invalid", reason: error.code } : { kind: "invalid" };
|
|
45
|
+
}
|
|
46
|
+
if (ambiguous || token === undefined)
|
|
40
47
|
return { kind: "invalid" };
|
|
48
|
+
let refresh;
|
|
49
|
+
try {
|
|
50
|
+
if (refreshInput !== undefined) {
|
|
51
|
+
refresh = parseBuildRefreshConfiguration(refreshInput);
|
|
52
|
+
assertBuildRefreshEnvironment(environment.origin, token);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// Optional refresh bindings never reject an otherwise valid fixed-lifetime launch.
|
|
57
|
+
refresh = undefined;
|
|
58
|
+
process.stderr.write("Warning: HUMAIN_CODE_BUILD_REFRESH: refresh_invalid_configuration\n");
|
|
59
|
+
}
|
|
41
60
|
let bearer = token;
|
|
42
61
|
return {
|
|
43
62
|
kind: "run",
|
|
@@ -47,11 +66,55 @@ export function takeHcodeRunBootstrap(env) {
|
|
|
47
66
|
throw new Error(UNAVAILABLE);
|
|
48
67
|
const credential = bearer;
|
|
49
68
|
bearer = undefined;
|
|
50
|
-
return createRunFacade(environment, credential);
|
|
69
|
+
return createRunFacade(environment, credential, refresh);
|
|
51
70
|
},
|
|
52
71
|
};
|
|
53
72
|
}
|
|
54
|
-
function createRunFacade(environment, token) {
|
|
73
|
+
function createRunFacade(environment, token, refresh) {
|
|
74
|
+
const tokens = refresh ? createBuildTokenSource(environment.origin, token, refresh) : undefined;
|
|
75
|
+
if (tokens)
|
|
76
|
+
token = ""; // The durable bootstrap capture is now the only remaining launch-bearer owner.
|
|
77
|
+
let refreshing;
|
|
78
|
+
let refreshFailure;
|
|
79
|
+
let cleanup;
|
|
80
|
+
const close = () => {
|
|
81
|
+
cleanup ??= (refreshing ?? Promise.resolve()).catch(() => { }).then(() => tokens?.close());
|
|
82
|
+
return cleanup;
|
|
83
|
+
};
|
|
84
|
+
const accessToken = (rejected) => {
|
|
85
|
+
if (!tokens)
|
|
86
|
+
return Promise.resolve(token);
|
|
87
|
+
if (refreshing) {
|
|
88
|
+
// A joined cached read may still return the rejected bearer; it is not a forced rotation.
|
|
89
|
+
return refreshing.then((current) => (current === rejected ? accessToken(rejected) : current));
|
|
90
|
+
}
|
|
91
|
+
refreshing = tokens
|
|
92
|
+
.get(rejected, signal)
|
|
93
|
+
.then((result) => {
|
|
94
|
+
refreshFailure = undefined;
|
|
95
|
+
return result.access_token;
|
|
96
|
+
})
|
|
97
|
+
.catch((error) => {
|
|
98
|
+
const reason = error instanceof BuildTokenError
|
|
99
|
+
? error.code === "refresh_out_of_credits"
|
|
100
|
+
? "buildOutOfCredits"
|
|
101
|
+
: error.code === "refresh_handle_reused"
|
|
102
|
+
? "buildRefreshReused"
|
|
103
|
+
: error.exitCode === 77
|
|
104
|
+
? "buildRefreshInactive"
|
|
105
|
+
: error.exitCode === 75
|
|
106
|
+
? "buildRefreshUnavailable"
|
|
107
|
+
: "buildRefreshInvalid"
|
|
108
|
+
: "buildRefreshInvalid";
|
|
109
|
+
const refusal = new HcodeLocalRefusal(reason);
|
|
110
|
+
refreshFailure = refusal.message;
|
|
111
|
+
throw refusal;
|
|
112
|
+
})
|
|
113
|
+
.finally(() => {
|
|
114
|
+
refreshing = undefined;
|
|
115
|
+
});
|
|
116
|
+
return refreshing;
|
|
117
|
+
};
|
|
55
118
|
// Forge checks the sliding idle deadline at admission, not while a response is streaming.
|
|
56
119
|
const lifetime = new AbortController();
|
|
57
120
|
const signal = lifetime.signal;
|
|
@@ -87,7 +150,8 @@ function createRunFacade(environment, token) {
|
|
|
87
150
|
const requestSignal = init.signal ? AbortSignal.any([signal, init.signal]) : signal;
|
|
88
151
|
requestSignal.throwIfAborted();
|
|
89
152
|
const headers = new Headers(init.headers);
|
|
90
|
-
|
|
153
|
+
const currentToken = await accessToken();
|
|
154
|
+
headers.set("authorization", `Bearer ${currentToken}`);
|
|
91
155
|
let response;
|
|
92
156
|
try {
|
|
93
157
|
response = await globalThis.fetch(url, {
|
|
@@ -107,6 +171,42 @@ function createRunFacade(environment, token) {
|
|
|
107
171
|
void response.body?.cancel().catch(() => { });
|
|
108
172
|
return refuse();
|
|
109
173
|
}
|
|
174
|
+
if (response.status === 401 && tokens && (method === "GET" || typeof init.body === "string")) {
|
|
175
|
+
// A 401 is a pre-admission refusal, never a partially emitted inference stream.
|
|
176
|
+
let expired = false;
|
|
177
|
+
try {
|
|
178
|
+
const error = await readHcodeJson(new Response(response.body, { headers: response.headers }), 4096, AbortSignal.any([requestSignal, AbortSignal.timeout(3000)]));
|
|
179
|
+
expired =
|
|
180
|
+
error !== null &&
|
|
181
|
+
typeof error === "object" &&
|
|
182
|
+
"code" in error &&
|
|
183
|
+
error.code === "build_token_expired";
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
/* Malformed refusals never authorize replay. */
|
|
187
|
+
}
|
|
188
|
+
if (expired) {
|
|
189
|
+
headers.set("authorization", `Bearer ${await accessToken(currentToken)}`);
|
|
190
|
+
try {
|
|
191
|
+
response = await globalThis.fetch(url, {
|
|
192
|
+
method,
|
|
193
|
+
body: init.body,
|
|
194
|
+
headers,
|
|
195
|
+
signal: requestSignal,
|
|
196
|
+
redirect: "error",
|
|
197
|
+
credentials: "omit",
|
|
198
|
+
cache: "no-store",
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return refuse();
|
|
203
|
+
}
|
|
204
|
+
if (response.redirected || (response.status >= 300 && response.status < 400)) {
|
|
205
|
+
void response.body?.cancel().catch(() => { });
|
|
206
|
+
return refuse();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
110
210
|
if (response.status === 401) {
|
|
111
211
|
tokenRejected = true;
|
|
112
212
|
void response.body?.cancel().catch(() => { });
|
|
@@ -119,6 +219,7 @@ function createRunFacade(environment, token) {
|
|
|
119
219
|
return {
|
|
120
220
|
reference,
|
|
121
221
|
tokenRejected: () => tokenRejected,
|
|
222
|
+
refreshFailure: () => refreshFailure,
|
|
122
223
|
provider,
|
|
123
224
|
signal,
|
|
124
225
|
context: { account, usage: { read: refuse }, environment, environmentId: environment.id },
|
|
@@ -137,11 +238,14 @@ function createRunFacade(environment, token) {
|
|
|
137
238
|
login: refuse,
|
|
138
239
|
logoutStored: refuse,
|
|
139
240
|
async shutdown() {
|
|
241
|
+
lifetime.abort();
|
|
242
|
+
await close();
|
|
140
243
|
return { remoteRevocation: "not-needed" };
|
|
141
244
|
},
|
|
142
245
|
dispose() {
|
|
143
246
|
lifetime.abort();
|
|
144
247
|
provider.dispose();
|
|
248
|
+
void close();
|
|
145
249
|
},
|
|
146
250
|
};
|
|
147
251
|
}
|