newcraw 1.0.2 → 1.0.4

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.
Files changed (220) hide show
  1. package/dist/REPL-DECTPCL5.js +50 -0
  2. package/dist/{acp-J4WDYGRX.js → acp-HA476EHW.js} +69 -40
  3. package/dist/acp-HA476EHW.js.map +7 -0
  4. package/dist/{agentsValidate-UBOER2IN.js → agentsValidate-EDPFUUMG.js} +13 -10
  5. package/dist/{agentsValidate-UBOER2IN.js.map → agentsValidate-EDPFUUMG.js.map} +1 -1
  6. package/dist/{ask-MGUO3L35.js → ask-5SP4YYRD.js} +62 -52
  7. package/dist/ask-5SP4YYRD.js.map +7 -0
  8. package/dist/{autoUpdater-2GS6LRPK.js → autoUpdater-FFMM2DR7.js} +5 -4
  9. package/dist/chunk-2BVCVKKB.js +135 -0
  10. package/dist/chunk-2BVCVKKB.js.map +7 -0
  11. package/dist/{chunk-2C43OXE7.js → chunk-2JCTO2EY.js} +38 -59
  12. package/dist/chunk-2JCTO2EY.js.map +7 -0
  13. package/dist/{chunk-OJIMOLIC.js → chunk-3CKC4ABU.js} +3631 -7464
  14. package/dist/chunk-3CKC4ABU.js.map +7 -0
  15. package/dist/chunk-ARCEUG3V.js +88 -0
  16. package/dist/chunk-ARCEUG3V.js.map +7 -0
  17. package/dist/{chunk-RUXIBQ3B.js → chunk-BJYXLCRS.js} +4 -4
  18. package/dist/{chunk-VKI7ORIO.js → chunk-BMKE6FT5.js} +37 -18
  19. package/dist/{chunk-VKI7ORIO.js.map → chunk-BMKE6FT5.js.map} +1 -1
  20. package/dist/chunk-BQCOSNM3.js +93 -0
  21. package/dist/chunk-BQCOSNM3.js.map +7 -0
  22. package/dist/chunk-CHB5K4GI.js +107 -0
  23. package/dist/chunk-CHB5K4GI.js.map +7 -0
  24. package/dist/chunk-D4OZACS2.js +35 -0
  25. package/dist/chunk-EHQ2M5B4.js +166 -0
  26. package/dist/{chunk-ZYSVG4X3.js.map → chunk-EHQ2M5B4.js.map} +2 -2
  27. package/dist/chunk-EUBZGAIN.js +372 -0
  28. package/dist/chunk-EUBZGAIN.js.map +7 -0
  29. package/dist/{chunk-UYRR6F5S.js → chunk-FIMCETCB.js} +9 -3
  30. package/dist/{chunk-UYRR6F5S.js.map → chunk-FIMCETCB.js.map} +1 -1
  31. package/dist/{chunk-DEF3KFP7.js → chunk-GVLJUD6R.js} +4 -2
  32. package/dist/{chunk-DEF3KFP7.js.map → chunk-GVLJUD6R.js.map} +1 -1
  33. package/dist/chunk-HLBLZKZH.js +45 -0
  34. package/dist/chunk-HLBLZKZH.js.map +7 -0
  35. package/dist/{chunk-XS6PU75S.js → chunk-IVWPPTDM.js} +1 -1
  36. package/dist/{chunk-A7X6OCZE.js → chunk-IXFBUXQW.js} +1 -1
  37. package/dist/{chunk-HSJ6HYAO.js → chunk-IZZTKEZH.js} +18 -10
  38. package/dist/chunk-IZZTKEZH.js.map +7 -0
  39. package/dist/{chunk-2EFL22PV.js → chunk-JI4HCLK7.js} +7 -3
  40. package/dist/chunk-JI4HCLK7.js.map +7 -0
  41. package/dist/chunk-JLVECHVJ.js +36 -0
  42. package/dist/chunk-JLVECHVJ.js.map +7 -0
  43. package/dist/{chunk-XXU2NVOE.js → chunk-KJTPUTU7.js} +30 -6
  44. package/dist/chunk-KJTPUTU7.js.map +7 -0
  45. package/dist/{chunk-V5U6BHT2.js → chunk-KS646CDL.js} +7 -3
  46. package/dist/{chunk-V5U6BHT2.js.map → chunk-KS646CDL.js.map} +1 -1
  47. package/dist/{chunk-53A4JHFW.js → chunk-MJ3MLGVB.js} +23 -4
  48. package/dist/chunk-MJ3MLGVB.js.map +7 -0
  49. package/dist/chunk-MJLWBVZP.js +822 -0
  50. package/dist/chunk-MJLWBVZP.js.map +7 -0
  51. package/dist/chunk-MMF5RMLU.js +65 -0
  52. package/dist/chunk-MMF5RMLU.js.map +7 -0
  53. package/dist/{chunk-QH2M65BR.js → chunk-MUW3J7CP.js} +7 -3
  54. package/dist/{chunk-QH2M65BR.js.map → chunk-MUW3J7CP.js.map} +1 -1
  55. package/dist/{chunk-3LMXSKZ7.js → chunk-NFXLN6FJ.js} +1 -1
  56. package/dist/chunk-NT7RDVDA.js +33 -0
  57. package/dist/{chunk-KQSHIOZK.js.map → chunk-NT7RDVDA.js.map} +1 -1
  58. package/dist/{chunk-OZHBEG7U.js → chunk-O4EKE3YR.js} +15 -5
  59. package/dist/{chunk-OZHBEG7U.js.map → chunk-O4EKE3YR.js.map} +1 -1
  60. package/dist/chunk-Q2OBTLBI.js +5473 -0
  61. package/dist/chunk-Q2OBTLBI.js.map +7 -0
  62. package/dist/{chunk-WWDVA4NV.js → chunk-QJ7MQIHN.js} +22 -6
  63. package/dist/{chunk-WWDVA4NV.js.map → chunk-QJ7MQIHN.js.map} +1 -1
  64. package/dist/{chunk-N5OHRWG2.js → chunk-QSRXXZO7.js} +4 -2
  65. package/dist/{chunk-N5OHRWG2.js.map → chunk-QSRXXZO7.js.map} +1 -1
  66. package/dist/{chunk-GZTCXXSS.js → chunk-QT5GS374.js} +57 -46
  67. package/dist/{chunk-GZTCXXSS.js.map → chunk-QT5GS374.js.map} +1 -1
  68. package/dist/chunk-QX5Y5CE5.js +683 -0
  69. package/dist/{chunk-F3COCCAE.js.map → chunk-QX5Y5CE5.js.map} +1 -1
  70. package/dist/{chunk-IIFUDVGS.js → chunk-U6IF5D3J.js} +310 -177
  71. package/dist/chunk-U6IF5D3J.js.map +7 -0
  72. package/dist/{chunk-VQSCECTS.js → chunk-UPRKGNBR.js} +6 -4
  73. package/dist/{chunk-VQSCECTS.js.map → chunk-UPRKGNBR.js.map} +1 -1
  74. package/dist/chunk-UUCRNFMH.js +62 -0
  75. package/dist/chunk-UUCRNFMH.js.map +7 -0
  76. package/dist/chunk-UYWZQVH5.js +35 -0
  77. package/dist/chunk-UYWZQVH5.js.map +7 -0
  78. package/dist/{chunk-XMGUQHMF.js → chunk-VSSVN6WG.js} +11 -1
  79. package/dist/chunk-VSSVN6WG.js.map +7 -0
  80. package/dist/{chunk-VHS2MZQS.js → chunk-W7Q3VYAB.js} +9 -6
  81. package/dist/{chunk-VHS2MZQS.js.map → chunk-W7Q3VYAB.js.map} +1 -1
  82. package/dist/{chunk-JWXQNBBA.js → chunk-WAXMRSVR.js} +7 -1
  83. package/dist/{chunk-JWXQNBBA.js.map → chunk-WAXMRSVR.js.map} +1 -1
  84. package/dist/{chunk-BWYKUDJR.js → chunk-X3NER6FY.js} +14 -8
  85. package/dist/{chunk-BWYKUDJR.js.map → chunk-X3NER6FY.js.map} +1 -1
  86. package/dist/{chunk-IM33F5CM.js → chunk-XYQZLDRB.js} +1668 -1623
  87. package/dist/chunk-XYQZLDRB.js.map +7 -0
  88. package/dist/{chunk-LOIZNQOU.js → chunk-ZM5FMRLS.js} +9 -3
  89. package/dist/{chunk-LOIZNQOU.js.map → chunk-ZM5FMRLS.js.map} +1 -1
  90. package/dist/{chunk-755HIAI3.js → chunk-ZMO4E7IW.js} +3 -42
  91. package/dist/chunk-ZMO4E7IW.js.map +7 -0
  92. package/dist/{cli-KZGF3FV5.js → cli-4KO6TA5J.js} +251 -485
  93. package/dist/cli-4KO6TA5J.js.map +7 -0
  94. package/dist/commands-JSY7CGSU.js +54 -0
  95. package/dist/{config-GTJWCNPF.js → config-DQEFVW3Y.js} +9 -6
  96. package/dist/{context-WF3TTXQU.js → context-HVQCTO5R.js} +8 -7
  97. package/dist/{costTracker-2G3ZI2JF.js → costTracker-VSWW7SRT.js} +3 -2
  98. package/dist/{customCommands-QOWK57EX.js → customCommands-XCINU5TG.js} +6 -5
  99. package/dist/{env-37BAP7QF.js → env-ZOPEXWMF.js} +10 -7
  100. package/dist/{gateway-IZYO6YFJ.js → gateway-SUXSILQL.js} +542 -96
  101. package/dist/gateway-SUXSILQL.js.map +7 -0
  102. package/dist/identity-3KZQQVBG.js +16 -0
  103. package/dist/index.js +8 -6
  104. package/dist/index.js.map +1 -1
  105. package/dist/{kodeAgentSessionId-KTGFX2BE.js → kodeAgentSessionId-4SH24DVH.js} +1 -1
  106. package/dist/{kodeAgentSessionLoad-6F7SJXBC.js → kodeAgentSessionLoad-HB3BYVNG.js} +6 -5
  107. package/dist/{kodeAgentSessionResume-UEEDRJ3N.js → kodeAgentSessionResume-IGSZZY3G.js} +6 -5
  108. package/dist/{kodeAgentStreamJson-VIXFTYL5.js → kodeAgentStreamJson-4ZKIWKS3.js} +4 -2
  109. package/dist/{kodeAgentStreamJsonSession-XC3IPREZ.js → kodeAgentStreamJsonSession-4L76UC75.js} +15 -4
  110. package/dist/kodeAgentStreamJsonSession-4L76UC75.js.map +7 -0
  111. package/dist/{kodeAgentStructuredStdio-SI5C7AAD.js → kodeAgentStructuredStdio-5DCUC6V6.js} +3 -3
  112. package/dist/{kodeHooks-V36SHCTC.js → kodeHooks-H6DMC3XX.js} +6 -5
  113. package/dist/{llm-CYUDKJNR.js → llm-OJZ6DZVC.js} +306 -60
  114. package/dist/llm-OJZ6DZVC.js.map +7 -0
  115. package/dist/{llmLazy-IXVVBRTN.js → llmLazy-TDLZZDPL.js} +2 -2
  116. package/dist/{loader-OEJ6C3TN.js → loader-MOVYZ76M.js} +6 -5
  117. package/dist/{mcp-KE3SILMX.js → mcp-DUYSIR5L.js} +10 -9
  118. package/dist/{mentionProcessor-GAU2WAYB.js → mentionProcessor-EKVLXJN4.js} +14 -7
  119. package/dist/{mentionProcessor-GAU2WAYB.js.map → mentionProcessor-EKVLXJN4.js.map} +1 -1
  120. package/dist/{messages-WCSGGSEU.js → messages-23ICFVMC.js} +2 -2
  121. package/dist/{model-4TQIV5J2.js → model-FUBCTRTV.js} +10 -7
  122. package/dist/{openai-KTZV6F7N.js → openai-SMYIAIO4.js} +8 -7
  123. package/dist/{outputStyles-WX5RYQOA.js → outputStyles-HBOYJFBE.js} +6 -5
  124. package/dist/{pluginRuntime-JXMJZ2LC.js → pluginRuntime-ATZMDZA7.js} +11 -8
  125. package/dist/{pluginRuntime-JXMJZ2LC.js.map → pluginRuntime-ATZMDZA7.js.map} +1 -1
  126. package/dist/{pluginValidation-JNQZYLUP.js → pluginValidation-7CGOMT6F.js} +8 -7
  127. package/dist/prompts-MFESKNYZ.js +58 -0
  128. package/dist/query-BFEFOX4S.js +58 -0
  129. package/dist/{responsesStreaming-2AIT6GHG.js → responsesStreaming-JORGEFQC.js} +1 -1
  130. package/dist/{ripgrep-KDPQAMB2.js → ripgrep-KNJBCJIQ.js} +5 -4
  131. package/dist/sandbox-P3FR4G4D.js +63 -0
  132. package/dist/{skillMarketplace-IXAGP3Q2.js → skillMarketplace-PCMKVV4O.js} +5 -4
  133. package/dist/{state-MSCYLB6Y.js → state-XBYIQ7R4.js} +6 -3
  134. package/dist/structuredOutput-KAVFUV2Z.js +9 -0
  135. package/dist/theme-4ZSXUILR.js +15 -0
  136. package/dist/thinking-TTNUZUB3.js +18 -0
  137. package/dist/{toolPermissionContext-I3IXPVED.js → toolPermissionContext-JCQ5MFUT.js} +1 -1
  138. package/dist/toolPermissionContext-JCQ5MFUT.js.map +7 -0
  139. package/dist/toolPermissionContextState-R6ZGMKP6.js +24 -0
  140. package/dist/toolPermissionContextState-R6ZGMKP6.js.map +7 -0
  141. package/dist/{toolPermissionSettings-EUZKGZU2.js → toolPermissionSettings-GMEYTJEA.js} +9 -8
  142. package/dist/toolPermissionSettings-GMEYTJEA.js.map +7 -0
  143. package/dist/tools-7FVKB7BG.js +55 -0
  144. package/dist/tools-7FVKB7BG.js.map +7 -0
  145. package/dist/{userInput-LJL4CVOB.js → userInput-SZEUY5J6.js} +49 -34
  146. package/dist/{userInput-LJL4CVOB.js.map → userInput-SZEUY5J6.js.map} +1 -1
  147. package/dist/{uuid-VA3KVASX.js → uuid-RQH3OZ3W.js} +1 -1
  148. package/dist/uuid-RQH3OZ3W.js.map +7 -0
  149. package/dist/workspace-EP63OB5S.js +21 -0
  150. package/dist/workspace-EP63OB5S.js.map +7 -0
  151. package/package.json +2 -2
  152. package/web/dist/assets/index-XuLVvSQF.js +251 -0
  153. package/web/dist/assets/index-pSid9IlY.css +10 -0
  154. package/web/dist/index.html +2 -2
  155. package/dist/REPL-IAK7ZN2Z.js +0 -42
  156. package/dist/acp-J4WDYGRX.js.map +0 -7
  157. package/dist/ask-MGUO3L35.js.map +0 -7
  158. package/dist/chunk-2C43OXE7.js.map +0 -7
  159. package/dist/chunk-2EFL22PV.js.map +0 -7
  160. package/dist/chunk-53A4JHFW.js.map +0 -7
  161. package/dist/chunk-755HIAI3.js.map +0 -7
  162. package/dist/chunk-AXWJI6N5.js +0 -11
  163. package/dist/chunk-F3COCCAE.js +0 -654
  164. package/dist/chunk-HSJ6HYAO.js.map +0 -7
  165. package/dist/chunk-IIFUDVGS.js.map +0 -7
  166. package/dist/chunk-IM33F5CM.js.map +0 -7
  167. package/dist/chunk-KQSHIOZK.js +0 -24
  168. package/dist/chunk-OJIMOLIC.js.map +0 -7
  169. package/dist/chunk-XMGUQHMF.js.map +0 -7
  170. package/dist/chunk-XXU2NVOE.js.map +0 -7
  171. package/dist/chunk-ZYSVG4X3.js +0 -151
  172. package/dist/cli-KZGF3FV5.js.map +0 -7
  173. package/dist/commands-AVEBLFVS.js +0 -46
  174. package/dist/gateway-IZYO6YFJ.js.map +0 -7
  175. package/dist/kodeAgentStreamJsonSession-XC3IPREZ.js.map +0 -7
  176. package/dist/llm-CYUDKJNR.js.map +0 -7
  177. package/dist/prompts-LE6GK75N.js +0 -48
  178. package/dist/query-GGIP6PWG.js +0 -50
  179. package/dist/theme-GAMFOLBW.js +0 -14
  180. package/dist/tools-3HOUIDM3.js +0 -47
  181. package/web/dist/assets/index-COAJqX1Z.css +0 -1
  182. package/web/dist/assets/index-CzS_4LmC.js +0 -179
  183. /package/dist/{REPL-IAK7ZN2Z.js.map → REPL-DECTPCL5.js.map} +0 -0
  184. /package/dist/{autoUpdater-2GS6LRPK.js.map → autoUpdater-FFMM2DR7.js.map} +0 -0
  185. /package/dist/{chunk-RUXIBQ3B.js.map → chunk-BJYXLCRS.js.map} +0 -0
  186. /package/dist/{chunk-AXWJI6N5.js.map → chunk-D4OZACS2.js.map} +0 -0
  187. /package/dist/{chunk-XS6PU75S.js.map → chunk-IVWPPTDM.js.map} +0 -0
  188. /package/dist/{chunk-A7X6OCZE.js.map → chunk-IXFBUXQW.js.map} +0 -0
  189. /package/dist/{chunk-3LMXSKZ7.js.map → chunk-NFXLN6FJ.js.map} +0 -0
  190. /package/dist/{commands-AVEBLFVS.js.map → commands-JSY7CGSU.js.map} +0 -0
  191. /package/dist/{config-GTJWCNPF.js.map → config-DQEFVW3Y.js.map} +0 -0
  192. /package/dist/{context-WF3TTXQU.js.map → context-HVQCTO5R.js.map} +0 -0
  193. /package/dist/{costTracker-2G3ZI2JF.js.map → costTracker-VSWW7SRT.js.map} +0 -0
  194. /package/dist/{customCommands-QOWK57EX.js.map → customCommands-XCINU5TG.js.map} +0 -0
  195. /package/dist/{env-37BAP7QF.js.map → env-ZOPEXWMF.js.map} +0 -0
  196. /package/dist/{kodeAgentSessionId-KTGFX2BE.js.map → identity-3KZQQVBG.js.map} +0 -0
  197. /package/dist/{kodeAgentSessionLoad-6F7SJXBC.js.map → kodeAgentSessionId-4SH24DVH.js.map} +0 -0
  198. /package/dist/{kodeAgentSessionResume-UEEDRJ3N.js.map → kodeAgentSessionLoad-HB3BYVNG.js.map} +0 -0
  199. /package/dist/{kodeAgentStreamJson-VIXFTYL5.js.map → kodeAgentSessionResume-IGSZZY3G.js.map} +0 -0
  200. /package/dist/{kodeAgentStructuredStdio-SI5C7AAD.js.map → kodeAgentStreamJson-4ZKIWKS3.js.map} +0 -0
  201. /package/dist/{kodeHooks-V36SHCTC.js.map → kodeAgentStructuredStdio-5DCUC6V6.js.map} +0 -0
  202. /package/dist/{llmLazy-IXVVBRTN.js.map → kodeHooks-H6DMC3XX.js.map} +0 -0
  203. /package/dist/{loader-OEJ6C3TN.js.map → llmLazy-TDLZZDPL.js.map} +0 -0
  204. /package/dist/{mcp-KE3SILMX.js.map → loader-MOVYZ76M.js.map} +0 -0
  205. /package/dist/{messages-WCSGGSEU.js.map → mcp-DUYSIR5L.js.map} +0 -0
  206. /package/dist/{model-4TQIV5J2.js.map → messages-23ICFVMC.js.map} +0 -0
  207. /package/dist/{openai-KTZV6F7N.js.map → model-FUBCTRTV.js.map} +0 -0
  208. /package/dist/{outputStyles-WX5RYQOA.js.map → openai-SMYIAIO4.js.map} +0 -0
  209. /package/dist/{pluginValidation-JNQZYLUP.js.map → outputStyles-HBOYJFBE.js.map} +0 -0
  210. /package/dist/{prompts-LE6GK75N.js.map → pluginValidation-7CGOMT6F.js.map} +0 -0
  211. /package/dist/{query-GGIP6PWG.js.map → prompts-MFESKNYZ.js.map} +0 -0
  212. /package/dist/{responsesStreaming-2AIT6GHG.js.map → query-BFEFOX4S.js.map} +0 -0
  213. /package/dist/{ripgrep-KDPQAMB2.js.map → responsesStreaming-JORGEFQC.js.map} +0 -0
  214. /package/dist/{skillMarketplace-IXAGP3Q2.js.map → ripgrep-KNJBCJIQ.js.map} +0 -0
  215. /package/dist/{state-MSCYLB6Y.js.map → sandbox-P3FR4G4D.js.map} +0 -0
  216. /package/dist/{theme-GAMFOLBW.js.map → skillMarketplace-PCMKVV4O.js.map} +0 -0
  217. /package/dist/{toolPermissionContext-I3IXPVED.js.map → state-XBYIQ7R4.js.map} +0 -0
  218. /package/dist/{toolPermissionSettings-EUZKGZU2.js.map → structuredOutput-KAVFUV2Z.js.map} +0 -0
  219. /package/dist/{tools-3HOUIDM3.js.map → theme-4ZSXUILR.js.map} +0 -0
  220. /package/dist/{uuid-VA3KVASX.js.map → thinking-TTNUZUB3.js.map} +0 -0
@@ -0,0 +1,683 @@
1
+ import { createRequire as __newcrawCreateRequire } from "node:module";
2
+ const require = __newcrawCreateRequire(import.meta.url);
3
+ import {
4
+ getGlobalConfig,
5
+ init_config,
6
+ saveGlobalConfig
7
+ } from "./chunk-U6IF5D3J.js";
8
+ import {
9
+ debug,
10
+ init_debugLogger
11
+ } from "./chunk-QT5GS374.js";
12
+ import {
13
+ init_log,
14
+ logError
15
+ } from "./chunk-XYQZLDRB.js";
16
+ import {
17
+ __esm,
18
+ __export
19
+ } from "./chunk-D4OZACS2.js";
20
+
21
+ // src/utils/model/index.ts
22
+ var model_exports = {};
23
+ __export(model_exports, {
24
+ ModelManager: () => ModelManager,
25
+ USE_BEDROCK: () => USE_BEDROCK,
26
+ USE_VERTEX: () => USE_VERTEX,
27
+ getModelManager: () => getModelManager,
28
+ getQuickModel: () => getQuickModel,
29
+ getSlowAndCapableModel: () => getSlowAndCapableModel,
30
+ getVertexRegionForModel: () => getVertexRegionForModel,
31
+ isDefaultSlowAndCapableModel: () => isDefaultSlowAndCapableModel,
32
+ reloadModelManager: () => reloadModelManager
33
+ });
34
+ import { memoize } from "lodash-es";
35
+ async function getModelConfig() {
36
+ return DEFAULT_MODEL_CONFIG;
37
+ }
38
+ async function isDefaultSlowAndCapableModel() {
39
+ return !process.env.ANTHROPIC_MODEL || process.env.ANTHROPIC_MODEL === await getSlowAndCapableModel();
40
+ }
41
+ function getVertexRegionForModel(model) {
42
+ if (model?.startsWith("claude-3-5-haiku")) {
43
+ return process.env.VERTEX_REGION_CLAUDE_3_5_HAIKU;
44
+ } else if (model?.startsWith("claude-3-5-sonnet")) {
45
+ return process.env.VERTEX_REGION_CLAUDE_3_5_SONNET;
46
+ } else if (model?.startsWith("claude-3-7-sonnet")) {
47
+ return process.env.VERTEX_REGION_CLAUDE_3_7_SONNET;
48
+ }
49
+ }
50
+ var USE_BEDROCK, USE_VERTEX, DEFAULT_MODEL_CONFIG, getSlowAndCapableModel, ModelManager, globalModelManager, getModelManager, reloadModelManager, getQuickModel;
51
+ var init_model = __esm({
52
+ "src/utils/model/index.ts"() {
53
+ init_log();
54
+ init_debugLogger();
55
+ init_config();
56
+ USE_BEDROCK = !!(process.env.NEWCRAW_USE_BEDROCK ?? process.env.CLAUDE_CODE_USE_BEDROCK);
57
+ USE_VERTEX = !!(process.env.NEWCRAW_USE_VERTEX ?? process.env.CLAUDE_CODE_USE_VERTEX);
58
+ DEFAULT_MODEL_CONFIG = {
59
+ bedrock: "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
60
+ vertex: "claude-3-7-sonnet@20250219",
61
+ firstParty: "claude-sonnet-4-20250514"
62
+ };
63
+ getSlowAndCapableModel = memoize(async () => {
64
+ const config = await getGlobalConfig();
65
+ const modelManager = new ModelManager(config);
66
+ const model = modelManager.getMainAgentModel();
67
+ if (model) {
68
+ return model;
69
+ }
70
+ const modelConfig = await getModelConfig();
71
+ if (USE_BEDROCK) return modelConfig.bedrock;
72
+ if (USE_VERTEX) return modelConfig.vertex;
73
+ return modelConfig.firstParty;
74
+ });
75
+ ModelManager = class {
76
+ config;
77
+ modelProfiles;
78
+ constructor(config) {
79
+ this.config = config;
80
+ this.modelProfiles = config.modelProfiles || [];
81
+ }
82
+ getCurrentModel() {
83
+ const mainModelName = this.config.modelPointers?.main;
84
+ if (mainModelName) {
85
+ const profile = this.findModelProfile(mainModelName);
86
+ if (profile && profile.isActive) {
87
+ return profile.modelName;
88
+ }
89
+ }
90
+ return this.getMainAgentModel();
91
+ }
92
+ getMainAgentModel() {
93
+ const mainModelName = this.config.modelPointers?.main;
94
+ if (mainModelName) {
95
+ const profile = this.findModelProfile(mainModelName);
96
+ if (profile && profile.isActive) {
97
+ return profile.modelName;
98
+ }
99
+ }
100
+ const activeProfile = this.modelProfiles.find((p) => p.isActive);
101
+ if (activeProfile) {
102
+ return activeProfile.modelName;
103
+ }
104
+ return null;
105
+ }
106
+ getTaskToolModel() {
107
+ const taskModelName = this.config.modelPointers?.task;
108
+ if (taskModelName) {
109
+ const profile = this.findModelProfile(taskModelName);
110
+ if (profile && profile.isActive) {
111
+ return profile.modelName;
112
+ }
113
+ }
114
+ return this.getMainAgentModel();
115
+ }
116
+ switchToNextModelWithContextCheck(currentContextTokens = 0) {
117
+ const allProfiles = this.getAllConfiguredModels();
118
+ if (allProfiles.length === 0) {
119
+ return {
120
+ success: false,
121
+ modelName: null,
122
+ previousModelName: null,
123
+ contextOverflow: false,
124
+ usagePercentage: 0,
125
+ currentContextTokens
126
+ };
127
+ }
128
+ allProfiles.sort((a, b) => a.createdAt - b.createdAt);
129
+ const currentMainModelName = this.config.modelPointers?.main;
130
+ const currentModel = currentMainModelName ? this.findModelProfile(currentMainModelName) : null;
131
+ const previousModelName = currentModel?.name || null;
132
+ const budgetForModel = (model) => {
133
+ const contextLength = Number(model.contextLength);
134
+ if (!Number.isFinite(contextLength) || contextLength <= 0) {
135
+ return { budgetTokens: null, usagePercentage: 0, compatible: true };
136
+ }
137
+ const budgetTokens = Math.floor(contextLength * 0.9);
138
+ const usagePercentage = budgetTokens > 0 ? currentContextTokens / budgetTokens * 100 : 0;
139
+ return {
140
+ budgetTokens,
141
+ usagePercentage,
142
+ compatible: budgetTokens > 0 ? currentContextTokens <= budgetTokens : true
143
+ };
144
+ };
145
+ const currentIndex = currentMainModelName ? allProfiles.findIndex((p) => p.modelName === currentMainModelName) : -1;
146
+ const startIndex = currentIndex >= 0 ? currentIndex : -1;
147
+ if (allProfiles.length === 1) {
148
+ return {
149
+ success: false,
150
+ modelName: null,
151
+ previousModelName,
152
+ contextOverflow: false,
153
+ usagePercentage: 0,
154
+ currentContextTokens
155
+ };
156
+ }
157
+ const maxOffsets = startIndex === -1 ? allProfiles.length : allProfiles.length - 1;
158
+ const skippedModels = [];
159
+ let selected = null;
160
+ let selectedUsagePercentage = 0;
161
+ for (let offset = 1; offset <= maxOffsets; offset++) {
162
+ const candidateIndex = (startIndex + offset + allProfiles.length) % allProfiles.length;
163
+ const candidate = allProfiles[candidateIndex];
164
+ if (!candidate) continue;
165
+ const { budgetTokens, usagePercentage, compatible } = budgetForModel(candidate);
166
+ if (compatible) {
167
+ selected = candidate;
168
+ selectedUsagePercentage = usagePercentage;
169
+ break;
170
+ }
171
+ skippedModels.push({
172
+ name: candidate.name,
173
+ provider: candidate.provider,
174
+ contextLength: candidate.contextLength,
175
+ budgetTokens,
176
+ usagePercentage
177
+ });
178
+ }
179
+ if (!selected) {
180
+ const firstSkipped = skippedModels[0];
181
+ return {
182
+ success: false,
183
+ modelName: null,
184
+ previousModelName,
185
+ contextOverflow: true,
186
+ usagePercentage: firstSkipped?.usagePercentage ?? 0,
187
+ currentContextTokens,
188
+ skippedModels
189
+ };
190
+ }
191
+ if (!selected.isActive) {
192
+ selected.isActive = true;
193
+ }
194
+ this.setPointer("main", selected.modelName);
195
+ this.updateLastUsed(selected.modelName);
196
+ return {
197
+ success: true,
198
+ modelName: selected.name,
199
+ previousModelName,
200
+ contextOverflow: false,
201
+ usagePercentage: selectedUsagePercentage,
202
+ currentContextTokens,
203
+ skippedModels
204
+ };
205
+ }
206
+ switchToNextModel(currentContextTokens = 0) {
207
+ const result = this.switchToNextModelWithContextCheck(currentContextTokens);
208
+ const formatTokens = (tokens) => {
209
+ if (!Number.isFinite(tokens)) return "unknown";
210
+ if (tokens >= 1e3) return `${Math.round(tokens / 1e3)}k`;
211
+ return String(Math.round(tokens));
212
+ };
213
+ const allModels = this.getAllConfiguredModels();
214
+ if (allModels.length === 0) {
215
+ return {
216
+ success: false,
217
+ modelName: null,
218
+ blocked: false,
219
+ message: "\u274C No models configured. Use /model to add models."
220
+ };
221
+ }
222
+ if (allModels.length === 1) {
223
+ return {
224
+ success: false,
225
+ modelName: null,
226
+ blocked: false,
227
+ message: `\u26A0\uFE0F Only one model configured (${allModels[0].modelName}). Use /model to add more models for switching.`
228
+ };
229
+ }
230
+ const currentModel = this.findModelProfile(this.config.modelPointers?.main);
231
+ const modelsSorted = [...allModels].sort(
232
+ (a, b) => a.createdAt - b.createdAt
233
+ );
234
+ const currentIndex = modelsSorted.findIndex(
235
+ (m) => m.modelName === currentModel?.modelName
236
+ );
237
+ const totalModels = modelsSorted.length;
238
+ if (result.success && result.modelName) {
239
+ const skippedCount = result.skippedModels?.length ?? 0;
240
+ const skippedSuffix = skippedCount > 0 ? ` \xB7 skipped ${skippedCount} incompatible` : "";
241
+ const contextSuffix = currentModel?.contextLength && result.currentContextTokens ? ` \xB7 context ~${formatTokens(result.currentContextTokens)}/${formatTokens(currentModel.contextLength)}` : "";
242
+ return {
243
+ success: true,
244
+ modelName: result.modelName,
245
+ blocked: false,
246
+ message: `\u2705 Switched to ${result.modelName} (${currentIndex + 1}/${totalModels})${currentModel?.provider ? ` [${currentModel.provider}]` : ""}${skippedSuffix}${contextSuffix}`
247
+ };
248
+ }
249
+ if (result.contextOverflow) {
250
+ const attempted = result.skippedModels?.[0];
251
+ const attemptedContext = attempted?.contextLength;
252
+ const attemptedBudget = attempted?.budgetTokens;
253
+ const currentLabel = currentModel?.name || currentModel?.modelName || "current model";
254
+ const attemptedText = attempted ? `Can't switch to ${attempted.name}: current ~${formatTokens(result.currentContextTokens)} tokens exceeds safe budget (~${formatTokens(attemptedBudget ?? 0)} tokens, 90% of ${formatTokens(attemptedContext ?? 0)}).` : `Can't switch models due to context size (~${formatTokens(result.currentContextTokens)} tokens).`;
255
+ return {
256
+ success: false,
257
+ modelName: null,
258
+ blocked: true,
259
+ message: `\u26A0\uFE0F ${attemptedText} Keeping ${currentLabel}.`
260
+ };
261
+ }
262
+ return {
263
+ success: false,
264
+ modelName: null,
265
+ blocked: false,
266
+ message: "\u274C Failed to switch models"
267
+ };
268
+ }
269
+ revertToPreviousModel(previousModelName) {
270
+ const previousModel = this.modelProfiles.find(
271
+ (p) => p.name === previousModelName && p.isActive
272
+ );
273
+ if (!previousModel) {
274
+ return false;
275
+ }
276
+ this.setPointer("main", previousModel.modelName);
277
+ this.updateLastUsed(previousModel.modelName);
278
+ return true;
279
+ }
280
+ analyzeContextCompatibility(model, contextTokens) {
281
+ const usableContext = Math.floor(model.contextLength * 0.8);
282
+ const usagePercentage = contextTokens / usableContext * 100;
283
+ if (usagePercentage <= 70) {
284
+ return {
285
+ compatible: true,
286
+ severity: "safe",
287
+ usagePercentage,
288
+ recommendation: "Full context preserved"
289
+ };
290
+ } else if (usagePercentage <= 90) {
291
+ return {
292
+ compatible: true,
293
+ severity: "warning",
294
+ usagePercentage,
295
+ recommendation: "Context usage high, consider compression"
296
+ };
297
+ } else {
298
+ return {
299
+ compatible: false,
300
+ severity: "critical",
301
+ usagePercentage,
302
+ recommendation: "Auto-compression or message truncation required"
303
+ };
304
+ }
305
+ }
306
+ switchToNextModelWithAnalysis(currentContextTokens = 0) {
307
+ const result = this.switchToNextModel(currentContextTokens);
308
+ if (!result.success || !result.modelName) {
309
+ return {
310
+ modelName: null,
311
+ contextAnalysis: null,
312
+ requiresCompression: false,
313
+ estimatedTokensAfterSwitch: 0
314
+ };
315
+ }
316
+ const newModel = this.getModel("main");
317
+ if (!newModel) {
318
+ return {
319
+ modelName: result.modelName,
320
+ contextAnalysis: null,
321
+ requiresCompression: false,
322
+ estimatedTokensAfterSwitch: currentContextTokens
323
+ };
324
+ }
325
+ const analysis = this.analyzeContextCompatibility(
326
+ newModel,
327
+ currentContextTokens
328
+ );
329
+ return {
330
+ modelName: result.modelName,
331
+ contextAnalysis: analysis,
332
+ requiresCompression: analysis.severity === "critical",
333
+ estimatedTokensAfterSwitch: currentContextTokens
334
+ };
335
+ }
336
+ canModelHandleContext(model, contextTokens) {
337
+ const analysis = this.analyzeContextCompatibility(model, contextTokens);
338
+ return analysis.compatible;
339
+ }
340
+ findModelWithSufficientContext(models, contextTokens) {
341
+ return models.find((model) => this.canModelHandleContext(model, contextTokens)) || null;
342
+ }
343
+ getModelForContext(contextType) {
344
+ switch (contextType) {
345
+ case "terminal":
346
+ return this.getCurrentModel();
347
+ case "main-agent":
348
+ return this.getMainAgentModel();
349
+ case "task-tool":
350
+ return this.getTaskToolModel();
351
+ default:
352
+ return this.getMainAgentModel();
353
+ }
354
+ }
355
+ getActiveModelProfiles() {
356
+ return this.modelProfiles.filter((p) => p.isActive);
357
+ }
358
+ hasConfiguredModels() {
359
+ return this.getActiveModelProfiles().length > 0;
360
+ }
361
+ getModel(pointer) {
362
+ const pointerId = this.config.modelPointers?.[pointer];
363
+ if (!pointerId) {
364
+ return this.getDefaultModel();
365
+ }
366
+ const profile = this.findModelProfile(pointerId);
367
+ return profile && profile.isActive ? profile : this.getDefaultModel();
368
+ }
369
+ getModelName(pointer) {
370
+ const profile = this.getModel(pointer);
371
+ return profile ? profile.modelName : null;
372
+ }
373
+ getCompactModel() {
374
+ return this.getModelName("compact") || this.getModelName("main");
375
+ }
376
+ getQuickModel() {
377
+ return this.getModelName("quick") || this.getModelName("task") || this.getModelName("main");
378
+ }
379
+ async addModel(config) {
380
+ const existingByModelName = this.modelProfiles.find(
381
+ (p) => p.modelName === config.modelName
382
+ );
383
+ if (existingByModelName) {
384
+ throw new Error(
385
+ `Model with modelName '${config.modelName}' already exists: ${existingByModelName.name}`
386
+ );
387
+ }
388
+ const existingByName = this.modelProfiles.find((p) => p.name === config.name);
389
+ if (existingByName) {
390
+ throw new Error(`Model with name '${config.name}' already exists`);
391
+ }
392
+ const newModel = {
393
+ ...config,
394
+ createdAt: Date.now(),
395
+ isActive: true
396
+ };
397
+ this.modelProfiles.push(newModel);
398
+ if (this.modelProfiles.length === 1) {
399
+ this.config.modelPointers = {
400
+ main: config.modelName,
401
+ task: config.modelName,
402
+ compact: config.modelName,
403
+ quick: config.modelName
404
+ };
405
+ this.config.defaultModelName = config.modelName;
406
+ } else {
407
+ if (!this.config.modelPointers) {
408
+ this.config.modelPointers = {
409
+ main: config.modelName,
410
+ task: "",
411
+ compact: "",
412
+ quick: ""
413
+ };
414
+ } else {
415
+ this.config.modelPointers.main = config.modelName;
416
+ }
417
+ }
418
+ this.saveConfig();
419
+ return config.modelName;
420
+ }
421
+ setPointer(pointer, modelName) {
422
+ if (!this.findModelProfile(modelName)) {
423
+ throw new Error(`Model '${modelName}' not found`);
424
+ }
425
+ if (!this.config.modelPointers) {
426
+ this.config.modelPointers = {
427
+ main: "",
428
+ task: "",
429
+ compact: "",
430
+ quick: ""
431
+ };
432
+ }
433
+ this.config.modelPointers[pointer] = modelName;
434
+ this.saveConfig();
435
+ }
436
+ getAvailableModels() {
437
+ return this.modelProfiles.filter((p) => p.isActive);
438
+ }
439
+ getAllConfiguredModels() {
440
+ return this.modelProfiles;
441
+ }
442
+ getAllAvailableModelNames() {
443
+ return this.getAvailableModels().map((p) => p.modelName);
444
+ }
445
+ getAllConfiguredModelNames() {
446
+ return this.getAllConfiguredModels().map((p) => p.modelName);
447
+ }
448
+ getModelSwitchingDebugInfo() {
449
+ const availableModels = this.getAvailableModels();
450
+ const currentMainModelName = this.config.modelPointers?.main;
451
+ return {
452
+ totalModels: this.modelProfiles.length,
453
+ activeModels: availableModels.length,
454
+ inactiveModels: this.modelProfiles.length - availableModels.length,
455
+ currentMainModel: currentMainModelName || null,
456
+ availableModels: this.modelProfiles.map((p) => ({
457
+ name: p.name,
458
+ modelName: p.modelName,
459
+ provider: p.provider,
460
+ isActive: p.isActive,
461
+ lastUsed: p.lastUsed
462
+ })),
463
+ modelPointers: this.config.modelPointers || {}
464
+ };
465
+ }
466
+ removeModel(modelName) {
467
+ this.modelProfiles = this.modelProfiles.filter(
468
+ (p) => p.modelName !== modelName
469
+ );
470
+ if (this.config.modelPointers) {
471
+ Object.keys(this.config.modelPointers).forEach((pointer) => {
472
+ if (this.config.modelPointers[pointer] === modelName) {
473
+ this.config.modelPointers[pointer] = this.config.defaultModelName || "";
474
+ }
475
+ });
476
+ }
477
+ this.saveConfig();
478
+ }
479
+ getDefaultModel() {
480
+ if (this.config.defaultModelId) {
481
+ const profile = this.findModelProfile(this.config.defaultModelId);
482
+ if (profile && profile.isActive) {
483
+ return profile;
484
+ }
485
+ }
486
+ return this.modelProfiles.find((p) => p.isActive) || null;
487
+ }
488
+ saveConfig() {
489
+ const updatedConfig = {
490
+ ...this.config,
491
+ modelProfiles: this.modelProfiles
492
+ };
493
+ saveGlobalConfig(updatedConfig);
494
+ }
495
+ async getFallbackModel() {
496
+ const modelConfig = await getModelConfig();
497
+ if (USE_BEDROCK) return modelConfig.bedrock;
498
+ if (USE_VERTEX) return modelConfig.vertex;
499
+ return modelConfig.firstParty;
500
+ }
501
+ resolveModel(modelParam) {
502
+ if (["main", "task", "compact", "quick"].includes(modelParam)) {
503
+ const pointerId = this.config.modelPointers?.[modelParam];
504
+ if (pointerId) {
505
+ let profile2 = this.findModelProfile(pointerId);
506
+ if (!profile2) {
507
+ profile2 = this.findModelProfileByModelName(pointerId);
508
+ }
509
+ if (profile2 && profile2.isActive) {
510
+ return profile2;
511
+ }
512
+ }
513
+ return this.getDefaultModel();
514
+ }
515
+ let profile = this.findModelProfile(modelParam);
516
+ if (profile && profile.isActive) {
517
+ return profile;
518
+ }
519
+ profile = this.findModelProfileByModelName(modelParam);
520
+ if (profile && profile.isActive) {
521
+ return profile;
522
+ }
523
+ profile = this.findModelProfileByName(modelParam);
524
+ if (profile && profile.isActive) {
525
+ return profile;
526
+ }
527
+ if (typeof modelParam === "string") {
528
+ const qualified = this.resolveProviderQualifiedModel(modelParam);
529
+ if (qualified && qualified.isActive) {
530
+ return qualified;
531
+ }
532
+ }
533
+ return this.getDefaultModel();
534
+ }
535
+ resolveModelWithInfo(modelParam) {
536
+ const isPointer = ["main", "task", "compact", "quick"].includes(modelParam);
537
+ if (isPointer) {
538
+ const pointerId = this.config.modelPointers?.[modelParam];
539
+ if (!pointerId) {
540
+ return {
541
+ success: false,
542
+ profile: null,
543
+ error: `Model pointer '${modelParam}' is not configured. Use /model to set up models.`
544
+ };
545
+ }
546
+ let profile = this.findModelProfile(pointerId);
547
+ if (!profile) {
548
+ profile = this.findModelProfileByModelName(pointerId);
549
+ }
550
+ if (!profile) {
551
+ return {
552
+ success: false,
553
+ profile: null,
554
+ error: `Model pointer '${modelParam}' points to invalid model '${pointerId}'. Use /model to reconfigure.`
555
+ };
556
+ }
557
+ if (!profile.isActive) {
558
+ return {
559
+ success: false,
560
+ profile: null,
561
+ error: `Model '${profile.name}' (pointed by '${modelParam}') is inactive. Use /model to activate it.`
562
+ };
563
+ }
564
+ return {
565
+ success: true,
566
+ profile
567
+ };
568
+ } else {
569
+ let profile = this.findModelProfile(modelParam);
570
+ if (!profile) {
571
+ profile = this.findModelProfileByModelName(modelParam);
572
+ }
573
+ if (!profile) {
574
+ profile = this.findModelProfileByName(modelParam);
575
+ }
576
+ if (!profile && typeof modelParam === "string") {
577
+ profile = this.resolveProviderQualifiedModel(modelParam);
578
+ }
579
+ if (!profile) {
580
+ return {
581
+ success: false,
582
+ profile: null,
583
+ error: `Model '${modelParam}' not found. Use /model to add models, or run 'newcraw models list' to see configured profiles.`
584
+ };
585
+ }
586
+ if (!profile.isActive) {
587
+ return {
588
+ success: false,
589
+ profile: null,
590
+ error: `Model '${profile.name}' is inactive. Use /model to activate it.`
591
+ };
592
+ }
593
+ return {
594
+ success: true,
595
+ profile
596
+ };
597
+ }
598
+ }
599
+ resolveProviderQualifiedModel(input) {
600
+ const trimmed = input.trim();
601
+ const colonIndex = trimmed.indexOf(":");
602
+ if (colonIndex <= 0 || colonIndex >= trimmed.length - 1) return null;
603
+ const provider = trimmed.slice(0, colonIndex).trim().toLowerCase();
604
+ const modelOrName = trimmed.slice(colonIndex + 1).trim();
605
+ if (!provider || !modelOrName) return null;
606
+ const providerProfiles = this.modelProfiles.filter(
607
+ (p) => String(p.provider).trim().toLowerCase() === provider
608
+ );
609
+ if (providerProfiles.length === 0) return null;
610
+ const byModelName = providerProfiles.find((p) => p.modelName === modelOrName);
611
+ if (byModelName) return byModelName;
612
+ const byName = providerProfiles.find((p) => p.name === modelOrName);
613
+ if (byName) return byName;
614
+ return null;
615
+ }
616
+ findModelProfile(modelName) {
617
+ return this.modelProfiles.find((p) => p.modelName === modelName) || null;
618
+ }
619
+ findModelProfileByModelName(modelName) {
620
+ return this.modelProfiles.find((p) => p.modelName === modelName) || null;
621
+ }
622
+ findModelProfileByName(name) {
623
+ return this.modelProfiles.find((p) => p.name === name) || null;
624
+ }
625
+ updateLastUsed(modelName) {
626
+ const profile = this.findModelProfile(modelName);
627
+ if (profile) {
628
+ profile.lastUsed = Date.now();
629
+ }
630
+ }
631
+ };
632
+ globalModelManager = null;
633
+ getModelManager = () => {
634
+ try {
635
+ if (!globalModelManager) {
636
+ const config = getGlobalConfig();
637
+ if (!config) {
638
+ debug.warn("MODEL_MANAGER_GLOBAL_CONFIG_MISSING", {});
639
+ globalModelManager = new ModelManager({
640
+ modelProfiles: [],
641
+ modelPointers: { main: "", task: "", compact: "", quick: "" }
642
+ });
643
+ } else {
644
+ globalModelManager = new ModelManager(config);
645
+ }
646
+ }
647
+ return globalModelManager;
648
+ } catch (error) {
649
+ logError(error);
650
+ debug.error("MODEL_MANAGER_CREATE_FAILED", {
651
+ error: error instanceof Error ? error.message : String(error)
652
+ });
653
+ return new ModelManager({
654
+ modelProfiles: [],
655
+ modelPointers: { main: "", task: "", compact: "", quick: "" }
656
+ });
657
+ }
658
+ };
659
+ reloadModelManager = () => {
660
+ globalModelManager = null;
661
+ getModelManager();
662
+ };
663
+ getQuickModel = () => {
664
+ const manager = getModelManager();
665
+ const quickModel = manager.getModel("quick");
666
+ return quickModel?.modelName || "quick";
667
+ };
668
+ }
669
+ });
670
+
671
+ export {
672
+ USE_BEDROCK,
673
+ USE_VERTEX,
674
+ getSlowAndCapableModel,
675
+ isDefaultSlowAndCapableModel,
676
+ getVertexRegionForModel,
677
+ ModelManager,
678
+ getModelManager,
679
+ reloadModelManager,
680
+ getQuickModel,
681
+ model_exports,
682
+ init_model
683
+ };