+21

![opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



![opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



James Long
Brendan Allan
Kit Langton
opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Affan Ali
affanali2k3
Frank
opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
Aiden Cline
Jay V
Dax Raad
Aarav Sareen
OpeOginni
Luke Parker
Ben Guthrie
Dax
Filip
Max Anderson
Brendan Allan
Jack
Shoubhit Dash
Dustin Deus
starptech
Aiden Cline
usrnk1
Jay
runvip
opencode
Julian Coy
Vladimir Glafirov
8c94e9005f
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com> Co-authored-by: Max Anderson <max.a.anderson95@gmail.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
125 lines
4.2 KiB
TypeScript
125 lines
4.2 KiB
TypeScript
import { expect } from "bun:test"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { Provider } from "../../src/provider/provider"
|
|
|
|
import { Effect } from "effect"
|
|
import { testEffect } from "../lib/effect"
|
|
import { ProviderV2 } from "@opencode-ai/core/provider"
|
|
|
|
const DIGITALOCEAN = ProviderV2.ID.make("digitalocean")
|
|
const it = testEffect(LayerNode.compile(Provider.node))
|
|
|
|
const withEnv = <A, E, R>(values: Record<string, string>, effect: Effect.Effect<A, E, R>) =>
|
|
Effect.acquireUseRelease(
|
|
Effect.sync(() => {
|
|
const previous = Object.fromEntries(Object.keys(values).map((key) => [key, process.env[key]] as const))
|
|
Object.assign(process.env, values)
|
|
return previous
|
|
}),
|
|
() => effect,
|
|
(previous) =>
|
|
Effect.sync(() => {
|
|
for (const [key, value] of Object.entries(previous)) {
|
|
if (value === undefined) delete process.env[key]
|
|
else process.env[key] = value
|
|
}
|
|
}),
|
|
)
|
|
|
|
const withAuth = <A, E, R>(metadata: Record<string, string> | undefined, effect: Effect.Effect<A, E, R>) =>
|
|
withEnv(
|
|
{
|
|
OPENCODE_AUTH_CONTENT: JSON.stringify({
|
|
digitalocean: {
|
|
type: "api",
|
|
key: "sk_do_test",
|
|
...(metadata ? { metadata } : {}),
|
|
},
|
|
}),
|
|
},
|
|
effect,
|
|
)
|
|
|
|
it.instance(
|
|
"digitalocean provider autoloads from DIGITALOCEAN_ACCESS_TOKEN",
|
|
() =>
|
|
withEnv(
|
|
{ DIGITALOCEAN_ACCESS_TOKEN: "test-token" },
|
|
Effect.gen(function* () {
|
|
const provider = yield* Provider.Service
|
|
const providers = yield* provider.list()
|
|
expect(providers[DIGITALOCEAN]).toBeDefined()
|
|
expect(providers[DIGITALOCEAN].source).toBe("env")
|
|
const baseModel = Object.values(providers[DIGITALOCEAN].models)[0]
|
|
expect(baseModel.api.url).toBe("https://inference.do-ai.run/v1")
|
|
expect(baseModel.api.npm).toBe("@ai-sdk/openai-compatible")
|
|
const routerEntries = Object.keys(providers[DIGITALOCEAN].models).filter((id) => id.startsWith("router:"))
|
|
expect(routerEntries.length).toBe(0)
|
|
}),
|
|
),
|
|
{ config: {} },
|
|
)
|
|
|
|
it.instance(
|
|
"digitalocean provider.models surfaces cached routers from auth metadata",
|
|
() =>
|
|
withAuth(
|
|
{
|
|
routers: JSON.stringify([
|
|
{ name: "my-router", uuid: "11f1499a-aaaa-bbbb-cccc-4e013e2ddde4" },
|
|
{ name: "other-router", uuid: "22f1499a-aaaa-bbbb-cccc-4e013e2ddde4" },
|
|
]),
|
|
routers_fetched_at: String(Date.now()),
|
|
oauth_access: "doo_v1_test",
|
|
oauth_expires: String(Date.now() + 60 * 60 * 1000),
|
|
},
|
|
Effect.gen(function* () {
|
|
const provider = yield* Provider.Service
|
|
const providers = yield* provider.list()
|
|
const models = providers[DIGITALOCEAN].models
|
|
expect(models["router:my-router"]).toBeDefined()
|
|
expect(models["router:my-router"].api.id).toBe("router:my-router")
|
|
expect(models["router:my-router"].api.url).toBe("https://inference.do-ai.run/v1")
|
|
expect(models["router:my-router"].api.npm).toBe("@ai-sdk/openai-compatible")
|
|
expect(models["router:other-router"]).toBeDefined()
|
|
}),
|
|
),
|
|
{ config: {} },
|
|
)
|
|
|
|
it.instance(
|
|
"digitalocean provider.models skips refresh when oauth bearer is expired",
|
|
() =>
|
|
withAuth(
|
|
{
|
|
routers: JSON.stringify([{ name: "stale-router", uuid: "stale" }]),
|
|
routers_fetched_at: "0",
|
|
oauth_access: "doo_v1_expired",
|
|
oauth_expires: "1",
|
|
},
|
|
Effect.gen(function* () {
|
|
const provider = yield* Provider.Service
|
|
const providers = yield* provider.list()
|
|
const models = providers[DIGITALOCEAN].models
|
|
expect(models["router:stale-router"]).toBeDefined()
|
|
}),
|
|
),
|
|
{ config: {} },
|
|
)
|
|
|
|
it.instance(
|
|
"digitalocean provider.models passes through base models when no auth metadata",
|
|
() =>
|
|
withEnv(
|
|
{ DIGITALOCEAN_ACCESS_TOKEN: "test-token" },
|
|
Effect.gen(function* () {
|
|
const provider = yield* Provider.Service
|
|
const providers = yield* provider.list()
|
|
const models = providers[DIGITALOCEAN].models
|
|
expect(Object.keys(models).length).toBeGreaterThan(0)
|
|
expect(Object.keys(models).filter((id) => id.startsWith("router:")).length).toBe(0)
|
|
}),
|
|
),
|
|
{ config: {} },
|
|
)
|