@opencode/ai 0.0.0-dev-210 → 0.0.0-dev-217

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.
@@ -44,10 +44,12 @@ interface State {
44
44
  /** The body fields `aspect` and `resolution` lower to; gateways that read other fields than `size` pass their own. */
45
45
  export type OpenAIImageSizing = (request: Request) => Record<string, unknown> | undefined;
46
46
  /**
47
- * How input images travel. `edits` is OpenAI's `/images/edits`; `references` keeps every request on
48
- * `/images/generations` and lists them as `input_references`, for gateways without an edits endpoint (OpenRouter).
47
+ * How input images travel. `edits` is OpenAI's `/images/edits`, uploading owned bytes as multipart; `json-edits` sends
48
+ * every edit there as JSON with data URLs, for hosts that reject multipart (the ChatGPT backend); `references` keeps
49
+ * every request on `/images/generations` and lists them as `input_references`, for gateways without an edits endpoint
50
+ * (OpenRouter).
49
51
  */
50
- export type OpenAIImageInput = "edits" | "references";
52
+ export type OpenAIImageInput = "edits" | "json-edits" | "references";
51
53
  export declare const protocol: MediaProtocol.Streamed<Request, {
52
54
  readonly type: "image-partial";
53
55
  readonly index: number;
@@ -158,8 +158,11 @@ const fromRequest = Effect.fn("OpenAIImages.fromRequest")(function* (request, op
158
158
  : references.map((item) => ({ type: "image_url", image_url: { url: item.value } })),
159
159
  }, fields) ?? {});
160
160
  }
161
- // Owned bytes go through multipart edits; remote URLs and file IDs use the JSON edits body instead.
162
- if (images.length > 0 && images.every(isInline) && (mask === undefined || isInline(mask))) {
161
+ // Owned bytes go through multipart edits; remote URLs, file IDs and `json-edits` hosts use the JSON edits body.
162
+ if (options.imageInput === "edits" &&
163
+ images.length > 0 &&
164
+ images.every(isInline) &&
165
+ (mask === undefined || isInline(mask))) {
163
166
  const form = new FormData();
164
167
  MediaInput.appendFields(form, { model: request.model.id, prompt: request.prompt }, { overlay: fields, reserved: RESERVED_FORM_FIELDS });
165
168
  const uploads = yield* Effect.forEach(images, (image) => MediaInput.inlineBytes(route.id, image));
@@ -290,7 +293,7 @@ export const model = (input) => {
290
293
  return ImageModel.fromRoute({
291
294
  protocol: input.provider === undefined ? base : { ...base, provider: ProviderID.make(input.provider) },
292
295
  baseURL: DEFAULT_BASE_URL,
293
- path: ({ request }) => (imageInput === "edits" && isEdit(request) ? EDIT_PATH : PATH),
296
+ path: ({ request }) => (imageInput !== "references" && isEdit(request) ? EDIT_PATH : PATH),
294
297
  }, input);
295
298
  };
296
299
  export const OpenAIImages = {
@@ -0,0 +1,2 @@
1
+ export { imageModel as model } from "../meta.js";
2
+ export type { Settings } from "../meta.js";
@@ -0,0 +1 @@
1
+ export { imageModel as model } from "../meta.js";
@@ -751,4 +751,5 @@ export declare const image: (modelID: string | ModelID) => import("../image.js")
751
751
  export declare const model: ProviderPackage.Model<Settings, OpenResponsesProviderOptionsInput>;
752
752
  export declare const chatModel: ProviderPackage.Model<Settings, OpenResponsesProviderOptionsInput>;
753
753
  export declare const messagesModel: ProviderPackage.Model<Settings, MessagesOptionsInput>;
754
+ export declare const imageModel: (modelID: string, settings?: Settings) => import("../image.js").ImageModel<MetaImages.ImageOptions>;
754
755
  export * as Meta from "./meta.js";
@@ -97,6 +97,7 @@ export const image = provider.image;
97
97
  export const model = (modelID, settings) => fromSettings(settings).responses(modelID);
98
98
  export const chatModel = (modelID, settings) => fromSettings(settings).chat(modelID);
99
99
  export const messagesModel = (modelID, settings) => fromSettings(settings).messages(modelID);
100
+ export const imageModel = (modelID, settings) => fromSettings(settings).image(modelID);
100
101
  function fromSettings({ apiKey, baseURL, body, headers, ...providerOptions } = {}) {
101
102
  return configure({
102
103
  apiKey,
@@ -51,7 +51,9 @@ export const configure = (input = {}) => {
51
51
  ...deployment,
52
52
  http: mergeHttpOptions(deployment.http, input.queryParams === undefined ? undefined : new HttpOptions({ query: input.queryParams })),
53
53
  };
54
- const image = (modelID, providerOptions) => OpenAIImages.model({ ...media, id: modelID, providerOptions });
54
+ // The ChatGPT backend (ChatGPT sign-in) rejects multipart image edits with "Unsupported content type".
55
+ const imageInput = media.baseURL?.startsWith("https://chatgpt.com/") ? "json-edits" : undefined;
56
+ const image = (modelID, providerOptions) => OpenAIImages.model({ ...media, id: modelID, providerOptions, imageInput });
55
57
  const speech = (modelID) => OpenAISpeech.model({ ...media, id: modelID });
56
58
  const transcription = (modelID) => OpenAITranscription.model({ ...media, id: modelID });
57
59
  const decisionRoute = OpenAIDecisions.route.with({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-dev-210",
3
+ "version": "0.0.0-dev-217",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -248,6 +248,10 @@
248
248
  "import": "./dist/providers/meta/chat.js",
249
249
  "types": "./dist/providers/meta/chat.d.ts"
250
250
  },
251
+ "./providers/meta/images": {
252
+ "import": "./dist/providers/meta/images.js",
253
+ "types": "./dist/providers/meta/images.d.ts"
254
+ },
251
255
  "./providers/meta/messages": {
252
256
  "import": "./dist/providers/meta/messages.js",
253
257
  "types": "./dist/providers/meta/messages.d.ts"
@@ -512,7 +516,7 @@
512
516
  "devDependencies": {
513
517
  "@clack/prompts": "1.0.0-alpha.1",
514
518
  "@effect/platform-node": "4.0.1",
515
- "@opencode/http-recorder": "0.0.0-dev-210",
519
+ "@opencode/http-recorder": "0.0.0-dev-217",
516
520
  "@tsconfig/bun": "1.0.9",
517
521
  "@types/bun": "1.4.3",
518
522
  "@typescript/native": "npm:typescript@7.1.0-beta",
@@ -522,7 +526,7 @@
522
526
  "@aws-sdk/credential-providers": "3.1057.0",
523
527
  "@smithy/eventstream-codec": "4.2.14",
524
528
  "@smithy/util-utf8": "4.2.2",
525
- "@opencode/schema": "0.0.0-dev-210",
529
+ "@opencode/schema": "0.0.0-dev-217",
526
530
  "aws4fetch": "1.0.20",
527
531
  "effect": "4.0.1",
528
532
  "google-auth-library": "10.5.0"