@opencode/ai 0.0.0-dev-1223 → 0.0.0-dev-1227
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.
|
@@ -19,6 +19,9 @@ declare const Answer: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
|
19
19
|
readonly score: Schema.Number;
|
|
20
20
|
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
21
21
|
readonly confidence: Schema.Number;
|
|
22
|
+
}>, Schema.Struct<{
|
|
23
|
+
readonly type: Schema.Literal<"refusal">;
|
|
24
|
+
readonly message: Schema.optional<Schema.String>;
|
|
22
25
|
}>]>;
|
|
23
26
|
export declare const Response: Schema.Struct<{
|
|
24
27
|
readonly model: Schema.String;
|
|
@@ -35,6 +38,9 @@ export declare const Response: Schema.Struct<{
|
|
|
35
38
|
readonly score: Schema.Number;
|
|
36
39
|
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
37
40
|
readonly confidence: Schema.Number;
|
|
41
|
+
}>, Schema.Struct<{
|
|
42
|
+
readonly type: Schema.Literal<"refusal">;
|
|
43
|
+
readonly message: Schema.optional<Schema.String>;
|
|
38
44
|
}>]>>;
|
|
39
45
|
readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
|
|
40
46
|
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
@@ -83,6 +89,9 @@ export declare const SystemOne: {
|
|
|
83
89
|
readonly score: Schema.Number;
|
|
84
90
|
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
85
91
|
readonly confidence: Schema.Number;
|
|
92
|
+
}>, Schema.Struct<{
|
|
93
|
+
readonly type: Schema.Literal<"refusal">;
|
|
94
|
+
readonly message: Schema.optional<Schema.String>;
|
|
86
95
|
}>]>;
|
|
87
96
|
readonly Response: Schema.Struct<{
|
|
88
97
|
readonly model: Schema.String;
|
|
@@ -99,6 +108,9 @@ export declare const SystemOne: {
|
|
|
99
108
|
readonly score: Schema.Number;
|
|
100
109
|
readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
|
|
101
110
|
readonly confidence: Schema.Number;
|
|
111
|
+
}>, Schema.Struct<{
|
|
112
|
+
readonly type: Schema.Literal<"refusal">;
|
|
113
|
+
readonly message: Schema.optional<Schema.String>;
|
|
102
114
|
}>]>>;
|
|
103
115
|
readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
|
|
104
116
|
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
@@ -23,6 +23,8 @@ const Answer = Schema.Union([
|
|
|
23
23
|
probabilities: Schema.Record(Schema.String, Probability),
|
|
24
24
|
confidence: Probability,
|
|
25
25
|
}),
|
|
26
|
+
// OpenRouter's and OpenCode Zen's answer for a question the upstream model declined.
|
|
27
|
+
Schema.Struct({ type: Schema.Literal("refusal"), message: Schema.optional(Schema.String) }),
|
|
26
28
|
]).pipe(Schema.toTaggedUnion("type"));
|
|
27
29
|
const NativeUsage = Schema.StructWithRest(Schema.Struct({
|
|
28
30
|
input_tokens: Schema.optional(Schema.Number),
|
|
@@ -91,7 +93,7 @@ const placeMedia = Effect.fnUntraced(function* (request, mediaInput) {
|
|
|
91
93
|
if (media.length === 0)
|
|
92
94
|
return { state: state(parts.map(plain)) };
|
|
93
95
|
if (mediaInput === "state")
|
|
94
|
-
return { state: yield* Effect.forEach(parts, (part) => stateItem(part, unsupported)) };
|
|
96
|
+
return { state: yield* Effect.forEach(parts, (part) => stateItem(part, unsupported, true)) };
|
|
95
97
|
// Chat-style content in one user message: text and JSON as text parts, media as in `state`.
|
|
96
98
|
if (mediaInput === "state.messages")
|
|
97
99
|
return {
|
|
@@ -100,7 +102,7 @@ const placeMedia = Effect.fnUntraced(function* (request, mediaInput) {
|
|
|
100
102
|
{
|
|
101
103
|
role: "user",
|
|
102
104
|
content: yield* Effect.forEach(parts, (part) => part.type === "media"
|
|
103
|
-
? stateItem(part, unsupported)
|
|
105
|
+
? stateItem(part, unsupported, false)
|
|
104
106
|
: Effect.succeed({ type: "text", text: part.type === "text" ? part.text : encodeJson(part.value) })),
|
|
105
107
|
},
|
|
106
108
|
],
|
|
@@ -144,20 +146,37 @@ const plain = (part) => {
|
|
|
144
146
|
return part.value;
|
|
145
147
|
return undefined;
|
|
146
148
|
};
|
|
147
|
-
|
|
149
|
+
/** A media part as a Chat Completions content part; `files` sends other media, such as PDFs, as `file` parts. */
|
|
150
|
+
const stateItem = (part, unsupported, files) => {
|
|
148
151
|
if (part.type !== "media")
|
|
149
152
|
return Effect.succeed(plain(part));
|
|
150
153
|
const asset = part.media;
|
|
151
|
-
if (asset.kind !== "image" && asset.kind !== "audio" && asset.kind !== "video")
|
|
154
|
+
if (!files && asset.kind !== "image" && asset.kind !== "audio" && asset.kind !== "video")
|
|
152
155
|
return Effect.fail(unsupported(asset, "images, audio and video"));
|
|
153
156
|
return ProviderShared.requireInlineMedia(NAME, asset).pipe(Effect.map((inline) => {
|
|
154
157
|
if (asset.kind === "image")
|
|
155
158
|
return { type: "image_url", image_url: { url: inline.dataUrl } };
|
|
156
159
|
if (asset.kind === "video")
|
|
157
160
|
return { type: "video_url", video_url: { url: inline.dataUrl } };
|
|
158
|
-
|
|
161
|
+
if (asset.kind === "audio") {
|
|
162
|
+
const format = inline.mime.slice("audio/".length).toLowerCase();
|
|
163
|
+
return { type: "input_audio", input_audio: { data: inline.base64, format: audioFormats[format] ?? format } };
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
type: "file",
|
|
167
|
+
file: { file_data: inline.dataUrl, ...(part.filename === undefined ? {} : { filename: part.filename }) },
|
|
168
|
+
};
|
|
159
169
|
}));
|
|
160
170
|
};
|
|
171
|
+
/** OpenRouter's `input_audio` format names for MIME subtypes that aren't one themselves. */
|
|
172
|
+
const audioFormats = {
|
|
173
|
+
"x-wav": "wav",
|
|
174
|
+
wave: "wav",
|
|
175
|
+
"vnd.wave": "wav",
|
|
176
|
+
"x-m4a": "m4a",
|
|
177
|
+
"x-aiff": "aiff",
|
|
178
|
+
"x-flac": "flac",
|
|
179
|
+
};
|
|
161
180
|
/** Map System One's answers, keyed by question name, back to the request's question order. */
|
|
162
181
|
export const toResponse = (data, request, providerMetadataKey, invalid) => {
|
|
163
182
|
const names = request.questions.map((question) => question.name);
|
|
@@ -185,6 +204,13 @@ export const toResponse = (data, request, providerMetadataKey, invalid) => {
|
|
|
185
204
|
}));
|
|
186
205
|
};
|
|
187
206
|
const toAnswer = (question, answer) => {
|
|
207
|
+
if (answer.type === "refusal")
|
|
208
|
+
return {
|
|
209
|
+
name: question.name,
|
|
210
|
+
type: "error",
|
|
211
|
+
reason: "refusal",
|
|
212
|
+
...(answer.message === undefined ? {} : { message: answer.message }),
|
|
213
|
+
};
|
|
188
214
|
if (answer.type === "noul")
|
|
189
215
|
return { name: question.name, type: "predicate", probability: answer.noul };
|
|
190
216
|
if (answer.type === "choice") {
|
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-1227",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -584,7 +584,7 @@
|
|
|
584
584
|
"devDependencies": {
|
|
585
585
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
586
586
|
"@effect/platform-node": "4.1.0",
|
|
587
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
587
|
+
"@opencode/http-recorder": "0.0.0-dev-1227",
|
|
588
588
|
"@tsconfig/bun": "1.0.9",
|
|
589
589
|
"@types/bun": "1.4.3",
|
|
590
590
|
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
@@ -594,7 +594,7 @@
|
|
|
594
594
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
595
595
|
"@smithy/eventstream-codec": "4.2.14",
|
|
596
596
|
"@smithy/util-utf8": "4.2.2",
|
|
597
|
-
"@opencode/schema": "0.0.0-dev-
|
|
597
|
+
"@opencode/schema": "0.0.0-dev-1227",
|
|
598
598
|
"aws4fetch": "1.0.20",
|
|
599
599
|
"effect": "4.1.0",
|
|
600
600
|
"google-auth-library": "10.5.0"
|