nolo-cli 0.8.0-alpha.21 → 0.8.0-alpha.23

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 (112) hide show
  1. package/{_executeModel-42U3VOVZ.js → _executeModel-YXTTYRXS.js} +44 -43
  2. package/{action-TLI3V62L.js → action-QM2ONPYZ.js} +9 -9
  3. package/{addContentAction-57RSIIMR.js → addContentAction-UXY3GM53.js} +8 -8
  4. package/{addDialogAgentAction-G3VWEA6E.js → addDialogAgentAction-MUBYOG65.js} +10 -10
  5. package/{agentDeleteCommand-5DD2IM3J.js → agentDeleteCommand-4NO7Y6UI.js} +28 -27
  6. package/{agentEmailCommands-6FACJBU4.js → agentEmailCommands-NPP5TGZV.js} +60 -58
  7. package/{agentListCommands-I6KZYCIG.js → agentListCommands-IP5BNB5W.js} +32 -30
  8. package/{agentMachineCommands-VKLIGMZA.js → agentMachineCommands-24NFTIKY.js} +27 -26
  9. package/{agentPullCommand-O2MTUAFR.js → agentPullCommand-N6UWRTVL.js} +3 -3
  10. package/{agentRecordCommands-7TZICYDT.js → agentRecordCommands-7AWSR46F.js} +51 -49
  11. package/{agentRunCommand-L4OM23KV.js → agentRunCommand-P46WCJ6P.js} +55 -52
  12. package/{agentRunControl-K4VKNEHF.js → agentRunControl-S3G62M6C.js} +3 -3
  13. package/{agentRuntimeLocal-ZYEIPTY4.js → agentRuntimeLocal-V5UV7S4R.js} +14 -12
  14. package/{agentSlice-BX7GXSNO.js → agentSlice-3CVAZZOP.js} +9 -9
  15. package/{authCommand-EB5JSOX5.js → authCommand-B6P2XYLN.js} +11 -11
  16. package/{authCommands-XPEHTKSM.js → authCommands-4YKA4GTU.js} +7 -7
  17. package/{chunk-AS4PVWA4.js → chunk-2CVZSC5L.js} +1 -1
  18. package/{chunk-VUW5FBDB.js → chunk-4VA3UQRF.js} +9 -9
  19. package/{chunk-2JCXITPK.js → chunk-5NYGMN4O.js} +15 -15
  20. package/{chunk-AGFH73SK.js → chunk-6KRA6AWI.js} +1 -1
  21. package/{chunk-P3PKED2I.js → chunk-6OHYC4BY.js} +9 -12
  22. package/{chunk-5KLGBAAR.js → chunk-6UUD2WES.js} +1 -1
  23. package/{chunk-ENOG22KJ.js → chunk-A4MYG3TR.js} +18 -20
  24. package/{chunk-2FTTDCD4.js → chunk-AMJ7LA5D.js} +1 -1
  25. package/chunk-AOKWJZ5N.js +4884 -0
  26. package/{chunk-JRKKFRAV.js → chunk-AWY2AFHN.js} +9 -5
  27. package/{chunk-RL776AGR.js → chunk-BB2PII22.js} +1 -1
  28. package/{chunk-I6XMPTMR.js → chunk-BFDWXLFF.js} +2 -2
  29. package/{chunk-VVX233PH.js → chunk-BT37DVDA.js} +9 -9
  30. package/chunk-BYXBJQAS.js +0 -0
  31. package/{chunk-C3RUNRHT.js → chunk-D55DXHXL.js} +1 -1
  32. package/{chunk-7DAJ4AI4.js → chunk-DSNLHTP3.js} +2 -2
  33. package/{chunk-SDJDLO5W.js → chunk-EUN3SYY7.js} +5 -5
  34. package/{chunk-FSO5B7GH.js → chunk-HAC6GPRE.js} +2 -2
  35. package/{chunk-CKOJQDKR.js → chunk-JEMATI63.js} +1 -1
  36. package/{chunk-7U44LYTR.js → chunk-JTINRTBT.js} +1 -1
  37. package/{chunk-YPRZSPF3.js → chunk-KLOCUWKZ.js} +1 -1
  38. package/{chunk-4O3CARJ4.js → chunk-KTHLAJEY.js} +1 -1
  39. package/{chunk-URUUZLPA.js → chunk-L3KWEH3V.js} +8 -8
  40. package/{chunk-O2ZNTTET.js → chunk-LBUTKV7S.js} +21 -12
  41. package/{chunk-GU3PEVGZ.js → chunk-LFFATN2M.js} +2632 -1578
  42. package/{chunk-UB6SN4NJ.js → chunk-LJCH34R2.js} +6 -6
  43. package/{chunk-5EFXE3O7.js → chunk-LTH6AVG7.js} +3 -3
  44. package/{chunk-7GNGZRLZ.js → chunk-LW6FJFCT.js} +45 -67
  45. package/{chunk-7KCUSYT2.js → chunk-MIQOUMSN.js} +7 -7
  46. package/{chunk-FVYY6MCS.js → chunk-O7VS7JLJ.js} +17 -17
  47. package/{chunk-RCSJFQPB.js → chunk-P7GAHW32.js} +361 -90
  48. package/{chunk-AL2KDGR2.js → chunk-PTT6KSYQ.js} +134 -84
  49. package/{chunk-4IJYA27C.js → chunk-PXZAAB4L.js} +4 -4
  50. package/{chunk-4XENYTF5.js → chunk-Q2WC4KGQ.js} +3 -3
  51. package/{chunk-4QEWT7KD.js → chunk-RBB43B5W.js} +367 -85
  52. package/chunk-RBCENBG7.js +36 -0
  53. package/{chunk-IWX4UW2E.js → chunk-RBCNBU2A.js} +88 -8
  54. package/{chunk-25LCXTML.js → chunk-RQPZX6KP.js} +2 -2
  55. package/{chunk-6KHNO3SK.js → chunk-RYMUT5JO.js} +23 -23
  56. package/{chunk-VX3SXJ3N.js → chunk-UBSKX3LP.js} +6 -6
  57. package/{chunk-4ZDM73SD.js → chunk-V2J635L5.js} +1 -1
  58. package/{chunk-DSZUWUYB.js → chunk-VBKJTOAW.js} +1 -1
  59. package/{chunk-XBUBEFNX.js → chunk-WESWWEVA.js} +1 -1
  60. package/{chunk-2ECQG4YX.js → chunk-ZAUDEKML.js} +253 -159
  61. package/{chunk-N54XAP77.js → chunk-ZJS64PZJ.js} +1 -1
  62. package/{createAgentAutomationAction-RJF3N2QY.js → createAgentAutomationAction-DYQOGAVE.js} +25 -24
  63. package/{createDialogAction-DRSPS6CE.js → createDialogAction-ETB3KQQE.js} +25 -24
  64. package/{createPageAction-6B2WMNO3.js → createPageAction-UF2RHA63.js} +25 -24
  65. package/{dbSlice-Q3TM2FJV.js → dbSlice-R5EJKZBW.js} +7 -7
  66. package/{deleteFile-OW53A6BX.js → deleteFile-WPWVZE4B.js} +5 -5
  67. package/{dialogCommands-4IX4XIZE.js → dialogCommands-LYYC7XHF.js} +23 -22
  68. package/{dialogSlice-3M7KX2TX.js → dialogSlice-IFBZ4IT2.js} +24 -23
  69. package/{docCreateCommands-SIL3NPGT.js → docCreateCommands-I66OI374.js} +22 -21
  70. package/{docDeleteCommands-7IOMLUS4.js → docDeleteCommands-OVRBCHMF.js} +23 -22
  71. package/{docReadCommands-FNFXUA5L.js → docReadCommands-YLWUMEH7.js} +22 -21
  72. package/{docStore-SV7E34D4.js → docStore-65WO7U36.js} +24 -23
  73. package/{docUpdateCommands-X2HNDVUC.js → docUpdateCommands-NSICS4IN.js} +22 -21
  74. package/fetchMessages-KTNM7QAR.js +1 -1
  75. package/{getPricing-3E6UNPKL.js → getPricing-7PUT44ZS.js} +7 -3
  76. package/{handleSendMessageAction-JYETO5RZ.js → handleSendMessageAction-T76HEDOP.js} +29 -28
  77. package/index.js +74 -74
  78. package/{localDialogRead-2VRI24F4.js → localDialogRead-YSKFFRTT.js} +1 -1
  79. package/{machineCommands-RIO3RP5Q.js → machineCommands-4HQY6UVZ.js} +57 -55
  80. package/{machineWsRunDispatch-W7UYLGB5.js → machineWsRunDispatch-7YW2M4FS.js} +49 -47
  81. package/{memoryCommands-O4MIPIWQ.js → memoryCommands-HG4WKTU7.js} +2 -2
  82. package/{models-4OPOOLFS.js → models-MFXNI3TF.js} +2 -2
  83. package/package.json +1 -1
  84. package/{read-GW7ZEI23.js → read-5ZMY7FKP.js} +5 -5
  85. package/{readDocTool-HUFU6OCT.js → readDocTool-2NXDK32S.js} +1 -1
  86. package/{readlineWorkspace-27JR7WPW.js → readlineWorkspace-FLQWOAUR.js} +759 -604
  87. package/{removeDialogAgentAction-CXKR4NJI.js → removeDialogAgentAction-KOLQ2R5W.js} +13 -12
  88. package/{runAgentClientLoop-HZFAPJHS.js → runAgentClientLoop-IUV2TR3X.js} +43 -42
  89. package/{runtimeDoctorCommands-LRHLPDRC.js → runtimeDoctorCommands-UWR5UDSM.js} +5 -5
  90. package/{setDialogExtraReferencesAction-6RKUSXHX.js → setDialogExtraReferencesAction-OMTEO7X6.js} +10 -10
  91. package/{setPrimaryDialogAgentAction-T3UTBEFG.js → setPrimaryDialogAgentAction-DOCIS6V4.js} +13 -12
  92. package/{settingSlice-IVKXJXMG.js → settingSlice-UWZJYDOA.js} +8 -8
  93. package/{spaceCommands-E7VOF4LO.js → spaceCommands-BDDAT4VU.js} +29 -28
  94. package/{spaceSlice-TSVROA5U.js → spaceSlice-HH633ZA4.js} +23 -22
  95. package/{streamAgentChatTurn-3C5RQZJF.js → streamAgentChatTurn-UBZOVFKV.js} +95 -72
  96. package/{tableCommands-O7O2LBEG.js → tableCommands-M3DJUETS.js} +10 -10
  97. package/{toolApiClient-QI3YBNWB.js → toolApiClient-C7P7YSE4.js} +2 -2
  98. package/{tools-EQDEKR6N.js → tools-OQZ34KCU.js} +31 -30
  99. package/{tuiSummaryLlmCaller-RV3THLZF.js → tuiSummaryLlmCaller-42AEL3LL.js} +8 -6
  100. package/{updateCommands-VOSPKXFF.js → updateCommands-TC5SX42Y.js} +3 -3
  101. package/{updateDialogTitleAction-3XV7VWSZ.js → updateDialogTitleAction-A3OOMSDO.js} +27 -26
  102. package/chunk-BBYVOSU2.js +0 -792
  103. package/chunk-DCOA4QSN.js +0 -105
  104. package/{chunk-DZ3XJVET.js → chunk-3QAF2LTL.js} +3 -3
  105. package/{chunk-EHLHSX7R.js → chunk-5MMZUWSG.js} +3 -3
  106. package/{chunk-ISNCLGUZ.js → chunk-AVMJVOQY.js} +3 -3
  107. package/{chunk-UTLZINAP.js → chunk-DVRHHFEA.js} +10 -10
  108. package/{chunk-4CQLVGRV.js → chunk-ID4G2MAR.js} +3 -3
  109. package/{chunk-5MIDPSSK.js → chunk-JK7VW2FN.js} +3 -3
  110. package/{chunk-TILFE6LV.js → chunk-YOCHZD7D.js} +3 -3
  111. package/{db-HCJ5PRB5.js → db-6QED3ZVO.js} +3 -3
  112. package/{understanding-3CUQQ6SV.js → understanding-ZOESBLF3.js} +3 -3
@@ -2,23 +2,17 @@ import {
2
2
  buildCurrentTimeBlock,
3
3
  buildIdentityBlock,
4
4
  buildRuntimeGuidanceBlocks
5
- } from "./chunk-AGFH73SK.js";
5
+ } from "./chunk-6KRA6AWI.js";
6
6
  import {
7
7
  canonicalizeToolNames
8
- } from "./chunk-P3PKED2I.js";
8
+ } from "./chunk-6OHYC4BY.js";
9
9
  import {
10
10
  clipCompactText
11
11
  } from "./chunk-5MMAK75Q.js";
12
12
  import {
13
13
  findModelConfig,
14
14
  getProviderByModelName
15
- } from "./chunk-BBYVOSU2.js";
16
- import {
17
- compactWhitespace
18
- } from "./chunk-DWLEOOGR.js";
19
- import {
20
- toErrorMessage
21
- } from "./chunk-HNMXYYJR.js";
15
+ } from "./chunk-AOKWJZ5N.js";
22
16
  import {
23
17
  asRecordOrEmpty
24
18
  } from "./chunk-KX6YBIHG.js";
@@ -26,11 +20,14 @@ import {
26
20
  asTrimmedLowercaseString
27
21
  } from "./chunk-QSJ3HFEF.js";
28
22
  import {
29
- asOptionalTrimmedString
30
- } from "./chunk-G3SUCT4W.js";
23
+ toErrorMessage
24
+ } from "./chunk-HNMXYYJR.js";
31
25
  import {
32
26
  isRecord
33
27
  } from "./chunk-KUG52IAP.js";
28
+ import {
29
+ asOptionalTrimmedString
30
+ } from "./chunk-G3SUCT4W.js";
34
31
 
35
32
  // packages/agent-runtime/actionGate.ts
36
33
  function readCommandActionGatePayload(payload) {
@@ -273,6 +270,20 @@ function summarizeToolArguments(toolName, rawArgs) {
273
270
  );
274
271
  }
275
272
 
273
+ // packages/agent-runtime/contextBlockScope.ts
274
+ var isContextBlockScope = (value) => {
275
+ if (typeof value !== "object" || value === null) return false;
276
+ const candidate = value;
277
+ return typeof candidate.content === "string" && (candidate.cacheScope === "session" || candidate.cacheScope === "turn");
278
+ };
279
+ var normalizeContextBlockScopes = (legacyBlocks = void 0, scopes = void 0) => {
280
+ const trimmedScopes = (Array.isArray(scopes) ? scopes : []).filter(isContextBlockScope).map((scope) => ({ content: scope.content.trim(), cacheScope: scope.cacheScope })).filter((scope) => scope.content.length > 0);
281
+ if (trimmedScopes.length > 0) {
282
+ return trimmedScopes;
283
+ }
284
+ return (Array.isArray(legacyBlocks) ? legacyBlocks : []).filter((block) => typeof block === "string").map((block) => block.trim()).filter((block) => block.length > 0).map((block) => ({ content: block, cacheScope: "turn" }));
285
+ };
286
+
276
287
  // packages/agent-runtime/localLoop.ts
277
288
  var LOCAL_AGENT_CONFIG_MISSING_CODE = "LOCAL_AGENT_CONFIG_MISSING";
278
289
  var EMPTY_ASSISTANT_REPAIR_PROMPT = "\u8BF7\u7ED9\u51FA\u660E\u786E\u7684\u6587\u5B57\u56DE\u7B54\u6216\u6267\u884C\u4E0B\u4E00\u6B65\uFF1A\u5982\u679C\u4EFB\u52A1\u5DF2\u5B8C\u6210\uFF0C\u8BF7\u76F4\u63A5\u603B\u7ED3\u7ED3\u679C\uFF1B\u5982\u679C\u9700\u8981\u8C03\u7528\u5DE5\u5177\uFF0C\u8BF7\u76F4\u63A5\u8F93\u51FA tool_calls\u3002\u8BF7\u5207\u52FF\u8FD4\u56DE\u7A7A\u5185\u5BB9\u3002";
@@ -341,14 +352,43 @@ function buildAbortedError() {
341
352
  function throwIfAborted(input) {
342
353
  if (input.abortSignal?.aborted) throw buildAbortedError();
343
354
  }
355
+ async function raceWithAbort(input, promise, pendingToolName) {
356
+ const signal = input.abortSignal;
357
+ if (!signal) return promise;
358
+ let abortListener;
359
+ const abortPromise = new Promise((_resolve, reject) => {
360
+ abortListener = () => {
361
+ const error = buildAbortedError();
362
+ if (pendingToolName) error.pendingToolName = pendingToolName;
363
+ promise.catch(() => {
364
+ });
365
+ reject(error);
366
+ };
367
+ if (signal.aborted) {
368
+ abortListener();
369
+ return;
370
+ }
371
+ signal.addEventListener("abort", abortListener, { once: true });
372
+ });
373
+ try {
374
+ return await Promise.race([promise, abortPromise]);
375
+ } finally {
376
+ if (signal && abortListener) signal.removeEventListener("abort", abortListener);
377
+ }
378
+ }
344
379
  function resolveLlmRequestTimeoutMs(input) {
345
380
  const raw = input.llmRequestTimeoutMs ?? input.timeoutMs;
346
381
  if (typeof raw !== "number" || !Number.isFinite(raw) || raw <= 0) return void 0;
347
382
  return raw;
348
383
  }
349
384
  async function runCompleteWithTimeout(args) {
350
- const { provider, messages, options, timeoutMs, round, input } = args;
351
- emitLoopEvent(input, { kind: "llm-start", round, atMs: Date.now() });
385
+ const { provider, messages, options, timeoutMs, round, input, context } = args;
386
+ emitLoopEvent(input, {
387
+ kind: "llm-start",
388
+ round,
389
+ atMs: Date.now(),
390
+ ...context ? { context } : {}
391
+ });
352
392
  const complete = provider.complete(messages, options);
353
393
  let ok = false;
354
394
  const signal = input.abortSignal;
@@ -513,50 +553,209 @@ function buildActionGate(args) {
513
553
  }
514
554
  var MAX_HISTORICAL_TOOL_CONTENT_CHARS = 1600;
515
555
  var MAX_IN_TURN_TOOL_CONTENT_CHARS = 4e3;
516
- function summarizeToolContentForProvider(content, maxChars, label) {
556
+ var DEFAULT_TOOL_OUTPUT_PROFILE = {
557
+ maxChars: MAX_IN_TURN_TOOL_CONTENT_CHARS,
558
+ headRatio: 0.5
559
+ };
560
+ var TOOL_OUTPUT_PROFILES = {
561
+ readFile: { maxChars: 4800, headRatio: 0.68 },
562
+ read_file: { maxChars: 4800, headRatio: 0.68 },
563
+ readWorkspaceFile: { maxChars: 4800, headRatio: 0.68 },
564
+ searchFiles: { maxChars: 3600, headRatio: 0.78 },
565
+ search_files: { maxChars: 3600, headRatio: 0.78 },
566
+ listFiles: { maxChars: 2800, headRatio: 0.85 },
567
+ globFiles: { maxChars: 2800, headRatio: 0.85 },
568
+ execShell: { maxChars: 4e3, headRatio: 0.35 },
569
+ runCommand: { maxChars: 4e3, headRatio: 0.35 },
570
+ launchProcess: { maxChars: 2800, headRatio: 0.35 },
571
+ editFile: { maxChars: 2800, headRatio: 0.62 },
572
+ writeFile: { maxChars: 2400, headRatio: 0.62 },
573
+ readPastedText: { maxChars: 4800, headRatio: 0.5 }
574
+ };
575
+ var TOOL_METADATA_KEYS = [
576
+ "path",
577
+ "query",
578
+ "effectivePattern",
579
+ "startLine",
580
+ "endLine",
581
+ "totalLines",
582
+ "totalBytes",
583
+ "bytes",
584
+ "totalChars",
585
+ "count",
586
+ "matchCount",
587
+ "matchedFiles",
588
+ "truncated",
589
+ "limitedByMaxResults",
590
+ "limitedByMaxDepth",
591
+ "visitedEntries",
592
+ "maxResults",
593
+ "exitCode",
594
+ "status",
595
+ "timedOut",
596
+ "aborted",
597
+ "replacements",
598
+ "code",
599
+ "error",
600
+ "message",
601
+ "pasteId",
602
+ "source"
603
+ ];
604
+ function resolveToolOutputProfile(toolName) {
605
+ return (toolName ? TOOL_OUTPUT_PROFILES[toolName] : void 0) ?? DEFAULT_TOOL_OUTPUT_PROFILE;
606
+ }
607
+ function contentCharCount(content) {
608
+ if (typeof content === "string") return content.length;
609
+ if (!Array.isArray(content)) return 0;
610
+ return content.reduce((total, part) => {
611
+ if (part?.type === "text") return total + part.text.length;
612
+ if (part?.type === "image_url") return total + part.image_url.url.length;
613
+ return total;
614
+ }, 0);
615
+ }
616
+ function compactToolMetadata(metadata) {
617
+ if (!metadata) return "";
618
+ const selected = {};
619
+ for (const key of TOOL_METADATA_KEYS) {
620
+ const value = metadata[key];
621
+ if (value === void 0) continue;
622
+ if (typeof value === "string") {
623
+ selected[key] = clipCompactText(value, 240);
624
+ continue;
625
+ }
626
+ if (Array.isArray(value)) {
627
+ selected[key] = value.slice(0, 20).map(
628
+ (item) => typeof item === "string" ? clipCompactText(item, 180) : clipCompactText(JSON.stringify(item), 180)
629
+ );
630
+ continue;
631
+ }
632
+ selected[key] = value;
633
+ }
634
+ return Object.keys(selected).length > 0 ? clipCompactText(JSON.stringify(selected), 1200) : "";
635
+ }
636
+ function clipToolText(content, maxChars, headRatio) {
637
+ const normalized = content.replace(/\r\n/g, "\n").trim();
638
+ if (normalized.length <= maxChars) return normalized;
639
+ const marker = "\n\n[... tool output middle omitted; head/tail preserved ...]\n\n";
640
+ if (maxChars <= marker.length + 2) return normalized.slice(0, maxChars);
641
+ const available = maxChars - marker.length;
642
+ const headChars = Math.max(1, Math.floor(available * headRatio));
643
+ const tailChars = Math.max(1, available - headChars);
644
+ return `${normalized.slice(0, headChars)}${marker}${normalized.slice(-tailChars)}`;
645
+ }
646
+ function projectToolContentForProvider(args) {
647
+ const content = args.content;
517
648
  if (typeof content !== "string") return content;
518
- if (content.length <= maxChars) return content;
519
- const compact = compactWhitespace(content);
520
- const clipped = compact.length > maxChars ? compact.slice(0, maxChars - 160) : compact;
521
- return [
522
- `[${label}]`,
523
- `originalChars=${content.length}`,
524
- clipped
525
- ].join("\n");
526
- }
527
- function summarizeHistoricalToolContent(content) {
528
- return summarizeToolContentForProvider(
529
- content,
530
- MAX_HISTORICAL_TOOL_CONTENT_CHARS,
531
- "historical tool result truncated for the next turn"
649
+ const metadataText = compactToolMetadata(args.metadata);
650
+ const embeddedMetadataIndex = metadataText ? content.indexOf("\n\n[tool metadata]\n") : -1;
651
+ const contentForProjection = embeddedMetadataIndex >= 0 ? content.slice(0, embeddedMetadataIndex) : content;
652
+ const metadataSuffix = metadataText ? `
653
+
654
+ [tool metadata]
655
+ ${metadataText}` : "";
656
+ if (embeddedMetadataIndex >= 0 && content.length <= args.maxChars) {
657
+ return content;
658
+ }
659
+ const headRatio = resolveToolOutputProfile(args.toolName).headRatio;
660
+ const diagnostic = (clippedLength) => `[${args.label}; originalChars=${content.length}; omittedChars=${Math.max(
661
+ 0,
662
+ content.length - clippedLength
663
+ )}]`;
664
+ const suffix = (clippedLength) => [diagnostic(clippedLength), metadataSuffix.trimStart()].filter(Boolean).join("\n\n");
665
+ const initialBudget = Math.max(
666
+ 1,
667
+ args.maxChars - suffix(contentForProjection.length).length - 2
532
668
  );
669
+ let clipped = clipToolText(contentForProjection, initialBudget, headRatio);
670
+ const wasClipped = clipped.length < contentForProjection.trim().length;
671
+ const needsProjection = wasClipped || Boolean(metadataSuffix) || embeddedMetadataIndex >= 0;
672
+ if (!needsProjection) return args.content;
673
+ let projected = wasClipped || metadataSuffix ? `${clipped}
674
+
675
+ ${suffix(clipped.length)}` : clipped;
676
+ if (projected.length > args.maxChars) {
677
+ const boundedBudget = Math.max(
678
+ 1,
679
+ args.maxChars - suffix(clipped.length).length - 2
680
+ );
681
+ clipped = clipToolText(contentForProjection, boundedBudget, headRatio);
682
+ projected = `${clipped}
683
+
684
+ ${suffix(clipped.length)}`;
685
+ }
686
+ return projected.length <= args.maxChars ? projected : projected.slice(0, args.maxChars);
687
+ }
688
+ function summarizeHistoricalToolContent(content, toolName, metadata) {
689
+ const profile = resolveToolOutputProfile(toolName);
690
+ return projectToolContentForProvider({
691
+ content,
692
+ toolName,
693
+ metadata,
694
+ maxChars: Math.min(profile.maxChars, MAX_HISTORICAL_TOOL_CONTENT_CHARS),
695
+ label: "historical tool result truncated for the next turn"
696
+ });
533
697
  }
534
698
  function prepareMessagesForProviderCall(messages) {
535
699
  const paired = sanitizeToolCallPairing(messages);
536
- return paired.map((message) => {
537
- const sanitizedContent = message.content == null ? "" : typeof message.content === "string" ? message.content : message.content;
538
- if (message.role !== "tool") {
700
+ let toolMessageCount = 0;
701
+ let rawToolContentChars = 0;
702
+ let projectedToolContentChars = 0;
703
+ let truncatedToolResults = 0;
704
+ const projected = paired.map((message) => {
705
+ const { context_reference: _contextReference, ...providerMessage } = message;
706
+ const sanitizedContent = providerMessage.content == null ? "" : typeof providerMessage.content === "string" ? providerMessage.content : providerMessage.content;
707
+ if (providerMessage.role !== "tool") {
539
708
  return {
540
- ...message,
709
+ ...providerMessage,
541
710
  content: sanitizedContent
542
711
  };
543
712
  }
713
+ toolMessageCount += 1;
714
+ rawToolContentChars += contentCharCount(sanitizedContent);
715
+ const profile = resolveToolOutputProfile(providerMessage.toolName);
716
+ const projectedContent = projectToolContentForProvider({
717
+ content: sanitizedContent,
718
+ toolName: providerMessage.toolName,
719
+ metadata: providerMessage.tool_result_metadata,
720
+ maxChars: profile.maxChars,
721
+ label: "in-turn tool result truncated/projected before next provider call"
722
+ });
723
+ projectedToolContentChars += contentCharCount(projectedContent);
724
+ if (contentCharCount(projectedContent) < contentCharCount(sanitizedContent)) {
725
+ truncatedToolResults += 1;
726
+ }
544
727
  return {
545
- ...message,
546
- content: summarizeToolContentForProvider(
547
- sanitizedContent,
548
- MAX_IN_TURN_TOOL_CONTENT_CHARS,
549
- "in-turn tool result truncated before next provider call"
550
- )
728
+ ...providerMessage,
729
+ content: projectedContent
551
730
  };
552
731
  });
732
+ return {
733
+ messages: projected,
734
+ metrics: {
735
+ messageCount: projected.length,
736
+ contentChars: projected.reduce((total, message) => total + contentCharCount(message.content), 0),
737
+ toolMessageCount,
738
+ rawToolContentChars,
739
+ projectedToolContentChars,
740
+ truncatedToolResults,
741
+ stableContextChars: 0,
742
+ dynamicContextChars: 0
743
+ }
744
+ };
553
745
  }
554
- function prepareHistoryForNextTurn(history) {
746
+ function prepareHistoryForNextTurn(history, contextReferenceResolver) {
555
747
  return history.map((message) => {
748
+ if (message.role === "user" && message.context_reference !== void 0 && contextReferenceResolver?.(message.context_reference)) {
749
+ return { ...message, content: message.context_reference };
750
+ }
556
751
  if (message.role !== "tool") return message;
557
752
  return {
558
753
  ...message,
559
- content: summarizeHistoricalToolContent(message.content)
754
+ content: summarizeHistoricalToolContent(
755
+ message.content,
756
+ message.toolName,
757
+ message.tool_result_metadata
758
+ )
560
759
  };
561
760
  });
562
761
  }
@@ -578,25 +777,33 @@ function buildMessages(args) {
578
777
  if (args.contextBlockScopes?.length) {
579
778
  const blocks2 = args.contextBlockScopes.filter((b) => b.content.trim());
580
779
  const stableParts = [args.prompt?.trim(), ...blocks2.filter((b) => b.cacheScope === "session").map((b) => b.content)].filter(Boolean);
581
- const dynamicParts = blocks2.filter((b) => b.cacheScope === "turn").map((b) => b.content).filter(Boolean);
780
+ const dynamicParts = blocks2.filter((b) => b.cacheScope === "turn").map((b) => b.content).map((block) => block.trim()).filter(Boolean);
582
781
  const stableContent = stableParts.join("\n\n");
583
782
  const dynamicContent = dynamicParts.join("\n\n");
584
783
  const systemContent2 = dynamicContent ? `${stableContent}
585
784
 
586
785
  ${dynamicContent}` : stableContent;
587
- return [
588
- ...systemContent2 ? [{ role: "system", content: systemContent2 }] : [],
589
- ...prepareHistoryForNextTurn(args.history),
590
- { role: "user", content: args.input }
591
- ];
786
+ return {
787
+ messages: [
788
+ ...systemContent2 ? [{ role: "system", content: systemContent2 }] : [],
789
+ ...prepareHistoryForNextTurn(args.history, args.contextReferenceResolver),
790
+ { role: "user", content: args.input }
791
+ ],
792
+ stableContextChars: stableContent.length,
793
+ dynamicContextChars: dynamicContent.length
794
+ };
592
795
  }
593
796
  const blocks = (args.contextBlocks ?? []).map((block) => block.trim()).filter(Boolean);
594
797
  const systemContent = [args.prompt?.trim(), ...blocks].filter(Boolean).join("\n\n");
595
- return [
596
- ...systemContent ? [{ role: "system", content: systemContent }] : [],
597
- ...prepareHistoryForNextTurn(args.history),
598
- { role: "user", content: args.input }
599
- ];
798
+ return {
799
+ messages: [
800
+ ...systemContent ? [{ role: "system", content: systemContent }] : [],
801
+ ...prepareHistoryForNextTurn(args.history, args.contextReferenceResolver),
802
+ { role: "user", content: args.input }
803
+ ],
804
+ stableContextChars: (args.prompt?.trim() ?? "").length,
805
+ dynamicContextChars: blocks.join("\n\n").length
806
+ };
600
807
  }
601
808
  function mergeTurnUsage(current, next) {
602
809
  if (!next) return current;
@@ -624,6 +831,52 @@ function extractUserInputText(content) {
624
831
  if (!Array.isArray(content)) return "";
625
832
  return content.flatMap((part) => part?.type === "text" && part.text ? [part.text] : []).join("\n").trim();
626
833
  }
834
+ function attachDialogIdToError(error, dialogId) {
835
+ if (!dialogId) return;
836
+ if (typeof error === "object" && error !== null) {
837
+ error.dialogId = dialogId;
838
+ }
839
+ }
840
+ async function persistFailedLocalTurn(args) {
841
+ const errorMessage = toErrorMessage(args.error);
842
+ try {
843
+ const saved = await args.adapter.saveTurn({
844
+ agentKey: args.agentKey,
845
+ messages: args.messages,
846
+ result: {
847
+ content: args.partialContent || `[nolo] Agent run failed: ${errorMessage}`,
848
+ model: args.model ?? "unknown",
849
+ toolCallCount: args.toolCallCount ?? 0,
850
+ error: true,
851
+ errorMessage
852
+ },
853
+ ...args.input.runtimeContext ? { runtimeContext: args.input.runtimeContext } : {},
854
+ ...args.input.continueDialogId ? { continueDialogId: args.input.continueDialogId } : {},
855
+ ...args.input.spaceId ? { spaceId: args.input.spaceId } : {},
856
+ ...args.input.category ? { category: args.input.category } : {},
857
+ ...args.input.inheritedFromDialogKey ? { inheritedFromDialogKey: args.input.inheritedFromDialogKey } : {},
858
+ ...args.input.parentDialogId ? { parentDialogId: args.input.parentDialogId } : {}
859
+ });
860
+ return saved?.dialogId;
861
+ } catch {
862
+ return args.input.continueDialogId;
863
+ }
864
+ }
865
+ function applyPersistedTurnInput(messages, persistedInput, persistedInputReference) {
866
+ if (persistedInput === void 0 && persistedInputReference === void 0) {
867
+ return messages;
868
+ }
869
+ let replaced = false;
870
+ return messages.map((message) => {
871
+ if (replaced || message.role !== "user") return message;
872
+ replaced = true;
873
+ return {
874
+ ...message,
875
+ ...persistedInput !== void 0 ? { content: persistedInput } : {},
876
+ ...persistedInputReference !== void 0 ? { context_reference: persistedInputReference } : {}
877
+ };
878
+ });
879
+ }
627
880
  async function runLocalAgentTurn(input) {
628
881
  const agentConfig = await input.adapter.loadAgentConfig(input.agentRef);
629
882
  if (!agentConfig) {
@@ -632,7 +885,21 @@ async function runLocalAgentTurn(input) {
632
885
  error.agentRef = input.agentRef;
633
886
  throw error;
634
887
  }
635
- const history = input.continueDialogId ? await input.adapter.loadDialogHistory(input.continueDialogId) : [];
888
+ let history = [];
889
+ try {
890
+ history = input.continueDialogId ? await input.adapter.loadDialogHistory(input.continueDialogId) : [];
891
+ } catch (error) {
892
+ const dialogId = await persistFailedLocalTurn({
893
+ adapter: input.adapter,
894
+ agentKey: agentConfig.key,
895
+ messages: [{ role: "user", content: input.input }],
896
+ error,
897
+ model: agentConfig.model,
898
+ input
899
+ });
900
+ attachDialogIdToError(error, dialogId);
901
+ throw error;
902
+ }
636
903
  const identityBlock = buildIdentityBlock({
637
904
  agentName: agentConfig.name,
638
905
  agentId: agentConfig.key,
@@ -649,27 +916,27 @@ async function runLocalAgentTurn(input) {
649
916
  const currentTimeScope = [
650
917
  { content: buildCurrentTimeBlock(/* @__PURE__ */ new Date(), void 0), cacheScope: "turn" }
651
918
  ];
919
+ const callerScopes = normalizeContextBlockScopes(
920
+ input.contextBlocks,
921
+ input.contextBlockScopes
922
+ );
652
923
  const mergedContextBlockScopes = [
653
924
  { content: identityBlock, cacheScope: "session" },
654
925
  ...guidanceScopes,
655
926
  ...currentTimeScope,
656
- ...input.contextBlockScopes ?? []
927
+ ...callerScopes
657
928
  ];
658
- const hasContextBlocks = (input.contextBlocks ?? []).some(
659
- (block) => block.trim()
660
- ) || mergedContextBlockScopes.some(
661
- (block) => block.content.trim()
662
- );
929
+ const hasContextBlocks = callerScopes.some((block) => block.content.trim()) || mergedContextBlockScopes.some((block) => block.content.trim());
663
930
  const promptMessageCount = agentConfig.prompt?.trim() || hasContextBlocks ? 1 : 0;
664
931
  const turnStartIndex = promptMessageCount + history.length;
665
- const messages = buildMessages({
932
+ const builtMessages = buildMessages({
666
933
  prompt: agentConfig.prompt,
667
- contextBlocks: input.contextBlocks,
668
934
  contextBlockScopes: mergedContextBlockScopes,
669
935
  history,
670
- input: input.input
936
+ input: input.input,
937
+ contextReferenceResolver: input.adapter.host === "cli" ? input.contextReferenceResolver : void 0
671
938
  });
672
- const provider = await input.adapter.resolveProvider(agentConfig);
939
+ const messages = builtMessages.messages;
673
940
  const supportsImages = resolveAgentImageInputSupport({
674
941
  apiSource: agentConfig.apiSource,
675
942
  provider: agentConfig.provider,
@@ -688,11 +955,13 @@ async function runLocalAgentTurn(input) {
688
955
  let skipFinalAppend = false;
689
956
  let partialContent = "";
690
957
  try {
958
+ const provider = await input.adapter.resolveProvider(agentConfig);
691
959
  while (true) {
692
960
  partialContent = "";
693
961
  throwIfAborted(input);
962
+ const preparedMessages = prepareMessagesForProviderCall(messages);
694
963
  const baseRequestMessages = filterImagePartsFromMessages(
695
- prepareMessagesForProviderCall(messages),
964
+ preparedMessages.messages,
696
965
  supportsImages
697
966
  );
698
967
  if (!supportsImages && !imageDowngradeNotified && messages.some((m) => Array.isArray(m.content) && m.content.some((p) => p?.type === "image_url"))) {
@@ -704,6 +973,16 @@ async function runLocalAgentTurn(input) {
704
973
  });
705
974
  }
706
975
  const requestMessages = emptyAssistantRepairPending ? [...baseRequestMessages, { role: "user", content: EMPTY_ASSISTANT_REPAIR_PROMPT }] : baseRequestMessages;
976
+ const contextMetrics = {
977
+ ...preparedMessages.metrics,
978
+ messageCount: requestMessages.length,
979
+ contentChars: requestMessages.reduce(
980
+ (total, message) => total + contentCharCount(message.content),
981
+ 0
982
+ ),
983
+ stableContextChars: builtMessages.stableContextChars,
984
+ dynamicContextChars: builtMessages.dynamicContextChars
985
+ };
707
986
  emptyAssistantRepairPending = false;
708
987
  result = await runCompleteWithTimeout({
709
988
  provider,
@@ -720,7 +999,8 @@ async function runLocalAgentTurn(input) {
720
999
  },
721
1000
  timeoutMs: resolveLlmRequestTimeoutMs(input),
722
1001
  round,
723
- input
1002
+ input,
1003
+ context: contextMetrics
724
1004
  });
725
1005
  turnUsage = mergeTurnUsage(turnUsage, result.usage);
726
1006
  const toolCalls = result.tool_calls ?? [];
@@ -790,13 +1070,14 @@ async function runLocalAgentTurn(input) {
790
1070
  argumentsPreview: summarizeToolArguments(toolName, toolCall.function.arguments)
791
1071
  });
792
1072
  try {
793
- toolResult = await input.adapter.executeTool({
1073
+ const executePromise = input.adapter.executeTool({
794
1074
  id: toolCall.id,
795
1075
  name: toolName,
796
1076
  arguments: toolCall.function.arguments,
797
1077
  ...userInputText ? { userInput: userInputText } : {},
798
1078
  ...input.abortSignal ? { abortSignal: input.abortSignal } : {}
799
1079
  });
1080
+ toolResult = await raceWithAbort(input, executePromise, toolName);
800
1081
  const actionGate = buildActionGate({
801
1082
  toolName,
802
1083
  toolCallId: toolCall.id,
@@ -821,6 +1102,9 @@ async function runLocalAgentTurn(input) {
821
1102
  });
822
1103
  } catch (error) {
823
1104
  emitLoopEvent(input, { kind: "tool-end", name: toolName, atMs: Date.now(), ok: false });
1105
+ if (error && typeof error === "object" && error.code === LOCAL_TURN_ABORTED_CODE) {
1106
+ throw error;
1107
+ }
824
1108
  if (!shouldReturnToolExecutionErrors(input.adapter)) throw error;
825
1109
  emitToolEvent(input, {
826
1110
  type: "tool-error",
@@ -858,28 +1142,22 @@ async function runLocalAgentTurn(input) {
858
1142
  loopError = error;
859
1143
  }
860
1144
  if (loopError) {
861
- const errorMessage = toErrorMessage(loopError);
862
- const turnMessages2 = messages.slice(turnStartIndex);
863
- const saved2 = await input.adapter.saveTurn({
1145
+ const turnMessages2 = applyPersistedTurnInput(
1146
+ messages.slice(turnStartIndex),
1147
+ input.persistedInput,
1148
+ input.persistedInputReference
1149
+ );
1150
+ const dialogId = await persistFailedLocalTurn({
1151
+ adapter: input.adapter,
864
1152
  agentKey: agentConfig.key,
865
1153
  messages: turnMessages2,
866
- result: {
867
- content: partialContent || `[nolo] Agent run failed: ${errorMessage}`,
868
- model: agentConfig.model ?? "unknown",
869
- toolCallCount,
870
- error: true,
871
- errorMessage
872
- },
873
- ...input.runtimeContext ? { runtimeContext: input.runtimeContext } : {},
874
- ...input.continueDialogId ? { continueDialogId: input.continueDialogId } : {},
875
- ...input.spaceId ? { spaceId: input.spaceId } : {},
876
- ...input.category ? { category: input.category } : {},
877
- ...input.inheritedFromDialogKey ? { inheritedFromDialogKey: input.inheritedFromDialogKey } : {},
878
- ...input.parentDialogId ? { parentDialogId: input.parentDialogId } : {}
1154
+ error: loopError,
1155
+ model: agentConfig.model,
1156
+ toolCallCount,
1157
+ partialContent,
1158
+ input
879
1159
  });
880
- if (saved2?.dialogId && typeof loopError === "object" && loopError !== null) {
881
- loopError.dialogId = saved2.dialogId;
882
- }
1160
+ attachDialogIdToError(loopError, dialogId);
883
1161
  throw loopError;
884
1162
  }
885
1163
  result = result;
@@ -892,7 +1170,11 @@ async function runLocalAgentTurn(input) {
892
1170
  ...result.reasoning_content ? { reasoning_content: result.reasoning_content } : {}
893
1171
  });
894
1172
  }
895
- const turnMessages = messages.slice(turnStartIndex);
1173
+ const turnMessages = applyPersistedTurnInput(
1174
+ messages.slice(turnStartIndex),
1175
+ input.persistedInput,
1176
+ input.persistedInputReference
1177
+ );
896
1178
  const saved = await input.adapter.saveTurn({
897
1179
  agentKey: agentConfig.key,
898
1180
  messages: turnMessages,
@@ -0,0 +1,36 @@
1
+ import {
2
+ cloudflareModels,
3
+ deepSeekModels,
4
+ deepinfraModels,
5
+ fireworksModels,
6
+ gmiModels,
7
+ googleModels,
8
+ openAIModels,
9
+ openrouterModels,
10
+ platformHostedModels,
11
+ xaiModels,
12
+ zaiModels
13
+ } from "./chunk-RBCNBU2A.js";
14
+
15
+ // packages/ai/llm/ollamaCloud.ts
16
+ var ollamaCloudModels = platformHostedModels;
17
+
18
+ // packages/ai/llm/models.ts
19
+ var withProvider = (provider) => (models) => models.map((model) => ({ ...model, provider }));
20
+ var ALL_MODELS = [
21
+ ...withProvider("nolo")(ollamaCloudModels),
22
+ ...withProvider("google")(googleModels),
23
+ ...withProvider("openai")(openAIModels),
24
+ ...withProvider("openrouter")(openrouterModels),
25
+ ...withProvider("xai")(xaiModels),
26
+ ...withProvider("deepseek")(deepSeekModels),
27
+ ...withProvider("deepinfra")(deepinfraModels),
28
+ ...withProvider("fireworks")(fireworksModels),
29
+ ...withProvider("cloudflare")(cloudflareModels),
30
+ ...withProvider("gmi")(gmiModels),
31
+ ...withProvider("zai")(zaiModels)
32
+ ];
33
+
34
+ export {
35
+ ALL_MODELS
36
+ };