|
|
@@ -1,3 +1,4 @@
|
|
|
+import { AISDK } from "@opencode-ai/core/aisdk"
|
|
|
import { describe, expect } from "bun:test"
|
|
|
import type { LanguageModelV3 } from "@ai-sdk/provider"
|
|
|
import { Effect } from "effect"
|
|
|
@@ -14,8 +15,9 @@ const it = testEffect(PluginTestLayer)
|
|
|
|
|
|
const addPlugin = Effect.fn(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
- const host = yield* PluginHost.make()
|
|
|
- yield* plugin.add({ id: AmazonBedrockPlugin.id, effect: AmazonBedrockPlugin.effect(host) })
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
+ const host = yield* PluginHost.make(plugin)
|
|
|
+ yield* AmazonBedrockPlugin.effect(host)
|
|
|
})
|
|
|
|
|
|
function required<T>(value: T | undefined): T {
|
|
|
@@ -109,25 +111,22 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
withEnv({ AWS_BEARER_TOKEN_BEDROCK: undefined, AWS_PROFILE: undefined, AWS_ACCESS_KEY_ID: undefined }, () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.sdk",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- package: "@ai-sdk/amazon-bedrock",
|
|
|
- options: {
|
|
|
- name: "amazon-bedrock",
|
|
|
- bearerToken: "token",
|
|
|
- baseURL: "https://base.example",
|
|
|
- endpoint: "https://endpoint.example",
|
|
|
- region: "us-east-1",
|
|
|
- },
|
|
|
+ const result = yield* aisdk.runSDK({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ package: "@ai-sdk/amazon-bedrock",
|
|
|
+ options: {
|
|
|
+ name: "amazon-bedrock",
|
|
|
+ bearerToken: "token",
|
|
|
+ baseURL: "https://base.example",
|
|
|
+ endpoint: "https://endpoint.example",
|
|
|
+ region: "us-east-1",
|
|
|
},
|
|
|
- {},
|
|
|
- )
|
|
|
+ })
|
|
|
expect(bedrockBaseURL(result.sdk)).toBe("https://endpoint.example")
|
|
|
}),
|
|
|
),
|
|
|
@@ -137,24 +136,21 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
withEnv({ AWS_BEARER_TOKEN_BEDROCK: undefined, AWS_PROFILE: undefined, AWS_ACCESS_KEY_ID: undefined }, () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.sdk",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- package: "@ai-sdk/amazon-bedrock",
|
|
|
- options: {
|
|
|
- name: "amazon-bedrock",
|
|
|
- bearerToken: "token",
|
|
|
- baseURL: "https://base.example",
|
|
|
- region: "us-east-1",
|
|
|
- },
|
|
|
+ const result = yield* aisdk.runSDK({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ package: "@ai-sdk/amazon-bedrock",
|
|
|
+ options: {
|
|
|
+ name: "amazon-bedrock",
|
|
|
+ bearerToken: "token",
|
|
|
+ baseURL: "https://base.example",
|
|
|
+ region: "us-east-1",
|
|
|
},
|
|
|
- {},
|
|
|
- )
|
|
|
+ })
|
|
|
expect(bedrockBaseURL(result.sdk)).toBe("https://base.example")
|
|
|
}),
|
|
|
),
|
|
|
@@ -174,23 +170,20 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
() =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.sdk",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: {
|
|
|
- id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"),
|
|
|
- type: "aisdk",
|
|
|
- package: "test-provider",
|
|
|
- },
|
|
|
- }),
|
|
|
- package: "@ai-sdk/amazon-bedrock",
|
|
|
- options: { name: "amazon-bedrock" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
+ const result = yield* aisdk.runSDK({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: {
|
|
|
+ id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"),
|
|
|
+ type: "aisdk",
|
|
|
+ package: "test-provider",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ package: "@ai-sdk/amazon-bedrock",
|
|
|
+ options: { name: "amazon-bedrock" },
|
|
|
+ })
|
|
|
expect(result.sdk).toBeDefined()
|
|
|
expect(bedrockBaseURL(result.sdk)).toBe("https://bedrock-runtime.us-east-1.amazonaws.com")
|
|
|
}),
|
|
|
@@ -201,19 +194,16 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
withEnv({ AWS_BEARER_TOKEN_BEDROCK: "token", AWS_REGION: "us-east-1" }, () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.sdk",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- package: "@ai-sdk/amazon-bedrock",
|
|
|
- options: { name: "amazon-bedrock", region: "eu-west-1" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
+ const result = yield* aisdk.runSDK({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ package: "@ai-sdk/amazon-bedrock",
|
|
|
+ options: { name: "amazon-bedrock", region: "eu-west-1" },
|
|
|
+ })
|
|
|
expect(bedrockBaseURL(result.sdk)).toBe("https://bedrock-runtime.eu-west-1.amazonaws.com")
|
|
|
}),
|
|
|
),
|
|
|
@@ -223,19 +213,16 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
withEnv({ AWS_BEARER_TOKEN_BEDROCK: "token", AWS_REGION: "eu-west-1" }, () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.sdk",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- package: "@ai-sdk/amazon-bedrock",
|
|
|
- options: { name: "amazon-bedrock" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
+ const result = yield* aisdk.runSDK({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ package: "@ai-sdk/amazon-bedrock",
|
|
|
+ options: { name: "amazon-bedrock" },
|
|
|
+ })
|
|
|
expect(bedrockBaseURL(result.sdk)).toBe("https://bedrock-runtime.eu-west-1.amazonaws.com")
|
|
|
}),
|
|
|
),
|
|
|
@@ -245,19 +232,16 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
withEnv({ AWS_BEARER_TOKEN_BEDROCK: "token", AWS_REGION: undefined }, () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.sdk",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- package: "@ai-sdk/amazon-bedrock",
|
|
|
- options: { name: "amazon-bedrock" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
+ const result = yield* aisdk.runSDK({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ package: "@ai-sdk/amazon-bedrock",
|
|
|
+ options: { name: "amazon-bedrock" },
|
|
|
+ })
|
|
|
expect(bedrockBaseURL(result.sdk)).toBe("https://bedrock-runtime.us-east-1.amazonaws.com")
|
|
|
}),
|
|
|
),
|
|
|
@@ -267,27 +251,24 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
withEnv({ AWS_ACCESS_KEY_ID: undefined, AWS_BEARER_TOKEN_BEDROCK: undefined, AWS_PROFILE: undefined }, () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
const headers: Array<string | null> = []
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.sdk",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- package: "@ai-sdk/amazon-bedrock",
|
|
|
- options: {
|
|
|
- name: "amazon-bedrock",
|
|
|
- bearerToken: "option-token",
|
|
|
- fetch: async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
|
|
|
- headers.push(new Headers(init?.headers).get("Authorization"))
|
|
|
- return new Response("{}")
|
|
|
- },
|
|
|
+ const result = yield* aisdk.runSDK({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ package: "@ai-sdk/amazon-bedrock",
|
|
|
+ options: {
|
|
|
+ name: "amazon-bedrock",
|
|
|
+ bearerToken: "option-token",
|
|
|
+ fetch: async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
|
|
|
+ headers.push(new Headers(init?.headers).get("Authorization"))
|
|
|
+ return new Response("{}")
|
|
|
},
|
|
|
},
|
|
|
- {},
|
|
|
- )
|
|
|
+ })
|
|
|
yield* Effect.promise(() => bedrockFetch(result.sdk)("https://bedrock.example", { method: "POST" }))
|
|
|
expect(process.env.AWS_BEARER_TOKEN_BEDROCK).toBe("option-token")
|
|
|
expect(headers).toEqual(["Bearer option-token"])
|
|
|
@@ -299,27 +280,24 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
withEnv({ AWS_BEARER_TOKEN_BEDROCK: "env-token" }, () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
const headers: Array<string | null> = []
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.sdk",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- package: "@ai-sdk/amazon-bedrock",
|
|
|
- options: {
|
|
|
- name: "amazon-bedrock",
|
|
|
- bearerToken: "option-token",
|
|
|
- fetch: async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
|
|
|
- headers.push(new Headers(init?.headers).get("Authorization"))
|
|
|
- return new Response("{}")
|
|
|
- },
|
|
|
+ const result = yield* aisdk.runSDK({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ package: "@ai-sdk/amazon-bedrock",
|
|
|
+ options: {
|
|
|
+ name: "amazon-bedrock",
|
|
|
+ bearerToken: "option-token",
|
|
|
+ fetch: async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
|
|
|
+ headers.push(new Headers(init?.headers).get("Authorization"))
|
|
|
+ return new Response("{}")
|
|
|
},
|
|
|
},
|
|
|
- {},
|
|
|
- )
|
|
|
+ })
|
|
|
yield* Effect.promise(() => bedrockFetch(result.sdk)("https://bedrock.example", { method: "POST" }))
|
|
|
expect(process.env.AWS_BEARER_TOKEN_BEDROCK).toBe("env-token")
|
|
|
expect(headers).toEqual(["Bearer env-token"])
|
|
|
@@ -331,28 +309,25 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
withEnv({ AWS_BEARER_TOKEN_BEDROCK: undefined, AWS_PROFILE: undefined, AWS_ACCESS_KEY_ID: undefined }, () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.sdk",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("openai.gpt-5.5")),
|
|
|
- api: {
|
|
|
- id: ModelV2.ID.make("openai.gpt-5.5"),
|
|
|
- type: "aisdk",
|
|
|
- package: "@ai-sdk/amazon-bedrock/mantle",
|
|
|
- },
|
|
|
- }),
|
|
|
- package: "@ai-sdk/amazon-bedrock/mantle",
|
|
|
- options: {
|
|
|
- name: "amazon-bedrock",
|
|
|
- bearerToken: "token",
|
|
|
- baseURL: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
|
|
|
- region: "us-east-2",
|
|
|
+ const result = yield* aisdk.runSDK({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("openai.gpt-5.5")),
|
|
|
+ api: {
|
|
|
+ id: ModelV2.ID.make("openai.gpt-5.5"),
|
|
|
+ type: "aisdk",
|
|
|
+ package: "@ai-sdk/amazon-bedrock/mantle",
|
|
|
},
|
|
|
+ }),
|
|
|
+ package: "@ai-sdk/amazon-bedrock/mantle",
|
|
|
+ options: {
|
|
|
+ name: "amazon-bedrock",
|
|
|
+ bearerToken: "token",
|
|
|
+ baseURL: "https://bedrock-mantle.us-east-2.api.aws/openai/v1",
|
|
|
+ region: "us-east-2",
|
|
|
},
|
|
|
- {},
|
|
|
- )
|
|
|
+ })
|
|
|
const language = result.sdk.responses("openai.gpt-5.5")
|
|
|
expect(openAIUrl(language, "/responses", "openai.gpt-5.5")).toBe(
|
|
|
"https://bedrock-mantle.us-east-2.api.aws/openai/v1/responses",
|
|
|
@@ -364,40 +339,33 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
it.effect("selects Mantle APIs without Bedrock cross-region prefixes", () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
const calls: string[] = []
|
|
|
yield* addPlugin()
|
|
|
- yield* plugin.trigger(
|
|
|
- "aisdk.language",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("openai.gpt-5.5")),
|
|
|
- api: {
|
|
|
- id: ModelV2.ID.make("openai.gpt-5.5"),
|
|
|
- type: "aisdk",
|
|
|
- package: "@ai-sdk/amazon-bedrock/mantle",
|
|
|
- },
|
|
|
- }),
|
|
|
- sdk: fakeSelectorSdk(calls),
|
|
|
- options: { baseURL: "https://bedrock-mantle.us-east-2.api.aws/openai/v1", region: "us-east-2" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
- yield* plugin.trigger(
|
|
|
- "aisdk.language",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("openai.gpt-oss-safeguard-120b")),
|
|
|
- api: {
|
|
|
- id: ModelV2.ID.make("openai.gpt-oss-safeguard-120b"),
|
|
|
- type: "aisdk",
|
|
|
- package: "@ai-sdk/amazon-bedrock/mantle",
|
|
|
- },
|
|
|
- }),
|
|
|
- sdk: fakeSelectorSdk(calls),
|
|
|
- options: { region: "us-east-1" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
+ yield* aisdk.runLanguage({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("openai.gpt-5.5")),
|
|
|
+ api: {
|
|
|
+ id: ModelV2.ID.make("openai.gpt-5.5"),
|
|
|
+ type: "aisdk",
|
|
|
+ package: "@ai-sdk/amazon-bedrock/mantle",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ sdk: fakeSelectorSdk(calls),
|
|
|
+ options: { baseURL: "https://bedrock-mantle.us-east-2.api.aws/openai/v1", region: "us-east-2" },
|
|
|
+ })
|
|
|
+ yield* aisdk.runLanguage({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("openai.gpt-oss-safeguard-120b")),
|
|
|
+ api: {
|
|
|
+ id: ModelV2.ID.make("openai.gpt-oss-safeguard-120b"),
|
|
|
+ type: "aisdk",
|
|
|
+ package: "@ai-sdk/amazon-bedrock/mantle",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ sdk: fakeSelectorSdk(calls),
|
|
|
+ options: { region: "us-east-1" },
|
|
|
+ })
|
|
|
expect(calls).toEqual(["responses:openai.gpt-5.5", "chat:openai.gpt-oss-safeguard-120b"])
|
|
|
}),
|
|
|
)
|
|
|
@@ -405,23 +373,20 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
it.effect("ignores other Bedrock provider subpaths", () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.sdk",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: {
|
|
|
- id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"),
|
|
|
- type: "aisdk",
|
|
|
- package: "@ai-sdk/amazon-bedrock/anthropic",
|
|
|
- },
|
|
|
- }),
|
|
|
- package: "@ai-sdk/amazon-bedrock/anthropic",
|
|
|
- options: { name: "amazon-bedrock" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
+ const result = yield* aisdk.runSDK({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: {
|
|
|
+ id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"),
|
|
|
+ type: "aisdk",
|
|
|
+ package: "@ai-sdk/amazon-bedrock/anthropic",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ package: "@ai-sdk/amazon-bedrock/anthropic",
|
|
|
+ options: { name: "amazon-bedrock" },
|
|
|
+ })
|
|
|
expect(result.sdk).toBeUndefined()
|
|
|
}),
|
|
|
)
|
|
|
@@ -438,30 +403,27 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
() =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
const headers: Array<string | null> = []
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.sdk",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: {
|
|
|
- id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"),
|
|
|
- type: "aisdk",
|
|
|
- package: "test-provider",
|
|
|
- },
|
|
|
- }),
|
|
|
- package: "@ai-sdk/amazon-bedrock",
|
|
|
- options: {
|
|
|
- name: "amazon-bedrock",
|
|
|
- fetch: async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
|
|
|
- headers.push(new Headers(init?.headers).get("Authorization"))
|
|
|
- return new Response("{}")
|
|
|
- },
|
|
|
+ const result = yield* aisdk.runSDK({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: {
|
|
|
+ id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"),
|
|
|
+ type: "aisdk",
|
|
|
+ package: "test-provider",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ package: "@ai-sdk/amazon-bedrock",
|
|
|
+ options: {
|
|
|
+ name: "amazon-bedrock",
|
|
|
+ fetch: async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
|
|
|
+ headers.push(new Headers(init?.headers).get("Authorization"))
|
|
|
+ return new Response("{}")
|
|
|
},
|
|
|
},
|
|
|
- {},
|
|
|
- )
|
|
|
+ })
|
|
|
yield* Effect.promise(() =>
|
|
|
bedrockFetch(result.sdk)("https://bedrock-runtime.us-east-1.amazonaws.com/model/test/invoke", {
|
|
|
body: "{}",
|
|
|
@@ -476,72 +438,53 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
it.effect("applies legacy cross-region inference prefixes", () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
const calls: string[] = []
|
|
|
yield* addPlugin()
|
|
|
- yield* plugin.trigger(
|
|
|
- "aisdk.language",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
- options: {},
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
- yield* plugin.trigger(
|
|
|
- "aisdk.language",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
- options: { region: "eu-west-1" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
- yield* plugin.trigger(
|
|
|
- "aisdk.language",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("global.anthropic.claude-sonnet-4-5")),
|
|
|
- api: {
|
|
|
- id: ModelV2.ID.make("global.anthropic.claude-sonnet-4-5"),
|
|
|
- type: "aisdk",
|
|
|
- package: "test-provider",
|
|
|
- },
|
|
|
- }),
|
|
|
- sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
- options: { region: "eu-west-1" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
- yield* plugin.trigger(
|
|
|
- "aisdk.language",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
- options: { region: "ap-northeast-1" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
- yield* plugin.trigger(
|
|
|
- "aisdk.language",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
- options: { region: "ap-southeast-2" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
+ yield* aisdk.runLanguage({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
+ options: {},
|
|
|
+ })
|
|
|
+ yield* aisdk.runLanguage({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
+ options: { region: "eu-west-1" },
|
|
|
+ })
|
|
|
+ yield* aisdk.runLanguage({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("global.anthropic.claude-sonnet-4-5")),
|
|
|
+ api: {
|
|
|
+ id: ModelV2.ID.make("global.anthropic.claude-sonnet-4-5"),
|
|
|
+ type: "aisdk",
|
|
|
+ package: "test-provider",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
+ options: { region: "eu-west-1" },
|
|
|
+ })
|
|
|
+ yield* aisdk.runLanguage({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
+ options: { region: "ap-northeast-1" },
|
|
|
+ })
|
|
|
+ yield* aisdk.runLanguage({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
+ options: { region: "ap-southeast-2" },
|
|
|
+ })
|
|
|
expect(calls).toEqual([
|
|
|
"languageModel:us.anthropic.claude-sonnet-4-5",
|
|
|
"languageModel:eu.anthropic.claude-sonnet-4-5",
|
|
|
@@ -556,20 +499,17 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
withEnv({ AWS_REGION: "eu-west-1" }, () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
const calls: string[] = []
|
|
|
yield* addPlugin()
|
|
|
- yield* plugin.trigger(
|
|
|
- "aisdk.language",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
- options: {},
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
+ yield* aisdk.runLanguage({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
+ options: {},
|
|
|
+ })
|
|
|
expect(calls).toEqual(["languageModel:eu.anthropic.claude-sonnet-4-5"])
|
|
|
}),
|
|
|
),
|
|
|
@@ -578,6 +518,7 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
it.effect("applies the full legacy cross-region prefix matrix", () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
const calls: string[] = []
|
|
|
const cases = [
|
|
|
{ region: "us-east-1", modelID: "amazon.nova-micro-v1:0", expected: "us.amazon.nova-micro-v1:0" },
|
|
|
@@ -647,18 +588,14 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
]
|
|
|
yield* addPlugin()
|
|
|
for (const item of cases) {
|
|
|
- yield* plugin.trigger(
|
|
|
- "aisdk.language",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make(item.modelID)),
|
|
|
- api: { id: ModelV2.ID.make(item.modelID), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
- options: { region: item.region },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
+ yield* aisdk.runLanguage({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.amazonBedrock, ModelV2.ID.make(item.modelID)),
|
|
|
+ api: { id: ModelV2.ID.make(item.modelID), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
+ options: { region: item.region },
|
|
|
+ })
|
|
|
}
|
|
|
expect(calls).toEqual(cases.map((item) => `languageModel:${item.expected}`))
|
|
|
}),
|
|
|
@@ -667,20 +604,17 @@ describe("AmazonBedrockPlugin", () => {
|
|
|
it.effect("ignores non-Bedrock providers for language selection", () =>
|
|
|
Effect.gen(function* () {
|
|
|
const plugin = yield* PluginV2.Service
|
|
|
+ const aisdk = yield* AISDK.Service
|
|
|
const calls: string[] = []
|
|
|
yield* addPlugin()
|
|
|
- const result = yield* plugin.trigger(
|
|
|
- "aisdk.language",
|
|
|
- {
|
|
|
- model: new ModelV2.Info({
|
|
|
- ...ModelV2.Info.empty(ProviderV2.ID.openai, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
- api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
- }),
|
|
|
- sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
- options: { region: "eu-west-1" },
|
|
|
- },
|
|
|
- {},
|
|
|
- )
|
|
|
+ const result = yield* aisdk.runLanguage({
|
|
|
+ model: new ModelV2.Info({
|
|
|
+ ...ModelV2.Info.empty(ProviderV2.ID.openai, ModelV2.ID.make("anthropic.claude-sonnet-4-5")),
|
|
|
+ api: { id: ModelV2.ID.make("anthropic.claude-sonnet-4-5"), type: "aisdk", package: "test-provider" },
|
|
|
+ }),
|
|
|
+ sdk: { languageModel: fakeSelectorSdk(calls).languageModel },
|
|
|
+ options: { region: "eu-west-1" },
|
|
|
+ })
|
|
|
expect(calls).toEqual([])
|
|
|
expect(result.language).toBeUndefined()
|
|
|
}),
|