@opencode/ai 0.0.0-dev-21748 → 0.0.0-dev-21757
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.
|
@@ -21,6 +21,10 @@ export type RealtimeSession = Readonly<Record<string, unknown>>;
|
|
|
21
21
|
export interface RealtimeConnectInput {
|
|
22
22
|
readonly model: string;
|
|
23
23
|
readonly apiKey: Redacted.Redacted;
|
|
24
|
+
/** Where a GPT-Live session starts, OpenAI by default: another host of its API, such as OpenCode's. */
|
|
25
|
+
readonly baseURL?: string;
|
|
26
|
+
/** Headers that host needs besides the API key, such as OpenCode's workspace. */
|
|
27
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
24
28
|
readonly session?: RealtimeSession;
|
|
25
29
|
readonly transport: RealtimeTransportInput;
|
|
26
30
|
}
|
|
@@ -35,7 +35,7 @@ export const connect = Effect.fn("Realtime.connect")(function* (input) {
|
|
|
35
35
|
const session = { ...input.session, model: input.model };
|
|
36
36
|
switch (resolved.id) {
|
|
37
37
|
case "openai-live": {
|
|
38
|
-
const data = yield* post(resolved.id, `${OPENAI_BASE_URL}/live/sessions`, input.apiKey, { session, transport: input.transport }, LiveSessionResponse);
|
|
38
|
+
const data = yield* post(resolved.id, `${input.baseURL ?? OPENAI_BASE_URL}/live/sessions`, input.apiKey, { session, transport: input.transport }, LiveSessionResponse, { headers: input.headers });
|
|
39
39
|
return { type: "webrtc", sdp: data.transport.sdp };
|
|
40
40
|
}
|
|
41
41
|
case "openai-realtime": {
|
|
@@ -63,7 +63,7 @@ export const connect = Effect.fn("Realtime.connect")(function* (input) {
|
|
|
63
63
|
expireTime: new Date(now + 30 * 60_000).toISOString(),
|
|
64
64
|
newSessionExpireTime: new Date(expiresAt).toISOString(),
|
|
65
65
|
bidiGenerateContentSetup: { ...input.session, model: `models/${input.model}` },
|
|
66
|
-
}, AuthTokenResponse, "x-goog-api-key");
|
|
66
|
+
}, AuthTokenResponse, { authHeader: "x-goog-api-key" });
|
|
67
67
|
return {
|
|
68
68
|
type: "websocket",
|
|
69
69
|
url: "wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContentConstrained",
|
|
@@ -92,10 +92,10 @@ const AuthTokenResponse = Schema.fromJsonString(Schema.Struct({
|
|
|
92
92
|
name: Schema.String,
|
|
93
93
|
}));
|
|
94
94
|
const invalidRequest = (message) => new AIError({ reason: new InvalidRequestError({ message }) });
|
|
95
|
-
const post = (route, url, apiKey, body, response,
|
|
95
|
+
const post = (route, url, apiKey, body, response, options = {}) => Effect.gen(function* () {
|
|
96
96
|
const executor = yield* RequestExecutor.Service;
|
|
97
|
-
const res = yield* executor.execute(HttpClientRequest.post(url).pipe(authHeader
|
|
98
|
-
? HttpClientRequest.setHeader(authHeader, Redacted.value(apiKey))
|
|
97
|
+
const res = yield* executor.execute(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders(options.headers ?? {}), options.authHeader
|
|
98
|
+
? HttpClientRequest.setHeader(options.authHeader, Redacted.value(apiKey))
|
|
99
99
|
: HttpClientRequest.bearerToken(apiKey), body instanceof FormData
|
|
100
100
|
? HttpClientRequest.bodyFormData(body)
|
|
101
101
|
: HttpClientRequest.bodyText(encodeJson(body), "application/json")));
|
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-21757",
|
|
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-21757",
|
|
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-21757",
|
|
49
49
|
"aws4fetch": "1.0.20",
|
|
50
50
|
"effect": "4.0.1",
|
|
51
51
|
"google-auth-library": "10.5.0"
|