@howaboua/pi-codex-conversion 1.0.24 → 1.0.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-codex-conversion",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "Codex-oriented tool and prompt adapter for pi coding agent",
5
5
  "type": "module",
6
6
  "repository": {
@@ -8,12 +8,10 @@ type Message = Context["messages"][number];
8
8
 
9
9
  interface ImageGenerationCallItem {
10
10
  type: "image_generation_call";
11
- id?: string;
12
- status?: string;
13
- result?: string | null;
14
- output_format?: string;
11
+ id: string;
12
+ status: string;
13
+ result: string | null;
15
14
  revised_prompt?: string;
16
- [key: string]: unknown;
17
15
  }
18
16
 
19
17
  interface ImageGenerationCallBlock {
@@ -76,6 +74,23 @@ function isImageGenerationCallBlock(block: InternalAssistantContent): block is I
76
74
  return block.type === "image_generation_call" && block.item?.type === "image_generation_call";
77
75
  }
78
76
 
77
+ function sanitizeImageGenerationCallItem(item: unknown): ImageGenerationCallItem | undefined {
78
+ if (!item || typeof item !== "object") return undefined;
79
+ const candidate = item as Record<string, unknown>;
80
+ if (candidate.type !== "image_generation_call") return undefined;
81
+ if (typeof candidate.id !== "string" || candidate.id === "") return undefined;
82
+ if (typeof candidate.status !== "string" || candidate.status === "") return undefined;
83
+ if (!(typeof candidate.result === "string" || candidate.result === null)) return undefined;
84
+
85
+ return {
86
+ type: "image_generation_call",
87
+ id: candidate.id,
88
+ status: candidate.status,
89
+ result: candidate.result,
90
+ ...(typeof candidate.revised_prompt === "string" ? { revised_prompt: candidate.revised_prompt } : {}),
91
+ };
92
+ }
93
+
79
94
  const NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
80
95
  const NON_VISION_TOOL_IMAGE_PLACEHOLDER = "(tool image omitted: model does not support images)";
81
96
 
@@ -287,7 +302,8 @@ export function convertResponsesMessages<TApi extends Api>(
287
302
  let assistantBlockIndex = 0;
288
303
  for (const block of msg.content as InternalAssistantContent[]) {
289
304
  if (isImageGenerationCallBlock(block)) {
290
- output.push(block.item as ResponseInput[number]);
305
+ const imageGenerationCall = sanitizeImageGenerationCallItem(block.item);
306
+ if (imageGenerationCall) output.push(imageGenerationCall as ResponseInput[number]);
291
307
  } else if (block.type === "thinking") {
292
308
  if (block.thinkingSignature) output.push(JSON.parse(block.thinkingSignature));
293
309
  } else if (block.type === "text") {
@@ -581,10 +597,13 @@ export async function processResponsesStream<TApi extends Api>(
581
597
  stream.push({ type: "toolcall_end", contentIndex: toolCallIndex, toolCall, partial: output });
582
598
  outputStates.delete(event.output_index);
583
599
  } else if (item.type === "image_generation_call") {
584
- (output.content as InternalAssistantContent[]).push({
585
- type: "image_generation_call",
586
- item: item as ImageGenerationCallItem,
587
- });
600
+ const imageGenerationCall = sanitizeImageGenerationCallItem(item);
601
+ if (imageGenerationCall) {
602
+ (output.content as InternalAssistantContent[]).push({
603
+ type: "image_generation_call",
604
+ item: imageGenerationCall,
605
+ });
606
+ }
588
607
  outputStates.delete(event.output_index);
589
608
  }
590
609
  } else if (event.type === "response.completed") {