@demicodes/provider-openai-api 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -25,6 +25,13 @@ interface OpenAIApiRequestOptions {
25
25
  maxRetries?: number;
26
26
  streamOptions?: Record<string, unknown> | null;
27
27
  extraBody?: Record<string, unknown>;
28
+ /**
29
+ * Emit `status: 'completed'` on replayed assistant messages. Gateways that validate
30
+ * input against the full Responses item schema require it — Volcengine Ark rejects the
31
+ * item with `missing input.status` — while relay bridges reject it as an unknown
32
+ * parameter, so it stays off unless the provider opts in.
33
+ */
34
+ replayAssistantStatus?: boolean;
28
35
  }
29
36
  type OpenAIApiWireApi = 'responses' | 'chat-completions';
30
37
  interface OpenAIApiProviderOptions {
package/dist/index.mjs CHANGED
@@ -266,7 +266,7 @@ function createOpenAIApiProvider(options = {}) {
266
266
  function buildOpenAIResponsesBody(request, options) {
267
267
  const body = {
268
268
  model: request.modelId,
269
- input: request.items.flatMap((item, index) => inferenceItemToOpenAIResponseInput(item, index)),
269
+ input: request.items.flatMap((item, index) => inferenceItemToOpenAIResponseInput(item, index, options)),
270
270
  stream: true,
271
271
  store: false,
272
272
  include: ["reasoning.encrypted_content"],
@@ -544,14 +544,29 @@ function inferenceItemsToOpenAIMessages(systemPrompt, items) {
544
544
  }
545
545
  });
546
546
  break;
547
- case "tool_result":
547
+ case "tool_result": {
548
548
  flushAssistant();
549
549
  messages.push({
550
550
  role: "tool",
551
551
  tool_call_id: item.toolUseId,
552
552
  content: toolResultContentToText(item.output)
553
553
  });
554
+ const media = item.output.filter((block) => block.type !== "text");
555
+ if (media.length > 0) messages.push({
556
+ role: "user",
557
+ content: [{
558
+ type: "text",
559
+ text: `[media returned by tool call ${item.toolUseId}]`
560
+ }, ...media.map((block) => ({
561
+ type: "image_url",
562
+ image_url: {
563
+ url: `data:${block.source.mediaType};base64,${block.source.data}`,
564
+ detail: "auto"
565
+ }
566
+ }))]
567
+ });
554
568
  break;
569
+ }
555
570
  case "assistant_thinking":
556
571
  case "assistant_redacted_thinking": break;
557
572
  }
@@ -630,7 +645,7 @@ function* flushOpenAIToolCalls(toolCalls) {
630
645
  }
631
646
  toolCalls.clear();
632
647
  }
633
- function inferenceItemToOpenAIResponseInput(item, index) {
648
+ function inferenceItemToOpenAIResponseInput(item, index, options) {
634
649
  switch (item.type) {
635
650
  case "user_message":
636
651
  case "user_steer": return [{
@@ -640,6 +655,7 @@ function inferenceItemToOpenAIResponseInput(item, index) {
640
655
  case "assistant_text": return [{
641
656
  type: "message",
642
657
  role: "assistant",
658
+ ...options?.replayAssistantStatus ? { status: "completed" } : {},
643
659
  content: [{
644
660
  type: "output_text",
645
661
  text: item.text,
@@ -668,7 +684,7 @@ function inferenceItemToOpenAIResponseInput(item, index) {
668
684
  call_id: callId,
669
685
  output: toolResultContentToText(item.output)
670
686
  }];
671
- const images = item.output.filter((block) => block.type === "image");
687
+ const images = item.output.filter((block) => block.type !== "text");
672
688
  if (images.length > 0) items.push({
673
689
  role: "user",
674
690
  content: [{
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@demicodes/provider-openai-api",
3
3
  "description": "OpenAI API provider adapter for Demi.",
4
- "version": "0.7.1",
4
+ "version": "0.8.0",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "exports": {
@@ -11,9 +11,9 @@
11
11
  }
12
12
  },
13
13
  "dependencies": {
14
- "@demicodes/core": "^0.7.1",
15
- "@demicodes/provider": "^0.7.1",
16
- "@demicodes/utils": "^0.7.1"
14
+ "@demicodes/core": "^0.8.0",
15
+ "@demicodes/provider": "^0.8.0",
16
+ "@demicodes/utils": "^0.8.0"
17
17
  },
18
18
  "license": "Apache-2.0",
19
19
  "main": "./dist/index.mjs",