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

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.
@@ -59,7 +59,6 @@ const GeminiInlineDataPart = Schema.Struct({
59
59
  }),
60
60
  thoughtSignature: optionalNull(Schema.String),
61
61
  });
62
- /** Gemini Files API reference; the only remote input Gemini accepts. */
63
62
  const GeminiFileDataPart = Schema.Struct({
64
63
  fileData: Schema.Struct({
65
64
  mimeType: Schema.String,
@@ -329,11 +328,13 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
329
328
  for (const item of content) {
330
329
  if (item.type === "text")
331
330
  continue;
332
- const value = yield* ProviderShared.requireInlineMedia("Gemini", ProviderShared.toolFileMedia(item).media);
333
- media.push({ inlineData: { mimeType: value.mime, data: value.base64 } });
331
+ const value = yield* GeminiGenerateContent.mediaPart("Gemini", GeminiGenerateContent.toolMedia(item));
332
+ // Nested fileData can be accepted without the model seeing the video, even on newer Gemini models.
333
+ if (legacyToolMedia || "fileData" in value)
334
+ (pendingMedia ??= []).push(value);
335
+ else
336
+ media.push(value);
334
337
  }
335
- if (legacyToolMedia && media.length > 0)
336
- (pendingMedia ??= []).push(...media);
337
338
  parts.push({
338
339
  functionResponse: {
339
340
  ...(omitCallIds ? {} : { id: part.id }),
@@ -342,7 +343,7 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
342
343
  name: part.name,
343
344
  content: text.join("\n"),
344
345
  },
345
- parts: legacyToolMedia || media.length === 0 ? undefined : media,
346
+ parts: media.length === 0 ? undefined : media,
346
347
  },
347
348
  });
348
349
  }
@@ -11,6 +11,7 @@ import { encodeJson } from "../utils/json.js";
11
11
  import { JsonObject, knownString, lenient, optionalNull, ProviderShared } from "./shared.js";
12
12
  import { Lifecycle } from "./utils/lifecycle.js";
13
13
  import { MediaInput } from "./utils/media-input.js";
14
+ import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
14
15
  import { ToolStream } from "./utils/tool-stream.js";
15
16
  const ADAPTER = "google-interactions";
16
17
  export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
@@ -172,7 +173,9 @@ const mediaContent = Effect.fnUntraced(function* (asset) {
172
173
  asset.mediaType !== "text/csv")
173
174
  return yield* ProviderShared.invalidRequest(`Google Interactions does not support ${asset.mediaType} document input`);
174
175
  const type = asset.kind === "image" || asset.kind === "audio" || asset.kind === "video" ? asset.kind : "document";
175
- const uri = MediaInput.refID(asset, ProviderID.make("google"));
176
+ const uri = asset.kind === "video" && asset.source.type === "url" && /^https?:\/\//i.test(asset.source.url)
177
+ ? asset.source.url
178
+ : MediaInput.refID(asset, ProviderID.make("google"));
176
179
  if (uri !== undefined)
177
180
  return { type, uri, mime_type: asset.mediaType };
178
181
  const inline = yield* ProviderShared.requireInlineMedia("Google Interactions", asset);
@@ -253,7 +256,7 @@ const lowerToolResult = Effect.fnUntraced(function* (part) {
253
256
  return yield* Effect.forEach(part.result.value, (item) => {
254
257
  if (item.type === "text")
255
258
  return Effect.succeed({ type: "text", text: item.text });
256
- return mediaContent(ProviderShared.toolFileMedia(item).media);
259
+ return mediaContent(GeminiGenerateContent.toolMedia(item));
257
260
  });
258
261
  });
259
262
  const fromRequest = Effect.fn("GoogleInteractions.fromRequest")(function* (request) {
@@ -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 yield* new AIError({
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;
@@ -1,5 +1,6 @@
1
1
  import { Effect, Schema, type Stream } from "effect";
2
- import type { Media } from "../../media.js";
2
+ import type { Tool } from "@opencode/schema/tool";
3
+ import { Media } from "../../media.js";
3
4
  import type { MediaProtocol } from "../../route/media-protocol.js";
4
5
  import { AIError, type MediaUsage, type ProviderMetadata } from "../../schema/index.js";
5
6
  declare const UsageMetadata: Schema.Struct<{
@@ -57,6 +58,7 @@ export declare const usage: (usage: UsageMetadata | undefined) => MediaUsage | u
57
58
  export declare const providerMetadata: (state: Metadata) => ProviderMetadata;
58
59
  export declare const path: (model: string, mode: MediaProtocol.Mode) => string;
59
60
  export declare const frames: (bytes: Stream.Stream<Uint8Array, AIError>, mode: MediaProtocol.Mode) => Stream.Stream<string, AIError, never>;
61
+ export declare const toolMedia: (item: Tool.FileContent) => Media.Asset;
60
62
  export declare const mediaPart: (route: string, asset: Media.Asset) => Effect.Effect<{
61
63
  readonly fileData: {
62
64
  readonly mimeType: string;
@@ -1,4 +1,5 @@
1
1
  import { Effect, Schema } from "effect";
2
+ import { Media } from "../../media.js";
2
3
  import { Framing } from "../../route/framing.js";
3
4
  import { AIError, ContentPolicyError, ProviderID } from "../../schema/index.js";
4
5
  import { ProviderShared } from "../shared.js";
@@ -88,9 +89,13 @@ export const providerMetadata = (state) => ({
88
89
  export const path = (model, mode) => mode === "stream" ? `/models/${model}:streamGenerateContent?alt=sse` : `/models/${model}:generateContent`;
89
90
  // `generateContent` answers with one document shaped exactly like a streamed chunk, so it is a single frame.
90
91
  export const frames = (bytes, mode) => mode === "stream" ? Framing.sse.frame(bytes) : Framing.document.frame(bytes);
91
- // Gemini does not fetch public URLs; inline payloads and Gemini Files references are the accepted inputs.
92
+ export const toolMedia = (item) => item.mime.startsWith("video/") && item.uri.startsWith("gs://")
93
+ ? Media.ref(PROVIDER, item.uri, item.mime)
94
+ : ProviderShared.toolFileMedia(item).media;
92
95
  export const mediaPart = (route, asset) => {
93
- const fileUri = MediaInput.refID(asset, PROVIDER);
96
+ const fileUri = asset.kind === "video" && asset.source.type === "url" && /^https?:\/\//i.test(asset.source.url)
97
+ ? asset.source.url
98
+ : MediaInput.refID(asset, PROVIDER);
94
99
  if (fileUri !== undefined)
95
100
  return Effect.succeed({ fileData: { mimeType: asset.mediaType, fileUri } });
96
101
  return ProviderShared.requireInlineMedia(route, asset).pipe(Effect.map((media) => ({ inlineData: { mimeType: media.mime, data: media.base64 } })));
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-21761",
3
+ "version": "0.0.0-dev-21764",
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-21761",
38
+ "@opencode/http-recorder": "0.0.0-dev-21764",
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-21761",
48
+ "@opencode/schema": "0.0.0-dev-21764",
49
49
  "aws4fetch": "1.0.20",
50
50
  "effect": "4.0.1",
51
51
  "google-auth-library": "10.5.0"