@opencode/ai 0.0.0-dev-21757 → 0.0.0-dev-21763
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.
|
@@ -676,12 +676,7 @@ const mapFinishReason = Effect.fnUntraced(function* (event, reason) {
|
|
|
676
676
|
case "tool_calls":
|
|
677
677
|
return "tool-calls";
|
|
678
678
|
default:
|
|
679
|
-
return
|
|
680
|
-
reason: new UnknownProviderError({
|
|
681
|
-
message: `Provider finish_reason: ${reason}`,
|
|
682
|
-
body: ProviderShared.encodeJson(event),
|
|
683
|
-
}),
|
|
684
|
-
});
|
|
679
|
+
return "unknown";
|
|
685
680
|
}
|
|
686
681
|
});
|
|
687
682
|
// OpenAI Chat reports `prompt_tokens` (inclusive total) with a
|
|
@@ -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({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Effect, Schema, SchemaGetter } from "effect";
|
|
2
2
|
import { Framing } from "../route/framing.js";
|
|
3
3
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
4
|
import { MediaRoute } from "../route/media.js";
|
|
@@ -13,6 +13,14 @@ const PCM_SAMPLE_RATE = 24000;
|
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
14
14
|
// 3. Streaming event schema
|
|
15
15
|
// ---------------------------------------------------------------------------
|
|
16
|
+
const EVENT_TYPES = new Set(["speech.audio.delta", "speech.audio.done"]);
|
|
17
|
+
/** OpenAI may add stream event types; frames outside `EVENT_TYPES` are ignored, while a malformed known type still fails decoding. */
|
|
18
|
+
const UnknownEvent = Schema.Struct({
|
|
19
|
+
type: Schema.String.check(Schema.makeFilter((type) => !EVENT_TYPES.has(type))),
|
|
20
|
+
}).pipe(Schema.decodeTo(Schema.Struct({ type: Schema.Literal("unknown"), rawType: Schema.String }), {
|
|
21
|
+
decode: SchemaGetter.transform((event) => ({ type: "unknown", rawType: event.type })),
|
|
22
|
+
encode: SchemaGetter.forbidden(() => "Unknown OpenAI Speech stream events are decode-only"),
|
|
23
|
+
}));
|
|
16
24
|
const SpeechStreamEvent = Schema.Union([
|
|
17
25
|
Schema.Struct({ type: Schema.Literal("speech.audio.delta"), audio: Schema.Uint8ArrayFromBase64 }),
|
|
18
26
|
Schema.Struct({
|
|
@@ -23,6 +31,7 @@ const SpeechStreamEvent = Schema.Union([
|
|
|
23
31
|
total_tokens: Schema.optional(Schema.Number),
|
|
24
32
|
})),
|
|
25
33
|
}),
|
|
34
|
+
UnknownEvent,
|
|
26
35
|
]);
|
|
27
36
|
const decodeEvent = route.decodeFrame(SpeechStreamEvent);
|
|
28
37
|
// ---------------------------------------------------------------------------
|
|
@@ -53,6 +62,8 @@ const fromRequest = Effect.fn("OpenAISpeech.fromRequest")(function* (request) {
|
|
|
53
62
|
const isSse = (body) => body.type === "json" && body.value.stream_format === "sse";
|
|
54
63
|
const onEvent = Effect.fnUntraced(function* (state, frame) {
|
|
55
64
|
const event = yield* decodeEvent(frame);
|
|
65
|
+
if (event.type === "unknown")
|
|
66
|
+
return [state, []];
|
|
56
67
|
if (event.type === "speech.audio.delta")
|
|
57
68
|
return SpeechStream.delta(state, event.audio);
|
|
58
69
|
const usage = event.usage;
|
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-21763",
|
|
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-
|
|
38
|
+
"@opencode/http-recorder": "0.0.0-dev-21763",
|
|
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-
|
|
48
|
+
"@opencode/schema": "0.0.0-dev-21763",
|
|
49
49
|
"aws4fetch": "1.0.20",
|
|
50
50
|
"effect": "4.0.1",
|
|
51
51
|
"google-auth-library": "10.5.0"
|