|
1 | | -import { |
2 | | - Clock, |
3 | | - Duration, |
4 | | - Effect, |
5 | | - Equal, |
6 | | - FiberHandle, |
7 | | - Option, |
8 | | - Predicate, |
9 | | - Schema, |
10 | | - Scope, |
11 | | - Semaphore, |
12 | | - Stream, |
13 | | -} from "effect" |
| 1 | +import { Clock, Duration, Effect, Equal, FiberHandle, Option, Schema, Scope, Semaphore, Stream } from "effect" |
14 | 2 | import type { IntegrationOAuthMethodRegistration } from "@opencode/plugin/effect/integration" |
15 | 3 | import { define } from "@opencode/plugin/effect/plugin" |
16 | 4 | import type { SessionHttpResponse } from "@opencode/plugin/effect/session" |
@@ -27,7 +15,6 @@ import { IntegrationConnection } from "../../integration/connection.js" |
27 | 15 | import { ManagedPolicy } from "../../managed-policy.js" |
28 | 16 | import { Provider } from "../../provider.js" |
29 | 17 | import { WebSearch } from "../../websearch.js" |
30 | | -import { OpencodeLegacy } from "./opencode-legacy.js" |
31 | 18 |
|
32 | 19 | const clientID = "opencode-cli" |
33 | 20 | const methodID = Integration.MethodID.make("device") |
@@ -173,9 +160,8 @@ export const OpencodePlugin = define< |
173 | 160 | const loading = Semaphore.makeUnsafe(1) |
174 | 161 | type ActiveConnection = Effect.Success<ReturnType<typeof ctx.integration.connection.active>> |
175 | 162 | let snapshot: { |
176 | | - // The Console response in one of its two formats: a regular OpenCode config, merged as an integration config |
177 | | - // layer, or the legacy response, which OpencodeLegacy applies directly. |
178 | | - remote: { type: "config"; info: ConfigIntegration.Remote } | OpencodeLegacy.Snapshot | undefined |
| 163 | + // The Console's regular OpenCode config, merged as an integration config layer. |
| 164 | + remote: ConfigIntegration.Remote | undefined |
179 | 165 | connection: ActiveConnection |
180 | 166 | organization: string | undefined |
181 | 167 | } = { remote: undefined, connection: undefined, organization: undefined } |
@@ -202,10 +188,7 @@ export const OpencodePlugin = define< |
202 | 188 | return Effect.succeed({ remote: undefined, connection, organization: undefined }) |
203 | 189 | return fetchConfig(http, credential).pipe( |
204 | 190 | Effect.map((remote) => ({ |
205 | | - remote: |
206 | | - remote?.type === "legacy" |
207 | | - ? OpencodeLegacy.make(remote.response, ConsoleAccess.headers(credential)) |
208 | | - : remote, |
| 191 | + remote, |
209 | 192 | connection, |
210 | 193 | organization: organizationName(credential), |
211 | 194 | })), |
@@ -228,7 +211,7 @@ export const OpencodePlugin = define< |
228 | 211 | ) |
229 | 212 | }) |
230 | 213 | // The Console document as config layered it. Its providers apply at this plugin's position in the provider chain, |
231 | | - // where the legacy overlay applies, while the rest of the document merges through config. |
| 214 | + // while the rest of the document merges through config. |
232 | 215 | let integrated: ConfigIntegration.Document | undefined |
233 | 216 | const integrate = Effect.fnUntraced(function* (document: ConfigIntegration.Document | undefined) { |
234 | 217 | yield* config.integration?.(Integration.ID.make("opencode"), document) ?? Effect.void |
@@ -239,30 +222,21 @@ export const OpencodePlugin = define< |
239 | 222 | }) |
240 | 223 | // Policies and providers ride on the snapshot, so a credential switch, disconnect, or 404 replaces them too. |
241 | 224 | const publish = Effect.fnUntraced(function* (next: typeof snapshot) { |
242 | | - switch (next.remote?.type) { |
243 | | - // A regular config merges as one integration document, which config loads right after managed policies, |
244 | | - // so its policies reach ManagedPolicy through config rather than as Console statements. |
245 | | - case "config": |
246 | | - yield* managed.set({ statements: [], organization: next.organization }) |
247 | | - return yield* integrate( |
248 | | - next.connection && |
249 | | - ConfigIntegration.make({ |
250 | | - integrationID: Integration.ID.make("opencode"), |
251 | | - connection: |
252 | | - next.connection.type === "credential" |
253 | | - ? { ...next.connection, id: Credential.ID.make(next.connection.id) } |
254 | | - : next.connection, |
255 | | - organization: next.organization, |
256 | | - info: next.remote.info, |
257 | | - }), |
258 | | - ) |
259 | | - case "legacy": |
260 | | - yield* managed.set({ statements: OpencodeLegacy.statements(next.remote), organization: next.organization }) |
261 | | - return yield* integrate(undefined) |
262 | | - default: |
263 | | - yield* managed.set({ statements: [], organization: next.organization }) |
264 | | - return yield* integrate(undefined) |
265 | | - } |
| 225 | + yield* managed.set({ statements: [], organization: next.organization }) |
| 226 | + // The config merges as one integration document, which config loads right after managed policies. |
| 227 | + yield* integrate( |
| 228 | + next.remote && |
| 229 | + next.connection && |
| 230 | + ConfigIntegration.make({ |
| 231 | + integrationID: Integration.ID.make("opencode"), |
| 232 | + connection: |
| 233 | + next.connection.type === "credential" |
| 234 | + ? { ...next.connection, id: Credential.ID.make(next.connection.id) } |
| 235 | + : next.connection, |
| 236 | + organization: next.organization, |
| 237 | + info: next.remote, |
| 238 | + }), |
| 239 | + ) |
266 | 240 | }) |
267 | 241 | const search = (providerID: WebSearch.ID, connection: NonNullable<ActiveConnection>) => ({ |
268 | 242 | id: providerID, |
@@ -324,7 +298,6 @@ export const OpencodePlugin = define< |
324 | 298 |
|
325 | 299 | snapshot = yield* load() |
326 | 300 | yield* publish(snapshot) |
327 | | - yield* OpencodeLegacy.register(ctx, () => snapshot, search) |
328 | 301 | yield* ctx.provider.transform((providers) => { |
329 | 302 | if (integrated) ConfigProviderPlugin.integrate(providers, integrated) |
330 | 303 | }) |
@@ -360,12 +333,7 @@ export const OpencodePlugin = define< |
360 | 333 | // config, where the user's own choice wins. |
361 | 334 | yield* ctx.websearch.transform((editor) => { |
362 | 335 | const provider = WebSearch.ID.make("opencode") |
363 | | - if ( |
364 | | - snapshot.remote?.type === "config" && |
365 | | - snapshot.remote.info.websearch && |
366 | | - snapshot.remote.info.websearch.provider === provider && |
367 | | - snapshot.connection |
368 | | - ) |
| 336 | + if (snapshot.remote?.websearch && snapshot.remote.websearch.provider === provider && snapshot.connection) |
369 | 337 | editor.add(search(provider, snapshot.connection)) |
370 | 338 | }) |
371 | 339 |
|
@@ -418,9 +386,7 @@ export const OpencodePlugin = define< |
418 | 386 | next.connection |
419 | 387 | ? new Set([ |
420 | 388 | Provider.ID.opencode, |
421 | | - ...(next.remote?.type === "config" |
422 | | - ? Object.keys(next.remote.info.providers ?? {}) |
423 | | - : OpencodeLegacy.providerIDs(next.remote)), |
| 389 | + ...Object.keys(next.remote?.providers ?? {}), |
424 | 390 | ]) |
425 | 391 | : [], |
426 | 392 | (providerID) => ctx.session.hook("http.response", explain, { providerID }).pipe(Scope.provide(scope)), |
@@ -473,10 +439,7 @@ function fetchConfig(http: HttpClient.HttpClient, value: Credential.Key | Creden |
473 | 439 | }) |
474 | 440 | } |
475 | 441 | const body = yield* HttpClientResponse.filterStatusOk(response).pipe(Effect.flatMap((ok) => ok.json)) |
476 | | - // A Console that serves a regular OpenCode config marks it with `$schema`; any other body is the legacy response. |
477 | | - if (Predicate.hasProperty(body, "$schema")) |
478 | | - return { type: "config" as const, info: yield* Schema.decodeUnknownEffect(ConfigIntegration.Remote)(body) } |
479 | | - return { type: "legacy" as const, response: yield* Schema.decodeUnknownEffect(OpencodeLegacy.Response)(body) } |
| 442 | + return yield* Schema.decodeUnknownEffect(ConfigIntegration.Remote)(body) |
480 | 443 | }), |
481 | 444 | ), |
482 | 445 | Effect.scoped, |
|