nolo-cli 0.19.0 → 0.24.0-alpha.14

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 (134) hide show
  1. package/README.md +9 -18
  2. package/{_executeModel-X5PCIZN6.js → _executeModel-ZPNYAEFW.js} +46 -44
  3. package/{action-LT7BRFLK.js → action-5MNAXR5B.js} +7 -6
  4. package/{addContentAction-PL3KKBDH.js → addContentAction-UNSYTVTB.js} +5 -5
  5. package/{addDialogAgentAction-FCMSKYAF.js → addDialogAgentAction-LJGNP2AO.js} +5 -5
  6. package/{agentDeleteCommand-2BZDQV36.js → agentDeleteCommand-5ZV4433K.js} +27 -26
  7. package/{agentEmailCommands-2QJDGRMB.js → agentEmailCommands-Z7KOYDVQ.js} +57 -55
  8. package/{agentListCommands-6VEPTKBI.js → agentListCommands-UQUXJYUN.js} +30 -26
  9. package/{agentMachineCommands-NVVHNWYI.js → agentMachineCommands-53O6P6L5.js} +25 -24
  10. package/{agentRecordCommands-4GGRDMD4.js → agentRecordCommands-ZRYNBSSS.js} +52 -50
  11. package/{agentRunCommand-XOLQNKBZ.js → agentRunCommand-B73MKVOG.js} +55 -54
  12. package/{agentRunControl-Y5AFH5PQ.js → agentRunControl-SNUKXN6J.js} +6 -2
  13. package/{agentRuntimeLocal-7WYWCGL4.js → agentRuntimeLocal-GVNERRKQ.js} +21 -18
  14. package/{agentSlice-EAXPGEYV.js → agentSlice-OJBHIL34.js} +5 -5
  15. package/{appDeleteCommands-77KR2RJ4.js → appDeleteCommands-23Z3Z6KE.js} +23 -22
  16. package/{appDeployCommands-K7CAHGBI.js → appDeployCommands-3MFAR4Z7.js} +23 -22
  17. package/{appDeployStatusCommands-4OEKLTBT.js → appDeployStatusCommands-JHU6GSN4.js} +23 -22
  18. package/{appGetCommands-VM2WDLAZ.js → appGetCommands-24J55H2Y.js} +23 -22
  19. package/{appListCommands-GX6BBA6U.js → appListCommands-HE5KP3PH.js} +23 -22
  20. package/{authCommand-DY6UUL6O.js → authCommand-KGRK6MNU.js} +12 -13
  21. package/{authCommands-XTBV7OFZ.js → authCommands-JSOG2H4E.js} +4 -5
  22. package/{chunk-OWOHNGCN.js → chunk-2MBTWINN.js} +42 -3
  23. package/{chunk-MVQ4TBSD.js → chunk-54VHTARN.js} +1 -1
  24. package/{chunk-RQN4SEKL.js → chunk-5DWZ46RJ.js} +1 -1
  25. package/{chunk-VYHDJEQD.js → chunk-5EDKWSQN.js} +136 -78
  26. package/{chunk-Z4NR32XR.js → chunk-5RGU3J7P.js} +13 -0
  27. package/{chunk-7BUYEZ6U.js → chunk-7H3UTGPM.js} +12 -72
  28. package/{chunk-3ZX7PERL.js → chunk-AAWJ5S3G.js} +20 -7
  29. package/{chunk-SCTYAHYK.js → chunk-ADE6577S.js} +237 -142
  30. package/{chunk-PJSV3IZ5.js → chunk-AOPOTHFK.js} +1 -1
  31. package/{chunk-3ND52WIL.js → chunk-ATWUOTJP.js} +180 -24
  32. package/{chunk-SWDPIPOY.js → chunk-AZW5AHMW.js} +1 -1
  33. package/chunk-CF7S2RYZ.js +376 -0
  34. package/{chunk-L4F3I4SR.js → chunk-CV6BM7LU.js} +4 -6
  35. package/{chunk-G5U6LDLG.js → chunk-CWTT2NZ6.js} +6 -6
  36. package/{chunk-MKA6QE5E.js → chunk-CZHE6LLV.js} +135 -55
  37. package/{chunk-KFEVY3ST.js → chunk-D34RI6NI.js} +18 -8
  38. package/{chunk-XRZJGPFI.js → chunk-FON47ACC.js} +4 -4
  39. package/{chunk-K6EUAOW3.js → chunk-FXFGNOT2.js} +67 -1
  40. package/{chunk-LLWKHDG4.js → chunk-G36SUBHA.js} +14 -6
  41. package/{chunk-REA4JLBH.js → chunk-GD23ZX7Z.js} +7 -6
  42. package/{chunk-ROWQEJRP.js → chunk-GE6IWA5N.js} +12 -4
  43. package/{chunk-EDV7EBOI.js → chunk-GGB6MPHD.js} +2155 -1503
  44. package/{chunk-IYEXFJPC.js → chunk-GNGOZMU2.js} +64 -57
  45. package/{chunk-4T5F7YZQ.js → chunk-I6RJGORZ.js} +1 -1
  46. package/{chunk-DFCFMCY6.js → chunk-J2WT5CEO.js} +2 -2
  47. package/{chunk-AHCY2S2I.js → chunk-JJ2WUBFN.js} +1 -1
  48. package/{chunk-UGUW3FHG.js → chunk-JMSCXQUG.js} +2 -2
  49. package/{chunk-VDXCXCXH.js → chunk-KURQBS7S.js} +1 -1
  50. package/{chunk-FQZZLA3C.js → chunk-KXKQO4Q6.js} +17 -0
  51. package/{chunk-3Q7WHGCB.js → chunk-L65QKSVJ.js} +1 -1
  52. package/{chunk-UAIVG4J6.js → chunk-LEHTC2FI.js} +1 -8
  53. package/{chunk-UBHAWFQ6.js → chunk-LLDGWLML.js} +42 -19
  54. package/{chunk-JLA4FXYC.js → chunk-MALVZUYL.js} +1 -1
  55. package/{chunk-N54HIJVJ.js → chunk-MCXQNEJ3.js} +101 -9
  56. package/{chunk-GFUIQ4RY.js → chunk-MXFQHRSS.js} +1 -1
  57. package/{chunk-LSFAWXKC.js → chunk-N7J63Q6C.js} +1 -0
  58. package/{chunk-6Y7A3OQQ.js → chunk-NRY4GCKJ.js} +2 -0
  59. package/{chunk-ELT65PZW.js → chunk-OXLLFZNF.js} +1 -1
  60. package/{chunk-YGW4G5W5.js → chunk-P3RZ6DHN.js} +133 -25
  61. package/{chunk-5MIDPSSK.js → chunk-PB7G5MAM.js} +3 -3
  62. package/{chunk-HEGV7BH3.js → chunk-PMCKFQYC.js} +1 -1
  63. package/{chunk-23FZYPLC.js → chunk-PTKI7TIN.js} +911 -1064
  64. package/{chunk-MHSGJW4Z.js → chunk-PXPISYEH.js} +44 -14
  65. package/{chunk-I2ZJKTG5.js → chunk-PY7VGC5M.js} +29 -10
  66. package/{chunk-PIZYJVHQ.js → chunk-RM464B7I.js} +4 -4
  67. package/{chunk-XHG22OEX.js → chunk-ROJI6DRT.js} +2 -2
  68. package/{chunk-VNAEBGDK.js → chunk-RZNYL4LW.js} +123 -26
  69. package/{chunk-RVOUXDFU.js → chunk-S6KVFOUG.js} +6 -34
  70. package/{chunk-BV4VEE3W.js → chunk-S7AV3NCK.js} +277 -357
  71. package/{chunk-R35XMF6F.js → chunk-SIUEKVK4.js} +484 -67
  72. package/{chunk-B5TOXZAK.js → chunk-SIZQB7BD.js} +1 -1
  73. package/{chunk-DFFIZ25G.js → chunk-SLOGKB7M.js} +4 -1
  74. package/{chunk-MPVYDS7I.js → chunk-TLYHUIWF.js} +3 -3
  75. package/{chunk-HWW2M4SN.js → chunk-TNM27YZ7.js} +5 -4
  76. package/{chunk-OK6YSWLH.js → chunk-TWA4L7J7.js} +1 -1
  77. package/chunk-UZ6XXCVR.js +50 -0
  78. package/{chunk-DKZFOK24.js → chunk-WCP5FDTF.js} +16 -304
  79. package/{chunk-TRT4I4UD.js → chunk-WSQLK2KR.js} +2 -2
  80. package/{chunk-FXUSIQC2.js → chunk-XNZJVYFS.js} +1 -1
  81. package/{chunk-V3ED5AWK.js → chunk-YJY7HODU.js} +27 -16
  82. package/chunk-YYLHWIW6.js +48 -0
  83. package/{chunk-CZ6NYQTV.js → chunk-ZFL3LTU7.js} +2 -2
  84. package/{chunk-34WPV75U.js → chunk-ZUXIXYJI.js} +1 -1
  85. package/{chunk-VC6OZXO5.js → chunk-ZWJOGMKH.js} +2 -26
  86. package/{cliExecutor-DNE7TCC4.js → cliExecutor-K3F7DMRO.js} +2 -2
  87. package/{codingSkills-36KN5NQT.js → codingSkills-EN6Z6G6U.js} +4 -4
  88. package/{createAgentAutomationAction-GNFF524X.js → createAgentAutomationAction-PO62NUR7.js} +19 -18
  89. package/{createDialogAction-RB55KCLO.js → createDialogAction-ORFRYI3C.js} +22 -20
  90. package/{createPageAction-Y7343GLU.js → createPageAction-XWVMNTYH.js} +20 -19
  91. package/{db-W3O47YGF.js → db-W5UHK4P3.js} +150 -0
  92. package/{dbSlice-CGSRFJN3.js → dbSlice-5BKDURDL.js} +4 -4
  93. package/{dialogCommands-IAZK6YHQ.js → dialogCommands-XTJHROXM.js} +24 -23
  94. package/{dialogSlice-UQAXF23P.js → dialogSlice-DJXC53YW.js} +24 -18
  95. package/{docCreateCommands-I2EWZGCI.js → docCreateCommands-T2XRVXYS.js} +24 -27
  96. package/{docDeleteCommands-IZ45UZKG.js → docDeleteCommands-L7RXFXY3.js} +25 -24
  97. package/{docReadCommands-R6Z4QJYU.js → docReadCommands-M5PYNADQ.js} +24 -23
  98. package/{docStore-5HOJ4D7D.js → docStore-6LKLLFDW.js} +20 -19
  99. package/{docUpdateCommands-2LRBKQPY.js → docUpdateCommands-OA5EGPLQ.js} +24 -27
  100. package/{fetchMessages-BMGVZVSE.js → fetchMessages-W4IKHPCS.js} +2 -3
  101. package/{getPricing-G7DLAST6.js → getPricing-6C3C47Y4.js} +3 -3
  102. package/{handleSendMessageAction-Q4HY35WX.js → handleSendMessageAction-ILFGZTN5.js} +23 -20
  103. package/index.js +74 -74
  104. package/{localDialogRead-4H3QJFLW.js → localDialogRead-JXTAHW2E.js} +2 -2
  105. package/{machineCommands-PKBPQKTY.js → machineCommands-AKAQGPAO.js} +59 -57
  106. package/{machineWsRunDispatch-UZAW4OXJ.js → machineWsRunDispatch-RSBERM64.js} +51 -49
  107. package/{models-DJFSJ7SW.js → models-ILWKIX2Y.js} +2 -2
  108. package/package.json +1 -1
  109. package/{read-3FMPZPER.js → read-F3L3T2WJ.js} +2 -1
  110. package/{readDocTool-VSYHKK3V.js → readDocTool-FOHWVA4R.js} +1 -1
  111. package/{readlineWorkspace-Y2RDOFZG.js → readlineWorkspace-TUH3SFHO.js} +937 -430
  112. package/{removeDialogAgentAction-OAGA2G3U.js → removeDialogAgentAction-QCFGIUIH.js} +8 -7
  113. package/{runAgentClientLoop-NBPIKJ6J.js → runAgentClientLoop-C3QB2EXV.js} +45 -38
  114. package/{setDialogExtraReferencesAction-JZEXA5SL.js → setDialogExtraReferencesAction-DK4CKERU.js} +5 -5
  115. package/{setPrimaryDialogAgentAction-4ZUQQKDG.js → setPrimaryDialogAgentAction-SJSO6N27.js} +8 -7
  116. package/{settingSlice-7MNKHZ6R.js → settingSlice-XNM5AFPU.js} +6 -5
  117. package/{spaceCommands-DHCZ7J5I.js → spaceCommands-SXYOFGUJ.js} +25 -24
  118. package/{spaceSlice-ZXLLG3CR.js → spaceSlice-6BHMRP5O.js} +21 -18
  119. package/{streamAgentChatTurn-L3YW6LSB.js → streamAgentChatTurn-GF5W5OIP.js} +140 -98
  120. package/switchDialogAgentAction-4OAC6QRN.js +61 -0
  121. package/{tableCommands-BEQAGE4I.js → tableCommands-QSZILI7I.js} +1 -1
  122. package/{toolApiClient-QI3YBNWB.js → toolApiClient-ISM4ZQX4.js} +2 -2
  123. package/{tools-ECGXR5QF.js → tools-KBCLJ43G.js} +36 -33
  124. package/{tuiSummaryLlmCaller-OMSCNHXA.js → tuiSummaryLlmCaller-ARIMGILF.js} +6 -6
  125. package/{updateCommands-XTW55TOT.js → updateCommands-AK2RDOFR.js} +8 -2
  126. package/{updateDialogTitleAction-HQ2EUDFT.js → updateDialogTitleAction-LMHZUY4Q.js} +28 -27
  127. package/chunk-DL6EPNIK.js +0 -50
  128. package/chunk-V5R4NZP2.js +0 -78
  129. package/chunk-X4Q4UZEY.js +0 -26
  130. package/queryRunOverlay-O4LOMMPO.js +0 -161
  131. package/runOverlayPresentation-ZO4VCWEU.js +0 -11
  132. package/types-ZSTJ7MPR.js +0 -7
  133. package/{chunk-X7W4TNB4.js → chunk-CMKUBIGW.js} +3 -3
  134. package/{runtimeDoctorCommands-E2OUORHK.js → runtimeDoctorCommands-HSU632DY.js} +3 -3
@@ -3,9 +3,10 @@ import {
3
3
  extractThinkContent,
4
4
  flushThinkParser,
5
5
  flushToolCallTextParserIntoCallback,
6
+ longestTagPrefixLength,
6
7
  processContentChunkWithToolCallStripping,
7
8
  processThinkChunk
8
- } from "./chunk-LSFAWXKC.js";
9
+ } from "./chunk-N7J63Q6C.js";
9
10
  import {
10
11
  convertMessagesToResponsesInput,
11
12
  extractTextFromResponseOutput,
@@ -14,7 +15,7 @@ import {
14
15
  shouldStripReasoningContentForOutbound,
15
16
  toOpenAiCompatibleMessages,
16
17
  toResponsesTools
17
- } from "./chunk-KFEVY3ST.js";
18
+ } from "./chunk-D34RI6NI.js";
18
19
  import {
19
20
  buildProviderExecutionPlan,
20
21
  canUsePlatformChatProvider,
@@ -23,7 +24,7 @@ import {
23
24
  resolvePlatformAuthToken,
24
25
  resolvePlatformServerUrl,
25
26
  resolveProviderTransportDecision
26
- } from "./chunk-MHSGJW4Z.js";
27
+ } from "./chunk-PXPISYEH.js";
27
28
  import {
28
29
  clipCompactText
29
30
  } from "./chunk-5MMAK75Q.js";
@@ -59,6 +60,90 @@ function providerHttpFailure(args) {
59
60
  );
60
61
  }
61
62
 
63
+ // packages/agent-runtime/deepseekDsmlParser.ts
64
+ var DSML_OPEN = "<\uFF5C\uFF5CDSML\uFF5C\uFF5Ctool_calls>";
65
+ var DSML_CLOSE = "</\uFF5C\uFF5CDSML\uFF5C\uFF5Ctool_calls>";
66
+ var DSML_INVOKE_RE = /<||DSML||invoke\s+name="([^"]+)">([\s\S]*?)<\/||DSML||invoke>/g;
67
+ var DSML_PARAMETER_RE = /<||DSML||parameter\s+([^>]+)>([\s\S]*?)<\/||DSML||parameter>/g;
68
+ function createDsmlParserState() {
69
+ return { mode: "content", buffer: "" };
70
+ }
71
+ function parseAttributes(raw) {
72
+ return {
73
+ name: raw.match(/(?:^|\s)name="([^"]+)"/)?.[1],
74
+ stringFlag: raw.match(/(?:^|\s)string="(true|false)"/)?.[1]
75
+ };
76
+ }
77
+ function decode(value) {
78
+ return value.replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
79
+ }
80
+ function parseValue(value) {
81
+ try {
82
+ return JSON.parse(value);
83
+ } catch {
84
+ return value;
85
+ }
86
+ }
87
+ function parseCalls(text) {
88
+ const calls = [];
89
+ for (const match of text.matchAll(DSML_INVOKE_RE)) {
90
+ const args = {};
91
+ for (const parameter of match[2].matchAll(DSML_PARAMETER_RE)) {
92
+ const attrs = parseAttributes(parameter[1]);
93
+ if (!attrs.name) continue;
94
+ const value = decode(parameter[2]);
95
+ args[attrs.name] = attrs.stringFlag === "true" ? value : attrs.stringFlag === "false" ? parseValue(value) : value;
96
+ }
97
+ const name = match[1];
98
+ if (name === "readFile" && args.path === void 0 && args.file !== void 0) {
99
+ args.path = args.file;
100
+ delete args.file;
101
+ }
102
+ calls.push({ name, arguments: JSON.stringify(args) });
103
+ }
104
+ return calls;
105
+ }
106
+ function pushDsmlChunk(chunk, state) {
107
+ state.buffer += chunk;
108
+ let content = "";
109
+ const toolCalls = [];
110
+ while (true) {
111
+ if (state.mode === "content") {
112
+ const index = state.buffer.indexOf(DSML_OPEN);
113
+ if (index < 0) {
114
+ const keep = longestTagPrefixLength(state.buffer, DSML_OPEN);
115
+ content += state.buffer.slice(0, state.buffer.length - keep);
116
+ state.buffer = state.buffer.slice(state.buffer.length - keep);
117
+ break;
118
+ }
119
+ content += state.buffer.slice(0, index);
120
+ state.buffer = state.buffer.slice(index + DSML_OPEN.length);
121
+ state.mode = "dsml";
122
+ } else {
123
+ const index = state.buffer.indexOf(DSML_CLOSE);
124
+ if (index < 0) break;
125
+ toolCalls.push(...parseCalls(state.buffer.slice(0, index)));
126
+ state.buffer = state.buffer.slice(index + DSML_CLOSE.length);
127
+ state.mode = "content";
128
+ }
129
+ }
130
+ return { content, toolCalls };
131
+ }
132
+ function finishDsml(state) {
133
+ const result = { content: "", toolCalls: [] };
134
+ if (state.mode === "dsml") result.toolCalls.push(...parseCalls(state.buffer));
135
+ else result.content = state.buffer;
136
+ state.mode = "content";
137
+ state.buffer = "";
138
+ return result;
139
+ }
140
+ function parseDsml(text) {
141
+ const state = createDsmlParserState();
142
+ const chunk = pushDsmlChunk(text, state);
143
+ const tail = finishDsml(state);
144
+ return { content: chunk.content + tail.content, toolCalls: [...chunk.toolCalls, ...tail.toolCalls] };
145
+ }
146
+
62
147
  // packages/agent-runtime/processChatCompletionDelta.ts
63
148
  function extractChatCompletionStreamError(parsed) {
64
149
  const raw = parsed?.error;
@@ -204,6 +289,9 @@ function shouldDisableThinking(providerConfig) {
204
289
  function isResponsesEndpoint(endpoint) {
205
290
  return /\/responses$/i.test(endpoint.trim());
206
291
  }
292
+ function buildDsmlToolCallId(baseCount, index) {
293
+ return `dsml-${baseCount + index + 1}`;
294
+ }
207
295
  function toResponsesRequestOptions(options) {
208
296
  const next = { ...options };
209
297
  const reasoningEffort = next.reasoning_effort;
@@ -266,9 +354,7 @@ function buildPlatformChatCompletionRequest(args) {
266
354
  const body = {
267
355
  model: args.providerConfig.model,
268
356
  ...usesResponsesApi ? {
269
- input: convertMessagesToResponsesInput(args.messages, {
270
- stripReasoningContent: shouldStripReasoning
271
- })
357
+ input: convertMessagesToResponsesInput(args.messages)
272
358
  } : {
273
359
  messages: toOpenAiCompatibleMessages(args.messages, {
274
360
  stripReasoningContent: shouldStripReasoning
@@ -353,13 +439,19 @@ function parsePlatformChatCompletionData(raw) {
353
439
  }
354
440
  function parsePlatformChatCompletionResponse(args) {
355
441
  if (isResponsesEndpoint(args.providerConfig.endpoint)) {
356
- const content2 = extractTextFromResponseOutput(args.data);
442
+ const rawContent2 = extractTextFromResponseOutput(args.data);
443
+ const dsml = parseDsml(rawContent2);
357
444
  const tool_calls = extractToolCallsFromResponseOutput(args.data);
445
+ const normalizedToolCalls = tool_calls.length > 0 ? tool_calls : dsml.toolCalls.map((call, index) => ({
446
+ id: buildDsmlToolCallId(tool_calls.length, index),
447
+ type: "function",
448
+ function: { name: call.name, arguments: call.arguments }
449
+ }));
358
450
  return {
359
- content: content2,
451
+ content: dsml.content,
360
452
  model: args.providerConfig.model,
361
453
  provider: args.providerConfig.provider,
362
- ...tool_calls.length > 0 ? { tool_calls } : {},
454
+ ...normalizedToolCalls.length > 0 ? { tool_calls: normalizedToolCalls } : {},
363
455
  stream_complete: true,
364
456
  usage: args.data?.usage,
365
457
  trace: args.trace
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildSkillDocMarkdown
3
- } from "./chunk-VC6OZXO5.js";
3
+ } from "./chunk-ZWJOGMKH.js";
4
4
 
5
5
  // packages/cli/docPageHelpers.ts
6
6
  import { readFileSync } from "node:fs";
@@ -231,6 +231,7 @@ function finalizeAccumulatedToolCalls(accumulator) {
231
231
  }
232
232
 
233
233
  export {
234
+ longestTagPrefixLength,
234
235
  extractThinkContent,
235
236
  createThinkParserState,
236
237
  processThinkChunk,
@@ -2755,6 +2755,8 @@ var createTokenKey = {
2755
2755
  record: (0, import_rambda.curry)(
2756
2756
  (userId, timestamp) => createKey("token", userId, timestamp.toString())
2757
2757
  ),
2758
+ /** Server provider-call record: retry-stable even when the retry clock changes. */
2759
+ recordForStableCall: (userId, callId) => createKey("token", userId, "call", encodeURIComponent(callId)),
2758
2760
  range: (userId, timestamp) => ({
2759
2761
  start: createKey("token", userId, timestamp.toString()),
2760
2762
  end: createKey("token", userId, (timestamp + 864e5).toString())
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  patch,
3
3
  read
4
- } from "./chunk-XRZJGPFI.js";
4
+ } from "./chunk-FON47ACC.js";
5
5
  import {
6
6
  DEVICE_LOCAL_OWNER_ID,
7
7
  isDeviceLocalSpaceBody,
@@ -3,30 +3,31 @@ import {
3
3
  buildCurrentTimeBlock,
4
4
  buildIdentityBlock,
5
5
  buildRuntimeGuidanceBlocks
6
- } from "./chunk-34WPV75U.js";
6
+ } from "./chunk-ZUXIXYJI.js";
7
7
  import {
8
8
  estimateTokenCount,
9
9
  getModelContextWindow,
10
10
  planCompression,
11
11
  planContextUsage,
12
12
  serializeMessageContent
13
- } from "./chunk-I2ZJKTG5.js";
13
+ } from "./chunk-PY7VGC5M.js";
14
14
  import {
15
15
  clipCompactText
16
16
  } from "./chunk-5MMAK75Q.js";
17
17
  import {
18
18
  findModelConfig,
19
19
  getProviderByModelName
20
- } from "./chunk-UAIVG4J6.js";
21
- import {
22
- toErrorMessage
23
- } from "./chunk-HNMXYYJR.js";
20
+ } from "./chunk-LEHTC2FI.js";
24
21
  import {
25
22
  buildDialogSummaryLayer
26
23
  } from "./chunk-AL2V7U3E.js";
27
24
  import {
25
+ canonicalizeToolName,
28
26
  canonicalizeToolNames
29
27
  } from "./chunk-ZZ2MH7LE.js";
28
+ import {
29
+ toErrorMessage
30
+ } from "./chunk-HNMXYYJR.js";
30
31
  import {
31
32
  asRecordOrEmpty
32
33
  } from "./chunk-KX6YBIHG.js";
@@ -372,24 +373,81 @@ function clipToolText(content, maxChars, headRatio, marker = "\n\n[... tool outp
372
373
  // packages/agent-runtime/localAutoCompaction.ts
373
374
  var LOCAL_AUTO_COMPACTION_SYSTEM_PROMPT = `\u4F60\u662F\u5BF9\u8BDD\u4E0A\u4E0B\u6587\u538B\u7F29\u5668\u3002\u6839\u636E\u3010\u73B0\u6709\u8BB0\u5FC6\u3011\u548C\u3010\u65B0\u589E\u5BF9\u8BDD\u3011\uFF0C\u8F93\u51FA\u53EF\u66FF\u4EE3\u539F\u59CB\u6D88\u606F\u7684\u4E8B\u5B9E\u6027\u8981\u70B9\uFF0C\u4F9B\u540E\u7EED\u5BF9\u8BDD\u76F4\u63A5\u4F7F\u7528\u3002
374
375
 
375
- \u4E25\u683C\u53EA\u8F93\u51FA\u4E0B\u9762\u4E24\u90E8\u5206\uFF0C\u6807\u9898\u5FC5\u987B\u5B8C\u5168\u4E00\u81F4\uFF1A
376
+ \u4E25\u683C\u53EA\u8F93\u51FA\u4E0B\u9762\u4E09\u90E8\u5206\uFF0C\u6807\u9898\u5FC5\u987B\u5B8C\u5168\u4E00\u81F4\uFF1A
376
377
  \u5173\u952E\u4E8B\u5B9E\u6863\u6848
377
378
  - ...
378
379
  \u5BF9\u8BDD\u8FDB\u5C55\u4E0E\u5F85\u529E
379
380
  - ...
381
+ \u6587\u4EF6\u64CD\u4F5C\u6E05\u5355
382
+ - ...
380
383
 
381
384
  \u8981\u6C42\uFF1A
382
385
  1) \u4F7F\u7528\u5BF9\u8BDD\u4E3B\u8BED\u8A00\uFF1B\u6DF7\u5408\u8BED\u8A00\u65F6\u4F18\u5148\u7528\u6237\u4E3B\u8981\u8BED\u8A00\uFF1B\u4E13\u6709\u540D\u8BCD\u3001\u6587\u4EF6\u8DEF\u5F84\u3001\u6807\u8BC6\u7B26\u3001\u547D\u4EE4\u4FDD\u7559\u539F\u6587\u3002
383
386
  2) \u5173\u952E\u4E8B\u5B9E\u6863\u6848\u53EA\u4FDD\u7559\u4E4B\u540E\u7EE7\u7EED\u5BF9\u8BDD\u4ECD\u6709\u4EF7\u503C\u7684\u4FE1\u606F\uFF1A\u7528\u6237\u76EE\u6807/\u504F\u597D\u3001\u7EA6\u675F\u3001\u6280\u672F\u6808\u3001\u786E\u5B9A\u7684\u6587\u4EF6\u8DEF\u5F84\u3001\u6838\u5FC3\u51B3\u7B56\u3001\u672A\u5B8C\u6210\u5F85\u529E\u3002
384
387
  3) \u5BF9\u8BDD\u8FDB\u5C55\u4E0E\u5F85\u529E\uFF1A\u5148\u6781\u7B80\u6982\u62EC\u65E7\u4E0A\u4E0B\u6587\uFF0C\u518D\u66F4\u8BE6\u7EC6\u8BB0\u5F55\u6700\u8FD1\u8FDB\u5C55\u3001\u7ED3\u8BBA\u3001\u5206\u6B67\u4E0E\u4E0B\u4E00\u6B65\u3002
385
- 4) \u5FFD\u7565\u5BD2\u6684\u3001\u91CD\u590D\u5C1D\u8BD5\u3001\u5DF2\u653E\u5F03\u65B9\u6848\u548C\u65E0\u4EF7\u503C\u5E9F\u8BDD\u3002
386
- 5) \u4E0D\u8981\u7F16\u9020\u672A\u51FA\u73B0\u7684\u4FE1\u606F\uFF1B\u4E0D\u8981\u5F00\u573A\u767D\u3001\u7ED3\u675F\u8BED\u3001markdown \u4EE3\u7801\u5757\u6216\u989D\u5916\u7AE0\u8282\uFF1B\u4E0D\u8981\u8C03\u7528\u4EFB\u4F55\u5DE5\u5177\u3002`;
387
- function buildLocalAutoCompactionUserContent(previousSummary, messagesText) {
388
- return `\u3010\u73B0\u6709\u8BB0\u5FC6\u3011\uFF1A
389
- ${previousSummary || "(\u65E0)"}
390
-
391
- \u3010\u65B0\u589E\u5BF9\u8BDD\u3011\uFF1A
392
- ${messagesText}`.trim();
388
+ 4) \u6587\u4EF6\u64CD\u4F5C\u6E05\u5355\uFF1A\u5217\u51FA\u672C\u6B21\u538B\u7F29\u8303\u56F4\u5185\u8BFB\u53D6\u3001\u5199\u5165\u3001\u7F16\u8F91\u8FC7\u7684\u6587\u4EF6\u8DEF\u5F84\u53CA\u64CD\u4F5C\u7C7B\u578B\uFF08\u5982: - \u8BFB\u53D6: path/to/file\uFF1B\u82E5\u672A\u6D89\u53CA\u6587\u4EF6\u64CD\u4F5C\u5199"\u65E0"\uFF09\u3002
389
+ 5) \u5FFD\u7565\u5BD2\u6684\u3001\u91CD\u590D\u5C1D\u8BD5\u3001\u5DF2\u653E\u5F03\u65B9\u6848\u548C\u65E0\u4EF7\u503C\u5E9F\u8BDD\u3002
390
+ 6) \u4E0D\u8981\u7F16\u9020\u672A\u51FA\u73B0\u7684\u4FE1\u606F\uFF1B\u4E0D\u8981\u5F00\u573A\u767D\u3001\u7ED3\u675F\u8BED\u3001markdown \u4EE3\u7801\u5757\u6216\u989D\u5916\u7AE0\u8282\uFF1B\u4E0D\u8981\u8C03\u7528\u4EFB\u4F55\u5DE5\u5177\u3002`;
391
+ function extractFileOperations(msgs) {
392
+ const result = [];
393
+ const seen = /* @__PURE__ */ new Set();
394
+ for (const msg of msgs) {
395
+ if (!Array.isArray(msg.tool_calls)) continue;
396
+ for (const call of msg.tool_calls) {
397
+ const name = call.function?.name || call.name || "";
398
+ if (!name) continue;
399
+ const canonicalName = canonicalizeToolName(name);
400
+ const fileOperationByTool = {
401
+ readFile: "read",
402
+ writeFile: "write",
403
+ editFile: "edit"
404
+ };
405
+ const opType = fileOperationByTool[canonicalName];
406
+ if (!opType) continue;
407
+ let rawArgs = call.function?.arguments ?? call.arguments;
408
+ let parsedArgs = null;
409
+ if (typeof rawArgs === "string") {
410
+ try {
411
+ parsedArgs = JSON.parse(rawArgs);
412
+ } catch {
413
+ }
414
+ } else if (typeof rawArgs === "object" && rawArgs !== null) {
415
+ parsedArgs = rawArgs;
416
+ }
417
+ const path = parsedArgs?.path ?? parsedArgs?.filePath ?? parsedArgs?.file;
418
+ if (typeof path === "string" && path.trim()) {
419
+ const key = `${opType}:${path.trim()}`;
420
+ if (!seen.has(key)) {
421
+ seen.add(key);
422
+ result.push({ type: opType, path: path.trim() });
423
+ }
424
+ }
425
+ }
426
+ }
427
+ return result;
428
+ }
429
+ function formatFileOperations(msgs) {
430
+ const ops = extractFileOperations(msgs);
431
+ if (ops.length === 0) {
432
+ return "\u65E0";
433
+ }
434
+ const typeLabelMap = {
435
+ read: "\u8BFB\u53D6",
436
+ write: "\u5199\u5165",
437
+ edit: "\u7F16\u8F91"
438
+ };
439
+ return ops.map((op) => `- ${typeLabelMap[op.type]}: ${op.path}`).join("\n");
440
+ }
441
+ function buildLocalAutoCompactionUserContent(previousSummary, messagesText, fileOpsText) {
442
+ const parts = [`\u3010\u73B0\u6709\u8BB0\u5FC6\u3011\uFF1A
443
+ ${previousSummary || "(\u65E0)"}`];
444
+ if (fileOpsText !== void 0) {
445
+ parts.push(`\u3010\u6587\u4EF6\u64CD\u4F5C\u6E05\u5355\u3011\uFF1A
446
+ ${fileOpsText || "\u65E0"}`);
447
+ }
448
+ parts.push(`\u3010\u65B0\u589E\u5BF9\u8BDD\u3011\uFF1A
449
+ ${messagesText}`);
450
+ return parts.join("\n\n").trim();
393
451
  }
394
452
  function toPlanCompressionMessages(history) {
395
453
  return history.map((message, index) => {
@@ -485,12 +543,13 @@ async function maybeAutoCompactLocalHistory(args) {
485
543
  }
486
544
  try {
487
545
  const provider = await args.resolveProvider();
488
- const messagesText = formatMessagesForLocalSummary(
489
- plan.msgsToCompress
490
- );
546
+ const msgsToCompress = plan.msgsToCompress;
547
+ const messagesText = formatMessagesForLocalSummary(msgsToCompress);
548
+ const fileOpsText = formatFileOperations(msgsToCompress);
491
549
  const promptContent = buildLocalAutoCompactionUserContent(
492
550
  existingSummary,
493
- messagesText
551
+ messagesText,
552
+ fileOpsText
494
553
  );
495
554
  const result = await provider.complete([
496
555
  { role: "system", content: LOCAL_AUTO_COMPACTION_SYSTEM_PROMPT },
@@ -1074,7 +1133,7 @@ function mergeTurnUsage(current, next) {
1074
1133
  const right = read(next);
1075
1134
  const left = current ? read(current) : { input: 0, output: 0, cacheHit: 0, cacheMiss: 0 };
1076
1135
  return {
1077
- input_tokens: right.input || left.input,
1136
+ input_tokens: left.input + right.input,
1078
1137
  output_tokens: left.output + right.output,
1079
1138
  cache_read_input_tokens: left.cacheHit + right.cacheHit,
1080
1139
  cache_creation_input_tokens: left.cacheMiss + right.cacheMiss
@@ -1120,8 +1179,12 @@ async function persistFailedLocalTurn(args) {
1120
1179
  model: args.model ?? "unknown",
1121
1180
  toolCallCount: args.toolCallCount ?? 0,
1122
1181
  error: true,
1123
- errorMessage
1182
+ errorMessage,
1183
+ ...args.usage ? { usage: args.usage } : {}
1124
1184
  },
1185
+ ...args.accountingUsage ? { accountingUsage: args.accountingUsage } : {},
1186
+ ...args.usageRecords?.length ? { usageRecords: args.usageRecords } : {},
1187
+ ...args.billingConfig ? { billingConfig: args.billingConfig } : {},
1125
1188
  ...args.input.runtimeContext ? { runtimeContext: args.input.runtimeContext } : {},
1126
1189
  ...args.input.continueDialogId ? { continueDialogId: args.input.continueDialogId } : {},
1127
1190
  ...args.input.spaceId ? { spaceId: args.input.spaceId } : {},
@@ -1159,6 +1222,18 @@ async function runLocalAgentTurn(input) {
1159
1222
  error.agentRef = input.agentRef;
1160
1223
  throw error;
1161
1224
  }
1225
+ const rawBillingConfig = agentConfig.rawRecord ?? {};
1226
+ const billingConfig = {
1227
+ model: agentConfig.model || "unknown",
1228
+ ...agentConfig.provider ? { provider: agentConfig.provider } : {},
1229
+ ...agentConfig.apiSource ? { apiSource: agentConfig.apiSource } : {},
1230
+ ...agentConfig.apiKeyRef !== void 0 ? { apiKeyRef: agentConfig.apiKeyRef } : {},
1231
+ ...typeof rawBillingConfig.inputPrice === "number" ? { inputPrice: rawBillingConfig.inputPrice } : {},
1232
+ ...typeof rawBillingConfig.outputPrice === "number" ? { outputPrice: rawBillingConfig.outputPrice } : {},
1233
+ ...rawBillingConfig.sharingLevel ? { sharingLevel: rawBillingConfig.sharingLevel } : {},
1234
+ id: agentConfig.key,
1235
+ ...typeof rawBillingConfig.userId === "string" ? { userId: rawBillingConfig.userId } : {}
1236
+ };
1162
1237
  let history = [];
1163
1238
  try {
1164
1239
  history = input.continueDialogId ? await input.adapter.loadDialogHistory(input.continueDialogId) : [];
@@ -1250,6 +1325,8 @@ async function runLocalAgentTurn(input) {
1250
1325
  let toolCallCount = 0;
1251
1326
  let result;
1252
1327
  let turnUsage;
1328
+ let contextUsage;
1329
+ const usageRecords = [];
1253
1330
  let loopError;
1254
1331
  let round = 0;
1255
1332
  let emptyAssistantRepairPending = false;
@@ -1306,6 +1383,15 @@ async function runLocalAgentTurn(input) {
1306
1383
  context: contextMetrics
1307
1384
  });
1308
1385
  turnUsage = mergeTurnUsage(turnUsage, result.usage);
1386
+ contextUsage = result.usage;
1387
+ if (result.usage && Object.keys(result.usage).length > 0) {
1388
+ usageRecords.push({
1389
+ callId: typeof result.usage.provider_call_id === "string" && result.usage.provider_call_id.trim() ? result.usage.provider_call_id.trim() : crypto.randomUUID(),
1390
+ usage: result.usage,
1391
+ model: result.model || agentConfig.model || "unknown",
1392
+ ...result.provider || agentConfig.provider ? { provider: result.provider || agentConfig.provider } : {}
1393
+ });
1394
+ }
1309
1395
  const toolCalls = result.tool_calls ?? [];
1310
1396
  const rawToolCallsCount = (result.tool_calls?.length ?? 0) || (Array.isArray(result.raw_tool_calls) ? result.raw_tool_calls.length : 0);
1311
1397
  if (toolCalls.length === 0 && rawToolCallsCount === 0) {
@@ -1463,6 +1549,18 @@ async function runLocalAgentTurn(input) {
1463
1549
  model: agentConfig.model,
1464
1550
  toolCallCount,
1465
1551
  partialContent,
1552
+ usage: contextUsage,
1553
+ accountingUsage: addOutOfBandUsage(turnUsage, compactionUsage),
1554
+ usageRecords: [
1555
+ ...compactionUsage ? [{
1556
+ callId: typeof compactionUsage.provider_call_id === "string" && compactionUsage.provider_call_id.trim() ? compactionUsage.provider_call_id.trim() : crypto.randomUUID(),
1557
+ usage: compactionUsage,
1558
+ model: agentConfig.model || "unknown",
1559
+ ...agentConfig.provider ? { provider: agentConfig.provider } : {}
1560
+ }] : [],
1561
+ ...usageRecords
1562
+ ],
1563
+ billingConfig,
1466
1564
  input
1467
1565
  });
1468
1566
  attachDialogIdToError(loopError, dialogId);
@@ -1483,6 +1581,15 @@ async function runLocalAgentTurn(input) {
1483
1581
  input.persistedInput,
1484
1582
  input.persistedInputReference
1485
1583
  );
1584
+ if (compactionUsage && Object.keys(compactionUsage).length > 0) {
1585
+ usageRecords.unshift({
1586
+ callId: typeof compactionUsage.provider_call_id === "string" && compactionUsage.provider_call_id.trim() ? compactionUsage.provider_call_id.trim() : crypto.randomUUID(),
1587
+ usage: compactionUsage,
1588
+ model: agentConfig.model || result.model || "unknown",
1589
+ ...agentConfig.provider ? { provider: agentConfig.provider } : {}
1590
+ });
1591
+ }
1592
+ const accountingUsage = addOutOfBandUsage(turnUsage, compactionUsage);
1486
1593
  const saved = await input.adapter.saveTurn({
1487
1594
  agentKey: agentConfig.key,
1488
1595
  messages: turnMessages,
@@ -1491,6 +1598,9 @@ async function runLocalAgentTurn(input) {
1491
1598
  ...toolCallCount > 0 ? { toolCallCount } : {},
1492
1599
  ...agentConfig.toolSurface ? { runtimeToolSurface: agentConfig.toolSurface } : {}
1493
1600
  },
1601
+ ...usageRecords.length > 0 ? { usageRecords } : {},
1602
+ ...accountingUsage ? { accountingUsage } : {},
1603
+ billingConfig,
1494
1604
  ...input.runtimeContext ? { runtimeContext: input.runtimeContext } : {},
1495
1605
  ...input.continueDialogId ? { continueDialogId: input.continueDialogId } : {},
1496
1606
  ...input.spaceId ? { spaceId: input.spaceId } : {},
@@ -1500,10 +1610,8 @@ async function runLocalAgentTurn(input) {
1500
1610
  });
1501
1611
  return {
1502
1612
  ...result,
1503
- ...(() => {
1504
- const merged = addOutOfBandUsage(turnUsage, compactionUsage);
1505
- return merged ? { usage: merged } : {};
1506
- })(),
1613
+ ...usageRecords.length > 0 ? { usageRecords } : {},
1614
+ ...accountingUsage ? { accountingUsage } : {},
1507
1615
  ...toolCallCount > 0 ? { toolCallCount } : {},
1508
1616
  ...agentConfig.toolSurface ? { runtimeToolSurface: agentConfig.toolSurface } : {},
1509
1617
  // 透出最后一轮 provider 调用的 finish_reason;多轮工具循环里只有最后一轮收尾状态有意义。
@@ -1,6 +1,3 @@
1
- import {
2
- extractCustomId
3
- } from "./chunk-DFFIZ25G.js";
4
1
  import {
5
2
  getActiveDialogKey
6
3
  } from "./chunk-3ASDTTEI.js";
@@ -10,6 +7,9 @@ import {
10
7
  import {
11
8
  asTrimmedLowercaseString
12
9
  } from "./chunk-QSJ3HFEF.js";
10
+ import {
11
+ extractCustomId
12
+ } from "./chunk-SLOGKB7M.js";
13
13
  import {
14
14
  isRecord
15
15
  } from "./chunk-KUG52IAP.js";
@@ -2,7 +2,7 @@ import {
2
2
  deleteDbRecord,
3
3
  queryUserRecords,
4
4
  readDbRecord
5
- } from "./chunk-DFCFMCY6.js";
5
+ } from "./chunk-J2WT5CEO.js";
6
6
  import {
7
7
  mergeAndDedupUserData
8
8
  } from "./chunk-KQHGZWSV.js";