mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-26 23:28:43 +00:00
chore(server): revert hosted GPT-Live on the connected OpenCode Console (#58461)
This commit is contained in:
parent
2abdf9604b
commit
8d95ef805b
17 changed files with 70 additions and 940 deletions
|
|
@ -1424,8 +1424,6 @@ export type VoiceModelsOutput = {
|
|||
readonly provider: string
|
||||
readonly transports: ReadonlyArray<"webrtc" | "websocket">
|
||||
readonly available: boolean
|
||||
readonly integration?: string | undefined
|
||||
readonly workspace?: string | undefined
|
||||
}>
|
||||
readonly default?: string | undefined
|
||||
}
|
||||
|
|
@ -1442,20 +1440,12 @@ export type VoiceSessionOutput = {
|
|||
readonly transport:
|
||||
| { readonly type: "webrtc"; readonly sdp: string }
|
||||
| { readonly type: "websocket"; readonly url: string; readonly token: string; readonly expiresAt: number }
|
||||
readonly session?: { readonly id: string } | undefined
|
||||
}
|
||||
export type VoiceSessionOperation<E = never> = (input: VoiceSessionInput) => Effect.Effect<VoiceSessionOutput, E>
|
||||
|
||||
export type VoiceInstructionsInput = { readonly sessionID: string; readonly instructions: string }
|
||||
export type VoiceInstructionsOutput = void
|
||||
export type VoiceInstructionsOperation<E = never> = (
|
||||
input: VoiceInstructionsInput,
|
||||
) => Effect.Effect<VoiceInstructionsOutput, E>
|
||||
|
||||
export interface VoiceApi<E = never> {
|
||||
readonly models: VoiceModelsOperation<E>
|
||||
readonly session: VoiceSessionOperation<E>
|
||||
readonly instructions: VoiceInstructionsOperation<E>
|
||||
}
|
||||
|
||||
export type ProviderListInput = { readonly location?: { readonly directory?: string | undefined } | undefined }
|
||||
|
|
|
|||
|
|
@ -118,8 +118,6 @@ import type {
|
|||
VoiceModelsOutput,
|
||||
VoiceSessionInput,
|
||||
VoiceSessionOutput,
|
||||
VoiceInstructionsInput,
|
||||
VoiceInstructionsOutput,
|
||||
ProviderListInput,
|
||||
ProviderListOutput,
|
||||
ProviderGetInput,
|
||||
|
|
@ -898,18 +896,9 @@ const EndpointVoiceSession = (raw: RawClient["server.voice"]) => (input: VoiceSe
|
|||
),
|
||||
)
|
||||
|
||||
const EndpointVoiceInstructions = (raw: RawClient["server.voice"]) => (input: VoiceInstructionsInput) =>
|
||||
preserveEffect<VoiceInstructionsOutput>()(
|
||||
raw["voice.instructions"]({
|
||||
params: { sessionID: input["sessionID"] },
|
||||
payload: { instructions: input["instructions"] },
|
||||
}).pipe(Effect.mapError(mapClientError)),
|
||||
)
|
||||
|
||||
const adaptGroupVoice = (raw: RawClient["server.voice"]) => ({
|
||||
models: EndpointVoiceModels(raw),
|
||||
session: EndpointVoiceSession(raw),
|
||||
instructions: EndpointVoiceInstructions(raw),
|
||||
})
|
||||
|
||||
const EndpointProviderList = (raw: RawClient["server.provider"]) => (input?: ProviderListInput) =>
|
||||
|
|
|
|||
|
|
@ -112,8 +112,6 @@ import type {
|
|||
VoiceModelsOutput,
|
||||
VoiceSessionInput,
|
||||
VoiceSessionOutput,
|
||||
VoiceInstructionsInput,
|
||||
VoiceInstructionsOutput,
|
||||
ProviderListInput,
|
||||
ProviderListOutput,
|
||||
ProviderGetInput,
|
||||
|
|
@ -1192,18 +1190,6 @@ export function make(options: ClientOptions) {
|
|||
},
|
||||
requestOptions,
|
||||
).then((value) => value.data),
|
||||
instructions: (input: VoiceInstructionsInput, requestOptions?: RequestOptions) =>
|
||||
request<VoiceInstructionsOutput>(
|
||||
{
|
||||
method: "POST",
|
||||
path: `/api/experimental/voice/session/${encodeURIComponent(input.sessionID)}/instructions`,
|
||||
body: { instructions: input["instructions"] },
|
||||
successStatus: 204,
|
||||
declaredStatuses: [400, 401, 404, 503],
|
||||
empty: true,
|
||||
},
|
||||
requestOptions,
|
||||
),
|
||||
},
|
||||
provider: {
|
||||
list: (input?: ProviderListInput, requestOptions?: RequestOptions) =>
|
||||
|
|
|
|||
|
|
@ -664,14 +664,7 @@ export type ModelCost = {
|
|||
cache: { read: MoneyUSDPerMillionTokens; write: MoneyUSDPerMillionTokens }
|
||||
}
|
||||
|
||||
export type VoiceModel = {
|
||||
model: string
|
||||
provider: string
|
||||
transports: Array<VoiceTransportType>
|
||||
available: boolean
|
||||
integration?: string | undefined
|
||||
workspace?: string | undefined
|
||||
}
|
||||
export type VoiceModel = { model: string; provider: string; transports: Array<VoiceTransportType>; available: boolean }
|
||||
|
||||
export type VoiceTransport = VoiceWebRTCTransport | VoiceWebSocketTransport
|
||||
|
||||
|
|
@ -1998,7 +1991,7 @@ export type ProviderInfo = {
|
|||
|
||||
export type VoiceModelsResponse = { data: { models: Array<VoiceModel>; default?: string | undefined } }
|
||||
|
||||
export type VoiceSessionResponse = { data: { transport: VoiceTransport; session?: { id: string } | undefined } }
|
||||
export type VoiceSessionResponse = { data: { transport: VoiceTransport } }
|
||||
|
||||
export type CredentialValue = CredentialOAuth | CredentialKey | CredentialExternal
|
||||
|
||||
|
|
@ -5008,13 +5001,6 @@ export type VoiceSessionInput = {
|
|||
|
||||
export type VoiceSessionOutput = VoiceSessionResponse["data"]
|
||||
|
||||
export type VoiceInstructionsInput = {
|
||||
readonly sessionID: { readonly sessionID: string }["sessionID"]
|
||||
readonly instructions: { readonly instructions: string }["instructions"]
|
||||
}
|
||||
|
||||
export type VoiceInstructionsOutput = void
|
||||
|
||||
export type ProviderListInput = {
|
||||
readonly location?: { readonly location?: { readonly directory?: string | undefined } | undefined }["location"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ test("exposes every standard HTTP API group", () => {
|
|||
expect(Object.keys(client.integration.oauth)).toEqual(["connect", "status", "complete", "cancel"])
|
||||
expect(Object.keys(client.integration.command)).toEqual(["connect", "status", "cancel"])
|
||||
expect(Object.keys(client.websearch)).toEqual(["providers", "query"])
|
||||
expect(Object.keys(client.voice)).toEqual(["models", "session", "instructions"])
|
||||
expect(Object.keys(client.voice)).toEqual(["models", "session"])
|
||||
expect(Object.keys(client.file)).toEqual(["read", "list", "find", "write"])
|
||||
expect(Object.keys(client.vcs)).toEqual(["init", "get", "base", "status", "branch", "diff"])
|
||||
expect(Object.keys(client.pty)).toEqual(["list", "create", "get", "update", "remove", "connect"])
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ import { Npm } from "@opencode/util/npm"
|
|||
import { Permission } from "../permission.js"
|
||||
import { Reference } from "../reference.js"
|
||||
import { WebSearch } from "../websearch.js"
|
||||
import { Voice } from "../voice.js"
|
||||
import { Ripgrep } from "../ripgrep.js"
|
||||
import { Session } from "../session.js"
|
||||
import { SessionCompaction } from "../session/compaction.js"
|
||||
|
|
@ -153,7 +152,6 @@ const services = [
|
|||
SkillDiscovery.Service,
|
||||
Tool.Service,
|
||||
ToolOutput.Service,
|
||||
Voice.Service,
|
||||
Watcher.Service,
|
||||
WellKnown.Service,
|
||||
Worktree.Service,
|
||||
|
|
@ -208,7 +206,6 @@ export const requirements = LayerNode.group([
|
|||
SkillDiscovery.node,
|
||||
Tool.node,
|
||||
ToolOutput.node,
|
||||
Voice.node,
|
||||
Watcher.node,
|
||||
WellKnown.node,
|
||||
Worktree.node,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import { ManagedPolicy } from "../../managed-policy.js"
|
|||
import { Model } from "../../model.js"
|
||||
import { Provider } from "../../provider.js"
|
||||
import { Variant } from "../../variant.js"
|
||||
import { Voice } from "../../voice.js"
|
||||
import { WebSearch } from "../../websearch.js"
|
||||
import { ConfigPolicy } from "@opencode/schema/config/policy"
|
||||
import { ConfigProvider } from "@opencode/schema/config/provider"
|
||||
|
|
@ -65,13 +64,6 @@ const RemoteResponse = Schema.Struct({
|
|||
Schema.Struct({ ...Mcp.RemoteConfig.fields, auth: Schema.Literal("console").pipe(Schema.optional) }),
|
||||
),
|
||||
}).pipe(Schema.optional),
|
||||
// Hosted voice models the Console starts for the caller's workspace, the inference base that creates them, and the
|
||||
// workspace's display name, which older Consoles omit.
|
||||
voice: Schema.Struct({
|
||||
baseURL: Schema.String,
|
||||
models: Schema.Array(Schema.String),
|
||||
workspace: Schema.String.pipe(Schema.optional),
|
||||
}).pipe(Schema.optional),
|
||||
// Organization policy compiled for the authenticated caller; omitted when there is none.
|
||||
// `experimental.policies` remains accepted alongside top-level `policies`.
|
||||
policies: RemotePolicies,
|
||||
|
|
@ -101,10 +93,6 @@ const SsoRequired = Schema.Struct({
|
|||
connectionId: Schema.String,
|
||||
})
|
||||
const InvalidGrant = Schema.Struct({ error: Schema.Literal("invalid_grant") })
|
||||
const LiveSession = Schema.fromJsonString(
|
||||
Schema.Struct({ session: Schema.Struct({ id: Schema.String }), transport: Schema.Struct({ sdp: Schema.String }) }),
|
||||
)
|
||||
const InferenceError = Schema.fromJsonString(Schema.Struct({ error: Schema.Struct({ message: Schema.String }) }))
|
||||
// Console's 401 when the session behind the access token was revoked or expired.
|
||||
const Unauthorized = Schema.Struct({ _tag: Schema.Literal("Unauthorized") })
|
||||
const signedOutMessage = "Reconnect OpenCode Console to continue"
|
||||
|
|
@ -206,9 +194,7 @@ function oauth(http: HttpClient.HttpClient) {
|
|||
} satisfies IntegrationOAuthMethodRegistration
|
||||
}
|
||||
|
||||
export const OpencodePlugin = define<
|
||||
HttpClient.HttpClient | Bus.Service | ManagedPolicy.Service | Voice.Service | Scope.Scope
|
||||
>({
|
||||
export const OpencodePlugin = define<HttpClient.HttpClient | Bus.Service | ManagedPolicy.Service | Scope.Scope>({
|
||||
id: "opencode.provider.opencode",
|
||||
effect: Effect.fn(function* (ctx) {
|
||||
const disableFree = ["1", "true"].includes(process.env.OPENCODE_DISABLE_FREE_MODELS?.toLowerCase() ?? "")
|
||||
|
|
@ -218,7 +204,6 @@ export const OpencodePlugin = define<
|
|||
// and whether it evaluates the policies it is being sent.
|
||||
const http = HttpClient.mapRequest(client, HttpClientRequest.setHeader("User-Agent", App.useragent(ctx.app)))
|
||||
const managed = yield* ManagedPolicy.Service
|
||||
const voice = yield* Voice.Service
|
||||
const scope = yield* Scope.Scope
|
||||
const loading = Semaphore.makeUnsafe(1)
|
||||
type ActiveConnection = Effect.Success<ReturnType<typeof ctx.integration.connection.active>>
|
||||
|
|
@ -277,105 +262,12 @@ export const OpencodePlugin = define<
|
|||
),
|
||||
)
|
||||
})
|
||||
// The credential of the connection a snapshot was built from, while it is still the active one.
|
||||
const resolveActive = Effect.fnUntraced(function* (connection: NonNullable<ActiveConnection>) {
|
||||
const active = yield* ctx.integration.connection.active("opencode")
|
||||
if (!active || IntegrationConnection.key(active) !== IntegrationConnection.key(connection))
|
||||
return yield* Effect.fail(new Error("OpenCode Console connection changed"))
|
||||
const credential = yield* ctx.integration.connection.resolve(active)
|
||||
if (!credential || credential.type === "external")
|
||||
return yield* Effect.fail(new Error("OpenCode Console is not connected"))
|
||||
return credential
|
||||
})
|
||||
|
||||
// Hosted GPT-Live: the server's apps start sessions on the Console's account, billed to the workspace, with
|
||||
// the credential of the connection whose config offered it.
|
||||
const consoleVoice = (
|
||||
connection: NonNullable<ActiveConnection>,
|
||||
offer: NonNullable<typeof RemoteResponse.Type.voice>,
|
||||
): Voice.Host => {
|
||||
const send = (path: string, body: unknown) =>
|
||||
Effect.gen(function* () {
|
||||
const credential = yield* resolveActive(connection)
|
||||
const response = yield* HttpClient.withScope(http).execute(
|
||||
HttpClientRequest.post(`${offer.baseURL}${path}`).pipe(
|
||||
HttpClientRequest.acceptJson,
|
||||
HttpClientRequest.setHeaders(credentialHeaders(credential)),
|
||||
HttpClientRequest.bodyJsonUnsafe(body),
|
||||
),
|
||||
)
|
||||
return { status: response.status, text: yield* response.text }
|
||||
}).pipe(
|
||||
Effect.provideService(FetchHttpClient.RequestInit, { redirect: "error" }),
|
||||
Effect.scoped,
|
||||
Effect.timeoutOrElse({
|
||||
duration: Duration.seconds(20),
|
||||
orElse: () => Effect.fail(new Error("OpenCode Console didn't answer in time")),
|
||||
}),
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new Voice.UnavailableError({
|
||||
service: "opencode",
|
||||
message: cause instanceof Error ? cause.message : String(cause),
|
||||
}),
|
||||
),
|
||||
Effect.flatMap((reply): Effect.Effect<string, Voice.Error> => {
|
||||
if (reply.status >= 200 && reply.status < 300) return Effect.succeed(reply.text)
|
||||
if (reply.status === 401)
|
||||
return Effect.fail(new Voice.UnavailableError({ service: "opencode", message: `${signedOutMessage}.` }))
|
||||
const message =
|
||||
Option.getOrUndefined(Schema.decodeUnknownOption(InferenceError)(reply.text))?.error.message ??
|
||||
`OpenCode Console refused the voice request (HTTP ${reply.status})`
|
||||
return Effect.fail(
|
||||
reply.status === 400 || reply.status === 404
|
||||
? new Voice.InvalidRequestError({ message })
|
||||
: new Voice.UnavailableError({ service: "opencode", message }),
|
||||
)
|
||||
}),
|
||||
)
|
||||
return {
|
||||
integration: "opencode",
|
||||
models: offer.models,
|
||||
workspace: offer.workspace,
|
||||
session: (input) =>
|
||||
send("/live/sessions", { session: { ...input.session, model: input.model }, transport: input.transport }).pipe(
|
||||
Effect.flatMap((text) =>
|
||||
Schema.decodeUnknownEffect(LiveSession)(text).pipe(
|
||||
Effect.mapError(
|
||||
() =>
|
||||
new Voice.UnavailableError({
|
||||
service: "opencode",
|
||||
message: "OpenCode Console returned an invalid voice session",
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
Effect.map((created) => ({
|
||||
transport: { type: "webrtc" as const, sdp: created.transport.sdp },
|
||||
id: created.session.id,
|
||||
})),
|
||||
),
|
||||
instruct: (input) =>
|
||||
send(`/live/sessions/${encodeURIComponent(input.id)}/instructions`, {
|
||||
instructions: input.instructions,
|
||||
}).pipe(Effect.asVoid),
|
||||
}
|
||||
}
|
||||
|
||||
// Statements and hosted voice ride on the snapshot, so a credential switch, disconnect, or 404 replaces them too.
|
||||
// Statements ride on the snapshot, so a credential switch, disconnect, or 404 replaces them too.
|
||||
const publish = (next: typeof snapshot) =>
|
||||
Effect.all(
|
||||
[
|
||||
managed.set({
|
||||
statements: [...(next.config?.experimental?.policies ?? []), ...(next.config?.policies ?? [])],
|
||||
organization: next.organization,
|
||||
}),
|
||||
voice.host(
|
||||
next.connection && next.config?.voice ? consoleVoice(next.connection, next.config.voice) : undefined,
|
||||
),
|
||||
],
|
||||
{ discard: true },
|
||||
)
|
||||
managed.set({
|
||||
statements: [...(next.config?.experimental?.policies ?? []), ...(next.config?.policies ?? [])],
|
||||
organization: next.organization,
|
||||
})
|
||||
|
||||
yield* ctx.integration.transform((editor) => {
|
||||
editor.update("opencode", (integration) => {
|
||||
|
|
@ -507,7 +399,18 @@ export const OpencodePlugin = define<
|
|||
name: "OpenCode Web Search",
|
||||
execute: (input) =>
|
||||
Effect.gen(function* () {
|
||||
const credential = yield* resolveActive(connection)
|
||||
const active = yield* ctx.integration.connection.active("opencode")
|
||||
if (
|
||||
!active ||
|
||||
(connection.type === "credential"
|
||||
? active.type !== "credential" || active.id !== connection.id
|
||||
: active.type !== "env" || active.name !== connection.name)
|
||||
) {
|
||||
return yield* Effect.fail(new Error("OpenCode Console connection changed"))
|
||||
}
|
||||
const credential = yield* ctx.integration.connection.resolve(active)
|
||||
if (!credential || credential.type === "external")
|
||||
return yield* Effect.fail(new Error("OpenCode Console is not connected"))
|
||||
const metadata = credential.metadata
|
||||
const orgID = typeof metadata?.orgID === "string" ? metadata.orgID : undefined
|
||||
const token = credential.type === "oauth" ? credential.access : credential.key
|
||||
|
|
|
|||
|
|
@ -19,10 +19,6 @@ export interface ModelInfo {
|
|||
readonly provider: string
|
||||
readonly transports: readonly RealtimeTransportType[]
|
||||
readonly available: boolean
|
||||
/** The integration whose connection starts its sessions: the provider's for a stored key, or a host's. */
|
||||
readonly integration?: string
|
||||
/** The workspace its sessions bill to, for display: set only when a host that names one runs it. */
|
||||
readonly workspace?: string
|
||||
}
|
||||
|
||||
export interface Models {
|
||||
|
|
@ -36,30 +32,6 @@ export interface SessionInput {
|
|||
readonly transport: RealtimeTransportInput
|
||||
}
|
||||
|
||||
export interface Session {
|
||||
readonly transport: RealtimeTransport
|
||||
/** A hosted session's ID, which `instruct` names it by. */
|
||||
readonly id?: string
|
||||
}
|
||||
|
||||
export interface InstructInput {
|
||||
readonly id: string
|
||||
readonly instructions: string
|
||||
}
|
||||
|
||||
/**
|
||||
* An integration that runs sessions for some models on its own account instead of a stored provider key, such as
|
||||
* the OpenCode Console's hosted GPT-Live. Its sessions' backend instructions change through it.
|
||||
*/
|
||||
export interface Host {
|
||||
readonly integration: string
|
||||
readonly models: readonly string[]
|
||||
/** The workspace its sessions bill to, for display. */
|
||||
readonly workspace?: string
|
||||
readonly session: (input: SessionInput) => Effect.Effect<Session, Error>
|
||||
readonly instruct: (input: InstructInput) => Effect.Effect<void, Error>
|
||||
}
|
||||
|
||||
export class InvalidRequestError extends Schema.TaggedError<InvalidRequestError>()("Voice.InvalidRequestError", {
|
||||
message: Schema.String,
|
||||
}) {}
|
||||
|
|
@ -73,11 +45,7 @@ export type Error = InvalidRequestError | UnavailableError
|
|||
|
||||
export interface Interface {
|
||||
readonly models: () => Effect.Effect<Models>
|
||||
readonly session: (input: SessionInput) => Effect.Effect<Session, Error>
|
||||
/** Replaces the backend instructions of a running session the host started. */
|
||||
readonly instruct: (input: InstructInput) => Effect.Effect<void, Error>
|
||||
/** Sets the host whose models start on it instead of a stored key, or removes it. */
|
||||
readonly host: (host: Host | undefined) => Effect.Effect<void>
|
||||
readonly session: (input: SessionInput) => Effect.Effect<RealtimeTransport, Error>
|
||||
}
|
||||
|
||||
export class Service extends Context.Service<Service, Interface>()("@opencode/Voice") {}
|
||||
|
|
@ -87,7 +55,6 @@ export const layer = Layer.effect(
|
|||
Effect.gen(function* () {
|
||||
const executor = yield* RequestExecutor.Service
|
||||
const integrations = yield* Integration.Service
|
||||
let hosted: Host | undefined
|
||||
|
||||
// Integration lists the active credential first, then newer stored credentials, then non-empty env vars.
|
||||
const findConnection = (provider: string) =>
|
||||
|
|
@ -96,26 +63,15 @@ export const layer = Layer.effect(
|
|||
.pipe(Effect.map((info) => info?.connections.find((item) => item.type === "env" || item.method === "key")))
|
||||
|
||||
const models = Effect.fn("Voice.models")(function* () {
|
||||
const host = hosted
|
||||
const list = yield* Effect.forEach(Realtime.engines, (engine): Effect.Effect<ModelInfo> =>
|
||||
host?.models.includes(engine.model)
|
||||
? Effect.succeed({
|
||||
model: engine.model,
|
||||
provider: engine.provider,
|
||||
transports: engine.transports,
|
||||
available: true,
|
||||
integration: host.integration,
|
||||
...(host.workspace === undefined ? {} : { workspace: host.workspace }),
|
||||
})
|
||||
: findConnection(engine.provider).pipe(
|
||||
Effect.map((connection) => ({
|
||||
model: engine.model,
|
||||
provider: engine.provider,
|
||||
transports: engine.transports,
|
||||
available: Boolean(connection),
|
||||
...(connection ? { integration: engine.provider } : {}),
|
||||
})),
|
||||
),
|
||||
const list = yield* Effect.forEach(Realtime.engines, (engine) =>
|
||||
findConnection(engine.provider).pipe(
|
||||
Effect.map((connection) => ({
|
||||
model: engine.model,
|
||||
provider: engine.provider,
|
||||
transports: engine.transports,
|
||||
available: Boolean(connection),
|
||||
})),
|
||||
),
|
||||
)
|
||||
const first = list.find((item) => item.available)?.model
|
||||
return first ? { models: list, default: first } : { models: list }
|
||||
|
|
@ -124,8 +80,6 @@ export const layer = Layer.effect(
|
|||
const session = Effect.fn("Voice.session")(function* (input: SessionInput) {
|
||||
const engine = Realtime.engine(input.model)
|
||||
if (!engine) return yield* new InvalidRequestError({ message: `Unsupported voice model: ${input.model}` })
|
||||
// A host offers a model on purpose, so it runs the model's sessions even where a stored key could.
|
||||
if (hosted?.models.includes(input.model)) return yield* hosted.session(input)
|
||||
|
||||
const connection = yield* findConnection(engine.provider)
|
||||
const credential = connection
|
||||
|
|
@ -141,7 +95,7 @@ export const layer = Layer.effect(
|
|||
message: missingKeyMessage[engine.provider],
|
||||
})
|
||||
|
||||
const transport = yield* Realtime.connect({ ...input, apiKey: Redacted.make(credential.key) }).pipe(
|
||||
return yield* Realtime.connect({ ...input, apiKey: Redacted.make(credential.key) }).pipe(
|
||||
Effect.provideService(RequestExecutor.Service, executor),
|
||||
Effect.mapError(
|
||||
(error: AIError): Error =>
|
||||
|
|
@ -150,23 +104,9 @@ export const layer = Layer.effect(
|
|||
: new UnavailableError({ message: error.message, service: engine.provider }),
|
||||
),
|
||||
)
|
||||
return { transport }
|
||||
})
|
||||
|
||||
const instruct = Effect.fn("Voice.instruct")(function* (input: InstructInput) {
|
||||
if (!hosted) return yield* new InvalidRequestError({ message: "Only hosted voice sessions take instructions" })
|
||||
return yield* hosted.instruct(input)
|
||||
})
|
||||
|
||||
return Service.of({
|
||||
models,
|
||||
session,
|
||||
instruct,
|
||||
host: (host) =>
|
||||
Effect.sync(() => {
|
||||
hosted = host
|
||||
}),
|
||||
})
|
||||
return Service.of({ models, session })
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import { SkillDiscovery } from "@opencode/core/skill/discovery"
|
|||
import { Watcher } from "@opencode/core/filesystem/watcher"
|
||||
import { Tool } from "@opencode/core/tool"
|
||||
import { Vcs } from "@opencode/core/vcs"
|
||||
import { Voice } from "@opencode/core/voice"
|
||||
import { WebSearch } from "@opencode/core/websearch"
|
||||
import { Worktree } from "@opencode/core/worktree"
|
||||
import { WorktreeStrategies } from "@opencode/core/worktree/strategies"
|
||||
|
|
@ -108,7 +107,6 @@ export const makePluginTestLayer = (permission = permissionLayer) =>
|
|||
SkillDiscovery.node,
|
||||
Tool.node,
|
||||
Vcs.node,
|
||||
Voice.node,
|
||||
Watcher.node,
|
||||
WebSearch.node,
|
||||
Worktree.node,
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import { PluginHost } from "@opencode/core/plugin/host"
|
|||
import { OpencodePlugin } from "@opencode/core/plugin/provider/opencode"
|
||||
import { Provider } from "@opencode/core/provider"
|
||||
import { Session } from "@opencode/core/session"
|
||||
import { Voice } from "@opencode/core/voice"
|
||||
import { WebSearch } from "@opencode/core/websearch"
|
||||
import { withEnv } from "../fixture/env"
|
||||
import { emptyMcp } from "../fixture/mcp"
|
||||
|
|
@ -2029,150 +2028,6 @@ describe("OpencodePlugin", () => {
|
|||
)
|
||||
})
|
||||
|
||||
describe("OpencodePlugin hosted voice", () => {
|
||||
// A Console whose config offers hosted GPT-Live while `offered`, answering sessions with `reply`.
|
||||
const voiceConsole = (reply: () => Response) =>
|
||||
Effect.sync(() => {
|
||||
const state = { offered: true }
|
||||
const requests: { path: string; authorization: string | null; orgID: string | null; body: unknown }[] = []
|
||||
const server = Bun.serve({
|
||||
port: 0,
|
||||
fetch: async (request) => {
|
||||
const url = new URL(request.url)
|
||||
if (url.pathname === "/api/v2/config")
|
||||
return Response.json({
|
||||
providers: {},
|
||||
...(state.offered
|
||||
? {
|
||||
voice: {
|
||||
baseURL: `${url.origin}/inference/openai/v1`,
|
||||
models: ["gpt-live-1"],
|
||||
workspace: "Anomaly",
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
})
|
||||
requests.push({
|
||||
path: url.pathname,
|
||||
authorization: request.headers.get("authorization"),
|
||||
orgID: request.headers.get("x-org-id"),
|
||||
body: await request.json(),
|
||||
})
|
||||
if (url.pathname.endsWith("/instructions")) return new Response(null, { status: 204 })
|
||||
return reply()
|
||||
},
|
||||
})
|
||||
return { server, state, requests }
|
||||
})
|
||||
|
||||
const connect = (server: ReturnType<typeof Bun.serve>) =>
|
||||
Effect.gen(function* () {
|
||||
const credentials = yield* Credential.Service
|
||||
yield* credentials.create({
|
||||
integrationID: Integration.ID.make("opencode"),
|
||||
value: Credential.OAuth.make({
|
||||
type: "oauth",
|
||||
methodID: Integration.MethodID.make("device"),
|
||||
access: "secret",
|
||||
refresh: "refresh",
|
||||
expires: Date.now() + 600_000,
|
||||
metadata: { server: server.url.origin, orgID: "org_test" },
|
||||
}),
|
||||
})
|
||||
yield* addPlugin().pipe(inProcess(server))
|
||||
})
|
||||
|
||||
const offer = {
|
||||
model: "gpt-live-1",
|
||||
session: { audio: { output: { voice: "marin" } } },
|
||||
transport: { type: "webrtc", sdp: "v=0" },
|
||||
} as const
|
||||
|
||||
it.effect("starts GPT-Live sessions on the Console with the connection's credential while it offers them", () =>
|
||||
Effect.acquireUseRelease(
|
||||
voiceConsole(() => Response.json({ session: { id: "sess_console" }, transport: { sdp: "answer:console" } })),
|
||||
({ server, state, requests }) =>
|
||||
Effect.gen(function* () {
|
||||
const voice = yield* Voice.Service
|
||||
yield* connect(server)
|
||||
const live = Effect.map(voice.models(), (list) => list.models.find((item) => item.model === "gpt-live-1"))
|
||||
|
||||
expect(yield* live).toMatchObject({ integration: "opencode", workspace: "Anomaly" })
|
||||
expect(yield* voice.session(offer)).toEqual({
|
||||
transport: { type: "webrtc", sdp: "answer:console" },
|
||||
id: "sess_console",
|
||||
})
|
||||
yield* voice.instruct({ id: "sess_console", instructions: "The screen shows ses_1." })
|
||||
expect(requests).toEqual([
|
||||
{
|
||||
path: "/inference/openai/v1/live/sessions",
|
||||
authorization: "Bearer secret",
|
||||
orgID: "org_test",
|
||||
body: {
|
||||
session: { audio: { output: { voice: "marin" } }, model: "gpt-live-1" },
|
||||
transport: { type: "webrtc", sdp: "v=0" },
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/inference/openai/v1/live/sessions/sess_console/instructions",
|
||||
authorization: "Bearer secret",
|
||||
orgID: "org_test",
|
||||
body: { instructions: "The screen shows ses_1." },
|
||||
},
|
||||
])
|
||||
|
||||
state.offered = false
|
||||
yield* TestClock.adjust("1 minute")
|
||||
yield* drain
|
||||
expect((yield* live)?.integration).not.toBe("opencode")
|
||||
}),
|
||||
({ server }) => Effect.promise(() => server.stop(true)),
|
||||
),
|
||||
)
|
||||
|
||||
for (const item of [
|
||||
{
|
||||
name: "a refusal's reason",
|
||||
reply: () =>
|
||||
Response.json(
|
||||
{ error: { type: "permission_error", message: "GPT-Live isn't enabled for this workspace" } },
|
||||
{ status: 403 },
|
||||
),
|
||||
expected: {
|
||||
_tag: "Voice.UnavailableError",
|
||||
service: "opencode",
|
||||
message: "GPT-Live isn't enabled for this workspace",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "an invalid session as the caller's",
|
||||
reply: () =>
|
||||
Response.json(
|
||||
{ error: { type: "invalid_request_error", message: "Stored GPT-Live sessions aren't available" } },
|
||||
{ status: 400 },
|
||||
),
|
||||
expected: { _tag: "Voice.InvalidRequestError", message: "Stored GPT-Live sessions aren't available" },
|
||||
},
|
||||
{
|
||||
name: "a rejected credential as a reconnect",
|
||||
reply: () => Response.json({ error: { message: "Invalid credential" } }, { status: 401 }),
|
||||
expected: { _tag: "Voice.UnavailableError", message: "Reconnect OpenCode Console to continue." },
|
||||
},
|
||||
])
|
||||
it.effect(`reports ${item.name}`, () =>
|
||||
Effect.acquireUseRelease(
|
||||
voiceConsole(item.reply),
|
||||
({ server }) =>
|
||||
Effect.gen(function* () {
|
||||
const voice = yield* Voice.Service
|
||||
yield* connect(server)
|
||||
expect(yield* voice.session(offer).pipe(Effect.flip)).toMatchObject(item.expected)
|
||||
}),
|
||||
({ server }) => Effect.promise(() => server.stop(true)),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
for (const key of [undefined, "secret"]) {
|
||||
testEffect(Layer.empty).effect(
|
||||
`disabled free models with ${key ? "an API key" : "a Console login after startup"}`,
|
||||
|
|
|
|||
|
|
@ -109,20 +109,16 @@ it.effect("uses the first key or env connection Integration lists and never a Ch
|
|||
const gemini = yield* call("gemini-3.8-live", [{ type: "env", name: "GEMINI_API_KEY" }])
|
||||
expect(auths).toEqual(["Bearer sk-active", "Bearer sk-stored", "Bearer xai-env-key", "gemini-env-key"])
|
||||
expect(grok).toEqual({
|
||||
transport: {
|
||||
type: "websocket",
|
||||
url: "wss://api.x.ai/v1/realtime?model=grok-voice-3.0",
|
||||
token: "ek_xai",
|
||||
expiresAt: 1760000999,
|
||||
},
|
||||
type: "websocket",
|
||||
url: "wss://api.x.ai/v1/realtime?model=grok-voice-3.0",
|
||||
token: "ek_xai",
|
||||
expiresAt: 1760000999,
|
||||
})
|
||||
expect(gemini).toEqual({
|
||||
transport: {
|
||||
type: "websocket",
|
||||
url: "wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContentConstrained",
|
||||
token: "auth_tokens/ek_gemini",
|
||||
expiresAt: 1760000060,
|
||||
},
|
||||
type: "websocket",
|
||||
url: "wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContentConstrained",
|
||||
token: "auth_tokens/ek_gemini",
|
||||
expiresAt: 1760000060,
|
||||
})
|
||||
|
||||
const signInOnly = yield* call("gpt-live-1", [credential("chatgpt", "oauth")]).pipe(Effect.flip)
|
||||
|
|
@ -161,14 +157,8 @@ it.effect("lists voice models with availability and default without resolving cr
|
|||
models: [
|
||||
{ model: "gpt-live-1", provider: "openai", transports: ["webrtc"], available: false },
|
||||
{ model: "gpt-realtime-2.1", provider: "openai", transports: ["webrtc", "websocket"], available: false },
|
||||
{ model: "grok-voice-3.0", provider: "xai", transports: ["websocket"], available: true, integration: "xai" },
|
||||
{
|
||||
model: "gemini-3.8-live",
|
||||
provider: "google",
|
||||
transports: ["websocket"],
|
||||
available: true,
|
||||
integration: "google",
|
||||
},
|
||||
{ model: "grok-voice-3.0", provider: "xai", transports: ["websocket"], available: true },
|
||||
{ model: "gemini-3.8-live", provider: "google", transports: ["websocket"], available: true },
|
||||
],
|
||||
default: "grok-voice-3.0",
|
||||
})
|
||||
|
|
@ -185,85 +175,3 @@ it.effect("lists voice models with availability and default without resolving cr
|
|||
expect("default" in none).toBe(false)
|
||||
}),
|
||||
)
|
||||
|
||||
// An OpenAI key the server could use instead, and the requests that reach OpenAI with it.
|
||||
const withStoredKey = (requests: string[]) =>
|
||||
Voice.layer.pipe(
|
||||
Layer.provide(
|
||||
Layer.merge(
|
||||
mockIntegration(
|
||||
(id) => (id === "openai" ? [credential("stored", "key")] : []),
|
||||
() => Effect.succeed(Credential.Key.make({ type: "key", key: "sk-stored" })),
|
||||
),
|
||||
RequestExecutor.layer.pipe(
|
||||
Layer.provide(
|
||||
Layer.succeed(
|
||||
HttpClient.HttpClient,
|
||||
HttpClient.make((req: HttpClientRequest.HttpClientRequest) =>
|
||||
Effect.sync(() => {
|
||||
requests.push(req.headers.authorization ?? "")
|
||||
return HttpClientResponse.fromWeb(req, Response.json({ transport: { sdp: "answer:openai" } }))
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
const hostedLive = (instructed: Voice.InstructInput[]): Voice.Host => ({
|
||||
integration: "opencode",
|
||||
models: ["gpt-live-1"],
|
||||
workspace: "Anomaly",
|
||||
session: (input) =>
|
||||
Effect.succeed({
|
||||
transport: { type: "webrtc", sdp: input.transport.type === "webrtc" ? `answer:hosted:${input.transport.sdp}` : "" },
|
||||
id: "sess_hosted",
|
||||
}),
|
||||
instruct: (input) =>
|
||||
Effect.sync(() => {
|
||||
instructed.push(input)
|
||||
}),
|
||||
})
|
||||
|
||||
const offer = { model: "gpt-live-1", transport: { type: "webrtc", sdp: "v=0" } } as const
|
||||
|
||||
it.effect("starts a host's models and relays their instructions on it, even beside a stored key", () => {
|
||||
const requests: string[] = []
|
||||
return Effect.gen(function* () {
|
||||
const voice = yield* Voice.Service
|
||||
const instructed: Voice.InstructInput[] = []
|
||||
yield* voice.host(hostedLive(instructed))
|
||||
|
||||
expect(yield* voice.session(offer)).toEqual({
|
||||
transport: { type: "webrtc", sdp: "answer:hosted:v=0" },
|
||||
id: "sess_hosted",
|
||||
})
|
||||
expect((yield* voice.models()).models.find((item) => item.model === "gpt-live-1")).toEqual({
|
||||
model: "gpt-live-1",
|
||||
provider: "openai",
|
||||
transports: ["webrtc"],
|
||||
available: true,
|
||||
integration: "opencode",
|
||||
workspace: "Anomaly",
|
||||
})
|
||||
yield* voice.instruct({ id: "sess_hosted", instructions: "The screen shows ses_1." })
|
||||
expect(instructed).toEqual([{ id: "sess_hosted", instructions: "The screen shows ses_1." }])
|
||||
expect(requests).toEqual([])
|
||||
}).pipe(Effect.provide(withStoredKey(requests)))
|
||||
})
|
||||
|
||||
it.effect("goes back to the stored key once the host is removed, and refuses instructions", () => {
|
||||
const requests: string[] = []
|
||||
return Effect.gen(function* () {
|
||||
const voice = yield* Voice.Service
|
||||
yield* voice.host(hostedLive([]))
|
||||
yield* voice.host(undefined)
|
||||
|
||||
expect(yield* voice.session(offer)).toEqual({ transport: { type: "webrtc", sdp: "answer:openai" } })
|
||||
expect(requests).toEqual(["Bearer sk-stored"])
|
||||
const refused = yield* voice.instruct({ id: "sess_hosted", instructions: "Hello" }).pipe(Effect.flip)
|
||||
expect(refused._tag).toBe("Voice.InvalidRequestError")
|
||||
}).pipe(Effect.provide(withStoredKey(requests)))
|
||||
})
|
||||
|
|
|
|||
|
|
@ -5440,7 +5440,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"description": "List supported voice models, their transports, whether the server has a usable API key for each provider or the connected OpenCode Console hosts the model, and the Console workspace a hosted model bills to.",
|
||||
"description": "List supported voice models, their transports, and whether the server has a usable API key for each provider.",
|
||||
"summary": "List voice models"
|
||||
}
|
||||
},
|
||||
|
|
@ -5502,7 +5502,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"description": "Create a server-brokered voice session using the server's configured provider credentials, or the connected OpenCode Console when it hosts the model, and return the WebRTC SDP answer or WebSocket ephemeral token.",
|
||||
"description": "Create a server-brokered voice session using the server's configured provider credentials and return the WebRTC SDP answer or WebSocket ephemeral token.",
|
||||
"summary": "Create voice session",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
|
|
@ -5536,87 +5536,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/experimental/voice/session/{sessionID}/instructions": {
|
||||
"post": {
|
||||
"tags": ["voice"],
|
||||
"operationId": "experimental.voice.instructions",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "sessionID",
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"security": [],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "<No Content>"
|
||||
},
|
||||
"400": {
|
||||
"description": "InvalidRequestError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/InvalidRequestErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "UnauthorizedError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/UnauthorizedErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "LocationNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"503": {
|
||||
"description": "ServiceUnavailableError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ServiceUnavailableErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "Replace the backend instructions of a running session the connected OpenCode Console hosts, whose data channel can't change them.",
|
||||
"summary": "Replace voice session instructions",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"instructions": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["instructions"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/provider": {
|
||||
"get": {
|
||||
"tags": ["provider"],
|
||||
|
|
@ -21086,26 +21005,6 @@
|
|||
},
|
||||
"available": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"integration": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"workspace": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": ["model", "provider", "transports", "available"],
|
||||
|
|
@ -21149,23 +21048,6 @@
|
|||
"properties": {
|
||||
"transport": {
|
||||
"$ref": "#/components/schemas/VoiceTransport"
|
||||
},
|
||||
"session": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["id"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": ["transport"],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Schema } from "effect"
|
||||
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api"
|
||||
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
|
||||
import { InvalidRequestError, LocationNotFoundError, ServiceUnavailableError } from "../errors.js"
|
||||
|
||||
export const VoiceTransportType = Schema.Literals(["webrtc", "websocket"]).annotate({
|
||||
|
|
@ -11,10 +11,6 @@ export const VoiceModel = Schema.Struct({
|
|||
provider: Schema.String,
|
||||
transports: Schema.Array(VoiceTransportType),
|
||||
available: Schema.Boolean,
|
||||
/** The integration whose connection starts its sessions: the provider's stored key, or `opencode` when the connected OpenCode Console hosts it. */
|
||||
integration: Schema.optional(Schema.String),
|
||||
/** The OpenCode Console workspace a hosted model's sessions bill to. */
|
||||
workspace: Schema.optional(Schema.String),
|
||||
}).annotate({ identifier: "VoiceModel" })
|
||||
|
||||
export const VoiceWebRTCTransportInput = Schema.Struct({
|
||||
|
|
@ -64,7 +60,7 @@ export const VoiceGroup = HttpApiGroup.make("server.voice")
|
|||
identifier: "experimental.voice.models",
|
||||
summary: "List voice models",
|
||||
description:
|
||||
"List supported voice models, their transports, whether the server has a usable API key for each provider or the connected OpenCode Console hosts the model, and the Console workspace a hosted model bills to.",
|
||||
"List supported voice models, their transports, and whether the server has a usable API key for each provider.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
|
@ -78,8 +74,6 @@ export const VoiceGroup = HttpApiGroup.make("server.voice")
|
|||
success: Schema.Struct({
|
||||
data: Schema.Struct({
|
||||
transport: VoiceTransport,
|
||||
/** A hosted session's ID, for `voice.instructions`. */
|
||||
session: Schema.optional(Schema.Struct({ id: Schema.String })),
|
||||
}),
|
||||
}).annotate({ identifier: "VoiceSessionResponse" }),
|
||||
error: [InvalidRequestError, ServiceUnavailableError, LocationNotFoundError],
|
||||
|
|
@ -88,22 +82,7 @@ export const VoiceGroup = HttpApiGroup.make("server.voice")
|
|||
identifier: "experimental.voice.session",
|
||||
summary: "Create voice session",
|
||||
description:
|
||||
"Create a server-brokered voice session using the server's configured provider credentials, or the connected OpenCode Console when it hosts the model, and return the WebRTC SDP answer or WebSocket ephemeral token.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.post("voice.instructions", "/api/experimental/voice/session/:sessionID/instructions", {
|
||||
params: { sessionID: Schema.String },
|
||||
payload: Schema.Struct({ instructions: Schema.String }),
|
||||
success: HttpApiSchema.NoContent,
|
||||
error: [InvalidRequestError, ServiceUnavailableError, LocationNotFoundError],
|
||||
}).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "experimental.voice.instructions",
|
||||
summary: "Replace voice session instructions",
|
||||
description:
|
||||
"Replace the backend instructions of a running session the connected OpenCode Console hosts, whose data channel can't change them.",
|
||||
"Create a server-brokered voice session using the server's configured provider credentials and return the WebRTC SDP answer or WebSocket ephemeral token.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,11 +9,6 @@ import { HttpApiBuilder } from "effect/http-api"
|
|||
import { Api } from "../api"
|
||||
import { awaitPlugins, locationErrors } from "../location"
|
||||
|
||||
const voiceErrors = (error: Voice.Error) =>
|
||||
error._tag === "Voice.InvalidRequestError"
|
||||
? new InvalidRequestError({ message: error.message })
|
||||
: new ServiceUnavailableError({ message: error.message, service: error.service })
|
||||
|
||||
export const VoiceHandler = HttpApiBuilder.group(Api, "server.voice", (handlers) =>
|
||||
Effect.gen(function* () {
|
||||
const global = yield* Global.Service
|
||||
|
|
@ -38,24 +33,16 @@ export const VoiceHandler = HttpApiBuilder.group(Api, "server.voice", (handlers)
|
|||
function* (request) {
|
||||
yield* awaitPlugins
|
||||
const voice = yield* Voice.Service
|
||||
const session = yield* voice.session(request.payload).pipe(Effect.mapError(voiceErrors))
|
||||
return {
|
||||
data: { transport: session.transport, ...(session.id === undefined ? {} : { session: { id: session.id } }) },
|
||||
}
|
||||
},
|
||||
Effect.provide(services),
|
||||
locationErrors,
|
||||
),
|
||||
)
|
||||
.handle(
|
||||
"voice.instructions",
|
||||
Effect.fn("server.voice.instructions")(
|
||||
function* (request) {
|
||||
yield* awaitPlugins
|
||||
const voice = yield* Voice.Service
|
||||
yield* voice
|
||||
.instruct({ id: request.params.sessionID, instructions: request.payload.instructions })
|
||||
.pipe(Effect.mapError(voiceErrors))
|
||||
const transport = yield* voice
|
||||
.session(request.payload)
|
||||
.pipe(
|
||||
Effect.mapError((error) =>
|
||||
error._tag === "Voice.InvalidRequestError"
|
||||
? new InvalidRequestError({ message: error.message })
|
||||
: new ServiceUnavailableError({ message: error.message, service: error.service }),
|
||||
),
|
||||
)
|
||||
return { data: { transport } }
|
||||
},
|
||||
Effect.provide(services),
|
||||
locationErrors,
|
||||
|
|
|
|||
|
|
@ -16,14 +16,7 @@ const voice = makeLocationNode({
|
|||
models: () =>
|
||||
Effect.succeed({
|
||||
models: [
|
||||
{
|
||||
model: "gpt-live-1",
|
||||
provider: "openai",
|
||||
transports: ["webrtc"],
|
||||
available: true,
|
||||
integration: "opencode",
|
||||
workspace: "Anomaly",
|
||||
},
|
||||
{ model: "gpt-live-1", provider: "openai", transports: ["webrtc"], available: true },
|
||||
{ model: "gpt-realtime-2.1", provider: "openai", transports: ["webrtc", "websocket"], available: true },
|
||||
{ model: "grok-voice-3.0", provider: "xai", transports: ["websocket"], available: false },
|
||||
{ model: "gemini-3.8-live", provider: "google", transports: ["websocket"], available: false },
|
||||
|
|
@ -37,22 +30,15 @@ const voice = makeLocationNode({
|
|||
return Effect.fail(new Voice.UnavailableError({ message: "OpenAI API key is required", service: "openai" }))
|
||||
return Effect.succeed(
|
||||
input.transport.type === "webrtc"
|
||||
? { transport: { type: "webrtc" as const, sdp: `answer:${input.model}:${input.transport.sdp}` }, id: "sess_1" }
|
||||
? { type: "webrtc" as const, sdp: `answer:${input.model}:${input.transport.sdp}` }
|
||||
: {
|
||||
transport: {
|
||||
type: "websocket" as const,
|
||||
url: `wss://api.x.ai/v1/realtime?model=${input.model}`,
|
||||
token: "ek_test",
|
||||
expiresAt: 1760000000,
|
||||
},
|
||||
type: "websocket" as const,
|
||||
url: `wss://api.x.ai/v1/realtime?model=${input.model}`,
|
||||
token: "ek_test",
|
||||
expiresAt: 1760000000,
|
||||
},
|
||||
)
|
||||
},
|
||||
instruct: (input) =>
|
||||
input.id === "sess_1"
|
||||
? Effect.void
|
||||
: Effect.fail(new Voice.InvalidRequestError({ message: "Only hosted voice sessions take instructions" })),
|
||||
host: () => Effect.void,
|
||||
}),
|
||||
),
|
||||
deps: [],
|
||||
|
|
@ -79,14 +65,7 @@ it.live("routes experimental voice models and session endpoints", () =>
|
|||
expect(yield* Effect.promise(() => modelsRes.json())).toEqual({
|
||||
data: {
|
||||
models: [
|
||||
{
|
||||
model: "gpt-live-1",
|
||||
provider: "openai",
|
||||
transports: ["webrtc"],
|
||||
available: true,
|
||||
integration: "opencode",
|
||||
workspace: "Anomaly",
|
||||
},
|
||||
{ model: "gpt-live-1", provider: "openai", transports: ["webrtc"], available: true },
|
||||
{ model: "gpt-realtime-2.1", provider: "openai", transports: ["webrtc", "websocket"], available: true },
|
||||
{ model: "grok-voice-3.0", provider: "xai", transports: ["websocket"], available: false },
|
||||
{ model: "gemini-3.8-live", provider: "google", transports: ["websocket"], available: false },
|
||||
|
|
@ -113,7 +92,7 @@ it.live("routes experimental voice models and session endpoints", () =>
|
|||
})
|
||||
expect(rtcRes.status).toBe(200)
|
||||
expect(yield* Effect.promise(() => rtcRes.json())).toEqual({
|
||||
data: { transport: { type: "webrtc", sdp: "answer:gpt-live-1:v=0" }, session: { id: "sess_1" } },
|
||||
data: { transport: { type: "webrtc", sdp: "answer:gpt-live-1:v=0" } },
|
||||
})
|
||||
|
||||
const wsRes = yield* post({ model: "grok-voice-3.0", transport: { type: "websocket" } })
|
||||
|
|
@ -131,18 +110,5 @@ it.live("routes experimental voice models and session endpoints", () =>
|
|||
|
||||
expect((yield* post({ model: "invalid", transport: { type: "websocket" } })).status).toBe(400)
|
||||
expect((yield* post({ model: "unavailable", transport: { type: "websocket" } })).status).toBe(503)
|
||||
|
||||
const instruct = (id: string) =>
|
||||
Effect.promise(() =>
|
||||
handler(
|
||||
new Request(`http://opencode.local/api/experimental/voice/session/${id}/instructions`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ instructions: "The screen shows ses_1." }),
|
||||
}),
|
||||
),
|
||||
)
|
||||
expect((yield* instruct("sess_1")).status).toBe(204)
|
||||
expect((yield* instruct("sess_unknown")).status).toBe(400)
|
||||
}),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5440,7 +5440,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"description": "List supported voice models, their transports, whether the server has a usable API key for each provider or the connected OpenCode Console hosts the model, and the Console workspace a hosted model bills to.",
|
||||
"description": "List supported voice models, their transports, and whether the server has a usable API key for each provider.",
|
||||
"summary": "List voice models"
|
||||
}
|
||||
},
|
||||
|
|
@ -5502,7 +5502,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"description": "Create a server-brokered voice session using the server's configured provider credentials, or the connected OpenCode Console when it hosts the model, and return the WebRTC SDP answer or WebSocket ephemeral token.",
|
||||
"description": "Create a server-brokered voice session using the server's configured provider credentials and return the WebRTC SDP answer or WebSocket ephemeral token.",
|
||||
"summary": "Create voice session",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
|
|
@ -5536,87 +5536,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/experimental/voice/session/{sessionID}/instructions": {
|
||||
"post": {
|
||||
"tags": ["voice"],
|
||||
"operationId": "experimental.voice.instructions",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "sessionID",
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"security": [],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "<No Content>"
|
||||
},
|
||||
"400": {
|
||||
"description": "InvalidRequestError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/InvalidRequestErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "UnauthorizedError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/UnauthorizedErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "LocationNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"503": {
|
||||
"description": "ServiceUnavailableError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ServiceUnavailableErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "Replace the backend instructions of a running session the connected OpenCode Console hosts, whose data channel can't change them.",
|
||||
"summary": "Replace voice session instructions",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"instructions": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["instructions"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/provider": {
|
||||
"get": {
|
||||
"tags": ["provider"],
|
||||
|
|
@ -21086,26 +21005,6 @@
|
|||
},
|
||||
"available": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"integration": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"workspace": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": ["model", "provider", "transports", "available"],
|
||||
|
|
@ -21149,23 +21048,6 @@
|
|||
"properties": {
|
||||
"transport": {
|
||||
"$ref": "#/components/schemas/VoiceTransport"
|
||||
},
|
||||
"session": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["id"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": ["transport"],
|
||||
|
|
|
|||
|
|
@ -5440,7 +5440,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"description": "List supported voice models, their transports, whether the server has a usable API key for each provider or the connected OpenCode Console hosts the model, and the Console workspace a hosted model bills to.",
|
||||
"description": "List supported voice models, their transports, and whether the server has a usable API key for each provider.",
|
||||
"summary": "List voice models"
|
||||
}
|
||||
},
|
||||
|
|
@ -5502,7 +5502,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"description": "Create a server-brokered voice session using the server's configured provider credentials, or the connected OpenCode Console when it hosts the model, and return the WebRTC SDP answer or WebSocket ephemeral token.",
|
||||
"description": "Create a server-brokered voice session using the server's configured provider credentials and return the WebRTC SDP answer or WebSocket ephemeral token.",
|
||||
"summary": "Create voice session",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
|
|
@ -5536,87 +5536,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/experimental/voice/session/{sessionID}/instructions": {
|
||||
"post": {
|
||||
"tags": ["voice"],
|
||||
"operationId": "experimental.voice.instructions",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "sessionID",
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"security": [],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "<No Content>"
|
||||
},
|
||||
"400": {
|
||||
"description": "InvalidRequestError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/InvalidRequestErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "UnauthorizedError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/UnauthorizedErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "LocationNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"503": {
|
||||
"description": "ServiceUnavailableError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ServiceUnavailableErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "Replace the backend instructions of a running session the connected OpenCode Console hosts, whose data channel can't change them.",
|
||||
"summary": "Replace voice session instructions",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"instructions": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["instructions"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/provider": {
|
||||
"get": {
|
||||
"tags": ["provider"],
|
||||
|
|
@ -21086,26 +21005,6 @@
|
|||
},
|
||||
"available": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"integration": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"workspace": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": ["model", "provider", "transports", "available"],
|
||||
|
|
@ -21149,23 +21048,6 @@
|
|||
"properties": {
|
||||
"transport": {
|
||||
"$ref": "#/components/schemas/VoiceTransport"
|
||||
},
|
||||
"session": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["id"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": ["transport"],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue