Skip to content

Commit 4f830b2

Browse files
opencode-agent[bot]davidgut1982
authored andcommitted
chore: generate
1 parent 75b3c29 commit 4f830b2

8 files changed

Lines changed: 1303 additions & 1866 deletions

File tree

packages/core/src/catalog.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ export const layer = Layer.effect(
9393
const integrations = yield* Integration.Service
9494
const scope = yield* Scope.Scope
9595

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) => {
10197
if (provider.disabled) return false
10298
if (typeof provider.request.body.apiKey === "string") return true
10399
if (connected) return true

packages/core/src/integration.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ export interface Interface {
228228
readonly label?: string
229229
}) => Effect.Effect<Attempt, AuthorizationError>
230230
/** 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>
232235
/** Removes a stored credential connection. */
233236
readonly remove: (credentialID: Credential.ID) => Effect.Effect<void>
234237
}
@@ -339,9 +342,11 @@ export const locationLayer = Layer.effect(
339342
})
340343

341344
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+
}))
345350
const detected = entry.methods
346351
.filter((method) => method.type === "env")
347352
.flatMap((method) => method.names.filter((name) => process.env[name]))
@@ -446,12 +451,10 @@ export const locationLayer = Layer.effect(
446451
list: Effect.fn("Integration.connection.list")(function* () {
447452
const saved = Map.groupBy(yield* credentials.all(), (credential) => credential.integrationID)
448453
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+
}),
455458
)
456459
}),
457460
forIntegration: Effect.fn("Integration.connection.forIntegration")(function* (id) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ export const OpencodePlugin = PluginV2.define({
1414
if (!item) return
1515
const integration = yield* integrations.get(Integration.ID.make(item.provider.id))
1616
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,
2018
)
2119
evt.provider.update(item.provider.id, (provider) => {
2220
if (!hasKey) provider.request.body.apiKey = "public"

packages/core/src/session/runner/model.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ export class Service extends Context.Service<Service, Interface>()("@opencode/v2
4848
/** Test or embedding seam for supplying a model resolver directly. */
4949
export const layerWith = (resolve: Interface["resolve"]) => Layer.succeed(Service, Service.of({ resolve }))
5050

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) => {
5652
if (credential?.value.type === "key") return Auth.value(credential.value.key)
5753
if (credential?.value.type === "oauth") return Auth.value(credential.value.access)
5854
const value = model.request.body.apiKey ?? model.api.settings?.apiKey

packages/core/test/catalog.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ describe("CatalogV2", () => {
3636
Effect.gen(function* () {
3737
const catalog = yield* Catalog.Service
3838
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)
4042
yield* Effect.yieldNow
4143

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"), () => {}))
4545

4646
expect((yield* Fiber.join(updated)).length).toBe(1)
4747
}),

packages/core/test/config/provider.test.ts

Lines changed: 110 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -136,123 +136,126 @@ describe("ConfigProviderPlugin.Plugin", () => {
136136
)
137137

138138
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+
},
172174
},
173175
},
174176
},
175-
},
177+
}),
176178
}),
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+
},
205207
},
206208
},
207209
},
208-
},
210+
}),
209211
}),
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+
}),
217219
}),
218-
}),
219-
]),
220-
})
220+
]),
221+
})
221222

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+
})
230231

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+
),
257260
)
258261
})

packages/core/test/integration.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,9 @@ describe("Integration", () => {
147147
method: { type: "key", label: "API key" },
148148
}),
149149
)
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)
155153
yield* Effect.yieldNow
156154

157155
yield* integrations.connection.key({

0 commit comments

Comments
 (0)