@openclaw/ai 2026.8.1-beta.3 → 2026.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{anthropic-B8KwTtlb.mjs → anthropic-DTGZ4VMY.mjs} +25 -23
- package/dist/{anthropic-compaction-replay-4Zx7-aCr.mjs → anthropic-compaction-replay-CKCDrZJv.mjs} +34 -35
- package/dist/{anthropic-payload-policy-CSx7MoKH.d.mts → anthropic-payload-policy-BTzmNC14.d.mts} +3 -2
- package/dist/{api-registry-DFxSnFqG.d.mts → api-registry-BbUHEKER.d.mts} +2 -1
- package/dist/{azure-openai-responses-Aa4mVcYG.mjs → azure-openai-responses-BmqaDXM1.mjs} +6 -5
- package/dist/{number-coercion-H9qHik3g.mjs → base64-CEFBpSkN.mjs} +73 -1
- package/dist/diagnostics.d.mts +2 -3
- package/dist/diagnostics.mjs +1 -1
- package/dist/{env-api-keys-DrgeBuva.mjs → env-api-keys-bktO00EJ.mjs} +2 -15
- package/dist/{event-stream-D91-ohD_.d.mts → event-stream-DcvAPSBe.d.mts} +1 -2
- package/dist/event-stream-pXT3FI6X.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -1
- package/dist/{google-yDRnipeq.mjs → google-CqjVZMwo.mjs} +8 -6
- package/dist/{google-shared-M1dl64nz.mjs → google-shared-Bnqni5j3.mjs} +34 -25
- package/dist/{google-vertex-DCJHM_a5.mjs → google-vertex-D_WREEJi.mjs} +8 -6
- package/dist/{host-DF_yxOsA.mjs → host-BIaiBURL.mjs} +4 -8
- package/dist/{host-DJq_FGcz.d.mts → host-DKFUAmCn.d.mts} +3 -3
- package/dist/index-CefaUGSS.d.mts +111 -0
- package/dist/index.d.mts +9 -10
- package/dist/index.mjs +4 -5
- package/dist/internal/anthropic.d.mts +51 -49
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +2 -3
- package/dist/internal/openai.d.mts +65 -63
- package/dist/internal/openai.mjs +10 -9
- package/dist/internal/retry-after.d.mts +2 -3
- package/dist/internal/runtime.d.mts +51 -40
- package/dist/internal/runtime.mjs +9 -9
- package/dist/internal/shared.d.mts +25 -25
- package/dist/internal/shared.mjs +3 -3
- package/dist/{json-parse-CDnesDM_.mjs → json-parse-BuAJEbdW.mjs} +18 -2
- package/dist/{mistral-D6hRXI7A.mjs → mistral-C24jVd6f.mjs} +34 -32
- package/dist/{openai-chatgpt-responses-C339VIfT.mjs → openai-chatgpt-responses-Czum0oXz.mjs} +38 -20
- package/dist/openai-completions-BfFwac6f.mjs +404 -0
- package/dist/{openai-completions-compat-B0KTleXp.d.mts → openai-completions-compat-SZhi0Lf4.d.mts} +3 -3
- package/dist/openai-completions-stream-DGOvau4J.mjs +1625 -0
- package/dist/{openai-responses-BXEcr-Tp.mjs → openai-responses-BAryVEJM.mjs} +11 -7
- package/dist/openai-responses-compaction-window-DO7yV7az.mjs +686 -0
- package/dist/{openai-responses-contracts-CD75pQ0m.d.mts → openai-responses-contracts-BthRXano.d.mts} +14 -5
- package/dist/{openai-responses-payload-policy-CNGFT9zr.d.mts → openai-responses-payload-policy-rLRPsSmB.d.mts} +1 -0
- package/dist/{openai-responses-prompt-observer-internal-BG-1AsBI.mjs → openai-responses-prompt-observer-internal--R0kZLOZ.mjs} +3 -2
- package/dist/{openai-responses-shared-Cvt5MgEm.mjs → openai-responses-shared-CxgdGBvm.mjs} +332 -1484
- package/dist/openai-stop-reason-Drnn_6Qj.mjs +28 -0
- package/dist/openai-tool-schema-CSMh5e9O.mjs +1697 -0
- package/dist/{provider-error-C8mBRJDl.mjs → provider-error-BI8kIViN.mjs} +14 -88
- package/dist/{provider-options-Cc5ZQ6Aa.d.mts → provider-options-DJd_9euj.d.mts} +13 -4
- package/dist/{provider-transcript-transform--gtf0ZbR.mjs → provider-transcript-transform-WvJmFUAf.mjs} +1 -1
- package/dist/provider-types.d.mts +18 -17
- package/dist/providers.d.mts +5 -6
- package/dist/providers.mjs +9 -9
- package/dist/{reasoning-tag-text-partitioner-5ygO2rZc.mjs → reasoning-tag-text-partitioner-BsUX44Tq.mjs} +30 -20
- package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
- package/dist/{sanitize-unicode-BP7HLLZn.mjs → sanitize-unicode-S6binQG-.mjs} +2 -9
- package/dist/simple-options-rdOPzr7Z.mjs +155 -0
- package/dist/{anthropic-BQXQudmA.mjs → src-C8U7lkoa.mjs} +75 -1
- package/dist/{stream-first-event-timeout-MK28puvq.mjs → stream-first-event-timeout-DcNjoFQE.mjs} +1 -1
- package/dist/{streaming-byte-guard-BrbkbwUu.mjs → streaming-byte-guard-CC-HMn_u.mjs} +5 -6
- package/dist/string-normalization--fwJ4S2q.mjs +16 -0
- package/dist/{tool-schema-json-projection-FEr-jOoZ.mjs → tool-schema-json-projection-BtZiml7r.mjs} +22 -32
- package/dist/transport-stream-shared-BbG7PThh.d.mts +138 -0
- package/dist/{simple-options-oqsXB6U3.mjs → transport-stream-shared-D8nQWCUo.mjs} +10 -118
- package/dist/{transport-utils-Bv0FHkd0.mjs → transport-utils-CtuS1Upe.mjs} +10 -10
- package/dist/transports.d.mts +130 -189
- package/dist/transports.mjs +227 -1249
- package/dist/{types-DTAP49HF.d.mts → types-Beemor2E.d.mts} +58 -24
- package/dist/types-COdhCX0U.d.mts +1 -0
- package/dist/types.d.mts +6 -5
- package/dist/types.mjs +3 -4
- package/dist/utf16-slice-qz3nsy87.mjs +84 -0
- package/dist/{validation-DYNNrU9u.d.mts → validation-CC6s7Smp.d.mts} +1 -2
- package/dist/{validation-B61OhAio.mjs → validation-CJZtym2g.mjs} +7 -5
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +6 -6
- package/dist/anthropic-BECQCNdF.d.mts +0 -98
- package/dist/event-stream-BVVgDSdq.d.mts +0 -1
- package/dist/headers-B_e4-1J0.mjs +0 -9
- package/dist/index-BVVgDSdq.d.mts +0 -1
- package/dist/openai-completions-D88orSJ9.mjs +0 -632
- package/dist/openai-responses-contracts-DvILoqBk.mjs +0 -247
- package/dist/openai-responses-payload-policy-BDo8CQsx.mjs +0 -208
- package/dist/openai-stop-reason-9OONKyAm.mjs +0 -579
- package/dist/openai-tool-projection-CHGLt03m.mjs +0 -426
- package/dist/provider-options-AvldWZt8.mjs +0 -21
- package/dist/record-coerce-DdXsgUd_.mjs +0 -23
- package/dist/src-D2H6yKkH.mjs +0 -2
- package/dist/stream-first-event-timeout-DvDeSucC.d.mts +0 -29
- package/dist/string-coerce-fsri9iCu.mjs +0 -34
- package/dist/types-BVVgDSdq.d.mts +0 -1
- package/dist/utf16-slice-CvGodqok.mjs +0 -29
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { D as Model, E as Message, J as
|
|
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-Beemor2E.mjs";
|
|
2
|
+
import "../types-COdhCX0U.mjs";
|
|
2
3
|
import { t as sanitizeSurrogates } from "../sanitize-unicode-BZiVbGwK.mjs";
|
|
3
4
|
import { n as normalizeStructuredPromptSection, r as sortPromptCacheToolsByName, t as normalizePromptCapabilityIds } from "../prompt-cache-stability-Cwcjv_fx.mjs";
|
|
4
|
-
|
|
5
5
|
//#region packages/ai/src/providers/simple-options.d.ts
|
|
6
6
|
type FirstEventStreamOptions = {
|
|
7
7
|
firstEventTimeoutMs?: number;
|
|
8
8
|
onFirstEventTimeout?: (reason: Error) => void;
|
|
9
9
|
};
|
|
10
|
-
declare function buildBaseOptions(model: Model, options?: SimpleStreamOptions, apiKey?: string): StreamOptions & FirstEventStreamOptions;
|
|
11
|
-
declare function clampMaxTokensToModel(model: Model, requestedMaxTokens: number): number;
|
|
12
|
-
declare function clampMaxTokensToModel(model: Model, requestedMaxTokens: number | undefined): number | undefined;
|
|
13
|
-
declare function clampReasoning(effort: ThinkingLevel): Exclude<ThinkingLevel, "xhigh">;
|
|
14
|
-
declare function clampReasoning(effort: ThinkingLevel | undefined): Exclude<ThinkingLevel, "xhigh"> | undefined;
|
|
15
|
-
declare function adjustMaxTokensForThinking(baseMaxTokens: number | undefined, modelMaxTokens: number, reasoningLevel: ThinkingLevel, customBudgets?: ThinkingBudgets): {
|
|
10
|
+
export declare function buildBaseOptions(model: Model, options?: SimpleStreamOptions, apiKey?: string): StreamOptions & FirstEventStreamOptions;
|
|
11
|
+
export declare function clampMaxTokensToModel(model: Model, requestedMaxTokens: number): number;
|
|
12
|
+
export declare function clampMaxTokensToModel(model: Model, requestedMaxTokens: number | undefined): number | undefined;
|
|
13
|
+
export declare function clampReasoning(effort: ThinkingLevel): Exclude<ThinkingLevel, "xhigh">;
|
|
14
|
+
export declare function clampReasoning(effort: ThinkingLevel | undefined): Exclude<ThinkingLevel, "xhigh"> | undefined;
|
|
15
|
+
export declare function adjustMaxTokensForThinking(baseMaxTokens: number | undefined, modelMaxTokens: number, reasoningLevel: ThinkingLevel, customBudgets?: ThinkingBudgets): {
|
|
16
16
|
maxTokens: number;
|
|
17
17
|
thinkingBudget: number;
|
|
18
18
|
};
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region packages/ai/src/providers/tool-result-text.d.ts
|
|
21
21
|
/** Media metadata alone is not an attachment; provider emitters need inline bytes. */
|
|
22
|
-
declare function hasMediaPayload(block: unknown): block is Record<string, unknown> & {
|
|
22
|
+
export declare function hasMediaPayload(block: unknown): block is Record<string, unknown> & {
|
|
23
23
|
data: string;
|
|
24
24
|
};
|
|
25
25
|
/** Image metadata alone is not an attachment; provider emitters need inline bytes. */
|
|
26
|
-
declare function isImageWithMediaPayload<T>(block: T): block is T & {
|
|
26
|
+
export declare function isImageWithMediaPayload<T>(block: T): block is T & {
|
|
27
27
|
type: "image";
|
|
28
28
|
data: string;
|
|
29
29
|
};
|
|
30
|
-
declare function describeToolResultMediaPlaceholder(blocks: readonly unknown[]): string | undefined;
|
|
31
|
-
declare function extractToolResultBlockText(block: unknown): string | undefined;
|
|
32
|
-
declare function extractToolResultText(blocks: readonly unknown[], options?: {
|
|
30
|
+
export declare function describeToolResultMediaPlaceholder(blocks: readonly unknown[]): string | undefined;
|
|
31
|
+
export declare function extractToolResultBlockText(block: unknown): string | undefined;
|
|
32
|
+
export declare function extractToolResultText(blocks: readonly unknown[], options?: {
|
|
33
33
|
includeStructured?: boolean;
|
|
34
34
|
}): string;
|
|
35
35
|
type ToolResultMediaSupport = {
|
|
@@ -37,8 +37,8 @@ type ToolResultMediaSupport = {
|
|
|
37
37
|
audio: boolean;
|
|
38
38
|
};
|
|
39
39
|
/** Describe media that cannot be represented on the target provider wire. */
|
|
40
|
-
declare function describeUnsupportedToolResultMedia(blocks: readonly unknown[], support: ToolResultMediaSupport): string | undefined;
|
|
41
|
-
declare function formatToolResultText(params: {
|
|
40
|
+
export declare function describeUnsupportedToolResultMedia(blocks: readonly unknown[], support: ToolResultMediaSupport): string | undefined;
|
|
41
|
+
export declare function formatToolResultText(params: {
|
|
42
42
|
text: string;
|
|
43
43
|
mediaPlaceholder?: string;
|
|
44
44
|
omittedMediaPlaceholder?: string;
|
|
@@ -46,29 +46,29 @@ declare function formatToolResultText(params: {
|
|
|
46
46
|
}): string;
|
|
47
47
|
//#endregion
|
|
48
48
|
//#region packages/ai/src/transcript-transform.d.ts
|
|
49
|
-
declare function transformMessages<TApi extends Api>(messages: Message[], model: Model<TApi>, normalizeToolCallId?: (id: string, model: Model<TApi>, source: AssistantMessage) => string): Message[];
|
|
49
|
+
export declare function transformMessages<TApi extends Api>(messages: Message[], model: Model<TApi>, normalizeToolCallId?: (id: string, model: Model<TApi>, source: AssistantMessage) => string): Message[];
|
|
50
50
|
//#endregion
|
|
51
51
|
//#region packages/ai/src/utils/system-prompt-cache-boundary.d.ts
|
|
52
|
-
declare const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
53
|
-
declare function stripSystemPromptCacheBoundary(text: string): string;
|
|
54
|
-
declare function ensureSystemPromptCacheBoundary(systemPrompt: string): string;
|
|
55
|
-
declare function splitSystemPromptCacheBoundary(text: string): {
|
|
52
|
+
export declare const SYSTEM_PROMPT_CACHE_BOUNDARY = "\n<!-- OPENCLAW_CACHE_BOUNDARY -->\n";
|
|
53
|
+
export declare function stripSystemPromptCacheBoundary(text: string): string;
|
|
54
|
+
export declare function ensureSystemPromptCacheBoundary(systemPrompt: string): string;
|
|
55
|
+
export declare function splitSystemPromptCacheBoundary(text: string): {
|
|
56
56
|
stablePrefix: string;
|
|
57
57
|
dynamicSuffix: string;
|
|
58
58
|
} | undefined;
|
|
59
|
-
declare function prependSystemPromptAdditionAfterCacheBoundary(params: {
|
|
59
|
+
export declare function prependSystemPromptAdditionAfterCacheBoundary(params: {
|
|
60
60
|
systemPrompt: string;
|
|
61
61
|
systemPromptAddition?: string;
|
|
62
62
|
}): string;
|
|
63
63
|
//#endregion
|
|
64
64
|
//#region packages/ai/src/utils/tls-certificate-errors.d.ts
|
|
65
|
-
type TlsCertificateErrorKind = "certificate_invalid" | "hostname_mismatch";
|
|
66
|
-
type TlsCertificateErrorDetails = {
|
|
65
|
+
export type TlsCertificateErrorKind = "certificate_invalid" | "hostname_mismatch";
|
|
66
|
+
export type TlsCertificateErrorDetails = {
|
|
67
67
|
kind: TlsCertificateErrorKind;
|
|
68
68
|
code?: string;
|
|
69
69
|
message: string;
|
|
70
70
|
};
|
|
71
71
|
/** Classify deterministic Node/OpenSSL certificate validation failures. */
|
|
72
|
-
declare function inspectTlsCertificateError(error: unknown): TlsCertificateErrorDetails | null;
|
|
72
|
+
export declare function inspectTlsCertificateError(error: unknown): TlsCertificateErrorDetails | null;
|
|
73
73
|
//#endregion
|
|
74
|
-
export {
|
|
74
|
+
export { normalizePromptCapabilityIds, normalizeStructuredPromptSection, sanitizeSurrogates, sortPromptCacheToolsByName };
|
package/dist/internal/shared.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as sanitizeSurrogates } from "../sanitize-unicode-
|
|
2
|
-
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-
|
|
3
|
-
import {
|
|
1
|
+
import { t as sanitizeSurrogates } from "../sanitize-unicode-S6binQG-.mjs";
|
|
2
|
+
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-BIaiBURL.mjs";
|
|
3
|
+
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-rdOPzr7Z.mjs";
|
|
4
4
|
import { t as inspectTlsCertificateError } from "../tls-certificate-errors-DXSpluKI.mjs";
|
|
5
5
|
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 };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as asNonArrayRecord } from "./utf16-slice-qz3nsy87.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([
|
|
@@ -126,5 +126,21 @@ function parseStreamingJson(partialJson) {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
+
const TOOL_ARGUMENT_PREVIEW_FIRST_CHECKPOINT_CHARS = 512;
|
|
130
|
+
/**
|
|
131
|
+
* Streamed tool-call arguments are preview-only; the terminal parse re-reads
|
|
132
|
+
* the full buffer authoritatively at content_block_stop. Reparsing every delta
|
|
133
|
+
* scans an ever-growing buffer and makes assembly quadratic in the argument
|
|
134
|
+
* size, so refresh previews on a geometric length schedule instead — bounded
|
|
135
|
+
* staleness, linear total parse work.
|
|
136
|
+
*/
|
|
137
|
+
function createToolArgumentPreviewSchedule() {
|
|
138
|
+
let nextCheckpointChars = TOOL_ARGUMENT_PREVIEW_FIRST_CHECKPOINT_CHARS;
|
|
139
|
+
return (accumulatedChars) => {
|
|
140
|
+
if (accumulatedChars < nextCheckpointChars) return false;
|
|
141
|
+
nextCheckpointChars = accumulatedChars * 2;
|
|
142
|
+
return true;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
129
145
|
//#endregion
|
|
130
|
-
export {
|
|
146
|
+
export { repairJson as i, parseJsonWithRepair as n, parseStreamingJson as r, createToolArgumentPreviewSchedule as t };
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
1
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
3
|
-
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-
|
|
4
|
-
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, l as formatToolResultText, n as getAiTransportHost } from "./host-
|
|
5
|
-
import { n as projectProviderError } from "./provider-error-
|
|
6
|
-
import {
|
|
7
|
-
import { n as
|
|
2
|
+
import { i as clampThinkingLevel, r as calculateCost, t as sanitizeSurrogates } from "./sanitize-unicode-S6binQG-.mjs";
|
|
3
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText, d as isImageWithMediaPayload, l as formatToolResultText, n as getAiTransportHost } from "./host-BIaiBURL.mjs";
|
|
4
|
+
import { n as projectProviderError } from "./provider-error-BI8kIViN.mjs";
|
|
5
|
+
import { d as stripSystemPromptCacheBoundary, m as sortPromptCacheToolsByName, n as buildBaseOptions, r as clampMaxTokensToModel } from "./simple-options-rdOPzr7Z.mjs";
|
|
6
|
+
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
7
|
+
import { _ as transportAbortError, f as notifyProviderHttpResponse, s as finalizeTerminalToolCallArguments } from "./transport-stream-shared-D8nQWCUo.mjs";
|
|
8
|
+
import { r as parseStreamingJson, t as createToolArgumentPreviewSchedule } from "./json-parse-BuAJEbdW.mjs";
|
|
8
9
|
import { t as shortHash } from "./hash-CHgqbJmD.mjs";
|
|
9
|
-
import { t as transformProviderMessages } from "./provider-transcript-transform
|
|
10
|
-
import { t as
|
|
10
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-WvJmFUAf.mjs";
|
|
11
|
+
import { t as mapOpenAIStopReason } from "./openai-stop-reason-Drnn_6Qj.mjs";
|
|
12
|
+
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
11
13
|
import { randomUUID } from "node:crypto";
|
|
12
|
-
import { HTTPClient
|
|
14
|
+
import { HTTPClient } from "@mistralai/mistralai/lib/http";
|
|
15
|
+
import { Chat } from "@mistralai/mistralai/sdk/chat";
|
|
13
16
|
//#region packages/ai/src/providers/mistral.ts
|
|
14
17
|
const MISTRAL_TOOL_CALL_ID_LENGTH = 9;
|
|
15
|
-
const MISTRAL_STREAM_BODY_MAX_BYTES =
|
|
18
|
+
const MISTRAL_STREAM_BODY_MAX_BYTES = 16777216;
|
|
16
19
|
/**
|
|
17
20
|
* Builds a `Fetcher` that wraps the default `fetch` with a 16 MiB byte cap
|
|
18
21
|
* on streamed response bodies. The wrapped `Response.body` exposes a
|
|
@@ -28,7 +31,8 @@ function createBoundedMistralFetcher(maxBytes = MISTRAL_STREAM_BODY_MAX_BYTES, u
|
|
|
28
31
|
return async (input, init) => {
|
|
29
32
|
const response = init == null ? await upstreamFetch(input) : await upstreamFetch(input, init);
|
|
30
33
|
if (!response.body || typeof response.body.getReader !== "function") return response;
|
|
31
|
-
const
|
|
34
|
+
const reader = response.body.getReader();
|
|
35
|
+
const guard = createSseByteGuard(reader, {
|
|
32
36
|
maxBytes,
|
|
33
37
|
onOverflow: ({ size, maxBytes: cap }) => /* @__PURE__ */ new Error(`mistral: stream body exceeds ${cap} bytes (got ${size})`)
|
|
34
38
|
});
|
|
@@ -77,7 +81,7 @@ const streamMistral = (model, context, options) => {
|
|
|
77
81
|
reportedResponse = response;
|
|
78
82
|
}
|
|
79
83
|
});
|
|
80
|
-
const
|
|
84
|
+
const chat = new Chat({
|
|
81
85
|
apiKey,
|
|
82
86
|
serverURL: model.baseUrl,
|
|
83
87
|
httpClient
|
|
@@ -91,7 +95,7 @@ const streamMistral = (model, context, options) => {
|
|
|
91
95
|
...options?.headers
|
|
92
96
|
};
|
|
93
97
|
if (resolveMistralPromptCacheKey(options) && options?.sessionId) headers["x-affinity"] ||= options.sessionId;
|
|
94
|
-
const mistralStream = await
|
|
98
|
+
const mistralStream = await chat.stream(payload, {
|
|
95
99
|
headers,
|
|
96
100
|
signal: options?.signal
|
|
97
101
|
});
|
|
@@ -107,7 +111,7 @@ const streamMistral = (model, context, options) => {
|
|
|
107
111
|
});
|
|
108
112
|
await consumeChatStream(model, output, stream, mistralStream);
|
|
109
113
|
if (options?.signal?.aborted) throw transportAbortError(options.signal);
|
|
110
|
-
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error("An unknown error occurred");
|
|
114
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error(output.errorMessage ?? "An unknown error occurred");
|
|
111
115
|
stream.push({
|
|
112
116
|
type: "done",
|
|
113
117
|
reason: output.stopReason,
|
|
@@ -195,7 +199,8 @@ function deriveMistralToolCallId(id, attempt) {
|
|
|
195
199
|
const normalized = id.replace(/[^a-zA-Z0-9]/g, "");
|
|
196
200
|
if (attempt === 0 && normalized.length === MISTRAL_TOOL_CALL_ID_LENGTH) return normalized;
|
|
197
201
|
const seedBase = normalized || id;
|
|
198
|
-
|
|
202
|
+
const seed = attempt === 0 ? seedBase : `${seedBase}:${attempt}`;
|
|
203
|
+
return shortHash(seed).replace(/[^a-zA-Z0-9]/g, "").padEnd(MISTRAL_TOOL_CALL_ID_LENGTH, "0").slice(0, MISTRAL_TOOL_CALL_ID_LENGTH);
|
|
199
204
|
}
|
|
200
205
|
function buildChatPayload(model, context, messages, options) {
|
|
201
206
|
const payload = {
|
|
@@ -241,6 +246,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
241
246
|
const blocks = output.content;
|
|
242
247
|
const blockIndex = () => blocks.length - 1;
|
|
243
248
|
const toolBlockIdentities = /* @__PURE__ */ new Map();
|
|
249
|
+
const toolArgumentPreviewSchedules = /* @__PURE__ */ new WeakMap();
|
|
244
250
|
const normalizeMissingToolCallId = createMistralToolCallIdNormalizer();
|
|
245
251
|
const missingToolCallIdScope = randomUUID();
|
|
246
252
|
const createMissingToolCallId = (contentIndex) => normalizeMissingToolCallId(`${missingToolCallIdScope}:toolcall:${contentIndex}`);
|
|
@@ -320,6 +326,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
320
326
|
for await (const event of mistralStream) {
|
|
321
327
|
const chunk = event.data;
|
|
322
328
|
output.responseId ||= chunk.id;
|
|
329
|
+
if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) output.responseModel ||= chunk.model;
|
|
323
330
|
if (chunk.usage) {
|
|
324
331
|
const promptTokens = chunk.usage.promptTokens || 0;
|
|
325
332
|
const cachedPromptTokens = readMistralCachedPromptTokens(chunk.usage, promptTokens);
|
|
@@ -334,7 +341,9 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
334
341
|
if (!choice) continue;
|
|
335
342
|
if (choice.finishReason) {
|
|
336
343
|
terminalFinishReason = choice.finishReason;
|
|
337
|
-
|
|
344
|
+
const { stopReason, errorMessage } = mapOpenAIStopReason(choice.finishReason === "model_length" ? "length" : choice.finishReason);
|
|
345
|
+
output.stopReason = stopReason;
|
|
346
|
+
if (errorMessage) output.errorMessage = errorMessage;
|
|
338
347
|
}
|
|
339
348
|
const delta = choice.delta;
|
|
340
349
|
if (delta.content !== null && delta.content !== void 0) {
|
|
@@ -365,7 +374,8 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
365
374
|
continue;
|
|
366
375
|
}
|
|
367
376
|
if (item.type === "thinking") {
|
|
368
|
-
const
|
|
377
|
+
const deltaText = item.thinking.map((part) => "text" in part ? part.text : "").filter((text) => text.length > 0).join("");
|
|
378
|
+
const thinkingDelta = sanitizeSurrogates(deltaText);
|
|
369
379
|
if (!thinkingDelta) continue;
|
|
370
380
|
if (!currentBlock || currentBlock.type !== "thinking") {
|
|
371
381
|
finishCurrentBlock(currentBlock);
|
|
@@ -445,6 +455,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
445
455
|
partialArgs: ""
|
|
446
456
|
};
|
|
447
457
|
output.content.push(block);
|
|
458
|
+
toolArgumentPreviewSchedules.set(block, createToolArgumentPreviewSchedule());
|
|
448
459
|
toolBlockIdentities.set(contentIndex, {
|
|
449
460
|
explicitIds: new Set(providedCallId ? [providedCallId] : []),
|
|
450
461
|
functionNames: new Set(functionName ? [functionName] : []),
|
|
@@ -472,7 +483,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
472
483
|
if (toolCallIndex !== void 0) identity.indexes.add(toolCallIndex);
|
|
473
484
|
const argsDelta = typeof toolCall.function.arguments === "string" ? toolCall.function.arguments : JSON.stringify(toolCall.function.arguments || {});
|
|
474
485
|
block.partialArgs = (block.partialArgs || "") + argsDelta;
|
|
475
|
-
block.arguments = parseStreamingJson(block.partialArgs);
|
|
486
|
+
if (toolArgumentPreviewSchedules.get(block)?.(block.partialArgs.length)) block.arguments = parseStreamingJson(block.partialArgs);
|
|
476
487
|
stream.push({
|
|
477
488
|
type: "toolcall_delta",
|
|
478
489
|
contentIndex,
|
|
@@ -506,7 +517,7 @@ async function consumeChatStream(model, output, stream, mistralStream) {
|
|
|
506
517
|
}
|
|
507
518
|
}
|
|
508
519
|
function toFunctionTools(tools) {
|
|
509
|
-
|
|
520
|
+
const converted = tools.flatMap((tool) => {
|
|
510
521
|
try {
|
|
511
522
|
const name = tool.name;
|
|
512
523
|
const description = tool.description;
|
|
@@ -526,7 +537,8 @@ function toFunctionTools(tools) {
|
|
|
526
537
|
} catch {
|
|
527
538
|
return [];
|
|
528
539
|
}
|
|
529
|
-
})
|
|
540
|
+
});
|
|
541
|
+
return sortPromptCacheToolsByName(converted).map(({ value }) => value);
|
|
530
542
|
}
|
|
531
543
|
function stripSymbolKeys(value) {
|
|
532
544
|
if (Array.isArray(value)) return value.map((item) => stripSymbolKeys(item));
|
|
@@ -611,10 +623,11 @@ function toChatMessages(messages, supportsImages) {
|
|
|
611
623
|
const toolContent = [];
|
|
612
624
|
const textResult = extractToolResultText(msg.content);
|
|
613
625
|
const mediaPlaceholder = describeToolResultMediaPlaceholder(msg.content);
|
|
626
|
+
const omittedMediaPlaceholder = msg.content.some(isImageWithMediaPayload) && !supportsImages ? textResult.trim() ? "[tool image omitted: model does not support images]" : mediaPlaceholder === "(see attached media)" ? "(media omitted: model does not support images)" : "(image omitted: model does not support images)" : void 0;
|
|
614
627
|
const toolText = formatToolResultText({
|
|
615
628
|
text: textResult,
|
|
616
629
|
mediaPlaceholder,
|
|
617
|
-
omittedMediaPlaceholder
|
|
630
|
+
omittedMediaPlaceholder,
|
|
618
631
|
isError: msg.isError
|
|
619
632
|
});
|
|
620
633
|
toolContent.push({
|
|
@@ -661,16 +674,5 @@ function mapToolChoice(choice, convertedToolNames) {
|
|
|
661
674
|
function: { name: toolName }
|
|
662
675
|
};
|
|
663
676
|
}
|
|
664
|
-
function mapChatStopReason(reason) {
|
|
665
|
-
if (reason === null) return "stop";
|
|
666
|
-
switch (reason) {
|
|
667
|
-
case "stop": return "stop";
|
|
668
|
-
case "length":
|
|
669
|
-
case "model_length": return "length";
|
|
670
|
-
case "tool_calls": return "toolUse";
|
|
671
|
-
case "error": return "error";
|
|
672
|
-
default: return "stop";
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
677
|
//#endregion
|
|
676
678
|
export { createBoundedMistralFetcher, streamMistral, streamSimpleMistral };
|
package/dist/{openai-chatgpt-responses-C339VIfT.mjs → openai-chatgpt-responses-Czum0oXz.mjs}
RENAMED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { n as getEnvApiKey } from "./env-api-keys-DrgeBuva.mjs";
|
|
2
1
|
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-COpOtRwq.mjs";
|
|
3
2
|
import { t as AssistantMessageEventStream } from "./event-stream-uSMZJ3FA.mjs";
|
|
4
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
5
|
-
import { n as projectProviderError } from "./provider-error-
|
|
6
|
-
import { n as toErrorObject, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal
|
|
7
|
-
import {
|
|
8
|
-
import { S as supportsOpenAITemperature, m as responsesPromptObserver } from "./openai-responses-contracts-DvILoqBk.mjs";
|
|
3
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-BIaiBURL.mjs";
|
|
4
|
+
import { n as projectProviderError } from "./provider-error-BI8kIViN.mjs";
|
|
5
|
+
import { n as toErrorObject, t as createResponsesPromptEgressObserver } from "./openai-responses-prompt-observer-internal--R0kZLOZ.mjs";
|
|
6
|
+
import { o as clampTimerTimeoutMs, u as resolveTimerTimeoutMs } from "./base64-CEFBpSkN.mjs";
|
|
9
7
|
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-mZTCdRPo.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import { t as headersToRecord } from "./headers-B_e4-1J0.mjs";
|
|
8
|
+
import { d as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-rdOPzr7Z.mjs";
|
|
12
9
|
import { parseRetryAfterHttpDateMs } from "./internal/retry-after.mjs";
|
|
13
|
-
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { a as
|
|
10
|
+
import { t as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "./transport-utils-CtuS1Upe.mjs";
|
|
11
|
+
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
12
|
+
import { C as headersToRecord, _ as transportAbortError, p as notifyProviderStreamOpened, y as withProviderResponseHook } from "./transport-stream-shared-D8nQWCUo.mjs";
|
|
13
|
+
import { F as commitResponsesEncryptedContentAttempt, L as isInvalidEncryptedContentError, W as buildOpenAIResponsesReasoningReplayMetadata, a as resolveResponsesReasoningEffort, c as processResponsesStream, i as createResponsesAssistantOutput, n as applyResponsesServiceTierPricing, p as ResponsesStreamFailure, q as suppressOpenAIResponsesCompaction, r as convertResponsesMessages, s as convertResponsesToolPayload, z as resolveNextResponsesEncryptedContentAttempt } from "./openai-responses-shared-CxgdGBvm.mjs";
|
|
14
|
+
import { C as createOpenAIProviderAcceptanceHook, w as createOpenAIResponseHook } from "./openai-tool-schema-CSMh5e9O.mjs";
|
|
15
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-DcNjoFQE.mjs";
|
|
16
|
+
import { A as supportsOpenAITemperature, S as responsesPromptObserver } from "./openai-responses-compaction-window-DO7yV7az.mjs";
|
|
17
|
+
import { t as createSseByteGuard } from "./streaming-byte-guard-CC-HMn_u.mjs";
|
|
17
18
|
import { n as registerSessionResourceCleanup } from "./session-resources-CkR4WWy1.mjs";
|
|
18
19
|
import "./diagnostics.mjs";
|
|
19
20
|
import { n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
20
|
-
import { t as createSseByteGuard } from "./streaming-byte-guard-BrbkbwUu.mjs";
|
|
21
21
|
import { t as inspectTlsCertificateError } from "./tls-certificate-errors-DXSpluKI.mjs";
|
|
22
22
|
//#region packages/ai/src/internal/retry-sleep.ts
|
|
23
23
|
function sleepWithAbort(ms, signal) {
|
|
@@ -40,7 +40,7 @@ function sleepWithAbort(ms, signal) {
|
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region packages/ai/src/providers/openai-chatgpt-responses-protocol.ts
|
|
43
|
-
const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES =
|
|
43
|
+
const OPENAI_CHATGPT_RESPONSES_SUCCESS_BODY_MAX_BYTES = 16777216;
|
|
44
44
|
var CodexProtocolError = class extends Error {
|
|
45
45
|
constructor(message, options) {
|
|
46
46
|
super(message);
|
|
@@ -110,7 +110,7 @@ const REQUEST_COMPRESSION_ZSTD_LEVEL = 3;
|
|
|
110
110
|
const CODEX_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "opencode"]);
|
|
111
111
|
const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
112
112
|
const WEBSOCKET_CONNECTION_LIMIT_REACHED_CODE = "websocket_connection_limit_reached";
|
|
113
|
-
const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES =
|
|
113
|
+
const OPENAI_CHATGPT_RESPONSES_ERROR_BODY_MAX_BYTES = 16384;
|
|
114
114
|
const CODEX_RESPONSE_STATUSES = /* @__PURE__ */ new Set([
|
|
115
115
|
"completed",
|
|
116
116
|
"incomplete",
|
|
@@ -154,6 +154,12 @@ function isRequestTimeoutError(error, callerSignal, requestSignal, timeoutMs) {
|
|
|
154
154
|
if (!(error instanceof Error)) return false;
|
|
155
155
|
return error.name === "AbortError" || error.name === "TimeoutError" || error.message === "Request was aborted";
|
|
156
156
|
}
|
|
157
|
+
/** Local-only failure category for transport diagnostics; never provider text. */
|
|
158
|
+
function classifyStreamFailure(error, signal, requestTimedOut) {
|
|
159
|
+
if (requestTimedOut) return "timeout";
|
|
160
|
+
if (signal?.aborted) return "caller-abort";
|
|
161
|
+
return error instanceof ResponsesStreamFailure || error instanceof CodexApiError ? "provider-failure" : "transport";
|
|
162
|
+
}
|
|
157
163
|
function formatRequestTimeoutError(timeoutMs, cause) {
|
|
158
164
|
return new Error(`Request timed out after ${timeoutMs}ms`, { cause: cause instanceof Error ? cause : void 0 });
|
|
159
165
|
}
|
|
@@ -171,6 +177,7 @@ function compressRequestBodyZstd(bodyJson) {
|
|
|
171
177
|
const streamOpenAICodexResponses = (model, context, options) => {
|
|
172
178
|
const stream = new AssistantMessageEventStream();
|
|
173
179
|
(async () => {
|
|
180
|
+
const startedAt = Date.now();
|
|
174
181
|
let requestTimeoutMs;
|
|
175
182
|
let requestTimeoutSignal;
|
|
176
183
|
let activeSignal;
|
|
@@ -333,7 +340,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
333
340
|
if (!nextSemanticAttempt) throw terminalResponseError ?? /* @__PURE__ */ new Error("Failed after retries");
|
|
334
341
|
semanticAttempt = nextSemanticAttempt;
|
|
335
342
|
}
|
|
336
|
-
|
|
343
|
+
const hookedResponseStream = withProviderResponseHook({
|
|
337
344
|
stream: mapCodexEvents(parseOpenAIChatGptResponsesSse(response)),
|
|
338
345
|
signal: firstEventAbort.signal,
|
|
339
346
|
abort: firstEventAbort.abort,
|
|
@@ -342,7 +349,8 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
342
349
|
type: "start",
|
|
343
350
|
partial: output
|
|
344
351
|
})
|
|
345
|
-
})
|
|
352
|
+
});
|
|
353
|
+
await processResponsesStream(hookedResponseStream, output, stream, model, {
|
|
346
354
|
serviceTier: options?.serviceTier,
|
|
347
355
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(options),
|
|
348
356
|
abortFirstEventStream: firstEventAbort.abort,
|
|
@@ -364,9 +372,19 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
364
372
|
});
|
|
365
373
|
stream.end();
|
|
366
374
|
} catch (error) {
|
|
367
|
-
const
|
|
375
|
+
const requestTimedOut = isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0;
|
|
376
|
+
const normalizedError = requestTimedOut && requestTimeoutMs !== void 0 ? formatRequestTimeoutError(requestTimeoutMs, error) : error;
|
|
368
377
|
for (const block of output.content) delete block.partialJson;
|
|
369
378
|
const terminal = projectProviderError(normalizedError, options?.signal);
|
|
379
|
+
getAiTransportHost().logWarn("openai-transport", "ChatGPT Responses stream terminated", {
|
|
380
|
+
provider: model.provider,
|
|
381
|
+
api: model.api,
|
|
382
|
+
model: model.id,
|
|
383
|
+
transport: options?.transport || "auto",
|
|
384
|
+
elapsedMs: Math.max(0, Date.now() - startedAt),
|
|
385
|
+
stopReason: terminal.stopReason,
|
|
386
|
+
failureKind: classifyStreamFailure(error, options?.signal, requestTimedOut)
|
|
387
|
+
});
|
|
370
388
|
Object.assign(output, terminal);
|
|
371
389
|
stream.push({
|
|
372
390
|
type: "error",
|
|
@@ -498,8 +516,8 @@ function normalizeCodexStatus(status) {
|
|
|
498
516
|
return CODEX_RESPONSE_STATUSES.has(status) ? status : void 0;
|
|
499
517
|
}
|
|
500
518
|
const OPENAI_BETA_RESPONSES_WEBSOCKETS = "responses_websockets=2026-02-06";
|
|
501
|
-
const SESSION_WEBSOCKET_CACHE_TTL_MS =
|
|
502
|
-
const SESSION_WEBSOCKET_MAX_AGE_MS =
|
|
519
|
+
const SESSION_WEBSOCKET_CACHE_TTL_MS = 3e5;
|
|
520
|
+
const SESSION_WEBSOCKET_MAX_AGE_MS = 33e5;
|
|
503
521
|
const websocketSessionCache = /* @__PURE__ */ new Map();
|
|
504
522
|
const websocketSseFallbackSessions = /* @__PURE__ */ new Set();
|
|
505
523
|
let cachedWebsocket = null;
|