@ai-sdk/openai-compatible 3.0.59 → 3.0.60

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.
@@ -1,216 +1,224 @@
1
- import * as _ai_sdk_provider from '@ai-sdk/provider';
2
- import { JSONValue, LanguageModelV4Prompt, LanguageModelV4Usage, LanguageModelV4FinishReason, LanguageModelV4CallOptions, SharedV4Warning, SharedV4ProviderMetadata, LanguageModelV4 } from '@ai-sdk/provider';
3
- import { FetchFunction } from '@ai-sdk/provider-utils';
4
- import { ZodType, z } from 'zod/v4';
5
-
1
+ import { JSONValue, LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4FinishReason, LanguageModelV4Prompt, LanguageModelV4Usage, SharedV4ProviderMetadata, SharedV4Warning } from "@ai-sdk/provider";
2
+ import { FetchFunction } from "@ai-sdk/provider-utils";
3
+ import { ZodType, z } from "zod/v4";
4
+ //#region src/chat/openai-compatible-api-types.d.ts
6
5
  type OpenAICompatibleChatPrompt = Array<OpenAICompatibleMessage>;
7
6
  type OpenAICompatibleMessage = OpenAICompatibleSystemMessage | OpenAICompatibleUserMessage | OpenAICompatibleAssistantMessage | OpenAICompatibleToolMessage;
8
7
  type JsonRecord<T = never> = Record<string, JSONValue | JSONValue[] | T | T[] | undefined>;
9
8
  interface OpenAICompatibleSystemMessage extends JsonRecord {
10
- role: 'system';
11
- content: string;
9
+ role: 'system';
10
+ content: string;
12
11
  }
13
12
  interface OpenAICompatibleUserMessage extends JsonRecord<OpenAICompatibleContentPart> {
14
- role: 'user';
15
- content: string | Array<OpenAICompatibleContentPart>;
13
+ role: 'user';
14
+ content: string | Array<OpenAICompatibleContentPart>;
16
15
  }
17
16
  type OpenAICompatibleContentPart = OpenAICompatibleContentPartText | OpenAICompatibleContentPartImage | OpenAICompatibleContentPartVideo | OpenAICompatibleContentPartInputAudio | OpenAICompatibleContentPartFile;
18
17
  interface OpenAICompatibleContentPartText extends JsonRecord {
19
- type: 'text';
20
- text: string;
18
+ type: 'text';
19
+ text: string;
21
20
  }
22
21
  interface OpenAICompatibleContentPartImage extends JsonRecord {
23
- type: 'image_url';
24
- image_url: {
25
- url: string;
26
- };
22
+ type: 'image_url';
23
+ image_url: {
24
+ url: string;
25
+ };
27
26
  }
28
27
  interface OpenAICompatibleContentPartVideo extends JsonRecord {
29
- type: 'video_url';
30
- video_url: {
31
- url: string;
32
- };
28
+ type: 'video_url';
29
+ video_url: {
30
+ url: string;
31
+ };
33
32
  }
34
33
  interface OpenAICompatibleContentPartInputAudio extends JsonRecord {
35
- type: 'input_audio';
36
- input_audio: {
37
- data: string;
38
- format: 'wav' | 'mp3';
39
- };
34
+ type: 'input_audio';
35
+ input_audio: {
36
+ data: string;
37
+ format: 'wav' | 'mp3';
38
+ };
40
39
  }
41
40
  interface OpenAICompatibleContentPartFile extends JsonRecord {
42
- type: 'file';
43
- file: {
44
- filename: string;
45
- file_data: string;
46
- };
41
+ type: 'file';
42
+ file: {
43
+ filename: string;
44
+ file_data: string;
45
+ };
47
46
  }
48
47
  interface OpenAICompatibleAssistantMessage extends JsonRecord<OpenAICompatibleMessageToolCall> {
49
- role: 'assistant';
50
- content?: string | null;
51
- reasoning_content?: string;
52
- tool_calls?: Array<OpenAICompatibleMessageToolCall>;
48
+ role: 'assistant';
49
+ content?: string | null;
50
+ reasoning_content?: string;
51
+ tool_calls?: Array<OpenAICompatibleMessageToolCall>;
53
52
  }
54
53
  interface OpenAICompatibleMessageToolCall extends JsonRecord {
55
- type: 'function';
56
- id: string;
57
- function: {
58
- arguments: string;
59
- name: string;
60
- };
61
- /**
62
- * Additional content for provider-specific features.
63
- * Used by Google Gemini for thought signatures via OpenAI compatibility.
64
- */
65
- extra_content?: {
66
- google?: {
67
- thought_signature?: string;
68
- };
54
+ type: 'function';
55
+ id: string;
56
+ function: {
57
+ arguments: string;
58
+ name: string;
59
+ };
60
+ /**
61
+ * Additional content for provider-specific features.
62
+ * Used by Google Gemini for thought signatures via OpenAI compatibility.
63
+ */
64
+ extra_content?: {
65
+ google?: {
66
+ thought_signature?: string;
69
67
  };
68
+ };
70
69
  }
71
70
  interface OpenAICompatibleToolMessage extends JsonRecord {
72
- role: 'tool';
73
- content: string;
74
- tool_call_id: string;
71
+ role: 'tool';
72
+ content: string;
73
+ tool_call_id: string;
75
74
  }
76
-
77
- declare function convertToOpenAICompatibleChatMessages(prompt: LanguageModelV4Prompt, { providerOptionsKey }?: {
78
- providerOptionsKey?: string;
75
+ //#endregion
76
+ //#region src/chat/convert-to-openai-compatible-chat-messages.d.ts
77
+ export declare function convertToOpenAICompatibleChatMessages(prompt: LanguageModelV4Prompt, { providerOptionsKey }?: {
78
+ providerOptionsKey?: string;
79
79
  }): OpenAICompatibleChatPrompt;
80
-
81
- declare function convertOpenAICompatibleChatUsage(usage: {
82
- prompt_tokens?: number | null;
83
- completion_tokens?: number | null;
84
- prompt_tokens_details?: {
85
- cached_tokens?: number | null;
86
- } | null;
87
- completion_tokens_details?: {
88
- reasoning_tokens?: number | null;
89
- } | null;
80
+ //#endregion
81
+ //#region src/chat/convert-openai-compatible-chat-usage.d.ts
82
+ export declare function convertOpenAICompatibleChatUsage(usage: {
83
+ prompt_tokens?: number | null;
84
+ completion_tokens?: number | null;
85
+ prompt_tokens_details?: {
86
+ cached_tokens?: number | null;
87
+ } | null;
88
+ completion_tokens_details?: {
89
+ reasoning_tokens?: number | null;
90
+ } | null;
90
91
  } | undefined | null): LanguageModelV4Usage;
91
-
92
- declare function mapOpenAICompatibleFinishReason(finishReason: string | null | undefined): LanguageModelV4FinishReason['unified'];
93
-
94
- declare function getResponseMetadata({ id, model, created, }: {
95
- id?: string | null;
96
- model?: string | null;
97
- created?: number | null;
98
- }): _ai_sdk_provider.LanguageModelV4ResponseMetadata;
99
-
100
- declare function prepareTools({ tools, toolChoice, }: {
101
- tools: LanguageModelV4CallOptions['tools'];
102
- toolChoice?: LanguageModelV4CallOptions['toolChoice'];
92
+ //#endregion
93
+ //#region src/chat/map-openai-compatible-finish-reason.d.ts
94
+ export declare function mapOpenAICompatibleFinishReason(finishReason: string | null | undefined): LanguageModelV4FinishReason['unified'];
95
+ //#endregion
96
+ //#region src/chat/get-response-metadata.d.ts
97
+ export declare function getResponseMetadata({ id, model, created }: {
98
+ id?: string | null;
99
+ model?: string | null;
100
+ created?: number | null;
101
+ }): import("@ai-sdk/provider").LanguageModelV4ResponseMetadata;
102
+ //#endregion
103
+ //#region src/chat/openai-compatible-prepare-tools.d.ts
104
+ export declare function prepareTools({ tools, toolChoice }: {
105
+ tools: LanguageModelV4CallOptions['tools'];
106
+ toolChoice?: LanguageModelV4CallOptions['toolChoice'];
103
107
  }): {
104
- tools: undefined | Array<{
105
- type: 'function';
106
- function: {
107
- name: string;
108
- description: string | undefined;
109
- parameters: unknown;
110
- strict?: boolean;
111
- };
112
- }>;
113
- toolChoice: {
114
- type: 'function';
115
- function: {
116
- name: string;
117
- };
118
- } | 'auto' | 'none' | 'required' | undefined;
119
- toolWarnings: SharedV4Warning[];
108
+ tools: undefined | Array<{
109
+ type: 'function';
110
+ function: {
111
+ name: string;
112
+ description: string | undefined;
113
+ parameters: unknown;
114
+ strict?: boolean;
115
+ };
116
+ }>;
117
+ toolChoice: {
118
+ type: 'function';
119
+ function: {
120
+ name: string;
121
+ };
122
+ } | 'auto' | 'none' | 'required' | undefined;
123
+ toolWarnings: SharedV4Warning[];
120
124
  };
121
-
125
+ //#endregion
126
+ //#region src/openai-compatible-error.d.ts
122
127
  type ProviderErrorStructure<T> = {
123
- errorSchema: ZodType<T>;
124
- errorToMessage: (error: T) => string;
125
- isRetryable?: (response: Response, error?: T) => boolean;
128
+ errorSchema: ZodType<T>;
129
+ errorToMessage: (error: T) => string;
130
+ isRetryable?: (response: Response, error?: T) => boolean;
126
131
  };
127
-
132
+ //#endregion
133
+ //#region src/chat/openai-compatible-metadata-extractor.d.ts
128
134
  /**
129
135
  * Extracts provider-specific metadata from API responses.
130
136
  * Used to standardize metadata handling across different LLM providers while allowing
131
137
  * provider-specific metadata to be captured.
132
138
  */
133
139
  type MetadataExtractor = {
140
+ /**
141
+ * Extracts provider metadata from a complete, non-streaming response.
142
+ *
143
+ * @param parsedBody - The parsed response JSON body from the provider's API.
144
+ *
145
+ * @returns Provider-specific metadata or undefined if no metadata is available.
146
+ * The metadata should be under a key indicating the provider id.
147
+ */
148
+ extractMetadata: ({ parsedBody }: {
149
+ parsedBody: unknown;
150
+ }) => Promise<SharedV4ProviderMetadata | undefined>;
151
+ /**
152
+ * Creates an extractor for handling streaming responses. The returned object provides
153
+ * methods to process individual chunks and build the final metadata from the accumulated
154
+ * stream data.
155
+ *
156
+ * @returns An object with methods to process chunks and build metadata from a stream
157
+ */
158
+ createStreamExtractor: () => {
134
159
  /**
135
- * Extracts provider metadata from a complete, non-streaming response.
160
+ * Process an individual chunk from the stream. Called for each chunk in the response stream
161
+ * to accumulate metadata throughout the streaming process.
136
162
  *
137
- * @param parsedBody - The parsed response JSON body from the provider's API.
138
- *
139
- * @returns Provider-specific metadata or undefined if no metadata is available.
140
- * The metadata should be under a key indicating the provider id.
163
+ * @param parsedChunk - The parsed JSON response chunk from the provider's API
141
164
  */
142
- extractMetadata: ({ parsedBody, }: {
143
- parsedBody: unknown;
144
- }) => Promise<SharedV4ProviderMetadata | undefined>;
165
+ processChunk(parsedChunk: unknown): void;
145
166
  /**
146
- * Creates an extractor for handling streaming responses. The returned object provides
147
- * methods to process individual chunks and build the final metadata from the accumulated
148
- * stream data.
167
+ * Builds the metadata object after all chunks have been processed.
168
+ * Called at the end of the stream to generate the complete provider metadata.
149
169
  *
150
- * @returns An object with methods to process chunks and build metadata from a stream
170
+ * @returns Provider-specific metadata or undefined if no metadata is available.
171
+ * The metadata should be under a key indicating the provider id.
151
172
  */
152
- createStreamExtractor: () => {
153
- /**
154
- * Process an individual chunk from the stream. Called for each chunk in the response stream
155
- * to accumulate metadata throughout the streaming process.
156
- *
157
- * @param parsedChunk - The parsed JSON response chunk from the provider's API
158
- */
159
- processChunk(parsedChunk: unknown): void;
160
- /**
161
- * Builds the metadata object after all chunks have been processed.
162
- * Called at the end of the stream to generate the complete provider metadata.
163
- *
164
- * @returns Provider-specific metadata or undefined if no metadata is available.
165
- * The metadata should be under a key indicating the provider id.
166
- */
167
- buildMetadata(): SharedV4ProviderMetadata | undefined;
168
- };
173
+ buildMetadata(): SharedV4ProviderMetadata | undefined;
174
+ };
169
175
  };
170
-
176
+ //#endregion
177
+ //#region src/chat/openai-compatible-chat-language-model.d.ts
171
178
  type OpenAICompatibleChatConfig = {
172
- provider: string;
173
- headers?: () => Record<string, string | undefined>;
174
- url: (options: {
175
- modelId: string;
176
- path: string;
177
- }) => string;
178
- fetch?: FetchFunction;
179
- includeUsage?: boolean;
180
- errorStructure?: ProviderErrorStructure<any>;
181
- metadataExtractor?: MetadataExtractor;
182
- /**
183
- * Whether the model supports structured outputs.
184
- */
185
- supportsStructuredOutputs?: boolean;
186
- /**
187
- * The supported URLs for the model.
188
- */
189
- supportedUrls?: () => LanguageModelV4['supportedUrls'];
190
- /**
191
- * Optional function to transform the request body before sending it to the API.
192
- * This is useful for proxy providers that may require a different request format
193
- * than the official OpenAI API.
194
- */
195
- transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
196
- /**
197
- * Optional usage converter for OpenAI-compatible providers with different
198
- * token accounting semantics.
199
- */
200
- convertUsage?: (usage: z.infer<typeof openaiCompatibleTokenUsageSchema>) => LanguageModelV4Usage;
179
+ provider: string;
180
+ headers?: () => Record<string, string | undefined>;
181
+ url: (options: {
182
+ modelId: string;
183
+ path: string;
184
+ }) => string;
185
+ fetch?: FetchFunction;
186
+ includeUsage?: boolean;
187
+ errorStructure?: ProviderErrorStructure<any>;
188
+ metadataExtractor?: MetadataExtractor;
189
+ /**
190
+ * Whether the model supports structured outputs.
191
+ */
192
+ supportsStructuredOutputs?: boolean;
193
+ /**
194
+ * The supported URLs for the model.
195
+ */
196
+ supportedUrls?: () => LanguageModelV4['supportedUrls'];
197
+ /**
198
+ * Optional function to transform the request body before sending it to the API.
199
+ * This is useful for proxy providers that may require a different request format
200
+ * than the official OpenAI API.
201
+ */
202
+ transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
203
+ /**
204
+ * Optional usage converter for OpenAI-compatible providers with different
205
+ * token accounting semantics.
206
+ */
207
+ convertUsage?: (usage: z.infer<typeof openaiCompatibleTokenUsageSchema>) => LanguageModelV4Usage;
201
208
  };
202
209
  declare const openaiCompatibleTokenUsageSchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
203
- prompt_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
204
- completion_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
205
- total_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
206
- prompt_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
207
- cached_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
208
- }, z.core.$loose>>>;
209
- completion_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
210
- reasoning_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
211
- accepted_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
212
- rejected_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
213
- }, z.core.$loose>>>;
210
+ prompt_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
211
+ completion_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
212
+ total_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
213
+ prompt_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
214
+ cached_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
215
+ }, z.core.$loose>>>;
216
+ completion_tokens_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
217
+ reasoning_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
218
+ accepted_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
219
+ rejected_prediction_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
220
+ }, z.core.$loose>>>;
214
221
  }, z.core.$loose>>>;
215
-
216
- export { type OpenAICompatibleChatConfig, convertOpenAICompatibleChatUsage, convertToOpenAICompatibleChatMessages, getResponseMetadata, mapOpenAICompatibleFinishReason, prepareTools };
222
+ //#endregion
223
+ export type { OpenAICompatibleChatConfig };
224
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/chat/openai-compatible-api-types.ts","../../src/chat/convert-to-openai-compatible-chat-messages.ts","../../src/chat/convert-openai-compatible-chat-usage.ts","../../src/chat/map-openai-compatible-finish-reason.ts","../../src/chat/get-response-metadata.ts","../../src/chat/openai-compatible-prepare-tools.ts","../../src/openai-compatible-error.ts","../../src/chat/openai-compatible-metadata-extractor.ts","../../src/chat/openai-compatible-chat-language-model.ts"],"mappings":";;;;KAEY,6BAA6B,MAAM;KAEnC,0BACR,gCACA,8BACA,mCACA;KAIC,WAAW,aAAa,eAE3B,YAAY,cAAc,IAAI;UAGf,sCAAsC;EACrD;EACA;;UAGe,oCAAoC,WAAW;EAC9D;EACA,kBAAkB,MAAM;;KAGd,8BACR,kCACA,mCACA,mCACA,wCACA;UAEa,wCAAwC;EACvD;EACA;;UAGe,yCAAyC;EACxD;EACA;IAAa;;;UAIE,yCAAyC;EACxD;EACA;IAAa;;;UAIE,8CAA8C;EAC7D;EACA;IAAe;IAAc;;;UAId,wCAAwC;EACvD;EACA;IAAQ;IAAkB;;;UAGX,yCAAyC,WAAW;EACnE;EACA;EACA;EACA,aAAa,MAAM;;UAGJ,wCAAwC;EACvD;EACA;EACA;IACE;IACA;;;;;;EAMF;IACE;MACE;;;;UAKW,oCAAoC;EACnD;EACA;EACA;;;;wBC3Dc,sCACd,QAAQ,yBACN;EAAmC;IACpC;;;wBC/Ba,iCACd;EAEM;EACA;EACA;IACE;;EAEF;IACE;;uBAKP;;;wBCfa,gCACd,0CACC;;;wBCFa,sBACd,IACA,OACA;EAEA;EACA;EACA;+BACD;;;wBCLe,eACd,OACA;EAEA,OAAO;EACP,aAAa;;EAEb,mBAEI;IACE;IACA;MACE;MACA;MACA;MACA;;;EAGR;IACM;IAAkB;MAAY;;;EAKpC,cAAc;;;;KCXJ,uBAAuB;EACjC,aAAa,QAAQ;EACrB,iBAAiB,OAAO;EACxB,eAAe,UAAU,UAAU,QAAQ;;;;;;;;;KCdjC;;;;;;;;;EASV,oBACE;IAEA;QACI,QAAQ;;;;;;;;EASd;;;;;;;IAOE,aAAa;;;;;;;;IASb,iBAAiB;;;;;KCgBT;EACV;EACA,gBAAgB;EAChB,MAAM;IAAW;IAAiB;;EAClC,QAAQ;EACR;EACA,iBAAiB;EACjB,oBAAoB;;;;EAKpB;;;;EAKA,sBAAsB;;;;;;EAOtB,wBAAwB,MAAM,wBAAwB;;;;;EAMtD,gBACE,OAAO,EAAE,aAAa,sCACnB;;cAqqBD,kCAAgC,EAAA,YAAA,EAAA,YAAA,EAAA;;;;;;;;;;;;GAkB1B,EAAA,KAAA"}