GeezerVison is showing github.com — chore: generate · ikvm/opencode@3ab19bf
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/core/src/catalog.ts +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,11 +93,7 @@ export const layer = Layer.effect( | 93 | 93 | const integrations = yield* Integration.Service | 94 | 94 | const scope = yield* Scope.Scope | 95 | 95 |
| 96 | | - const available = ( | 97 | | - provider: ProviderV2.Info, | 98 | | - integration: Integration.Info | undefined, | 99 | | - connected: boolean, | 100 | | - ) => { | | 96 | + const available = (provider: ProviderV2.Info, integration: Integration.Info | undefined, connected: boolean) => { | 101 | 97 | if (provider.disabled) return false | 102 | 98 | if (typeof provider.request.body.apiKey === "string") return true | 103 | 99 | if (connected) return true | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/integration.ts +13-10Lines changed: 13 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -228,7 +228,10 @@ export interface Interface { | 228 | 228 | readonly label?: string | 229 | 229 | }) => Effect.Effect<Attempt, AuthorizationError> | 230 | 230 | /** Updates a stored credential exposed as a connection. */ | 231 | | - readonly update: (credentialID: Credential.ID, updates: Partial<Pick<Credential.Stored, "label">>) => Effect.Effect<void> | | 231 | + readonly update: ( | | 232 | + credentialID: Credential.ID, | | 233 | + updates: Partial<Pick<Credential.Stored, "label">>, | | 234 | + ) => Effect.Effect<void> | 232 | 235 | /** Removes a stored credential connection. */ | 233 | 236 | readonly remove: (credentialID: Credential.ID) => Effect.Effect<void> | 234 | 237 | } | @@ -339,9 +342,11 @@ export const locationLayer = Layer.effect( | 339 | 342 | }) | 340 | 343 |
| 341 | 344 | const connections = (entry: Entry, saved: readonly Credential.Stored[]): IntegrationConnection.Info[] => { | 342 | | - const connected = saved.map( | 343 | | - (credential) => ({ type: "credential" as const, id: credential.id, label: credential.label }), | 344 | | - ) | | 345 | + const connected = saved.map((credential) => ({ | | 346 | + type: "credential" as const, | | 347 | + id: credential.id, | | 348 | + label: credential.label, | | 349 | + })) | 345 | 350 | const detected = entry.methods | 346 | 351 | .filter((method) => method.type === "env") | 347 | 352 | .flatMap((method) => method.names.filter((name) => process.env[name])) | @@ -446,12 +451,10 @@ export const locationLayer = Layer.effect( | 446 | 451 | list: Effect.fn("Integration.connection.list")(function* () { | 447 | 452 | const saved = Map.groupBy(yield* credentials.all(), (credential) => credential.integrationID) | 448 | 453 | return new Map( | 449 | | - new Set([...state.get().integrations.keys(), ...saved.keys()]) | 450 | | - .values() | 451 | | - .flatMap((id) => { | 452 | | - const connection = activeConnection(state.get().integrations.get(id), saved.get(id) ?? []) | 453 | | - return connection ? [[id, connection] as const] : [] | 454 | | - }), | | 454 | + new Set([...state.get().integrations.keys(), ...saved.keys()]).values().flatMap((id) => { | | 455 | + const connection = activeConnection(state.get().integrations.get(id), saved.get(id) ?? []) | | 456 | + return connection ? [[id, connection] as const] : [] | | 457 | + }), | 455 | 458 | ) | 456 | 459 | }), | 457 | 460 | forIntegration: Effect.fn("Integration.connection.forIntegration")(function* (id) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/plugin/provider/opencode.ts +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,9 +14,7 @@ export const OpencodePlugin = PluginV2.define({ | 14 | 14 | if (!item) return | 15 | 15 | const integration = yield* integrations.get(Integration.ID.make(item.provider.id)) | 16 | 16 | hasKey = Boolean( | 17 | | - process.env.OPENCODE_API_KEY || | 18 | | - integration?.connections.length || | 19 | | - item.provider.request.body.apiKey, | | 17 | + process.env.OPENCODE_API_KEY || integration?.connections.length || item.provider.request.body.apiKey, | 20 | 18 | ) | 21 | 19 | evt.provider.update(item.provider.id, (provider) => { | 22 | 20 | if (!hasKey) provider.request.body.apiKey = "public" | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/session/runner/model.ts +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,11 +48,7 @@ export class Service extends Context.Service<Service, Interface>()("@opencode/v2 | 48 | 48 | /** Test or embedding seam for supplying a model resolver directly. */ | 49 | 49 | export const layerWith = (resolve: Interface["resolve"]) => Layer.succeed(Service, Service.of({ resolve })) | 50 | 50 |
| 51 | | -const apiKey = ( | 52 | | - model: ModelV2.Info, | 53 | | - connection?: IntegrationConnection.Info, | 54 | | - credential?: Credential.Stored, | 55 | | -) => { | | 51 | +const apiKey = (model: ModelV2.Info, connection?: IntegrationConnection.Info, credential?: Credential.Stored) => { | 56 | 52 | if (credential?.value.type === "key") return Auth.value(credential.value.key) | 57 | 53 | if (credential?.value.type === "oauth") return Auth.value(credential.value.access) | 58 | 54 | const value = model.request.body.apiKey ?? model.api.settings?.apiKey | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/test/catalog.test.ts +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,12 +36,12 @@ describe("CatalogV2", () => { | 36 | 36 | Effect.gen(function* () { | 37 | 37 | const catalog = yield* Catalog.Service | 38 | 38 | const events = yield* EventV2.Service | 39 | | - const updated = yield* events.subscribe(Catalog.Event.Updated).pipe(Stream.take(1), Stream.runCollect, Effect.forkScoped) | | 39 | + const updated = yield* events | | 40 | + .subscribe(Catalog.Event.Updated) | | 41 | + .pipe(Stream.take(1), Stream.runCollect, Effect.forkScoped) | 40 | 42 | yield* Effect.yieldNow | 41 | 43 |
| 42 | | - yield* (yield* catalog.transform())((editor) => | 43 | | - editor.provider.update(ProviderV2.ID.make("test"), () => {}), | 44 | | - ) | | 44 | + yield* (yield* catalog.transform())((editor) => editor.provider.update(ProviderV2.ID.make("test"), () => {})) | 45 | 45 |
| 46 | 46 | expect((yield* Fiber.join(updated)).length).toBe(1) | 47 | 47 | }), | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/test/config/provider.test.ts +110-107Lines changed: 110 additions & 107 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -136,123 +136,126 @@ describe("ConfigProviderPlugin.Plugin", () => { | 136 | 136 | ) | 137 | 137 |
| 138 | 138 | it.effect("loads configured providers and applies later model overrides", () => | 139 | | - withEnv({ CUSTOM_API_KEY: "secret" }, () => Effect.gen(function* () { | 140 | | - const catalog = yield* Catalog.Service | 141 | | - const integrations = yield* Integration.Service | 142 | | - const plugin = yield* PluginV2.Service | 143 | | - const providerID = ProviderV2.ID.make("custom") | 144 | | - const modelID = ModelV2.ID.make("chat") | 145 | | - const config = Config.Service.of({ | 146 | | - entries: () => | 147 | | - Effect.succeed([ | 148 | | - new Config.Document({ | 149 | | - type: "document", | 150 | | - info: decode({ | 151 | | - model: "custom/first", | 152 | | - providers: { | 153 | | - custom: { | 154 | | - name: "Configured", | 155 | | - env: ["CUSTOM_API_KEY"], | 156 | | - api: { type: "native", settings: {} }, | 157 | | - request: request({ first: "first", shared: "first" }), | 158 | | - models: { | 159 | | - chat: { | 160 | | - name: "First", | 161 | | - capabilities: { tools: true, input: ["text"], output: ["text"] }, | 162 | | - disabled: true, | 163 | | - limit: { context: 100, output: 50 }, | 164 | | - cost: { input: 1, output: 2 }, | 165 | | - request: request({ first: "first", shared: "first" }, "retained"), | 166 | | - variants: [ | 167 | | - { | 168 | | - id: "fast", | 169 | | - headers: { first: "first", shared: "first" }, | 170 | | - }, | 171 | | - ], | | 139 | + withEnv({ CUSTOM_API_KEY: "secret" }, () => | | 140 | + Effect.gen(function* () { | | 141 | + const catalog = yield* Catalog.Service | | 142 | + const integrations = yield* Integration.Service | | 143 | + const plugin = yield* PluginV2.Service | | 144 | + const providerID = ProviderV2.ID.make("custom") | | 145 | + const modelID = ModelV2.ID.make("chat") | | 146 | + const config = Config.Service.of({ | | 147 | + entries: () => | | 148 | + Effect.succeed([ | | 149 | + new Config.Document({ | | 150 | + type: "document", | | 151 | + info: decode({ | | 152 | + model: "custom/first", | | 153 | + providers: { | | 154 | + custom: { | | 155 | + name: "Configured", | | 156 | + env: ["CUSTOM_API_KEY"], | | 157 | + api: { type: "native", settings: {} }, | | 158 | + request: request({ first: "first", shared: "first" }), | | 159 | + models: { | | 160 | + chat: { | | 161 | + name: "First", | | 162 | + capabilities: { tools: true, input: ["text"], output: ["text"] }, | | 163 | + disabled: true, | | 164 | + limit: { context: 100, output: 50 }, | | 165 | + cost: { input: 1, output: 2 }, | | 166 | + request: request({ first: "first", shared: "first" }, "retained"), | | 167 | + variants: [ | | 168 | + { | | 169 | + id: "fast", | | 170 | + headers: { first: "first", shared: "first" }, | | 171 | + }, | | 172 | + ], | | 173 | + }, | 172 | 174 | }, | 173 | 175 | }, | 174 | 176 | }, | 175 | | - }, | | 177 | + }), | 176 | 178 | }), | 177 | | - }), | 178 | | - new Config.Document({ | 179 | | - type: "document", | 180 | | - info: decode({ | 181 | | - model: "custom/default", | 182 | | - providers: { | 183 | | - custom: { | 184 | | - api: { type: "aisdk", package: "custom-sdk", url: "https://example.test" }, | 185 | | - request: request({ last: "last", shared: "last" }), | 186 | | - models: { | 187 | | - default: { | 188 | | - name: "Default", | 189 | | - }, | 190 | | - chat: { | 191 | | - api: { id: "api-chat" }, | 192 | | - name: "Last", | 193 | | - limit: { output: 75 }, | 194 | | - request: request({ last: "last", shared: "last" }), | 195 | | - variants: [ | 196 | | - { | 197 | | - id: "fast", | 198 | | - headers: { last: "last", shared: "last" }, | 199 | | - }, | 200 | | - { | 201 | | - id: "slow", | 202 | | - headers: { slow: "slow" }, | 203 | | - }, | 204 | | - ], | | 179 | + new Config.Document({ | | 180 | + type: "document", | | 181 | + info: decode({ | | 182 | + model: "custom/default", | | 183 | + providers: { | | 184 | + custom: { | | 185 | + api: { type: "aisdk", package: "custom-sdk", url: "https://example.test" }, | | 186 | + request: request({ last: "last", shared: "last" }), | | 187 | + models: { | | 188 | + default: { | | 189 | + name: "Default", | | 190 | + }, | | 191 | + chat: { | | 192 | + api: { id: "api-chat" }, | | 193 | + name: "Last", | | 194 | + limit: { output: 75 }, | | 195 | + request: request({ last: "last", shared: "last" }), | | 196 | + variants: [ | | 197 | + { | | 198 | + id: "fast", | | 199 | + headers: { last: "last", shared: "last" }, | | 200 | + }, | | 201 | + { | | 202 | + id: "slow", | | 203 | + headers: { slow: "slow" }, | | 204 | + }, | | 205 | + ], | | 206 | + }, | 205 | 207 | }, | 206 | 208 | }, | 207 | 209 | }, | 208 | | - }, | | 210 | + }), | 209 | 211 | }), | 210 | | - }), | 211 | | - new Config.Document({ | 212 | | - type: "document", | 213 | | - info: decode({ | 214 | | - providers: { | 215 | | - custom: { name: "Renamed" }, | 216 | | - }, | | 212 | + new Config.Document({ | | 213 | + type: "document", | | 214 | + info: decode({ | | 215 | + providers: { | | 216 | + custom: { name: "Renamed" }, | | 217 | + }, | | 218 | + }), | 217 | 219 | }), | 218 | | - }), | 219 | | - ]), | 220 | | - }) | | 220 | + ]), | | 221 | + }) | 221 | 222 |
| 222 | | - yield* plugin.add({ | 223 | | - ...ConfigProviderPlugin.Plugin, | 224 | | - effect: ConfigProviderPlugin.Plugin.effect.pipe( | 225 | | - Effect.provideService(Config.Service, config), | 226 | | - Effect.provideService(Catalog.Service, catalog), | 227 | | - Effect.provideService(Integration.Service, integrations), | 228 | | - ), | 229 | | - }) | | 223 | + yield* plugin.add({ | | 224 | + ...ConfigProviderPlugin.Plugin, | | 225 | + effect: ConfigProviderPlugin.Plugin.effect.pipe( | | 226 | + Effect.provideService(Config.Service, config), | | 227 | + Effect.provideService(Catalog.Service, catalog), | | 228 | + Effect.provideService(Integration.Service, integrations), | | 229 | + ), | | 230 | + }) | 230 | 231 |
| 231 | | - const provider = yield* catalog.provider.get(providerID) | 232 | | - const model = yield* catalog.model.get(providerID, modelID) | 233 | | - expect(Option.getOrUndefined(yield* catalog.model.default())?.id).toBe(ModelV2.ID.make("default")) | 234 | | - expect(provider.name).toBe("Renamed") | 235 | | - expect((yield* integrations.get(Integration.ID.make("custom")))?.methods).toContainEqual( | 236 | | - { type: "env", names: ["CUSTOM_API_KEY"] }, | 237 | | - ) | 238 | | - expect((yield* integrations.get(Integration.ID.make("custom")))?.name).toBe("Renamed") | 239 | | - expect(provider.disabled).toBeUndefined() | 240 | | - expect(provider.api).toEqual({ type: "aisdk", package: "custom-sdk", url: "https://example.test" }) | 241 | | - expect(provider.request.headers).toEqual({ first: "first", shared: "last", last: "last" }) | 242 | | - expect(model.api.id).toBe(ModelV2.ID.make("api-chat")) | 243 | | - expect(model.name).toBe("Last") | 244 | | - expect(model.capabilities).toEqual({ tools: true, input: ["text"], output: ["text"] }) | 245 | | - expect(model.enabled).toBe(false) | 246 | | - expect(model.limit).toEqual({ context: 100, output: 75 }) | 247 | | - expect(model.cost).toEqual([{ input: 1, output: 2, cache: { read: 0, write: 0 }, tier: undefined }]) | 248 | | - expect(model.request.headers).toEqual({ first: "first", shared: "last", last: "last" }) | 249 | | - expect(model.request.variant).toBe("retained") | 250 | | - expect(model.variants.map((variant) => variant.id)).toEqual([ | 251 | | - ModelV2.VariantID.make("fast"), | 252 | | - ModelV2.VariantID.make("slow"), | 253 | | - ]) | 254 | | - expect(model.variants[0]?.headers).toEqual({ first: "first", shared: "last", last: "last" }) | 255 | | - expect(model.variants[1]?.headers).toEqual({ slow: "slow" }) | 256 | | - })), | | 232 | + const provider = yield* catalog.provider.get(providerID) | | 233 | + const model = yield* catalog.model.get(providerID, modelID) | | 234 | + expect(Option.getOrUndefined(yield* catalog.model.default())?.id).toBe(ModelV2.ID.make("default")) | | 235 | + expect(provider.name).toBe("Renamed") | | 236 | + expect((yield* integrations.get(Integration.ID.make("custom")))?.methods).toContainEqual({ | | 237 | + type: "env", | | 238 | + names: ["CUSTOM_API_KEY"], | | 239 | + }) | | 240 | + expect((yield* integrations.get(Integration.ID.make("custom")))?.name).toBe("Renamed") | | 241 | + expect(provider.disabled).toBeUndefined() | | 242 | + expect(provider.api).toEqual({ type: "aisdk", package: "custom-sdk", url: "https://example.test" }) | | 243 | + expect(provider.request.headers).toEqual({ first: "first", shared: "last", last: "last" }) | | 244 | + expect(model.api.id).toBe(ModelV2.ID.make("api-chat")) | | 245 | + expect(model.name).toBe("Last") | | 246 | + expect(model.capabilities).toEqual({ tools: true, input: ["text"], output: ["text"] }) | | 247 | + expect(model.enabled).toBe(false) | | 248 | + expect(model.limit).toEqual({ context: 100, output: 75 }) | | 249 | + expect(model.cost).toEqual([{ input: 1, output: 2, cache: { read: 0, write: 0 }, tier: undefined }]) | | 250 | + expect(model.request.headers).toEqual({ first: "first", shared: "last", last: "last" }) | | 251 | + expect(model.request.variant).toBe("retained") | | 252 | + expect(model.variants.map((variant) => variant.id)).toEqual([ | | 253 | + ModelV2.VariantID.make("fast"), | | 254 | + ModelV2.VariantID.make("slow"), | | 255 | + ]) | | 256 | + expect(model.variants[0]?.headers).toEqual({ first: "first", shared: "last", last: "last" }) | | 257 | + expect(model.variants[1]?.headers).toEqual({ slow: "slow" }) | | 258 | + }), | | 259 | + ), | 257 | 260 | ) | 258 | 261 | }) |
Collapse file Copy file name to clipboardExpand all lines: packages/core/test/integration.test.ts +3-5Lines changed: 3 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -147,11 +147,9 @@ describe("Integration", () => { | 147 | 147 | method: { type: "key", label: "API key" }, | 148 | 148 | }), | 149 | 149 | ) | 150 | | - const updated = yield* events.subscribe(Integration.Event.Updated).pipe( | 151 | | - Stream.take(1), | 152 | | - Stream.runCollect, | 153 | | - Effect.forkScoped, | 154 | | - ) | | 150 | + const updated = yield* events | | 151 | + .subscribe(Integration.Event.Updated) | | 152 | + .pipe(Stream.take(1), Stream.runCollect, Effect.forkScoped) | 155 | 153 | yield* Effect.yieldNow | 156 | 154 |
| 157 | 155 | yield* integrations.connection.key({ | |
|