Skip to content

Commit 8d95ef8

Browse files
authored
chore(server): revert hosted GPT-Live on the connected OpenCode Console (anomalyco#58461)
1 parent 2abdf96 commit 8d95ef8

17 files changed

Lines changed: 70 additions & 940 deletions

File tree

‎packages/client/src/effect/api/api.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,6 @@ export type VoiceModelsOutput = {
14241424
readonly provider: string
14251425
readonly transports: ReadonlyArray<"webrtc" | "websocket">
14261426
readonly available: boolean
1427-
readonly integration?: string | undefined
1428-
readonly workspace?: string | undefined
14291427
}>
14301428
readonly default?: string | undefined
14311429
}
@@ -1442,20 +1440,12 @@ export type VoiceSessionOutput = {
14421440
readonly transport:
14431441
| { readonly type: "webrtc"; readonly sdp: string }
14441442
| { readonly type: "websocket"; readonly url: string; readonly token: string; readonly expiresAt: number }
1445-
readonly session?: { readonly id: string } | undefined
14461443
}
14471444
export type VoiceSessionOperation<E = never> = (input: VoiceSessionInput) => Effect.Effect<VoiceSessionOutput, E>
14481445

1449-
export type VoiceInstructionsInput = { readonly sessionID: string; readonly instructions: string }
1450-
export type VoiceInstructionsOutput = void
1451-
export type VoiceInstructionsOperation<E = never> = (
1452-
input: VoiceInstructionsInput,
1453-
) => Effect.Effect<VoiceInstructionsOutput, E>
1454-
14551446
export interface VoiceApi<E = never> {
14561447
readonly models: VoiceModelsOperation<E>
14571448
readonly session: VoiceSessionOperation<E>
1458-
readonly instructions: VoiceInstructionsOperation<E>
14591449
}
14601450

14611451
export type ProviderListInput = { readonly location?: { readonly directory?: string | undefined } | undefined }

‎packages/client/src/effect/generated/client.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ import type {
118118
VoiceModelsOutput,
119119
VoiceSessionInput,
120120
VoiceSessionOutput,
121-
VoiceInstructionsInput,
122-
VoiceInstructionsOutput,
123121
ProviderListInput,
124122
ProviderListOutput,
125123
ProviderGetInput,
@@ -898,18 +896,9 @@ const EndpointVoiceSession = (raw: RawClient["server.voice"]) => (input: VoiceSe
898896
),
899897
)
900898

901-
const EndpointVoiceInstructions = (raw: RawClient["server.voice"]) => (input: VoiceInstructionsInput) =>
902-
preserveEffect<VoiceInstructionsOutput>()(
903-
raw["voice.instructions"]({
904-
params: { sessionID: input["sessionID"] },
905-
payload: { instructions: input["instructions"] },
906-
}).pipe(Effect.mapError(mapClientError)),
907-
)
908-
909899
const adaptGroupVoice = (raw: RawClient["server.voice"]) => ({
910900
models: EndpointVoiceModels(raw),
911901
session: EndpointVoiceSession(raw),
912-
instructions: EndpointVoiceInstructions(raw),
913902
})
914903

915904
const EndpointProviderList = (raw: RawClient["server.provider"]) => (input?: ProviderListInput) =>

‎packages/client/src/promise/generated/client.ts‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ import type {
112112
VoiceModelsOutput,
113113
VoiceSessionInput,
114114
VoiceSessionOutput,
115-
VoiceInstructionsInput,
116-
VoiceInstructionsOutput,
117115
ProviderListInput,
118116
ProviderListOutput,
119117
ProviderGetInput,
@@ -1192,18 +1190,6 @@ export function make(options: ClientOptions) {
11921190
},
11931191
requestOptions,
11941192
).then((value) => value.data),
1195-
instructions: (input: VoiceInstructionsInput, requestOptions?: RequestOptions) =>
1196-
request<VoiceInstructionsOutput>(
1197-
{
1198-
method: "POST",
1199-
path: `/api/experimental/voice/session/${encodeURIComponent(input.sessionID)}/instructions`,
1200-
body: { instructions: input["instructions"] },
1201-
successStatus: 204,
1202-
declaredStatuses: [400, 401, 404, 503],
1203-
empty: true,
1204-
},
1205-
requestOptions,
1206-
),
12071193
},
12081194
provider: {
12091195
list: (input?: ProviderListInput, requestOptions?: RequestOptions) =>

‎packages/client/src/promise/generated/types.ts‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,7 @@ export type ModelCost = {
664664
cache: { read: MoneyUSDPerMillionTokens; write: MoneyUSDPerMillionTokens }
665665
}
666666

667-
export type VoiceModel = {
668-
model: string
669-
provider: string
670-
transports: Array<VoiceTransportType>
671-
available: boolean
672-
integration?: string | undefined
673-
workspace?: string | undefined
674-
}
667+
export type VoiceModel = { model: string; provider: string; transports: Array<VoiceTransportType>; available: boolean }
675668

676669
export type VoiceTransport = VoiceWebRTCTransport | VoiceWebSocketTransport
677670

@@ -1998,7 +1991,7 @@ export type ProviderInfo = {
19981991

19991992
export type VoiceModelsResponse = { data: { models: Array<VoiceModel>; default?: string | undefined } }
20001993

2001-
export type VoiceSessionResponse = { data: { transport: VoiceTransport; session?: { id: string } | undefined } }
1994+
export type VoiceSessionResponse = { data: { transport: VoiceTransport } }
20021995

20031996
export type CredentialValue = CredentialOAuth | CredentialKey | CredentialExternal
20041997

@@ -5008,13 +5001,6 @@ export type VoiceSessionInput = {
50085001

50095002
export type VoiceSessionOutput = VoiceSessionResponse["data"]
50105003

5011-
export type VoiceInstructionsInput = {
5012-
readonly sessionID: { readonly sessionID: string }["sessionID"]
5013-
readonly instructions: { readonly instructions: string }["instructions"]
5014-
}
5015-
5016-
export type VoiceInstructionsOutput = void
5017-
50185004
export type ProviderListInput = {
50195005
readonly location?: { readonly location?: { readonly directory?: string | undefined } | undefined }["location"]
50205006
}

‎packages/client/test/promise.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test("exposes every standard HTTP API group", () => {
4646
expect(Object.keys(client.integration.oauth)).toEqual(["connect", "status", "complete", "cancel"])
4747
expect(Object.keys(client.integration.command)).toEqual(["connect", "status", "cancel"])
4848
expect(Object.keys(client.websearch)).toEqual(["providers", "query"])
49-
expect(Object.keys(client.voice)).toEqual(["models", "session", "instructions"])
49+
expect(Object.keys(client.voice)).toEqual(["models", "session"])
5050
expect(Object.keys(client.file)).toEqual(["read", "list", "find", "write"])
5151
expect(Object.keys(client.vcs)).toEqual(["init", "get", "base", "status", "branch", "diff"])
5252
expect(Object.keys(client.pty)).toEqual(["list", "create", "get", "update", "remove", "connect"])

‎packages/core/src/plugin/internal.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import { Npm } from "@opencode/util/npm"
5757
import { Permission } from "../permission.js"
5858
import { Reference } from "../reference.js"
5959
import { WebSearch } from "../websearch.js"
60-
import { Voice } from "../voice.js"
6160
import { Ripgrep } from "../ripgrep.js"
6261
import { Session } from "../session.js"
6362
import { SessionCompaction } from "../session/compaction.js"
@@ -153,7 +152,6 @@ const services = [
153152
SkillDiscovery.Service,
154153
Tool.Service,
155154
ToolOutput.Service,
156-
Voice.Service,
157155
Watcher.Service,
158156
WellKnown.Service,
159157
Worktree.Service,
@@ -208,7 +206,6 @@ export const requirements = LayerNode.group([
208206
SkillDiscovery.node,
209207
Tool.node,
210208
ToolOutput.node,
211-
Voice.node,
212209
Watcher.node,
213210
WellKnown.node,
214211
Worktree.node,

‎packages/core/src/plugin/provider/opencode.ts‎

Lines changed: 18 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { ManagedPolicy } from "../../managed-policy.js"
2424
import { Model } from "../../model.js"
2525
import { Provider } from "../../provider.js"
2626
import { Variant } from "../../variant.js"
27-
import { Voice } from "../../voice.js"
2827
import { WebSearch } from "../../websearch.js"
2928
import { ConfigPolicy } from "@opencode/schema/config/policy"
3029
import { ConfigProvider } from "@opencode/schema/config/provider"
@@ -65,13 +64,6 @@ const RemoteResponse = Schema.Struct({
6564
Schema.Struct({ ...Mcp.RemoteConfig.fields, auth: Schema.Literal("console").pipe(Schema.optional) }),
6665
),
6766
}).pipe(Schema.optional),
68-
// Hosted voice models the Console starts for the caller's workspace, the inference base that creates them, and the
69-
// workspace's display name, which older Consoles omit.
70-
voice: Schema.Struct({
71-
baseURL: Schema.String,
72-
models: Schema.Array(Schema.String),
73-
workspace: Schema.String.pipe(Schema.optional),
74-
}).pipe(Schema.optional),
7567
// Organization policy compiled for the authenticated caller; omitted when there is none.
7668
// `experimental.policies` remains accepted alongside top-level `policies`.
7769
policies: RemotePolicies,
@@ -101,10 +93,6 @@ const SsoRequired = Schema.Struct({
10193
connectionId: Schema.String,
10294
})
10395
const InvalidGrant = Schema.Struct({ error: Schema.Literal("invalid_grant") })
104-
const LiveSession = Schema.fromJsonString(
105-
Schema.Struct({ session: Schema.Struct({ id: Schema.String }), transport: Schema.Struct({ sdp: Schema.String }) }),
106-
)
107-
const InferenceError = Schema.fromJsonString(Schema.Struct({ error: Schema.Struct({ message: Schema.String }) }))
10896
// Console's 401 when the session behind the access token was revoked or expired.
10997
const Unauthorized = Schema.Struct({ _tag: Schema.Literal("Unauthorized") })
11098
const signedOutMessage = "Reconnect OpenCode Console to continue"
@@ -206,9 +194,7 @@ function oauth(http: HttpClient.HttpClient) {
206194
} satisfies IntegrationOAuthMethodRegistration
207195
}
208196

209-
export const OpencodePlugin = define<
210-
HttpClient.HttpClient | Bus.Service | ManagedPolicy.Service | Voice.Service | Scope.Scope
211-
>({
197+
export const OpencodePlugin = define<HttpClient.HttpClient | Bus.Service | ManagedPolicy.Service | Scope.Scope>({
212198
id: "opencode.provider.opencode",
213199
effect: Effect.fn(function* (ctx) {
214200
const disableFree = ["1", "true"].includes(process.env.OPENCODE_DISABLE_FREE_MODELS?.toLowerCase() ?? "")
@@ -218,7 +204,6 @@ export const OpencodePlugin = define<
218204
// and whether it evaluates the policies it is being sent.
219205
const http = HttpClient.mapRequest(client, HttpClientRequest.setHeader("User-Agent", App.useragent(ctx.app)))
220206
const managed = yield* ManagedPolicy.Service
221-
const voice = yield* Voice.Service
222207
const scope = yield* Scope.Scope
223208
const loading = Semaphore.makeUnsafe(1)
224209
type ActiveConnection = Effect.Success<ReturnType<typeof ctx.integration.connection.active>>
@@ -277,105 +262,12 @@ export const OpencodePlugin = define<
277262
),
278263
)
279264
})
280-
// The credential of the connection a snapshot was built from, while it is still the active one.
281-
const resolveActive = Effect.fnUntraced(function* (connection: NonNullable<ActiveConnection>) {
282-
const active = yield* ctx.integration.connection.active("opencode")
283-
if (!active || IntegrationConnection.key(active) !== IntegrationConnection.key(connection))
284-
return yield* Effect.fail(new Error("OpenCode Console connection changed"))
285-
const credential = yield* ctx.integration.connection.resolve(active)
286-
if (!credential || credential.type === "external")
287-
return yield* Effect.fail(new Error("OpenCode Console is not connected"))
288-
return credential
289-
})
290-
291-
// Hosted GPT-Live: the server's apps start sessions on the Console's account, billed to the workspace, with
292-
// the credential of the connection whose config offered it.
293-
const consoleVoice = (
294-
connection: NonNullable<ActiveConnection>,
295-
offer: NonNullable<typeof RemoteResponse.Type.voice>,
296-
): Voice.Host => {
297-
const send = (path: string, body: unknown) =>
298-
Effect.gen(function* () {
299-
const credential = yield* resolveActive(connection)
300-
const response = yield* HttpClient.withScope(http).execute(
301-
HttpClientRequest.post(`${offer.baseURL}${path}`).pipe(
302-
HttpClientRequest.acceptJson,
303-
HttpClientRequest.setHeaders(credentialHeaders(credential)),
304-
HttpClientRequest.bodyJsonUnsafe(body),
305-
),
306-
)
307-
return { status: response.status, text: yield* response.text }
308-
}).pipe(
309-
Effect.provideService(FetchHttpClient.RequestInit, { redirect: "error" }),
310-
Effect.scoped,
311-
Effect.timeoutOrElse({
312-
duration: Duration.seconds(20),
313-
orElse: () => Effect.fail(new Error("OpenCode Console didn't answer in time")),
314-
}),
315-
Effect.mapError(
316-
(cause) =>
317-
new Voice.UnavailableError({
318-
service: "opencode",
319-
message: cause instanceof Error ? cause.message : String(cause),
320-
}),
321-
),
322-
Effect.flatMap((reply): Effect.Effect<string, Voice.Error> => {
323-
if (reply.status >= 200 && reply.status < 300) return Effect.succeed(reply.text)
324-
if (reply.status === 401)
325-
return Effect.fail(new Voice.UnavailableError({ service: "opencode", message: `${signedOutMessage}.` }))
326-
const message =
327-
Option.getOrUndefined(Schema.decodeUnknownOption(InferenceError)(reply.text))?.error.message ??
328-
`OpenCode Console refused the voice request (HTTP ${reply.status})`
329-
return Effect.fail(
330-
reply.status === 400 || reply.status === 404
331-
? new Voice.InvalidRequestError({ message })
332-
: new Voice.UnavailableError({ service: "opencode", message }),
333-
)
334-
}),
335-
)
336-
return {
337-
integration: "opencode",
338-
models: offer.models,
339-
workspace: offer.workspace,
340-
session: (input) =>
341-
send("/live/sessions", { session: { ...input.session, model: input.model }, transport: input.transport }).pipe(
342-
Effect.flatMap((text) =>
343-
Schema.decodeUnknownEffect(LiveSession)(text).pipe(
344-
Effect.mapError(
345-
() =>
346-
new Voice.UnavailableError({
347-
service: "opencode",
348-
message: "OpenCode Console returned an invalid voice session",
349-
}),
350-
),
351-
),
352-
),
353-
Effect.map((created) => ({
354-
transport: { type: "webrtc" as const, sdp: created.transport.sdp },
355-
id: created.session.id,
356-
})),
357-
),
358-
instruct: (input) =>
359-
send(`/live/sessions/${encodeURIComponent(input.id)}/instructions`, {
360-
instructions: input.instructions,
361-
}).pipe(Effect.asVoid),
362-
}
363-
}
364-
365-
// Statements and hosted voice ride on the snapshot, so a credential switch, disconnect, or 404 replaces them too.
265+
// Statements ride on the snapshot, so a credential switch, disconnect, or 404 replaces them too.
366266
const publish = (next: typeof snapshot) =>
367-
Effect.all(
368-
[
369-
managed.set({
370-
statements: [...(next.config?.experimental?.policies ?? []), ...(next.config?.policies ?? [])],
371-
organization: next.organization,
372-
}),
373-
voice.host(
374-
next.connection && next.config?.voice ? consoleVoice(next.connection, next.config.voice) : undefined,
375-
),
376-
],
377-
{ discard: true },
378-
)
267+
managed.set({
268+
statements: [...(next.config?.experimental?.policies ?? []), ...(next.config?.policies ?? [])],
269+
organization: next.organization,
270+
})
379271

380272
yield* ctx.integration.transform((editor) => {
381273
editor.update("opencode", (integration) => {
@@ -507,7 +399,18 @@ export const OpencodePlugin = define<
507399
name: "OpenCode Web Search",
508400
execute: (input) =>
509401
Effect.gen(function* () {
510-
const credential = yield* resolveActive(connection)
402+
const active = yield* ctx.integration.connection.active("opencode")
403+
if (
404+
!active ||
405+
(connection.type === "credential"
406+
? active.type !== "credential" || active.id !== connection.id
407+
: active.type !== "env" || active.name !== connection.name)
408+
) {
409+
return yield* Effect.fail(new Error("OpenCode Console connection changed"))
410+
}
411+
const credential = yield* ctx.integration.connection.resolve(active)
412+
if (!credential || credential.type === "external")
413+
return yield* Effect.fail(new Error("OpenCode Console is not connected"))
511414
const metadata = credential.metadata
512415
const orgID = typeof metadata?.orgID === "string" ? metadata.orgID : undefined
513416
const token = credential.type === "oauth" ? credential.access : credential.key

0 commit comments

Comments
 (0)