@opencode/ai 2.0.31 → 2.1.0
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/ai-client.d.ts +2 -2
- package/dist/experimental/evaluation-client.d.ts +1 -1
- package/dist/experimental/evaluation.d.ts +20 -20
- package/dist/experimental/realtime.d.ts +47 -0
- package/dist/experimental/realtime.js +99 -0
- package/dist/experimental/system-one.d.ts +1 -1
- package/dist/experimental.d.ts +2 -0
- package/dist/experimental.js +1 -0
- package/dist/image-client.d.ts +8 -8
- package/dist/image.d.ts +593 -437
- package/dist/llm.d.ts +51 -51
- package/dist/media-client.d.ts +1 -1
- package/dist/media.d.ts +4 -4
- package/dist/promise.d.ts +199 -198
- package/dist/protocols/alibaba-chat.d.ts +81 -82
- package/dist/protocols/alibaba-chat.js +0 -1
- package/dist/protocols/alibaba-messages.d.ts +99 -99
- package/dist/protocols/alibaba-responses.d.ts +120 -120
- package/dist/protocols/anthropic-messages.d.ts +187 -187
- package/dist/protocols/anthropic-messages.js +3 -2
- package/dist/protocols/assemblyai-transcription.d.ts +1 -1
- package/dist/protocols/bedrock-converse.d.ts +75 -79
- package/dist/protocols/bfl-images.d.ts +1 -1
- package/dist/protocols/cartesia-speech.d.ts +17 -17
- package/dist/protocols/cohere-chat.d.ts +26 -23
- package/dist/protocols/cohere-chat.js +22 -1
- package/dist/protocols/deepgram-speech.d.ts +17 -17
- package/dist/protocols/deepgram-transcription.d.ts +1 -1
- package/dist/protocols/elevenlabs-speech.d.ts +17 -17
- package/dist/protocols/elevenlabs-transcription.d.ts +1 -1
- package/dist/protocols/fal-images.d.ts +1 -1
- package/dist/protocols/fal-video.d.ts +1 -1
- package/dist/protocols/gemini.d.ts +55 -55
- package/dist/protocols/gemini.js +11 -1
- package/dist/protocols/google-images.d.ts +1 -1
- package/dist/protocols/google-interactions.d.ts +64 -62
- package/dist/protocols/google-interactions.js +19 -1
- package/dist/protocols/google-speech.d.ts +17 -17
- package/dist/protocols/google-transcription.d.ts +47 -47
- package/dist/protocols/google-video.d.ts +1 -1
- package/dist/protocols/meta-messages.d.ts +121 -121
- package/dist/protocols/meta-responses.d.ts +201 -201
- package/dist/protocols/mistral-chat.d.ts +45 -45
- package/dist/protocols/open-responses-channel.d.ts +1 -1
- package/dist/protocols/open-responses.d.ts +584 -450
- package/dist/protocols/open-responses.js +27 -35
- package/dist/protocols/openai-chat.d.ts +248 -248
- package/dist/protocols/openai-chat.js +11 -42
- package/dist/protocols/openai-compatible-chat.d.ts +32 -32
- package/dist/protocols/openai-compatible-responses.d.ts +88 -88
- package/dist/protocols/openai-images.d.ts +17 -17
- package/dist/protocols/openai-responses.d.ts +567 -567
- package/dist/protocols/openai-responses.js +1 -1
- package/dist/protocols/openai-speech.d.ts +17 -17
- package/dist/protocols/openai-transcription.d.ts +47 -47
- package/dist/protocols/replicate-images.d.ts +1 -1
- package/dist/protocols/runway-video.d.ts +1 -1
- package/dist/protocols/shared.d.ts +12 -1
- package/dist/protocols/shared.js +17 -1
- package/dist/protocols/stability-images.d.ts +2 -2
- package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
- package/dist/protocols/utils/bedrock-media.d.ts +4 -4
- package/dist/protocols/utils/openai-options.d.ts +1 -1
- package/dist/protocols/utils/speech-stream.d.ts +1 -1
- package/dist/protocols/utils/tool-schema.d.ts +10 -5
- package/dist/protocols/utils/tool-stream.d.ts +152 -152
- package/dist/protocols/venice-chat.d.ts +109 -110
- package/dist/protocols/venice-chat.js +0 -1
- package/dist/protocols/xai-images.d.ts +1 -1
- package/dist/protocols/xai-responses.d.ts +79 -79
- package/dist/protocols/xai-video.d.ts +1 -1
- package/dist/protocols/zai-chat.d.ts +77 -78
- package/dist/protocols/zai-chat.js +0 -1
- package/dist/protocols/zai-images.d.ts +1 -1
- package/dist/protocols/zai-messages.d.ts +97 -97
- package/dist/providers/alibaba.d.ts +222 -283
- package/dist/providers/amazon-bedrock-mantle.d.ts +291 -298
- package/dist/providers/amazon-bedrock.d.ts +22 -28
- package/dist/providers/anthropic-compatible.d.ts +86 -90
- package/dist/providers/anthropic.d.ts +86 -90
- package/dist/providers/assemblyai.d.ts +2 -6
- package/dist/providers/azure.d.ts +228 -238
- package/dist/providers/baseten.d.ts +66 -70
- package/dist/providers/black-forest-labs.d.ts +2 -6
- package/dist/providers/cartesia.d.ts +2 -6
- package/dist/providers/cerebras.d.ts +66 -70
- package/dist/providers/cerebras.js +0 -1
- package/dist/providers/cloudflare-ai-gateway.d.ts +352 -356
- package/dist/providers/cloudflare-workers-ai.d.ts +66 -70
- package/dist/providers/cohere.d.ts +122 -132
- package/dist/providers/cohere.js +0 -2
- package/dist/providers/deepgram.d.ts +2 -7
- package/dist/providers/deepinfra.d.ts +66 -70
- package/dist/providers/deepinfra.js +0 -1
- package/dist/providers/deepseek.d.ts +66 -70
- package/dist/providers/deepseek.js +1 -1
- package/dist/providers/digitalocean.d.ts +137 -141
- package/dist/providers/elevenlabs.d.ts +2 -7
- package/dist/providers/fal.d.ts +2 -7
- package/dist/providers/fireworks.d.ts +66 -70
- package/dist/providers/google-vertex-chat.d.ts +34 -38
- package/dist/providers/google-vertex-interactions.d.ts +31 -41
- package/dist/providers/google-vertex-messages.d.ts +81 -85
- package/dist/providers/google-vertex-mistral.d.ts +23 -27
- package/dist/providers/google-vertex-responses.d.ts +90 -94
- package/dist/providers/google-vertex.d.ts +26 -30
- package/dist/providers/google.d.ts +94 -109
- package/dist/providers/groq.d.ts +111 -115
- package/dist/providers/groq.js +0 -1
- package/dist/providers/meta.d.ts +309 -317
- package/dist/providers/meta.js +1 -1
- package/dist/providers/minimax.d.ts +296 -303
- package/dist/providers/minimax.js +1 -1
- package/dist/providers/mistral.d.ts +22 -26
- package/dist/providers/moonshot.d.ts +296 -303
- package/dist/providers/moonshot.js +0 -1
- package/dist/providers/openai-compatible-responses.d.ts +90 -94
- package/dist/providers/openai-compatible.d.ts +34 -38
- package/dist/providers/openai.d.ts +93 -108
- package/dist/providers/opencode.d.ts +2 -8
- package/dist/providers/openrouter.d.ts +137 -144
- package/dist/providers/replicate.d.ts +2 -6
- package/dist/providers/runway.d.ts +2 -6
- package/dist/providers/stability.d.ts +2 -7
- package/dist/providers/togetherai.d.ts +66 -70
- package/dist/providers/togetherai.js +1 -1
- package/dist/providers/typesafe-ai.d.ts +2 -8
- package/dist/providers/venice.d.ts +58 -63
- package/dist/providers/vercel-ai-gateway.d.ts +2 -12
- package/dist/providers/xai.d.ts +38 -50
- package/dist/providers/zai-coding-plan.d.ts +206 -213
- package/dist/providers/zai.d.ts +40 -46
- package/dist/route/client.d.ts +51 -51
- package/dist/route/media-protocol.d.ts +1 -1
- package/dist/route/transport/http.d.ts +1 -1
- package/dist/route/transport/websocket.d.ts +8 -8
- package/dist/schema/errors.d.ts +19 -19
- package/dist/schema/events.d.ts +3090 -3288
- package/dist/schema/messages.d.ts +8 -7
- package/dist/schema/options.d.ts +2 -1
- package/dist/schema/options.js +2 -1
- package/dist/speech-client.d.ts +8 -8
- package/dist/speech.d.ts +434 -398
- package/dist/testing.d.ts +338 -338
- package/dist/tool-runtime.d.ts +1 -1
- package/dist/transcription-client.d.ts +23 -23
- package/dist/transcription.d.ts +562 -646
- package/dist/utils/sanitize.d.ts +4 -0
- package/dist/utils/sanitize.js +23 -6
- package/dist/video-client.d.ts +8 -8
- package/dist/video.d.ts +416 -372
- package/package.json +6 -6
package/dist/ai-client.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import { RequestExecutor } from "./route/executor.js";
|
|
3
3
|
/** Every modality client over `executor`, which stays in the output so `asset.bytes()` and `Media.write` resolve. */
|
|
4
|
-
export declare const layerWith: <E, R>(executor: Layer.Layer<RequestExecutor.Service, E, R>) => Layer.Layer<import("./
|
|
4
|
+
export declare const layerWith: <E, R>(executor: Layer.Layer<RequestExecutor.Service, E, R>) => Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | import("./route/executor-service.js").RequestExecutorService | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, E, R>;
|
|
5
5
|
/** Every modality client plus the executor over `RequestExecutor.fetchLayer`: the one layer most programs need. */
|
|
6
|
-
export declare const layer: Layer.Layer<import("./
|
|
6
|
+
export declare const layer: Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | import("./route/executor-service.js").RequestExecutorService | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, never, never>;
|
|
7
7
|
export type Services = Layer.Success<typeof layer>;
|
|
8
8
|
export * as AIClient from "./ai-client.js";
|
|
@@ -16,6 +16,6 @@ export declare const EvaluationClient: {
|
|
|
16
16
|
readonly Service: typeof Service;
|
|
17
17
|
readonly layer: Layer.Layer<Service, never, import("../route/executor-service.js").RequestExecutorService>;
|
|
18
18
|
readonly fetchLayer: Layer.Layer<import("../route/executor-service.js").RequestExecutorService | Service, never, never>;
|
|
19
|
-
readonly evaluate:
|
|
19
|
+
readonly evaluate: typeof evaluate;
|
|
20
20
|
};
|
|
21
21
|
export {};
|
|
@@ -7,9 +7,9 @@ export declare const ChoiceQuestion: Schema.Struct<{
|
|
|
7
7
|
readonly type: Schema.Literal<"choice">;
|
|
8
8
|
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
9
9
|
readonly criteria: Schema.refine<{
|
|
10
|
-
readonly [x: string]: string | {
|
|
10
|
+
readonly [x: string]: string | readonly Schema.Json[] | {
|
|
11
11
|
readonly [x: string]: Schema.Json;
|
|
12
|
-
} |
|
|
12
|
+
} | null;
|
|
13
13
|
}, Schema.$Record<Schema.String, Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>>>;
|
|
14
14
|
}>;
|
|
15
15
|
export type ChoiceQuestion = Schema.Schema.Type<typeof ChoiceQuestion>;
|
|
@@ -32,9 +32,9 @@ export declare const EvaluationQuestion: Schema.toTaggedUnion<"type", readonly [
|
|
|
32
32
|
readonly type: Schema.Literal<"choice">;
|
|
33
33
|
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
34
34
|
readonly criteria: Schema.refine<{
|
|
35
|
-
readonly [x: string]: string | {
|
|
35
|
+
readonly [x: string]: string | readonly Schema.Json[] | {
|
|
36
36
|
readonly [x: string]: Schema.Json;
|
|
37
|
-
} |
|
|
37
|
+
} | null;
|
|
38
38
|
}, Schema.$Record<Schema.String, Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>>>;
|
|
39
39
|
}>, Schema.Struct<{
|
|
40
40
|
readonly type: Schema.Literal<"score">;
|
|
@@ -131,43 +131,43 @@ declare const EvaluationRequest_base: Schema.Class<EvaluationRequest, Schema.Str
|
|
|
131
131
|
readonly questions: Schema.refine<{
|
|
132
132
|
readonly [x: string]: {
|
|
133
133
|
readonly type: "choice";
|
|
134
|
-
readonly instructions: string | {
|
|
134
|
+
readonly instructions: string | readonly Schema.Json[] | {
|
|
135
135
|
readonly [x: string]: Schema.Json;
|
|
136
|
-
}
|
|
136
|
+
};
|
|
137
137
|
readonly criteria: {
|
|
138
|
-
readonly [x: string]: string | {
|
|
138
|
+
readonly [x: string]: string | readonly Schema.Json[] | {
|
|
139
139
|
readonly [x: string]: Schema.Json;
|
|
140
|
-
} |
|
|
140
|
+
} | null;
|
|
141
141
|
};
|
|
142
142
|
} | {
|
|
143
143
|
readonly type: "score";
|
|
144
|
-
readonly instructions: string | {
|
|
144
|
+
readonly instructions: string | readonly Schema.Json[] | {
|
|
145
145
|
readonly [x: string]: Schema.Json;
|
|
146
|
-
}
|
|
147
|
-
readonly criteria: readonly (string | {
|
|
146
|
+
};
|
|
147
|
+
readonly criteria: readonly (string | readonly Schema.Json[] | {
|
|
148
148
|
readonly [x: string]: Schema.Json;
|
|
149
|
-
} |
|
|
149
|
+
} | null)[];
|
|
150
150
|
} | {
|
|
151
151
|
readonly type: "boolean";
|
|
152
|
-
readonly instructions: string | {
|
|
152
|
+
readonly instructions: string | readonly Schema.Json[] | {
|
|
153
153
|
readonly [x: string]: Schema.Json;
|
|
154
|
-
}
|
|
154
|
+
};
|
|
155
155
|
readonly criteria?: {
|
|
156
|
-
readonly true?: string | {
|
|
156
|
+
readonly true?: string | readonly Schema.Json[] | {
|
|
157
157
|
readonly [x: string]: Schema.Json;
|
|
158
|
-
} |
|
|
159
|
-
readonly false?: string | {
|
|
158
|
+
} | null | undefined;
|
|
159
|
+
readonly false?: string | readonly Schema.Json[] | {
|
|
160
160
|
readonly [x: string]: Schema.Json;
|
|
161
|
-
} |
|
|
161
|
+
} | null | undefined;
|
|
162
162
|
} | undefined;
|
|
163
163
|
};
|
|
164
164
|
}, Schema.$Record<Schema.String, Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
165
165
|
readonly type: Schema.Literal<"choice">;
|
|
166
166
|
readonly instructions: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
167
167
|
readonly criteria: Schema.refine<{
|
|
168
|
-
readonly [x: string]: string | {
|
|
168
|
+
readonly [x: string]: string | readonly Schema.Json[] | {
|
|
169
169
|
readonly [x: string]: Schema.Json;
|
|
170
|
-
} |
|
|
170
|
+
} | null;
|
|
171
171
|
}, Schema.$Record<Schema.String, Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.Codec<Schema.Json, Schema.Json, never, never>>]>>>>;
|
|
172
172
|
}>, Schema.Struct<{
|
|
173
173
|
readonly type: Schema.Literal<"score">;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Effect, Redacted } from "effect";
|
|
2
|
+
import { AIError } from "../schema/index.js";
|
|
3
|
+
export type RealtimeTransportInput = {
|
|
4
|
+
readonly type: "webrtc";
|
|
5
|
+
readonly sdp: string;
|
|
6
|
+
readonly dcid?: number;
|
|
7
|
+
} | {
|
|
8
|
+
readonly type: "websocket";
|
|
9
|
+
};
|
|
10
|
+
export type RealtimeTransport = {
|
|
11
|
+
readonly type: "webrtc";
|
|
12
|
+
readonly sdp: string;
|
|
13
|
+
} | {
|
|
14
|
+
readonly type: "websocket";
|
|
15
|
+
readonly url: string;
|
|
16
|
+
readonly token: string;
|
|
17
|
+
readonly expiresAt: number;
|
|
18
|
+
};
|
|
19
|
+
export type RealtimeSession = Readonly<Record<string, unknown>>;
|
|
20
|
+
export interface RealtimeConnectInput {
|
|
21
|
+
readonly model: string;
|
|
22
|
+
readonly apiKey: Redacted.Redacted;
|
|
23
|
+
readonly session?: RealtimeSession;
|
|
24
|
+
readonly transport: RealtimeTransportInput;
|
|
25
|
+
}
|
|
26
|
+
export declare const engine: (model: string) => {
|
|
27
|
+
readonly family: "gpt-live";
|
|
28
|
+
readonly id: "openai-live";
|
|
29
|
+
readonly provider: "openai";
|
|
30
|
+
} | {
|
|
31
|
+
readonly family: "gpt-realtime";
|
|
32
|
+
readonly id: "openai-realtime";
|
|
33
|
+
readonly provider: "openai";
|
|
34
|
+
} | {
|
|
35
|
+
readonly family: "grok-voice";
|
|
36
|
+
readonly id: "xai-realtime";
|
|
37
|
+
readonly provider: "xai";
|
|
38
|
+
} | {
|
|
39
|
+
readonly family: "gemini-3.8-live";
|
|
40
|
+
readonly id: "gemini-live";
|
|
41
|
+
readonly provider: "google";
|
|
42
|
+
} | undefined;
|
|
43
|
+
export declare const connect: (input: RealtimeConnectInput) => Effect.Effect<RealtimeTransport, AIError, import("../route/executor-service.js").RequestExecutorService>;
|
|
44
|
+
export declare const Realtime: {
|
|
45
|
+
readonly engine: typeof engine;
|
|
46
|
+
readonly connect: (input: RealtimeConnectInput) => Effect.Effect<RealtimeTransport, AIError, import("../route/executor-service.js").RequestExecutorService>;
|
|
47
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Clock, Effect, Redacted, Schema } from "effect";
|
|
2
|
+
import { HttpClientRequest } from "effect/http";
|
|
3
|
+
import { RequestExecutor } from "../route/executor.js";
|
|
4
|
+
import { AIError, HttpContext, InvalidProviderOutputError, InvalidRequestError } from "../schema/index.js";
|
|
5
|
+
import { encodeJson } from "../utils/json.js";
|
|
6
|
+
const OPENAI_BASE_URL = "https://api.openai.com/v1";
|
|
7
|
+
const XAI_BASE_URL = "https://api.x.ai/v1";
|
|
8
|
+
const GOOGLE_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
9
|
+
const engines = [
|
|
10
|
+
{ family: "gpt-live", id: "openai-live", provider: "openai" },
|
|
11
|
+
{ family: "gpt-realtime", id: "openai-realtime", provider: "openai" },
|
|
12
|
+
{ family: "grok-voice", id: "xai-realtime", provider: "xai" },
|
|
13
|
+
{ family: "gemini-3.8-live", id: "gemini-live", provider: "google" },
|
|
14
|
+
];
|
|
15
|
+
// Matches the bare family name (`gpt-realtime`) and its versions (`gpt-realtime-2.1`, `gpt-realtime-mini`).
|
|
16
|
+
export const engine = (model) => engines.find((item) => model === item.family || model.startsWith(`${item.family}-`));
|
|
17
|
+
export const connect = Effect.fn("Realtime.connect")(function* (input) {
|
|
18
|
+
const resolved = engine(input.model);
|
|
19
|
+
if (!resolved)
|
|
20
|
+
return yield* invalidRequest(`Unsupported voice model: ${input.model}`);
|
|
21
|
+
const session = { ...input.session, model: input.model };
|
|
22
|
+
switch (resolved.id) {
|
|
23
|
+
case "openai-live": {
|
|
24
|
+
if (input.transport.type !== "webrtc")
|
|
25
|
+
return yield* invalidRequest("OpenAI GPT-Live only supports WebRTC transport");
|
|
26
|
+
const data = yield* post(resolved.id, `${OPENAI_BASE_URL}/live/sessions`, input.apiKey, { session, transport: input.transport }, LiveSessionResponse);
|
|
27
|
+
return { type: "webrtc", sdp: data.transport.sdp };
|
|
28
|
+
}
|
|
29
|
+
case "openai-realtime": {
|
|
30
|
+
if (input.transport.type === "websocket")
|
|
31
|
+
return yield* clientSecret(resolved.id, OPENAI_BASE_URL, input.model, input.apiKey, session);
|
|
32
|
+
const form = new FormData();
|
|
33
|
+
form.append("sdp", input.transport.sdp);
|
|
34
|
+
form.append("session", encodeJson(session));
|
|
35
|
+
const query = input.transport.dcid === undefined ? "" : `?dcid=${input.transport.dcid}`;
|
|
36
|
+
const sdp = yield* post(resolved.id, `${OPENAI_BASE_URL}/realtime/calls${query}`, input.apiKey, form, Schema.String);
|
|
37
|
+
return { type: "webrtc", sdp };
|
|
38
|
+
}
|
|
39
|
+
case "xai-realtime": {
|
|
40
|
+
if (input.transport.type !== "websocket")
|
|
41
|
+
return yield* invalidRequest("xAI Grok Voice only supports WebSocket transport");
|
|
42
|
+
return yield* clientSecret(resolved.id, XAI_BASE_URL, input.model, input.apiKey);
|
|
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
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
export const Realtime = {
|
|
65
|
+
engine,
|
|
66
|
+
connect,
|
|
67
|
+
};
|
|
68
|
+
const LiveSessionResponse = Schema.fromJsonString(Schema.Struct({
|
|
69
|
+
transport: Schema.Struct({ sdp: Schema.String }),
|
|
70
|
+
}));
|
|
71
|
+
// xAI's ephemeral-token docs (https://docs.x.ai/developers/model-capabilities/audio/ephemeral-tokens)
|
|
72
|
+
// document the request body (`{ expires_after: { seconds } }`) but not the response payload; we assume
|
|
73
|
+
// it mirrors OpenAI's `{ value, expires_at }` response shape.
|
|
74
|
+
const ClientSecretResponse = Schema.fromJsonString(Schema.Struct({
|
|
75
|
+
value: Schema.String,
|
|
76
|
+
expires_at: Schema.Number,
|
|
77
|
+
}));
|
|
78
|
+
const AuthTokenResponse = Schema.fromJsonString(Schema.Struct({
|
|
79
|
+
name: Schema.String,
|
|
80
|
+
}));
|
|
81
|
+
const invalidRequest = (message) => new AIError({ reason: new InvalidRequestError({ message }) });
|
|
82
|
+
const post = (route, url, apiKey, body, response, authHeader) => Effect.gen(function* () {
|
|
83
|
+
const executor = yield* RequestExecutor.Service;
|
|
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
|
|
87
|
+
? HttpClientRequest.bodyFormData(body)
|
|
88
|
+
: HttpClientRequest.bodyText(encodeJson(body), "application/json")));
|
|
89
|
+
const http = new HttpContext({ url: res.request.url, status: res.status, headers: res.headers });
|
|
90
|
+
const fail = (message, cause, raw) => new AIError({ reason: new InvalidProviderOutputError({ route, message, body: raw, http, cause }) });
|
|
91
|
+
const text = yield* res.text.pipe(Effect.mapError((cause) => fail(`Failed to read ${route} response`, cause)));
|
|
92
|
+
return yield* Schema.decodeEffect(response)(text).pipe(Effect.mapError((cause) => fail(`${route} returned an invalid response`, cause, text)));
|
|
93
|
+
});
|
|
94
|
+
const clientSecret = (route, baseURL, model, apiKey, session) => post(route, `${baseURL}/realtime/client_secrets`, apiKey, { expires_after: { seconds: 60 }, session }, ClientSecretResponse).pipe(Effect.map((data) => ({
|
|
95
|
+
type: "websocket",
|
|
96
|
+
url: `${baseURL.replace(/^http/, "ws")}/realtime?model=${encodeURIComponent(model)}`,
|
|
97
|
+
token: data.value,
|
|
98
|
+
expiresAt: data.expires_at,
|
|
99
|
+
})));
|
|
@@ -12,5 +12,5 @@ export interface ModelInput {
|
|
|
12
12
|
}
|
|
13
13
|
export declare const model: <Options extends EvaluationOptions = EvaluationOptions>(cfg: ModelInput) => EvaluationModel<Options>;
|
|
14
14
|
export declare const SystemOne: {
|
|
15
|
-
readonly model:
|
|
15
|
+
readonly model: typeof model;
|
|
16
16
|
};
|
package/dist/experimental.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { EvaluationClient } from "./experimental/evaluation-client.js";
|
|
2
2
|
export { BooleanAnswer, BooleanQuestion, ChoiceAnswer, ChoiceQuestion, Evaluation, EvaluationAnswer, EvaluationInput, EvaluationModel, EvaluationModelSchema, EvaluationQuestion, EvaluationRequest, EvaluationResponse, EvaluationRounding, ScoreAnswer, ScoreQuestion, } from "./experimental/evaluation.js";
|
|
3
3
|
export type { AnswerFor, AnswersFor, EvaluationModelOptions, EvaluationOptions, EvaluationQuestions, EvaluationRequestFor, EvaluationRequestInput, EvaluationResponseFor, EvaluationRoute, } from "./experimental/evaluation.js";
|
|
4
|
+
export { Realtime } from "./experimental/realtime.js";
|
|
5
|
+
export type { RealtimeConnectInput, RealtimeSession, RealtimeTransport, RealtimeTransportInput, } from "./experimental/realtime.js";
|
package/dist/experimental.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { EvaluationClient } from "./experimental/evaluation-client.js";
|
|
2
2
|
export { BooleanAnswer, BooleanQuestion, ChoiceAnswer, ChoiceQuestion, Evaluation, EvaluationAnswer, EvaluationInput, EvaluationModel, EvaluationModelSchema, EvaluationQuestion, EvaluationRequest, EvaluationResponse, EvaluationRounding, ScoreAnswer, ScoreQuestion, } from "./experimental/evaluation.js";
|
|
3
|
+
export { Realtime } from "./experimental/realtime.js";
|
package/dist/image-client.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type Service = ImageClientService;
|
|
|
10
10
|
export declare const ImageClient: {
|
|
11
11
|
readonly layer: import("effect/Layer").Layer<ImageClientService, never, import("./route/executor-service.js").RequestExecutorService>;
|
|
12
12
|
readonly generate: (request: ImageRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Effect").Effect<ImageResponse, import("./index.js").AIError, ImageClientService>;
|
|
13
|
-
readonly stream: (request: ImageRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<
|
|
13
|
+
readonly stream: (request: ImageRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<{
|
|
14
14
|
readonly type: "image-partial";
|
|
15
15
|
readonly index: number;
|
|
16
16
|
readonly image: import("./media.js").Asset;
|
|
@@ -20,11 +20,6 @@ export declare const ImageClient: {
|
|
|
20
20
|
readonly image: import("./media.js").Asset;
|
|
21
21
|
} | {
|
|
22
22
|
readonly type: "finish";
|
|
23
|
-
readonly providerMetadata?: {
|
|
24
|
-
readonly [x: string]: {
|
|
25
|
-
readonly [x: string]: unknown;
|
|
26
|
-
};
|
|
27
|
-
} | undefined;
|
|
28
23
|
readonly usage?: {
|
|
29
24
|
readonly type: "tokens";
|
|
30
25
|
readonly input?: number | undefined;
|
|
@@ -47,7 +42,7 @@ export declare const ImageClient: {
|
|
|
47
42
|
readonly seconds: number;
|
|
48
43
|
} | undefined;
|
|
49
44
|
readonly notices?: readonly {
|
|
50
|
-
readonly type: "
|
|
45
|
+
readonly type: "filtered" | "moderated" | "other";
|
|
51
46
|
readonly message: string;
|
|
52
47
|
readonly providerMetadata?: {
|
|
53
48
|
readonly [x: string]: {
|
|
@@ -55,7 +50,12 @@ export declare const ImageClient: {
|
|
|
55
50
|
};
|
|
56
51
|
} | undefined;
|
|
57
52
|
}[] | undefined;
|
|
58
|
-
|
|
53
|
+
readonly providerMetadata?: {
|
|
54
|
+
readonly [x: string]: {
|
|
55
|
+
readonly [x: string]: unknown;
|
|
56
|
+
};
|
|
57
|
+
} | undefined;
|
|
58
|
+
} | import("./generation.js").Observation, import("./index.js").AIError, ImageClientService>;
|
|
59
59
|
readonly start: (request: ImageRequestFor) => import("effect/Effect").Effect<import("./generation.js").Generation<ImageResponse>, import("./index.js").AIError, ImageClientService>;
|
|
60
60
|
readonly resume: (model: import("./image.js").ImageModel<import("./media-model.js").MediaModel.Options>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<ImageResponse>, import("./index.js").AIError, ImageClientService>;
|
|
61
61
|
readonly Service: typeof ImageClientService;
|