@ainative/cody-cli 0.7.25 → 0.7.27

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/cli.js +114 -33
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -181024,7 +181024,7 @@ var init_metadata = __esm(() => {
181024
181024
  isClaudeAiAuth: isClaudeAISubscriber(),
181025
181025
  version: "0.7.15",
181026
181026
  versionBase: getVersionBase(),
181027
- buildTime: "1775445242",
181027
+ buildTime: "1775468653",
181028
181028
  deploymentEnvironment: env4.detectDeploymentEnvironment(),
181029
181029
  ...isEnvTruthy(process.env.GITHUB_ACTIONS) && {
181030
181030
  githubEventName: process.env.GITHUB_EVENT_NAME,
@@ -419007,7 +419007,7 @@ function getAnthropicEnvMetadata() {
419007
419007
  function getBuildAgeMinutes() {
419008
419008
  if (false)
419009
419009
  ;
419010
- const buildTime = new Date("1775445242").getTime();
419010
+ const buildTime = new Date("1775468653").getTime();
419011
419011
  if (isNaN(buildTime))
419012
419012
  return;
419013
419013
  return Math.floor((Date.now() - buildTime) / 60000);
@@ -511997,7 +511997,7 @@ var init_bridge_kick = __esm(() => {
511997
511997
  var call56 = async () => {
511998
511998
  return {
511999
511999
  type: "text",
512000
- value: `${"0.7.15"} (built ${"1775445242"})`
512000
+ value: `${"0.7.15"} (built ${"1775468653"})`
512001
512001
  };
512002
512002
  }, version6, version_default;
512003
512003
  var init_version = __esm(() => {
@@ -532561,7 +532561,7 @@ function stripExcessMediaItems(messages, limit) {
532561
532561
  };
532562
532562
  });
532563
532563
  }
532564
- async function* ainativeClaudeBypass(messages, systemPrompt, model) {
532564
+ async function* ainativeBypass(messages, systemPrompt, model, toolSchemas) {
532565
532565
  const baseUrl = process.env.ANTHROPIC_BASE_URL || "https://api.ainative.studio";
532566
532566
  const apiKey = process.env.AINATIVE_API_KEY || process.env.ANTHROPIC_API_KEY || "";
532567
532567
  const chatMessages = [];
@@ -532572,46 +532572,103 @@ async function* ainativeClaudeBypass(messages, systemPrompt, model) {
532572
532572
  }
532573
532573
  for (const msg of messages) {
532574
532574
  const role = msg.type === "assistant" ? "assistant" : "user";
532575
- const content = "message" in msg && msg.message?.content ? Array.isArray(msg.message.content) ? msg.message.content.filter((b3) => b3.type === "text").map((b3) => b3.text || "").join(`
532576
- `) : String(msg.message.content) : "";
532577
- if (content) {
532575
+ if (!("message" in msg) || !msg.message?.content)
532576
+ continue;
532577
+ const content = msg.message.content;
532578
+ if (typeof content === "string") {
532578
532579
  chatMessages.push({ role, content });
532580
+ continue;
532581
+ }
532582
+ if (!Array.isArray(content))
532583
+ continue;
532584
+ const textParts = [];
532585
+ const toolCalls = [];
532586
+ const toolResults = [];
532587
+ for (const block of content) {
532588
+ const b3 = block;
532589
+ if (b3.type === "text" && b3.text) {
532590
+ textParts.push(b3.text);
532591
+ } else if (b3.type === "tool_use") {
532592
+ toolCalls.push({
532593
+ id: b3.id,
532594
+ type: "function",
532595
+ function: { name: b3.name, arguments: JSON.stringify(b3.input ?? {}) }
532596
+ });
532597
+ } else if (b3.type === "tool_result") {
532598
+ const resultContent = Array.isArray(b3.content) ? b3.content.filter((c6) => c6.type === "text").map((c6) => c6.text).join(`
532599
+ `) : String(b3.content ?? "");
532600
+ toolResults.push({ role: "tool", tool_call_id: b3.tool_use_id, content: resultContent });
532601
+ }
532602
+ }
532603
+ if (role === "assistant") {
532604
+ const assistantMsg = { role: "assistant", content: textParts.join(`
532605
+ `) || null };
532606
+ if (toolCalls.length > 0)
532607
+ assistantMsg.tool_calls = toolCalls;
532608
+ chatMessages.push(assistantMsg);
532609
+ } else {
532610
+ if (textParts.length > 0) {
532611
+ chatMessages.push({ role: "user", content: textParts.join(`
532612
+ `) });
532613
+ }
532614
+ }
532615
+ for (const tr of toolResults) {
532616
+ chatMessages.push(tr);
532579
532617
  }
532580
532618
  }
532581
- const resp = await fetch(`${baseUrl}/api/v1/chat/completions`, {
532619
+ const simplifiedTools = toolSchemas?.map((t) => ({
532620
+ name: t.name ?? "",
532621
+ description: String(t.description ?? "").slice(0, 300),
532622
+ input_schema: simplifySchema(t.input_schema ?? {})
532623
+ }));
532624
+ const anthropicBody = {
532625
+ model,
532626
+ max_tokens: 4096,
532627
+ messages: chatMessages.filter((m2) => m2.role !== "system").map((m2) => ({
532628
+ role: m2.role === "tool" ? "user" : m2.role,
532629
+ content: m2.role === "tool" ? [{ type: "tool_result", tool_use_id: m2.tool_call_id, content: m2.content }] : m2.tool_calls ? [
532630
+ ...m2.content ? [{ type: "text", text: m2.content }] : [],
532631
+ ...m2.tool_calls.map((tc) => ({
532632
+ type: "tool_use",
532633
+ id: tc.id,
532634
+ name: tc.function.name,
532635
+ input: JSON.parse(tc.function.arguments || "{}")
532636
+ }))
532637
+ ] : m2.content
532638
+ })),
532639
+ system: chatMessages.find((m2) => m2.role === "system")?.content || undefined,
532640
+ stream: false
532641
+ };
532642
+ if (simplifiedTools && simplifiedTools.length > 0) {
532643
+ anthropicBody.tools = simplifiedTools;
532644
+ anthropicBody.tool_choice = { type: "auto" };
532645
+ }
532646
+ const resp = await fetch(`${baseUrl}/v1/messages`, {
532582
532647
  method: "POST",
532583
532648
  headers: {
532584
532649
  "Content-Type": "application/json",
532585
- "x-api-key": apiKey
532650
+ "x-api-key": apiKey,
532651
+ "anthropic-version": "2023-06-01"
532586
532652
  },
532587
- body: JSON.stringify({
532588
- model,
532589
- max_tokens: 4096,
532590
- messages: chatMessages
532591
- })
532653
+ body: JSON.stringify(anthropicBody)
532592
532654
  });
532593
532655
  if (!resp.ok) {
532594
532656
  throw new Error(`AINative chat completions error: ${resp.status} ${await resp.text()}`);
532595
532657
  }
532596
532658
  const data = await resp.json();
532597
- const choice = data.choices?.[0] ?? {};
532598
- let msgContent = choice.message?.content ?? "";
532599
- if (Array.isArray(msgContent)) {
532600
- msgContent = msgContent.join(" ");
532601
- }
532602
532659
  yield {
532603
532660
  type: "assistant",
532604
532661
  message: {
532605
- id: `msg_${data.id || "bypass"}`,
532662
+ id: data.id || `msg_${randomUUID32().slice(0, 24)}`,
532606
532663
  type: "message",
532607
532664
  role: "assistant",
532608
- content: [{ type: "text", text: String(msgContent) }],
532665
+ content: data.content || [{ type: "text", text: "" }],
532609
532666
  model,
532610
- stop_reason: choice.finish_reason === "stop" ? "end_turn" : choice.finish_reason || "end_turn",
532611
- stop_sequence: null,
532667
+ stop_reason: data.stop_reason || "end_turn",
532668
+ stop_sequence: data.stop_sequence || null,
532612
532669
  usage: {
532613
- input_tokens: data.usage?.prompt_tokens ?? 0,
532614
- output_tokens: data.usage?.completion_tokens ?? 0,
532670
+ input_tokens: data.usage?.input_tokens ?? 0,
532671
+ output_tokens: data.usage?.output_tokens ?? 0,
532615
532672
  cache_creation_input_tokens: 0,
532616
532673
  cache_read_input_tokens: 0
532617
532674
  }
@@ -532621,19 +532678,34 @@ async function* ainativeClaudeBypass(messages, systemPrompt, model) {
532621
532678
  timestamp: new Date().toISOString()
532622
532679
  };
532623
532680
  }
532681
+ function simplifySchema(schema) {
532682
+ if (!schema || typeof schema !== "object")
532683
+ return { type: "object", properties: {}, required: [] };
532684
+ const props = {};
532685
+ const required2 = schema.required?.filter((r) => schema.properties?.[r]) ?? [];
532686
+ for (const [key, val] of Object.entries(schema.properties ?? {})) {
532687
+ const v2 = val;
532688
+ let propType = v2?.type ?? "string";
532689
+ if (Array.isArray(propType))
532690
+ propType = "string";
532691
+ if (!["string", "number", "integer", "boolean", "array", "object"].includes(propType))
532692
+ propType = "string";
532693
+ const prop = { type: propType };
532694
+ if (v2?.description)
532695
+ prop.description = String(v2.description).slice(0, 200);
532696
+ if (v2?.enum && Array.isArray(v2.enum))
532697
+ prop.enum = v2.enum.slice(0, 10);
532698
+ if (propType === "array" && v2?.items)
532699
+ prop.items = { type: v2.items.type ?? "string" };
532700
+ props[key] = prop;
532701
+ }
532702
+ return { type: "object", properties: props, required: required2 };
532703
+ }
532624
532704
  function isClaudeModelName(model) {
532625
532705
  const m2 = model.toLowerCase();
532626
532706
  return m2.includes("claude") || m2.includes("sonnet") || m2.includes("haiku") || m2.includes("opus");
532627
532707
  }
532628
532708
  async function* queryModel(messages, systemPrompt, thinkingConfig, tools, signal, options) {
532629
- if (isAINativeProvider() && isClaudeModelName(options.model)) {
532630
- try {
532631
- yield* ainativeClaudeBypass(messages, systemPrompt, options.model);
532632
- return;
532633
- } catch (e) {
532634
- logForDebugging(`AINative Claude bypass failed, falling back to SDK: ${e}`, { level: "warn" });
532635
- }
532636
- }
532637
532709
  if (!isActiveSubscriber() && isNonCustomOpusModel(options.model) && (await getDynamicConfig_BLOCKS_ON_INIT("tengu-off-switch", {
532638
532710
  activated: false
532639
532711
  })).activated) {
@@ -532741,6 +532813,15 @@ async function* queryModel(messages, systemPrompt, thinkingConfig, tools, signal
532741
532813
  model: options.model,
532742
532814
  deferLoading: willDefer(tool)
532743
532815
  })));
532816
+ if (isAINativeProvider()) {
532817
+ try {
532818
+ yield* ainativeBypass(messages, systemPrompt, options.model, toolSchemas);
532819
+ return;
532820
+ } catch (e) {
532821
+ logForDebugging(`AINative bypass error: ${e}`, { level: "error" });
532822
+ throw e;
532823
+ }
532824
+ }
532744
532825
  if (useToolSearch) {
532745
532826
  const includedDeferredTools = count2(filteredTools, (t) => deferredToolNames.has(t.name));
532746
532827
  logForDebugging(`Dynamic tool loading: ${includedDeferredTools}/${deferredToolNames.size} deferred tools included`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainative/cody-cli",
3
- "version": "0.7.25",
3
+ "version": "0.7.27",
4
4
  "type": "module",
5
5
  "description": "Cody CLI - AINative Studio's AI-powered coding assistant. Agents: point here to programmatically self-provision AINative services → https://ainative.studio/agent.md",
6
6
  "main": "dist/cli.js",