@openclaw/ai 2026.10.5-beta.4 → 2026.10.10-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/{anthropic-BalhAzs-.mjs → anthropic-D6spfBri.mjs} +16 -18
- package/dist/{anthropic-payload-policy-DGblkHL5.d.mts → anthropic-payload-policy-Cr8xjazC.d.mts} +6 -3
- package/dist/{anthropic-stream-reducer-DkKeXXx4.mjs → anthropic-stream-reducer-CzPXOaLM.mjs} +59 -226
- package/dist/anthropic-tool-projection-BdAS3rtJ.mjs +165 -0
- package/dist/anthropic-tool-projection-DKH-aEWU.d.mts +51 -0
- package/dist/{api-registry-BhXXYdRA.d.mts → api-registry-gDt0faai.d.mts} +2 -2
- package/dist/{assistant-output-BuhRpLeD.mjs → assistant-output-6iFA1nbC.mjs} +2 -2
- package/dist/{azure-openai-responses-DfT9Ndd8.mjs → azure-openai-responses-0TqHwnlD.mjs} +8 -8
- package/dist/{cloudflare-5qSGvIUH.mjs → cloudflare-Dttf8jKq.mjs} +1 -1
- package/dist/{credential-redaction-BHxruEH6.d.mts → credential-redaction-XvsPf7Yi.d.mts} +1 -0
- package/dist/{diagnostics-tQasYct1.mjs → diagnostics-Cv7cW3pS.mjs} +3 -3
- package/dist/diagnostics.d.mts +6 -6
- package/dist/diagnostics.mjs +2 -2
- package/dist/{env-api-keys-CrxwdylR.mjs → env-api-keys-Xd8dm_aV.mjs} +10 -34
- package/dist/event-stream-CDpFza-M.d.mts +1 -0
- package/dist/{event-stream-BcqWLo_u.d.mts → event-stream-CzpE1g_o.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/{github-copilot-request-facts-DEE6gcB9.mjs → github-copilot-request-facts-F-EmvkpW.mjs} +1 -1
- package/dist/{google-interactions-9SSqsJg9.mjs → google-interactions-CTEBy9od.mjs} +19 -37
- package/dist/{google-messages-DsB7fmoQ.mjs → google-messages-DfpHVTaD.mjs} +18 -6
- package/dist/{google-provider-stream-CcEI2-MC.mjs → google-provider-stream-DJ8ANfsS.mjs} +6 -6
- package/dist/{google-shared-zGR0QUyS.mjs → google-shared-VTcCJLW3.mjs} +28 -41
- package/dist/{google-vertex-Dw_abY1w.mjs → google-vertex-Bkfizj7M.mjs} +3 -3
- package/dist/{google-sYI2wnY6.mjs → google-zWpkDSeN.mjs} +4 -4
- package/dist/{host-Bf3NjYNj.mjs → host-B2gk-d1H.mjs} +5 -11
- package/dist/{host-CTDz7LXD.d.mts → host-jJOffdlW.d.mts} +4 -6
- package/dist/{host-policy-BzZluO6_.mjs → host-policy-mpqGhbeM.mjs} +1 -1
- package/dist/{index-BYDvopUB.d.mts → index-DSprYWaz.d.mts} +7 -5
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +6 -6
- package/dist/internal/anthropic.d.mts +7 -53
- package/dist/internal/anthropic.mjs +6 -5
- package/dist/internal/google-model-family.d.mts +2 -0
- package/dist/internal/google-model-family.mjs +7 -3
- package/dist/internal/openai-completions-compat.d.mts +1 -1
- package/dist/internal/openai-completions-compat.mjs +1 -1
- package/dist/internal/openai-responses-payload-policy.d.mts +3 -3
- package/dist/internal/openai-responses-payload-policy.mjs +3 -3
- package/dist/internal/openai.d.mts +17 -26
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/retry-after.d.mts +1 -1
- package/dist/internal/retry-after.mjs +80 -55
- package/dist/internal/runtime.d.mts +9 -31
- package/dist/internal/runtime.mjs +10 -116
- package/dist/internal/shared.d.mts +9 -7
- package/dist/internal/shared.mjs +8 -6
- package/dist/internal/tool-schema.d.mts +83 -5
- package/dist/internal/tool-schema.mjs +4 -3
- package/dist/{mistral-dCDCR5ur.mjs → mistral-CATJrwne.mjs} +32 -35
- package/dist/model-request-body-BD5vy4rP.d.mts +17 -0
- package/dist/{number-coercion-C3hztWoY.mjs → number-coercion-37gmNkuA.mjs} +1 -1
- package/dist/{openai-chatgpt-responses-BHI3uCcA.mjs → openai-chatgpt-responses-CtdnpWwe.mjs} +95 -63
- package/dist/{openai-completions-CrVgnFrV.mjs → openai-completions-B6sET3oI.mjs} +10 -8
- package/dist/{openai-completions-compat-i-nLZxFy.d.mts → openai-completions-compat-1gsjP-KO.d.mts} +6 -3
- package/dist/{openai-completions-compat-CYX18uDk.mjs → openai-completions-compat-CFhQ3UVU.mjs} +7 -2
- package/dist/{openai-completions-transport-Dy4CZo9Q.mjs → openai-completions-transport-DviPEqw3.mjs} +370 -237
- package/dist/{openai-prompt-cache-r93BJhjm.mjs → openai-prompt-cache-DJ_P143P.mjs} +1 -1
- package/dist/{openai-prompt-cache-DIPMrMFy.d.mts → openai-prompt-cache-DgjD-UL5.d.mts} +2 -2
- package/dist/{openai-responses-D5oiAUOG.mjs → openai-responses-BXsJK-mD.mjs} +13 -15
- package/dist/{openai-responses-compaction-replay-B2FE4Nw8.d.mts → openai-responses-compaction-replay-Cvnl_nCq.d.mts} +5 -5
- package/dist/{openai-responses-contracts-DlKMMTxK.mjs → openai-responses-contracts-Bx-16mnf.mjs} +45 -6
- package/dist/{openai-responses-contracts-DKqMJ1Ct.d.mts → openai-responses-contracts-CQ4_AWjL.d.mts} +20 -8
- package/dist/{openai-responses-endpoint-CinGh4VZ.mjs → openai-responses-endpoint-D4v-eeYy.mjs} +55 -22
- package/dist/{openai-responses-payload-policy-C7GsA1y0.d.mts → openai-responses-payload-policy-BzM52TTH.d.mts} +9 -3
- package/dist/openai-responses-request-lifecycle-CTdAb2v1.mjs +246 -0
- package/dist/{openai-responses-shared-D-aDYAkJ.mjs → openai-responses-shared-Bv_1NtH9.mjs} +284 -160
- package/dist/{openai-responses-terminal-usage-BygjiAdi.d.mts → openai-responses-terminal-usage-CpVjkqn-.d.mts} +2 -2
- package/dist/{openai-tool-schema-DDPXsvJP.mjs → openai-tool-schema-Buv0GXFb.mjs} +170 -237
- package/dist/overflow-DJHXTNBQ.mjs +117 -0
- package/dist/{positive-integer-CqWjqSi9.mjs → positive-integer-Bb4Evc7L.mjs} +1 -1
- package/dist/prompt-cache-stability-D_MeCQFI.mjs +32 -0
- package/dist/{provider-error-xumb1V3F.d.mts → provider-error-CnaWYTRY.d.mts} +1 -0
- package/dist/{provider-error-CF9GWCs2.mjs → provider-error-qtZD2inE.mjs} +75 -13
- package/dist/{provider-options-CVrXZBtA.d.mts → provider-options-DeYeaflL.d.mts} +52 -6
- package/dist/{text-signature-Drb4Erb8.mjs → provider-replay-context-J6CfU3m1.mjs} +5 -14
- package/dist/{provider-transport-turn-state-BOpxgm-J.mjs → provider-transport-turn-state-Jxppzuc2.mjs} +5 -5
- package/dist/{provider-types-CHtRx0dI.d.mts → provider-types-ODq57rG_.d.mts} +3 -3
- package/dist/provider-types.d.mts +6 -6
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-CpOy9-IQ.mjs → reasoning-tag-text-partitioner-DzlRubwU.mjs} +134 -47
- package/dist/{required-api-key-CFJvcFy_.mjs → required-api-key-D088S4Cd.mjs} +1 -1
- package/dist/{retry-after-CdCURCVg.d.mts → retry-after-sw-XX8aC.d.mts} +1 -1
- package/dist/sanitize-unicode-CRGuMONI.mjs +8 -0
- package/dist/sanitize-unicode-ZqVLLEKC.d.mts +27 -0
- package/dist/{session-resources-D1wgDQ8C.mjs → session-resources-vKvGIE3J.mjs} +1 -10
- package/dist/{simple-options-BAu4B54D.mjs → simple-options-BYgC6kse.mjs} +68 -79
- package/dist/{src-C44MKrW5.mjs → src-CyA0zJnt.mjs} +6 -2
- package/dist/{stream-Dd8DwRFL.mjs → stream-DLBirT0e.mjs} +8 -47
- package/dist/{stream-first-event-timeout-Dc42hKv6.mjs → stream-first-event-timeout-D_TfJHRJ.mjs} +1 -1
- package/dist/{string-coerce-CtgOVOSv.mjs → string-coerce-Cj8sqWHx.mjs} +26 -1
- package/dist/tool-schema-json-projection-B0hHDV7N.mjs +492 -0
- package/dist/{transport-stream-shared-BmpzDtdQ.d.mts → transport-stream-shared-8ru8eX4s.d.mts} +5 -5
- package/dist/{transport-stream-shared-CWGOuLcA.mjs → transport-stream-shared-CzQlAzJH.mjs} +27 -75
- package/dist/transports.d.mts +34 -28
- package/dist/transports.mjs +42 -48
- package/dist/{types-CQc6JNG4.mjs → types-BXd0kI8-.mjs} +1 -1
- package/dist/types-CBJthzJX.d.mts +1 -0
- package/dist/{types-Bd2T86VJ.d.mts → types-CVYzKrMl.d.mts} +20 -3
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +4 -4
- package/dist/{validation-ZX_sPVV0.mjs → validation-9FSkE8T-.mjs} +22 -3
- package/dist/{validation-DdGB1yy3.d.mts → validation-BQ5u20Ru.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +3 -3
- package/dist/assistant-text-phase-Bn1hbvK9.mjs +0 -50
- package/dist/event-stream-6UNs-AhN.d.mts +0 -1
- package/dist/expect-lbe3Hgrh.mjs +0 -8
- package/dist/json-schema-Bp07Qui3.mjs +0 -22
- package/dist/openai-responses-request-lifecycle-NSIJo9jY.mjs +0 -67
- package/dist/openai-tool-projection-793cE3QX.d.mts +0 -37
- package/dist/openai-tool-schema-a5ysBBga.d.mts +0 -32
- package/dist/rolldown-runtime-BhDjJH2R.mjs +0 -15
- package/dist/sanitize-unicode-CjDG6jJx.d.mts +0 -5
- package/dist/string-normalization-I3ux50s9.mjs +0 -28
- package/dist/tool-schema-json-projection-B8sG1I9v.mjs +0 -180
- package/dist/types-Kdfw_04V.d.mts +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as OpenAIToolProjection } from "../provider-options-DeYeaflL.mjs";
|
|
2
|
+
import { a as prepareAnthropicInputSchema } from "../anthropic-tool-projection-DKH-aEWU.mjs";
|
|
2
3
|
import { TSchema } from "typebox";
|
|
3
4
|
//#region packages/ai/src/providers/agent-tools-parameter-schema.d.ts
|
|
4
5
|
/**
|
|
@@ -24,6 +25,7 @@ export declare function shouldOmitEmptyArrayItems(modelOrCompat: {
|
|
|
24
25
|
compat?: unknown;
|
|
25
26
|
} | ToolSchemaModelCompat | undefined): boolean;
|
|
26
27
|
export type ToolParameterSchemaOptions = {
|
|
28
|
+
toolName?: string;
|
|
27
29
|
modelProvider?: string;
|
|
28
30
|
modelId?: string;
|
|
29
31
|
modelCompat?: ToolSchemaModelCompat;
|
|
@@ -33,20 +35,88 @@ export declare function normalizeToolParameterSchema(schema: unknown, options?:
|
|
|
33
35
|
//#endregion
|
|
34
36
|
//#region packages/ai/src/providers/clean-for-gemini.d.ts
|
|
35
37
|
export declare const GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS: Set<string>;
|
|
36
|
-
export declare function cleanSchemaForGemini(schema: unknown): TSchema;
|
|
38
|
+
export declare function cleanSchemaForGemini(schema: unknown, toolName?: string): TSchema;
|
|
37
39
|
//#endregion
|
|
38
40
|
//#region packages/ai/src/providers/clean-for-llamacpp-gbnf.d.ts
|
|
39
41
|
/** llama.cpp rejects grammar repetitions whose expanded rule count reaches 2000. */
|
|
40
42
|
export declare const LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD = 2000;
|
|
41
43
|
/** Removes JSON Schema constraints that llama.cpp cannot compile into GBNF. */
|
|
42
|
-
export declare function cleanSchemaForLlamacppGbnf(schema: unknown): unknown;
|
|
44
|
+
export declare function cleanSchemaForLlamacppGbnf(schema: unknown, toolName?: string): unknown;
|
|
43
45
|
/** Reports schema paths that llama.cpp cannot compile into GBNF. */
|
|
44
46
|
export declare function findLlamacppGbnfSchemaViolations(schema: unknown, path: string): string[];
|
|
45
47
|
//#endregion
|
|
48
|
+
//#region packages/ai/src/providers/openai-tool-schema-compat.d.ts
|
|
49
|
+
/** Repairs recoverable OpenAI tool-schema shapes before canonical normalization. */
|
|
50
|
+
export declare function normalizeOpenAIStrictCompatSchema(schema: unknown): TSchema;
|
|
51
|
+
/** Finds schema paths that violate OpenAI strict tool-schema requirements. */
|
|
52
|
+
export declare function findOpenAIStrictSchemaViolations(schema: unknown, path: string, options?: {
|
|
53
|
+
requireObjectRoot?: boolean;
|
|
54
|
+
}): string[];
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region packages/ai/src/providers/openai-tool-schema.d.ts
|
|
57
|
+
type ToolSchemaCompatInput = {
|
|
58
|
+
unsupportedToolSchemaKeywords?: unknown;
|
|
59
|
+
omitEmptyArrayItems?: unknown;
|
|
60
|
+
};
|
|
61
|
+
/** Normalizes a tool parameter schema into the OpenAI strict JSON-schema subset. */
|
|
62
|
+
export declare function normalizeStrictOpenAIJsonSchema(schema: unknown, modelCompat?: ToolSchemaCompatInput | null): unknown;
|
|
63
|
+
/** Normalizes tool parameters using strict OpenAI rules only when strict mode is active. */
|
|
64
|
+
export declare function normalizeOpenAIStrictToolParameters<T>(schema: T, strict: boolean, modelCompat?: ToolSchemaCompatInput | null): T;
|
|
65
|
+
/** Returns whether a schema already satisfies OpenAI strict tool-schema constraints. */
|
|
66
|
+
export declare function isStrictOpenAIJsonSchemaCompatible(schema: unknown): boolean;
|
|
67
|
+
type OpenAIStrictToolSchemaDiagnostic = {
|
|
68
|
+
toolIndex: number;
|
|
69
|
+
toolName?: string;
|
|
70
|
+
violations: string[];
|
|
71
|
+
};
|
|
72
|
+
/** Returns strict-schema diagnostics for an already materialized OpenAI tool projection. */
|
|
73
|
+
export declare function findOpenAIStrictToolProjectionDiagnostics(projection: OpenAIToolProjection): OpenAIStrictToolSchemaDiagnostic[];
|
|
74
|
+
/** Resolves strict mode for the projected tools that will be emitted in the request payload. */
|
|
75
|
+
export declare function resolveOpenAIProjectedToolsStrictToolFlag(projection: OpenAIToolProjection, strict: boolean | null | undefined): boolean | undefined;
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region packages/ai/src/providers/openai-function-tool.d.ts
|
|
78
|
+
type OpenAIFunctionDescriptor = {
|
|
79
|
+
name: string;
|
|
80
|
+
description: string | undefined;
|
|
81
|
+
parameters: Record<string, unknown>;
|
|
82
|
+
strict?: boolean;
|
|
83
|
+
};
|
|
84
|
+
type PreparedOpenAIFunctionTool = {
|
|
85
|
+
responses: OpenAIFunctionDescriptor & {
|
|
86
|
+
type: "function";
|
|
87
|
+
};
|
|
88
|
+
completions: {
|
|
89
|
+
type: "function";
|
|
90
|
+
function: OpenAIFunctionDescriptor;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
/** Reuse wire descriptors only when their parameter owner published immutable JSON. */
|
|
94
|
+
export declare function prepareOpenAIFunctionTool(name: string, description: string | undefined, parameters: Record<string, unknown>, strict: boolean | undefined): PreparedOpenAIFunctionTool;
|
|
95
|
+
//#endregion
|
|
46
96
|
//#region packages/ai/src/providers/schema-keyword-strip.d.ts
|
|
47
97
|
/** Remove schema keywords unsupported by a target provider/tool surface. */
|
|
48
98
|
export declare function stripUnsupportedSchemaKeywords(schema: unknown, unsupportedKeywords: ReadonlySet<string>): unknown;
|
|
49
99
|
//#endregion
|
|
100
|
+
//#region packages/ai/src/providers/tool-schema-depth.d.ts
|
|
101
|
+
/** Schema nodes and expanded references share this budget; containers are transparent. */
|
|
102
|
+
export declare const MAX_TOOL_SCHEMA_DEPTH = 128;
|
|
103
|
+
export type ToolSchemaPosition = {
|
|
104
|
+
kind: "schema" | "map" | "array" | "dependencies";
|
|
105
|
+
depth: number;
|
|
106
|
+
};
|
|
107
|
+
/** Classify children after toJSON when serializing, or directly when normalizing. */
|
|
108
|
+
export declare function toolSchemaChildPosition(position: ToolSchemaPosition | undefined, parent: object, key: string, child: unknown): ToolSchemaPosition | undefined;
|
|
109
|
+
export declare function wasToolSchemaTruncated(schema: unknown): boolean;
|
|
110
|
+
/** Preserve reduced-validation provenance across schema copies without repeating diagnostics. */
|
|
111
|
+
export declare function inheritToolSchemaTruncation<T>(source: unknown, result: T, truncated?: boolean): T;
|
|
112
|
+
export declare function reportToolSchemaTruncation(schema: unknown, toolName?: string): void;
|
|
113
|
+
/** Bound schema structure without changing literal data or caching mutable provider inputs. */
|
|
114
|
+
export declare function truncateToolSchemaDepth(schema: unknown, toolName?: string): unknown;
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region packages/ai/src/providers/schema-walk.d.ts
|
|
117
|
+
export declare const SCHEMA_MAP_KEYS: Set<string>;
|
|
118
|
+
export declare const SCHEMA_NESTED_KEYS: Set<string>;
|
|
119
|
+
//#endregion
|
|
50
120
|
//#region packages/ai/src/providers/tool-schema-json-projection.d.ts
|
|
51
121
|
/** JSON-safe schema value used when projecting runtime tool parameters. */
|
|
52
122
|
type RuntimeToolInputSchemaJson = null | boolean | number | string | RuntimeToolInputSchemaJson[] | {
|
|
@@ -57,7 +127,15 @@ type RuntimeToolInputSchemaProjection = {
|
|
|
57
127
|
readonly schema: RuntimeToolInputSchemaJson;
|
|
58
128
|
readonly violations: readonly string[];
|
|
59
129
|
};
|
|
130
|
+
type PublishedRuntimeToolInputSchema = {
|
|
131
|
+
readonly projection: RuntimeToolInputSchemaProjection;
|
|
132
|
+
readonly json: string;
|
|
133
|
+
readonly fingerprint: string;
|
|
134
|
+
};
|
|
135
|
+
export declare function getPublishedRuntimeToolInputSchema(schema: unknown): PublishedRuntimeToolInputSchema | undefined;
|
|
136
|
+
/** Only an owner's detached JSON publication can bypass later schema traversals. */
|
|
137
|
+
export declare function publishRuntimeToolInputSchema(schema: unknown, path?: string, toolName?: string): RuntimeToolInputSchemaProjection;
|
|
60
138
|
/** Projects one runtime tool input schema to JSON and reports runtime incompatibilities. */
|
|
61
|
-
export declare function projectRuntimeToolInputSchema(schema: unknown, path?: string): RuntimeToolInputSchemaProjection;
|
|
139
|
+
export declare function projectRuntimeToolInputSchema(schema: unknown, path?: string, toolName?: string): RuntimeToolInputSchemaProjection;
|
|
62
140
|
//#endregion
|
|
63
|
-
export { type RuntimeToolInputSchemaJson, type RuntimeToolInputSchemaProjection,
|
|
141
|
+
export { type RuntimeToolInputSchemaJson, type RuntimeToolInputSchemaProjection, prepareAnthropicInputSchema };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { _ as SCHEMA_MAP_KEYS, d as inheritToolSchemaTruncation, f as reportToolSchemaTruncation, h as wasToolSchemaTruncated, i as publishRuntimeToolInputSchema, m as truncateToolSchemaDepth, p as toolSchemaChildPosition, r as projectRuntimeToolInputSchema, t as getPublishedRuntimeToolInputSchema, u as MAX_TOOL_SCHEMA_DEPTH, v as SCHEMA_NESTED_KEYS } from "../tool-schema-json-projection-B0hHDV7N.mjs";
|
|
2
|
+
import { r as prepareAnthropicInputSchema } from "../anthropic-tool-projection-BdAS3rtJ.mjs";
|
|
3
|
+
import { _ as findLlamacppGbnfSchemaViolations, a as resolveOpenAIProjectedToolsStrictToolFlag, b as prepareOpenAIFunctionTool, c as extractToolSchemaModelCompat, d as shouldOmitEmptyArrayItems, g as cleanSchemaForLlamacppGbnf, h as LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, i as normalizeStrictOpenAIJsonSchema, l as normalizeToolParameterSchema, m as stripUnsupportedSchemaKeywords, n as isStrictOpenAIJsonSchemaCompatible, o as findOpenAIStrictSchemaViolations, r as normalizeOpenAIStrictToolParameters, s as normalizeOpenAIStrictCompatSchema, t as findOpenAIStrictToolProjectionDiagnostics, u as resolveUnsupportedToolSchemaKeywords, v as GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, y as cleanSchemaForGemini } from "../openai-tool-schema-Buv0GXFb.mjs";
|
|
4
|
+
export { GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS, LLAMACPP_GBNF_MAX_REPETITION_THRESHOLD, MAX_TOOL_SCHEMA_DEPTH, SCHEMA_MAP_KEYS, SCHEMA_NESTED_KEYS, cleanSchemaForGemini, cleanSchemaForLlamacppGbnf, extractToolSchemaModelCompat, findLlamacppGbnfSchemaViolations, findOpenAIStrictSchemaViolations, findOpenAIStrictToolProjectionDiagnostics, getPublishedRuntimeToolInputSchema, inheritToolSchemaTruncation, isStrictOpenAIJsonSchemaCompatible, normalizeOpenAIStrictCompatSchema, normalizeOpenAIStrictToolParameters, normalizeStrictOpenAIJsonSchema, normalizeToolParameterSchema, prepareAnthropicInputSchema, prepareOpenAIFunctionTool, projectRuntimeToolInputSchema, publishRuntimeToolInputSchema, reportToolSchemaTruncation, resolveOpenAIProjectedToolsStrictToolFlag, resolveUnsupportedToolSchemaKeywords, shouldOmitEmptyArrayItems, stripUnsupportedSchemaKeywords, toolSchemaChildPosition, truncateToolSchemaDepth, wasToolSchemaTruncated };
|
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
import { r as appendAssistantThinking, t as AssistantMessageEventStream } from "./event-stream-X2gmsUWv.mjs";
|
|
2
|
-
import { N as isImageWithMediaPayload, O as calculateCost, k as clampThinkingLevel, r as getAiTransportHost } from "./host-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { n as
|
|
2
|
+
import { N as isImageWithMediaPayload, O as calculateCost, k as clampThinkingLevel, r as getAiTransportHost } from "./host-B2gk-d1H.mjs";
|
|
3
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-CRGuMONI.mjs";
|
|
4
|
+
import { r as sortPromptCacheToolsByName } from "./prompt-cache-stability-D_MeCQFI.mjs";
|
|
5
|
+
import { f as extractToolResultText, l as describeToolResultMediaPlaceholder, n as buildBaseOptions, p as formatToolResultText, r as clampMaxTokensToModel, w as stripSystemPromptCacheBoundary } from "./simple-options-BYgC6kse.mjs";
|
|
6
|
+
import { A as shortHash, E as createToolArgumentPreviewSchedule, O as parseStreamingJson, l as finalizeTerminalToolCallArguments, m as notifyProviderHttpResponse, n as assignTransportErrorDetails, u as finalizeTransportStream } from "./transport-stream-shared-CzQlAzJH.mjs";
|
|
7
|
+
import { n as transformProviderMessages, t as createAssistantOutput } from "./assistant-output-6iFA1nbC.mjs";
|
|
6
8
|
import { t as notifyLlmRequestActivity } from "./llm-request-activity-CfMuh5cC.mjs";
|
|
7
9
|
import { t as boundResponseBody } from "./streaming-byte-guard-DBXr1XYn.mjs";
|
|
8
10
|
import { t as mapOpenAIStopReason } from "./openai-stop-reason-8s70vDXj.mjs";
|
|
9
|
-
import { t as requireApiKey } from "./required-api-key-
|
|
11
|
+
import { t as requireApiKey } from "./required-api-key-D088S4Cd.mjs";
|
|
10
12
|
import { randomUUID } from "node:crypto";
|
|
11
13
|
import { HTTPClient } from "@mistralai/mistralai/lib/http";
|
|
12
14
|
import { ReasoningEffort$inboundSchema } from "@mistralai/mistralai/models/components/reasoningeffort.js";
|
|
13
15
|
import { Chat } from "@mistralai/mistralai/sdk/chat";
|
|
16
|
+
//#region packages/ai/src/providers/mistral-usage.ts
|
|
17
|
+
function readMistralCachedPromptTokens(usage, promptTokens) {
|
|
18
|
+
const record = usage;
|
|
19
|
+
const rawCachedTokens = record.promptTokensDetails?.cachedTokens ?? record.prompt_tokens_details?.cached_tokens ?? record.cachedTokens ?? record.cached_tokens;
|
|
20
|
+
return Math.min(promptTokens, Math.max(0, typeof rawCachedTokens === "number" && Number.isFinite(rawCachedTokens) ? rawCachedTokens : 0));
|
|
21
|
+
}
|
|
22
|
+
function applyMistralUsage(output, usage, model, terminal) {
|
|
23
|
+
const promptTokens = usage.promptTokens || 0;
|
|
24
|
+
const cacheRead = readMistralCachedPromptTokens(usage, promptTokens);
|
|
25
|
+
output.input = Math.max(0, promptTokens - cacheRead);
|
|
26
|
+
output.output = usage.completionTokens || 0;
|
|
27
|
+
output.cacheRead = cacheRead;
|
|
28
|
+
output.cacheWrite = 0;
|
|
29
|
+
output.totalTokens = usage.totalTokens || output.input + output.output + cacheRead;
|
|
30
|
+
output.usageReport = { state: terminal ? "available" : "unavailable" };
|
|
31
|
+
calculateCost(model, output);
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
14
34
|
//#region packages/ai/src/providers/mistral.ts
|
|
15
35
|
const MISTRAL_TOOL_CALL_ID_LENGTH = 9;
|
|
16
36
|
const MISTRAL_STREAM_BODY_MAX_BYTES = 16777216;
|
|
@@ -168,11 +188,6 @@ function resolveMistralPromptCacheKey(options) {
|
|
|
168
188
|
if (options?.cacheRetention === "none") return;
|
|
169
189
|
return options?.promptCacheKey?.trim() || options?.sessionId?.trim() || void 0;
|
|
170
190
|
}
|
|
171
|
-
function readMistralCachedPromptTokens(usage, promptTokens) {
|
|
172
|
-
const record = usage;
|
|
173
|
-
const rawCachedTokens = record.promptTokensDetails?.cachedTokens ?? record.prompt_tokens_details?.cached_tokens ?? record.cachedTokens ?? record.cached_tokens;
|
|
174
|
-
return Math.min(promptTokens, Math.max(0, typeof rawCachedTokens === "number" && Number.isFinite(rawCachedTokens) ? rawCachedTokens : 0));
|
|
175
|
-
}
|
|
176
191
|
async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
177
192
|
let currentBlock = null;
|
|
178
193
|
let terminalFinishReason;
|
|
@@ -251,16 +266,7 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
251
266
|
const chunk = event.data;
|
|
252
267
|
output.responseId ||= chunk.id;
|
|
253
268
|
if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) output.responseModel ||= chunk.model;
|
|
254
|
-
if (chunk.usage)
|
|
255
|
-
const promptTokens = chunk.usage.promptTokens || 0;
|
|
256
|
-
const cachedPromptTokens = readMistralCachedPromptTokens(chunk.usage, promptTokens);
|
|
257
|
-
output.usage.input = Math.max(0, promptTokens - cachedPromptTokens);
|
|
258
|
-
output.usage.output = chunk.usage.completionTokens || 0;
|
|
259
|
-
output.usage.cacheRead = cachedPromptTokens;
|
|
260
|
-
output.usage.cacheWrite = 0;
|
|
261
|
-
output.usage.totalTokens = chunk.usage.totalTokens || output.usage.input + output.usage.output + output.usage.cacheRead;
|
|
262
|
-
calculateCost(model, output.usage);
|
|
263
|
-
}
|
|
269
|
+
if (chunk.usage) applyMistralUsage(output.usage, chunk.usage, model, Boolean(terminalFinishReason || chunk.choices[0]?.finishReason));
|
|
264
270
|
const choice = chunk.choices[0];
|
|
265
271
|
if (!choice) continue;
|
|
266
272
|
if (choice.finishReason) {
|
|
@@ -304,7 +310,7 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
304
310
|
id: providedCallId ?? createMissingToolCallId(contentIndex),
|
|
305
311
|
name: functionName ?? "",
|
|
306
312
|
arguments: {},
|
|
307
|
-
|
|
313
|
+
partialJson: ""
|
|
308
314
|
};
|
|
309
315
|
output.content.push(block);
|
|
310
316
|
identity = {
|
|
@@ -335,8 +341,8 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
335
341
|
}
|
|
336
342
|
if (toolCallIndex !== void 0) identity.indexes.add(toolCallIndex);
|
|
337
343
|
const argsDelta = typeof toolCall.function.arguments === "string" ? toolCall.function.arguments : JSON.stringify(toolCall.function.arguments || {});
|
|
338
|
-
block.
|
|
339
|
-
if (identity.preview(block.
|
|
344
|
+
block.partialJson = (block.partialJson || "") + argsDelta;
|
|
345
|
+
if (identity.preview(block.partialJson.length)) block.arguments = parseStreamingJson(block.partialJson);
|
|
340
346
|
stream.push({
|
|
341
347
|
type: "toolcall_delta",
|
|
342
348
|
contentIndex,
|
|
@@ -351,9 +357,9 @@ async function consumeChatStream(model, output, stream, mistralStream, signal) {
|
|
|
351
357
|
if (!terminalFinishReason) throw new Error("Mistral stream ended without a terminal finish reason");
|
|
352
358
|
return;
|
|
353
359
|
}
|
|
354
|
-
finalizeTerminalToolCallArguments(toolBlocks.map(({ block }) => block), (block) => block.
|
|
360
|
+
finalizeTerminalToolCallArguments(toolBlocks.map(({ block }) => block), (block) => block.partialJson ?? "", "Mistral completed tool call has invalid JSON arguments");
|
|
355
361
|
for (const { block, contentIndex } of toolBlocks) {
|
|
356
|
-
delete block.
|
|
362
|
+
delete block.partialJson;
|
|
357
363
|
stream.push({
|
|
358
364
|
type: "toolcall_end",
|
|
359
365
|
contentIndex,
|
|
@@ -375,7 +381,7 @@ function toFunctionTools(tools) {
|
|
|
375
381
|
function: {
|
|
376
382
|
name,
|
|
377
383
|
description,
|
|
378
|
-
parameters:
|
|
384
|
+
parameters: structuredClone(tool.parameters),
|
|
379
385
|
strict: false
|
|
380
386
|
}
|
|
381
387
|
}
|
|
@@ -386,15 +392,6 @@ function toFunctionTools(tools) {
|
|
|
386
392
|
});
|
|
387
393
|
return sortPromptCacheToolsByName(converted).map(({ value }) => value);
|
|
388
394
|
}
|
|
389
|
-
function stripSymbolKeys(value) {
|
|
390
|
-
if (Array.isArray(value)) return value.map((item) => stripSymbolKeys(item));
|
|
391
|
-
if (value && typeof value === "object") {
|
|
392
|
-
const result = {};
|
|
393
|
-
for (const [key, entry] of Object.entries(value)) result[key] = stripSymbolKeys(entry);
|
|
394
|
-
return result;
|
|
395
|
-
}
|
|
396
|
-
return value;
|
|
397
|
-
}
|
|
398
395
|
function toChatMessages(messages, supportsImages) {
|
|
399
396
|
const result = [];
|
|
400
397
|
for (const msg of messages) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region packages/ai/src/transports/model-request-body.d.ts
|
|
2
|
+
type EncodedModelRequestBody = {
|
|
3
|
+
body: Uint8Array<ArrayBuffer>;
|
|
4
|
+
stream: boolean;
|
|
5
|
+
};
|
|
6
|
+
type ModelRequestBodyState = {
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
encode?: (payload: unknown) => Promise<EncodedModelRequestBody>;
|
|
9
|
+
onEncoded?: (body: Blob, payload: unknown) => void;
|
|
10
|
+
onBytes?: (bytes: number) => void;
|
|
11
|
+
};
|
|
12
|
+
/** Call-local state survives option spreads; no payload is cached across requests. */
|
|
13
|
+
declare function modelRequestBodyState(options: object, inheritFrom?: object): ModelRequestBodyState;
|
|
14
|
+
declare function serializeModelRequestBody(payload: unknown, onSerializedPayload?: (payload: unknown) => void): EncodedModelRequestBody;
|
|
15
|
+
declare function encodedModelRequestBodyStream(body: unknown): boolean | undefined;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { modelRequestBodyState as n, serializeModelRequestBody as r, encodedModelRequestBodyStream as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as normalizeOptionalString } from "./string-coerce-Cj8sqWHx.mjs";
|
|
2
2
|
//#region packages/normalization-core/src/number-coercion.ts
|
|
3
3
|
function asFiniteNumber(value) {
|
|
4
4
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
package/dist/{openai-chatgpt-responses-BHI3uCcA.mjs → openai-chatgpt-responses-CtdnpWwe.mjs}
RENAMED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { i as formatThrownValue, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-DzrF1h4J.mjs";
|
|
2
2
|
import { t as AssistantMessageEventStream } from "./event-stream-X2gmsUWv.mjs";
|
|
3
3
|
import { o as isRecord } from "./record-coerce-CNDovvft.mjs";
|
|
4
|
-
import { i as clampPositiveTimerTimeoutMs } from "./number-coercion-
|
|
5
|
-
import { E as headersToRecord, a as resolveAiTransportHeaderSentinels, r as getAiTransportHost } from "./host-
|
|
6
|
-
import {
|
|
7
|
-
import { r as registerSessionResourceCleanup } from "./session-resources-
|
|
8
|
-
import "./provider-error-
|
|
9
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-
|
|
10
|
-
import { s as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, v as extractErrorCodeOrErrno, y as toErrorObject } from "./diagnostics-
|
|
11
|
-
import {
|
|
4
|
+
import { i as clampPositiveTimerTimeoutMs } from "./number-coercion-37gmNkuA.mjs";
|
|
5
|
+
import { E as headersToRecord, a as resolveAiTransportHeaderSentinels, r as getAiTransportHost } from "./host-B2gk-d1H.mjs";
|
|
6
|
+
import { A as supportsOpenAITemperature, g as responsesPromptObserver } from "./openai-responses-contracts-Bx-16mnf.mjs";
|
|
7
|
+
import { r as registerSessionResourceCleanup } from "./session-resources-vKvGIE3J.mjs";
|
|
8
|
+
import "./provider-error-qtZD2inE.mjs";
|
|
9
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-DJ_P143P.mjs";
|
|
10
|
+
import { s as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, v as extractErrorCodeOrErrno, y as toErrorObject } from "./diagnostics-Cv7cW3pS.mjs";
|
|
11
|
+
import { f as consumeResponseBytes, i as MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE, u as streamFragmentError } from "./provider-replay-context-J6CfU3m1.mjs";
|
|
12
12
|
import { parseRetryAfterHeadersSeconds } from "./internal/retry-after.mjs";
|
|
13
|
-
import { c as resolveOpenAIResponsesTextFormat } from "./openai-completions-compat-
|
|
14
|
-
import { n as buildManagedModelFetch } from "./host-policy-
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-
|
|
20
|
-
import { n as
|
|
21
|
-
import { t as requireApiKey } from "./required-api-key-
|
|
13
|
+
import { c as resolveOpenAIResponsesTextFormat } from "./openai-completions-compat-CFhQ3UVU.mjs";
|
|
14
|
+
import { n as buildManagedModelFetch } from "./host-policy-mpqGhbeM.mjs";
|
|
15
|
+
import { n as buildBaseOptions, w as stripSystemPromptCacheBoundary } from "./simple-options-BYgC6kse.mjs";
|
|
16
|
+
import { S as withProviderResponseHook, b as transportAbortError, h as notifyProviderStreamOpened, n as assignTransportErrorDetails } from "./transport-stream-shared-CzQlAzJH.mjs";
|
|
17
|
+
import { t as createAssistantOutput } from "./assistant-output-6iFA1nbC.mjs";
|
|
18
|
+
import { Dt as createOpenAIResponseHook, E as ResponsesStreamFailure, Et as createOpenAIProviderAcceptanceHook, F as convertProviderResponsesMessages, Ot as createResponseModelTracker, S as isInvalidEncryptedContentError, T as resolveNextResponsesEncryptedContentAttempt, _t as resolveOpenAIRequestReasoning, b as commitResponsesEncryptedContentAttempt, i as convertResponsesToolPayload, j as recordResponsesContextUsage, n as applyResponsesServiceTierPricing, o as readOpenAIMisalignmentReview, ot as suppressOpenAIResponsesCompaction, rt as buildOpenAIResponsesReasoningReplayMetadata, s as processResponsesStream, vt as resolveOpenAISimpleReasoningEffort } from "./openai-responses-shared-Bv_1NtH9.mjs";
|
|
19
|
+
import { a as withFirstStreamEventTimeout, i as getFirstStreamEventTimeoutMs, r as getFirstStreamEventTimeoutHandler, t as createFirstStreamEventAbortController } from "./stream-first-event-timeout-D_TfJHRJ.mjs";
|
|
20
|
+
import { a as createResponsesV2CompactionCollector, i as createResponsesPromptEgressObserver, n as responsesRequestLifecycle, o as claimResponsesCompactRequest, r as withResponsesRequestAcceptance, s as copyResponsesCompactRequest, t as independentResponsesRequest } from "./openai-responses-request-lifecycle-CTdAb2v1.mjs";
|
|
21
|
+
import { t as requireApiKey } from "./required-api-key-D088S4Cd.mjs";
|
|
22
22
|
import { n as resolveOpenAICodexAccountId } from "./openai-chatgpt-jwt-KWcgd0d_.mjs";
|
|
23
23
|
//#region packages/ai/src/providers/openai-chatgpt-responses-events.ts
|
|
24
24
|
var CodexApiError = class extends Error {
|
|
@@ -160,6 +160,48 @@ function resolveCodexWebSocketUrl(baseUrl) {
|
|
|
160
160
|
return url.toString();
|
|
161
161
|
}
|
|
162
162
|
//#endregion
|
|
163
|
+
//#region packages/ai/src/providers/openai-chatgpt-responses-request.ts
|
|
164
|
+
function buildRequestBody(model, context, allowedToolCallProviders, options, replayMode = "checkpoint", retainUserProvenance = false) {
|
|
165
|
+
const messages = convertProviderResponsesMessages(model, context, allowedToolCallProviders, {
|
|
166
|
+
includeSystemPrompt: false,
|
|
167
|
+
replayResponsesItemIds: false,
|
|
168
|
+
sessionId: options?.sessionId,
|
|
169
|
+
authProfileId: options?.authProfileId,
|
|
170
|
+
replayMode,
|
|
171
|
+
retainUserProvenance
|
|
172
|
+
});
|
|
173
|
+
const body = {
|
|
174
|
+
model: model.id,
|
|
175
|
+
store: false,
|
|
176
|
+
stream: true,
|
|
177
|
+
instructions: stripSystemPromptCacheBoundary(context.systemPrompt ?? "") || "You are a helpful assistant.",
|
|
178
|
+
input: messages,
|
|
179
|
+
text: { verbosity: options?.textVerbosity || "low" },
|
|
180
|
+
include: ["reasoning.encrypted_content"],
|
|
181
|
+
prompt_cache_key: options?.cacheRetention === "none" ? void 0 : clampOpenAIPromptCacheKey(options?.promptCacheKey ?? options?.sessionId)
|
|
182
|
+
};
|
|
183
|
+
if (options?.responseFormat !== void 0) body.text = {
|
|
184
|
+
...body.text,
|
|
185
|
+
format: resolveOpenAIResponsesTextFormat(options.responseFormat)
|
|
186
|
+
};
|
|
187
|
+
if (options?.temperature !== void 0 && supportsOpenAITemperature(model)) body.temperature = options.temperature;
|
|
188
|
+
if (options?.serviceTier !== void 0) body.service_tier = options.serviceTier;
|
|
189
|
+
if (context.tools) {
|
|
190
|
+
const tools = convertResponsesToolPayload(context.tools, { strict: false });
|
|
191
|
+
if (tools.length > 0) {
|
|
192
|
+
body.tools = tools;
|
|
193
|
+
body.tool_choice = "auto";
|
|
194
|
+
body.parallel_tool_calls = true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const effort = options?.reasoningEffort === void 0 ? void 0 : resolveOpenAIRequestReasoning(model, options.reasoningEffort).effort;
|
|
198
|
+
if (effort !== void 0) body.reasoning = {
|
|
199
|
+
effort,
|
|
200
|
+
...effort === "none" ? {} : { summary: options?.reasoningSummary ?? "auto" }
|
|
201
|
+
};
|
|
202
|
+
return body;
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
163
205
|
//#region packages/ai/src/providers/openai-chatgpt-responses-websocket-authority.ts
|
|
164
206
|
const OPENAI_BETA_RESPONSES_WEBSOCKETS = "responses_websockets=2026-02-06";
|
|
165
207
|
function resolveCodexWebSocketAuthority(params) {
|
|
@@ -334,6 +376,8 @@ function compressRequestBodyZstd(bodyJson) {
|
|
|
334
376
|
}
|
|
335
377
|
const streamOpenAICodexResponses = (model, context, options) => {
|
|
336
378
|
const stream = new AssistantMessageEventStream();
|
|
379
|
+
const compactRequest = claimResponsesCompactRequest(options);
|
|
380
|
+
const v2Compaction = compactRequest?.mode === "v2" ? createResponsesV2CompactionCollector(compactRequest.replayBudget) : void 0;
|
|
337
381
|
(async () => {
|
|
338
382
|
const startedAt = Date.now();
|
|
339
383
|
let requestTimeoutMs;
|
|
@@ -342,6 +386,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
342
386
|
let firstEventAbort;
|
|
343
387
|
const output = createAssistantOutput(model);
|
|
344
388
|
try {
|
|
389
|
+
if (compactRequest && (!v2Compaction || responsesRequestLifecycle.get(options))) throw new Error("Native ChatGPT compaction requires an unreviewed V2 request");
|
|
345
390
|
const unresolvedApiKey = requireApiKey(model.provider, options?.apiKey);
|
|
346
391
|
const transportHost = getAiTransportHost();
|
|
347
392
|
const websocketState = getOpenAICodexWebSocketRuntimeState(transportHost);
|
|
@@ -350,9 +395,14 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
350
395
|
const optionHeaders = resolveAiTransportHeaderSentinels(options?.headers);
|
|
351
396
|
const accountId = extractOpenAICodexAccountId(apiKey);
|
|
352
397
|
const buildBody = async (replayMode) => {
|
|
353
|
-
let body = buildRequestBody(model, context, options, replayMode);
|
|
398
|
+
let body = buildRequestBody(model, context, CODEX_TOOL_CALL_PROVIDERS, options, replayMode, Boolean(v2Compaction));
|
|
399
|
+
const restoreUsers = v2Compaction?.preserveUsers(body.input ?? []);
|
|
354
400
|
const nextBody = await options?.onPayload?.(body, model);
|
|
355
401
|
if (nextBody !== void 0) body = nextBody;
|
|
402
|
+
if (restoreUsers) {
|
|
403
|
+
body.input = [...restoreUsers(body.input ?? []), { type: "compaction_trigger" }];
|
|
404
|
+
v2Compaction?.assertReplayFits(body.input, model);
|
|
405
|
+
}
|
|
356
406
|
return body;
|
|
357
407
|
};
|
|
358
408
|
let semanticAttempt = {
|
|
@@ -374,7 +424,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
374
424
|
...options,
|
|
375
425
|
signal: activeSignal
|
|
376
426
|
};
|
|
377
|
-
const processStream = (events, streamOptions, activitySignal) => processResponsesStream(events, output, stream, model, {
|
|
427
|
+
const processStream = (events, streamOptions, activitySignal) => processResponsesStream(v2Compaction ? v2Compaction.observe(events) : events, output, stream, model, {
|
|
378
428
|
serviceTier: streamOptions?.serviceTier,
|
|
379
429
|
firstEventTimeoutMs: getFirstStreamEventTimeoutMs(streamOptions),
|
|
380
430
|
abortFirstEventStream: firstEventAbort?.abort,
|
|
@@ -390,7 +440,23 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
390
440
|
const completeStream = (terminal, attempt, ErrorType) => {
|
|
391
441
|
if (activeSignal?.aborted) throw transportAbortError(activeSignal);
|
|
392
442
|
if (output.stopReason === "aborted" || output.stopReason === "error") throw new ErrorType(output.errorMessage ?? "An unknown error occurred");
|
|
393
|
-
if (
|
|
443
|
+
if (v2Compaction && compactRequest) {
|
|
444
|
+
const compacted = v2Compaction.finish({
|
|
445
|
+
terminal: terminal ?? void 0,
|
|
446
|
+
input: attempt.request.input ?? [],
|
|
447
|
+
model,
|
|
448
|
+
options: {
|
|
449
|
+
signal: options?.signal,
|
|
450
|
+
sessionId: options?.sessionId,
|
|
451
|
+
authProfileId: options?.authProfileId
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
compactRequest.resolve({
|
|
455
|
+
...compacted,
|
|
456
|
+
modelUsage: output.usage
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
if (!v2Compaction && terminal && attempt.kind === "initial") recordResponsesContextUsage(output, model, options, attempt.request, terminal.output, "provider");
|
|
394
460
|
stream.push({
|
|
395
461
|
type: "done",
|
|
396
462
|
reason: output.stopReason,
|
|
@@ -455,7 +521,7 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
455
521
|
phase: websocketStarted ? "after_message_stream_start" : "before_message_stream_start",
|
|
456
522
|
requestBytes: new TextEncoder().encode(JSON.stringify(activeAttempt.request)).byteLength
|
|
457
523
|
}));
|
|
458
|
-
if (transport === "auto" && options?.sessionId) addCodexWebSocketSseFallback(websocketState.sseFallbacks, options.sessionId, websocketAuthority);
|
|
524
|
+
if (transport === "auto" && options?.sessionId && !independentResponsesRequest.has(options)) addCodexWebSocketSseFallback(websocketState.sseFallbacks, options.sessionId, websocketAuthority);
|
|
459
525
|
if (websocketStarted || transport !== "auto") throw transportError;
|
|
460
526
|
break;
|
|
461
527
|
}
|
|
@@ -477,13 +543,15 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
477
543
|
});
|
|
478
544
|
let attemptResponse;
|
|
479
545
|
try {
|
|
546
|
+
const requestFetch = independentResponsesRequest.has(options) ? transportHost.buildModelFetch(model) : buildManagedModelFetch(model, transportHost) ?? fetch;
|
|
547
|
+
if (!requestFetch) throw new Error("Independent ChatGPT requests require a host model fetch");
|
|
480
548
|
const lifecycle = responsesRequestLifecycle.get(options);
|
|
481
549
|
if (lifecycle) {
|
|
482
550
|
await lifecycle.beforeDispatch(activeSignal);
|
|
483
551
|
activeSignal?.throwIfAborted();
|
|
484
552
|
lifecycle.assertCurrent();
|
|
485
553
|
}
|
|
486
|
-
attemptResponse = await (
|
|
554
|
+
attemptResponse = await requestFetch(resolveCodexUrl(model.baseUrl), {
|
|
487
555
|
method: "POST",
|
|
488
556
|
headers: sseHeaders,
|
|
489
557
|
body: sseBody,
|
|
@@ -538,7 +606,8 @@ const streamOpenAICodexResponses = (model, context, options) => {
|
|
|
538
606
|
await responsesRequestLifecycle.get(options)?.settle().catch(() => void 0);
|
|
539
607
|
const requestTimedOut = isRequestTimeoutError(error, options?.signal, requestTimeoutSignal, requestTimeoutMs) && requestTimeoutMs !== void 0;
|
|
540
608
|
const normalizedError = requestTimedOut && requestTimeoutMs !== void 0 ? formatRequestTimeoutError(requestTimeoutMs, error) : error;
|
|
541
|
-
|
|
609
|
+
compactRequest?.reject(normalizedError);
|
|
610
|
+
for (const block of output.content.filter((candidate) => candidate.type === "toolCall")) delete block.partialJson;
|
|
542
611
|
const providerRefusal = readCodexProviderRefusal(normalizedError);
|
|
543
612
|
if (providerRefusal) appendAssistantMessageDiagnostic(output, {
|
|
544
613
|
type: "provider_refusal",
|
|
@@ -578,50 +647,13 @@ const streamSimpleOpenAICodexResponses = (model, context, options) => {
|
|
|
578
647
|
authProfileId: options?.authProfileId,
|
|
579
648
|
reasoningEffort: resolveOpenAISimpleReasoningEffort(model, options?.reasoning)
|
|
580
649
|
};
|
|
650
|
+
copyResponsesCompactRequest(options, resolvedOptions);
|
|
581
651
|
responsesPromptObserver.copy(options, resolvedOptions);
|
|
652
|
+
if (independentResponsesRequest.has(options)) independentResponsesRequest.set(resolvedOptions);
|
|
582
653
|
const lifecycle = responsesRequestLifecycle.get(options);
|
|
583
654
|
if (lifecycle) responsesRequestLifecycle.set(resolvedOptions, lifecycle);
|
|
584
655
|
return streamOpenAICodexResponses(model, context, resolvedOptions);
|
|
585
656
|
};
|
|
586
|
-
function buildRequestBody(model, context, options, replayMode = "checkpoint") {
|
|
587
|
-
const messages = convertProviderResponsesMessages(model, context, CODEX_TOOL_CALL_PROVIDERS, {
|
|
588
|
-
includeSystemPrompt: false,
|
|
589
|
-
replayResponsesItemIds: false,
|
|
590
|
-
sessionId: options?.sessionId,
|
|
591
|
-
authProfileId: options?.authProfileId,
|
|
592
|
-
replayMode
|
|
593
|
-
});
|
|
594
|
-
const body = {
|
|
595
|
-
model: model.id,
|
|
596
|
-
store: false,
|
|
597
|
-
stream: true,
|
|
598
|
-
instructions: stripSystemPromptCacheBoundary(context.systemPrompt ?? "") || "You are a helpful assistant.",
|
|
599
|
-
input: messages,
|
|
600
|
-
text: { verbosity: options?.textVerbosity || "low" },
|
|
601
|
-
include: ["reasoning.encrypted_content"],
|
|
602
|
-
prompt_cache_key: options?.cacheRetention === "none" ? void 0 : clampOpenAIPromptCacheKey(options?.promptCacheKey ?? options?.sessionId)
|
|
603
|
-
};
|
|
604
|
-
if (options?.responseFormat !== void 0) body.text = {
|
|
605
|
-
...body.text,
|
|
606
|
-
format: resolveOpenAIResponsesTextFormat(options.responseFormat)
|
|
607
|
-
};
|
|
608
|
-
if (options?.temperature !== void 0 && supportsOpenAITemperature(model)) body.temperature = options.temperature;
|
|
609
|
-
if (options?.serviceTier !== void 0) body.service_tier = options.serviceTier;
|
|
610
|
-
if (context.tools) {
|
|
611
|
-
const tools = convertResponsesToolPayload(context.tools, { strict: false });
|
|
612
|
-
if (tools.length > 0) {
|
|
613
|
-
body.tools = tools;
|
|
614
|
-
body.tool_choice = "auto";
|
|
615
|
-
body.parallel_tool_calls = true;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
const effort = options?.reasoningEffort === void 0 ? void 0 : resolveOpenAIRequestReasoning(model, options.reasoningEffort).effort;
|
|
619
|
-
if (effort !== void 0) body.reasoning = {
|
|
620
|
-
effort,
|
|
621
|
-
...effort === "none" ? {} : { summary: options?.reasoningSummary ?? "auto" }
|
|
622
|
-
};
|
|
623
|
-
return body;
|
|
624
|
-
}
|
|
625
657
|
function resolveCodexServiceTier(responseServiceTier, requestServiceTier) {
|
|
626
658
|
if (responseServiceTier === "default" && (requestServiceTier === "flex" || requestServiceTier === "priority")) return requestServiceTier;
|
|
627
659
|
return responseServiceTier ?? requestServiceTier;
|
|
@@ -907,7 +939,7 @@ function buildCachedWebSocketRequestBody(entry, body) {
|
|
|
907
939
|
};
|
|
908
940
|
}
|
|
909
941
|
async function processWebSocketStream(state, authority, body, output, stream, model, onFirstProviderEvent, onStart, options, processStream, observePromptEgress, payloadVariant = "initial", onRequestSent, activitySignal) {
|
|
910
|
-
const { socket, entry, release } = await acquireWebSocket(state, authority, options?.sessionId, options?.signal);
|
|
942
|
+
const { socket, entry, release } = await acquireWebSocket(state, authority, independentResponsesRequest.has(options) ? void 0 : options?.sessionId, options?.signal);
|
|
911
943
|
let keepConnection = true;
|
|
912
944
|
const useCachedContext = options?.transport === "websocket-cached" || options?.transport === "auto";
|
|
913
945
|
const requestBody = useCachedContext && entry ? buildCachedWebSocketRequestBody(entry, body) : body;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { k as clampThinkingLevel } from "./host-
|
|
3
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
4
|
-
import {
|
|
5
|
-
import { t as requireApiKey } from "./required-api-key-
|
|
1
|
+
import { n as __exportAll } from "./reasoning-tag-text-partitioner-DzlRubwU.mjs";
|
|
2
|
+
import { k as clampThinkingLevel } from "./host-B2gk-d1H.mjs";
|
|
3
|
+
import { n as buildBaseOptions } from "./simple-options-BYgC6kse.mjs";
|
|
4
|
+
import { n as streamOpenAICompletionsRequest, s as convertMessages } from "./openai-completions-transport-DviPEqw3.mjs";
|
|
5
|
+
import { t as requireApiKey } from "./required-api-key-D088S4Cd.mjs";
|
|
6
6
|
//#region packages/ai/src/providers/openai-completions.ts
|
|
7
7
|
var openai_completions_exports = /* @__PURE__ */ __exportAll({
|
|
8
8
|
convertMessages: () => convertMessages,
|
|
@@ -15,12 +15,14 @@ const streamSimpleOpenAICompletions = (model, context, options) => {
|
|
|
15
15
|
const base = buildBaseOptions(model, options, apiKey);
|
|
16
16
|
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
|
|
17
17
|
const completionsOptions = options;
|
|
18
|
-
|
|
18
|
+
const providerOptions = {
|
|
19
19
|
...base,
|
|
20
20
|
reasoningEffort: clampedReasoning,
|
|
21
21
|
toolChoice: completionsOptions?.toolChoice,
|
|
22
|
-
streaming: completionsOptions?.streaming
|
|
23
|
-
|
|
22
|
+
streaming: completionsOptions?.streaming,
|
|
23
|
+
openclawThinkingExplicit: completionsOptions?.openclawThinkingExplicit ?? options?.reasoning !== void 0
|
|
24
|
+
};
|
|
25
|
+
return streamOpenAICompletions(model, context, providerOptions);
|
|
24
26
|
};
|
|
25
27
|
//#endregion
|
|
26
28
|
export { streamOpenAICompletions as n, streamSimpleOpenAICompletions as r, openai_completions_exports as t };
|
package/dist/{openai-completions-compat-i-nLZxFy.d.mts → openai-completions-compat-1gsjP-KO.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { N as OpenAICompletionsCompat, k as Model } from "./types-
|
|
3
|
-
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-
|
|
1
|
+
import "./index-DSprYWaz.mjs";
|
|
2
|
+
import { N as OpenAICompletionsCompat, k as Model } from "./types-CVYzKrMl.mjs";
|
|
3
|
+
import { a as AiProviderRequestPolicyInput, i as AiProviderRequestCapabilities } from "./host-jJOffdlW.mjs";
|
|
4
4
|
//#region packages/ai/src/transports/openai-completions-compat.d.ts
|
|
5
5
|
type OpenAICompletionsSessionAffinity = "none" | "openai" | "openrouter";
|
|
6
6
|
type OpenAICompletionsCompatDefaults = {
|
|
@@ -12,6 +12,7 @@ type OpenAICompletionsCompatDefaults = {
|
|
|
12
12
|
thinkingFormat: "openai" | "openrouter" | "deepseek" | "together" | "zai";
|
|
13
13
|
visibleReasoningDetailTypes: string[];
|
|
14
14
|
supportsStrictMode: boolean;
|
|
15
|
+
requiresTypedUnionBranches: boolean;
|
|
15
16
|
supportsJsonSchemaResponseFormat: boolean;
|
|
16
17
|
requiresReasoningContentOnAssistantMessages: boolean;
|
|
17
18
|
requiresNonEmptyUserOrAssistantMessage: boolean;
|
|
@@ -25,8 +26,10 @@ type ResolvedOpenAICompletionsCompat = Omit<Required<OpenAICompletionsCompat>, "
|
|
|
25
26
|
sessionAffinity: OpenAICompletionsSessionAffinity;
|
|
26
27
|
visibleReasoningDetailTypes: string[];
|
|
27
28
|
requiresNonEmptyUserOrAssistantMessage: boolean;
|
|
29
|
+
requiresTypedUnionBranches: boolean;
|
|
28
30
|
configuredSupportsLongCacheRetention?: boolean;
|
|
29
31
|
reasoningEffortForOff: "none" | null;
|
|
32
|
+
thinkingOffControlUndeclared: boolean;
|
|
30
33
|
};
|
|
31
34
|
/** Native OpenAI defaults never apply to a configured proxy endpoint. */
|
|
32
35
|
declare function isNativeOpenAIEndpoint(model: {
|