@openclaw/ai 2026.9.4 → 2026.9.6
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 +1 -1
- package/dist/{anthropic-C4Qu4H0Z.mjs → anthropic-DZQ_7gD1.mjs} +37 -38
- package/dist/{anthropic-payload-policy-BZ8umAbk.d.mts → anthropic-payload-policy-DyfwikYJ.d.mts} +4 -4
- package/dist/{anthropic-stream-reducer-CILWF7JD.mjs → anthropic-stream-reducer-D6ZI1wwj.mjs} +70 -50
- package/dist/{api-registry-ByUwIR0e.d.mts → api-registry-C2T3lTV7.d.mts} +2 -2
- package/dist/{assistant-output-tLt4H-iQ.mjs → assistant-output-DM1JBNs1.mjs} +1 -1
- package/dist/{azure-openai-responses-BAlqlKKc.mjs → azure-openai-responses-DS86GYzq.mjs} +6 -9
- package/dist/{base64-D-su8YVo.mjs → base64-CPmadnUf.mjs} +12 -12
- package/dist/credential-redaction-BKv49aiv.d.mts +24 -0
- package/dist/{diagnostics-QuErwCIl.mjs → diagnostics-CH8j2wIG.mjs} +139 -7
- package/dist/{diagnostics-CPeq9F7y.mjs → diagnostics-DzrF1h4J.mjs} +18 -1
- package/dist/diagnostics.d.mts +11 -24
- package/dist/diagnostics.mjs +4 -4
- package/dist/event-stream-C0nsgbj2.d.mts +1 -0
- package/dist/{event-stream-Bt5Y4Pav.d.mts → event-stream-CjnIZZst.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{google-DPBAOaOW.mjs → google-BZJFjhuC.mjs} +6 -9
- package/dist/{google-messages-6JkpHrhJ.mjs → google-messages-DB7GKkDk.mjs} +3 -3
- package/dist/{google-shared-BvBeW9aq.mjs → google-shared-Bok4I6zB.mjs} +13 -13
- package/dist/{google-vertex-k-TMCAYD.mjs → google-vertex-3eVNR2qW.mjs} +5 -8
- package/dist/{host-4atIX-2V.d.mts → host-DH-Z-LDb.d.mts} +5 -3
- package/dist/{host-policy-Zcg_cNz8.mjs → host-policy-DZO3oPPk.mjs} +1 -1
- package/dist/{host-B8YfDGd4.mjs → host-yTvBrYM2.mjs} +63 -31
- package/dist/{index-DdD3qerf.d.mts → index-C25RT6bP.d.mts} +37 -14
- package/dist/index.d.mts +7 -8
- package/dist/index.mjs +5 -6
- package/dist/internal/anthropic.d.mts +13 -10
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-completions-compat.d.mts +2 -0
- package/dist/internal/openai-completions-compat.mjs +2 -0
- 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 +24 -53
- package/dist/internal/openai.mjs +12 -9
- package/dist/internal/runtime.d.mts +6 -8
- package/dist/internal/runtime.mjs +6 -10
- package/dist/internal/shared.d.mts +7 -5
- package/dist/internal/shared.mjs +4 -3
- package/dist/internal/tool-schema.d.mts +4 -4
- package/dist/internal/tool-schema.mjs +2 -2
- package/dist/{mistral-CxUZ1jUb.mjs → mistral-C_13dVBn.mjs} +9 -13
- package/dist/{model-transport-url-DKocrEsb.d.mts → model-transport-url-C5f59L3Y.d.mts} +1 -1
- package/dist/{openai-chatgpt-responses-CgO6kZfo.mjs → openai-chatgpt-responses-sTxPl4zM.mjs} +150 -83
- package/dist/{openai-completions-yJuk7eis.mjs → openai-completions-BO6D_hrB.mjs} +11 -12
- package/dist/{openai-prompt-cache-Bds-n_9Q.mjs → openai-completions-compat-CUollwl6.mjs} +5 -50
- package/dist/{openai-completions-compat-eHgh5UPE.d.mts → openai-completions-compat-DfJG1wSO.d.mts} +4 -4
- package/dist/{openai-completions-stream-Da2vvl-S.mjs → openai-completions-stream-BpuJ0ZOA.mjs} +117 -106
- package/dist/{openai-prompt-cache-B4eYo2-I.d.mts → openai-prompt-cache-C4RHdN4n.d.mts} +2 -2
- package/dist/openai-prompt-cache-CjV_2IRI.mjs +46 -0
- package/dist/{openai-provider-client-S2gCrM2Z.mjs → openai-provider-client-BP8J1aeg.mjs} +2 -2
- package/dist/openai-reasoning-effort-ash8dPrd.mjs +243 -0
- package/dist/{openai-responses-DaYwH05E.mjs → openai-responses-BJ_IEoMU.mjs} +8 -12
- package/dist/{openai-responses-compaction-window-CIhBAkkq.mjs → openai-responses-compaction-window-BiNCT0bS.mjs} +20 -62
- package/dist/{openai-responses-contracts-BjBAqAg_.d.mts → openai-responses-contracts-B1ENJFpI.d.mts} +9 -5
- package/dist/openai-responses-contracts-DWrfMODE.mjs +81 -0
- package/dist/{openai-responses-payload-policy-rLRPsSmB.d.mts → openai-responses-payload-policy-C7GsA1y0.d.mts} +5 -3
- package/dist/openai-responses-prompt-observer-internal-DPHWgbBH.mjs +198 -0
- package/dist/openai-responses-request-lifecycle-DFuyO1pQ.mjs +36 -0
- package/dist/{openai-responses-shared-B8RdBPCv.mjs → openai-responses-shared-DvSqtJ6_.mjs} +859 -581
- package/dist/openai-responses-terminal-usage-BNFbvY9f.d.mts +47 -0
- package/dist/{openai-tool-schema-CzjyYXun.mjs → openai-tool-schema-D4BMcj2D.mjs} +262 -162
- package/dist/{openai-transport-params-9aPuV5YY.mjs → openai-transport-params-DZKOTSfH.mjs} +157 -47
- package/dist/{positive-integer-41zhOdcV.mjs → positive-integer-BiUxrd71.mjs} +1 -1
- package/dist/{provider-error-BA-v_tKd.mjs → provider-error-CRhW7lkJ.mjs} +139 -44
- package/dist/{provider-error-CzNw4BWX.d.mts → provider-error-xumb1V3F.d.mts} +3 -1
- package/dist/{provider-options-Ceqv1OKk.d.mts → provider-options-DZYq53lj.d.mts} +12 -7
- package/dist/{provider-replay-context-CJ_YvcEW.mjs → provider-replay-context-DPr3w20a.mjs} +1 -1
- package/dist/{provider-transcript-transform-V5YzU9zh.mjs → provider-transcript-transform-BTocjCRs.mjs} +1 -1
- package/dist/{provider-transport-turn-state-D5EXOFL2.mjs → provider-transport-turn-state-lrXEFkYr.mjs} +1 -1
- package/dist/{provider-types-CVjKjsuq.d.mts → provider-types-w1rEqrGP.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -7
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +10 -10
- package/dist/{reasoning-tag-text-partitioner-BcR5pztD.mjs → reasoning-tag-text-partitioner-Di38crhI.mjs} +167 -40
- package/dist/{simple-options-BQbb4yQL.mjs → simple-options-np1XPuhm.mjs} +5 -3
- package/dist/{usage-cost-BNWbbXav.mjs → src-DwGYYyZp.mjs} +18 -11
- package/dist/{stream-first-event-timeout-2hfrquuz.mjs → stream-first-event-timeout-BeptfRL6.mjs} +1 -1
- package/dist/{string-normalization-CmLIasuf.mjs → string-normalization-J9ZiLfGO.mjs} +13 -1
- package/dist/tool-schema-json-projection-CD9c_fK8.mjs +134 -0
- package/dist/{transport-stream-shared-zHll9BxO.mjs → transport-stream-shared-B5RioB_Q.mjs} +16 -24
- package/dist/{transport-stream-shared-DNvmoWnv.d.mts → transport-stream-shared-B7Z9oCYg.d.mts} +5 -5
- package/dist/{transport-utils-zrYjICLZ.mjs → transport-utils-03Qi0CN2.mjs} +3 -3
- package/dist/transports.d.mts +27 -13
- package/dist/transports.mjs +168 -462
- package/dist/types-DTvddOfm.d.mts +1 -0
- package/dist/{types-Ntv5z2g2.d.mts → types-qZFbaDbK.d.mts} +49 -3
- package/dist/types.d.mts +6 -7
- package/dist/types.mjs +4 -5
- package/dist/{validation-B0t_G2H6.d.mts → validation-DhQhmt6t.d.mts} +1 -1
- package/dist/{validation-BDzVDnTs.mjs → validation-Dw7cb6BV.mjs} +1 -0
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +11 -6
- package/dist/diagnostics-DnPnOui6.d.mts +0 -29
- package/dist/event-stream-C3WGFsum.d.mts +0 -1
- package/dist/openai-responses-contracts-DDOHA62Y.mjs +0 -245
- package/dist/openai-responses-prompt-observer-internal-f8J7wpsk.mjs +0 -32
- package/dist/src-DDmEryvj.mjs +0 -2
- package/dist/tool-schema-json-projection-ClptDdAO.mjs +0 -82
- package/dist/types-DlfwzH3T.d.mts +0 -1
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { a as isProviderRefusalAssistantError } from "./diagnostics-DzrF1h4J.mjs";
|
|
1
2
|
import { n as normalizeLowercaseStringOrEmpty } from "./string-coerce-fsri9iCu.mjs";
|
|
2
|
-
import "./
|
|
3
|
+
import { i as asOptionalRecord, o as isRecord } from "./record-coerce-DwRYMj3t.mjs";
|
|
4
|
+
import "./provider-error-CRhW7lkJ.mjs";
|
|
5
|
+
import { r as asFiniteNumber } from "./base64-CPmadnUf.mjs";
|
|
3
6
|
//#region packages/normalization-core/src/error-coercion.ts
|
|
4
7
|
function readProperty(value, key) {
|
|
5
8
|
try {
|
|
@@ -59,6 +62,7 @@ function collectNestedErrorCandidates(err) {
|
|
|
59
62
|
readProperty(current, "reason"),
|
|
60
63
|
readProperty(current, "original"),
|
|
61
64
|
readProperty(current, "error"),
|
|
65
|
+
readProperty(current, "suppressed"),
|
|
62
66
|
readProperty(current, "data")
|
|
63
67
|
];
|
|
64
68
|
const errors = readProperty(current, "errors");
|
|
@@ -67,6 +71,137 @@ function collectNestedErrorCandidates(err) {
|
|
|
67
71
|
});
|
|
68
72
|
}
|
|
69
73
|
//#endregion
|
|
74
|
+
//#region packages/normalization-core/src/json-coercion.ts
|
|
75
|
+
/** Parses JSON without throwing, returning undefined for invalid input. */
|
|
76
|
+
function safeParseJson(value) {
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(value);
|
|
79
|
+
} catch {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Parses JSON into a non-array record, returning undefined for every other result. */
|
|
84
|
+
function safeParseJsonRecord(value) {
|
|
85
|
+
return /^[\t\n\r ]*\{/.test(value) ? asOptionalRecord(safeParseJson(value)) : void 0;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region packages/ai/src/providers/openai-responses-terminal-usage.ts
|
|
89
|
+
/**
|
|
90
|
+
* Canonical mapping for terminal OpenAI Responses events.
|
|
91
|
+
*
|
|
92
|
+
* `response.completed`, `response.incomplete`, and `response.failed` are terminal and can carry
|
|
93
|
+
* usage, so every Responses path finalizes through the helpers here. Keeping one owner prevents
|
|
94
|
+
* package and managed transports from drifting on token buckets, service-tier pricing, or future
|
|
95
|
+
* terminal-event semantics.
|
|
96
|
+
*/
|
|
97
|
+
/** A known output ceiling can resume sampling after admitted tools have settled. */
|
|
98
|
+
function isResponsesOutputLimitToolCallError(message) {
|
|
99
|
+
return message.stopReason === "error" && message.errorCode === "incomplete_tool_call" && !isProviderRefusalAssistantError(message) && message.diagnostics?.some(({ type, details }) => type === "openai_responses_terminal" && details?.eventType === "response.incomplete" && details.stopReason === "length" && details.incompleteReason === "max_output_tokens") === true;
|
|
100
|
+
}
|
|
101
|
+
function readReportedCount(value) {
|
|
102
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
103
|
+
}
|
|
104
|
+
function readCount(value) {
|
|
105
|
+
return readReportedCount(value) ?? 0;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Split a terminal usage payload into the priced buckets.
|
|
109
|
+
*
|
|
110
|
+
* OpenAI includes cache reads and writes in `input_tokens`, so both are subtracted out of the
|
|
111
|
+
* billable input bucket. `total_tokens` comes from the payload, but never below the sum of the
|
|
112
|
+
* split buckets: proxies routinely omit it (reporting 0 would understate the turn), and a payload
|
|
113
|
+
* whose `cached_tokens` exceeds `input_tokens` clamps the input bucket, leaving the reported total
|
|
114
|
+
* short of what the buckets actually price.
|
|
115
|
+
*/
|
|
116
|
+
function mapResponsesTerminalUsage(usage) {
|
|
117
|
+
if (!usage) return;
|
|
118
|
+
const cacheRead = readCount(usage.input_tokens_details?.cached_tokens);
|
|
119
|
+
const cacheWrite = readCount(usage.input_tokens_details?.cache_write_tokens);
|
|
120
|
+
const input = Math.max(0, readCount(usage.input_tokens) - cacheRead - cacheWrite);
|
|
121
|
+
const output = readCount(usage.output_tokens);
|
|
122
|
+
const bucketTotal = input + output + cacheRead + cacheWrite;
|
|
123
|
+
const totalTokens = Math.max(bucketTotal, readCount(usage.total_tokens));
|
|
124
|
+
const reportedInput = readReportedCount(usage.input_tokens);
|
|
125
|
+
const reportedOutput = readReportedCount(usage.output_tokens);
|
|
126
|
+
const reportedTotal = readReportedCount(usage.total_tokens);
|
|
127
|
+
return {
|
|
128
|
+
input,
|
|
129
|
+
output,
|
|
130
|
+
cacheRead,
|
|
131
|
+
cacheWrite,
|
|
132
|
+
contextUsage: reportedInput !== void 0 && (reportedOutput !== void 0 || reportedTotal !== void 0 && reportedTotal >= reportedInput) && cacheRead + cacheWrite <= reportedInput ? {
|
|
133
|
+
state: "available",
|
|
134
|
+
promptTokens: reportedInput,
|
|
135
|
+
totalTokens: Math.max(totalTokens, reportedInput + (reportedOutput ?? 0))
|
|
136
|
+
} : { state: "unavailable" },
|
|
137
|
+
totalTokens
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** Reasoning tokens are reported by the agent path only; the package path does not track them. */
|
|
141
|
+
function readResponsesReasoningTokens(usage) {
|
|
142
|
+
return asFiniteNumber(usage?.output_tokens_details?.reasoning_tokens);
|
|
143
|
+
}
|
|
144
|
+
function mapResponsesTerminalStopReason(status) {
|
|
145
|
+
if (!status) return "stop";
|
|
146
|
+
switch (status) {
|
|
147
|
+
case "completed": return "stop";
|
|
148
|
+
case "incomplete": return "length";
|
|
149
|
+
case "failed":
|
|
150
|
+
case "cancelled": return "error";
|
|
151
|
+
case "in_progress":
|
|
152
|
+
case "queued": return "stop";
|
|
153
|
+
default: throw new Error(`Unhandled stop reason: ${String(status)}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Resolve the terminal stop reason, including the two overrides every Responses path shares: a
|
|
158
|
+
* content-filtered turn is a provider error rather than a truncated answer, and a turn that
|
|
159
|
+
* produced tool calls reports `toolUse` instead of a plain stop.
|
|
160
|
+
*/
|
|
161
|
+
function resolveResponsesTerminalStopReason(params) {
|
|
162
|
+
const status = params.status ?? (params.terminalEventType === "response.incomplete" ? "incomplete" : void 0);
|
|
163
|
+
if (status === "incomplete" && params.incompleteReason === "content_filter") return {
|
|
164
|
+
stopReason: "error",
|
|
165
|
+
errorMessage: "Provider incomplete_reason: content_filter"
|
|
166
|
+
};
|
|
167
|
+
const stopReason = mapResponsesTerminalStopReason(status);
|
|
168
|
+
if (stopReason === "stop" && params.hasToolCall) return { stopReason: "toolUse" };
|
|
169
|
+
return { stopReason };
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region packages/ai/src/transports/openai-responses-stream-errors.ts
|
|
173
|
+
const OUTPUT_IDENTITY_ERROR_CODE = "responses_output_identity_conflict";
|
|
174
|
+
function outputType(type) {
|
|
175
|
+
return type === "reasoning" || type === "message" || type === "function_call" || type === "compaction" ? type : "other";
|
|
176
|
+
}
|
|
177
|
+
function isResponsesProviderTool(item) {
|
|
178
|
+
return outputType(item.type) === "other";
|
|
179
|
+
}
|
|
180
|
+
/** Inspect the admitted request, including payload-hook changes and transport retries. */
|
|
181
|
+
function hasOnlyResponsesFunctionTools(request) {
|
|
182
|
+
return request !== void 0 && (request.tools === void 0 || Array.isArray(request.tools) && request.tools.every((tool) => isRecord(tool) && tool.type === "function"));
|
|
183
|
+
}
|
|
184
|
+
var ResponsesOutputIdentityError = class extends Error {
|
|
185
|
+
constructor(details) {
|
|
186
|
+
super("Responses stream changed output item identity");
|
|
187
|
+
this.code = OUTPUT_IDENTITY_ERROR_CODE;
|
|
188
|
+
this.name = "ResponsesOutputIdentityError";
|
|
189
|
+
this.errorBody = JSON.stringify({
|
|
190
|
+
...details,
|
|
191
|
+
expectedType: outputType(details.expectedType),
|
|
192
|
+
actualType: outputType(details.actualType),
|
|
193
|
+
mismatch: details.expectedType !== details.actualType ? "type" : "call_id",
|
|
194
|
+
eventType: details.eventType === "response.output_item.added" || details.eventType === "response.output_item.done" || details.eventType === "response.completed" || details.eventType === "response.incomplete" ? details.eventType : "unknown",
|
|
195
|
+
retrySafe: details.retrySafe && !details.completedToolCall
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
/** Resume only a response that could not have completed tools or exposed visible output. */
|
|
200
|
+
function resolveResponsesOutputIdentityRetry(message) {
|
|
201
|
+
if (message.errorCode !== OUTPUT_IDENTITY_ERROR_CODE) return;
|
|
202
|
+
return message.stopReason === "error" && message.content?.every((block) => block.type === "thinking" || block.type === "text" && block.text.length === 0) === true && safeParseJsonRecord(message.errorBody ?? "")?.retrySafe === true ? "retry" : "stop";
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
70
205
|
//#region packages/ai/src/utils/retryable-network-errors.ts
|
|
71
206
|
const WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE = "ERR_WEBSOCKET_NON_RETRYABLE_CLOSE";
|
|
72
207
|
const TRANSIENT_NETWORK_CODES = /* @__PURE__ */ new Set([
|
|
@@ -173,12 +308,9 @@ function resolveModelSseDebugMode(env = process.env) {
|
|
|
173
308
|
function isModelTransportDebugEnabled(env = process.env) {
|
|
174
309
|
return isTruthyEnv(env.OPENCLAW_DEBUG_MODEL_TRANSPORT) || resolveModelPayloadDebugMode(env) !== "off" || resolveModelSseDebugMode(env) !== "off" || isTruthyEnv(env.OPENCLAW_DEBUG_CODE_MODE);
|
|
175
310
|
}
|
|
176
|
-
|
|
177
|
-
return message.startsWith("[model-fetch]");
|
|
178
|
-
}
|
|
179
|
-
/** Emits model-fetch metadata at info level by default; other diagnostics require debug env. */
|
|
311
|
+
/** Emits transport diagnostics at debug, promoted to info by explicit debug flags. */
|
|
180
312
|
function emitModelTransportDebug(log, message) {
|
|
181
|
-
if (
|
|
313
|
+
if (isModelTransportDebugEnabled()) {
|
|
182
314
|
log.info(message);
|
|
183
315
|
return;
|
|
184
316
|
}
|
|
@@ -208,4 +340,4 @@ function formatModelTransportDebugBaseUrl(rawUrl) {
|
|
|
208
340
|
return rawUrl ? formatModelTransportDebugUrl(rawUrl) : "default";
|
|
209
341
|
}
|
|
210
342
|
//#endregion
|
|
211
|
-
export { resolveModelSseDebugMode as a, isTransientNetworkError as c, resolveModelPayloadDebugMode as i,
|
|
343
|
+
export { extractErrorCodeOrErrno as _, resolveModelSseDebugMode as a, isTransientNetworkError as c, isResponsesProviderTool as d, resolveResponsesOutputIdentityRetry as f, resolveResponsesTerminalStopReason as g, readResponsesReasoningTokens as h, resolveModelPayloadDebugMode as i, ResponsesOutputIdentityError as l, mapResponsesTerminalUsage as m, formatModelTransportDebugUrl as n, WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE as o, isResponsesOutputLimitToolCallError as p, emitModelTransportDebug as r, hasRetryableConnectionErrorCode as s, formatModelTransportDebugBaseUrl as t, hasOnlyResponsesFunctionTools as u, toErrorObject as v };
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
import { Guard } from "typebox/guard";
|
|
2
|
+
//#region packages/llm-core/src/utils/provider-refusal.ts
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
function isBoundedText(value, maxBytes) {
|
|
5
|
+
return typeof value === "string" && value.length <= maxBytes && value.trim().length > 0 && encoder.encode(value).byteLength <= maxBytes;
|
|
6
|
+
}
|
|
7
|
+
/** Keep exact provider text. Truncation must never make an invalid continuation usable. */
|
|
8
|
+
function readProviderRefusalReview(value) {
|
|
9
|
+
if (!Guard.IsObjectNotArray(value) || !isBoundedText(value.explanation, 65536)) return;
|
|
10
|
+
const continuation = Guard.IsObjectNotArray(value.continuation) ? value.continuation.message : void 0;
|
|
11
|
+
return {
|
|
12
|
+
explanation: value.explanation,
|
|
13
|
+
...isBoundedText(continuation, 1024) ? { continuation: { message: continuation } } : {},
|
|
14
|
+
...typeof value.errorType === "string" && value.errorType.trim() ? { errorType: value.errorType } : {}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
1
18
|
//#region packages/llm-core/src/utils/diagnostics.ts
|
|
2
19
|
/** True when the provider explicitly refused the request payload. */
|
|
3
20
|
function isProviderRefusalAssistantError(message) {
|
|
@@ -37,4 +54,4 @@ function appendAssistantMessageDiagnostic(message, diagnostic) {
|
|
|
37
54
|
message.diagnostics = [...message.diagnostics ?? [], diagnostic];
|
|
38
55
|
}
|
|
39
56
|
//#endregion
|
|
40
|
-
export { isProviderRefusalAssistantError as a, formatThrownValue as i, createAssistantMessageDiagnostic as n, extractDiagnosticError as r, appendAssistantMessageDiagnostic as t };
|
|
57
|
+
export { isProviderRefusalAssistantError as a, formatThrownValue as i, createAssistantMessageDiagnostic as n, readProviderRefusalReview as o, extractDiagnosticError as r, appendAssistantMessageDiagnostic as t };
|
package/dist/diagnostics.d.mts
CHANGED
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
type DiagnosticProjectionPolicy = {
|
|
13
|
-
omitField?: (key: string) => boolean;
|
|
14
|
-
propertyScope?: "enumerable" | "error";
|
|
15
|
-
projectBinary?: (binary: Uint8Array) => unknown;
|
|
16
|
-
projectMedia?: (key: string, media: Extract<DiagnosticMediaField, {
|
|
17
|
-
kind: "redacted";
|
|
18
|
-
}>) => Record<string, unknown>;
|
|
19
|
-
};
|
|
20
|
-
export declare function projectDiagnosticValue(value: unknown, policy?: DiagnosticProjectionPolicy, seen?: WeakSet<object>, mediaPayload?: boolean, state?: {
|
|
21
|
-
changed: boolean;
|
|
22
|
-
nodesRemaining: number;
|
|
23
|
-
}): unknown;
|
|
1
|
+
import { a as ProviderRefusalReview, o as readProviderRefusalReview } from "./index-C25RT6bP.mjs";
|
|
2
|
+
import { a as AssistantMessage, dt as DiagnosticErrorInfo, ft as appendAssistantMessageDiagnostic, gt as isProviderRefusalAssistantError, ht as formatThrownValue, mt as extractDiagnosticError, pt as createAssistantMessageDiagnostic, ut as AssistantMessageDiagnostic } from "./types-qZFbaDbK.mjs";
|
|
3
|
+
import "./types-DTvddOfm.mjs";
|
|
4
|
+
import { n as isResponsesOutputLimitToolCallError } from "./openai-responses-terminal-usage-BNFbvY9f.mjs";
|
|
5
|
+
import { n as ProviderErrorRedactor, r as configureProviderErrorRedactor } from "./provider-error-xumb1V3F.mjs";
|
|
6
|
+
import { r as projectDiagnosticValue, t as DiagnosticProjectionPolicy } from "./credential-redaction-BKv49aiv.mjs";
|
|
7
|
+
import { n as formatModelTransportDebugUrl, r as emitModelTransportDebug, t as formatModelTransportDebugBaseUrl } from "./model-transport-url-C5f59L3Y.mjs";
|
|
8
|
+
//#region packages/ai/src/transports/openai-responses-stream-errors.d.ts
|
|
9
|
+
/** Resume only a response that could not have completed tools or exposed visible output. */
|
|
10
|
+
export declare function resolveResponsesOutputIdentityRetry(message: Pick<AssistantMessage, "errorCode"> & Partial<Pick<AssistantMessage, "stopReason" | "errorBody" | "content">>): "retry" | "stop" | undefined;
|
|
24
11
|
//#endregion
|
|
25
12
|
//#region packages/ai/src/utils/retryable-network-errors.d.ts
|
|
26
13
|
export declare const WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE = "ERR_WEBSOCKET_NON_RETRYABLE_CLOSE";
|
|
@@ -28,4 +15,4 @@ export declare function hasRetryableConnectionErrorCode(message: string): boolea
|
|
|
28
15
|
/** Returns true when any nested error proves a transient network failure. */
|
|
29
16
|
export declare function isTransientNetworkError(err: unknown): boolean;
|
|
30
17
|
//#endregion
|
|
31
|
-
export { AssistantMessageDiagnostic, DiagnosticErrorInfo, type DiagnosticProjectionPolicy, type ProviderErrorRedactor, appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, emitModelTransportDebug, extractDiagnosticError, formatModelTransportDebugBaseUrl, formatModelTransportDebugUrl, formatThrownValue, isProviderRefusalAssistantError };
|
|
18
|
+
export { AssistantMessageDiagnostic, DiagnosticErrorInfo, type DiagnosticProjectionPolicy, type ProviderErrorRedactor, type ProviderRefusalReview, appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, emitModelTransportDebug, extractDiagnosticError, formatModelTransportDebugBaseUrl, formatModelTransportDebugUrl, formatThrownValue, isProviderRefusalAssistantError, isResponsesOutputLimitToolCallError, projectDiagnosticValue, readProviderRefusalReview };
|
package/dist/diagnostics.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as isProviderRefusalAssistantError, i as formatThrownValue, n as createAssistantMessageDiagnostic, r as extractDiagnosticError, t as appendAssistantMessageDiagnostic } from "./diagnostics-
|
|
2
|
-
import {
|
|
3
|
-
import { c as isTransientNetworkError, n as formatModelTransportDebugUrl, o as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, r as emitModelTransportDebug, s as hasRetryableConnectionErrorCode, t as formatModelTransportDebugBaseUrl } from "./diagnostics-
|
|
4
|
-
export { WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, emitModelTransportDebug, extractDiagnosticError, formatModelTransportDebugBaseUrl, formatModelTransportDebugUrl, formatThrownValue, hasRetryableConnectionErrorCode, isProviderRefusalAssistantError, isTransientNetworkError, projectDiagnosticValue };
|
|
1
|
+
import { a as isProviderRefusalAssistantError, i as formatThrownValue, n as createAssistantMessageDiagnostic, o as readProviderRefusalReview, r as extractDiagnosticError, t as appendAssistantMessageDiagnostic } from "./diagnostics-DzrF1h4J.mjs";
|
|
2
|
+
import { i as projectDiagnosticValue, t as configureProviderErrorRedactor } from "./provider-error-CRhW7lkJ.mjs";
|
|
3
|
+
import { c as isTransientNetworkError, f as resolveResponsesOutputIdentityRetry, n as formatModelTransportDebugUrl, o as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, p as isResponsesOutputLimitToolCallError, r as emitModelTransportDebug, s as hasRetryableConnectionErrorCode, t as formatModelTransportDebugBaseUrl } from "./diagnostics-CH8j2wIG.mjs";
|
|
4
|
+
export { WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, emitModelTransportDebug, extractDiagnosticError, formatModelTransportDebugBaseUrl, formatModelTransportDebugUrl, formatThrownValue, hasRetryableConnectionErrorCode, isProviderRefusalAssistantError, isResponsesOutputLimitToolCallError, isTransientNetworkError, projectDiagnosticValue, readProviderRefusalReview, resolveResponsesOutputIdentityRetry };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./event-stream-CjnIZZst.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as ThinkingContent, a as AssistantMessage, o as AssistantMessageEvent, s as AssistantMessageEventStreamContract } from "./types-
|
|
1
|
+
import { $ as ThinkingContent, a as AssistantMessage, o as AssistantMessageEvent, s as AssistantMessageEventStreamContract } from "./types-qZFbaDbK.mjs";
|
|
2
2
|
//#region packages/llm-core/src/utils/event-stream.d.ts
|
|
3
3
|
/** Returns only an append whose current and previously observed snapshots still match. */
|
|
4
4
|
declare function readAssistantThinkingAppend(block: ThinkingContent, previous: string): string | undefined;
|
package/dist/event-stream.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
-
import "./event-stream-
|
|
1
|
+
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-CjnIZZst.mjs";
|
|
2
|
+
import "./event-stream-C0nsgbj2.mjs";
|
|
3
3
|
export { AssistantMessageEventStream, EventStream, createAssistantMessageEventStream };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region packages/normalization-core/src/expect.ts
|
|
2
|
+
/** Returns the value or throws with the named context; use for genuine invariants only. */
|
|
3
|
+
function expectDefined(value, context) {
|
|
4
|
+
if (value === null || value === void 0) throw new Error("expected " + context + " to be defined");
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { expectDefined as t };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
2
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
3
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
2
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-yTvBrYM2.mjs";
|
|
3
|
+
import { n as buildBaseOptions } from "./simple-options-np1XPuhm.mjs";
|
|
4
4
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
5
|
-
import { u as mergeTransportHeaders } from "./transport-stream-shared-
|
|
6
|
-
import { t as createAssistantOutput } from "./assistant-output-
|
|
5
|
+
import { u as mergeTransportHeaders } from "./transport-stream-shared-B5RioB_Q.mjs";
|
|
6
|
+
import { t as createAssistantOutput } from "./assistant-output-DM1JBNs1.mjs";
|
|
7
7
|
import { n as resolveOpencodeSessionHeaders } from "./session-affinity-Bcunsn4I.mjs";
|
|
8
|
-
import { n as buildGoogleSimpleThinking, r as runGoogleGenerateContentLifecycle, t as buildGoogleGenerateContentParams } from "./google-shared-
|
|
8
|
+
import { n as buildGoogleSimpleThinking, r as runGoogleGenerateContentLifecycle, t as buildGoogleGenerateContentParams } from "./google-shared-Bok4I6zB.mjs";
|
|
9
9
|
import { GoogleGenAI } from "@google/genai";
|
|
10
10
|
//#region packages/ai/src/providers/google.ts
|
|
11
11
|
let toolCallCounter = 0;
|
|
@@ -31,10 +31,7 @@ const streamSimpleGoogle = (model, context, options) => {
|
|
|
31
31
|
const base = buildBaseOptions(model, options, apiKey);
|
|
32
32
|
return streamGoogle(model, context, {
|
|
33
33
|
...base,
|
|
34
|
-
thinking: buildGoogleSimpleThinking(model, options
|
|
35
|
-
includeGemma4ThinkingLevel: true,
|
|
36
|
-
useFlashLiteBudgets: true
|
|
37
|
-
})
|
|
34
|
+
thinking: buildGoogleSimpleThinking(model, options)
|
|
38
35
|
});
|
|
39
36
|
};
|
|
40
37
|
function createClient(model, apiKey, optionsHeaders) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as appendAssistantThinking } from "./event-stream-D8PARQfL.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { v as sortPromptCacheToolsByName } from "./simple-options-
|
|
4
|
-
import { _ as sanitizeTransportPayloadText, r as coerceTransportToolCallArguments, v as transportAbortError } from "./transport-stream-shared-
|
|
2
|
+
import { M as calculateCost, _ as isImageWithMediaPayload, d as describeToolResultMediaPlaceholder, m as extractToolResultText, v as sanitizeSurrogates } from "./host-yTvBrYM2.mjs";
|
|
3
|
+
import { v as sortPromptCacheToolsByName } from "./simple-options-np1XPuhm.mjs";
|
|
4
|
+
import { _ as sanitizeTransportPayloadText, r as coerceTransportToolCallArguments, v as transportAbortError } from "./transport-stream-shared-B5RioB_Q.mjs";
|
|
5
5
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-BjtkplhG.mjs";
|
|
6
6
|
//#region packages/ai/src/transports/google-thinking-level.ts
|
|
7
7
|
/** Returns whether a Gemini Flash model accepts the MINIMAL thinking level. */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { m as stripSystemPromptCacheBoundary } from "./simple-options-
|
|
3
|
-
import { m as notifyProviderStreamOpened, n as assignTransportErrorDetails, v as transportAbortError } from "./transport-stream-shared-
|
|
4
|
-
import { a as googleFlashSupportsMinimalThinking, i as consumeGoogleGenerateContentStream, n as projectGoogleMessages, r as requiresGoogleToolCallId, t as convertGoogleTools } from "./google-messages-
|
|
5
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform-
|
|
1
|
+
import { N as clampThinkingLevel, v as sanitizeSurrogates } from "./host-yTvBrYM2.mjs";
|
|
2
|
+
import { m as stripSystemPromptCacheBoundary } from "./simple-options-np1XPuhm.mjs";
|
|
3
|
+
import { m as notifyProviderStreamOpened, n as assignTransportErrorDetails, v as transportAbortError } from "./transport-stream-shared-B5RioB_Q.mjs";
|
|
4
|
+
import { a as googleFlashSupportsMinimalThinking, i as consumeGoogleGenerateContentStream, n as projectGoogleMessages, r as requiresGoogleToolCallId, t as convertGoogleTools } from "./google-messages-DB7GKkDk.mjs";
|
|
5
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-BTocjCRs.mjs";
|
|
6
6
|
import { FunctionCallingConfigMode, ThinkingLevel } from "@google/genai";
|
|
7
7
|
//#region packages/ai/src/providers/google-shared.ts
|
|
8
8
|
/**
|
|
@@ -97,7 +97,7 @@ function buildGoogleGenerateContentParams(model, context, options = {}) {
|
|
|
97
97
|
function isAdaptiveGoogleReasoningLevel(value) {
|
|
98
98
|
return value === "adaptive";
|
|
99
99
|
}
|
|
100
|
-
function buildGoogleSimpleThinking(model, options
|
|
100
|
+
function buildGoogleSimpleThinking(model, options) {
|
|
101
101
|
if (!options?.reasoning || options.reasoning === "off") return { enabled: false };
|
|
102
102
|
if (isAdaptiveGoogleReasoningLevel(options.reasoning)) {
|
|
103
103
|
if (!model.reasoning) return { enabled: false };
|
|
@@ -113,13 +113,13 @@ function buildGoogleSimpleThinking(model, options, config) {
|
|
|
113
113
|
const clampedReasoning = clampThinkingLevel(model, options.reasoning);
|
|
114
114
|
if (clampedReasoning === "off") return { enabled: false };
|
|
115
115
|
const effort = clampedReasoning === "max" ? "high" : clampedReasoning;
|
|
116
|
-
if (isGemini3ProModel(model) || isGemini3FlashModel(model) ||
|
|
116
|
+
if (isGemini3ProModel(model) || isGemini3FlashModel(model) || isGemma4Model(model)) return {
|
|
117
117
|
enabled: true,
|
|
118
|
-
level: getGoogleThinkingLevel(effort, model
|
|
118
|
+
level: getGoogleThinkingLevel(effort, model)
|
|
119
119
|
};
|
|
120
120
|
return {
|
|
121
121
|
enabled: true,
|
|
122
|
-
budgetTokens: getGoogleBudget(model, effort, options.thinkingBudgets
|
|
122
|
+
budgetTokens: getGoogleBudget(model, effort, options.thinkingBudgets)
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
125
|
function getDisabledGoogleThinkingConfig(model) {
|
|
@@ -138,14 +138,14 @@ function isGemini3ProModel(model) {
|
|
|
138
138
|
function isGemini3FlashModel(model) {
|
|
139
139
|
return /gemini-(?:3(?:\.\d+)?-flash|flash(?:-lite)?-latest)/.test(model.id.toLowerCase());
|
|
140
140
|
}
|
|
141
|
-
function getGoogleThinkingLevel(effort, model
|
|
141
|
+
function getGoogleThinkingLevel(effort, model) {
|
|
142
142
|
if (isGemini3ProModel(model)) switch (effort) {
|
|
143
143
|
case "minimal":
|
|
144
144
|
case "low": return ThinkingLevel.LOW;
|
|
145
145
|
case "medium":
|
|
146
146
|
case "high": return ThinkingLevel.HIGH;
|
|
147
147
|
}
|
|
148
|
-
if (
|
|
148
|
+
if (isGemma4Model(model)) switch (effort) {
|
|
149
149
|
case "minimal":
|
|
150
150
|
case "low": return ThinkingLevel.MINIMAL;
|
|
151
151
|
case "medium":
|
|
@@ -159,7 +159,7 @@ function getGoogleThinkingLevel(effort, model, config) {
|
|
|
159
159
|
}
|
|
160
160
|
return ThinkingLevel.HIGH;
|
|
161
161
|
}
|
|
162
|
-
function getGoogleBudget(model, effort, customBudgets
|
|
162
|
+
function getGoogleBudget(model, effort, customBudgets) {
|
|
163
163
|
if (customBudgets?.[effort] !== void 0) return customBudgets[effort];
|
|
164
164
|
if (model.id.includes("2.5-pro")) return {
|
|
165
165
|
minimal: 128,
|
|
@@ -167,7 +167,7 @@ function getGoogleBudget(model, effort, customBudgets, config) {
|
|
|
167
167
|
medium: 8192,
|
|
168
168
|
high: 32768
|
|
169
169
|
}[effort];
|
|
170
|
-
if (
|
|
170
|
+
if (model.id.includes("2.5-flash-lite")) return {
|
|
171
171
|
minimal: 512,
|
|
172
172
|
low: 2048,
|
|
173
173
|
medium: 8192,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
2
2
|
import { a as normalizeOptionalString } from "./string-coerce-fsri9iCu.mjs";
|
|
3
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
4
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
5
|
-
import { t as createAssistantOutput } from "./assistant-output-
|
|
6
|
-
import { n as buildGoogleSimpleThinking, r as runGoogleGenerateContentLifecycle, t as buildGoogleGenerateContentParams } from "./google-shared-
|
|
3
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-yTvBrYM2.mjs";
|
|
4
|
+
import { n as buildBaseOptions } from "./simple-options-np1XPuhm.mjs";
|
|
5
|
+
import { t as createAssistantOutput } from "./assistant-output-DM1JBNs1.mjs";
|
|
6
|
+
import { n as buildGoogleSimpleThinking, r as runGoogleGenerateContentLifecycle, t as buildGoogleGenerateContentParams } from "./google-shared-Bok4I6zB.mjs";
|
|
7
7
|
import { GoogleGenAI, ResourceScope } from "@google/genai";
|
|
8
8
|
//#region packages/ai/src/providers/google-vertex.ts
|
|
9
9
|
const API_VERSION = "v1";
|
|
@@ -30,10 +30,7 @@ const streamSimpleGoogleVertex = (model, context, options) => {
|
|
|
30
30
|
const base = buildBaseOptions(model, options, void 0);
|
|
31
31
|
return streamGoogleVertex(model, context, {
|
|
32
32
|
...base,
|
|
33
|
-
thinking: buildGoogleSimpleThinking(model, options
|
|
34
|
-
includeGemma4ThinkingLevel: true,
|
|
35
|
-
useFlashLiteBudgets: true
|
|
36
|
-
})
|
|
33
|
+
thinking: buildGoogleSimpleThinking(model, options)
|
|
37
34
|
});
|
|
38
35
|
};
|
|
39
36
|
function createClient(model, project, location, optionsHeaders) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { O as Model, d as Context, n as Api, q as StreamFn } from "./types-
|
|
3
|
-
import { n as ApiRegistry } from "./api-registry-
|
|
1
|
+
import "./index-C25RT6bP.mjs";
|
|
2
|
+
import { O as Model, d as Context, n as Api, q as StreamFn } from "./types-qZFbaDbK.mjs";
|
|
3
|
+
import { n as ApiRegistry } from "./api-registry-C2T3lTV7.mjs";
|
|
4
4
|
//#region packages/ai/src/host.d.ts
|
|
5
5
|
/** Provider capability facts needed by the package-owned transports. */
|
|
6
6
|
interface AiProviderRequestCapabilities {
|
|
@@ -115,6 +115,8 @@ interface AiTransportHost {
|
|
|
115
115
|
}): typeof fetch | undefined;
|
|
116
116
|
/** Resolves host-owned process-local secret sentinel substrings immediately before egress. */
|
|
117
117
|
resolveSecretSentinel(value: string): string;
|
|
118
|
+
/** Resolves visible headers and host-private request overrides before plugin handoff. */
|
|
119
|
+
unwrapModelTransportSentinels?<T extends Model>(model: T, boundary: string): T;
|
|
118
120
|
/** Redacts model-visible tool results without treating ordinary source assignments as secrets. */
|
|
119
121
|
redactModelVisibleSecrets<T>(value: T): T;
|
|
120
122
|
/** Redacts secret-bearing text in tool payload strings. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as getAiTransportHost } from "./host-
|
|
1
|
+
import { n as getAiTransportHost } from "./host-yTvBrYM2.mjs";
|
|
2
2
|
//#region packages/ai/src/transports/host-policy.ts
|
|
3
3
|
function buildGuardedModelFetch(model, timeoutMs, options) {
|
|
4
4
|
const host = getAiTransportHost();
|