@supersolutions/super-chat-core 0.0.0 → 0.2.0

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.
@@ -0,0 +1,194 @@
1
+ import { e as Transport, R as RetryPolicy, P as ProviderCapabilities, f as ModelInfo, g as Provider, N as NormalizedRequest, M as Message } from './types-y3SK7HwA.js';
2
+
3
+ type AnthropicProviderConfig = {
4
+ transport: Transport;
5
+ /** Provider id, so several instances can coexist. Defaults to "anthropic". */
6
+ id?: string;
7
+ label?: string;
8
+ retry?: RetryPolicy;
9
+ capabilities?: Partial<ProviderCapabilities>;
10
+ models?: ModelInfo[];
11
+ /** `anthropic-version` header value. */
12
+ version?: string;
13
+ /** `max_tokens` is REQUIRED on this wire; applied when the request has none. */
14
+ defaultMaxTokens?: number;
15
+ };
16
+ declare function createAnthropicProvider(config: AnthropicProviderConfig): Provider;
17
+
18
+ type AnthropicImageSource = {
19
+ type: "base64";
20
+ media_type: string;
21
+ data: string;
22
+ } | {
23
+ type: "url";
24
+ url: string;
25
+ } | {
26
+ type: "file";
27
+ file_id: string;
28
+ };
29
+ type AnthropicContentBlock = {
30
+ type: "text";
31
+ text: string;
32
+ } | {
33
+ type: "image";
34
+ source: AnthropicImageSource;
35
+ } | {
36
+ type: "document";
37
+ source: AnthropicImageSource;
38
+ title?: string;
39
+ } | {
40
+ type: "tool_use";
41
+ id: string;
42
+ name: string;
43
+ input: unknown;
44
+ } | {
45
+ type: "tool_result";
46
+ tool_use_id: string;
47
+ content: string | {
48
+ type: "text";
49
+ text: string;
50
+ }[];
51
+ is_error?: boolean;
52
+ } | {
53
+ type: "thinking";
54
+ thinking: string;
55
+ signature?: string;
56
+ } | {
57
+ type: "redacted_thinking";
58
+ data: string;
59
+ };
60
+ type AnthropicMessage = {
61
+ role: "user" | "assistant";
62
+ content: AnthropicContentBlock[];
63
+ };
64
+ type AnthropicTool = {
65
+ name: string;
66
+ description?: string;
67
+ input_schema: Record<string, unknown>;
68
+ strict?: boolean;
69
+ };
70
+ type AnthropicToolChoice = {
71
+ type: "auto";
72
+ disable_parallel_tool_use?: boolean;
73
+ } | {
74
+ type: "any";
75
+ disable_parallel_tool_use?: boolean;
76
+ } | {
77
+ type: "tool";
78
+ name: string;
79
+ disable_parallel_tool_use?: boolean;
80
+ } | {
81
+ type: "none";
82
+ };
83
+ type AnthropicRequest = {
84
+ model: string;
85
+ max_tokens: number;
86
+ system?: string;
87
+ messages: AnthropicMessage[];
88
+ tools?: AnthropicTool[];
89
+ tool_choice?: AnthropicToolChoice;
90
+ thinking?: {
91
+ type: "adaptive";
92
+ display?: "summarized" | "omitted";
93
+ };
94
+ output_config?: {
95
+ effort?: "low" | "medium" | "high" | "xhigh" | "max";
96
+ format?: {
97
+ type: "json_schema";
98
+ schema: Record<string, unknown>;
99
+ };
100
+ };
101
+ temperature?: number;
102
+ top_p?: number;
103
+ stop_sequences?: string[];
104
+ stream?: boolean;
105
+ metadata?: {
106
+ user_id?: string;
107
+ };
108
+ };
109
+ type AnthropicUsage = {
110
+ input_tokens?: number;
111
+ output_tokens?: number;
112
+ cache_read_input_tokens?: number;
113
+ cache_creation_input_tokens?: number;
114
+ };
115
+ type AnthropicStopReason = "end_turn" | "max_tokens" | "stop_sequence" | "tool_use" | "refusal" | "pause_turn" | "model_context_window_exceeded" | (string & {});
116
+ type AnthropicResponse = {
117
+ id: string;
118
+ type: "message";
119
+ role: "assistant";
120
+ model: string;
121
+ content: AnthropicContentBlock[];
122
+ stop_reason: AnthropicStopReason | null;
123
+ stop_sequence: string | null;
124
+ usage: AnthropicUsage;
125
+ };
126
+ type AnthropicStreamEvent = {
127
+ type: "message_start";
128
+ message: AnthropicResponse;
129
+ } | {
130
+ type: "content_block_start";
131
+ index: number;
132
+ content_block: AnthropicContentBlock;
133
+ } | {
134
+ type: "content_block_delta";
135
+ index: number;
136
+ delta: AnthropicDelta;
137
+ } | {
138
+ type: "content_block_stop";
139
+ index: number;
140
+ } | {
141
+ type: "message_delta";
142
+ delta: {
143
+ stop_reason?: AnthropicStopReason | null;
144
+ };
145
+ usage?: AnthropicUsage;
146
+ } | {
147
+ type: "message_stop";
148
+ } | {
149
+ type: "ping";
150
+ } | {
151
+ type: "error";
152
+ error: {
153
+ type: string;
154
+ message: string;
155
+ };
156
+ };
157
+ type AnthropicDelta = {
158
+ type: "text_delta";
159
+ text: string;
160
+ } | {
161
+ type: "input_json_delta";
162
+ partial_json: string;
163
+ } | {
164
+ type: "thinking_delta";
165
+ thinking: string;
166
+ } | {
167
+ type: "signature_delta";
168
+ signature: string;
169
+ };
170
+
171
+ type AnthropicBuildOptions = {
172
+ stream?: boolean;
173
+ providerId?: string;
174
+ parallelToolCalls?: boolean;
175
+ /** Applied when the request carries no maxOutputTokens (`max_tokens` is required). */
176
+ defaultMaxTokens?: number;
177
+ };
178
+ /**
179
+ * Fold normalized messages into Anthropic's user/assistant alternation.
180
+ * System messages are hoisted by the caller; `tool` role messages become USER
181
+ * messages carrying tool_result blocks (the wire has no tool role). Adjacent
182
+ * same-role messages merge — cheap, and robust to strict-alternation servers.
183
+ */
184
+ declare function toAnthropicMessages(messages: readonly Message[], providerId?: string): AnthropicMessage[];
185
+ /**
186
+ * Same orphan rule as OpenAI: a `tool_use` with no `tool_result` in the next
187
+ * user message 400s the whole request. A cancelled turn leaves exactly that in
188
+ * persisted history, so prune rather than letting one lost step poison the
189
+ * thread forever.
190
+ */
191
+ declare function dropOrphanToolUses(messages: AnthropicMessage[]): AnthropicMessage[];
192
+ declare function buildAnthropicRequest(req: NormalizedRequest, opts?: AnthropicBuildOptions): AnthropicRequest;
193
+
194
+ export { type AnthropicProviderConfig as A, type AnthropicStopReason as a, buildAnthropicRequest as b, createAnthropicProvider as c, type AnthropicResponse as d, type AnthropicUsage as e, type AnthropicBuildOptions as f, type AnthropicContentBlock as g, type AnthropicDelta as h, type AnthropicImageSource as i, type AnthropicMessage as j, type AnthropicRequest as k, type AnthropicStreamEvent as l, type AnthropicTool as m, type AnthropicToolChoice as n, dropOrphanToolUses as o, toAnthropicMessages as t };
@@ -0,0 +1,411 @@
1
+ import { i as JobHandle, j as JobStatus, n as JobSnapshot, g as Provider, e as Transport, R as RetryPolicy, P as ProviderCapabilities, f as ModelInfo, N as NormalizedRequest, M as Message } from './types-y3SK7HwA.js';
2
+
3
+ /**
4
+ * Await a background job to a terminal state.
5
+ *
6
+ * Polling rather than streaming because polling survives a closed tab, a lost
7
+ * network and a serverless function timeout — which is the entire reason to use
8
+ * background mode. The interval backs off so a 20-minute job does not make 1200
9
+ * requests.
10
+ *
11
+ * Provider-generic: it needs only `pollJob`, so it lives here rather than in any
12
+ * one adapter.
13
+ */
14
+ declare function awaitJob(provider: Provider, handle: JobHandle, opts?: {
15
+ signal?: AbortSignal;
16
+ initialIntervalMs?: number;
17
+ maxIntervalMs?: number;
18
+ timeoutMs?: number;
19
+ onStatus?: (snapshot: JobSnapshot) => void;
20
+ }): Promise<JobSnapshot>;
21
+ type StoredJob = {
22
+ handle: JobHandle;
23
+ status: JobStatus;
24
+ /** Thread this job belongs to, so a resumed result lands in the right place. */
25
+ threadId?: string;
26
+ createdAt: number;
27
+ updatedAt: number;
28
+ label?: string;
29
+ };
30
+ type JobStore = {
31
+ list(): Promise<StoredJob[]>;
32
+ get(id: string): Promise<StoredJob | undefined>;
33
+ put(job: StoredJob): Promise<void>;
34
+ remove(id: string): Promise<void>;
35
+ };
36
+ declare function createMemoryJobStore(): JobStore;
37
+ /**
38
+ * localStorage-backed store, key per job: `{prefix}:index` holds the list of
39
+ * live job ids, `{prefix}:{id}` holds one job. `resumeJobs`/`reap` put or
40
+ * remove one job at a time in a loop — a single-blob layout would mean
41
+ * re-parsing and re-stringifying every OTHER job's data on each of those
42
+ * calls, which turns an O(n) sweep into O(n²) localStorage churn.
43
+ *
44
+ * Every read is defensive: a corrupted or hand-edited entry must not throw on
45
+ * app start.
46
+ */
47
+ declare function createLocalJobStore(prefix?: string): JobStore;
48
+ declare const isTerminal: (status: JobStatus) => boolean;
49
+ /** Drop terminal jobs and stale non-terminal ones. */
50
+ declare function reap(store: JobStore, opts?: {
51
+ maxAgeMs?: number;
52
+ }): Promise<StoredJob[]>;
53
+ type ResumeResult = {
54
+ job: StoredJob;
55
+ snapshot: JobSnapshot;
56
+ };
57
+ /**
58
+ * Re-poll every unfinished job in the store. Call this on app start.
59
+ *
60
+ * A 404/expired handle resolves as `failed` with an explanatory message rather
61
+ * than throwing — the job is genuinely gone, and the user needs to be told that
62
+ * rather than watching a spinner.
63
+ */
64
+ declare function resumeJobs(store: JobStore, providers: Record<string, Provider>, opts?: {
65
+ signal?: AbortSignal;
66
+ }): Promise<ResumeResult[]>;
67
+
68
+ type ResponsesInputContent = {
69
+ type: "input_text";
70
+ text: string;
71
+ } | {
72
+ type: "input_image";
73
+ image_url?: string;
74
+ file_id?: string;
75
+ detail?: "auto" | "low" | "high";
76
+ } | {
77
+ type: "input_file";
78
+ file_id?: string;
79
+ filename?: string;
80
+ file_data?: string;
81
+ } | {
82
+ type: "output_text";
83
+ text: string;
84
+ };
85
+ type ResponsesInputItem = {
86
+ type: "message";
87
+ role: "user" | "assistant" | "system" | "developer";
88
+ content: ResponsesInputContent[];
89
+ } | {
90
+ type: "function_call";
91
+ call_id: string;
92
+ name: string;
93
+ arguments: string;
94
+ id?: string;
95
+ } | {
96
+ type: "function_call_output";
97
+ call_id: string;
98
+ output: string;
99
+ } | {
100
+ type: "reasoning";
101
+ id: string;
102
+ summary: {
103
+ type: "summary_text";
104
+ text: string;
105
+ }[];
106
+ encrypted_content?: string;
107
+ };
108
+ type ResponsesTool = {
109
+ type: "function";
110
+ name: string;
111
+ description?: string;
112
+ parameters: Record<string, unknown>;
113
+ strict?: boolean;
114
+ };
115
+ type ResponsesToolChoice = "auto" | "none" | "required" | {
116
+ type: "function";
117
+ name: string;
118
+ };
119
+ type ResponsesRequest = {
120
+ model: string;
121
+ input: ResponsesInputItem[];
122
+ instructions?: string;
123
+ tools?: ResponsesTool[];
124
+ tool_choice?: ResponsesToolChoice;
125
+ parallel_tool_calls?: boolean;
126
+ max_output_tokens?: number;
127
+ temperature?: number;
128
+ top_p?: number;
129
+ text?: {
130
+ format: {
131
+ type: "text";
132
+ } | {
133
+ type: "json_object";
134
+ } | {
135
+ type: "json_schema";
136
+ name: string;
137
+ schema: Record<string, unknown>;
138
+ strict?: boolean;
139
+ };
140
+ };
141
+ reasoning?: {
142
+ effort?: "minimal" | "low" | "medium" | "high";
143
+ summary?: "auto" | "concise" | "detailed";
144
+ };
145
+ background?: boolean;
146
+ store?: boolean;
147
+ stream?: boolean;
148
+ previous_response_id?: string;
149
+ metadata?: Record<string, string>;
150
+ include?: string[];
151
+ };
152
+ type ResponsesOutputItem = {
153
+ type: "message";
154
+ id?: string;
155
+ role: "assistant";
156
+ status?: string;
157
+ content: ({
158
+ type: "output_text";
159
+ text: string;
160
+ annotations?: unknown[];
161
+ } | {
162
+ type: "refusal";
163
+ refusal: string;
164
+ })[];
165
+ } | {
166
+ type: "function_call";
167
+ id?: string;
168
+ call_id: string;
169
+ name: string;
170
+ arguments: string;
171
+ status?: string;
172
+ } | {
173
+ type: "reasoning";
174
+ id: string;
175
+ summary?: {
176
+ type: "summary_text";
177
+ text: string;
178
+ }[];
179
+ encrypted_content?: string;
180
+ } | {
181
+ type: string;
182
+ [k: string]: unknown;
183
+ };
184
+ type ResponsesUsage = {
185
+ input_tokens?: number;
186
+ output_tokens?: number;
187
+ total_tokens?: number;
188
+ input_tokens_details?: {
189
+ cached_tokens?: number;
190
+ };
191
+ output_tokens_details?: {
192
+ reasoning_tokens?: number;
193
+ };
194
+ };
195
+ type ResponsesResponse = {
196
+ id: string;
197
+ object: "response";
198
+ created_at: number;
199
+ model: string;
200
+ status: "queued" | "in_progress" | "completed" | "failed" | "incomplete" | "cancelled";
201
+ output: ResponsesOutputItem[];
202
+ output_text?: string;
203
+ usage?: ResponsesUsage;
204
+ error?: {
205
+ code?: string;
206
+ message: string;
207
+ } | null;
208
+ incomplete_details?: {
209
+ reason?: string;
210
+ } | null;
211
+ previous_response_id?: string | null;
212
+ };
213
+ /** Streaming envelope. Every event carries `sequence_number` — that is the cursor
214
+ * `starting_after` uses to resume a background stream after a disconnect. */
215
+ type ResponsesStreamEvent = {
216
+ type: string;
217
+ sequence_number?: number;
218
+ delta?: string;
219
+ text?: string;
220
+ item_id?: string;
221
+ output_index?: number;
222
+ content_index?: number;
223
+ item?: ResponsesOutputItem;
224
+ response?: ResponsesResponse;
225
+ arguments?: string;
226
+ code?: string;
227
+ message?: string;
228
+ };
229
+ type ChatContentPart = {
230
+ type: "text";
231
+ text: string;
232
+ } | {
233
+ type: "image_url";
234
+ image_url: {
235
+ url: string;
236
+ detail?: "auto" | "low" | "high";
237
+ };
238
+ } | {
239
+ type: "input_audio";
240
+ input_audio: {
241
+ data: string;
242
+ format: "wav" | "mp3";
243
+ };
244
+ } | {
245
+ type: "file";
246
+ file: {
247
+ file_id?: string;
248
+ filename?: string;
249
+ file_data?: string;
250
+ };
251
+ };
252
+ type ChatToolCall = {
253
+ id: string;
254
+ type: "function";
255
+ function: {
256
+ name: string;
257
+ arguments: string;
258
+ };
259
+ /** Present only on streamed deltas, to correlate partial calls. */
260
+ index?: number;
261
+ };
262
+ type ChatMessage = {
263
+ role: "system" | "developer";
264
+ content: string;
265
+ } | {
266
+ role: "user";
267
+ content: string | ChatContentPart[];
268
+ } | {
269
+ role: "assistant";
270
+ content?: string | null;
271
+ tool_calls?: ChatToolCall[];
272
+ refusal?: string | null;
273
+ } | {
274
+ role: "tool";
275
+ content: string;
276
+ tool_call_id: string;
277
+ };
278
+ type ChatTool = {
279
+ type: "function";
280
+ function: {
281
+ name: string;
282
+ description?: string;
283
+ parameters: Record<string, unknown>;
284
+ strict?: boolean;
285
+ };
286
+ };
287
+ type ChatRequest = {
288
+ model: string;
289
+ messages: ChatMessage[];
290
+ tools?: ChatTool[];
291
+ tool_choice?: "auto" | "none" | "required" | {
292
+ type: "function";
293
+ function: {
294
+ name: string;
295
+ };
296
+ };
297
+ parallel_tool_calls?: boolean;
298
+ /** Newer name for max_tokens; required for reasoning models, accepted by the rest. */
299
+ max_completion_tokens?: number;
300
+ temperature?: number;
301
+ top_p?: number;
302
+ stop?: string[];
303
+ response_format?: {
304
+ type: "text";
305
+ } | {
306
+ type: "json_object";
307
+ } | {
308
+ type: "json_schema";
309
+ json_schema: {
310
+ name: string;
311
+ schema: Record<string, unknown>;
312
+ strict?: boolean;
313
+ };
314
+ };
315
+ reasoning_effort?: "minimal" | "low" | "medium" | "high";
316
+ stream?: boolean;
317
+ stream_options?: {
318
+ include_usage?: boolean;
319
+ };
320
+ store?: boolean;
321
+ metadata?: Record<string, string>;
322
+ };
323
+ type ChatUsage = {
324
+ prompt_tokens?: number;
325
+ completion_tokens?: number;
326
+ total_tokens?: number;
327
+ prompt_tokens_details?: {
328
+ cached_tokens?: number;
329
+ };
330
+ completion_tokens_details?: {
331
+ reasoning_tokens?: number;
332
+ };
333
+ };
334
+ type ChatResponse = {
335
+ id: string;
336
+ object: string;
337
+ model: string;
338
+ choices: {
339
+ index: number;
340
+ message: {
341
+ role: "assistant";
342
+ content?: string | null;
343
+ tool_calls?: ChatToolCall[];
344
+ refusal?: string | null;
345
+ /**
346
+ * Same non-standard field the streamed delta carries, and emitted by the
347
+ * same servers — LM Studio returns it on a plain POST too. Declaring it
348
+ * only on the stream chunk is why sync mode used to drop a reasoning
349
+ * model's thinking entirely.
350
+ */
351
+ reasoning_content?: string | null;
352
+ };
353
+ finish_reason: string | null;
354
+ }[];
355
+ usage?: ChatUsage;
356
+ };
357
+ type ChatStreamChunk = {
358
+ id: string;
359
+ model: string;
360
+ choices: {
361
+ index: number;
362
+ delta: {
363
+ role?: string;
364
+ content?: string | null;
365
+ tool_calls?: ChatToolCall[];
366
+ /** Non-standard but widely emitted by OpenAI-compatible routers. */
367
+ reasoning_content?: string | null;
368
+ };
369
+ finish_reason: string | null;
370
+ }[];
371
+ usage?: ChatUsage;
372
+ };
373
+
374
+ type OpenAIDialect = "responses" | "chat";
375
+ type OpenAIProviderConfig = {
376
+ transport: Transport;
377
+ /** Defaults to "responses". Use "chat" for OpenAI-compatible third parties. */
378
+ dialect?: OpenAIDialect;
379
+ /** Provider id, so several instances (openai, groq, nvidia) can coexist. */
380
+ id?: string;
381
+ label?: string;
382
+ retry?: RetryPolicy;
383
+ /** Capability overrides — a compatible endpoint may lack background/reasoning. */
384
+ capabilities?: Partial<ProviderCapabilities>;
385
+ models?: ModelInfo[];
386
+ };
387
+ declare function createOpenAIProvider(config: OpenAIProviderConfig): Provider;
388
+
389
+ declare function toResponsesInput(messages: readonly Message[], providerId?: string): ResponsesInputItem[];
390
+ /**
391
+ * Drop `function_call` items with no matching `function_call_output`.
392
+ *
393
+ * This happens for real: a turn is cancelled mid-tool, or the user reloads while
394
+ * a tool is running. Replaying that history unfixed makes OpenAI reject the
395
+ * whole request, so the thread becomes permanently unusable. Dropping the
396
+ * dangling call costs one lost step and keeps the thread alive.
397
+ */
398
+ declare function dropOrphanToolCalls(items: ResponsesInputItem[]): ResponsesInputItem[];
399
+ type BuildOptions = {
400
+ stream?: boolean;
401
+ providerId?: string;
402
+ /** Declared capability; when false the flag is omitted from the wire. */
403
+ parallelToolCalls?: boolean;
404
+ };
405
+ declare function buildResponsesRequest(req: NormalizedRequest, opts?: BuildOptions): ResponsesRequest;
406
+ declare function toChatMessages(messages: readonly Message[], system?: string, providerId?: string): ChatMessage[];
407
+ /** Same orphan problem as Responses: an assistant tool_call with no `role:"tool"` reply 400s. */
408
+ declare function dropOrphanChatToolCalls(messages: ChatMessage[]): ChatMessage[];
409
+ declare function buildChatRequest(req: NormalizedRequest, opts?: BuildOptions): ChatRequest;
410
+
411
+ export { dropOrphanChatToolCalls as A, dropOrphanToolCalls as B, type ChatResponse as C, toChatMessages as D, toResponsesInput as E, type JobStore as J, type OpenAIDialect as O, type ResumeResult as R, type StoredJob as S, type OpenAIProviderConfig as a, awaitJob as b, buildChatRequest as c, buildResponsesRequest as d, createLocalJobStore as e, createMemoryJobStore as f, createOpenAIProvider as g, resumeJobs as h, isTerminal as i, type ResponsesResponse as j, type ChatUsage as k, type ResponsesUsage as l, type ChatContentPart as m, type ChatMessage as n, type ChatRequest as o, type ChatStreamChunk as p, type ChatTool as q, reap as r, type ChatToolCall as s, type ResponsesInputContent as t, type ResponsesInputItem as u, type ResponsesOutputItem as v, type ResponsesRequest as w, type ResponsesStreamEvent as x, type ResponsesTool as y, type ResponsesToolChoice as z };
@@ -0,0 +1,52 @@
1
+ import { j as ResponsesResponse, C as ChatResponse, k as ChatUsage, l as ResponsesUsage } from './map-in-CXwWaHl2.js';
2
+ export { m as ChatContentPart, n as ChatMessage, o as ChatRequest, p as ChatStreamChunk, q as ChatTool, s as ChatToolCall, O as OpenAIDialect, a as OpenAIProviderConfig, t as ResponsesInputContent, u as ResponsesInputItem, v as ResponsesOutputItem, w as ResponsesRequest, x as ResponsesStreamEvent, y as ResponsesTool, z as ResponsesToolChoice, b as awaitJob, c as buildChatRequest, d as buildResponsesRequest, g as createOpenAIProvider, A as dropOrphanChatToolCalls, B as dropOrphanToolCalls, D as toChatMessages, E as toResponsesInput } from './map-in-CXwWaHl2.js';
3
+ import { S as StreamEvent, F as FinishReason, C as ContentPart, U as Usage, f as ModelInfo, P as ProviderCapabilities } from './types-y3SK7HwA.js';
4
+
5
+ /**
6
+ * Translate a Responses SSE body. `onCursor` receives each event's
7
+ * `sequence_number` so a caller can persist it and resume with `starting_after`
8
+ * after a dropped connection.
9
+ */
10
+ declare function streamResponses(body: ReadableStream<Uint8Array>, opts?: {
11
+ onCursor?: (seq: number) => void;
12
+ }): AsyncGenerator<StreamEvent>;
13
+ /** Translate a Chat Completions SSE body. */
14
+ declare function streamChat(body: ReadableStream<Uint8Array>): AsyncGenerator<StreamEvent>;
15
+ /**
16
+ * Read a Responses SSE body purely to recover the terminal response object.
17
+ * Used when resuming a background job's stream: the caller wants the final
18
+ * result, not the deltas it already missed.
19
+ */
20
+ declare function finalResponseFromStream(body: ReadableStream<Uint8Array>): Promise<ResponsesResponse | null>;
21
+
22
+ declare function usageFromResponses(u?: ResponsesUsage): Usage;
23
+ declare function usageFromChat(u?: ChatUsage): Usage;
24
+ /**
25
+ * Map Responses `status` + `incomplete_details` to a finish reason.
26
+ * `incomplete` is ambiguous on its own — the reason field is what distinguishes
27
+ * "hit max_output_tokens" from "tripped a content filter", and those need
28
+ * different handling upstream (retry bigger vs never retry).
29
+ */
30
+ declare function finishFromResponses(r: ResponsesResponse): FinishReason;
31
+ declare function finishFromChat(raw: string | null | undefined): FinishReason;
32
+ declare function partsFromResponses(r: ResponsesResponse): ContentPart[];
33
+ declare function partsFromChat(r: ChatResponse): ContentPart[];
34
+
35
+ declare const OPENAI_MODELS: ModelInfo[];
36
+ /**
37
+ * Per-model capability deltas that matter for request building.
38
+ *
39
+ * The one that actually bites: reasoning models reject `temperature` and
40
+ * `top_p`. `sanitizeForModel` below drops them rather than letting the request
41
+ * 400 — a sampling knob is not worth failing a turn over.
42
+ */
43
+ declare function modelCapabilities(modelId: string): Partial<ProviderCapabilities> | undefined;
44
+ declare function isReasoningModel(modelId: string): boolean;
45
+ /** Drop parameters the target model is known to reject. */
46
+ declare function sanitizeForModel<T extends {
47
+ temperature?: number;
48
+ topP?: number;
49
+ reasoning?: unknown;
50
+ }>(req: T, modelId: string): T;
51
+
52
+ export { ChatResponse, ChatUsage, OPENAI_MODELS, ResponsesResponse, ResponsesUsage, finalResponseFromStream, finishFromChat, finishFromResponses, isReasoningModel, modelCapabilities, partsFromChat, partsFromResponses, sanitizeForModel, streamChat, streamResponses, usageFromChat, usageFromResponses };
package/dist/openai.js ADDED
@@ -0,0 +1,48 @@
1
+ import {
2
+ OPENAI_MODELS,
3
+ awaitJob,
4
+ buildChatRequest,
5
+ buildResponsesRequest,
6
+ createOpenAIProvider,
7
+ dropOrphanChatToolCalls,
8
+ dropOrphanToolCalls,
9
+ finalResponseFromStream,
10
+ finishFromChat,
11
+ finishFromResponses,
12
+ isReasoningModel,
13
+ modelCapabilities,
14
+ partsFromChat,
15
+ partsFromResponses,
16
+ sanitizeForModel,
17
+ streamChat,
18
+ streamResponses,
19
+ toChatMessages,
20
+ toResponsesInput,
21
+ usageFromChat,
22
+ usageFromResponses
23
+ } from "./chunk-MHGENDQX.js";
24
+ import "./chunk-32DPF33V.js";
25
+ export {
26
+ OPENAI_MODELS,
27
+ awaitJob,
28
+ buildChatRequest,
29
+ buildResponsesRequest,
30
+ createOpenAIProvider,
31
+ dropOrphanChatToolCalls,
32
+ dropOrphanToolCalls,
33
+ finalResponseFromStream,
34
+ finishFromChat,
35
+ finishFromResponses,
36
+ isReasoningModel,
37
+ modelCapabilities,
38
+ partsFromChat,
39
+ partsFromResponses,
40
+ sanitizeForModel,
41
+ streamChat,
42
+ streamResponses,
43
+ toChatMessages,
44
+ toResponsesInput,
45
+ usageFromChat,
46
+ usageFromResponses
47
+ };
48
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}