opencode-anthropic-multi-account 0.2.27 → 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.
- package/dist/index.js +80 -34
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -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
|
|
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
|
|
2196
|
-
const
|
|
2197
|
-
const
|
|
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
|
-
|
|
2200
|
-
if (
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
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
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
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
|
-
|
|
2212
|
-
|
|
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
|
|
2262
|
+
return { originalToOutgoing, outgoingToOriginal };
|
|
2215
2263
|
}
|
|
2216
|
-
function getOutgoingName(name,
|
|
2264
|
+
function getOutgoingName(name, lookup) {
|
|
2217
2265
|
if (!name) {
|
|
2218
2266
|
return name;
|
|
2219
2267
|
}
|
|
2220
|
-
|
|
2221
|
-
|
|
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,
|
|
2273
|
+
function rewriteToolUseNames(value, lookup) {
|
|
2228
2274
|
if (Array.isArray(value)) {
|
|
2229
|
-
return value.map((item) => rewriteToolUseNames(item,
|
|
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,
|
|
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,
|
|
2285
|
+
cloned.name = getOutgoingName(cloned.name, lookup);
|
|
2240
2286
|
}
|
|
2241
2287
|
return cloned;
|
|
2242
2288
|
}
|
|
2243
2289
|
function applyOutboundToolFlow(parsed, claudeToolNames) {
|
|
2244
|
-
const
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
|