@opencode/ai 0.0.0-dev-21233 → 0.0.0-dev-21244
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect,
|
|
1
|
+
import { Effect, Redacted } from "effect";
|
|
2
2
|
import { AIError } from "../schema/index.js";
|
|
3
3
|
export type RealtimeTransportInput = {
|
|
4
4
|
readonly type: "webrtc";
|
|
@@ -35,6 +35,10 @@ export declare const engine: (model: string) => {
|
|
|
35
35
|
readonly family: "grok-voice";
|
|
36
36
|
readonly id: "xai-realtime";
|
|
37
37
|
readonly provider: "xai";
|
|
38
|
+
} | {
|
|
39
|
+
readonly family: "gemini-3.8-live";
|
|
40
|
+
readonly id: "gemini-live";
|
|
41
|
+
readonly provider: "google";
|
|
38
42
|
} | undefined;
|
|
39
43
|
export declare const connect: (input: RealtimeConnectInput) => Effect.Effect<RealtimeTransport, AIError, import("../route/executor-service.js").RequestExecutorService>;
|
|
40
44
|
export declare const Realtime: {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Clock, Effect, Redacted, Schema } from "effect";
|
|
2
2
|
import { HttpClientRequest } from "effect/http";
|
|
3
3
|
import { RequestExecutor } from "../route/executor.js";
|
|
4
4
|
import { AIError, HttpContext, InvalidProviderOutputError, InvalidRequestError } from "../schema/index.js";
|
|
5
5
|
import { encodeJson } from "../utils/json.js";
|
|
6
6
|
const OPENAI_BASE_URL = "https://api.openai.com/v1";
|
|
7
7
|
const XAI_BASE_URL = "https://api.x.ai/v1";
|
|
8
|
+
const GOOGLE_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
8
9
|
const engines = [
|
|
9
10
|
{ family: "gpt-live", id: "openai-live", provider: "openai" },
|
|
10
11
|
{ family: "gpt-realtime", id: "openai-realtime", provider: "openai" },
|
|
11
12
|
{ family: "grok-voice", id: "xai-realtime", provider: "xai" },
|
|
13
|
+
{ family: "gemini-3.8-live", id: "gemini-live", provider: "google" },
|
|
12
14
|
];
|
|
13
15
|
// Matches the bare family name (`gpt-realtime`) and its versions (`gpt-realtime-2.1`, `gpt-realtime-mini`).
|
|
14
16
|
export const engine = (model) => engines.find((item) => model === item.family || model.startsWith(`${item.family}-`));
|
|
@@ -39,6 +41,24 @@ export const connect = Effect.fn("Realtime.connect")(function* (input) {
|
|
|
39
41
|
return yield* invalidRequest("xAI Grok Voice only supports WebSocket transport");
|
|
40
42
|
return yield* clientSecret(resolved.id, XAI_BASE_URL, input.model, input.apiKey);
|
|
41
43
|
}
|
|
44
|
+
case "gemini-live": {
|
|
45
|
+
if (input.transport.type !== "websocket")
|
|
46
|
+
return yield* invalidRequest("Google Gemini Live only supports WebSocket transport");
|
|
47
|
+
const now = yield* Clock.currentTimeMillis;
|
|
48
|
+
const expiresAt = now + 60_000;
|
|
49
|
+
const data = yield* post(resolved.id, `${GOOGLE_BASE_URL}/auth_tokens`, input.apiKey, {
|
|
50
|
+
uses: 1,
|
|
51
|
+
expireTime: new Date(now + 30 * 60_000).toISOString(),
|
|
52
|
+
newSessionExpireTime: new Date(expiresAt).toISOString(),
|
|
53
|
+
bidiGenerateContentSetup: { ...input.session, model: `models/${input.model}` },
|
|
54
|
+
}, AuthTokenResponse, "x-goog-api-key");
|
|
55
|
+
return {
|
|
56
|
+
type: "websocket",
|
|
57
|
+
url: "wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContentConstrained",
|
|
58
|
+
token: data.name,
|
|
59
|
+
expiresAt: Math.floor(expiresAt / 1000),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
42
62
|
}
|
|
43
63
|
});
|
|
44
64
|
export const Realtime = {
|
|
@@ -55,10 +75,15 @@ const ClientSecretResponse = Schema.fromJsonString(Schema.Struct({
|
|
|
55
75
|
value: Schema.String,
|
|
56
76
|
expires_at: Schema.Number,
|
|
57
77
|
}));
|
|
78
|
+
const AuthTokenResponse = Schema.fromJsonString(Schema.Struct({
|
|
79
|
+
name: Schema.String,
|
|
80
|
+
}));
|
|
58
81
|
const invalidRequest = (message) => new AIError({ reason: new InvalidRequestError({ message }) });
|
|
59
|
-
const post = (route, url, apiKey, body, response) => Effect.gen(function* () {
|
|
82
|
+
const post = (route, url, apiKey, body, response, authHeader) => Effect.gen(function* () {
|
|
60
83
|
const executor = yield* RequestExecutor.Service;
|
|
61
|
-
const res = yield* executor.execute(HttpClientRequest.post(url).pipe(
|
|
84
|
+
const res = yield* executor.execute(HttpClientRequest.post(url).pipe(authHeader
|
|
85
|
+
? HttpClientRequest.setHeader(authHeader, Redacted.value(apiKey))
|
|
86
|
+
: HttpClientRequest.bearerToken(apiKey), body instanceof FormData
|
|
62
87
|
? HttpClientRequest.bodyFormData(body)
|
|
63
88
|
: HttpClientRequest.bodyText(encodeJson(body), "application/json")));
|
|
64
89
|
const http = new HttpContext({ url: res.request.url, status: res.status, headers: res.headers });
|
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-21244",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
36
36
|
"@effect/platform-node": "4.0.1",
|
|
37
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
37
|
+
"@opencode/http-recorder": "0.0.0-dev-21244",
|
|
38
38
|
"@tsconfig/bun": "1.0.9",
|
|
39
39
|
"@types/bun": "1.4.0",
|
|
40
40
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
45
45
|
"@smithy/eventstream-codec": "4.2.14",
|
|
46
46
|
"@smithy/util-utf8": "4.2.2",
|
|
47
|
-
"@opencode/schema": "0.0.0-dev-
|
|
47
|
+
"@opencode/schema": "0.0.0-dev-21244",
|
|
48
48
|
"aws4fetch": "1.0.20",
|
|
49
49
|
"effect": "4.0.1",
|
|
50
50
|
"google-auth-library": "10.5.0"
|