@opencode/ai 0.0.0-dev-21763 → 0.0.0-dev-21765
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.
package/dist/protocols/gemini.js
CHANGED
|
@@ -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*
|
|
333
|
-
|
|
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:
|
|
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 =
|
|
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(
|
|
259
|
+
return mediaContent(GeminiGenerateContent.toolMedia(item));
|
|
257
260
|
});
|
|
258
261
|
});
|
|
259
262
|
const fromRequest = Effect.fn("GoogleInteractions.fromRequest")(function* (request) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect, Schema, type Stream } from "effect";
|
|
2
|
-
import type {
|
|
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
|
-
|
|
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 =
|
|
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-
|
|
3
|
+
"version": "0.0.0-dev-21765",
|
|
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-21765",
|
|
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-21765",
|
|
49
49
|
"aws4fetch": "1.0.20",
|
|
50
50
|
"effect": "4.0.1",
|
|
51
51
|
"google-auth-library": "10.5.0"
|