@zhivex-ai/openai 0.8.1 → 0.9.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/README.md +63 -0
- package/dist/image-generation.d.ts +109 -0
- package/dist/image-generation.d.ts.map +1 -0
- package/dist/image-generation.js +343 -0
- package/dist/image-generation.js.map +1 -0
- package/dist/index.d.ts +52 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +347 -18
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -67,6 +67,69 @@ Multi-turn Responses normally continue through `previous_response_id`. With `pro
|
|
|
67
67
|
|
|
68
68
|
Use `providerOptions.safety_identifier` for a stable, non-PII identifier for the end user. It is sent as an OpenAI request field; do not put email addresses, names, or other direct personal data in it.
|
|
69
69
|
|
|
70
|
+
## GPT Image 2 and hosted image generation
|
|
71
|
+
|
|
72
|
+
Use the shared image contract for direct Image API generations. `gpt-image-2` supports the current square, portrait, landscape, and wide output sizes exposed by OpenAI. See the official [GPT Image 2 model page](https://developers.openai.com/api/docs/models/gpt-image-2) and [image generation guide](https://developers.openai.com/api/docs/guides/image-generation).
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { generateImage } from "@zhivex-ai/core";
|
|
76
|
+
import { createOpenAI } from "@zhivex-ai/openai";
|
|
77
|
+
|
|
78
|
+
const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
|
79
|
+
|
|
80
|
+
const result = await generateImage({
|
|
81
|
+
model: openai.imageGenerationModel!("gpt-image-2"),
|
|
82
|
+
prompt: "A clean editorial illustration of a distributed system",
|
|
83
|
+
aspectRatio: "16:9",
|
|
84
|
+
outputMimeType: "image/webp",
|
|
85
|
+
providerOptions: {
|
|
86
|
+
quality: "high"
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
console.log(result.images[0]?.mediaType);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
For conversational generation, edits, reference images, or progressive previews, use the provider-hosted Responses tool. Buffered and collected text calls expose final media on `result.steps.at(-1)?.response.images`; streaming calls emit typed `image-generation` events:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { streamText } from "@zhivex-ai/core";
|
|
97
|
+
import {
|
|
98
|
+
openAIImageGenerationTool,
|
|
99
|
+
openAIImageGenerationToolChoice
|
|
100
|
+
} from "@zhivex-ai/openai";
|
|
101
|
+
|
|
102
|
+
const stream = await streamText({
|
|
103
|
+
model: openai("gpt-5.6"),
|
|
104
|
+
prompt: "Generate a wide product concept, then refine its lighting.",
|
|
105
|
+
tools: {
|
|
106
|
+
image: openAIImageGenerationTool({
|
|
107
|
+
action: "auto",
|
|
108
|
+
output_format: "webp",
|
|
109
|
+
partial_images: 2,
|
|
110
|
+
size: "1536x864"
|
|
111
|
+
})
|
|
112
|
+
},
|
|
113
|
+
providerOptions: {
|
|
114
|
+
tool_choice: openAIImageGenerationToolChoice()
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
for await (const event of stream) {
|
|
119
|
+
if (event.type === "image-generation") {
|
|
120
|
+
console.log(event.partial, event.image.mediaType, event.image.data?.byteLength);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Partial images are transient live stream events: they are not copied into collected messages or replayed to consumers that subscribe after generation. The shared `ImageGenerationModel` path is buffered; use the Responses tool when you need partial-image streaming or image edits.
|
|
126
|
+
|
|
127
|
+
## Realtime 2.1 and remote MCP
|
|
128
|
+
|
|
129
|
+
`gpt-realtime-2.1` and `gpt-realtime-2.1-mini` use the GA Realtime tool shape and support image input. A stable `providerOptions.safety_identifier` is sent as the `OpenAI-Safety-Identifier` header for both server WebSocket sessions and browser client-secret creation.
|
|
130
|
+
|
|
131
|
+
Remote MCP lifecycle, calls, failures, and approval requests arrive as `realtime-provider-data` events so provider-executed MCP is not confused with an app-executed function tool. Return an approval with `openAIRealtimeMcpApprovalResult()` through `session.sendToolResult()`. See OpenAI's [Realtime MCP guide](https://developers.openai.com/api/docs/guides/realtime-mcp).
|
|
132
|
+
|
|
70
133
|
## Prompt caching
|
|
71
134
|
|
|
72
135
|
OpenAI prompt cache controls pass through `providerOptions`. Explicit breakpoints can be attached directly to a cacheable text, image, or file part through `providerMetadata`, or inserted immediately after a cacheable part with `openAIPromptCacheBreakpoint()`.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type GeneratedMedia, type ImageGenerationModel, type ImageGenerationModelInput, type ImageGenerationResult, type JsonValue, type ModelCapabilities } from "@zhivex-ai/core";
|
|
2
|
+
export type OpenAIImageOutputFormat = "png" | "jpeg" | "webp";
|
|
3
|
+
export type OpenAIImageSize = "auto" | `${number}x${number}`;
|
|
4
|
+
export type OpenAIImageQuality = "auto" | "low" | "medium" | "high" | "standard" | "hd";
|
|
5
|
+
export type OpenAIImageGenerationOptions = Record<string, unknown> & {
|
|
6
|
+
background?: "auto" | "opaque" | "transparent";
|
|
7
|
+
moderation?: "auto" | "low";
|
|
8
|
+
output_compression?: number;
|
|
9
|
+
output_format?: OpenAIImageOutputFormat;
|
|
10
|
+
quality?: OpenAIImageQuality;
|
|
11
|
+
response_format?: "url" | "b64_json";
|
|
12
|
+
style?: "vivid" | "natural";
|
|
13
|
+
user?: string;
|
|
14
|
+
/** Extra HTTP headers. Authorization and content-type remain SDK-controlled. */
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
/** Maximum JSON response size, including base64 image data. Defaults to 128 MiB. */
|
|
17
|
+
responseMaxBytes?: number;
|
|
18
|
+
/** Maximum error response body retained for diagnostics. Defaults to 64 KiB. */
|
|
19
|
+
errorBodyMaxBytes?: number;
|
|
20
|
+
/** Streaming belongs to the Responses/Image streaming APIs, not ImageGenerationModel. */
|
|
21
|
+
stream?: false;
|
|
22
|
+
partial_images?: never;
|
|
23
|
+
};
|
|
24
|
+
export interface OpenAIImageGenerationToolConfig {
|
|
25
|
+
action?: "auto" | "generate" | "edit";
|
|
26
|
+
background?: "auto" | "opaque" | "transparent";
|
|
27
|
+
input_fidelity?: "low" | "high";
|
|
28
|
+
output_compression?: number;
|
|
29
|
+
output_format?: OpenAIImageOutputFormat;
|
|
30
|
+
partial_images?: 0 | 1 | 2 | 3;
|
|
31
|
+
quality?: "auto" | "low" | "medium" | "high";
|
|
32
|
+
size?: OpenAIImageSize;
|
|
33
|
+
}
|
|
34
|
+
export interface OpenAIImageGenerationToolChoice {
|
|
35
|
+
type: "image_generation";
|
|
36
|
+
}
|
|
37
|
+
export interface OpenAIImageGenerationModelConfig {
|
|
38
|
+
modelId: string;
|
|
39
|
+
apiKey: string;
|
|
40
|
+
baseURL?: string;
|
|
41
|
+
fetch?: typeof globalThis.fetch;
|
|
42
|
+
responseMaxBytes?: number;
|
|
43
|
+
errorBodyMaxBytes?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface OpenAIImageGenerationCall {
|
|
46
|
+
type: "image_generation_call";
|
|
47
|
+
id?: string;
|
|
48
|
+
status?: string;
|
|
49
|
+
revised_prompt?: string | null;
|
|
50
|
+
result?: string | null;
|
|
51
|
+
output_format?: OpenAIImageOutputFormat;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
export interface NormalizedOpenAIImageGenerationCall {
|
|
55
|
+
id?: string;
|
|
56
|
+
status?: string;
|
|
57
|
+
revisedPrompt?: string;
|
|
58
|
+
image?: GeneratedMedia;
|
|
59
|
+
providerMetadata: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
export type OpenAIImageGenerationPartialImageEvent = {
|
|
62
|
+
type: "response.image_generation_call.partial_image";
|
|
63
|
+
partial_image_b64: string;
|
|
64
|
+
partial_image_index: number;
|
|
65
|
+
item_id?: string;
|
|
66
|
+
output_index?: number;
|
|
67
|
+
sequence_number?: number;
|
|
68
|
+
output_format?: OpenAIImageOutputFormat;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
} | {
|
|
71
|
+
type: "image_generation.partial_image";
|
|
72
|
+
b64_json: string;
|
|
73
|
+
partial_image_index: number;
|
|
74
|
+
output_format?: OpenAIImageOutputFormat;
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
};
|
|
77
|
+
export interface NormalizedOpenAIImageGenerationPartialImage {
|
|
78
|
+
source: "responses" | "images";
|
|
79
|
+
callId?: string;
|
|
80
|
+
partialImageIndex: number;
|
|
81
|
+
outputIndex?: number;
|
|
82
|
+
sequenceNumber?: number;
|
|
83
|
+
image: GeneratedMedia;
|
|
84
|
+
providerMetadata: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
/** Creates the hosted Responses API image_generation tool definition. */
|
|
87
|
+
export declare const openAIImageGenerationTool: (config?: OpenAIImageGenerationToolConfig) => import("@zhivex-ai/core").HostedToolDefinition<JsonValue>;
|
|
88
|
+
/** Forces the hosted Responses image_generation tool for the current turn. */
|
|
89
|
+
export declare const openAIImageGenerationToolChoice: () => OpenAIImageGenerationToolChoice;
|
|
90
|
+
export declare const isOpenAIImageGenerationCall: (value: unknown) => value is OpenAIImageGenerationCall;
|
|
91
|
+
/** Decodes a Responses image_generation_call without retaining a second base64 copy in metadata. */
|
|
92
|
+
export declare const normalizeOpenAIImageGenerationCall: (value: unknown, fallbackOutputFormat?: OpenAIImageOutputFormat, maxImageBytes?: number) => NormalizedOpenAIImageGenerationCall | undefined;
|
|
93
|
+
export declare const isOpenAIImageGenerationPartialImageEvent: (value: unknown) => value is OpenAIImageGenerationPartialImageEvent;
|
|
94
|
+
/** Normalizes partial images from both Responses and the streaming Image API. */
|
|
95
|
+
export declare const normalizeOpenAIImageGenerationPartialImage: (value: unknown, fallbackOutputFormat?: OpenAIImageOutputFormat, maxImageBytes?: number) => NormalizedOpenAIImageGenerationPartialImage | undefined;
|
|
96
|
+
export declare class OpenAIImageGenerationModel implements ImageGenerationModel<OpenAIImageGenerationOptions> {
|
|
97
|
+
readonly provider = "openai";
|
|
98
|
+
readonly capabilities: ModelCapabilities;
|
|
99
|
+
readonly modelId: string;
|
|
100
|
+
private readonly apiKey;
|
|
101
|
+
private readonly baseURL;
|
|
102
|
+
private readonly fetcher;
|
|
103
|
+
private readonly responseMaxBytes;
|
|
104
|
+
private readonly errorBodyMaxBytes;
|
|
105
|
+
constructor(config: OpenAIImageGenerationModelConfig);
|
|
106
|
+
generateImage(input: ImageGenerationModelInput<OpenAIImageGenerationOptions>): Promise<ImageGenerationResult>;
|
|
107
|
+
}
|
|
108
|
+
export declare const createOpenAIImageGenerationModel: (config: OpenAIImageGenerationModelConfig) => OpenAIImageGenerationModel;
|
|
109
|
+
//# sourceMappingURL=image-generation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-generation.d.ts","sourceRoot":"","sources":["../src/image-generation.ts"],"names":[],"mappings":"AAEA,OAAO,EAWL,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;AAMzB,MAAM,MAAM,uBAAuB,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAC9D,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;AAC7D,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,IAAI,CAAC;AAExF,MAAM,MAAM,4BAA4B,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACnE,UAAU,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,aAAa,CAAC;IAC/C,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,aAAa,CAAC,EAAE,uBAAuB,CAAC;IACxC,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B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qLlC;AAED,eAAO,MAAM,gCAAgC,GAAI,QAAQ,gCAAgC,+BACjD,CAAC"}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { ParseError, ProviderHTTPError, UnsupportedFeatureError, ValidationError, decodeBase64WithLimit, hostedTool, readErrorBodyWithLimit, readJsonWithLimit, withRetry, withTimeoutSignal } from "@zhivex-ai/core";
|
|
3
|
+
const MIB = 1024 * 1024;
|
|
4
|
+
const DEFAULT_RESPONSE_MAX_BYTES = 128 * MIB;
|
|
5
|
+
const DEFAULT_ERROR_BODY_MAX_BYTES = 64 * 1024;
|
|
6
|
+
const imageGenerationCapabilities = {
|
|
7
|
+
streaming: false,
|
|
8
|
+
tools: false,
|
|
9
|
+
structuredOutput: false,
|
|
10
|
+
jsonMode: false,
|
|
11
|
+
toolChoice: false,
|
|
12
|
+
parallelToolCalls: false,
|
|
13
|
+
vision: false,
|
|
14
|
+
files: false,
|
|
15
|
+
audioInput: false,
|
|
16
|
+
audioOutput: false,
|
|
17
|
+
embeddings: false,
|
|
18
|
+
imageGeneration: true,
|
|
19
|
+
reasoning: false,
|
|
20
|
+
webSearch: false
|
|
21
|
+
};
|
|
22
|
+
const normalizePositiveLimit = (value, name) => {
|
|
23
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
24
|
+
throw new ValidationError(`The OpenAI image generation "${name}" option must be a positive safe integer.`);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
};
|
|
28
|
+
const validateIntegerRange = (value, name, minimum, maximum) => {
|
|
29
|
+
if (value === undefined) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!Number.isSafeInteger(value) || value < minimum || value > maximum) {
|
|
33
|
+
throw new ValidationError(`The OpenAI image generation "${name}" option must be an integer from ${minimum} to ${maximum}.`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const outputFormatFromMimeType = (mediaType) => {
|
|
37
|
+
if (mediaType === undefined)
|
|
38
|
+
return undefined;
|
|
39
|
+
const normalized = mediaType.trim().toLowerCase();
|
|
40
|
+
if (normalized === "image/png")
|
|
41
|
+
return "png";
|
|
42
|
+
if (normalized === "image/jpeg" || normalized === "image/jpg")
|
|
43
|
+
return "jpeg";
|
|
44
|
+
if (normalized === "image/webp")
|
|
45
|
+
return "webp";
|
|
46
|
+
throw new UnsupportedFeatureError(`Provider "openai" does not support image output MIME type "${mediaType}".`);
|
|
47
|
+
};
|
|
48
|
+
const mediaTypeFromOutputFormat = (format) => format === "jpeg" ? "image/jpeg" : format === "webp" ? "image/webp" : "image/png";
|
|
49
|
+
const normalizedModelId = (modelId) => modelId.trim().toLowerCase();
|
|
50
|
+
const isGPTImageModel = (modelId) => /^gpt-image(?:-|$)/.test(normalizedModelId(modelId));
|
|
51
|
+
const isGPTImage2Model = (modelId) => /^gpt-image-2(?:-|$)/.test(normalizedModelId(modelId));
|
|
52
|
+
const isDallE2Model = (modelId) => /^dall-e-2(?:-|$)/.test(normalizedModelId(modelId));
|
|
53
|
+
const isDallE3Model = (modelId) => /^dall-e-3(?:-|$)/.test(normalizedModelId(modelId));
|
|
54
|
+
const promptLimitForModel = (modelId) => {
|
|
55
|
+
if (isDallE2Model(modelId))
|
|
56
|
+
return 1_000;
|
|
57
|
+
if (isDallE3Model(modelId))
|
|
58
|
+
return 4_000;
|
|
59
|
+
if (isGPTImageModel(modelId))
|
|
60
|
+
return 32_000;
|
|
61
|
+
return undefined;
|
|
62
|
+
};
|
|
63
|
+
const sizeFromAspectRatio = (aspectRatio, modelId) => {
|
|
64
|
+
if (!aspectRatio)
|
|
65
|
+
return undefined;
|
|
66
|
+
const normalized = aspectRatio.replaceAll(" ", "");
|
|
67
|
+
if (isDallE2Model(modelId)) {
|
|
68
|
+
if (normalized === "1:1")
|
|
69
|
+
return "1024x1024";
|
|
70
|
+
throw new UnsupportedFeatureError(`Provider "openai" model "dall-e-2" cannot map aspect ratio "${aspectRatio}" because it only supports square output.`);
|
|
71
|
+
}
|
|
72
|
+
if (isDallE3Model(modelId)) {
|
|
73
|
+
if (normalized === "1:1")
|
|
74
|
+
return "1024x1024";
|
|
75
|
+
if (normalized === "16:9")
|
|
76
|
+
return "1792x1024";
|
|
77
|
+
if (normalized === "9:16")
|
|
78
|
+
return "1024x1792";
|
|
79
|
+
throw new UnsupportedFeatureError(`Provider "openai" cannot map aspect ratio "${aspectRatio}" to a supported size for model "dall-e-3". Pass an explicit "size" instead.`);
|
|
80
|
+
}
|
|
81
|
+
const standard = {
|
|
82
|
+
"1:1": "1024x1024",
|
|
83
|
+
"3:2": "1536x1024",
|
|
84
|
+
"2:3": "1024x1536"
|
|
85
|
+
};
|
|
86
|
+
if (standard[normalized])
|
|
87
|
+
return standard[normalized];
|
|
88
|
+
if (isGPTImage2Model(modelId)) {
|
|
89
|
+
if (normalized === "16:9")
|
|
90
|
+
return "1536x864";
|
|
91
|
+
if (normalized === "9:16")
|
|
92
|
+
return "864x1536";
|
|
93
|
+
}
|
|
94
|
+
throw new UnsupportedFeatureError(`Provider "openai" cannot map aspect ratio "${aspectRatio}" to a supported size for model "${modelId}". Pass an explicit "size" instead.`);
|
|
95
|
+
};
|
|
96
|
+
const sanitizeMetadata = (value, base64Keys) => {
|
|
97
|
+
const sanitized = { ...value };
|
|
98
|
+
for (const key of base64Keys)
|
|
99
|
+
delete sanitized[key];
|
|
100
|
+
return sanitized;
|
|
101
|
+
};
|
|
102
|
+
const validateToolConfig = (config) => {
|
|
103
|
+
validateIntegerRange(config.partial_images, "partial_images", 0, 3);
|
|
104
|
+
validateIntegerRange(config.output_compression, "output_compression", 0, 100);
|
|
105
|
+
if (config.background === "transparent" && config.output_format === "jpeg") {
|
|
106
|
+
throw new ValidationError('OpenAI image generation requires "png" or "webp" output for a transparent background.');
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
/** Creates the hosted Responses API image_generation tool definition. */
|
|
110
|
+
export const openAIImageGenerationTool = (config = {}) => {
|
|
111
|
+
validateToolConfig(config);
|
|
112
|
+
return hostedTool({
|
|
113
|
+
name: "image_generation",
|
|
114
|
+
provider: "openai",
|
|
115
|
+
type: "image_generation",
|
|
116
|
+
toolClass: "custom",
|
|
117
|
+
config: config
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
/** Forces the hosted Responses image_generation tool for the current turn. */
|
|
121
|
+
export const openAIImageGenerationToolChoice = () => ({
|
|
122
|
+
type: "image_generation"
|
|
123
|
+
});
|
|
124
|
+
export const isOpenAIImageGenerationCall = (value) => Boolean(value && typeof value === "object" && value.type === "image_generation_call");
|
|
125
|
+
/** Decodes a Responses image_generation_call without retaining a second base64 copy in metadata. */
|
|
126
|
+
export const normalizeOpenAIImageGenerationCall = (value, fallbackOutputFormat = "png", maxImageBytes) => {
|
|
127
|
+
if (!isOpenAIImageGenerationCall(value))
|
|
128
|
+
return undefined;
|
|
129
|
+
const revisedPrompt = typeof value.revised_prompt === "string" ? value.revised_prompt : undefined;
|
|
130
|
+
const outputFormat = value.output_format ?? fallbackOutputFormat;
|
|
131
|
+
const providerMetadata = sanitizeMetadata(value, ["result"]);
|
|
132
|
+
const result = typeof value.result === "string" && value.result ? value.result : undefined;
|
|
133
|
+
return {
|
|
134
|
+
id: typeof value.id === "string" ? value.id : undefined,
|
|
135
|
+
status: typeof value.status === "string" ? value.status : undefined,
|
|
136
|
+
revisedPrompt,
|
|
137
|
+
image: result
|
|
138
|
+
? {
|
|
139
|
+
data: maxImageBytes === undefined
|
|
140
|
+
? Uint8Array.from(Buffer.from(result, "base64"))
|
|
141
|
+
: decodeBase64WithLimit(result, {
|
|
142
|
+
maxBytes: maxImageBytes,
|
|
143
|
+
provider: "openai",
|
|
144
|
+
endpoint: "hosted image generation event"
|
|
145
|
+
}),
|
|
146
|
+
mediaType: mediaTypeFromOutputFormat(outputFormat),
|
|
147
|
+
text: revisedPrompt,
|
|
148
|
+
providerMetadata
|
|
149
|
+
}
|
|
150
|
+
: undefined,
|
|
151
|
+
providerMetadata
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
export const isOpenAIImageGenerationPartialImageEvent = (value) => {
|
|
155
|
+
if (!value || typeof value !== "object")
|
|
156
|
+
return false;
|
|
157
|
+
const event = value;
|
|
158
|
+
return ((event.type === "response.image_generation_call.partial_image" && typeof event.partial_image_b64 === "string") ||
|
|
159
|
+
(event.type === "image_generation.partial_image" && typeof event.b64_json === "string")) && Number.isSafeInteger(event.partial_image_index);
|
|
160
|
+
};
|
|
161
|
+
/** Normalizes partial images from both Responses and the streaming Image API. */
|
|
162
|
+
export const normalizeOpenAIImageGenerationPartialImage = (value, fallbackOutputFormat = "png", maxImageBytes) => {
|
|
163
|
+
if (!isOpenAIImageGenerationPartialImageEvent(value))
|
|
164
|
+
return undefined;
|
|
165
|
+
const isResponses = value.type === "response.image_generation_call.partial_image";
|
|
166
|
+
const base64 = isResponses ? value.partial_image_b64 : value.b64_json;
|
|
167
|
+
const providerMetadata = sanitizeMetadata(value, ["partial_image_b64", "b64_json"]);
|
|
168
|
+
return {
|
|
169
|
+
source: isResponses ? "responses" : "images",
|
|
170
|
+
callId: isResponses && typeof value.item_id === "string" ? value.item_id : undefined,
|
|
171
|
+
partialImageIndex: value.partial_image_index,
|
|
172
|
+
outputIndex: isResponses && typeof value.output_index === "number" ? value.output_index : undefined,
|
|
173
|
+
sequenceNumber: isResponses && typeof value.sequence_number === "number" ? value.sequence_number : undefined,
|
|
174
|
+
image: {
|
|
175
|
+
data: maxImageBytes === undefined
|
|
176
|
+
? Uint8Array.from(Buffer.from(base64, "base64"))
|
|
177
|
+
: decodeBase64WithLimit(base64, {
|
|
178
|
+
maxBytes: maxImageBytes,
|
|
179
|
+
provider: "openai",
|
|
180
|
+
endpoint: "hosted image generation event"
|
|
181
|
+
}),
|
|
182
|
+
mediaType: mediaTypeFromOutputFormat(value.output_format ?? fallbackOutputFormat),
|
|
183
|
+
providerMetadata
|
|
184
|
+
},
|
|
185
|
+
providerMetadata
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
export class OpenAIImageGenerationModel {
|
|
189
|
+
provider = "openai";
|
|
190
|
+
capabilities = imageGenerationCapabilities;
|
|
191
|
+
modelId;
|
|
192
|
+
apiKey;
|
|
193
|
+
baseURL;
|
|
194
|
+
fetcher;
|
|
195
|
+
responseMaxBytes;
|
|
196
|
+
errorBodyMaxBytes;
|
|
197
|
+
constructor(config) {
|
|
198
|
+
this.modelId = config.modelId;
|
|
199
|
+
this.apiKey = config.apiKey;
|
|
200
|
+
this.baseURL = (config.baseURL ?? "https://api.openai.com/v1").replace(/\/$/, "");
|
|
201
|
+
this.fetcher = config.fetch ?? globalThis.fetch;
|
|
202
|
+
this.responseMaxBytes = normalizePositiveLimit(config.responseMaxBytes ?? DEFAULT_RESPONSE_MAX_BYTES, "responseMaxBytes");
|
|
203
|
+
this.errorBodyMaxBytes = normalizePositiveLimit(config.errorBodyMaxBytes ?? DEFAULT_ERROR_BODY_MAX_BYTES, "errorBodyMaxBytes");
|
|
204
|
+
}
|
|
205
|
+
async generateImage(input) {
|
|
206
|
+
if (!input.prompt.trim()) {
|
|
207
|
+
throw new ValidationError('The OpenAI image generation "prompt" field is required.');
|
|
208
|
+
}
|
|
209
|
+
const promptLimit = promptLimitForModel(this.modelId);
|
|
210
|
+
if (promptLimit !== undefined && input.prompt.length > promptLimit) {
|
|
211
|
+
throw new ValidationError(`The OpenAI image generation prompt exceeds the ${promptLimit}-character limit for model "${this.modelId}".`);
|
|
212
|
+
}
|
|
213
|
+
if (input.images?.length) {
|
|
214
|
+
throw new UnsupportedFeatureError('Provider "openai" image generations do not accept input images. Use the Responses image_generation tool for conversational edits.');
|
|
215
|
+
}
|
|
216
|
+
if (input.negativePrompt) {
|
|
217
|
+
throw new UnsupportedFeatureError('Provider "openai" image generations do not support a separate negative prompt.');
|
|
218
|
+
}
|
|
219
|
+
validateIntegerRange(input.count, "count", 1, 10);
|
|
220
|
+
if (isDallE3Model(this.modelId) && input.count !== undefined && input.count !== 1) {
|
|
221
|
+
throw new UnsupportedFeatureError('Provider "openai" model "dall-e-3" only supports one image per request.');
|
|
222
|
+
}
|
|
223
|
+
const providerOptions = { ...(input.providerOptions ?? {}) };
|
|
224
|
+
if (providerOptions.stream !== undefined && providerOptions.stream !== false) {
|
|
225
|
+
throw new UnsupportedFeatureError('OpenAI Image API streaming is not supported through ImageGenerationModel. Use the Responses streaming API for partial images.');
|
|
226
|
+
}
|
|
227
|
+
if (providerOptions.partial_images !== undefined) {
|
|
228
|
+
throw new UnsupportedFeatureError('The OpenAI "partial_images" option requires streaming and is not supported through ImageGenerationModel.');
|
|
229
|
+
}
|
|
230
|
+
const customHeaders = providerOptions.headers;
|
|
231
|
+
if (customHeaders !== undefined && (!customHeaders || typeof customHeaders !== "object" || Array.isArray(customHeaders))) {
|
|
232
|
+
throw new ValidationError('The OpenAI image generation "headers" option must be an object.');
|
|
233
|
+
}
|
|
234
|
+
const safeCustomHeaders = Object.fromEntries(Object.entries((customHeaders ?? {})).filter(([key]) => !["authorization", "content-type"].includes(key.toLowerCase())));
|
|
235
|
+
delete providerOptions.headers;
|
|
236
|
+
delete providerOptions.stream;
|
|
237
|
+
delete providerOptions.partial_images;
|
|
238
|
+
const responseMaxBytes = normalizePositiveLimit(typeof providerOptions.responseMaxBytes === "number" ? providerOptions.responseMaxBytes : this.responseMaxBytes, "responseMaxBytes");
|
|
239
|
+
const errorBodyMaxBytes = normalizePositiveLimit(typeof providerOptions.errorBodyMaxBytes === "number" ? providerOptions.errorBodyMaxBytes : this.errorBodyMaxBytes, "errorBodyMaxBytes");
|
|
240
|
+
delete providerOptions.responseMaxBytes;
|
|
241
|
+
delete providerOptions.errorBodyMaxBytes;
|
|
242
|
+
validateIntegerRange(typeof providerOptions.output_compression === "number" ? providerOptions.output_compression : undefined, "output_compression", 0, 100);
|
|
243
|
+
const mimeOutputFormat = outputFormatFromMimeType(input.outputMimeType);
|
|
244
|
+
let outputFormat = mimeOutputFormat ??
|
|
245
|
+
providerOptions.output_format;
|
|
246
|
+
if (outputFormat !== undefined && !["png", "jpeg", "webp"].includes(outputFormat)) {
|
|
247
|
+
throw new ValidationError(`The OpenAI image generation "output_format" option "${String(outputFormat)}" is invalid.`);
|
|
248
|
+
}
|
|
249
|
+
if (isDallE2Model(this.modelId) || isDallE3Model(this.modelId)) {
|
|
250
|
+
if (mimeOutputFormat !== undefined && mimeOutputFormat !== "png") {
|
|
251
|
+
throw new UnsupportedFeatureError(`Provider "openai" model "${this.modelId}" only supports PNG image output.`);
|
|
252
|
+
}
|
|
253
|
+
if (providerOptions.output_format !== undefined) {
|
|
254
|
+
throw new UnsupportedFeatureError(`Provider "openai" model "${this.modelId}" does not support the "output_format" option.`);
|
|
255
|
+
}
|
|
256
|
+
outputFormat = undefined;
|
|
257
|
+
}
|
|
258
|
+
if (isGPTImageModel(this.modelId) && providerOptions.response_format !== undefined) {
|
|
259
|
+
throw new UnsupportedFeatureError(`Provider "openai" model "${this.modelId}" always returns base64 images and does not support "response_format".`);
|
|
260
|
+
}
|
|
261
|
+
const background = providerOptions.background;
|
|
262
|
+
if (background === "transparent" && outputFormat === "jpeg") {
|
|
263
|
+
throw new ValidationError('OpenAI image generation requires "png" or "webp" output for a transparent background.');
|
|
264
|
+
}
|
|
265
|
+
if (isGPTImage2Model(this.modelId) && background === "transparent") {
|
|
266
|
+
throw new UnsupportedFeatureError('Provider "openai" model "gpt-image-2" does not support transparent backgrounds.');
|
|
267
|
+
}
|
|
268
|
+
if (providerOptions.output_compression !== undefined && outputFormat !== "jpeg" && outputFormat !== "webp") {
|
|
269
|
+
throw new ValidationError('OpenAI image generation only supports "output_compression" with "jpeg" or "webp" output.');
|
|
270
|
+
}
|
|
271
|
+
const size = input.size ?? sizeFromAspectRatio(input.aspectRatio, this.modelId);
|
|
272
|
+
const { signal, cleanup, abort } = withTimeoutSignal(input);
|
|
273
|
+
try {
|
|
274
|
+
const json = await withRetry(async () => {
|
|
275
|
+
const response = await this.fetcher(`${this.baseURL}/images/generations`, {
|
|
276
|
+
method: "POST",
|
|
277
|
+
headers: {
|
|
278
|
+
...safeCustomHeaders,
|
|
279
|
+
"content-type": "application/json",
|
|
280
|
+
authorization: `Bearer ${this.apiKey}`
|
|
281
|
+
},
|
|
282
|
+
signal,
|
|
283
|
+
body: JSON.stringify({
|
|
284
|
+
...providerOptions,
|
|
285
|
+
model: this.modelId,
|
|
286
|
+
prompt: input.prompt,
|
|
287
|
+
n: input.count,
|
|
288
|
+
size,
|
|
289
|
+
output_format: outputFormat
|
|
290
|
+
})
|
|
291
|
+
});
|
|
292
|
+
if (!response.ok) {
|
|
293
|
+
const responseBody = await readErrorBodyWithLimit(response, errorBodyMaxBytes);
|
|
294
|
+
throw new ProviderHTTPError(`OpenAI image generation failed with status ${response.status}.`, response.status, {
|
|
295
|
+
responseBody
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
return readJsonWithLimit(response, {
|
|
299
|
+
maxBytes: responseMaxBytes,
|
|
300
|
+
provider: "openai",
|
|
301
|
+
endpoint: "images/generations",
|
|
302
|
+
abort
|
|
303
|
+
});
|
|
304
|
+
}, input);
|
|
305
|
+
if (!Array.isArray(json.data)) {
|
|
306
|
+
throw new ParseError("OpenAI image generation response did not contain an image data array.");
|
|
307
|
+
}
|
|
308
|
+
const mediaType = mediaTypeFromOutputFormat(outputFormat);
|
|
309
|
+
const images = json.data.map((item, index) => {
|
|
310
|
+
if (!item || typeof item !== "object") {
|
|
311
|
+
throw new ParseError(`OpenAI image generation response item ${index} was invalid.`);
|
|
312
|
+
}
|
|
313
|
+
const providerMetadata = sanitizeMetadata(item, ["b64_json"]);
|
|
314
|
+
const hasData = typeof item.b64_json === "string" && item.b64_json.length > 0;
|
|
315
|
+
const hasUri = typeof item.url === "string" && item.url.length > 0;
|
|
316
|
+
if (!hasData && !hasUri) {
|
|
317
|
+
throw new ParseError(`OpenAI image generation response item ${index} contained neither image data nor a URL.`);
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
data: hasData ? Uint8Array.from(Buffer.from(item.b64_json, "base64")) : undefined,
|
|
321
|
+
uri: hasUri ? item.url : undefined,
|
|
322
|
+
mediaType,
|
|
323
|
+
text: typeof item.revised_prompt === "string" ? item.revised_prompt : undefined,
|
|
324
|
+
providerMetadata
|
|
325
|
+
};
|
|
326
|
+
});
|
|
327
|
+
const revisedPrompts = images.flatMap((image) => image.text ? [image.text] : []);
|
|
328
|
+
return {
|
|
329
|
+
images,
|
|
330
|
+
text: revisedPrompts.length ? revisedPrompts.join("\n") : undefined,
|
|
331
|
+
rawResponse: {
|
|
332
|
+
...json,
|
|
333
|
+
data: json.data.map((item) => sanitizeMetadata(item, ["b64_json"]))
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
finally {
|
|
338
|
+
cleanup();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
export const createOpenAIImageGenerationModel = (config) => new OpenAIImageGenerationModel(config);
|
|
343
|
+
//# sourceMappingURL=image-generation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-generation.js","sourceRoot":"","sources":["../src/image-generation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,qBAAqB,EACrB,UAAU,EACV,sBAAsB,EACtB,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EAOlB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AACxB,MAAM,0BAA0B,GAAG,GAAG,GAAG,GAAG,CAAC;AAC7C,MAAM,4BAA4B,GAAG,EAAE,GAAG,IAAI,CAAC;AA6G/C,MAAM,2BAA2B,GAAsB;IACrD,SAAS,EAAE,KAAK;IAChB,KAAK,EAAE,KAAK;IACZ,gBAAgB,EAAE,KAAK;IACvB,QAAQ,EAAE,KA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CAAC;CACF;AAED,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,MAAwC,EAAE,EAAE,CAC3F,IAAI,0BAA0B,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { type AudioResponseLimits, type CallableProviderAdapter, type JsonValue, type ProviderAdapter, type RealtimeConnectionFactory, type ToolDefinition } from "@zhivex-ai/core";
|
|
2
|
+
import { type AudioResponseLimits, type CallableProviderAdapter, type JsonValue, type ProviderAdapter, type RealtimeConnectionFactory, type ToolDefinition, type ToolExecutionResult } from "@zhivex-ai/core";
|
|
3
|
+
export interface OpenAIResponseLimits extends AudioResponseLimits {
|
|
4
|
+
/** Maximum decoded bytes in one hosted image partial or final SSE event. Defaults to 32 MiB. */
|
|
5
|
+
hostedImageEventBytes?: number;
|
|
6
|
+
/** Maximum decoded hosted image bytes across one Responses SSE stream. Defaults to 128 MiB. */
|
|
7
|
+
hostedImageTotalBytes?: number;
|
|
8
|
+
}
|
|
3
9
|
export interface OpenAIProviderOptions {
|
|
4
10
|
apiKey?: string;
|
|
5
11
|
baseURL?: string;
|
|
@@ -7,7 +13,20 @@ export interface OpenAIProviderOptions {
|
|
|
7
13
|
realtimeURL?: string;
|
|
8
14
|
browserTokenURL?: string;
|
|
9
15
|
realtimeConnectionFactory?: RealtimeConnectionFactory;
|
|
10
|
-
responseLimits?:
|
|
16
|
+
responseLimits?: OpenAIResponseLimits;
|
|
17
|
+
}
|
|
18
|
+
export interface OpenAIRealtimeProviderOptions {
|
|
19
|
+
/** Additional headers for the Realtime connection or client-secret request. */
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
/** Stable, privacy-preserving end-user identifier sent as OpenAI-Safety-Identifier. */
|
|
22
|
+
safety_identifier?: string;
|
|
23
|
+
/** Override the WebSocket URL for this session. */
|
|
24
|
+
realtime_url?: string;
|
|
25
|
+
/** Additional query parameters for the Realtime WebSocket URL. */
|
|
26
|
+
realtime_query?: Record<string, string | number | boolean>;
|
|
27
|
+
/** Client-secret expiration settings passed at the request top level. */
|
|
28
|
+
expires_after?: Record<string, unknown>;
|
|
29
|
+
[key: string]: unknown;
|
|
11
30
|
}
|
|
12
31
|
export interface OpenAIWebSearchToolConfig {
|
|
13
32
|
type?: "web_search" | "web_search_2025_08_26";
|
|
@@ -220,6 +239,30 @@ export interface OpenAIMcpListTools {
|
|
|
220
239
|
server_label?: string;
|
|
221
240
|
tools?: JsonValue;
|
|
222
241
|
}
|
|
242
|
+
export declare const openAIRealtimeMcpMetadataKey = "openai.realtime_mcp";
|
|
243
|
+
export interface OpenAIRealtimeMcpMetadata {
|
|
244
|
+
type: "mcp_list_tools" | "mcp_approval_request" | "mcp_approval_response" | "mcp_call";
|
|
245
|
+
status: "in_progress" | "completed" | "failed" | "approval_required" | "approved" | "rejected" | "arguments_delta" | "arguments_done";
|
|
246
|
+
item_id?: string;
|
|
247
|
+
approval_request_id?: string;
|
|
248
|
+
server_label?: string;
|
|
249
|
+
name?: string;
|
|
250
|
+
approve?: boolean;
|
|
251
|
+
reason?: string;
|
|
252
|
+
arguments?: JsonValue;
|
|
253
|
+
delta?: JsonValue;
|
|
254
|
+
tools?: JsonValue;
|
|
255
|
+
output?: JsonValue;
|
|
256
|
+
error?: JsonValue;
|
|
257
|
+
raw_event?: JsonValue;
|
|
258
|
+
}
|
|
259
|
+
export interface OpenAIRealtimeMcpApprovalResultOptions {
|
|
260
|
+
approvalRequestId: string;
|
|
261
|
+
name: string;
|
|
262
|
+
approve: boolean;
|
|
263
|
+
reason?: string;
|
|
264
|
+
itemId?: string;
|
|
265
|
+
}
|
|
223
266
|
export interface OpenAIPromptCacheBreakpointData {
|
|
224
267
|
type: "prompt_cache_breakpoint";
|
|
225
268
|
mode: "explicit";
|
|
@@ -253,6 +296,11 @@ export interface OpenAILanguageModelOptions {
|
|
|
253
296
|
function: {
|
|
254
297
|
name: string;
|
|
255
298
|
};
|
|
299
|
+
} | {
|
|
300
|
+
type: "function";
|
|
301
|
+
name: string;
|
|
302
|
+
} | {
|
|
303
|
+
type: "image_generation";
|
|
256
304
|
};
|
|
257
305
|
[key: string]: unknown;
|
|
258
306
|
}
|
|
@@ -267,11 +315,12 @@ export declare const openAIProgrammaticToolCallingTool: () => import("@zhivex-ai
|
|
|
267
315
|
export declare const openAIProgrammaticTool: <TSchema extends z.ZodTypeAny, TResult>(definition: ToolDefinition<TSchema, TResult>, options?: OpenAIProgrammaticToolOptions) => ToolDefinition<TSchema, TResult>;
|
|
268
316
|
export declare const openAIRemoteMcpTool: (config: OpenAIRemoteMcpToolConfig) => import("@zhivex-ai/core").HostedToolDefinition<JsonValue>;
|
|
269
317
|
export declare const openAIMcpApprovalResponse: (response: Omit<OpenAIMcpApprovalResponse, "type">) => import("@zhivex-ai/core").ContentPart;
|
|
318
|
+
export declare const openAIRealtimeMcpApprovalResult: (response: OpenAIRealtimeMcpApprovalResultOptions) => ToolExecutionResult;
|
|
270
319
|
export declare const openAIPromptCacheBreakpoint: () => import("@zhivex-ai/core").ContentPart;
|
|
271
320
|
export declare const openAIComputerUseTool: (config: OpenAIComputerUseToolConfig) => import("@zhivex-ai/core").HostedToolDefinition<JsonValue>;
|
|
272
321
|
export declare const openAIComputerTool: (config: OpenAIComputerToolConfig) => ToolDefinition<z.ZodType<OpenAIComputerCallInput>, JsonValue>;
|
|
273
322
|
export declare const openAIHostedShellTool: (config: OpenAIHostedShellToolConfig) => import("@zhivex-ai/core").HostedToolDefinition<JsonValue>;
|
|
274
323
|
export declare const openAIShellTool: (config?: OpenAIShellToolConfig) => ToolDefinition<z.ZodType<OpenAIShellToolInput>, JsonValue>;
|
|
275
324
|
export declare const openAIApplyPatchTool: (config: OpenAIApplyPatchToolConfig) => ToolDefinition<z.ZodType<OpenAIApplyPatchToolInput>, JsonValue>;
|
|
276
|
-
export
|
|
325
|
+
export * from "./image-generation.js";
|
|
277
326
|
//# sourceMappingURL=index.d.ts.map
|