@mariozechner/pi-ai 0.5.31 → 0.5.34
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 +275 -10
- package/dist/agent/agent.d.ts +5 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +161 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/index.d.ts +4 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +3 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/tools/calculate.d.ts +17 -0
- package/dist/agent/tools/calculate.d.ts.map +1 -0
- package/dist/agent/tools/calculate.js +23 -0
- package/dist/agent/tools/calculate.js.map +1 -0
- package/dist/agent/tools/get-current-time.d.ts +20 -0
- package/dist/agent/tools/get-current-time.d.ts.map +1 -0
- package/dist/agent/tools/get-current-time.js +36 -0
- package/dist/agent/tools/get-current-time.js.map +1 -0
- package/dist/agent/tools/index.d.ts +3 -0
- package/dist/agent/tools/index.d.ts.map +1 -0
- package/dist/agent/tools/index.js +3 -0
- package/dist/agent/tools/index.js.map +1 -0
- package/dist/agent/types.d.ts +53 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +2 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/event-stream.d.ts +19 -0
- package/dist/event-stream.d.ts.map +1 -0
- package/dist/event-stream.js +77 -0
- package/dist/event-stream.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/models.generated.d.ts +129 -10
- package/dist/models.generated.d.ts.map +1 -1
- package/dist/models.generated.js +234 -115
- package/dist/models.generated.js.map +1 -1
- package/dist/providers/anthropic.d.ts +3 -3
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +108 -56
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/google.d.ts +3 -3
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/google.js +56 -13
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/openai-completions.d.ts +3 -3
- package/dist/providers/openai-completions.d.ts.map +1 -1
- package/dist/providers/openai-completions.js +92 -150
- package/dist/providers/openai-completions.js.map +1 -1
- package/dist/providers/openai-responses.d.ts +3 -3
- package/dist/providers/openai-responses.d.ts.map +1 -1
- package/dist/providers/openai-responses.js +59 -9
- package/dist/providers/openai-responses.js.map +1 -1
- package/dist/providers/{utils.d.ts → transorm-messages.d.ts} +1 -1
- package/dist/providers/transorm-messages.d.ts.map +1 -0
- package/dist/providers/{utils.js → transorm-messages.js} +1 -1
- package/dist/providers/transorm-messages.js.map +1 -0
- package/dist/stream.d.ts +10 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/{generate.js → stream.js} +3 -65
- package/dist/stream.js.map +1 -0
- package/dist/types.d.ts +28 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/validation.d.ts +10 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +30 -0
- package/dist/validation.js.map +1 -0
- package/package.json +7 -5
- package/dist/generate.d.ts +0 -22
- package/dist/generate.d.ts.map +0 -1
- package/dist/generate.js.map +0 -1
- package/dist/providers/utils.d.ts.map +0 -1
- package/dist/providers/utils.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export interface OpenAIResponsesOptions extends
|
|
1
|
+
import type { StreamFunction, StreamOptions } from "../types.js";
|
|
2
|
+
export interface OpenAIResponsesOptions extends StreamOptions {
|
|
3
3
|
reasoningEffort?: "minimal" | "low" | "medium" | "high";
|
|
4
4
|
reasoningSummary?: "auto" | "detailed" | "concise" | null;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Generate function for OpenAI Responses API
|
|
8
8
|
*/
|
|
9
|
-
export declare const streamOpenAIResponses:
|
|
9
|
+
export declare const streamOpenAIResponses: StreamFunction<"openai-responses">;
|
|
10
10
|
//# sourceMappingURL=openai-responses.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-responses.d.ts","sourceRoot":"","sources":["../../src/providers/openai-responses.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai-responses.d.ts","sourceRoot":"","sources":["../../src/providers/openai-responses.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAMX,cAAc,EACd,aAAa,EAKb,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,sBAAuB,SAAQ,aAAa;IAC5D,eAAe,CAAC,EAAE,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACxD,gBAAgB,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,IAAI,CAAC;CAC1D;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,cAAc,CAAC,kBAAkB,CAwQpE,CAAC"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import OpenAI from "openai";
|
|
2
|
-
import {
|
|
2
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
|
+
import { AssistantMessageEventStream } from "../event-stream.js";
|
|
3
4
|
import { calculateCost } from "../models.js";
|
|
4
|
-
import {
|
|
5
|
+
import { validateToolArguments } from "../validation.js";
|
|
6
|
+
import { transformMessages } from "./transorm-messages.js";
|
|
5
7
|
/**
|
|
6
8
|
* Generate function for OpenAI Responses API
|
|
7
9
|
*/
|
|
8
10
|
export const streamOpenAIResponses = (model, context, options) => {
|
|
9
|
-
const stream = new
|
|
11
|
+
const stream = new AssistantMessageEventStream();
|
|
10
12
|
// Start async processing
|
|
11
13
|
(async () => {
|
|
12
14
|
const output = {
|
|
@@ -32,6 +34,8 @@ export const streamOpenAIResponses = (model, context, options) => {
|
|
|
32
34
|
stream.push({ type: "start", partial: output });
|
|
33
35
|
let currentItem = null;
|
|
34
36
|
let currentBlock = null;
|
|
37
|
+
const blocks = output.content;
|
|
38
|
+
const blockIndex = () => blocks.length - 1;
|
|
35
39
|
for await (const event of openaiStream) {
|
|
36
40
|
// Handle output item start
|
|
37
41
|
if (event.type === "response.output_item.added") {
|
|
@@ -40,13 +44,25 @@ export const streamOpenAIResponses = (model, context, options) => {
|
|
|
40
44
|
currentItem = item;
|
|
41
45
|
currentBlock = { type: "thinking", thinking: "" };
|
|
42
46
|
output.content.push(currentBlock);
|
|
43
|
-
stream.push({ type: "thinking_start", partial: output });
|
|
47
|
+
stream.push({ type: "thinking_start", contentIndex: blockIndex(), partial: output });
|
|
44
48
|
}
|
|
45
49
|
else if (item.type === "message") {
|
|
46
50
|
currentItem = item;
|
|
47
51
|
currentBlock = { type: "text", text: "" };
|
|
48
52
|
output.content.push(currentBlock);
|
|
49
|
-
stream.push({ type: "text_start", partial: output });
|
|
53
|
+
stream.push({ type: "text_start", contentIndex: blockIndex(), partial: output });
|
|
54
|
+
}
|
|
55
|
+
else if (item.type === "function_call") {
|
|
56
|
+
currentItem = item;
|
|
57
|
+
currentBlock = {
|
|
58
|
+
type: "toolCall",
|
|
59
|
+
id: item.call_id + "|" + item.id,
|
|
60
|
+
name: item.name,
|
|
61
|
+
arguments: {},
|
|
62
|
+
partialJson: item.arguments || "",
|
|
63
|
+
};
|
|
64
|
+
output.content.push(currentBlock);
|
|
65
|
+
stream.push({ type: "toolcall_start", contentIndex: blockIndex(), partial: output });
|
|
50
66
|
}
|
|
51
67
|
}
|
|
52
68
|
// Handle reasoning summary deltas
|
|
@@ -68,6 +84,7 @@ export const streamOpenAIResponses = (model, context, options) => {
|
|
|
68
84
|
lastPart.text += event.delta;
|
|
69
85
|
stream.push({
|
|
70
86
|
type: "thinking_delta",
|
|
87
|
+
contentIndex: blockIndex(),
|
|
71
88
|
delta: event.delta,
|
|
72
89
|
partial: output,
|
|
73
90
|
});
|
|
@@ -87,6 +104,7 @@ export const streamOpenAIResponses = (model, context, options) => {
|
|
|
87
104
|
lastPart.text += "\n\n";
|
|
88
105
|
stream.push({
|
|
89
106
|
type: "thinking_delta",
|
|
107
|
+
contentIndex: blockIndex(),
|
|
90
108
|
delta: "\n\n",
|
|
91
109
|
partial: output,
|
|
92
110
|
});
|
|
@@ -108,6 +126,7 @@ export const streamOpenAIResponses = (model, context, options) => {
|
|
|
108
126
|
lastPart.text += event.delta;
|
|
109
127
|
stream.push({
|
|
110
128
|
type: "text_delta",
|
|
129
|
+
contentIndex: blockIndex(),
|
|
111
130
|
delta: event.delta,
|
|
112
131
|
partial: output,
|
|
113
132
|
});
|
|
@@ -122,12 +141,35 @@ export const streamOpenAIResponses = (model, context, options) => {
|
|
|
122
141
|
lastPart.refusal += event.delta;
|
|
123
142
|
stream.push({
|
|
124
143
|
type: "text_delta",
|
|
144
|
+
contentIndex: blockIndex(),
|
|
125
145
|
delta: event.delta,
|
|
126
146
|
partial: output,
|
|
127
147
|
});
|
|
128
148
|
}
|
|
129
149
|
}
|
|
130
150
|
}
|
|
151
|
+
// Handle function call argument deltas
|
|
152
|
+
else if (event.type === "response.function_call_arguments.delta") {
|
|
153
|
+
if (currentItem &&
|
|
154
|
+
currentItem.type === "function_call" &&
|
|
155
|
+
currentBlock &&
|
|
156
|
+
currentBlock.type === "toolCall") {
|
|
157
|
+
currentBlock.partialJson += event.delta;
|
|
158
|
+
try {
|
|
159
|
+
const args = JSON.parse(currentBlock.partialJson);
|
|
160
|
+
currentBlock.arguments = args;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// Ignore JSON parse errors - the JSON might be incomplete
|
|
164
|
+
}
|
|
165
|
+
stream.push({
|
|
166
|
+
type: "toolcall_delta",
|
|
167
|
+
contentIndex: blockIndex(),
|
|
168
|
+
delta: event.delta,
|
|
169
|
+
partial: output,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
131
173
|
// Handle output item completion
|
|
132
174
|
else if (event.type === "response.output_item.done") {
|
|
133
175
|
const item = event.item;
|
|
@@ -136,6 +178,7 @@ export const streamOpenAIResponses = (model, context, options) => {
|
|
|
136
178
|
currentBlock.thinkingSignature = JSON.stringify(item);
|
|
137
179
|
stream.push({
|
|
138
180
|
type: "thinking_end",
|
|
181
|
+
contentIndex: blockIndex(),
|
|
139
182
|
content: currentBlock.thinking,
|
|
140
183
|
partial: output,
|
|
141
184
|
});
|
|
@@ -146,6 +189,7 @@ export const streamOpenAIResponses = (model, context, options) => {
|
|
|
146
189
|
currentBlock.textSignature = item.id;
|
|
147
190
|
stream.push({
|
|
148
191
|
type: "text_end",
|
|
192
|
+
contentIndex: blockIndex(),
|
|
149
193
|
content: currentBlock.text,
|
|
150
194
|
partial: output,
|
|
151
195
|
});
|
|
@@ -158,8 +202,14 @@ export const streamOpenAIResponses = (model, context, options) => {
|
|
|
158
202
|
name: item.name,
|
|
159
203
|
arguments: JSON.parse(item.arguments),
|
|
160
204
|
};
|
|
161
|
-
|
|
162
|
-
|
|
205
|
+
// Validate tool arguments if tool definition is available
|
|
206
|
+
if (context.tools) {
|
|
207
|
+
const tool = context.tools.find((t) => t.name === toolCall.name);
|
|
208
|
+
if (tool) {
|
|
209
|
+
toolCall.arguments = validateToolArguments(tool, toolCall);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
stream.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });
|
|
163
213
|
}
|
|
164
214
|
}
|
|
165
215
|
// Handle completion
|
|
@@ -351,7 +401,7 @@ function convertMessages(model, context) {
|
|
|
351
401
|
messages.push({
|
|
352
402
|
type: "function_call_output",
|
|
353
403
|
call_id: msg.toolCallId.split("|")[0],
|
|
354
|
-
output: msg.
|
|
404
|
+
output: msg.output,
|
|
355
405
|
});
|
|
356
406
|
}
|
|
357
407
|
}
|
|
@@ -362,7 +412,7 @@ function convertTools(tools) {
|
|
|
362
412
|
type: "function",
|
|
363
413
|
name: tool.name,
|
|
364
414
|
description: tool.description,
|
|
365
|
-
parameters: tool.parameters,
|
|
415
|
+
parameters: zodToJsonSchema(tool.parameters, { $refStrategy: "none" }),
|
|
366
416
|
strict: null,
|
|
367
417
|
}));
|
|
368
418
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-responses.js","sourceRoot":"","sources":["../../src/providers/openai-responses.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAY5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAe7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAQ/C;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAyC,CAC1E,KAAgC,EAChC,OAAgB,EAChB,OAAgC,EACf,EAAE;IACnB,MAAM,MAAM,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAE1C,yBAAyB;IACzB,CAAC,KAAK,IAAI,EAAE;QACX,MAAM,MAAM,GAAqB;YAChC,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,EAAE;YACX,GAAG,EAAE,kBAAyB;YAC9B,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,KAAK,EAAE,KAAK,CAAC,EAAE;YACf,KAAK,EAAE;gBACN,KAAK,EAAE,CAAC;gBACR,MAAM,EAAE,CAAC;gBACT,SAAS,EAAE,CAAC;gBACZ,UAAU,EAAE,CAAC;gBACb,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;aACpE;YACD,UAAU,EAAE,MAAM;SAClB,CAAC;QAEF,IAAI,CAAC;YACJ,uBAAuB;YACvB,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;YACpD,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YACpD,MAAM,YA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,0BAA0B,WAAW,EAAE,CAAC,CAAC;QAC1D,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import OpenAI from \"openai\";\nimport type {\n\tTool as OpenAITool,\n\tResponseCreateParamsStreaming,\n\tResponseFunctionToolCall,\n\tResponseInput,\n\tResponseInputContent,\n\tResponseInputImage,\n\tResponseInputText,\n\tResponseOutputMessage,\n\tResponseReasoningItem,\n} from \"openai/resources/responses/responses.js\";\nimport { QueuedGenerateStream } from \"../generate.js\";\nimport { calculateCost } from \"../models.js\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tGenerateFunction,\n\tGenerateOptions,\n\tGenerateStream,\n\tModel,\n\tStopReason,\n\tTextContent,\n\tThinkingContent,\n\tTool,\n\tToolCall,\n} from \"../types.js\";\nimport { transformMessages } from \"./utils.js\";\n\n// OpenAI Responses-specific options\nexport interface OpenAIResponsesOptions extends GenerateOptions {\n\treasoningEffort?: \"minimal\" | \"low\" | \"medium\" | \"high\";\n\treasoningSummary?: \"auto\" | \"detailed\" | \"concise\" | null;\n}\n\n/**\n * Generate function for OpenAI Responses API\n */\nexport const streamOpenAIResponses: GenerateFunction<\"openai-responses\"> = (\n\tmodel: Model<\"openai-responses\">,\n\tcontext: Context,\n\toptions?: OpenAIResponsesOptions,\n): GenerateStream => {\n\tconst stream = new QueuedGenerateStream();\n\n\t// Start async processing\n\t(async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"openai-responses\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t};\n\n\t\ttry {\n\t\t\t// Create OpenAI client\n\t\t\tconst client = createClient(model, options?.apiKey);\n\t\t\tconst params = buildParams(model, context, options);\n\t\t\tconst openaiStream = await client.responses.create(params, { signal: options?.signal });\n\t\t\tstream.push({ type: \"start\", partial: output });\n\n\t\t\tlet currentItem: ResponseReasoningItem | ResponseOutputMessage | ResponseFunctionToolCall | null = null;\n\t\t\tlet currentBlock: ThinkingContent | TextContent | ToolCall | null = null;\n\n\t\t\tfor await (const event of openaiStream) {\n\t\t\t\t// Handle output item start\n\t\t\t\tif (event.type === \"response.output_item.added\") {\n\t\t\t\t\tconst item = event.item;\n\t\t\t\t\tif (item.type === \"reasoning\") {\n\t\t\t\t\t\tcurrentItem = item;\n\t\t\t\t\t\tcurrentBlock = { type: \"thinking\", thinking: \"\" };\n\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", partial: output });\n\t\t\t\t\t} else if (item.type === \"message\") {\n\t\t\t\t\t\tcurrentItem = item;\n\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\tstream.push({ type: \"text_start\", partial: output });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Handle reasoning summary deltas\n\t\t\t\telse if (event.type === \"response.reasoning_summary_part.added\") {\n\t\t\t\t\tif (currentItem && currentItem.type === \"reasoning\") {\n\t\t\t\t\t\tcurrentItem.summary = currentItem.summary || [];\n\t\t\t\t\t\tcurrentItem.summary.push(event.part);\n\t\t\t\t\t}\n\t\t\t\t} else if (event.type === \"response.reasoning_summary_text.delta\") {\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrentItem &&\n\t\t\t\t\t\tcurrentItem.type === \"reasoning\" &&\n\t\t\t\t\t\tcurrentBlock &&\n\t\t\t\t\t\tcurrentBlock.type === \"thinking\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tcurrentItem.summary = currentItem.summary || [];\n\t\t\t\t\t\tconst lastPart = currentItem.summary[currentItem.summary.length - 1];\n\t\t\t\t\t\tif (lastPart) {\n\t\t\t\t\t\t\tcurrentBlock.thinking += event.delta;\n\t\t\t\t\t\t\tlastPart.text += event.delta;\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\tdelta: event.delta,\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Add a new line between summary parts (hack...)\n\t\t\t\telse if (event.type === \"response.reasoning_summary_part.done\") {\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrentItem &&\n\t\t\t\t\t\tcurrentItem.type === \"reasoning\" &&\n\t\t\t\t\t\tcurrentBlock &&\n\t\t\t\t\t\tcurrentBlock.type === \"thinking\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tcurrentItem.summary = currentItem.summary || [];\n\t\t\t\t\t\tconst lastPart = currentItem.summary[currentItem.summary.length - 1];\n\t\t\t\t\t\tif (lastPart) {\n\t\t\t\t\t\t\tcurrentBlock.thinking += \"\\n\\n\";\n\t\t\t\t\t\t\tlastPart.text += \"\\n\\n\";\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\tdelta: \"\\n\\n\",\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Handle text output deltas\n\t\t\t\telse if (event.type === \"response.content_part.added\") {\n\t\t\t\t\tif (currentItem && currentItem.type === \"message\") {\n\t\t\t\t\t\tcurrentItem.content = currentItem.content || [];\n\t\t\t\t\t\tcurrentItem.content.push(event.part);\n\t\t\t\t\t}\n\t\t\t\t} else if (event.type === \"response.output_text.delta\") {\n\t\t\t\t\tif (currentItem && currentItem.type === \"message\" && currentBlock && currentBlock.type === \"text\") {\n\t\t\t\t\t\tconst lastPart = currentItem.content[currentItem.content.length - 1];\n\t\t\t\t\t\tif (lastPart && lastPart.type === \"output_text\") {\n\t\t\t\t\t\t\tcurrentBlock.text += event.delta;\n\t\t\t\t\t\t\tlastPart.text += event.delta;\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\tdelta: event.delta,\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (event.type === \"response.refusal.delta\") {\n\t\t\t\t\tif (currentItem && currentItem.type === \"message\" && currentBlock && currentBlock.type === \"text\") {\n\t\t\t\t\t\tconst lastPart = currentItem.content[currentItem.content.length - 1];\n\t\t\t\t\t\tif (lastPart && lastPart.type === \"refusal\") {\n\t\t\t\t\t\t\tcurrentBlock.text += event.delta;\n\t\t\t\t\t\t\tlastPart.refusal += event.delta;\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\tdelta: event.delta,\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Handle output item completion\n\t\t\t\telse if (event.type === \"response.output_item.done\") {\n\t\t\t\t\tconst item = event.item;\n\n\t\t\t\t\tif (item.type === \"reasoning\" && currentBlock && currentBlock.type === \"thinking\") {\n\t\t\t\t\t\tcurrentBlock.thinking = item.summary?.map((s) => s.text).join(\"\\n\\n\") || \"\";\n\t\t\t\t\t\tcurrentBlock.thinkingSignature = JSON.stringify(item);\n\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcurrentBlock = null;\n\t\t\t\t\t} else if (item.type === \"message\" && currentBlock && currentBlock.type === \"text\") {\n\t\t\t\t\t\tcurrentBlock.text = item.content.map((c) => (c.type === \"output_text\" ? c.text : c.refusal)).join(\"\");\n\t\t\t\t\t\tcurrentBlock.textSignature = item.id;\n\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcurrentBlock = null;\n\t\t\t\t\t} else if (item.type === \"function_call\") {\n\t\t\t\t\t\tconst toolCall: ToolCall = {\n\t\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\t\tid: item.call_id + \"|\" + item.id,\n\t\t\t\t\t\t\tname: item.name,\n\t\t\t\t\t\t\targuments: JSON.parse(item.arguments),\n\t\t\t\t\t\t};\n\t\t\t\t\t\toutput.content.push(toolCall);\n\t\t\t\t\t\tstream.push({ type: \"toolCall\", toolCall, partial: output });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Handle completion\n\t\t\t\telse if (event.type === \"response.completed\") {\n\t\t\t\t\tconst response = event.response;\n\t\t\t\t\tif (response?.usage) {\n\t\t\t\t\t\toutput.usage = {\n\t\t\t\t\t\t\tinput: response.usage.input_tokens || 0,\n\t\t\t\t\t\t\toutput: response.usage.output_tokens || 0,\n\t\t\t\t\t\t\tcacheRead: response.usage.input_tokens_details?.cached_tokens || 0,\n\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tcalculateCost(model, output.usage);\n\t\t\t\t\t// Map status to stop reason\n\t\t\t\t\toutput.stopReason = mapStopReason(response?.status);\n\t\t\t\t\tif (output.content.some((b) => b.type === \"toolCall\") && output.stopReason === \"stop\") {\n\t\t\t\t\t\toutput.stopReason = \"toolUse\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Handle errors\n\t\t\t\telse if (event.type === \"error\") {\n\t\t\t\t\toutput.stopReason = \"error\";\n\t\t\t\t\toutput.error = `Code ${event.code}: ${event.message}` || \"Unknown error\";\n\t\t\t\t\tstream.push({ type: \"error\", error: output.error, partial: output });\n\t\t\t\t\tstream.end();\n\t\t\t\t\treturn output;\n\t\t\t\t} else if (event.type === \"response.failed\") {\n\t\t\t\t\toutput.stopReason = \"error\";\n\t\t\t\t\toutput.error = \"Unknown error\";\n\t\t\t\t\tstream.push({ type: \"error\", error: output.error, partial: output });\n\t\t\t\t\tstream.end();\n\t\t\t\t\treturn output;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\toutput.stopReason = \"error\";\n\t\t\toutput.error = error instanceof Error ? error.message : JSON.stringify(error);\n\t\t\tstream.push({ type: \"error\", error: output.error, partial: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nfunction createClient(model: Model<\"openai-responses\">, apiKey?: string) {\n\tif (!apiKey) {\n\t\tif (!process.env.OPENAI_API_KEY) {\n\t\t\tthrow new Error(\n\t\t\t\t\"OpenAI API key is required. Set OPENAI_API_KEY environment variable or pass it as an argument.\",\n\t\t\t);\n\t\t}\n\t\tapiKey = process.env.OPENAI_API_KEY;\n\t}\n\treturn new OpenAI({ apiKey, baseURL: model.baseUrl, dangerouslyAllowBrowser: true });\n}\n\nfunction buildParams(model: Model<\"openai-responses\">, context: Context, options?: OpenAIResponsesOptions) {\n\tconst messages = convertMessages(model, context);\n\n\tconst params: ResponseCreateParamsStreaming = {\n\t\tmodel: model.id,\n\t\tinput: messages,\n\t\tstream: true,\n\t};\n\n\tif (options?.maxTokens) {\n\t\tparams.max_output_tokens = options?.maxTokens;\n\t}\n\n\tif (options?.temperature !== undefined) {\n\t\tparams.temperature = options?.temperature;\n\t}\n\n\tif (context.tools) {\n\t\tparams.tools = convertTools(context.tools);\n\t}\n\n\tif (model.reasoning) {\n\t\tif (options?.reasoningEffort || options?.reasoningSummary) {\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: options?.reasoningEffort || \"medium\",\n\t\t\t\tsummary: options?.reasoningSummary || \"auto\",\n\t\t\t};\n\t\t\tparams.include = [\"reasoning.encrypted_content\"];\n\t\t} else {\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: model.name.startsWith(\"gpt-5\") ? \"minimal\" : null,\n\t\t\t\tsummary: null,\n\t\t\t};\n\n\t\t\tif (model.name.startsWith(\"gpt-5\")) {\n\t\t\t\t// Jesus Christ, see https://community.openai.com/t/need-reasoning-false-option-for-gpt-5/1351588/7\n\t\t\t\tmessages.push({\n\t\t\t\t\trole: \"developer\",\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"input_text\",\n\t\t\t\t\t\t\ttext: \"# Juice: 0 !important\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn params;\n}\n\nfunction convertMessages(model: Model<\"openai-responses\">, context: Context): ResponseInput {\n\tconst messages: ResponseInput = [];\n\n\tconst transformedMessages = transformMessages(context.messages, model);\n\n\tif (context.systemPrompt) {\n\t\tconst role = model.reasoning ? \"developer\" : \"system\";\n\t\tmessages.push({\n\t\t\trole,\n\t\t\tcontent: context.systemPrompt,\n\t\t});\n\t}\n\n\tfor (const msg of transformedMessages) {\n\t\tif (msg.role === \"user\") {\n\t\t\tif (typeof msg.content === \"string\") {\n\t\t\t\tmessages.push({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [{ type: \"input_text\", text: msg.content }],\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst content: ResponseInputContent[] = msg.content.map((item): ResponseInputContent => {\n\t\t\t\t\tif (item.type === \"text\") {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttype: \"input_text\",\n\t\t\t\t\t\t\ttext: item.text,\n\t\t\t\t\t\t} satisfies ResponseInputText;\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttype: \"input_image\",\n\t\t\t\t\t\t\tdetail: \"auto\",\n\t\t\t\t\t\t\timage_url: `data:${item.mimeType};base64,${item.data}`,\n\t\t\t\t\t\t} satisfies ResponseInputImage;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tconst filteredContent = !model.input.includes(\"image\")\n\t\t\t\t\t? content.filter((c) => c.type !== \"input_image\")\n\t\t\t\t\t: content;\n\t\t\t\tif (filteredContent.length === 0) continue;\n\t\t\t\tmessages.push({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: filteredContent,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (msg.role === \"assistant\") {\n\t\t\tconst output: ResponseInput = [];\n\n\t\t\tfor (const block of msg.content) {\n\t\t\t\t// Do not submit thinking blocks if the completion had an error (i.e. abort)\n\t\t\t\tif (block.type === \"thinking\" && msg.stopReason !== \"error\") {\n\t\t\t\t\tif (block.thinkingSignature) {\n\t\t\t\t\t\tconst reasoningItem = JSON.parse(block.thinkingSignature);\n\t\t\t\t\t\toutput.push(reasoningItem);\n\t\t\t\t\t}\n\t\t\t\t} else if (block.type === \"text\") {\n\t\t\t\t\tconst textBlock = block as TextContent;\n\t\t\t\t\toutput.push({\n\t\t\t\t\t\ttype: \"message\",\n\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\tcontent: [{ type: \"output_text\", text: textBlock.text, annotations: [] }],\n\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\tid: textBlock.textSignature || \"msg_\" + Math.random().toString(36).substring(2, 15),\n\t\t\t\t\t} satisfies ResponseOutputMessage);\n\t\t\t\t\t// Do not submit toolcall blocks if the completion had an error (i.e. abort)\n\t\t\t\t} else if (block.type === \"toolCall\" && msg.stopReason !== \"error\") {\n\t\t\t\t\tconst toolCall = block as ToolCall;\n\t\t\t\t\toutput.push({\n\t\t\t\t\t\ttype: \"function_call\",\n\t\t\t\t\t\tid: toolCall.id.split(\"|\")[1],\n\t\t\t\t\t\tcall_id: toolCall.id.split(\"|\")[0],\n\t\t\t\t\t\tname: toolCall.name,\n\t\t\t\t\t\targuments: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (output.length === 0) continue;\n\t\t\tmessages.push(...output);\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\tmessages.push({\n\t\t\t\ttype: \"function_call_output\",\n\t\t\t\tcall_id: msg.toolCallId.split(\"|\")[0],\n\t\t\t\toutput: msg.content,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn messages;\n}\n\nfunction convertTools(tools: Tool[]): OpenAITool[] {\n\treturn tools.map((tool) => ({\n\t\ttype: \"function\",\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters,\n\t\tstrict: null,\n\t}));\n}\n\nfunction mapStopReason(status: OpenAI.Responses.ResponseStatus | undefined): StopReason {\n\tif (!status) return \"stop\";\n\tswitch (status) {\n\t\tcase \"completed\":\n\t\t\treturn \"stop\";\n\t\tcase \"incomplete\":\n\t\t\treturn \"length\";\n\t\tcase \"failed\":\n\t\tcase \"cancelled\":\n\t\t\treturn \"error\";\n\t\t// These two are wonky ...\n\t\tcase \"in_progress\":\n\t\tcase \"queued\":\n\t\t\treturn \"stop\";\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = status;\n\t\t\tthrow new Error(`Unhandled stop reason: ${_exhaustive}`);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"openai-responses.js","sourceRoot":"","sources":["../../src/providers/openai-responses.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAY5B,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C7B,UAAU,EAAE,eAAe,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;QACtE,MAAM,EAAE,IAAI;KACZ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,MAAmD;IACzE,IAAI,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC;IAC3B,QAAQ,MAAM,EAAE,CAAC;QAChB,KAAK,WAAW;YACf,OAAO,MAAM,CAAC;QACf,KAAK,YAAY;YAChB,OAAO,QAAQ,CAAC;QACjB,KAAK,QAAQ,CAAC;QACd,KAAK,WAAW;YACf,OAAO,OAAO,CAAC;QAChB,0BAA0B;QAC1B,KAAK,aAAa,CAAC;QACnB,KAAK,QAAQ;YACZ,OAAO,MAAM,CAAC;QACf,OAAO,CAAC,CAAC,CAAC;YACT,MAAM,WAAW,GAAU,MAAM,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,0BAA0B,WAAW,EAAE,CAAC,CAAC;QAC1D,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import OpenAI from \"openai\";\nimport type {\n\tTool as OpenAITool,\n\tResponseCreateParamsStreaming,\n\tResponseFunctionToolCall,\n\tResponseInput,\n\tResponseInputContent,\n\tResponseInputImage,\n\tResponseInputText,\n\tResponseOutputMessage,\n\tResponseReasoningItem,\n} from \"openai/resources/responses/responses.js\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { AssistantMessageEventStream } from \"../event-stream.js\";\nimport { calculateCost } from \"../models.js\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tContext,\n\tModel,\n\tStopReason,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingContent,\n\tTool,\n\tToolCall,\n} from \"../types.js\";\nimport { validateToolArguments } from \"../validation.js\";\nimport { transformMessages } from \"./transorm-messages.js\";\n\n// OpenAI Responses-specific options\nexport interface OpenAIResponsesOptions extends StreamOptions {\n\treasoningEffort?: \"minimal\" | \"low\" | \"medium\" | \"high\";\n\treasoningSummary?: \"auto\" | \"detailed\" | \"concise\" | null;\n}\n\n/**\n * Generate function for OpenAI Responses API\n */\nexport const streamOpenAIResponses: StreamFunction<\"openai-responses\"> = (\n\tmodel: Model<\"openai-responses\">,\n\tcontext: Context,\n\toptions?: OpenAIResponsesOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t// Start async processing\n\t(async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"openai-responses\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t};\n\n\t\ttry {\n\t\t\t// Create OpenAI client\n\t\t\tconst client = createClient(model, options?.apiKey);\n\t\t\tconst params = buildParams(model, context, options);\n\t\t\tconst openaiStream = await client.responses.create(params, { signal: options?.signal });\n\t\t\tstream.push({ type: \"start\", partial: output });\n\n\t\t\tlet currentItem: ResponseReasoningItem | ResponseOutputMessage | ResponseFunctionToolCall | null = null;\n\t\t\tlet currentBlock: ThinkingContent | TextContent | (ToolCall & { partialJson: string }) | null = null;\n\t\t\tconst blocks = output.content;\n\t\t\tconst blockIndex = () => blocks.length - 1;\n\n\t\t\tfor await (const event of openaiStream) {\n\t\t\t\t// Handle output item start\n\t\t\t\tif (event.type === \"response.output_item.added\") {\n\t\t\t\t\tconst item = event.item;\n\t\t\t\t\tif (item.type === \"reasoning\") {\n\t\t\t\t\t\tcurrentItem = item;\n\t\t\t\t\t\tcurrentBlock = { type: \"thinking\", thinking: \"\" };\n\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t} else if (item.type === \"message\") {\n\t\t\t\t\t\tcurrentItem = item;\n\t\t\t\t\t\tcurrentBlock = { type: \"text\", text: \"\" };\n\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t} else if (item.type === \"function_call\") {\n\t\t\t\t\t\tcurrentItem = item;\n\t\t\t\t\t\tcurrentBlock = {\n\t\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\t\tid: item.call_id + \"|\" + item.id,\n\t\t\t\t\t\t\tname: item.name,\n\t\t\t\t\t\t\targuments: {},\n\t\t\t\t\t\t\tpartialJson: item.arguments || \"\",\n\t\t\t\t\t\t};\n\t\t\t\t\t\toutput.content.push(currentBlock);\n\t\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: blockIndex(), partial: output });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Handle reasoning summary deltas\n\t\t\t\telse if (event.type === \"response.reasoning_summary_part.added\") {\n\t\t\t\t\tif (currentItem && currentItem.type === \"reasoning\") {\n\t\t\t\t\t\tcurrentItem.summary = currentItem.summary || [];\n\t\t\t\t\t\tcurrentItem.summary.push(event.part);\n\t\t\t\t\t}\n\t\t\t\t} else if (event.type === \"response.reasoning_summary_text.delta\") {\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrentItem &&\n\t\t\t\t\t\tcurrentItem.type === \"reasoning\" &&\n\t\t\t\t\t\tcurrentBlock &&\n\t\t\t\t\t\tcurrentBlock.type === \"thinking\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tcurrentItem.summary = currentItem.summary || [];\n\t\t\t\t\t\tconst lastPart = currentItem.summary[currentItem.summary.length - 1];\n\t\t\t\t\t\tif (lastPart) {\n\t\t\t\t\t\t\tcurrentBlock.thinking += event.delta;\n\t\t\t\t\t\t\tlastPart.text += event.delta;\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\tdelta: event.delta,\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Add a new line between summary parts (hack...)\n\t\t\t\telse if (event.type === \"response.reasoning_summary_part.done\") {\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrentItem &&\n\t\t\t\t\t\tcurrentItem.type === \"reasoning\" &&\n\t\t\t\t\t\tcurrentBlock &&\n\t\t\t\t\t\tcurrentBlock.type === \"thinking\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tcurrentItem.summary = currentItem.summary || [];\n\t\t\t\t\t\tconst lastPart = currentItem.summary[currentItem.summary.length - 1];\n\t\t\t\t\t\tif (lastPart) {\n\t\t\t\t\t\t\tcurrentBlock.thinking += \"\\n\\n\";\n\t\t\t\t\t\t\tlastPart.text += \"\\n\\n\";\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\tdelta: \"\\n\\n\",\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Handle text output deltas\n\t\t\t\telse if (event.type === \"response.content_part.added\") {\n\t\t\t\t\tif (currentItem && currentItem.type === \"message\") {\n\t\t\t\t\t\tcurrentItem.content = currentItem.content || [];\n\t\t\t\t\t\tcurrentItem.content.push(event.part);\n\t\t\t\t\t}\n\t\t\t\t} else if (event.type === \"response.output_text.delta\") {\n\t\t\t\t\tif (currentItem && currentItem.type === \"message\" && currentBlock && currentBlock.type === \"text\") {\n\t\t\t\t\t\tconst lastPart = currentItem.content[currentItem.content.length - 1];\n\t\t\t\t\t\tif (lastPart && lastPart.type === \"output_text\") {\n\t\t\t\t\t\t\tcurrentBlock.text += event.delta;\n\t\t\t\t\t\t\tlastPart.text += event.delta;\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\tdelta: event.delta,\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (event.type === \"response.refusal.delta\") {\n\t\t\t\t\tif (currentItem && currentItem.type === \"message\" && currentBlock && currentBlock.type === \"text\") {\n\t\t\t\t\t\tconst lastPart = currentItem.content[currentItem.content.length - 1];\n\t\t\t\t\t\tif (lastPart && lastPart.type === \"refusal\") {\n\t\t\t\t\t\t\tcurrentBlock.text += event.delta;\n\t\t\t\t\t\t\tlastPart.refusal += event.delta;\n\t\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\t\tdelta: event.delta,\n\t\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Handle function call argument deltas\n\t\t\t\telse if (event.type === \"response.function_call_arguments.delta\") {\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrentItem &&\n\t\t\t\t\t\tcurrentItem.type === \"function_call\" &&\n\t\t\t\t\t\tcurrentBlock &&\n\t\t\t\t\t\tcurrentBlock.type === \"toolCall\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tcurrentBlock.partialJson += event.delta;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst args = JSON.parse(currentBlock.partialJson);\n\t\t\t\t\t\t\tcurrentBlock.arguments = args;\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// Ignore JSON parse errors - the JSON might be incomplete\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\tdelta: event.delta,\n\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Handle output item completion\n\t\t\t\telse if (event.type === \"response.output_item.done\") {\n\t\t\t\t\tconst item = event.item;\n\n\t\t\t\t\tif (item.type === \"reasoning\" && currentBlock && currentBlock.type === \"thinking\") {\n\t\t\t\t\t\tcurrentBlock.thinking = item.summary?.map((s) => s.text).join(\"\\n\\n\") || \"\";\n\t\t\t\t\t\tcurrentBlock.thinkingSignature = JSON.stringify(item);\n\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\tcontent: currentBlock.thinking,\n\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcurrentBlock = null;\n\t\t\t\t\t} else if (item.type === \"message\" && currentBlock && currentBlock.type === \"text\") {\n\t\t\t\t\t\tcurrentBlock.text = item.content.map((c) => (c.type === \"output_text\" ? c.text : c.refusal)).join(\"\");\n\t\t\t\t\t\tcurrentBlock.textSignature = item.id;\n\t\t\t\t\t\tstream.push({\n\t\t\t\t\t\t\ttype: \"text_end\",\n\t\t\t\t\t\t\tcontentIndex: blockIndex(),\n\t\t\t\t\t\t\tcontent: currentBlock.text,\n\t\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcurrentBlock = null;\n\t\t\t\t\t} else if (item.type === \"function_call\") {\n\t\t\t\t\t\tconst toolCall: ToolCall = {\n\t\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\t\tid: item.call_id + \"|\" + item.id,\n\t\t\t\t\t\t\tname: item.name,\n\t\t\t\t\t\t\targuments: JSON.parse(item.arguments),\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t// Validate tool arguments if tool definition is available\n\t\t\t\t\t\tif (context.tools) {\n\t\t\t\t\t\t\tconst tool = context.tools.find((t) => t.name === toolCall.name);\n\t\t\t\t\t\t\tif (tool) {\n\t\t\t\t\t\t\t\ttoolCall.arguments = validateToolArguments(tool, toolCall);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tstream.push({ type: \"toolcall_end\", contentIndex: blockIndex(), toolCall, partial: output });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Handle completion\n\t\t\t\telse if (event.type === \"response.completed\") {\n\t\t\t\t\tconst response = event.response;\n\t\t\t\t\tif (response?.usage) {\n\t\t\t\t\t\toutput.usage = {\n\t\t\t\t\t\t\tinput: response.usage.input_tokens || 0,\n\t\t\t\t\t\t\toutput: response.usage.output_tokens || 0,\n\t\t\t\t\t\t\tcacheRead: response.usage.input_tokens_details?.cached_tokens || 0,\n\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tcalculateCost(model, output.usage);\n\t\t\t\t\t// Map status to stop reason\n\t\t\t\t\toutput.stopReason = mapStopReason(response?.status);\n\t\t\t\t\tif (output.content.some((b) => b.type === \"toolCall\") && output.stopReason === \"stop\") {\n\t\t\t\t\t\toutput.stopReason = \"toolUse\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Handle errors\n\t\t\t\telse if (event.type === \"error\") {\n\t\t\t\t\toutput.stopReason = \"error\";\n\t\t\t\t\toutput.error = `Code ${event.code}: ${event.message}` || \"Unknown error\";\n\t\t\t\t\tstream.push({ type: \"error\", error: output.error, partial: output });\n\t\t\t\t\tstream.end();\n\t\t\t\t\treturn output;\n\t\t\t\t} else if (event.type === \"response.failed\") {\n\t\t\t\t\toutput.stopReason = \"error\";\n\t\t\t\t\toutput.error = \"Unknown error\";\n\t\t\t\t\tstream.push({ type: \"error\", error: output.error, partial: output });\n\t\t\t\t\tstream.end();\n\t\t\t\t\treturn output;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options?.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\toutput.stopReason = \"error\";\n\t\t\toutput.error = error instanceof Error ? error.message : JSON.stringify(error);\n\t\t\tstream.push({ type: \"error\", error: output.error, partial: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\nfunction createClient(model: Model<\"openai-responses\">, apiKey?: string) {\n\tif (!apiKey) {\n\t\tif (!process.env.OPENAI_API_KEY) {\n\t\t\tthrow new Error(\n\t\t\t\t\"OpenAI API key is required. Set OPENAI_API_KEY environment variable or pass it as an argument.\",\n\t\t\t);\n\t\t}\n\t\tapiKey = process.env.OPENAI_API_KEY;\n\t}\n\treturn new OpenAI({ apiKey, baseURL: model.baseUrl, dangerouslyAllowBrowser: true });\n}\n\nfunction buildParams(model: Model<\"openai-responses\">, context: Context, options?: OpenAIResponsesOptions) {\n\tconst messages = convertMessages(model, context);\n\n\tconst params: ResponseCreateParamsStreaming = {\n\t\tmodel: model.id,\n\t\tinput: messages,\n\t\tstream: true,\n\t};\n\n\tif (options?.maxTokens) {\n\t\tparams.max_output_tokens = options?.maxTokens;\n\t}\n\n\tif (options?.temperature !== undefined) {\n\t\tparams.temperature = options?.temperature;\n\t}\n\n\tif (context.tools) {\n\t\tparams.tools = convertTools(context.tools);\n\t}\n\n\tif (model.reasoning) {\n\t\tif (options?.reasoningEffort || options?.reasoningSummary) {\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: options?.reasoningEffort || \"medium\",\n\t\t\t\tsummary: options?.reasoningSummary || \"auto\",\n\t\t\t};\n\t\t\tparams.include = [\"reasoning.encrypted_content\"];\n\t\t} else {\n\t\t\tparams.reasoning = {\n\t\t\t\teffort: model.name.startsWith(\"gpt-5\") ? \"minimal\" : null,\n\t\t\t\tsummary: null,\n\t\t\t};\n\n\t\t\tif (model.name.startsWith(\"gpt-5\")) {\n\t\t\t\t// Jesus Christ, see https://community.openai.com/t/need-reasoning-false-option-for-gpt-5/1351588/7\n\t\t\t\tmessages.push({\n\t\t\t\t\trole: \"developer\",\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"input_text\",\n\t\t\t\t\t\t\ttext: \"# Juice: 0 !important\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn params;\n}\n\nfunction convertMessages(model: Model<\"openai-responses\">, context: Context): ResponseInput {\n\tconst messages: ResponseInput = [];\n\n\tconst transformedMessages = transformMessages(context.messages, model);\n\n\tif (context.systemPrompt) {\n\t\tconst role = model.reasoning ? \"developer\" : \"system\";\n\t\tmessages.push({\n\t\t\trole,\n\t\t\tcontent: context.systemPrompt,\n\t\t});\n\t}\n\n\tfor (const msg of transformedMessages) {\n\t\tif (msg.role === \"user\") {\n\t\t\tif (typeof msg.content === \"string\") {\n\t\t\t\tmessages.push({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [{ type: \"input_text\", text: msg.content }],\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst content: ResponseInputContent[] = msg.content.map((item): ResponseInputContent => {\n\t\t\t\t\tif (item.type === \"text\") {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttype: \"input_text\",\n\t\t\t\t\t\t\ttext: item.text,\n\t\t\t\t\t\t} satisfies ResponseInputText;\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttype: \"input_image\",\n\t\t\t\t\t\t\tdetail: \"auto\",\n\t\t\t\t\t\t\timage_url: `data:${item.mimeType};base64,${item.data}`,\n\t\t\t\t\t\t} satisfies ResponseInputImage;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tconst filteredContent = !model.input.includes(\"image\")\n\t\t\t\t\t? content.filter((c) => c.type !== \"input_image\")\n\t\t\t\t\t: content;\n\t\t\t\tif (filteredContent.length === 0) continue;\n\t\t\t\tmessages.push({\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: filteredContent,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (msg.role === \"assistant\") {\n\t\t\tconst output: ResponseInput = [];\n\n\t\t\tfor (const block of msg.content) {\n\t\t\t\t// Do not submit thinking blocks if the completion had an error (i.e. abort)\n\t\t\t\tif (block.type === \"thinking\" && msg.stopReason !== \"error\") {\n\t\t\t\t\tif (block.thinkingSignature) {\n\t\t\t\t\t\tconst reasoningItem = JSON.parse(block.thinkingSignature);\n\t\t\t\t\t\toutput.push(reasoningItem);\n\t\t\t\t\t}\n\t\t\t\t} else if (block.type === \"text\") {\n\t\t\t\t\tconst textBlock = block as TextContent;\n\t\t\t\t\toutput.push({\n\t\t\t\t\t\ttype: \"message\",\n\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\tcontent: [{ type: \"output_text\", text: textBlock.text, annotations: [] }],\n\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\tid: textBlock.textSignature || \"msg_\" + Math.random().toString(36).substring(2, 15),\n\t\t\t\t\t} satisfies ResponseOutputMessage);\n\t\t\t\t\t// Do not submit toolcall blocks if the completion had an error (i.e. abort)\n\t\t\t\t} else if (block.type === \"toolCall\" && msg.stopReason !== \"error\") {\n\t\t\t\t\tconst toolCall = block as ToolCall;\n\t\t\t\t\toutput.push({\n\t\t\t\t\t\ttype: \"function_call\",\n\t\t\t\t\t\tid: toolCall.id.split(\"|\")[1],\n\t\t\t\t\t\tcall_id: toolCall.id.split(\"|\")[0],\n\t\t\t\t\t\tname: toolCall.name,\n\t\t\t\t\t\targuments: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (output.length === 0) continue;\n\t\t\tmessages.push(...output);\n\t\t} else if (msg.role === \"toolResult\") {\n\t\t\tmessages.push({\n\t\t\t\ttype: \"function_call_output\",\n\t\t\t\tcall_id: msg.toolCallId.split(\"|\")[0],\n\t\t\t\toutput: msg.output,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn messages;\n}\n\nfunction convertTools(tools: Tool[]): OpenAITool[] {\n\treturn tools.map((tool) => ({\n\t\ttype: \"function\",\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tparameters: zodToJsonSchema(tool.parameters, { $refStrategy: \"none\" }),\n\t\tstrict: null,\n\t}));\n}\n\nfunction mapStopReason(status: OpenAI.Responses.ResponseStatus | undefined): StopReason {\n\tif (!status) return \"stop\";\n\tswitch (status) {\n\t\tcase \"completed\":\n\t\t\treturn \"stop\";\n\t\tcase \"incomplete\":\n\t\t\treturn \"length\";\n\t\tcase \"failed\":\n\t\tcase \"cancelled\":\n\t\t\treturn \"error\";\n\t\t// These two are wonky ...\n\t\tcase \"in_progress\":\n\t\tcase \"queued\":\n\t\t\treturn \"stop\";\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = status;\n\t\t\tthrow new Error(`Unhandled stop reason: ${_exhaustive}`);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transorm-messages.d.ts","sourceRoot":"","sources":["../../src/providers/transorm-messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAoB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzE,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,EAAE,CAqCtG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transorm-messages.js","sourceRoot":"","sources":["../../src/providers/transorm-messages.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iBAAiB,CAAmB,QAAmB,EAAE,KAAkB;IAC1F,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAC3B,sDAAsD;QACtD,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YACtD,OAAO,GAAG,CAAC;QACZ,CAAC;QAED,+CAA+C;QAC/C,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAC9B,MAAM,YAAY,GAAG,GAAuB,CAAC;YAE7C,2DAA2D;YAC3D,IAAI,YAAY,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,IAAI,YAAY,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,EAAE,CAAC;gBAChF,OAAO,GAAG,CAAC;YACZ,CAAC;YAED,kDAAkD;YAClD,MAAM,kBAAkB,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC7D,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;oBAC/B,4DAA4D;oBAC5D,OAAO;wBACN,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,eAAe,KAAK,CAAC,QAAQ,eAAe;qBAClD,CAAC;gBACH,CAAC;gBACD,2DAA2D;gBAC3D,OAAO,KAAK,CAAC;YACd,CAAC,CAAC,CAAC;YAEH,uCAAuC;YACvC,OAAO;gBACN,GAAG,YAAY;gBACf,OAAO,EAAE,kBAAkB;aAC3B,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Api, AssistantMessage, Message, Model } from \"../types.js\";\n\nexport function transformMessages<TApi extends Api>(messages: Message[], model: Model<TApi>): Message[] {\n\treturn messages.map((msg) => {\n\t\t// User and toolResult messages pass through unchanged\n\t\tif (msg.role === \"user\" || msg.role === \"toolResult\") {\n\t\t\treturn msg;\n\t\t}\n\n\t\t// Assistant messages need transformation check\n\t\tif (msg.role === \"assistant\") {\n\t\t\tconst assistantMsg = msg as AssistantMessage;\n\n\t\t\t// If message is from the same provider and API, keep as is\n\t\t\tif (assistantMsg.provider === model.provider && assistantMsg.api === model.api) {\n\t\t\t\treturn msg;\n\t\t\t}\n\n\t\t\t// Transform message from different provider/model\n\t\t\tconst transformedContent = assistantMsg.content.map((block) => {\n\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\t// Convert thinking block to text block with <thinking> tags\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext: `<thinking>\\n${block.thinking}\\n</thinking>`,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\t// All other blocks (text, toolCall) pass through unchanged\n\t\t\t\treturn block;\n\t\t\t});\n\n\t\t\t// Return transformed assistant message\n\t\t\treturn {\n\t\t\t\t...assistantMsg,\n\t\t\t\tcontent: transformedContent,\n\t\t\t};\n\t\t}\n\t\treturn msg;\n\t});\n}\n"]}
|
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Api, AssistantMessage, AssistantMessageEventStream, Context, KnownProvider, Model, OptionsForApi, SimpleStreamOptions } from "./types.js";
|
|
2
|
+
export declare function setApiKey(provider: KnownProvider, key: string): void;
|
|
3
|
+
export declare function setApiKey(provider: string, key: string): void;
|
|
4
|
+
export declare function getApiKey(provider: KnownProvider): string | undefined;
|
|
5
|
+
export declare function getApiKey(provider: string): string | undefined;
|
|
6
|
+
export declare function stream<TApi extends Api>(model: Model<TApi>, context: Context, options?: OptionsForApi<TApi>): AssistantMessageEventStream;
|
|
7
|
+
export declare function complete<TApi extends Api>(model: Model<TApi>, context: Context, options?: OptionsForApi<TApi>): Promise<AssistantMessage>;
|
|
8
|
+
export declare function streamSimple<TApi extends Api>(model: Model<TApi>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;
|
|
9
|
+
export declare function completeSimple<TApi extends Api>(model: Model<TApi>, context: Context, options?: SimpleStreamOptions): Promise<AssistantMessage>;
|
|
10
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAChB,2BAA2B,EAC3B,OAAO,EACP,aAAa,EACb,KAAK,EACL,aAAa,EAEb,mBAAmB,EACnB,MAAM,YAAY,CAAC;AAIpB,wBAAgB,SAAS,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;AACtE,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;AAK/D,wBAAgB,SAAS,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS,CAAC;AACvE,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAsBhE,wBAAgB,MAAM,CAAC,IAAI,SAAS,GAAG,EACtC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,GAC3B,2BAA2B,CA2B7B;AAED,wBAAsB,QAAQ,CAAC,IAAI,SAAS,GAAG,EAC9C,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CAG3B;AAED,wBAAgB,YAAY,CAAC,IAAI,SAAS,GAAG,EAC5C,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,2BAA2B,CAQ7B;AAED,wBAAsB,cAAc,CAAC,IAAI,SAAS,GAAG,EACpD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CAG3B"}
|
|
@@ -2,68 +2,6 @@ import { streamAnthropic } from "./providers/anthropic.js";
|
|
|
2
2
|
import { streamGoogle } from "./providers/google.js";
|
|
3
3
|
import { streamOpenAICompletions } from "./providers/openai-completions.js";
|
|
4
4
|
import { streamOpenAIResponses } from "./providers/openai-responses.js";
|
|
5
|
-
export class QueuedGenerateStream {
|
|
6
|
-
queue = [];
|
|
7
|
-
waiting = [];
|
|
8
|
-
done = false;
|
|
9
|
-
finalMessagePromise;
|
|
10
|
-
resolveFinalMessage;
|
|
11
|
-
constructor() {
|
|
12
|
-
this.finalMessagePromise = new Promise((resolve) => {
|
|
13
|
-
this.resolveFinalMessage = resolve;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
push(event) {
|
|
17
|
-
if (this.done)
|
|
18
|
-
return;
|
|
19
|
-
if (event.type === "done") {
|
|
20
|
-
this.done = true;
|
|
21
|
-
this.resolveFinalMessage(event.message);
|
|
22
|
-
}
|
|
23
|
-
if (event.type === "error") {
|
|
24
|
-
this.done = true;
|
|
25
|
-
this.resolveFinalMessage(event.partial);
|
|
26
|
-
}
|
|
27
|
-
// Deliver to waiting consumer or queue it
|
|
28
|
-
const waiter = this.waiting.shift();
|
|
29
|
-
if (waiter) {
|
|
30
|
-
waiter({ value: event, done: false });
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
this.queue.push(event);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
end() {
|
|
37
|
-
this.done = true;
|
|
38
|
-
// Notify all waiting consumers that we're done
|
|
39
|
-
while (this.waiting.length > 0) {
|
|
40
|
-
const waiter = this.waiting.shift();
|
|
41
|
-
waiter({ value: undefined, done: true });
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async *[Symbol.asyncIterator]() {
|
|
45
|
-
while (true) {
|
|
46
|
-
// If we have queued events, yield them
|
|
47
|
-
if (this.queue.length > 0) {
|
|
48
|
-
yield this.queue.shift();
|
|
49
|
-
}
|
|
50
|
-
else if (this.done) {
|
|
51
|
-
// No more events and we're done
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// Wait for next event
|
|
56
|
-
const result = await new Promise((resolve) => this.waiting.push(resolve));
|
|
57
|
-
if (result.done)
|
|
58
|
-
return;
|
|
59
|
-
yield result.value;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
finalMessage() {
|
|
64
|
-
return this.finalMessagePromise;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
5
|
const apiKeys = new Map();
|
|
68
6
|
export function setApiKey(provider, key) {
|
|
69
7
|
apiKeys.set(provider, key);
|
|
@@ -112,7 +50,7 @@ export function stream(model, context, options) {
|
|
|
112
50
|
}
|
|
113
51
|
export async function complete(model, context, options) {
|
|
114
52
|
const s = stream(model, context, options);
|
|
115
|
-
return s.
|
|
53
|
+
return s.result();
|
|
116
54
|
}
|
|
117
55
|
export function streamSimple(model, context, options) {
|
|
118
56
|
const apiKey = options?.apiKey || getApiKey(model.provider);
|
|
@@ -124,7 +62,7 @@ export function streamSimple(model, context, options) {
|
|
|
124
62
|
}
|
|
125
63
|
export async function completeSimple(model, context, options) {
|
|
126
64
|
const s = streamSimple(model, context, options);
|
|
127
|
-
return s.
|
|
65
|
+
return s.result();
|
|
128
66
|
}
|
|
129
67
|
function mapOptionsForApi(model, options, apiKey) {
|
|
130
68
|
const base = {
|
|
@@ -202,4 +140,4 @@ function getGoogleBudget(model, effort) {
|
|
|
202
140
|
// Unknown model - use dynamic
|
|
203
141
|
return -1;
|
|
204
142
|
}
|
|
205
|
-
//# sourceMappingURL=
|
|
143
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAClF,OAAO,EAAsB,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAiC,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC3G,OAAO,EAA+B,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAarG,MAAM,OAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;AAI/C,MAAM,UAAU,SAAS,CAAC,QAAa,EAAE,GAAW;IACnD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AAC5B,CAAC;AAID,MAAM,UAAU,SAAS,CAAC,QAAa;IACtC,4BAA4B;IAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClC,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC;IAEpB,qCAAqC;IACrC,MAAM,MAAM,GAA2B;QACtC,MAAM,EAAE,gBAAgB;QACxB,SAAS,EAAE,mBAAmB;QAC9B,MAAM,EAAE,gBAAgB;QACxB,IAAI,EAAE,cAAc;QACpB,QAAQ,EAAE,kBAAkB;QAC5B,GAAG,EAAE,aAAa;QAClB,UAAU,EAAE,oBAAoB;QAChC,GAAG,EAAE,aAAa;KAClB,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,MAAM,CACrB,KAAkB,EAClB,OAAgB,EAChB,OAA6B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AI;YACZ,IAAI,EAAE,KAAK;SACX,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,8BAA8B;IAC9B,OAAO,CAAC,CAAC,CAAC;AACX,CAAC","sourcesContent":["import { type AnthropicOptions, streamAnthropic } from \"./providers/anthropic.js\";\nimport { type GoogleOptions, streamGoogle } from \"./providers/google.js\";\nimport { type OpenAICompletionsOptions, streamOpenAICompletions } from \"./providers/openai-completions.js\";\nimport { type OpenAIResponsesOptions, streamOpenAIResponses } from \"./providers/openai-responses.js\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tKnownProvider,\n\tModel,\n\tOptionsForApi,\n\tReasoningEffort,\n\tSimpleStreamOptions,\n} from \"./types.js\";\n\nconst apiKeys: Map<string, string> = new Map();\n\nexport function setApiKey(provider: KnownProvider, key: string): void;\nexport function setApiKey(provider: string, key: string): void;\nexport function setApiKey(provider: any, key: string): void {\n\tapiKeys.set(provider, key);\n}\n\nexport function getApiKey(provider: KnownProvider): string | undefined;\nexport function getApiKey(provider: string): string | undefined;\nexport function getApiKey(provider: any): string | undefined {\n\t// Check explicit keys first\n\tconst key = apiKeys.get(provider);\n\tif (key) return key;\n\n\t// Fall back to environment variables\n\tconst envMap: Record<string, string> = {\n\t\topenai: \"OPENAI_API_KEY\",\n\t\tanthropic: \"ANTHROPIC_API_KEY\",\n\t\tgoogle: \"GEMINI_API_KEY\",\n\t\tgroq: \"GROQ_API_KEY\",\n\t\tcerebras: \"CEREBRAS_API_KEY\",\n\t\txai: \"XAI_API_KEY\",\n\t\topenrouter: \"OPENROUTER_API_KEY\",\n\t\tzai: \"ZAI_API_KEY\",\n\t};\n\n\tconst envVar = envMap[provider];\n\treturn envVar ? process.env[envVar] : undefined;\n}\n\nexport function stream<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: OptionsForApi<TApi>,\n): AssistantMessageEventStream {\n\tconst apiKey = options?.apiKey || getApiKey(model.provider);\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\tconst providerOptions = { ...options, apiKey };\n\n\tconst api: Api = model.api;\n\tswitch (api) {\n\t\tcase \"anthropic-messages\":\n\t\t\treturn streamAnthropic(model as Model<\"anthropic-messages\">, context, providerOptions);\n\n\t\tcase \"openai-completions\":\n\t\t\treturn streamOpenAICompletions(model as Model<\"openai-completions\">, context, providerOptions as any);\n\n\t\tcase \"openai-responses\":\n\t\t\treturn streamOpenAIResponses(model as Model<\"openai-responses\">, context, providerOptions as any);\n\n\t\tcase \"google-generative-ai\":\n\t\t\treturn streamGoogle(model as Model<\"google-generative-ai\">, context, providerOptions);\n\n\t\tdefault: {\n\t\t\t// This should never be reached if all Api cases are handled\n\t\t\tconst _exhaustive: never = api;\n\t\t\tthrow new Error(`Unhandled API: ${_exhaustive}`);\n\t\t}\n\t}\n}\n\nexport async function complete<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: OptionsForApi<TApi>,\n): Promise<AssistantMessage> {\n\tconst s = stream(model, context, options);\n\treturn s.result();\n}\n\nexport function streamSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst apiKey = options?.apiKey || getApiKey(model.provider);\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst providerOptions = mapOptionsForApi(model, options, apiKey);\n\treturn stream(model, context, providerOptions);\n}\n\nexport async function completeSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = streamSimple(model, context, options);\n\treturn s.result();\n}\n\nfunction mapOptionsForApi<TApi extends Api>(\n\tmodel: Model<TApi>,\n\toptions?: SimpleStreamOptions,\n\tapiKey?: string,\n): OptionsForApi<TApi> {\n\tconst base = {\n\t\ttemperature: options?.temperature,\n\t\tmaxTokens: options?.maxTokens,\n\t\tsignal: options?.signal,\n\t\tapiKey: apiKey || options?.apiKey,\n\t};\n\n\tswitch (model.api) {\n\t\tcase \"anthropic-messages\": {\n\t\t\tif (!options?.reasoning) return base satisfies AnthropicOptions;\n\n\t\t\tconst anthropicBudgets = {\n\t\t\t\tminimal: 1024,\n\t\t\t\tlow: 2048,\n\t\t\t\tmedium: 8192,\n\t\t\t\thigh: Math.min(25000, model.maxTokens - 1000),\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\tthinkingEnabled: true,\n\t\t\t\tthinkingBudgetTokens: anthropicBudgets[options.reasoning],\n\t\t\t} satisfies AnthropicOptions;\n\t\t}\n\n\t\tcase \"openai-completions\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\treasoningEffort: options?.reasoning,\n\t\t\t} satisfies OpenAICompletionsOptions;\n\n\t\tcase \"openai-responses\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\treasoningEffort: options?.reasoning,\n\t\t\t} satisfies OpenAIResponsesOptions;\n\n\t\tcase \"google-generative-ai\": {\n\t\t\tif (!options?.reasoning) return base as any;\n\n\t\t\tconst googleBudget = getGoogleBudget(model as Model<\"google-generative-ai\">, options.reasoning);\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\tthinking: {\n\t\t\t\t\tenabled: true,\n\t\t\t\t\tbudgetTokens: googleBudget,\n\t\t\t\t},\n\t\t\t} satisfies GoogleOptions;\n\t\t}\n\n\t\tdefault: {\n\t\t\t// Exhaustiveness check\n\t\t\tconst _exhaustive: never = model.api;\n\t\t\tthrow new Error(`Unhandled API in mapOptionsForApi: ${_exhaustive}`);\n\t\t}\n\t}\n}\n\nfunction getGoogleBudget(model: Model<\"google-generative-ai\">, effort: ReasoningEffort): number {\n\t// See https://ai.google.dev/gemini-api/docs/thinking#set-budget\n\tif (model.id.includes(\"2.5-pro\")) {\n\t\tconst budgets = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 32768,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\tif (model.id.includes(\"2.5-flash\")) {\n\t\t// Covers 2.5-flash-lite as well\n\t\tconst budgets = {\n\t\t\tminimal: 128,\n\t\t\tlow: 2048,\n\t\t\tmedium: 8192,\n\t\t\thigh: 24576,\n\t\t};\n\t\treturn budgets[effort];\n\t}\n\n\t// Unknown model - use dynamic\n\treturn -1;\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { AssistantMessageEventStream } from "./event-stream";
|
|
1
2
|
import type { AnthropicOptions } from "./providers/anthropic";
|
|
2
3
|
import type { GoogleOptions } from "./providers/google";
|
|
3
4
|
import type { OpenAICompletionsOptions } from "./providers/openai-completions";
|
|
4
5
|
import type { OpenAIResponsesOptions } from "./providers/openai-responses";
|
|
6
|
+
export type { AssistantMessageEventStream } from "./event-stream";
|
|
5
7
|
export type Api = "openai-completions" | "openai-responses" | "anthropic-messages" | "google-generative-ai";
|
|
6
8
|
export interface ApiOptionsMap {
|
|
7
9
|
"anthropic-messages": AnthropicOptions;
|
|
@@ -13,19 +15,16 @@ export type OptionsForApi<TApi extends Api> = ApiOptionsMap[TApi];
|
|
|
13
15
|
export type KnownProvider = "anthropic" | "google" | "openai" | "xai" | "groq" | "cerebras" | "openrouter" | "zai";
|
|
14
16
|
export type Provider = KnownProvider | string;
|
|
15
17
|
export type ReasoningEffort = "minimal" | "low" | "medium" | "high";
|
|
16
|
-
export interface
|
|
17
|
-
finalMessage(): Promise<AssistantMessage>;
|
|
18
|
-
}
|
|
19
|
-
export interface GenerateOptions {
|
|
18
|
+
export interface StreamOptions {
|
|
20
19
|
temperature?: number;
|
|
21
20
|
maxTokens?: number;
|
|
22
21
|
signal?: AbortSignal;
|
|
23
22
|
apiKey?: string;
|
|
24
23
|
}
|
|
25
|
-
export interface
|
|
24
|
+
export interface SimpleStreamOptions extends StreamOptions {
|
|
26
25
|
reasoning?: ReasoningEffort;
|
|
27
26
|
}
|
|
28
|
-
export type
|
|
27
|
+
export type StreamFunction<TApi extends Api> = (model: Model<TApi>, context: Context, options: OptionsForApi<TApi>) => AssistantMessageEventStream;
|
|
29
28
|
export interface TextContent {
|
|
30
29
|
type: "text";
|
|
31
30
|
text: string;
|
|
@@ -75,18 +74,20 @@ export interface AssistantMessage {
|
|
|
75
74
|
stopReason: StopReason;
|
|
76
75
|
error?: string;
|
|
77
76
|
}
|
|
78
|
-
export interface ToolResultMessage {
|
|
77
|
+
export interface ToolResultMessage<TDetails = any> {
|
|
79
78
|
role: "toolResult";
|
|
80
79
|
toolCallId: string;
|
|
81
80
|
toolName: string;
|
|
82
|
-
|
|
81
|
+
output: string;
|
|
82
|
+
details?: TDetails;
|
|
83
83
|
isError: boolean;
|
|
84
84
|
}
|
|
85
85
|
export type Message = UserMessage | AssistantMessage | ToolResultMessage;
|
|
86
|
-
|
|
86
|
+
import type { ZodSchema } from "zod";
|
|
87
|
+
export interface Tool<TParameters extends ZodSchema = ZodSchema> {
|
|
87
88
|
name: string;
|
|
88
89
|
description: string;
|
|
89
|
-
parameters:
|
|
90
|
+
parameters: TParameters;
|
|
90
91
|
}
|
|
91
92
|
export interface Context {
|
|
92
93
|
systemPrompt?: string;
|
|
@@ -98,28 +99,44 @@ export type AssistantMessageEvent = {
|
|
|
98
99
|
partial: AssistantMessage;
|
|
99
100
|
} | {
|
|
100
101
|
type: "text_start";
|
|
102
|
+
contentIndex: number;
|
|
101
103
|
partial: AssistantMessage;
|
|
102
104
|
} | {
|
|
103
105
|
type: "text_delta";
|
|
106
|
+
contentIndex: number;
|
|
104
107
|
delta: string;
|
|
105
108
|
partial: AssistantMessage;
|
|
106
109
|
} | {
|
|
107
110
|
type: "text_end";
|
|
111
|
+
contentIndex: number;
|
|
108
112
|
content: string;
|
|
109
113
|
partial: AssistantMessage;
|
|
110
114
|
} | {
|
|
111
115
|
type: "thinking_start";
|
|
116
|
+
contentIndex: number;
|
|
112
117
|
partial: AssistantMessage;
|
|
113
118
|
} | {
|
|
114
119
|
type: "thinking_delta";
|
|
120
|
+
contentIndex: number;
|
|
115
121
|
delta: string;
|
|
116
122
|
partial: AssistantMessage;
|
|
117
123
|
} | {
|
|
118
124
|
type: "thinking_end";
|
|
125
|
+
contentIndex: number;
|
|
119
126
|
content: string;
|
|
120
127
|
partial: AssistantMessage;
|
|
121
128
|
} | {
|
|
122
|
-
type: "
|
|
129
|
+
type: "toolcall_start";
|
|
130
|
+
contentIndex: number;
|
|
131
|
+
partial: AssistantMessage;
|
|
132
|
+
} | {
|
|
133
|
+
type: "toolcall_delta";
|
|
134
|
+
contentIndex: number;
|
|
135
|
+
delta: string;
|
|
136
|
+
partial: AssistantMessage;
|
|
137
|
+
} | {
|
|
138
|
+
type: "toolcall_end";
|
|
139
|
+
contentIndex: number;
|
|
123
140
|
toolCall: ToolCall;
|
|
124
141
|
partial: AssistantMessage;
|
|
125
142
|
} | {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAE3E,MAAM,MAAM,GAAG,GAAG,oBAAoB,GAAG,kBAAkB,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;AAE5G,MAAM,WAAW,aAAa;IAC7B,oBAAoB,EAAE,gBAAgB,CAAC;IACvC,oBAAoB,EAAE,wBAAwB,CAAC;IAC/C,kBAAkB,EAAE,sBAAsB,CAAC;IAC3C,sBAAsB,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