@herbertgao/pi-extensions 2026.10.11 → 2026.10.13
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/README.md +8 -8
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/node_modules/@herbertgao/pi-agency/README.md +5 -3
- package/node_modules/@herbertgao/pi-agency/package.json +1 -1
- package/node_modules/@herbertgao/pi-agency/src/index.ts +51 -7
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +6 -8
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +6 -8
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +11 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/footer.ts +28 -6
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +33 -12
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +16 -3
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/agent-color.ts +11 -2
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +10 -5
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +3 -2
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/ui/fleet-list.ts +1 -0
- package/node_modules/@herbertgao/sol-pi/README.md +1 -1
- package/node_modules/@herbertgao/sol-pi/agents-install.md +2 -2
- package/node_modules/@narumitw/pi-btw/README.md +14 -5
- package/node_modules/@narumitw/pi-btw/dist/index.ts +1067 -560
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +4 -4
- package/node_modules/@narumitw/pi-btw/docs/core-alignment.md +277 -0
- package/node_modules/@narumitw/pi-btw/docs/native-appearance.md +857 -0
- package/node_modules/@narumitw/pi-btw/docs/workflows.md +34 -13
- package/node_modules/@narumitw/pi-btw/package.json +4 -4
- package/node_modules/@narumitw/pi-btw/src/btw.ts +152 -108
- package/node_modules/@narumitw/pi-btw/src/conversation-chrome.ts +93 -0
- package/node_modules/@narumitw/pi-btw/src/fullscreen-renderer.ts +329 -0
- package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +109 -315
- package/node_modules/@narumitw/pi-btw/src/keybindings.ts +100 -22
- package/node_modules/@narumitw/pi-btw/src/menu.ts +42 -27
- package/node_modules/@narumitw/pi-btw/src/session-lifetime.ts +66 -0
- package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +366 -164
- package/node_modules/@narumitw/pi-btw/src/workspace-layout.ts +96 -36
- package/node_modules/pi-lens/CHANGELOG.md +281 -0
- package/node_modules/pi-lens/README.md +13 -1
- package/node_modules/pi-lens/dist/{chunk-SS36ZX4J.js → chunk-24AKHFGP.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-JSQFTSC6.js → chunk-2FN63LPV.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-5UCAH366.js → chunk-2KXTHF3M.js} +20 -20
- package/node_modules/pi-lens/dist/{chunk-EU63SDCG.js → chunk-3DA2JDOL.js} +367 -281
- package/node_modules/pi-lens/dist/{chunk-RWWYJ623.js → chunk-3KAZU3VR.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-3PTHXJXR.js +28 -0
- package/node_modules/pi-lens/dist/chunk-3QED2P4V.js +31 -0
- package/node_modules/pi-lens/dist/{chunk-N2H3ZPZY.js → chunk-3RKP3FMS.js} +1 -0
- package/node_modules/pi-lens/dist/{chunk-XVF2VVXP.js → chunk-5HSRT26B.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-MXGY6KPT.js → chunk-5IUSNGOC.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-EJIUXPBX.js → chunk-5OFV52AM.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-AW7R2GWG.js → chunk-5VSF4UUQ.js} +12 -7
- package/node_modules/pi-lens/dist/{chunk-6STA6Z7I.js → chunk-5WRPDP2A.js} +18 -18
- package/node_modules/pi-lens/dist/{chunk-YIUAVF7E.js → chunk-6DLWKFEX.js} +35 -34
- package/node_modules/pi-lens/dist/{chunk-WOA4LN2R.js → chunk-7D6L4MTX.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-GAEGEPOC.js → chunk-7HXE67BN.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-AGSS7277.js +84 -0
- package/node_modules/pi-lens/dist/{chunk-R3PCY3YS.js → chunk-AMERCH6V.js} +13 -13
- package/node_modules/pi-lens/dist/{chunk-WU567RSC.js → chunk-ATKJFDQN.js} +14 -10
- package/node_modules/pi-lens/dist/{chunk-VSSBEUFT.js → chunk-AWSCPCN2.js} +16 -16
- package/node_modules/pi-lens/dist/{chunk-VCHXCQFG.js → chunk-BWD5EPKO.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-H6MF6EVN.js → chunk-CT4MN5IU.js} +1200 -230
- package/node_modules/pi-lens/dist/{chunk-FCSOVF55.js → chunk-CUHSHSB6.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-CHOW74WE.js → chunk-CYRKQRPM.js} +7 -10
- package/node_modules/pi-lens/dist/{chunk-Q7DUK4LX.js → chunk-DEL2U6CM.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-6C7JWPCP.js → chunk-DGUKIYSI.js} +26 -23
- package/node_modules/pi-lens/dist/{chunk-PHDMFAKM.js → chunk-DUO2TU77.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-MRXKYPCS.js → chunk-EBC36LNN.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-CSHFH5IN.js → chunk-ED36RF6Y.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-76MWC2K6.js → chunk-EUXZEFTV.js} +90 -97
- package/node_modules/pi-lens/dist/{chunk-QOZXJ4NA.js → chunk-FM4RDMKT.js} +11 -8
- package/node_modules/pi-lens/dist/{chunk-ACXEQZOU.js → chunk-GAQ7OQG6.js} +31 -28
- package/node_modules/pi-lens/dist/{chunk-XAGLWMJ4.js → chunk-GL5LUMZE.js} +23 -23
- package/node_modules/pi-lens/dist/{chunk-BKE7E7TC.js → chunk-GMX5OS7B.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-ZHFZWTZV.js → chunk-GSLNCYGG.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-3W7IEVVL.js → chunk-GSM5UU7A.js} +26 -34
- package/node_modules/pi-lens/dist/{chunk-724UL2TJ.js → chunk-GXFV6MYU.js} +3 -3
- package/node_modules/pi-lens/dist/chunk-HAD7QRQI.js +30 -0
- package/node_modules/pi-lens/dist/{chunk-QOBUHWHX.js → chunk-HRNHZA3N.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-VWCXW2E7.js → chunk-HWCCCQNX.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-7DYBLXYA.js → chunk-HYGZEMX6.js} +3 -3
- package/node_modules/pi-lens/dist/chunk-IJYGIDF4.js +186 -0
- package/node_modules/pi-lens/dist/{chunk-4W4VLAPJ.js → chunk-IQWN5JCP.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-SQ4TVJBR.js → chunk-IUE7SSKV.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-IBGIOBEE.js → chunk-IWDLU6K3.js} +68 -5
- package/node_modules/pi-lens/dist/{chunk-XCJN5IJU.js → chunk-IYNJ6YPZ.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-JAU72XNY.js → chunk-J64T55EI.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-2BBLFX75.js → chunk-J6MPGQTS.js} +5 -5
- package/node_modules/pi-lens/dist/chunk-JORED7EX.js +44 -0
- package/node_modules/pi-lens/dist/{chunk-6SDEP3AJ.js → chunk-JUKMK5Y4.js} +8 -8
- package/node_modules/pi-lens/dist/{chunk-FMSO6RDZ.js → chunk-JW3YWBVB.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-L3BLXZG7.js → chunk-KAPJINKN.js} +30 -69
- package/node_modules/pi-lens/dist/{chunk-2B73ZPOK.js → chunk-KN35K52N.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-C34ZXZ7O.js → chunk-KUA4OJ5Y.js} +24 -11
- package/node_modules/pi-lens/dist/chunk-KYUB6QDC.js +72 -0
- package/node_modules/pi-lens/dist/{chunk-67WMNWEE.js → chunk-LLJNQKQW.js} +12 -10
- package/node_modules/pi-lens/dist/chunk-LZSEQW6A.js +57 -0
- package/node_modules/pi-lens/dist/{chunk-ZANLILYD.js → chunk-M2IFVFWU.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-M2UD3LPU.js +88 -0
- package/node_modules/pi-lens/dist/{chunk-XIJZVPD5.js → chunk-MBKQHGA7.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-P7266HLM.js → chunk-MPNJLASA.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6GFRNVYR.js → chunk-MZGQNL3Y.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-ZWFS3OEF.js → chunk-N5FLEO7W.js} +33 -32
- package/node_modules/pi-lens/dist/{chunk-3JNKMP3B.js → chunk-O4NWQT6I.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-T6CPIZNT.js → chunk-OHKJ7PQF.js} +33 -32
- package/node_modules/pi-lens/dist/{chunk-VRZP76YM.js → chunk-P63GXC37.js} +4 -1
- package/node_modules/pi-lens/dist/{chunk-XTMJ7XDT.js → chunk-POMLXPMY.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-QQNQ7SJW.js → chunk-QBFBRV2B.js} +10 -4
- package/node_modules/pi-lens/dist/{chunk-CMMHNUZ2.js → chunk-R3T7CLQ2.js} +60 -38
- package/node_modules/pi-lens/dist/{chunk-23WOO7TX.js → chunk-R7YOCSNV.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-2CD5RS6M.js → chunk-RKBXZN3A.js} +23 -2
- package/node_modules/pi-lens/dist/{chunk-OCAGUNBC.js → chunk-RKKOYPRA.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-52FUZI6K.js → chunk-RMLC67LF.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-XMSXXAHW.js → chunk-ROYSX2S5.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-M6HSLBWY.js → chunk-RVK72CZX.js} +6507 -7514
- package/node_modules/pi-lens/dist/{chunk-FLKWCIZH.js → chunk-S2HEXIWI.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-UZ3TUTRV.js → chunk-S67KYG37.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-VCO24T4L.js → chunk-SD4I7ZO4.js} +14 -14
- package/node_modules/pi-lens/dist/{chunk-Z527N6YQ.js → chunk-SKAMFC7A.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-MQLUAEOC.js → chunk-SRYEJNES.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-BRGDSBJE.js → chunk-SYE6T2EB.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-GXW6K4YJ.js → chunk-T57LYLZT.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-ZXYDQ3TZ.js → chunk-T7FEBKXN.js} +48 -15
- package/node_modules/pi-lens/dist/{chunk-3EFKIGZN.js → chunk-TIQ2PKDW.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-QILIYSJF.js → chunk-TLX72JTG.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-TYM6OUIT.js → chunk-TOY6QKOH.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-IZSHAIJ7.js → chunk-TRETHTQO.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-3VPVG5SU.js → chunk-U44DJXQP.js} +10 -6
- package/node_modules/pi-lens/dist/{chunk-PNQDPDRC.js → chunk-UA7ZXYDR.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-OXXKQCSV.js → chunk-UBOQLVT2.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-QGQ5CCCG.js → chunk-UMS2MFPZ.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-QHJ6DQ2R.js → chunk-US7ECLD7.js} +55 -13
- package/node_modules/pi-lens/dist/{chunk-AB3YYG6N.js → chunk-UZ2XCLYS.js} +8 -8
- package/node_modules/pi-lens/dist/chunk-V35JG4JB.js +2667 -0
- package/node_modules/pi-lens/dist/{chunk-N3X6Q4YT.js → chunk-VOOAPROD.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-SAEFPSB6.js → chunk-W66O5E25.js} +21 -11
- package/node_modules/pi-lens/dist/{chunk-KBG47GHP.js → chunk-WMYE35PX.js} +15 -11
- package/node_modules/pi-lens/dist/{chunk-5NGR67U5.js → chunk-XBJVAEEO.js} +32 -5
- package/node_modules/pi-lens/dist/{chunk-YYOIQFRS.js → chunk-XHJBS436.js} +122 -44
- package/node_modules/pi-lens/dist/{chunk-GBPP5P7X.js → chunk-XTBDCR27.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-4UNXBNE2.js → chunk-XTFDJI3T.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-UXGETRP4.js → chunk-XYURS6EN.js} +13 -12
- package/node_modules/pi-lens/dist/{chunk-RPLINGVB.js → chunk-Y6GZHWSJ.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-2VUQMUMT.js → chunk-YCWYO6TQ.js} +41 -38
- package/node_modules/pi-lens/dist/{chunk-77M37OKR.js → chunk-YH5MVY2U.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-AOHZU2BM.js → chunk-YNE3RP52.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-YSZNHOBY.js → chunk-ZHH37KZL.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-ZGDGW2V3.js → chunk-ZIVJBOO3.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-RXCOMYPY.js → chunk-ZVUL7QYY.js} +29 -28
- package/node_modules/pi-lens/dist/index.js +11052 -5852
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +10 -9
- package/node_modules/pi-lens/dist/mcp/cli.js +41 -38
- package/node_modules/pi-lens/dist/mcp/server.js +1120 -474
- package/node_modules/pi-lens/dist/mcp/worker.js +61 -58
- package/node_modules/pi-lens/dist/probes/installer.js +19 -19
- package/node_modules/pi-lens/dist/workers/project-snapshot-persist-worker.js +28 -9
- package/node_modules/pi-lens/dist/workers/review-graph-persist-worker.js +1 -1
- package/node_modules/pi-lens/docs/configuration.md +11 -0
- package/node_modules/pi-lens/docs/engineering-principles.md +32 -0
- package/node_modules/pi-lens/docs/lsp-capability-matrix.md +1 -1
- package/node_modules/pi-lens/docs/lsp-idle-eviction.md +15 -26
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +117 -13
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +97 -7
- package/node_modules/pi-lens/docs/pi-lens-monitor.md +8 -2
- package/node_modules/pi-lens/docs/pi-lens-retro.md +4 -1
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +112 -4
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +22 -14
- package/node_modules/pi-lens/docs/release-qa-baseline.md +3 -1
- package/node_modules/pi-lens/docs/servercapabilities.md +9 -19
- package/node_modules/pi-lens/package.json +7 -5
- package/node_modules/pi-lens/scripts/download-grammars.js +40 -7
- package/node_modules/pi-lens/scripts/lib/latency-log-phases.mjs +95 -0
- package/node_modules/pi-lens/scripts/rpc-load-check.mjs +570 -81
- package/node_modules/pi-provider-qoder/dist/index.js +545 -221
- package/node_modules/pi-provider-qoder/package.json +1 -1
- package/node_modules/pi-web-access/CHANGELOG.md +39 -0
- package/node_modules/pi-web-access/README.md +83 -12
- package/node_modules/pi-web-access/anysearch.ts +4 -3
- package/node_modules/pi-web-access/bocha.ts +4 -3
- package/node_modules/pi-web-access/brightdata-unlocker.ts +3 -2
- package/node_modules/pi-web-access/brightdata.ts +4 -3
- package/node_modules/pi-web-access/ceramic.ts +3 -2
- package/node_modules/pi-web-access/curator-page.ts +3 -1
- package/node_modules/pi-web-access/curator-server.ts +1 -0
- package/node_modules/pi-web-access/deepseek.ts +179 -6
- package/node_modules/pi-web-access/dist/index.js +1118 -688
- package/node_modules/pi-web-access/dist/mcp-cli.js +1081 -667
- package/node_modules/pi-web-access/extract.ts +58 -6
- package/node_modules/pi-web-access/gemini-search.ts +29 -6
- package/node_modules/pi-web-access/index.ts +20 -3
- package/node_modules/pi-web-access/jina-search.ts +6 -4
- package/node_modules/pi-web-access/kagi.ts +5 -4
- package/node_modules/pi-web-access/keenable.ts +3 -2
- package/node_modules/pi-web-access/linkup.ts +170 -0
- package/node_modules/pi-web-access/mistral-search.ts +4 -3
- package/node_modules/pi-web-access/ollama.ts +5 -4
- package/node_modules/pi-web-access/package.json +1 -1
- package/node_modules/pi-web-access/parallel.ts +7 -7
- package/node_modules/pi-web-access/perplexity.ts +5 -3
- package/node_modules/pi-web-access/querit.ts +4 -3
- package/node_modules/pi-web-access/search1api.ts +4 -3
- package/node_modules/pi-web-access/searchinfinity.ts +4 -3
- package/node_modules/pi-web-access/serpapi.ts +7 -5
- package/node_modules/pi-web-access/serpbase.ts +5 -4
- package/node_modules/pi-web-access/serpdive.ts +4 -3
- package/node_modules/pi-web-access/serper.ts +6 -4
- package/node_modules/pi-web-access/serply.ts +3 -2
- package/node_modules/pi-web-access/utils.ts +24 -1
- package/node_modules/pi-web-access/valyu.ts +4 -3
- package/node_modules/pi-web-access/web-tool-core.ts +5 -0
- package/node_modules/pi-web-access/xai-search.ts +49 -7
- package/node_modules/pi-web-access/xcrawl.ts +4 -3
- package/node_modules/pi-web-access/you.ts +3 -2
- package/package.json +10 -10
- package/node_modules/pi-lens/dist/chunk-3YN6V5TV.js +0 -85
- package/node_modules/pi-lens/dist/chunk-466Z26MG.js +0 -30
- package/node_modules/pi-lens/dist/chunk-EC47DWFA.js +0 -56
- package/node_modules/pi-lens/dist/chunk-KDERNTCQ.js +0 -28
- package/node_modules/pi-lens/dist/chunk-KSX3TXSZ.js +0 -69
- package/node_modules/pi-lens/dist/chunk-LOP6GRPH.js +0 -31
- package/node_modules/pi-lens/dist/chunk-UOPVJQ4N.js +0 -103
- /package/node_modules/pi-lens/dist/{chunk-FC4RP4I2.js → chunk-6HWVI6MI.js} +0 -0
|
@@ -719,6 +719,24 @@ function buildThinkingLevelMap(entry) {
|
|
|
719
719
|
}
|
|
720
720
|
return void 0;
|
|
721
721
|
}
|
|
722
|
+
function buildThinkingConfig(entry) {
|
|
723
|
+
const tc = entry.thinking_config;
|
|
724
|
+
const efforts = tc?.enabled?.efforts;
|
|
725
|
+
if (!efforts || typeof efforts !== "object") return void 0;
|
|
726
|
+
const supported = new Set(Object.keys(efforts));
|
|
727
|
+
const ordered = PI_THINKING_LEVELS.filter((level) => supported.has(level));
|
|
728
|
+
if (ordered.length === 0) return void 0;
|
|
729
|
+
const defaultLevel = PI_THINKING_LEVELS.find((level) => efforts[level]?.is_default);
|
|
730
|
+
return {
|
|
731
|
+
mode: "effort",
|
|
732
|
+
efforts: ordered,
|
|
733
|
+
...defaultLevel ? { defaultLevel } : {},
|
|
734
|
+
// Qoder's catalog marks a `disabled` branch when thinking can be turned
|
|
735
|
+
// off. Without it reasoning is mandatory upstream, so omp clamps "off" to
|
|
736
|
+
// the lowest supported effort instead of disabling.
|
|
737
|
+
requiresEffort: !tc?.disabled
|
|
738
|
+
};
|
|
739
|
+
}
|
|
722
740
|
function getCachedModels(mode) {
|
|
723
741
|
const data = readParsedModelCache(mode);
|
|
724
742
|
if (data && Array.isArray(data.models)) {
|
|
@@ -730,7 +748,7 @@ function getCachedModels(mode) {
|
|
|
730
748
|
if (staticModel) return { ...model, id: staticModel.id, name: staticModel.name };
|
|
731
749
|
return model.name ? { ...model, id: toQoderModelId(model.name) } : model;
|
|
732
750
|
});
|
|
733
|
-
if (data.configs && typeof data.configs === "object" && !data.configs.auto) {
|
|
751
|
+
if (data.configs && typeof data.configs === "object" && !data.configs.auto && !data.configs.Auto) {
|
|
734
752
|
return models.filter((model) => model.id.toLowerCase() !== "auto");
|
|
735
753
|
}
|
|
736
754
|
return models;
|
|
@@ -830,6 +848,7 @@ async function updateQoderModelsCache(authToken, userID, name, email, mode) {
|
|
|
830
848
|
const isReasoning = !!entry.is_reasoning || !!entry.thinking_config;
|
|
831
849
|
const supportsEffort = !!entry.thinking_config?.enabled?.efforts;
|
|
832
850
|
const thinkingLevelMap = buildThinkingLevelMap(entry);
|
|
851
|
+
const thinking = buildThinkingConfig(entry);
|
|
833
852
|
const modelInfo = { id: toQoderModelId(display), name: display };
|
|
834
853
|
configs[modelInfo.id] = entry;
|
|
835
854
|
newModels.push({
|
|
@@ -841,6 +860,7 @@ async function updateQoderModelsCache(authToken, userID, name, email, mode) {
|
|
|
841
860
|
reasoning: isReasoning,
|
|
842
861
|
supportsEffort,
|
|
843
862
|
thinkingLevelMap,
|
|
863
|
+
thinking,
|
|
844
864
|
input: isVL ? ["text", "image"] : ["text"],
|
|
845
865
|
cost: ZERO_COST,
|
|
846
866
|
contextWindow: ctxLen,
|
|
@@ -9830,6 +9850,148 @@ function transformMessagesForQoder(messages) {
|
|
|
9830
9850
|
}
|
|
9831
9851
|
|
|
9832
9852
|
// src/protocol/stream.ts
|
|
9853
|
+
var MODEL_BUSY_CODE = "10605";
|
|
9854
|
+
var DEFAULT_MODEL_BUSY_RETRIES = 2;
|
|
9855
|
+
var MAX_MODEL_BUSY_RETRIES = 10;
|
|
9856
|
+
var MODEL_BUSY_MAX_WAIT_MS = 5e3;
|
|
9857
|
+
var QoderModelBusyError = class extends Error {
|
|
9858
|
+
constructor(message, retryAfterMs, sawModelOutput = false) {
|
|
9859
|
+
super(message);
|
|
9860
|
+
this.retryAfterMs = retryAfterMs;
|
|
9861
|
+
this.sawModelOutput = sawModelOutput;
|
|
9862
|
+
this.name = "QoderModelBusyError";
|
|
9863
|
+
}
|
|
9864
|
+
retryAfterMs;
|
|
9865
|
+
sawModelOutput;
|
|
9866
|
+
};
|
|
9867
|
+
function parseJsonObject(value, depth = 0) {
|
|
9868
|
+
if (depth > 4) return void 0;
|
|
9869
|
+
if (typeof value === "string") {
|
|
9870
|
+
try {
|
|
9871
|
+
return parseJsonObject(JSON.parse(value), depth + 1);
|
|
9872
|
+
} catch {
|
|
9873
|
+
return void 0;
|
|
9874
|
+
}
|
|
9875
|
+
}
|
|
9876
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
9877
|
+
}
|
|
9878
|
+
function parseModelBusyRejection(body) {
|
|
9879
|
+
const outer = parseJsonObject(body);
|
|
9880
|
+
const busy = parseJsonObject(outer?.message);
|
|
9881
|
+
if (busy?.code !== MODEL_BUSY_CODE) return void 0;
|
|
9882
|
+
const queue = parseJsonObject(busy.message);
|
|
9883
|
+
if (!queue) return void 0;
|
|
9884
|
+
if (queue.isQueued !== false || queue.serviceAvailable !== true) return void 0;
|
|
9885
|
+
const seconds = queue.retryAfterSeconds;
|
|
9886
|
+
const retryAfterMs = typeof seconds === "number" && Number.isFinite(seconds) && seconds > 0 ? Math.round(seconds * 1e3) : 0;
|
|
9887
|
+
return { retryAfterMs };
|
|
9888
|
+
}
|
|
9889
|
+
function sleepWithAbort(ms, signal) {
|
|
9890
|
+
if (signal?.aborted) return Promise.reject(new Error("Aborted"));
|
|
9891
|
+
if (ms <= 0) return Promise.resolve();
|
|
9892
|
+
return new Promise((resolve2, reject) => {
|
|
9893
|
+
if (signal?.aborted) {
|
|
9894
|
+
reject(new Error("Aborted"));
|
|
9895
|
+
return;
|
|
9896
|
+
}
|
|
9897
|
+
const onAbort = () => {
|
|
9898
|
+
clearTimeout(timer);
|
|
9899
|
+
reject(new Error("Aborted"));
|
|
9900
|
+
};
|
|
9901
|
+
const timer = setTimeout(() => {
|
|
9902
|
+
signal?.removeEventListener("abort", onAbort);
|
|
9903
|
+
resolve2();
|
|
9904
|
+
}, ms);
|
|
9905
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
9906
|
+
});
|
|
9907
|
+
}
|
|
9908
|
+
function refreshToolIndexes(output, toolCalls) {
|
|
9909
|
+
const lastToolState = toolCalls.lastToolState;
|
|
9910
|
+
if (!lastToolState || output.content[lastToolState.contentIndex] === lastToolState.block) return;
|
|
9911
|
+
for (let index = 0; index < output.content.length; index++) {
|
|
9912
|
+
const block = output.content[index];
|
|
9913
|
+
if (block.type !== "toolCall") continue;
|
|
9914
|
+
const state = toolCalls.statesByBlock.get(block);
|
|
9915
|
+
if (state) state.contentIndex = index;
|
|
9916
|
+
}
|
|
9917
|
+
}
|
|
9918
|
+
function retireCompleteCandidates(toolCalls, candidates) {
|
|
9919
|
+
for (const state of candidates.complete) {
|
|
9920
|
+
parseToolArguments(state);
|
|
9921
|
+
candidates.states.delete(state);
|
|
9922
|
+
state.candidates.delete(candidates);
|
|
9923
|
+
if (state.candidates.size === 0 && !state.unindexed) toolCalls.unscopedCandidates.delete(state);
|
|
9924
|
+
}
|
|
9925
|
+
candidates.complete.clear();
|
|
9926
|
+
candidates.unique = candidates.states.size === 1 ? candidates.states.values().next().value : void 0;
|
|
9927
|
+
}
|
|
9928
|
+
var TOOL_ARGUMENT_STRUCTURE = /["\\{}[\]]/g;
|
|
9929
|
+
var NON_JSON_WHITESPACE = /[^ \t\r\n]/;
|
|
9930
|
+
function invalidToolArguments(state) {
|
|
9931
|
+
return new Error(`Invalid or incomplete tool-call JSON (characters=${state.argumentLength})`);
|
|
9932
|
+
}
|
|
9933
|
+
function appendToolArguments(state, fragment) {
|
|
9934
|
+
state.argumentChunks.push(fragment);
|
|
9935
|
+
state.argumentLength += fragment.length;
|
|
9936
|
+
if (state.complete) {
|
|
9937
|
+
if (NON_JSON_WHITESPACE.test(fragment)) throw invalidToolArguments(state);
|
|
9938
|
+
return;
|
|
9939
|
+
}
|
|
9940
|
+
let start = 0;
|
|
9941
|
+
if (state.objectRoot === void 0) {
|
|
9942
|
+
start = fragment.search(NON_JSON_WHITESPACE);
|
|
9943
|
+
if (start === -1) return;
|
|
9944
|
+
state.objectRoot = fragment[start] === "{";
|
|
9945
|
+
}
|
|
9946
|
+
if (!state.objectRoot) return;
|
|
9947
|
+
if (state.escaped) {
|
|
9948
|
+
start = 1;
|
|
9949
|
+
state.escaped = false;
|
|
9950
|
+
}
|
|
9951
|
+
TOOL_ARGUMENT_STRUCTURE.lastIndex = start;
|
|
9952
|
+
while (true) {
|
|
9953
|
+
const match = TOOL_ARGUMENT_STRUCTURE.exec(fragment);
|
|
9954
|
+
if (!match) break;
|
|
9955
|
+
const character = match[0];
|
|
9956
|
+
if (state.inString) {
|
|
9957
|
+
if (character === "\\") {
|
|
9958
|
+
if (TOOL_ARGUMENT_STRUCTURE.lastIndex === fragment.length) state.escaped = true;
|
|
9959
|
+
else TOOL_ARGUMENT_STRUCTURE.lastIndex++;
|
|
9960
|
+
} else if (character === '"') {
|
|
9961
|
+
state.inString = false;
|
|
9962
|
+
}
|
|
9963
|
+
} else if (character === '"') {
|
|
9964
|
+
state.inString = true;
|
|
9965
|
+
} else if (character === "{" || character === "[") {
|
|
9966
|
+
state.depth++;
|
|
9967
|
+
} else if (character === "}" || character === "]") {
|
|
9968
|
+
state.depth--;
|
|
9969
|
+
if (state.depth === 0) {
|
|
9970
|
+
state.complete = true;
|
|
9971
|
+
if (NON_JSON_WHITESPACE.test(fragment.slice(TOOL_ARGUMENT_STRUCTURE.lastIndex))) {
|
|
9972
|
+
throw invalidToolArguments(state);
|
|
9973
|
+
}
|
|
9974
|
+
return;
|
|
9975
|
+
}
|
|
9976
|
+
}
|
|
9977
|
+
}
|
|
9978
|
+
}
|
|
9979
|
+
function parseToolArguments(state) {
|
|
9980
|
+
if (state.parsedArguments) return state.parsedArguments;
|
|
9981
|
+
let args = {};
|
|
9982
|
+
if (state.argumentLength > 0) {
|
|
9983
|
+
try {
|
|
9984
|
+
args = JSON.parse(state.argumentChunks.join(""));
|
|
9985
|
+
} catch {
|
|
9986
|
+
throw invalidToolArguments(state);
|
|
9987
|
+
}
|
|
9988
|
+
}
|
|
9989
|
+
if (args === null || typeof args !== "object" || Array.isArray(args)) {
|
|
9990
|
+
throw new Error(`Non-object tool-call arguments (characters=${state.argumentLength})`);
|
|
9991
|
+
}
|
|
9992
|
+
state.parsedArguments = args;
|
|
9993
|
+
return state.parsedArguments;
|
|
9994
|
+
}
|
|
9833
9995
|
function stableHash(prefix, ...inputs) {
|
|
9834
9996
|
const hash = crypto3.createHash("sha256");
|
|
9835
9997
|
hash.update(prefix);
|
|
@@ -9892,10 +10054,15 @@ function resolveRequestContext(piAi, context) {
|
|
|
9892
10054
|
const collapsed = collapseSystemMessages(context);
|
|
9893
10055
|
const transcriptMessages = collapsed.messages;
|
|
9894
10056
|
const initialSystem = getInitialSystemMessage(transcriptMessages);
|
|
10057
|
+
if (!initialSystem) {
|
|
10058
|
+
return {
|
|
10059
|
+
messages: context.messages,
|
|
10060
|
+
systemText: contentToText(context.systemPrompt || ""),
|
|
10061
|
+
tools: context.tools ?? []
|
|
10062
|
+
};
|
|
10063
|
+
}
|
|
9895
10064
|
const tools = getCurrentTools(transcriptMessages);
|
|
9896
|
-
const systemText = contentToText(
|
|
9897
|
-
initialSystem && getSystemMessageText ? getSystemMessageText(initialSystem) : context.systemPrompt || ""
|
|
9898
|
-
);
|
|
10065
|
+
const systemText = contentToText(getSystemMessageText?.(initialSystem) ?? context.systemPrompt ?? "");
|
|
9899
10066
|
const messages = withoutInitialSystemMessage(transcriptMessages);
|
|
9900
10067
|
return { messages, systemText, tools };
|
|
9901
10068
|
}
|
|
@@ -9960,7 +10127,9 @@ function streamQoder(model, context, options) {
|
|
|
9960
10127
|
const toolsRaw = resolved.tools.length > 0 ? transformTools(resolved.tools) : void 0;
|
|
9961
10128
|
const recordID = stableChatRecordID(qoderModel, normalizedMessages, toolsRaw, maxTokens);
|
|
9962
10129
|
const requestedLevel = options?.reasoning;
|
|
9963
|
-
const
|
|
10130
|
+
const extOptions = options;
|
|
10131
|
+
const explicitlyOff = extOptions?.disableReasoning === true || extOptions?.forceReasoningOff === true || requestedLevel === false || requestedLevel === "off";
|
|
10132
|
+
const clamped = !explicitlyOff && requestedLevel ? clampThinkingLevel(model, requestedLevel) : void 0;
|
|
9964
10133
|
const reasoningLevel = clamped === "off" ? void 0 : clamped;
|
|
9965
10134
|
const parameters = { max_tokens: maxTokens };
|
|
9966
10135
|
if (reasoningLevel) {
|
|
@@ -9972,6 +10141,11 @@ function streamQoder(model, context, options) {
|
|
|
9972
10141
|
}
|
|
9973
10142
|
} else {
|
|
9974
10143
|
parameters.enable_thinking = false;
|
|
10144
|
+
const tc = modelConfig?.thinking_config;
|
|
10145
|
+
const lacksDisabledBranch = tc?.enabled?.efforts && !tc.disabled || model.thinkingLevelMap?.off === null;
|
|
10146
|
+
if (!lacksDisabledBranch) {
|
|
10147
|
+
parameters.reasoning_effort = "none";
|
|
10148
|
+
}
|
|
9975
10149
|
}
|
|
9976
10150
|
const reqBody = {
|
|
9977
10151
|
request_id: crypto3.randomUUID(),
|
|
@@ -10005,14 +10179,14 @@ function streamQoder(model, context, options) {
|
|
|
10005
10179
|
context: [],
|
|
10006
10180
|
modelConfig: {
|
|
10007
10181
|
key: qoderModel,
|
|
10008
|
-
is_reasoning: isReasoning
|
|
10182
|
+
is_reasoning: reasoningLevel ? isReasoning : false
|
|
10009
10183
|
},
|
|
10010
10184
|
originalContent: lastUserText
|
|
10011
10185
|
},
|
|
10012
10186
|
features: [],
|
|
10013
10187
|
text: lastUserText
|
|
10014
10188
|
},
|
|
10015
|
-
model_config: modelConfig,
|
|
10189
|
+
model_config: reasoningLevel ? modelConfig : { ...modelConfig, is_reasoning: false },
|
|
10016
10190
|
business: {
|
|
10017
10191
|
product: "cli",
|
|
10018
10192
|
version: "1.0.0",
|
|
@@ -10023,251 +10197,401 @@ function streamQoder(model, context, options) {
|
|
|
10023
10197
|
begin_at: Date.now()
|
|
10024
10198
|
}
|
|
10025
10199
|
};
|
|
10026
|
-
const bodyBytes = Buffer.from(JSON.stringify(reqBody));
|
|
10027
|
-
const encodedBytes = qoderEncodeBody(bodyBytes);
|
|
10028
10200
|
const chatURL = getQoderChatURL(providerMode);
|
|
10029
|
-
const
|
|
10201
|
+
const modelSource = modelConfig.source || "system";
|
|
10202
|
+
const requestedRetries = options?.maxRetries;
|
|
10203
|
+
const modelBusyRetries = Math.min(
|
|
10204
|
+
Math.max(
|
|
10205
|
+
0,
|
|
10206
|
+
typeof requestedRetries === "number" && Number.isFinite(requestedRetries) ? Math.floor(requestedRetries) : DEFAULT_MODEL_BUSY_RETRIES
|
|
10207
|
+
),
|
|
10208
|
+
MAX_MODEL_BUSY_RETRIES
|
|
10209
|
+
);
|
|
10210
|
+
const requestedMaxWaitMs = options?.maxRetryDelayMs;
|
|
10211
|
+
const modelBusyMaxWaitMs = typeof requestedMaxWaitMs === "number" && Number.isFinite(requestedMaxWaitMs) && requestedMaxWaitMs > 0 ? Math.min(MODEL_BUSY_MAX_WAIT_MS, requestedMaxWaitMs) : MODEL_BUSY_MAX_WAIT_MS;
|
|
10212
|
+
let encodedBytes = qoderEncodeBody(Buffer.from(JSON.stringify(reqBody)));
|
|
10213
|
+
let headers = buildAuthHeaders(encodedBytes, chatURL, {
|
|
10030
10214
|
userID,
|
|
10031
10215
|
authToken: accessToken,
|
|
10032
10216
|
name,
|
|
10033
10217
|
email,
|
|
10034
10218
|
machineID
|
|
10035
10219
|
});
|
|
10036
|
-
const modelSource = modelConfig.source || "system";
|
|
10037
|
-
const response = await fetch(chatURL, {
|
|
10038
|
-
method: "POST",
|
|
10039
|
-
headers: {
|
|
10040
|
-
"Content-Type": "application/json",
|
|
10041
|
-
Accept: "text/event-stream",
|
|
10042
|
-
"Cache-Control": "no-cache",
|
|
10043
|
-
"Accept-Encoding": "identity",
|
|
10044
|
-
"X-Model-Key": qoderModel,
|
|
10045
|
-
"X-Model-Source": modelSource,
|
|
10046
|
-
...headers
|
|
10047
|
-
},
|
|
10048
|
-
body: encodedBytes,
|
|
10049
|
-
signal: options?.signal
|
|
10050
|
-
});
|
|
10051
|
-
if (!response.ok) {
|
|
10052
|
-
const errText = await response.text();
|
|
10053
|
-
throw new Error(`Qoder API request failed: ${response.status} ${response.statusText}. Response: ${errText}`);
|
|
10054
|
-
}
|
|
10055
|
-
const reader = response.body?.getReader();
|
|
10056
|
-
if (!reader) throw new Error("No response body");
|
|
10057
|
-
const decoder = new TextDecoder();
|
|
10058
|
-
let buffer = "";
|
|
10059
|
-
let bufferStart = 0;
|
|
10060
|
-
let contentBlockIndex = -1;
|
|
10061
|
-
let thinkingBlockIndex = -1;
|
|
10062
|
-
let rawReasoningTail = "";
|
|
10063
|
-
const toolCallsState = [];
|
|
10064
10220
|
const thinkingEnabled = options?.reasoning !== false && options?.reasoning !== "off";
|
|
10065
|
-
const thinkingParser = thinkingEnabled ? new ThinkingTagParser(output, stream) : null;
|
|
10066
10221
|
stream.push({ type: "start", partial: output });
|
|
10067
|
-
|
|
10068
|
-
|
|
10069
|
-
|
|
10070
|
-
|
|
10071
|
-
|
|
10072
|
-
|
|
10073
|
-
|
|
10222
|
+
const runAttempt = async () => {
|
|
10223
|
+
options?.signal?.throwIfAborted();
|
|
10224
|
+
output.stopReason = "stop";
|
|
10225
|
+
output.errorMessage = void 0;
|
|
10226
|
+
output.responseId = void 0;
|
|
10227
|
+
output.responseModel = void 0;
|
|
10228
|
+
output.usage = {
|
|
10229
|
+
input: 0,
|
|
10230
|
+
output: 0,
|
|
10231
|
+
cacheRead: 0,
|
|
10232
|
+
cacheWrite: 0,
|
|
10233
|
+
totalTokens: 0,
|
|
10234
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
10235
|
+
};
|
|
10236
|
+
const response = await fetch(chatURL, {
|
|
10237
|
+
method: "POST",
|
|
10238
|
+
headers: {
|
|
10239
|
+
"Content-Type": "application/json",
|
|
10240
|
+
Accept: "text/event-stream",
|
|
10241
|
+
"Cache-Control": "no-cache",
|
|
10242
|
+
"Accept-Encoding": "identity",
|
|
10243
|
+
"X-Model-Key": qoderModel,
|
|
10244
|
+
"X-Model-Source": modelSource,
|
|
10245
|
+
...headers
|
|
10246
|
+
},
|
|
10247
|
+
body: encodedBytes,
|
|
10248
|
+
signal: options?.signal
|
|
10249
|
+
});
|
|
10250
|
+
if (!response.ok) {
|
|
10251
|
+
const errText = await response.text();
|
|
10252
|
+
throw new Error(`Qoder API request failed: ${response.status} ${response.statusText}. Response: ${errText}`);
|
|
10074
10253
|
}
|
|
10075
|
-
|
|
10076
|
-
|
|
10077
|
-
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
sawDone = true;
|
|
10095
|
-
break;
|
|
10096
|
-
}
|
|
10097
|
-
if (!innerStr) continue;
|
|
10098
|
-
const inner = JSON.parse(innerStr);
|
|
10099
|
-
if (inner.id) output.responseId = inner.id;
|
|
10100
|
-
if (inner.model) output.responseModel = inner.model;
|
|
10101
|
-
if (inner.usage) {
|
|
10102
|
-
applyQoderCredits(output.usage, inner.usage, model.provider === "qoder-cn" ? "qoder-cn" : "qoder");
|
|
10103
|
-
const u = inner.usage;
|
|
10104
|
-
const promptTokens = u.prompt_tokens ?? 0;
|
|
10105
|
-
const cacheReadTokens = u.prompt_tokens_details?.cached_tokens ?? 0;
|
|
10106
|
-
const cacheWriteTokens = u.prompt_tokens_details?.cache_write_tokens ?? 0;
|
|
10107
|
-
output.usage.input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
|
|
10108
|
-
output.usage.output = u.completion_tokens ?? 0;
|
|
10109
|
-
output.usage.totalTokens = u.total_tokens ?? 0;
|
|
10110
|
-
output.usage.cacheRead = cacheReadTokens;
|
|
10111
|
-
output.usage.cacheWrite = cacheWriteTokens;
|
|
10254
|
+
const reader = response.body?.getReader();
|
|
10255
|
+
if (!reader) throw new Error("No response body");
|
|
10256
|
+
const decoder = new TextDecoder();
|
|
10257
|
+
let buffer = "";
|
|
10258
|
+
let bufferStart = 0;
|
|
10259
|
+
let contentBlockIndex = -1;
|
|
10260
|
+
let thinkingBlockIndex = -1;
|
|
10261
|
+
let rawReasoningTail = "";
|
|
10262
|
+
let toolCalls;
|
|
10263
|
+
const thinkingParser = thinkingEnabled ? new ThinkingTagParser(output, stream) : null;
|
|
10264
|
+
let sawModelOutput = false;
|
|
10265
|
+
let sawDone = false;
|
|
10266
|
+
try {
|
|
10267
|
+
while (!sawDone) {
|
|
10268
|
+
const { done, value } = await reader.read();
|
|
10269
|
+
if (done) break;
|
|
10270
|
+
if (bufferStart > 0) {
|
|
10271
|
+
buffer = buffer.substring(bufferStart);
|
|
10272
|
+
bufferStart = 0;
|
|
10112
10273
|
}
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
const
|
|
10116
|
-
if (
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
|
|
10274
|
+
buffer += decoder.decode(value, { stream: true });
|
|
10275
|
+
while (true) {
|
|
10276
|
+
const lineEnd = buffer.indexOf("\n", bufferStart);
|
|
10277
|
+
if (lineEnd === -1) break;
|
|
10278
|
+
const line = buffer.substring(bufferStart, lineEnd).trim();
|
|
10279
|
+
bufferStart = lineEnd + 1;
|
|
10280
|
+
if (!line.startsWith("data:")) continue;
|
|
10281
|
+
const dataStr = line.substring(5).trim();
|
|
10282
|
+
if (dataStr === "[DONE]") {
|
|
10283
|
+
sawDone = true;
|
|
10284
|
+
break;
|
|
10285
|
+
}
|
|
10286
|
+
try {
|
|
10287
|
+
const envelope = JSON.parse(dataStr);
|
|
10288
|
+
if (envelope.statusCodeValue && envelope.statusCodeValue !== 200) {
|
|
10289
|
+
const busy = parseModelBusyRejection(envelope.body);
|
|
10290
|
+
if (busy) {
|
|
10291
|
+
throw new QoderModelBusyError(
|
|
10292
|
+
`Upstream status ${envelope.statusCodeValue}: ${envelope.body}`,
|
|
10293
|
+
busy.retryAfterMs,
|
|
10294
|
+
sawModelOutput
|
|
10295
|
+
);
|
|
10134
10296
|
}
|
|
10297
|
+
throw new Error(`Upstream status ${envelope.statusCodeValue}: ${envelope.body}`);
|
|
10135
10298
|
}
|
|
10136
|
-
|
|
10137
|
-
|
|
10138
|
-
|
|
10139
|
-
|
|
10140
|
-
type: "thinking_end",
|
|
10141
|
-
contentIndex: thinkingBlockIndex,
|
|
10142
|
-
content: block.thinking,
|
|
10143
|
-
partial: output
|
|
10144
|
-
});
|
|
10145
|
-
thinkingBlockIndex = -1;
|
|
10146
|
-
}
|
|
10147
|
-
if (thinkingParser) {
|
|
10148
|
-
thinkingParser.processChunk(delta.content);
|
|
10149
|
-
} else {
|
|
10150
|
-
if (contentBlockIndex === -1) {
|
|
10151
|
-
contentBlockIndex = output.content.length;
|
|
10152
|
-
output.content.push({ type: "text", text: "" });
|
|
10153
|
-
stream.push({ type: "text_start", contentIndex: contentBlockIndex, partial: output });
|
|
10154
|
-
}
|
|
10155
|
-
const block = output.content[contentBlockIndex];
|
|
10156
|
-
block.text += delta.content;
|
|
10157
|
-
stream.push({
|
|
10158
|
-
type: "text_delta",
|
|
10159
|
-
contentIndex: contentBlockIndex,
|
|
10160
|
-
delta: delta.content,
|
|
10161
|
-
partial: output
|
|
10162
|
-
});
|
|
10163
|
-
}
|
|
10299
|
+
const innerStr = envelope.body;
|
|
10300
|
+
if (innerStr === "[DONE]") {
|
|
10301
|
+
sawDone = true;
|
|
10302
|
+
break;
|
|
10164
10303
|
}
|
|
10165
|
-
if (
|
|
10166
|
-
|
|
10167
|
-
|
|
10168
|
-
|
|
10169
|
-
|
|
10304
|
+
if (!innerStr) continue;
|
|
10305
|
+
const inner = JSON.parse(innerStr);
|
|
10306
|
+
if (inner.id) output.responseId = inner.id;
|
|
10307
|
+
if (inner.model) output.responseModel = inner.model;
|
|
10308
|
+
if (inner.usage) {
|
|
10309
|
+
applyQoderCredits(output.usage, inner.usage, model.provider === "qoder-cn" ? "qoder-cn" : "qoder");
|
|
10310
|
+
const u = inner.usage;
|
|
10311
|
+
const promptTokens = u.prompt_tokens ?? 0;
|
|
10312
|
+
const cacheReadTokens = u.prompt_tokens_details?.cached_tokens ?? 0;
|
|
10313
|
+
const cacheWriteTokens = u.prompt_tokens_details?.cache_write_tokens ?? 0;
|
|
10314
|
+
output.usage.input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
|
|
10315
|
+
output.usage.output = u.completion_tokens ?? 0;
|
|
10316
|
+
output.usage.totalTokens = u.total_tokens ?? 0;
|
|
10317
|
+
output.usage.cacheRead = cacheReadTokens;
|
|
10318
|
+
output.usage.cacheWrite = cacheWriteTokens;
|
|
10319
|
+
}
|
|
10320
|
+
if (inner.choices && inner.choices.length > 0) {
|
|
10321
|
+
const choice = inner.choices[0];
|
|
10322
|
+
const delta = choice.delta;
|
|
10323
|
+
if (delta) {
|
|
10324
|
+
if (delta.reasoning_content || delta.content || Array.isArray(delta.tool_calls) && delta.tool_calls.length > 0) {
|
|
10325
|
+
sawModelOutput = true;
|
|
10170
10326
|
}
|
|
10171
|
-
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
|
|
10175
|
-
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10183
|
-
|
|
10327
|
+
if (delta.reasoning_content) {
|
|
10328
|
+
rawReasoningTail = (rawReasoningTail + delta.reasoning_content).slice(-512);
|
|
10329
|
+
const reasoningChunk = stripDsmlResidue(stripThinkingTags(delta.reasoning_content));
|
|
10330
|
+
if (reasoningChunk) {
|
|
10331
|
+
if (thinkingBlockIndex === -1) {
|
|
10332
|
+
thinkingBlockIndex = output.content.length;
|
|
10333
|
+
output.content.push({ type: "thinking", thinking: "" });
|
|
10334
|
+
stream.push({ type: "thinking_start", contentIndex: thinkingBlockIndex, partial: output });
|
|
10335
|
+
}
|
|
10336
|
+
const block = output.content[thinkingBlockIndex];
|
|
10337
|
+
block.thinking += reasoningChunk;
|
|
10338
|
+
stream.push({
|
|
10339
|
+
type: "thinking_delta",
|
|
10340
|
+
contentIndex: thinkingBlockIndex,
|
|
10341
|
+
delta: reasoningChunk,
|
|
10342
|
+
partial: output
|
|
10343
|
+
});
|
|
10344
|
+
}
|
|
10184
10345
|
}
|
|
10185
|
-
if (
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10346
|
+
if (delta.content) {
|
|
10347
|
+
if (thinkingBlockIndex !== -1) {
|
|
10348
|
+
const block = output.content[thinkingBlockIndex];
|
|
10349
|
+
stream.push({
|
|
10350
|
+
type: "thinking_end",
|
|
10351
|
+
contentIndex: thinkingBlockIndex,
|
|
10352
|
+
content: block.thinking,
|
|
10353
|
+
partial: output
|
|
10354
|
+
});
|
|
10355
|
+
thinkingBlockIndex = -1;
|
|
10356
|
+
}
|
|
10357
|
+
if (thinkingParser) {
|
|
10358
|
+
thinkingParser.processChunk(delta.content);
|
|
10359
|
+
if (toolCalls?.lastToolState) refreshToolIndexes(output, toolCalls);
|
|
10360
|
+
} else {
|
|
10361
|
+
if (contentBlockIndex === -1) {
|
|
10362
|
+
contentBlockIndex = output.content.length;
|
|
10363
|
+
output.content.push({ type: "text", text: "" });
|
|
10364
|
+
stream.push({ type: "text_start", contentIndex: contentBlockIndex, partial: output });
|
|
10365
|
+
}
|
|
10366
|
+
const block = output.content[contentBlockIndex];
|
|
10367
|
+
block.text += delta.content;
|
|
10368
|
+
stream.push({
|
|
10369
|
+
type: "text_delta",
|
|
10370
|
+
contentIndex: contentBlockIndex,
|
|
10371
|
+
delta: delta.content,
|
|
10372
|
+
partial: output
|
|
10373
|
+
});
|
|
10374
|
+
}
|
|
10189
10375
|
}
|
|
10190
|
-
if (
|
|
10191
|
-
const
|
|
10192
|
-
|
|
10193
|
-
|
|
10194
|
-
|
|
10195
|
-
|
|
10196
|
-
|
|
10197
|
-
|
|
10198
|
-
|
|
10376
|
+
if (delta.tool_calls && Array.isArray(delta.tool_calls)) {
|
|
10377
|
+
for (const tc of delta.tool_calls) {
|
|
10378
|
+
const id = tc.id || "";
|
|
10379
|
+
const name2 = tc.function?.name || "";
|
|
10380
|
+
const argDelta = tc.function?.arguments ?? "";
|
|
10381
|
+
if (typeof id !== "string" || typeof name2 !== "string") {
|
|
10382
|
+
throw new Error("Tool-call identity conflict: invalid metadata");
|
|
10383
|
+
}
|
|
10384
|
+
if (typeof argDelta !== "string") throw new Error("Invalid tool-call argument fragment");
|
|
10385
|
+
if (!id && !name2 && !argDelta) continue;
|
|
10386
|
+
toolCalls ??= {
|
|
10387
|
+
states: [],
|
|
10388
|
+
byId: /* @__PURE__ */ new Map(),
|
|
10389
|
+
byIndex: /* @__PURE__ */ new Map(),
|
|
10390
|
+
unscopedCandidates: /* @__PURE__ */ new Set(),
|
|
10391
|
+
statesByBlock: /* @__PURE__ */ new Map()
|
|
10392
|
+
};
|
|
10393
|
+
const index = typeof tc.index === "number" ? tc.index : void 0;
|
|
10394
|
+
let candidates;
|
|
10395
|
+
if (index !== void 0) {
|
|
10396
|
+
candidates = toolCalls.byIndex.get(index);
|
|
10397
|
+
if (!candidates) {
|
|
10398
|
+
candidates = { states: /* @__PURE__ */ new Set(), complete: /* @__PURE__ */ new Set(), unique: void 0 };
|
|
10399
|
+
toolCalls.byIndex.set(index, candidates);
|
|
10400
|
+
}
|
|
10401
|
+
}
|
|
10402
|
+
let state = id ? toolCalls.byId.get(id) : void 0;
|
|
10403
|
+
let associated = !!state && !!candidates && candidates.states.has(state);
|
|
10404
|
+
if (id && candidates && !associated && candidates.complete.size > 0) {
|
|
10405
|
+
retireCompleteCandidates(toolCalls, candidates);
|
|
10406
|
+
}
|
|
10407
|
+
const available = candidates?.states ?? toolCalls.unscopedCandidates;
|
|
10408
|
+
if (!state) {
|
|
10409
|
+
const only = available.size === 1 ? candidates ? candidates.unique : available.values().next().value : void 0;
|
|
10410
|
+
if (!id && available.size > 1) {
|
|
10411
|
+
throw new Error(`Ambiguous tool-call continuation (candidates=${available.size})`);
|
|
10412
|
+
}
|
|
10413
|
+
if (only && (!id || !only.id)) {
|
|
10414
|
+
state = only;
|
|
10415
|
+
associated = candidates !== void 0;
|
|
10416
|
+
} else {
|
|
10417
|
+
state = {
|
|
10418
|
+
argumentChunks: [],
|
|
10419
|
+
argumentLength: 0,
|
|
10420
|
+
depth: 0,
|
|
10421
|
+
inString: false,
|
|
10422
|
+
escaped: false,
|
|
10423
|
+
complete: false,
|
|
10424
|
+
id: "",
|
|
10425
|
+
name: "",
|
|
10426
|
+
contentIndex: -1,
|
|
10427
|
+
candidates: /* @__PURE__ */ new Set(),
|
|
10428
|
+
unindexed: index === void 0
|
|
10429
|
+
};
|
|
10430
|
+
toolCalls.states.push(state);
|
|
10431
|
+
}
|
|
10432
|
+
}
|
|
10433
|
+
if (name2 && state.name && name2 !== state.name) {
|
|
10434
|
+
throw new Error("Tool-call identity conflict: inconsistent name");
|
|
10435
|
+
}
|
|
10436
|
+
const newlyIdentified = !!id && !state.id;
|
|
10437
|
+
const newlyNamed = !!name2 && !state.name;
|
|
10438
|
+
if (newlyIdentified) {
|
|
10439
|
+
state.id = id;
|
|
10440
|
+
toolCalls.byId.set(id, state);
|
|
10441
|
+
}
|
|
10442
|
+
if (newlyNamed) state.name = name2;
|
|
10443
|
+
if (!associated) {
|
|
10444
|
+
toolCalls.unscopedCandidates.add(state);
|
|
10445
|
+
if (candidates) {
|
|
10446
|
+
state.unindexed = false;
|
|
10447
|
+
state.candidates.add(candidates);
|
|
10448
|
+
candidates.states.add(state);
|
|
10449
|
+
candidates.unique = candidates.states.size === 1 ? state : void 0;
|
|
10450
|
+
if (state.complete && state.id) candidates.complete.add(state);
|
|
10451
|
+
}
|
|
10452
|
+
}
|
|
10453
|
+
const wasComplete = state.complete;
|
|
10454
|
+
if (argDelta) appendToolArguments(state, argDelta);
|
|
10455
|
+
if (state.complete && state.id && (!wasComplete || newlyIdentified)) {
|
|
10456
|
+
for (const scope of state.candidates) scope.complete.add(state);
|
|
10457
|
+
}
|
|
10458
|
+
if (!state.block && (state.id || state.name)) {
|
|
10459
|
+
state.block = { type: "toolCall", id: state.id, name: state.name, arguments: {} };
|
|
10460
|
+
state.contentIndex = output.content.length;
|
|
10461
|
+
output.content.push(state.block);
|
|
10462
|
+
toolCalls.statesByBlock.set(state.block, state);
|
|
10463
|
+
toolCalls.lastToolState = state;
|
|
10464
|
+
stream.push({ type: "toolcall_start", contentIndex: state.contentIndex, partial: output });
|
|
10465
|
+
for (const fragment of state.argumentChunks) {
|
|
10466
|
+
stream.push({
|
|
10467
|
+
type: "toolcall_delta",
|
|
10468
|
+
contentIndex: state.contentIndex,
|
|
10469
|
+
delta: fragment,
|
|
10470
|
+
partial: output
|
|
10471
|
+
});
|
|
10472
|
+
}
|
|
10473
|
+
} else if (state.block) {
|
|
10474
|
+
if (newlyIdentified) state.block.id = state.id;
|
|
10475
|
+
if (newlyNamed) state.block.name = state.name;
|
|
10476
|
+
if (argDelta) {
|
|
10477
|
+
stream.push({
|
|
10478
|
+
type: "toolcall_delta",
|
|
10479
|
+
contentIndex: state.contentIndex,
|
|
10480
|
+
delta: argDelta,
|
|
10481
|
+
partial: output
|
|
10482
|
+
});
|
|
10483
|
+
}
|
|
10484
|
+
}
|
|
10485
|
+
}
|
|
10199
10486
|
}
|
|
10200
10487
|
}
|
|
10488
|
+
if (choice.finish_reason) {
|
|
10489
|
+
output.stopReason = choice.finish_reason;
|
|
10490
|
+
}
|
|
10201
10491
|
}
|
|
10492
|
+
} catch (e) {
|
|
10493
|
+
if (e instanceof SyntaxError) {
|
|
10494
|
+
if (process.env.QODER_DEBUG) {
|
|
10495
|
+
console.error("[pi-provider-qoder] skipping malformed SSE line:", dataStr.slice(0, 200));
|
|
10496
|
+
}
|
|
10497
|
+
continue;
|
|
10498
|
+
}
|
|
10499
|
+
throw e;
|
|
10202
10500
|
}
|
|
10203
|
-
if (choice.finish_reason) {
|
|
10204
|
-
output.stopReason = choice.finish_reason;
|
|
10205
|
-
}
|
|
10206
|
-
}
|
|
10207
|
-
} catch (e) {
|
|
10208
|
-
if (e instanceof SyntaxError) {
|
|
10209
|
-
if (process.env.QODER_DEBUG) {
|
|
10210
|
-
console.error("[pi-provider-qoder] skipping malformed SSE line:", dataStr.slice(0, 200));
|
|
10211
|
-
}
|
|
10212
|
-
continue;
|
|
10213
10501
|
}
|
|
10214
|
-
throw e;
|
|
10215
10502
|
}
|
|
10216
|
-
}
|
|
10217
|
-
}
|
|
10218
|
-
await reader.cancel().catch(() => {
|
|
10219
|
-
});
|
|
10220
|
-
if (thinkingParser) {
|
|
10221
|
-
thinkingParser.finalize();
|
|
10222
|
-
}
|
|
10223
|
-
if (thinkingBlockIndex !== -1) {
|
|
10224
|
-
const block = output.content[thinkingBlockIndex];
|
|
10225
|
-
stream.push({
|
|
10226
|
-
type: "thinking_end",
|
|
10227
|
-
contentIndex: thinkingBlockIndex,
|
|
10228
|
-
content: block.thinking,
|
|
10229
|
-
partial: output
|
|
10230
|
-
});
|
|
10231
|
-
}
|
|
10232
|
-
for (const state of toolCallsState) {
|
|
10233
|
-
if (state?.emittedStart && !state.emittedEnd) {
|
|
10234
|
-
state.emittedEnd = true;
|
|
10235
|
-
let args = {};
|
|
10503
|
+
} finally {
|
|
10236
10504
|
try {
|
|
10237
|
-
|
|
10238
|
-
|
|
10505
|
+
await reader.cancel().catch(() => {
|
|
10506
|
+
});
|
|
10507
|
+
} finally {
|
|
10508
|
+
reader.releaseLock();
|
|
10239
10509
|
}
|
|
10240
|
-
|
|
10241
|
-
|
|
10510
|
+
}
|
|
10511
|
+
if (thinkingParser) {
|
|
10512
|
+
thinkingParser.finalize();
|
|
10513
|
+
if (toolCalls?.lastToolState) refreshToolIndexes(output, toolCalls);
|
|
10514
|
+
}
|
|
10515
|
+
if (thinkingBlockIndex !== -1) {
|
|
10516
|
+
const block = output.content[thinkingBlockIndex];
|
|
10242
10517
|
stream.push({
|
|
10243
|
-
type: "
|
|
10244
|
-
contentIndex:
|
|
10245
|
-
|
|
10246
|
-
type: "toolCall",
|
|
10247
|
-
id: state.id,
|
|
10248
|
-
name: state.name,
|
|
10249
|
-
arguments: args
|
|
10250
|
-
},
|
|
10518
|
+
type: "thinking_end",
|
|
10519
|
+
contentIndex: thinkingBlockIndex,
|
|
10520
|
+
content: block.thinking,
|
|
10251
10521
|
partial: output
|
|
10252
10522
|
});
|
|
10253
10523
|
}
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
|
|
10257
|
-
|
|
10258
|
-
|
|
10259
|
-
|
|
10260
|
-
|
|
10261
|
-
|
|
10524
|
+
if (toolCalls) {
|
|
10525
|
+
for (const state of toolCalls.states) {
|
|
10526
|
+
if (!state.id || !state.name) {
|
|
10527
|
+
throw new Error(`Unresolved tool-call identity (characters=${state.argumentLength})`);
|
|
10528
|
+
}
|
|
10529
|
+
parseToolArguments(state);
|
|
10530
|
+
}
|
|
10531
|
+
for (const [block, state] of toolCalls.statesByBlock) {
|
|
10532
|
+
block.arguments = parseToolArguments(state);
|
|
10533
|
+
stream.push({
|
|
10534
|
+
type: "toolcall_end",
|
|
10535
|
+
contentIndex: state.contentIndex,
|
|
10536
|
+
toolCall: block,
|
|
10537
|
+
partial: output
|
|
10538
|
+
});
|
|
10539
|
+
}
|
|
10540
|
+
if (toolCalls.statesByBlock.size > 0 && output.stopReason !== "length") {
|
|
10541
|
+
output.stopReason = "toolUse";
|
|
10542
|
+
}
|
|
10543
|
+
}
|
|
10544
|
+
if (isDegenerateDsmlTurn(output, rawReasoningTail)) {
|
|
10545
|
+
output.stopReason = "error";
|
|
10546
|
+
output.errorMessage = "Qoder server error: degenerate model output (unparseable DSML tool-call markup, no tool call executed)";
|
|
10547
|
+
stream.push({ type: "error", reason: "error", error: output });
|
|
10548
|
+
stream.end();
|
|
10549
|
+
return;
|
|
10550
|
+
}
|
|
10551
|
+
stream.push({
|
|
10552
|
+
type: "done",
|
|
10553
|
+
reason: output.stopReason,
|
|
10554
|
+
message: output
|
|
10555
|
+
});
|
|
10262
10556
|
stream.end();
|
|
10263
|
-
|
|
10557
|
+
};
|
|
10558
|
+
for (let attempt = 0; ; attempt++) {
|
|
10559
|
+
try {
|
|
10560
|
+
await runAttempt();
|
|
10561
|
+
return;
|
|
10562
|
+
} catch (e) {
|
|
10563
|
+
if (!(e instanceof QoderModelBusyError)) throw e;
|
|
10564
|
+
if (e.sawModelOutput || output.content.length > 0) {
|
|
10565
|
+
throw new Error("Qoder model rejected the request after partial output (10605 RESOURCE_LIMIT)");
|
|
10566
|
+
}
|
|
10567
|
+
const requestedWaitMs = e.retryAfterMs ?? 0;
|
|
10568
|
+
if (attempt >= modelBusyRetries) {
|
|
10569
|
+
throw new QoderModelBusyError(
|
|
10570
|
+
`Qoder server error: model is busy (10605 RESOURCE_LIMIT, retryAfterSeconds=${Math.round(requestedWaitMs / 1e3)}, attempts=${attempt + 1})`,
|
|
10571
|
+
requestedWaitMs
|
|
10572
|
+
);
|
|
10573
|
+
}
|
|
10574
|
+
if (requestedWaitMs > modelBusyMaxWaitMs) {
|
|
10575
|
+
throw new QoderModelBusyError(
|
|
10576
|
+
`Qoder server error: model is busy (10605 RESOURCE_LIMIT, requested delay ${requestedWaitMs}ms exceeds local cap ${modelBusyMaxWaitMs}ms)`,
|
|
10577
|
+
requestedWaitMs
|
|
10578
|
+
);
|
|
10579
|
+
}
|
|
10580
|
+
await sleepWithAbort(requestedWaitMs, options?.signal);
|
|
10581
|
+
options?.signal?.throwIfAborted();
|
|
10582
|
+
const nextId = crypto3.randomUUID();
|
|
10583
|
+
reqBody.request_id = nextId;
|
|
10584
|
+
reqBody.chat_record_id = nextId;
|
|
10585
|
+
encodedBytes = qoderEncodeBody(Buffer.from(JSON.stringify(reqBody)));
|
|
10586
|
+
headers = buildAuthHeaders(encodedBytes, chatURL, {
|
|
10587
|
+
userID,
|
|
10588
|
+
authToken: accessToken,
|
|
10589
|
+
name,
|
|
10590
|
+
email,
|
|
10591
|
+
machineID
|
|
10592
|
+
});
|
|
10593
|
+
}
|
|
10264
10594
|
}
|
|
10265
|
-
stream.push({
|
|
10266
|
-
type: "done",
|
|
10267
|
-
reason: output.stopReason,
|
|
10268
|
-
message: output
|
|
10269
|
-
});
|
|
10270
|
-
stream.end();
|
|
10271
10595
|
} catch (e) {
|
|
10272
10596
|
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
10273
10597
|
output.errorMessage = e instanceof Error ? e.message : String(e);
|