@openclaw/ai 2026.7.2-beta.3 → 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/README.md +6 -5
- package/dist/{anthropic-D7SyZQ5v.mjs → anthropic-CQVj3le6.mjs} +174 -33
- package/dist/{index-BoTnz8cv.d.mts → anthropic-SrGtwsJu.d.mts} +27 -1
- package/dist/{api-registry-DXBIXISf.d.mts → api-registry-DlMgPR39.d.mts} +1 -2
- package/dist/{azure-openai-responses-BkZgyZ3I.mjs → azure-openai-responses-DIYgsqFM.mjs} +7 -11
- package/dist/{env-api-keys-DnhYpc27.mjs → env-api-keys-DrgeBuva.mjs} +1 -1
- package/dist/error-coercion-DgxlWC0n.mjs +15 -0
- package/dist/{event-stream-BPemFrFW.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-C_biGbV7.mjs → google-f-A8xrae.mjs} +4 -4
- package/dist/{google-shared-BK-NoHl8.mjs → google-shared-J6qvYINH.mjs} +5 -4
- package/dist/{google-vertex-CvdzF1U7.mjs → google-vertex-D3yMVXIY.mjs} +3 -3
- package/dist/host-B9GUmcra.d.mts +173 -0
- package/dist/host-XYGZcgO8.mjs +98 -0
- package/dist/index-BVVgDSdq.d.mts +1 -0
- package/dist/index.d.mts +7 -50
- package/dist/index.mjs +3 -3
- package/dist/internal/anthropic.d.mts +15 -11
- package/dist/internal/anthropic.mjs +4 -4
- package/dist/internal/openai.d.mts +3 -280
- package/dist/internal/openai.mjs +5 -7
- package/dist/internal/runtime.d.mts +13 -34
- package/dist/internal/runtime.mjs +19 -11
- package/dist/internal/shared.d.mts +13 -8
- package/dist/internal/shared.mjs +2 -2
- package/dist/{mistral-BdrQmDWp.mjs → mistral-CKV-TOQj.mjs} +7 -6
- package/dist/number-coercion-DvG7SNMg.mjs +129 -0
- package/dist/openai-BPor_3WI.d.mts +358 -0
- package/dist/{openai-responses-shared-CwnGU0KW.mjs → openai-D3PD6PE-.mjs} +1890 -705
- package/dist/{openai-chatgpt-responses-DP63Qt01.mjs → openai-chatgpt-responses-CedIj0hk.mjs} +54 -58
- package/dist/{openai-completions-zLDfebnN.mjs → openai-completions-CiSutyu0.mjs} +459 -104
- 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-LMfTEkfO.mjs → provider-error-apVOZI6G.mjs} +9 -2
- package/dist/providers.d.mts +3 -2
- package/dist/providers.mjs +10 -9
- package/dist/{transform-messages-eb6lxDLB.mjs → shared-CdjNZd35.mjs} +273 -161
- 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 +593 -0
- package/dist/transports.mjs +4069 -0
- package/dist/{types-CYORveZ7.d.mts → types-bzp5k29J.d.mts} +8 -0
- package/dist/types.d.mts +5 -5
- package/dist/types.mjs +2 -2
- package/dist/{validation-BX8euiDv.d.mts → validation-B-j7cOYp.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/package.json +36 -11
- package/dist/azure-openai-responses-client-compat-C7K7QfUE.mjs +0 -62
- package/dist/github-copilot-headers-BsH5cqGj.mjs +0 -48
- package/dist/host-4t713IeR.mjs +0 -37
- package/dist/model-utils-1GiZ2_rr.mjs +0 -64
- package/dist/openai-responses-ClspWt4I.mjs +0 -136
- package/dist/openai-tool-projection-WHf2nuOI.mjs +0 -200
- package/dist/reasoning-tag-text-partitioner-BlVe67g6.mjs +0 -400
- package/dist/stream-first-event-timeout-RjWszj8c.mjs +0 -106
- package/npm-shrinkwrap.json +0 -645
|
@@ -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 };
|
|
@@ -0,0 +1,358 @@
|
|
|
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";
|
|
3
|
+
import OpenAI from "openai";
|
|
4
|
+
import { TSchema } from "typebox";
|
|
5
|
+
import { ChatCompletionMessageParam } from "openai/resources/chat/completions.js";
|
|
6
|
+
import { ResponseCreateParamsStreaming } from "openai/resources/responses/responses.js";
|
|
7
|
+
|
|
8
|
+
//#region packages/ai/src/providers/agent-tools-parameter-schema.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Narrow structural view of the host's model compat config. packages/ai must stay
|
|
11
|
+
* config-agnostic, so only tool-schema-relevant fields are modeled here; the host's
|
|
12
|
+
* ModelCompatConfig remains structurally assignable.
|
|
13
|
+
*/
|
|
14
|
+
type ToolSchemaModelCompat = {
|
|
15
|
+
toolSchemaProfile?: string;
|
|
16
|
+
unsupportedToolSchemaKeywords?: string[];
|
|
17
|
+
omitEmptyArrayItems?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/** Extracts the compat record whether callers pass a model (`{ compat }`) or the compat itself. */
|
|
20
|
+
declare function extractToolSchemaModelCompat(modelOrCompat: {
|
|
21
|
+
compat?: unknown;
|
|
22
|
+
} | ToolSchemaModelCompat | undefined): ToolSchemaModelCompat | undefined;
|
|
23
|
+
/** JSON Schema keywords this model/provider rejects in tool schemas. */
|
|
24
|
+
declare function resolveUnsupportedToolSchemaKeywords(modelOrCompat: {
|
|
25
|
+
compat?: unknown;
|
|
26
|
+
} | ToolSchemaModelCompat | undefined): ReadonlySet<string>;
|
|
27
|
+
/** Whether empty `items: {}` on array schemas must be omitted for this model/provider. */
|
|
28
|
+
declare function shouldOmitEmptyArrayItems(modelOrCompat: {
|
|
29
|
+
compat?: unknown;
|
|
30
|
+
} | ToolSchemaModelCompat | undefined): boolean;
|
|
31
|
+
type ToolParameterSchemaOptions = {
|
|
32
|
+
modelProvider?: string;
|
|
33
|
+
modelId?: string;
|
|
34
|
+
modelCompat?: ToolSchemaModelCompat;
|
|
35
|
+
};
|
|
36
|
+
/** Return a provider-compatible JSON schema for a model-facing tool. */
|
|
37
|
+
declare function normalizeToolParameterSchema(schema: unknown, options?: ToolParameterSchemaOptions): TSchema;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region packages/ai/src/providers/azure-deployment-map.d.ts
|
|
40
|
+
/** Parses AZURE_OPENAI_DEPLOYMENT_MAP-style model=deployment entries. */
|
|
41
|
+
declare function parseAzureDeploymentNameMap(value: string | undefined): Map<string, string>;
|
|
42
|
+
/**
|
|
43
|
+
* Resolves the Azure deployment name for a model id, falling back to the model id.
|
|
44
|
+
*
|
|
45
|
+
* An exact-case match always wins, so configs that intentionally distinguish keys by
|
|
46
|
+
* case keep their exact mappings; a case-insensitive match is only used as a fallback
|
|
47
|
+
* (e.g. `GPT-4o` against a `gpt-4o=...` map) to avoid 404s from casing differences.
|
|
48
|
+
*/
|
|
49
|
+
declare function resolveAzureDeploymentNameFromMap(params: {
|
|
50
|
+
modelId: string;
|
|
51
|
+
deploymentMap?: string;
|
|
52
|
+
}): string;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region packages/ai/src/providers/azure-openai-responses-client-compat.d.ts
|
|
55
|
+
declare function isTraditionalAzureOpenAIHost(hostname: string): boolean;
|
|
56
|
+
declare function isOpenAICompatibleAzureResponsesBaseUrl(baseUrl: string): boolean;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region packages/ai/src/providers/clean-for-gemini.d.ts
|
|
59
|
+
declare const GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS: Set<string>;
|
|
60
|
+
declare function cleanSchemaForGemini(schema: unknown): TSchema;
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region packages/ai/src/transports/openai-completions-compat.d.ts
|
|
63
|
+
type ProviderRequestCapabilities = AiProviderRequestCapabilities;
|
|
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
|
+
};
|
|
85
|
+
type ResolvedOpenAICompletionsCompat = Omit<Required<OpenAICompletionsCompat>, "cacheControlFormat" | "openRouterRouting" | "sendSessionAffinityHeaders"> & {
|
|
86
|
+
cacheControlFormat?: OpenAICompletionsCompat["cacheControlFormat"];
|
|
87
|
+
openRouterRouting?: OpenAICompletionsCompat["openRouterRouting"];
|
|
88
|
+
sessionAffinity: OpenAICompletionsSessionAffinity;
|
|
89
|
+
visibleReasoningDetailTypes: string[];
|
|
90
|
+
requiresNonEmptyUserOrAssistantMessage: boolean;
|
|
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;
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region packages/ai/src/providers/openai-tool-projection.d.ts
|
|
102
|
+
type OpenAIToolDescriptor = {
|
|
103
|
+
readonly name?: unknown;
|
|
104
|
+
readonly description?: unknown;
|
|
105
|
+
readonly parameters: unknown;
|
|
106
|
+
};
|
|
107
|
+
type OpenAIProjectedTool = {
|
|
108
|
+
readonly toolIndex: number;
|
|
109
|
+
readonly name: string;
|
|
110
|
+
readonly description?: string;
|
|
111
|
+
readonly parameters: Record<string, unknown>;
|
|
112
|
+
};
|
|
113
|
+
type OpenAIToolProjectionDiagnostic = {
|
|
114
|
+
readonly toolIndex: number;
|
|
115
|
+
readonly toolName?: string;
|
|
116
|
+
readonly violations: readonly string[];
|
|
117
|
+
};
|
|
118
|
+
type OpenAIToolProjection = {
|
|
119
|
+
readonly inputToolCount: number;
|
|
120
|
+
readonly tools: readonly OpenAIProjectedTool[];
|
|
121
|
+
readonly diagnostics: readonly OpenAIToolProjectionDiagnostic[];
|
|
122
|
+
};
|
|
123
|
+
type OpenAIResponsesToolChoice = ResponseCreateParamsStreaming["tool_choice"];
|
|
124
|
+
type OpenAICompletionsSdkToolChoice = OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming["tool_choice"];
|
|
125
|
+
type OpenAICompletionsToolChoice = Exclude<OpenAICompletionsSdkToolChoice, {
|
|
126
|
+
type: "custom";
|
|
127
|
+
}>;
|
|
128
|
+
/** Snapshots direct/custom tool descriptors before OpenAI payload construction. */
|
|
129
|
+
declare function projectOpenAITools(tools: readonly OpenAIToolDescriptor[]): OpenAIToolProjection;
|
|
130
|
+
/** Keeps Responses tool choices aligned with surviving function schemas. */
|
|
131
|
+
declare function reconcileOpenAIResponsesToolChoice(choice: OpenAIResponsesToolChoice, projection: OpenAIToolProjection): OpenAIResponsesToolChoice | undefined;
|
|
132
|
+
/** Keeps Chat Completions tool choices aligned with surviving function schemas. */
|
|
133
|
+
declare function reconcileOpenAICompletionsToolChoice(choice: OpenAICompletionsSdkToolChoice, projection: OpenAIToolProjection): OpenAICompletionsSdkToolChoice | undefined;
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region packages/ai/src/providers/openai-completions.d.ts
|
|
136
|
+
interface OpenAICompletionsOptions extends StreamOptions {
|
|
137
|
+
toolChoice?: OpenAICompletionsToolChoice;
|
|
138
|
+
reasoningEffort?: "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
139
|
+
}
|
|
140
|
+
declare const streamOpenAICompletions: StreamFunction<"openai-completions", OpenAICompletionsOptions>;
|
|
141
|
+
declare const streamSimpleOpenAICompletions: StreamFunction<"openai-completions", SimpleStreamOptions>;
|
|
142
|
+
declare function convertMessages(model: Model<"openai-completions">, context: Context, compat: ResolvedOpenAICompletionsCompat, options?: {
|
|
143
|
+
cacheOptOutIndexes?: Set<number>;
|
|
144
|
+
preserveSystemPromptCacheBoundary?: boolean;
|
|
145
|
+
}): ChatCompletionMessageParam[];
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region packages/ai/src/providers/openai-reasoning-effort.d.ts
|
|
148
|
+
type OpenAIReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
149
|
+
type OpenAIApiReasoningEffort = OpenAIReasoningEffort | (string & {});
|
|
150
|
+
type OpenAIReasoningModel = {
|
|
151
|
+
provider?: unknown;
|
|
152
|
+
id?: unknown;
|
|
153
|
+
name?: unknown;
|
|
154
|
+
api?: unknown;
|
|
155
|
+
baseUrl?: unknown;
|
|
156
|
+
compat?: unknown;
|
|
157
|
+
};
|
|
158
|
+
/** Return whether a model is the GPT-5.4 mini family. */
|
|
159
|
+
declare function isOpenAIGpt54MiniModel(model: OpenAIReasoningModel): boolean;
|
|
160
|
+
/** Return whether a model is the GPT-5.5 family. */
|
|
161
|
+
declare function isOpenAIGpt55Model(model: OpenAIReasoningModel): boolean;
|
|
162
|
+
/** Return whether a model is the GPT-5.6 family. */
|
|
163
|
+
declare function isOpenAIGpt56Model(model: OpenAIReasoningModel): boolean;
|
|
164
|
+
/** Normalize user-facing reasoning effort names to API effort names. */
|
|
165
|
+
declare function normalizeOpenAIReasoningEffort(effort: string): string;
|
|
166
|
+
/** Resolve the reasoning efforts accepted by a specific OpenAI-compatible model. */
|
|
167
|
+
declare function resolveOpenAISupportedReasoningEfforts(model: OpenAIReasoningModel): readonly OpenAIApiReasoningEffort[];
|
|
168
|
+
/**
|
|
169
|
+
* Return whether a model accepts the temperature parameter. The GPT-5.6
|
|
170
|
+
* family rejects it with a 400; catalog compat can override per model.
|
|
171
|
+
*/
|
|
172
|
+
declare function supportsOpenAITemperature(model: OpenAIReasoningModel): boolean;
|
|
173
|
+
/** Return whether a model accepts a requested reasoning effort. */
|
|
174
|
+
declare function supportsOpenAIReasoningEffort(model: OpenAIReasoningModel, effort: string): boolean;
|
|
175
|
+
/** Resolve a requested reasoning effort to the closest value supported by the model. */
|
|
176
|
+
declare function resolveOpenAIReasoningEffortForModel(params: {
|
|
177
|
+
model: OpenAIReasoningModel;
|
|
178
|
+
effort: string;
|
|
179
|
+
fallbackMap?: Record<string, string>;
|
|
180
|
+
}): OpenAIApiReasoningEffort | undefined;
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region packages/ai/src/providers/openai-responses.d.ts
|
|
183
|
+
interface OpenAIResponsesOptions extends StreamOptions {
|
|
184
|
+
reasoningEffort?: "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
185
|
+
reasoningSummary?: "auto" | "detailed" | "concise" | null;
|
|
186
|
+
replayResponsesItemIds?: boolean;
|
|
187
|
+
serviceTier?: ResponseCreateParamsStreaming["service_tier"];
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Generate function for OpenAI Responses API
|
|
191
|
+
*/
|
|
192
|
+
declare const streamOpenAIResponses: StreamFunction<"openai-responses", OpenAIResponsesOptions>;
|
|
193
|
+
declare const streamSimpleOpenAIResponses: StreamFunction<"openai-responses", SimpleStreamOptions>;
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region packages/ai/src/providers/openai-responses-stream-compat.d.ts
|
|
196
|
+
declare const OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE = "output_text";
|
|
197
|
+
declare const AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE = "text";
|
|
198
|
+
declare const OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE = "response.output_text.delta";
|
|
199
|
+
declare const AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE = "response.text.delta";
|
|
200
|
+
type ResponsesTextContentPartType = typeof OPENAI_RESPONSES_OUTPUT_TEXT_CONTENT_PART_TYPE | typeof AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE;
|
|
201
|
+
type ResponsesTextDeltaEventType = typeof OPENAI_RESPONSES_OUTPUT_TEXT_DELTA_EVENT_TYPE | typeof AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE;
|
|
202
|
+
type AzureResponsesTextContentPart = {
|
|
203
|
+
type: typeof AZURE_RESPONSES_TEXT_CONTENT_PART_TYPE;
|
|
204
|
+
text: string;
|
|
205
|
+
};
|
|
206
|
+
type AzureResponsesTextDeltaEvent = {
|
|
207
|
+
type: typeof AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE;
|
|
208
|
+
delta: string;
|
|
209
|
+
};
|
|
210
|
+
declare function isResponsesTextContentPartType(type: unknown): type is ResponsesTextContentPartType;
|
|
211
|
+
declare function isResponsesTextDeltaEventType(type: unknown): type is ResponsesTextDeltaEventType;
|
|
212
|
+
declare function isAzureResponsesTextDeltaEventType(type: unknown): type is typeof AZURE_RESPONSES_TEXT_DELTA_EVENT_TYPE;
|
|
213
|
+
declare function isAzureResponsesTextDeltaEvent(event: {
|
|
214
|
+
type?: unknown;
|
|
215
|
+
delta?: unknown;
|
|
216
|
+
}): event is AzureResponsesTextDeltaEvent;
|
|
217
|
+
type ResponsesMessageSnapshotCollapse = {
|
|
218
|
+
kind: "extend";
|
|
219
|
+
text: string;
|
|
220
|
+
} | {
|
|
221
|
+
kind: "keep";
|
|
222
|
+
};
|
|
223
|
+
declare function resolveResponsesMessageSnapshotCollapse(params: {
|
|
224
|
+
prior: {
|
|
225
|
+
text: string;
|
|
226
|
+
phase: string | undefined;
|
|
227
|
+
} | null;
|
|
228
|
+
nextText: string;
|
|
229
|
+
nextPhase: string | undefined;
|
|
230
|
+
}): ResponsesMessageSnapshotCollapse;
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region packages/ai/src/providers/openai-responses-terminal-usage.d.ts
|
|
233
|
+
/** Terminal usage payload, modeled structurally so untyped callers can pass raw records. */
|
|
234
|
+
type ResponsesTerminalUsagePayload = {
|
|
235
|
+
input_tokens?: number | null;
|
|
236
|
+
output_tokens?: number | null;
|
|
237
|
+
total_tokens?: number | null;
|
|
238
|
+
input_tokens_details?: {
|
|
239
|
+
cached_tokens?: number | null;
|
|
240
|
+
cache_write_tokens?: number | null;
|
|
241
|
+
} | null;
|
|
242
|
+
output_tokens_details?: {
|
|
243
|
+
reasoning_tokens?: number | null;
|
|
244
|
+
} | null;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Split a terminal usage payload into the priced buckets.
|
|
248
|
+
*
|
|
249
|
+
* OpenAI includes cache reads and writes in `input_tokens`, so both are subtracted out of the
|
|
250
|
+
* billable input bucket. `total_tokens` comes from the payload, but never below the sum of the
|
|
251
|
+
* split buckets: proxies routinely omit it (reporting 0 would understate the turn), and a payload
|
|
252
|
+
* whose `cached_tokens` exceeds `input_tokens` clamps the input bucket, leaving the reported total
|
|
253
|
+
* short of what the buckets actually price.
|
|
254
|
+
*/
|
|
255
|
+
declare function mapResponsesTerminalUsage(usage: ResponsesTerminalUsagePayload | undefined | null): Pick<Usage, "input" | "output" | "cacheRead" | "cacheWrite" | "totalTokens"> | undefined;
|
|
256
|
+
/** Reasoning tokens are reported by the agent path only; the package path does not track them. */
|
|
257
|
+
declare function readResponsesReasoningTokens(usage: ResponsesTerminalUsagePayload | undefined | null): number | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* Resolve the terminal stop reason, including the two overrides every Responses path shares: a
|
|
260
|
+
* content-filtered turn is a provider error rather than a truncated answer, and a turn that
|
|
261
|
+
* produced tool calls reports `toolUse` instead of a plain stop.
|
|
262
|
+
*/
|
|
263
|
+
declare function resolveResponsesTerminalStopReason(params: {
|
|
264
|
+
status: OpenAI.Responses.ResponseStatus | undefined;
|
|
265
|
+
incompleteReason?: string;
|
|
266
|
+
hasToolCall: boolean;
|
|
267
|
+
}): {
|
|
268
|
+
stopReason: StopReason;
|
|
269
|
+
errorMessage?: string;
|
|
270
|
+
};
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region packages/ai/src/providers/openai-responses-tool-call-tracker.d.ts
|
|
273
|
+
type ResponsesToolCallIdentity = {
|
|
274
|
+
itemId?: string;
|
|
275
|
+
callId?: string;
|
|
276
|
+
};
|
|
277
|
+
type ResponsesToolCallState = ResponsesToolCallIdentity & {
|
|
278
|
+
argumentStreamReliable: boolean;
|
|
279
|
+
};
|
|
280
|
+
type ResponsesToolCallEvent = {
|
|
281
|
+
output_index?: unknown;
|
|
282
|
+
item_id?: unknown;
|
|
283
|
+
};
|
|
284
|
+
declare function readResponsesToolCallItemIdentity(item: {
|
|
285
|
+
id?: unknown;
|
|
286
|
+
call_id?: unknown;
|
|
287
|
+
}): ResponsesToolCallIdentity;
|
|
288
|
+
declare function createResponsesToolCallTracker<TState extends ResponsesToolCallState>(): {
|
|
289
|
+
register(event: ResponsesToolCallEvent, state: TState): void;
|
|
290
|
+
resolve(event: ResponsesToolCallEvent, identity?: ResponsesToolCallIdentity): TState | undefined;
|
|
291
|
+
forget(toolCall: TState): void;
|
|
292
|
+
markArgumentsUnreliable(): void;
|
|
293
|
+
hasActive(): boolean;
|
|
294
|
+
};
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region packages/ai/src/providers/openai-stop-reason.d.ts
|
|
297
|
+
type OpenAIStopReasonResult = {
|
|
298
|
+
stopReason: StopReason;
|
|
299
|
+
errorMessage?: string;
|
|
300
|
+
};
|
|
301
|
+
declare function mapOpenAIStopReason(reason: string | null, options?: {
|
|
302
|
+
allowSingularToolCall?: boolean;
|
|
303
|
+
}): OpenAIStopReasonResult;
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region packages/ai/src/providers/openai-tool-schema-compat.d.ts
|
|
306
|
+
/** Repairs recoverable OpenAI tool-schema shapes before canonical normalization. */
|
|
307
|
+
declare function normalizeOpenAIStrictCompatSchema(schema: unknown): TSchema;
|
|
308
|
+
/** Finds schema paths that violate OpenAI strict tool-schema requirements. */
|
|
309
|
+
declare function findOpenAIStrictSchemaViolations(schema: unknown, path: string, options?: {
|
|
310
|
+
requireObjectRoot?: boolean;
|
|
311
|
+
}): string[];
|
|
312
|
+
//#endregion
|
|
313
|
+
//#region packages/ai/src/providers/openai-tool-schema.d.ts
|
|
314
|
+
/**
|
|
315
|
+
* OpenAI strict-tool-schema normalization and diagnostics.
|
|
316
|
+
*
|
|
317
|
+
* Strict schemas need all object properties required and `additionalProperties: false`; model
|
|
318
|
+
* compatibility settings can also remove unsupported schema constructs before strict checks run.
|
|
319
|
+
*/
|
|
320
|
+
type ToolSchemaCompatInput = {
|
|
321
|
+
unsupportedToolSchemaKeywords?: unknown;
|
|
322
|
+
omitEmptyArrayItems?: unknown;
|
|
323
|
+
};
|
|
324
|
+
declare function clearOpenAIToolSchemaCacheForTest(): void;
|
|
325
|
+
/** Normalizes a tool parameter schema into the OpenAI strict JSON-schema subset. */
|
|
326
|
+
declare function normalizeStrictOpenAIJsonSchema(schema: unknown, modelCompat?: ToolSchemaCompatInput | null): unknown;
|
|
327
|
+
/** Normalizes tool parameters using strict OpenAI rules only when strict mode is active. */
|
|
328
|
+
declare function normalizeOpenAIStrictToolParameters<T>(schema: T, strict: boolean, modelCompat?: ToolSchemaCompatInput | null): T;
|
|
329
|
+
/** Returns whether a schema already satisfies OpenAI strict tool-schema constraints. */
|
|
330
|
+
declare function isStrictOpenAIJsonSchemaCompatible(schema: unknown): boolean;
|
|
331
|
+
type OpenAIStrictToolSchemaDiagnostic = {
|
|
332
|
+
toolIndex: number;
|
|
333
|
+
toolName?: string;
|
|
334
|
+
violations: string[];
|
|
335
|
+
};
|
|
336
|
+
/** Returns strict-schema diagnostics for an already materialized OpenAI tool projection. */
|
|
337
|
+
declare function findOpenAIStrictToolProjectionDiagnostics(projection: OpenAIToolProjection): OpenAIStrictToolSchemaDiagnostic[];
|
|
338
|
+
/** Resolves strict mode for the projected tools that will be emitted in the request payload. */
|
|
339
|
+
declare function resolveOpenAIProjectedToolsStrictToolFlag(projection: OpenAIToolProjection, strict: boolean | null | undefined): boolean | undefined;
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region packages/ai/src/providers/schema-keyword-strip.d.ts
|
|
342
|
+
/** Recursively remove schema keywords unsupported by a target provider/tool surface. */
|
|
343
|
+
declare function stripUnsupportedSchemaKeywords(schema: unknown, unsupportedKeywords: ReadonlySet<string>): unknown;
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region packages/ai/src/providers/tool-schema-json-projection.d.ts
|
|
346
|
+
/** JSON-safe schema value used when projecting runtime tool parameters. */
|
|
347
|
+
type RuntimeToolInputSchemaJson = null | boolean | number | string | RuntimeToolInputSchemaJson[] | {
|
|
348
|
+
[key: string]: RuntimeToolInputSchemaJson;
|
|
349
|
+
};
|
|
350
|
+
/** Projected runtime tool schema plus validation violations. */
|
|
351
|
+
type RuntimeToolInputSchemaProjection = {
|
|
352
|
+
readonly schema: RuntimeToolInputSchemaJson;
|
|
353
|
+
readonly violations: readonly string[];
|
|
354
|
+
};
|
|
355
|
+
/** Projects one runtime tool input schema to JSON and reports runtime incompatibilities. */
|
|
356
|
+
declare function projectRuntimeToolInputSchema(schema: unknown, path?: string): RuntimeToolInputSchemaProjection;
|
|
357
|
+
//#endregion
|
|
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 };
|