opencode-anthropic-multi-account 0.2.40 → 0.2.42
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/README.md +3 -1
- package/dist/{chunk-YH55ZRXQ.js → chunk-7MZVOHO3.js} +4 -4
- package/dist/{chunk-YH55ZRXQ.js.map → chunk-7MZVOHO3.js.map} +1 -1
- package/dist/fingerprint-capture.d.ts +1 -1
- package/dist/fingerprint-capture.js +1 -1
- package/dist/index.js +55 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
showToast,
|
|
26
26
|
sleep,
|
|
27
27
|
updateConfigField
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-7MZVOHO3.js";
|
|
29
29
|
import "./chunk-QDWAW66H.js";
|
|
30
30
|
|
|
31
31
|
// ../providers/claude-code/src/opencode-shared.ts
|
|
@@ -1239,7 +1239,7 @@ If the result says the push wasn't sent, that's expected \u2014 no action needed
|
|
|
1239
1239
|
"Write"
|
|
1240
1240
|
],
|
|
1241
1241
|
anthropic_beta: "claude-code-20250219,oauth-2025-04-20,context-1m-2025-08-07,interleaved-thinking-2025-05-14,thinking-token-count-2026-05-13,context-management-2025-06-27,prompt-caching-scope-2026-01-05,mid-conversation-system-2026-04-07,advisor-tool-2026-03-01,effort-2025-11-24,extended-cache-ttl-2025-04-11",
|
|
1242
|
-
cc_version: "2.1.
|
|
1242
|
+
cc_version: "2.1.159",
|
|
1243
1243
|
header_order: [
|
|
1244
1244
|
"Accept",
|
|
1245
1245
|
"Authorization",
|
|
@@ -1269,7 +1269,7 @@ If the result says the push wasn't sent, that's expected \u2014 no action needed
|
|
|
1269
1269
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
1270
1270
|
"anthropic-version": "2023-06-01",
|
|
1271
1271
|
"content-type": "application/json",
|
|
1272
|
-
"user-agent": "claude-cli/2.1.
|
|
1272
|
+
"user-agent": "claude-cli/2.1.159 (external, sdk-cli)",
|
|
1273
1273
|
"x-app": "cli",
|
|
1274
1274
|
"x-stainless-timeout": "600"
|
|
1275
1275
|
},
|
|
@@ -3409,6 +3409,7 @@ var SESSION_IDLE_ROTATE_MS = 15 * 60 * 1e3;
|
|
|
3409
3409
|
var DEFAULT_CONTEXT_MANAGEMENT = {};
|
|
3410
3410
|
var DEFAULT_OUTPUT_EFFORT = "high";
|
|
3411
3411
|
var VALID_OUTPUT_EFFORT_VALUES = /* @__PURE__ */ new Set(["low", "medium", "high", "xhigh", "ultracode", "max", "client"]);
|
|
3412
|
+
var OPENCODE_OUTPUT_EFFORT_HEADER = "x-kyoli-opencode-effort";
|
|
3412
3413
|
var upstreamRequestTestOverrides = {};
|
|
3413
3414
|
var sessionId = randomUUID4();
|
|
3414
3415
|
var sessionLastUsed = 0;
|
|
@@ -3439,9 +3440,25 @@ function readOutputEffortValue(value) {
|
|
|
3439
3440
|
const normalized = readString(value)?.toLowerCase();
|
|
3440
3441
|
return normalized && VALID_OUTPUT_EFFORT_VALUES.has(normalized) ? normalized : void 0;
|
|
3441
3442
|
}
|
|
3443
|
+
function readOpenCodeVariantEffort(value) {
|
|
3444
|
+
const normalized = readString(value)?.toLowerCase();
|
|
3445
|
+
if (normalized === "minimal") return "low";
|
|
3446
|
+
return readOutputEffortValue(normalized);
|
|
3447
|
+
}
|
|
3442
3448
|
function normalizeEffortForWire(effort) {
|
|
3443
3449
|
return effort === "ultracode" ? "xhigh" : effort;
|
|
3444
3450
|
}
|
|
3451
|
+
function readPositiveNumber(value) {
|
|
3452
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
|
|
3453
|
+
}
|
|
3454
|
+
function effortFromThinkingBudget(thinking) {
|
|
3455
|
+
const budgetTokens = readPositiveNumber(thinking?.budget_tokens) ?? readPositiveNumber(thinking?.budgetTokens);
|
|
3456
|
+
if (budgetTokens === void 0) return void 0;
|
|
3457
|
+
if (budgetTokens >= 31999) return "max";
|
|
3458
|
+
if (budgetTokens >= 16e3) return "high";
|
|
3459
|
+
if (budgetTokens >= 8e3) return "medium";
|
|
3460
|
+
return "low";
|
|
3461
|
+
}
|
|
3445
3462
|
function getConfiguredOutputEffort() {
|
|
3446
3463
|
return upstreamRequestTestOverrides.outputEffort ?? readOutputEffortValue(process.env.CLAUDE_MULTI_ACCOUNT_EFFORT) ?? readOutputEffortValue(process.env.ANTHROPIC_MULTI_ACCOUNT_EFFORT);
|
|
3447
3464
|
}
|
|
@@ -3449,7 +3466,7 @@ function getClientOutputEffort(inputBody) {
|
|
|
3449
3466
|
const outputConfig = isRecord3(inputBody.output_config) ? inputBody.output_config : void 0;
|
|
3450
3467
|
const reasoning = isRecord3(inputBody.reasoning) ? inputBody.reasoning : void 0;
|
|
3451
3468
|
const thinking = isRecord3(inputBody.thinking) ? inputBody.thinking : void 0;
|
|
3452
|
-
return readOutputEffortValue(outputConfig?.effort) ?? readOutputEffortValue(reasoning?.effort) ?? readOutputEffortValue(inputBody.reasoning_effort) ?? readOutputEffortValue(inputBody.reasoningEffort) ?? readOutputEffortValue(thinking?.effort);
|
|
3469
|
+
return readOutputEffortValue(outputConfig?.effort) ?? readOutputEffortValue(inputBody.effort) ?? readOutputEffortValue(reasoning?.effort) ?? readOutputEffortValue(inputBody.reasoning_effort) ?? readOutputEffortValue(inputBody.reasoningEffort) ?? readOutputEffortValue(thinking?.effort) ?? effortFromThinkingBudget(thinking);
|
|
3453
3470
|
}
|
|
3454
3471
|
function resolveOutputEffort(inputBody, configuredEffort = getConfiguredOutputEffort()) {
|
|
3455
3472
|
if (configuredEffort && configuredEffort !== "client") {
|
|
@@ -3577,6 +3594,7 @@ function remapSseLine(line, reverseLookup) {
|
|
|
3577
3594
|
function buildUpstreamRequest(inputBody, identity, template2, options) {
|
|
3578
3595
|
const { body, firstUserMessage, systemTexts } = normalizeAnthropicClientRequest(inputBody);
|
|
3579
3596
|
const activeSessionId = options?.sessionId ?? getActiveSessionId();
|
|
3597
|
+
const configuredEffort = getConfiguredOutputEffort() ?? options?.outputEffort;
|
|
3580
3598
|
const incomingTools = Array.isArray(body.tools) ? body.tools : [];
|
|
3581
3599
|
body.tools = selectOpenCodeNativeTools({
|
|
3582
3600
|
incomingTools,
|
|
@@ -3588,7 +3606,7 @@ function buildUpstreamRequest(inputBody, identity, template2, options) {
|
|
|
3588
3606
|
body.context_management = DEFAULT_CONTEXT_MANAGEMENT;
|
|
3589
3607
|
}
|
|
3590
3608
|
if (modelId && !isHaikuModel(modelId)) {
|
|
3591
|
-
body.output_config = { effort: resolveOutputEffort(inputBody) };
|
|
3609
|
+
body.output_config = { effort: resolveOutputEffort(inputBody, configuredEffort) };
|
|
3592
3610
|
}
|
|
3593
3611
|
body.max_tokens = resolveMaxTokens(body.max_tokens);
|
|
3594
3612
|
return applyClaudeCodeUpstreamBodyFields(body, {
|
|
@@ -4068,6 +4086,9 @@ function extractIncomingHeaders(input, init) {
|
|
|
4068
4086
|
function isRecord5(value) {
|
|
4069
4087
|
return typeof value === "object" && value !== null;
|
|
4070
4088
|
}
|
|
4089
|
+
function readHeaderOutputEffort(headers) {
|
|
4090
|
+
return readOpenCodeVariantEffort(headers[OPENCODE_OUTPUT_EFFORT_HEADER]);
|
|
4091
|
+
}
|
|
4071
4092
|
function messageHasToolUse(message) {
|
|
4072
4093
|
return Array.isArray(message.content) && message.content.some((block) => isRecord5(block) && block.type === "tool_use");
|
|
4073
4094
|
}
|
|
@@ -4115,7 +4136,7 @@ function excludeBetas(values, excludedBetas2) {
|
|
|
4115
4136
|
}
|
|
4116
4137
|
return values.filter((beta) => !excludedBetas2.has(beta));
|
|
4117
4138
|
}
|
|
4118
|
-
function transformBodyToUpstream(body, identity, sessionId2) {
|
|
4139
|
+
function transformBodyToUpstream(body, identity, sessionId2, outputEffort) {
|
|
4119
4140
|
try {
|
|
4120
4141
|
const parsed = JSON.parse(body);
|
|
4121
4142
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
@@ -4126,7 +4147,7 @@ function transformBodyToUpstream(body, identity, sessionId2) {
|
|
|
4126
4147
|
parsed,
|
|
4127
4148
|
identity,
|
|
4128
4149
|
template2,
|
|
4129
|
-
{ sessionId: sessionId2 }
|
|
4150
|
+
{ sessionId: sessionId2, outputEffort }
|
|
4130
4151
|
);
|
|
4131
4152
|
const validationError = getDanglingToolUseError(
|
|
4132
4153
|
Array.isArray(upstreamRequest.messages) ? upstreamRequest.messages : []
|
|
@@ -4279,6 +4300,8 @@ var AccountRuntimeFactory = class {
|
|
|
4279
4300
|
const excludedBetas2 = getExcludedBetas(modelId);
|
|
4280
4301
|
const incomingHeaders = extractIncomingHeaders(transformedInput, init);
|
|
4281
4302
|
const sessionId2 = incomingHeaders["x-claude-code-session-id"] ?? getUpstreamSessionId();
|
|
4303
|
+
const outputEffort = readHeaderOutputEffort(incomingHeaders);
|
|
4304
|
+
delete incomingHeaders[OPENCODE_OUTPUT_EFFORT_HEADER];
|
|
4282
4305
|
const headers = this.buildOutboundHeaders(
|
|
4283
4306
|
incomingHeaders,
|
|
4284
4307
|
sessionId2,
|
|
@@ -4290,7 +4313,7 @@ var AccountRuntimeFactory = class {
|
|
|
4290
4313
|
void recordObservedToolNames(extractToolNamesFromRequestBody(init.body)).catch(() => {
|
|
4291
4314
|
});
|
|
4292
4315
|
}
|
|
4293
|
-
const transformedRequest = typeof init?.body === "string" ? transformBodyToUpstream(init.body, identity, sessionId2) : { body: init?.body, reverseLookup: /* @__PURE__ */ new Map(), validationError: null };
|
|
4316
|
+
const transformedRequest = typeof init?.body === "string" ? transformBodyToUpstream(init.body, identity, sessionId2, outputEffort) : { body: init?.body, reverseLookup: /* @__PURE__ */ new Map(), validationError: null };
|
|
4294
4317
|
if (transformedRequest.validationError) {
|
|
4295
4318
|
return new Response(JSON.stringify({
|
|
4296
4319
|
error: {
|
|
@@ -4523,6 +4546,12 @@ function applyOrderedHeaders(output, headers) {
|
|
|
4523
4546
|
const orderedHeaders = orderHeadersForOutbound(headers);
|
|
4524
4547
|
output.headers = Array.isArray(orderedHeaders) ? Object.fromEntries(orderedHeaders) : orderedHeaders;
|
|
4525
4548
|
}
|
|
4549
|
+
function getMessageVariant(input) {
|
|
4550
|
+
return input.message?.model?.variant;
|
|
4551
|
+
}
|
|
4552
|
+
function isAnthropicChatHook(input) {
|
|
4553
|
+
return input.provider?.info?.id === ANTHROPIC_OAUTH_ADAPTER.authProviderId || input.model?.providerID === ANTHROPIC_OAUTH_ADAPTER.authProviderId;
|
|
4554
|
+
}
|
|
4526
4555
|
var ClaudeMultiAuthPlugin = async (ctx) => {
|
|
4527
4556
|
if (process.env.CLAUDE_MULTI_ACCOUNT_TRACE_PLUGIN === "1") {
|
|
4528
4557
|
console.error("[anthropic-multi-account] plugin function called");
|
|
@@ -4538,6 +4567,7 @@ var ClaudeMultiAuthPlugin = async (ctx) => {
|
|
|
4538
4567
|
let heartbeatHandle = null;
|
|
4539
4568
|
let heartbeatToken = null;
|
|
4540
4569
|
let heartbeatSessionId = null;
|
|
4570
|
+
const outputEffortBySession = /* @__PURE__ */ new Map();
|
|
4541
4571
|
const stopHeartbeat = () => {
|
|
4542
4572
|
heartbeatHandle?.stop();
|
|
4543
4573
|
heartbeatHandle = null;
|
|
@@ -4754,7 +4784,22 @@ var ClaudeMultiAuthPlugin = async (ctx) => {
|
|
|
4754
4784
|
});
|
|
4755
4785
|
await lifecycle.load({ type: "api" }).catch(() => {
|
|
4756
4786
|
});
|
|
4757
|
-
|
|
4787
|
+
const hooks = {
|
|
4788
|
+
"chat.params": async (input, output) => {
|
|
4789
|
+
if (!isAnthropicChatHook(input)) return;
|
|
4790
|
+
const outputEffort = getClientOutputEffort(output.options) ?? readOpenCodeVariantEffort(getMessageVariant(input));
|
|
4791
|
+
if (!outputEffort || outputEffort === "client") {
|
|
4792
|
+
outputEffortBySession.delete(input.sessionID);
|
|
4793
|
+
return;
|
|
4794
|
+
}
|
|
4795
|
+
outputEffortBySession.set(input.sessionID, outputEffort);
|
|
4796
|
+
},
|
|
4797
|
+
"chat.headers": async (input, output) => {
|
|
4798
|
+
if (!isAnthropicChatHook(input)) return;
|
|
4799
|
+
const outputEffort = outputEffortBySession.get(input.sessionID) ?? readOpenCodeVariantEffort(getMessageVariant(input));
|
|
4800
|
+
if (!outputEffort || outputEffort === "client") return;
|
|
4801
|
+
output.headers[OPENCODE_OUTPUT_EFFORT_HEADER] = outputEffort;
|
|
4802
|
+
},
|
|
4758
4803
|
"experimental.chat.system.transform": async (input, output) => {
|
|
4759
4804
|
const billingHeader = composeBillingSystemEntry(extractFirstUserText2(input), claudeCodeVersion);
|
|
4760
4805
|
prependMissingSystemEntries(output, [
|
|
@@ -4772,6 +4817,7 @@ var ClaudeMultiAuthPlugin = async (ctx) => {
|
|
|
4772
4817
|
loader: authLoader
|
|
4773
4818
|
}
|
|
4774
4819
|
};
|
|
4820
|
+
return hooks;
|
|
4775
4821
|
};
|
|
4776
4822
|
export {
|
|
4777
4823
|
ClaudeMultiAuthPlugin
|