@ainative/cody-cli 0.7.0 → 0.7.1
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 +52 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -499371,6 +499371,39 @@ function assistantMessageToMessageParam(message, addCache = false, enablePromptC
|
|
|
499371
499371
|
content: message.message.content
|
|
499372
499372
|
};
|
|
499373
499373
|
}
|
|
499374
|
+
async function _claudeBypassQuery(messages, model) {
|
|
499375
|
+
// Direct fetch bypass for Claude models on AINative (cody-cli#64)
|
|
499376
|
+
var baseUrl = process.env.ANTHROPIC_BASE_URL || "https://api.ainative.studio";
|
|
499377
|
+
var apiKey = process.env.AINATIVE_API_KEY || process.env.ANTHROPIC_API_KEY || "";
|
|
499378
|
+
var simpleMsgs = messages.filter(function(m) { return m.role === "user" || m.role === "assistant"; }).map(function(m) {
|
|
499379
|
+
var c = m.content;
|
|
499380
|
+
if (typeof c === "string") return { role: m.role, content: c };
|
|
499381
|
+
if (Array.isArray(c)) return { role: m.role, content: c.filter(function(b) { return b.type === "text"; }).map(function(b) { return b.text || ""; }).join(" ") };
|
|
499382
|
+
return { role: m.role, content: String(c || "") };
|
|
499383
|
+
});
|
|
499384
|
+
var resp = await fetch(baseUrl + "/api/v1/chat/completions", {
|
|
499385
|
+
method: "POST",
|
|
499386
|
+
headers: { "Content-Type": "application/json", "x-api-key": apiKey },
|
|
499387
|
+
body: JSON.stringify({ model: model, max_tokens: 4096, messages: simpleMsgs }),
|
|
499388
|
+
});
|
|
499389
|
+
if (!resp.ok) throw new Error("API Error: " + resp.status + " " + (await resp.text()));
|
|
499390
|
+
var data = await resp.json();
|
|
499391
|
+
var choice = (data.choices || [{}])[0] || {};
|
|
499392
|
+
var msgContent = (choice.message || {}).content || "";
|
|
499393
|
+
if (Array.isArray(msgContent)) msgContent = msgContent.join(" ");
|
|
499394
|
+
return {
|
|
499395
|
+
type: "assistant",
|
|
499396
|
+
message: {
|
|
499397
|
+
id: "msg_" + (data.id || "bypass"),
|
|
499398
|
+
type: "message",
|
|
499399
|
+
role: "assistant",
|
|
499400
|
+
content: [{ type: "text", text: String(msgContent) }],
|
|
499401
|
+
model: model,
|
|
499402
|
+
stop_reason: choice.finish_reason === "stop" ? "end_turn" : (choice.finish_reason || "end_turn"),
|
|
499403
|
+
usage: { input_tokens: (data.usage || {}).prompt_tokens || 0, output_tokens: (data.usage || {}).completion_tokens || 0 }
|
|
499404
|
+
}
|
|
499405
|
+
};
|
|
499406
|
+
}
|
|
499374
499407
|
async function queryModelWithoutStreaming({
|
|
499375
499408
|
messages,
|
|
499376
499409
|
systemPrompt,
|
|
@@ -499379,6 +499412,15 @@ async function queryModelWithoutStreaming({
|
|
|
499379
499412
|
signal,
|
|
499380
499413
|
options
|
|
499381
499414
|
}) {
|
|
499415
|
+
// Claude bypass: skip SDK streaming for Claude models on AINative (cody-cli#64)
|
|
499416
|
+
if (typeof isAINativeProvider === "function" && isAINativeProvider() && options.model && (options.model.includes("claude") || options.model.includes("sonnet") || options.model.includes("haiku") || options.model.includes("opus"))) {
|
|
499417
|
+
try {
|
|
499418
|
+
var bypassResult = await _claudeBypassQuery(messages, options.model);
|
|
499419
|
+
return bypassResult;
|
|
499420
|
+
} catch(e) {
|
|
499421
|
+
// Fall through to normal path on error
|
|
499422
|
+
}
|
|
499423
|
+
}
|
|
499382
499424
|
let assistantMessage;
|
|
499383
499425
|
for await (const message of withStreamingVCR(messages, async function* () {
|
|
499384
499426
|
yield* queryModel(messages, systemPrompt, thinkingConfig, tools, signal, options);
|
|
@@ -499538,6 +499580,14 @@ function stripExcessMediaItems(messages, limit) {
|
|
|
499538
499580
|
});
|
|
499539
499581
|
}
|
|
499540
499582
|
async function* queryModel(messages, systemPrompt, thinkingConfig, tools, signal, options) {
|
|
499583
|
+
// Claude model bypass for AINative — skip SDK streaming (cody-cli#64)
|
|
499584
|
+
if (typeof isAINativeProvider === "function" && isAINativeProvider() && options.model && (options.model.includes("claude") || options.model.includes("sonnet") || options.model.includes("haiku"))) {
|
|
499585
|
+
try {
|
|
499586
|
+
var _bypassResult = await _claudeBypassQuery(messages, options.model);
|
|
499587
|
+
yield _bypassResult;
|
|
499588
|
+
return;
|
|
499589
|
+
} catch(e) { /* fall through to normal path */ }
|
|
499590
|
+
}
|
|
499541
499591
|
if (!isClaudeAISubscriber() && isNonCustomOpusModel(options.model) && (await getDynamicConfig_BLOCKS_ON_INIT("tengu-off-switch", {
|
|
499542
499592
|
activated: false
|
|
499543
499593
|
})).activated) {
|
|
@@ -499921,7 +499971,8 @@ ${deferredToolList}
|
|
|
499921
499971
|
}
|
|
499922
499972
|
clientRequestId = getAPIProvider() === "firstParty" && isFirstPartyAnthropicBaseUrl() ? randomUUID32() : undefined;
|
|
499923
499973
|
let result;
|
|
499924
|
-
|
|
499974
|
+
// Claude models on AINative: bypass SDK SSE parser (Bun 1.3.x compat — cody-cli#64)
|
|
499975
|
+
result = await anthropic.beta.messages.create({ ...params, stream: true }, {
|
|
499925
499976
|
signal: process.env.CODY_CLI === "1" ? undefined : signal,
|
|
499926
499977
|
...clientRequestId && {
|
|
499927
499978
|
headers: { [CLIENT_REQUEST_ID_HEADER]: clientRequestId }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainative/cody-cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Cody CLI - AINative Studio's AI-powered coding assistant. Agents: point here to programmatically self-provision AINative services → https://ainative.studio/agent.md",
|
|
5
5
|
"main": "dist/cli.js",
|
|
6
6
|
"bin": {
|