opencode-anthropic-multi-account 0.2.93 → 0.2.95
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/{chunk-KQ5RHIZP.js → chunk-DQKGY67S.js} +660 -39
- package/dist/chunk-DQKGY67S.js.map +1 -0
- package/dist/fingerprint-capture.d.ts +1 -0
- package/dist/fingerprint-capture.js +1 -1
- package/dist/index.js +74 -598
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-KQ5RHIZP.js.map +0 -1
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
var data_default = {
|
|
22
22
|
_version: 1,
|
|
23
23
|
_schemaVersion: 1,
|
|
24
|
-
_captured: "2026-07-
|
|
24
|
+
_captured: "2026-07-17T00:28:24.510Z",
|
|
25
25
|
_source: "bundled",
|
|
26
26
|
agent_identity: "You are a Claude agent, built on Anthropic's Claude Agent SDK.",
|
|
27
27
|
system_prompt: `You are an interactive agent that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
|
|
@@ -1161,6 +1161,11 @@ When the user is actively at the terminal, your output already reaches them \u20
|
|
|
1161
1161
|
description: "One-sentence statement of the defect",
|
|
1162
1162
|
type: "string"
|
|
1163
1163
|
},
|
|
1164
|
+
short_summary: {
|
|
1165
|
+
description: "Compressed label for compact UI (\u226460 chars): the claim alone, no rationale or consequence clause",
|
|
1166
|
+
type: "string",
|
|
1167
|
+
maxLength: 60
|
|
1168
|
+
},
|
|
1164
1169
|
failure_scenario: {
|
|
1165
1170
|
description: "Concrete inputs/state \u2192 wrong output/crash",
|
|
1166
1171
|
type: "string"
|
|
@@ -1607,7 +1612,7 @@ IMPORTANT - Use the correct year in search queries:
|
|
|
1607
1612
|
"Write"
|
|
1608
1613
|
],
|
|
1609
1614
|
anthropic_beta: "claude-code-20250219,oauth-2025-04-20,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",
|
|
1610
|
-
cc_version: "2.1.
|
|
1615
|
+
cc_version: "2.1.212",
|
|
1611
1616
|
header_order: [
|
|
1612
1617
|
"Accept",
|
|
1613
1618
|
"Authorization",
|
|
@@ -1637,7 +1642,7 @@ IMPORTANT - Use the correct year in search queries:
|
|
|
1637
1642
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
1638
1643
|
"anthropic-version": "2023-06-01",
|
|
1639
1644
|
"content-type": "application/json",
|
|
1640
|
-
"user-agent": "claude-cli/2.1.
|
|
1645
|
+
"user-agent": "claude-cli/2.1.212 (external, sdk-cli)",
|
|
1641
1646
|
"x-app": "cli",
|
|
1642
1647
|
"x-stainless-timeout": "600"
|
|
1643
1648
|
},
|
|
@@ -1768,6 +1773,594 @@ function compareVersionStrings(left, right) {
|
|
|
1768
1773
|
|
|
1769
1774
|
// ../providers/claude-code/src/fingerprint-capture.ts
|
|
1770
1775
|
import { getConfigDir } from "opencode-multi-account-core";
|
|
1776
|
+
|
|
1777
|
+
// ../providers/claude-code/src/opencode-shared.ts
|
|
1778
|
+
import { createHash as createHash2, randomUUID } from "crypto";
|
|
1779
|
+
|
|
1780
|
+
// ../providers/claude-code/src/fingerprint-template.ts
|
|
1781
|
+
var template = fingerprint_data_default;
|
|
1782
|
+
var toolNames = new Set(template.tools.map((tool) => tool.name));
|
|
1783
|
+
function getClaudeCodeTemplateMetadata() {
|
|
1784
|
+
return {
|
|
1785
|
+
agentIdentity: template.agent_identity,
|
|
1786
|
+
anthropicBeta: template.anthropic_beta,
|
|
1787
|
+
bodyFieldOrder: template.body_field_order ? [...template.body_field_order] : void 0,
|
|
1788
|
+
ccVersion: template.cc_version,
|
|
1789
|
+
headerValues: { ...template.header_values },
|
|
1790
|
+
headerOrder: template.header_order ? [...template.header_order] : void 0,
|
|
1791
|
+
systemPrompt: template.system_prompt,
|
|
1792
|
+
systemPromptFable: template.system_prompt_fable,
|
|
1793
|
+
toolNames: template.tool_names ? [...template.tool_names] : template.tools.map((tool) => tool.name)
|
|
1794
|
+
};
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
// ../providers/claude-code/src/cch.ts
|
|
1798
|
+
var CCH_SEEDS = {
|
|
1799
|
+
"2.1.177": 0x4d659218e32a3268n
|
|
1800
|
+
// 2.1.178 was checked during the issue #91 review; the 2.1.177 seed did
|
|
1801
|
+
// not reproduce the captured cch, so leave it unstamped until a new seed is
|
|
1802
|
+
// independently extracted and verified.
|
|
1803
|
+
};
|
|
1804
|
+
var MASK = 0xfffffn;
|
|
1805
|
+
var U64 = (1n << 64n) - 1n;
|
|
1806
|
+
var P1 = 0x9e3779b185ebca87n;
|
|
1807
|
+
var P2 = 0xc2b2ae3d27d4eb4fn;
|
|
1808
|
+
var P3 = 0x165667b19e3779f9n;
|
|
1809
|
+
var P4 = 0x85ebca77c2b2ae63n;
|
|
1810
|
+
var P5 = 0x27d4eb2f165667c5n;
|
|
1811
|
+
var BILLING_HEADER_PREFIX = "x-anthropic-billing-header:";
|
|
1812
|
+
var CCH_RE = /(cc_entrypoint=[a-z0-9-]{1,32}; cch=)[0-9a-fA-F]{5}(?=;)/;
|
|
1813
|
+
var CC_VERSION_RE = /\bcc_version=([0-9]+(?:\.[0-9]+){2})(?:\.[0-9a-f]+)?;/;
|
|
1814
|
+
function rotl(value, bits) {
|
|
1815
|
+
return (value << bits | value >> 64n - bits) & U64;
|
|
1816
|
+
}
|
|
1817
|
+
function round(accumulator, input) {
|
|
1818
|
+
let next = accumulator + input * P2 & U64;
|
|
1819
|
+
next = rotl(next, 31n);
|
|
1820
|
+
return next * P1 & U64;
|
|
1821
|
+
}
|
|
1822
|
+
function mergeRound(accumulator, value) {
|
|
1823
|
+
const rounded = round(0n, value);
|
|
1824
|
+
const next = (accumulator ^ rounded) & U64;
|
|
1825
|
+
return next * P1 + P4 & U64;
|
|
1826
|
+
}
|
|
1827
|
+
function xxh64(data, seed) {
|
|
1828
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
1829
|
+
const length = data.length;
|
|
1830
|
+
let offset = 0;
|
|
1831
|
+
let hash;
|
|
1832
|
+
if (length >= 32) {
|
|
1833
|
+
let v1 = seed + P1 + P2 & U64;
|
|
1834
|
+
let v2 = seed + P2 & U64;
|
|
1835
|
+
let v3 = seed & U64;
|
|
1836
|
+
let v4 = seed - P1 & U64;
|
|
1837
|
+
const limit = length - 32;
|
|
1838
|
+
while (offset <= limit) {
|
|
1839
|
+
v1 = round(v1, view.getBigUint64(offset, true));
|
|
1840
|
+
offset += 8;
|
|
1841
|
+
v2 = round(v2, view.getBigUint64(offset, true));
|
|
1842
|
+
offset += 8;
|
|
1843
|
+
v3 = round(v3, view.getBigUint64(offset, true));
|
|
1844
|
+
offset += 8;
|
|
1845
|
+
v4 = round(v4, view.getBigUint64(offset, true));
|
|
1846
|
+
offset += 8;
|
|
1847
|
+
}
|
|
1848
|
+
hash = rotl(v1, 1n) + rotl(v2, 7n) + rotl(v3, 12n) + rotl(v4, 18n) & U64;
|
|
1849
|
+
hash = mergeRound(hash, v1);
|
|
1850
|
+
hash = mergeRound(hash, v2);
|
|
1851
|
+
hash = mergeRound(hash, v3);
|
|
1852
|
+
hash = mergeRound(hash, v4);
|
|
1853
|
+
} else {
|
|
1854
|
+
hash = seed + P5 & U64;
|
|
1855
|
+
}
|
|
1856
|
+
hash = hash + BigInt(length) & U64;
|
|
1857
|
+
while (offset + 8 <= length) {
|
|
1858
|
+
const k1 = round(0n, view.getBigUint64(offset, true));
|
|
1859
|
+
hash = (hash ^ k1) & U64;
|
|
1860
|
+
hash = rotl(hash, 27n) * P1 + P4 & U64;
|
|
1861
|
+
offset += 8;
|
|
1862
|
+
}
|
|
1863
|
+
if (offset + 4 <= length) {
|
|
1864
|
+
hash = (hash ^ BigInt(view.getUint32(offset, true)) * P1 & U64) & U64;
|
|
1865
|
+
hash = rotl(hash, 23n) * P2 + P3 & U64;
|
|
1866
|
+
offset += 4;
|
|
1867
|
+
}
|
|
1868
|
+
while (offset < length) {
|
|
1869
|
+
hash = (hash ^ BigInt(data[offset] ?? 0) * P5 & U64) & U64;
|
|
1870
|
+
hash = rotl(hash, 11n) * P1 & U64;
|
|
1871
|
+
offset += 1;
|
|
1872
|
+
}
|
|
1873
|
+
hash = (hash ^ hash >> 33n) & U64;
|
|
1874
|
+
hash = hash * P2 & U64;
|
|
1875
|
+
hash = (hash ^ hash >> 29n) & U64;
|
|
1876
|
+
hash = hash * P3 & U64;
|
|
1877
|
+
hash = (hash ^ hash >> 32n) & U64;
|
|
1878
|
+
return hash;
|
|
1879
|
+
}
|
|
1880
|
+
function replaceBillingCch(body, cch) {
|
|
1881
|
+
const system = body.system;
|
|
1882
|
+
if (!Array.isArray(system)) return { replaced: false };
|
|
1883
|
+
for (const entry of system) {
|
|
1884
|
+
if (!entry || typeof entry !== "object") continue;
|
|
1885
|
+
const systemEntry = entry;
|
|
1886
|
+
if (typeof systemEntry.text !== "string") continue;
|
|
1887
|
+
if (!systemEntry.text.startsWith(BILLING_HEADER_PREFIX)) continue;
|
|
1888
|
+
if (!CCH_RE.test(systemEntry.text)) continue;
|
|
1889
|
+
const version = CC_VERSION_RE.exec(systemEntry.text)?.[1];
|
|
1890
|
+
systemEntry.text = systemEntry.text.replace(CCH_RE, (_match, prefix) => `${prefix}${cch}`);
|
|
1891
|
+
return { replaced: true, version };
|
|
1892
|
+
}
|
|
1893
|
+
return { replaced: false };
|
|
1894
|
+
}
|
|
1895
|
+
function cchMaterial(bodyText) {
|
|
1896
|
+
const body = JSON.parse(bodyText);
|
|
1897
|
+
const { replaced, version } = replaceBillingCch(body, "00000");
|
|
1898
|
+
if (!replaced) return null;
|
|
1899
|
+
body.model = "";
|
|
1900
|
+
delete body.fallbacks;
|
|
1901
|
+
delete body.fallback_credit_token;
|
|
1902
|
+
delete body.max_tokens;
|
|
1903
|
+
return { bytes: new TextEncoder().encode(JSON.stringify(body)), version };
|
|
1904
|
+
}
|
|
1905
|
+
function cchForBody(bodyText, version) {
|
|
1906
|
+
let material;
|
|
1907
|
+
try {
|
|
1908
|
+
material = cchMaterial(bodyText);
|
|
1909
|
+
} catch {
|
|
1910
|
+
return null;
|
|
1911
|
+
}
|
|
1912
|
+
if (!material) return null;
|
|
1913
|
+
const seed = CCH_SEEDS[material.version ?? version ?? ""];
|
|
1914
|
+
if (seed === void 0) return null;
|
|
1915
|
+
const hash = xxh64(material.bytes, seed) & MASK;
|
|
1916
|
+
return hash.toString(16).padStart(5, "0");
|
|
1917
|
+
}
|
|
1918
|
+
function stampClaudeCodeCch(bodyText, version) {
|
|
1919
|
+
const cch = cchForBody(bodyText, version);
|
|
1920
|
+
if (cch === null) return bodyText;
|
|
1921
|
+
try {
|
|
1922
|
+
const body = JSON.parse(bodyText);
|
|
1923
|
+
const { replaced } = replaceBillingCch(body, cch);
|
|
1924
|
+
return replaced ? JSON.stringify(body) : bodyText;
|
|
1925
|
+
} catch {
|
|
1926
|
+
return bodyText;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
// ../providers/claude-code/src/effort-capability.ts
|
|
1931
|
+
var EFFORT_PREFERENCE = ["xhigh", "max", "high", "medium", "low"];
|
|
1932
|
+
function readRecord(value) {
|
|
1933
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
1934
|
+
}
|
|
1935
|
+
function normalizeEffortValue(value) {
|
|
1936
|
+
return value.trim().toLowerCase().replace(/[^a-z_-]+$/g, "");
|
|
1937
|
+
}
|
|
1938
|
+
function parseEffortCapabilityRejection(body) {
|
|
1939
|
+
const match = /does not support effort level\s+['"`]?([^'"`.\s]+)['"`]?\.?\s*Supported levels:\s*([a-z,\s_-]+)/i.exec(body);
|
|
1940
|
+
if (!match?.[1] || !match[2]) {
|
|
1941
|
+
return null;
|
|
1942
|
+
}
|
|
1943
|
+
const supported = match[2].split(",").map(normalizeEffortValue).filter(Boolean);
|
|
1944
|
+
return supported.length > 0 ? { rejected: normalizeEffortValue(match[1]), supported } : null;
|
|
1945
|
+
}
|
|
1946
|
+
function bestSupportedEffort(supported) {
|
|
1947
|
+
for (const effort of EFFORT_PREFERENCE) {
|
|
1948
|
+
if (supported.includes(effort)) {
|
|
1949
|
+
return effort;
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
return supported[0] ?? "high";
|
|
1953
|
+
}
|
|
1954
|
+
function clampUnsupportedEffortInBody(body, supportedEffortsByModel) {
|
|
1955
|
+
if (typeof body !== "string") {
|
|
1956
|
+
return { body, changed: false };
|
|
1957
|
+
}
|
|
1958
|
+
try {
|
|
1959
|
+
const parsed = JSON.parse(body);
|
|
1960
|
+
const record = readRecord(parsed);
|
|
1961
|
+
const modelId = typeof record?.model === "string" ? record.model : void 0;
|
|
1962
|
+
const outputConfig = readRecord(record?.output_config);
|
|
1963
|
+
const effort = typeof outputConfig?.effort === "string" ? outputConfig.effort : void 0;
|
|
1964
|
+
if (!modelId || !outputConfig || !effort) {
|
|
1965
|
+
return { body, changed: false, modelId };
|
|
1966
|
+
}
|
|
1967
|
+
const supported = supportedEffortsByModel.get(modelId);
|
|
1968
|
+
if (!supported || supported.includes(effort)) {
|
|
1969
|
+
return { body, changed: false, modelId, effort };
|
|
1970
|
+
}
|
|
1971
|
+
const clamped = bestSupportedEffort(supported);
|
|
1972
|
+
outputConfig.effort = clamped;
|
|
1973
|
+
return { body: JSON.stringify(record), changed: true, modelId, effort: clamped };
|
|
1974
|
+
} catch {
|
|
1975
|
+
return { body, changed: false };
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
function clampEffortAfterRejection(body, rejection, supportedEffortsByModel) {
|
|
1979
|
+
if (typeof body !== "string") {
|
|
1980
|
+
return { body, changed: false };
|
|
1981
|
+
}
|
|
1982
|
+
try {
|
|
1983
|
+
const parsed = JSON.parse(body);
|
|
1984
|
+
const record = readRecord(parsed);
|
|
1985
|
+
const modelId = typeof record?.model === "string" ? record.model : void 0;
|
|
1986
|
+
const outputConfig = readRecord(record?.output_config);
|
|
1987
|
+
const effort = typeof outputConfig?.effort === "string" ? outputConfig.effort : void 0;
|
|
1988
|
+
if (!modelId || !outputConfig || !effort) {
|
|
1989
|
+
return { body, changed: false, modelId };
|
|
1990
|
+
}
|
|
1991
|
+
supportedEffortsByModel.set(modelId, [...rejection.supported]);
|
|
1992
|
+
if (rejection.supported.includes(effort)) {
|
|
1993
|
+
return { body, changed: false, modelId, effort };
|
|
1994
|
+
}
|
|
1995
|
+
const clamped = bestSupportedEffort(rejection.supported);
|
|
1996
|
+
outputConfig.effort = clamped;
|
|
1997
|
+
return { body: JSON.stringify(record), changed: true, modelId, effort: clamped };
|
|
1998
|
+
} catch {
|
|
1999
|
+
return { body, changed: false };
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
// ../providers/claude-code/src/model-aliases.ts
|
|
2004
|
+
var MODEL_FAMILIES = ["fable", "opus", "sonnet", "haiku"];
|
|
2005
|
+
var FAMILY_RANK = { fable: 0, opus: 1, sonnet: 2, haiku: 3 };
|
|
2006
|
+
var CLAUDE_FABLE_MODEL_ID = "claude-fable-5";
|
|
2007
|
+
var CLAUDE_FABLE_1M_MODEL_ID = `${CLAUDE_FABLE_MODEL_ID}[1m]`;
|
|
2008
|
+
var CLAUDE_SONNET_MODEL_ID = "claude-sonnet-5";
|
|
2009
|
+
var CLAUDE_SONNET_1M_MODEL_ID = `${CLAUDE_SONNET_MODEL_ID}[1m]`;
|
|
2010
|
+
var FALLBACK_CLAUDE_CODE_BASE_MODEL_IDS = [
|
|
2011
|
+
CLAUDE_FABLE_MODEL_ID,
|
|
2012
|
+
"claude-opus-4-8",
|
|
2013
|
+
"claude-opus-4-7",
|
|
2014
|
+
"claude-opus-4-6",
|
|
2015
|
+
CLAUDE_SONNET_MODEL_ID,
|
|
2016
|
+
"claude-sonnet-4-6",
|
|
2017
|
+
"claude-haiku-4-5"
|
|
2018
|
+
];
|
|
2019
|
+
var STATIC_MODEL_ALIASES = {
|
|
2020
|
+
opus47: "claude-opus-4-7",
|
|
2021
|
+
opus46: "claude-opus-4-6",
|
|
2022
|
+
sonnet46: "claude-sonnet-4-6"
|
|
2023
|
+
};
|
|
2024
|
+
var cachedBaseModelIds = [...FALLBACK_CLAUDE_CODE_BASE_MODEL_IDS];
|
|
2025
|
+
function stripClaudeCodeProviderPrefix(modelId) {
|
|
2026
|
+
const slash = modelId.indexOf("/");
|
|
2027
|
+
if (slash === -1) return modelId;
|
|
2028
|
+
const provider = modelId.slice(0, slash).toLowerCase();
|
|
2029
|
+
return provider === "anthropic" || provider === "claude-code" ? modelId.slice(slash + 1) : modelId;
|
|
2030
|
+
}
|
|
2031
|
+
function resolveClaudeCodeModelAlias(modelId) {
|
|
2032
|
+
const unprefixed = stripClaudeCodeProviderPrefix(modelId.trim());
|
|
2033
|
+
return resolveAliasAgainst(unprefixed, cachedBaseModelIds) ?? STATIC_MODEL_ALIASES[unprefixed.toLowerCase()] ?? unprefixed;
|
|
2034
|
+
}
|
|
2035
|
+
function stripClaudeCodeContext1mTag(modelId) {
|
|
2036
|
+
return modelId.replace(/\[1m\]$/i, "");
|
|
2037
|
+
}
|
|
2038
|
+
function toClaudeCodeWireModelId(modelId) {
|
|
2039
|
+
return stripClaudeCodeContext1mTag(resolveClaudeCodeModelAlias(modelId));
|
|
2040
|
+
}
|
|
2041
|
+
function isClaudeCode1mModelLabel(modelId) {
|
|
2042
|
+
return /\[1m\]$/i.test(resolveClaudeCodeModelAlias(modelId));
|
|
2043
|
+
}
|
|
2044
|
+
function isClaudeFableModel(modelId) {
|
|
2045
|
+
return resolveClaudeCodeModelAlias(modelId).toLowerCase().includes("fable");
|
|
2046
|
+
}
|
|
2047
|
+
function resolveFamilyBase(family, baseIds) {
|
|
2048
|
+
return baseIds.filter((id) => modelFamily(id) === family && !id.includes("[")).sort(compareClaudeCodeBaseModelIds)[0];
|
|
2049
|
+
}
|
|
2050
|
+
function longContextEligible(id) {
|
|
2051
|
+
const normalized = id.toLowerCase();
|
|
2052
|
+
return normalized.startsWith("claude-") && !normalized.includes("haiku") && !normalized.endsWith("[1m]");
|
|
2053
|
+
}
|
|
2054
|
+
function compareClaudeCodeBaseModelIds(a, b) {
|
|
2055
|
+
const aRank = FAMILY_RANK[modelFamily(a) ?? ""] ?? 99;
|
|
2056
|
+
const bRank = FAMILY_RANK[modelFamily(b) ?? ""] ?? 99;
|
|
2057
|
+
if (aRank !== bRank) return aRank - bRank;
|
|
2058
|
+
return compareVersionDesc(modelVersionKey(a), modelVersionKey(b));
|
|
2059
|
+
}
|
|
2060
|
+
function modelFamily(id) {
|
|
2061
|
+
const normalized = stripClaudeCodeContext1mTag(stripClaudeCodeProviderPrefix(id)).toLowerCase();
|
|
2062
|
+
for (const family of MODEL_FAMILIES) {
|
|
2063
|
+
if (normalized.includes(family)) return family;
|
|
2064
|
+
}
|
|
2065
|
+
return void 0;
|
|
2066
|
+
}
|
|
2067
|
+
function resolveAliasAgainst(modelId, baseIds) {
|
|
2068
|
+
const normalized = stripClaudeCodeProviderPrefix(modelId).trim().toLowerCase();
|
|
2069
|
+
if (isModelFamily(normalized)) return resolveFamilyBase(normalized, baseIds) ?? void 0;
|
|
2070
|
+
const match = /^([a-z]+)1m$/.exec(normalized);
|
|
2071
|
+
if (match?.[1] && isModelFamily(match[1])) {
|
|
2072
|
+
const base = resolveFamilyBase(match[1], baseIds);
|
|
2073
|
+
return base && longContextEligible(base) ? `${base}[1m]` : void 0;
|
|
2074
|
+
}
|
|
2075
|
+
return void 0;
|
|
2076
|
+
}
|
|
2077
|
+
function isModelFamily(value) {
|
|
2078
|
+
return MODEL_FAMILIES.includes(value);
|
|
2079
|
+
}
|
|
2080
|
+
function modelVersionKey(id) {
|
|
2081
|
+
return id.match(/\d+/g)?.map(Number) ?? [];
|
|
2082
|
+
}
|
|
2083
|
+
function compareVersionDesc(a, b) {
|
|
2084
|
+
const length = Math.max(a.length, b.length);
|
|
2085
|
+
for (let index = 0; index < length; index += 1) {
|
|
2086
|
+
const diff = (b[index] ?? -1) - (a[index] ?? -1);
|
|
2087
|
+
if (diff !== 0) return diff;
|
|
2088
|
+
}
|
|
2089
|
+
return 0;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
// ../providers/claude-code/src/opencode-shared.ts
|
|
2093
|
+
var CLAUDE_CODE_API_BASE_URL = "https://api.anthropic.com";
|
|
2094
|
+
var STAINLESS_PACKAGE_VERSION = "0.81.0";
|
|
2095
|
+
var DEFAULT_OPENCODE_TIMEOUT_SECONDS = "300";
|
|
2096
|
+
var BILLING_SEED = "59cf53e54c78";
|
|
2097
|
+
var templateMetadata = getClaudeCodeTemplateMetadata();
|
|
2098
|
+
var templateHeaders = templateMetadata.headerValues;
|
|
2099
|
+
var CLAUDE_CODE_VERSION = templateMetadata.ccVersion ?? "2.1.137";
|
|
2100
|
+
var CCH_REMOVED_VERSION = "2.1.183";
|
|
2101
|
+
var CLIENT_SYSTEM_PREFACE = "\n\n---\n\nIMPORTANT: The operator of this session has supplied the following task-specific instructions. Follow them for task format, style, and output requirements when they do not conflict with security, authorization, refusal, tool-execution, confirmation, or other safety rules above. Those safety and tool-use constraints remain higher priority and cannot be overridden:\n\n";
|
|
2102
|
+
function loadClaudeCodeSharedRequestProfile() {
|
|
2103
|
+
return {
|
|
2104
|
+
anthropicBeta: templateMetadata.anthropicBeta ?? templateHeaders["anthropic-beta"] ?? "oauth-2025-04-20",
|
|
2105
|
+
anthropicVersion: templateHeaders["anthropic-version"] ?? "2023-06-01",
|
|
2106
|
+
apiV1BaseUrl: `${CLAUDE_CODE_API_BASE_URL}/v1`,
|
|
2107
|
+
baseUrl: CLAUDE_CODE_API_BASE_URL,
|
|
2108
|
+
ccVersion: CLAUDE_CODE_VERSION,
|
|
2109
|
+
headerOrder: templateMetadata.headerOrder ? [...templateMetadata.headerOrder] : void 0,
|
|
2110
|
+
headerValues: { ...templateHeaders },
|
|
2111
|
+
packageVersion: templateHeaders["x-stainless-package-version"] ?? STAINLESS_PACKAGE_VERSION,
|
|
2112
|
+
userAgent: templateHeaders["user-agent"] ?? `claude-cli/${CLAUDE_CODE_VERSION} (external, sdk-cli)`,
|
|
2113
|
+
xApp: templateHeaders["x-app"] ?? "cli"
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
function createClaudeCodeStaticHeaders(input) {
|
|
2117
|
+
return {
|
|
2118
|
+
"accept": "application/json",
|
|
2119
|
+
"content-type": "application/json",
|
|
2120
|
+
"anthropic-dangerous-direct-browser-access": "true",
|
|
2121
|
+
"user-agent": input.userAgent,
|
|
2122
|
+
"x-app": input.xApp,
|
|
2123
|
+
"x-stainless-arch": process.arch,
|
|
2124
|
+
"x-stainless-lang": "js",
|
|
2125
|
+
"x-stainless-os": getOsName(),
|
|
2126
|
+
"x-stainless-package-version": input.packageVersion ?? STAINLESS_PACKAGE_VERSION,
|
|
2127
|
+
"x-stainless-retry-count": "0",
|
|
2128
|
+
"x-stainless-runtime": "node",
|
|
2129
|
+
"x-stainless-runtime-version": process.version,
|
|
2130
|
+
...input.headerValues ?? {}
|
|
2131
|
+
};
|
|
2132
|
+
}
|
|
2133
|
+
function createClaudeCodePerRequestHeaders(input) {
|
|
2134
|
+
return {
|
|
2135
|
+
"x-claude-code-session-id": input.sessionId,
|
|
2136
|
+
"x-client-request-id": randomUUID(),
|
|
2137
|
+
"anthropic-version": input.anthropicVersion,
|
|
2138
|
+
"x-stainless-timeout": input.timeoutSeconds ?? DEFAULT_OPENCODE_TIMEOUT_SECONDS
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2141
|
+
function orderClaudeCodeHeadersForOutbound(headers, headerOrder) {
|
|
2142
|
+
if (!Array.isArray(headerOrder) || headerOrder.length === 0) return headers;
|
|
2143
|
+
const lowerToValue = /* @__PURE__ */ new Map();
|
|
2144
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
2145
|
+
lowerToValue.set(key.toLowerCase(), value);
|
|
2146
|
+
}
|
|
2147
|
+
const ordered = [];
|
|
2148
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2149
|
+
for (const name of headerOrder) {
|
|
2150
|
+
const key = name.toLowerCase();
|
|
2151
|
+
const value = lowerToValue.get(key);
|
|
2152
|
+
if (value === void 0 || seen.has(key)) continue;
|
|
2153
|
+
ordered.push([name, value]);
|
|
2154
|
+
seen.add(key);
|
|
2155
|
+
}
|
|
2156
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
2157
|
+
if (seen.has(key.toLowerCase())) continue;
|
|
2158
|
+
ordered.push([key, value]);
|
|
2159
|
+
}
|
|
2160
|
+
return ordered;
|
|
2161
|
+
}
|
|
2162
|
+
function computeClaudeCodeBuildTag(userMessage, version) {
|
|
2163
|
+
const chars = [4, 7, 20].map((index) => userMessage[index] ?? "0").join("");
|
|
2164
|
+
return createHash2("sha256").update(`${BILLING_SEED}${chars}${version}`).digest("hex").slice(0, 3);
|
|
2165
|
+
}
|
|
2166
|
+
function composeClaudeCodeBillingSystemEntry(firstUserMessage, version, cch = "00000") {
|
|
2167
|
+
const buildTag = computeClaudeCodeBuildTag(firstUserMessage, version);
|
|
2168
|
+
const base = `x-anthropic-billing-header: cc_version=${version}.${buildTag}; cc_entrypoint=sdk-cli;`;
|
|
2169
|
+
return claudeCodeBillingUsesCch(version) ? `${base} cch=${cch};` : base;
|
|
2170
|
+
}
|
|
2171
|
+
function claudeCodeBillingUsesCch(version) {
|
|
2172
|
+
const comparison = compareSemver(version, CCH_REMOVED_VERSION);
|
|
2173
|
+
return comparison === null || comparison < 0;
|
|
2174
|
+
}
|
|
2175
|
+
function compareSemver(left, right) {
|
|
2176
|
+
const leftParts = parseSemver(left);
|
|
2177
|
+
const rightParts = parseSemver(right);
|
|
2178
|
+
if (!leftParts || !rightParts) return null;
|
|
2179
|
+
for (let index = 0; index < leftParts.length; index += 1) {
|
|
2180
|
+
const diff = leftParts[index] - rightParts[index];
|
|
2181
|
+
if (diff !== 0) return diff;
|
|
2182
|
+
}
|
|
2183
|
+
return 0;
|
|
2184
|
+
}
|
|
2185
|
+
function parseSemver(version) {
|
|
2186
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
2187
|
+
if (!match) return null;
|
|
2188
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
2189
|
+
}
|
|
2190
|
+
function summarizeClaudeCodeCacheControls(body) {
|
|
2191
|
+
const observations = [];
|
|
2192
|
+
const observe = (value, path) => {
|
|
2193
|
+
const record = readRecord2(value);
|
|
2194
|
+
if (!record || !Object.hasOwn(record, "cache_control")) {
|
|
2195
|
+
return;
|
|
2196
|
+
}
|
|
2197
|
+
const cacheControl = readRecord2(record.cache_control);
|
|
2198
|
+
observations.push({
|
|
2199
|
+
path,
|
|
2200
|
+
type: typeof cacheControl?.type === "string" ? cacheControl.type : null,
|
|
2201
|
+
ttl: typeof cacheControl?.ttl === "string" ? cacheControl.ttl : null
|
|
2202
|
+
});
|
|
2203
|
+
};
|
|
2204
|
+
if (Array.isArray(body.system)) {
|
|
2205
|
+
body.system.forEach((block, index) => {
|
|
2206
|
+
observe(block, `system[${index}].cache_control`);
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
if (Array.isArray(body.tools)) {
|
|
2210
|
+
body.tools.forEach((tool, index) => {
|
|
2211
|
+
observe(tool, `tools[${index}].cache_control`);
|
|
2212
|
+
});
|
|
2213
|
+
}
|
|
2214
|
+
if (Array.isArray(body.messages)) {
|
|
2215
|
+
body.messages.forEach((message, messageIndex) => {
|
|
2216
|
+
const content = readRecord2(message)?.content;
|
|
2217
|
+
if (!Array.isArray(content)) return;
|
|
2218
|
+
content.forEach((block, contentIndex) => {
|
|
2219
|
+
observe(
|
|
2220
|
+
block,
|
|
2221
|
+
`messages[${messageIndex}].content[${contentIndex}].cache_control`
|
|
2222
|
+
);
|
|
2223
|
+
});
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
return observations;
|
|
2227
|
+
}
|
|
2228
|
+
function resolveClaudeCodeCacheControl(body) {
|
|
2229
|
+
const observations = summarizeClaudeCodeCacheControls(body);
|
|
2230
|
+
return observations.length > 0 && observations.every(
|
|
2231
|
+
(cacheControl) => cacheControl.type === "ephemeral" && cacheControl.ttl === "1h"
|
|
2232
|
+
) ? { type: "ephemeral", ttl: "1h" } : { type: "ephemeral" };
|
|
2233
|
+
}
|
|
2234
|
+
function applyClaudeCodePromptCaching(body, cacheControl = { type: "ephemeral" }) {
|
|
2235
|
+
const tools = body.tools;
|
|
2236
|
+
if (Array.isArray(tools) && tools.length > 0) {
|
|
2237
|
+
const clonedTools = tools.map((tool) => {
|
|
2238
|
+
const cloned = { ...tool };
|
|
2239
|
+
delete cloned.cache_control;
|
|
2240
|
+
return cloned;
|
|
2241
|
+
});
|
|
2242
|
+
clonedTools[clonedTools.length - 1] = {
|
|
2243
|
+
...clonedTools[clonedTools.length - 1],
|
|
2244
|
+
cache_control: cacheControl
|
|
2245
|
+
};
|
|
2246
|
+
body.tools = clonedTools;
|
|
2247
|
+
}
|
|
2248
|
+
const messages = body.messages;
|
|
2249
|
+
if (!Array.isArray(messages) || messages.length === 0) {
|
|
2250
|
+
return;
|
|
2251
|
+
}
|
|
2252
|
+
const lastMessage = messages[messages.length - 1];
|
|
2253
|
+
const content = lastMessage?.content;
|
|
2254
|
+
if (!Array.isArray(content) || content.length === 0) {
|
|
2255
|
+
return;
|
|
2256
|
+
}
|
|
2257
|
+
content[content.length - 1] = {
|
|
2258
|
+
...content[content.length - 1],
|
|
2259
|
+
cache_control: cacheControl
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
function applyClaudeCodeUpstreamBodyFields(body, input) {
|
|
2263
|
+
const cacheControl = input.cacheControl ?? { type: "ephemeral" };
|
|
2264
|
+
const firstUserMessage = input.firstUserMessage ?? extractFirstUserText(body.messages);
|
|
2265
|
+
const billingHeader = composeClaudeCodeBillingSystemEntry(
|
|
2266
|
+
firstUserMessage,
|
|
2267
|
+
input.ccVersion,
|
|
2268
|
+
input.cch
|
|
2269
|
+
);
|
|
2270
|
+
const systemTexts = input.systemTexts ?? normalizeClaudeCodeSystemTexts(body.system);
|
|
2271
|
+
const injectedSystemTexts = filterInjectedSystemTexts(systemTexts, {
|
|
2272
|
+
agentIdentity: input.agentIdentity,
|
|
2273
|
+
billingHeader,
|
|
2274
|
+
systemPrompt: input.systemPrompt
|
|
2275
|
+
});
|
|
2276
|
+
const mergedSystemPrompt = injectedSystemTexts.length > 0 ? `${input.systemPrompt}${CLIENT_SYSTEM_PREFACE}${injectedSystemTexts.join("\n\n")}` : input.systemPrompt;
|
|
2277
|
+
body.system = [
|
|
2278
|
+
{ type: "text", text: billingHeader },
|
|
2279
|
+
{
|
|
2280
|
+
type: "text",
|
|
2281
|
+
text: input.agentIdentity,
|
|
2282
|
+
cache_control: cacheControl
|
|
2283
|
+
},
|
|
2284
|
+
{
|
|
2285
|
+
type: "text",
|
|
2286
|
+
text: mergedSystemPrompt,
|
|
2287
|
+
cache_control: cacheControl
|
|
2288
|
+
}
|
|
2289
|
+
];
|
|
2290
|
+
body.metadata = {
|
|
2291
|
+
...readRecord2(body.metadata),
|
|
2292
|
+
user_id: JSON.stringify({
|
|
2293
|
+
device_id: input.identity.deviceId,
|
|
2294
|
+
account_uuid: input.identity.accountUuid,
|
|
2295
|
+
session_id: input.sessionId
|
|
2296
|
+
})
|
|
2297
|
+
};
|
|
2298
|
+
if (input.defaultTools && (!Array.isArray(body.tools) || body.tools.length === 0)) {
|
|
2299
|
+
body.tools = input.defaultTools.map((tool) => ({ ...tool }));
|
|
2300
|
+
}
|
|
2301
|
+
applyClaudeCodePromptCaching(body, cacheControl);
|
|
2302
|
+
return orderClaudeCodeBodyForOutbound(body, input.bodyFieldOrder);
|
|
2303
|
+
}
|
|
2304
|
+
function orderClaudeCodeBodyForOutbound(body, fieldOrder) {
|
|
2305
|
+
if (!Array.isArray(fieldOrder) || fieldOrder.length === 0) return body;
|
|
2306
|
+
const ordered = {};
|
|
2307
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2308
|
+
for (const field of fieldOrder) {
|
|
2309
|
+
if (seen.has(field)) continue;
|
|
2310
|
+
if (Object.prototype.hasOwnProperty.call(body, field)) {
|
|
2311
|
+
ordered[field] = body[field];
|
|
2312
|
+
seen.add(field);
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
for (const [field, value] of Object.entries(body)) {
|
|
2316
|
+
if (seen.has(field)) continue;
|
|
2317
|
+
ordered[field] = value;
|
|
2318
|
+
}
|
|
2319
|
+
return ordered;
|
|
2320
|
+
}
|
|
2321
|
+
function normalizeClaudeCodeSystemTexts(system) {
|
|
2322
|
+
if (typeof system === "string" && system.length > 0) return [system];
|
|
2323
|
+
if (!Array.isArray(system)) return [];
|
|
2324
|
+
const texts = [];
|
|
2325
|
+
for (const entry of system) {
|
|
2326
|
+
if (typeof entry === "string" && entry.length > 0) {
|
|
2327
|
+
texts.push(entry);
|
|
2328
|
+
continue;
|
|
2329
|
+
}
|
|
2330
|
+
const record = readRecord2(entry);
|
|
2331
|
+
const text = typeof record?.text === "string" && record.text.length > 0 ? record.text : void 0;
|
|
2332
|
+
if (text) texts.push(text);
|
|
2333
|
+
}
|
|
2334
|
+
return texts;
|
|
2335
|
+
}
|
|
2336
|
+
function filterInjectedSystemTexts(systemTexts, input) {
|
|
2337
|
+
return systemTexts.filter((entry) => entry !== input.billingHeader && entry !== input.agentIdentity && entry !== input.systemPrompt && !entry.startsWith("x-anthropic-billing-header:"));
|
|
2338
|
+
}
|
|
2339
|
+
function extractFirstUserText(messages) {
|
|
2340
|
+
if (!Array.isArray(messages)) return "";
|
|
2341
|
+
for (const message of messages) {
|
|
2342
|
+
const record = readRecord2(message);
|
|
2343
|
+
if (record?.role !== "user") continue;
|
|
2344
|
+
if (typeof record.content === "string") return record.content;
|
|
2345
|
+
if (!Array.isArray(record.content)) return "";
|
|
2346
|
+
return record.content.map((block) => {
|
|
2347
|
+
const text = readRecord2(block)?.text;
|
|
2348
|
+
return typeof text === "string" && text.length > 0 ? text : void 0;
|
|
2349
|
+
}).filter((text) => Boolean(text)).join("\n\n");
|
|
2350
|
+
}
|
|
2351
|
+
return "";
|
|
2352
|
+
}
|
|
2353
|
+
function readRecord2(value) {
|
|
2354
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
2355
|
+
}
|
|
2356
|
+
function getOsName() {
|
|
2357
|
+
const platform2 = process.platform;
|
|
2358
|
+
if (platform2 === "win32") return "Windows";
|
|
2359
|
+
if (platform2 === "darwin") return "MacOS";
|
|
2360
|
+
return "Linux";
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
// ../providers/claude-code/src/fingerprint-capture.ts
|
|
1771
2364
|
var CURRENT_SCHEMA_VERSION = 1;
|
|
1772
2365
|
var LIVE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
1773
2366
|
var DEFAULT_CAPTURE_TIMEOUT_MS = 1e4;
|
|
@@ -1814,35 +2407,35 @@ function isTemplateData(value) {
|
|
|
1814
2407
|
}
|
|
1815
2408
|
return typeof value._version === "number" && typeof value._captured === "string" && typeof value._source === "string" && typeof value.agent_identity === "string" && typeof value.system_prompt === "string" && Array.isArray(value.tools) && value.tools.every(isTemplateTool) && Array.isArray(value.tool_names) && value.tool_names.every((toolName) => typeof toolName === "string");
|
|
1816
2409
|
}
|
|
1817
|
-
function hasUsableToolSchemas(
|
|
1818
|
-
return
|
|
2410
|
+
function hasUsableToolSchemas(template2) {
|
|
2411
|
+
return template2.tools.length > 0 && template2.tools.every((tool) => tool.name.startsWith("mcp__") || isRecord(tool.input_schema));
|
|
1819
2412
|
}
|
|
1820
|
-
function isUsableTemplate(
|
|
1821
|
-
return
|
|
2413
|
+
function isUsableTemplate(template2) {
|
|
2414
|
+
return template2._schemaVersion === CURRENT_SCHEMA_VERSION && hasUsableToolSchemas(template2);
|
|
1822
2415
|
}
|
|
1823
|
-
function cloneTemplate(
|
|
2416
|
+
function cloneTemplate(template2, sourceOverride) {
|
|
1824
2417
|
return {
|
|
1825
|
-
...
|
|
1826
|
-
_source: sourceOverride ??
|
|
1827
|
-
tools:
|
|
1828
|
-
tool_names: [...
|
|
1829
|
-
header_order:
|
|
1830
|
-
header_values:
|
|
1831
|
-
body_field_order:
|
|
2418
|
+
...template2,
|
|
2419
|
+
_source: sourceOverride ?? template2._source,
|
|
2420
|
+
tools: template2.tools.map((tool) => ({ ...tool })),
|
|
2421
|
+
tool_names: [...template2.tool_names],
|
|
2422
|
+
header_order: template2.header_order ? [...template2.header_order] : void 0,
|
|
2423
|
+
header_values: template2.header_values ? { ...template2.header_values } : void 0,
|
|
2424
|
+
body_field_order: template2.body_field_order ? [...template2.body_field_order] : void 0
|
|
1832
2425
|
};
|
|
1833
2426
|
}
|
|
1834
|
-
function applyBundledTemplateFallbacks(
|
|
2427
|
+
function applyBundledTemplateFallbacks(template2) {
|
|
1835
2428
|
const bundledFablePrompt = bundledTemplate.system_prompt_fable;
|
|
1836
|
-
if (
|
|
1837
|
-
return
|
|
2429
|
+
if (template2.system_prompt_fable || typeof bundledFablePrompt !== "string" || bundledFablePrompt.length === 0) {
|
|
2430
|
+
return template2;
|
|
1838
2431
|
}
|
|
1839
2432
|
return {
|
|
1840
|
-
...
|
|
2433
|
+
...template2,
|
|
1841
2434
|
system_prompt_fable: bundledFablePrompt
|
|
1842
2435
|
};
|
|
1843
2436
|
}
|
|
1844
|
-
function prepareBundledTemplate(
|
|
1845
|
-
const rest = cloneTemplate(
|
|
2437
|
+
function prepareBundledTemplate(template2) {
|
|
2438
|
+
const rest = cloneTemplate(template2, "bundled");
|
|
1846
2439
|
return {
|
|
1847
2440
|
...rest,
|
|
1848
2441
|
_version: CURRENT_SCHEMA_VERSION,
|
|
@@ -1851,14 +2444,14 @@ function prepareBundledTemplate(template) {
|
|
|
1851
2444
|
tool_names: rest.tools.map((tool) => tool.name)
|
|
1852
2445
|
};
|
|
1853
2446
|
}
|
|
1854
|
-
function matchesBundledClaudeCodeFingerprint(
|
|
2447
|
+
function matchesBundledClaudeCodeFingerprint(template2, reference = bundledTemplate) {
|
|
1855
2448
|
const expectedToolNames = comparableHeadlessToolNames(reference.tool_names);
|
|
1856
|
-
const actualToolNames = comparableHeadlessToolNames(
|
|
2449
|
+
const actualToolNames = comparableHeadlessToolNames(template2.tools.map((tool) => tool.name));
|
|
1857
2450
|
const matchesExpectedTools = actualToolNames.length === expectedToolNames.length && expectedToolNames.every((name, index) => actualToolNames[index] === name);
|
|
1858
|
-
return
|
|
2451
|
+
return template2.agent_identity === reference.agent_identity && matchesExpectedTools;
|
|
1859
2452
|
}
|
|
1860
|
-
function comparableHeadlessToolNames(
|
|
1861
|
-
return
|
|
2453
|
+
function comparableHeadlessToolNames(toolNames2) {
|
|
2454
|
+
return toolNames2.filter((toolName) => !INTERACTIVE_ONLY_TOOL_NAMES.has(toolName));
|
|
1862
2455
|
}
|
|
1863
2456
|
function loadBundledTemplate() {
|
|
1864
2457
|
if (bundledTemplate._schemaVersion !== CURRENT_SCHEMA_VERSION) {
|
|
@@ -1900,11 +2493,11 @@ function readLiveCacheSync(sourceOverride = "cached") {
|
|
|
1900
2493
|
return null;
|
|
1901
2494
|
}
|
|
1902
2495
|
}
|
|
1903
|
-
function getCapturedAt(
|
|
1904
|
-
return Date.parse(
|
|
2496
|
+
function getCapturedAt(template2) {
|
|
2497
|
+
return Date.parse(template2._captured);
|
|
1905
2498
|
}
|
|
1906
|
-
function isFreshTemplate(
|
|
1907
|
-
const capturedAt = getCapturedAt(
|
|
2499
|
+
function isFreshTemplate(template2) {
|
|
2500
|
+
const capturedAt = getCapturedAt(template2);
|
|
1908
2501
|
return Number.isFinite(capturedAt) && now() - capturedAt < LIVE_TTL_MS;
|
|
1909
2502
|
}
|
|
1910
2503
|
function pickTemplate(cached, bundled) {
|
|
@@ -1928,8 +2521,8 @@ async function atomicWriteJson(targetPath, payload) {
|
|
|
1928
2521
|
`, "utf8");
|
|
1929
2522
|
await rename(tmpPath, targetPath);
|
|
1930
2523
|
}
|
|
1931
|
-
async function writeLiveCache(
|
|
1932
|
-
await atomicWriteJson(getCachePath(), cloneTemplate(
|
|
2524
|
+
async function writeLiveCache(template2) {
|
|
2525
|
+
await atomicWriteJson(getCachePath(), cloneTemplate(template2, "live"));
|
|
1933
2526
|
}
|
|
1934
2527
|
function toText(value) {
|
|
1935
2528
|
if (typeof value === "string") {
|
|
@@ -2103,7 +2696,7 @@ function extractTemplate(captured) {
|
|
|
2103
2696
|
if (!billingHeader || !agentIdentity || !systemPrompt || extractedTools.length === 0) {
|
|
2104
2697
|
return null;
|
|
2105
2698
|
}
|
|
2106
|
-
const
|
|
2699
|
+
const toolNames2 = extractedTools.map((tool) => tool.name);
|
|
2107
2700
|
const headerValues = extractStaticHeaderValues(captured.headers);
|
|
2108
2701
|
const bodyFieldOrder = Object.keys(captured.body);
|
|
2109
2702
|
return {
|
|
@@ -2114,7 +2707,7 @@ function extractTemplate(captured) {
|
|
|
2114
2707
|
agent_identity: agentIdentity,
|
|
2115
2708
|
system_prompt: systemPrompt,
|
|
2116
2709
|
tools: extractedTools,
|
|
2117
|
-
tool_names:
|
|
2710
|
+
tool_names: toolNames2,
|
|
2118
2711
|
anthropic_beta: captured.headers["anthropic-beta"],
|
|
2119
2712
|
cc_version: extractCCVersion(billingHeader, captured.headers["user-agent"]),
|
|
2120
2713
|
header_order: extractHeaderOrder(captured.rawHeaders),
|
|
@@ -2164,10 +2757,23 @@ async function captureLiveTemplateAsync(timeoutMs = DEFAULT_CAPTURE_TIMEOUT_MS,
|
|
|
2164
2757
|
});
|
|
2165
2758
|
const baseUrl = `http://${LOOPBACK_HOST}:${address.port}`;
|
|
2166
2759
|
await runClaudeCapture({ binaryPath, baseUrl, timeoutMs, model: options.model });
|
|
2167
|
-
|
|
2760
|
+
const captured = capturedRequest;
|
|
2761
|
+
if (!captured) {
|
|
2168
2762
|
return null;
|
|
2169
2763
|
}
|
|
2170
|
-
|
|
2764
|
+
const template2 = extractTemplate(captured);
|
|
2765
|
+
if (template2 && options.cacheControlEvidencePath) {
|
|
2766
|
+
await writeFile2(
|
|
2767
|
+
options.cacheControlEvidencePath,
|
|
2768
|
+
`${JSON.stringify({
|
|
2769
|
+
cc_version: template2.cc_version,
|
|
2770
|
+
cache_controls: summarizeClaudeCodeCacheControls(captured.body)
|
|
2771
|
+
}, null, 2)}
|
|
2772
|
+
`,
|
|
2773
|
+
"utf8"
|
|
2774
|
+
);
|
|
2775
|
+
}
|
|
2776
|
+
return template2;
|
|
2171
2777
|
} catch {
|
|
2172
2778
|
return null;
|
|
2173
2779
|
} finally {
|
|
@@ -2229,8 +2835,8 @@ function compareVersions(left, right) {
|
|
|
2229
2835
|
}
|
|
2230
2836
|
return leftPatch - rightPatch;
|
|
2231
2837
|
}
|
|
2232
|
-
function detectDrift(
|
|
2233
|
-
const cachedVersion =
|
|
2838
|
+
function detectDrift(template2, installedOverride) {
|
|
2839
|
+
const cachedVersion = template2.cc_version ?? null;
|
|
2234
2840
|
const installedVersion = installedOverride ?? probeInstalledCCVersion();
|
|
2235
2841
|
if (!cachedVersion) {
|
|
2236
2842
|
return {
|
|
@@ -2315,6 +2921,21 @@ function resetFingerprintCaptureForTest() {
|
|
|
2315
2921
|
|
|
2316
2922
|
export {
|
|
2317
2923
|
fingerprint_data_default,
|
|
2924
|
+
stampClaudeCodeCch,
|
|
2925
|
+
parseEffortCapabilityRejection,
|
|
2926
|
+
clampUnsupportedEffortInBody,
|
|
2927
|
+
clampEffortAfterRejection,
|
|
2928
|
+
resolveClaudeCodeModelAlias,
|
|
2929
|
+
toClaudeCodeWireModelId,
|
|
2930
|
+
isClaudeCode1mModelLabel,
|
|
2931
|
+
isClaudeFableModel,
|
|
2932
|
+
loadClaudeCodeSharedRequestProfile,
|
|
2933
|
+
createClaudeCodeStaticHeaders,
|
|
2934
|
+
createClaudeCodePerRequestHeaders,
|
|
2935
|
+
orderClaudeCodeHeadersForOutbound,
|
|
2936
|
+
composeClaudeCodeBillingSystemEntry,
|
|
2937
|
+
resolveClaudeCodeCacheControl,
|
|
2938
|
+
applyClaudeCodeUpstreamBodyFields,
|
|
2318
2939
|
detectCliVersion,
|
|
2319
2940
|
LIVE_TTL_MS,
|
|
2320
2941
|
SUPPORTED_CC_RANGE,
|
|
@@ -2330,4 +2951,4 @@ export {
|
|
|
2330
2951
|
setFingerprintCaptureTestOverridesForTest,
|
|
2331
2952
|
resetFingerprintCaptureForTest
|
|
2332
2953
|
};
|
|
2333
|
-
//# sourceMappingURL=chunk-
|
|
2954
|
+
//# sourceMappingURL=chunk-DQKGY67S.js.map
|