@opencode/ai 0.0.0-dev-21761 → 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 } 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"
|