@openclaw/ai 2026.10.10 → 2026.11.5-beta.1
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 +11 -1
- package/dist/.source-module-urls/fe058cc430242ce2ab0dfbcbe153e240a52cf9c3072c3dc0a73e5f956b6ba49b.json +1 -0
- package/dist/anthropic-CTND83W3.mjs +182 -0
- package/dist/{anthropic-payload-policy-rqCq9sT_.d.mts → anthropic-payload-policy-CXCJ5Pmj.d.mts} +21 -4
- package/dist/{anthropic-stream-reducer-C__ByTq1.mjs → anthropic-stream-lifecycle-rJe4OH5H.mjs} +845 -649
- package/dist/{anthropic-tool-projection-JTvMo4KG.d.mts → anthropic-tool-projection-D5DyrL6C.d.mts} +6 -7
- package/dist/{anthropic-tool-projection-DA_KeluM.mjs → anthropic-tool-projection-dGRfr4iT.mjs} +22 -32
- package/dist/{api-registry-gDt0faai.d.mts → api-registry-DY2MLUyg.d.mts} +2 -2
- package/dist/assistant-output-CD4kY9gu.mjs +16 -0
- package/dist/{azure-openai-responses-DHzTwi-y.mjs → azure-openai-responses-BhoLtP4Z.mjs} +46 -52
- package/dist/{cloudflare-Dttf8jKq.mjs → cloudflare-BJ2_Xabx.mjs} +1 -1
- package/dist/{credential-redaction-XvsPf7Yi.d.mts → credential-redaction-DrgndwTJ.d.mts} +5 -3
- package/dist/{deferred-event-buffer-DAvyP7qA.mjs → deferred-event-buffer-tIGkTkTm.mjs} +1 -2
- package/dist/{diagnostics-Cv7cW3pS.mjs → diagnostics-CloVGQiK.mjs} +42 -19
- package/dist/{diagnostics-DzrF1h4J.mjs → diagnostics-o1PrVNQb.mjs} +11 -4
- package/dist/diagnostics.d.mts +6 -7
- package/dist/diagnostics.mjs +4 -4
- package/dist/{env-api-keys-Xd8dm_aV.mjs → env-api-keys-BuHc86ya.mjs} +1 -26
- package/dist/event-stream-B4ZcSvsu.d.mts +1 -0
- package/dist/{event-stream-CzpE1g_o.d.mts → event-stream-BYmtRe8-.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{github-copilot-request-facts-F-EmvkpW.mjs → github-copilot-request-facts-BZ_EMo7X.mjs} +1 -1
- package/dist/{google-CZ6uGVkV.mjs → google-1uObh-eI.mjs} +7 -8
- package/dist/{google-interactions-qd4flmND.mjs → google-interactions-CY8Xb87S.mjs} +208 -233
- package/dist/{google-messages-B-svbJuN.mjs → google-messages-CwBqSoa4.mjs} +16 -13
- package/dist/{google-provider-stream-DlhaCvCf.mjs → google-provider-stream-D30s9EZp.mjs} +17 -10
- package/dist/{google-shared-Cif7nve-.mjs → google-shared-li0lmEZK.mjs} +70 -42
- package/dist/{google-vertex-BZTcYnWU.mjs → google-vertex-B5CHglca.mjs} +3 -3
- package/dist/{host-rCxf5Tjd.mjs → host-DX7ORpeH.mjs} +57 -46
- package/dist/{host-jJOffdlW.d.mts → host-ccbwPC3A.d.mts} +17 -9
- package/dist/{host-policy-Ci1cKluf.mjs → host-policy-jCZebuXx.mjs} +2 -2
- package/dist/index-Bczt0MnO.d.mts +17 -0
- package/dist/index.d.mts +8 -7
- package/dist/index.mjs +9 -7
- package/dist/internal/anthropic.d.mts +21 -26
- package/dist/internal/anthropic.mjs +6 -6
- package/dist/internal/google-model-family.mjs +1 -1
- package/dist/internal/google.d.mts +15 -0
- package/dist/internal/google.mjs +1 -0
- package/dist/internal/model-request-body.d.mts +37 -0
- package/dist/internal/model-request-body.mjs +106 -0
- package/dist/internal/openai-completions-compat.d.mts +5 -1
- package/dist/internal/openai-completions-compat.mjs +3 -2
- package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +14 -12
- package/dist/internal/openai.mjs +11 -10
- package/dist/internal/reasoning-tag-text-partitioner.d.mts +26 -0
- package/dist/{reasoning-tag-text-partitioner-DzlRubwU.mjs → internal/reasoning-tag-text-partitioner.mjs} +313 -122
- package/dist/internal/retry-after.d.mts +2 -2
- package/dist/internal/retry-after.mjs +165 -27
- package/dist/internal/runtime.d.mts +15 -41
- package/dist/internal/runtime.mjs +9 -10
- package/dist/internal/shared.d.mts +21 -25
- package/dist/internal/shared.mjs +9 -98
- package/dist/internal/tool-schema.d.mts +10 -10
- package/dist/internal/tool-schema.mjs +4 -4
- package/dist/{llm-request-activity-CfMuh5cC.mjs → llm-request-activity-DzaHoRAU.mjs} +2 -2
- package/dist/mistral-F5_asrmU.mjs +3741 -0
- package/dist/mistral.LICENSE +201 -0
- package/dist/{model-transport-url-BrsjjdjR.d.mts → model-transport-url-BdksnBqu.d.mts} +6 -8
- package/dist/{number-coercion-37gmNkuA.mjs → number-coercion-C7HsBgUL.mjs} +7 -2
- package/dist/observe-async-iterator-AlARO5wS.d.mts +178 -0
- package/dist/observe-async-iterator-DgmegcZR.mjs +181 -0
- package/dist/{openai-chatgpt-responses-iGYDPbmc.mjs → openai-chatgpt-responses-BIK7HROH.mjs} +61 -80
- package/dist/{openai-completions-CDy5u1mv.mjs → openai-completions-ClJ7QHEB.mjs} +5 -5
- package/dist/{openai-completions-compat-CBvb2eld.d.mts → openai-completions-compat-CJ-NsDzg.d.mts} +12 -6
- package/dist/{openai-completions-compat-CJ0OXZgi.mjs → openai-completions-compat-CstlTQuF.mjs} +74 -50
- package/dist/openai-completions-reasoning-replay-BwT1xwRI.mjs +45 -0
- package/dist/{openai-completions-transport-DLrm5EWi.mjs → openai-completions-transport-C6J4_oGf.mjs} +501 -563
- package/dist/{openai-prompt-cache-DgjD-UL5.d.mts → openai-prompt-cache-BZGaIWYh.d.mts} +4 -4
- package/dist/{openai-prompt-cache-h8vXRiaH.mjs → openai-prompt-cache-CgDoFhO0.mjs} +5 -4
- package/dist/openai-responses-Beifmf1s.mjs +89 -0
- package/dist/{openai-responses-compaction-replay-DUBbsfku.d.mts → openai-responses-compaction-replay-CNHk6k53.d.mts} +4 -4
- package/dist/{openai-responses-contracts-gnl6ZRs1.d.mts → openai-responses-contracts-BXMcvO7F.d.mts} +4 -10
- package/dist/{openai-responses-contracts-DCG51Us0.mjs → openai-responses-contracts-xU-n9AJJ.mjs} +36 -37
- package/dist/{openai-responses-endpoint-JbBT8IDv.mjs → openai-responses-endpoint-DCkURKS0.mjs} +55 -8
- package/dist/{openai-responses-payload-policy-BzM52TTH.d.mts → openai-responses-payload-policy-DyE30gdD.d.mts} +7 -7
- package/dist/{openai-responses-request-lifecycle-DuMpdA6y.mjs → openai-responses-request-lifecycle-o-ODC_rF.mjs} +12 -26
- package/dist/{openai-responses-shared-CNfHudFg.mjs → openai-responses-shared-CrFDkZ0N.mjs} +637 -389
- package/dist/{openai-responses-terminal-usage-CpVjkqn-.d.mts → openai-responses-terminal-usage-D7IhRA6i.d.mts} +9 -3
- package/dist/{openai-tool-schema-CGhEl7ao.mjs → openai-tool-schema-CsoYgnWy.mjs} +97 -122
- package/dist/otel-D-BkX8bB.mjs +766 -0
- package/dist/{overflow-OF3PgPbw.mjs → overflow-CpApyjG2.mjs} +1 -1
- package/dist/{positive-integer-Bb4Evc7L.mjs → positive-integer-DiqE5vNi.mjs} +2 -3
- package/dist/{prompt-cache-stability-D_MeCQFI.mjs → prompt-cache-stability-w-ICeyOI.mjs} +1 -1
- package/dist/{provider-error-qtZD2inE.mjs → provider-error-DD-fo4Rz.mjs} +71 -234
- package/dist/{provider-options-Bo8GzTGX.d.mts → provider-options-Mo8NM5d1.d.mts} +15 -4
- package/dist/{provider-replay-context-BC23HyZo.mjs → provider-replay-context-xyU7-CiT.mjs} +2 -2
- package/dist/provider-transcript-transform-BHq3Q4nc.mjs +32 -0
- package/dist/{provider-transport-turn-state-B11rmZpv.mjs → provider-transport-turn-state-DQd9K4Pd.mjs} +3 -3
- package/dist/{provider-types-ODq57rG_.d.mts → provider-types-B1e98js5.d.mts} +6 -4
- package/dist/provider-types.d.mts +7 -6
- package/dist/provider-types.mjs +2 -1
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +26 -29
- package/dist/{record-coerce-CNDovvft.mjs → record-coerce-BQaoiN3r.mjs} +4 -1
- package/dist/request-headers-DO4Mqhw1.mjs +10 -0
- package/dist/{required-api-key-D088S4Cd.mjs → required-api-key-2zZTkmsi.mjs} +1 -1
- package/dist/retry-after-DnHBlFS2.d.mts +45 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/{sanitize-unicode-ZqVLLEKC.d.mts → sanitize-unicode-BISmUlUv.d.mts} +2 -2
- package/dist/{simple-options-BdJJbzZk.mjs → simple-options-tLSeECry.mjs} +108 -82
- package/dist/src-BUsVkrNt.mjs +105 -0
- package/dist/{src-CyA0zJnt.mjs → src-CQ7nH2mL.mjs} +4 -7
- package/dist/stable-stringify-CchQEmeA.mjs +84 -0
- package/dist/{stream-DQqGjhbq.mjs → stream-DrtAWu7c.mjs} +2 -6
- package/dist/{stream-first-event-timeout-D_TfJHRJ.mjs → stream-first-event-timeout-B7RcufAV.mjs} +16 -13
- package/dist/{string-coerce-Cj8sqWHx.mjs → string-coerce-BCuWMIrk.mjs} +1 -1
- package/dist/string-normalization-B8TDDBX_.mjs +32 -0
- package/dist/telemetry-B9f7K_Xe.mjs +582 -0
- package/dist/{tool-schema-json-projection-Cvq69Ajp.mjs → tool-schema-json-projection-BQpiJlXJ.mjs} +53 -69
- package/dist/{transport-stream-shared-DdnJGEj0.mjs → transport-stream-shared-D2uFMhMc.mjs} +177 -93
- package/dist/{transport-stream-shared-8ru8eX4s.d.mts → transport-stream-shared-D3IAU4jn.d.mts} +29 -15
- package/dist/{transport-utils-CcCAuFVS.mjs → transport-utils-Da_39MYi.mjs} +23 -38
- package/dist/transports.d.mts +39 -38
- package/dist/transports.mjs +214 -295
- package/dist/{types-CVYzKrMl.d.mts → types-BVdTf0YV.d.mts} +38 -3
- package/dist/types-Cb3-5WM9.d.mts +1 -0
- package/dist/{types-BXd0kI8-.mjs → types-OVEWUaDh.mjs} +3 -1
- package/dist/types.d.mts +7 -6
- package/dist/types.mjs +7 -5
- package/dist/{validation-9FSkE8T-.mjs → validation-DGXqfvkj.mjs} +45 -27
- package/dist/{validation-BQ5u20Ru.d.mts → validation-QmyD0E5A.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -2
- package/package.json +40 -6
- package/dist/anthropic-B54Ts1tV.mjs +0 -221
- package/dist/assistant-output-DbgdWAhJ.mjs +0 -47
- package/dist/event-stream-CDpFza-M.d.mts +0 -1
- package/dist/index-DSprYWaz.d.mts +0 -185
- package/dist/mistral-C_ImzxlK.mjs +0 -512
- package/dist/model-request-body-BD5vy4rP.d.mts +0 -17
- package/dist/openai-responses-Cp2QPq7K.mjs +0 -87
- package/dist/retry-after-sw-XX8aC.d.mts +0 -15
- package/dist/types-CBJthzJX.d.mts +0 -1
|
@@ -28,31 +28,55 @@ const OBSOLETE_ASCTIME_DATE_RE = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Ap
|
|
|
28
28
|
function ownDataValue(value, key) {
|
|
29
29
|
return value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, key)?.value : void 0;
|
|
30
30
|
}
|
|
31
|
+
const QUOTA_RESET_HEADERS = [...[
|
|
32
|
+
"tokens",
|
|
33
|
+
"requests",
|
|
34
|
+
"project-tokens"
|
|
35
|
+
].map((dimension) => ({
|
|
36
|
+
remaining: `x-ratelimit-remaining-${dimension}`,
|
|
37
|
+
reset: `x-ratelimit-reset-${dimension}`,
|
|
38
|
+
parseResetSeconds: parseQuotaResetSeconds
|
|
39
|
+
})), ...[
|
|
40
|
+
"requests",
|
|
41
|
+
"tokens",
|
|
42
|
+
"input-tokens",
|
|
43
|
+
"output-tokens"
|
|
44
|
+
].map((dimension) => ({
|
|
45
|
+
remaining: `anthropic-ratelimit-${dimension}-remaining`,
|
|
46
|
+
reset: `anthropic-ratelimit-${dimension}-reset`,
|
|
47
|
+
parseResetSeconds: parseRfc3339ResetSeconds
|
|
48
|
+
}))];
|
|
49
|
+
const TIMING_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
50
|
+
"retry-after",
|
|
51
|
+
"retry-after-ms",
|
|
52
|
+
...QUOTA_RESET_HEADERS.flatMap(({ remaining, reset }) => [remaining, reset])
|
|
53
|
+
]);
|
|
54
|
+
function maxDefined(...values) {
|
|
55
|
+
let floor;
|
|
56
|
+
for (const value of values) if (value !== void 0) floor = Math.max(floor ?? 0, value);
|
|
57
|
+
return floor;
|
|
58
|
+
}
|
|
31
59
|
/** Reads only retry timing metadata, without invoking provider getters or serialization hooks. */
|
|
32
60
|
function parseRetryAfterHeadersSeconds(headers, nowMs = Date.now(), status) {
|
|
61
|
+
const timing = parseRetryAfterHeadersTiming(headers, nowMs, status);
|
|
62
|
+
return timing?.explicitSeconds ?? timing?.resetSeconds;
|
|
63
|
+
}
|
|
64
|
+
/** Header timing with explicit retry instructions kept apart from bucket refills. */
|
|
65
|
+
function parseRetryAfterHeadersTiming(headers, nowMs = Date.now(), status) {
|
|
33
66
|
if (!headers || typeof headers !== "object") return;
|
|
34
67
|
try {
|
|
35
68
|
let entries;
|
|
36
69
|
try {
|
|
37
|
-
entries = [
|
|
38
|
-
"retry-after",
|
|
39
|
-
"retry-after-ms",
|
|
40
|
-
"x-ratelimit-remaining-tokens",
|
|
41
|
-
"x-ratelimit-reset-tokens",
|
|
42
|
-
"x-ratelimit-remaining-requests",
|
|
43
|
-
"x-ratelimit-reset-requests",
|
|
44
|
-
"x-ratelimit-remaining-project-tokens",
|
|
45
|
-
"x-ratelimit-reset-project-tokens"
|
|
46
|
-
].map((key) => [key, Headers.prototype.get.call(headers, key)]);
|
|
70
|
+
entries = [...TIMING_HEADER_NAMES].map((key) => [key, Headers.prototype.get.call(headers, key)]);
|
|
47
71
|
} catch {
|
|
48
72
|
entries = Object.getOwnPropertyNames(headers).flatMap((key) => {
|
|
49
73
|
const name = key.toLowerCase();
|
|
50
|
-
return
|
|
74
|
+
return TIMING_HEADER_NAMES.has(name) ? [[name, ownDataValue(headers, key)]] : [];
|
|
51
75
|
});
|
|
52
76
|
}
|
|
53
77
|
let floor;
|
|
54
78
|
for (const [key, value] of entries) {
|
|
55
|
-
if (key
|
|
79
|
+
if (key !== "retry-after" && key !== "retry-after-ms") continue;
|
|
56
80
|
const text = typeof value === "string" ? value.trim() : typeof value === "number" ? String(value) : "";
|
|
57
81
|
const milliseconds = key === "retry-after-ms";
|
|
58
82
|
const numeric = typeof value === "number" ? value >= 0 && (milliseconds || Number.isInteger(value) || value === Infinity) : (milliseconds ? /^\d+(?:\.\d+)?$/ : /^\d+$/).test(text);
|
|
@@ -61,26 +85,32 @@ function parseRetryAfterHeadersSeconds(headers, nowMs = Date.now(), status) {
|
|
|
61
85
|
const seconds = numeric ? Number.isFinite(number) && number <= Number.MAX_SAFE_INTEGER ? number / (milliseconds ? 1e3 : 1) : Infinity : retryAt === void 0 ? void 0 : Math.max(0, (retryAt - nowMs) / 1e3);
|
|
62
86
|
if (seconds !== void 0) floor = Math.max(floor ?? 0, seconds);
|
|
63
87
|
}
|
|
88
|
+
let resetFloor;
|
|
64
89
|
if (status === 429) {
|
|
65
90
|
const values = new Map(entries);
|
|
66
|
-
for (const
|
|
67
|
-
|
|
68
|
-
"requests",
|
|
69
|
-
"project-tokens"
|
|
70
|
-
]) {
|
|
71
|
-
const remaining = values.get(`x-ratelimit-remaining-${dimension}`);
|
|
91
|
+
for (const { remaining: remainingKey, reset: resetKey, parseResetSeconds } of QUOTA_RESET_HEADERS) {
|
|
92
|
+
const remaining = values.get(remainingKey);
|
|
72
93
|
const numericRemaining = typeof remaining === "number" ? remaining : typeof remaining === "string" && /^-?\d+(?:\.\d+)?$/.test(remaining.trim()) ? Number(remaining) : NaN;
|
|
73
94
|
if (!Number.isFinite(numericRemaining) || numericRemaining > 0) continue;
|
|
74
|
-
const reset = values.get(
|
|
75
|
-
const seconds = typeof reset === "string" ?
|
|
76
|
-
|
|
95
|
+
const reset = values.get(resetKey);
|
|
96
|
+
const seconds = typeof reset === "string" ? parseResetSeconds(reset, nowMs) : void 0;
|
|
97
|
+
resetFloor = maxDefined(resetFloor, seconds);
|
|
77
98
|
}
|
|
78
99
|
}
|
|
79
|
-
return floor
|
|
100
|
+
return floor === void 0 && resetFloor === void 0 ? void 0 : {
|
|
101
|
+
...floor === void 0 ? {} : { explicitSeconds: floor },
|
|
102
|
+
...resetFloor === void 0 ? {} : { resetSeconds: resetFloor }
|
|
103
|
+
};
|
|
80
104
|
} catch {
|
|
81
105
|
return;
|
|
82
106
|
}
|
|
83
107
|
}
|
|
108
|
+
/** Anthropic reports bucket resets as RFC 3339 instants. */
|
|
109
|
+
function parseRfc3339ResetSeconds(value, nowMs) {
|
|
110
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(value)) return;
|
|
111
|
+
const resetAtMs = Date.parse(value);
|
|
112
|
+
return Number.isFinite(resetAtMs) ? Math.max(0, (resetAtMs - nowMs) / 1e3) : void 0;
|
|
113
|
+
}
|
|
84
114
|
function parseQuotaResetSeconds(value) {
|
|
85
115
|
if (!/^(?:\d+(?:\.\d+)?(?:ms|s|m|h))+$/.test(value)) return;
|
|
86
116
|
const scales = {
|
|
@@ -99,13 +129,121 @@ function parseQuotaResetSeconds(value) {
|
|
|
99
129
|
}
|
|
100
130
|
/** SDK errors carry native response headers separately from their error body. */
|
|
101
131
|
function parseRetryAfterErrorSeconds(error, nowMs = Date.now()) {
|
|
132
|
+
const timing = parseRetryAfterErrorTiming(error, nowMs);
|
|
133
|
+
return timing?.explicitSeconds ?? timing?.resetSeconds;
|
|
134
|
+
}
|
|
135
|
+
/** Header timing from an SDK error and its response, merged per authority. */
|
|
136
|
+
function parseRetryAfterErrorTiming(error, nowMs = Date.now()) {
|
|
102
137
|
try {
|
|
103
138
|
const status = ownDataValue(error, "status") ?? ownDataValue(error, "statusCode");
|
|
104
139
|
const response = ownDataValue(error, "response");
|
|
105
140
|
const responseStatus = ownDataValue(response, "status") ?? ownDataValue(response, "statusCode");
|
|
106
|
-
const direct =
|
|
107
|
-
const
|
|
108
|
-
|
|
141
|
+
const direct = parseRetryAfterHeadersTiming(ownDataValue(error, "headers"), nowMs, typeof status === "number" ? status : void 0);
|
|
142
|
+
const responseTiming = parseRetryAfterHeadersTiming(ownDataValue(response, "headers"), nowMs, typeof responseStatus === "number" ? responseStatus : typeof status === "number" ? status : void 0);
|
|
143
|
+
const explicitSeconds = maxDefined(direct?.explicitSeconds, responseTiming?.explicitSeconds);
|
|
144
|
+
const resetSeconds = maxDefined(direct?.resetSeconds, responseTiming?.resetSeconds);
|
|
145
|
+
return explicitSeconds === void 0 && resetSeconds === void 0 ? void 0 : {
|
|
146
|
+
...explicitSeconds === void 0 ? {} : { explicitSeconds },
|
|
147
|
+
...resetSeconds === void 0 ? {} : { resetSeconds }
|
|
148
|
+
};
|
|
149
|
+
} catch {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Provider prose such as "Please try again in 6s", "retry in 32s" or "Retry-After: 7". */
|
|
154
|
+
const RETRY_AFTER_TEXT_RE = /\b(?:retry[- ]after\b\s*:?\s*(?:in\b\s*)?|(?:please\s+)?(?:try again|retry) in\s+)([^\r\n;]+)/i;
|
|
155
|
+
const RETRY_TEXT_NUMBER_RE = /^(\d+(?:\.\d+)?|Infinity)\s*([a-z]+)?\b/i;
|
|
156
|
+
const MS_PER_SECOND = 1e3;
|
|
157
|
+
const RETRY_TEXT_UNIT_MS = new Map([
|
|
158
|
+
["milliseconds millisecond msecs msec ms", 1],
|
|
159
|
+
["seconds second secs sec s", MS_PER_SECOND],
|
|
160
|
+
["minutes minute mins min m", 60 * MS_PER_SECOND],
|
|
161
|
+
["hours hour hrs hr h", 3600 * MS_PER_SECOND],
|
|
162
|
+
["days day d", 86400 * MS_PER_SECOND]
|
|
163
|
+
].flatMap(([aliases, milliseconds]) => aliases.split(" ").map((alias) => [alias, milliseconds])));
|
|
164
|
+
/** Seconds named by a captured retry-text value: a number with an optional time unit, or an HTTP-date. */
|
|
165
|
+
function parseRetryAfterTextSeconds(valueText, nowMs = Date.now()) {
|
|
166
|
+
const secondsMatch = RETRY_TEXT_NUMBER_RE.exec(valueText);
|
|
167
|
+
if (secondsMatch?.[1]) {
|
|
168
|
+
const value = /^infinity$/i.test(secondsMatch[1]) ? Infinity : Number(secondsMatch[1]);
|
|
169
|
+
if (Number.isNaN(value) || value < 0) return;
|
|
170
|
+
const unitMilliseconds = RETRY_TEXT_UNIT_MS.get(secondsMatch[2]?.toLowerCase() ?? "s");
|
|
171
|
+
if (unitMilliseconds === void 0) return;
|
|
172
|
+
return unitMilliseconds === 1 ? value / MS_PER_SECOND : value * (unitMilliseconds / MS_PER_SECOND);
|
|
173
|
+
}
|
|
174
|
+
const retryAtMs = parseRetryAfterHttpDateMs(valueText, nowMs);
|
|
175
|
+
return retryAtMs === void 0 ? void 0 : Math.max(0, (retryAtMs - nowMs) / MS_PER_SECOND);
|
|
176
|
+
}
|
|
177
|
+
/** Whether text carries an explicit retry instruction that parseRetryAfterTextSeconds accepts. */
|
|
178
|
+
function hasExplicitRetryText(text, nowMs = Date.now()) {
|
|
179
|
+
if (typeof text !== "string" || !text) return false;
|
|
180
|
+
for (const match of text.matchAll(new RegExp(RETRY_AFTER_TEXT_RE, "gi"))) if (parseRetryAfterTextSeconds(match[1]?.trim() ?? "", nowMs) !== void 0) return true;
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
const GOOGLE_RETRY_DELAY_TEXT_RE = /"retryDelay"\s*:\s*"(\d+(?:\.\d{1,9})?)s"/g;
|
|
184
|
+
const GOOGLE_RETRY_DELAY_VALUE_RE = /^(\d+(?:\.\d{1,9})?)s$/;
|
|
185
|
+
const GOOGLE_RETRY_INFO_TYPE = "type.googleapis.com/google.rpc.RetryInfo";
|
|
186
|
+
const MAX_GOOGLE_ERROR_DETAILS = 16;
|
|
187
|
+
function googleRetryDelayTextSeconds(text) {
|
|
188
|
+
let floor;
|
|
189
|
+
for (const match of text.matchAll(GOOGLE_RETRY_DELAY_TEXT_RE)) floor = maxDefined(floor, Number(match[1]));
|
|
190
|
+
return floor;
|
|
191
|
+
}
|
|
192
|
+
function googleStatusRetryDelaySeconds(status) {
|
|
193
|
+
if (typeof status === "string") return googleRetryDelayTextSeconds(status);
|
|
194
|
+
const details = ownDataValue(status, "details");
|
|
195
|
+
if (!Array.isArray(details)) return;
|
|
196
|
+
let floor;
|
|
197
|
+
for (let index = 0; index < Math.min(details.length, MAX_GOOGLE_ERROR_DETAILS); index += 1) {
|
|
198
|
+
const detail = ownDataValue(details, String(index));
|
|
199
|
+
if (ownDataValue(detail, "@type") !== GOOGLE_RETRY_INFO_TYPE) continue;
|
|
200
|
+
const delay = ownDataValue(detail, "retryDelay");
|
|
201
|
+
const match = typeof delay === "string" ? GOOGLE_RETRY_DELAY_VALUE_RE.exec(delay) : null;
|
|
202
|
+
floor = maxDefined(floor, match?.[1] ? Number(match[1]) : void 0);
|
|
203
|
+
}
|
|
204
|
+
return floor;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Reads google.rpc.RetryInfo delays from raw error text or a google.rpc.Status-shaped body
|
|
208
|
+
* in any key order, with a fixed number of descriptor reads and no getters. Pass the
|
|
209
|
+
* untruncated body: Gemini puts RetryInfo after its QuotaFailure details.
|
|
210
|
+
*/
|
|
211
|
+
function parseGoogleRetryDelaySeconds(value) {
|
|
212
|
+
try {
|
|
213
|
+
if (typeof value === "string") return googleRetryDelayTextSeconds(value);
|
|
214
|
+
const response = ownDataValue(value, "response");
|
|
215
|
+
return maxDefined(...[
|
|
216
|
+
value,
|
|
217
|
+
ownDataValue(value, "error"),
|
|
218
|
+
ownDataValue(value, "message"),
|
|
219
|
+
ownDataValue(value, "errorBody"),
|
|
220
|
+
ownDataValue(value, "body"),
|
|
221
|
+
ownDataValue(response, "body"),
|
|
222
|
+
ownDataValue(response, "data")
|
|
223
|
+
].flatMap((candidate) => [googleStatusRetryDelaySeconds(candidate), typeof candidate === "string" ? void 0 : googleStatusRetryDelaySeconds(ownDataValue(candidate, "error"))]));
|
|
224
|
+
} catch {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Retry time for one thrown provider error, before any lossy projection.
|
|
230
|
+
* Explicit instructions (Retry-After headers, Google RetryInfo) win; prose timing is left
|
|
231
|
+
* for text consumers; an exhausted-bucket refill applies only when neither is present.
|
|
232
|
+
*/
|
|
233
|
+
function resolveProviderErrorRetrySeconds(error, nowMs = Date.now()) {
|
|
234
|
+
try {
|
|
235
|
+
const timing = parseRetryAfterErrorTiming(error, nowMs);
|
|
236
|
+
const explicitSeconds = maxDefined(timing?.explicitSeconds, parseGoogleRetryDelaySeconds(error));
|
|
237
|
+
if (explicitSeconds !== void 0 || timing?.resetSeconds === void 0) return explicitSeconds;
|
|
238
|
+
const response = ownDataValue(error, "response");
|
|
239
|
+
return [
|
|
240
|
+
ownDataValue(error, "message"),
|
|
241
|
+
ownDataValue(error, "errorBody"),
|
|
242
|
+
ownDataValue(error, "body"),
|
|
243
|
+
ownDataValue(response, "body"),
|
|
244
|
+
ownDataValue(response, "data"),
|
|
245
|
+
ownDataValue(ownDataValue(error, "error"), "message")
|
|
246
|
+
].some((source) => hasExplicitRetryText(source, nowMs)) ? void 0 : timing.resetSeconds;
|
|
109
247
|
} catch {
|
|
110
248
|
return;
|
|
111
249
|
}
|
|
@@ -164,7 +302,7 @@ function parseHttpDateComponents(components) {
|
|
|
164
302
|
}
|
|
165
303
|
function parseHttpDateCalendarMs(components) {
|
|
166
304
|
const { year, month, day, hours, minutes, seconds } = components;
|
|
167
|
-
if (month === void 0 ||
|
|
305
|
+
if (month === void 0 || year < 1900 || seconds > 60) return;
|
|
168
306
|
const calendarSecond = Math.min(seconds, 59);
|
|
169
307
|
const timestamp = Date.UTC(year, month, day, hours, minutes, calendarSecond);
|
|
170
308
|
const parsedDate = new Date(timestamp);
|
|
@@ -172,4 +310,4 @@ function parseHttpDateCalendarMs(components) {
|
|
|
172
310
|
return seconds === 60 ? timestamp + 1e3 : timestamp;
|
|
173
311
|
}
|
|
174
312
|
//#endregion
|
|
175
|
-
export { parseHttpDateInstant, parseRetryAfterErrorSeconds, parseRetryAfterHeadersSeconds, parseRetryAfterHttpDateMs };
|
|
313
|
+
export { RETRY_AFTER_TEXT_RE, hasExplicitRetryText, parseGoogleRetryDelaySeconds, parseHttpDateInstant, parseRetryAfterErrorSeconds, parseRetryAfterErrorTiming, parseRetryAfterHeadersSeconds, parseRetryAfterHeadersTiming, parseRetryAfterHttpDateMs, parseRetryAfterTextSeconds, resolveProviderErrorRetrySeconds };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import
|
|
3
|
-
import { i as getEventStreamCompletion } from "../event-stream-
|
|
4
|
-
import { a as RegisteredApiProvider, t as ApiProvider } from "../api-registry-
|
|
5
|
-
import { m as getDefaultAiTransportHost } from "../host-
|
|
6
|
-
import "../types-
|
|
7
|
-
import { n as isContextOverflow, t as sanitizeSurrogates } from "../sanitize-unicode-
|
|
8
|
-
import {
|
|
1
|
+
import { G as ProviderStreamOptions, N as ModelThinkingLevel, a as AssistantMessage, at as StreamOptions, d as Context, gt as Usage, k as Model, n as Api, s as AssistantMessageEventStreamContract, tt as SimpleStreamOptions } from "../types-BVdTf0YV.mjs";
|
|
2
|
+
import "../index-Bczt0MnO.mjs";
|
|
3
|
+
import { i as getEventStreamCompletion } from "../event-stream-BYmtRe8-.mjs";
|
|
4
|
+
import { a as RegisteredApiProvider, t as ApiProvider } from "../api-registry-DY2MLUyg.mjs";
|
|
5
|
+
import { m as getDefaultAiTransportHost } from "../host-ccbwPC3A.mjs";
|
|
6
|
+
import "../types-Cb3-5WM9.mjs";
|
|
7
|
+
import { n as isContextOverflow, t as sanitizeSurrogates } from "../sanitize-unicode-BISmUlUv.mjs";
|
|
8
|
+
import { y as parseTerminalToolCallArguments } from "../transport-stream-shared-D3IAU4jn.mjs";
|
|
9
9
|
//#region packages/ai/src/internal/default-runtime.d.ts
|
|
10
10
|
export declare const defaultApiRegistry: {
|
|
11
11
|
registerApiProvider: <TApi extends Api, TOptions extends StreamOptions>(provider: ApiProvider<TApi, TOptions>, sourceId?: string) => void;
|
|
@@ -91,10 +91,9 @@ export declare function registerSessionResourceCleanup(cleanup: SessionResourceC
|
|
|
91
91
|
export declare function cleanupSessionResources(sessionId?: string, owner?: SessionResourceOwner): void;
|
|
92
92
|
//#endregion
|
|
93
93
|
//#region packages/ai/src/utils/deferred-event-buffer.d.ts
|
|
94
|
-
|
|
94
|
+
export declare function createDeferredEventBuffer<T>(sink: {
|
|
95
95
|
push(event: T): void;
|
|
96
|
-
}
|
|
97
|
-
export declare function createDeferredEventBuffer<T>(sink: EventSink<T>, onBufferedEvent?: () => void): {
|
|
96
|
+
}): {
|
|
98
97
|
push(event: T): void;
|
|
99
98
|
flush(): void;
|
|
100
99
|
discard(): void;
|
|
@@ -143,8 +142,9 @@ export type ToolArgumentPreviewSchedule = (accumulatedChars: number) => boolean;
|
|
|
143
142
|
export declare function createToolArgumentPreviewSchedule(): ToolArgumentPreviewSchedule;
|
|
144
143
|
//#endregion
|
|
145
144
|
//#region packages/ai/src/utils/llm-request-activity.d.ts
|
|
146
|
-
|
|
147
|
-
export declare function
|
|
145
|
+
type ActivityListener = (progress: boolean, progressTimeoutMs?: number) => void;
|
|
146
|
+
export declare function notifyLlmRequestActivity(signal: AbortSignal | undefined, progress?: boolean, progressTimeoutMs?: number): void;
|
|
147
|
+
export declare function onLlmRequestActivity(signal: AbortSignal, listener: ActivityListener): () => void;
|
|
148
148
|
//#endregion
|
|
149
149
|
//#region packages/ai/src/utils/oauth/openai-chatgpt-jwt.d.ts
|
|
150
150
|
declare const OPENAI_CODEX_AUTH_CLAIM = "https://api.openai.com/auth";
|
|
@@ -157,39 +157,13 @@ export type OpenAICodexJwtPayload = {
|
|
|
157
157
|
export declare function decodeOpenAICodexJwtPayload(token: string): OpenAICodexJwtPayload | null;
|
|
158
158
|
export declare function resolveOpenAICodexAccountId(token: string): string | null;
|
|
159
159
|
//#endregion
|
|
160
|
-
//#region packages/markdown-core/src/reasoning-tag-parser.d.ts
|
|
161
|
-
type ReasoningTagTextDelta = {
|
|
162
|
-
kind: "text";
|
|
163
|
-
text: string;
|
|
164
|
-
} | {
|
|
165
|
-
kind: "thinking";
|
|
166
|
-
text: string;
|
|
167
|
-
};
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region packages/markdown-core/src/reasoning-tags.d.ts
|
|
170
|
-
interface ReasoningTagTextPartitioner {
|
|
171
|
-
markStrict(): void;
|
|
172
|
-
push(chunk: string): ReasoningTagTextDelta[];
|
|
173
|
-
pushVisible(chunk: string): ReasoningTagTextDelta[];
|
|
174
|
-
flush(options?: {
|
|
175
|
-
recoverUnclosed?: boolean;
|
|
176
|
-
}): ReasoningTagTextDelta[];
|
|
177
|
-
hasPending(): boolean;
|
|
178
|
-
/** Whether more input can change buffered Markdown or reasoning-tag ownership. */
|
|
179
|
-
hasPendingSyntax(): boolean;
|
|
180
|
-
isInsideReasoning(): boolean;
|
|
181
|
-
}
|
|
182
|
-
/** Creates a block-incremental parser that emits only Markdown-stable text. */
|
|
183
|
-
export declare function createReasoningTagTextPartitioner(): ReasoningTagTextPartitioner;
|
|
184
|
-
//#endregion
|
|
185
160
|
//#region packages/ai/src/utils/stream-first-event-timeout.d.ts
|
|
186
|
-
type StreamStage = "responses" | "completions";
|
|
187
161
|
export type FirstStreamEventTimeoutContext = {
|
|
188
162
|
provider?: string;
|
|
189
163
|
api?: string;
|
|
190
164
|
model?: string;
|
|
191
165
|
timeoutMs: number;
|
|
192
|
-
stage?:
|
|
166
|
+
stage?: "responses" | "completions";
|
|
193
167
|
hint?: string;
|
|
194
168
|
abort?: (reason: Error) => void;
|
|
195
169
|
onTimeout?: (reason: Error) => void;
|
|
@@ -231,4 +205,4 @@ export declare function createSseByteGuard(reader: ReadableStreamDefaultReader<U
|
|
|
231
205
|
/** Lazily bound an SDK response while preserving upstream cancellation. */
|
|
232
206
|
export declare function boundResponseBody(response: Response, options: ReadSseStreamWithLimitOptions): Response;
|
|
233
207
|
//#endregion
|
|
234
|
-
export {
|
|
208
|
+
export { complete, completeSimple, getApiProvider, getApiProviders, getEventStreamCompletion, isContextOverflow, parseTerminalToolCallArguments, sanitizeSurrogates, stream, streamSimple };
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { t as createReasoningTagTextPartitioner } from "../reasoning-tag-text-partitioner-DzlRubwU.mjs";
|
|
2
1
|
import { o as getEventStreamCompletion } from "../event-stream-X2gmsUWv.mjs";
|
|
3
|
-
import { r as createApiRegistry, t as createLlmRuntime } from "../stream-
|
|
4
|
-
import { A as getSupportedThinkingLevels, D as applyProviderReportedUsageCost, E as headersToRecord, O as calculateCost, j as modelsAreEqual, k as clampThinkingLevel } from "../host-
|
|
2
|
+
import { r as createApiRegistry, t as createLlmRuntime } from "../stream-DrtAWu7c.mjs";
|
|
3
|
+
import { A as getSupportedThinkingLevels, D as applyProviderReportedUsageCost, E as headersToRecord, O as calculateCost, j as modelsAreEqual, k as clampThinkingLevel } from "../host-DX7ORpeH.mjs";
|
|
5
4
|
import { n as getSessionResourceOwnerId, r as registerSessionResourceCleanup, t as cleanupSessionResources } from "../session-resources-vKvGIE3J.mjs";
|
|
6
5
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-CRGuMONI.mjs";
|
|
7
|
-
import { A as
|
|
8
|
-
import { n as getEnvApiKey, t as findEnvKeys } from "../env-api-keys-
|
|
9
|
-
import { t as createDeferredEventBuffer } from "../deferred-event-buffer-
|
|
10
|
-
import { n as onLlmRequestActivity, t as notifyLlmRequestActivity } from "../llm-request-activity-
|
|
11
|
-
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-
|
|
6
|
+
import { A as parseStreamingJson, D as shortHash, O as createToolArgumentPreviewSchedule, _ as parseTerminalToolCallArguments, j as repairJson, k as parseJsonWithRepair } from "../transport-stream-shared-D2uFMhMc.mjs";
|
|
7
|
+
import { n as getEnvApiKey, t as findEnvKeys } from "../env-api-keys-BuHc86ya.mjs";
|
|
8
|
+
import { t as createDeferredEventBuffer } from "../deferred-event-buffer-tIGkTkTm.mjs";
|
|
9
|
+
import { n as onLlmRequestActivity, t as notifyLlmRequestActivity } from "../llm-request-activity-DzaHoRAU.mjs";
|
|
10
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-B7RcufAV.mjs";
|
|
12
11
|
import { n as createSseByteGuard, t as boundResponseBody } from "../streaming-byte-guard-DBXr1XYn.mjs";
|
|
13
12
|
import { n as resolveOpenAICodexAccountId, t as decodeOpenAICodexJwtPayload } from "../openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
14
|
-
import { t as isContextOverflow } from "../overflow-
|
|
13
|
+
import { t as isContextOverflow } from "../overflow-CpApyjG2.mjs";
|
|
15
14
|
//#region packages/ai/src/internal/default-runtime.ts
|
|
16
15
|
const DEFAULT_RUNTIME_KEY = Symbol.for("openclaw.ai.defaultRuntime");
|
|
17
16
|
function resolveDefaultRuntime() {
|
|
@@ -31,4 +30,4 @@ const defaultLlmRuntime = defaultRuntime.runtime;
|
|
|
31
30
|
const { getApiProvider, getApiProviders } = defaultApiRegistry;
|
|
32
31
|
const { stream, complete, streamSimple, completeSimple } = defaultLlmRuntime;
|
|
33
32
|
//#endregion
|
|
34
|
-
export { applyProviderReportedUsageCost, boundResponseBody, calculateCost, clampThinkingLevel, cleanupSessionResources, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError,
|
|
33
|
+
export { applyProviderReportedUsageCost, boundResponseBody, calculateCost, clampThinkingLevel, cleanupSessionResources, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createSseByteGuard, createToolArgumentPreviewSchedule, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getEventStreamCompletion, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSessionResourceOwnerId, getSupportedThinkingLevels, headersToRecord, isContextOverflow, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, parseTerminalToolCallArguments, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, withFirstStreamEventTimeout };
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { O as Message,
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import "../types-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { O as Message, a as AssistantMessage, ct as ThinkingBudgets, d as Context, k as Model, n as Api, tt as SimpleStreamOptions, ut as ThinkingLevel, z as PreparedSystemPrompt } from "../types-BVdTf0YV.mjs";
|
|
2
|
+
import "../index-Bczt0MnO.mjs";
|
|
3
|
+
import { a as readAssistantThinkingAppend } from "../event-stream-BYmtRe8-.mjs";
|
|
4
|
+
import "../types-Cb3-5WM9.mjs";
|
|
5
|
+
import { u as ProviderStreamOptions } from "../provider-types-B1e98js5.mjs";
|
|
6
|
+
import { f as preparedRequestSuffix } from "../provider-options-Mo8NM5d1.mjs";
|
|
7
|
+
import { serializeModelRequestBody } from "./model-request-body.mjs";
|
|
8
|
+
import { r as matchesContextOverflowMessage, t as sanitizeSurrogates } from "../sanitize-unicode-BISmUlUv.mjs";
|
|
7
9
|
import { i as projectProviderError } from "../provider-error-CnaWYTRY.mjs";
|
|
8
|
-
import {
|
|
10
|
+
import { m as iterateSseFrames } from "../transport-stream-shared-D3IAU4jn.mjs";
|
|
11
|
+
import { i as projectPreparedDiagnosticValue, n as isCredentialFieldName } from "../credential-redaction-DrgndwTJ.mjs";
|
|
9
12
|
import { n as normalizeStructuredPromptSection, r as sortPromptCacheToolsByName, t as normalizePromptCapabilityIds } from "../prompt-cache-stability-Cwcjv_fx.mjs";
|
|
10
13
|
//#region packages/ai/src/providers/simple-options.d.ts
|
|
11
14
|
type FirstEventStreamOptions = {
|
|
12
15
|
firstEventTimeoutMs?: number;
|
|
13
16
|
onFirstEventTimeout?: (reason: Error) => void;
|
|
14
17
|
};
|
|
15
|
-
export declare function buildBaseOptions(model: Model, options?: SimpleStreamOptions, apiKey?: string):
|
|
18
|
+
export declare function buildBaseOptions(model: Model, options?: SimpleStreamOptions & ProviderStreamOptions, apiKey?: string): ProviderStreamOptions & FirstEventStreamOptions & Pick<SimpleStreamOptions, "serviceTier">;
|
|
16
19
|
export declare function clampMaxTokensToModel(model: Model, requestedMaxTokens: number): number;
|
|
17
20
|
export declare function clampMaxTokensToModel(model: Model, requestedMaxTokens: number | undefined): number | undefined;
|
|
18
21
|
export declare function clampReasoning(effort: ThinkingLevel): Exclude<ThinkingLevel, "xhigh">;
|
|
@@ -28,12 +31,11 @@ export declare function extractToolResultBlockText(block: unknown): string | und
|
|
|
28
31
|
export declare function extractToolResultText(blocks: readonly unknown[], options?: {
|
|
29
32
|
includeStructured?: boolean;
|
|
30
33
|
}): string;
|
|
31
|
-
|
|
34
|
+
/** Describe media that cannot be represented on the target provider wire. */
|
|
35
|
+
export declare function describeUnsupportedToolResultMedia(blocks: readonly unknown[], support: {
|
|
32
36
|
images: boolean;
|
|
33
37
|
audio: boolean;
|
|
34
|
-
};
|
|
35
|
-
/** Describe media that cannot be represented on the target provider wire. */
|
|
36
|
-
export declare function describeUnsupportedToolResultMedia(blocks: readonly unknown[], support: ToolResultMediaSupport): string | undefined;
|
|
38
|
+
}): string | undefined;
|
|
37
39
|
export declare function formatToolResultText(params: {
|
|
38
40
|
text: string;
|
|
39
41
|
mediaPlaceholder?: string;
|
|
@@ -59,6 +61,7 @@ export declare function transformMessages<TApi extends Api>(messages: Message[],
|
|
|
59
61
|
type AssistantTurnLike = {
|
|
60
62
|
role?: unknown;
|
|
61
63
|
stopReason?: unknown;
|
|
64
|
+
errorCode?: unknown;
|
|
62
65
|
content?: unknown;
|
|
63
66
|
};
|
|
64
67
|
/** Returns true when an assistant turn contains only provider reasoning and blank text. */
|
|
@@ -68,17 +71,20 @@ export declare function isReasoningOnlyLengthAssistantTurn(message: AssistantTur
|
|
|
68
71
|
export declare const STREAM_ERROR_FALLBACK_TEXT = "[assistant turn failed before producing content]";
|
|
69
72
|
export declare function isStreamErrorFallbackContent(content: unknown): boolean;
|
|
70
73
|
export declare const FAILED_ASSISTANT_REPLAY_TEXT = "[This turn failed before it completed. Do not redo its work without confirming with the user first.]";
|
|
71
|
-
type FailedAssistantReplay = "keep" | "drop" | "marker";
|
|
72
74
|
/** Classify failed source content before model-specific thinking or tool projection. */
|
|
73
75
|
export declare function resolveFailedAssistantReplay(message: AssistantTurnLike, options: {
|
|
74
76
|
pairingAware: boolean;
|
|
75
|
-
}):
|
|
77
|
+
}): "keep" | "drop" | "marker";
|
|
76
78
|
//#endregion
|
|
77
79
|
//#region packages/ai/src/utils/system-prompt-cache-boundary.d.ts
|
|
78
80
|
export declare const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
79
81
|
/** Producer-delimited Runtime facts; instructions must remain outside this region. */
|
|
80
82
|
export declare const SYSTEM_PROMPT_RELOCATABLE_BOUNDARY = "\n<!-- OPENCLAW-RELOCATABLE-BOUNDARY -->\n";
|
|
81
83
|
export declare const SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END = "\n<!-- /OPENCLAW-RELOCATABLE-BOUNDARY -->";
|
|
84
|
+
/** Carry this fact with its session; interleaved sessions cannot evict a live revision. */
|
|
85
|
+
export declare function prepareSystemPrompt(text: string, previous?: PreparedSystemPrompt): PreparedSystemPrompt;
|
|
86
|
+
/** A stream's boundary transform carries the revision it actually passes downstream. */
|
|
87
|
+
export declare function createSystemPromptCacheBoundaryStripper(): <T extends Pick<Context, "systemPrompt" | "preparedSystemPrompt">>(context: T) => T;
|
|
82
88
|
export declare function stripSystemPromptCacheBoundary(text: string): string;
|
|
83
89
|
/** Reject ambiguous markers from workspace or hook text instead of moving instructions. */
|
|
84
90
|
export declare function splitSystemPromptRelocatableBoundary(text: string): {
|
|
@@ -97,16 +103,6 @@ export declare function prependSystemPromptAdditionAfterCacheBoundary(params: {
|
|
|
97
103
|
systemPromptAddition?: string;
|
|
98
104
|
}): string;
|
|
99
105
|
//#endregion
|
|
100
|
-
//#region packages/ai/src/utils/tls-certificate-errors.d.ts
|
|
101
|
-
export type TlsCertificateErrorKind = "certificate_invalid" | "hostname_mismatch";
|
|
102
|
-
export type TlsCertificateErrorDetails = {
|
|
103
|
-
kind: TlsCertificateErrorKind;
|
|
104
|
-
code?: string;
|
|
105
|
-
message: string;
|
|
106
|
-
};
|
|
107
|
-
/** Classify deterministic Node/OpenSSL certificate validation failures. */
|
|
108
|
-
export declare function inspectTlsCertificateError(error: unknown): TlsCertificateErrorDetails | null;
|
|
109
|
-
//#endregion
|
|
110
106
|
//#region packages/ai/src/providers/github-copilot-request-facts.d.ts
|
|
111
107
|
/** Request facts shared by Copilot transports; identity headers remain plugin-owned. */
|
|
112
108
|
export declare function projectCopilotRequestFacts(messages: readonly {
|
|
@@ -119,4 +115,4 @@ export declare function projectCopilotRequestFacts(messages: readonly {
|
|
|
119
115
|
hasImages: boolean;
|
|
120
116
|
};
|
|
121
117
|
//#endregion
|
|
122
|
-
export {
|
|
118
|
+
export { isCredentialFieldName, iterateSseFrames, matchesContextOverflowMessage, normalizePromptCapabilityIds, normalizeStructuredPromptSection, preparedRequestSuffix, projectPreparedDiagnosticValue, projectProviderError, readAssistantThinkingAppend, sanitizeSurrogates, serializeModelRequestBody, sortPromptCacheToolsByName };
|
package/dist/internal/shared.mjs
CHANGED
|
@@ -1,100 +1,11 @@
|
|
|
1
1
|
import { s as readAssistantThinkingAppend } from "../event-stream-X2gmsUWv.mjs";
|
|
2
|
-
import { M as hasMediaPayload, N as isImageWithMediaPayload, c as transformMessages, d as hasOnlyAssistantReasoningContent, f as isReasoningOnlyLengthAssistantTurn, l as FAILED_ASSISTANT_REPLAY_TEXT, m as resolveFailedAssistantReplay, p as isStreamErrorFallbackContent, u as STREAM_ERROR_FALLBACK_TEXT } from "../host-
|
|
3
|
-
import { i as isCredentialFieldName, n as projectProviderError,
|
|
2
|
+
import { M as hasMediaPayload, N as isImageWithMediaPayload, c as transformMessages, d as hasOnlyAssistantReasoningContent, f as isReasoningOnlyLengthAssistantTurn, l as FAILED_ASSISTANT_REPLAY_TEXT, m as resolveFailedAssistantReplay, p as isStreamErrorFallbackContent, u as STREAM_ERROR_FALLBACK_TEXT } from "../host-DX7ORpeH.mjs";
|
|
3
|
+
import { i as isCredentialFieldName, n as projectProviderError, o as projectPreparedDiagnosticValue } from "../provider-error-DD-fo4Rz.mjs";
|
|
4
4
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-CRGuMONI.mjs";
|
|
5
|
-
import { n as normalizeStructuredPromptSection, r as sortPromptCacheToolsByName, t as normalizePromptCapabilityIds } from "../prompt-cache-stability-
|
|
6
|
-
import { C as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"CERT_CHAIN_TOO_LONG",
|
|
13
|
-
"CERT_HAS_EXPIRED",
|
|
14
|
-
"CERT_NOT_YET_VALID",
|
|
15
|
-
"CERT_REJECTED",
|
|
16
|
-
"CERT_REVOKED",
|
|
17
|
-
"CERT_SIGNATURE_FAILURE",
|
|
18
|
-
"CERT_UNTRUSTED",
|
|
19
|
-
"CRL_HAS_EXPIRED",
|
|
20
|
-
"CRL_NOT_YET_VALID",
|
|
21
|
-
"CRL_SIGNATURE_FAILURE",
|
|
22
|
-
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
23
|
-
"ERROR_IN_CERT_NOT_AFTER_FIELD",
|
|
24
|
-
"ERROR_IN_CERT_NOT_BEFORE_FIELD",
|
|
25
|
-
"ERROR_IN_CRL_LAST_UPDATE_FIELD",
|
|
26
|
-
"ERROR_IN_CRL_NEXT_UPDATE_FIELD",
|
|
27
|
-
"INVALID_CA",
|
|
28
|
-
"INVALID_PURPOSE",
|
|
29
|
-
"PATH_LENGTH_EXCEEDED",
|
|
30
|
-
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
31
|
-
"UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY",
|
|
32
|
-
"UNABLE_TO_DECRYPT_CERT_SIGNATURE",
|
|
33
|
-
"UNABLE_TO_DECRYPT_CRL_SIGNATURE",
|
|
34
|
-
"UNABLE_TO_GET_CRL",
|
|
35
|
-
"UNABLE_TO_GET_ISSUER_CERT",
|
|
36
|
-
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
37
|
-
"UNABLE_TO_VERIFY_LEAF_SIGNATURE"
|
|
38
|
-
]);
|
|
39
|
-
const HOSTNAME_MISMATCH_PATTERNS = [
|
|
40
|
-
/hostname\/ip does not match certificate(?:'s)? altnames/i,
|
|
41
|
-
/hostname mismatch/i,
|
|
42
|
-
/host: .+ is not in the cert(?:ificate)?(?:'s)? altnames/i
|
|
43
|
-
];
|
|
44
|
-
const CERTIFICATE_INVALID_PATTERNS = [
|
|
45
|
-
/certificate has expired/i,
|
|
46
|
-
/certificate is not yet valid/i,
|
|
47
|
-
/self[- ]signed certificate/i,
|
|
48
|
-
/unable to get local issuer certificate/i,
|
|
49
|
-
/unable to verify the first certificate/i
|
|
50
|
-
];
|
|
51
|
-
const MAX_TLS_ERROR_DEPTH = 8;
|
|
52
|
-
function classifyCode(code) {
|
|
53
|
-
if (HOSTNAME_MISMATCH_CODES.has(code)) return "hostname_mismatch";
|
|
54
|
-
return CERTIFICATE_INVALID_CODES.has(code) ? "certificate_invalid" : null;
|
|
55
|
-
}
|
|
56
|
-
function classifyMessage(message) {
|
|
57
|
-
if (HOSTNAME_MISMATCH_PATTERNS.some((pattern) => pattern.test(message))) return "hostname_mismatch";
|
|
58
|
-
return CERTIFICATE_INVALID_PATTERNS.some((pattern) => pattern.test(message)) ? "certificate_invalid" : null;
|
|
59
|
-
}
|
|
60
|
-
function inspectTlsCertificateErrorInternal(error, seen, depth) {
|
|
61
|
-
if (depth > MAX_TLS_ERROR_DEPTH) return null;
|
|
62
|
-
if (typeof error === "string") {
|
|
63
|
-
const kind = classifyMessage(error);
|
|
64
|
-
return kind ? {
|
|
65
|
-
kind,
|
|
66
|
-
message: error
|
|
67
|
-
} : null;
|
|
68
|
-
}
|
|
69
|
-
if (!error || typeof error !== "object" || seen.has(error)) return null;
|
|
70
|
-
seen.add(error);
|
|
71
|
-
const candidate = error;
|
|
72
|
-
const code = typeof candidate.code === "string" ? candidate.code.trim().toUpperCase() : void 0;
|
|
73
|
-
const message = typeof candidate.message === "string" && candidate.message.trim() ? candidate.message : void 0;
|
|
74
|
-
const codeKind = code ? classifyCode(code) : null;
|
|
75
|
-
if (code && codeKind) return {
|
|
76
|
-
kind: codeKind,
|
|
77
|
-
code,
|
|
78
|
-
message: message ?? code
|
|
79
|
-
};
|
|
80
|
-
const nestedErrors = Array.isArray(candidate.errors) ? candidate.errors : [];
|
|
81
|
-
for (const nested of [
|
|
82
|
-
candidate.cause,
|
|
83
|
-
candidate.error,
|
|
84
|
-
...nestedErrors
|
|
85
|
-
]) {
|
|
86
|
-
const details = inspectTlsCertificateErrorInternal(nested, seen, depth + 1);
|
|
87
|
-
if (details) return details;
|
|
88
|
-
}
|
|
89
|
-
const messageKind = message ? classifyMessage(message) : null;
|
|
90
|
-
return messageKind && message ? {
|
|
91
|
-
kind: messageKind,
|
|
92
|
-
message
|
|
93
|
-
} : null;
|
|
94
|
-
}
|
|
95
|
-
/** Classify deterministic Node/OpenSSL certificate validation failures. */
|
|
96
|
-
function inspectTlsCertificateError(error) {
|
|
97
|
-
return inspectTlsCertificateErrorInternal(error, /* @__PURE__ */ new Set(), 0);
|
|
98
|
-
}
|
|
99
|
-
//#endregion
|
|
100
|
-
export { FAILED_ASSISTANT_REPLAY_TEXT, STREAM_ERROR_FALLBACK_TEXT, SYSTEM_PROMPT_CACHE_BOUNDARY, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END, adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToModel, clampReasoning, createDiagnosticRecord, describeToolResultMediaPlaceholder, describeUnsupportedToolResultMedia, ensureSystemPromptCacheBoundary, extractToolResultBlockText, extractToolResultText, formatToolResultText, hasMediaPayload, hasOnlyAssistantReasoningContent, inspectTlsCertificateError, isCredentialFieldName, isImageWithMediaPayload, isReasoningOnlyLengthAssistantTurn, isStreamErrorFallbackContent, matchesContextOverflowMessage, normalizePromptCapabilityIds, normalizeStructuredPromptSection, preparedRequestSuffix, prependSystemPromptAdditionAfterCacheBoundary, projectCopilotRequestFacts, projectProviderError, readAssistantThinkingAppend, resolveFailedAssistantReplay, sanitizeSurrogates, serializeModelRequestBody, sortPromptCacheToolsByName, splitSystemPromptCacheBoundary, splitSystemPromptRelocatableBoundary, stripSystemPromptCacheBoundary, stripSystemPromptRelocatableBoundary, transformMessages };
|
|
5
|
+
import { n as normalizeStructuredPromptSection, r as sortPromptCacheToolsByName, t as normalizePromptCapabilityIds } from "../prompt-cache-stability-w-ICeyOI.mjs";
|
|
6
|
+
import { C as stripSystemPromptCacheBoundary, S as splitSystemPromptRelocatableBoundary, _ as createSystemPromptCacheBoundaryStripper, a as describeToolResultMediaPlaceholder, b as prependSystemPromptAdditionAfterCacheBoundary, c as extractToolResultText, f as preparedRequestSuffix, g as SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END, h as SYSTEM_PROMPT_RELOCATABLE_BOUNDARY, i as clampReasoning, l as formatToolResultText, m as SYSTEM_PROMPT_CACHE_BOUNDARY, n as buildBaseOptions, o as describeUnsupportedToolResultMedia, r as clampMaxTokensToModel, s as extractToolResultBlockText, t as adjustMaxTokensForThinking, v as ensureSystemPromptCacheBoundary, w as stripSystemPromptRelocatableBoundary, x as splitSystemPromptCacheBoundary, y as prepareSystemPrompt } from "../simple-options-tLSeECry.mjs";
|
|
7
|
+
import { f as iterateSseFrames } from "../transport-stream-shared-D2uFMhMc.mjs";
|
|
8
|
+
import { serializeModelRequestBody } from "./model-request-body.mjs";
|
|
9
|
+
import { t as projectCopilotRequestFacts } from "../github-copilot-request-facts-BZ_EMo7X.mjs";
|
|
10
|
+
import { n as matchesContextOverflowMessage } from "../overflow-CpApyjG2.mjs";
|
|
11
|
+
export { FAILED_ASSISTANT_REPLAY_TEXT, STREAM_ERROR_FALLBACK_TEXT, SYSTEM_PROMPT_CACHE_BOUNDARY, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY, SYSTEM_PROMPT_RELOCATABLE_BOUNDARY_END, adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToModel, clampReasoning, createSystemPromptCacheBoundaryStripper, describeToolResultMediaPlaceholder, describeUnsupportedToolResultMedia, ensureSystemPromptCacheBoundary, extractToolResultBlockText, extractToolResultText, formatToolResultText, hasMediaPayload, hasOnlyAssistantReasoningContent, isCredentialFieldName, isImageWithMediaPayload, isReasoningOnlyLengthAssistantTurn, isStreamErrorFallbackContent, iterateSseFrames, matchesContextOverflowMessage, normalizePromptCapabilityIds, normalizeStructuredPromptSection, prepareSystemPrompt, preparedRequestSuffix, prependSystemPromptAdditionAfterCacheBoundary, projectCopilotRequestFacts, projectPreparedDiagnosticValue, projectProviderError, readAssistantThinkingAppend, resolveFailedAssistantReplay, sanitizeSurrogates, serializeModelRequestBody, sortPromptCacheToolsByName, splitSystemPromptCacheBoundary, splitSystemPromptRelocatableBoundary, stripSystemPromptCacheBoundary, stripSystemPromptRelocatableBoundary, transformMessages };
|