refactor(core): nest model api id (#30603)

This commit is contained in:
Dax
2026-06-03 14:11:38 -04:00
committed by GitHub
parent af6383485b
commit 11dbd15812
35 changed files with 129 additions and 79 deletions

View File

@@ -53,13 +53,13 @@ describe("AlibabaPlugin", () => {
}),
)
it.effect("uses the old default languageModel(apiID) behavior", () =>
it.effect("uses the old default languageModel(api.id) behavior", () =>
Effect.gen(function* () {
const plugin = yield* PluginV2.Service
yield* plugin.add(AlibabaPlugin)
const item = model("alibaba", "alias", { apiID: ModelV2.ID.make("qwen-plus") })
const item = model("alibaba", "alias", { api: { id: ModelV2.ID.make("qwen-plus") } })
const result = yield* plugin.trigger("aisdk.sdk", { model: item, package: "@ai-sdk/alibaba", options: {} }, {})
const language = result.sdk?.languageModel(item.apiID)
const language = result.sdk?.languageModel(item.api.id)
expect(language?.modelId).toBe("qwen-plus")
expect(language?.provider).toBe("alibaba.chat")
}),

View File

@@ -253,7 +253,7 @@ describe("CloudflareWorkersAIPlugin", () => {
const result = yield* plugin.trigger(
"aisdk.language",
{
model: model("cloudflare-workers-ai", "alias", { apiID: ModelV2.ID.make("@cf/api-model") }),
model: model("cloudflare-workers-ai", "alias", { api: { id: ModelV2.ID.make("@cf/api-model") } }),
sdk: fakeSelectorSdk(calls),
options: {},
},

View File

@@ -73,7 +73,7 @@ describe("CoherePlugin", () => {
yield* plugin.add(CoherePlugin)
const result = yield* plugin.trigger(
"aisdk.language",
{ model: model("cohere", "alias", { apiID: ModelV2.ID.make("command-r-plus") }), sdk, options: {} },
{ model: model("cohere", "alias", { api: { id: ModelV2.ID.make("command-r-plus") } }), sdk, options: {} },
{},
)

View File

@@ -158,15 +158,14 @@ describe("DynamicProviderPlugin", () => {
}),
)
itWithAISDK.effect("uses the model apiID for the default language model", () =>
itWithAISDK.effect("uses the model api.id for the default language model", () =>
Effect.gen(function* () {
const plugin = yield* PluginV2.Service
const aisdk = yield* AISDK.Service
yield* plugin.add(dynamicPlugin())
const language = yield* aisdk.language(
model("custom", "alias", {
apiID: ModelV2.ID.make("test-model-api"),
api: { type: "aisdk", package: fixtureProvider },
api: { id: ModelV2.ID.make("test-model-api"), type: "aisdk", package: fixtureProvider },
}),
)
expect(language).toMatchObject({ modelID: "test-model-api", options: { name: "custom" } })

View File

@@ -61,7 +61,7 @@ describe("GithubCopilotPlugin", () => {
yield* plugin.trigger(
"aisdk.language",
{
model: model("github-copilot", "alias", { apiID: ModelV2.ID.make("claude-sonnet-4") }),
model: model("github-copilot", "alias", { api: { id: ModelV2.ID.make("claude-sonnet-4") } }),
sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
options: {},
},
@@ -119,7 +119,7 @@ describe("GithubCopilotPlugin", () => {
yield* plugin.trigger(
"aisdk.language",
{
model: model("github-copilot", "default", { apiID: ModelV2.ID.make("gpt-5") }),
model: model("github-copilot", "default", { api: { id: ModelV2.ID.make("gpt-5") } }),
sdk: fakeSelectorSdk(calls),
options: {},
},
@@ -128,7 +128,7 @@ describe("GithubCopilotPlugin", () => {
yield* plugin.trigger(
"aisdk.language",
{
model: model("github-copilot", "small", { apiID: ModelV2.ID.make("gpt-5-mini") }),
model: model("github-copilot", "small", { api: { id: ModelV2.ID.make("gpt-5-mini") } }),
sdk: fakeSelectorSdk(calls),
options: {},
},
@@ -137,7 +137,7 @@ describe("GithubCopilotPlugin", () => {
yield* plugin.trigger(
"aisdk.language",
{
model: model("github-copilot", "sonnet", { apiID: ModelV2.ID.make("claude-sonnet-4") }),
model: model("github-copilot", "sonnet", { api: { id: ModelV2.ID.make("claude-sonnet-4") } }),
sdk: fakeSelectorSdk(calls),
options: {},
},

View File

@@ -51,8 +51,8 @@ describe("GooglePlugin", () => {
yield* plugin.add(GooglePlugin)
const language = yield* aisdk.language(
model("custom-google", "alias", {
apiID: ModelV2.ID.make("gemini-api"),
api: {
id: ModelV2.ID.make("gemini-api"),
type: "aisdk",
package: "@ai-sdk/google",
},

View File

@@ -75,15 +75,15 @@ describe("GroqPlugin", () => {
}),
)
aisdkIt.effect("uses the default languageModel(apiID) behavior", () =>
aisdkIt.effect("uses the default languageModel(api.id) behavior", () =>
Effect.gen(function* () {
const plugin = yield* PluginV2.Service
const aisdk = yield* AISDK.Service
yield* plugin.add(GroqPlugin)
const result = yield* aisdk.language(
model("groq", "alias", {
apiID: ModelV2.ID.make("llama-api"),
api: {
id: ModelV2.ID.make("llama-api"),
type: "aisdk",
package: "@ai-sdk/groq",
},

View File

@@ -60,7 +60,7 @@ type ProviderInput = Partial<Omit<ProviderV2.Info, "api" | "request">> & {
}
type ModelInput = Partial<Omit<ModelV2.Info, "api" | "request">> & {
api?: ProviderV2.Api
api?: (ProviderV2.Api & { id?: ModelV2.ID }) | { id: ModelV2.ID }
request?: ModelV2.Info["request"]
}
@@ -83,12 +83,16 @@ export function provider(providerID: string, options?: ProviderInput) {
export function model(providerID: string, modelID: string, options?: ModelInput) {
return new ModelV2.Info({
...ModelV2.Info.empty(ProviderV2.ID.make(providerID), ModelV2.ID.make(modelID)),
apiID: ModelV2.ID.make(modelID),
api: options?.api ?? {
type: "aisdk",
package: "test-provider",
},
...options,
api:
options?.api && "type" in options.api
? { id: ModelV2.ID.make(modelID), ...options.api }
: {
id: ModelV2.ID.make(modelID),
...options?.api,
type: "aisdk",
package: "test-provider",
},
request: {
headers: {},
body: {},

View File

@@ -87,7 +87,7 @@ describe("MistralPlugin", () => {
}),
)
it.effect("leaves Mistral language selection on the default sdk.languageModel(apiID) path", () =>
it.effect("leaves Mistral language selection on the default sdk.languageModel(api.id) path", () =>
Effect.gen(function* () {
const plugin = yield* PluginV2.Service
const calls: string[] = []
@@ -95,10 +95,10 @@ describe("MistralPlugin", () => {
yield* plugin.add(MistralPlugin)
const result = yield* plugin.trigger(
"aisdk.language",
{ model: model("mistral", "alias", { apiID: ModelV2.ID.make("mistral-large") }), sdk, options: {} },
{ model: model("mistral", "alias", { api: { id: ModelV2.ID.make("mistral-large") } }), sdk, options: {} },
{},
)
const language = result.language ?? sdk.languageModel(result.model.apiID)
const language = result.language ?? sdk.languageModel(result.model.api.id)
expect(calls).toEqual(["languageModel:mistral-large"])
expect(language).toBeDefined()
}),

View File

@@ -46,7 +46,9 @@ describe("OpenAIPlugin", () => {
const result = yield* plugin.trigger(
"aisdk.language",
{
model: model("openai", "alias", { apiID: ModelV2.ID.make("gpt-5") }),
model: model("openai", "alias", {
api: { id: ModelV2.ID.make("gpt-5"), type: "aisdk", package: "test-provider" },
}),
sdk: fakeSelectorSdk(calls),
options: {},
},

View File

@@ -94,7 +94,7 @@ describe("PerplexityPlugin", () => {
const result = yield* plugin.trigger(
"aisdk.language",
{
model: model("perplexity", "alias", { apiID: ModelV2.ID.make("sonar") }),
model: model("perplexity", "alias", { api: { id: ModelV2.ID.make("sonar") } }),
sdk: fakeSelectorSdk(calls),
options: {},
},

View File

@@ -90,7 +90,7 @@ describe("TogetherAIPlugin", () => {
expect(result.language).toBeUndefined()
expect(calls).toEqual([])
expect(result.language ?? fakeSelectorSdk(calls).languageModel(result.model.apiID)).toBeDefined()
expect(result.language ?? fakeSelectorSdk(calls).languageModel(result.model.api.id)).toBeDefined()
expect(calls).toEqual(["languageModel:meta-llama/Llama-3.3-70B-Instruct-Turbo"])
}),
)

View File

@@ -12,8 +12,8 @@ const it = testEffect(PluginV2.locationLayer.pipe(Layer.provide(EventV2.defaultL
const model = new ModelV2.Info({
...ModelV2.Info.empty(ProviderV2.ID.make("xai"), ModelV2.ID.make("grok-4")),
apiID: ModelV2.ID.make("grok-4"),
api: {
id: ModelV2.ID.make("grok-4"),
type: "aisdk",
package: "@ai-sdk/xai",
},
@@ -72,7 +72,7 @@ describe("XAIPlugin", () => {
}),
)
it.effect("uses responses with the model apiID for xAI language models", () =>
it.effect("uses responses with the model api.id for xAI language models", () =>
Effect.gen(function* () {
const plugin = yield* PluginV2.Service
const calls: string[] = []
@@ -81,7 +81,7 @@ describe("XAIPlugin", () => {
const result = yield* plugin.trigger(
"aisdk.language",
{
model: new ModelV2.Info({ ...model, id: ModelV2.ID.make("alias"), apiID: ModelV2.ID.make("grok-4") }),
model: new ModelV2.Info({ ...model, id: ModelV2.ID.make("alias") }),
sdk: fakeSelectorSdk(calls),
options: {},
},