opencode-anthropic-multi-account 0.2.41 → 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.
@@ -1,7 +1,7 @@
1
1
  declare const LIVE_TTL_MS: number;
2
2
  declare const SUPPORTED_CC_RANGE: {
3
3
  readonly min: "1.0.0";
4
- readonly maxTested: "2.1.158";
4
+ readonly maxTested: "2.1.159";
5
5
  };
6
6
  type TemplateSource = "bundled" | "cached" | "live";
7
7
  type TemplateTool = {
@@ -12,7 +12,7 @@ import {
12
12
  refreshLiveFingerprintAsync,
13
13
  resetFingerprintCaptureForTest,
14
14
  setFingerprintCaptureTestOverridesForTest
15
- } from "./chunk-YH55ZRXQ.js";
15
+ } from "./chunk-7MZVOHO3.js";
16
16
  import "./chunk-QDWAW66H.js";
17
17
  export {
18
18
  LIVE_TTL_MS,
package/dist/index.js CHANGED
@@ -25,7 +25,7 @@ import {
25
25
  showToast,
26
26
  sleep,
27
27
  updateConfigField
28
- } from "./chunk-YH55ZRXQ.js";
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.158",
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.158 (external, sdk-cli)",
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,6 +3440,11 @@ 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
  }
@@ -3448,7 +3454,7 @@ function readPositiveNumber(value) {
3448
3454
  function effortFromThinkingBudget(thinking) {
3449
3455
  const budgetTokens = readPositiveNumber(thinking?.budget_tokens) ?? readPositiveNumber(thinking?.budgetTokens);
3450
3456
  if (budgetTokens === void 0) return void 0;
3451
- if (budgetTokens >= 32e3) return "max";
3457
+ if (budgetTokens >= 31999) return "max";
3452
3458
  if (budgetTokens >= 16e3) return "high";
3453
3459
  if (budgetTokens >= 8e3) return "medium";
3454
3460
  return "low";
@@ -3460,7 +3466,7 @@ function getClientOutputEffort(inputBody) {
3460
3466
  const outputConfig = isRecord3(inputBody.output_config) ? inputBody.output_config : void 0;
3461
3467
  const reasoning = isRecord3(inputBody.reasoning) ? inputBody.reasoning : void 0;
3462
3468
  const thinking = isRecord3(inputBody.thinking) ? inputBody.thinking : void 0;
3463
- return readOutputEffortValue(outputConfig?.effort) ?? readOutputEffortValue(reasoning?.effort) ?? readOutputEffortValue(inputBody.reasoning_effort) ?? readOutputEffortValue(inputBody.reasoningEffort) ?? readOutputEffortValue(thinking?.effort) ?? effortFromThinkingBudget(thinking);
3469
+ return readOutputEffortValue(outputConfig?.effort) ?? readOutputEffortValue(inputBody.effort) ?? readOutputEffortValue(reasoning?.effort) ?? readOutputEffortValue(inputBody.reasoning_effort) ?? readOutputEffortValue(inputBody.reasoningEffort) ?? readOutputEffortValue(thinking?.effort) ?? effortFromThinkingBudget(thinking);
3464
3470
  }
3465
3471
  function resolveOutputEffort(inputBody, configuredEffort = getConfiguredOutputEffort()) {
3466
3472
  if (configuredEffort && configuredEffort !== "client") {
@@ -3588,6 +3594,7 @@ function remapSseLine(line, reverseLookup) {
3588
3594
  function buildUpstreamRequest(inputBody, identity, template2, options) {
3589
3595
  const { body, firstUserMessage, systemTexts } = normalizeAnthropicClientRequest(inputBody);
3590
3596
  const activeSessionId = options?.sessionId ?? getActiveSessionId();
3597
+ const configuredEffort = getConfiguredOutputEffort() ?? options?.outputEffort;
3591
3598
  const incomingTools = Array.isArray(body.tools) ? body.tools : [];
3592
3599
  body.tools = selectOpenCodeNativeTools({
3593
3600
  incomingTools,
@@ -3599,7 +3606,7 @@ function buildUpstreamRequest(inputBody, identity, template2, options) {
3599
3606
  body.context_management = DEFAULT_CONTEXT_MANAGEMENT;
3600
3607
  }
3601
3608
  if (modelId && !isHaikuModel(modelId)) {
3602
- body.output_config = { effort: resolveOutputEffort(inputBody) };
3609
+ body.output_config = { effort: resolveOutputEffort(inputBody, configuredEffort) };
3603
3610
  }
3604
3611
  body.max_tokens = resolveMaxTokens(body.max_tokens);
3605
3612
  return applyClaudeCodeUpstreamBodyFields(body, {
@@ -4079,6 +4086,9 @@ function extractIncomingHeaders(input, init) {
4079
4086
  function isRecord5(value) {
4080
4087
  return typeof value === "object" && value !== null;
4081
4088
  }
4089
+ function readHeaderOutputEffort(headers) {
4090
+ return readOpenCodeVariantEffort(headers[OPENCODE_OUTPUT_EFFORT_HEADER]);
4091
+ }
4082
4092
  function messageHasToolUse(message) {
4083
4093
  return Array.isArray(message.content) && message.content.some((block) => isRecord5(block) && block.type === "tool_use");
4084
4094
  }
@@ -4126,7 +4136,7 @@ function excludeBetas(values, excludedBetas2) {
4126
4136
  }
4127
4137
  return values.filter((beta) => !excludedBetas2.has(beta));
4128
4138
  }
4129
- function transformBodyToUpstream(body, identity, sessionId2) {
4139
+ function transformBodyToUpstream(body, identity, sessionId2, outputEffort) {
4130
4140
  try {
4131
4141
  const parsed = JSON.parse(body);
4132
4142
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
@@ -4137,7 +4147,7 @@ function transformBodyToUpstream(body, identity, sessionId2) {
4137
4147
  parsed,
4138
4148
  identity,
4139
4149
  template2,
4140
- { sessionId: sessionId2 }
4150
+ { sessionId: sessionId2, outputEffort }
4141
4151
  );
4142
4152
  const validationError = getDanglingToolUseError(
4143
4153
  Array.isArray(upstreamRequest.messages) ? upstreamRequest.messages : []
@@ -4290,6 +4300,8 @@ var AccountRuntimeFactory = class {
4290
4300
  const excludedBetas2 = getExcludedBetas(modelId);
4291
4301
  const incomingHeaders = extractIncomingHeaders(transformedInput, init);
4292
4302
  const sessionId2 = incomingHeaders["x-claude-code-session-id"] ?? getUpstreamSessionId();
4303
+ const outputEffort = readHeaderOutputEffort(incomingHeaders);
4304
+ delete incomingHeaders[OPENCODE_OUTPUT_EFFORT_HEADER];
4293
4305
  const headers = this.buildOutboundHeaders(
4294
4306
  incomingHeaders,
4295
4307
  sessionId2,
@@ -4301,7 +4313,7 @@ var AccountRuntimeFactory = class {
4301
4313
  void recordObservedToolNames(extractToolNamesFromRequestBody(init.body)).catch(() => {
4302
4314
  });
4303
4315
  }
4304
- 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 };
4305
4317
  if (transformedRequest.validationError) {
4306
4318
  return new Response(JSON.stringify({
4307
4319
  error: {
@@ -4534,6 +4546,12 @@ function applyOrderedHeaders(output, headers) {
4534
4546
  const orderedHeaders = orderHeadersForOutbound(headers);
4535
4547
  output.headers = Array.isArray(orderedHeaders) ? Object.fromEntries(orderedHeaders) : orderedHeaders;
4536
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
+ }
4537
4555
  var ClaudeMultiAuthPlugin = async (ctx) => {
4538
4556
  if (process.env.CLAUDE_MULTI_ACCOUNT_TRACE_PLUGIN === "1") {
4539
4557
  console.error("[anthropic-multi-account] plugin function called");
@@ -4549,6 +4567,7 @@ var ClaudeMultiAuthPlugin = async (ctx) => {
4549
4567
  let heartbeatHandle = null;
4550
4568
  let heartbeatToken = null;
4551
4569
  let heartbeatSessionId = null;
4570
+ const outputEffortBySession = /* @__PURE__ */ new Map();
4552
4571
  const stopHeartbeat = () => {
4553
4572
  heartbeatHandle?.stop();
4554
4573
  heartbeatHandle = null;
@@ -4765,7 +4784,22 @@ var ClaudeMultiAuthPlugin = async (ctx) => {
4765
4784
  });
4766
4785
  await lifecycle.load({ type: "api" }).catch(() => {
4767
4786
  });
4768
- return {
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
+ },
4769
4803
  "experimental.chat.system.transform": async (input, output) => {
4770
4804
  const billingHeader = composeBillingSystemEntry(extractFirstUserText2(input), claudeCodeVersion);
4771
4805
  prependMissingSystemEntries(output, [
@@ -4783,6 +4817,7 @@ var ClaudeMultiAuthPlugin = async (ctx) => {
4783
4817
  loader: authLoader
4784
4818
  }
4785
4819
  };
4820
+ return hooks;
4786
4821
  };
4787
4822
  export {
4788
4823
  ClaudeMultiAuthPlugin