@openclaw/ai 2026.9.2 → 2026.9.3
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 +3 -2
- package/dist/anthropic-CZy5U0NY.mjs +376 -0
- package/dist/{anthropic-payload-policy-d46X2pR0.d.mts → anthropic-payload-policy-wuRCb6MH.d.mts} +16 -6
- package/dist/{anthropic-compaction-replay-DB2FGLQc.mjs → anthropic-stream-reducer-B_yo_7pf.mjs} +923 -181
- package/dist/{api-registry-DWtPjzyn.d.mts → api-registry-CB1-1oQ2.d.mts} +2 -2
- package/dist/assistant-output-iqnlJCV2.mjs +16 -0
- package/dist/assistant-text-phase-C20rxWwP.mjs +55 -0
- package/dist/{azure-openai-responses-C5bZRfAP.mjs → azure-openai-responses-Crpa40QR.mjs} +5 -5
- package/dist/{base64-CEFBpSkN.mjs → base64-D-su8YVo.mjs} +1 -27
- package/dist/{diagnostics-DfFyKeX_.mjs → diagnostics-dV98PqIy.mjs} +96 -21
- package/dist/diagnostics.d.mts +3 -1
- package/dist/diagnostics.mjs +3 -3
- package/dist/{event-stream-BhT5T1Ay.d.mts → event-stream-C1Z2piyk.d.mts} +11 -3
- package/dist/{event-stream-BgDvQeum.mjs → event-stream-D8PARQfL.mjs} +45 -1
- package/dist/event-stream-I_GlBsuZ.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{github-copilot-headers-NCJtz9i0.mjs → github-copilot-headers-B37TB3rB.mjs} +3 -10
- package/dist/github-copilot-request-facts-BTEBMeOv.mjs +16 -0
- package/dist/{google-4qeuE8iX.mjs → google-BDPriaVe.mjs} +10 -10
- package/dist/google-messages-CVn9eFpF.mjs +449 -0
- package/dist/google-shared-BedY23XS.mjs +185 -0
- package/dist/{google-vertex-O9BcnB6X.mjs → google-vertex-DMz8XQCn.mjs} +7 -6
- package/dist/{host-CEvLw30U.mjs → host-CWuF-sS3.mjs} +44 -39
- package/dist/{host-DjzGmdZ2.d.mts → host-DK3wmS3e.d.mts} +3 -3
- package/dist/host-policy-CAopLRKA.mjs +37 -0
- package/dist/{index-FnHM2FcI.d.mts → index-CQ6LTHw8.d.mts} +3 -3
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +4 -4
- package/dist/internal/anthropic.d.mts +7 -7
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/google-model-family.d.mts +5 -0
- package/dist/internal/google-model-family.mjs +15 -0
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +1 -1
- package/dist/internal/openai.d.mts +8 -103
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/retry-after.d.mts +2 -4
- package/dist/internal/retry-after.mjs +57 -8
- package/dist/internal/runtime.d.mts +7 -6
- package/dist/internal/runtime.mjs +8 -7
- package/dist/internal/shared.d.mts +14 -3
- package/dist/internal/shared.mjs +6 -4
- package/dist/internal/tool-schema.d.mts +63 -0
- package/dist/internal/tool-schema.mjs +3 -0
- package/dist/{json-parse-BuAJEbdW.mjs → json-parse-Dw_hnxsA.mjs} +1 -1
- package/dist/{mistral-Tb6oalqH.mjs → mistral--m-Jm6VZ.mjs} +13 -37
- package/dist/model-transport-url-DKocrEsb.d.mts +28 -0
- package/dist/{openai-chatgpt-responses-yUXjPNfu.mjs → openai-chatgpt-responses-nDZccFW-.mjs} +48 -38
- package/dist/openai-completions-KuoZyx0d.mjs +187 -0
- package/dist/{openai-completions-compat-CpjYUArk.d.mts → openai-completions-compat-CXn3T1we.d.mts} +26 -4
- package/dist/{openai-completions-stream-BsrBe3Gg.mjs → openai-completions-stream-BQk3SkLD.mjs} +622 -452
- package/dist/openai-prompt-cache-BI0rkM-5.mjs +220 -0
- package/dist/openai-prompt-cache-rrutvqxq.d.mts +16 -0
- package/dist/openai-provider-client-ha_WxTyj.mjs +24 -0
- package/dist/openai-reasoning-effort-BK7FbcLT.mjs +167 -0
- package/dist/{openai-responses-CCL41ALM.mjs → openai-responses-D99dOzKI.mjs} +14 -29
- package/dist/{openai-responses-compaction-window-BMVHFOtq.mjs → openai-responses-compaction-window-D5jbzCi3.mjs} +7 -170
- package/dist/{openai-responses-contracts-rF5DDRNS.d.mts → openai-responses-contracts-B55afwRo.d.mts} +3 -3
- package/dist/{openai-responses-prompt-observer-internal-D0bhBfgL.mjs → openai-responses-prompt-observer-internal-tApyTLVu.mjs} +3 -3
- package/dist/{openai-responses-shared-Bmma_3Qc.mjs → openai-responses-shared-ZyQEzS5i.mjs} +44 -115
- package/dist/openai-tool-projection-793cE3QX.d.mts +37 -0
- package/dist/{openai-tool-schema-_pTAJqKF.mjs → openai-tool-schema-CzjyYXun.mjs} +38 -556
- package/dist/openai-tool-schema-ynZBgqW-.d.mts +38 -0
- package/dist/openai-transport-params-DNasp2fU.mjs +674 -0
- package/dist/{provider-error-9TraxGvt.mjs → provider-error-C6TbKiey.mjs} +23 -6
- package/dist/{provider-options-Bcc_p-TU.d.mts → provider-options-BXr9Ec83.d.mts} +4 -39
- package/dist/{provider-transcript-transform-BaMbI1hr.mjs → provider-transcript-transform-pPmUIwKt.mjs} +1 -1
- package/dist/provider-types-CAV0Og3m.d.mts +29 -0
- package/dist/provider-types.d.mts +6 -31
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-DLCNXki6.mjs → reasoning-tag-text-partitioner-BQBi4B9d.mjs} +19 -12
- package/dist/record-coerce-DwRYMj3t.mjs +32 -0
- package/dist/retry-after-CdCURCVg.d.mts +15 -0
- package/dist/{sanitize-unicode-D6xUvZaS.mjs → sanitize-unicode-Bb-v9meu.mjs} +1 -1
- package/dist/session-affinity-CCH7eYdB.mjs +20 -0
- package/dist/{simple-options-BjHCCh4v.mjs → simple-options-tcKOqnpF.mjs} +3 -3
- package/dist/{src-2qBGKg8O.mjs → src-B2Q_6G8V.mjs} +1 -1
- package/dist/{stream-first-event-timeout-DcNjoFQE.mjs → stream-first-event-timeout-2hfrquuz.mjs} +1 -1
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{string-normalization--fwJ4S2q.mjs → string-normalization-CmLIasuf.mjs} +1 -1
- package/dist/{tool-schema-json-projection-mJhXDcyz.mjs → tool-schema-json-projection-ClptDdAO.mjs} +2 -38
- package/dist/{transport-stream-shared-CZqMhfIw.mjs → transport-stream-shared-Cu3ZPhNW.mjs} +5 -5
- package/dist/{transport-stream-shared-xnaqxmbP.d.mts → transport-stream-shared-DOxpGJ-H.d.mts} +4 -4
- package/dist/transport-utils-CCooe-cr.mjs +121 -0
- package/dist/transports.d.mts +113 -41
- package/dist/transports.mjs +162 -1276
- package/dist/types-BADKjDBI.d.mts +1 -0
- package/dist/{types-CJ1-Ht7A.d.mts → types-Dy1q0CSu.d.mts} +72 -57
- package/dist/types.d.mts +5 -5
- package/dist/types.mjs +3 -3
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-CJZtym2g.mjs → validation-BDzVDnTs.mjs} +9 -1
- package/dist/{validation-AKZBDGQd.d.mts → validation-CaFUZN9B.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +13 -3
- package/dist/anthropic-BDdqdVLK.mjs +0 -886
- package/dist/event-stream-zctLx0yr.d.mts +0 -1
- package/dist/google-shared-CWeG8RIl.mjs +0 -636
- package/dist/google-thinking-level-C-V3tecN.mjs +0 -9
- package/dist/openai-completions-BIUV3RDT.mjs +0 -403
- package/dist/openai-prompt-cache-CGnVB74a.mjs +0 -21
- package/dist/openai-prompt-cache-CNoIfHYC.d.mts +0 -16
- package/dist/transport-utils-7il795_9.mjs +0 -138
- package/dist/types-3Lnm-QSJ.d.mts +0 -1
- package/dist/utf16-slice-qz3nsy87.mjs +0 -84
|
@@ -34,10 +34,55 @@ const HTTP_DATE_LONG_WEEKDAY_INDEX = new Map([
|
|
|
34
34
|
const IMF_FIXDATE_RE = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d{2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d{2}):(\d{2}):(\d{2}) GMT$/;
|
|
35
35
|
const OBSOLETE_RFC850_DATE_RE = /^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d{2})-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d{2}) (\d{2}):(\d{2}):(\d{2}) GMT$/;
|
|
36
36
|
const OBSOLETE_ASCTIME_DATE_RE = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{2}| \d) (\d{2}):(\d{2}):(\d{2}) (\d{4})$/;
|
|
37
|
-
|
|
37
|
+
function ownDataValue(value, key) {
|
|
38
|
+
return value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, key)?.value : void 0;
|
|
39
|
+
}
|
|
40
|
+
/** Reads only retry timing metadata, without invoking provider getters or serialization hooks. */
|
|
41
|
+
function parseRetryAfterHeadersSeconds(headers, nowMs = Date.now()) {
|
|
42
|
+
if (!headers || typeof headers !== "object") return;
|
|
43
|
+
try {
|
|
44
|
+
let entries;
|
|
45
|
+
try {
|
|
46
|
+
entries = ["retry-after", "retry-after-ms"].map((key) => [key, Headers.prototype.get.call(headers, key)]);
|
|
47
|
+
} catch {
|
|
48
|
+
entries = Object.getOwnPropertyNames(headers).flatMap((key) => {
|
|
49
|
+
const name = key.toLowerCase();
|
|
50
|
+
return name === "retry-after" || name === "retry-after-ms" ? [[name, ownDataValue(headers, key)]] : [];
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
let floor;
|
|
54
|
+
for (const [key, value] of entries) {
|
|
55
|
+
const text = typeof value === "string" ? value.trim() : typeof value === "number" ? String(value) : "";
|
|
56
|
+
const milliseconds = key === "retry-after-ms";
|
|
57
|
+
const numeric = typeof value === "number" ? value >= 0 && (milliseconds || Number.isInteger(value) || value === Infinity) : (milliseconds ? /^\d+(?:\.\d+)?$/ : /^\d+$/).test(text);
|
|
58
|
+
const number = typeof value === "number" ? value : Number(text);
|
|
59
|
+
const retryAt = !numeric && !milliseconds ? parseRetryAfterHttpDateMs(text, nowMs) : void 0;
|
|
60
|
+
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);
|
|
61
|
+
if (seconds !== void 0) floor = Math.max(floor ?? 0, seconds);
|
|
62
|
+
}
|
|
63
|
+
return floor;
|
|
64
|
+
} catch {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** SDK errors carry native response headers separately from their error body. */
|
|
69
|
+
function parseRetryAfterErrorSeconds(error, nowMs = Date.now()) {
|
|
70
|
+
try {
|
|
71
|
+
const direct = parseRetryAfterHeadersSeconds(ownDataValue(error, "headers"), nowMs);
|
|
72
|
+
const response = parseRetryAfterHeadersSeconds(ownDataValue(ownDataValue(error, "response"), "headers"), nowMs);
|
|
73
|
+
return direct === void 0 && response === void 0 ? void 0 : Math.max(direct ?? 0, response ?? 0);
|
|
74
|
+
} catch {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Round leap seconds forward for Retry-After so an unrepresentable instant cannot retry early. */
|
|
38
79
|
function parseRetryAfterHttpDateMs(value, nowMs = Date.now()) {
|
|
80
|
+
return parseHttpDateInstant(value, nowMs)?.timestampMs;
|
|
81
|
+
}
|
|
82
|
+
/** Parse all three HTTP-date forms while retaining leap-second ordering. */
|
|
83
|
+
function parseHttpDateInstant(value, nowMs = Date.now()) {
|
|
39
84
|
const imfFixdate = IMF_FIXDATE_RE.exec(value);
|
|
40
|
-
if (imfFixdate) return
|
|
85
|
+
if (imfFixdate) return parseHttpDateComponents({
|
|
41
86
|
weekday: HTTP_DATE_SHORT_WEEKDAY_INDEX.get(imfFixdate[1] ?? ""),
|
|
42
87
|
year: Number.parseInt(imfFixdate[4] ?? "", 10),
|
|
43
88
|
month: HTTP_DATE_MONTH_INDEX.get(imfFixdate[3] ?? ""),
|
|
@@ -65,13 +110,13 @@ function parseRetryAfterHttpDateMs(value, nowMs = Date.now()) {
|
|
|
65
110
|
...components
|
|
66
111
|
});
|
|
67
112
|
if (candidate === void 0) return;
|
|
68
|
-
return
|
|
113
|
+
return parseHttpDateComponents({
|
|
69
114
|
year: candidate > Date.UTC(now.getUTCFullYear() + 50, now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds()) ? candidateYear - 100 : candidateYear,
|
|
70
115
|
...components
|
|
71
116
|
});
|
|
72
117
|
}
|
|
73
118
|
const asctimeDate = OBSOLETE_ASCTIME_DATE_RE.exec(value);
|
|
74
|
-
if (asctimeDate) return
|
|
119
|
+
if (asctimeDate) return parseHttpDateComponents({
|
|
75
120
|
weekday: HTTP_DATE_SHORT_WEEKDAY_INDEX.get(asctimeDate[1] ?? ""),
|
|
76
121
|
year: Number.parseInt(asctimeDate[7] ?? "", 10),
|
|
77
122
|
month: HTTP_DATE_MONTH_INDEX.get(asctimeDate[2] ?? ""),
|
|
@@ -81,12 +126,16 @@ function parseRetryAfterHttpDateMs(value, nowMs = Date.now()) {
|
|
|
81
126
|
seconds: Number.parseInt(asctimeDate[6] ?? "", 10)
|
|
82
127
|
});
|
|
83
128
|
}
|
|
84
|
-
function
|
|
129
|
+
function parseHttpDateComponents(components) {
|
|
85
130
|
const timestamp = parseHttpDateCalendarMs(components);
|
|
86
131
|
if (timestamp === void 0) return;
|
|
87
|
-
const
|
|
132
|
+
const leapSecond = components.seconds === 60;
|
|
133
|
+
const weekdayTimestamp = leapSecond ? timestamp - 1e3 : timestamp;
|
|
88
134
|
if (new Date(weekdayTimestamp).getUTCDay() !== components.weekday) return;
|
|
89
|
-
return
|
|
135
|
+
return {
|
|
136
|
+
timestampMs: timestamp,
|
|
137
|
+
leapSecond
|
|
138
|
+
};
|
|
90
139
|
}
|
|
91
140
|
function parseHttpDateCalendarMs(components) {
|
|
92
141
|
const { year, month, day, hours, minutes, seconds } = components;
|
|
@@ -98,4 +147,4 @@ function parseHttpDateCalendarMs(components) {
|
|
|
98
147
|
return seconds === 60 ? timestamp + 1e3 : timestamp;
|
|
99
148
|
}
|
|
100
149
|
//#endregion
|
|
101
|
-
export { parseRetryAfterHttpDateMs };
|
|
150
|
+
export { parseHttpDateInstant, parseRetryAfterErrorSeconds, parseRetryAfterHeadersSeconds, parseRetryAfterHttpDateMs };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import "../index-
|
|
2
|
-
import { A as ModelThinkingLevel, D as Model, J as StreamOptions, V as ProviderStreamOptions, W as SimpleStreamOptions, a as AssistantMessage, at as Usage, d as Context, n as Api, s as AssistantMessageEventStreamContract } from "../types-
|
|
3
|
-
import {
|
|
4
|
-
import "../
|
|
1
|
+
import "../index-CQ6LTHw8.mjs";
|
|
2
|
+
import { A as ModelThinkingLevel, D as Model, J as StreamOptions, V as ProviderStreamOptions, W as SimpleStreamOptions, a as AssistantMessage, at as Usage, d as Context, n as Api, s as AssistantMessageEventStreamContract } from "../types-Dy1q0CSu.mjs";
|
|
3
|
+
import { i as getEventStreamCompletion } from "../event-stream-C1Z2piyk.mjs";
|
|
4
|
+
import { a as RegisteredApiProvider, t as ApiProvider } from "../api-registry-CB1-1oQ2.mjs";
|
|
5
|
+
import "../types-BADKjDBI.mjs";
|
|
5
6
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-BZiVbGwK.mjs";
|
|
6
|
-
import { C as FirstStreamEventInternalOptions, D as getFirstStreamEventTimeoutHandler, E as createFirstStreamEventTimeoutError, O as getFirstStreamEventTimeoutMs, S as FirstStreamEventAbortController, T as createFirstStreamEventAbortController, g as parseTerminalToolCallArguments, k as withFirstStreamEventTimeout, w as FirstStreamEventTimeoutContext } from "../transport-stream-shared-
|
|
7
|
+
import { C as FirstStreamEventInternalOptions, D as getFirstStreamEventTimeoutHandler, E as createFirstStreamEventTimeoutError, O as getFirstStreamEventTimeoutMs, S as FirstStreamEventAbortController, T as createFirstStreamEventAbortController, g as parseTerminalToolCallArguments, k as withFirstStreamEventTimeout, w as FirstStreamEventTimeoutContext } from "../transport-stream-shared-DOxpGJ-H.mjs";
|
|
7
8
|
//#region packages/ai/src/internal/default-runtime.d.ts
|
|
8
9
|
export declare const defaultApiRegistry: {
|
|
9
10
|
registerApiProvider: <TApi extends Api, TOptions extends StreamOptions>(provider: ApiProvider<TApi, TOptions>, sourceId?: string) => void;
|
|
@@ -246,4 +247,4 @@ export type SseByteGuard = {
|
|
|
246
247
|
};
|
|
247
248
|
export declare function createSseByteGuard(reader: ReadableStreamDefaultReader<Uint8Array>, opts: ReadSseStreamWithLimitOptions): SseByteGuard;
|
|
248
249
|
//#endregion
|
|
249
|
-
export { FirstStreamEventAbortController, FirstStreamEventInternalOptions, FirstStreamEventTimeoutContext, type ReasoningTagTextDelta, type ReasoningTagTextPartitioner, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, parseTerminalToolCallArguments, sanitizeSurrogates, withFirstStreamEventTimeout };
|
|
250
|
+
export { FirstStreamEventAbortController, FirstStreamEventInternalOptions, FirstStreamEventTimeoutContext, type ReasoningTagTextDelta, type ReasoningTagTextPartitioner, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, getEventStreamCompletion, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, parseTerminalToolCallArguments, sanitizeSurrogates, withFirstStreamEventTimeout };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { a as isProviderRefusalAssistantError } from "../diagnostics-CPeq9F7y.mjs";
|
|
2
|
+
import { a as getEventStreamCompletion } from "../event-stream-D8PARQfL.mjs";
|
|
2
3
|
import { n as createApiRegistry, t as createLlmRuntime } from "../stream-CREqxHgU.mjs";
|
|
3
|
-
import { a as getSupportedThinkingLevels, i as clampThinkingLevel, n as applyProviderReportedUsageCost, o as modelsAreEqual, r as calculateCost, t as sanitizeSurrogates } from "../sanitize-unicode-
|
|
4
|
-
import { t as createReasoningTagTextPartitioner } from "../reasoning-tag-text-partitioner-
|
|
4
|
+
import { a as getSupportedThinkingLevels, i as clampThinkingLevel, n as applyProviderReportedUsageCost, o as modelsAreEqual, r as calculateCost, t as sanitizeSurrogates } from "../sanitize-unicode-Bb-v9meu.mjs";
|
|
5
|
+
import { t as createReasoningTagTextPartitioner } from "../reasoning-tag-text-partitioner-BQBi4B9d.mjs";
|
|
5
6
|
import { n as getEnvApiKey, t as findEnvKeys } from "../env-api-keys-bktO00EJ.mjs";
|
|
6
|
-
import { C as headersToRecord, m as parseTerminalToolCallArguments } from "../transport-stream-shared-
|
|
7
|
+
import { C as headersToRecord, m as parseTerminalToolCallArguments } from "../transport-stream-shared-Cu3ZPhNW.mjs";
|
|
7
8
|
import { t as createDeferredEventBuffer } from "../deferred-event-buffer-DAvyP7qA.mjs";
|
|
8
|
-
import { i as repairJson, n as parseJsonWithRepair, r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "../json-parse-BuAJEbdW.mjs";
|
|
9
|
-
import { n as onLlmRequestActivity, t as notifyLlmRequestActivity } from "../llm-request-activity-BjtkplhG.mjs";
|
|
10
9
|
import { t as shortHash } from "../hash-CHgqbJmD.mjs";
|
|
11
|
-
import {
|
|
10
|
+
import { i as repairJson, n as parseJsonWithRepair, r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "../json-parse-Dw_hnxsA.mjs";
|
|
11
|
+
import { n as onLlmRequestActivity, t as notifyLlmRequestActivity } from "../llm-request-activity-BjtkplhG.mjs";
|
|
12
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-2hfrquuz.mjs";
|
|
12
13
|
import { t as createSseByteGuard } from "../streaming-byte-guard-CC-HMn_u.mjs";
|
|
13
14
|
import { n as registerSessionResourceCleanup, t as cleanupSessionResources } from "../session-resources-CkR4WWy1.mjs";
|
|
14
15
|
import { n as resolveOpenAICodexAccountId, t as decodeOpenAICodexJwtPayload } from "../openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
@@ -200,4 +201,4 @@ function isContextOverflow(message, contextWindow) {
|
|
|
200
201
|
return false;
|
|
201
202
|
}
|
|
202
203
|
//#endregion
|
|
203
|
-
export { applyProviderReportedUsageCost, calculateCost, clampThinkingLevel, cleanupSessionResources, clearApiProviders, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createReasoningTagTextPartitioner, createSseByteGuard, createToolArgumentPreviewSchedule, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSupportedThinkingLevels, headersToRecord, isConfiguredContextSizeOverflowError, isContextOverflow, matchesContextOverflowMessage, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, parseTerminalToolCallArguments, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, withFirstStreamEventTimeout };
|
|
204
|
+
export { applyProviderReportedUsageCost, calculateCost, clampThinkingLevel, cleanupSessionResources, clearApiProviders, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createReasoningTagTextPartitioner, createSseByteGuard, createToolArgumentPreviewSchedule, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getEventStreamCompletion, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSupportedThinkingLevels, headersToRecord, isConfiguredContextSizeOverflowError, isContextOverflow, matchesContextOverflowMessage, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, parseTerminalToolCallArguments, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, withFirstStreamEventTimeout };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { $ as ThinkingLevel, D as Model, E as Message, J as StreamOptions, W as SimpleStreamOptions, Z as ThinkingBudgets, a as AssistantMessage, n as Api } from "../types-
|
|
2
|
-
import "../
|
|
1
|
+
import { $ as ThinkingLevel, D as Model, E as Message, J as StreamOptions, W as SimpleStreamOptions, Z as ThinkingBudgets, a as AssistantMessage, n as Api } from "../types-Dy1q0CSu.mjs";
|
|
2
|
+
import { a as readAssistantThinkingAppend } from "../event-stream-C1Z2piyk.mjs";
|
|
3
|
+
import "../types-BADKjDBI.mjs";
|
|
3
4
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-BZiVbGwK.mjs";
|
|
4
5
|
import { n as normalizeStructuredPromptSection, r as sortPromptCacheToolsByName, t as normalizePromptCapabilityIds } from "../prompt-cache-stability-Cwcjv_fx.mjs";
|
|
5
6
|
//#region packages/ai/src/providers/simple-options.d.ts
|
|
@@ -71,4 +72,14 @@ export type TlsCertificateErrorDetails = {
|
|
|
71
72
|
/** Classify deterministic Node/OpenSSL certificate validation failures. */
|
|
72
73
|
export declare function inspectTlsCertificateError(error: unknown): TlsCertificateErrorDetails | null;
|
|
73
74
|
//#endregion
|
|
74
|
-
|
|
75
|
+
//#region packages/ai/src/providers/github-copilot-request-facts.d.ts
|
|
76
|
+
/** Request facts shared by Copilot transports; identity headers remain plugin-owned. */
|
|
77
|
+
export declare function projectCopilotRequestFacts(messages: readonly {
|
|
78
|
+
role: string;
|
|
79
|
+
content: unknown;
|
|
80
|
+
}[], contentMode: "direct" | "nested", hasImages?: boolean): {
|
|
81
|
+
initiator: "user" | "agent";
|
|
82
|
+
hasImages: boolean;
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
export { normalizePromptCapabilityIds, normalizeStructuredPromptSection, readAssistantThinkingAppend, sanitizeSurrogates, sortPromptCacheToolsByName };
|
package/dist/internal/shared.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { o as readAssistantThinkingAppend } from "../event-stream-D8PARQfL.mjs";
|
|
2
|
+
import { t as sanitizeSurrogates } from "../sanitize-unicode-Bb-v9meu.mjs";
|
|
3
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, i as transformMessages, l as formatToolResultText, o as describeUnsupportedToolResultMedia, s as extractToolResultBlockText, u as hasMediaPayload } from "../host-CWuF-sS3.mjs";
|
|
4
|
+
import { c as ensureSystemPromptCacheBoundary, d as stripSystemPromptCacheBoundary, f as normalizePromptCapabilityIds, i as clampReasoning, l as prependSystemPromptAdditionAfterCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, p as normalizeStructuredPromptSection, r as clampMaxTokensToModel, s as SYSTEM_PROMPT_CACHE_BOUNDARY, t as adjustMaxTokensForThinking, u as splitSystemPromptCacheBoundary } from "../simple-options-tcKOqnpF.mjs";
|
|
5
|
+
import { t as projectCopilotRequestFacts } from "../github-copilot-request-facts-BTEBMeOv.mjs";
|
|
4
6
|
//#region packages/ai/src/utils/tls-certificate-errors.ts
|
|
5
7
|
const HOSTNAME_MISMATCH_CODES = /* @__PURE__ */ new Set(["ERR_TLS_CERT_ALTNAME_INVALID", "HOSTNAME_MISMATCH"]);
|
|
6
8
|
const CERTIFICATE_INVALID_CODES = /* @__PURE__ */ new Set([
|
|
@@ -93,4 +95,4 @@ function inspectTlsCertificateError(error) {
|
|
|
93
95
|
return inspectTlsCertificateErrorInternal(error, /* @__PURE__ */ new Set(), 0);
|
|
94
96
|
}
|
|
95
97
|
//#endregion
|
|
96
|
-
export { SYSTEM_PROMPT_CACHE_BOUNDARY, adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToModel, clampReasoning, describeToolResultMediaPlaceholder, describeUnsupportedToolResultMedia, ensureSystemPromptCacheBoundary, extractToolResultBlockText, extractToolResultText, formatToolResultText, hasMediaPayload, inspectTlsCertificateError, isImageWithMediaPayload, normalizePromptCapabilityIds, normalizeStructuredPromptSection, prependSystemPromptAdditionAfterCacheBoundary, sanitizeSurrogates, sortPromptCacheToolsByName, splitSystemPromptCacheBoundary, stripSystemPromptCacheBoundary, transformMessages };
|
|
98
|
+
export { SYSTEM_PROMPT_CACHE_BOUNDARY, adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToModel, clampReasoning, describeToolResultMediaPlaceholder, describeUnsupportedToolResultMedia, ensureSystemPromptCacheBoundary, extractToolResultBlockText, extractToolResultText, formatToolResultText, hasMediaPayload, inspectTlsCertificateError, isImageWithMediaPayload, normalizePromptCapabilityIds, normalizeStructuredPromptSection, prependSystemPromptAdditionAfterCacheBoundary, projectCopilotRequestFacts, readAssistantThinkingAppend, sanitizeSurrogates, sortPromptCacheToolsByName, splitSystemPromptCacheBoundary, stripSystemPromptCacheBoundary, transformMessages };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { a as resolveOpenAIProjectedToolsStrictToolFlag, i as normalizeStrictOpenAIJsonSchema, n as isStrictOpenAIJsonSchemaCompatible, o as findOpenAIStrictSchemaViolations, r as normalizeOpenAIStrictToolParameters, s as normalizeOpenAIStrictCompatSchema, t as findOpenAIStrictToolProjectionDiagnostics } from "../openai-tool-schema-ynZBgqW-.mjs";
|
|
2
|
+
import { TSchema } from "typebox";
|
|
3
|
+
//#region packages/ai/src/providers/agent-tools-parameter-schema.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Narrow structural view of the host's model compat config. packages/ai must stay
|
|
6
|
+
* config-agnostic, so only tool-schema-relevant fields are modeled here; the host's
|
|
7
|
+
* ModelCompatConfig remains structurally assignable.
|
|
8
|
+
*/
|
|
9
|
+
export type ToolSchemaModelCompat = {
|
|
10
|
+
toolSchemaProfile?: string;
|
|
11
|
+
unsupportedToolSchemaKeywords?: string[];
|
|
12
|
+
omitEmptyArrayItems?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/** Extracts the compat record whether callers pass a model (`{ compat }`) or the compat itself. */
|
|
15
|
+
export declare function extractToolSchemaModelCompat(modelOrCompat: {
|
|
16
|
+
compat?: unknown;
|
|
17
|
+
} | ToolSchemaModelCompat | undefined): ToolSchemaModelCompat | undefined;
|
|
18
|
+
/** JSON Schema keywords this model/provider rejects in tool schemas. */
|
|
19
|
+
export declare function resolveUnsupportedToolSchemaKeywords(modelOrCompat: {
|
|
20
|
+
compat?: unknown;
|
|
21
|
+
} | ToolSchemaModelCompat | undefined): ReadonlySet<string>;
|
|
22
|
+
/** Whether empty `items: {}` on array schemas must be omitted for this model/provider. */
|
|
23
|
+
export declare function shouldOmitEmptyArrayItems(modelOrCompat: {
|
|
24
|
+
compat?: unknown;
|
|
25
|
+
} | ToolSchemaModelCompat | undefined): boolean;
|
|
26
|
+
export type ToolParameterSchemaOptions = {
|
|
27
|
+
modelProvider?: string;
|
|
28
|
+
modelId?: string;
|
|
29
|
+
modelCompat?: ToolSchemaModelCompat;
|
|
30
|
+
};
|
|
31
|
+
/** Return a provider-compatible JSON schema for a model-facing tool. */
|
|
32
|
+
export declare function normalizeToolParameterSchema(schema: unknown, options?: ToolParameterSchemaOptions): TSchema;
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region packages/ai/src/providers/clean-for-gemini.d.ts
|
|
35
|
+
export declare const GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS: Set<string>;
|
|
36
|
+
export declare function cleanSchemaForGemini(schema: unknown): TSchema;
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region packages/ai/src/providers/clean-for-llamacpp-gbnf.d.ts
|
|
39
|
+
/** llama.cpp rejects grammar repetitions whose expanded rule count reaches 2000. */
|
|
40
|
+
export declare const LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD = 2000;
|
|
41
|
+
/** Removes JSON Schema constraints that llama.cpp cannot compile into GBNF. */
|
|
42
|
+
export declare function cleanSchemaForLlamacppGbnf(schema: unknown): unknown;
|
|
43
|
+
/** Reports schema paths that llama.cpp cannot compile into GBNF. */
|
|
44
|
+
export declare function findLlamacppGbnfSchemaViolations(schema: unknown, path: string): string[];
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region packages/ai/src/providers/schema-keyword-strip.d.ts
|
|
47
|
+
/** Recursively remove schema keywords unsupported by a target provider/tool surface. */
|
|
48
|
+
export declare function stripUnsupportedSchemaKeywords(schema: unknown, unsupportedKeywords: ReadonlySet<string>): unknown;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region packages/ai/src/providers/tool-schema-json-projection.d.ts
|
|
51
|
+
/** JSON-safe schema value used when projecting runtime tool parameters. */
|
|
52
|
+
export type RuntimeToolInputSchemaJson = null | boolean | number | string | RuntimeToolInputSchemaJson[] | {
|
|
53
|
+
[key: string]: RuntimeToolInputSchemaJson;
|
|
54
|
+
};
|
|
55
|
+
/** Projected runtime tool schema plus validation violations. */
|
|
56
|
+
export type RuntimeToolInputSchemaProjection = {
|
|
57
|
+
readonly schema: RuntimeToolInputSchemaJson;
|
|
58
|
+
readonly violations: readonly string[];
|
|
59
|
+
};
|
|
60
|
+
/** Projects one runtime tool input schema to JSON and reports runtime incompatibilities. */
|
|
61
|
+
export declare function projectRuntimeToolInputSchema(schema: unknown, path?: string): RuntimeToolInputSchemaProjection;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { findOpenAIStrictSchemaViolations, findOpenAIStrictToolProjectionDiagnostics, isStrictOpenAIJsonSchemaCompatible, normalizeOpenAIStrictCompatSchema, normalizeOpenAIStrictToolParameters, normalizeStrictOpenAIJsonSchema, resolveOpenAIProjectedToolsStrictToolFlag };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { t as projectRuntimeToolInputSchema } from "../tool-schema-json-projection-ClptDdAO.mjs";
|
|
2
|
+
import { _ as cleanSchemaForGemini, a as resolveOpenAIProjectedToolsStrictToolFlag, c as extractToolSchemaModelCompat, d as shouldOmitEmptyArrayItems, f as stripUnsupportedSchemaKeywords, g as GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, h as findLlamacppGbnfSchemaViolations, i as normalizeStrictOpenAIJsonSchema, l as normalizeToolParameterSchema, m as cleanSchemaForLlamacppGbnf, n as isStrictOpenAIJsonSchemaCompatible, o as findOpenAIStrictSchemaViolations, p as LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, r as normalizeOpenAIStrictToolParameters, s as normalizeOpenAIStrictCompatSchema, t as findOpenAIStrictToolProjectionDiagnostics, u as resolveUnsupportedToolSchemaKeywords } from "../openai-tool-schema-CzjyYXun.mjs";
|
|
3
|
+
export { GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, cleanSchemaForGemini, cleanSchemaForLlamacppGbnf, extractToolSchemaModelCompat, findLlamacppGbnfSchemaViolations, findOpenAIStrictSchemaViolations, findOpenAIStrictToolProjectionDiagnostics, isStrictOpenAIJsonSchemaCompatible, normalizeOpenAIStrictCompatSchema, normalizeOpenAIStrictToolParameters, normalizeStrictOpenAIJsonSchema, normalizeToolParameterSchema, projectRuntimeToolInputSchema, resolveOpenAIProjectedToolsStrictToolFlag, resolveUnsupportedToolSchemaKeywords, shouldOmitEmptyArrayItems, stripUnsupportedSchemaKeywords };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as asNonArrayRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
2
2
|
import { parse } from "partial-json";
|
|
3
3
|
//#region packages/ai/src/utils/json-parse.ts
|
|
4
4
|
const VALID_JSON_ESCAPES = /* @__PURE__ */ new Set([
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
-
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-
|
|
3
|
-
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, l as formatToolResultText, n as getAiTransportHost } from "./host-
|
|
4
|
-
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-
|
|
1
|
+
import { r as appendAssistantThinking, t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
2
|
+
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-Bb-v9meu.mjs";
|
|
3
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, l as formatToolResultText, n as getAiTransportHost } from "./host-CWuF-sS3.mjs";
|
|
4
|
+
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-tcKOqnpF.mjs";
|
|
5
5
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
6
|
-
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments, t as assignTransportErrorDetails } from "./transport-stream-shared-
|
|
7
|
-
import { r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
|
|
8
|
-
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
6
|
+
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments, t as assignTransportErrorDetails } from "./transport-stream-shared-Cu3ZPhNW.mjs";
|
|
9
7
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
10
|
-
import { t as
|
|
8
|
+
import { r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-Dw_hnxsA.mjs";
|
|
9
|
+
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
10
|
+
import { t as createAssistantOutput } from "./assistant-output-iqnlJCV2.mjs";
|
|
11
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-pPmUIwKt.mjs";
|
|
11
12
|
import { t as mapOpenAIStopReason } from "./openai-stop-reason-Drnn_6Qj.mjs";
|
|
12
13
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
13
14
|
import { randomUUID } from "node:crypto";
|
|
@@ -62,7 +63,7 @@ function createBoundedMistralFetcher(maxBytes = MISTRAL_STREAM_BODY_MAX_BYTES, u
|
|
|
62
63
|
const streamMistral = (model, context, options) => {
|
|
63
64
|
const stream = new AssistantMessageEventStream();
|
|
64
65
|
(async () => {
|
|
65
|
-
const output =
|
|
66
|
+
const output = createAssistantOutput(model);
|
|
66
67
|
try {
|
|
67
68
|
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
68
69
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
@@ -151,31 +152,6 @@ const streamSimpleMistral = (model, context, options) => {
|
|
|
151
152
|
reasoningEffort: shouldUseReasoning && usesReasoningEffort(model) ? mapReasoningEffort(model, reasoning) : void 0
|
|
152
153
|
});
|
|
153
154
|
};
|
|
154
|
-
function createOutput(model) {
|
|
155
|
-
return {
|
|
156
|
-
role: "assistant",
|
|
157
|
-
content: [],
|
|
158
|
-
api: model.api,
|
|
159
|
-
provider: model.provider,
|
|
160
|
-
model: model.id,
|
|
161
|
-
usage: {
|
|
162
|
-
input: 0,
|
|
163
|
-
output: 0,
|
|
164
|
-
cacheRead: 0,
|
|
165
|
-
cacheWrite: 0,
|
|
166
|
-
totalTokens: 0,
|
|
167
|
-
cost: {
|
|
168
|
-
input: 0,
|
|
169
|
-
output: 0,
|
|
170
|
-
cacheRead: 0,
|
|
171
|
-
cacheWrite: 0,
|
|
172
|
-
total: 0
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
stopReason: "stop",
|
|
176
|
-
timestamp: Date.now()
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
155
|
function createMistralToolCallIdNormalizer() {
|
|
180
156
|
const idMap = /* @__PURE__ */ new Map();
|
|
181
157
|
const reverseMap = /* @__PURE__ */ new Map();
|
|
@@ -271,7 +247,6 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
271
247
|
const toolCallIndex = params.index;
|
|
272
248
|
const idCandidates = explicitId ? findIdentityCandidates((identity) => identity.explicitIds.has(explicitId), params.usedContentIndexes) : /* @__PURE__ */ new Set();
|
|
273
249
|
const nameCandidates = functionName ? findIdentityCandidates((identity) => identity.functionNames.has(functionName), params.usedContentIndexes) : /* @__PURE__ */ new Set();
|
|
274
|
-
const indexCandidates = toolCallIndex === void 0 ? /* @__PURE__ */ new Set() : findIdentityCandidates((identity) => identity.indexes.has(toolCallIndex), params.usedContentIndexes);
|
|
275
250
|
if (idCandidates.size > 0) {
|
|
276
251
|
let candidates = idCandidates;
|
|
277
252
|
if (nameCandidates.size > 0) candidates = intersectCandidates(candidates, nameCandidates);
|
|
@@ -292,6 +267,7 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
292
267
|
if (indexCompatibleCandidates.size === 0) return;
|
|
293
268
|
return requireSingleCandidate(indexCompatibleCandidates);
|
|
294
269
|
}
|
|
270
|
+
const indexCandidates = toolCallIndex === void 0 ? /* @__PURE__ */ new Set() : findIdentityCandidates((identity) => identity.indexes.has(toolCallIndex), params.usedContentIndexes);
|
|
295
271
|
if (functionName) {
|
|
296
272
|
const namelessCandidates = new Set([...indexCandidates].filter((contentIndex) => {
|
|
297
273
|
const identity = toolBlockIdentities.get(contentIndex);
|
|
@@ -375,7 +351,7 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
375
351
|
continue;
|
|
376
352
|
}
|
|
377
353
|
if (item.type === "thinking") {
|
|
378
|
-
const deltaText = item.thinking.map((part) => "text" in part ? part.text : "").
|
|
354
|
+
const deltaText = item.thinking.map((part) => "text" in part ? part.text : "").join("");
|
|
379
355
|
const thinkingDelta = sanitizeSurrogates(deltaText);
|
|
380
356
|
if (!thinkingDelta) continue;
|
|
381
357
|
if (!currentBlock || currentBlock.type !== "thinking") {
|
|
@@ -391,7 +367,7 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
391
367
|
partial: output
|
|
392
368
|
});
|
|
393
369
|
}
|
|
394
|
-
currentBlock
|
|
370
|
+
appendAssistantThinking(currentBlock, thinkingDelta);
|
|
395
371
|
stream.push({
|
|
396
372
|
type: "thinking_delta",
|
|
397
373
|
contentIndex: blockIndex(),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region packages/ai/src/transports/model-transport-debug.d.ts
|
|
2
|
+
type SubsystemLogger = {
|
|
3
|
+
info(message: string): void;
|
|
4
|
+
debug(message: string): void;
|
|
5
|
+
};
|
|
6
|
+
type ModelTransportDebugEnv = NodeJS.ProcessEnv;
|
|
7
|
+
/** Payload debug detail levels accepted by `OPENCLAW_DEBUG_MODEL_PAYLOAD`. */
|
|
8
|
+
type ModelPayloadDebugMode = "off" | "summary" | "tools" | "full-redacted";
|
|
9
|
+
/** SSE debug detail levels accepted by `OPENCLAW_DEBUG_SSE`. */
|
|
10
|
+
type ModelSseDebugMode = "off" | "events" | "peek";
|
|
11
|
+
/** Resolves model payload debug verbosity from `OPENCLAW_DEBUG_MODEL_PAYLOAD`. */
|
|
12
|
+
declare function resolveModelPayloadDebugMode(env?: ModelTransportDebugEnv): ModelPayloadDebugMode;
|
|
13
|
+
/** Resolves SSE stream debug verbosity from `OPENCLAW_DEBUG_SSE`. */
|
|
14
|
+
declare function resolveModelSseDebugMode(env?: ModelTransportDebugEnv): ModelSseDebugMode;
|
|
15
|
+
/** Emits model-fetch metadata at info level by default; other diagnostics require debug env. */
|
|
16
|
+
declare function emitModelTransportDebug(log: SubsystemLogger, message: string): void;
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region packages/ai/src/transports/model-transport-url.d.ts
|
|
19
|
+
/**
|
|
20
|
+
* Debug formatting helpers for model transport endpoints.
|
|
21
|
+
* Keeps logs useful without exposing credentials, request params, or fragments.
|
|
22
|
+
*/
|
|
23
|
+
/** Return a sanitized URL suitable for logs and diagnostics. */
|
|
24
|
+
declare function formatModelTransportDebugUrl(rawUrl: string): string;
|
|
25
|
+
/** Format a configured base URL for debug output, or the implicit default. */
|
|
26
|
+
declare function formatModelTransportDebugBaseUrl(rawUrl: string | undefined): string;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { resolveModelSseDebugMode as a, resolveModelPayloadDebugMode as i, formatModelTransportDebugUrl as n, emitModelTransportDebug as r, formatModelTransportDebugBaseUrl as t };
|
package/dist/{openai-chatgpt-responses-yUXjPNfu.mjs → openai-chatgpt-responses-nDZccFW-.mjs}
RENAMED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-CPeq9F7y.mjs";
|
|
2
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
3
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
4
|
-
import {
|
|
5
|
-
import { u as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
2
|
+
import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
3
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-CWuF-sS3.mjs";
|
|
4
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-BI0rkM-5.mjs";
|
|
5
|
+
import { l as extractErrorCodeOrErrno, o as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, u as toErrorObject } from "./diagnostics-dV98PqIy.mjs";
|
|
6
|
+
import { s as resolveTimerTimeoutMs } from "./base64-D-su8YVo.mjs";
|
|
7
|
+
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-CCooe-cr.mjs";
|
|
8
|
+
import { parseRetryAfterHeadersSeconds } from "./internal/retry-after.mjs";
|
|
9
|
+
import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-tcKOqnpF.mjs";
|
|
10
|
+
import { _ as createOpenAIProviderAcceptanceHook, v as createOpenAIResponseHook } from "./openai-transport-params-DNasp2fU.mjs";
|
|
9
11
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
10
|
-
import { C as headersToRecord, _ as transportAbortError, p as notifyProviderStreamOpened, t as assignTransportErrorDetails, y as withProviderResponseHook } from "./transport-stream-shared-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
12
|
+
import { C as headersToRecord, _ as transportAbortError, p as notifyProviderStreamOpened, t as assignTransportErrorDetails, y as withProviderResponseHook } from "./transport-stream-shared-Cu3ZPhNW.mjs";
|
|
13
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-2hfrquuz.mjs";
|
|
14
|
+
import { l as supportsOpenAITemperature } from "./openai-reasoning-effort-BK7FbcLT.mjs";
|
|
15
|
+
import { S as responsesPromptObserver } from "./openai-responses-compaction-window-D5jbzCi3.mjs";
|
|
16
|
+
import { J as buildOpenAIResponsesReasoningReplayMetadata, L as commitResponsesEncryptedContentAttempt, Q as suppressOpenAIResponsesCompaction, V as resolveNextResponsesEncryptedContentAttempt, a as resolveResponsesReasoningEffort, h as ResponsesStreamFailure, i as createResponsesAssistantOutput, l as convertResponsesToolPayload, n as applyResponsesServiceTierPricing, o as resolveResponsesRequestReasoningEffort, r as convertResponsesMessages, u as processResponsesStream, z as isInvalidEncryptedContentError } from "./openai-responses-shared-ZyQEzS5i.mjs";
|
|
15
17
|
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
16
18
|
import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
|
|
17
|
-
import { t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-
|
|
19
|
+
import { t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal-tApyTLVu.mjs";
|
|
18
20
|
import { n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
19
21
|
//#region packages/ai/src/providers/openai-chatgpt-responses-protocol.ts
|
|
20
22
|
const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES = 16777216;
|
|
@@ -83,6 +85,17 @@ const os = loadNodeOs();
|
|
|
83
85
|
const DEFAULT_CODEX_BASE_URL = "https://chatgpt.com/backend-api";
|
|
84
86
|
const REQUEST_COMPRESSION_ZSTD_LEVEL = 3;
|
|
85
87
|
const CODEX_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "opencode"]);
|
|
88
|
+
const WEBSOCKET_TRANSPORT_ERROR_CODE = "ERR_WEBSOCKET_TRANSPORT";
|
|
89
|
+
const RETRYABLE_WEBSOCKET_CLOSE_CODES = /* @__PURE__ */ new Set([
|
|
90
|
+
1001,
|
|
91
|
+
1005,
|
|
92
|
+
1006,
|
|
93
|
+
1011,
|
|
94
|
+
1012,
|
|
95
|
+
1013,
|
|
96
|
+
1014,
|
|
97
|
+
1015
|
|
98
|
+
]);
|
|
86
99
|
const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
87
100
|
const WEBSOCKET_CONNECTION_LIMIT_REACHED_CODE = "websocket_connection_limit_reached";
|
|
88
101
|
const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES = 16384;
|
|
@@ -184,7 +197,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
184
197
|
commitSemanticAttempt(activeAttempt);
|
|
185
198
|
}, requestOptions, firstEventAbort.abort, observePromptEgress, activeAttempt.kind, () => {
|
|
186
199
|
websocketRequestSent = true;
|
|
187
|
-
});
|
|
200
|
+
}, options?.signal);
|
|
188
201
|
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
189
202
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new CodexApiError(output.errorMessage ?? "An unknown error occurred");
|
|
190
203
|
stream.push({
|
|
@@ -367,9 +380,9 @@ function buildRequestBody(model, context, options, replayMode = "checkpoint") {
|
|
|
367
380
|
if (options?.temperature !== void 0 && supportsOpenAITemperature(model)) body.temperature = options.temperature;
|
|
368
381
|
if (options?.serviceTier !== void 0) body.service_tier = options.serviceTier;
|
|
369
382
|
if (context.tools) {
|
|
370
|
-
const
|
|
371
|
-
if (
|
|
372
|
-
body.tools =
|
|
383
|
+
const tools = convertResponsesToolPayload(context.tools, { strict: null });
|
|
384
|
+
if (tools.length > 0) {
|
|
385
|
+
body.tools = tools;
|
|
373
386
|
body.tool_choice = "auto";
|
|
374
387
|
body.parallel_tool_calls = true;
|
|
375
388
|
}
|
|
@@ -503,15 +516,9 @@ async function getWebSocketConstructor() {
|
|
|
503
516
|
if (typeof ctor !== "function") return null;
|
|
504
517
|
return ctor;
|
|
505
518
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
this.name = "WebSocketCloseError";
|
|
510
|
-
this.code = options?.code;
|
|
511
|
-
this.reason = options?.reason;
|
|
512
|
-
this.wasClean = options?.wasClean;
|
|
513
|
-
}
|
|
514
|
-
};
|
|
519
|
+
function createWebSocketTransportError(message, cause) {
|
|
520
|
+
return Object.assign(new Error(message, cause ? { cause } : void 0), { code: extractErrorCodeOrErrno(cause) ?? WEBSOCKET_TRANSPORT_ERROR_CODE });
|
|
521
|
+
}
|
|
515
522
|
function getWebSocketReadyState(socket) {
|
|
516
523
|
const readyState = socket.readyState;
|
|
517
524
|
return typeof readyState === "number" ? readyState : void 0;
|
|
@@ -684,15 +691,15 @@ async function acquireWebSocket(url, headers, sessionId, signal) {
|
|
|
684
691
|
function extractWebSocketError(event) {
|
|
685
692
|
if (event && typeof event === "object") {
|
|
686
693
|
const message = "message" in event ? event.message : void 0;
|
|
687
|
-
if (typeof message === "string" && message.length > 0) return new Error(message);
|
|
688
694
|
const nestedError = "error" in event ? event.error : void 0;
|
|
689
|
-
|
|
690
|
-
if (nestedError
|
|
691
|
-
const
|
|
692
|
-
|
|
695
|
+
const eventMessage = typeof message === "string" && message.length > 0 ? message : void 0;
|
|
696
|
+
if (nestedError !== void 0) {
|
|
697
|
+
const cause = toErrorObject(nestedError, eventMessage ?? "WebSocket error");
|
|
698
|
+
return createWebSocketTransportError(eventMessage ?? (cause.message || "WebSocket error"), cause);
|
|
693
699
|
}
|
|
700
|
+
if (eventMessage) return createWebSocketTransportError(eventMessage);
|
|
694
701
|
}
|
|
695
|
-
return
|
|
702
|
+
return createWebSocketTransportError("WebSocket error");
|
|
696
703
|
}
|
|
697
704
|
function extractWebSocketCloseError(event) {
|
|
698
705
|
if (event && typeof event === "object") {
|
|
@@ -702,13 +709,16 @@ function extractWebSocketCloseError(event) {
|
|
|
702
709
|
const codeText = typeof code === "number" ? ` ${code}` : "";
|
|
703
710
|
let reasonText = typeof reason === "string" && reason.length > 0 ? ` ${reason}` : "";
|
|
704
711
|
if (!reasonText && code === WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE) reasonText = " message too big";
|
|
705
|
-
|
|
706
|
-
|
|
712
|
+
const message = `WebSocket closed${codeText}${reasonText}`;
|
|
713
|
+
const error = typeof code === "number" && RETRYABLE_WEBSOCKET_CLOSE_CODES.has(code) ? createWebSocketTransportError(message) : Object.assign(new Error(message), { code: WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE });
|
|
714
|
+
return Object.assign(error, {
|
|
715
|
+
name: "WebSocketCloseError",
|
|
716
|
+
closeCode: typeof code === "number" ? code : void 0,
|
|
707
717
|
reason: typeof reason === "string" && reason.length > 0 ? reason : void 0,
|
|
708
718
|
wasClean: typeof wasClean === "boolean" ? wasClean : void 0
|
|
709
719
|
});
|
|
710
720
|
}
|
|
711
|
-
return
|
|
721
|
+
return createWebSocketTransportError("WebSocket closed");
|
|
712
722
|
}
|
|
713
723
|
async function* parseWebSocket(socket, signal) {
|
|
714
724
|
const queue = [];
|
|
@@ -842,7 +852,7 @@ async function* startWebSocketOutputOnFirstEvent(events, output, stream, onFirst
|
|
|
842
852
|
yield event;
|
|
843
853
|
}
|
|
844
854
|
}
|
|
845
|
-
async function processWebSocketStream(url, body, headers, output, stream, model, onFirstProviderEvent, onStart, options, abortFirstEventStream, observePromptEgress, payloadVariant = "initial", onRequestSent) {
|
|
855
|
+
async function processWebSocketStream(url, body, headers, output, stream, model, onFirstProviderEvent, onStart, options, abortFirstEventStream, observePromptEgress, payloadVariant = "initial", onRequestSent, activitySignal) {
|
|
846
856
|
const { socket, entry, release } = await acquireWebSocket(url, headers, options?.sessionId, options?.signal);
|
|
847
857
|
let keepConnection = true;
|
|
848
858
|
const useCachedContext = options?.transport === "websocket-cached" || options?.transport === "auto";
|
|
@@ -870,7 +880,7 @@ async function processWebSocketStream(url, body, headers, output, stream, model,
|
|
|
870
880
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
871
881
|
abortFirstEventStream,
|
|
872
882
|
onFirstEventTimeout: getFirstStreamEventTimeoutHandler(options),
|
|
873
|
-
signal: options?.signal,
|
|
883
|
+
signal: activitySignal ?? options?.signal,
|
|
874
884
|
reasoningReplayMetadata: buildOpenAIResponsesReasoningReplayMetadata(model, {
|
|
875
885
|
sessionId: options?.sessionId,
|
|
876
886
|
authProfileId: options?.authProfileId
|
|
@@ -966,7 +976,7 @@ function parseErrorResponse(raw, response) {
|
|
|
966
976
|
message = err.message || friendlyMessage || message;
|
|
967
977
|
}
|
|
968
978
|
} catch {}
|
|
969
|
-
const retryAfterSeconds =
|
|
979
|
+
const retryAfterSeconds = parseRetryAfterHeadersSeconds(response.headers);
|
|
970
980
|
const retryAfterSuffix = Number.isFinite(retryAfterSeconds) ? `; Retry-After: ${Math.ceil(retryAfterSeconds ?? 0)} seconds` : "";
|
|
971
981
|
return new CodexApiError(`${friendlyMessage || message}${retryAfterSuffix}`, {
|
|
972
982
|
code,
|