@opencode/ai 0.0.0-dev-21757 → 0.0.0-dev-21761

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.
@@ -1,4 +1,4 @@
1
- import { Effect, Schema, Stream } from "effect";
1
+ import { Effect, Schema, SchemaGetter, Stream } from "effect";
2
2
  import { ImageFinishEvent, ImageModel, ImageOutputEvent, ImagePartialEvent, } from "../image.js";
3
3
  import { Media } from "../media.js";
4
4
  import { classifyProviderFailure } from "../provider-error.js";
@@ -38,6 +38,20 @@ const OpenAIImageResponse = Schema.Struct({
38
38
  // ---------------------------------------------------------------------------
39
39
  // 3. Streaming event schema
40
40
  // ---------------------------------------------------------------------------
41
+ const EVENT_TYPES = new Set([
42
+ "image_generation.partial_image",
43
+ "image_edit.partial_image",
44
+ "image_generation.completed",
45
+ "image_edit.completed",
46
+ "error",
47
+ ]);
48
+ /** OpenAI may add stream event types; frames outside `EVENT_TYPES` are ignored, while a malformed known type still fails decoding. */
49
+ const UnknownEvent = Schema.Struct({
50
+ type: Schema.String.check(Schema.makeFilter((type) => !EVENT_TYPES.has(type))),
51
+ }).pipe(Schema.decodeTo(Schema.Struct({ type: Schema.Literal("unknown"), rawType: Schema.String }), {
52
+ decode: SchemaGetter.transform((event) => ({ type: "unknown", rawType: event.type })),
53
+ encode: SchemaGetter.forbidden(() => "Unknown OpenAI Images stream events are decode-only"),
54
+ }));
41
55
  const StreamEvent = Schema.Union([
42
56
  Schema.Struct({
43
57
  type: Schema.Literals(["image_generation.partial_image", "image_edit.partial_image"]),
@@ -57,6 +71,7 @@ const StreamEvent = Schema.Union([
57
71
  type: Schema.Literal("error"),
58
72
  error: Schema.optional(Schema.Struct({ message: Schema.optional(Schema.String) })),
59
73
  }),
74
+ UnknownEvent,
60
75
  ]);
61
76
  const decodeEvent = route.decodeFrame(StreamEvent);
62
77
  const decodeDocument = Schema.decodeUnknownEffect(Schema.fromJsonString(OpenAIImageResponse));
@@ -165,6 +180,8 @@ const eventImage = (frame, label, data, format, size) => MediaInput.decodedAsset
165
180
  });
166
181
  const onEvent = Effect.fnUntraced(function* (state, frame) {
167
182
  const event = yield* decodeEvent(frame);
183
+ if (event.type === "unknown")
184
+ return [state, []];
168
185
  if (event.type === "error")
169
186
  return yield* new AIError({
170
187
  reason: classifyProviderFailure({
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-21757",
3
+ "version": "0.0.0-dev-21761",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "devDependencies": {
36
36
  "@clack/prompts": "1.0.0-alpha.1",
37
37
  "@effect/platform-node": "4.0.1",
38
- "@opencode/http-recorder": "0.0.0-dev-21757",
38
+ "@opencode/http-recorder": "0.0.0-dev-21761",
39
39
  "@tsconfig/bun": "1.0.9",
40
40
  "@types/bun": "1.4.3",
41
41
  "@typescript/native": "npm:typescript@7.1.0-beta",
@@ -45,7 +45,7 @@
45
45
  "@aws-sdk/credential-providers": "3.1057.0",
46
46
  "@smithy/eventstream-codec": "4.2.14",
47
47
  "@smithy/util-utf8": "4.2.2",
48
- "@opencode/schema": "0.0.0-dev-21757",
48
+ "@opencode/schema": "0.0.0-dev-21761",
49
49
  "aws4fetch": "1.0.20",
50
50
  "effect": "4.0.1",
51
51
  "google-auth-library": "10.5.0"