@opencow-ai/opencow-agent-sdk 0.4.3 → 0.4.4
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.mjs +253 -85
- package/dist/client.js +244 -76
- package/dist/lib/schemaSanitizer.d.ts +27 -6
- package/dist/providers/openai/capabilities.d.ts +8 -0
- package/dist/providers/openai/shim.d.ts +9 -2
- package/dist/sdk.js +244 -76
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -57406,12 +57406,12 @@ function getOpus46CostTier(fastMode) {
|
|
|
57406
57406
|
return COST_TIER_5_25;
|
|
57407
57407
|
}
|
|
57408
57408
|
function tokensToUSDCost(modelCosts, usage) {
|
|
57409
|
-
return usage
|
|
57409
|
+
return (usage?.input_tokens ?? 0) / 1e6 * modelCosts.inputTokens + (usage?.output_tokens ?? 0) / 1e6 * modelCosts.outputTokens + (usage?.cache_read_input_tokens ?? 0) / 1e6 * modelCosts.promptCacheReadTokens + (usage?.cache_creation_input_tokens ?? 0) / 1e6 * modelCosts.promptCacheWriteTokens + (usage?.server_tool_use?.web_search_requests ?? 0) * modelCosts.webSearchRequests;
|
|
57410
57410
|
}
|
|
57411
57411
|
function getModelCosts(model, usage) {
|
|
57412
57412
|
const shortName = getCanonicalName(model);
|
|
57413
57413
|
if (shortName === firstPartyNameToCanonical(CLAUDE_OPUS_4_6_CONFIG.firstParty)) {
|
|
57414
|
-
const isFastMode = usage
|
|
57414
|
+
const isFastMode = usage?.speed === "fast";
|
|
57415
57415
|
return getOpus46CostTier(isFastMode);
|
|
57416
57416
|
}
|
|
57417
57417
|
const costs = MODEL_COSTS[shortName];
|
|
@@ -84200,10 +84200,25 @@ function sanitizeTypeField(record2) {
|
|
|
84200
84200
|
record2.type = filtered;
|
|
84201
84201
|
}
|
|
84202
84202
|
}
|
|
84203
|
-
function makeSchemaNullable(schema) {
|
|
84203
|
+
function makeSchemaNullable(schema, style = "union") {
|
|
84204
84204
|
if ("enum" in schema || "const" in schema)
|
|
84205
84205
|
return schema;
|
|
84206
|
+
if (schema.nullable === true)
|
|
84207
|
+
return schema;
|
|
84206
84208
|
const raw = schema.type;
|
|
84209
|
+
if (style === "nullable") {
|
|
84210
|
+
if (typeof raw === "string") {
|
|
84211
|
+
if (raw === "null")
|
|
84212
|
+
return schema;
|
|
84213
|
+
return { ...schema, nullable: true };
|
|
84214
|
+
}
|
|
84215
|
+
if (Array.isArray(raw)) {
|
|
84216
|
+
if (raw.includes("null"))
|
|
84217
|
+
return schema;
|
|
84218
|
+
return { ...schema, nullable: true };
|
|
84219
|
+
}
|
|
84220
|
+
return schema;
|
|
84221
|
+
}
|
|
84207
84222
|
if (typeof raw === "string") {
|
|
84208
84223
|
if (raw === "null")
|
|
84209
84224
|
return schema;
|
|
@@ -84216,6 +84231,52 @@ function makeSchemaNullable(schema) {
|
|
|
84216
84231
|
}
|
|
84217
84232
|
return schema;
|
|
84218
84233
|
}
|
|
84234
|
+
function splitTypeArrayToAnyOf(schema) {
|
|
84235
|
+
if (!Array.isArray(schema.type) || schema.type.length < 2)
|
|
84236
|
+
return schema;
|
|
84237
|
+
const types = schema.type;
|
|
84238
|
+
const hasNull = types.includes("null");
|
|
84239
|
+
const nonNullTypes = types.filter((t) => t !== "null");
|
|
84240
|
+
if (hasNull && nonNullTypes.length === 1) {
|
|
84241
|
+
const { type: _type, ...rest } = schema;
|
|
84242
|
+
return { ...rest, type: nonNullTypes[0], nullable: true };
|
|
84243
|
+
}
|
|
84244
|
+
const ARRAY_KEYS = new Set(["items"]);
|
|
84245
|
+
const OBJECT_KEYS = new Set(["properties", "required", "additionalProperties"]);
|
|
84246
|
+
const TYPE_SPECIFIC_KEYS = new Set([...ARRAY_KEYS, ...OBJECT_KEYS]);
|
|
84247
|
+
const base2 = {};
|
|
84248
|
+
const structural = {};
|
|
84249
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
84250
|
+
if (key === "type")
|
|
84251
|
+
continue;
|
|
84252
|
+
if (TYPE_SPECIFIC_KEYS.has(key)) {
|
|
84253
|
+
structural[key] = value;
|
|
84254
|
+
} else {
|
|
84255
|
+
base2[key] = value;
|
|
84256
|
+
}
|
|
84257
|
+
}
|
|
84258
|
+
const variants = nonNullTypes.map((t) => {
|
|
84259
|
+
const variant = { type: t };
|
|
84260
|
+
if (t === "array") {
|
|
84261
|
+
for (const k of ARRAY_KEYS) {
|
|
84262
|
+
if (k in structural)
|
|
84263
|
+
variant[k] = structural[k];
|
|
84264
|
+
}
|
|
84265
|
+
} else if (t === "object") {
|
|
84266
|
+
for (const k of OBJECT_KEYS) {
|
|
84267
|
+
if (k in structural)
|
|
84268
|
+
variant[k] = structural[k];
|
|
84269
|
+
}
|
|
84270
|
+
}
|
|
84271
|
+
return variant;
|
|
84272
|
+
});
|
|
84273
|
+
if (hasNull)
|
|
84274
|
+
base2.nullable = true;
|
|
84275
|
+
if (variants.length === 1) {
|
|
84276
|
+
return { ...base2, ...variants[0] };
|
|
84277
|
+
}
|
|
84278
|
+
return { ...base2, anyOf: variants };
|
|
84279
|
+
}
|
|
84219
84280
|
function sanitizeSchemaForOpenAICompat(schema) {
|
|
84220
84281
|
const stripped = stripSchemaKeywords(schema, OPENAI_INCOMPATIBLE_SCHEMA_KEYWORDS);
|
|
84221
84282
|
if (!isSchemaRecord(stripped)) {
|
|
@@ -85040,6 +85101,51 @@ var init_shim = __esm(() => {
|
|
|
85040
85101
|
init_schema();
|
|
85041
85102
|
});
|
|
85042
85103
|
|
|
85104
|
+
// src/providers/openai/capabilities.ts
|
|
85105
|
+
function supportsReasoningEffort(model) {
|
|
85106
|
+
return /^(o\d|gpt-5|gpt-4\.5)/i.test(model);
|
|
85107
|
+
}
|
|
85108
|
+
function isGeminiLikeModel(model) {
|
|
85109
|
+
const normalized = (model ?? "").trim().toLowerCase();
|
|
85110
|
+
return normalized.startsWith("gemini-") || normalized.includes("/gemini-");
|
|
85111
|
+
}
|
|
85112
|
+
function isGeminiTarget(model) {
|
|
85113
|
+
if (isEnvTruthy(getQueryEnvVar("CLAUDE_CODE_USE_GEMINI")))
|
|
85114
|
+
return true;
|
|
85115
|
+
return isGeminiLikeModel(model);
|
|
85116
|
+
}
|
|
85117
|
+
function supportsParallelToolCalls(model) {
|
|
85118
|
+
return !isGeminiTarget(model);
|
|
85119
|
+
}
|
|
85120
|
+
function getOpenAICompatMaxOutputTokens(model) {
|
|
85121
|
+
const max = getOpenAIMaxOutputTokens(model);
|
|
85122
|
+
if (max === undefined)
|
|
85123
|
+
return null;
|
|
85124
|
+
return { default: max, upperLimit: max };
|
|
85125
|
+
}
|
|
85126
|
+
function getOpenAICompatContextWindow(model) {
|
|
85127
|
+
return getOpenAIContextWindow(model) ?? null;
|
|
85128
|
+
}
|
|
85129
|
+
function openAICompatSupports(feature, model) {
|
|
85130
|
+
if (feature === "reasoning-effort")
|
|
85131
|
+
return supportsReasoningEffort(model);
|
|
85132
|
+
if (feature === "parallel-tool-calls")
|
|
85133
|
+
return supportsParallelToolCalls(model);
|
|
85134
|
+
return FEATURES_OPENAI_COMPAT.includes(feature);
|
|
85135
|
+
}
|
|
85136
|
+
var FEATURES_OPENAI_COMPAT;
|
|
85137
|
+
var init_capabilities2 = __esm(() => {
|
|
85138
|
+
init_openaiContextWindows();
|
|
85139
|
+
init_envUtils();
|
|
85140
|
+
init_state2();
|
|
85141
|
+
FEATURES_OPENAI_COMPAT = Object.freeze([
|
|
85142
|
+
"streaming",
|
|
85143
|
+
"tool-use",
|
|
85144
|
+
"image-input",
|
|
85145
|
+
"system-message-top-level"
|
|
85146
|
+
]);
|
|
85147
|
+
});
|
|
85148
|
+
|
|
85043
85149
|
// src/providers/openai/shim.ts
|
|
85044
85150
|
var exports_shim = {};
|
|
85045
85151
|
__export(exports_shim, {
|
|
@@ -85209,15 +85315,18 @@ function convertMessages(messages, system) {
|
|
|
85209
85315
|
}
|
|
85210
85316
|
}
|
|
85211
85317
|
if (otherContent.length > 0) {
|
|
85212
|
-
|
|
85213
|
-
|
|
85214
|
-
|
|
85215
|
-
|
|
85318
|
+
const converted = convertContentBlocks(otherContent);
|
|
85319
|
+
if (converted !== "") {
|
|
85320
|
+
result.push({
|
|
85321
|
+
role: "user",
|
|
85322
|
+
content: converted
|
|
85323
|
+
});
|
|
85324
|
+
}
|
|
85216
85325
|
}
|
|
85217
85326
|
} else {
|
|
85218
85327
|
result.push({
|
|
85219
85328
|
role: "user",
|
|
85220
|
-
content: convertContentBlocks(content)
|
|
85329
|
+
content: convertContentBlocks(content) || "."
|
|
85221
85330
|
});
|
|
85222
85331
|
}
|
|
85223
85332
|
} else if (role === "assistant") {
|
|
@@ -85229,7 +85338,8 @@ function convertMessages(messages, system) {
|
|
|
85229
85338
|
role: "assistant",
|
|
85230
85339
|
content: (() => {
|
|
85231
85340
|
const c5 = convertContentBlocks(textContent);
|
|
85232
|
-
|
|
85341
|
+
const text = typeof c5 === "string" ? c5 : Array.isArray(c5) ? c5.map((p) => p.text ?? "").join("") : "";
|
|
85342
|
+
return text || null;
|
|
85233
85343
|
})()
|
|
85234
85344
|
};
|
|
85235
85345
|
if (thinkingBlocks.length > 0) {
|
|
@@ -85252,26 +85362,28 @@ function convertMessages(messages, system) {
|
|
|
85252
85362
|
}
|
|
85253
85363
|
result.push(assistantMsg);
|
|
85254
85364
|
} else {
|
|
85365
|
+
const c5 = convertContentBlocks(content);
|
|
85366
|
+
const text = typeof c5 === "string" ? c5 : Array.isArray(c5) ? c5.map((p) => p.text ?? "").join("") : "";
|
|
85255
85367
|
result.push({
|
|
85256
85368
|
role: "assistant",
|
|
85257
|
-
content:
|
|
85258
|
-
const c5 = convertContentBlocks(content);
|
|
85259
|
-
return typeof c5 === "string" ? c5 : Array.isArray(c5) ? c5.map((p) => p.text ?? "").join("") : "";
|
|
85260
|
-
})()
|
|
85369
|
+
content: text || null
|
|
85261
85370
|
});
|
|
85262
85371
|
}
|
|
85263
85372
|
}
|
|
85264
85373
|
}
|
|
85265
85374
|
return result;
|
|
85266
85375
|
}
|
|
85267
|
-
function normalizeSchemaForOpenAI(schema, strict = true, topLevel = true) {
|
|
85268
|
-
|
|
85376
|
+
function normalizeSchemaForOpenAI(schema, strict = true, topLevel = true, geminiTarget = false) {
|
|
85377
|
+
let record2 = sanitizeSchemaForOpenAICompat(schema);
|
|
85378
|
+
if (geminiTarget) {
|
|
85379
|
+
record2 = splitTypeArrayToAnyOf(record2);
|
|
85380
|
+
}
|
|
85269
85381
|
if (record2.type === "object" && record2.properties) {
|
|
85270
85382
|
const properties = record2.properties;
|
|
85271
85383
|
const existingRequired = Array.isArray(record2.required) ? record2.required : [];
|
|
85272
85384
|
const normalizedProps = {};
|
|
85273
85385
|
for (const [key, value] of Object.entries(properties)) {
|
|
85274
|
-
normalizedProps[key] = normalizeSchemaForOpenAI(value, strict, false);
|
|
85386
|
+
normalizedProps[key] = normalizeSchemaForOpenAI(value, strict, false, geminiTarget);
|
|
85275
85387
|
}
|
|
85276
85388
|
record2.properties = normalizedProps;
|
|
85277
85389
|
if (strict) {
|
|
@@ -85279,9 +85391,10 @@ function normalizeSchemaForOpenAI(schema, strict = true, topLevel = true) {
|
|
|
85279
85391
|
record2.required = Array.from(new Set([...existingRequired, ...allKeys]));
|
|
85280
85392
|
record2.additionalProperties = false;
|
|
85281
85393
|
if (topLevel) {
|
|
85394
|
+
const style = geminiTarget ? "nullable" : "union";
|
|
85282
85395
|
for (const key of allKeys) {
|
|
85283
85396
|
if (!existingRequired.includes(key)) {
|
|
85284
|
-
normalizedProps[key] = makeSchemaNullable(normalizedProps[key]);
|
|
85397
|
+
normalizedProps[key] = makeSchemaNullable(normalizedProps[key], style);
|
|
85285
85398
|
}
|
|
85286
85399
|
}
|
|
85287
85400
|
}
|
|
@@ -85291,20 +85404,21 @@ function normalizeSchemaForOpenAI(schema, strict = true, topLevel = true) {
|
|
|
85291
85404
|
}
|
|
85292
85405
|
if ("items" in record2) {
|
|
85293
85406
|
if (Array.isArray(record2.items)) {
|
|
85294
|
-
record2.items = record2.items.map((item) => normalizeSchemaForOpenAI(item, strict, false));
|
|
85407
|
+
record2.items = record2.items.map((item) => normalizeSchemaForOpenAI(item, strict, false, geminiTarget));
|
|
85295
85408
|
} else {
|
|
85296
|
-
record2.items = normalizeSchemaForOpenAI(record2.items, strict, false);
|
|
85409
|
+
record2.items = normalizeSchemaForOpenAI(record2.items, strict, false, geminiTarget);
|
|
85297
85410
|
}
|
|
85298
85411
|
}
|
|
85299
85412
|
for (const key of ["anyOf", "oneOf", "allOf"]) {
|
|
85300
85413
|
if (key in record2 && Array.isArray(record2[key])) {
|
|
85301
|
-
record2[key] = record2[key].map((item) => normalizeSchemaForOpenAI(item, strict, false));
|
|
85414
|
+
record2[key] = record2[key].map((item) => normalizeSchemaForOpenAI(item, strict, false, geminiTarget));
|
|
85302
85415
|
}
|
|
85303
85416
|
}
|
|
85304
85417
|
return record2;
|
|
85305
85418
|
}
|
|
85306
|
-
function convertTools(tools) {
|
|
85419
|
+
function convertTools(tools, model = "") {
|
|
85307
85420
|
const isGemini = isEnvTruthy(getQueryEnvVar("CLAUDE_CODE_USE_GEMINI"));
|
|
85421
|
+
const geminiTarget = isGeminiTarget(model);
|
|
85308
85422
|
return tools.filter((t) => t.name !== "ToolSearchTool").map((t) => {
|
|
85309
85423
|
const schema = { ...t.input_schema ?? { type: "object", properties: {} } };
|
|
85310
85424
|
if (t.name === "Agent" && schema.properties) {
|
|
@@ -85322,7 +85436,7 @@ function convertTools(tools) {
|
|
|
85322
85436
|
function: {
|
|
85323
85437
|
name: t.name,
|
|
85324
85438
|
description: t.description ?? "",
|
|
85325
|
-
parameters: normalizeSchemaForOpenAI(schema, !isGemini)
|
|
85439
|
+
parameters: normalizeSchemaForOpenAI(schema, !isGemini, true, geminiTarget)
|
|
85326
85440
|
}
|
|
85327
85441
|
};
|
|
85328
85442
|
});
|
|
@@ -85343,8 +85457,63 @@ function convertChunkUsage(usage) {
|
|
|
85343
85457
|
function toOpenAIChatReasoningEffort(effort) {
|
|
85344
85458
|
return effort === "xhigh" ? "high" : effort;
|
|
85345
85459
|
}
|
|
85460
|
+
function getOpenAIChatProviderCapabilities(model) {
|
|
85461
|
+
return {
|
|
85462
|
+
supportsParallelToolCalls: openAICompatSupports("parallel-tool-calls", model)
|
|
85463
|
+
};
|
|
85464
|
+
}
|
|
85465
|
+
function collectAdjacentToolMessages(messages, startIndex) {
|
|
85466
|
+
const toolMessages = [];
|
|
85467
|
+
for (let i2 = startIndex;i2 < messages.length && messages[i2]?.role === "tool"; i2++) {
|
|
85468
|
+
toolMessages.push(messages[i2]);
|
|
85469
|
+
}
|
|
85470
|
+
return toolMessages;
|
|
85471
|
+
}
|
|
85472
|
+
function indexToolMessagesById(toolMessages) {
|
|
85473
|
+
const byId = new Map;
|
|
85474
|
+
for (const toolMessage of toolMessages) {
|
|
85475
|
+
if (typeof toolMessage.tool_call_id === "string") {
|
|
85476
|
+
byId.set(toolMessage.tool_call_id, toolMessage);
|
|
85477
|
+
}
|
|
85478
|
+
}
|
|
85479
|
+
return byId;
|
|
85480
|
+
}
|
|
85481
|
+
function splitParallelToolCallTurn(assistantMessage, toolCalls, toolMessagesById) {
|
|
85482
|
+
const serialized = [];
|
|
85483
|
+
toolCalls.forEach((toolCall, index) => {
|
|
85484
|
+
serialized.push({
|
|
85485
|
+
...assistantMessage,
|
|
85486
|
+
tool_calls: [toolCall],
|
|
85487
|
+
content: index === 0 ? assistantMessage.content : null
|
|
85488
|
+
});
|
|
85489
|
+
const toolResponse = toolMessagesById.get(toolCall.id);
|
|
85490
|
+
if (toolResponse)
|
|
85491
|
+
serialized.push(toolResponse);
|
|
85492
|
+
});
|
|
85493
|
+
return serialized;
|
|
85494
|
+
}
|
|
85495
|
+
function serializeParallelToolCalls(messages, capabilities) {
|
|
85496
|
+
if (capabilities.supportsParallelToolCalls)
|
|
85497
|
+
return messages;
|
|
85498
|
+
const result = [];
|
|
85499
|
+
for (let i2 = 0;i2 < messages.length; i2++) {
|
|
85500
|
+
const message = messages[i2];
|
|
85501
|
+
const toolCalls = message.tool_calls;
|
|
85502
|
+
const isParallelToolTurn = message.role === "assistant" && (toolCalls?.length ?? 0) > 1;
|
|
85503
|
+
if (!isParallelToolTurn || !toolCalls) {
|
|
85504
|
+
result.push(message);
|
|
85505
|
+
continue;
|
|
85506
|
+
}
|
|
85507
|
+
const toolMessages = collectAdjacentToolMessages(messages, i2 + 1);
|
|
85508
|
+
const toolMessagesById = indexToolMessagesById(toolMessages);
|
|
85509
|
+
result.push(...splitParallelToolCallTurn(message, toolCalls, toolMessagesById));
|
|
85510
|
+
i2 += toolMessages.length;
|
|
85511
|
+
}
|
|
85512
|
+
return result;
|
|
85513
|
+
}
|
|
85346
85514
|
function buildOpenAIRequestBody(params, ctx) {
|
|
85347
|
-
const
|
|
85515
|
+
const capabilities = getOpenAIChatProviderCapabilities(ctx.resolvedModel);
|
|
85516
|
+
const openaiMessages = serializeParallelToolCalls(convertMessages(params.messages, params.system), capabilities);
|
|
85348
85517
|
const body = {
|
|
85349
85518
|
model: ctx.resolvedModel,
|
|
85350
85519
|
messages: openaiMessages,
|
|
@@ -85372,9 +85541,12 @@ function buildOpenAIRequestBody(params, ctx) {
|
|
|
85372
85541
|
body.reasoning_effort = toOpenAIChatReasoningEffort(ctx.reasoning.effort);
|
|
85373
85542
|
}
|
|
85374
85543
|
if (params.tools && params.tools.length > 0) {
|
|
85375
|
-
const converted = convertTools(params.tools);
|
|
85544
|
+
const converted = convertTools(params.tools, ctx.resolvedModel);
|
|
85376
85545
|
if (converted.length > 0) {
|
|
85377
85546
|
body.tools = converted;
|
|
85547
|
+
if (!capabilities.supportsParallelToolCalls) {
|
|
85548
|
+
body.parallel_tool_calls = false;
|
|
85549
|
+
}
|
|
85378
85550
|
if (params.tool_choice) {
|
|
85379
85551
|
const tc = params.tool_choice;
|
|
85380
85552
|
if (tc.type === "auto") {
|
|
@@ -85470,7 +85642,13 @@ async function* openaiStreamToAnthropic(response, model) {
|
|
|
85470
85642
|
})}`);
|
|
85471
85643
|
}
|
|
85472
85644
|
}
|
|
85473
|
-
|
|
85645
|
+
let reasoningText = delta.reasoning_content ?? delta.reasoning;
|
|
85646
|
+
if (reasoningText == null && Array.isArray(delta.reasoning_details)) {
|
|
85647
|
+
const parts = delta.reasoning_details.map((d) => d.content ?? d.summary ?? "").filter(Boolean);
|
|
85648
|
+
if (parts.length > 0)
|
|
85649
|
+
reasoningText = parts.join("");
|
|
85650
|
+
}
|
|
85651
|
+
if (reasoningText != null) {
|
|
85474
85652
|
if (reasoningBlockIndex === null) {
|
|
85475
85653
|
reasoningBlockIndex = contentBlockIndex;
|
|
85476
85654
|
contentBlockIndex++;
|
|
@@ -85492,7 +85670,7 @@ async function* openaiStreamToAnthropic(response, model) {
|
|
|
85492
85670
|
index: reasoningBlockIndex,
|
|
85493
85671
|
delta: {
|
|
85494
85672
|
type: "thinking_delta",
|
|
85495
|
-
thinking:
|
|
85673
|
+
thinking: reasoningText
|
|
85496
85674
|
}
|
|
85497
85675
|
};
|
|
85498
85676
|
continue;
|
|
@@ -85855,6 +86033,22 @@ class OpenAIShimMessages {
|
|
|
85855
86033
|
function convertOpenAIResponseToAnthropic(data, model) {
|
|
85856
86034
|
const choice = data.choices?.[0];
|
|
85857
86035
|
const content = [];
|
|
86036
|
+
const msg = choice?.message;
|
|
86037
|
+
let reasoningText = msg?.reasoning_content ?? msg?.reasoning;
|
|
86038
|
+
if (reasoningText == null && Array.isArray(msg?.reasoning_details)) {
|
|
86039
|
+
const parts = msg.reasoning_details.map((d) => d.content ?? d.summary ?? "").filter(Boolean);
|
|
86040
|
+
if (parts.length > 0)
|
|
86041
|
+
reasoningText = parts.join(`
|
|
86042
|
+
`);
|
|
86043
|
+
}
|
|
86044
|
+
if (typeof reasoningText === "string" && reasoningText) {
|
|
86045
|
+
content.push({
|
|
86046
|
+
type: "thinking",
|
|
86047
|
+
thinking: reasoningText,
|
|
86048
|
+
signature: "",
|
|
86049
|
+
extra_content: { provenance: "openai-chat" }
|
|
86050
|
+
});
|
|
86051
|
+
}
|
|
85858
86052
|
const rawContent = choice?.message?.content;
|
|
85859
86053
|
if (typeof rawContent === "string" && rawContent) {
|
|
85860
86054
|
content.push({ type: "text", text: rawContent });
|
|
@@ -85958,6 +86152,7 @@ var init_shim2 = __esm(() => {
|
|
|
85958
86152
|
init_config3();
|
|
85959
86153
|
init_schemaSanitizer();
|
|
85960
86154
|
init_providerProfile();
|
|
86155
|
+
init_capabilities2();
|
|
85961
86156
|
OpenAIShimStream = class OpenAIShimStream {
|
|
85962
86157
|
generator;
|
|
85963
86158
|
controller = new AbortController;
|
|
@@ -86230,36 +86425,6 @@ var init_anthropic = __esm(() => {
|
|
|
86230
86425
|
init_errors5();
|
|
86231
86426
|
});
|
|
86232
86427
|
|
|
86233
|
-
// src/providers/openai/capabilities.ts
|
|
86234
|
-
function supportsReasoningEffort(model) {
|
|
86235
|
-
return /^(o\d|gpt-5|gpt-4\.5)/i.test(model);
|
|
86236
|
-
}
|
|
86237
|
-
function getOpenAICompatMaxOutputTokens(model) {
|
|
86238
|
-
const max = getOpenAIMaxOutputTokens(model);
|
|
86239
|
-
if (max === undefined)
|
|
86240
|
-
return null;
|
|
86241
|
-
return { default: max, upperLimit: max };
|
|
86242
|
-
}
|
|
86243
|
-
function getOpenAICompatContextWindow(model) {
|
|
86244
|
-
return getOpenAIContextWindow(model) ?? null;
|
|
86245
|
-
}
|
|
86246
|
-
function openAICompatSupports(feature, model) {
|
|
86247
|
-
if (feature === "reasoning-effort")
|
|
86248
|
-
return supportsReasoningEffort(model);
|
|
86249
|
-
return FEATURES_OPENAI_COMPAT.includes(feature);
|
|
86250
|
-
}
|
|
86251
|
-
var FEATURES_OPENAI_COMPAT;
|
|
86252
|
-
var init_capabilities2 = __esm(() => {
|
|
86253
|
-
init_openaiContextWindows();
|
|
86254
|
-
FEATURES_OPENAI_COMPAT = Object.freeze([
|
|
86255
|
-
"streaming",
|
|
86256
|
-
"tool-use",
|
|
86257
|
-
"image-input",
|
|
86258
|
-
"parallel-tool-calls",
|
|
86259
|
-
"system-message-top-level"
|
|
86260
|
-
]);
|
|
86261
|
-
});
|
|
86262
|
-
|
|
86263
86428
|
// src/providers/openai/errors.ts
|
|
86264
86429
|
function readErrorMessage(body) {
|
|
86265
86430
|
if (!body || typeof body !== "object")
|
|
@@ -94201,7 +94366,7 @@ function printStartupScreen() {
|
|
|
94201
94366
|
const sLen = ` ● ${sL} Ready — type /help to begin`.length;
|
|
94202
94367
|
out.push(boxRow(sRow, W2, sLen));
|
|
94203
94368
|
out.push(`${rgb(...BORDER)}╚${"═".repeat(W2 - 2)}╝${RESET}`);
|
|
94204
|
-
out.push(` ${DIM}${rgb(...DIMCOL)}opencow ${RESET}${rgb(...ACCENT)}v${"0.4.
|
|
94369
|
+
out.push(` ${DIM}${rgb(...DIMCOL)}opencow ${RESET}${rgb(...ACCENT)}v${"0.4.4"}${RESET}`);
|
|
94205
94370
|
out.push("");
|
|
94206
94371
|
process.stdout.write(out.join(`
|
|
94207
94372
|
`) + `
|
|
@@ -95356,10 +95521,10 @@ function getCLISyspromptPrefix(options) {
|
|
|
95356
95521
|
return DEFAULT_PREFIX;
|
|
95357
95522
|
}
|
|
95358
95523
|
function isAttributionHeaderEnabled() {
|
|
95359
|
-
if (
|
|
95360
|
-
return
|
|
95524
|
+
if (isEnvTruthy(resolveEnvVar("ATTRIBUTION_HEADER"))) {
|
|
95525
|
+
return true;
|
|
95361
95526
|
}
|
|
95362
|
-
return getFeatureValue_CACHED_MAY_BE_STALE("tengu_attribution_header",
|
|
95527
|
+
return getFeatureValue_CACHED_MAY_BE_STALE("tengu_attribution_header", false);
|
|
95363
95528
|
}
|
|
95364
95529
|
function getAttributionHeader(fingerprint) {
|
|
95365
95530
|
if (!isAttributionHeaderEnabled()) {
|
|
@@ -95370,7 +95535,7 @@ function getAttributionHeader(fingerprint) {
|
|
|
95370
95535
|
const cch = "";
|
|
95371
95536
|
const workload = getWorkload();
|
|
95372
95537
|
const workloadPair = workload ? ` cc_workload=${workload};` : "";
|
|
95373
|
-
const header = `x-
|
|
95538
|
+
const header = `x-opencow-billing-header: cc_version=${version2}; cc_entrypoint=${entrypoint};${cch}${workloadPair}`;
|
|
95374
95539
|
logForDebugging2(`attribution header ${header}`);
|
|
95375
95540
|
return header;
|
|
95376
95541
|
}
|
|
@@ -106296,7 +106461,7 @@ function getInitialAdvisorSetting() {
|
|
|
106296
106461
|
return getInitialSettings().advisorModel;
|
|
106297
106462
|
}
|
|
106298
106463
|
function getAdvisorUsage(usage) {
|
|
106299
|
-
const iterations = usage
|
|
106464
|
+
const iterations = usage?.iterations;
|
|
106300
106465
|
if (!iterations) {
|
|
106301
106466
|
return [];
|
|
106302
106467
|
}
|
|
@@ -106454,11 +106619,11 @@ function addToTotalModelUsage(cost, usage, model) {
|
|
|
106454
106619
|
contextWindow: 0,
|
|
106455
106620
|
maxOutputTokens: 0
|
|
106456
106621
|
};
|
|
106457
|
-
modelUsage.inputTokens += usage
|
|
106458
|
-
modelUsage.outputTokens += usage
|
|
106459
|
-
modelUsage.cacheReadInputTokens += usage
|
|
106460
|
-
modelUsage.cacheCreationInputTokens += usage
|
|
106461
|
-
modelUsage.webSearchRequests += usage
|
|
106622
|
+
modelUsage.inputTokens += usage?.input_tokens ?? 0;
|
|
106623
|
+
modelUsage.outputTokens += usage?.output_tokens ?? 0;
|
|
106624
|
+
modelUsage.cacheReadInputTokens += usage?.cache_read_input_tokens ?? 0;
|
|
106625
|
+
modelUsage.cacheCreationInputTokens += usage?.cache_creation_input_tokens ?? 0;
|
|
106626
|
+
modelUsage.webSearchRequests += usage?.server_tool_use?.web_search_requests ?? 0;
|
|
106462
106627
|
modelUsage.costUSD += cost;
|
|
106463
106628
|
modelUsage.contextWindow = getContextWindowForModel(model, getSdkBetas());
|
|
106464
106629
|
modelUsage.maxOutputTokens = getModelMaxOutputTokens(model).default;
|
|
@@ -106467,15 +106632,18 @@ function addToTotalModelUsage(cost, usage, model) {
|
|
|
106467
106632
|
function addToTotalSessionCost(cost, usage, model) {
|
|
106468
106633
|
const modelUsage = addToTotalModelUsage(cost, usage, model);
|
|
106469
106634
|
addToTotalCostState(cost, modelUsage, model);
|
|
106470
|
-
const attrs = isFastModeEnabled() && usage
|
|
106635
|
+
const attrs = isFastModeEnabled() && usage?.speed === "fast" ? { model, speed: "fast" } : { model };
|
|
106471
106636
|
getCostCounter()?.add(cost, attrs);
|
|
106472
|
-
getTokenCounter()?.add(usage
|
|
106473
|
-
getTokenCounter()?.add(usage
|
|
106474
|
-
|
|
106637
|
+
getTokenCounter()?.add(usage?.input_tokens ?? 0, { ...attrs, type: "input" });
|
|
106638
|
+
getTokenCounter()?.add(usage?.output_tokens ?? 0, {
|
|
106639
|
+
...attrs,
|
|
106640
|
+
type: "output"
|
|
106641
|
+
});
|
|
106642
|
+
getTokenCounter()?.add(usage?.cache_read_input_tokens ?? 0, {
|
|
106475
106643
|
...attrs,
|
|
106476
106644
|
type: "cacheRead"
|
|
106477
106645
|
});
|
|
106478
|
-
getTokenCounter()?.add(usage
|
|
106646
|
+
getTokenCounter()?.add(usage?.cache_creation_input_tokens ?? 0, {
|
|
106479
106647
|
...attrs,
|
|
106480
106648
|
type: "cacheCreation"
|
|
106481
106649
|
});
|
|
@@ -243992,7 +244160,7 @@ function getAnthropicEnvMetadata() {
|
|
|
243992
244160
|
function getBuildAgeMinutes() {
|
|
243993
244161
|
if (false)
|
|
243994
244162
|
;
|
|
243995
|
-
const buildTime = new Date("2026-
|
|
244163
|
+
const buildTime = new Date("2026-06-03T08:42:39.310Z").getTime();
|
|
243996
244164
|
if (isNaN(buildTime))
|
|
243997
244165
|
return;
|
|
243998
244166
|
return Math.floor((Date.now() - buildTime) / 60000);
|
|
@@ -306219,7 +306387,7 @@ function splitSysPromptPrefix(systemPrompt, options2) {
|
|
|
306219
306387
|
continue;
|
|
306220
306388
|
if (prompt === SYSTEM_PROMPT_DYNAMIC_BOUNDARY)
|
|
306221
306389
|
continue;
|
|
306222
|
-
if (prompt.startsWith("x-
|
|
306390
|
+
if (prompt.startsWith("x-opencow-billing-header")) {
|
|
306223
306391
|
attributionHeader2 = prompt;
|
|
306224
306392
|
} else if (CLI_SYSPROMPT_PREFIXES.has(prompt)) {
|
|
306225
306393
|
systemPromptPrefix2 = prompt;
|
|
@@ -306253,7 +306421,7 @@ function splitSysPromptPrefix(systemPrompt, options2) {
|
|
|
306253
306421
|
const block2 = systemPrompt[i3];
|
|
306254
306422
|
if (!block2 || block2 === SYSTEM_PROMPT_DYNAMIC_BOUNDARY)
|
|
306255
306423
|
continue;
|
|
306256
|
-
if (block2.startsWith("x-
|
|
306424
|
+
if (block2.startsWith("x-opencow-billing-header")) {
|
|
306257
306425
|
attributionHeader2 = block2;
|
|
306258
306426
|
} else if (CLI_SYSPROMPT_PREFIXES.has(block2)) {
|
|
306259
306427
|
systemPromptPrefix2 = block2;
|
|
@@ -306296,7 +306464,7 @@ function splitSysPromptPrefix(systemPrompt, options2) {
|
|
|
306296
306464
|
for (const block2 of systemPrompt) {
|
|
306297
306465
|
if (!block2)
|
|
306298
306466
|
continue;
|
|
306299
|
-
if (block2.startsWith("x-
|
|
306467
|
+
if (block2.startsWith("x-opencow-billing-header")) {
|
|
306300
306468
|
attributionHeader = block2;
|
|
306301
306469
|
} else if (CLI_SYSPROMPT_PREFIXES.has(block2)) {
|
|
306302
306470
|
systemPromptPrefix = block2;
|
|
@@ -479131,7 +479299,7 @@ function buildPrimarySection() {
|
|
|
479131
479299
|
}, undefined, false, undefined, this);
|
|
479132
479300
|
return [{
|
|
479133
479301
|
label: "Version",
|
|
479134
|
-
value: "0.4.
|
|
479302
|
+
value: "0.4.4"
|
|
479135
479303
|
}, {
|
|
479136
479304
|
label: "Session name",
|
|
479137
479305
|
value: nameValue
|
|
@@ -535449,7 +535617,7 @@ var init_bridge_kick = __esm(() => {
|
|
|
535449
535617
|
var call58 = async () => {
|
|
535450
535618
|
return {
|
|
535451
535619
|
type: "text",
|
|
535452
|
-
value: `${"99.0.0"} (built ${"2026-
|
|
535620
|
+
value: `${"99.0.0"} (built ${"2026-06-03T08:42:39.310Z"})`
|
|
535453
535621
|
};
|
|
535454
535622
|
}, version2, version_default;
|
|
535455
535623
|
var init_version = __esm(() => {
|
|
@@ -557559,7 +557727,7 @@ function WelcomeV2() {
|
|
|
557559
557727
|
dimColor: true,
|
|
557560
557728
|
children: [
|
|
557561
557729
|
"v",
|
|
557562
|
-
"0.4.
|
|
557730
|
+
"0.4.4",
|
|
557563
557731
|
" "
|
|
557564
557732
|
]
|
|
557565
557733
|
}, undefined, true, undefined, this)
|
|
@@ -557759,7 +557927,7 @@ function WelcomeV2() {
|
|
|
557759
557927
|
dimColor: true,
|
|
557760
557928
|
children: [
|
|
557761
557929
|
"v",
|
|
557762
|
-
"0.4.
|
|
557930
|
+
"0.4.4",
|
|
557763
557931
|
" "
|
|
557764
557932
|
]
|
|
557765
557933
|
}, undefined, true, undefined, this)
|
|
@@ -557985,7 +558153,7 @@ function AppleTerminalWelcomeV2(t0) {
|
|
|
557985
558153
|
dimColor: true,
|
|
557986
558154
|
children: [
|
|
557987
558155
|
"v",
|
|
557988
|
-
"0.4.
|
|
558156
|
+
"0.4.4",
|
|
557989
558157
|
" "
|
|
557990
558158
|
]
|
|
557991
558159
|
}, undefined, true, undefined, this);
|
|
@@ -558239,7 +558407,7 @@ function AppleTerminalWelcomeV2(t0) {
|
|
|
558239
558407
|
dimColor: true,
|
|
558240
558408
|
children: [
|
|
558241
558409
|
"v",
|
|
558242
|
-
"0.4.
|
|
558410
|
+
"0.4.4",
|
|
558243
558411
|
" "
|
|
558244
558412
|
]
|
|
558245
558413
|
}, undefined, true, undefined, this);
|
|
@@ -579085,7 +579253,7 @@ Usage: claude --remote "your task description"`, () => gracefulShutdown(1));
|
|
|
579085
579253
|
pendingHookMessages
|
|
579086
579254
|
}, renderAndRun);
|
|
579087
579255
|
}
|
|
579088
|
-
}).version("0.4.
|
|
579256
|
+
}).version("0.4.4 (OpenCow)", "-v, --version", "Output the version number");
|
|
579089
579257
|
program2.option("-w, --worktree [name]", "Create a new git worktree for this session (optionally specify a name)");
|
|
579090
579258
|
program2.option("--tmux", "Create a tmux session for the worktree (requires --worktree). Uses iTerm2 native panes when available; use --tmux=classic for traditional tmux.");
|
|
579091
579259
|
if (canUserConfigureAdvisor()) {
|
|
@@ -579731,7 +579899,7 @@ if (false) {}
|
|
|
579731
579899
|
async function main2() {
|
|
579732
579900
|
const args = process.argv.slice(2);
|
|
579733
579901
|
if (args.length === 1 && (args[0] === "--version" || args[0] === "-v" || args[0] === "-V")) {
|
|
579734
|
-
console.log(`${"0.4.
|
|
579902
|
+
console.log(`${"0.4.4"} (OpenCow)`);
|
|
579735
579903
|
return;
|
|
579736
579904
|
}
|
|
579737
579905
|
if (args.includes("--provider")) {
|
|
@@ -579849,4 +580017,4 @@ async function main2() {
|
|
|
579849
580017
|
}
|
|
579850
580018
|
main2();
|
|
579851
580019
|
|
|
579852
|
-
//# debugId=
|
|
580020
|
+
//# debugId=BECBE1E77E67BFDB64756E2164756E21
|