@humain/humain-code 0.7.0 → 0.8.0
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 +139 -0
- package/README.md +2 -2
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/anthropic-messages-UZB5HJE3.js +77 -0
- package/dist/bundle/chunks/anthropic.js +25 -24
- package/dist/bundle/chunks/azure-openai-responses-J3LCMWPQ.js +15 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +460 -431
- package/dist/bundle/chunks/bowser-DXKSTXFQ.js +89 -0
- package/dist/bundle/chunks/{chunk-HTA325LJ.js → chunk-2NVGOSBN.js} +1 -1
- package/dist/bundle/chunks/{chunk-5B25YXF7.js → chunk-3CGMVKHA.js} +13 -3
- package/dist/bundle/chunks/{chunk-SCINMV4X.js → chunk-46C6D7UC.js} +22 -21
- package/dist/bundle/chunks/{chunk-RS6PZK35.js → chunk-4EV7CK26.js} +249 -216
- package/dist/bundle/chunks/{chunk-T7BXP46S.js → chunk-4SFWYKL5.js} +1848 -1662
- package/dist/bundle/chunks/{chunk-TGDPZCSW.js → chunk-4TDNOR36.js} +1 -1
- package/dist/bundle/chunks/{chunk-C6VERWRZ.js → chunk-4XF5JX7X.js} +1 -1
- package/dist/bundle/chunks/chunk-6HTHDVJC.js +4 -0
- package/dist/bundle/chunks/{chunk-2G7YVAVF.js → chunk-7EONJCBE.js} +1 -1
- package/dist/bundle/chunks/chunk-7H2WNBX7.js +11 -0
- package/dist/bundle/chunks/{chunk-2FYYW6FY.js → chunk-7OZNMWAJ.js} +1 -1
- package/dist/bundle/chunks/{chunk-R6YQR7TZ.js → chunk-7WE77IE3.js} +1 -1
- package/dist/bundle/chunks/{chunk-Z5YLKK3S.js → chunk-7WETECIB.js} +1 -1
- package/dist/bundle/chunks/{chunk-EIC7CQX3.js → chunk-AI7EHDAX.js} +1 -1
- package/dist/bundle/chunks/{chunk-KRCX3ZBA.js → chunk-APNPBT7Y.js} +1 -1
- package/dist/bundle/chunks/{chunk-4HTVBBJD.js → chunk-ATFZAFMS.js} +2 -2
- package/dist/bundle/chunks/{chunk-R5OOX7RW.js → chunk-B47PNNLL.js} +9 -2
- package/dist/bundle/chunks/{chunk-AZXVJN6E.js → chunk-C4DHVDYT.js} +1 -1
- package/dist/bundle/chunks/{chunk-4PRNKB6V.js → chunk-CET2MXXN.js} +7 -7
- package/dist/bundle/chunks/{chunk-66FZJO75.js → chunk-CU6KU7JK.js} +472 -3924
- package/dist/bundle/chunks/{chunk-MD7K7RPN.js → chunk-D3KYOSQY.js} +1 -1
- package/dist/bundle/chunks/{chunk-I3NDOUHE.js → chunk-DCXHRP6C.js} +1 -1
- package/dist/bundle/chunks/{chunk-OB332KMV.js → chunk-DD5UT56Y.js} +46 -32
- package/dist/bundle/chunks/{chunk-G4QPSFBF.js → chunk-EMBIUIQ2.js} +216 -223
- package/dist/bundle/chunks/{chunk-Q7VXYXY3.js → chunk-ENBDASDN.js} +2 -2
- package/dist/bundle/chunks/{chunk-2H3LUS62.js → chunk-FJIISX5W.js} +241 -229
- package/dist/bundle/chunks/{chunk-WQOOJP7U.js → chunk-GV5OVRKK.js} +1 -1
- package/dist/bundle/chunks/{chunk-KTSJYIYC.js → chunk-HHWVVNGG.js} +1 -1
- package/dist/bundle/chunks/{chunk-4JRER4XK.js → chunk-HQMUDHC3.js} +19 -19
- package/dist/bundle/chunks/{chunk-WQ7EJQIT.js → chunk-IOLLZXQN.js} +225 -239
- package/dist/bundle/chunks/chunk-IXQYPQRQ.js +2079 -0
- package/dist/bundle/chunks/{chunk-RU7ADKA7.js → chunk-J4GII2EE.js} +112 -96
- package/dist/bundle/chunks/chunk-J5TSAJGC.js +22 -0
- package/dist/bundle/chunks/{chunk-QT6ZHDMP.js → chunk-JBSWWCT5.js} +1 -1
- package/dist/bundle/chunks/{chunk-P6AXBESH.js → chunk-JV7VHOAY.js} +1119 -1098
- package/dist/bundle/chunks/{chunk-PWUDFU5V.js → chunk-JWOPWHVH.js} +4 -4
- package/dist/bundle/chunks/{chunk-4V5VL2BO.js → chunk-KLSRGGOH.js} +131 -154
- package/dist/bundle/chunks/{chunk-JF7FYXAI.js → chunk-KONLZKPL.js} +7 -6
- package/dist/bundle/chunks/{chunk-32QLLD2P.js → chunk-KQXXBQ57.js} +360 -332
- package/dist/bundle/chunks/{chunk-UZNIPOGS.js → chunk-L4J7SMJB.js} +1 -1
- package/dist/bundle/chunks/chunk-MPRAQ6ZI.js +41 -0
- package/dist/bundle/chunks/{chunk-GUHNFZ2Q.js → chunk-NNWNIBLG.js} +20 -19
- package/dist/bundle/chunks/{chunk-TWAHPPXN.js → chunk-OVDMYBIT.js} +1307 -1194
- package/dist/bundle/chunks/{chunk-WAPZN4KP.js → chunk-P2Y2H7SD.js} +2 -2
- package/dist/bundle/chunks/{chunk-PPBDDQHP.js → chunk-PGVDL4KB.js} +7 -6
- package/dist/bundle/chunks/{chunk-XHDVDJM7.js → chunk-PVNXN2TC.js} +7 -7
- package/dist/bundle/chunks/{chunk-RNBZBCH2.js → chunk-QJB5YI3I.js} +1 -1
- package/dist/bundle/chunks/{chunk-I5E7RQ5V.js → chunk-QRYDGY5I.js} +5 -5
- package/dist/bundle/chunks/{chunk-4QAXV5T6.js → chunk-R3VDXQW2.js} +9 -9
- package/dist/bundle/chunks/chunk-SKCJ25SX.js +24 -0
- package/dist/bundle/chunks/chunk-SQ7NTRLJ.js +77 -0
- package/dist/bundle/chunks/{chunk-SSRCVJZK.js → chunk-TYN46EVI.js} +5 -5
- package/dist/bundle/chunks/{chunk-6E6RHNOU.js → chunk-UXM4WFLH.js} +12 -11
- package/dist/bundle/chunks/{chunk-LB4CIS4F.js → chunk-VCMXBP5S.js} +17 -17
- package/dist/bundle/chunks/{chunk-N2SNMUD3.js → chunk-VKQNYZUA.js} +1 -1
- package/dist/bundle/chunks/{chunk-JYWUOKOI.js → chunk-WBSGWISD.js} +367 -353
- package/dist/bundle/chunks/{chunk-3EDMWQ35.js → chunk-WGXMYMPE.js} +17 -15
- package/dist/bundle/chunks/chunk-WRYGY5XG.js +24 -0
- package/dist/bundle/chunks/{chunk-GRJUKEE3.js → chunk-XVIQYONJ.js} +4 -4
- package/dist/bundle/chunks/chunk-YSWDFV2L.js +11 -0
- package/dist/bundle/chunks/{chunk-AEWYICBL.js → chunk-Z5UFSRO4.js} +2 -2
- package/dist/bundle/chunks/chunk-ZG74NES2.js +2 -0
- package/dist/bundle/chunks/chunk-ZTG5OKI7.js +3 -0
- package/dist/bundle/chunks/{cli-H4LJNE2V.js → cli-6DJO467D.js} +2 -2
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-T5R2RVFQ.js → cloudflare-workers-ai-system-one-ETKC6B2S.js} +1 -1
- package/dist/bundle/chunks/codemode-worker.js +68 -68
- package/dist/bundle/chunks/compat-HS4ARZK3.js +15 -0
- package/dist/bundle/chunks/curator-server-TC7RVVN2.js +3600 -0
- package/dist/bundle/chunks/dist-35STTNYA.js +37 -0
- package/dist/bundle/chunks/{dist-FMWWM4H7.js → dist-5AQPJ2TI.js} +2 -2
- package/dist/bundle/chunks/{dist-NHQTBDHT.js → dist-DYB3AR7C.js} +91 -257
- package/dist/bundle/chunks/dist-NMEXYUP3.js +11 -0
- package/dist/bundle/chunks/dist-cjs-EROMDUKS.js +193 -0
- package/dist/bundle/chunks/{easter-egg-3d-BUEOC3NO.js → easter-egg-3d-VVUF3C3X.js} +1 -1
- package/dist/bundle/chunks/entry-2GZ3PTWQ.js +2 -0
- package/dist/bundle/chunks/{entry-A2CSLKHC.js → entry-SRYLSS5P.js} +3 -3
- package/dist/bundle/chunks/{event-streams-7YGFEPBZ.js → event-streams-F67JLS6B.js} +1 -1
- package/dist/bundle/chunks/{execute-MY5JSEPV.js → execute-I3WGGPWL.js} +2 -2
- package/dist/bundle/chunks/{extract-PTGACPGP.js → extract-QHZTEVJP.js} +68 -65
- package/dist/bundle/chunks/{flow-implementer-APJFY4YI.js → flow-implementer-QMN3HKE2.js} +8 -9
- package/dist/bundle/chunks/github-copilot.js +55 -45
- package/dist/bundle/chunks/google-generative-ai-ZND73WDQ.js +22 -0
- package/dist/bundle/chunks/google-vertex-YAH62YRM.js +25 -0
- package/dist/bundle/chunks/host-Q565BCXB.js +3 -0
- package/dist/bundle/chunks/image-resize-worker.js +3 -3
- package/dist/bundle/chunks/{index.bundle-THL4EUSU.js → index.bundle-HONF3PUD.js} +177 -176
- package/dist/bundle/chunks/{inprocess-5NP5VJHZ.js → inprocess-453SLFL5.js} +6 -6
- package/dist/bundle/chunks/interactive-mode-MVZOJ5OU.js +5 -0
- package/dist/bundle/chunks/{llama-cpp-classify-GJAXULWL.js → llama-cpp-classify-Z4GZY4GC.js} +1 -1
- package/dist/bundle/chunks/mistral-conversations-7I5JURDP.js +43 -0
- package/dist/bundle/chunks/{node-ZFIIS5IM.js → node-IMSYVRPL.js} +53 -30
- package/dist/bundle/chunks/{node-UNHECG4X.js → node-MHHE76P4.js} +475 -440
- package/dist/bundle/chunks/{openai-codex-responses-S7CMCAOY.js → openai-codex-responses-LTHOMN37.js} +30 -29
- package/dist/bundle/chunks/openai-codex.js +9 -8
- package/dist/bundle/chunks/{openai-completions-2Z57N7PC.js → openai-completions-W2X635EE.js} +22 -22
- package/dist/bundle/chunks/{openai-decisions-JIOJDB4C.js → openai-decisions-TN2GNOYI.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-5VBZSTHL.js → openai-responses-DVY4QXOG.js} +4 -5
- package/dist/bundle/chunks/{openrouter-images-S6O7DBEJ.js → openrouter-images-SE2JMS44.js} +1 -1
- package/dist/bundle/chunks/openrouter.js +9 -8
- package/dist/bundle/chunks/pdfjs-FE3L72A6.js +3662 -0
- package/dist/bundle/chunks/{pdfjs-decoders-OFXX4HDZ.js → pdfjs-decoders-VCMCTQJ2.js} +1 -1
- package/dist/bundle/chunks/pdfjs-jbig2_nowasm_fallback-I4K6AIV4.js +295 -0
- package/dist/bundle/chunks/pdfjs-openjpeg-PYQCV6CM.js +590 -0
- package/dist/bundle/chunks/pdfjs-openjpeg_nowasm_fallback-G363SGDI.js +775 -0
- package/dist/bundle/chunks/{pi-messages-SMLN5J2W.js → pi-messages-WAS6Z5L5.js} +11 -11
- package/dist/bundle/chunks/radius.js +8 -7
- package/dist/bundle/chunks/{runtime-OYTWXIUM.js → runtime-H7LYNKCZ.js} +1 -1
- package/dist/bundle/chunks/session-picker-XNVLSJ22.js +4 -0
- package/dist/bundle/chunks/startup-ui-3TCT465D.js +3 -0
- package/dist/bundle/chunks/{trace-command-YLDYCL55.js → trace-command-7ORDQ3JS.js} +4 -4
- package/dist/bundle/chunks/{typesafe-system-one-7BEL3H5N.js → typesafe-system-one-AAZH6S3I.js} +1 -1
- package/dist/bundle/chunks/{undici-C6S56CGI.js → undici-WVNE45GY.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-CIVXCEAN.js +28 -0
- package/dist/bundle/cli-runtime.js +5 -5
- package/dist/bundle/flow/package.json +5 -5
- package/dist/bundle/index.js +13 -13
- package/dist/bundle/orchestrate/package.json +22 -6
- package/dist/bundle/rpc-entry.js +4 -5
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +4 -3
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +9 -6
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js +9 -6
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +8 -4
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +11 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +19 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +0 -2
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +0 -2
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +31 -39
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +231 -535
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/anthropic-subscription-usage.d.ts +4 -2
- package/dist/core/anthropic-subscription-usage.d.ts.map +1 -1
- package/dist/core/anthropic-subscription-usage.js +32 -16
- package/dist/core/anthropic-subscription-usage.js.map +1 -1
- package/dist/core/auto-session-namer.js +1 -1
- package/dist/core/auto-session-namer.js.map +1 -1
- package/dist/core/cache-warmer.d.ts.map +1 -1
- package/dist/core/cache-warmer.js +2 -0
- package/dist/core/cache-warmer.js.map +1 -1
- package/dist/core/exec.d.ts +1 -0
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +4 -1
- package/dist/core/exec.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts +6 -1
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js +57 -20
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/template.js +1 -1
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +2 -3
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +18 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +5 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +5 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/flow-implementer.d.ts.map +1 -1
- package/dist/core/flow-implementer.js +3 -9
- package/dist/core/flow-implementer.js.map +1 -1
- package/dist/core/keybindings.d.ts +40 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +5 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +13 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-registry.d.ts +3 -0
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +32 -8
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +0 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +3 -10
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +18 -7
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +41 -8
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/oauth-account-pool.d.ts +5 -0
- package/dist/core/oauth-account-pool.d.ts.map +1 -1
- package/dist/core/oauth-account-pool.js +34 -3
- package/dist/core/oauth-account-pool.js.map +1 -1
- package/dist/core/package-manager.d.ts +16 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +46 -3
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-ai-schemas.d.ts +1 -0
- package/dist/core/pi-ai-schemas.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +7 -0
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts +5 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +2 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/run-outcome.d.ts +6 -3
- package/dist/core/run-outcome.d.ts.map +1 -1
- package/dist/core/run-outcome.js +36 -9
- package/dist/core/run-outcome.js.map +1 -1
- package/dist/core/run-preflight.d.ts +1 -1
- package/dist/core/run-preflight.d.ts.map +1 -1
- package/dist/core/run-preflight.js +19 -11
- package/dist/core/run-preflight.js.map +1 -1
- package/dist/core/sdk.d.ts +0 -6
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +7 -16
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +0 -5
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +0 -9
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +0 -4
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +0 -1
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/tools/bash-jobs.d.ts.map +1 -1
- package/dist/core/tools/bash-jobs.js +2 -9
- package/dist/core/tools/bash-jobs.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +28 -16
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +4 -1
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/read.d.ts +8 -4
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +10 -15
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/renderers/read.d.ts.map +1 -1
- package/dist/core/tools/renderers/read.js +6 -2
- package/dist/core/tools/renderers/read.js.map +1 -1
- package/dist/core/tools/subagent-worktree.d.ts.map +1 -1
- package/dist/core/tools/subagent-worktree.js +2 -10
- package/dist/core/tools/subagent-worktree.js.map +1 -1
- package/dist/core/trace-client/credential-store.d.ts.map +1 -1
- package/dist/core/trace-client/credential-store.js +9 -5
- package/dist/core/trace-client/credential-store.js.map +1 -1
- package/dist/extensions/codemode/execute.js +2 -2
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +6 -4
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/extensions/usage/account-reconnect.d.ts +5 -0
- package/dist/extensions/usage/account-reconnect.d.ts.map +1 -0
- package/dist/extensions/usage/account-reconnect.js +12 -0
- package/dist/extensions/usage/account-reconnect.js.map +1 -0
- package/dist/extensions/usage/hcode-overview.d.ts +6 -19
- package/dist/extensions/usage/hcode-overview.d.ts.map +1 -1
- package/dist/extensions/usage/hcode-overview.js +86 -100
- package/dist/extensions/usage/hcode-overview.js.map +1 -1
- package/dist/extensions/usage/index.d.ts.map +1 -1
- package/dist/extensions/usage/index.js +74 -98
- package/dist/extensions/usage/index.js.map +1 -1
- package/dist/extensions/usage/overview.d.ts +22 -17
- package/dist/extensions/usage/overview.d.ts.map +1 -1
- package/dist/extensions/usage/overview.js +98 -13
- package/dist/extensions/usage/overview.js.map +1 -1
- package/dist/extensions/usage/popup.d.ts +9 -14
- package/dist/extensions/usage/popup.d.ts.map +1 -1
- package/dist/extensions/usage/popup.js +78 -165
- package/dist/extensions/usage/popup.js.map +1 -1
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +4 -1
- package/dist/humain/flow-command.js +1 -1
- package/dist/humain/flow-command.js.map +1 -1
- package/dist/humain/flow-loader.d.ts +9 -4
- package/dist/humain/flow-loader.d.ts.map +1 -1
- package/dist/humain/flow-loader.js +30 -21
- package/dist/humain/flow-loader.js.map +1 -1
- package/dist/humain/gateway/client.d.ts +3 -1
- package/dist/humain/gateway/client.d.ts.map +1 -1
- package/dist/humain/gateway/client.js +10 -5
- package/dist/humain/gateway/client.js.map +1 -1
- package/dist/humain/gateway/login.d.ts.map +1 -1
- package/dist/humain/gateway/login.js +160 -53
- package/dist/humain/gateway/login.js.map +1 -1
- package/dist/humain/hcode/account-store.d.ts +29 -5
- package/dist/humain/hcode/account-store.d.ts.map +1 -1
- package/dist/humain/hcode/account-store.js +224 -124
- package/dist/humain/hcode/account-store.js.map +1 -1
- package/dist/humain/hcode/account.d.ts +6 -0
- package/dist/humain/hcode/account.d.ts.map +1 -1
- package/dist/humain/hcode/account.js +348 -129
- package/dist/humain/hcode/account.js.map +1 -1
- package/dist/humain/hcode/catalog-watch.d.ts +21 -0
- package/dist/humain/hcode/catalog-watch.d.ts.map +1 -0
- package/dist/humain/hcode/catalog-watch.js +46 -0
- package/dist/humain/hcode/catalog-watch.js.map +1 -0
- package/dist/humain/hcode/contracts.d.ts +16 -1
- package/dist/humain/hcode/contracts.d.ts.map +1 -1
- package/dist/humain/hcode/contracts.js +122 -128
- package/dist/humain/hcode/contracts.js.map +1 -1
- package/dist/humain/hcode/environment.d.ts +3 -1
- package/dist/humain/hcode/environment.d.ts.map +1 -1
- package/dist/humain/hcode/environment.js +12 -2
- package/dist/humain/hcode/environment.js.map +1 -1
- package/dist/humain/hcode/facade.d.ts +26 -6
- package/dist/humain/hcode/facade.d.ts.map +1 -1
- package/dist/humain/hcode/facade.js +148 -38
- package/dist/humain/hcode/facade.js.map +1 -1
- package/dist/humain/hcode/http.d.ts +3 -1
- package/dist/humain/hcode/http.d.ts.map +1 -1
- package/dist/humain/hcode/http.js +44 -23
- package/dist/humain/hcode/http.js.map +1 -1
- package/dist/humain/hcode/images.d.ts +67 -0
- package/dist/humain/hcode/images.d.ts.map +1 -0
- package/dist/humain/hcode/images.js +463 -0
- package/dist/humain/hcode/images.js.map +1 -0
- package/dist/humain/hcode/login-copy.d.ts +28 -0
- package/dist/humain/hcode/login-copy.d.ts.map +1 -0
- package/dist/humain/hcode/login-copy.js +74 -0
- package/dist/humain/hcode/login-copy.js.map +1 -0
- package/dist/humain/hcode/login-failure.d.ts +26 -0
- package/dist/humain/hcode/login-failure.d.ts.map +1 -0
- package/dist/humain/hcode/login-failure.js +50 -0
- package/dist/humain/hcode/login-failure.js.map +1 -0
- package/dist/humain/hcode/notices.d.ts +24 -1
- package/dist/humain/hcode/notices.d.ts.map +1 -1
- package/dist/humain/hcode/notices.js +93 -7
- package/dist/humain/hcode/notices.js.map +1 -1
- package/dist/humain/hcode/provider.d.ts +7 -3
- package/dist/humain/hcode/provider.d.ts.map +1 -1
- package/dist/humain/hcode/provider.js +123 -19
- package/dist/humain/hcode/provider.js.map +1 -1
- package/dist/humain/hcode/selection.d.ts +2 -0
- package/dist/humain/hcode/selection.d.ts.map +1 -1
- package/dist/humain/hcode/selection.js +8 -1
- package/dist/humain/hcode/selection.js.map +1 -1
- package/dist/humain/hcode/transport.d.ts +13 -10
- package/dist/humain/hcode/transport.d.ts.map +1 -1
- package/dist/humain/hcode/transport.js +103 -148
- package/dist/humain/hcode/transport.js.map +1 -1
- package/dist/humain/hcode/wire.d.ts +3 -0
- package/dist/humain/hcode/wire.d.ts.map +1 -1
- package/dist/humain/hcode/wire.js +11 -0
- package/dist/humain/hcode/wire.js.map +1 -1
- package/dist/humain/metadata/contracts.d.ts +1 -0
- package/dist/humain/metadata/contracts.d.ts.map +1 -1
- package/dist/humain/metadata/contracts.js +2 -1
- package/dist/humain/metadata/contracts.js.map +1 -1
- package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/anysearch.js +7 -3
- package/dist/humain/web-access/vendor/anysearch.js.map +1 -1
- package/dist/humain/web-access/vendor/autom.d.ts +4 -0
- package/dist/humain/web-access/vendor/autom.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/autom.js +191 -0
- package/dist/humain/web-access/vendor/autom.js.map +1 -0
- package/dist/humain/web-access/vendor/cloro.d.ts +4 -0
- package/dist/humain/web-access/vendor/cloro.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/cloro.js +236 -0
- package/dist/humain/web-access/vendor/cloro.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.js +7 -1
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.js +6 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
- package/dist/humain/web-access/vendor/domain-filter-normalization.d.ts +8 -0
- package/dist/humain/web-access/vendor/domain-filter-normalization.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/domain-filter-normalization.js +37 -0
- package/dist/humain/web-access/vendor/domain-filter-normalization.js.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo-rate-limit.d.ts +28 -8
- package/dist/humain/web-access/vendor/duckduckgo-rate-limit.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo-rate-limit.js +135 -34
- package/dist/humain/web-access/vendor/duckduckgo-rate-limit.js.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.d.ts +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.js +10 -3
- package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +61 -5
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.d.ts +3 -3
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +35 -5
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +8 -1
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/page-query.d.ts +5 -0
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/page-query.js +12 -2
- package/dist/humain/web-access/vendor/page-query.js.map +1 -1
- package/dist/humain/web-access/vendor/specstream.d.ts +6 -0
- package/dist/humain/web-access/vendor/specstream.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/specstream.js +253 -0
- package/dist/humain/web-access/vendor/specstream.js.map +1 -0
- package/dist/humain/web-access/vendor/tool-activation.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/tool-activation.js +21 -5
- package/dist/humain/web-access/vendor/tool-activation.js.map +1 -1
- package/dist/humain/web-access/vendor/upgrade-notice.d.ts +1 -1
- package/dist/humain/web-access/vendor/upgrade-notice.js +1 -1
- package/dist/humain/web-access/vendor/upgrade-notice.js.map +1 -1
- package/dist/humain/web-access/vendor/utils.d.ts +1 -0
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +3 -0
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/humain/web-access/vendor/video-extract.js +2 -2
- package/dist/humain/web-access/vendor/video-extract.js.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.d.ts +13 -0
- package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.js +16 -5
- package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
- package/dist/humain/web-access/vendor/youtube-extract.js +2 -2
- package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +96 -28
- package/dist/main.js.map +1 -1
- package/dist/modes/diagnostics-stderr.d.ts +4 -0
- package/dist/modes/diagnostics-stderr.d.ts.map +1 -0
- package/dist/modes/diagnostics-stderr.js +11 -0
- package/dist/modes/diagnostics-stderr.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +5 -2
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +14 -5
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts +2 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +6 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +10 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +101 -23
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +5 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +17 -6
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/radius-login-selector.js +2 -1
- package/dist/modes/interactive/components/radius-login-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +13 -6
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +8 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +41 -9
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.js +5 -1
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +0 -17
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +1 -78
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/themed-text.d.ts +1 -1
- package/dist/modes/interactive/components/themed-text.d.ts.map +1 -1
- package/dist/modes/interactive/components/themed-text.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +5 -1
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +3 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/trust-selector.js +14 -5
- package/dist/modes/interactive/components/trust-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts +2 -2
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +20 -2
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +605 -223
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/model-catalog-refresh.d.ts +4 -0
- package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -1
- package/dist/modes/interactive/model-catalog-refresh.js +40 -1
- package/dist/modes/interactive/model-catalog-refresh.js.map +1 -1
- package/dist/modes/interactive/oauth-account-format.d.ts +6 -2
- package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
- package/dist/modes/interactive/oauth-account-format.js +12 -3
- package/dist/modes/interactive/oauth-account-format.js.map +1 -1
- package/dist/modes/interactive/session-share.js +2 -0
- package/dist/modes/interactive/session-share.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +1 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +30 -32
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +26 -39
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +1 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +14 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/abort.d.ts +5 -0
- package/dist/utils/abort.d.ts.map +1 -1
- package/dist/utils/abort.js +9 -0
- package/dist/utils/abort.js.map +1 -1
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +3 -2
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/flush-stdout.d.ts +8 -0
- package/dist/utils/flush-stdout.d.ts.map +1 -0
- package/dist/utils/flush-stdout.js +23 -0
- package/dist/utils/flush-stdout.js.map +1 -0
- package/dist/utils/image-process.d.ts +2 -0
- package/dist/utils/image-process.d.ts.map +1 -1
- package/dist/utils/image-process.js +3 -3
- package/dist/utils/image-process.js.map +1 -1
- package/dist/utils/image-resize-core.js +2 -2
- package/dist/utils/image-resize-core.js.map +1 -1
- package/dist/utils/shell.d.ts +2 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +19 -0
- package/dist/utils/shell.js.map +1 -1
- package/docs/cli.md +1 -1
- package/docs/development.md +0 -13
- package/docs/extensions.md +6 -4
- package/docs/flow.md +4 -62
- package/docs/humain-code-forge-architecture.md +1 -47
- package/docs/humain-code-forge-flow-walkthrough.md +1 -1
- package/docs/humain-code.md +1 -1
- package/docs/keybindings.md +2 -0
- package/docs/llama-cpp.md +5 -5
- package/docs/models-configuration.md +4 -2
- package/docs/nvidia-rtx-llama-cpp.md +5 -5
- package/docs/providers.md +14 -9
- package/docs/rpc-commands.md +1 -1
- package/docs/run-preflight.md +1 -1
- package/docs/slash-commands.md +1 -1
- package/docs/tui.md +2 -0
- package/examples/README.md +0 -3
- package/examples/extensions/custom-provider-anthropic/package-lock.json +4 -4
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/gondolin/index.ts +4 -7
- package/examples/tsconfig.json +96 -76
- package/npm-shrinkwrap.json +285 -764
- package/package.json +24 -37
- package/schemas/keybindings.schema.json +20 -0
- package/schemas/models.schema.json +5 -1
- package/schemas/settings.schema.json +0 -13
- package/src/humain/web-access/UPSTREAM.md +52 -1
- package/src/humain/web-access/upstream.json +5 -5
- package/src/humain/web-access/vendor/CHANGELOG.md +29 -0
- package/dist/bundle/chunks/adaptive-peer-worker-X2ZNZE3S.js +0 -8
- package/dist/bundle/chunks/adaptive-session-host-7KDSQV5I.js +0 -162
- package/dist/bundle/chunks/anthropic-messages-TQK3FUV3.js +0 -68
- package/dist/bundle/chunks/azure-openai-responses-JY7OSLH2.js +0 -15
- package/dist/bundle/chunks/chunk-5L4PBYC7.js +0 -11
- package/dist/bundle/chunks/chunk-6PNQYO6A.js +0 -10
- package/dist/bundle/chunks/chunk-CRN54O4D.js +0 -24
- package/dist/bundle/chunks/chunk-CTU2ECLD.js +0 -7
- package/dist/bundle/chunks/chunk-DBL35X7L.js +0 -3
- package/dist/bundle/chunks/chunk-GME4AWDG.js +0 -23
- package/dist/bundle/chunks/chunk-GTILMMUF.js +0 -12
- package/dist/bundle/chunks/chunk-J57HOSWD.js +0 -21
- package/dist/bundle/chunks/chunk-KQM7ZGL6.js +0 -11
- package/dist/bundle/chunks/chunk-MX4Q4W6H.js +0 -214
- package/dist/bundle/chunks/chunk-NXA6NEHE.js +0 -54
- package/dist/bundle/chunks/chunk-PJACZCIR.js +0 -2
- package/dist/bundle/chunks/chunk-T5A6T24H.js +0 -93
- package/dist/bundle/chunks/chunk-WCFHG6NO.js +0 -16
- package/dist/bundle/chunks/chunk-ZJUU6WOV.js +0 -2052
- package/dist/bundle/chunks/compat-ZK2DIW3P.js +0 -15
- package/dist/bundle/chunks/dist-EY7YKQHB.js +0 -11
- package/dist/bundle/chunks/dist-J5IUPLMH.js +0 -37
- package/dist/bundle/chunks/dist-cjs-2SKN226B.js +0 -184
- package/dist/bundle/chunks/entry-AL54ZGYO.js +0 -2
- package/dist/bundle/chunks/es5-GYTRHFKS.js +0 -77
- package/dist/bundle/chunks/google-generative-ai-UL7YEQ6J.js +0 -21
- package/dist/bundle/chunks/google-vertex-OTMSPUYH.js +0 -26
- package/dist/bundle/chunks/host-75YAHLDR.js +0 -3
- package/dist/bundle/chunks/interactive-mode-IW4PIVAQ.js +0 -5
- package/dist/bundle/chunks/mistral-conversations-E72Y6OC3.js +0 -43
- package/dist/bundle/chunks/pdfjs-AKD6EBKN.js +0 -3614
- package/dist/bundle/chunks/pdfjs-jbig2_nowasm_fallback-FH3KJM4H.js +0 -326
- package/dist/bundle/chunks/pdfjs-openjpeg-SKR7C34X.js +0 -671
- package/dist/bundle/chunks/pdfjs-openjpeg_nowasm_fallback-VUBL7UEE.js +0 -974
- package/dist/bundle/chunks/session-picker-DM6S37IF.js +0 -4
- package/dist/bundle/chunks/startup-ui-4GGLWNSU.js +0 -3
- package/dist/bundle/chunks/virtual-modules-TI3W24YL.js +0 -28
- package/dist/core/internal-process.d.ts +0 -23
- package/dist/core/internal-process.d.ts.map +0 -1
- package/dist/core/internal-process.js +0 -88
- package/dist/core/internal-process.js.map +0 -1
- package/dist/humain/adaptive-execution.d.ts +0 -51
- package/dist/humain/adaptive-execution.d.ts.map +0 -1
- package/dist/humain/adaptive-execution.js +0 -100
- package/dist/humain/adaptive-execution.js.map +0 -1
- package/dist/humain/adaptive-peer-process.d.ts +0 -44
- package/dist/humain/adaptive-peer-process.d.ts.map +0 -1
- package/dist/humain/adaptive-peer-process.js +0 -159
- package/dist/humain/adaptive-peer-process.js.map +0 -1
- package/dist/humain/adaptive-peer-worker.d.ts +0 -3
- package/dist/humain/adaptive-peer-worker.d.ts.map +0 -1
- package/dist/humain/adaptive-peer-worker.js +0 -122
- package/dist/humain/adaptive-peer-worker.js.map +0 -1
- package/dist/humain/adaptive-runtime-types.d.ts +0 -621
- package/dist/humain/adaptive-runtime-types.d.ts.map +0 -1
- package/dist/humain/adaptive-runtime-types.js +0 -3
- package/dist/humain/adaptive-runtime-types.js.map +0 -1
- package/dist/humain/adaptive-session-host.d.ts +0 -113
- package/dist/humain/adaptive-session-host.d.ts.map +0 -1
- package/dist/humain/adaptive-session-host.js +0 -1838
- package/dist/humain/adaptive-session-host.js.map +0 -1
- package/dist/utils/deprecation.d.ts +0 -4
- package/dist/utils/deprecation.d.ts.map +0 -1
- package/dist/utils/deprecation.js +0 -13
- package/dist/utils/deprecation.js.map +0 -1
- package/examples/plugins/pi-example-plugin/README.md +0 -38
- package/examples/plugins/pi-example-plugin/package.json +0 -10
- package/examples/plugins/pi-example-plugin/src/contract.ts +0 -13
- package/examples/plugins/pi-example-plugin/src/session.ts +0 -24
- package/examples/plugins/pi-example-plugin/src/tui.ts +0 -31
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
// Fits HUMAIN Code request images to the selected model's catalog limits and names each refusal cause.
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
+
import { getImageDimensions } from "@earendil-works/pi-tui";
|
|
4
|
+
import { processImage } from "../../utils/image-process.js";
|
|
5
|
+
import { loadPhoton } from "../../utils/photon.js";
|
|
6
|
+
import { HCODE_REQUEST_MAX_IMAGE_BYTES, HCODE_REQUEST_MAX_NON_IMAGE_BYTES, hcodeDecodedImageBytes, parseHcodeMessagesRequest, } from "./contracts.js";
|
|
7
|
+
// Content array identity survives custom-message conversion without adding metadata to the wire.
|
|
8
|
+
export const hcodeActivePrompts = new WeakSet();
|
|
9
|
+
const optionalImageText = new WeakSet();
|
|
10
|
+
const imageOmissionObserver = new AsyncLocalStorage();
|
|
11
|
+
/** Observe serialized image omissions for this session's requests, not other sessions sharing the provider. */
|
|
12
|
+
export function observeHcodeImageOmissions(observe, run, { autoResizeImages = true, onImageSizeRefusal, } = {}) {
|
|
13
|
+
return imageOmissionObserver.run({ observe, autoResizeImages, onImageSizeRefusal }, run);
|
|
14
|
+
}
|
|
15
|
+
/** Record fresh attachments refused before dispatch so the session can omit them from subsequent projections. */
|
|
16
|
+
export function reportHcodeImageSizeRefusal() {
|
|
17
|
+
imageOmissionObserver.getStore()?.onImageSizeRefusal?.();
|
|
18
|
+
}
|
|
19
|
+
/** Report wire-level omissions after the final transport dispatches the request. */
|
|
20
|
+
export function reportHcodeImageOmissions(count, model) {
|
|
21
|
+
try {
|
|
22
|
+
imageOmissionObserver.getStore()?.observe(hcodeImageOmissionNotice(count, "requestBytes", model));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// A notice listener cannot turn a submitted request into a reported transport failure.
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Format the notice presented to the caller for projected or serialized omissions. */
|
|
29
|
+
export function hcodeImageOmissionNotice(count, reason, model) {
|
|
30
|
+
return `${count === 1 ? "1 image was" : `${count} images were`} left out of this HUMAIN Code request. ${hcodeImageMessage(reason, model)}`;
|
|
31
|
+
}
|
|
32
|
+
/** The model accepts only these inline image types; anything else is converted to PNG first. */
|
|
33
|
+
const HCODE_IMAGE_MIME_TYPES = ["image/png", "image/jpeg", "image/webp"];
|
|
34
|
+
/**
|
|
35
|
+
* Downscale or recompress every image to the model's catalog limits. Newer messages keep their images
|
|
36
|
+
* first; images over the count limits or that cannot fit become a text note, so one bad image never
|
|
37
|
+
* blocks later requests. Original messages are not changed.
|
|
38
|
+
*/
|
|
39
|
+
export async function fitHcodeImages(model, messages, { autoResizeImages, blockImages }, fresh, rejected) {
|
|
40
|
+
const limits = imageLimits(model);
|
|
41
|
+
const fitted = messages.slice();
|
|
42
|
+
const omitted = [];
|
|
43
|
+
const shared = limits &&
|
|
44
|
+
autoResizeImages &&
|
|
45
|
+
!blockImages &&
|
|
46
|
+
limits.maxPerRequest * limits.resize.maxBytes * 0.75 > HCODE_REQUEST_MAX_IMAGE_BYTES
|
|
47
|
+
? await fitFreshAggregate(fresh, limits)
|
|
48
|
+
: undefined;
|
|
49
|
+
let count = 0;
|
|
50
|
+
let remainingBytes = HCODE_REQUEST_MAX_IMAGE_BYTES;
|
|
51
|
+
const order = messages.map((_, index) => index).reverse();
|
|
52
|
+
for (const index of [
|
|
53
|
+
...order.filter((i) => fresh.has(messages[i])),
|
|
54
|
+
...order.filter((i) => !fresh.has(messages[i])),
|
|
55
|
+
]) {
|
|
56
|
+
const message = messages[index];
|
|
57
|
+
if (!("content" in message) || !Array.isArray(message.content))
|
|
58
|
+
continue;
|
|
59
|
+
if (!message.content.some((block) => block.type === "image"))
|
|
60
|
+
continue;
|
|
61
|
+
const content = [];
|
|
62
|
+
let perMessage = 0;
|
|
63
|
+
for (const block of message.content) {
|
|
64
|
+
if (block.type !== "image") {
|
|
65
|
+
content.push(block);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const result = rejected?.has(message)
|
|
69
|
+
? "requestBytes"
|
|
70
|
+
: blockImages
|
|
71
|
+
? "blocked"
|
|
72
|
+
: !limits
|
|
73
|
+
? "unsupported"
|
|
74
|
+
: perMessage >= limits.maxPerMessage
|
|
75
|
+
? "perMessage"
|
|
76
|
+
: count >= limits.maxPerRequest
|
|
77
|
+
? "perRequest"
|
|
78
|
+
: ((fresh.has(message) ? shared?.get(block) : undefined) ??
|
|
79
|
+
(await fitImage(block, limits, autoResizeImages)));
|
|
80
|
+
let reason;
|
|
81
|
+
if (typeof result === "string")
|
|
82
|
+
reason = result;
|
|
83
|
+
else {
|
|
84
|
+
const reduced = hcodeDecodedImageBytes(result.image.data) > remainingBytes && fresh.has(message) && limits
|
|
85
|
+
? await fitImage(block, limits, autoResizeImages, Math.floor(remainingBytes / 3) * 4)
|
|
86
|
+
: result;
|
|
87
|
+
const bytes = typeof reduced === "string" ? Infinity : hcodeDecodedImageBytes(reduced.image.data);
|
|
88
|
+
if (typeof reduced !== "string" && bytes <= remainingBytes) {
|
|
89
|
+
remainingBytes -= bytes;
|
|
90
|
+
count++;
|
|
91
|
+
perMessage++;
|
|
92
|
+
content.push(reduced.image);
|
|
93
|
+
if (reduced.hints.length)
|
|
94
|
+
content.push(imageText(reduced.hints.join("\n")));
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
reason = "aggregateBytes";
|
|
98
|
+
}
|
|
99
|
+
omitted.push({ index, reason });
|
|
100
|
+
content.push(imageOmissionBlock(reason, model));
|
|
101
|
+
}
|
|
102
|
+
fitted[index] = { ...message, content };
|
|
103
|
+
}
|
|
104
|
+
return { messages: fitted, omitted };
|
|
105
|
+
}
|
|
106
|
+
// A fresh batch must fit as a whole. Don't spend the aggregate budget in transcript order.
|
|
107
|
+
async function fitFreshAggregate(fresh, limits) {
|
|
108
|
+
const images = [...fresh].flatMap((message) => "content" in message && Array.isArray(message.content)
|
|
109
|
+
? message.content.filter((block) => block.type === "image")
|
|
110
|
+
: []);
|
|
111
|
+
if (images.length > limits.maxPerRequest ||
|
|
112
|
+
images.length * limits.resize.maxBytes * 0.75 <= HCODE_REQUEST_MAX_IMAGE_BYTES)
|
|
113
|
+
return;
|
|
114
|
+
let total = 0;
|
|
115
|
+
for (const block of images) {
|
|
116
|
+
const result = await fitImage(block, limits, true);
|
|
117
|
+
if (typeof result === "string")
|
|
118
|
+
return;
|
|
119
|
+
total += hcodeDecodedImageBytes(result.image.data);
|
|
120
|
+
}
|
|
121
|
+
if (total <= HCODE_REQUEST_MAX_IMAGE_BYTES)
|
|
122
|
+
return;
|
|
123
|
+
const maxBytes = Math.floor(HCODE_REQUEST_MAX_IMAGE_BYTES / images.length / 3) * 4;
|
|
124
|
+
const reduced = new Map();
|
|
125
|
+
for (const block of images) {
|
|
126
|
+
if (!reduced.has(block))
|
|
127
|
+
reduced.set(block, await fitImage(block, limits, true, maxBytes));
|
|
128
|
+
}
|
|
129
|
+
return reduced;
|
|
130
|
+
}
|
|
131
|
+
function imageText(text) {
|
|
132
|
+
const block = { type: "text", text };
|
|
133
|
+
optionalImageText.add(block);
|
|
134
|
+
return block;
|
|
135
|
+
}
|
|
136
|
+
function imageOmissionBlock(reason, model) {
|
|
137
|
+
return imageText(`[Image omitted from this HUMAIN Code request: ${hcodeImageMessage(reason, model)}]`);
|
|
138
|
+
}
|
|
139
|
+
/** Isolate the transcript from payload hooks and retain image provenance across reordering or cloning. */
|
|
140
|
+
export function hcodeImagePayloadDraft(payload, active) {
|
|
141
|
+
const draft = JSON.parse(JSON.stringify(payload));
|
|
142
|
+
const fresh = [];
|
|
143
|
+
const history = [];
|
|
144
|
+
for (const [index, message] of payload.context.messages.entries()) {
|
|
145
|
+
if (typeof message.content === "string")
|
|
146
|
+
continue;
|
|
147
|
+
const copy = draft.context.messages[index].content;
|
|
148
|
+
for (const [i, block] of message.content.entries()) {
|
|
149
|
+
if (block.type === "image")
|
|
150
|
+
(active.has(index) ? fresh : history).push(block);
|
|
151
|
+
if (block.type === "text" && optionalImageText.has(block))
|
|
152
|
+
optionalImageText.add(copy[i]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
draft,
|
|
157
|
+
protectedMessages(messages) {
|
|
158
|
+
return new Set(messages.flatMap((message, index) => {
|
|
159
|
+
if (typeof message.content === "string")
|
|
160
|
+
return [];
|
|
161
|
+
const protectedImage = message.content.some((block) => {
|
|
162
|
+
if (block.type !== "image")
|
|
163
|
+
return false;
|
|
164
|
+
const { data, mimeType } = block;
|
|
165
|
+
const matches = (image) => image.data === data && image.mimeType === mimeType;
|
|
166
|
+
// Added or changed images are not eligible for silent eviction. Fresh wins on identical copies.
|
|
167
|
+
return Object.keys(block).length !== 3 || fresh.some(matches) || !history.some(matches);
|
|
168
|
+
});
|
|
169
|
+
return protectedImage ? [index] : [];
|
|
170
|
+
}));
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** The catalog and hard wire limits apply to the exact JSON, including image metadata and options. */
|
|
175
|
+
export async function fitHcodeRequestSize(model, messages, active, serialize) {
|
|
176
|
+
const limit = Math.min(12582912, model.inputLimits?.maxRequestBytes ?? 12582912);
|
|
177
|
+
const imageData = (block) => block.type === "image";
|
|
178
|
+
const byteLength = (value) => Buffer.byteLength(value, "utf8");
|
|
179
|
+
let body = serialize(messages);
|
|
180
|
+
let bytes = byteLength(body);
|
|
181
|
+
let nonImageBytes = bytes;
|
|
182
|
+
let hasImageContent = false;
|
|
183
|
+
for (const message of messages) {
|
|
184
|
+
if (typeof message.content === "string")
|
|
185
|
+
continue;
|
|
186
|
+
for (const block of message.content) {
|
|
187
|
+
if (imageData(block)) {
|
|
188
|
+
nonImageBytes -= block.data.length;
|
|
189
|
+
hasImageContent = true;
|
|
190
|
+
}
|
|
191
|
+
else if (block.type === "text" && optionalImageText.has(block))
|
|
192
|
+
hasImageContent = true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const fits = () => bytes <= limit && nonImageBytes <= HCODE_REQUEST_MAX_NON_IMAGE_BYTES;
|
|
196
|
+
// Text-only requests retain their existing strict parse and final-send size checks.
|
|
197
|
+
if (!hasImageContent || fits())
|
|
198
|
+
return { body, omitted: 0 };
|
|
199
|
+
const projected = messages.slice();
|
|
200
|
+
const optional = [];
|
|
201
|
+
const historical = [];
|
|
202
|
+
const fresh = [];
|
|
203
|
+
for (const [index, message] of messages.entries()) {
|
|
204
|
+
if (typeof message.content === "string" || (message.role !== "user" && message.role !== "toolResult"))
|
|
205
|
+
continue;
|
|
206
|
+
const slots = [...message.content];
|
|
207
|
+
let length = slots.length;
|
|
208
|
+
for (const [i, block] of message.content.entries()) {
|
|
209
|
+
const put = (value) => {
|
|
210
|
+
const previous = slots[i];
|
|
211
|
+
const delta = (b) => (b ? byteLength(JSON.stringify(b)) : 0);
|
|
212
|
+
const data = (b) => (b && imageData(b) ? b.data.length : 0);
|
|
213
|
+
const separator = !previous && value && length > 0 ? 1 : previous && !value && length > 1 ? -1 : 0;
|
|
214
|
+
length += Number(value !== undefined) - Number(previous !== undefined);
|
|
215
|
+
const change = delta(value) - delta(previous) + separator;
|
|
216
|
+
bytes += change;
|
|
217
|
+
nonImageBytes += change + data(previous) - data(value);
|
|
218
|
+
slots[i] = value;
|
|
219
|
+
projected[index] = { ...message, content: slots.filter((entry) => entry !== undefined) };
|
|
220
|
+
};
|
|
221
|
+
if (block.type === "text" && optionalImageText.has(block))
|
|
222
|
+
optional.push({ put, note: block });
|
|
223
|
+
else if (imageData(block)) {
|
|
224
|
+
if (active.has(index))
|
|
225
|
+
fresh.push({ put, image: block });
|
|
226
|
+
else
|
|
227
|
+
historical.push(put);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
for (const { put } of optional)
|
|
232
|
+
put(undefined);
|
|
233
|
+
let omitted = 0;
|
|
234
|
+
for (const put of historical) {
|
|
235
|
+
if (fits())
|
|
236
|
+
break;
|
|
237
|
+
put(undefined);
|
|
238
|
+
omitted++;
|
|
239
|
+
optional.push({ put, note: imageText("[Image omitted: request size limit.]") });
|
|
240
|
+
}
|
|
241
|
+
if (!fits() && nonImageBytes <= HCODE_REQUEST_MAX_NON_IMAGE_BYTES) {
|
|
242
|
+
const limits = imageLimits(model);
|
|
243
|
+
const autoResize = imageOmissionObserver.getStore()?.autoResizeImages ?? true;
|
|
244
|
+
if (limits && autoResize) {
|
|
245
|
+
// Reserve wire metadata for every attachment; smaller images keep their bytes first.
|
|
246
|
+
fresh.sort((a, b) => a.image.data.length - b.image.data.length);
|
|
247
|
+
let remaining = limit - bytes + fresh.reduce((sum, { image }) => sum + image.data.length, 0);
|
|
248
|
+
for (const [i, { put, image }] of fresh.entries()) {
|
|
249
|
+
const share = Math.floor(remaining / (fresh.length - i));
|
|
250
|
+
const result = await fitImage(image, limits, true, share);
|
|
251
|
+
if (typeof result === "string")
|
|
252
|
+
return;
|
|
253
|
+
put(result.image);
|
|
254
|
+
remaining -= result.image.data.length + result.image.mimeType.length - image.mimeType.length;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (!fits())
|
|
259
|
+
return;
|
|
260
|
+
for (const { put, note } of optional) {
|
|
261
|
+
put(note);
|
|
262
|
+
if (!fits())
|
|
263
|
+
put(undefined);
|
|
264
|
+
}
|
|
265
|
+
body = serialize(projected);
|
|
266
|
+
return { body, omitted };
|
|
267
|
+
}
|
|
268
|
+
function imageLimits(model) {
|
|
269
|
+
// The provider supplies only its X1-validated, immutable canonical model; pi's generic limits are optional.
|
|
270
|
+
return model.input.includes("image") ? model.inputLimits?.images : undefined;
|
|
271
|
+
}
|
|
272
|
+
// History blocks are stable objects, so each image is decoded and resized once per limits profile.
|
|
273
|
+
const fitCache = new WeakMap();
|
|
274
|
+
async function fitImage(block, limits, autoResizeImages, byteBudget = limits.resize.maxBytes) {
|
|
275
|
+
const maxBytes = Math.min(byteBudget, limits.resize.maxBytes);
|
|
276
|
+
if (maxBytes < 4)
|
|
277
|
+
return "size";
|
|
278
|
+
const cacheable = maxBytes === limits.resize.maxBytes;
|
|
279
|
+
const cached = cacheable ? fitCache.get(block) : undefined;
|
|
280
|
+
if (cached?.limits === limits && cached.autoResizeImages === autoResizeImages)
|
|
281
|
+
return cached.result;
|
|
282
|
+
const effective = cacheable ? limits : { ...limits, resize: { ...limits.resize, maxBytes } };
|
|
283
|
+
const processed = await processImage(Buffer.from(block.data, "base64"), block.mimeType, {
|
|
284
|
+
autoResizeImages,
|
|
285
|
+
resizeOptions: effective.resize,
|
|
286
|
+
mimeTypes: HCODE_IMAGE_MIME_TYPES,
|
|
287
|
+
});
|
|
288
|
+
let result;
|
|
289
|
+
if (!processed.ok)
|
|
290
|
+
result = (await checkHcodeImage(block, effective)) ?? "size";
|
|
291
|
+
else {
|
|
292
|
+
const unchanged = processed.data === block.data && processed.mimeType === block.mimeType;
|
|
293
|
+
const image = unchanged
|
|
294
|
+
? block
|
|
295
|
+
: { type: "image", data: processed.data, mimeType: processed.mimeType };
|
|
296
|
+
result = (await checkHcodeImage(image, effective)) ?? { image, hints: processed.hints };
|
|
297
|
+
}
|
|
298
|
+
if (cacheable)
|
|
299
|
+
fitCache.set(block, { limits, autoResizeImages, result });
|
|
300
|
+
return result;
|
|
301
|
+
}
|
|
302
|
+
/** One plain message per refusal cause, naming the catalog limit that applies. */
|
|
303
|
+
export function hcodeImageMessage(reason, model) {
|
|
304
|
+
const limits = imageLimits(model);
|
|
305
|
+
switch (reason) {
|
|
306
|
+
case "blocked":
|
|
307
|
+
return "HUMAIN Code image attachments are blocked. Remove them or change /settings before sending.";
|
|
308
|
+
case "requestBytes":
|
|
309
|
+
return "Earlier images exceeded the HUMAIN Code request size limit.";
|
|
310
|
+
case "unsupported":
|
|
311
|
+
return "This HUMAIN Code model doesn't support images. Remove the image or choose an image-capable model with /model.";
|
|
312
|
+
case "perMessage":
|
|
313
|
+
return `HUMAIN Code accepts at most ${images(limits?.maxPerMessage)} per message. Remove some images and try again.`;
|
|
314
|
+
case "perRequest":
|
|
315
|
+
return `HUMAIN Code accepts at most ${images(limits?.maxPerRequest)} per request, including earlier messages. Remove some images and try again.`;
|
|
316
|
+
case "aggregateBytes":
|
|
317
|
+
return "This HUMAIN Code request exceeds the combined image size limit of 8 MiB. Attach fewer or smaller images.";
|
|
318
|
+
case "size":
|
|
319
|
+
return `This image couldn't be reduced to the HUMAIN Code limits (${limits?.resize.maxWidth}x${limits?.resize.maxHeight} px, ${limits?.resize.maxBytes} bytes). Attach a smaller image.`;
|
|
320
|
+
case "invalid":
|
|
321
|
+
return "This image isn't a readable single-frame PNG, JPEG or WebP image. Attach a different image.";
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function images(count) {
|
|
325
|
+
return count === 1 ? "1 image" : `${count} images`;
|
|
326
|
+
}
|
|
327
|
+
/** Refuse a request whose images do not meet the model's limits; the final guard before the wire. */
|
|
328
|
+
export async function validateHcodeImages(model, messages) {
|
|
329
|
+
const groups = messages.flatMap((message) => {
|
|
330
|
+
if (typeof message.content === "string")
|
|
331
|
+
return [];
|
|
332
|
+
const content = message.content.filter((block) => block.type === "image");
|
|
333
|
+
return content.length ? [content] : [];
|
|
334
|
+
});
|
|
335
|
+
if (!groups.length)
|
|
336
|
+
return;
|
|
337
|
+
const limits = imageLimits(model);
|
|
338
|
+
const refuse = (reason) => {
|
|
339
|
+
throw new Error(hcodeImageMessage(reason, model));
|
|
340
|
+
};
|
|
341
|
+
if (!limits)
|
|
342
|
+
return refuse("unsupported");
|
|
343
|
+
if (groups.some((group) => group.length > limits.maxPerMessage))
|
|
344
|
+
return refuse("perMessage");
|
|
345
|
+
const blocks = groups.flat();
|
|
346
|
+
if (blocks.length > limits.maxPerRequest)
|
|
347
|
+
return refuse("perRequest");
|
|
348
|
+
let bytes = 0;
|
|
349
|
+
for (const block of blocks) {
|
|
350
|
+
const reason = await checkHcodeImage(block, limits);
|
|
351
|
+
if (reason)
|
|
352
|
+
return refuse(reason);
|
|
353
|
+
bytes += hcodeDecodedImageBytes(block.data);
|
|
354
|
+
}
|
|
355
|
+
if (bytes > HCODE_REQUEST_MAX_IMAGE_BYTES)
|
|
356
|
+
return refuse("aggregateBytes");
|
|
357
|
+
try {
|
|
358
|
+
// Reuse X1's canonical base64, MIME, count and aggregate byte bounds for the whole request.
|
|
359
|
+
parseHcodeMessagesRequest({
|
|
360
|
+
model: model.id,
|
|
361
|
+
context: { messages: groups.map((content) => ({ role: "user", content, timestamp: 0 })) },
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
catch {
|
|
365
|
+
refuse("size");
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/** Check one image against the limits without changing it; undefined when it can be sent as is. */
|
|
369
|
+
async function checkHcodeImage(block, limits) {
|
|
370
|
+
if (block.data.length > limits.resize.maxBytes)
|
|
371
|
+
return "size";
|
|
372
|
+
try {
|
|
373
|
+
parseHcodeMessagesRequest({
|
|
374
|
+
model: "image",
|
|
375
|
+
context: { messages: [{ role: "user", content: [block], timestamp: 0 }] },
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
catch {
|
|
379
|
+
return "invalid";
|
|
380
|
+
}
|
|
381
|
+
const dimensions = getImageDimensions(block.data, block.mimeType);
|
|
382
|
+
if (!dimensions || dimensions.widthPx < 1 || dimensions.heightPx < 1)
|
|
383
|
+
return "invalid";
|
|
384
|
+
if (dimensions.widthPx > limits.resize.maxWidth || dimensions.heightPx > limits.resize.maxHeight)
|
|
385
|
+
return "size";
|
|
386
|
+
const data = Buffer.from(block.data, "base64");
|
|
387
|
+
// Image bytes are wire input: reject animation, incomplete containers and hidden trailing frames before decoding.
|
|
388
|
+
if (!isStaticImageContainer(data, block.mimeType))
|
|
389
|
+
return "invalid";
|
|
390
|
+
const photon = await loadPhoton();
|
|
391
|
+
if (!photon)
|
|
392
|
+
return "invalid";
|
|
393
|
+
try {
|
|
394
|
+
const image = photon.PhotonImage.new_from_byteslice(data);
|
|
395
|
+
try {
|
|
396
|
+
if (image.get_width() !== dimensions.widthPx || image.get_height() !== dimensions.heightPx)
|
|
397
|
+
return "invalid";
|
|
398
|
+
}
|
|
399
|
+
finally {
|
|
400
|
+
image.free();
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
return "invalid";
|
|
405
|
+
}
|
|
406
|
+
return undefined;
|
|
407
|
+
}
|
|
408
|
+
function isStaticImageContainer(data, mime) {
|
|
409
|
+
if (mime === "image/png") {
|
|
410
|
+
let offset = 8, pixels = false;
|
|
411
|
+
while (offset + 12 <= data.length) {
|
|
412
|
+
const length = data.readUInt32BE(offset), name = data.toString("ascii", offset + 4, offset + 8);
|
|
413
|
+
if (length > data.length - offset - 12 || name === "acTL" || name === "fcTL" || name === "fdAT")
|
|
414
|
+
return false;
|
|
415
|
+
if (name === "IDAT")
|
|
416
|
+
pixels = true;
|
|
417
|
+
offset += length + 12;
|
|
418
|
+
if (name === "IEND")
|
|
419
|
+
return !length && pixels && offset === data.length;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
else if (mime === "image/webp") {
|
|
423
|
+
if (data.length < 12 || data.readUInt32LE(4) !== data.length - 8)
|
|
424
|
+
return false;
|
|
425
|
+
let offset = 12, frames = 0;
|
|
426
|
+
while (offset + 8 <= data.length) {
|
|
427
|
+
const name = data.toString("ascii", offset, offset + 4), length = data.readUInt32LE(offset + 4);
|
|
428
|
+
if (length > data.length - offset - 8 ||
|
|
429
|
+
name === "ANIM" ||
|
|
430
|
+
name === "ANMF" ||
|
|
431
|
+
(name === "VP8X" && data[offset + 8] & 2))
|
|
432
|
+
return false;
|
|
433
|
+
if (name === "VP8 " || name === "VP8L")
|
|
434
|
+
frames++;
|
|
435
|
+
offset += 8 + length + (length % 2);
|
|
436
|
+
}
|
|
437
|
+
return offset === data.length && frames === 1;
|
|
438
|
+
}
|
|
439
|
+
else if (mime === "image/jpeg") {
|
|
440
|
+
let offset = 2;
|
|
441
|
+
while (offset < data.length) {
|
|
442
|
+
if (data[offset++] !== 255)
|
|
443
|
+
continue;
|
|
444
|
+
while (data[offset] === 255)
|
|
445
|
+
offset++;
|
|
446
|
+
const marker = data[offset++];
|
|
447
|
+
if (marker === 217)
|
|
448
|
+
return offset === data.length;
|
|
449
|
+
if (marker === 216)
|
|
450
|
+
return false;
|
|
451
|
+
if (marker === 0 || marker === 1 || (marker !== undefined && marker >= 208 && marker <= 215))
|
|
452
|
+
continue;
|
|
453
|
+
if (offset + 2 > data.length)
|
|
454
|
+
return false;
|
|
455
|
+
const length = data.readUInt16BE(offset);
|
|
456
|
+
if (length < 2 || length > data.length - offset)
|
|
457
|
+
return false;
|
|
458
|
+
offset += length;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
//# sourceMappingURL=images.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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CAAC;QACrC,CAAC;QACD,OAAO,MAAM,KAAK,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,CAAC,CAAC;IAC/C,CAAC;SAAM,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;QAClC,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YAC7B,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,GAAG;gBAAE,SAAS;YACrC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG;gBAAE,MAAM,EAAE,CAAC;YACtC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAC9B,IAAI,MAAM,KAAK,GAAG;gBAAE,OAAO,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC;YAClD,IAAI,MAAM,KAAK,GAAG;gBAAE,OAAO,KAAK,CAAC;YACjC,IAAI,MAAM,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC;gBAAE,SAAS;YACvG,IAAI,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM;gBAAE,OAAO,KAAK,CAAC;YAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;YACzC,IAAI,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,MAAM;gBAAE,OAAO,KAAK,CAAC;YAC9D,MAAM,IAAI,MAAM,CAAC;QAClB,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["// Fits HUMAIN Code request images to the selected model's catalog limits and names each refusal cause.\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { Api, ImageContent, Model, TextContent } from \"@earendil-works/pi-ai\";\nimport { getImageDimensions } from \"@earendil-works/pi-tui\";\nimport { processImage } from \"../../utils/image-process.ts\";\nimport { loadPhoton } from \"../../utils/photon.ts\";\nimport {\n\tHCODE_REQUEST_MAX_IMAGE_BYTES,\n\tHCODE_REQUEST_MAX_NON_IMAGE_BYTES,\n\ttype HcodeModel,\n\ttype HcodeText,\n\thcodeDecodedImageBytes,\n\tparseHcodeMessagesRequest,\n} from \"./contracts.ts\";\n\n/** Why an image cannot be part of a HUMAIN Code request. */\nexport type HcodeImageReason =\n\t| \"blocked\"\n\t| \"unsupported\"\n\t| \"perMessage\"\n\t| \"perRequest\"\n\t| \"aggregateBytes\"\n\t| \"requestBytes\"\n\t| \"size\"\n\t| \"invalid\";\n\n// Content array identity survives custom-message conversion without adding metadata to the wire.\nexport const hcodeActivePrompts = new WeakSet<readonly unknown[]>();\nconst optionalImageText = new WeakSet<TextContent>();\n\nconst imageOmissionObserver = new AsyncLocalStorage<{\n\tobserve: (message: string) => void;\n\tautoResizeImages: boolean;\n\tonImageSizeRefusal?: () => void;\n}>();\n\n/** Observe serialized image omissions for this session's requests, not other sessions sharing the provider. */\nexport function observeHcodeImageOmissions<T>(\n\tobserve: (message: string) => void,\n\trun: () => T,\n\t{\n\t\tautoResizeImages = true,\n\t\tonImageSizeRefusal,\n\t}: { autoResizeImages?: boolean; onImageSizeRefusal?: () => void } = {},\n): T {\n\treturn imageOmissionObserver.run({ observe, autoResizeImages, onImageSizeRefusal }, run);\n}\n\n/** Record fresh attachments refused before dispatch so the session can omit them from subsequent projections. */\nexport function reportHcodeImageSizeRefusal(): void {\n\timageOmissionObserver.getStore()?.onImageSizeRefusal?.();\n}\n\n/** Report wire-level omissions after the final transport dispatches the request. */\nexport function reportHcodeImageOmissions(count: number, model: Model<Api>): void {\n\ttry {\n\t\timageOmissionObserver.getStore()?.observe(hcodeImageOmissionNotice(count, \"requestBytes\", model));\n\t} catch {\n\t\t// A notice listener cannot turn a submitted request into a reported transport failure.\n\t}\n}\n\n/** Format the notice presented to the caller for projected or serialized omissions. */\nexport function hcodeImageOmissionNotice(count: number, reason: HcodeImageReason, model: Model<Api>): string {\n\treturn `${count === 1 ? \"1 image was\" : `${count} images were`} left out of this HUMAIN Code request. ${hcodeImageMessage(reason, model)}`;\n}\n\n/** Request messages with every image fitted, and the images that had to be left out (by message index). */\nexport interface FittedHcodeImages {\n\tmessages: AgentMessage[];\n\tomitted: { index: number; reason: HcodeImageReason }[];\n}\n\ntype ImageLimits = HcodeModel[\"inputLimits\"][\"images\"] & {};\n\n/** The model accepts only these inline image types; anything else is converted to PNG first. */\nconst HCODE_IMAGE_MIME_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\"] as const;\n\n/**\n * Downscale or recompress every image to the model's catalog limits. Newer messages keep their images\n * first; images over the count limits or that cannot fit become a text note, so one bad image never\n * blocks later requests. Original messages are not changed.\n */\nexport async function fitHcodeImages(\n\tmodel: Model<Api>,\n\tmessages: AgentMessage[],\n\t{ autoResizeImages, blockImages }: { autoResizeImages: boolean; blockImages: boolean },\n\tfresh: ReadonlySet<AgentMessage>,\n\trejected?: ReadonlySet<AgentMessage>,\n): Promise<FittedHcodeImages> {\n\tconst limits = imageLimits(model);\n\tconst fitted = messages.slice();\n\tconst omitted: FittedHcodeImages[\"omitted\"] = [];\n\tconst shared =\n\t\tlimits &&\n\t\tautoResizeImages &&\n\t\t!blockImages &&\n\t\tlimits.maxPerRequest * limits.resize.maxBytes * 0.75 > HCODE_REQUEST_MAX_IMAGE_BYTES\n\t\t\t? await fitFreshAggregate(fresh, limits)\n\t\t\t: undefined;\n\tlet count = 0;\n\tlet remainingBytes = HCODE_REQUEST_MAX_IMAGE_BYTES;\n\tconst order = messages.map((_, index) => index).reverse();\n\tfor (const index of [\n\t\t...order.filter((i) => fresh.has(messages[i]!)),\n\t\t...order.filter((i) => !fresh.has(messages[i]!)),\n\t]) {\n\t\tconst message = messages[index]!;\n\t\tif (!(\"content\" in message) || !Array.isArray(message.content)) continue;\n\t\tif (!message.content.some((block) => block.type === \"image\")) continue;\n\t\tconst content: (TextContent | ImageContent)[] = [];\n\t\tlet perMessage = 0;\n\t\tfor (const block of message.content as (TextContent | ImageContent)[]) {\n\t\t\tif (block.type !== \"image\") {\n\t\t\t\tcontent.push(block);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = rejected?.has(message)\n\t\t\t\t? \"requestBytes\"\n\t\t\t\t: blockImages\n\t\t\t\t\t? \"blocked\"\n\t\t\t\t\t: !limits\n\t\t\t\t\t\t? \"unsupported\"\n\t\t\t\t\t\t: perMessage >= limits.maxPerMessage\n\t\t\t\t\t\t\t? \"perMessage\"\n\t\t\t\t\t\t\t: count >= limits.maxPerRequest\n\t\t\t\t\t\t\t\t? \"perRequest\"\n\t\t\t\t\t\t\t\t: ((fresh.has(message) ? shared?.get(block) : undefined) ??\n\t\t\t\t\t\t\t\t\t(await fitImage(block, limits, autoResizeImages)));\n\t\t\tlet reason: HcodeImageReason;\n\t\t\tif (typeof result === \"string\") reason = result;\n\t\t\telse {\n\t\t\t\tconst reduced =\n\t\t\t\t\thcodeDecodedImageBytes(result.image.data) > remainingBytes && fresh.has(message) && limits\n\t\t\t\t\t\t? await fitImage(block, limits, autoResizeImages, Math.floor(remainingBytes / 3) * 4)\n\t\t\t\t\t\t: result;\n\t\t\t\tconst bytes = typeof reduced === \"string\" ? Infinity : hcodeDecodedImageBytes(reduced.image.data);\n\t\t\t\tif (typeof reduced !== \"string\" && bytes <= remainingBytes) {\n\t\t\t\t\tremainingBytes -= bytes;\n\t\t\t\t\tcount++;\n\t\t\t\t\tperMessage++;\n\t\t\t\t\tcontent.push(reduced.image);\n\t\t\t\t\tif (reduced.hints.length) content.push(imageText(reduced.hints.join(\"\\n\")));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\treason = \"aggregateBytes\";\n\t\t\t}\n\t\t\tomitted.push({ index, reason });\n\t\t\tcontent.push(imageOmissionBlock(reason, model));\n\t\t}\n\t\tfitted[index] = { ...message, content } as AgentMessage;\n\t}\n\treturn { messages: fitted, omitted };\n}\n\n// A fresh batch must fit as a whole. Don't spend the aggregate budget in transcript order.\nasync function fitFreshAggregate(fresh: ReadonlySet<AgentMessage>, limits: ImageLimits) {\n\tconst images = [...fresh].flatMap((message) =>\n\t\t\"content\" in message && Array.isArray(message.content)\n\t\t\t? message.content.filter((block): block is ImageContent => block.type === \"image\")\n\t\t\t: [],\n\t);\n\tif (\n\t\timages.length > limits.maxPerRequest ||\n\t\timages.length * limits.resize.maxBytes * 0.75 <= HCODE_REQUEST_MAX_IMAGE_BYTES\n\t)\n\t\treturn;\n\tlet total = 0;\n\tfor (const block of images) {\n\t\tconst result = await fitImage(block, limits, true);\n\t\tif (typeof result === \"string\") return;\n\t\ttotal += hcodeDecodedImageBytes(result.image.data);\n\t}\n\tif (total <= HCODE_REQUEST_MAX_IMAGE_BYTES) return;\n\tconst maxBytes = Math.floor(HCODE_REQUEST_MAX_IMAGE_BYTES / images.length / 3) * 4;\n\tconst reduced = new Map<ImageContent, FitResult>();\n\tfor (const block of images) {\n\t\tif (!reduced.has(block)) reduced.set(block, await fitImage(block, limits, true, maxBytes));\n\t}\n\treturn reduced;\n}\n\nfunction imageText(text: string): HcodeText {\n\tconst block = { type: \"text\" as const, text };\n\toptionalImageText.add(block);\n\treturn block;\n}\n\nfunction imageOmissionBlock(reason: HcodeImageReason, model: Model<Api>): HcodeText {\n\treturn imageText(`[Image omitted from this HUMAIN Code request: ${hcodeImageMessage(reason, model)}]`);\n}\n\ntype PayloadMessage = { content: string | readonly { type: string }[] };\n\n/** Isolate the transcript from payload hooks and retain image provenance across reordering or cloning. */\nexport function hcodeImagePayloadDraft<T extends { context: { messages: PayloadMessage[] } }>(\n\tpayload: T,\n\tactive: ReadonlySet<number>,\n): { draft: T; protectedMessages: (messages: PayloadMessage[]) => Set<number> } {\n\tconst draft = JSON.parse(JSON.stringify(payload)) as T;\n\tconst fresh: ImageContent[] = [];\n\tconst history: ImageContent[] = [];\n\tfor (const [index, message] of payload.context.messages.entries()) {\n\t\tif (typeof message.content === \"string\") continue;\n\t\tconst copy = draft.context.messages[index]!.content as readonly { type: string }[];\n\t\tfor (const [i, block] of message.content.entries()) {\n\t\t\tif (block.type === \"image\") (active.has(index) ? fresh : history).push(block as ImageContent);\n\t\t\tif (block.type === \"text\" && optionalImageText.has(block as TextContent))\n\t\t\t\toptionalImageText.add(copy[i] as TextContent);\n\t\t}\n\t}\n\treturn {\n\t\tdraft,\n\t\tprotectedMessages(messages) {\n\t\t\treturn new Set(\n\t\t\t\tmessages.flatMap((message, index) => {\n\t\t\t\t\tif (typeof message.content === \"string\") return [];\n\t\t\t\t\tconst protectedImage = message.content.some((block) => {\n\t\t\t\t\t\tif (block.type !== \"image\") return false;\n\t\t\t\t\t\tconst { data, mimeType } = block as ImageContent;\n\t\t\t\t\t\tconst matches = (image: ImageContent) => image.data === data && image.mimeType === mimeType;\n\t\t\t\t\t\t// Added or changed images are not eligible for silent eviction. Fresh wins on identical copies.\n\t\t\t\t\t\treturn Object.keys(block).length !== 3 || fresh.some(matches) || !history.some(matches);\n\t\t\t\t\t});\n\t\t\t\t\treturn protectedImage ? [index] : [];\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t};\n}\n\n/** The catalog and hard wire limits apply to the exact JSON, including image metadata and options. */\nexport async function fitHcodeRequestSize<T extends { role: string; content: string | readonly { type: string }[] }>(\n\tmodel: Model<Api>,\n\tmessages: T[],\n\tactive: ReadonlySet<number>,\n\tserialize: (messages: T[]) => string,\n): Promise<{ body: string; omitted: number } | undefined> {\n\tconst limit = Math.min(12582912, model.inputLimits?.maxRequestBytes ?? 12582912);\n\tconst imageData = (block: { type: string }): block is ImageContent => block.type === \"image\";\n\tconst byteLength = (value: string) => Buffer.byteLength(value, \"utf8\");\n\tlet body = serialize(messages);\n\tlet bytes = byteLength(body);\n\tlet nonImageBytes = bytes;\n\tlet hasImageContent = false;\n\tfor (const message of messages) {\n\t\tif (typeof message.content === \"string\") continue;\n\t\tfor (const block of message.content) {\n\t\t\tif (imageData(block)) {\n\t\t\t\tnonImageBytes -= block.data.length;\n\t\t\t\thasImageContent = true;\n\t\t\t} else if (block.type === \"text\" && optionalImageText.has(block as TextContent)) hasImageContent = true;\n\t\t}\n\t}\n\tconst fits = () => bytes <= limit && nonImageBytes <= HCODE_REQUEST_MAX_NON_IMAGE_BYTES;\n\t// Text-only requests retain their existing strict parse and final-send size checks.\n\tif (!hasImageContent || fits()) return { body, omitted: 0 };\n\n\tconst projected = messages.slice();\n\tconst optional: { put: (block: TextContent | undefined) => void; note: TextContent }[] = [];\n\tconst historical: ((block: TextContent | undefined) => void)[] = [];\n\tconst fresh: { put: (block: ImageContent) => void; image: ImageContent }[] = [];\n\tfor (const [index, message] of messages.entries()) {\n\t\tif (typeof message.content === \"string\" || (message.role !== \"user\" && message.role !== \"toolResult\")) continue;\n\t\tconst slots: ({ type: string } | undefined)[] = [...message.content];\n\t\tlet length = slots.length;\n\t\tfor (const [i, block] of message.content.entries()) {\n\t\t\tconst put = (value: (typeof slots)[number]) => {\n\t\t\t\tconst previous = slots[i];\n\t\t\t\tconst delta = (b: typeof previous) => (b ? byteLength(JSON.stringify(b)) : 0);\n\t\t\t\tconst data = (b: typeof previous) => (b && imageData(b) ? b.data.length : 0);\n\t\t\t\tconst separator = !previous && value && length > 0 ? 1 : previous && !value && length > 1 ? -1 : 0;\n\t\t\t\tlength += Number(value !== undefined) - Number(previous !== undefined);\n\t\t\t\tconst change = delta(value) - delta(previous) + separator;\n\t\t\t\tbytes += change;\n\t\t\t\tnonImageBytes += change + data(previous) - data(value);\n\t\t\t\tslots[i] = value;\n\t\t\t\tprojected[index] = { ...message, content: slots.filter((entry) => entry !== undefined) };\n\t\t\t};\n\t\t\tif (block.type === \"text\" && optionalImageText.has(block as TextContent))\n\t\t\t\toptional.push({ put, note: block as TextContent });\n\t\t\telse if (imageData(block)) {\n\t\t\t\tif (active.has(index)) fresh.push({ put, image: block });\n\t\t\t\telse historical.push(put);\n\t\t\t}\n\t\t}\n\t}\n\tfor (const { put } of optional) put(undefined);\n\tlet omitted = 0;\n\tfor (const put of historical) {\n\t\tif (fits()) break;\n\t\tput(undefined);\n\t\tomitted++;\n\t\toptional.push({ put, note: imageText(\"[Image omitted: request size limit.]\") });\n\t}\n\tif (!fits() && nonImageBytes <= HCODE_REQUEST_MAX_NON_IMAGE_BYTES) {\n\t\tconst limits = imageLimits(model);\n\t\tconst autoResize = imageOmissionObserver.getStore()?.autoResizeImages ?? true;\n\t\tif (limits && autoResize) {\n\t\t\t// Reserve wire metadata for every attachment; smaller images keep their bytes first.\n\t\t\tfresh.sort((a, b) => a.image.data.length - b.image.data.length);\n\t\t\tlet remaining = limit - bytes + fresh.reduce((sum, { image }) => sum + image.data.length, 0);\n\t\t\tfor (const [i, { put, image }] of fresh.entries()) {\n\t\t\t\tconst share = Math.floor(remaining / (fresh.length - i));\n\t\t\t\tconst result = await fitImage(image, limits, true, share);\n\t\t\t\tif (typeof result === \"string\") return;\n\t\t\t\tput(result.image);\n\t\t\t\tremaining -= result.image.data.length + result.image.mimeType.length - image.mimeType.length;\n\t\t\t}\n\t\t}\n\t}\n\tif (!fits()) return;\n\tfor (const { put, note } of optional) {\n\t\tput(note);\n\t\tif (!fits()) put(undefined);\n\t}\n\tbody = serialize(projected);\n\treturn { body, omitted };\n}\n\nfunction imageLimits(model: Model<Api>): ImageLimits | undefined {\n\t// The provider supplies only its X1-validated, immutable canonical model; pi's generic limits are optional.\n\treturn model.input.includes(\"image\") ? (model.inputLimits?.images as ImageLimits | undefined) : undefined;\n}\n\ntype FitResult = { image: ImageContent; hints: string[] } | HcodeImageReason;\n\n// History blocks are stable objects, so each image is decoded and resized once per limits profile.\nconst fitCache = new WeakMap<ImageContent, { limits: ImageLimits; autoResizeImages: boolean; result: FitResult }>();\n\nasync function fitImage(\n\tblock: ImageContent,\n\tlimits: ImageLimits,\n\tautoResizeImages: boolean,\n\tbyteBudget = limits.resize.maxBytes,\n): Promise<FitResult> {\n\tconst maxBytes = Math.min(byteBudget, limits.resize.maxBytes);\n\tif (maxBytes < 4) return \"size\";\n\tconst cacheable = maxBytes === limits.resize.maxBytes;\n\tconst cached = cacheable ? fitCache.get(block) : undefined;\n\tif (cached?.limits === limits && cached.autoResizeImages === autoResizeImages) return cached.result;\n\tconst effective = cacheable ? limits : { ...limits, resize: { ...limits.resize, maxBytes } };\n\tconst processed = await processImage(Buffer.from(block.data, \"base64\"), block.mimeType, {\n\t\tautoResizeImages,\n\t\tresizeOptions: effective.resize,\n\t\tmimeTypes: HCODE_IMAGE_MIME_TYPES,\n\t});\n\tlet result: FitResult;\n\tif (!processed.ok) result = (await checkHcodeImage(block, effective)) ?? \"size\";\n\telse {\n\t\tconst unchanged = processed.data === block.data && processed.mimeType === block.mimeType;\n\t\tconst image: ImageContent = unchanged\n\t\t\t? block\n\t\t\t: { type: \"image\", data: processed.data, mimeType: processed.mimeType };\n\t\tresult = (await checkHcodeImage(image, effective)) ?? { image, hints: processed.hints };\n\t}\n\tif (cacheable) fitCache.set(block, { limits, autoResizeImages, result });\n\treturn result;\n}\n\n/** One plain message per refusal cause, naming the catalog limit that applies. */\nexport function hcodeImageMessage(reason: HcodeImageReason, model: Model<Api>): string {\n\tconst limits = imageLimits(model);\n\tswitch (reason) {\n\t\tcase \"blocked\":\n\t\t\treturn \"HUMAIN Code image attachments are blocked. Remove them or change /settings before sending.\";\n\t\tcase \"requestBytes\":\n\t\t\treturn \"Earlier images exceeded the HUMAIN Code request size limit.\";\n\t\tcase \"unsupported\":\n\t\t\treturn \"This HUMAIN Code model doesn't support images. Remove the image or choose an image-capable model with /model.\";\n\t\tcase \"perMessage\":\n\t\t\treturn `HUMAIN Code accepts at most ${images(limits?.maxPerMessage)} per message. Remove some images and try again.`;\n\t\tcase \"perRequest\":\n\t\t\treturn `HUMAIN Code accepts at most ${images(limits?.maxPerRequest)} per request, including earlier messages. Remove some images and try again.`;\n\t\tcase \"aggregateBytes\":\n\t\t\treturn \"This HUMAIN Code request exceeds the combined image size limit of 8 MiB. Attach fewer or smaller images.\";\n\t\tcase \"size\":\n\t\t\treturn `This image couldn't be reduced to the HUMAIN Code limits (${limits?.resize.maxWidth}x${limits?.resize.maxHeight} px, ${limits?.resize.maxBytes} bytes). Attach a smaller image.`;\n\t\tcase \"invalid\":\n\t\t\treturn \"This image isn't a readable single-frame PNG, JPEG or WebP image. Attach a different image.\";\n\t}\n}\n\nfunction images(count: number | undefined): string {\n\treturn count === 1 ? \"1 image\" : `${count} images`;\n}\n\n/** Refuse a request whose images do not meet the model's limits; the final guard before the wire. */\nexport async function validateHcodeImages(\n\tmodel: Model<Api>,\n\tmessages: readonly { content: string | readonly { type: string }[] }[],\n): Promise<void> {\n\tconst groups = messages.flatMap((message) => {\n\t\tif (typeof message.content === \"string\") return [];\n\t\tconst content = message.content.filter((block): block is ImageContent => block.type === \"image\");\n\t\treturn content.length ? [content] : [];\n\t});\n\tif (!groups.length) return;\n\tconst limits = imageLimits(model);\n\tconst refuse = (reason: HcodeImageReason) => {\n\t\tthrow new Error(hcodeImageMessage(reason, model));\n\t};\n\tif (!limits) return refuse(\"unsupported\");\n\tif (groups.some((group) => group.length > limits.maxPerMessage)) return refuse(\"perMessage\");\n\tconst blocks = groups.flat();\n\tif (blocks.length > limits.maxPerRequest) return refuse(\"perRequest\");\n\tlet bytes = 0;\n\tfor (const block of blocks) {\n\t\tconst reason = await checkHcodeImage(block, limits);\n\t\tif (reason) return refuse(reason);\n\t\tbytes += hcodeDecodedImageBytes(block.data);\n\t}\n\tif (bytes > HCODE_REQUEST_MAX_IMAGE_BYTES) return refuse(\"aggregateBytes\");\n\ttry {\n\t\t// Reuse X1's canonical base64, MIME, count and aggregate byte bounds for the whole request.\n\t\tparseHcodeMessagesRequest({\n\t\t\tmodel: model.id,\n\t\t\tcontext: { messages: groups.map((content) => ({ role: \"user\", content, timestamp: 0 })) },\n\t\t});\n\t} catch {\n\t\trefuse(\"size\");\n\t}\n}\n\n/** Check one image against the limits without changing it; undefined when it can be sent as is. */\nasync function checkHcodeImage(block: ImageContent, limits: ImageLimits): Promise<HcodeImageReason | undefined> {\n\tif (block.data.length > limits.resize.maxBytes) return \"size\";\n\ttry {\n\t\tparseHcodeMessagesRequest({\n\t\t\tmodel: \"image\",\n\t\t\tcontext: { messages: [{ role: \"user\", content: [block], timestamp: 0 }] },\n\t\t});\n\t} catch {\n\t\treturn \"invalid\";\n\t}\n\tconst dimensions = getImageDimensions(block.data, block.mimeType);\n\tif (!dimensions || dimensions.widthPx < 1 || dimensions.heightPx < 1) return \"invalid\";\n\tif (dimensions.widthPx > limits.resize.maxWidth || dimensions.heightPx > limits.resize.maxHeight) return \"size\";\n\tconst data = Buffer.from(block.data, \"base64\");\n\t// Image bytes are wire input: reject animation, incomplete containers and hidden trailing frames before decoding.\n\tif (!isStaticImageContainer(data, block.mimeType)) return \"invalid\";\n\tconst photon = await loadPhoton();\n\tif (!photon) return \"invalid\";\n\ttry {\n\t\tconst image = photon.PhotonImage.new_from_byteslice(data);\n\t\ttry {\n\t\t\tif (image.get_width() !== dimensions.widthPx || image.get_height() !== dimensions.heightPx) return \"invalid\";\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\treturn \"invalid\";\n\t}\n\treturn undefined;\n}\n\nfunction isStaticImageContainer(data: Buffer, mime: string): boolean {\n\tif (mime === \"image/png\") {\n\t\tlet offset = 8,\n\t\t\tpixels = false;\n\t\twhile (offset + 12 <= data.length) {\n\t\t\tconst length = data.readUInt32BE(offset),\n\t\t\t\tname = data.toString(\"ascii\", offset + 4, offset + 8);\n\t\t\tif (length > data.length - offset - 12 || name === \"acTL\" || name === \"fcTL\" || name === \"fdAT\") return false;\n\t\t\tif (name === \"IDAT\") pixels = true;\n\t\t\toffset += length + 12;\n\t\t\tif (name === \"IEND\") return !length && pixels && offset === data.length;\n\t\t}\n\t} else if (mime === \"image/webp\") {\n\t\tif (data.length < 12 || data.readUInt32LE(4) !== data.length - 8) return false;\n\t\tlet offset = 12,\n\t\t\tframes = 0;\n\t\twhile (offset + 8 <= data.length) {\n\t\t\tconst name = data.toString(\"ascii\", offset, offset + 4),\n\t\t\t\tlength = data.readUInt32LE(offset + 4);\n\t\t\tif (\n\t\t\t\tlength > data.length - offset - 8 ||\n\t\t\t\tname === \"ANIM\" ||\n\t\t\t\tname === \"ANMF\" ||\n\t\t\t\t(name === \"VP8X\" && data[offset + 8]! & 2)\n\t\t\t)\n\t\t\t\treturn false;\n\t\t\tif (name === \"VP8 \" || name === \"VP8L\") frames++;\n\t\t\toffset += 8 + length + (length % 2);\n\t\t}\n\t\treturn offset === data.length && frames === 1;\n\t} else if (mime === \"image/jpeg\") {\n\t\tlet offset = 2;\n\t\twhile (offset < data.length) {\n\t\t\tif (data[offset++] !== 255) continue;\n\t\t\twhile (data[offset] === 255) offset++;\n\t\t\tconst marker = data[offset++];\n\t\t\tif (marker === 217) return offset === data.length;\n\t\t\tif (marker === 216) return false;\n\t\t\tif (marker === 0 || marker === 1 || (marker !== undefined && marker >= 208 && marker <= 215)) continue;\n\t\t\tif (offset + 2 > data.length) return false;\n\t\t\tconst length = data.readUInt16BE(offset);\n\t\t\tif (length < 2 || length > data.length - offset) return false;\n\t\t\toffset += length;\n\t\t}\n\t}\n\treturn false;\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { HcodeCatalogEmptyReason } from "./contracts.ts";
|
|
2
|
+
import type { HcodeLoginReadiness } from "./facade.ts";
|
|
3
|
+
/** Why a signed-in account has no models: Forge's reason (if it sent one), or the list couldn't be loaded. */
|
|
4
|
+
export type HcodeEmptyCatalogCause = {
|
|
5
|
+
kind: "empty";
|
|
6
|
+
reason?: HcodeCatalogEmptyReason;
|
|
7
|
+
} | {
|
|
8
|
+
kind: "failed";
|
|
9
|
+
};
|
|
10
|
+
/** Guidance for a direct login when the server's sign-in settings don't match this CLI. */
|
|
11
|
+
export declare const HCODE_LOGIN_MISMATCH_DETAILS = "HUMAIN Code's sign-in settings (/api/cli/config or issuer discovery) don't match what this CLI version accepts. Update the CLI with `humain-code update`, or ask the HUMAIN Code platform team to check the server's CLI sign-in configuration.";
|
|
12
|
+
/** Say why the account's catalog is empty and what to do; servers without a reason keep the generic text. */
|
|
13
|
+
export declare function hcodeEmptyCatalogMessage(reason: HcodeCatalogEmptyReason | undefined): string;
|
|
14
|
+
/** The short reason and who can fix it: an admin, the server's configuration or the network. */
|
|
15
|
+
export declare function hcodeEmptyCatalogReason(cause: HcodeEmptyCatalogCause): {
|
|
16
|
+
reason: string;
|
|
17
|
+
fix: string;
|
|
18
|
+
};
|
|
19
|
+
/** Non-blocking notice after a sign-in that produced no models. */
|
|
20
|
+
export declare function hcodeEmptyCatalogNotice(environmentId: string, email: string | undefined, cause: HcodeEmptyCatalogCause): string;
|
|
21
|
+
/** `/login` row state for a readiness check; `undefined` means the check is still running. */
|
|
22
|
+
export declare function hcodeLoginAvailability(readiness: HcodeLoginReadiness | undefined): {
|
|
23
|
+
state: "pending" | "ready" | "failed";
|
|
24
|
+
text: string;
|
|
25
|
+
};
|
|
26
|
+
/** Says that the saved sign-in belongs to another environment and how to use it, e.g. after starting without --env. */
|
|
27
|
+
export declare function hcodeSignedInElsewhereNotice(environmentId: string, elsewhere: readonly string[]): string | undefined;
|
|
28
|
+
//# sourceMappingURL=login-copy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-copy.d.ts","sourceRoot":"","sources":["../../../src/humain/hcode/login-copy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,8GAA8G;AAC9G,MAAM,MAAM,sBAAsB,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,uBAAuB,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAE9G,2FAA2F;AAC3F,eAAO,MAAM,4BAA4B,oPACyM,CAAC;AAyBnP,6GAA6G;AAC7G,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,uBAAuB,GAAG,SAAS,GAAG,MAAM,CAI5F;AAED,gGAAgG;AAChG,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,sBAAsB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAMtG;AAED,mEAAmE;AACnE,wBAAgB,uBAAuB,CACtC,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,KAAK,EAAE,sBAAsB,GAC3B,MAAM,CASR;AAED,8FAA8F;AAC9F,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,mBAAmB,GAAG,SAAS,GAAG;IACnF,KAAK,EAAE,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;CACb,CAYA;AAED,uHAAuH;AACvH,wBAAgB,4BAA4B,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAIpH"}
|