@sanity-labs/nuum 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +41 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -35674,6 +35674,20 @@ function estimateSummaryTokens(input) {
35674
35674
  }
35675
35675
  // src/agent/loop.ts
35676
35676
  var log5 = Log.create({ service: "agent-loop" });
35677
+ var MODEL_MAX_OUTPUT_TOKENS = {
35678
+ "claude-opus-4-6": 128000,
35679
+ "claude-opus-4-6-20250918": 128000,
35680
+ "claude-sonnet-4-5-20250929": 64000,
35681
+ "claude-sonnet-4-5": 64000,
35682
+ "claude-haiku-4-5-20251001": 64000,
35683
+ "claude-haiku-4-5": 64000,
35684
+ "claude-3-5-sonnet-20241022": 8192,
35685
+ "claude-3-5-haiku-20241022": 8192
35686
+ };
35687
+ var DEFAULT_MAX_OUTPUT_TOKENS = 16384;
35688
+ function getMaxOutputTokens(modelId) {
35689
+ return MODEL_MAX_OUTPUT_TOKENS[modelId] ?? DEFAULT_MAX_OUTPUT_TOKENS;
35690
+ }
35677
35691
  function addCacheMarkers(messages) {
35678
35692
  if (messages.length === 0)
35679
35693
  return messages;
@@ -35702,7 +35716,7 @@ async function runAgentLoop(options) {
35702
35716
  systemPrompt,
35703
35717
  initialMessages,
35704
35718
  tools,
35705
- maxTokens = 4096,
35719
+ maxTokens: maxTokensOverride,
35706
35720
  temperature,
35707
35721
  maxTurns,
35708
35722
  abortSignal,
@@ -35713,6 +35727,12 @@ async function runAgentLoop(options) {
35713
35727
  onBeforeTurn,
35714
35728
  onThinking
35715
35729
  } = options;
35730
+ const maxTokens = maxTokensOverride ?? getMaxOutputTokens(model.modelId);
35731
+ log5.info("agent loop starting", {
35732
+ model: model.modelId,
35733
+ maxTokens,
35734
+ maxTurns
35735
+ });
35716
35736
  if (abortSignal?.aborted) {
35717
35737
  throw new AgentLoopCancelledError;
35718
35738
  }
@@ -35768,6 +35788,13 @@ async function runAgentLoop(options) {
35768
35788
  cacheHitRate: total > 0 ? `${Math.round(cacheRead / total * 100)}%` : "0%"
35769
35789
  });
35770
35790
  }
35791
+ if (response.finishReason === "length") {
35792
+ log5.warn("output truncated - model hit maxTokens limit", {
35793
+ maxTokens,
35794
+ outputTokens: response.usage.completionTokens,
35795
+ hasToolCalls: (response.toolCalls?.length ?? 0) > 0
35796
+ });
35797
+ }
35771
35798
  if (response.text) {
35772
35799
  finalText = response.text;
35773
35800
  await onText?.(response.text);
@@ -35812,6 +35839,15 @@ async function runAgentLoop(options) {
35812
35839
  content: toolResultParts
35813
35840
  };
35814
35841
  messages.push(toolMsg);
35842
+ if (response.finishReason === "length") {
35843
+ const hadInvalidCalls = toolCallInfos.some((tc) => tc.toolName === "__invalid_tool_call__");
35844
+ if (hadInvalidCalls) {
35845
+ messages.push({
35846
+ role: "user",
35847
+ content: "[SYSTEM: Your previous output was truncated because it exceeded the output token limit. " + "Your tool call was incomplete \u2014 parameters were cut off mid-generation. " + "To fix this: break large content into smaller chunks, or use bash with echo/cat to write files incrementally. " + "Do NOT retry the same large tool call \u2014 it will truncate again.]"
35848
+ });
35849
+ }
35850
+ }
35815
35851
  if (isDone(toolCallInfos)) {
35816
35852
  stopReason = "done";
35817
35853
  break;
@@ -36138,7 +36174,6 @@ async function runCompaction(storage, config) {
36138
36174
  systemPrompt: ctx.systemPrompt,
36139
36175
  initialMessages,
36140
36176
  tools,
36141
- maxTokens: 4096,
36142
36177
  temperature: 0,
36143
36178
  maxTurns: 5,
36144
36179
  isDone: stopOnTool("finish_distillation"),
@@ -36244,7 +36279,7 @@ async function runSubAgent(storage, config) {
36244
36279
  extractResult,
36245
36280
  tier = "workhorse",
36246
36281
  maxTurns = 20,
36247
- maxTokens = 4096,
36282
+ maxTokens,
36248
36283
  temperature = 0,
36249
36284
  onToolResult
36250
36285
  } = config;
@@ -36431,8 +36466,7 @@ async function runReflection(storage, question) {
36431
36466
  finishToolName: "finish_reflection",
36432
36467
  extractResult: getAnswer,
36433
36468
  tier: "workhorse",
36434
- maxTurns: 20,
36435
- maxTokens: 4096
36469
+ maxTurns: 20
36436
36470
  });
36437
36471
  const answer = result.result ?? "Unable to find relevant information.";
36438
36472
  activity.reflection.complete(`${result.turnsUsed} turns, ${answer.length} chars`);
@@ -36836,7 +36870,6 @@ async function runResearch(storage, topic) {
36836
36870
  },
36837
36871
  tier: "workhorse",
36838
36872
  maxTurns: MAX_RESEARCH_TURNS,
36839
- maxTokens: 8192,
36840
36873
  onToolResult: (toolCallId) => {
36841
36874
  const toolResult = getLastResult(toolCallId);
36842
36875
  if (!toolResult)
@@ -45371,8 +45404,8 @@ var Mcp;
45371
45404
  })(Mcp ||= {});
45372
45405
 
45373
45406
  // src/version.ts
45374
- var VERSION = "0.5.3";
45375
- var GIT_HASH = "a2a5ddc";
45407
+ var VERSION = "0.5.4";
45408
+ var GIT_HASH = "e1f89a6";
45376
45409
  var VERSION_STRING = `nuum v${VERSION} (${GIT_HASH})`;
45377
45410
 
45378
45411
  // src/tool/mcp-status.ts
@@ -46890,7 +46923,6 @@ async function runConsolidation(storage, messages) {
46890
46923
  },
46891
46924
  tier: "workhorse",
46892
46925
  maxTurns: MAX_CONSOLIDATION_TURNS,
46893
- maxTokens: 2048,
46894
46926
  onToolResult: (toolCallId) => {
46895
46927
  const toolResult = getLastResult(toolCallId);
46896
46928
  if (!toolResult)
@@ -47432,7 +47464,6 @@ async function runAgent(prompt, options) {
47432
47464
  systemPrompt: ctx.systemPrompt,
47433
47465
  initialMessages,
47434
47466
  tools,
47435
- maxTokens: 8192,
47436
47467
  maxTurns: MAX_TURNS,
47437
47468
  abortSignal,
47438
47469
  onText: async (text3) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity-labs/nuum",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "AI coding agent with continuous memory - infinite context across sessions",
5
5
  "type": "module",
6
6
  "bin": {