nolo-cli 0.103.0-alpha.1 → 0.103.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/README.md +1 -1
  2. package/{_executeModel-3UCNJCQA.js → _executeModel-7J7Q3WXY.js} +75 -68
  3. package/action-C4KMTCJF.js +20 -0
  4. package/{addContentAction-O7R66HEX.js → addContentAction-7TNIOVZI.js} +12 -11
  5. package/{addDialogAgentAction-74OA7KYP.js → addDialogAgentAction-O47J3MVW.js} +18 -19
  6. package/{agentDeleteCommand-2YAHAZFJ.js → agentDeleteCommand-YPJHK7JA.js} +117 -42
  7. package/{agentEmailCommands-WLYF3JRS.js → agentEmailCommands-AWEXOHWM.js} +98 -88
  8. package/agentListCommands-2DTLLJZD.js +742 -0
  9. package/{agentMachineCommands-HNGAR5GI.js → agentMachineCommands-PGEEQ4JJ.js} +48 -43
  10. package/{agentProviderCommands-GNPTL5XR.js → agentProviderCommands-XPJYZSCE.js} +97 -2
  11. package/{agentPullCommand-O5MPVJ5E.js → agentPullCommand-B4T2DJ5H.js} +1 -1
  12. package/agentRecordCommands-DZVLCPLJ.js +138 -0
  13. package/agentRunCommand-AX5CYQ46.js +167 -0
  14. package/{agentRunControl-AVJR4JW4.js → agentRunControl-3HWA2LLQ.js} +2 -2
  15. package/{agentRuntimeLocal-VXZSDIGT.js → agentRuntimeLocal-PITRQ2EU.js} +48 -39
  16. package/{agentSlice-SICQBMCM.js → agentSlice-4TLSG6FB.js} +14 -13
  17. package/{appDeleteCommands-32MHLR4L.js → appDeleteCommands-UC2JW5FJ.js} +46 -41
  18. package/{appDeployCommands-WCQOUSOB.js → appDeployCommands-OL2RKVJ3.js} +46 -41
  19. package/{appDeployStatusCommands-6QKB7DYN.js → appDeployStatusCommands-B3PLC62M.js} +46 -41
  20. package/{appGetCommands-SFAPP5PB.js → appGetCommands-REESA2XQ.js} +46 -41
  21. package/{appListCommands-EKUBDRUO.js → appListCommands-UF6XX7HR.js} +46 -41
  22. package/{authCommand-F4EFRRX6.js → authCommand-NQPMGYHP.js} +118 -24
  23. package/{authCommands-RGOGCPP6.js → authCommands-LWLOZETU.js} +7 -5
  24. package/{builtinSkillRegistry-FUAVTRVZ.js → builtinSkillRegistry-GFY77VRN.js} +10 -8
  25. package/{chromeCommands-FZYAU75D.js → chromeCommands-K27J4OVZ.js} +124 -28
  26. package/{chromeOpsCommands-62P2Q2YB.js → chromeOpsCommands-IXRLN57H.js} +4 -3
  27. package/{chunk-UKZDAFYT.js → chunk-22RVE2PC.js} +6 -10
  28. package/{chunk-6OZ36FXI.js → chunk-27ONFIEY.js} +22 -4
  29. package/{chunk-HVURBGF3.js → chunk-2H6SEVDS.js} +6 -6
  30. package/{chunk-TOP2VXOR.js → chunk-2K4TM6AW.js} +5 -5
  31. package/{chunk-JEDZAO7L.js → chunk-2SYTUTLI.js} +257 -37
  32. package/{chunk-53HEEOTT.js → chunk-2WJ57RJA.js} +83 -16
  33. package/{chunk-OIVSQH2O.js → chunk-3BXNTXYI.js} +299 -5
  34. package/chunk-4A2R7KHG.js +13545 -0
  35. package/{chunk-EYAQT56M.js → chunk-4DPP773Q.js} +2 -2
  36. package/{chunk-JRQFUXY7.js → chunk-4G4C5SXT.js} +99 -22
  37. package/{chunk-DHDMC6FO.js → chunk-4HTMUQIZ.js} +14 -9
  38. package/{chunk-B3TVQ6PI.js → chunk-4IVA6UUE.js} +20 -11
  39. package/chunk-4LCOCOR5.js +50 -0
  40. package/{chunk-2GRGFCF6.js → chunk-4VJAC32I.js} +2 -1
  41. package/{chunk-MC4XLIJ7.js → chunk-523DITKR.js} +1 -1
  42. package/{chunk-H62HCIUP.js → chunk-56HJ2LAA.js} +35 -22
  43. package/{chunk-V4MJDUSR.js → chunk-5EPHWMP5.js} +2 -2
  44. package/{chunk-E4MARS3Q.js → chunk-5GVBDNTO.js} +1 -1
  45. package/{chunk-3WLK2JQ5.js → chunk-5IWONK6X.js} +68 -46
  46. package/chunk-5J3PYNUP.js +255 -0
  47. package/chunk-5MMAK75Q.js +15 -0
  48. package/{chunk-LW4VFPAY.js → chunk-5ZDLVKNG.js} +873 -228
  49. package/{chunk-42V6BK2E.js → chunk-62IL3KQV.js} +4 -34
  50. package/{chunk-AEOE4Z6Q.js → chunk-6UEJDFF7.js} +39 -15
  51. package/{chunk-JPGCXHNM.js → chunk-7JWCVINR.js} +1 -1
  52. package/{chunk-GQBOR3G6.js → chunk-7KVZ5LDQ.js} +2 -2
  53. package/{chunk-IIVGDG4I.js → chunk-7KWFIKKK.js} +13 -7
  54. package/chunk-A4SQRTZ6.js +15 -0
  55. package/chunk-AGIM7IMJ.js +147 -0
  56. package/{chunk-5UTFL4QJ.js → chunk-AOTBKDRK.js} +7 -0
  57. package/{chunk-L5UXH3B2.js → chunk-B455PEFD.js} +27 -8
  58. package/{chunk-XS5SWEDQ.js → chunk-BELZY72F.js} +1 -1
  59. package/chunk-BMQ2MJUK.js +153 -0
  60. package/{chunk-6YTOJY35.js → chunk-BZ7NPA6G.js} +35 -2
  61. package/chunk-CHOZJMJS.js +78 -0
  62. package/{chunk-3BMYXEUW.js → chunk-CUF4MYKI.js} +1 -1
  63. package/{chunk-ACTMNVHM.js → chunk-CYSYR67N.js} +1 -1
  64. package/{chunk-WV42OMV7.js → chunk-D2GQE6AF.js} +8 -8
  65. package/{chunk-GBRG75BQ.js → chunk-D2MDMY2M.js} +1 -0
  66. package/chunk-DZ7R5V3Y.js +164 -0
  67. package/{chunk-3VNWWVKB.js → chunk-E3YWHWCR.js} +50 -18
  68. package/{chunk-KQ4ONNQD.js → chunk-EKPKW6RM.js} +155 -8
  69. package/{chunk-ABQYVJBJ.js → chunk-EV235ILT.js} +5 -5
  70. package/{chunk-TRV2MIDW.js → chunk-EXAJ6DCR.js} +1 -0
  71. package/{chunk-AGVEIAQA.js → chunk-F442UK5V.js} +29 -78
  72. package/{chunk-HJUYAD4A.js → chunk-FBTNYNAL.js} +5 -5
  73. package/{chunk-2F7RJC6L.js → chunk-FOXQ7BAB.js} +1 -1
  74. package/{chunk-ETI2NYVF.js → chunk-GCTKWVLU.js} +4 -4
  75. package/chunk-GMZLP5DV.js +82 -0
  76. package/{chunk-FDTR4QJ6.js → chunk-H6A6X4EK.js} +32 -1
  77. package/{chunk-6VFARHZW.js → chunk-H7TQORR4.js} +994 -1079
  78. package/{chunk-5H7KJX7J.js → chunk-HD3S2F7U.js} +5 -5
  79. package/chunk-HDJRLWTG.js +8002 -0
  80. package/{chunk-DVINR3PL.js → chunk-HDLLCBRF.js} +1 -1
  81. package/{chunk-QOKAKDPE.js → chunk-HIM3FCLF.js} +0 -1
  82. package/{chunk-ONXOABJR.js → chunk-HNGRBWYF.js} +3 -0
  83. package/{chunk-VLTIYV3X.js → chunk-HP57OUJO.js} +4 -4
  84. package/{chunk-4OEFYTWL.js → chunk-IRZTHHNM.js} +67 -48
  85. package/{chunk-GPCZ7UXG.js → chunk-K6U4NKFJ.js} +1 -1
  86. package/{chunk-OZGZPSEG.js → chunk-KGRP4VOK.js} +47 -67
  87. package/{chunk-DNCEALKX.js → chunk-LB5A6JTU.js} +22 -29
  88. package/{chunk-LS2ZANRJ.js → chunk-LOCNXNOU.js} +1 -1
  89. package/{chunk-PUOC4YRO.js → chunk-M7VLQGQP.js} +11 -0
  90. package/{chunk-Z77CRGTW.js → chunk-MSFZ7FMO.js} +1 -1
  91. package/chunk-NKWIS6G2.js +442 -0
  92. package/{chunk-BFU6C242.js → chunk-NMFV26UG.js} +1 -1
  93. package/{chunk-FZGV4FGK.js → chunk-NUHHBEJC.js} +378 -187
  94. package/chunk-NWENLDMM.js +42 -0
  95. package/chunk-O7SVKKLY.js +875 -0
  96. package/chunk-OCZKATRC.js +129 -0
  97. package/{chunk-PQFHGD77.js → chunk-OM2RUOEU.js} +161 -14
  98. package/{chunk-KQHGZWSV.js → chunk-OXME3PEE.js} +1 -1
  99. package/{chunk-TQBHNYVR.js → chunk-PLRFCQ7C.js} +567 -519
  100. package/{chunk-6D6VBVEW.js → chunk-Q7O72MF5.js} +80 -14
  101. package/{chunk-J4MOO56S.js → chunk-RILRSUGC.js} +10 -2
  102. package/{chunk-RSONHHPE.js → chunk-RNUDNZJW.js} +10 -10
  103. package/{chunk-3N3W7KBB.js → chunk-RZJAZVCF.js} +11 -9
  104. package/{chunk-BYMV6QZG.js → chunk-TNIX77YM.js} +4 -0
  105. package/{chunk-GEPUP7OO.js → chunk-TSXNDTXL.js} +3 -3
  106. package/chunk-TY3TIUJK.js +89 -0
  107. package/{chunk-I3TQJXQ7.js → chunk-U3C3IA32.js} +9 -2
  108. package/{chunk-UZGQNTVW.js → chunk-UA324D4O.js} +8 -6
  109. package/{chunk-YYLHWIW6.js → chunk-UKZX3NHN.js} +1 -1
  110. package/{chunk-BP4XNZRM.js → chunk-UNAOTLKO.js} +4 -4
  111. package/{chunk-CUQEXCAU.js → chunk-UQ5P2WHS.js} +29 -9
  112. package/{chunk-NA35QHCF.js → chunk-V6YASAZR.js} +1 -1
  113. package/{chunk-3DII57IT.js → chunk-VCAQFMVN.js} +1 -1
  114. package/chunk-VIWDGTDA.js +8 -0
  115. package/chunk-VJVNU77E.js +83 -0
  116. package/{chunk-ZCYXJSTU.js → chunk-VL3H5ZU3.js} +66 -94
  117. package/{chunk-Q554LLSI.js → chunk-VLGL7FOL.js} +1 -1
  118. package/{chunk-UKWGR5SS.js → chunk-VY6VFGKR.js} +194 -1144
  119. package/{chunk-4EG4QFTK.js → chunk-WI6TUGLJ.js} +19 -17
  120. package/{chunk-QDSINZM3.js → chunk-WJ3B6FX6.js} +1 -14
  121. package/{chunk-OEVAY4J6.js → chunk-XMUZHRSB.js} +18 -20
  122. package/{chunk-O6OSWFZQ.js → chunk-XUWRURDF.js} +6 -0
  123. package/{chunk-Q67DOFOO.js → chunk-Y3PMXGLH.js} +2 -0
  124. package/{chunk-7S4YWN7P.js → chunk-YDO5ERB4.js} +4 -4
  125. package/chunk-YK5MHOWM.js +915 -0
  126. package/{chunk-SH43IESU.js → chunk-YUNJN43V.js} +44 -9
  127. package/chunk-YV25TM3R.js +780 -0
  128. package/{chunk-IONPPCL5.js → chunk-YZZREBID.js} +86 -16
  129. package/{chunk-DNUUJ45N.js → chunk-Z3WSAK6A.js} +23 -28
  130. package/chunk-ZRAU6T47.js +56 -0
  131. package/commandRegistry-VQPFWVDH.js +833 -0
  132. package/{contentThunks-S4S7QPSO.js → contentThunks-A26ME6OJ.js} +37 -35
  133. package/{cooldownCommands-REAWYVTY.js → cooldownCommands-ZLEPIB4A.js} +2 -2
  134. package/{createAgentAutomationAction-ODGL2YGP.js → createAgentAutomationAction-BSAMZJ5W.js} +39 -37
  135. package/createDialogAction-CMCQXYHD.js +69 -0
  136. package/{createPageAction-FBV3OWX7.js → createPageAction-ANGKJTK2.js} +46 -43
  137. package/{chunk-F2RNI7ZR.js → cursorProvider-YGGNMVWX.js} +2496 -9897
  138. package/{dbSlice-XVWBAGYN.js → dbSlice-QOLNF5GN.js} +11 -10
  139. package/{deleteFile-YG6QMJLU.js → deleteFile-KESP65GC.js} +7 -6
  140. package/{dialogCommands-5J56DFWN.js → dialogCommands-AMPAWLX4.js} +49 -45
  141. package/{dialogSlice-LEO27SQG.js → dialogSlice-DGWDEBYC.js} +41 -34
  142. package/{dist-VODFSGNG.js → dist-NJC2W7I4.js} +61 -54
  143. package/{docCreateCommands-KYI2DC2U.js → docCreateCommands-7NMIYL5D.js} +48 -43
  144. package/{docDeleteCommands-67REUSRY.js → docDeleteCommands-BD4OM5PV.js} +49 -44
  145. package/{docReadCommands-HOSVSBDJ.js → docReadCommands-5IOVAKU2.js} +47 -42
  146. package/{docStore-MNX5MHA5.js → docStore-TP4QDER4.js} +16 -12
  147. package/{docUpdateCommands-EMGCSMXY.js → docUpdateCommands-ZTKJ6UPC.js} +48 -43
  148. package/{fetchMessages-EIU7UFFK.js → fetchMessages-5L7OVM5Y.js} +5 -5
  149. package/{getPricing-LUSEABA6.js → getPricing-NMMFT3YI.js} +4 -4
  150. package/{handleSendMessageAction-YB6KQFJS.js → handleSendMessageAction-N4WKFRSQ.js} +111 -87
  151. package/index.js +87 -884
  152. package/{lib-FRRS27KN.js → lib-PU2G2MSO.js} +523 -191
  153. package/{localDialogRead-BTFJ4V2I.js → localDialogRead-O5A26FDK.js} +2 -2
  154. package/{localRuntimeAuthority-6IR6BBXE.js → localRuntimeAuthority-TU6OBC76.js} +9 -6
  155. package/{localRuntimeDb-SYQGUF4U.js → localRuntimeDb-VKWVOPPI.js} +1 -1
  156. package/{machineCommands-7GVQCUAK.js → machineCommands-47WKGY5Z.js} +92 -82
  157. package/machineWsRunDispatch-CYW5FJ52.js +154 -0
  158. package/{memberThunks-QGFLFVCI.js → memberThunks-25K6DDRA.js} +20 -18
  159. package/{models-T3SG6MJ5.js → models-ZPU5EDF4.js} +2 -2
  160. package/oauthTokenStore-ITEB663N.js +23 -0
  161. package/package.json +1 -1
  162. package/pdf-U6KSUEZZ.js +26435 -0
  163. package/processSpawn-SOAV3FEV.js +11 -0
  164. package/profileConfig-ZGOFORWV.js +43 -0
  165. package/{providerPresetApply-FG6NZ57W.js → providerPresetApply-TEBH7FDX.js} +7 -7
  166. package/{providerRegistry-757OWH3O.js → providerRegistry-CBJLNCET.js} +11 -7
  167. package/{read-COE3ZYR6.js → read-PJIT2YEJ.js} +7 -6
  168. package/{readDocTool-5USN4A6V.js → readDocTool-DRSXHGNL.js} +5 -3
  169. package/{readlineWorkspace-WA7JNI6J.js → readlineWorkspace-CK7GOVOC.js} +2698 -2055
  170. package/{removeDialogAgentAction-IX3MN2ZO.js → removeDialogAgentAction-VIWJL6MX.js} +21 -25
  171. package/{runAgentClientLoop-JGFQ6KIR.js → runAgentClientLoop-BGHGP5AR.js} +76 -70
  172. package/{runtimeDoctorCommands-X6WDBEQX.js → runtimeDoctorCommands-PIVSBZRZ.js} +4 -4
  173. package/runtimeModeArgs-2Y7BALTO.js +31 -0
  174. package/{setDialogExtraReferencesAction-X4HCPNZL.js → setDialogExtraReferencesAction-A7VA3NFM.js} +15 -13
  175. package/{setPrimaryDialogAgentAction-4GMIQLOD.js → setPrimaryDialogAgentAction-B4P7YQX2.js} +22 -26
  176. package/{chunk-AFUORTY4.js → settingThunks-KOYSAT65.js} +226 -940
  177. package/{skillDiscovery-CYUCJMAG.js → skillDiscovery-ZBU76COE.js} +3 -3
  178. package/{slateUtils-RIZES3PV.js → slateUtils-NGV2NMKM.js} +1 -1
  179. package/{spaceCommands-NKJVJCQQ.js → spaceCommands-QJCYG27F.js} +51 -46
  180. package/{streamAgentChatTurn-XLFZ66UC.js → streamAgentChatTurn-ANE7OTCZ.js} +214 -108
  181. package/{switchDialogAgentAction-N52LRPA3.js → switchDialogAgentAction-3VYWHZKH.js} +18 -19
  182. package/{tableCommands-O6NWHFKV.js → tableCommands-6U4BMLRR.js} +10 -10
  183. package/{toolApiClient-QVJ6HDNN.js → toolApiClient-EJT6TMFG.js} +3 -3
  184. package/tools-WPOVVP7M.js +116 -0
  185. package/{tuiSummaryLlmCaller-WFRWERGK.js → tuiSummaryLlmCaller-QCHCULPM.js} +25 -22
  186. package/{updateCommands-2M74UL7P.js → updateCommands-4EHDLF5J.js} +3 -3
  187. package/{updateDialogTitleAction-6MBTD4UE.js → updateDialogTitleAction-C4GRCXL4.js} +82 -44
  188. package/action-YVYQEAAV.js +0 -31
  189. package/agentListCommands-JP7S7PT2.js +0 -469
  190. package/agentRecordCommands-SXFPW3DL.js +0 -128
  191. package/agentRunCommand-JIQ4HY4D.js +0 -155
  192. package/browser-image-compression-MFDTD7K6.js +0 -1763
  193. package/chatQueueReduxAdapter-HHMUDNXL.js +0 -186
  194. package/chunk-CQ3WA2NE.js +0 -299
  195. package/chunk-M76ECQRD.js +0 -13658
  196. package/chunk-MEYIRKDN.js +0 -8967
  197. package/chunk-Q5FJJ6XI.js +0 -103
  198. package/chunk-S7Z2HMCN.js +0 -25
  199. package/chunk-XVZ22N6C.js +0 -20782
  200. package/chunk-Y5GCAMGP.js +0 -9
  201. package/chunk-YPREESF4.js +0 -225
  202. package/createDialogAction-GFKRXTK4.js +0 -65
  203. package/machineWsRunDispatch-XA7TD7Z7.js +0 -144
  204. package/settingSlice-ZQZVUPKK.js +0 -204
  205. package/syncMapping-N6RGXGBW.js +0 -437
  206. package/tools-NF5AB34X.js +0 -110
  207. package/{chunk-VMFTFOWF.js → chunk-ODAPITXL.js} +7 -7
  208. package/{chunk-X7HHHIOZ.js → chunk-Y6ROFCZO.js} +0 -0
  209. package/{db-WK5MDZVN.js → db-VQSAOWAO.js} +1 -1
@@ -96,6 +96,10 @@ function preserveAgentStateFields(source, target, options) {
96
96
  }
97
97
  if (Array.isArray(source.tool_calls)) {
98
98
  mutableTarget.tool_calls = source.tool_calls;
99
+ const replayPlaceholder = options?.replayReasoningPlaceholder;
100
+ if (typeof replayPlaceholder === "string" && replayPlaceholder.length > 0 && !options?.stripReasoningContent && source.tool_calls.length > 0 && !(typeof mutableTarget.reasoning_content === "string" && mutableTarget.reasoning_content.length > 0)) {
101
+ mutableTarget.reasoning_content = replayPlaceholder;
102
+ }
99
103
  }
100
104
  }
101
105
  if (source.role === "tool") {
@@ -121,6 +125,12 @@ function shouldStripReasoningContentForOutbound(provider, model) {
121
125
  }
122
126
  return false;
123
127
  }
128
+ function shouldReplayReasoningContentForOutbound(provider, model) {
129
+ const p = provider?.trim().toLowerCase();
130
+ const m = model?.trim().toLowerCase();
131
+ if (!p || !m) return false;
132
+ return p === "opencode-go" && m.includes("deepseek");
133
+ }
124
134
 
125
135
  // packages/integrations/openai/responsesHelpers.ts
126
136
  var RESPONSES_TOP_LEVEL_SCHEMA_KEYS = ["anyOf", "oneOf", "allOf", "enum", "not"];
@@ -383,6 +393,7 @@ export {
383
393
  preserveAgentStateFields,
384
394
  toOpenAiCompatibleMessages,
385
395
  shouldStripReasoningContentForOutbound,
396
+ shouldReplayReasoningContentForOutbound,
386
397
  toResponsesTools,
387
398
  convertMessagesToResponsesInput,
388
399
  extractTextFromResponseOutput,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  buildAgentRuntimeAgentLookupKeys,
3
3
  shouldFetchAgentRuntimeRecordRemotely
4
- } from "./chunk-IIVGDG4I.js";
4
+ } from "./chunk-7KWFIKKK.js";
5
5
 
6
6
  // packages/cli/client/localAgentRecords.ts
7
7
  var buildLocalAgentLookupKeys = buildAgentRuntimeAgentLookupKeys;
@@ -0,0 +1,442 @@
1
+ // packages/agent-runtime/declaredToolNames.ts
2
+ function extractDeclaredToolNames(tools) {
3
+ if (!Array.isArray(tools)) return void 0;
4
+ const names = /* @__PURE__ */ new Set();
5
+ for (const t of tools) {
6
+ const fn = t?.function;
7
+ if (fn && typeof fn.name === "string" && fn.name) names.add(fn.name);
8
+ }
9
+ return names;
10
+ }
11
+
12
+ // packages/agent-runtime/outboundHistorySanitize.ts
13
+ function sanitizeForOutbound(messages, tools) {
14
+ return sanitizeOutboundHistory(messages, {
15
+ declaredToolNames: extractDeclaredToolNames(tools)
16
+ });
17
+ }
18
+ function stableToolCallId(assistantIndex, callIndex) {
19
+ return `call_sanitize_${assistantIndex}_${callIndex}`;
20
+ }
21
+ function isString(v) {
22
+ return typeof v === "string";
23
+ }
24
+ function isNonEmptyString(v) {
25
+ return typeof v === "string" && v.length > 0;
26
+ }
27
+ function joinLines(...parts) {
28
+ return parts.filter(isNonEmptyString).join("\n");
29
+ }
30
+ function jsonStringifyArguments(args) {
31
+ if (typeof args === "string") return args;
32
+ try {
33
+ return JSON.stringify(args ?? "");
34
+ } catch {
35
+ return "";
36
+ }
37
+ }
38
+ function renderToolCallAsText(call) {
39
+ const c = call && typeof call === "object" ? call : {};
40
+ const name = isString(c.function?.name) && c.function.name.length > 0 ? c.function.name : "unknown";
41
+ const rawArgs = c.function?.arguments;
42
+ const args = jsonStringifyArguments(rawArgs);
43
+ return `[tool_call: ${name}(${args})]`;
44
+ }
45
+ function renderToolResultAsText(message) {
46
+ const name = isNonEmptyString(message.toolName) ? message.toolName : "tool";
47
+ const body = typeof message.content === "string" ? message.content : "";
48
+ return `[tool_result: ${name}: ${body}]`;
49
+ }
50
+ function normalizeToolCall(call, assistantIndex, callIndex) {
51
+ if (!call || typeof call !== "object") return null;
52
+ const c = call;
53
+ const fn = c.function;
54
+ if (!fn || typeof fn !== "object" || !isString(fn.name) || fn.name.length === 0) return null;
55
+ const id = isNonEmptyString(c.id) ? c.id : stableToolCallId(assistantIndex, callIndex);
56
+ return {
57
+ id,
58
+ type: isString(c.type) && c.type ? c.type : "function",
59
+ function: { name: fn.name, arguments: jsonStringifyArguments(fn.arguments) },
60
+ ...typeof c.thought_signature === "string" ? { thought_signature: c.thought_signature } : {}
61
+ };
62
+ }
63
+ function classifyAssistantCalls(toolCalls, assistantIndex) {
64
+ const callIds = [];
65
+ const idCounts = /* @__PURE__ */ new Map();
66
+ const unparsableIndices = /* @__PURE__ */ new Set();
67
+ const unparsableIds = /* @__PURE__ */ new Set();
68
+ toolCalls.forEach((rawCall, callIndex) => {
69
+ const c = rawCall && typeof rawCall === "object" ? rawCall : {};
70
+ const id = isNonEmptyString(c.id) ? c.id : stableToolCallId(assistantIndex, callIndex);
71
+ callIds.push(id);
72
+ idCounts.set(id, (idCounts.get(id) ?? 0) + 1);
73
+ if (!hasParsableObjectArguments(c.function?.arguments)) {
74
+ unparsableIndices.add(callIndex);
75
+ unparsableIds.add(id);
76
+ }
77
+ });
78
+ const duplicateIds = /* @__PURE__ */ new Set();
79
+ for (const [id, count] of idCounts) {
80
+ if (count > 1) duplicateIds.add(id);
81
+ }
82
+ return { callIds, duplicateIds, unparsableIndices, unparsableIds };
83
+ }
84
+ function sanitizeOutboundHistory(messages, options) {
85
+ if (!Array.isArray(messages) || messages.length === 0) return messages;
86
+ const declared = options?.declaredToolNames;
87
+ const keptCallIndicesPerAssistant = /* @__PURE__ */ new Map();
88
+ const keptToolIndices = /* @__PURE__ */ new Set();
89
+ let i = 0;
90
+ while (i < messages.length) {
91
+ const m = messages[i];
92
+ if (m.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
93
+ const asstIdx = i;
94
+ const { callIds, duplicateIds, unparsableIndices } = classifyAssistantCalls(m.tool_calls, asstIdx);
95
+ const candidateCallMap = /* @__PURE__ */ new Map();
96
+ m.tool_calls.forEach((call, callIndex) => {
97
+ const id = callIds[callIndex];
98
+ if (duplicateIds.has(id)) return;
99
+ if (unparsableIndices.has(callIndex)) return;
100
+ const name = call?.function?.name;
101
+ if (!isString(name) || name.length === 0) return;
102
+ const declaredAllows = !declared || declared.has(name);
103
+ if (!declaredAllows) return;
104
+ candidateCallMap.set(id, callIndex);
105
+ });
106
+ let j = i + 1;
107
+ const matchedCallIndices = /* @__PURE__ */ new Set();
108
+ const matchedToolIds = /* @__PURE__ */ new Set();
109
+ while (j < messages.length && messages[j].role === "tool") {
110
+ const toolMsg = messages[j];
111
+ const toolCallId = isNonEmptyString(toolMsg.tool_call_id) ? toolMsg.tool_call_id : "";
112
+ if (toolCallId && candidateCallMap.has(toolCallId) && !matchedToolIds.has(toolCallId)) {
113
+ matchedToolIds.add(toolCallId);
114
+ matchedCallIndices.add(candidateCallMap.get(toolCallId));
115
+ keptToolIndices.add(j);
116
+ }
117
+ j++;
118
+ }
119
+ keptCallIndicesPerAssistant.set(asstIdx, matchedCallIndices);
120
+ i = j;
121
+ } else {
122
+ i++;
123
+ }
124
+ }
125
+ const out = [];
126
+ let k = 0;
127
+ while (k < messages.length) {
128
+ const m = messages[k];
129
+ if (m.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
130
+ const asstIdx = k;
131
+ const keptIndices = keptCallIndicesPerAssistant.get(asstIdx) ?? /* @__PURE__ */ new Set();
132
+ const keptToolCalls = [];
133
+ const downgradedCallLines = [];
134
+ m.tool_calls.forEach((call, callIndex) => {
135
+ const name = call?.function?.name;
136
+ const declaredAllows = !declared || isString(name) && declared.has(name);
137
+ const keep = keptIndices.has(callIndex) && declaredAllows && hasParsableObjectArguments(call?.function?.arguments);
138
+ if (keep) {
139
+ const normalized = normalizeToolCall(call, asstIdx, callIndex);
140
+ if (normalized) {
141
+ keptToolCalls.push(normalized);
142
+ } else {
143
+ downgradedCallLines.push(renderToolCallAsText(call));
144
+ }
145
+ } else {
146
+ downgradedCallLines.push(renderToolCallAsText(call));
147
+ }
148
+ });
149
+ if (keptToolCalls.length === 0) {
150
+ const downgradedText = joinLines(...downgradedCallLines);
151
+ const contentWithDowngrade = downgradedText.length > 0 ? combineContentWithText(m.content, downgradedText) : m.content;
152
+ const sanitizedAssistant2 = {
153
+ ...m,
154
+ content: contentWithDowngrade
155
+ };
156
+ delete sanitizedAssistant2.tool_calls;
157
+ out.push(sanitizedAssistant2);
158
+ let nextIdx2 = k + 1;
159
+ while (nextIdx2 < messages.length && messages[nextIdx2].role === "tool") {
160
+ out.push({
161
+ role: "assistant",
162
+ content: renderToolResultAsText(messages[nextIdx2])
163
+ });
164
+ nextIdx2++;
165
+ }
166
+ k = nextIdx2;
167
+ continue;
168
+ }
169
+ const sanitizedAssistant = {
170
+ ...m,
171
+ tool_calls: keptToolCalls
172
+ };
173
+ out.push(sanitizedAssistant);
174
+ let nextIdx = k + 1;
175
+ const deferredResultLines = [];
176
+ while (nextIdx < messages.length && messages[nextIdx].role === "tool") {
177
+ if (keptToolIndices.has(nextIdx)) {
178
+ const toolMsg = messages[nextIdx];
179
+ out.push({
180
+ ...toolMsg,
181
+ content: toolMsg.content ?? "",
182
+ tool_call_id: toolMsg.tool_call_id
183
+ });
184
+ } else {
185
+ deferredResultLines.push(renderToolResultAsText(messages[nextIdx]));
186
+ }
187
+ nextIdx++;
188
+ }
189
+ const deferredLines = [...downgradedCallLines, ...deferredResultLines];
190
+ if (deferredLines.length > 0) {
191
+ out.push({
192
+ role: "assistant",
193
+ content: joinLines(...deferredLines)
194
+ });
195
+ }
196
+ k = nextIdx;
197
+ continue;
198
+ }
199
+ if (m.role === "tool") {
200
+ out.push({
201
+ role: "assistant",
202
+ content: renderToolResultAsText(m)
203
+ });
204
+ k++;
205
+ continue;
206
+ }
207
+ out.push({ ...m });
208
+ k++;
209
+ }
210
+ return out;
211
+ }
212
+ function combineContentWithText(base, extra) {
213
+ if (typeof base === "string") {
214
+ return base ? `${base}
215
+ ${extra}` : extra;
216
+ }
217
+ if (Array.isArray(base)) {
218
+ return [...base, { type: "text", text: extra }];
219
+ }
220
+ return extra;
221
+ }
222
+ function hasParsableObjectArguments(raw) {
223
+ if (raw === void 0) return true;
224
+ if (raw === null || typeof raw === "number" || typeof raw === "boolean") {
225
+ return false;
226
+ }
227
+ if (typeof raw !== "string") return true;
228
+ if (raw.trim() === "") return true;
229
+ try {
230
+ const parsed = JSON.parse(raw);
231
+ return parsed !== null && typeof parsed === "object";
232
+ } catch {
233
+ return false;
234
+ }
235
+ }
236
+ var STRICT_JSON_STRING_TOKEN = /^"(?:[^"\\\u0000-\u001F]|\\["\\/bfnrt]|\\u[0-9A-Fa-f]{4})*"$/;
237
+ function isStrictJsonStringToken(value) {
238
+ if (!STRICT_JSON_STRING_TOKEN.test(value)) return false;
239
+ try {
240
+ return typeof JSON.parse(value) === "string";
241
+ } catch {
242
+ return false;
243
+ }
244
+ }
245
+ function closersOf(openStack) {
246
+ return openStack.slice().reverse().map((ch) => ch === "{" ? "}" : "]").join("");
247
+ }
248
+ function scanJsonForTailRepair(input) {
249
+ const stack = [];
250
+ let inString = false;
251
+ let escaped = false;
252
+ let lastCommaOutsideString = null;
253
+ for (let i = 0; i < input.length; i += 1) {
254
+ const ch = input[i];
255
+ if (inString) {
256
+ if (escaped) escaped = false;
257
+ else if (ch === "\\") escaped = true;
258
+ else if (ch === '"') inString = false;
259
+ continue;
260
+ }
261
+ if (ch === '"') {
262
+ inString = true;
263
+ continue;
264
+ }
265
+ if (ch === "{" || ch === "[") {
266
+ stack.push(ch);
267
+ continue;
268
+ }
269
+ if (ch === "}" || ch === "]") {
270
+ const open = stack.pop();
271
+ if (open !== (ch === "}" ? "{" : "[")) return null;
272
+ continue;
273
+ }
274
+ if (ch === ",") {
275
+ lastCommaOutsideString = { index: i, closers: closersOf(stack) };
276
+ continue;
277
+ }
278
+ }
279
+ return { inString, closers: closersOf(stack), lastCommaOutsideString };
280
+ }
281
+ function repairTruncatedToolArguments(raw) {
282
+ if (typeof raw !== "string") return null;
283
+ const withoutTrailingSpace = raw.replace(/\s+$/, "");
284
+ const endsWithComma = withoutTrailingSpace.endsWith(",");
285
+ const trimmed = endsWithComma ? withoutTrailingSpace.slice(0, -1).replace(/\s+$/, "") : withoutTrailingSpace;
286
+ if (trimmed === "" || trimmed.endsWith(",")) return null;
287
+ const scan = scanJsonForTailRepair(trimmed);
288
+ if (!scan || scan.inString) return null;
289
+ const lastChar = trimmed[trimmed.length - 1];
290
+ const tailIsCompleteToken = endsWithComma || lastChar === '"' || lastChar === "}" || lastChar === "]";
291
+ if (!tailIsCompleteToken) return null;
292
+ const candidates = [trimmed + scan.closers];
293
+ const lastComma = scan.lastCommaOutsideString;
294
+ if (lastComma && lastComma.index > 0) {
295
+ const tailAfterComma = trimmed.slice(lastComma.index + 1).trim();
296
+ if (isStrictJsonStringToken(tailAfterComma)) {
297
+ const head = trimmed.slice(0, lastComma.index);
298
+ candidates.push(head + lastComma.closers);
299
+ }
300
+ }
301
+ for (const candidate of candidates) {
302
+ try {
303
+ const parsed = JSON.parse(candidate);
304
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) && Object.keys(parsed).length > 0) {
305
+ return candidate;
306
+ }
307
+ } catch {
308
+ }
309
+ }
310
+ return null;
311
+ }
312
+ function downgradeUnparsableToolCalls(messages) {
313
+ if (!Array.isArray(messages) || messages.length === 0) {
314
+ return { messages, downgraded: 0 };
315
+ }
316
+ let hasAnyPoison = false;
317
+ for (const m of messages) {
318
+ if (m.role === "assistant" && Array.isArray(m.tool_calls)) {
319
+ for (const call of m.tool_calls) {
320
+ if (!hasParsableObjectArguments(call?.function?.arguments)) {
321
+ hasAnyPoison = true;
322
+ break;
323
+ }
324
+ }
325
+ }
326
+ if (hasAnyPoison) break;
327
+ }
328
+ if (!hasAnyPoison) return { messages, downgraded: 0 };
329
+ const poisonedCallsPerAssistant = /* @__PURE__ */ new Map();
330
+ const poisonedToolIndices = /* @__PURE__ */ new Set();
331
+ let i = 0;
332
+ while (i < messages.length) {
333
+ const m = messages[i];
334
+ if (m.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
335
+ const asstIdx = i;
336
+ const { unparsableIds } = classifyAssistantCalls(m.tool_calls, asstIdx);
337
+ let j = i + 1;
338
+ while (j < messages.length && messages[j].role === "tool") {
339
+ const toolMsg = messages[j];
340
+ const toolCallId = isNonEmptyString(toolMsg.tool_call_id) ? toolMsg.tool_call_id : "";
341
+ if (toolCallId && unparsableIds.has(toolCallId)) {
342
+ poisonedToolIndices.add(j);
343
+ }
344
+ j++;
345
+ }
346
+ if (unparsableIds.size > 0) {
347
+ poisonedCallsPerAssistant.set(asstIdx, unparsableIds);
348
+ }
349
+ i = j;
350
+ } else {
351
+ i++;
352
+ }
353
+ }
354
+ let downgraded = 0;
355
+ const out = [];
356
+ let k = 0;
357
+ while (k < messages.length) {
358
+ const m = messages[k];
359
+ if (m.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
360
+ const badIds = poisonedCallsPerAssistant.get(k);
361
+ if (!badIds || badIds.size === 0) {
362
+ out.push(m);
363
+ k++;
364
+ continue;
365
+ }
366
+ const kept = [];
367
+ const lines = [];
368
+ const { callIds } = classifyAssistantCalls(m.tool_calls, k);
369
+ m.tool_calls.forEach((call, callIndex) => {
370
+ const id = callIds[callIndex];
371
+ if (badIds.has(id)) {
372
+ lines.push(renderToolCallAsText(call));
373
+ downgraded++;
374
+ } else {
375
+ kept.push(call);
376
+ }
377
+ });
378
+ if (kept.length === 0) {
379
+ const sanitized2 = {
380
+ ...m,
381
+ content: combineContentWithText(m.content, joinLines(...lines))
382
+ };
383
+ delete sanitized2.tool_calls;
384
+ out.push(sanitized2);
385
+ let nextIdx2 = k + 1;
386
+ while (nextIdx2 < messages.length && messages[nextIdx2].role === "tool") {
387
+ if (poisonedToolIndices.has(nextIdx2)) {
388
+ out.push({ role: "assistant", content: renderToolResultAsText(messages[nextIdx2]) });
389
+ } else {
390
+ out.push(messages[nextIdx2]);
391
+ }
392
+ nextIdx2++;
393
+ }
394
+ k = nextIdx2;
395
+ continue;
396
+ }
397
+ const sanitized = {
398
+ ...m,
399
+ content: lines.length > 0 ? combineContentWithText(m.content, joinLines(...lines)) : m.content,
400
+ tool_calls: kept
401
+ };
402
+ out.push(sanitized);
403
+ let nextIdx = k + 1;
404
+ const deferredResultLines = [];
405
+ while (nextIdx < messages.length && messages[nextIdx].role === "tool") {
406
+ if (poisonedToolIndices.has(nextIdx)) {
407
+ deferredResultLines.push(renderToolResultAsText(messages[nextIdx]));
408
+ } else {
409
+ out.push(messages[nextIdx]);
410
+ }
411
+ nextIdx++;
412
+ }
413
+ if (deferredResultLines.length > 0) {
414
+ out.push({
415
+ role: "assistant",
416
+ content: joinLines(...deferredResultLines)
417
+ });
418
+ }
419
+ k = nextIdx;
420
+ continue;
421
+ }
422
+ if (m.role === "tool") {
423
+ if (poisonedToolIndices.has(k)) {
424
+ out.push({ role: "assistant", content: renderToolResultAsText(m) });
425
+ } else {
426
+ out.push(m);
427
+ }
428
+ k++;
429
+ continue;
430
+ }
431
+ out.push(m);
432
+ k++;
433
+ }
434
+ return { messages: out, downgraded };
435
+ }
436
+
437
+ export {
438
+ sanitizeForOutbound,
439
+ hasParsableObjectArguments,
440
+ repairTruncatedToolArguments,
441
+ downgradeUnparsableToolCalls
442
+ };
@@ -37,7 +37,7 @@ function resolveCliAuthorityBrokerPort(options = {}) {
37
37
  ...options,
38
38
  env: options.env ?? {}
39
39
  });
40
- return 47e3 + hashString(noloHome) % 2e3;
40
+ return 24e3 + hashString(noloHome) % 2e3;
41
41
  }
42
42
  function resolveCliAuthorityStoreDriver(options = {}) {
43
43
  return readCliAuthorityDriver(options.env ?? {}).driver;