Files
opencode/packages/core/test/aisdk.test.ts
+16 9e0d3976e1 chore: merge dev into v2 (#35591)
Co-authored-by: Frank <[email protected]>
Co-authored-by: Aarav Sareen <[email protected]>
Co-authored-by: Brendan Allan <[email protected]>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: Jack <[email protected]>
Co-authored-by: Brendan Allan <[email protected]>
Co-authored-by: Shoubhit Dash <[email protected]>
Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: James Long <[email protected]>
Co-authored-by: Dustin Deus <[email protected]>
Co-authored-by: starptech <[email protected]>
Co-authored-by: Luke Parker <[email protected]>
Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <[email protected]>
Co-authored-by: Dax <[email protected]>
Co-authored-by: usrnk1 <[email protected]>
Co-authored-by: Jay <[email protected]>
Co-authored-by: runvip <[email protected]>
Co-authored-by: opencode <[email protected]>
Co-authored-by: Julian Coy <[email protected]>
Co-authored-by: Vladimir Glafirov <[email protected]>
Co-authored-by: Adam <[email protected]>
Co-authored-by: Kit Langton <[email protected]>
Co-authored-by: Simon Klee <[email protected]>
Co-authored-by: Jay <[email protected]>
Co-authored-by: David Hill <[email protected]>
2026-07-06 16:05:29 -05:00

72 lines
2.5 KiB
TypeScript

import type { LanguageModelV3CallOptions } from "@ai-sdk/provider"
import { AISDK } from "@opencode-ai/core/aisdk"
import { ModelV2 } from "@opencode-ai/core/model"
import { ProviderV2 } from "@opencode-ai/core/provider"
import { LLM } from "@opencode-ai/llm"
import { LLMClient } from "@opencode-ai/llm/route"
import { expect } from "bun:test"
import { Effect } from "effect"
import { testEffect } from "./lib/effect"
const it = testEffect(AISDK.locationLayer)
const model = (packageName: string, settings: Record<string, unknown> = {}) =>
ModelV2.Info.make({
...ModelV2.Info.empty(ProviderV2.ID.make("test-provider"), ModelV2.ID.make("catalog-model")),
modelID: ModelV2.ID.make("api-model"),
package: ProviderV2.aisdk(packageName),
settings,
limit: { context: 100, output: 20 },
})
it.effect("keys language models by package and flattened overlays", () =>
Effect.gen(function* () {
const aisdk = yield* AISDK.Service
const loaded: string[] = []
yield* aisdk.hook.sdk((event) => {
loaded.push(event.package)
event.sdk = { languageModel: () => ({ package: event.package }) }
})
const first = yield* aisdk.language(model("first", { region: "us-east-1" }))
const second = yield* aisdk.language(model("second", { region: "us-east-1" }))
const third = yield* aisdk.language(model("second", { region: "us-west-2" }))
expect(first).not.toBe(second)
expect(second).not.toBe(third)
expect(loaded).toEqual(["first", "second", "second"])
}),
)
it.effect("projects request settings, headers, and body overlays", () =>
Effect.gen(function* () {
const aisdk = yield* AISDK.Service
let body: unknown
yield* aisdk.hook.sdk((event) => {
body = event.options.body
event.sdk = { languageModel: () => ({ provider: event.model.providerID }) }
})
const input = model("@ai-sdk/google", {
apiKey: "secret",
thinkingConfig: { thinkingBudget: 1024 },
})
const resolved = yield* aisdk.model(
{
...input,
headers: { "x-test": "header" },
body: { safety_setting: "strict" },
},
)
const prepared = yield* LLMClient.prepare<LanguageModelV3CallOptions>(
LLM.request({ model: resolved, prompt: "Hello" }),
)
expect(prepared.body.providerOptions).toEqual({
google: { thinkingConfig: { thinkingBudget: 1024 } },
})
expect(prepared.body.headers).toEqual({ "x-test": "header" })
expect(body).toEqual({ safety_setting: "strict" })
}),
)