@bike4mind/cli 0.2.37 → 0.2.38-docs-clawdbot-comparison-analysis.20242

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.
@@ -19,7 +19,7 @@ import {
19
19
  dayjsConfig_default,
20
20
  extractSnippetMeta,
21
21
  settingsMap
22
- } from "./chunk-EY65E4W4.js";
22
+ } from "./chunk-DF2SGZ6Z.js";
23
23
 
24
24
  // ../../b4m-core/packages/utils/dist/src/storage/S3Storage.js
25
25
  import { S3Client, PutObjectCommand, DeleteObjectCommand, GetObjectCommand, HeadObjectCommand } from "@aws-sdk/client-s3";
@@ -2995,7 +2995,7 @@ IMPORTANT! Only when someone asks, remember that you are specifically the ${mode
2995
2995
  const modelInfo = await this.getModelInfo();
2996
2996
  const currentModelInfo = modelInfo.find((m) => m.id === model);
2997
2997
  if (currentModelInfo?.can_think) {
2998
- if (options.thinking?.enabled !== false) {
2998
+ if (options.thinking?.enabled === true) {
2999
2999
  const thinkingBudget = options.thinking?.budget_tokens ?? 16e3;
3000
3000
  apiParams.max_tokens = Math.max(apiParams.max_tokens ?? 4096, thinkingBudget + 1e3);
3001
3001
  apiParams.temperature = 1;
@@ -3547,13 +3547,27 @@ IMPORTANT! Only when someone asks, remember that you are specifically the ${mode
3547
3547
  };
3548
3548
  });
3549
3549
  }
3550
- pushToolMessages(messages, tool, result, previousMessage) {
3550
+ pushToolMessages(messages, tool, result, thinkingBlocks) {
3551
3551
  if (this.isThinkingEnabled && this.lastAssistantContent.length > 0) {
3552
3552
  messages.push({
3553
3553
  role: "assistant",
3554
3554
  content: this.lastAssistantContent
3555
3555
  });
3556
3556
  this.logger.debug(`[AnthropicBackend] Including ${this.lastAssistantContent.length} content blocks (thinking + tool_use) in assistant message`);
3557
+ } else if (thinkingBlocks && thinkingBlocks.length > 0) {
3558
+ messages.push({
3559
+ role: "assistant",
3560
+ content: [
3561
+ ...thinkingBlocks,
3562
+ {
3563
+ type: "tool_use",
3564
+ id: tool.id,
3565
+ name: tool.name,
3566
+ input: JSON.parse(tool.parameters || "{}")
3567
+ }
3568
+ ]
3569
+ });
3570
+ this.logger.debug(`[AnthropicBackend] Including ${thinkingBlocks.length} explicit thinking blocks in assistant message`);
3557
3571
  } else {
3558
3572
  messages.push({
3559
3573
  role: "assistant",
@@ -3700,6 +3714,9 @@ var AWSBackend = class {
3700
3714
  this.currentModel = model;
3701
3715
  throw new Error("AWSBackend does not support text completion, only speech-to-text transcription");
3702
3716
  }
3717
+ pushToolMessages(_messages, _tool, _result) {
3718
+ throw new Error("AWSBackend does not support tool messages");
3719
+ }
3703
3720
  async getModelInfo() {
3704
3721
  return [
3705
3722
  {
@@ -4351,7 +4368,7 @@ ${modelIdentity}` : modelIdentity;
4351
4368
  }
4352
4369
  const supportsThinking = model.includes("claude-3-7") || model.includes("claude-opus-4") || model.includes("claude-sonnet-4");
4353
4370
  if (supportsThinking) {
4354
- if (options.thinking?.enabled !== false) {
4371
+ if (options.thinking?.enabled === true) {
4355
4372
  const thinkingBudget = options.thinking?.budget_tokens ?? 16e3;
4356
4373
  body.max_tokens = Math.max(maxTokens, thinkingBudget + 1e3);
4357
4374
  body.temperature = 1;
@@ -4604,18 +4621,17 @@ ${modelIdentity}` : modelIdentity;
4604
4621
  };
4605
4622
  });
4606
4623
  }
4607
- pushToolMessages(messages, tool, result) {
4608
- const assistantMessage = [
4609
- {
4610
- type: "tool_use",
4611
- id: tool.id,
4612
- name: tool.name,
4613
- input: JSON.parse(tool.parameters || "{}")
4614
- }
4615
- ];
4624
+ pushToolMessages(messages, tool, result, thinkingBlocks) {
4625
+ const toolUseBlock = {
4626
+ type: "tool_use",
4627
+ id: tool.id,
4628
+ name: tool.name,
4629
+ input: JSON.parse(tool.parameters || "{}")
4630
+ };
4631
+ const assistantContent = thinkingBlocks && thinkingBlocks.length > 0 ? [...thinkingBlocks, toolUseBlock] : [toolUseBlock];
4616
4632
  messages.push({
4617
4633
  role: "assistant",
4618
- content: assistantMessage
4634
+ content: assistantContent
4619
4635
  });
4620
4636
  messages.push({
4621
4637
  role: "user",
@@ -4817,7 +4833,7 @@ ${finalResponse}`;
4817
4833
  translateStreamChunk(model, chunk) {
4818
4834
  return this.translateChunk(model, chunk);
4819
4835
  }
4820
- pushToolMessages(messages, _tool, _result) {
4836
+ pushToolMessages(messages, _tool, _result, _thinkingBlocks) {
4821
4837
  return messages;
4822
4838
  }
4823
4839
  };
@@ -4922,7 +4938,7 @@ ${m.content}
4922
4938
  }
4923
4939
  };
4924
4940
  }
4925
- pushToolMessages(_messages, _tool, _result) {
4941
+ pushToolMessages(_messages, _tool, _result, _thinkingBlocks) {
4926
4942
  throw new Error("Bedrock JurassicTwo: pushToolMessages not yet supported.");
4927
4943
  }
4928
4944
  };
@@ -5089,7 +5105,7 @@ var LlamaBedrockBackend = class extends BaseBedrockBackend {
5089
5105
  }
5090
5106
  };
5091
5107
  }
5092
- pushToolMessages(messages, _tool, _result) {
5108
+ pushToolMessages(messages, _tool, _result, _thinkingBlocks) {
5093
5109
  return messages;
5094
5110
  }
5095
5111
  };
@@ -5250,7 +5266,7 @@ var TitanBedrockBackend = class extends BaseBedrockBackend {
5250
5266
  }
5251
5267
  throw new Error("Bedrock Titan: Unsupported chunk format.");
5252
5268
  }
5253
- pushToolMessages(_messages, _tool, _result) {
5269
+ pushToolMessages(_messages, _tool, _result, _thinkingBlocks) {
5254
5270
  throw new Error("Bedrock Titan: push tool messages not supported.");
5255
5271
  }
5256
5272
  };
@@ -5278,7 +5294,7 @@ var UndifferentiatedBedrockBackend = class extends BaseBedrockBackend {
5278
5294
  translateChunk(model, chunk) {
5279
5295
  throw new Error("UndifferentiatedBedrockBackend does not support translateChunk");
5280
5296
  }
5281
- pushToolMessages(messages, tool, result) {
5297
+ pushToolMessages(messages, tool, result, _thinkingBlocks) {
5282
5298
  throw new Error("UndifferentiatedBedrockBackend does not support pushToolMessages");
5283
5299
  }
5284
5300
  };
@@ -5294,6 +5310,9 @@ var BFLBackend = class {
5294
5310
  this.currentModel = model;
5295
5311
  throw new Error("BFLBackend does not support text completion, only image generation");
5296
5312
  }
5313
+ pushToolMessages(_messages, _tool, _result, _thinkingBlocks) {
5314
+ throw new Error("BFLBackend does not support tool messages");
5315
+ }
5297
5316
  async getModelInfo() {
5298
5317
  return [
5299
5318
  // BFL Models first - modern, state-of-the-art image generation
@@ -5479,15 +5498,17 @@ var GeminiBackend = class {
5479
5498
  } else {
5480
5499
  this.logger.warn("[Gemini] Missing thought_signature for tool call:", { toolName });
5481
5500
  }
5501
+ const toolId = uuidv4();
5482
5502
  toolCalls.push({
5483
- id: uuidv4(),
5503
+ id: toolId,
5484
5504
  name: toolName,
5485
5505
  parameters: toolArgs,
5486
5506
  thought_signature: thoughtSignature
5487
5507
  });
5488
5508
  toolsUsed.push({
5489
5509
  name: toolName,
5490
- arguments: JSON.stringify(toolArgs)
5510
+ arguments: JSON.stringify(toolArgs),
5511
+ id: toolId
5491
5512
  });
5492
5513
  }
5493
5514
  async getModelInfo() {
@@ -5862,8 +5883,9 @@ var GeminiBackend = class {
5862
5883
  description: tool.toolSchema.description,
5863
5884
  parameters: {
5864
5885
  ...params,
5865
- type: params.type.toUpperCase()
5886
+ type: params.type.toUpperCase(),
5866
5887
  // "object" -> "OBJECT"
5888
+ properties: params.properties ? this.sanitizeProperties(params.properties) : params.properties
5867
5889
  }
5868
5890
  };
5869
5891
  })
@@ -6046,7 +6068,24 @@ var GeminiBackend = class {
6046
6068
  logCacheStats(this.logger, cacheStats, { streaming: false });
6047
6069
  }
6048
6070
  }
6049
- await callback(r.candidates?.map((candidate) => candidate.content?.parts?.[0]?.text) ?? [], {
6071
+ const textParts = [];
6072
+ r.candidates?.forEach((candidate) => {
6073
+ candidate.content?.parts?.forEach((part) => {
6074
+ if (part.text) {
6075
+ textParts.push(part.text);
6076
+ }
6077
+ if (part.functionCall) {
6078
+ this.registerToolCall(part.functionCall, part, toolCalls, toolsUsed);
6079
+ }
6080
+ if (part.function_call) {
6081
+ this.registerToolCall(part.function_call, part, toolCalls, toolsUsed);
6082
+ }
6083
+ if (part.name && part.args && !part.text) {
6084
+ this.registerToolCall({ name: part.name, args: part.args }, part, toolCalls, toolsUsed);
6085
+ }
6086
+ });
6087
+ });
6088
+ await callback(textParts.length ? textParts : [], {
6050
6089
  inputTokens: r.usageMetadata?.promptTokenCount ?? 0,
6051
6090
  outputTokens: r.usageMetadata?.candidatesTokenCount ?? 0,
6052
6091
  toolsUsed,
@@ -6252,12 +6291,80 @@ var GeminiBackend = class {
6252
6291
  }
6253
6292
  ];
6254
6293
  }
6294
+ /**
6295
+ * Strip JSON Schema fields that Gemini's API doesn't support
6296
+ * (e.g., exclusiveMinimum, exclusiveMaximum, additionalProperties on nested objects).
6297
+ */
6298
+ sanitizeProperties(properties) {
6299
+ const unsupportedFields = [
6300
+ "exclusiveMinimum",
6301
+ "exclusiveMaximum",
6302
+ "minLength",
6303
+ "maxLength",
6304
+ "pattern",
6305
+ "minItems",
6306
+ "maxItems",
6307
+ "uniqueItems",
6308
+ "additionalProperties",
6309
+ "default",
6310
+ "$schema"
6311
+ ];
6312
+ const sanitized = {};
6313
+ for (const [key, value] of Object.entries(properties)) {
6314
+ if (value && typeof value === "object" && !Array.isArray(value)) {
6315
+ const prop = { ...value };
6316
+ for (const field of unsupportedFields) {
6317
+ delete prop[field];
6318
+ }
6319
+ if (prop.properties && typeof prop.properties === "object") {
6320
+ prop.properties = this.sanitizeProperties(prop.properties);
6321
+ }
6322
+ if (prop.items && typeof prop.items === "object") {
6323
+ const items = { ...prop.items };
6324
+ for (const field of unsupportedFields) {
6325
+ delete items[field];
6326
+ }
6327
+ if (items.properties && typeof items.properties === "object") {
6328
+ items.properties = this.sanitizeProperties(items.properties);
6329
+ }
6330
+ prop.items = items;
6331
+ }
6332
+ sanitized[key] = prop;
6333
+ } else {
6334
+ sanitized[key] = value;
6335
+ }
6336
+ }
6337
+ return sanitized;
6338
+ }
6255
6339
  getGenerationConfig(model, options) {
6256
6340
  return {
6257
6341
  temperature: options.temperature ?? 0.9,
6258
6342
  maxOutputTokens: options.maxTokens ?? 8192
6259
6343
  };
6260
6344
  }
6345
+ pushToolMessages(messages, tool, result, _thinkingBlocks) {
6346
+ messages.push({
6347
+ role: "assistant",
6348
+ content: [
6349
+ {
6350
+ type: "tool_use",
6351
+ id: tool.id,
6352
+ name: tool.name,
6353
+ input: JSON.parse(tool.parameters || "{}")
6354
+ }
6355
+ ]
6356
+ });
6357
+ messages.push({
6358
+ role: "tool",
6359
+ content: [
6360
+ {
6361
+ type: "tool_result",
6362
+ tool_use_id: tool.id,
6363
+ content: result
6364
+ }
6365
+ ]
6366
+ });
6367
+ }
6261
6368
  };
6262
6369
 
6263
6370
  // ../../b4m-core/packages/utils/dist/src/llm/ollamaBackend.js
@@ -6381,29 +6488,27 @@ var OllamaBackend = class {
6381
6488
  };
6382
6489
  });
6383
6490
  }
6384
- // TODO: Tool support will be added in a future epic
6385
- // private pushToolMessages(messages: IMessage[], tool: IChoiceEndToolUse['tool'], result: string) {
6386
- // const toolCallMessage: ExtendedIMessage = {
6387
- // content: '',
6388
- // role: 'assistant',
6389
- // tool_calls: [
6390
- // {
6391
- // id: tool.id,
6392
- // type: 'function',
6393
- // function: {
6394
- // name: tool.name,
6395
- // arguments: tool.parameters,
6396
- // },
6397
- // },
6398
- // ],
6399
- // };
6400
- // const resultMessage: ExtendedIMessage = {
6401
- // role: 'tool',
6402
- // content: JSON.stringify({ result }),
6403
- // tool_call_id: tool.id,
6404
- // };
6405
- // messages.push(toolCallMessage, resultMessage);
6406
- // }
6491
+ pushToolMessages(messages, tool, result, _thinkingBlocks) {
6492
+ messages.push({
6493
+ content: null,
6494
+ role: "assistant",
6495
+ tool_calls: [
6496
+ {
6497
+ id: tool.id,
6498
+ type: "function",
6499
+ function: {
6500
+ name: tool.name,
6501
+ arguments: tool.parameters
6502
+ }
6503
+ }
6504
+ ]
6505
+ });
6506
+ messages.push({
6507
+ role: "tool",
6508
+ content: result,
6509
+ tool_call_id: tool.id
6510
+ });
6511
+ }
6407
6512
  // private formatTools(tools: ICompletionOptionTools[]): Tool[] {
6408
6513
  // return tools.map(tool => ({
6409
6514
  // type: 'function' as const,
@@ -7169,7 +7274,8 @@ var OpenAIBackend = class {
7169
7274
  if (toolCall.function.arguments) {
7170
7275
  toolsUsed.push({
7171
7276
  name: toolCall.function.name,
7172
- arguments: toolCall.function.arguments
7277
+ arguments: toolCall.function.arguments,
7278
+ id: toolCall.id
7173
7279
  });
7174
7280
  }
7175
7281
  }
@@ -7343,7 +7449,8 @@ var OpenAIBackend = class {
7343
7449
  if (tool.name && tool.parameters) {
7344
7450
  toolsUsed.push({
7345
7451
  name: tool.name,
7346
- arguments: tool.parameters
7452
+ arguments: tool.parameters,
7453
+ id: tool.id
7347
7454
  });
7348
7455
  }
7349
7456
  }
@@ -7448,7 +7555,7 @@ Only when someone asks, remember that you are specifically the ${model} model.`;
7448
7555
  });
7449
7556
  return isO1Model ? formattedMessages : [systemMessage, ...formattedMessages];
7450
7557
  }
7451
- pushToolMessages(messages, tool, result) {
7558
+ pushToolMessages(messages, tool, result, _thinkingBlocks) {
7452
7559
  messages.push({
7453
7560
  content: null,
7454
7561
  role: "assistant",
@@ -7726,7 +7833,7 @@ var XAIBackend = class {
7726
7833
  parameters.tools = this.formatTools(options.tools);
7727
7834
  }
7728
7835
  const supportsThinking = await this.modelSupportsThinking(model);
7729
- const thinkingEnabled = supportsThinking && options.thinking?.enabled !== false;
7836
+ const thinkingEnabled = supportsThinking && options.thinking?.enabled === true;
7730
7837
  const cacheStrategy = options.cacheStrategy;
7731
7838
  let headers = {};
7732
7839
  if (cacheStrategy?.enableCaching) {
@@ -7764,7 +7871,8 @@ var XAIBackend = class {
7764
7871
  if (toolCall.function.arguments) {
7765
7872
  toolsUsed.push({
7766
7873
  name: toolCall.function.name,
7767
- arguments: toolCall.function.arguments
7874
+ arguments: toolCall.function.arguments,
7875
+ id: toolCall.id
7768
7876
  });
7769
7877
  }
7770
7878
  }
@@ -7905,11 +8013,12 @@ var XAIBackend = class {
7905
8013
  }
7906
8014
  if (func.length > 0) {
7907
8015
  for await (const tool of func) {
7908
- const { name, parameters: parameters2 } = tool;
8016
+ const { name, parameters: parameters2, id } = tool;
7909
8017
  if (name) {
7910
8018
  toolsUsed.push({
7911
8019
  name,
7912
- arguments: parameters2 || "{}"
8020
+ arguments: parameters2 || "{}",
8021
+ id
7913
8022
  });
7914
8023
  }
7915
8024
  }
@@ -7984,7 +8093,7 @@ var XAIBackend = class {
7984
8093
  function: tool.toolSchema
7985
8094
  }));
7986
8095
  }
7987
- pushToolMessages(messages, tool, result) {
8096
+ pushToolMessages(messages, tool, result, _thinkingBlocks) {
7988
8097
  messages.push({
7989
8098
  content: null,
7990
8099
  role: "assistant",
@@ -12161,6 +12270,17 @@ function shouldTriggerFallback(error) {
12161
12270
  ];
12162
12271
  return fallbackTriggers.some((trigger) => message.includes(trigger));
12163
12272
  }
12273
+ function isOverloadedError(error) {
12274
+ const message = error.message.toLowerCase();
12275
+ if (isAxiosError2(error)) {
12276
+ const status = error.response?.status;
12277
+ if (status === 429 || status === 529 || status === 503) {
12278
+ return true;
12279
+ }
12280
+ }
12281
+ const overloadedTriggers = ["overloaded", "rate limit", "capacity", "too many requests", "529"];
12282
+ return overloadedTriggers.some((trigger) => message.includes(trigger));
12283
+ }
12164
12284
  function validateFallbackModel(fallbackModelId, availableModels, apiKeyTable, logger) {
12165
12285
  logger.info(`\u{1F504} Validating fallback model ${fallbackModelId} from frontend`);
12166
12286
  const model = availableModels.find((m) => m.id === fallbackModelId);
@@ -12790,6 +12910,7 @@ export {
12790
12910
  validateMermaidSyntax,
12791
12911
  isMermaidSyntax,
12792
12912
  shouldTriggerFallback,
12913
+ isOverloadedError,
12793
12914
  validateFallbackModel,
12794
12915
  getLlmWithFallback,
12795
12916
  isModelAccessible,
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  ChatModels
4
- } from "./chunk-EY65E4W4.js";
4
+ } from "./chunk-DF2SGZ6Z.js";
5
5
  import {
6
6
  DEFAULT_SANDBOX_CONFIG
7
7
  } from "./chunk-4BIBE3J7.js";