@openai-oauth/core 2.0.0-beta.2 → 2.0.0-beta.3
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 +2 -0
- package/dist/images.d.ts +7 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +187 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +31 -8
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/images.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const CODEX_IMAGE_MODEL = "gpt-image-2";
|
|
2
|
+
export type PreparedCodexImageRequest = {
|
|
3
|
+
body: BodyInit | null | undefined;
|
|
4
|
+
response?: Response;
|
|
5
|
+
};
|
|
6
|
+
export declare const prepareCodexImageRequest: (pathname: string, headers: Headers, body: BodyInit | null | undefined) => Promise<PreparedCodexImageRequest>;
|
|
7
|
+
//# sourceMappingURL=images.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../src/images.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,gBAAgB,CAAA;AAY9C,MAAM,MAAM,yBAAyB,GAAG;IACvC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,CAAA;IACjC,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACnB,CAAA;AAsLD,eAAO,MAAM,wBAAwB,GACpC,UAAU,MAAM,EAChB,SAAS,OAAO,EAChB,MAAM,QAAQ,GAAG,IAAI,GAAG,SAAS,KAC/B,OAAO,CAAC,yBAAyB,CA6CnC,CAAA"}
|
package/dist/images.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
export const CODEX_IMAGE_MODEL = "gpt-image-2";
|
|
2
|
+
const MAX_REFERENCE_IMAGES = 5;
|
|
3
|
+
const MAX_REFERENCE_IMAGE_BYTES = 50 * 1024 * 1024;
|
|
4
|
+
const unsupportedOptions = [
|
|
5
|
+
"input_fidelity",
|
|
6
|
+
"moderation",
|
|
7
|
+
"output_compression",
|
|
8
|
+
"output_format",
|
|
9
|
+
"partial_images",
|
|
10
|
+
];
|
|
11
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
|
+
const errorResponse = (message) => Response.json({
|
|
13
|
+
error: {
|
|
14
|
+
message,
|
|
15
|
+
type: "invalid_request_error",
|
|
16
|
+
},
|
|
17
|
+
}, { status: 400 });
|
|
18
|
+
const bytesToBase64 = (bytes) => {
|
|
19
|
+
let binary = "";
|
|
20
|
+
const chunkSize = 0x8000;
|
|
21
|
+
for (let offset = 0; offset < bytes.length; offset += chunkSize) {
|
|
22
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + chunkSize));
|
|
23
|
+
}
|
|
24
|
+
return btoa(binary);
|
|
25
|
+
};
|
|
26
|
+
const fileToDataUrl = async (file) => {
|
|
27
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
28
|
+
return `data:${file.type || "image/png"};base64,${bytesToBase64(bytes)}`;
|
|
29
|
+
};
|
|
30
|
+
const decodeBody = async (body) => {
|
|
31
|
+
if (typeof body === "string")
|
|
32
|
+
return body;
|
|
33
|
+
if (body instanceof Blob)
|
|
34
|
+
return body.text();
|
|
35
|
+
if (body instanceof ArrayBuffer)
|
|
36
|
+
return new TextDecoder().decode(body);
|
|
37
|
+
if (ArrayBuffer.isView(body))
|
|
38
|
+
return new TextDecoder().decode(body);
|
|
39
|
+
return undefined;
|
|
40
|
+
};
|
|
41
|
+
const normalizeGeneration = (body) => {
|
|
42
|
+
if (body.stream === true) {
|
|
43
|
+
return {
|
|
44
|
+
body: undefined,
|
|
45
|
+
response: errorResponse("Streaming image generation is not supported by ChatGPT OAuth."),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (typeof body.prompt !== "string" || body.prompt.length === 0) {
|
|
49
|
+
return {
|
|
50
|
+
body: undefined,
|
|
51
|
+
response: errorResponse("`prompt` must be a non-empty string."),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const unsupported = unsupportedOptions.find((key) => body[key] !== undefined);
|
|
55
|
+
if (unsupported) {
|
|
56
|
+
return {
|
|
57
|
+
body: undefined,
|
|
58
|
+
response: errorResponse(`\`${unsupported}\` is not supported by ChatGPT OAuth image generation.`),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (body.response_format !== undefined &&
|
|
62
|
+
body.response_format !== "b64_json") {
|
|
63
|
+
return {
|
|
64
|
+
body: undefined,
|
|
65
|
+
response: errorResponse("ChatGPT OAuth image generation only returns `b64_json`."),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const normalized = {
|
|
69
|
+
model: typeof body.model === "string" && body.model.length > 0
|
|
70
|
+
? body.model
|
|
71
|
+
: CODEX_IMAGE_MODEL,
|
|
72
|
+
prompt: body.prompt,
|
|
73
|
+
};
|
|
74
|
+
for (const key of ["background", "n", "quality", "size"]) {
|
|
75
|
+
if (body[key] !== undefined)
|
|
76
|
+
normalized[key] = body[key];
|
|
77
|
+
}
|
|
78
|
+
return { body: JSON.stringify(normalized) };
|
|
79
|
+
};
|
|
80
|
+
const normalizeEdit = async (body) => {
|
|
81
|
+
if (body.get("stream") === "true") {
|
|
82
|
+
return {
|
|
83
|
+
body: undefined,
|
|
84
|
+
response: errorResponse("Streaming image editing is not supported by ChatGPT OAuth."),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (body.has("mask")) {
|
|
88
|
+
return {
|
|
89
|
+
body: undefined,
|
|
90
|
+
response: errorResponse("Image masks are not supported by ChatGPT OAuth."),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const prompt = body.get("prompt");
|
|
94
|
+
if (typeof prompt !== "string" || prompt.length === 0) {
|
|
95
|
+
return {
|
|
96
|
+
body: undefined,
|
|
97
|
+
response: errorResponse("`prompt` must be a non-empty string."),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const files = [...body.getAll("image"), ...body.getAll("image[]")].filter((value) => typeof value !== "string");
|
|
101
|
+
if (files.length === 0 || files.length > MAX_REFERENCE_IMAGES) {
|
|
102
|
+
return {
|
|
103
|
+
body: undefined,
|
|
104
|
+
response: errorResponse(files.length === 0
|
|
105
|
+
? "At least one `image` is required."
|
|
106
|
+
: "ChatGPT OAuth supports at most 5 reference images."),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const oversized = files.find((file) => file.size > MAX_REFERENCE_IMAGE_BYTES);
|
|
110
|
+
if (oversized) {
|
|
111
|
+
return {
|
|
112
|
+
body: undefined,
|
|
113
|
+
response: errorResponse(`Reference image \`${oversized.name}\` exceeds the 50 MB limit.`),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const unsupported = unsupportedOptions.find((key) => body.has(key));
|
|
117
|
+
if (unsupported) {
|
|
118
|
+
return {
|
|
119
|
+
body: undefined,
|
|
120
|
+
response: errorResponse(`\`${unsupported}\` is not supported by ChatGPT OAuth image editing.`),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const responseFormat = body.get("response_format");
|
|
124
|
+
if (responseFormat !== null && responseFormat !== "b64_json") {
|
|
125
|
+
return {
|
|
126
|
+
body: undefined,
|
|
127
|
+
response: errorResponse("ChatGPT OAuth image editing only returns `b64_json`."),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const model = body.get("model");
|
|
131
|
+
const normalized = {
|
|
132
|
+
images: await Promise.all(files.map(async (file) => ({ image_url: await fileToDataUrl(file) }))),
|
|
133
|
+
model: typeof model === "string" && model ? model : CODEX_IMAGE_MODEL,
|
|
134
|
+
prompt,
|
|
135
|
+
};
|
|
136
|
+
const n = body.get("n");
|
|
137
|
+
if (typeof n === "string" && n) {
|
|
138
|
+
const parsed = Number(n);
|
|
139
|
+
if (Number.isFinite(parsed))
|
|
140
|
+
normalized.n = parsed;
|
|
141
|
+
}
|
|
142
|
+
for (const key of ["background", "quality", "size"]) {
|
|
143
|
+
const value = body.get(key);
|
|
144
|
+
if (typeof value === "string" && value)
|
|
145
|
+
normalized[key] = value;
|
|
146
|
+
}
|
|
147
|
+
return { body: JSON.stringify(normalized) };
|
|
148
|
+
};
|
|
149
|
+
export const prepareCodexImageRequest = async (pathname, headers, body) => {
|
|
150
|
+
if (pathname.endsWith("/images/generations")) {
|
|
151
|
+
const bodyText = await decodeBody(body);
|
|
152
|
+
if (bodyText === undefined) {
|
|
153
|
+
return {
|
|
154
|
+
body: undefined,
|
|
155
|
+
response: errorResponse("Image generation requires a JSON request body."),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
const parsed = JSON.parse(bodyText);
|
|
160
|
+
if (!isRecord(parsed)) {
|
|
161
|
+
return {
|
|
162
|
+
body: undefined,
|
|
163
|
+
response: errorResponse("Image generation request body must be a JSON object."),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
headers.set("content-type", "application/json");
|
|
167
|
+
return normalizeGeneration(parsed);
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return {
|
|
171
|
+
body: undefined,
|
|
172
|
+
response: errorResponse("Image generation request is invalid JSON."),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (pathname.endsWith("/images/edits")) {
|
|
177
|
+
if (!(body instanceof FormData)) {
|
|
178
|
+
return {
|
|
179
|
+
body: undefined,
|
|
180
|
+
response: errorResponse("Image editing requires a multipart/form-data request body."),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
headers.set("content-type", "application/json");
|
|
184
|
+
return normalizeEdit(body);
|
|
185
|
+
}
|
|
186
|
+
return { body };
|
|
187
|
+
};
|
package/dist/runtime.d.ts
CHANGED
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[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tC,OAAO,CAAC,wBAAwB,CAYhC,CAAA;AA0GH,eAAO,MAAM,2BAA2B,QAAO,MACpB,CAAA;AA4G3B,eAAO,MAAM,2BAA2B,GACvC,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,UAAS,kCAAuC,KAC9C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAuD,CAAA;AAqPhF,eAAO,MAAM,qBAAqB,GACjC,UAAU,yBAAyB,KACjC,aAgGF,CAAA;AAcD,eAAO,MAAM,sBAAsB,GAClC,UAAU,yBAAyB,KACjC,gBAUF,CAAA;AAED,eAAO,MAAM,0BAA0B,GACtC,UAAU,2BAA2B,KACnC,oBAoBF,CAAA"}
|
package/dist/runtime.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { withoutTrailingSlash } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { CODEX_IMAGE_MODEL, prepareCodexImageRequest } from "./images.js";
|
|
2
3
|
import { fetchCodexModelCatalog, isPublicCodexModel, } from "./models.js";
|
|
3
4
|
import { CodexResponsesState } from "./state.js";
|
|
4
5
|
export { collectCompletedResponseFromSse, iterateServerSentEvents, } from "./sse.js";
|
|
@@ -280,7 +281,11 @@ const readRequestParts = async (input, init) => {
|
|
|
280
281
|
method: init?.method ?? input.method,
|
|
281
282
|
headers,
|
|
282
283
|
body: init?.body ??
|
|
283
|
-
(input.body == null
|
|
284
|
+
(input.body == null
|
|
285
|
+
? undefined
|
|
286
|
+
: input.headers.get("content-type")?.includes("multipart/form-data")
|
|
287
|
+
? await input.clone().formData()
|
|
288
|
+
: await input.clone().text()),
|
|
284
289
|
signal: init?.signal ?? input.signal,
|
|
285
290
|
};
|
|
286
291
|
}
|
|
@@ -594,12 +599,24 @@ export const createCodexOAuthFetch = (settings) => {
|
|
|
594
599
|
}
|
|
595
600
|
return Response.json({
|
|
596
601
|
object: "list",
|
|
597
|
-
data:
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
602
|
+
data: [
|
|
603
|
+
...models.map((model) => ({
|
|
604
|
+
id: model.slug,
|
|
605
|
+
object: "model",
|
|
606
|
+
created: 0,
|
|
607
|
+
owned_by: "codex-oauth",
|
|
608
|
+
})),
|
|
609
|
+
...(models.some((model) => model.slug === CODEX_IMAGE_MODEL)
|
|
610
|
+
? []
|
|
611
|
+
: [
|
|
612
|
+
{
|
|
613
|
+
id: CODEX_IMAGE_MODEL,
|
|
614
|
+
object: "model",
|
|
615
|
+
created: 0,
|
|
616
|
+
owned_by: "codex-oauth",
|
|
617
|
+
},
|
|
618
|
+
]),
|
|
619
|
+
],
|
|
603
620
|
});
|
|
604
621
|
}
|
|
605
622
|
const headers = new Headers(settings.headers);
|
|
@@ -607,7 +624,11 @@ export const createCodexOAuthFetch = (settings) => {
|
|
|
607
624
|
headers.set(key, value);
|
|
608
625
|
});
|
|
609
626
|
applyAuthHeaders(headers, auth);
|
|
610
|
-
const
|
|
627
|
+
const preparedImage = await prepareCodexImageRequest(target.pathname, headers, request.body);
|
|
628
|
+
if (preparedImage.response) {
|
|
629
|
+
return preparedImage.response;
|
|
630
|
+
}
|
|
631
|
+
const preparedBody = await prepareResponsesRequestBody(target.pathname, headers, preparedImage.body, settings, responsesState, auth, resolveModelInfo);
|
|
611
632
|
const response = await fetch(target.toString(), {
|
|
612
633
|
method: request.method ?? init?.method,
|
|
613
634
|
headers,
|
|
@@ -649,6 +670,8 @@ export const createOpenAIOAuthTransport = (settings) => {
|
|
|
649
670
|
chatCompletions: true,
|
|
650
671
|
models: true,
|
|
651
672
|
streaming: true,
|
|
673
|
+
imageGeneration: true,
|
|
674
|
+
imageEditing: true,
|
|
652
675
|
},
|
|
653
676
|
};
|
|
654
677
|
};
|