@bike4mind/cli 0.2.26 → 0.2.27-epic-lattice.18719

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.
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ HydrationEngine,
4
+ createHydrationEngine
5
+ } from "./chunk-NHP3UPYU.js";
6
+ export {
7
+ HydrationEngine,
8
+ createHydrationEngine
9
+ };
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CurationArtifactType
4
- } from "./chunk-F3HPUK2I.js";
4
+ } from "./chunk-HQYUB4DK.js";
5
5
 
6
6
  // ../../b4m-core/packages/services/dist/src/notebookCurationService/artifactExtractor.js
7
7
  var ARTIFACT_TAG_REGEX = /<artifact\s+(.*?)>([\s\S]*?)<\/artifact>/gi;
@@ -15,7 +15,7 @@ import {
15
15
  dayjsConfig_default,
16
16
  extractSnippetMeta,
17
17
  settingsMap
18
- } from "./chunk-F3HPUK2I.js";
18
+ } from "./chunk-HQYUB4DK.js";
19
19
  import {
20
20
  Logger
21
21
  } from "./chunk-OCYRD7D6.js";
@@ -227,7 +227,7 @@ var ChoiceEndReason;
227
227
  // ../../b4m-core/packages/utils/dist/src/llm/toolStreamingHelper.js
228
228
  async function handleToolResultStreaming(toolName, toolResult, streamCallback) {
229
229
  const resultString = toolResult.toString();
230
- const shouldStream = toolName === "recharts" || resultString.includes("<artifact") || resultString.includes('type="application/vnd.ant.');
230
+ const shouldStream = toolName === "recharts" || resultString.includes("<artifact") || resultString.includes('type="application/vnd.ant.') || resultString.includes('type="application/vnd.b4m.');
231
231
  if (shouldStream) {
232
232
  await streamCallback([resultString]);
233
233
  }
@@ -1076,10 +1076,10 @@ async function fetchAndProcessPreviousMessages(session, historyCount = null, { d
1076
1076
  }
1077
1077
  if (assistantContent.length > 0) {
1078
1078
  acc.push({ role: "assistant", content: assistantContent });
1079
- const toolResults = cur.promptMeta.functionCalls.filter((fc) => fc.id && fc.returnValue !== void 0).map((fc) => ({
1079
+ const toolResults = cur.promptMeta.functionCalls.filter((fc) => fc.id && fc.name).map((fc) => ({
1080
1080
  type: "tool_result",
1081
1081
  tool_use_id: fc.id,
1082
- content: fc.returnValue || "",
1082
+ content: fc.returnValue ?? (fc.success === false ? "Tool execution failed" : ""),
1083
1083
  is_error: fc.success === false
1084
1084
  }));
1085
1085
  if (toolResults.length > 0) {
@@ -1793,6 +1793,96 @@ var ensureToolPairingIntegrity = (messages, logger) => {
1793
1793
  }
1794
1794
  logger.log(`Tool pairing integrity: removed ${parts.join(" and ")} after truncation`);
1795
1795
  }
1796
+ let adjacencyStrippedCount = 0;
1797
+ for (let i = 0; i < result.length; i++) {
1798
+ const msg = result[i];
1799
+ if (msg.role !== "assistant" || !Array.isArray(msg.content))
1800
+ continue;
1801
+ const content = msg.content;
1802
+ const toolUseBlockIds = content.filter((b) => b.type === "tool_use" && "id" in b).map((b) => b.id);
1803
+ if (toolUseBlockIds.length === 0)
1804
+ continue;
1805
+ const adjacentResultIds = /* @__PURE__ */ new Set();
1806
+ const nextMsg = result[i + 1];
1807
+ if (nextMsg?.role === "user" && Array.isArray(nextMsg.content)) {
1808
+ const nextContent = nextMsg.content;
1809
+ for (const b of nextContent) {
1810
+ if (b.type === "tool_result" && "tool_use_id" in b) {
1811
+ adjacentResultIds.add(b.tool_use_id);
1812
+ }
1813
+ }
1814
+ }
1815
+ const unmatchedIds = toolUseBlockIds.filter((id) => !adjacentResultIds.has(id));
1816
+ if (unmatchedIds.length === 0)
1817
+ continue;
1818
+ const unmatchedSet = new Set(unmatchedIds);
1819
+ const filtered = content.filter((b) => {
1820
+ if (b.type === "tool_use" && "id" in b && unmatchedSet.has(b.id)) {
1821
+ adjacencyStrippedCount++;
1822
+ return false;
1823
+ }
1824
+ return true;
1825
+ });
1826
+ if (filtered.length > 0) {
1827
+ result[i] = { ...msg, content: filtered };
1828
+ } else {
1829
+ result[i] = { ...msg, content: [{ type: "text", text: "" }] };
1830
+ }
1831
+ if (logger) {
1832
+ logger.warn(`[Tool Pairing Adjacency] Stripped ${unmatchedIds.length} non-adjacent tool_use block(s) from message ${i} (IDs: ${unmatchedIds.join(", ")})`);
1833
+ }
1834
+ for (let j = i + 1; j < result.length; j++) {
1835
+ const laterMsg = result[j];
1836
+ if (laterMsg?.role !== "user" || !Array.isArray(laterMsg.content))
1837
+ continue;
1838
+ const laterContent = laterMsg.content;
1839
+ const cleanedContent = laterContent.filter((b) => {
1840
+ if (b.type === "tool_result" && "tool_use_id" in b && unmatchedSet.has(b.tool_use_id)) {
1841
+ return false;
1842
+ }
1843
+ return true;
1844
+ });
1845
+ if (cleanedContent.length > 0) {
1846
+ if (cleanedContent.length !== laterContent.length) {
1847
+ result[j] = { ...laterMsg, content: cleanedContent };
1848
+ }
1849
+ } else {
1850
+ result[j] = { ...laterMsg, content: "[Tool results removed during adjacency repair]" };
1851
+ }
1852
+ }
1853
+ }
1854
+ return result;
1855
+ };
1856
+ var stripAllToolBlocks = (messages, logger) => {
1857
+ let strippedToolUse = 0;
1858
+ let strippedToolResult = 0;
1859
+ const result = [];
1860
+ for (const message of messages) {
1861
+ if (!Array.isArray(message.content)) {
1862
+ result.push(message);
1863
+ continue;
1864
+ }
1865
+ const content = message.content;
1866
+ const filtered = content.filter((block) => {
1867
+ if (block.type === "tool_use") {
1868
+ strippedToolUse++;
1869
+ return false;
1870
+ }
1871
+ if (block.type === "tool_result") {
1872
+ strippedToolResult++;
1873
+ return false;
1874
+ }
1875
+ return true;
1876
+ });
1877
+ if (filtered.length > 0) {
1878
+ result.push({ ...message, content: filtered });
1879
+ } else if (message.role === "user") {
1880
+ result.push({ ...message, content: "[Tool results removed during error recovery]" });
1881
+ }
1882
+ }
1883
+ if ((strippedToolUse > 0 || strippedToolResult > 0) && logger) {
1884
+ logger.warn(`[Tool Pairing Recovery] Stripped ${strippedToolUse} tool_use and ${strippedToolResult} tool_result blocks from history`);
1885
+ }
1796
1886
  return result;
1797
1887
  };
1798
1888
  async function buildAndSortMessages(previousMessages, fabMessages, userPrompt, maxInputTokens, settings, historyCount = 0, logger, tokenizer, options = { verbose: false }) {
@@ -2401,23 +2491,33 @@ var AnthropicBackend = class {
2401
2491
  const normalizedTools = Array.isArray(rawTools) ? rawTools : rawTools ? [rawTools] : void 0;
2402
2492
  options.tools = normalizedTools;
2403
2493
  const system = this.consolidateSystemMessages(messages);
2404
- const filteredMessages = ensureToolPairingIntegrity(this.filterRelevantMessages(messages), this.logger);
2405
- const toolUseCount = filteredMessages.reduce((count, msg) => {
2406
- if (msg.role === "assistant" && Array.isArray(msg.content)) {
2407
- return count + msg.content.filter((b) => b.type === "tool_use").length;
2408
- }
2409
- return count;
2410
- }, 0);
2411
- const toolResultCount = filteredMessages.reduce((count, msg) => {
2412
- if (msg.role === "user" && Array.isArray(msg.content)) {
2413
- return count + msg.content.filter((b) => b.type === "tool_result").length;
2494
+ let filteredMessages = ensureToolPairingIntegrity(this.filterRelevantMessages(messages), this.logger);
2495
+ const countToolBlocks = (msgs) => {
2496
+ let useCount = 0;
2497
+ let resultCount = 0;
2498
+ for (const msg of msgs) {
2499
+ if (!Array.isArray(msg.content))
2500
+ continue;
2501
+ for (const b of msg.content) {
2502
+ if (b.type === "tool_use")
2503
+ useCount++;
2504
+ if (b.type === "tool_result")
2505
+ resultCount++;
2506
+ }
2414
2507
  }
2415
- return count;
2416
- }, 0);
2508
+ return { useCount, resultCount };
2509
+ };
2510
+ let { useCount: toolUseCount, resultCount: toolResultCount } = countToolBlocks(filteredMessages);
2417
2511
  if (toolUseCount > 0 || toolResultCount > 0) {
2418
2512
  this.logger.debug(`[Pre-API #6181] Sending ${filteredMessages.length} messages with ${toolUseCount} tool_use and ${toolResultCount} tool_result blocks`);
2419
2513
  if (toolUseCount !== toolResultCount) {
2420
- this.logger.warn(`[Pre-API #6181] Tool block mismatch! tool_use: ${toolUseCount}, tool_result: ${toolResultCount}. This may cause API errors.`);
2514
+ this.logger.warn(`[Pre-API #6181] Tool block mismatch! tool_use: ${toolUseCount}, tool_result: ${toolResultCount}. Attempting auto-repair...`);
2515
+ filteredMessages = ensureToolPairingIntegrity(filteredMessages, this.logger);
2516
+ ({ useCount: toolUseCount, resultCount: toolResultCount } = countToolBlocks(filteredMessages));
2517
+ if (toolUseCount !== toolResultCount) {
2518
+ this.logger.warn(`[Pre-API #6181] Auto-repair insufficient (tool_use: ${toolUseCount}, tool_result: ${toolResultCount}). Stripping all tool blocks.`);
2519
+ filteredMessages = stripAllToolBlocks(filteredMessages, this.logger);
2520
+ }
2421
2521
  }
2422
2522
  }
2423
2523
  const apiParams = {
@@ -11129,6 +11229,8 @@ function mapMimeTypeToArtifactType(mimeType) {
11129
11229
  case ClaudeArtifactMimeTypes.MARKDOWN:
11130
11230
  return "code";
11131
11231
  // Treat markdown as code for now
11232
+ case ClaudeArtifactMimeTypes.LATTICE:
11233
+ return "lattice";
11132
11234
  default:
11133
11235
  if (mimeType.includes("javascript") || mimeType.includes("jsx")) {
11134
11236
  return "react";
@@ -11877,6 +11979,7 @@ export {
11877
11979
  includeImagePromptSystemMessage,
11878
11980
  includeArtifactSystemMessage,
11879
11981
  ensureToolPairingIntegrity,
11982
+ stripAllToolBlocks,
11880
11983
  buildAndSortMessages,
11881
11984
  getLastBuildDebugInfo,
11882
11985
  AnthropicBackend,
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  BadRequestError,
4
4
  secureParameters
5
- } from "./chunk-MMAOFFE3.js";
5
+ } from "./chunk-5GK7VJLI.js";
6
6
  import {
7
7
  CompletionApiUsageTransaction,
8
8
  GenericCreditDeductTransaction,
@@ -12,7 +12,7 @@ import {
12
12
  TextGenerationUsageTransaction,
13
13
  TransferCreditTransaction,
14
14
  VideoGenerationUsageTransaction
15
- } from "./chunk-F3HPUK2I.js";
15
+ } from "./chunk-HQYUB4DK.js";
16
16
 
17
17
  // ../../b4m-core/packages/services/dist/src/creditService/subtractCredits.js
18
18
  import { z } from "zod";
@@ -6,12 +6,12 @@ import {
6
6
  getSettingsByNames,
7
7
  obfuscateApiKey,
8
8
  secureParameters
9
- } from "./chunk-MMAOFFE3.js";
9
+ } from "./chunk-5GK7VJLI.js";
10
10
  import {
11
11
  ApiKeyType,
12
12
  MementoTier,
13
13
  isSupportedEmbeddingModel
14
- } from "./chunk-F3HPUK2I.js";
14
+ } from "./chunk-HQYUB4DK.js";
15
15
 
16
16
  // ../../b4m-core/packages/services/dist/src/apiKeyService/get.js
17
17
  import { z } from "zod";