@mariozechner/pi-ai 0.5.24 → 0.5.26

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.
@@ -17,10 +17,14 @@ export class OpenAIResponsesLLM {
17
17
  getModel() {
18
18
  return this.modelInfo;
19
19
  }
20
+ getApi() {
21
+ return "openai-responses";
22
+ }
20
23
  async generate(request, options) {
21
24
  const output = {
22
25
  role: "assistant",
23
26
  content: [],
27
+ api: this.getApi(),
24
28
  provider: this.modelInfo.provider,
25
29
  model: this.modelInfo.id,
26
30
  usage: {
@@ -49,12 +53,32 @@ export class OpenAIResponsesLLM {
49
53
  params.tools = this.convertTools(request.tools);
50
54
  }
51
55
  // Add reasoning options for models that support it
52
- if (this.modelInfo?.reasoning && (options?.reasoningEffort || options?.reasoningSummary)) {
53
- params.reasoning = {
54
- effort: options?.reasoningEffort || "medium",
55
- summary: options?.reasoningSummary || "auto",
56
- };
57
- params.include = ["reasoning.encrypted_content"];
56
+ if (this.modelInfo?.reasoning) {
57
+ if (options?.reasoningEffort || options?.reasoningSummary) {
58
+ params.reasoning = {
59
+ effort: options?.reasoningEffort || "medium",
60
+ summary: options?.reasoningSummary || "auto",
61
+ };
62
+ params.include = ["reasoning.encrypted_content"];
63
+ }
64
+ else {
65
+ params.reasoning = {
66
+ effort: this.modelInfo.name.startsWith("gpt-5") ? "minimal" : null,
67
+ summary: null,
68
+ };
69
+ if (this.modelInfo.name.startsWith("gpt-5")) {
70
+ // Jesus Christ, see https://community.openai.com/t/need-reasoning-false-option-for-gpt-5/1351588/7
71
+ input.push({
72
+ role: "developer",
73
+ content: [
74
+ {
75
+ type: "input_text",
76
+ text: "# Juice: 0 !important",
77
+ },
78
+ ],
79
+ });
80
+ }
81
+ }
58
82
  }
59
83
  const stream = await this.client.responses.create(params, {
60
84
  signal: options?.signal,
@@ -248,7 +272,7 @@ export class OpenAIResponsesLLM {
248
272
  convertToInput(messages, systemPrompt) {
249
273
  const input = [];
250
274
  // Transform messages for cross-provider compatibility
251
- const transformedMessages = transformMessages(messages, this.modelInfo);
275
+ const transformedMessages = transformMessages(messages, this.modelInfo, this.getApi());
252
276
  // Add system prompt if provided
253
277
  if (systemPrompt) {
254
278
  const role = this.modelInfo?.reasoning ? "developer" : "system";
@@ -285,9 +309,12 @@ export class OpenAIResponsesLLM {
285
309
  };
286
310
  }
287
311
  });
312
+ const filteredContent = !this.modelInfo?.input.includes("image")
313
+ ? content.filter((c) => c.type !== "input_image")
314
+ : content;
288
315
  input.push({
289
316
  role: "user",
290
- content,
317
+ content: filteredContent,
291
318
  });
292
319
  }
293
320
  }
@@ -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,aAAa,EAAE,MAAM,cAAc,CAAC;AAa7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAO/C,MAAM,OAAO,kBAAkB;IACtB,MAAM,CAAS;IACf,SAAS,CAAQ;IAEzB,YAAY,KAAY,EAAE,MAAe;QACxC,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CACd,gGAAgG,CAChG,CAAC;YACH,CAAC;YACD,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5F,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACxB,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAgB,EAAE,OAA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,CAAC,MAA0B;QAC/C,QAAQ,MAAM,EAAE,CAAC;YAChB,KAAK,WAAW;gBACf,OAAO,MAAM,CAAC;YACf,KAAK,YAAY;gBAChB,OAAO,QAAQ,CAAC;YACjB,KAAK,QAAQ,CAAC;YACd,KAAK,WAAW;gBACf,OAAO,OAAO,CAAC;YAChB;gBACC,OAAO,MAAM,CAAC;QAChB,CAAC;IACF,CAAC;CACD","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 { calculateCost } from \"../models.js\";\nimport type {\n\tAssistantMessage,\n\tContext,\n\tLLM,\n\tLLMOptions,\n\tMessage,\n\tModel,\n\tStopReason,\n\tTextContent,\n\tTool,\n\tToolCall,\n} from \"../types.js\";\nimport { transformMessages } from \"./utils.js\";\n\nexport interface OpenAIResponsesLLMOptions extends LLMOptions {\n\treasoningEffort?: \"minimal\" | \"low\" | \"medium\" | \"high\";\n\treasoningSummary?: \"auto\" | \"detailed\" | \"concise\" | null;\n}\n\nexport class OpenAIResponsesLLM implements LLM<OpenAIResponsesLLMOptions> {\n\tprivate client: OpenAI;\n\tprivate modelInfo: Model;\n\n\tconstructor(model: Model, apiKey?: string) {\n\t\tif (!apiKey) {\n\t\t\tif (!process.env.OPENAI_API_KEY) {\n\t\t\t\tthrow new Error(\n\t\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\t);\n\t\t\t}\n\t\t\tapiKey = process.env.OPENAI_API_KEY;\n\t\t}\n\t\tthis.client = new OpenAI({ apiKey, baseURL: model.baseUrl, dangerouslyAllowBrowser: true });\n\t\tthis.modelInfo = model;\n\t}\n\n\tgetModel(): Model {\n\t\treturn this.modelInfo;\n\t}\n\n\tasync generate(request: Context, options?: OpenAIResponsesLLMOptions): Promise<AssistantMessage> {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tprovider: this.modelInfo.provider,\n\t\t\tmodel: this.modelInfo.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\t\ttry {\n\t\t\tconst input = this.convertToInput(request.messages, request.systemPrompt);\n\n\t\t\tconst params: ResponseCreateParamsStreaming = {\n\t\t\t\tmodel: this.modelInfo.id,\n\t\t\t\tinput,\n\t\t\t\tstream: true,\n\t\t\t};\n\n\t\t\tif (options?.maxTokens) {\n\t\t\t\tparams.max_output_tokens = options?.maxTokens;\n\t\t\t}\n\n\t\t\tif (options?.temperature !== undefined) {\n\t\t\t\tparams.temperature = options?.temperature;\n\t\t\t}\n\n\t\t\tif (request.tools) {\n\t\t\t\tparams.tools = this.convertTools(request.tools);\n\t\t\t}\n\n\t\t\t// Add reasoning options for models that support it\n\t\t\tif (this.modelInfo?.reasoning && (options?.reasoningEffort || options?.reasoningSummary)) {\n\t\t\t\tparams.reasoning = {\n\t\t\t\t\teffort: options?.reasoningEffort || \"medium\",\n\t\t\t\t\tsummary: options?.reasoningSummary || \"auto\",\n\t\t\t\t};\n\t\t\t\tparams.include = [\"reasoning.encrypted_content\"];\n\t\t\t}\n\n\t\t\tconst stream = await this.client.responses.create(params, {\n\t\t\t\tsignal: options?.signal,\n\t\t\t});\n\n\t\t\toptions?.onEvent?.({ type: \"start\", model: this.modelInfo.id, provider: this.modelInfo.provider });\n\n\t\t\tconst outputItems: (ResponseReasoningItem | ResponseOutputMessage | ResponseFunctionToolCall)[] = [];\n\t\t\tlet currentItem: ResponseReasoningItem | ResponseOutputMessage | ResponseFunctionToolCall | null = null;\n\n\t\t\tfor await (const event of stream) {\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\toptions?.onEvent?.({ type: \"thinking_start\" });\n\t\t\t\t\t\toutputItems.push(item);\n\t\t\t\t\t\tcurrentItem = item;\n\t\t\t\t\t} else if (item.type === \"message\") {\n\t\t\t\t\t\toptions?.onEvent?.({ type: \"text_start\" });\n\t\t\t\t\t\toutputItems.push(item);\n\t\t\t\t\t\tcurrentItem = item;\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 (currentItem && currentItem.type === \"reasoning\") {\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\tlastPart.text += event.delta;\n\t\t\t\t\t\t\toptions?.onEvent?.({\n\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\tcontent: currentItem.summary.map((s) => s.text).join(\"\\n\\n\"),\n\t\t\t\t\t\t\t\tdelta: event.delta,\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 (currentItem && currentItem.type === \"reasoning\") {\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\tlastPart.text += \"\\n\\n\";\n\t\t\t\t\t\t\toptions?.onEvent?.({\n\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\tcontent: currentItem.summary.map((s) => s.text).join(\"\\n\\n\"),\n\t\t\t\t\t\t\t\tdelta: \"\\n\\n\",\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\") {\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\tlastPart.text += event.delta;\n\t\t\t\t\t\t\toptions?.onEvent?.({\n\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\tcontent: currentItem.content\n\t\t\t\t\t\t\t\t\t.map((c) => (c.type === \"output_text\" ? c.text : c.refusal))\n\t\t\t\t\t\t\t\t\t.join(\"\"),\n\t\t\t\t\t\t\t\tdelta: event.delta,\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\") {\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\tlastPart.refusal += event.delta;\n\t\t\t\t\t\t\toptions?.onEvent?.({\n\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\tcontent: currentItem.content\n\t\t\t\t\t\t\t\t\t.map((c) => (c.type === \"output_text\" ? c.text : c.refusal))\n\t\t\t\t\t\t\t\t\t.join(\"\"),\n\t\t\t\t\t\t\t\tdelta: event.delta,\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\") {\n\t\t\t\t\t\toutputItems[outputItems.length - 1] = item; // Update with final item\n\t\t\t\t\t\tconst thinkingContent = item.summary?.map((s) => s.text).join(\"\\n\\n\") || \"\";\n\t\t\t\t\t\toptions?.onEvent?.({ type: \"thinking_end\", content: thinkingContent });\n\t\t\t\t\t} else if (item.type === \"message\") {\n\t\t\t\t\t\toutputItems[outputItems.length - 1] = item; // Update with final item\n\t\t\t\t\t\tconst textContent = item.content.map((c) => (c.type === \"output_text\" ? c.text : c.refusal)).join(\"\");\n\t\t\t\t\t\toptions?.onEvent?.({ type: \"text_end\", content: textContent });\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\toptions?.onEvent?.({ type: \"toolCall\", toolCall });\n\t\t\t\t\t\toutputItems.push(item);\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(this.modelInfo, output.usage);\n\t\t\t\t\t// Map status to stop reason\n\t\t\t\t\toutput.stopReason = this.mapStopReason(response?.status);\n\t\t\t\t\tif (outputItems.some((b) => b.type === \"function_call\") && 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\toptions?.onEvent?.({ type: \"error\", error: output.error });\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\toptions?.onEvent?.({ type: \"error\", error: output.error });\n\t\t\t\t\treturn output;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Convert output items to blocks\n\t\t\tfor (const item of outputItems) {\n\t\t\t\tif (item.type === \"reasoning\") {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"thinking\",\n\t\t\t\t\t\tthinking: item.summary?.map((s: any) => s.text).join(\"\\n\\n\") || \"\",\n\t\t\t\t\t\tthinkingSignature: JSON.stringify(item), // Full item for resubmission\n\t\t\t\t\t});\n\t\t\t\t} else if (item.type === \"message\") {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: item.content.map((c) => (c.type === \"output_text\" ? c.text : c.refusal)).join(\"\"),\n\t\t\t\t\t\ttextSignature: item.id, // ID for resubmission\n\t\t\t\t\t});\n\t\t\t\t} else if (item.type === \"function_call\") {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\tid: item.call_id + \"|\" + item.id,\n\t\t\t\t\t\tname: item.name,\n\t\t\t\t\t\targuments: JSON.parse(item.arguments),\n\t\t\t\t\t});\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\toptions?.onEvent?.({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\treturn output;\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\toptions?.onEvent?.({ type: \"error\", error: output.error });\n\t\t\treturn output;\n\t\t}\n\t}\n\n\tprivate convertToInput(messages: Message[], systemPrompt?: string): ResponseInput {\n\t\tconst input: ResponseInput = [];\n\n\t\t// Transform messages for cross-provider compatibility\n\t\tconst transformedMessages = transformMessages(messages, this.modelInfo);\n\n\t\t// Add system prompt if provided\n\t\tif (systemPrompt) {\n\t\t\tconst role = this.modelInfo?.reasoning ? \"developer\" : \"system\";\n\t\t\tinput.push({\n\t\t\t\trole,\n\t\t\t\tcontent: systemPrompt,\n\t\t\t});\n\t\t}\n\n\t\t// Convert messages\n\t\tfor (const msg of transformedMessages) {\n\t\t\tif (msg.role === \"user\") {\n\t\t\t\t// Handle both string and array content\n\t\t\t\tif (typeof msg.content === \"string\") {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"input_text\", text: msg.content }],\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\t// Convert array content to OpenAI Responses format\n\t\t\t\t\tconst content: ResponseInputContent[] = msg.content.map((item): ResponseInputContent => {\n\t\t\t\t\t\tif (item.type === \"text\") {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: \"input_text\",\n\t\t\t\t\t\t\t\ttext: item.text,\n\t\t\t\t\t\t\t} satisfies ResponseInputText;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Image content - OpenAI Responses uses data URLs\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: \"input_image\",\n\t\t\t\t\t\t\t\tdetail: \"auto\",\n\t\t\t\t\t\t\t\timage_url: `data:${item.mimeType};base64,${item.data}`,\n\t\t\t\t\t\t\t} satisfies ResponseInputImage;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else if (msg.role === \"assistant\") {\n\t\t\t\t// Process content blocks in order\n\t\t\t\tconst output: ResponseInput = [];\n\n\t\t\t\tfor (const block of msg.content) {\n\t\t\t\t\t// Do not submit thinking blocks if the completion had an error (i.e. abort)\n\t\t\t\t\tif (block.type === \"thinking\" && msg.stopReason !== \"error\") {\n\t\t\t\t\t\t// Push the full reasoning item(s) from signature\n\t\t\t\t\t\tif (block.thinkingSignature) {\n\t\t\t\t\t\t\tconst reasoningItem = JSON.parse(block.thinkingSignature);\n\t\t\t\t\t\t\toutput.push(reasoningItem);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (block.type === \"text\") {\n\t\t\t\t\t\tconst textBlock = block as TextContent;\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\ttype: \"message\",\n\t\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\t\tcontent: [{ type: \"output_text\", text: textBlock.text, annotations: [] }],\n\t\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\t\tid: textBlock.textSignature || \"msg_\" + Math.random().toString(36).substring(2, 15),\n\t\t\t\t\t\t} satisfies ResponseOutputMessage);\n\t\t\t\t\t\t// Do not submit thinking blocks if the completion had an error (i.e. abort)\n\t\t\t\t\t} else if (block.type === \"toolCall\" && msg.stopReason !== \"error\") {\n\t\t\t\t\t\tconst toolCall = block as ToolCall;\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\ttype: \"function_call\",\n\t\t\t\t\t\t\tid: toolCall.id.split(\"|\")[1], // Extract original ID\n\t\t\t\t\t\t\tcall_id: toolCall.id.split(\"|\")[0], // Extract call session ID\n\t\t\t\t\t\t\tname: toolCall.name,\n\t\t\t\t\t\t\targuments: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Add all output items to input\n\t\t\t\tinput.push(...output);\n\t\t\t} else if (msg.role === \"toolResult\") {\n\t\t\t\t// Tool results are sent as function_call_output\n\t\t\t\tinput.push({\n\t\t\t\t\ttype: \"function_call_output\",\n\t\t\t\t\tcall_id: msg.toolCallId.split(\"|\")[0], // Extract call session ID\n\t\t\t\t\toutput: msg.content,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn input;\n\t}\n\n\tprivate convertTools(tools: Tool[]): OpenAITool[] {\n\t\treturn tools.map((tool) => ({\n\t\t\ttype: \"function\",\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: tool.parameters,\n\t\t\tstrict: null,\n\t\t}));\n\t}\n\n\tprivate mapStopReason(status: string | undefined): StopReason {\n\t\tswitch (status) {\n\t\t\tcase \"completed\":\n\t\t\t\treturn \"stop\";\n\t\t\tcase \"incomplete\":\n\t\t\t\treturn \"length\";\n\t\t\tcase \"failed\":\n\t\t\tcase \"cancelled\":\n\t\t\t\treturn \"error\";\n\t\t\tdefault:\n\t\t\t\treturn \"stop\";\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"openai-responses.js","sourceRoot":"","sources":["../../src/providers/openai-responses.ts"],"names":[],"mappings":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;oBACjE,MAAM,EAAE,GAAG,CAAC,OAAO;iBACnB,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QAED,OAAO,KAAK,CAAC;IACd,CAAC;IAEO,YAAY,CAAC,KAAa;QACjC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC3B,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,MAAM,EAAE,IAAI;SACZ,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,MAA0B;QAC/C,QAAQ,MAAM,EAAE,CAAC;YAChB,KAAK,WAAW;gBACf,OAAO,MAAM,CAAC;YACf,KAAK,YAAY;gBAChB,OAAO,QAAQ,CAAC;YACjB,KAAK,QAAQ,CAAC;YACd,KAAK,WAAW;gBACf,OAAO,OAAO,CAAC;YAChB;gBACC,OAAO,MAAM,CAAC;QAChB,CAAC;IACF,CAAC;CACD","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 { calculateCost } from \"../models.js\";\nimport type {\n\tAssistantMessage,\n\tContext,\n\tLLM,\n\tLLMOptions,\n\tMessage,\n\tModel,\n\tStopReason,\n\tTextContent,\n\tTool,\n\tToolCall,\n} from \"../types.js\";\nimport { transformMessages } from \"./utils.js\";\n\nexport interface OpenAIResponsesLLMOptions extends LLMOptions {\n\treasoningEffort?: \"minimal\" | \"low\" | \"medium\" | \"high\";\n\treasoningSummary?: \"auto\" | \"detailed\" | \"concise\" | null;\n}\n\nexport class OpenAIResponsesLLM implements LLM<OpenAIResponsesLLMOptions> {\n\tprivate client: OpenAI;\n\tprivate modelInfo: Model;\n\n\tconstructor(model: Model, apiKey?: string) {\n\t\tif (!apiKey) {\n\t\t\tif (!process.env.OPENAI_API_KEY) {\n\t\t\t\tthrow new Error(\n\t\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\t);\n\t\t\t}\n\t\t\tapiKey = process.env.OPENAI_API_KEY;\n\t\t}\n\t\tthis.client = new OpenAI({ apiKey, baseURL: model.baseUrl, dangerouslyAllowBrowser: true });\n\t\tthis.modelInfo = model;\n\t}\n\n\tgetModel(): Model {\n\t\treturn this.modelInfo;\n\t}\n\n\tgetApi(): string {\n\t\treturn \"openai-responses\";\n\t}\n\n\tasync generate(request: Context, options?: OpenAIResponsesLLMOptions): Promise<AssistantMessage> {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: this.getApi(),\n\t\t\tprovider: this.modelInfo.provider,\n\t\t\tmodel: this.modelInfo.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\t\ttry {\n\t\t\tconst input = this.convertToInput(request.messages, request.systemPrompt);\n\n\t\t\tconst params: ResponseCreateParamsStreaming = {\n\t\t\t\tmodel: this.modelInfo.id,\n\t\t\t\tinput,\n\t\t\t\tstream: true,\n\t\t\t};\n\n\t\t\tif (options?.maxTokens) {\n\t\t\t\tparams.max_output_tokens = options?.maxTokens;\n\t\t\t}\n\n\t\t\tif (options?.temperature !== undefined) {\n\t\t\t\tparams.temperature = options?.temperature;\n\t\t\t}\n\n\t\t\tif (request.tools) {\n\t\t\t\tparams.tools = this.convertTools(request.tools);\n\t\t\t}\n\n\t\t\t// Add reasoning options for models that support it\n\t\t\tif (this.modelInfo?.reasoning) {\n\t\t\t\tif (options?.reasoningEffort || options?.reasoningSummary) {\n\t\t\t\t\tparams.reasoning = {\n\t\t\t\t\t\teffort: options?.reasoningEffort || \"medium\",\n\t\t\t\t\t\tsummary: options?.reasoningSummary || \"auto\",\n\t\t\t\t\t};\n\t\t\t\t\tparams.include = [\"reasoning.encrypted_content\"];\n\t\t\t\t} else {\n\t\t\t\t\tparams.reasoning = {\n\t\t\t\t\t\teffort: this.modelInfo.name.startsWith(\"gpt-5\") ? \"minimal\" : null,\n\t\t\t\t\t\tsummary: null,\n\t\t\t\t\t};\n\n\t\t\t\t\tif (this.modelInfo.name.startsWith(\"gpt-5\")) {\n\t\t\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\t\t\tinput.push({\n\t\t\t\t\t\t\trole: \"developer\",\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"input_text\",\n\t\t\t\t\t\t\t\t\ttext: \"# Juice: 0 !important\",\n\t\t\t\t\t\t\t\t},\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}\n\n\t\t\tconst stream = await this.client.responses.create(params, {\n\t\t\t\tsignal: options?.signal,\n\t\t\t});\n\n\t\t\toptions?.onEvent?.({ type: \"start\", model: this.modelInfo.id, provider: this.modelInfo.provider });\n\n\t\t\tconst outputItems: (ResponseReasoningItem | ResponseOutputMessage | ResponseFunctionToolCall)[] = [];\n\t\t\tlet currentItem: ResponseReasoningItem | ResponseOutputMessage | ResponseFunctionToolCall | null = null;\n\n\t\t\tfor await (const event of stream) {\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\toptions?.onEvent?.({ type: \"thinking_start\" });\n\t\t\t\t\t\toutputItems.push(item);\n\t\t\t\t\t\tcurrentItem = item;\n\t\t\t\t\t} else if (item.type === \"message\") {\n\t\t\t\t\t\toptions?.onEvent?.({ type: \"text_start\" });\n\t\t\t\t\t\toutputItems.push(item);\n\t\t\t\t\t\tcurrentItem = item;\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 (currentItem && currentItem.type === \"reasoning\") {\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\tlastPart.text += event.delta;\n\t\t\t\t\t\t\toptions?.onEvent?.({\n\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\tcontent: currentItem.summary.map((s) => s.text).join(\"\\n\\n\"),\n\t\t\t\t\t\t\t\tdelta: event.delta,\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 (currentItem && currentItem.type === \"reasoning\") {\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\tlastPart.text += \"\\n\\n\";\n\t\t\t\t\t\t\toptions?.onEvent?.({\n\t\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\t\tcontent: currentItem.summary.map((s) => s.text).join(\"\\n\\n\"),\n\t\t\t\t\t\t\t\tdelta: \"\\n\\n\",\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\") {\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\tlastPart.text += event.delta;\n\t\t\t\t\t\t\toptions?.onEvent?.({\n\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\tcontent: currentItem.content\n\t\t\t\t\t\t\t\t\t.map((c) => (c.type === \"output_text\" ? c.text : c.refusal))\n\t\t\t\t\t\t\t\t\t.join(\"\"),\n\t\t\t\t\t\t\t\tdelta: event.delta,\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\") {\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\tlastPart.refusal += event.delta;\n\t\t\t\t\t\t\toptions?.onEvent?.({\n\t\t\t\t\t\t\t\ttype: \"text_delta\",\n\t\t\t\t\t\t\t\tcontent: currentItem.content\n\t\t\t\t\t\t\t\t\t.map((c) => (c.type === \"output_text\" ? c.text : c.refusal))\n\t\t\t\t\t\t\t\t\t.join(\"\"),\n\t\t\t\t\t\t\t\tdelta: event.delta,\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\") {\n\t\t\t\t\t\toutputItems[outputItems.length - 1] = item; // Update with final item\n\t\t\t\t\t\tconst thinkingContent = item.summary?.map((s) => s.text).join(\"\\n\\n\") || \"\";\n\t\t\t\t\t\toptions?.onEvent?.({ type: \"thinking_end\", content: thinkingContent });\n\t\t\t\t\t} else if (item.type === \"message\") {\n\t\t\t\t\t\toutputItems[outputItems.length - 1] = item; // Update with final item\n\t\t\t\t\t\tconst textContent = item.content.map((c) => (c.type === \"output_text\" ? c.text : c.refusal)).join(\"\");\n\t\t\t\t\t\toptions?.onEvent?.({ type: \"text_end\", content: textContent });\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\toptions?.onEvent?.({ type: \"toolCall\", toolCall });\n\t\t\t\t\t\toutputItems.push(item);\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(this.modelInfo, output.usage);\n\t\t\t\t\t// Map status to stop reason\n\t\t\t\t\toutput.stopReason = this.mapStopReason(response?.status);\n\t\t\t\t\tif (outputItems.some((b) => b.type === \"function_call\") && 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\toptions?.onEvent?.({ type: \"error\", error: output.error });\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\toptions?.onEvent?.({ type: \"error\", error: output.error });\n\t\t\t\t\treturn output;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Convert output items to blocks\n\t\t\tfor (const item of outputItems) {\n\t\t\t\tif (item.type === \"reasoning\") {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"thinking\",\n\t\t\t\t\t\tthinking: item.summary?.map((s: any) => s.text).join(\"\\n\\n\") || \"\",\n\t\t\t\t\t\tthinkingSignature: JSON.stringify(item), // Full item for resubmission\n\t\t\t\t\t});\n\t\t\t\t} else if (item.type === \"message\") {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: item.content.map((c) => (c.type === \"output_text\" ? c.text : c.refusal)).join(\"\"),\n\t\t\t\t\t\ttextSignature: item.id, // ID for resubmission\n\t\t\t\t\t});\n\t\t\t\t} else if (item.type === \"function_call\") {\n\t\t\t\t\toutput.content.push({\n\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\tid: item.call_id + \"|\" + item.id,\n\t\t\t\t\t\tname: item.name,\n\t\t\t\t\t\targuments: JSON.parse(item.arguments),\n\t\t\t\t\t});\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\toptions?.onEvent?.({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\treturn output;\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\toptions?.onEvent?.({ type: \"error\", error: output.error });\n\t\t\treturn output;\n\t\t}\n\t}\n\n\tprivate convertToInput(messages: Message[], systemPrompt?: string): ResponseInput {\n\t\tconst input: ResponseInput = [];\n\n\t\t// Transform messages for cross-provider compatibility\n\t\tconst transformedMessages = transformMessages(messages, this.modelInfo, this.getApi());\n\n\t\t// Add system prompt if provided\n\t\tif (systemPrompt) {\n\t\t\tconst role = this.modelInfo?.reasoning ? \"developer\" : \"system\";\n\t\t\tinput.push({\n\t\t\t\trole,\n\t\t\t\tcontent: systemPrompt,\n\t\t\t});\n\t\t}\n\n\t\t// Convert messages\n\t\tfor (const msg of transformedMessages) {\n\t\t\tif (msg.role === \"user\") {\n\t\t\t\t// Handle both string and array content\n\t\t\t\tif (typeof msg.content === \"string\") {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"input_text\", text: msg.content }],\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\t// Convert array content to OpenAI Responses format\n\t\t\t\t\tconst content: ResponseInputContent[] = msg.content.map((item): ResponseInputContent => {\n\t\t\t\t\t\tif (item.type === \"text\") {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: \"input_text\",\n\t\t\t\t\t\t\t\ttext: item.text,\n\t\t\t\t\t\t\t} satisfies ResponseInputText;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Image content - OpenAI Responses uses data URLs\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: \"input_image\",\n\t\t\t\t\t\t\t\tdetail: \"auto\",\n\t\t\t\t\t\t\t\timage_url: `data:${item.mimeType};base64,${item.data}`,\n\t\t\t\t\t\t\t} satisfies ResponseInputImage;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tconst filteredContent = !this.modelInfo?.input.includes(\"image\")\n\t\t\t\t\t\t? content.filter((c) => c.type !== \"input_image\")\n\t\t\t\t\t\t: content;\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: filteredContent,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else if (msg.role === \"assistant\") {\n\t\t\t\t// Process content blocks in order\n\t\t\t\tconst output: ResponseInput = [];\n\n\t\t\t\tfor (const block of msg.content) {\n\t\t\t\t\t// Do not submit thinking blocks if the completion had an error (i.e. abort)\n\t\t\t\t\tif (block.type === \"thinking\" && msg.stopReason !== \"error\") {\n\t\t\t\t\t\t// Push the full reasoning item(s) from signature\n\t\t\t\t\t\tif (block.thinkingSignature) {\n\t\t\t\t\t\t\tconst reasoningItem = JSON.parse(block.thinkingSignature);\n\t\t\t\t\t\t\toutput.push(reasoningItem);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (block.type === \"text\") {\n\t\t\t\t\t\tconst textBlock = block as TextContent;\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\ttype: \"message\",\n\t\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\t\tcontent: [{ type: \"output_text\", text: textBlock.text, annotations: [] }],\n\t\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\t\tid: textBlock.textSignature || \"msg_\" + Math.random().toString(36).substring(2, 15),\n\t\t\t\t\t\t} satisfies ResponseOutputMessage);\n\t\t\t\t\t\t// Do not submit thinking blocks if the completion had an error (i.e. abort)\n\t\t\t\t\t} else if (block.type === \"toolCall\" && msg.stopReason !== \"error\") {\n\t\t\t\t\t\tconst toolCall = block as ToolCall;\n\t\t\t\t\t\toutput.push({\n\t\t\t\t\t\t\ttype: \"function_call\",\n\t\t\t\t\t\t\tid: toolCall.id.split(\"|\")[1], // Extract original ID\n\t\t\t\t\t\t\tcall_id: toolCall.id.split(\"|\")[0], // Extract call session ID\n\t\t\t\t\t\t\tname: toolCall.name,\n\t\t\t\t\t\t\targuments: JSON.stringify(toolCall.arguments),\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Add all output items to input\n\t\t\t\tinput.push(...output);\n\t\t\t} else if (msg.role === \"toolResult\") {\n\t\t\t\t// Tool results are sent as function_call_output\n\t\t\t\tinput.push({\n\t\t\t\t\ttype: \"function_call_output\",\n\t\t\t\t\tcall_id: msg.toolCallId.split(\"|\")[0], // Extract call session ID\n\t\t\t\t\toutput: msg.content,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn input;\n\t}\n\n\tprivate convertTools(tools: Tool[]): OpenAITool[] {\n\t\treturn tools.map((tool) => ({\n\t\t\ttype: \"function\",\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: tool.parameters,\n\t\t\tstrict: null,\n\t\t}));\n\t}\n\n\tprivate mapStopReason(status: string | undefined): StopReason {\n\t\tswitch (status) {\n\t\t\tcase \"completed\":\n\t\t\t\treturn \"stop\";\n\t\t\tcase \"incomplete\":\n\t\t\t\treturn \"length\";\n\t\t\tcase \"failed\":\n\t\t\tcase \"cancelled\":\n\t\t\t\treturn \"error\";\n\t\t\tdefault:\n\t\t\t\treturn \"stop\";\n\t\t}\n\t}\n}\n"]}
@@ -11,5 +11,5 @@ import type { Message, Model } from "../types.js";
11
11
  * @param model The target model that will process these messages
12
12
  * @returns A copy of the messages array with transformations applied
13
13
  */
14
- export declare function transformMessages(messages: Message[], model: Model): Message[];
14
+ export declare function transformMessages(messages: Message[], model: Model, api: string): Message[];
15
15
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpE;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,EAAE,CAuC9E"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpE;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,EAAE,CAuC3F"}
@@ -10,7 +10,7 @@
10
10
  * @param model The target model that will process these messages
11
11
  * @returns A copy of the messages array with transformations applied
12
12
  */
13
- export function transformMessages(messages, model) {
13
+ export function transformMessages(messages, model, api) {
14
14
  return messages.map((msg) => {
15
15
  // User and toolResult messages pass through unchanged
16
16
  if (msg.role === "user" || msg.role === "toolResult") {
@@ -19,8 +19,8 @@ export function transformMessages(messages, model) {
19
19
  // Assistant messages need transformation check
20
20
  if (msg.role === "assistant") {
21
21
  const assistantMsg = msg;
22
- // If message is from the same provider and model, keep as-is
23
- if (assistantMsg.provider === model.provider && assistantMsg.model === model.id) {
22
+ // If message is from the same provider and API, keep as is
23
+ if (assistantMsg.provider === model.provider && assistantMsg.api === api) {
24
24
  return msg;
25
25
  }
26
26
  // Transform message from different provider/model
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAmB,EAAE,KAAY;IAClE,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,6DAA6D;YAC7D,IAAI,YAAY,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,IAAI,YAAY,CAAC,KAAK,KAAK,KAAK,CAAC,EAAE,EAAE,CAAC;gBACjF,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;QAED,qDAAqD;QACrD,OAAO,GAAG,CAAC;IACZ,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { AssistantMessage, Message, Model } from \"../types.js\";\n\n/**\n * Transform messages for cross-provider compatibility.\n *\n * - User and toolResult messages are copied verbatim\n * - Assistant messages:\n * - If from the same provider/model, copied as-is\n * - If from different provider/model, thinking blocks are converted to text blocks with <thinking></thinking> tags\n *\n * @param messages The messages to transform\n * @param model The target model that will process these messages\n * @returns A copy of the messages array with transformations applied\n */\nexport function transformMessages(messages: Message[], model: Model): 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 model, keep as-is\n\t\t\tif (assistantMsg.provider === model.provider && assistantMsg.model === model.id) {\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\n\t\t// Should not reach here, but return as-is for safety\n\t\treturn msg;\n\t});\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAmB,EAAE,KAAY,EAAE,GAAW;IAC/E,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,GAAG,EAAE,CAAC;gBAC1E,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;QAED,qDAAqD;QACrD,OAAO,GAAG,CAAC;IACZ,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { AssistantMessage, Message, Model } from \"../types.js\";\n\n/**\n * Transform messages for cross-provider compatibility.\n *\n * - User and toolResult messages are copied verbatim\n * - Assistant messages:\n * - If from the same provider/model, copied as-is\n * - If from different provider/model, thinking blocks are converted to text blocks with <thinking></thinking> tags\n *\n * @param messages The messages to transform\n * @param model The target model that will process these messages\n * @returns A copy of the messages array with transformations applied\n */\nexport function transformMessages(messages: Message[], model: Model, api: string): 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 === 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\n\t\t// Should not reach here, but return as-is for safety\n\t\treturn msg;\n\t});\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface LLMOptions {
7
7
  export interface LLM<T extends LLMOptions> {
8
8
  generate(request: Context, options?: T): Promise<AssistantMessage>;
9
9
  getModel(): Model;
10
+ getApi(): string;
10
11
  }
11
12
  export interface TextContent {
12
13
  type: "text";
@@ -50,6 +51,7 @@ export interface UserMessage {
50
51
  export interface AssistantMessage {
51
52
  role: "assistant";
52
53
  content: (TextContent | ThinkingContent | ToolCall)[];
54
+ api: string;
53
55
  provider: string;
54
56
  model: string;
55
57
  usage: Usage;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACjD,MAA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,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACtD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,GAC/D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAGpC,MAAM,WAAW,KAAK;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IAC5B,IAAI,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CAClB"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface LLMOptions {\n\ttemperature?: number;\n\tmaxTokens?: number;\n\tonEvent?: (event: AssistantMessageEvent) => void;\n\tsignal?: AbortSignal;\n}\n\nexport interface LLM<T extends LLMOptions> {\n\tgenerate(request: Context, options?: T): Promise<AssistantMessage>;\n\tgetModel(): Model;\n}\n\nexport interface TextContent {\n\ttype: \"text\";\n\ttext: string;\n\ttextSignature?: string; // e.g., for OpenAI responses, the message ID\n}\n\nexport interface ThinkingContent {\n\ttype: \"thinking\";\n\tthinking: string;\n\tthinkingSignature?: string; // e.g., for OpenAI responses, the reasoning item ID\n}\n\nexport interface ImageContent {\n\ttype: \"image\";\n\tdata: string; // base64 encoded image data\n\tmimeType: string; // e.g., \"image/jpeg\", \"image/png\"\n}\n\nexport interface ToolCall {\n\ttype: \"toolCall\";\n\tid: string;\n\tname: string;\n\targuments: Record<string, any>;\n}\n\nexport interface Usage {\n\tinput: number;\n\toutput: number;\n\tcacheRead: number;\n\tcacheWrite: number;\n\tcost: {\n\t\tinput: number;\n\t\toutput: number;\n\t\tcacheRead: number;\n\t\tcacheWrite: number;\n\t\ttotal: number;\n\t};\n}\n\nexport type StopReason = \"stop\" | \"length\" | \"toolUse\" | \"safety\" | \"error\";\n\nexport interface UserMessage {\n\trole: \"user\";\n\tcontent: string | (TextContent | ImageContent)[];\n}\n\nexport interface AssistantMessage {\n\trole: \"assistant\";\n\tcontent: (TextContent | ThinkingContent | ToolCall)[];\n\tprovider: string;\n\tmodel: string;\n\tusage: Usage;\n\n\tstopReason: StopReason;\n\terror?: string | Error;\n}\n\nexport interface ToolResultMessage {\n\trole: \"toolResult\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tcontent: string;\n\tisError: boolean;\n}\n\nexport type Message = UserMessage | AssistantMessage | ToolResultMessage;\n\nexport interface Tool {\n\tname: string;\n\tdescription: string;\n\tparameters: Record<string, any>; // JSON Schema\n}\n\nexport interface Context {\n\tsystemPrompt?: string;\n\tmessages: Message[];\n\ttools?: Tool[];\n}\n\nexport type AssistantMessageEvent =\n\t| { type: \"start\"; model: string; provider: string }\n\t| { type: \"text_start\" }\n\t| { type: \"text_delta\"; content: string; delta: string }\n\t| { type: \"text_end\"; content: string }\n\t| { type: \"thinking_start\" }\n\t| { type: \"thinking_delta\"; content: string; delta: string }\n\t| { type: \"thinking_end\"; content: string }\n\t| { type: \"toolCall\"; toolCall: ToolCall }\n\t| { type: \"done\"; reason: StopReason; message: AssistantMessage }\n\t| { type: \"error\"; error: string };\n\n// Model interface for the unified model system\nexport interface Model {\n\tid: string;\n\tname: string;\n\tprovider: string;\n\tbaseUrl?: string;\n\treasoning: boolean;\n\tinput: (\"text\" | \"image\")[];\n\tcost: {\n\t\tinput: number; // $/million tokens\n\t\toutput: number; // $/million tokens\n\t\tcacheRead: number; // $/million tokens\n\t\tcacheWrite: number; // $/million tokens\n\t};\n\tcontextWindow: number;\n\tmaxTokens: number;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface LLMOptions {\n\ttemperature?: number;\n\tmaxTokens?: number;\n\tonEvent?: (event: AssistantMessageEvent) => void;\n\tsignal?: AbortSignal;\n}\n\nexport interface LLM<T extends LLMOptions> {\n\tgenerate(request: Context, options?: T): Promise<AssistantMessage>;\n\tgetModel(): Model;\n\tgetApi(): string;\n}\n\nexport interface TextContent {\n\ttype: \"text\";\n\ttext: string;\n\ttextSignature?: string; // e.g., for OpenAI responses, the message ID\n}\n\nexport interface ThinkingContent {\n\ttype: \"thinking\";\n\tthinking: string;\n\tthinkingSignature?: string; // e.g., for OpenAI responses, the reasoning item ID\n}\n\nexport interface ImageContent {\n\ttype: \"image\";\n\tdata: string; // base64 encoded image data\n\tmimeType: string; // e.g., \"image/jpeg\", \"image/png\"\n}\n\nexport interface ToolCall {\n\ttype: \"toolCall\";\n\tid: string;\n\tname: string;\n\targuments: Record<string, any>;\n}\n\nexport interface Usage {\n\tinput: number;\n\toutput: number;\n\tcacheRead: number;\n\tcacheWrite: number;\n\tcost: {\n\t\tinput: number;\n\t\toutput: number;\n\t\tcacheRead: number;\n\t\tcacheWrite: number;\n\t\ttotal: number;\n\t};\n}\n\nexport type StopReason = \"stop\" | \"length\" | \"toolUse\" | \"safety\" | \"error\";\n\nexport interface UserMessage {\n\trole: \"user\";\n\tcontent: string | (TextContent | ImageContent)[];\n}\n\nexport interface AssistantMessage {\n\trole: \"assistant\";\n\tcontent: (TextContent | ThinkingContent | ToolCall)[];\n\tapi: string;\n\tprovider: string;\n\tmodel: string;\n\tusage: Usage;\n\n\tstopReason: StopReason;\n\terror?: string | Error;\n}\n\nexport interface ToolResultMessage {\n\trole: \"toolResult\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tcontent: string;\n\tisError: boolean;\n}\n\nexport type Message = UserMessage | AssistantMessage | ToolResultMessage;\n\nexport interface Tool {\n\tname: string;\n\tdescription: string;\n\tparameters: Record<string, any>; // JSON Schema\n}\n\nexport interface Context {\n\tsystemPrompt?: string;\n\tmessages: Message[];\n\ttools?: Tool[];\n}\n\nexport type AssistantMessageEvent =\n\t| { type: \"start\"; model: string; provider: string }\n\t| { type: \"text_start\" }\n\t| { type: \"text_delta\"; content: string; delta: string }\n\t| { type: \"text_end\"; content: string }\n\t| { type: \"thinking_start\" }\n\t| { type: \"thinking_delta\"; content: string; delta: string }\n\t| { type: \"thinking_end\"; content: string }\n\t| { type: \"toolCall\"; toolCall: ToolCall }\n\t| { type: \"done\"; reason: StopReason; message: AssistantMessage }\n\t| { type: \"error\"; error: string };\n\n// Model interface for the unified model system\nexport interface Model {\n\tid: string;\n\tname: string;\n\tprovider: string;\n\tbaseUrl?: string;\n\treasoning: boolean;\n\tinput: (\"text\" | \"image\")[];\n\tcost: {\n\t\tinput: number; // $/million tokens\n\t\toutput: number; // $/million tokens\n\t\tcacheRead: number; // $/million tokens\n\t\tcacheWrite: number; // $/million tokens\n\t};\n\tcontextWindow: number;\n\tmaxTokens: number;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mariozechner/pi-ai",
3
- "version": "0.5.24",
3
+ "version": "0.5.26",
4
4
  "description": "Unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",