@ainative/cody-cli 0.7.25 → 0.7.26
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.
- package/dist/cli.js +130 -33
- 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: "
|
|
181027
|
+
buildTime: "1775457519",
|
|
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("
|
|
419010
|
+
const buildTime = new Date("1775457519").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 ${"
|
|
512000
|
+
value: `${"0.7.15"} (built ${"1775457519"})`
|
|
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*
|
|
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,119 @@ 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
|
-
|
|
532576
|
-
|
|
532577
|
-
|
|
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
|
|
532619
|
+
const simplifiedTools = toolSchemas?.map((t) => ({
|
|
532620
|
+
type: "function",
|
|
532621
|
+
function: {
|
|
532622
|
+
name: t.name ?? "",
|
|
532623
|
+
description: String(t.description ?? "").slice(0, 300),
|
|
532624
|
+
parameters: simplifySchema(t.input_schema ?? {})
|
|
532625
|
+
}
|
|
532626
|
+
}));
|
|
532627
|
+
const body = {
|
|
532628
|
+
model,
|
|
532629
|
+
max_tokens: 4096,
|
|
532630
|
+
messages: chatMessages
|
|
532631
|
+
};
|
|
532632
|
+
if (simplifiedTools && simplifiedTools.length > 0) {
|
|
532633
|
+
body.tools = simplifiedTools;
|
|
532634
|
+
body.tool_choice = "auto";
|
|
532635
|
+
}
|
|
532636
|
+
const anthropicBody = {
|
|
532637
|
+
model,
|
|
532638
|
+
max_tokens: 4096,
|
|
532639
|
+
messages: chatMessages.filter((m2) => m2.role !== "system").map((m2) => ({
|
|
532640
|
+
role: m2.role === "tool" ? "user" : m2.role,
|
|
532641
|
+
content: m2.role === "tool" ? [{ type: "tool_result", tool_use_id: m2.tool_call_id, content: m2.content }] : m2.tool_calls ? [
|
|
532642
|
+
...m2.content ? [{ type: "text", text: m2.content }] : [],
|
|
532643
|
+
...m2.tool_calls.map((tc) => ({
|
|
532644
|
+
type: "tool_use",
|
|
532645
|
+
id: tc.id,
|
|
532646
|
+
name: tc.function.name,
|
|
532647
|
+
input: JSON.parse(tc.function.arguments || "{}")
|
|
532648
|
+
}))
|
|
532649
|
+
] : m2.content
|
|
532650
|
+
})),
|
|
532651
|
+
system: chatMessages.find((m2) => m2.role === "system")?.content || undefined,
|
|
532652
|
+
stream: false
|
|
532653
|
+
};
|
|
532654
|
+
if (simplifiedTools && simplifiedTools.length > 0) {
|
|
532655
|
+
anthropicBody.tools = simplifiedTools.map((t) => ({
|
|
532656
|
+
name: t.function.name,
|
|
532657
|
+
description: t.function.description,
|
|
532658
|
+
input_schema: t.function.parameters
|
|
532659
|
+
}));
|
|
532660
|
+
anthropicBody.tool_choice = { type: "auto" };
|
|
532661
|
+
}
|
|
532662
|
+
const resp = await fetch(`${baseUrl}/v1/messages`, {
|
|
532582
532663
|
method: "POST",
|
|
532583
532664
|
headers: {
|
|
532584
532665
|
"Content-Type": "application/json",
|
|
532585
|
-
"x-api-key": apiKey
|
|
532666
|
+
"x-api-key": apiKey,
|
|
532667
|
+
"anthropic-version": "2023-06-01"
|
|
532586
532668
|
},
|
|
532587
|
-
body: JSON.stringify(
|
|
532588
|
-
model,
|
|
532589
|
-
max_tokens: 4096,
|
|
532590
|
-
messages: chatMessages
|
|
532591
|
-
})
|
|
532669
|
+
body: JSON.stringify(anthropicBody)
|
|
532592
532670
|
});
|
|
532593
532671
|
if (!resp.ok) {
|
|
532594
532672
|
throw new Error(`AINative chat completions error: ${resp.status} ${await resp.text()}`);
|
|
532595
532673
|
}
|
|
532596
532674
|
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
532675
|
yield {
|
|
532603
532676
|
type: "assistant",
|
|
532604
532677
|
message: {
|
|
532605
|
-
id: `msg_${
|
|
532678
|
+
id: data.id || `msg_${randomUUID32().slice(0, 24)}`,
|
|
532606
532679
|
type: "message",
|
|
532607
532680
|
role: "assistant",
|
|
532608
|
-
content: [{ type: "text", text:
|
|
532681
|
+
content: data.content || [{ type: "text", text: "" }],
|
|
532609
532682
|
model,
|
|
532610
|
-
stop_reason:
|
|
532611
|
-
stop_sequence: null,
|
|
532683
|
+
stop_reason: data.stop_reason || "end_turn",
|
|
532684
|
+
stop_sequence: data.stop_sequence || null,
|
|
532612
532685
|
usage: {
|
|
532613
|
-
input_tokens: data.usage?.
|
|
532614
|
-
output_tokens: data.usage?.
|
|
532686
|
+
input_tokens: data.usage?.input_tokens ?? 0,
|
|
532687
|
+
output_tokens: data.usage?.output_tokens ?? 0,
|
|
532615
532688
|
cache_creation_input_tokens: 0,
|
|
532616
532689
|
cache_read_input_tokens: 0
|
|
532617
532690
|
}
|
|
@@ -532621,19 +532694,34 @@ async function* ainativeClaudeBypass(messages, systemPrompt, model) {
|
|
|
532621
532694
|
timestamp: new Date().toISOString()
|
|
532622
532695
|
};
|
|
532623
532696
|
}
|
|
532697
|
+
function simplifySchema(schema) {
|
|
532698
|
+
if (!schema || typeof schema !== "object")
|
|
532699
|
+
return { type: "object", properties: {}, required: [] };
|
|
532700
|
+
const props = {};
|
|
532701
|
+
const required2 = schema.required?.filter((r) => schema.properties?.[r]) ?? [];
|
|
532702
|
+
for (const [key, val] of Object.entries(schema.properties ?? {})) {
|
|
532703
|
+
const v2 = val;
|
|
532704
|
+
let propType = v2?.type ?? "string";
|
|
532705
|
+
if (Array.isArray(propType))
|
|
532706
|
+
propType = "string";
|
|
532707
|
+
if (!["string", "number", "integer", "boolean", "array", "object"].includes(propType))
|
|
532708
|
+
propType = "string";
|
|
532709
|
+
const prop = { type: propType };
|
|
532710
|
+
if (v2?.description)
|
|
532711
|
+
prop.description = String(v2.description).slice(0, 200);
|
|
532712
|
+
if (v2?.enum && Array.isArray(v2.enum))
|
|
532713
|
+
prop.enum = v2.enum.slice(0, 10);
|
|
532714
|
+
if (propType === "array" && v2?.items)
|
|
532715
|
+
prop.items = { type: v2.items.type ?? "string" };
|
|
532716
|
+
props[key] = prop;
|
|
532717
|
+
}
|
|
532718
|
+
return { type: "object", properties: props, required: required2 };
|
|
532719
|
+
}
|
|
532624
532720
|
function isClaudeModelName(model) {
|
|
532625
532721
|
const m2 = model.toLowerCase();
|
|
532626
532722
|
return m2.includes("claude") || m2.includes("sonnet") || m2.includes("haiku") || m2.includes("opus");
|
|
532627
532723
|
}
|
|
532628
532724
|
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
532725
|
if (!isActiveSubscriber() && isNonCustomOpusModel(options.model) && (await getDynamicConfig_BLOCKS_ON_INIT("tengu-off-switch", {
|
|
532638
532726
|
activated: false
|
|
532639
532727
|
})).activated) {
|
|
@@ -532741,6 +532829,15 @@ async function* queryModel(messages, systemPrompt, thinkingConfig, tools, signal
|
|
|
532741
532829
|
model: options.model,
|
|
532742
532830
|
deferLoading: willDefer(tool)
|
|
532743
532831
|
})));
|
|
532832
|
+
if (isAINativeProvider()) {
|
|
532833
|
+
try {
|
|
532834
|
+
yield* ainativeBypass(messages, systemPrompt, options.model, toolSchemas);
|
|
532835
|
+
return;
|
|
532836
|
+
} catch (e) {
|
|
532837
|
+
logForDebugging(`AINative bypass error: ${e}`, { level: "error" });
|
|
532838
|
+
throw e;
|
|
532839
|
+
}
|
|
532840
|
+
}
|
|
532744
532841
|
if (useToolSearch) {
|
|
532745
532842
|
const includedDeferredTools = count2(filteredTools, (t) => deferredToolNames.has(t.name));
|
|
532746
532843
|
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.
|
|
3
|
+
"version": "0.7.26",
|
|
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",
|