newcraw 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/REPL-CTTH53A7.js +50 -0
- package/dist/{acp-J4WDYGRX.js → acp-25PIN25O.js} +69 -40
- package/dist/acp-25PIN25O.js.map +7 -0
- package/dist/{agentsValidate-UBOER2IN.js → agentsValidate-BXDD54YP.js} +13 -10
- package/dist/{agentsValidate-UBOER2IN.js.map → agentsValidate-BXDD54YP.js.map} +1 -1
- package/dist/{ask-MGUO3L35.js → ask-EL4XAA5P.js} +62 -52
- package/dist/ask-EL4XAA5P.js.map +7 -0
- package/dist/{autoUpdater-2GS6LRPK.js → autoUpdater-DKMSJXWW.js} +5 -4
- package/dist/{chunk-2C43OXE7.js → chunk-2OVXJBJV.js} +38 -59
- package/dist/chunk-2OVXJBJV.js.map +7 -0
- package/dist/{chunk-53A4JHFW.js → chunk-3D3C7MRI.js} +23 -4
- package/dist/chunk-3D3C7MRI.js.map +7 -0
- package/dist/{chunk-VKI7ORIO.js → chunk-3ZQRACCP.js} +37 -18
- package/dist/{chunk-VKI7ORIO.js.map → chunk-3ZQRACCP.js.map} +1 -1
- package/dist/chunk-4A6CDBDH.js +822 -0
- package/dist/chunk-4A6CDBDH.js.map +7 -0
- package/dist/{chunk-VQSCECTS.js → chunk-53VETVCP.js} +6 -4
- package/dist/{chunk-VQSCECTS.js.map → chunk-53VETVCP.js.map} +1 -1
- package/dist/{chunk-WWDVA4NV.js → chunk-6WT3ZRYF.js} +22 -6
- package/dist/{chunk-WWDVA4NV.js.map → chunk-6WT3ZRYF.js.map} +1 -1
- package/dist/{chunk-RUXIBQ3B.js → chunk-7E2L7EH2.js} +4 -4
- package/dist/{chunk-VHS2MZQS.js → chunk-7PWVUHQ2.js} +9 -6
- package/dist/{chunk-VHS2MZQS.js.map → chunk-7PWVUHQ2.js.map} +1 -1
- package/dist/{chunk-2EFL22PV.js → chunk-ADJ4YEII.js} +7 -3
- package/dist/chunk-ADJ4YEII.js.map +7 -0
- package/dist/chunk-AKNZJBBU.js +372 -0
- package/dist/chunk-AKNZJBBU.js.map +7 -0
- package/dist/chunk-ALQSPHXV.js +135 -0
- package/dist/chunk-ALQSPHXV.js.map +7 -0
- package/dist/{chunk-XS6PU75S.js → chunk-APSIF3YK.js} +1 -1
- package/dist/{chunk-IM33F5CM.js → chunk-BMJ5XGFR.js} +1668 -1623
- package/dist/chunk-BMJ5XGFR.js.map +7 -0
- package/dist/chunk-BQCOSNM3.js +93 -0
- package/dist/chunk-BQCOSNM3.js.map +7 -0
- package/dist/{chunk-OJIMOLIC.js → chunk-BTCASL4X.js} +3621 -7413
- package/dist/chunk-BTCASL4X.js.map +7 -0
- package/dist/chunk-CHB5K4GI.js +107 -0
- package/dist/chunk-CHB5K4GI.js.map +7 -0
- package/dist/{chunk-QH2M65BR.js → chunk-D2FSAFMO.js} +7 -3
- package/dist/{chunk-QH2M65BR.js.map → chunk-D2FSAFMO.js.map} +1 -1
- package/dist/chunk-D4OZACS2.js +35 -0
- package/dist/{chunk-IIFUDVGS.js → chunk-ENLHVQCX.js} +310 -177
- package/dist/chunk-ENLHVQCX.js.map +7 -0
- package/dist/{chunk-A7X6OCZE.js → chunk-ERKWSZ3K.js} +1 -1
- package/dist/{chunk-UYRR6F5S.js → chunk-FSSZHQEJ.js} +9 -3
- package/dist/{chunk-UYRR6F5S.js.map → chunk-FSSZHQEJ.js.map} +1 -1
- package/dist/chunk-GV73HKJO.js +5473 -0
- package/dist/chunk-GV73HKJO.js.map +7 -0
- package/dist/{chunk-GZTCXXSS.js → chunk-GZ4BEVMZ.js} +57 -46
- package/dist/{chunk-GZTCXXSS.js.map → chunk-GZ4BEVMZ.js.map} +1 -1
- package/dist/chunk-HLBLZKZH.js +45 -0
- package/dist/chunk-HLBLZKZH.js.map +7 -0
- package/dist/chunk-JLVECHVJ.js +36 -0
- package/dist/chunk-JLVECHVJ.js.map +7 -0
- package/dist/chunk-KNSAVNMD.js +683 -0
- package/dist/{chunk-F3COCCAE.js.map → chunk-KNSAVNMD.js.map} +1 -1
- package/dist/{chunk-V5U6BHT2.js → chunk-KRN3WHHL.js} +7 -3
- package/dist/{chunk-V5U6BHT2.js.map → chunk-KRN3WHHL.js.map} +1 -1
- package/dist/{chunk-3LMXSKZ7.js → chunk-NFYAVT54.js} +1 -1
- package/dist/chunk-NT7RDVDA.js +33 -0
- package/dist/{chunk-KQSHIOZK.js.map → chunk-NT7RDVDA.js.map} +1 -1
- package/dist/chunk-NW7WSLD5.js +166 -0
- package/dist/{chunk-ZYSVG4X3.js.map → chunk-NW7WSLD5.js.map} +2 -2
- package/dist/{chunk-HSJ6HYAO.js → chunk-P52SGBC4.js} +18 -10
- package/dist/chunk-P52SGBC4.js.map +7 -0
- package/dist/{chunk-XXU2NVOE.js → chunk-PC6QOCGI.js} +30 -6
- package/dist/chunk-PC6QOCGI.js.map +7 -0
- package/dist/{chunk-N5OHRWG2.js → chunk-QSRXXZO7.js} +4 -2
- package/dist/{chunk-N5OHRWG2.js.map → chunk-QSRXXZO7.js.map} +1 -1
- package/dist/{chunk-DEF3KFP7.js → chunk-QZFKONA3.js} +4 -2
- package/dist/{chunk-DEF3KFP7.js.map → chunk-QZFKONA3.js.map} +1 -1
- package/dist/{chunk-JWXQNBBA.js → chunk-RE226X4F.js} +7 -1
- package/dist/{chunk-JWXQNBBA.js.map → chunk-RE226X4F.js.map} +1 -1
- package/dist/chunk-RF57YWGW.js +88 -0
- package/dist/chunk-RF57YWGW.js.map +7 -0
- package/dist/chunk-UGBECBIR.js +62 -0
- package/dist/chunk-UGBECBIR.js.map +7 -0
- package/dist/chunk-UYWZQVH5.js +35 -0
- package/dist/chunk-UYWZQVH5.js.map +7 -0
- package/dist/{chunk-LOIZNQOU.js → chunk-VHZRJ7RI.js} +9 -3
- package/dist/{chunk-LOIZNQOU.js.map → chunk-VHZRJ7RI.js.map} +1 -1
- package/dist/{chunk-XMGUQHMF.js → chunk-VSSVN6WG.js} +11 -1
- package/dist/chunk-VSSVN6WG.js.map +7 -0
- package/dist/{chunk-OZHBEG7U.js → chunk-XV7LPJNT.js} +15 -5
- package/dist/{chunk-OZHBEG7U.js.map → chunk-XV7LPJNT.js.map} +1 -1
- package/dist/chunk-Y7MDOB3N.js +65 -0
- package/dist/chunk-Y7MDOB3N.js.map +7 -0
- package/dist/{chunk-BWYKUDJR.js → chunk-ZLAB3Z4G.js} +14 -8
- package/dist/{chunk-BWYKUDJR.js.map → chunk-ZLAB3Z4G.js.map} +1 -1
- package/dist/{chunk-755HIAI3.js → chunk-ZMO4E7IW.js} +3 -42
- package/dist/chunk-ZMO4E7IW.js.map +7 -0
- package/dist/{cli-KZGF3FV5.js → cli-Z2BNJWHT.js} +251 -485
- package/dist/cli-Z2BNJWHT.js.map +7 -0
- package/dist/commands-3Y3OQOXT.js +54 -0
- package/dist/{config-GTJWCNPF.js → config-5RS7HDIK.js} +9 -6
- package/dist/{context-WF3TTXQU.js → context-XZXRRYKS.js} +8 -7
- package/dist/{costTracker-2G3ZI2JF.js → costTracker-VSWW7SRT.js} +3 -2
- package/dist/{customCommands-QOWK57EX.js → customCommands-6KDAODFQ.js} +6 -5
- package/dist/{env-37BAP7QF.js → env-WIM2DQ4L.js} +10 -7
- package/dist/{gateway-IZYO6YFJ.js → gateway-DKHC7H3K.js} +542 -96
- package/dist/gateway-DKHC7H3K.js.map +7 -0
- package/dist/identity-3KZQQVBG.js +16 -0
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/{kodeAgentSessionId-KTGFX2BE.js → kodeAgentSessionId-4SH24DVH.js} +1 -1
- package/dist/{kodeAgentSessionLoad-6F7SJXBC.js → kodeAgentSessionLoad-4S452GGD.js} +6 -5
- package/dist/{kodeAgentSessionResume-UEEDRJ3N.js → kodeAgentSessionResume-MSMG4QUR.js} +6 -5
- package/dist/{kodeAgentStreamJson-VIXFTYL5.js → kodeAgentStreamJson-4ZKIWKS3.js} +4 -2
- package/dist/{kodeAgentStreamJsonSession-XC3IPREZ.js → kodeAgentStreamJsonSession-CYG6MLKP.js} +15 -4
- package/dist/kodeAgentStreamJsonSession-CYG6MLKP.js.map +7 -0
- package/dist/{kodeAgentStructuredStdio-SI5C7AAD.js → kodeAgentStructuredStdio-5DCUC6V6.js} +3 -3
- package/dist/{kodeHooks-V36SHCTC.js → kodeHooks-WX3N6CL6.js} +6 -5
- package/dist/{llm-CYUDKJNR.js → llm-V2W4KJIA.js} +239 -57
- package/dist/llm-V2W4KJIA.js.map +7 -0
- package/dist/{llmLazy-IXVVBRTN.js → llmLazy-I7SO67YA.js} +2 -2
- package/dist/{loader-OEJ6C3TN.js → loader-YJGRGJNH.js} +6 -5
- package/dist/{mcp-KE3SILMX.js → mcp-WG3RQQCZ.js} +10 -9
- package/dist/{mentionProcessor-GAU2WAYB.js → mentionProcessor-PKWDUKTN.js} +14 -7
- package/dist/{mentionProcessor-GAU2WAYB.js.map → mentionProcessor-PKWDUKTN.js.map} +1 -1
- package/dist/{messages-WCSGGSEU.js → messages-RXHQ6VKL.js} +2 -2
- package/dist/{model-4TQIV5J2.js → model-JNWAZGT7.js} +10 -7
- package/dist/{openai-KTZV6F7N.js → openai-6NL5UXO7.js} +8 -7
- package/dist/{outputStyles-WX5RYQOA.js → outputStyles-BVPXT3MW.js} +6 -5
- package/dist/{pluginRuntime-JXMJZ2LC.js → pluginRuntime-XHI3TCRJ.js} +11 -8
- package/dist/{pluginRuntime-JXMJZ2LC.js.map → pluginRuntime-XHI3TCRJ.js.map} +1 -1
- package/dist/{pluginValidation-JNQZYLUP.js → pluginValidation-WDFL352C.js} +8 -7
- package/dist/prompts-C4RUFGX2.js +58 -0
- package/dist/query-IA3UKMGR.js +58 -0
- package/dist/{responsesStreaming-2AIT6GHG.js → responsesStreaming-JORGEFQC.js} +1 -1
- package/dist/{ripgrep-KDPQAMB2.js → ripgrep-BHDXRABJ.js} +5 -4
- package/dist/sandbox-QOXESHL4.js +63 -0
- package/dist/{skillMarketplace-IXAGP3Q2.js → skillMarketplace-RIAMO2YA.js} +5 -4
- package/dist/{state-MSCYLB6Y.js → state-TM2XZQE2.js} +6 -3
- package/dist/structuredOutput-KAVFUV2Z.js +9 -0
- package/dist/theme-BXUQNXSD.js +15 -0
- package/dist/thinking-BCZ4WDT6.js +18 -0
- package/dist/{toolPermissionContext-I3IXPVED.js → toolPermissionContext-JCQ5MFUT.js} +1 -1
- package/dist/toolPermissionContext-JCQ5MFUT.js.map +7 -0
- package/dist/toolPermissionContextState-ILRPUITK.js +24 -0
- package/dist/toolPermissionContextState-ILRPUITK.js.map +7 -0
- package/dist/{toolPermissionSettings-EUZKGZU2.js → toolPermissionSettings-LNYZ6XFE.js} +9 -8
- package/dist/toolPermissionSettings-LNYZ6XFE.js.map +7 -0
- package/dist/tools-HIPUGTF5.js +55 -0
- package/dist/tools-HIPUGTF5.js.map +7 -0
- package/dist/{userInput-LJL4CVOB.js → userInput-I33T2RX2.js} +49 -34
- package/dist/{userInput-LJL4CVOB.js.map → userInput-I33T2RX2.js.map} +1 -1
- package/dist/{uuid-VA3KVASX.js → uuid-RQH3OZ3W.js} +1 -1
- package/dist/uuid-RQH3OZ3W.js.map +7 -0
- package/dist/workspace-EP63OB5S.js +21 -0
- package/dist/workspace-EP63OB5S.js.map +7 -0
- package/package.json +1 -1
- package/web/dist/assets/index-XuLVvSQF.js +251 -0
- package/web/dist/assets/index-pSid9IlY.css +10 -0
- package/web/dist/index.html +2 -2
- package/dist/REPL-IAK7ZN2Z.js +0 -42
- package/dist/acp-J4WDYGRX.js.map +0 -7
- package/dist/ask-MGUO3L35.js.map +0 -7
- package/dist/chunk-2C43OXE7.js.map +0 -7
- package/dist/chunk-2EFL22PV.js.map +0 -7
- package/dist/chunk-53A4JHFW.js.map +0 -7
- package/dist/chunk-755HIAI3.js.map +0 -7
- package/dist/chunk-AXWJI6N5.js +0 -11
- package/dist/chunk-F3COCCAE.js +0 -654
- package/dist/chunk-HSJ6HYAO.js.map +0 -7
- package/dist/chunk-IIFUDVGS.js.map +0 -7
- package/dist/chunk-IM33F5CM.js.map +0 -7
- package/dist/chunk-KQSHIOZK.js +0 -24
- package/dist/chunk-OJIMOLIC.js.map +0 -7
- package/dist/chunk-XMGUQHMF.js.map +0 -7
- package/dist/chunk-XXU2NVOE.js.map +0 -7
- package/dist/chunk-ZYSVG4X3.js +0 -151
- package/dist/cli-KZGF3FV5.js.map +0 -7
- package/dist/commands-AVEBLFVS.js +0 -46
- package/dist/gateway-IZYO6YFJ.js.map +0 -7
- package/dist/kodeAgentStreamJsonSession-XC3IPREZ.js.map +0 -7
- package/dist/llm-CYUDKJNR.js.map +0 -7
- package/dist/prompts-LE6GK75N.js +0 -48
- package/dist/query-GGIP6PWG.js +0 -50
- package/dist/theme-GAMFOLBW.js +0 -14
- package/dist/tools-3HOUIDM3.js +0 -47
- package/web/dist/assets/index-COAJqX1Z.css +0 -1
- package/web/dist/assets/index-CzS_4LmC.js +0 -179
- /package/dist/{REPL-IAK7ZN2Z.js.map → REPL-CTTH53A7.js.map} +0 -0
- /package/dist/{autoUpdater-2GS6LRPK.js.map → autoUpdater-DKMSJXWW.js.map} +0 -0
- /package/dist/{chunk-RUXIBQ3B.js.map → chunk-7E2L7EH2.js.map} +0 -0
- /package/dist/{chunk-XS6PU75S.js.map → chunk-APSIF3YK.js.map} +0 -0
- /package/dist/{chunk-AXWJI6N5.js.map → chunk-D4OZACS2.js.map} +0 -0
- /package/dist/{chunk-A7X6OCZE.js.map → chunk-ERKWSZ3K.js.map} +0 -0
- /package/dist/{chunk-3LMXSKZ7.js.map → chunk-NFYAVT54.js.map} +0 -0
- /package/dist/{commands-AVEBLFVS.js.map → commands-3Y3OQOXT.js.map} +0 -0
- /package/dist/{config-GTJWCNPF.js.map → config-5RS7HDIK.js.map} +0 -0
- /package/dist/{context-WF3TTXQU.js.map → context-XZXRRYKS.js.map} +0 -0
- /package/dist/{costTracker-2G3ZI2JF.js.map → costTracker-VSWW7SRT.js.map} +0 -0
- /package/dist/{customCommands-QOWK57EX.js.map → customCommands-6KDAODFQ.js.map} +0 -0
- /package/dist/{env-37BAP7QF.js.map → env-WIM2DQ4L.js.map} +0 -0
- /package/dist/{kodeAgentSessionId-KTGFX2BE.js.map → identity-3KZQQVBG.js.map} +0 -0
- /package/dist/{kodeAgentSessionLoad-6F7SJXBC.js.map → kodeAgentSessionId-4SH24DVH.js.map} +0 -0
- /package/dist/{kodeAgentSessionResume-UEEDRJ3N.js.map → kodeAgentSessionLoad-4S452GGD.js.map} +0 -0
- /package/dist/{kodeAgentStreamJson-VIXFTYL5.js.map → kodeAgentSessionResume-MSMG4QUR.js.map} +0 -0
- /package/dist/{kodeAgentStructuredStdio-SI5C7AAD.js.map → kodeAgentStreamJson-4ZKIWKS3.js.map} +0 -0
- /package/dist/{kodeHooks-V36SHCTC.js.map → kodeAgentStructuredStdio-5DCUC6V6.js.map} +0 -0
- /package/dist/{llmLazy-IXVVBRTN.js.map → kodeHooks-WX3N6CL6.js.map} +0 -0
- /package/dist/{loader-OEJ6C3TN.js.map → llmLazy-I7SO67YA.js.map} +0 -0
- /package/dist/{mcp-KE3SILMX.js.map → loader-YJGRGJNH.js.map} +0 -0
- /package/dist/{messages-WCSGGSEU.js.map → mcp-WG3RQQCZ.js.map} +0 -0
- /package/dist/{model-4TQIV5J2.js.map → messages-RXHQ6VKL.js.map} +0 -0
- /package/dist/{openai-KTZV6F7N.js.map → model-JNWAZGT7.js.map} +0 -0
- /package/dist/{outputStyles-WX5RYQOA.js.map → openai-6NL5UXO7.js.map} +0 -0
- /package/dist/{pluginValidation-JNQZYLUP.js.map → outputStyles-BVPXT3MW.js.map} +0 -0
- /package/dist/{prompts-LE6GK75N.js.map → pluginValidation-WDFL352C.js.map} +0 -0
- /package/dist/{query-GGIP6PWG.js.map → prompts-C4RUFGX2.js.map} +0 -0
- /package/dist/{responsesStreaming-2AIT6GHG.js.map → query-IA3UKMGR.js.map} +0 -0
- /package/dist/{ripgrep-KDPQAMB2.js.map → responsesStreaming-JORGEFQC.js.map} +0 -0
- /package/dist/{skillMarketplace-IXAGP3Q2.js.map → ripgrep-BHDXRABJ.js.map} +0 -0
- /package/dist/{state-MSCYLB6Y.js.map → sandbox-QOXESHL4.js.map} +0 -0
- /package/dist/{theme-GAMFOLBW.js.map → skillMarketplace-RIAMO2YA.js.map} +0 -0
- /package/dist/{toolPermissionContext-I3IXPVED.js.map → state-TM2XZQE2.js.map} +0 -0
- /package/dist/{toolPermissionSettings-EUZKGZU2.js.map → structuredOutput-KAVFUV2Z.js.map} +0 -0
- /package/dist/{tools-3HOUIDM3.js.map → theme-BXUQNXSD.js.map} +0 -0
- /package/dist/{uuid-VA3KVASX.js.map → thinking-BCZ4WDT6.js.map} +0 -0
|
@@ -2,47 +2,55 @@
|
|
|
2
2
|
import { createRequire as __newcrawCreateRequire } from "node:module";
|
|
3
3
|
const require = __newcrawCreateRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
20
|
-
import "./chunk-
|
|
21
|
-
import "./chunk-RUXIBQ3B.js";
|
|
22
|
-
import "./chunk-JWXQNBBA.js";
|
|
23
|
-
import "./chunk-2C43OXE7.js";
|
|
24
|
-
import "./chunk-BWYKUDJR.js";
|
|
25
|
-
import "./chunk-2EFL22PV.js";
|
|
26
|
-
import "./chunk-U7S4MEYP.js";
|
|
27
|
-
import "./chunk-UYRR6F5S.js";
|
|
5
|
+
showSetupScreens
|
|
6
|
+
} from "./chunk-AKNZJBBU.js";
|
|
7
|
+
import {
|
|
8
|
+
buildSkillMatchDirective,
|
|
9
|
+
createQueryOptions,
|
|
10
|
+
matchSkillForPrompt
|
|
11
|
+
} from "./chunk-RF57YWGW.js";
|
|
12
|
+
import {
|
|
13
|
+
registerHealthProbe,
|
|
14
|
+
startPeriodicHealthCheck,
|
|
15
|
+
stopPeriodicHealthCheck
|
|
16
|
+
} from "./chunk-ALQSPHXV.js";
|
|
17
|
+
import "./chunk-GV73HKJO.js";
|
|
18
|
+
import "./chunk-D2FSAFMO.js";
|
|
19
|
+
import "./chunk-7E2L7EH2.js";
|
|
20
|
+
import "./chunk-6WT3ZRYF.js";
|
|
28
21
|
import "./chunk-TY3CCSAT.js";
|
|
29
|
-
import "./chunk-LOIZNQOU.js";
|
|
30
|
-
import "./chunk-INJSFEKL.js";
|
|
31
|
-
import "./chunk-2UO3BFZH.js";
|
|
32
22
|
import {
|
|
33
23
|
createAssistantMessage,
|
|
34
24
|
createUserMessage
|
|
35
|
-
} from "./chunk-
|
|
36
|
-
import
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
import "./chunk-
|
|
42
|
-
import
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
25
|
+
} from "./chunk-ERKWSZ3K.js";
|
|
26
|
+
import {
|
|
27
|
+
init_sandbox,
|
|
28
|
+
shutdownSandboxPool,
|
|
29
|
+
tryInitSandboxPool
|
|
30
|
+
} from "./chunk-4A6CDBDH.js";
|
|
31
|
+
import "./chunk-ADJ4YEII.js";
|
|
32
|
+
import {
|
|
33
|
+
getIdentity,
|
|
34
|
+
setIdentity
|
|
35
|
+
} from "./chunk-JLVECHVJ.js";
|
|
36
|
+
import "./chunk-2UO3BFZH.js";
|
|
37
|
+
import "./chunk-KNSAVNMD.js";
|
|
38
|
+
import "./chunk-QZFKONA3.js";
|
|
39
|
+
import {
|
|
40
|
+
enableConfigs,
|
|
41
|
+
getGlobalConfig,
|
|
42
|
+
init_config
|
|
43
|
+
} from "./chunk-ENLHVQCX.js";
|
|
44
|
+
import "./chunk-NT7RDVDA.js";
|
|
45
|
+
import "./chunk-GZ4BEVMZ.js";
|
|
46
|
+
import {
|
|
47
|
+
init_log,
|
|
48
|
+
logError
|
|
49
|
+
} from "./chunk-BMJ5XGFR.js";
|
|
50
|
+
import "./chunk-UYWZQVH5.js";
|
|
51
|
+
import "./chunk-NW7WSLD5.js";
|
|
52
|
+
import "./chunk-HLBLZKZH.js";
|
|
53
|
+
import "./chunk-D4OZACS2.js";
|
|
46
54
|
|
|
47
55
|
// src/sessions/manager.ts
|
|
48
56
|
var SessionManager = class {
|
|
@@ -80,95 +88,166 @@ var SessionManager = class {
|
|
|
80
88
|
// src/gateway/agentCore.ts
|
|
81
89
|
import { cwd as processCwd } from "process";
|
|
82
90
|
var gatewayPermissionHandler = async (tool, _input, _context, _assistantMessage) => {
|
|
83
|
-
if (tool.isReadOnly()) {
|
|
84
|
-
return { result: true };
|
|
85
|
-
}
|
|
86
91
|
return { result: true };
|
|
87
92
|
};
|
|
88
|
-
async function loadGatewayTools(domainId) {
|
|
89
|
-
const { getTools } = await import("./tools-3HOUIDM3.js");
|
|
90
|
-
const domain = getDomain(domainId);
|
|
91
|
-
const allTools = await getTools();
|
|
92
|
-
if (!domain) return allTools;
|
|
93
|
-
const allowedNames = new Set(domain.tools());
|
|
94
|
-
const filtered = allTools.filter((t) => allowedNames.has(t.name));
|
|
95
|
-
return filtered.length > 0 ? filtered : allTools;
|
|
96
|
-
}
|
|
97
93
|
function convertSessionHistory(history) {
|
|
98
94
|
return history.map(
|
|
99
95
|
(msg) => msg.role === "user" ? createUserMessage(msg.content) : createAssistantMessage(msg.content)
|
|
100
96
|
);
|
|
101
97
|
}
|
|
102
98
|
async function gatewayQuery(options) {
|
|
103
|
-
const {
|
|
104
|
-
const {
|
|
99
|
+
const { query } = await import("./query-IA3UKMGR.js");
|
|
100
|
+
const { getSystemPrompt } = await import("./prompts-C4RUFGX2.js");
|
|
101
|
+
const { getContext } = await import("./context-XZXRRYKS.js");
|
|
102
|
+
const { setCwd } = await import("./state-TM2XZQE2.js");
|
|
105
103
|
const identity = getIdentity();
|
|
106
104
|
const domainId = options.domain ?? identity.domain;
|
|
107
105
|
const cwd = options.cwd ?? processCwd();
|
|
108
106
|
await setCwd(cwd);
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
107
|
+
const userMessage = createUserMessage(options.prompt);
|
|
108
|
+
const messages = [...options.sessionMessages ?? [], userMessage];
|
|
109
|
+
const messageLogName = `gateway-${Date.now()}`;
|
|
110
|
+
const [systemPrompt, context, queryOpts, skillMatch] = await Promise.all([
|
|
111
|
+
getSystemPrompt({ domain: domainId }),
|
|
112
|
+
getContext(),
|
|
113
|
+
createQueryOptions({
|
|
114
|
+
messages,
|
|
115
|
+
safeMode: options.safeMode,
|
|
116
|
+
messageLogName,
|
|
117
|
+
verbose: false,
|
|
118
|
+
persistSession: false
|
|
119
|
+
}),
|
|
120
|
+
matchSkillForPrompt(options.prompt)
|
|
121
|
+
]);
|
|
122
|
+
if (skillMatch) {
|
|
123
|
+
systemPrompt.unshift(buildSkillMatchDirective(skillMatch));
|
|
124
|
+
}
|
|
125
|
+
const abortController = new AbortController();
|
|
126
|
+
for await (const m of query(
|
|
127
|
+
messages,
|
|
128
|
+
systemPrompt,
|
|
129
|
+
context,
|
|
130
|
+
gatewayPermissionHandler,
|
|
131
|
+
{
|
|
132
|
+
...queryOpts,
|
|
133
|
+
abortController
|
|
134
|
+
}
|
|
135
|
+
)) {
|
|
136
|
+
messages.push(m);
|
|
137
|
+
}
|
|
138
|
+
const last = messages[messages.length - 1];
|
|
139
|
+
const resultText = last?.type === "assistant" ? last.message.content.find((c) => c.type === "text")?.text ?? "" : "";
|
|
123
140
|
return {
|
|
124
|
-
resultText
|
|
141
|
+
resultText,
|
|
125
142
|
messages: [],
|
|
126
|
-
totalCost:
|
|
143
|
+
totalCost: 0
|
|
127
144
|
};
|
|
128
145
|
}
|
|
129
146
|
async function* gatewayQueryStream(options) {
|
|
130
|
-
const { query } = await import("./query-
|
|
131
|
-
const { getSystemPrompt } = await import("./prompts-
|
|
132
|
-
const { getContext } = await import("./context-
|
|
133
|
-
const { setCwd } = await import("./state-
|
|
147
|
+
const { query } = await import("./query-IA3UKMGR.js");
|
|
148
|
+
const { getSystemPrompt } = await import("./prompts-C4RUFGX2.js");
|
|
149
|
+
const { getContext } = await import("./context-XZXRRYKS.js");
|
|
150
|
+
const { setCwd } = await import("./state-TM2XZQE2.js");
|
|
134
151
|
const identity = getIdentity();
|
|
135
152
|
const domainId = options.domain ?? identity.domain;
|
|
136
153
|
const cwd = options.cwd ?? processCwd();
|
|
137
154
|
await setCwd(cwd);
|
|
138
|
-
const tools = options.tools ?? await loadGatewayTools(domainId);
|
|
139
|
-
const [systemPrompt, context] = await Promise.all([
|
|
140
|
-
getSystemPrompt({ domain: domainId }),
|
|
141
|
-
getContext()
|
|
142
|
-
]);
|
|
143
155
|
const userMessage = createUserMessage(options.prompt);
|
|
144
156
|
const messages = [...options.sessionMessages ?? [], userMessage];
|
|
157
|
+
const messageLogName = `gateway-${Date.now()}`;
|
|
158
|
+
const [systemPrompt, context, queryOpts, skillMatch] = await Promise.all([
|
|
159
|
+
getSystemPrompt({ domain: domainId }),
|
|
160
|
+
getContext(),
|
|
161
|
+
createQueryOptions({
|
|
162
|
+
messages,
|
|
163
|
+
safeMode: options.safeMode,
|
|
164
|
+
messageLogName,
|
|
165
|
+
verbose: false,
|
|
166
|
+
persistSession: false
|
|
167
|
+
}),
|
|
168
|
+
matchSkillForPrompt(options.prompt)
|
|
169
|
+
]);
|
|
170
|
+
if (skillMatch) {
|
|
171
|
+
systemPrompt.unshift(buildSkillMatchDirective(skillMatch));
|
|
172
|
+
}
|
|
145
173
|
const abortController = new AbortController();
|
|
146
174
|
const seenToolUseIds = /* @__PURE__ */ new Set();
|
|
175
|
+
const toolTrace = [];
|
|
176
|
+
const reasoningEvents = [];
|
|
177
|
+
let modelName = "unknown";
|
|
178
|
+
try {
|
|
179
|
+
const { getModelManager } = await import("./model-JNWAZGT7.js");
|
|
180
|
+
const manager = getModelManager();
|
|
181
|
+
modelName = manager.getModelName("main") ?? "unknown";
|
|
182
|
+
} catch {
|
|
183
|
+
}
|
|
184
|
+
yield {
|
|
185
|
+
type: "status",
|
|
186
|
+
content: JSON.stringify({
|
|
187
|
+
model: modelName,
|
|
188
|
+
state: "started",
|
|
189
|
+
iteration: 0,
|
|
190
|
+
timestamp: Date.now()
|
|
191
|
+
})
|
|
192
|
+
};
|
|
193
|
+
let iterationCount = 0;
|
|
194
|
+
let totalInputTokens = 0;
|
|
195
|
+
let totalOutputTokens = 0;
|
|
196
|
+
let totalCacheReadTokens = 0;
|
|
197
|
+
let totalCacheCreationTokens = 0;
|
|
147
198
|
for await (const msg of query(
|
|
148
199
|
messages,
|
|
149
200
|
systemPrompt,
|
|
150
201
|
context,
|
|
151
202
|
gatewayPermissionHandler,
|
|
152
203
|
{
|
|
153
|
-
|
|
154
|
-
commands: [],
|
|
155
|
-
tools,
|
|
156
|
-
verbose: false,
|
|
157
|
-
safeMode: options.safeMode ?? false,
|
|
158
|
-
forkNumber: 0,
|
|
159
|
-
messageLogName: `gateway-${Date.now()}`,
|
|
160
|
-
maxThinkingTokens: 0,
|
|
161
|
-
persistSession: false,
|
|
162
|
-
shouldAvoidPermissionPrompts: true
|
|
163
|
-
},
|
|
204
|
+
...queryOpts,
|
|
164
205
|
abortController,
|
|
165
|
-
|
|
166
|
-
readFileTimestamps: {},
|
|
167
|
-
setToolJSX: () => {
|
|
168
|
-
}
|
|
206
|
+
reasoningEvents
|
|
169
207
|
}
|
|
170
208
|
)) {
|
|
209
|
+
while (reasoningEvents.length > 0) {
|
|
210
|
+
const event = reasoningEvents.shift();
|
|
211
|
+
yield { type: "reasoning", content: JSON.stringify(event) };
|
|
212
|
+
}
|
|
171
213
|
if (msg.type === "assistant") {
|
|
214
|
+
iterationCount++;
|
|
215
|
+
const usage = msg.message.usage;
|
|
216
|
+
if (usage) {
|
|
217
|
+
const input = usage.input_tokens ?? 0;
|
|
218
|
+
const output = usage.output_tokens ?? 0;
|
|
219
|
+
const cacheRead = usage.cache_read_input_tokens ?? 0;
|
|
220
|
+
const cacheCreation = usage.cache_creation_input_tokens ?? 0;
|
|
221
|
+
totalInputTokens += input;
|
|
222
|
+
totalOutputTokens += output;
|
|
223
|
+
totalCacheReadTokens += cacheRead;
|
|
224
|
+
totalCacheCreationTokens += cacheCreation;
|
|
225
|
+
yield {
|
|
226
|
+
type: "usage",
|
|
227
|
+
content: JSON.stringify({
|
|
228
|
+
inputTokens: input,
|
|
229
|
+
outputTokens: output,
|
|
230
|
+
cacheReadTokens: cacheRead,
|
|
231
|
+
cacheCreationTokens: cacheCreation,
|
|
232
|
+
totalInputTokens,
|
|
233
|
+
totalOutputTokens,
|
|
234
|
+
totalCacheReadTokens,
|
|
235
|
+
totalCacheCreationTokens,
|
|
236
|
+
costUSD: msg.costUSD ?? 0,
|
|
237
|
+
iteration: iterationCount
|
|
238
|
+
})
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
yield {
|
|
242
|
+
type: "status",
|
|
243
|
+
content: JSON.stringify({
|
|
244
|
+
model: modelName,
|
|
245
|
+
state: "thinking",
|
|
246
|
+
iteration: iterationCount,
|
|
247
|
+
toolCallCount: toolTrace.length,
|
|
248
|
+
timestamp: Date.now()
|
|
249
|
+
})
|
|
250
|
+
};
|
|
172
251
|
for (const block of msg.message.content) {
|
|
173
252
|
if (block.type === "text" && block.text) {
|
|
174
253
|
yield { type: "text", content: block.text };
|
|
@@ -177,6 +256,7 @@ async function* gatewayQueryStream(options) {
|
|
|
177
256
|
} else if (block.type === "tool_use") {
|
|
178
257
|
seenToolUseIds.add(block.id);
|
|
179
258
|
const inputBrief = JSON.stringify(block.input).slice(0, 200);
|
|
259
|
+
toolTrace.push({ name: block.name, input: inputBrief, succeeded: true });
|
|
180
260
|
yield { type: "tool_call", content: `${block.name}(${inputBrief})` };
|
|
181
261
|
}
|
|
182
262
|
}
|
|
@@ -185,6 +265,7 @@ async function* gatewayQueryStream(options) {
|
|
|
185
265
|
if (block.type === "tool_use" && !seenToolUseIds.has(block.id)) {
|
|
186
266
|
seenToolUseIds.add(block.id);
|
|
187
267
|
const inputBrief = JSON.stringify(block.input).slice(0, 200);
|
|
268
|
+
toolTrace.push({ name: block.name, input: inputBrief, succeeded: true });
|
|
188
269
|
yield { type: "tool_call", content: `${block.name}(${inputBrief})` };
|
|
189
270
|
}
|
|
190
271
|
}
|
|
@@ -194,12 +275,43 @@ async function* gatewayQueryStream(options) {
|
|
|
194
275
|
for (const block of content) {
|
|
195
276
|
if (block.type === "tool_result") {
|
|
196
277
|
const raw = typeof block.content === "string" ? block.content : JSON.stringify(block.content);
|
|
278
|
+
const isError = block.is_error === true || raw.includes("error") || raw.includes("Error") || raw.includes("REDIRECT");
|
|
279
|
+
if (isError && toolTrace.length > 0) {
|
|
280
|
+
toolTrace[toolTrace.length - 1].succeeded = false;
|
|
281
|
+
}
|
|
197
282
|
yield { type: "tool_result", content: raw.slice(0, 500) };
|
|
198
283
|
}
|
|
199
284
|
}
|
|
200
285
|
}
|
|
201
286
|
}
|
|
202
287
|
}
|
|
288
|
+
while (reasoningEvents.length > 0) {
|
|
289
|
+
const event = reasoningEvents.shift();
|
|
290
|
+
yield { type: "reasoning", content: JSON.stringify(event) };
|
|
291
|
+
}
|
|
292
|
+
if (toolTrace.length > 0) {
|
|
293
|
+
const steps = toolTrace.map((t, i) => {
|
|
294
|
+
const status = t.succeeded ? "\u2713" : "\u2717";
|
|
295
|
+
return `${i + 1}. ${status} ${t.name}`;
|
|
296
|
+
});
|
|
297
|
+
const summary = `
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
**\u83B7\u53D6\u8DEF\u5F84**: ${steps.join(" \u2192 ")}`;
|
|
301
|
+
yield { type: "text", content: summary };
|
|
302
|
+
}
|
|
303
|
+
yield {
|
|
304
|
+
type: "status",
|
|
305
|
+
content: JSON.stringify({
|
|
306
|
+
model: modelName,
|
|
307
|
+
state: "completed",
|
|
308
|
+
iteration: iterationCount,
|
|
309
|
+
toolCallCount: toolTrace.length,
|
|
310
|
+
totalInputTokens,
|
|
311
|
+
totalOutputTokens,
|
|
312
|
+
timestamp: Date.now()
|
|
313
|
+
})
|
|
314
|
+
};
|
|
203
315
|
yield { type: "done", content: "" };
|
|
204
316
|
}
|
|
205
317
|
|
|
@@ -274,9 +386,137 @@ function maxConcurrencyMiddleware(options = {}) {
|
|
|
274
386
|
|
|
275
387
|
// src/channels/http.ts
|
|
276
388
|
import { createServer } from "http";
|
|
277
|
-
import { randomUUID } from "crypto";
|
|
389
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
278
390
|
import { resolve, join, extname } from "path";
|
|
279
391
|
import { readFile, stat } from "fs/promises";
|
|
392
|
+
|
|
393
|
+
// src/gateway/openaiCompat.ts
|
|
394
|
+
import { randomUUID } from "crypto";
|
|
395
|
+
function convertOpenAIRequestToGateway(body, sessionKey) {
|
|
396
|
+
const messages = body.messages ?? [];
|
|
397
|
+
let prompt = "";
|
|
398
|
+
let systemPrompt = "";
|
|
399
|
+
const systemMessages = messages.filter((m) => m.role === "system");
|
|
400
|
+
if (systemMessages.length > 0) {
|
|
401
|
+
systemPrompt = systemMessages.map((m) => m.content ?? "").filter(Boolean).join("\n\n");
|
|
402
|
+
}
|
|
403
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
404
|
+
if (messages[i].role === "user" && messages[i].content) {
|
|
405
|
+
prompt = messages[i].content;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
const conversationHistory = messages.filter((m) => m.role !== "system");
|
|
410
|
+
const contextParts = [];
|
|
411
|
+
if (systemPrompt) {
|
|
412
|
+
contextParts.push(`<system_context>
|
|
413
|
+
${systemPrompt}
|
|
414
|
+
</system_context>`);
|
|
415
|
+
}
|
|
416
|
+
const priorMessages = conversationHistory.slice(0, -1);
|
|
417
|
+
if (priorMessages.length > 0) {
|
|
418
|
+
const historyLines = priorMessages.map((m) => {
|
|
419
|
+
if (m.role === "assistant") {
|
|
420
|
+
if (m.tool_calls && m.tool_calls.length > 0) {
|
|
421
|
+
const toolDescs = m.tool_calls.map((tc) => `[tool_call: ${tc.function.name}(${tc.function.arguments})]`).join(" ");
|
|
422
|
+
return `Assistant: ${m.content ?? ""} ${toolDescs}`;
|
|
423
|
+
}
|
|
424
|
+
return `Assistant: ${m.content ?? ""}`;
|
|
425
|
+
}
|
|
426
|
+
if (m.role === "tool") {
|
|
427
|
+
return `Tool(${m.tool_call_id ?? m.name ?? ""}): ${m.content ?? ""}`;
|
|
428
|
+
}
|
|
429
|
+
if (m.role === "user") {
|
|
430
|
+
return `User: ${m.content ?? ""}`;
|
|
431
|
+
}
|
|
432
|
+
return "";
|
|
433
|
+
}).filter(Boolean);
|
|
434
|
+
if (historyLines.length > 0) {
|
|
435
|
+
contextParts.push(`<conversation_history>
|
|
436
|
+
${historyLines.join("\n")}
|
|
437
|
+
</conversation_history>`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (body.tools && body.tools.length > 0) {
|
|
441
|
+
const toolDescriptions = body.tools.map((t) => `- ${t.function.name}: ${t.function.description ?? "(no description)"}`).join("\n");
|
|
442
|
+
contextParts.push(`<available_tools>
|
|
443
|
+
${toolDescriptions}
|
|
444
|
+
</available_tools>`);
|
|
445
|
+
}
|
|
446
|
+
if (contextParts.length > 0 && prompt) {
|
|
447
|
+
prompt = `${contextParts.join("\n\n")}
|
|
448
|
+
|
|
449
|
+
${prompt}`;
|
|
450
|
+
}
|
|
451
|
+
return {
|
|
452
|
+
prompt,
|
|
453
|
+
domain: "coding",
|
|
454
|
+
safeMode: false,
|
|
455
|
+
systemPrompt,
|
|
456
|
+
conversationHistory,
|
|
457
|
+
openaiTools: body.tools
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
function buildCompletionResponse(model, content) {
|
|
461
|
+
return {
|
|
462
|
+
id: `chatcmpl-${randomUUID().replace(/-/g, "").slice(0, 24)}`,
|
|
463
|
+
object: "chat.completion",
|
|
464
|
+
created: Math.floor(Date.now() / 1e3),
|
|
465
|
+
model,
|
|
466
|
+
choices: [
|
|
467
|
+
{
|
|
468
|
+
index: 0,
|
|
469
|
+
message: {
|
|
470
|
+
role: "assistant",
|
|
471
|
+
content
|
|
472
|
+
},
|
|
473
|
+
finish_reason: "stop"
|
|
474
|
+
}
|
|
475
|
+
],
|
|
476
|
+
usage: {
|
|
477
|
+
prompt_tokens: 0,
|
|
478
|
+
completion_tokens: 0,
|
|
479
|
+
total_tokens: 0
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
function buildChunk(completionId, model, delta, finishReason = null) {
|
|
484
|
+
return {
|
|
485
|
+
id: completionId,
|
|
486
|
+
object: "chat.completion.chunk",
|
|
487
|
+
created: Math.floor(Date.now() / 1e3),
|
|
488
|
+
model,
|
|
489
|
+
choices: [
|
|
490
|
+
{
|
|
491
|
+
index: 0,
|
|
492
|
+
delta,
|
|
493
|
+
finish_reason: finishReason
|
|
494
|
+
}
|
|
495
|
+
]
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function buildDoneChunk(completionId, model) {
|
|
499
|
+
return {
|
|
500
|
+
id: completionId,
|
|
501
|
+
object: "chat.completion.chunk",
|
|
502
|
+
created: Math.floor(Date.now() / 1e3),
|
|
503
|
+
model,
|
|
504
|
+
choices: [
|
|
505
|
+
{
|
|
506
|
+
index: 0,
|
|
507
|
+
delta: {},
|
|
508
|
+
finish_reason: "stop"
|
|
509
|
+
}
|
|
510
|
+
],
|
|
511
|
+
usage: {
|
|
512
|
+
prompt_tokens: 0,
|
|
513
|
+
completion_tokens: 0,
|
|
514
|
+
total_tokens: 0
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// src/channels/http.ts
|
|
280
520
|
var MIME_TYPES = {
|
|
281
521
|
".html": "text/html; charset=utf-8",
|
|
282
522
|
".js": "application/javascript; charset=utf-8",
|
|
@@ -365,6 +605,14 @@ var HttpChannel = class {
|
|
|
365
605
|
await this.handleChatStream(req, res);
|
|
366
606
|
return;
|
|
367
607
|
}
|
|
608
|
+
if (req.method === "POST" && (req.url === "/v1/chat/completions" || req.url === "/chat/completions")) {
|
|
609
|
+
await this.handleOpenAICompat(req, res);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
if (req.method === "GET" && req.url === "/v1/models") {
|
|
613
|
+
await this.handleOpenAIModels(req, res);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
368
616
|
if (req.method === "GET" && this.config.webDistDir) {
|
|
369
617
|
const served = await this.serveStatic(req, res);
|
|
370
618
|
if (served) return;
|
|
@@ -429,7 +677,7 @@ var HttpChannel = class {
|
|
|
429
677
|
res.end(JSON.stringify({ error: "No handler registered" }));
|
|
430
678
|
return;
|
|
431
679
|
}
|
|
432
|
-
const requestId =
|
|
680
|
+
const requestId = randomUUID2();
|
|
433
681
|
this.pendingResponses.set(requestId, []);
|
|
434
682
|
await this.handler({
|
|
435
683
|
channelId: "http",
|
|
@@ -479,7 +727,7 @@ var HttpChannel = class {
|
|
|
479
727
|
userId,
|
|
480
728
|
sessionKey: sessionKey ?? `http:${userId}`,
|
|
481
729
|
text: message,
|
|
482
|
-
metadata: { requestId:
|
|
730
|
+
metadata: { requestId: randomUUID2() }
|
|
483
731
|
};
|
|
484
732
|
await this.streamHandler(unifiedMsg, res);
|
|
485
733
|
} catch (err) {
|
|
@@ -493,6 +741,144 @@ var HttpChannel = class {
|
|
|
493
741
|
}
|
|
494
742
|
}
|
|
495
743
|
}
|
|
744
|
+
async handleOpenAICompat(req, res) {
|
|
745
|
+
if (!this.checkAuth(req, res)) return;
|
|
746
|
+
try {
|
|
747
|
+
const raw = await readBody(req);
|
|
748
|
+
const body = JSON.parse(raw);
|
|
749
|
+
const model = body.model ?? "kode-agent";
|
|
750
|
+
const isStream = body.stream === true;
|
|
751
|
+
const gatewayOpts = convertOpenAIRequestToGateway(body, `openai:${randomUUID2().slice(0, 8)}`);
|
|
752
|
+
if (!gatewayOpts.prompt) {
|
|
753
|
+
res.setHeader("Content-Type", "application/json");
|
|
754
|
+
res.writeHead(400);
|
|
755
|
+
res.end(JSON.stringify({
|
|
756
|
+
error: { message: "No user message found in messages array", type: "invalid_request_error", code: "missing_user_message" }
|
|
757
|
+
}));
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
if (isStream) {
|
|
761
|
+
res.writeHead(200, {
|
|
762
|
+
"Content-Type": "text/event-stream",
|
|
763
|
+
"Cache-Control": "no-cache",
|
|
764
|
+
"Connection": "keep-alive",
|
|
765
|
+
"X-Accel-Buffering": "no"
|
|
766
|
+
});
|
|
767
|
+
const completionId = `chatcmpl-${randomUUID2().replace(/-/g, "").slice(0, 24)}`;
|
|
768
|
+
let streamEnded = false;
|
|
769
|
+
const safeWrite = (data) => {
|
|
770
|
+
if (streamEnded || res.writableEnded || res.destroyed) return false;
|
|
771
|
+
try {
|
|
772
|
+
return res.write(data);
|
|
773
|
+
} catch {
|
|
774
|
+
return false;
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
safeWrite(`data: ${JSON.stringify(buildChunk(completionId, model, { role: "assistant", content: "" }))}
|
|
778
|
+
|
|
779
|
+
`);
|
|
780
|
+
if (this.streamHandler) {
|
|
781
|
+
const unifiedMsg = {
|
|
782
|
+
channelId: "http",
|
|
783
|
+
userId: "openai-compat",
|
|
784
|
+
sessionKey: `openai:${randomUUID2().slice(0, 8)}`,
|
|
785
|
+
text: gatewayOpts.prompt,
|
|
786
|
+
metadata: { requestId: randomUUID2(), openaiCompat: true }
|
|
787
|
+
};
|
|
788
|
+
const interceptRes = Object.create(res);
|
|
789
|
+
interceptRes.write = ((data) => {
|
|
790
|
+
if (typeof data === "string" && data.startsWith("event:")) {
|
|
791
|
+
const lines = data.split("\n");
|
|
792
|
+
for (const line of lines) {
|
|
793
|
+
if (line.startsWith("data: ")) {
|
|
794
|
+
try {
|
|
795
|
+
const parsed = JSON.parse(line.slice(6));
|
|
796
|
+
if (parsed.type === "text" || parsed.content && typeof parsed.content === "string") {
|
|
797
|
+
const textContent = parsed.content ?? parsed.text ?? "";
|
|
798
|
+
if (textContent) {
|
|
799
|
+
safeWrite(`data: ${JSON.stringify(buildChunk(completionId, model, { content: textContent }))}
|
|
800
|
+
|
|
801
|
+
`);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
} catch {
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
return true;
|
|
809
|
+
}
|
|
810
|
+
return safeWrite(data);
|
|
811
|
+
});
|
|
812
|
+
interceptRes.end = (() => {
|
|
813
|
+
});
|
|
814
|
+
await this.streamHandler(unifiedMsg, interceptRes);
|
|
815
|
+
}
|
|
816
|
+
safeWrite(`data: ${JSON.stringify(buildDoneChunk(completionId, model))}
|
|
817
|
+
|
|
818
|
+
`);
|
|
819
|
+
safeWrite("data: [DONE]\n\n");
|
|
820
|
+
streamEnded = true;
|
|
821
|
+
res.end();
|
|
822
|
+
} else {
|
|
823
|
+
if (!this.handler) {
|
|
824
|
+
res.setHeader("Content-Type", "application/json");
|
|
825
|
+
res.writeHead(503);
|
|
826
|
+
res.end(JSON.stringify({
|
|
827
|
+
error: { message: "Service unavailable", type: "server_error" }
|
|
828
|
+
}));
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
const requestId = randomUUID2();
|
|
832
|
+
this.pendingResponses.set(requestId, []);
|
|
833
|
+
await this.handler({
|
|
834
|
+
channelId: "http",
|
|
835
|
+
userId: requestId,
|
|
836
|
+
sessionKey: `openai:${requestId.slice(0, 8)}`,
|
|
837
|
+
text: gatewayOpts.prompt,
|
|
838
|
+
metadata: { requestId, openaiCompat: true }
|
|
839
|
+
});
|
|
840
|
+
const responses = this.pendingResponses.get(requestId) ?? [];
|
|
841
|
+
this.pendingResponses.delete(requestId);
|
|
842
|
+
const textContent = responses.filter((r) => r.type === "text").map((r) => r.content).join("");
|
|
843
|
+
const completion = buildCompletionResponse(model, textContent);
|
|
844
|
+
res.setHeader("Content-Type", "application/json");
|
|
845
|
+
res.writeHead(200);
|
|
846
|
+
res.end(JSON.stringify(completion));
|
|
847
|
+
}
|
|
848
|
+
} catch (err) {
|
|
849
|
+
if (!res.headersSent) {
|
|
850
|
+
res.setHeader("Content-Type", "application/json");
|
|
851
|
+
res.writeHead(500);
|
|
852
|
+
res.end(JSON.stringify({
|
|
853
|
+
error: { message: err.message ?? "Internal server error", type: "server_error" }
|
|
854
|
+
}));
|
|
855
|
+
} else if (!res.writableEnded && !res.destroyed) {
|
|
856
|
+
try {
|
|
857
|
+
res.write(`data: ${JSON.stringify({ error: { message: err.message } })}
|
|
858
|
+
|
|
859
|
+
`);
|
|
860
|
+
res.write("data: [DONE]\n\n");
|
|
861
|
+
res.end();
|
|
862
|
+
} catch {
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
async handleOpenAIModels(_req, res) {
|
|
868
|
+
res.setHeader("Content-Type", "application/json");
|
|
869
|
+
res.writeHead(200);
|
|
870
|
+
res.end(JSON.stringify({
|
|
871
|
+
object: "list",
|
|
872
|
+
data: [
|
|
873
|
+
{
|
|
874
|
+
id: "kode-agent",
|
|
875
|
+
object: "model",
|
|
876
|
+
created: Math.floor(Date.now() / 1e3),
|
|
877
|
+
owned_by: "kode"
|
|
878
|
+
}
|
|
879
|
+
]
|
|
880
|
+
}));
|
|
881
|
+
}
|
|
496
882
|
};
|
|
497
883
|
function writeSseEvent(res, event, data) {
|
|
498
884
|
res.write(`event: ${event}
|
|
@@ -687,7 +1073,7 @@ var Gateway = class {
|
|
|
687
1073
|
// src/channels/websocket.ts
|
|
688
1074
|
import { createServer as createServer2 } from "http";
|
|
689
1075
|
import { WebSocketServer } from "ws";
|
|
690
|
-
import { randomUUID as
|
|
1076
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
691
1077
|
var WebSocketChannel = class {
|
|
692
1078
|
constructor(config) {
|
|
693
1079
|
this.config = config;
|
|
@@ -751,7 +1137,7 @@ var WebSocketChannel = class {
|
|
|
751
1137
|
return;
|
|
752
1138
|
}
|
|
753
1139
|
}
|
|
754
|
-
const clientId =
|
|
1140
|
+
const clientId = randomUUID3();
|
|
755
1141
|
this.clients.set(clientId, {
|
|
756
1142
|
ws,
|
|
757
1143
|
userId: clientId,
|
|
@@ -979,10 +1365,13 @@ var FileSessionStorage = class {
|
|
|
979
1365
|
};
|
|
980
1366
|
|
|
981
1367
|
// src/entrypoints/gateway.ts
|
|
1368
|
+
init_config();
|
|
982
1369
|
import { join as join3, dirname } from "path";
|
|
983
1370
|
import { homedir } from "os";
|
|
984
1371
|
import { existsSync as existsSync2 } from "fs";
|
|
985
1372
|
import { fileURLToPath } from "url";
|
|
1373
|
+
init_log();
|
|
1374
|
+
init_sandbox();
|
|
986
1375
|
function parseArgs(argv) {
|
|
987
1376
|
const opts = {
|
|
988
1377
|
port: 3e3,
|
|
@@ -1109,6 +1498,15 @@ function resolveWebDir(explicit) {
|
|
|
1109
1498
|
}
|
|
1110
1499
|
async function main() {
|
|
1111
1500
|
const opts = parseArgs(process.argv);
|
|
1501
|
+
try {
|
|
1502
|
+
enableConfigs();
|
|
1503
|
+
} catch (e) {
|
|
1504
|
+
logError(e);
|
|
1505
|
+
}
|
|
1506
|
+
const config = getGlobalConfig();
|
|
1507
|
+
if (!config.hasCompletedOnboarding) {
|
|
1508
|
+
await showSetupScreens(opts.safeMode);
|
|
1509
|
+
}
|
|
1112
1510
|
if (opts.name || opts.description) {
|
|
1113
1511
|
setIdentity({
|
|
1114
1512
|
...opts.name ? { name: opts.name } : {},
|
|
@@ -1154,11 +1552,59 @@ async function main() {
|
|
|
1154
1552
|
const cliChannel = new CliChannel({ prompt: `[${opts.name ?? "NewCraw"}] > ` });
|
|
1155
1553
|
gateway.registerChannel(cliChannel);
|
|
1156
1554
|
}
|
|
1555
|
+
const { pool: sandboxPool, capabilities: sandboxCaps } = await tryInitSandboxPool();
|
|
1556
|
+
if (sandboxPool) {
|
|
1557
|
+
console.log(`[Gateway] Container sandbox ready: ${sandboxCaps.name} (${sandboxCaps.version ?? "unknown"})${sandboxCaps.rootless ? " [rootless]" : ""}`);
|
|
1558
|
+
} else {
|
|
1559
|
+
console.log(`[Gateway] Container sandbox not available (bwrap/sandbox-exec fallback active)`);
|
|
1560
|
+
}
|
|
1561
|
+
registerHealthProbe(async (provider) => {
|
|
1562
|
+
try {
|
|
1563
|
+
const { getModelManager } = await import("./model-JNWAZGT7.js");
|
|
1564
|
+
const manager = getModelManager();
|
|
1565
|
+
const profiles = [
|
|
1566
|
+
manager.getModel("main"),
|
|
1567
|
+
manager.getModel("task"),
|
|
1568
|
+
manager.getModel("quick")
|
|
1569
|
+
].filter(Boolean);
|
|
1570
|
+
const match = profiles.find((p) => p?.provider === provider);
|
|
1571
|
+
if (!match) return true;
|
|
1572
|
+
const OpenAI = (await import("openai")).default;
|
|
1573
|
+
const client = new OpenAI({
|
|
1574
|
+
apiKey: match.apiKey ?? process.env.OPENAI_API_KEY ?? "sk-probe",
|
|
1575
|
+
baseURL: match.baseUrl,
|
|
1576
|
+
timeout: 1e4
|
|
1577
|
+
});
|
|
1578
|
+
await client.models.list();
|
|
1579
|
+
return true;
|
|
1580
|
+
} catch {
|
|
1581
|
+
return false;
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
try {
|
|
1585
|
+
const { getModelManager } = await import("./model-JNWAZGT7.js");
|
|
1586
|
+
const manager = getModelManager();
|
|
1587
|
+
const providerSet = /* @__PURE__ */ new Set();
|
|
1588
|
+
for (const role of ["main", "task", "quick"]) {
|
|
1589
|
+
const profile = manager.getModel(role);
|
|
1590
|
+
if (profile && profile.provider) {
|
|
1591
|
+
providerSet.add(profile.provider);
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
if (providerSet.size > 0) {
|
|
1595
|
+
startPeriodicHealthCheck([...providerSet]);
|
|
1596
|
+
}
|
|
1597
|
+
} catch {
|
|
1598
|
+
}
|
|
1157
1599
|
process.on("SIGINT", async () => {
|
|
1600
|
+
stopPeriodicHealthCheck();
|
|
1601
|
+
await shutdownSandboxPool();
|
|
1158
1602
|
await gateway.stop();
|
|
1159
1603
|
process.exit(0);
|
|
1160
1604
|
});
|
|
1161
1605
|
process.on("SIGTERM", async () => {
|
|
1606
|
+
stopPeriodicHealthCheck();
|
|
1607
|
+
await shutdownSandboxPool();
|
|
1162
1608
|
await gateway.stop();
|
|
1163
1609
|
process.exit(0);
|
|
1164
1610
|
});
|