@openclaw/ai 2026.7.2-beta.4 → 2026.7.2-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{anthropic-CrUDIBpM.mjs → anthropic-CQVj3le6.mjs} +53 -19
- package/dist/{anthropic-BoTnz8cv.d.mts → anthropic-SrGtwsJu.d.mts} +27 -1
- package/dist/{api-registry-BMphkFf1.d.mts → api-registry-DlMgPR39.d.mts} +1 -1
- package/dist/{azure-openai-responses-CbrpVeEv.mjs → azure-openai-responses-DIYgsqFM.mjs} +3 -4
- package/dist/error-coercion-DgxlWC0n.mjs +15 -0
- package/dist/{event-stream-Douf9dob.d.mts → event-stream-YjaPW20U.d.mts} +1 -1
- package/dist/event-stream.d.mts +1 -1
- package/dist/{tool-schema-json-projection-BwNu3nDi.mjs → github-copilot-headers-BCoBNmL7.mjs} +48 -1
- package/dist/{google-Cs62KA7t.mjs → google-f-A8xrae.mjs} +2 -2
- package/dist/{google-shared-CMLI-tCZ.mjs → google-shared-J6qvYINH.mjs} +5 -4
- package/dist/{google-vertex-B4SD3U0f.mjs → google-vertex-D3yMVXIY.mjs} +2 -2
- package/dist/{host-WvWBo4h8.d.mts → host-B9GUmcra.d.mts} +2 -2
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +2 -2
- package/dist/internal/anthropic.d.mts +15 -11
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai.d.mts +2 -1
- package/dist/internal/openai.mjs +4 -6
- package/dist/internal/runtime.d.mts +8 -32
- package/dist/internal/runtime.mjs +2 -3
- package/dist/internal/shared.d.mts +13 -8
- package/dist/internal/shared.mjs +2 -2
- package/dist/{mistral-D5Ps7Led.mjs → mistral-CKV-TOQj.mjs} +4 -3
- package/dist/number-coercion-DvG7SNMg.mjs +129 -0
- package/dist/{openai-CoGicoDt.d.mts → openai-BPor_3WI.d.mts} +35 -9
- package/dist/{openai-responses-shared-CzCurmY1.mjs → openai-D3PD6PE-.mjs} +1771 -745
- package/dist/{openai-chatgpt-responses-h0o5yV8Y.mjs → openai-chatgpt-responses-CedIj0hk.mjs} +19 -20
- package/dist/{openai-completions-exO8NFQf.mjs → openai-completions-CiSutyu0.mjs} +366 -227
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +7 -0
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +12 -0
- package/dist/prompt-cache-stability-Cwcjv_fx.d.mts +13 -0
- package/dist/{provider-error-C4VvV_3t.mjs → provider-error-apVOZI6G.mjs} +8 -2
- package/dist/providers.d.mts +3 -2
- package/dist/providers.mjs +10 -9
- package/dist/{system-prompt-cache-boundary-CbHeV4_l.mjs → shared-CdjNZd35.mjs} +117 -9
- package/dist/{src-CXno1H5g.mjs → src-QkygScBs.mjs} +23 -4
- package/dist/stream-first-event-timeout-C3OgBjIk.mjs +12294 -0
- package/dist/stream-first-event-timeout-DvDeSucC.d.mts +29 -0
- package/dist/transport-stream-shared-BbMELSI4.mjs +297 -0
- package/dist/transports.d.mts +105 -102
- package/dist/transports.mjs +334 -1966
- package/dist/{types-AFwwWium.d.mts → types-bzp5k29J.d.mts} +7 -0
- package/dist/types.d.mts +5 -5
- package/dist/types.mjs +2 -2
- package/dist/{validation-sxvxC8J-.d.mts → validation-B-j7cOYp.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/package.json +1 -2
- package/dist/azure-openai-responses-client-compat-C7K7QfUE.mjs +0 -62
- package/dist/github-copilot-headers-BsH5cqGj.mjs +0 -48
- package/dist/model-utils-1GiZ2_rr.mjs +0 -64
- package/dist/openai-responses-BHpmtUKo.mjs +0 -136
- package/dist/openai-tool-projection-ITOU9bG1.mjs +0 -200
- package/dist/reasoning-tag-text-partitioner-BlVe67g6.mjs +0 -400
- package/dist/stream-first-event-timeout-DP4xEyBY.mjs +0 -150
- package/npm-shrinkwrap.json +0 -638
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { D as ModelThinkingLevel, E as Model, F as SimpleStreamOptions, P as ProviderStreamOptions, X as Usage, i as AssistantMessage, n as Api, o as AssistantMessageEventStreamContract, u as Context, z as StreamOptions } from "../types-
|
|
2
|
-
import { a as RegisteredApiProvider, t as ApiProvider } from "../api-registry-
|
|
1
|
+
import { D as ModelThinkingLevel, E as Model, F as SimpleStreamOptions, P as ProviderStreamOptions, X as Usage, i as AssistantMessage, n as Api, o as AssistantMessageEventStreamContract, u as Context, z as StreamOptions } from "../types-bzp5k29J.mjs";
|
|
2
|
+
import { a as RegisteredApiProvider, t as ApiProvider } from "../api-registry-DlMgPR39.mjs";
|
|
3
3
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-BZiVbGwK.mjs";
|
|
4
|
+
import { a as createFirstStreamEventTimeoutError, c as withFirstStreamEventTimeout, i as createFirstStreamEventAbortController, n as FirstStreamEventInternalOptions, o as getFirstStreamEventTimeoutHandler, r as FirstStreamEventTimeoutContext, s as getFirstStreamEventTimeoutMs, t as FirstStreamEventAbortController } from "../stream-first-event-timeout-DvDeSucC.mjs";
|
|
4
5
|
|
|
5
6
|
//#region packages/ai/src/internal/default-runtime.d.ts
|
|
6
7
|
declare const defaultApiRegistry: {
|
|
@@ -169,7 +170,7 @@ declare function isConfiguredContextSizeOverflowError(errorMessage: string): boo
|
|
|
169
170
|
*/
|
|
170
171
|
declare function isContextOverflow(message: AssistantMessage, contextWindow?: number): boolean;
|
|
171
172
|
//#endregion
|
|
172
|
-
//#region packages/
|
|
173
|
+
//#region packages/markdown-core/src/reasoning-tag-parser.d.ts
|
|
173
174
|
type ReasoningTagTextDelta = {
|
|
174
175
|
kind: "text";
|
|
175
176
|
text: string;
|
|
@@ -177,6 +178,8 @@ type ReasoningTagTextDelta = {
|
|
|
177
178
|
kind: "thinking";
|
|
178
179
|
text: string;
|
|
179
180
|
};
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region packages/markdown-core/src/reasoning-tags.d.ts
|
|
180
183
|
interface ReasoningTagTextPartitioner {
|
|
181
184
|
markStrict(): void;
|
|
182
185
|
push(chunk: string): ReasoningTagTextDelta[];
|
|
@@ -185,36 +188,9 @@ interface ReasoningTagTextPartitioner {
|
|
|
185
188
|
hasPending(): boolean;
|
|
186
189
|
isInsideReasoning(): boolean;
|
|
187
190
|
}
|
|
191
|
+
/** Creates a block-incremental parser that emits only Markdown-stable text. */
|
|
188
192
|
declare function createReasoningTagTextPartitioner(): ReasoningTagTextPartitioner;
|
|
189
193
|
//#endregion
|
|
190
|
-
//#region packages/ai/src/utils/stream-first-event-timeout.d.ts
|
|
191
|
-
type StreamStage = "responses" | "completions";
|
|
192
|
-
type FirstStreamEventTimeoutContext = {
|
|
193
|
-
provider?: string;
|
|
194
|
-
api?: string;
|
|
195
|
-
model?: string;
|
|
196
|
-
timeoutMs: number;
|
|
197
|
-
stage?: StreamStage;
|
|
198
|
-
hint?: string;
|
|
199
|
-
abort?: (reason: Error) => void;
|
|
200
|
-
onTimeout?: (reason: Error) => void;
|
|
201
|
-
};
|
|
202
|
-
type FirstStreamEventInternalOptions = {
|
|
203
|
-
firstEventTimeoutMs?: number;
|
|
204
|
-
abortFirstEventStream?: (reason: Error) => void;
|
|
205
|
-
onFirstEventTimeout?: (reason: Error) => void;
|
|
206
|
-
};
|
|
207
|
-
type FirstStreamEventAbortController = {
|
|
208
|
-
signal: AbortSignal;
|
|
209
|
-
abort: (reason: Error) => void;
|
|
210
|
-
dispose: () => void;
|
|
211
|
-
};
|
|
212
|
-
declare function getFirstStreamEventTimeoutMs(options: unknown): number | undefined;
|
|
213
|
-
declare function getFirstStreamEventTimeoutHandler(options: unknown): ((reason: Error) => void) | undefined;
|
|
214
|
-
declare function createFirstStreamEventTimeoutError(context: FirstStreamEventTimeoutContext): Error;
|
|
215
|
-
declare function createFirstStreamEventAbortController(parentSignal?: AbortSignal): FirstStreamEventAbortController;
|
|
216
|
-
declare function withFirstStreamEventTimeout<T>(stream: AsyncIterable<T>, context: FirstStreamEventTimeoutContext): AsyncIterable<T>;
|
|
217
|
-
//#endregion
|
|
218
194
|
//#region packages/ai/src/utils/streaming-byte-guard.d.ts
|
|
219
195
|
/**
|
|
220
196
|
* Bounded SSE / NDJSON stream reader guard.
|
|
@@ -245,4 +221,4 @@ type SseByteGuard = {
|
|
|
245
221
|
};
|
|
246
222
|
declare function createSseByteGuard(reader: ReadableStreamDefaultReader<Uint8Array>, opts: ReadSseStreamWithLimitOptions): SseByteGuard;
|
|
247
223
|
//#endregion
|
|
248
|
-
export { FirstStreamEventAbortController, FirstStreamEventInternalOptions, FirstStreamEventTimeoutContext, OpenAICodexJwtPayload, ReadSseStreamWithLimitOptions, ReasoningTagTextDelta, ReasoningTagTextPartitioner, SessionResourceCleanup, SseByteGuard, SseStreamOverflow, applyProviderReportedUsageCost, calculateCost, clampThinkingLevel, cleanupSessionResources, clearApiProviders, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createReasoningTagTextPartitioner, createSseByteGuard, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSupportedThinkingLevels, headersToRecord, isConfiguredContextSizeOverflowError, isContextOverflow, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, withFirstStreamEventTimeout };
|
|
224
|
+
export { FirstStreamEventAbortController, FirstStreamEventInternalOptions, FirstStreamEventTimeoutContext, OpenAICodexJwtPayload, ReadSseStreamWithLimitOptions, type ReasoningTagTextDelta, type ReasoningTagTextPartitioner, SessionResourceCleanup, SseByteGuard, SseStreamOverflow, applyProviderReportedUsageCost, calculateCost, clampThinkingLevel, cleanupSessionResources, clearApiProviders, complete, completeSimple, createDeferredEventBuffer, createFirstStreamEventAbortController, createFirstStreamEventTimeoutError, createReasoningTagTextPartitioner, createSseByteGuard, decodeOpenAICodexJwtPayload, defaultApiRegistry, defaultLlmRuntime, findEnvKeys, getApiProvider, getApiProviders, getEnvApiKey, getFirstStreamEventTimeoutHandler, getFirstStreamEventTimeoutMs, getSupportedThinkingLevels, headersToRecord, isConfiguredContextSizeOverflowError, isContextOverflow, modelsAreEqual, notifyLlmRequestActivity, onLlmRequestActivity, parseJsonWithRepair, parseStreamingJson, registerSessionResourceCleanup, repairJson, resolveOpenAICodexAccountId, sanitizeSurrogates, shortHash, stream, streamSimple, withFirstStreamEventTimeout };
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { n as getEnvApiKey, t as findEnvKeys } from "../env-api-keys-DrgeBuva.mjs";
|
|
2
2
|
import { n as createApiRegistry, t as createLlmRuntime } from "../stream-CREqxHgU.mjs";
|
|
3
3
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-DT5o51ur.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { c as calculateCost, d as modelsAreEqual, l as clampThinkingLevel, s as applyProviderReportedUsageCost, u as getSupportedThinkingLevels } from "../number-coercion-DvG7SNMg.mjs";
|
|
5
5
|
import { n as onLlmRequestActivity, r as createDeferredEventBuffer, t as notifyLlmRequestActivity } from "../llm-request-activity-CehVkZP-.mjs";
|
|
6
6
|
import { t as headersToRecord } from "../headers-B_e4-1J0.mjs";
|
|
7
7
|
import { n as parseStreamingJson, r as repairJson, t as parseJsonWithRepair } from "../json-parse-BvXNt1-7.mjs";
|
|
8
8
|
import { i as registerSessionResourceCleanup, n as resolveOpenAICodexAccountId, r as cleanupSessionResources, t as decodeOpenAICodexJwtPayload } from "../openai-chatgpt-jwt-DhAAzLkj.mjs";
|
|
9
9
|
import { t as shortHash } from "../hash-CHgqbJmD.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-DP4xEyBY.mjs";
|
|
10
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, n as createFirstStreamEventTimeoutError, o as createReasoningTagTextPartitioner, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "../stream-first-event-timeout-C3OgBjIk.mjs";
|
|
12
11
|
import { t as createSseByteGuard } from "../streaming-byte-guard-BrbkbwUu.mjs";
|
|
13
12
|
//#region packages/ai/src/internal/default-runtime.ts
|
|
14
13
|
const DEFAULT_RUNTIME_KEY = Symbol.for("openclaw.ai.defaultRuntime");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { E as Model, F as SimpleStreamOptions, H as ThinkingBudgets, T as Message, W as ThinkingLevel, i as AssistantMessage, n as Api, z as StreamOptions } from "../types-
|
|
1
|
+
import { E as Model, F as SimpleStreamOptions, H as ThinkingBudgets, T as Message, W as ThinkingLevel, i as AssistantMessage, n as Api, z as StreamOptions } from "../types-bzp5k29J.mjs";
|
|
2
2
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-BZiVbGwK.mjs";
|
|
3
|
+
import { n as normalizeStructuredPromptSection, r as sortPromptCacheToolsByName, t as normalizePromptCapabilityIds } from "../prompt-cache-stability-Cwcjv_fx.mjs";
|
|
3
4
|
|
|
4
5
|
//#region packages/ai/src/providers/simple-options.d.ts
|
|
5
6
|
type FirstEventStreamOptions = {
|
|
@@ -38,12 +39,6 @@ declare function extractToolResultText(blocks: readonly unknown[]): string;
|
|
|
38
39
|
*/
|
|
39
40
|
declare function transformMessages<TApi extends Api>(messages: Message[], model: Model<TApi>, normalizeToolCallId?: (id: string, model: Model<TApi>, source: AssistantMessage) => string): Message[];
|
|
40
41
|
//#endregion
|
|
41
|
-
//#region packages/ai/src/utils/prompt-cache-stability.d.ts
|
|
42
|
-
/** Normalize structured prompt text before hashing or snapshot comparison. */
|
|
43
|
-
declare function normalizeStructuredPromptSection(text: string): string;
|
|
44
|
-
/** Normalize, de-dupe, and sort capability ids for stable prompt payloads. */
|
|
45
|
-
declare function normalizePromptCapabilityIds(capabilities: ReadonlyArray<string>): string[];
|
|
46
|
-
//#endregion
|
|
47
42
|
//#region packages/ai/src/utils/system-prompt-cache-boundary.d.ts
|
|
48
43
|
declare const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
49
44
|
declare function stripSystemPromptCacheBoundary(text: string): string;
|
|
@@ -57,4 +52,14 @@ declare function prependSystemPromptAdditionAfterCacheBoundary(params: {
|
|
|
57
52
|
systemPromptAddition?: string;
|
|
58
53
|
}): string;
|
|
59
54
|
//#endregion
|
|
60
|
-
|
|
55
|
+
//#region packages/ai/src/utils/tls-certificate-errors.d.ts
|
|
56
|
+
type TlsCertificateErrorKind = "certificate_invalid" | "hostname_mismatch";
|
|
57
|
+
type TlsCertificateErrorDetails = {
|
|
58
|
+
kind: TlsCertificateErrorKind;
|
|
59
|
+
code?: string;
|
|
60
|
+
message: string;
|
|
61
|
+
};
|
|
62
|
+
/** Classify deterministic Node/OpenSSL certificate validation failures. */
|
|
63
|
+
declare function inspectTlsCertificateError(error: unknown): TlsCertificateErrorDetails | null;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { SYSTEM_PROMPT_CACHE_BOUNDARY, TlsCertificateErrorDetails, TlsCertificateErrorKind, adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToModel, clampReasoning, describeToolResultMediaPlaceholder, ensureSystemPromptCacheBoundary, extractToolResultBlockText, extractToolResultText, hasMediaPayload, inspectTlsCertificateError, isImageWithMediaPayload, normalizePromptCapabilityIds, normalizeStructuredPromptSection, prependSystemPromptAdditionAfterCacheBoundary, sanitizeSurrogates, sortPromptCacheToolsByName, splitSystemPromptCacheBoundary, stripSystemPromptCacheBoundary, transformMessages };
|
package/dist/internal/shared.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as buildBaseOptions, C as extractToolResultBlockText, E as isImageWithMediaPayload, M as clampReasoning, S as describeToolResultMediaPlaceholder, T as hasMediaPayload, a as splitSystemPromptCacheBoundary, c as normalizeStructuredPromptSection, i as prependSystemPromptAdditionAfterCacheBoundary, j as clampMaxTokensToModel, k as adjustMaxTokensForThinking, l as sortPromptCacheToolsByName, n as SYSTEM_PROMPT_CACHE_BOUNDARY, o as stripSystemPromptCacheBoundary, r as ensureSystemPromptCacheBoundary, s as normalizePromptCapabilityIds, t as inspectTlsCertificateError, u as transformMessages, w as extractToolResultText } from "../shared-CdjNZd35.mjs";
|
|
2
2
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-DT5o51ur.mjs";
|
|
3
|
-
export { SYSTEM_PROMPT_CACHE_BOUNDARY, adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToModel, clampReasoning, describeToolResultMediaPlaceholder, ensureSystemPromptCacheBoundary, extractToolResultBlockText, extractToolResultText, hasMediaPayload, isImageWithMediaPayload, normalizePromptCapabilityIds, normalizeStructuredPromptSection, prependSystemPromptAdditionAfterCacheBoundary, sanitizeSurrogates, splitSystemPromptCacheBoundary, stripSystemPromptCacheBoundary, transformMessages };
|
|
3
|
+
export { SYSTEM_PROMPT_CACHE_BOUNDARY, adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToModel, clampReasoning, describeToolResultMediaPlaceholder, ensureSystemPromptCacheBoundary, extractToolResultBlockText, extractToolResultText, hasMediaPayload, inspectTlsCertificateError, isImageWithMediaPayload, normalizePromptCapabilityIds, normalizeStructuredPromptSection, prependSystemPromptAdditionAfterCacheBoundary, sanitizeSurrogates, sortPromptCacheToolsByName, splitSystemPromptCacheBoundary, stripSystemPromptCacheBoundary, transformMessages };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-D8n2uFee.mjs";
|
|
3
3
|
import { n as getAiTransportHost } from "./host-XYGZcgO8.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { A as buildBaseOptions, D as truncateUtf16Safe, E as isImageWithMediaPayload, S as describeToolResultMediaPlaceholder, j as clampMaxTokensToModel, o as stripSystemPromptCacheBoundary, u as transformMessages, w as extractToolResultText } from "./shared-CdjNZd35.mjs";
|
|
5
5
|
import { t as sanitizeSurrogates } from "./sanitize-unicode-DT5o51ur.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { c as calculateCost, l as clampThinkingLevel } from "./number-coercion-DvG7SNMg.mjs";
|
|
7
|
+
import { d as transportAbortError } from "./transport-stream-shared-BbMELSI4.mjs";
|
|
7
8
|
import { n as parseStreamingJson } from "./json-parse-BvXNt1-7.mjs";
|
|
8
9
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
9
10
|
import { t as createSseByteGuard } from "./streaming-byte-guard-BrbkbwUu.mjs";
|
|
@@ -85,7 +86,7 @@ const streamMistral = (model, context, options) => {
|
|
|
85
86
|
partial: output
|
|
86
87
|
});
|
|
87
88
|
await consumeChatStream(model, output, stream, mistralStream);
|
|
88
|
-
if (options?.signal?.aborted) throw
|
|
89
|
+
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
89
90
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error("An unknown error occurred");
|
|
90
91
|
stream.push({
|
|
91
92
|
type: "done",
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { a as requiresClaudeMandatoryAdaptiveThinking, l as resolveClaudeNativeThinkingLevelMap } from "./src-QkygScBs.mjs";
|
|
2
|
+
//#region packages/ai/src/model-utils.ts
|
|
3
|
+
/** Calculates and stores model cost fields from token usage and per-million pricing. */
|
|
4
|
+
function calculateCost(model, usage) {
|
|
5
|
+
const cacheWrite1h = Math.min(usage.cacheWrite, Math.max(0, usage.cacheWrite1h ?? 0));
|
|
6
|
+
const cacheWrite5m = usage.cacheWrite - cacheWrite1h;
|
|
7
|
+
usage.cost.input = model.cost.input / 1e6 * usage.input;
|
|
8
|
+
usage.cost.output = model.cost.output / 1e6 * usage.output;
|
|
9
|
+
usage.cost.cacheRead = model.cost.cacheRead / 1e6 * usage.cacheRead;
|
|
10
|
+
usage.cost.cacheWrite = (model.cost.cacheWrite * cacheWrite5m + model.cost.input * 2 * cacheWrite1h) / 1e6;
|
|
11
|
+
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
12
|
+
return usage.cost;
|
|
13
|
+
}
|
|
14
|
+
/** Replaces the catalog estimate when the provider reports an authoritative billed total. */
|
|
15
|
+
function applyProviderReportedUsageCost(usage, reportedCost) {
|
|
16
|
+
if (typeof reportedCost !== "number" || !Number.isFinite(reportedCost) || reportedCost < 0) return;
|
|
17
|
+
usage.cost.total = reportedCost;
|
|
18
|
+
usage.cost.totalOrigin = "provider-billed";
|
|
19
|
+
}
|
|
20
|
+
const EXTENDED_THINKING_LEVELS = [
|
|
21
|
+
"off",
|
|
22
|
+
"minimal",
|
|
23
|
+
"low",
|
|
24
|
+
"medium",
|
|
25
|
+
"high",
|
|
26
|
+
"xhigh",
|
|
27
|
+
"max"
|
|
28
|
+
];
|
|
29
|
+
function resolveThinkingLevelMap(model) {
|
|
30
|
+
return model.api === "anthropic-messages" ? resolveClaudeNativeThinkingLevelMap(model) ?? model.thinkingLevelMap : model.thinkingLevelMap;
|
|
31
|
+
}
|
|
32
|
+
/** Returns thinking levels exposed by a reasoning-capable model. */
|
|
33
|
+
function getSupportedThinkingLevels(model) {
|
|
34
|
+
const mandatoryAdaptiveContract = model.api === "anthropic-messages" && requiresClaudeMandatoryAdaptiveThinking(model);
|
|
35
|
+
if (!model.reasoning && !mandatoryAdaptiveContract) return ["off"];
|
|
36
|
+
const thinkingLevelMap = resolveThinkingLevelMap(model);
|
|
37
|
+
return EXTENDED_THINKING_LEVELS.filter((level) => {
|
|
38
|
+
const mapped = thinkingLevelMap?.[level];
|
|
39
|
+
if (mapped === null) return false;
|
|
40
|
+
if (level === "xhigh" || level === "max") return mapped !== void 0;
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** Clamps a requested thinking level to the closest supported level for a model. */
|
|
45
|
+
function clampThinkingLevel(model, level) {
|
|
46
|
+
const availableLevels = getSupportedThinkingLevels(model);
|
|
47
|
+
if (availableLevels.includes(level)) return level;
|
|
48
|
+
const requestedIndex = EXTENDED_THINKING_LEVELS.indexOf(level);
|
|
49
|
+
if (requestedIndex === -1) return availableLevels[0] ?? "off";
|
|
50
|
+
const thinkingLevelMap = resolveThinkingLevelMap(model);
|
|
51
|
+
if ((level === "xhigh" || level === "max") && thinkingLevelMap?.[level] === null) {
|
|
52
|
+
for (const candidate of EXTENDED_THINKING_LEVELS.slice(0, requestedIndex).toReversed()) if (availableLevels.includes(candidate)) return candidate;
|
|
53
|
+
}
|
|
54
|
+
for (const candidate of EXTENDED_THINKING_LEVELS.slice(requestedIndex)) if (availableLevels.includes(candidate)) return candidate;
|
|
55
|
+
for (const candidate of EXTENDED_THINKING_LEVELS.slice(0, requestedIndex).toReversed()) if (availableLevels.includes(candidate)) return candidate;
|
|
56
|
+
return availableLevels[0] ?? "off";
|
|
57
|
+
}
|
|
58
|
+
/** Compares model identity by provider and id. */
|
|
59
|
+
function modelsAreEqual(a, b) {
|
|
60
|
+
if (!a || !b) return false;
|
|
61
|
+
return a.id === b.id && a.provider === b.provider;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region packages/normalization-core/src/number-coercion.ts
|
|
65
|
+
/** Returns a number only when the input is already finite. */
|
|
66
|
+
function asFiniteNumber(value) {
|
|
67
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
68
|
+
}
|
|
69
|
+
/** Returns a finite number only when it satisfies the supplied inclusive/exclusive bounds. */
|
|
70
|
+
function asFiniteNumberInRange(value, range) {
|
|
71
|
+
const number = asFiniteNumber(value);
|
|
72
|
+
if (number === void 0) return;
|
|
73
|
+
if (range.min !== void 0) {
|
|
74
|
+
if (range.minExclusive ? number <= range.min : number < range.min) return;
|
|
75
|
+
}
|
|
76
|
+
if (range.max !== void 0) {
|
|
77
|
+
if (range.maxExclusive ? number >= range.max : number > range.max) return;
|
|
78
|
+
}
|
|
79
|
+
return number;
|
|
80
|
+
}
|
|
81
|
+
function normalizeNumericString(value) {
|
|
82
|
+
const trimmed = value.trim();
|
|
83
|
+
return trimmed ? trimmed : void 0;
|
|
84
|
+
}
|
|
85
|
+
/** Parses only safe integer numbers or base-10 integer strings. */
|
|
86
|
+
function parseStrictInteger(value) {
|
|
87
|
+
if (typeof value === "number") return Number.isSafeInteger(value) ? value : void 0;
|
|
88
|
+
if (typeof value !== "string") return;
|
|
89
|
+
const normalized = normalizeNumericString(value);
|
|
90
|
+
if (!normalized || !/^[+-]?\d+$/.test(normalized)) return;
|
|
91
|
+
const parsed = Number(normalized);
|
|
92
|
+
return Number.isSafeInteger(parsed) ? parsed : void 0;
|
|
93
|
+
}
|
|
94
|
+
/** Parses only finite decimal/scientific string tokens, rejecting partial numbers. */
|
|
95
|
+
function parseStrictFiniteNumber(value) {
|
|
96
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
97
|
+
if (typeof value !== "string") return;
|
|
98
|
+
const normalized = normalizeNumericString(value);
|
|
99
|
+
if (!normalized || !/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:e[+-]?\d+)?$/i.test(normalized)) return;
|
|
100
|
+
const parsed = Number(normalized);
|
|
101
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
102
|
+
}
|
|
103
|
+
/** Conservative upper bound for Node timer delays. */
|
|
104
|
+
const MAX_TIMER_TIMEOUT_MS = 2147e6;
|
|
105
|
+
/** Clamps finite millisecond values into the Node-safe timer range. */
|
|
106
|
+
function clampTimerTimeoutMs(valueMs, minMs = 1) {
|
|
107
|
+
const value = asFiniteNumber(valueMs);
|
|
108
|
+
if (value === void 0) return;
|
|
109
|
+
return Math.min(Math.max(Math.floor(value), Math.max(1, Math.floor(minMs))), MAX_TIMER_TIMEOUT_MS);
|
|
110
|
+
}
|
|
111
|
+
/** Resolves arbitrary timeout input with fallback and minimum timer bounds. */
|
|
112
|
+
function resolveTimerTimeoutMs(valueMs, fallbackMs, minMs = 1) {
|
|
113
|
+
const value = asFiniteNumber(valueMs) ?? asFiniteNumber(fallbackMs);
|
|
114
|
+
const min = Math.max(0, Math.floor(minMs));
|
|
115
|
+
if (value === void 0) return min;
|
|
116
|
+
return Math.min(Math.max(Math.floor(value), min), MAX_TIMER_TIMEOUT_MS);
|
|
117
|
+
}
|
|
118
|
+
/** Parses strict positive integer values from numbers or strings. */
|
|
119
|
+
function parseStrictPositiveInteger(value) {
|
|
120
|
+
const parsed = parseStrictInteger(value);
|
|
121
|
+
return parsed !== void 0 && parsed > 0 ? parsed : void 0;
|
|
122
|
+
}
|
|
123
|
+
/** Parses strict non-negative integer values from numbers or strings. */
|
|
124
|
+
function parseStrictNonNegativeInteger(value) {
|
|
125
|
+
const parsed = parseStrictInteger(value);
|
|
126
|
+
return parsed !== void 0 && parsed >= 0 ? parsed : void 0;
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
export { parseStrictPositiveInteger as a, calculateCost as c, modelsAreEqual as d, parseStrictNonNegativeInteger as i, clampThinkingLevel as l, clampTimerTimeoutMs as n, resolveTimerTimeoutMs as o, parseStrictFiniteNumber as r, applyProviderReportedUsageCost as s, asFiniteNumberInRange as t, getSupportedThinkingLevels as u };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { E as Model, F as SimpleStreamOptions, I as StopReason, O as OpenAICompletionsCompat, R as StreamFunction, X as Usage, u as Context, z as StreamOptions } from "./types-
|
|
1
|
+
import { E as Model, F as SimpleStreamOptions, I as StopReason, O as OpenAICompletionsCompat, R as StreamFunction, X as Usage, u as Context, z as StreamOptions } from "./types-bzp5k29J.mjs";
|
|
2
|
+
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-B9GUmcra.mjs";
|
|
2
3
|
import OpenAI from "openai";
|
|
3
4
|
import { TSchema } from "typebox";
|
|
4
5
|
import { ChatCompletionMessageParam } from "openai/resources/chat/completions.js";
|
|
@@ -58,13 +59,44 @@ declare function isOpenAICompatibleAzureResponsesBaseUrl(baseUrl: string): boole
|
|
|
58
59
|
declare const GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS: Set<string>;
|
|
59
60
|
declare function cleanSchemaForGemini(schema: unknown): TSchema;
|
|
60
61
|
//#endregion
|
|
61
|
-
//#region packages/ai/src/
|
|
62
|
+
//#region packages/ai/src/transports/openai-completions-compat.d.ts
|
|
63
|
+
type ProviderRequestCapabilities = AiProviderRequestCapabilities;
|
|
62
64
|
type OpenAICompletionsSessionAffinity = "none" | "openai" | "openrouter";
|
|
65
|
+
type OpenAICompletionsCompatDefaults = {
|
|
66
|
+
supportsStore: boolean;
|
|
67
|
+
supportsDeveloperRole: boolean;
|
|
68
|
+
supportsReasoningEffort: boolean;
|
|
69
|
+
supportsUsageInStreaming: boolean;
|
|
70
|
+
maxTokensField: "max_completion_tokens" | "max_tokens";
|
|
71
|
+
thinkingFormat: "openai" | "openrouter" | "deepseek" | "together" | "zai";
|
|
72
|
+
visibleReasoningDetailTypes: string[];
|
|
73
|
+
supportsStrictMode: boolean;
|
|
74
|
+
supportsJsonSchemaResponseFormat: boolean;
|
|
75
|
+
requiresReasoningContentOnAssistantMessages: boolean;
|
|
76
|
+
requiresNonEmptyUserOrAssistantMessage: boolean;
|
|
77
|
+
cacheControlFormat?: OpenAICompletionsCompat["cacheControlFormat"];
|
|
78
|
+
sessionAffinityFormat: Exclude<OpenAICompletionsSessionAffinity, "none">;
|
|
79
|
+
supportsLongCacheRetention: boolean;
|
|
80
|
+
};
|
|
81
|
+
type DetectedOpenAICompletionsCompat = {
|
|
82
|
+
capabilities: ProviderRequestCapabilities;
|
|
83
|
+
defaults: OpenAICompletionsCompatDefaults;
|
|
84
|
+
};
|
|
63
85
|
type ResolvedOpenAICompletionsCompat = Omit<Required<OpenAICompletionsCompat>, "cacheControlFormat" | "openRouterRouting" | "sendSessionAffinityHeaders"> & {
|
|
64
86
|
cacheControlFormat?: OpenAICompletionsCompat["cacheControlFormat"];
|
|
65
87
|
openRouterRouting?: OpenAICompletionsCompat["openRouterRouting"];
|
|
66
88
|
sessionAffinity: OpenAICompletionsSessionAffinity;
|
|
89
|
+
visibleReasoningDetailTypes: string[];
|
|
90
|
+
requiresNonEmptyUserOrAssistantMessage: boolean;
|
|
67
91
|
};
|
|
92
|
+
/** Detects endpoint capabilities and defaults for an OpenAI-completions model. */
|
|
93
|
+
declare function detectOpenAICompletionsCompat(model: Pick<Model<"openai-completions">, "provider" | "baseUrl" | "id"> & {
|
|
94
|
+
compat?: {
|
|
95
|
+
supportsStore?: boolean;
|
|
96
|
+
} | null;
|
|
97
|
+
}, resolveCapabilities?: (input: AiProviderRequestPolicyInput) => ProviderRequestCapabilities): DetectedOpenAICompletionsCompat;
|
|
98
|
+
/** Applies explicit model overrides once on top of the canonical transport defaults. */
|
|
99
|
+
declare function resolveOpenAICompletionsCompat(model: Model<"openai-completions">, resolveCapabilities?: (input: AiProviderRequestPolicyInput) => ProviderRequestCapabilities): ResolvedOpenAICompletionsCompat;
|
|
68
100
|
//#endregion
|
|
69
101
|
//#region packages/ai/src/providers/openai-tool-projection.d.ts
|
|
70
102
|
type OpenAIToolDescriptor = {
|
|
@@ -112,12 +144,6 @@ declare function convertMessages(model: Model<"openai-completions">, context: Co
|
|
|
112
144
|
preserveSystemPromptCacheBoundary?: boolean;
|
|
113
145
|
}): ChatCompletionMessageParam[];
|
|
114
146
|
//#endregion
|
|
115
|
-
//#region packages/ai/src/providers/openai-prompt-cache.d.ts
|
|
116
|
-
/** Maximum prompt cache key length accepted by OpenAI-compatible request metadata. */
|
|
117
|
-
declare const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
118
|
-
/** Truncates a prompt cache key by Unicode code point count. */
|
|
119
|
-
declare function clampOpenAIPromptCacheKey(key: string | undefined): string | undefined;
|
|
120
|
-
//#endregion
|
|
121
147
|
//#region packages/ai/src/providers/openai-reasoning-effort.d.ts
|
|
122
148
|
type OpenAIReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
123
149
|
type OpenAIApiReasoningEffort = OpenAIReasoningEffort | (string & {});
|
|
@@ -329,4 +355,4 @@ type RuntimeToolInputSchemaProjection = {
|
|
|
329
355
|
/** Projects one runtime tool input schema to JSON and reports runtime incompatibilities. */
|
|
330
356
|
declare function projectRuntimeToolInputSchema(schema: unknown, path?: string): RuntimeToolInputSchemaProjection;
|
|
331
357
|
//#endregion
|
|
332
|
-
export {
|
|
358
|
+
export { streamSimpleOpenAICompletions as $, ResponsesTextContentPartType as A, OpenAIApiReasoningEffort as B, AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE as C, OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE as D, AzureResponsesTextDeltaEvent as E, isResponsesTextDeltaEventType as F, normalizeOpenAIReasoningEffort as G, isOpenAIGpt54MiniModel as H, resolveResponsesMessageSnapshotCollapse as I, supportsOpenAIReasoningEffort as J, resolveOpenAIReasoningEffortForModel as K, OpenAIResponsesOptions as L, isAzureResponsesTextDeltaEvent as M, isAzureResponsesTextDeltaEventType as N, OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE as O, isResponsesTextContentPartType as P, streamOpenAICompletions as Q, streamOpenAIResponses as R, resolveResponsesTerminalStopReason as S, AzureResponsesTextContentPart as T, isOpenAIGpt55Model as U, OpenAIReasoningEffort as V, isOpenAIGpt56Model as W, OpenAICompletionsOptions as X, supportsOpenAITemperature as Y, convertMessages as Z, createResponsesToolCallTracker as _, normalizeToolParameterSchema as _t, clearOpenAIToolSchemaCacheForTest as a, ResolvedOpenAICompletionsCompat as at, mapResponsesTerminalUsage as b, normalizeOpenAIStrictToolParameters as c, GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS as ct, findOpenAIStrictSchemaViolations as d, isTraditionalAzureOpenAIHost as dt, OpenAICompletionsToolChoice as et, normalizeOpenAIStrictCompatSchema as f, parseAzureDeploymentNameMap as ft, ResponsesToolCallState as g, extractToolSchemaModelCompat as gt, ResponsesToolCallIdentity as h, ToolSchemaModelCompat as ht, stripUnsupportedSchemaKeywords as i, reconcileOpenAIResponsesToolChoice as it, ResponsesTextDeltaEventType as j, ResponsesMessageSnapshotCollapse as k, normalizeStrictOpenAIJsonSchema as l, cleanSchemaForGemini as lt, mapOpenAIStopReason as m, ToolParameterSchemaOptions as mt, RuntimeToolInputSchemaProjection as n, projectOpenAITools as nt, findOpenAIStrictToolProjectionDiagnostics as o, detectOpenAICompletionsCompat as ot, OpenAIStopReasonResult as p, resolveAzureDeploymentNameFromMap as pt, resolveOpenAISupportedReasoningEfforts as q, projectRuntimeToolInputSchema as r, reconcileOpenAICompletionsToolChoice as rt, isStrictOpenAIJsonSchemaCompatible as s, resolveOpenAICompletionsCompat as st, RuntimeToolInputSchemaJson as t, OpenAIToolProjection as tt, resolveOpenAIProjectedToolsStrictToolFlag as u, isOpenAICompatibleAzureResponsesBaseUrl as ut, readResponsesToolCallItemIdentity as v, resolveUnsupportedToolSchemaKeywords as vt, AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE as w, readResponsesReasoningTokens as x, ResponsesTerminalUsagePayload as y, shouldOmitEmptyArrayItems as yt, streamSimpleOpenAIResponses as z };
|