@opencode/ai 0.0.0-dev-65 → 0.0.0-dev-70
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.
|
@@ -3,6 +3,7 @@ import { ImageModel, ImageResponse } from "../image.js";
|
|
|
3
3
|
import { Media } from "../media.js";
|
|
4
4
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
5
|
import { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
+
import { ProviderShared } from "./shared.js";
|
|
6
7
|
import { ImageSizing } from "./utils/image-sizing.js";
|
|
7
8
|
import { MediaInput } from "./utils/media-input.js";
|
|
8
9
|
const route = MediaProtocol.identity({
|
|
@@ -33,10 +34,18 @@ const fromRequest = Effect.fn("CloudflareWorkersAIImages.fromRequest")(function*
|
|
|
33
34
|
...(yield* ImageSizing.exact(route, request, { multiple: 16, minEdge: 256, maxEdge: 2048 })),
|
|
34
35
|
};
|
|
35
36
|
const native = mergeJsonRecords(request.providerOptions, request.http?.body);
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
const images = request.images ?? [];
|
|
38
|
+
if (!request.model.id.startsWith(MULTIPART_MODEL_PREFIX)) {
|
|
39
|
+
if (images.length > 1)
|
|
40
|
+
return yield* route.unsupported("media.images", `${request.model.id} takes one input image as image_b64`);
|
|
41
|
+
const image = images[0]?.inline();
|
|
42
|
+
if (images[0] !== undefined && image === undefined)
|
|
43
|
+
return yield* ProviderShared.inlineRequired(route.id, images[0]);
|
|
44
|
+
return MediaProtocol.json(mergeJsonRecords({ ...fields, image_b64: image?.base64 }, native) ?? {});
|
|
45
|
+
}
|
|
38
46
|
const body = new FormData();
|
|
39
47
|
MediaInput.appendFields(body, fields, { overlay: native, reserved: RESERVED_FORM_FIELDS });
|
|
48
|
+
yield* Effect.forEach(images, (image, index) => MediaInput.inlineBytes(route.id, image).pipe(Effect.map((bytes) => body.append(`input_image_${index}`, MediaInput.blob(bytes, image.mediaType), `image_${index}`))));
|
|
40
49
|
return MediaProtocol.multipart(body);
|
|
41
50
|
});
|
|
42
51
|
// ---------------------------------------------------------------------------
|
|
@@ -61,7 +70,6 @@ const decodeResponse = Effect.fn("CloudflareWorkersAIImages.decodeResponse")(fun
|
|
|
61
70
|
// 7. Protocol and route
|
|
62
71
|
// ---------------------------------------------------------------------------
|
|
63
72
|
export const protocol = MediaProtocol.inline(route, {
|
|
64
|
-
unsupported: ["images"],
|
|
65
73
|
body: { from: fromRequest },
|
|
66
74
|
response: { decode: decodeResponse },
|
|
67
75
|
});
|
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-
|
|
3
|
+
"version": "0.0.0-dev-70",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -532,7 +532,7 @@
|
|
|
532
532
|
"devDependencies": {
|
|
533
533
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
534
534
|
"@effect/platform-node": "4.0.1",
|
|
535
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
535
|
+
"@opencode/http-recorder": "0.0.0-dev-70",
|
|
536
536
|
"@tsconfig/bun": "1.0.9",
|
|
537
537
|
"@types/bun": "1.4.3",
|
|
538
538
|
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
@@ -542,7 +542,7 @@
|
|
|
542
542
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
543
543
|
"@smithy/eventstream-codec": "4.2.14",
|
|
544
544
|
"@smithy/util-utf8": "4.2.2",
|
|
545
|
-
"@opencode/schema": "0.0.0-dev-
|
|
545
|
+
"@opencode/schema": "0.0.0-dev-70",
|
|
546
546
|
"aws4fetch": "1.0.20",
|
|
547
547
|
"effect": "4.0.1",
|
|
548
548
|
"google-auth-library": "10.5.0"
|