opencode-anthropic-multi-account 0.2.26 → 0.2.28

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.121";
4
+ readonly maxTested: "2.1.122";
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-5PQ3VP24.js";
15
+ } from "./chunk-I2QRH74W.js";
16
16
  import "./chunk-3CTML5AX.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-5PQ3VP24.js";
28
+ } from "./chunk-I2QRH74W.js";
29
29
  import "./chunk-3CTML5AX.js";
30
30
 
31
31
  // src/index.ts
@@ -2153,17 +2153,36 @@ var TOOL_MASK_PREFIX = "tool_";
2153
2153
  function isRecord3(value) {
2154
2154
  return typeof value === "object" && value !== null;
2155
2155
  }
2156
- function shouldMaskToolName(name, claudeToolNames) {
2156
+ function shouldMaskToolName(name, claudeToolNames, options) {
2157
2157
  if (!name) {
2158
2158
  return false;
2159
2159
  }
2160
- return !claudeToolNames.has(name) && !name.startsWith("mcp__") && !name.startsWith(TOOL_MASK_PREFIX);
2160
+ return !claudeToolNames.has(name) && !name.startsWith("mcp__") && (!options.preserveToolPrefix || !name.startsWith(TOOL_MASK_PREFIX));
2161
2161
  }
2162
2162
  function buildMaskedToolName(toolName, length = 8) {
2163
2163
  const digest = createHash3("sha256").update(`tool-mask:${toolName}`).digest("hex").slice(0, length);
2164
2164
  return `${TOOL_MASK_PREFIX}${digest}`;
2165
2165
  }
2166
- function collectToolNames(parsed) {
2166
+ function isOutgoingNameAvailable(name, registry) {
2167
+ return !registry.usedOutgoing.has(name) && !registry.reservedOriginals.has(name);
2168
+ }
2169
+ function buildAvailableMaskedToolName(toolName, registry) {
2170
+ for (let length = 8; length <= 64; length += 2) {
2171
+ const masked = buildMaskedToolName(toolName, length);
2172
+ if (isOutgoingNameAvailable(masked, registry)) {
2173
+ return masked;
2174
+ }
2175
+ }
2176
+ const fullDigestName = buildMaskedToolName(toolName, 64);
2177
+ for (let suffix = 1; suffix <= 1024; suffix += 1) {
2178
+ const masked = `${fullDigestName}_${suffix}`;
2179
+ if (isOutgoingNameAvailable(masked, registry)) {
2180
+ return masked;
2181
+ }
2182
+ }
2183
+ return `${fullDigestName}_${registry.usedOutgoing.size + registry.reservedOriginals.size}`;
2184
+ }
2185
+ function collectCurrentToolNames(parsed) {
2167
2186
  const names = /* @__PURE__ */ new Set();
2168
2187
  if (Array.isArray(parsed.tools)) {
2169
2188
  for (const tool2 of parsed.tools) {
@@ -2172,6 +2191,10 @@ function collectToolNames(parsed) {
2172
2191
  }
2173
2192
  }
2174
2193
  }
2194
+ return [...names];
2195
+ }
2196
+ function collectReferencedToolNames(parsed) {
2197
+ const names = /* @__PURE__ */ new Set();
2175
2198
  if (Array.isArray(parsed.messages)) {
2176
2199
  for (const message of parsed.messages) {
2177
2200
  if (!isRecord3(message) || !Array.isArray(message.content)) {
@@ -2192,61 +2215,84 @@ function collectToolNames(parsed) {
2192
2215
  function buildClaudeToolNameSet(claudeToolNames) {
2193
2216
  return new Set(claudeToolNames.filter((name) => typeof name === "string" && name.length > 0));
2194
2217
  }
2195
- function buildRequestScopedToolLookup(parsed, claudeToolNames) {
2196
- const lookup = /* @__PURE__ */ new Map();
2197
- const usedOutgoing = /* @__PURE__ */ new Set();
2218
+ function buildToolFlowLookup(parsed, claudeToolNames) {
2219
+ const originalToOutgoing = /* @__PURE__ */ new Map();
2220
+ const outgoingToOriginal = /* @__PURE__ */ new Map();
2221
+ const registry = {
2222
+ usedOutgoing: /* @__PURE__ */ new Set(),
2223
+ reservedOriginals: new Set(collectCurrentToolNames(parsed))
2224
+ };
2198
2225
  const claudeToolSet = buildClaudeToolNameSet(claudeToolNames);
2199
- for (const originalName of collectToolNames(parsed)) {
2200
- if (!shouldMaskToolName(originalName, claudeToolSet)) {
2201
- lookup.set(originalName, originalName);
2202
- usedOutgoing.add(originalName);
2203
- continue;
2226
+ const registerCurrent = (originalName) => {
2227
+ if (originalToOutgoing.has(originalName)) {
2228
+ return;
2229
+ }
2230
+ if (!shouldMaskToolName(originalName, claudeToolSet, { preserveToolPrefix: false })) {
2231
+ originalToOutgoing.set(originalName, originalName);
2232
+ outgoingToOriginal.set(originalName, originalName);
2233
+ registry.usedOutgoing.add(originalName);
2234
+ return;
2204
2235
  }
2205
- let length = 8;
2206
- let masked = buildMaskedToolName(originalName, length);
2207
- while (usedOutgoing.has(masked)) {
2208
- length += 2;
2209
- masked = buildMaskedToolName(originalName, length);
2236
+ const masked = buildAvailableMaskedToolName(originalName, registry);
2237
+ originalToOutgoing.set(originalName, masked);
2238
+ outgoingToOriginal.set(masked, originalName);
2239
+ registry.usedOutgoing.add(masked);
2240
+ };
2241
+ const registerReference = (originalName) => {
2242
+ if (originalToOutgoing.has(originalName) || outgoingToOriginal.has(originalName)) {
2243
+ return;
2210
2244
  }
2211
- lookup.set(masked, originalName);
2212
- usedOutgoing.add(masked);
2245
+ if (!shouldMaskToolName(originalName, claudeToolSet, { preserveToolPrefix: true })) {
2246
+ originalToOutgoing.set(originalName, originalName);
2247
+ outgoingToOriginal.set(originalName, originalName);
2248
+ registry.usedOutgoing.add(originalName);
2249
+ return;
2250
+ }
2251
+ const masked = buildAvailableMaskedToolName(originalName, registry);
2252
+ originalToOutgoing.set(originalName, masked);
2253
+ outgoingToOriginal.set(masked, originalName);
2254
+ registry.usedOutgoing.add(masked);
2255
+ };
2256
+ for (const originalName of collectCurrentToolNames(parsed)) {
2257
+ registerCurrent(originalName);
2258
+ }
2259
+ for (const originalName of collectReferencedToolNames(parsed)) {
2260
+ registerReference(originalName);
2213
2261
  }
2214
- return lookup;
2262
+ return { originalToOutgoing, outgoingToOriginal };
2215
2263
  }
2216
- function getOutgoingName(name, reverseLookup) {
2264
+ function getOutgoingName(name, lookup) {
2217
2265
  if (!name) {
2218
2266
  return name;
2219
2267
  }
2220
- for (const [outgoing, original] of reverseLookup) {
2221
- if (original === name) {
2222
- return outgoing;
2223
- }
2268
+ if (lookup.outgoingToOriginal.has(name)) {
2269
+ return name;
2224
2270
  }
2225
- return name;
2271
+ return lookup.originalToOutgoing.get(name) ?? name;
2226
2272
  }
2227
- function rewriteToolUseNames(value, reverseLookup) {
2273
+ function rewriteToolUseNames(value, lookup) {
2228
2274
  if (Array.isArray(value)) {
2229
- return value.map((item) => rewriteToolUseNames(item, reverseLookup));
2275
+ return value.map((item) => rewriteToolUseNames(item, lookup));
2230
2276
  }
2231
2277
  if (!isRecord3(value)) {
2232
2278
  return value;
2233
2279
  }
2234
2280
  const cloned = {};
2235
2281
  for (const [key, nested] of Object.entries(value)) {
2236
- cloned[key] = rewriteToolUseNames(nested, reverseLookup);
2282
+ cloned[key] = rewriteToolUseNames(nested, lookup);
2237
2283
  }
2238
2284
  if (cloned.type === "tool_use" && typeof cloned.name === "string") {
2239
- cloned.name = getOutgoingName(cloned.name, reverseLookup);
2285
+ cloned.name = getOutgoingName(cloned.name, lookup);
2240
2286
  }
2241
2287
  return cloned;
2242
2288
  }
2243
2289
  function applyOutboundToolFlow(parsed, claudeToolNames) {
2244
- const reverseLookup = buildRequestScopedToolLookup(parsed, claudeToolNames);
2290
+ const lookup = buildToolFlowLookup(parsed, claudeToolNames);
2245
2291
  const next = { ...parsed };
2246
2292
  if (Array.isArray(parsed.tools)) {
2247
2293
  next.tools = parsed.tools.map((tool2) => ({
2248
2294
  ...tool2,
2249
- name: getOutgoingName(tool2.name, reverseLookup)
2295
+ name: getOutgoingName(tool2.name, lookup)
2250
2296
  }));
2251
2297
  }
2252
2298
  if (Array.isArray(parsed.messages)) {
@@ -2256,19 +2302,19 @@ function applyOutboundToolFlow(parsed, claudeToolNames) {
2256
2302
  }
2257
2303
  return {
2258
2304
  ...message,
2259
- content: rewriteToolUseNames(message.content, reverseLookup)
2305
+ content: rewriteToolUseNames(message.content, lookup)
2260
2306
  };
2261
2307
  });
2262
2308
  }
2263
2309
  if (isRecord3(parsed.tool_choice) && parsed.tool_choice.type === "tool") {
2264
2310
  next.tool_choice = {
2265
2311
  ...parsed.tool_choice,
2266
- name: getOutgoingName(parsed.tool_choice.name, reverseLookup)
2312
+ name: getOutgoingName(parsed.tool_choice.name, lookup)
2267
2313
  };
2268
2314
  }
2269
2315
  return {
2270
2316
  body: JSON.stringify(next),
2271
- reverseLookup
2317
+ reverseLookup: lookup.outgoingToOriginal
2272
2318
  };
2273
2319
  }
2274
2320
 
@@ -2522,6 +2568,7 @@ function resolvePacingConfig(explicit = {}, env = process.env) {
2522
2568
 
2523
2569
  // src/runtime/factory.ts
2524
2570
  var TOKEN_REFRESH_PERMANENT_FAILURE_STATUS = 401;
2571
+ var ASSISTANT_PREFILL_UNSUPPORTED_MESSAGE = "This model does not support assistant message prefill";
2525
2572
  function mergeHeaders(target, headers) {
2526
2573
  if (!headers) {
2527
2574
  return;
@@ -2552,6 +2599,41 @@ function extractIncomingHeaders(input, init) {
2552
2599
  mergeHeaders(headers, init?.headers);
2553
2600
  return headers;
2554
2601
  }
2602
+ function isRecord4(value) {
2603
+ return typeof value === "object" && value !== null;
2604
+ }
2605
+ function messageHasToolUse(message) {
2606
+ return Array.isArray(message.content) && message.content.some((block) => isRecord4(block) && block.type === "tool_use");
2607
+ }
2608
+ function removeTrailingAssistantPrefillBody(body) {
2609
+ if (typeof body !== "string") {
2610
+ return null;
2611
+ }
2612
+ try {
2613
+ const parsed = JSON.parse(body);
2614
+ if (!isRecord4(parsed) || !Array.isArray(parsed.messages)) {
2615
+ return null;
2616
+ }
2617
+ const messages = parsed.messages;
2618
+ const originalLength = messages.length;
2619
+ while (messages.length > 0) {
2620
+ const lastMessage = messages[messages.length - 1];
2621
+ if (!lastMessage || lastMessage.role !== "assistant" || messageHasToolUse(lastMessage)) {
2622
+ break;
2623
+ }
2624
+ messages.pop();
2625
+ }
2626
+ return messages.length === originalLength ? null : JSON.stringify(parsed);
2627
+ } catch {
2628
+ return null;
2629
+ }
2630
+ }
2631
+ async function isAssistantPrefillUnsupportedResponse(response) {
2632
+ if (response.status !== 400) {
2633
+ return false;
2634
+ }
2635
+ return (await response.clone().text()).includes(ASSISTANT_PREFILL_UNSUPPORTED_MESSAGE);
2636
+ }
2555
2637
  function splitBetaValues(value) {
2556
2638
  if (!value) {
2557
2639
  return [];
@@ -2765,13 +2847,13 @@ var AccountRuntimeFactory = class {
2765
2847
  releaseGate?.();
2766
2848
  }
2767
2849
  };
2768
- const performFetch = async (requestHeaders) => {
2850
+ const performFetch = async (requestHeaders, requestBody) => {
2769
2851
  await reservePacingSlot();
2770
2852
  try {
2771
2853
  const response2 = await fetch(transformedInput, {
2772
2854
  ...init,
2773
2855
  headers: requestHeaders,
2774
- body: transformedRequest.body
2856
+ body: requestBody
2775
2857
  });
2776
2858
  return await enrichRateLimitResponse(response2);
2777
2859
  } catch (error) {
@@ -2781,7 +2863,15 @@ var AccountRuntimeFactory = class {
2781
2863
  throw error;
2782
2864
  }
2783
2865
  };
2784
- let response = await performFetch(headers);
2866
+ let outboundBody = transformedRequest.body;
2867
+ let response = await performFetch(headers, outboundBody);
2868
+ if (await isAssistantPrefillUnsupportedResponse(response)) {
2869
+ const retryBody = removeTrailingAssistantPrefillBody(outboundBody);
2870
+ if (retryBody) {
2871
+ outboundBody = retryBody;
2872
+ response = await performFetch(headers, outboundBody);
2873
+ }
2874
+ }
2785
2875
  for (let attempt = 0; attempt < LONG_CONTEXT_BETAS.length; attempt += 1) {
2786
2876
  if (response.status !== 400 && response.status !== 429) {
2787
2877
  break;
@@ -2812,7 +2902,7 @@ var AccountRuntimeFactory = class {
2812
2902
  modelId,
2813
2903
  getExcludedBetas(modelId)
2814
2904
  );
2815
- response = await performFetch(retryHeaders);
2905
+ response = await performFetch(retryHeaders, outboundBody);
2816
2906
  }
2817
2907
  return applyResponseReverseLookup(response, transformedRequest.reverseLookup);
2818
2908
  }