@openclaw/ai 2026.11.3 → 2026.11.5-beta.2
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 -8
- package/dist/.source-module-urls/fe058cc430242ce2ab0dfbcbe153e240a52cf9c3072c3dc0a73e5f956b6ba49b.json +1 -0
- package/dist/anthropic-DEKgalVg.mjs +182 -0
- package/dist/{anthropic-payload-policy-C0ki72BT.d.mts → anthropic-payload-policy-CXCJ5Pmj.d.mts} +21 -4
- package/dist/{anthropic-stream-reducer-yWDb5Cct.mjs → anthropic-stream-lifecycle-DF2qVvg1.mjs} +845 -649
- package/dist/{anthropic-tool-projection-C2-d1eZ3.d.mts → anthropic-tool-projection-D5DyrL6C.d.mts} +6 -7
- package/dist/{anthropic-tool-projection-DZOKfAmL.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-BvvXzZbi.mjs → azure-openai-responses-DbQV5RTx.mjs} +47 -53
- 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-v7oVEW59.mjs → diagnostics-CloVGQiK.mjs} +27 -20
- 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-Cpi_cLKZ.mjs → google-B1g82bn4.mjs} +7 -8
- package/dist/{google-interactions-CGINbsjO.mjs → google-interactions-Ckr0Z99Z.mjs} +243 -269
- package/dist/{google-messages-DQMgG5yG.mjs → google-messages-A-9d3y5V.mjs} +52 -18
- package/dist/{google-provider-stream-BHd0cST9.mjs → google-provider-stream-CNVh4gpm.mjs} +19 -11
- package/dist/{google-shared-vtag8bj5.mjs → google-shared-WNM86ZcW.mjs} +72 -42
- package/dist/{google-vertex-eKoUnW7N.mjs → google-vertex-CXjleC6g.mjs} +3 -3
- package/dist/{google-video-slots-D8tPH8wX.mjs → google-video-slots-Bxt-OXO8.mjs} +1 -1
- package/dist/{host-CWt55nnF.mjs → host-DX7ORpeH.mjs} +46 -39
- package/dist/{host-jJOffdlW.d.mts → host-ccbwPC3A.d.mts} +17 -9
- package/dist/{host-policy-Dm7PM6AD.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 +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- 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-CU9A4Lg8.mjs → internal/reasoning-tag-text-partitioner.mjs} +313 -111
- package/dist/internal/retry-after.d.mts +2 -2
- package/dist/internal/retry-after.mjs +96 -32
- 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-CjHkvsqR.mjs +3741 -0
- package/dist/{openai.LICENSE → mistral.LICENSE} +1 -1
- 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-BZa3SySh.mjs → openai-chatgpt-responses-CwS5JP7A.mjs} +61 -80
- package/dist/{openai-completions-compat-CBvb2eld.d.mts → openai-completions-compat-CJ-NsDzg.d.mts} +12 -6
- package/dist/{openai-completions-compat-bNQXF1y9.mjs → openai-completions-compat-CstlTQuF.mjs} +74 -50
- package/dist/{openai-completions-CCZ_UHCk.mjs → openai-completions-sj4S-RXQ.mjs} +5 -5
- package/dist/openai-completions-transport-BDAIA0_P.mjs +3406 -0
- package/dist/{openai-prompt-cache-DgjD-UL5.d.mts → openai-prompt-cache-BZGaIWYh.d.mts} +4 -4
- package/dist/{openai-prompt-cache-B9AvdoEo.mjs → openai-prompt-cache-CgDoFhO0.mjs} +5 -4
- package/dist/{openai-responses-compaction-replay-_sUXtcwU.d.mts → openai-responses-compaction-replay-CNHk6k53.d.mts} +4 -4
- package/dist/{openai-responses-contracts-B1nkeLL6.d.mts → openai-responses-contracts-BXMcvO7F.d.mts} +4 -10
- package/dist/{openai-responses-contracts-B5mGAbR6.mjs → openai-responses-contracts-xU-n9AJJ.mjs} +36 -37
- package/dist/{openai-responses-endpoint-CfKR6N5f.mjs → openai-responses-endpoint-DCkURKS0.mjs} +55 -8
- package/dist/openai-responses-ev_c6oTy.mjs +89 -0
- package/dist/{openai-responses-payload-policy-BzM52TTH.d.mts → openai-responses-payload-policy-DyE30gdD.d.mts} +7 -7
- package/dist/{openai-responses-request-lifecycle-CTqHc02t.mjs → openai-responses-request-lifecycle-BuOs0mwI.mjs} +12 -26
- package/dist/{openai-responses-shared-wx9v1MCn.mjs → openai-responses-shared-BmRQnUPP.mjs} +633 -1493
- package/dist/{openai-responses-terminal-usage-CpVjkqn-.d.mts → openai-responses-terminal-usage-D7IhRA6i.d.mts} +9 -3
- package/dist/{openai-tool-schema-BTEU2xmN.mjs → openai-tool-schema-CsoYgnWy.mjs} +97 -122
- package/dist/otel-Buswj0Mf.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-DAzsyi49.d.mts → provider-options-Mo8NM5d1.d.mts} +16 -5
- package/dist/{provider-replay-context-4vxI7p4V.mjs → provider-replay-context-xyU7-CiT.mjs} +2 -2
- package/dist/provider-transcript-transform-DtaxNcC1.mjs +32 -0
- package/dist/{provider-transport-turn-state-D_GjPJHe.mjs → provider-transport-turn-state-BIS8maBK.mjs} +4 -4
- package/dist/{provider-types-CWl4VXvE.d.mts → provider-types-B1e98js5.d.mts} +3 -3
- package/dist/provider-types.d.mts +7 -6
- 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-BrmTv0jL.d.mts → retry-after-DnHBlFS2.d.mts} +21 -1
- 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-xJkqrG_E.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-C4YDqhFj.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-CvK1yQg7.mjs +582 -0
- package/dist/{tool-schema-json-projection-B1sTYwfH.mjs → tool-schema-json-projection-BQpiJlXJ.mjs} +53 -69
- package/dist/{transport-stream-shared-lhgkTOz3.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-DwOpuTjL.mjs → transport-utils-Da_39MYi.mjs} +23 -38
- package/dist/transports.d.mts +42 -39
- package/dist/transports.mjs +215 -296
- 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-lueA8LUg.mjs +0 -221
- package/dist/assistant-output-BnQm3fov.mjs +0 -47
- package/dist/event-stream-CDpFza-M.d.mts +0 -1
- package/dist/index-DSprYWaz.d.mts +0 -185
- package/dist/mistral-CQ7aoWg2.mjs +0 -512
- package/dist/model-request-body-BD5vy4rP.d.mts +0 -17
- package/dist/openai-CiRi-nVE.mjs +0 -20077
- package/dist/openai-completions-transport-DFvSBbUT.mjs +0 -10881
- package/dist/openai-responses-DQsZKUoI.mjs +0 -87
- package/dist/rolldown-runtime-B4iAMlE-.mjs +0 -35
- package/dist/types-CBJthzJX.d.mts +0 -1
- package/dist/ws.LICENSE +0 -20
|
@@ -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,22 +129,27 @@ 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
|
+
};
|
|
109
149
|
} catch {
|
|
110
150
|
return;
|
|
111
151
|
}
|
|
112
152
|
}
|
|
113
|
-
function maxDefined(...values) {
|
|
114
|
-
let floor;
|
|
115
|
-
for (const value of values) if (value !== void 0) floor = Math.max(floor ?? 0, value);
|
|
116
|
-
return floor;
|
|
117
|
-
}
|
|
118
153
|
/** Provider prose such as "Please try again in 6s", "retry in 32s" or "Retry-After: 7". */
|
|
119
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;
|
|
120
155
|
const RETRY_TEXT_NUMBER_RE = /^(\d+(?:\.\d+)?|Infinity)\s*([a-z]+)?\b/i;
|
|
@@ -139,6 +174,12 @@ function parseRetryAfterTextSeconds(valueText, nowMs = Date.now()) {
|
|
|
139
174
|
const retryAtMs = parseRetryAfterHttpDateMs(valueText, nowMs);
|
|
140
175
|
return retryAtMs === void 0 ? void 0 : Math.max(0, (retryAtMs - nowMs) / MS_PER_SECOND);
|
|
141
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
|
+
}
|
|
142
183
|
const GOOGLE_RETRY_DELAY_TEXT_RE = /"retryDelay"\s*:\s*"(\d+(?:\.\d{1,9})?)s"/g;
|
|
143
184
|
const GOOGLE_RETRY_DELAY_VALUE_RE = /^(\d+(?:\.\d{1,9})?)s$/;
|
|
144
185
|
const GOOGLE_RETRY_INFO_TYPE = "type.googleapis.com/google.rpc.RetryInfo";
|
|
@@ -184,6 +225,29 @@ function parseGoogleRetryDelaySeconds(value) {
|
|
|
184
225
|
return;
|
|
185
226
|
}
|
|
186
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;
|
|
247
|
+
} catch {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
187
251
|
/** Round leap seconds forward for Retry-After so an unrepresentable instant cannot retry early. */
|
|
188
252
|
function parseRetryAfterHttpDateMs(value, nowMs = Date.now()) {
|
|
189
253
|
return parseHttpDateInstant(value, nowMs)?.timestampMs;
|
|
@@ -238,7 +302,7 @@ function parseHttpDateComponents(components) {
|
|
|
238
302
|
}
|
|
239
303
|
function parseHttpDateCalendarMs(components) {
|
|
240
304
|
const { year, month, day, hours, minutes, seconds } = components;
|
|
241
|
-
if (month === void 0 ||
|
|
305
|
+
if (month === void 0 || year < 1900 || seconds > 60) return;
|
|
242
306
|
const calendarSecond = Math.min(seconds, 59);
|
|
243
307
|
const timestamp = Date.UTC(year, month, day, hours, minutes, calendarSecond);
|
|
244
308
|
const parsedDate = new Date(timestamp);
|
|
@@ -246,4 +310,4 @@ function parseHttpDateCalendarMs(components) {
|
|
|
246
310
|
return seconds === 60 ? timestamp + 1e3 : timestamp;
|
|
247
311
|
}
|
|
248
312
|
//#endregion
|
|
249
|
-
export { RETRY_AFTER_TEXT_RE, parseGoogleRetryDelaySeconds, parseHttpDateInstant, parseRetryAfterErrorSeconds, parseRetryAfterHeadersSeconds, parseRetryAfterHttpDateMs, parseRetryAfterTextSeconds };
|
|
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
1
|
import { o as getEventStreamCompletion } from "../event-stream-X2gmsUWv.mjs";
|
|
2
|
-
import { r as createApiRegistry, t as createLlmRuntime } from "../stream-
|
|
3
|
-
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";
|
|
4
4
|
import { n as getSessionResourceOwnerId, r as registerSessionResourceCleanup, t as cleanupSessionResources } from "../session-resources-vKvGIE3J.mjs";
|
|
5
5
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-CRGuMONI.mjs";
|
|
6
|
-
import { A as
|
|
7
|
-
import { n as getEnvApiKey, t as findEnvKeys } from "../env-api-keys-
|
|
8
|
-
import { t as createDeferredEventBuffer } from "../deferred-event-buffer-
|
|
9
|
-
import { n as onLlmRequestActivity, t as notifyLlmRequestActivity } from "../llm-request-activity-
|
|
10
|
-
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";
|
|
11
11
|
import { n as createSseByteGuard, t as boundResponseBody } from "../streaming-byte-guard-DBXr1XYn.mjs";
|
|
12
|
-
import { t as createReasoningTagTextPartitioner } from "../reasoning-tag-text-partitioner-CU9A4Lg8.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 };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as prepareAnthropicInputSchema } from "../anthropic-tool-projection-
|
|
1
|
+
import { h as OpenAIToolProjection } from "../provider-options-Mo8NM5d1.mjs";
|
|
2
|
+
import { a as prepareAnthropicInputSchema } from "../anthropic-tool-projection-D5DyrL6C.mjs";
|
|
3
3
|
import { TSchema } from "typebox";
|
|
4
4
|
//#region packages/ai/src/providers/agent-tools-parameter-schema.d.ts
|
|
5
5
|
/**
|
|
@@ -47,7 +47,9 @@ export declare function findLlamacppGbnfSchemaViolations(schema: unknown, path:
|
|
|
47
47
|
//#endregion
|
|
48
48
|
//#region packages/ai/src/providers/openai-tool-schema-compat.d.ts
|
|
49
49
|
/** Repairs recoverable OpenAI tool-schema shapes before canonical normalization. */
|
|
50
|
-
export declare function normalizeOpenAIStrictCompatSchema(schema: unknown): TSchema;
|
|
50
|
+
export declare function normalizeOpenAIStrictCompatSchema(schema: unknown, toolName?: string): TSchema;
|
|
51
|
+
/** Finds nested open dictionaries whose keys compatibility normalization closes. */
|
|
52
|
+
export declare function findCompatClosedObjectPaths(schema: unknown, path: string): string[];
|
|
51
53
|
/** Finds schema paths that violate OpenAI strict tool-schema requirements. */
|
|
52
54
|
export declare function findOpenAIStrictSchemaViolations(schema: unknown, path: string, options?: {
|
|
53
55
|
requireObjectRoot?: boolean;
|
|
@@ -64,13 +66,12 @@ export declare function normalizeStrictOpenAIJsonSchema(schema: unknown, modelCo
|
|
|
64
66
|
export declare function normalizeOpenAIStrictToolParameters<T>(schema: T, strict: boolean, modelCompat?: ToolSchemaCompatInput | null): T;
|
|
65
67
|
/** Returns whether a schema already satisfies OpenAI strict tool-schema constraints. */
|
|
66
68
|
export declare function isStrictOpenAIJsonSchemaCompatible(schema: unknown): boolean;
|
|
67
|
-
|
|
69
|
+
/** Returns strict-schema diagnostics for an already materialized OpenAI tool projection. */
|
|
70
|
+
export declare function findOpenAIStrictToolProjectionDiagnostics(projection: OpenAIToolProjection): {
|
|
68
71
|
toolIndex: number;
|
|
69
72
|
toolName?: string;
|
|
70
73
|
violations: string[];
|
|
71
|
-
};
|
|
72
|
-
/** Returns strict-schema diagnostics for an already materialized OpenAI tool projection. */
|
|
73
|
-
export declare function findOpenAIStrictToolProjectionDiagnostics(projection: OpenAIToolProjection): OpenAIStrictToolSchemaDiagnostic[];
|
|
74
|
+
}[];
|
|
74
75
|
/** Resolves strict mode for the projected tools that will be emitted in the request payload. */
|
|
75
76
|
export declare function resolveOpenAIProjectedToolsStrictToolFlag(projection: OpenAIToolProjection, strict: boolean | null | undefined): boolean | undefined;
|
|
76
77
|
//#endregion
|
|
@@ -81,7 +82,7 @@ type OpenAIFunctionDescriptor = {
|
|
|
81
82
|
parameters: Record<string, unknown>;
|
|
82
83
|
strict?: boolean;
|
|
83
84
|
};
|
|
84
|
-
|
|
85
|
+
export declare function prepareOpenAIFunctionTool(name: string, description: string | undefined, parameters: Record<string, unknown>, strict: boolean | undefined, mutableParameters?: boolean): {
|
|
85
86
|
responses: OpenAIFunctionDescriptor & {
|
|
86
87
|
type: "function";
|
|
87
88
|
};
|
|
@@ -90,8 +91,6 @@ type PreparedOpenAIFunctionTool = {
|
|
|
90
91
|
function: OpenAIFunctionDescriptor;
|
|
91
92
|
};
|
|
92
93
|
};
|
|
93
|
-
/** Reuse wire descriptors only when their parameter owner published immutable JSON. */
|
|
94
|
-
export declare function prepareOpenAIFunctionTool(name: string, description: string | undefined, parameters: Record<string, unknown>, strict: boolean | undefined): PreparedOpenAIFunctionTool;
|
|
95
94
|
//#endregion
|
|
96
95
|
//#region packages/ai/src/providers/schema-keyword-strip.d.ts
|
|
97
96
|
/** Remove schema keywords unsupported by a target provider/tool surface. */
|
|
@@ -131,6 +130,7 @@ type PublishedRuntimeToolInputSchema = {
|
|
|
131
130
|
readonly projection: RuntimeToolInputSchemaProjection;
|
|
132
131
|
readonly json: string;
|
|
133
132
|
readonly fingerprint: string;
|
|
133
|
+
readonly canonicalFingerprint: string;
|
|
134
134
|
};
|
|
135
135
|
export declare function getPublishedRuntimeToolInputSchema(schema: unknown): PublishedRuntimeToolInputSchema | undefined;
|
|
136
136
|
/** Only an owner's detached JSON publication can bypass later schema traversals. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as prepareAnthropicInputSchema } from "../anthropic-tool-projection-
|
|
3
|
-
import { _ as
|
|
4
|
-
export { GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, MAX_TOOL_SCHEMA_DEPTH, SCHEMA_MAP_KEYS, SCHEMA_NESTED_KEYS, cleanSchemaForGemini, cleanSchemaForLlamacppGbnf, extractToolSchemaModelCompat, findLlamacppGbnfSchemaViolations, findOpenAIStrictSchemaViolations, findOpenAIStrictToolProjectionDiagnostics, getPublishedRuntimeToolInputSchema, inheritToolSchemaTruncation, isStrictOpenAIJsonSchemaCompatible, normalizeOpenAIStrictCompatSchema, normalizeOpenAIStrictToolParameters, normalizeStrictOpenAIJsonSchema, normalizeToolParameterSchema, prepareAnthropicInputSchema, prepareOpenAIFunctionTool, projectRuntimeToolInputSchema, publishRuntimeToolInputSchema, reportToolSchemaTruncation, resolveOpenAIProjectedToolsStrictToolFlag, resolveUnsupportedToolSchemaKeywords, shouldOmitEmptyArrayItems, stripUnsupportedSchemaKeywords, toolSchemaChildPosition, truncateToolSchemaDepth, wasToolSchemaTruncated };
|
|
1
|
+
import { d as MAX_TOOL_SCHEMA_DEPTH, f as inheritToolSchemaTruncation, g as wasToolSchemaTruncated, h as truncateToolSchemaDepth, i as publishRuntimeToolInputSchema, m as toolSchemaChildPosition, p as reportToolSchemaTruncation, r as projectRuntimeToolInputSchema, t as getPublishedRuntimeToolInputSchema, v as SCHEMA_MAP_KEYS, y as SCHEMA_NESTED_KEYS } from "../tool-schema-json-projection-BQpiJlXJ.mjs";
|
|
2
|
+
import { r as prepareAnthropicInputSchema } from "../anthropic-tool-projection-dGRfr4iT.mjs";
|
|
3
|
+
import { _ as cleanSchemaForLlamacppGbnf, a as resolveOpenAIProjectedToolsStrictToolFlag, b as cleanSchemaForGemini, c as normalizeOpenAIStrictCompatSchema, d as resolveUnsupportedToolSchemaKeywords, f as shouldOmitEmptyArrayItems, g as LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, h as stripUnsupportedSchemaKeywords, i as normalizeStrictOpenAIJsonSchema, l as extractToolSchemaModelCompat, n as isStrictOpenAIJsonSchemaCompatible, o as findCompatClosedObjectPaths, r as normalizeOpenAIStrictToolParameters, s as findOpenAIStrictSchemaViolations, t as findOpenAIStrictToolProjectionDiagnostics, u as normalizeToolParameterSchema, v as findLlamacppGbnfSchemaViolations, x as prepareOpenAIFunctionTool, y as GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS } from "../openai-tool-schema-CsoYgnWy.mjs";
|
|
4
|
+
export { GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, MAX_TOOL_SCHEMA_DEPTH, SCHEMA_MAP_KEYS, SCHEMA_NESTED_KEYS, cleanSchemaForGemini, cleanSchemaForLlamacppGbnf, extractToolSchemaModelCompat, findCompatClosedObjectPaths, findLlamacppGbnfSchemaViolations, findOpenAIStrictSchemaViolations, findOpenAIStrictToolProjectionDiagnostics, getPublishedRuntimeToolInputSchema, inheritToolSchemaTruncation, isStrictOpenAIJsonSchemaCompatible, normalizeOpenAIStrictCompatSchema, normalizeOpenAIStrictToolParameters, normalizeStrictOpenAIJsonSchema, normalizeToolParameterSchema, prepareAnthropicInputSchema, prepareOpenAIFunctionTool, projectRuntimeToolInputSchema, publishRuntimeToolInputSchema, reportToolSchemaTruncation, resolveOpenAIProjectedToolsStrictToolFlag, resolveUnsupportedToolSchemaKeywords, shouldOmitEmptyArrayItems, stripUnsupportedSchemaKeywords, toolSchemaChildPosition, truncateToolSchemaDepth, wasToolSchemaTruncated };
|