@tanstack/ai-bedrock 0.3.8 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/adapters/responses-text.js +1 -1
- package/dist/esm/adapters/responses-text.js.map +1 -1
- package/dist/esm/adapters/text.js +1 -1
- package/dist/esm/adapters/text.js.map +1 -1
- package/dist/esm/api-compatibility.d.ts +33 -0
- package/dist/esm/api-compatibility.js +121 -0
- package/dist/esm/api-compatibility.js.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/model-catalog.generated.d.ts +27 -0
- package/dist/esm/model-catalog.generated.js +30 -0
- package/dist/esm/model-catalog.generated.js.map +1 -1
- package/dist/esm/model-meta.js +1 -1
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/utils/client.d.ts +1 -1
- package/dist/esm/utils/client.js +7 -5
- package/dist/esm/utils/client.js.map +1 -1
- package/package.json +3 -3
- package/src/adapters/responses-text.ts +1 -1
- package/src/adapters/text.ts +5 -1
- package/src/api-compatibility.ts +105 -0
- package/src/index.ts +25 -5
- package/src/model-catalog.generated.ts +18 -0
- package/src/model-meta.ts +3 -3
- package/src/utils/client.ts +12 -4
|
@@ -12,7 +12,7 @@ var BedrockResponsesTextAdapter = class extends OpenAIBaseResponsesTextAdapter {
|
|
|
12
12
|
kind = "text";
|
|
13
13
|
name = "bedrock-responses";
|
|
14
14
|
constructor(config, model) {
|
|
15
|
-
super(model, "bedrock-responses", new OpenAI(withBedrockDefaults(config, "mantle")));
|
|
15
|
+
super(model, "bedrock-responses", new OpenAI(withBedrockDefaults(config, "mantle", model)));
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
/** Responses adapter with an explicit API key (low-level; the public branching factory delegates here). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses-text.js","names":[],"sources":["../../../src/adapters/responses-text.ts"],"sourcesContent":["import OpenAI from 'openai'\nimport { OpenAIBaseResponsesTextAdapter } from '@tanstack/openai-base'\nimport { withBedrockDefaults } from '../utils/client'\nimport type { Modality } from '@tanstack/ai'\nimport type { BedrockClientConfig } from '../utils/client'\nimport type { BedrockMessageMetadataByModality } from '../message-types'\nimport type {\n BedrockChatModelToolCapabilitiesByName,\n BedrockResponsesModels,\n ResolveInputModalities,\n} from '../model-meta'\nimport type { ExternalResponsesProviderOptions } from '../text/responses-provider-options'\n\nexport interface BedrockResponsesConfig extends BedrockClientConfig {}\n\nexport type { ExternalResponsesProviderOptions as BedrockResponsesProviderOptions } from '../text/responses-provider-options'\n\ntype ResolveToolCapabilities<TModel extends string> =\n TModel extends keyof BedrockChatModelToolCapabilitiesByName\n ? NonNullable<BedrockChatModelToolCapabilitiesByName[TModel]>\n : readonly []\n\n/**\n * Bedrock Responses adapter. Drives mantle's OpenAI-compatible `/responses`\n * endpoint via the OpenAI SDK (`client.responses.create`) — the same base\n * class ai-openai's `openaiText` uses. Responses is mantle-only, so the\n * constructor forces the mantle baseURL.\n */\nexport class BedrockResponsesTextAdapter<\n TModel extends BedrockResponsesModels,\n // Constraint mirrors the chat adapter (and ai-groq / ai-openai) and the base,\n // which parameterises `TProviderOptions extends Record<string, any>`. Our\n // default `ExternalResponsesProviderOptions` is an interface that (lacking an\n // implicit index signature) `Record<string, unknown>` would reject but\n // `Record<string, any>` accepts. This `any` is confined to the generic\n // constraint — no value/shape `as` cast is introduced.\n TProviderOptions extends Record<string, any> =\n ExternalResponsesProviderOptions,\n TInputModalities extends ReadonlyArray<Modality> =\n ResolveInputModalities<TModel>,\n TToolCapabilities extends ReadonlyArray<string> =\n ResolveToolCapabilities<TModel>,\n> extends OpenAIBaseResponsesTextAdapter<\n TModel,\n TProviderOptions,\n TInputModalities,\n BedrockMessageMetadataByModality,\n TToolCapabilities\n> {\n override readonly kind = 'text' as const\n override readonly name = 'bedrock-responses' as const\n\n constructor(config: BedrockResponsesConfig, model: TModel) {\n // Responses is mantle-only — force the mantle base URL (an explicit\n // config.baseURL still wins, e.g. E2E pointing at aimock).\n super(\n model,\n 'bedrock-responses',\n new OpenAI(withBedrockDefaults(config, 'mantle')),\n )\n }\n}\n\n/** Responses adapter with an explicit API key (low-level; the public branching factory delegates here). */\nexport function createBedrockResponsesText<\n TModel extends BedrockResponsesModels,\n>(\n model: TModel,\n apiKey: string,\n config?: Omit<BedrockResponsesConfig, 'apiKey'>,\n): BedrockResponsesTextAdapter<TModel> {\n return new BedrockResponsesTextAdapter({ ...config, apiKey }, model)\n}\n"],"mappings":";;;;;;;;;;AA4BA,IAAa,8BAAb,cAcU,+BAMR;CACA,OAAyB;CACzB,OAAyB;CAEzB,YAAY,QAAgC,OAAe;EAGzD,MACE,OACA,qBACA,IAAI,OAAO,oBAAoB,QAAQ,
|
|
1
|
+
{"version":3,"file":"responses-text.js","names":[],"sources":["../../../src/adapters/responses-text.ts"],"sourcesContent":["import OpenAI from 'openai'\nimport { OpenAIBaseResponsesTextAdapter } from '@tanstack/openai-base'\nimport { withBedrockDefaults } from '../utils/client'\nimport type { Modality } from '@tanstack/ai'\nimport type { BedrockClientConfig } from '../utils/client'\nimport type { BedrockMessageMetadataByModality } from '../message-types'\nimport type {\n BedrockChatModelToolCapabilitiesByName,\n BedrockResponsesModels,\n ResolveInputModalities,\n} from '../model-meta'\nimport type { ExternalResponsesProviderOptions } from '../text/responses-provider-options'\n\nexport interface BedrockResponsesConfig extends BedrockClientConfig {}\n\nexport type { ExternalResponsesProviderOptions as BedrockResponsesProviderOptions } from '../text/responses-provider-options'\n\ntype ResolveToolCapabilities<TModel extends string> =\n TModel extends keyof BedrockChatModelToolCapabilitiesByName\n ? NonNullable<BedrockChatModelToolCapabilitiesByName[TModel]>\n : readonly []\n\n/**\n * Bedrock Responses adapter. Drives mantle's OpenAI-compatible `/responses`\n * endpoint via the OpenAI SDK (`client.responses.create`) — the same base\n * class ai-openai's `openaiText` uses. Responses is mantle-only, so the\n * constructor forces the mantle baseURL.\n */\nexport class BedrockResponsesTextAdapter<\n TModel extends BedrockResponsesModels,\n // Constraint mirrors the chat adapter (and ai-groq / ai-openai) and the base,\n // which parameterises `TProviderOptions extends Record<string, any>`. Our\n // default `ExternalResponsesProviderOptions` is an interface that (lacking an\n // implicit index signature) `Record<string, unknown>` would reject but\n // `Record<string, any>` accepts. This `any` is confined to the generic\n // constraint — no value/shape `as` cast is introduced.\n TProviderOptions extends Record<string, any> =\n ExternalResponsesProviderOptions,\n TInputModalities extends ReadonlyArray<Modality> =\n ResolveInputModalities<TModel>,\n TToolCapabilities extends ReadonlyArray<string> =\n ResolveToolCapabilities<TModel>,\n> extends OpenAIBaseResponsesTextAdapter<\n TModel,\n TProviderOptions,\n TInputModalities,\n BedrockMessageMetadataByModality,\n TToolCapabilities\n> {\n override readonly kind = 'text' as const\n override readonly name = 'bedrock-responses' as const\n\n constructor(config: BedrockResponsesConfig, model: TModel) {\n // Responses is mantle-only — force the mantle base URL (an explicit\n // config.baseURL still wins, e.g. E2E pointing at aimock).\n super(\n model,\n 'bedrock-responses',\n new OpenAI(withBedrockDefaults(config, 'mantle', model)),\n )\n }\n}\n\n/** Responses adapter with an explicit API key (low-level; the public branching factory delegates here). */\nexport function createBedrockResponsesText<\n TModel extends BedrockResponsesModels,\n>(\n model: TModel,\n apiKey: string,\n config?: Omit<BedrockResponsesConfig, 'apiKey'>,\n): BedrockResponsesTextAdapter<TModel> {\n return new BedrockResponsesTextAdapter({ ...config, apiKey }, model)\n}\n"],"mappings":";;;;;;;;;;AA4BA,IAAa,8BAAb,cAcU,+BAMR;CACA,OAAyB;CACzB,OAAyB;CAEzB,YAAY,QAAgC,OAAe;EAGzD,MACE,OACA,qBACA,IAAI,OAAO,oBAAoB,QAAQ,UAAU,KAAK,CAAC,CACzD;CACF;AACF;;AAGA,SAAgB,2BAGd,OACA,QACA,QACqC;CACrC,OAAO,IAAI,4BAA4B;EAAE,GAAG;EAAQ;CAAO,GAAG,KAAK;AACrE"}
|
|
@@ -12,7 +12,7 @@ var BedrockTextAdapter = class extends OpenAIBaseChatCompletionsTextAdapter {
|
|
|
12
12
|
kind = "text";
|
|
13
13
|
name = "bedrock";
|
|
14
14
|
constructor(config, model) {
|
|
15
|
-
super(model, "bedrock", new OpenAI(withBedrockDefaults(config)));
|
|
15
|
+
super(model, "bedrock", new OpenAI(withBedrockDefaults(config, void 0, model)));
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Surface reasoning deltas (gpt-oss / Claude reasoning) the OpenAI-compatible
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","names":[],"sources":["../../../src/adapters/text.ts"],"sourcesContent":["import OpenAI from 'openai'\nimport { OpenAIBaseChatCompletionsTextAdapter } from '@tanstack/openai-base'\nimport { withBedrockDefaults } from '../utils/client'\nimport type { Modality } from '@tanstack/ai'\nimport type { BedrockClientConfig } from '../utils/client'\nimport type { BedrockMessageMetadataByModality } from '../message-types'\nimport type {\n BedrockChatModelToolCapabilitiesByName,\n BedrockChatModels,\n ResolveInputModalities,\n ResolveProviderOptions,\n} from '../model-meta'\n\nexport interface BedrockTextConfig extends BedrockClientConfig {}\n\nexport type { ExternalTextProviderOptions as BedrockTextProviderOptions } from '../text/text-provider-options'\n\ntype ResolveToolCapabilities<TModel extends string> =\n TModel extends keyof BedrockChatModelToolCapabilitiesByName\n ? NonNullable<BedrockChatModelToolCapabilitiesByName[TModel]>\n : readonly []\n\n/**\n * Bedrock Chat Completions adapter. Drives Bedrock's OpenAI-compatible\n * `/chat/completions` endpoint via the OpenAI SDK with a baseURL override\n * (same pattern as ai-groq). Tool conversion, streaming, structured output,\n * and the agent loop come from the base.\n */\nexport class BedrockTextAdapter<\n TModel extends BedrockChatModels,\n // Constraint mirrors ai-groq and the base, which parameterises\n // `TProviderOptions extends Record<string, any>`. Our default\n // `ResolveProviderOptions<TModel>` resolves to the `BedrockTextProviderOptions`\n // interface, which (lacking an implicit index signature) `Record<string,\n // unknown>` would reject but `Record<string, any>` accepts. This `any` is\n // confined to the generic constraint (the established ai-groq pattern) — no\n // value/shape `as` cast is introduced.\n TProviderOptions extends Record<string, any> = ResolveProviderOptions<TModel>,\n TInputModalities extends ReadonlyArray<Modality> =\n ResolveInputModalities<TModel>,\n TToolCapabilities extends ReadonlyArray<string> =\n ResolveToolCapabilities<TModel>,\n> extends OpenAIBaseChatCompletionsTextAdapter<\n TModel,\n TProviderOptions,\n TInputModalities,\n BedrockMessageMetadataByModality,\n TToolCapabilities\n> {\n override readonly kind = 'text' as const\n override readonly name = 'bedrock' as const\n\n constructor(config: BedrockTextConfig, model: TModel) {\n // No `forced` -> honors config.endpoint ('runtime' default, 'mantle' allowed).\n super(model
|
|
1
|
+
{"version":3,"file":"text.js","names":[],"sources":["../../../src/adapters/text.ts"],"sourcesContent":["import OpenAI from 'openai'\nimport { OpenAIBaseChatCompletionsTextAdapter } from '@tanstack/openai-base'\nimport { withBedrockDefaults } from '../utils/client'\nimport type { Modality } from '@tanstack/ai'\nimport type { BedrockClientConfig } from '../utils/client'\nimport type { BedrockMessageMetadataByModality } from '../message-types'\nimport type {\n BedrockChatModelToolCapabilitiesByName,\n BedrockChatModels,\n ResolveInputModalities,\n ResolveProviderOptions,\n} from '../model-meta'\n\nexport interface BedrockTextConfig extends BedrockClientConfig {}\n\nexport type { ExternalTextProviderOptions as BedrockTextProviderOptions } from '../text/text-provider-options'\n\ntype ResolveToolCapabilities<TModel extends string> =\n TModel extends keyof BedrockChatModelToolCapabilitiesByName\n ? NonNullable<BedrockChatModelToolCapabilitiesByName[TModel]>\n : readonly []\n\n/**\n * Bedrock Chat Completions adapter. Drives Bedrock's OpenAI-compatible\n * `/chat/completions` endpoint via the OpenAI SDK with a baseURL override\n * (same pattern as ai-groq). Tool conversion, streaming, structured output,\n * and the agent loop come from the base.\n */\nexport class BedrockTextAdapter<\n TModel extends BedrockChatModels,\n // Constraint mirrors ai-groq and the base, which parameterises\n // `TProviderOptions extends Record<string, any>`. Our default\n // `ResolveProviderOptions<TModel>` resolves to the `BedrockTextProviderOptions`\n // interface, which (lacking an implicit index signature) `Record<string,\n // unknown>` would reject but `Record<string, any>` accepts. This `any` is\n // confined to the generic constraint (the established ai-groq pattern) — no\n // value/shape `as` cast is introduced.\n TProviderOptions extends Record<string, any> = ResolveProviderOptions<TModel>,\n TInputModalities extends ReadonlyArray<Modality> =\n ResolveInputModalities<TModel>,\n TToolCapabilities extends ReadonlyArray<string> =\n ResolveToolCapabilities<TModel>,\n> extends OpenAIBaseChatCompletionsTextAdapter<\n TModel,\n TProviderOptions,\n TInputModalities,\n BedrockMessageMetadataByModality,\n TToolCapabilities\n> {\n override readonly kind = 'text' as const\n override readonly name = 'bedrock' as const\n\n constructor(config: BedrockTextConfig, model: TModel) {\n // No `forced` -> honors config.endpoint ('runtime' default, 'mantle' allowed).\n super(\n model,\n 'bedrock',\n new OpenAI(withBedrockDefaults(config, undefined, model)),\n )\n }\n\n /**\n * Surface reasoning deltas (gpt-oss / Claude reasoning) the OpenAI-compatible\n * way. Base types the chunk as `unknown`; narrow with runtime guards — no\n * `as` casts, no `any`.\n */\n protected override extractReasoning(\n chunk: unknown,\n ): { text: string } | undefined {\n return readDeltaReasoning(chunk)\n }\n}\n\n/** Cast-free narrowing of a Chat Completions chunk's reasoning delta. */\nfunction readDeltaReasoning(chunk: unknown): { text: string } | undefined {\n if (typeof chunk !== 'object' || chunk === null || !('choices' in chunk))\n return undefined\n if (!Array.isArray(chunk.choices)) return undefined\n const choice: unknown = chunk.choices[0]\n if (typeof choice !== 'object' || choice === null || !('delta' in choice))\n return undefined\n const delta = choice.delta\n if (typeof delta !== 'object' || delta === null) return undefined\n const raw =\n 'reasoning' in delta && typeof delta.reasoning === 'string'\n ? delta.reasoning\n : 'reasoning_content' in delta &&\n typeof delta.reasoning_content === 'string'\n ? delta.reasoning_content\n : undefined\n return raw && raw.length > 0 ? { text: raw } : undefined\n}\n\n/** Chat adapter with an explicit API key (low-level; the public branching factory delegates here). */\nexport function createBedrockChat<TModel extends BedrockChatModels>(\n model: TModel,\n apiKey: string,\n config?: Omit<BedrockTextConfig, 'apiKey'>,\n): BedrockTextAdapter<TModel> {\n return new BedrockTextAdapter({ ...config, apiKey }, model)\n}\n"],"mappings":";;;;;;;;;;AA4BA,IAAa,qBAAb,cAcU,qCAMR;CACA,OAAyB;CACzB,OAAyB;CAEzB,YAAY,QAA2B,OAAe;EAEpD,MACE,OACA,WACA,IAAI,OAAO,oBAAoB,QAAQ,KAAA,GAAW,KAAK,CAAC,CAC1D;CACF;;;;;;CAOA,iBACE,OAC8B;EAC9B,OAAO,mBAAmB,KAAK;CACjC;AACF;;AAGA,SAAS,mBAAmB,OAA8C;CACxE,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,aAAa,QAChE,OAAO,KAAA;CACT,IAAI,CAAC,MAAM,QAAQ,MAAM,OAAO,GAAG,OAAO,KAAA;CAC1C,MAAM,SAAkB,MAAM,QAAQ;CACtC,IAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,EAAE,WAAW,SAChE,OAAO,KAAA;CACT,MAAM,QAAQ,OAAO;CACrB,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,KAAA;CACxD,MAAM,MACJ,eAAe,SAAS,OAAO,MAAM,cAAc,WAC/C,MAAM,YACN,uBAAuB,SACrB,OAAO,MAAM,sBAAsB,WACnC,MAAM,oBACN,KAAA;CACR,OAAO,OAAO,IAAI,SAAS,IAAI,EAAE,MAAM,IAAI,IAAI,KAAA;AACjD;;AAGA,SAAgB,kBACd,OACA,QACA,QAC4B;CAC5B,OAAO,IAAI,mBAAmB;EAAE,GAAG;EAAQ;CAAO,GAAG,KAAK;AAC5D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bedrock API compatibility config. First matching `match` substring wins.
|
|
3
|
+
* Transcribed from:
|
|
4
|
+
* https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html
|
|
5
|
+
* mantlePath is transcribed from each model card's Programmatic Access URL
|
|
6
|
+
* (default /v1). Put more specific matches first.
|
|
7
|
+
*
|
|
8
|
+
* `models` lists ids the AWS ListFoundationModels call does not return so
|
|
9
|
+
* `scripts/fetch-bedrock-models.ts` can still emit them.
|
|
10
|
+
*/
|
|
11
|
+
export type BedrockMantlePath = '/v1' | '/openai/v1';
|
|
12
|
+
export interface BedrockSeedModel {
|
|
13
|
+
id: string;
|
|
14
|
+
input: ReadonlyArray<string>;
|
|
15
|
+
}
|
|
16
|
+
export interface BedrockCompatibilityRule {
|
|
17
|
+
match: string;
|
|
18
|
+
converse: boolean;
|
|
19
|
+
chat: boolean;
|
|
20
|
+
responses: boolean;
|
|
21
|
+
mantlePath?: BedrockMantlePath;
|
|
22
|
+
models?: ReadonlyArray<BedrockSeedModel>;
|
|
23
|
+
}
|
|
24
|
+
export interface BedrockCompatibility {
|
|
25
|
+
converse: boolean;
|
|
26
|
+
chat: boolean;
|
|
27
|
+
responses: boolean;
|
|
28
|
+
mantlePath: BedrockMantlePath;
|
|
29
|
+
}
|
|
30
|
+
export declare const BEDROCK_API_COMPATIBILITY: ReadonlyArray<BedrockCompatibilityRule>;
|
|
31
|
+
export declare function lookupBedrockCompatibility(id: string): BedrockCompatibility;
|
|
32
|
+
/** Mantle OpenAI path from the compatibility config. Unknown ids stay on `/v1`. */
|
|
33
|
+
export declare function mantlePathForModel(model: string | undefined): BedrockMantlePath;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
//#region src/api-compatibility.ts
|
|
2
|
+
var BEDROCK_API_COMPATIBILITY = [
|
|
3
|
+
{
|
|
4
|
+
match: "openai.gpt-oss",
|
|
5
|
+
converse: true,
|
|
6
|
+
chat: true,
|
|
7
|
+
responses: true
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
match: "anthropic.claude",
|
|
11
|
+
converse: true,
|
|
12
|
+
chat: false,
|
|
13
|
+
responses: false
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
match: "amazon.nova",
|
|
17
|
+
converse: true,
|
|
18
|
+
chat: false,
|
|
19
|
+
responses: false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
match: "meta.llama",
|
|
23
|
+
converse: true,
|
|
24
|
+
chat: false,
|
|
25
|
+
responses: false
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
match: "ai21.jamba",
|
|
29
|
+
converse: true,
|
|
30
|
+
chat: false,
|
|
31
|
+
responses: false
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
match: "cohere.command",
|
|
35
|
+
converse: true,
|
|
36
|
+
chat: false,
|
|
37
|
+
responses: false
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
match: "deepseek.r1",
|
|
41
|
+
converse: true,
|
|
42
|
+
chat: false,
|
|
43
|
+
responses: false
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
match: "deepseek",
|
|
47
|
+
converse: true,
|
|
48
|
+
chat: true,
|
|
49
|
+
responses: false
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
match: "mistral.pixtral",
|
|
53
|
+
converse: true,
|
|
54
|
+
chat: false,
|
|
55
|
+
responses: false
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
match: "mistral",
|
|
59
|
+
converse: true,
|
|
60
|
+
chat: true,
|
|
61
|
+
responses: false
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
match: "qwen",
|
|
65
|
+
converse: true,
|
|
66
|
+
chat: true,
|
|
67
|
+
responses: false
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
match: "google.gemma-4-",
|
|
71
|
+
converse: false,
|
|
72
|
+
chat: true,
|
|
73
|
+
responses: true,
|
|
74
|
+
mantlePath: "/openai/v1",
|
|
75
|
+
models: [
|
|
76
|
+
{
|
|
77
|
+
id: "google.gemma-4-31b",
|
|
78
|
+
input: ["text", "image"]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "google.gemma-4-26b-a4b",
|
|
82
|
+
input: ["text", "image"]
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: "google.gemma-4-e2b",
|
|
86
|
+
input: ["text", "image"]
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
match: "google.gemma",
|
|
92
|
+
converse: true,
|
|
93
|
+
chat: true,
|
|
94
|
+
responses: false,
|
|
95
|
+
mantlePath: "/v1"
|
|
96
|
+
}
|
|
97
|
+
];
|
|
98
|
+
var DEFAULT_COMPAT = {
|
|
99
|
+
converse: true,
|
|
100
|
+
chat: false,
|
|
101
|
+
responses: false,
|
|
102
|
+
mantlePath: "/v1"
|
|
103
|
+
};
|
|
104
|
+
function lookupBedrockCompatibility(id) {
|
|
105
|
+
for (const rule of BEDROCK_API_COMPATIBILITY) if (id.includes(rule.match)) return {
|
|
106
|
+
converse: rule.converse,
|
|
107
|
+
chat: rule.chat,
|
|
108
|
+
responses: rule.responses,
|
|
109
|
+
mantlePath: rule.mantlePath ?? "/v1"
|
|
110
|
+
};
|
|
111
|
+
return DEFAULT_COMPAT;
|
|
112
|
+
}
|
|
113
|
+
/** Mantle OpenAI path from the compatibility config. Unknown ids stay on `/v1`. */
|
|
114
|
+
function mantlePathForModel(model) {
|
|
115
|
+
if (typeof model !== "string") return "/v1";
|
|
116
|
+
return lookupBedrockCompatibility(model).mantlePath;
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
export { BEDROCK_API_COMPATIBILITY, lookupBedrockCompatibility, mantlePathForModel };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=api-compatibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-compatibility.js","names":[],"sources":["../../src/api-compatibility.ts"],"sourcesContent":["/**\n * Bedrock API compatibility config. First matching `match` substring wins.\n * Transcribed from:\n * https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html\n * mantlePath is transcribed from each model card's Programmatic Access URL\n * (default /v1). Put more specific matches first.\n *\n * `models` lists ids the AWS ListFoundationModels call does not return so\n * `scripts/fetch-bedrock-models.ts` can still emit them.\n */\nexport type BedrockMantlePath = '/v1' | '/openai/v1'\n\nexport interface BedrockSeedModel {\n id: string\n input: ReadonlyArray<string>\n}\n\nexport interface BedrockCompatibilityRule {\n match: string\n converse: boolean\n chat: boolean\n responses: boolean\n mantlePath?: BedrockMantlePath\n models?: ReadonlyArray<BedrockSeedModel>\n}\n\nexport interface BedrockCompatibility {\n converse: boolean\n chat: boolean\n responses: boolean\n mantlePath: BedrockMantlePath\n}\n\nexport const BEDROCK_API_COMPATIBILITY: ReadonlyArray<BedrockCompatibilityRule> =\n [\n { match: 'openai.gpt-oss', converse: true, chat: true, responses: true },\n {\n match: 'anthropic.claude',\n converse: true,\n chat: false,\n responses: false,\n },\n { match: 'amazon.nova', converse: true, chat: false, responses: false },\n { match: 'meta.llama', converse: true, chat: false, responses: false },\n { match: 'ai21.jamba', converse: true, chat: false, responses: false },\n { match: 'cohere.command', converse: true, chat: false, responses: false },\n { match: 'deepseek.r1', converse: true, chat: false, responses: false },\n { match: 'deepseek', converse: true, chat: true, responses: false },\n {\n match: 'mistral.pixtral',\n converse: true,\n chat: false,\n responses: false,\n },\n { match: 'mistral', converse: true, chat: true, responses: false },\n { match: 'qwen', converse: true, chat: true, responses: false },\n {\n match: 'google.gemma-4-',\n converse: false,\n chat: true,\n responses: true,\n mantlePath: '/openai/v1',\n models: [\n { id: 'google.gemma-4-31b', input: ['text', 'image'] },\n { id: 'google.gemma-4-26b-a4b', input: ['text', 'image'] },\n { id: 'google.gemma-4-e2b', input: ['text', 'image'] },\n ],\n },\n {\n match: 'google.gemma',\n converse: true,\n chat: true,\n responses: false,\n mantlePath: '/v1',\n },\n ]\n\nconst DEFAULT_COMPAT: BedrockCompatibility = {\n converse: true,\n chat: false,\n responses: false,\n mantlePath: '/v1',\n}\n\nexport function lookupBedrockCompatibility(id: string): BedrockCompatibility {\n for (const rule of BEDROCK_API_COMPATIBILITY) {\n if (id.includes(rule.match)) {\n return {\n converse: rule.converse,\n chat: rule.chat,\n responses: rule.responses,\n mantlePath: rule.mantlePath ?? '/v1',\n }\n }\n }\n return DEFAULT_COMPAT\n}\n\n/** Mantle OpenAI path from the compatibility config. Unknown ids stay on `/v1`. */\nexport function mantlePathForModel(\n model: string | undefined,\n): BedrockMantlePath {\n if (typeof model !== 'string') return '/v1'\n return lookupBedrockCompatibility(model).mantlePath\n}\n"],"mappings":";AAiCA,IAAa,4BACX;CACE;EAAE,OAAO;EAAkB,UAAU;EAAM,MAAM;EAAM,WAAW;CAAK;CACvE;EACE,OAAO;EACP,UAAU;EACV,MAAM;EACN,WAAW;CACb;CACA;EAAE,OAAO;EAAe,UAAU;EAAM,MAAM;EAAO,WAAW;CAAM;CACtE;EAAE,OAAO;EAAc,UAAU;EAAM,MAAM;EAAO,WAAW;CAAM;CACrE;EAAE,OAAO;EAAc,UAAU;EAAM,MAAM;EAAO,WAAW;CAAM;CACrE;EAAE,OAAO;EAAkB,UAAU;EAAM,MAAM;EAAO,WAAW;CAAM;CACzE;EAAE,OAAO;EAAe,UAAU;EAAM,MAAM;EAAO,WAAW;CAAM;CACtE;EAAE,OAAO;EAAY,UAAU;EAAM,MAAM;EAAM,WAAW;CAAM;CAClE;EACE,OAAO;EACP,UAAU;EACV,MAAM;EACN,WAAW;CACb;CACA;EAAE,OAAO;EAAW,UAAU;EAAM,MAAM;EAAM,WAAW;CAAM;CACjE;EAAE,OAAO;EAAQ,UAAU;EAAM,MAAM;EAAM,WAAW;CAAM;CAC9D;EACE,OAAO;EACP,UAAU;EACV,MAAM;EACN,WAAW;EACX,YAAY;EACZ,QAAQ;GACN;IAAE,IAAI;IAAsB,OAAO,CAAC,QAAQ,OAAO;GAAE;GACrD;IAAE,IAAI;IAA0B,OAAO,CAAC,QAAQ,OAAO;GAAE;GACzD;IAAE,IAAI;IAAsB,OAAO,CAAC,QAAQ,OAAO;GAAE;EACvD;CACF;CACA;EACE,OAAO;EACP,UAAU;EACV,MAAM;EACN,WAAW;EACX,YAAY;CACd;AACF;AAEF,IAAM,iBAAuC;CAC3C,UAAU;CACV,MAAM;CACN,WAAW;CACX,YAAY;AACd;AAEA,SAAgB,2BAA2B,IAAkC;CAC3E,KAAK,MAAM,QAAQ,2BACjB,IAAI,GAAG,SAAS,KAAK,KAAK,GACxB,OAAO;EACL,UAAU,KAAK;EACf,MAAM,KAAK;EACX,WAAW,KAAK;EAChB,YAAY,KAAK,cAAc;CACjC;CAGJ,OAAO;AACT;;AAGA,SAAgB,mBACd,OACmB;CACnB,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,OAAO,2BAA2B,KAAK,CAAC,CAAC;AAC3C"}
|
package/dist/esm/index.js
CHANGED
|
@@ -22,6 +22,10 @@ function isResponsesModel(model) {
|
|
|
22
22
|
function isChatModel(model) {
|
|
23
23
|
return BEDROCK_CHAT_MODELS.some((m) => m === model);
|
|
24
24
|
}
|
|
25
|
+
/** Cast-free runtime guard: is this model in the Converse-capable subset? */
|
|
26
|
+
function isConverseModel(model) {
|
|
27
|
+
return BEDROCK_CONVERSE_MODELS.some((m) => m === model);
|
|
28
|
+
}
|
|
25
29
|
/** Strip the `api` discriminator from a config without an unused-var lint error. */
|
|
26
30
|
function stripApi(config) {
|
|
27
31
|
const { api, ...rest } = config;
|
|
@@ -45,6 +49,7 @@ function build(model, config) {
|
|
|
45
49
|
if (!isChatModel(model)) throw new Error(`Model "${model}" is not available on the Bedrock Chat Completions API. Chat-capable models: ${BEDROCK_CHAT_MODELS.join(", ")}.`);
|
|
46
50
|
return new BedrockTextAdapter(stripApi(config), model);
|
|
47
51
|
}
|
|
52
|
+
if (!isConverseModel(model)) throw new Error(`Model "${model}" is not available on the Bedrock Converse API. Converse-capable models: ${BEDROCK_CONVERSE_MODELS.join(", ")}.`);
|
|
48
53
|
return new BedrockConverseTextAdapter(config ? stripApi(config) : {}, model);
|
|
49
54
|
}
|
|
50
55
|
function createBedrockText(model, apiKey, config) {
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/**\n * @module @tanstack/ai-bedrock\n *\n * Amazon Bedrock adapter for TanStack AI via Bedrock's OpenAI-compatible APIs\n * and the native Converse API. The public `bedrockText` / `createBedrockText`\n * factory branches between the Converse adapter (DEFAULT), the Chat Completions\n * adapter (`api: 'chat'`), and the Responses adapter (`api: 'responses'`).\n */\n\nimport { BedrockTextAdapter } from './adapters/text'\nimport { BedrockResponsesTextAdapter } from './adapters/responses-text'\nimport { BedrockConverseTextAdapter } from './adapters/converse-text'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/**\n * @module @tanstack/ai-bedrock\n *\n * Amazon Bedrock adapter for TanStack AI via Bedrock's OpenAI-compatible APIs\n * and the native Converse API. The public `bedrockText` / `createBedrockText`\n * factory branches between the Converse adapter (DEFAULT), the Chat Completions\n * adapter (`api: 'chat'`), and the Responses adapter (`api: 'responses'`).\n */\n\nimport { BedrockTextAdapter } from './adapters/text'\nimport { BedrockResponsesTextAdapter } from './adapters/responses-text'\nimport { BedrockConverseTextAdapter } from './adapters/converse-text'\nimport {\n BEDROCK_CHAT_MODELS,\n BEDROCK_CONVERSE_MODELS,\n BEDROCK_RESPONSES_MODELS,\n} from './model-meta'\nimport type { BedrockTextConfig } from './adapters/text'\nimport type { BedrockResponsesConfig } from './adapters/responses-text'\nimport type { BedrockConverseConfig } from './adapters/converse-text'\nimport type { BedrockClientConfig } from './utils/client'\nimport type {\n BedrockChatModels,\n BedrockConverseModels,\n BedrockResponsesModels,\n} from './model-meta'\n\n/** Config for the branching factory's converse mode (default, or api: 'converse'). */\nexport type BedrockConverseApiConfig = BedrockConverseConfig & {\n api?: 'converse'\n}\n/** Config for the branching factory's chat mode (api: 'chat' required). */\nexport type BedrockChatApiConfig = BedrockTextConfig & {\n api: 'chat'\n}\n/** Config for the branching factory's responses mode (api: 'responses' required). */\nexport type BedrockResponsesApiConfig = BedrockResponsesConfig & {\n api: 'responses'\n}\n\ntype AnyBedrockAdapter =\n | BedrockConverseTextAdapter<BedrockConverseModels>\n | BedrockTextAdapter<BedrockChatModels>\n | BedrockResponsesTextAdapter<BedrockResponsesModels>\n\n/** Any catalog id the branching factory can receive. */\ntype BedrockFactoryModel =\n | BedrockConverseModels\n | BedrockChatModels\n | BedrockResponsesModels\n\n/** Cast-free runtime guard: is this model in the Responses-capable subset? */\nfunction isResponsesModel(model: string): model is BedrockResponsesModels {\n return BEDROCK_RESPONSES_MODELS.some((m) => m === model)\n}\n\n/** Cast-free runtime guard: is this model in the Chat-capable subset? */\nfunction isChatModel(model: string): model is BedrockChatModels {\n return BEDROCK_CHAT_MODELS.some((m) => m === model)\n}\n\n/** Cast-free runtime guard: is this model in the Converse-capable subset? */\nfunction isConverseModel(model: string): model is BedrockConverseModels {\n return BEDROCK_CONVERSE_MODELS.some((m) => m === model)\n}\n\n/** Strip the `api` discriminator from a config without an unused-var lint error. */\nfunction stripApi<T extends { api?: unknown }>(config: T): Omit<T, 'api'> {\n const { api, ...rest } = config\n void api\n return rest\n}\n\n/**\n * Shared branching used by both public factories. Constructs the adapter\n * classes directly so their constructors run the full auth cascade lazily\n * (config.apiKey → BEDROCK_API_KEY → AWS_BEARER_TOKEN_BEDROCK → SigV4). No\n * eager env-key fetch here, so `auth: 'sigv4'` never throws for a missing key.\n *\n * Default path → Converse adapter; opt-in via `api: 'chat'` or `api: 'responses'`.\n */\nfunction build(\n model: BedrockFactoryModel,\n config?: BedrockClientConfig & { api?: 'converse' | 'chat' | 'responses' },\n): AnyBedrockAdapter {\n if (config?.api === 'responses') {\n const rest = stripApi(config)\n if (!isResponsesModel(model)) {\n throw new Error(\n `Model \"${model}\" is not available on the Bedrock Responses API. ` +\n `Responses-capable models: ${BEDROCK_RESPONSES_MODELS.join(', ')}.`,\n )\n }\n return new BedrockResponsesTextAdapter(rest, model)\n }\n if (config?.api === 'chat') {\n if (!isChatModel(model)) {\n throw new Error(\n `Model \"${model}\" is not available on the Bedrock Chat Completions API. ` +\n `Chat-capable models: ${BEDROCK_CHAT_MODELS.join(', ')}.`,\n )\n }\n return new BedrockTextAdapter(stripApi(config), model)\n }\n if (!isConverseModel(model)) {\n throw new Error(\n `Model \"${model}\" is not available on the Bedrock Converse API. ` +\n `Converse-capable models: ${BEDROCK_CONVERSE_MODELS.join(', ')}.`,\n )\n }\n return new BedrockConverseTextAdapter(config ? stripApi(config) : {}, model)\n}\n\n// --- createBedrockText: explicit key, overloaded on `api` ---\nexport function createBedrockText<TModel extends BedrockConverseModels>(\n model: TModel,\n apiKey: string,\n config?: BedrockConverseApiConfig,\n): BedrockConverseTextAdapter<TModel>\nexport function createBedrockText<TModel extends BedrockChatModels>(\n model: TModel,\n apiKey: string,\n config: BedrockChatApiConfig,\n): BedrockTextAdapter<TModel>\nexport function createBedrockText<TModel extends BedrockResponsesModels>(\n model: TModel,\n apiKey: string,\n config: BedrockResponsesApiConfig,\n): BedrockResponsesTextAdapter<TModel>\nexport function createBedrockText(\n model: BedrockFactoryModel,\n apiKey: string,\n config?:\n | BedrockConverseApiConfig\n | BedrockChatApiConfig\n | BedrockResponsesApiConfig,\n): AnyBedrockAdapter {\n // Explicit apiKey is authoritative — spread config first so it can't override.\n return build(model, { ...config, apiKey })\n}\n\n// --- bedrockText: env-key counterpart, same overloads ---\nexport function bedrockText<TModel extends BedrockConverseModels>(\n model: TModel,\n config?: BedrockConverseApiConfig,\n): BedrockConverseTextAdapter<TModel>\nexport function bedrockText<TModel extends BedrockChatModels>(\n model: TModel,\n config: BedrockChatApiConfig,\n): BedrockTextAdapter<TModel>\nexport function bedrockText<TModel extends BedrockResponsesModels>(\n model: TModel,\n config: BedrockResponsesApiConfig,\n): BedrockResponsesTextAdapter<TModel>\nexport function bedrockText(\n model: BedrockFactoryModel,\n config?:\n | BedrockConverseApiConfig\n | BedrockChatApiConfig\n | BedrockResponsesApiConfig,\n): AnyBedrockAdapter {\n // No eager env-key fetch: the adapter constructor resolves auth lazily so\n // SigV4 (and the env-key fallback) work without a forced API key here.\n return build(model, config)\n}\n\n// --- Re-exports ---\nexport {\n BedrockTextAdapter,\n createBedrockChat,\n type BedrockTextConfig,\n type BedrockTextProviderOptions,\n} from './adapters/text'\nexport {\n BedrockResponsesTextAdapter,\n createBedrockResponsesText,\n type BedrockResponsesConfig,\n type BedrockResponsesProviderOptions,\n} from './adapters/responses-text'\nexport {\n BedrockConverseTextAdapter,\n createBedrockConverse,\n type BedrockConverseConfig,\n} from './adapters/converse-text'\nexport {\n BedrockEmbeddingAdapter,\n bedrockEmbedding,\n createBedrockEmbedding,\n type BedrockEmbeddingConfig,\n} from './adapters/embedding'\nexport type {\n BedrockCohereEmbeddingInputType,\n BedrockCohereEmbeddingProviderOptions,\n BedrockEmbeddingProviderOptions,\n BedrockTitanImageEmbeddingProviderOptions,\n BedrockTitanTextEmbeddingProviderOptions,\n} from './embedding/embedding-provider-options'\nexport type { BedrockConverseProviderOptions } from './converse/provider-options'\nexport {\n resolveBedrockAuth,\n withBedrockDefaults,\n type BedrockClientConfig,\n type BedrockEndpoint,\n type ResolvedBedrockAuth,\n} from './utils/client'\nexport {\n BEDROCK_CHAT_MODELS,\n BEDROCK_RESPONSES_MODELS,\n BEDROCK_CONVERSE_MODELS,\n BEDROCK_EMBEDDING_MODELS,\n type BedrockEmbeddingModel,\n type BedrockEmbeddingModelProviderOptionsByName,\n type BedrockEmbeddingModelInputModalitiesByName,\n type BedrockChatModels,\n type BedrockResponsesModels,\n type BedrockConverseModels,\n type BedrockChatModelProviderOptionsByName,\n type BedrockChatModelToolCapabilitiesByName,\n type BedrockModelInputModalitiesByName,\n} from './model-meta'\nexport type {\n BedrockMessageMetadataByModality,\n BedrockTextMetadata,\n BedrockImageMetadata,\n BedrockAudioMetadata,\n BedrockVideoMetadata,\n BedrockDocumentMetadata,\n} from './message-types'\n"],"mappings":";;;;;;;;;;;;;;;;;AAoDA,SAAS,iBAAiB,OAAgD;CACxE,OAAO,yBAAyB,MAAM,MAAM,MAAM,KAAK;AACzD;;AAGA,SAAS,YAAY,OAA2C;CAC9D,OAAO,oBAAoB,MAAM,MAAM,MAAM,KAAK;AACpD;;AAGA,SAAS,gBAAgB,OAA+C;CACtE,OAAO,wBAAwB,MAAM,MAAM,MAAM,KAAK;AACxD;;AAGA,SAAS,SAAsC,QAA2B;CACxE,MAAM,EAAE,KAAK,GAAG,SAAS;CAEzB,OAAO;AACT;;;;;;;;;AAUA,SAAS,MACP,OACA,QACmB;CACnB,IAAI,QAAQ,QAAQ,aAAa;EAC/B,MAAM,OAAO,SAAS,MAAM;EAC5B,IAAI,CAAC,iBAAiB,KAAK,GACzB,MAAM,IAAI,MACR,UAAU,MAAM,6EACe,yBAAyB,KAAK,IAAI,EAAE,EACrE;EAEF,OAAO,IAAI,4BAA4B,MAAM,KAAK;CACpD;CACA,IAAI,QAAQ,QAAQ,QAAQ;EAC1B,IAAI,CAAC,YAAY,KAAK,GACpB,MAAM,IAAI,MACR,UAAU,MAAM,+EACU,oBAAoB,KAAK,IAAI,EAAE,EAC3D;EAEF,OAAO,IAAI,mBAAmB,SAAS,MAAM,GAAG,KAAK;CACvD;CACA,IAAI,CAAC,gBAAgB,KAAK,GACxB,MAAM,IAAI,MACR,UAAU,MAAM,2EACc,wBAAwB,KAAK,IAAI,EAAE,EACnE;CAEF,OAAO,IAAI,2BAA2B,SAAS,SAAS,MAAM,IAAI,CAAC,GAAG,KAAK;AAC7E;AAkBA,SAAgB,kBACd,OACA,QACA,QAImB;CAEnB,OAAO,MAAM,OAAO;EAAE,GAAG;EAAQ;CAAO,CAAC;AAC3C;AAeA,SAAgB,YACd,OACA,QAImB;CAGnB,OAAO,MAAM,OAAO,MAAM;AAC5B"}
|
|
@@ -124,4 +124,31 @@ export declare const GENERATED_BEDROCK_MODELS: readonly [{
|
|
|
124
124
|
readonly chat: false;
|
|
125
125
|
readonly responses: false;
|
|
126
126
|
};
|
|
127
|
+
}, {
|
|
128
|
+
readonly id: "google.gemma-4-31b";
|
|
129
|
+
readonly input: readonly ["text", "image"];
|
|
130
|
+
readonly output: readonly ["text"];
|
|
131
|
+
readonly apis: {
|
|
132
|
+
readonly converse: false;
|
|
133
|
+
readonly chat: true;
|
|
134
|
+
readonly responses: true;
|
|
135
|
+
};
|
|
136
|
+
}, {
|
|
137
|
+
readonly id: "google.gemma-4-26b-a4b";
|
|
138
|
+
readonly input: readonly ["text", "image"];
|
|
139
|
+
readonly output: readonly ["text"];
|
|
140
|
+
readonly apis: {
|
|
141
|
+
readonly converse: false;
|
|
142
|
+
readonly chat: true;
|
|
143
|
+
readonly responses: true;
|
|
144
|
+
};
|
|
145
|
+
}, {
|
|
146
|
+
readonly id: "google.gemma-4-e2b";
|
|
147
|
+
readonly input: readonly ["text", "image"];
|
|
148
|
+
readonly output: readonly ["text"];
|
|
149
|
+
readonly apis: {
|
|
150
|
+
readonly converse: false;
|
|
151
|
+
readonly chat: true;
|
|
152
|
+
readonly responses: true;
|
|
153
|
+
};
|
|
127
154
|
}];
|
|
@@ -163,6 +163,36 @@ var GENERATED_BEDROCK_MODELS = [
|
|
|
163
163
|
chat: false,
|
|
164
164
|
responses: false
|
|
165
165
|
}
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
id: "google.gemma-4-31b",
|
|
169
|
+
input: ["text", "image"],
|
|
170
|
+
output: ["text"],
|
|
171
|
+
apis: {
|
|
172
|
+
converse: false,
|
|
173
|
+
chat: true,
|
|
174
|
+
responses: true
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
id: "google.gemma-4-26b-a4b",
|
|
179
|
+
input: ["text", "image"],
|
|
180
|
+
output: ["text"],
|
|
181
|
+
apis: {
|
|
182
|
+
converse: false,
|
|
183
|
+
chat: true,
|
|
184
|
+
responses: true
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
id: "google.gemma-4-e2b",
|
|
189
|
+
input: ["text", "image"],
|
|
190
|
+
output: ["text"],
|
|
191
|
+
apis: {
|
|
192
|
+
converse: false,
|
|
193
|
+
chat: true,
|
|
194
|
+
responses: true
|
|
195
|
+
}
|
|
166
196
|
}
|
|
167
197
|
];
|
|
168
198
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-catalog.generated.js","names":[],"sources":["../../src/model-catalog.generated.ts"],"sourcesContent":["// GENERATED by scripts/fetch-bedrock-models.ts — do not edit by hand.\n// Refresh: AWS_REGION=us-east-1 pnpm tsx scripts/fetch-bedrock-models.ts\nexport const GENERATED_BEDROCK_MODELS = [\n {\n id: 'openai.gpt-oss-120b-1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: true, responses: true },\n },\n {\n id: 'openai.gpt-oss-20b-1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: true, responses: true },\n },\n {\n id: 'us.anthropic.claude-sonnet-4-5-20250929-v1:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.anthropic.claude-haiku-4-5-20251001-v1:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.anthropic.claude-3-7-sonnet-20250219-v1:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.anthropic.claude-3-5-sonnet-20241022-v2:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.anthropic.claude-3-5-haiku-20241022-v1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.amazon.nova-pro-v1:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.amazon.nova-lite-v1:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.amazon.nova-micro-v1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.meta.llama3-3-70b-instruct-v1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.meta.llama4-maverick-17b-instruct-v1:0',\n input: ['text', 'image'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.mistral.pixtral-large-2502-v1:0',\n input: ['text', 'image'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.deepseek.r1-v1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n] as const\n"],"mappings":";AAEA,IAAa,2BAA2B;CACtC;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAM,WAAW;EAAK;CACtD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAM,WAAW;EAAK;CACtD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,QAAQ,OAAO;EACvB,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,QAAQ,OAAO;EACvB,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;AACF"}
|
|
1
|
+
{"version":3,"file":"model-catalog.generated.js","names":[],"sources":["../../src/model-catalog.generated.ts"],"sourcesContent":["// GENERATED by scripts/fetch-bedrock-models.ts — do not edit by hand.\n// Refresh: AWS_REGION=us-east-1 pnpm tsx scripts/fetch-bedrock-models.ts\nexport const GENERATED_BEDROCK_MODELS = [\n {\n id: 'openai.gpt-oss-120b-1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: true, responses: true },\n },\n {\n id: 'openai.gpt-oss-20b-1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: true, responses: true },\n },\n {\n id: 'us.anthropic.claude-sonnet-4-5-20250929-v1:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.anthropic.claude-haiku-4-5-20251001-v1:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.anthropic.claude-3-7-sonnet-20250219-v1:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.anthropic.claude-3-5-sonnet-20241022-v2:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.anthropic.claude-3-5-haiku-20241022-v1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.amazon.nova-pro-v1:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.amazon.nova-lite-v1:0',\n input: ['text', 'image', 'document'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.amazon.nova-micro-v1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.meta.llama3-3-70b-instruct-v1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.meta.llama4-maverick-17b-instruct-v1:0',\n input: ['text', 'image'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.mistral.pixtral-large-2502-v1:0',\n input: ['text', 'image'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'us.deepseek.r1-v1:0',\n input: ['text'],\n output: ['text'],\n apis: { converse: true, chat: false, responses: false },\n },\n {\n id: 'google.gemma-4-31b',\n input: ['text', 'image'],\n output: ['text'],\n apis: { converse: false, chat: true, responses: true },\n },\n {\n id: 'google.gemma-4-26b-a4b',\n input: ['text', 'image'],\n output: ['text'],\n apis: { converse: false, chat: true, responses: true },\n },\n {\n id: 'google.gemma-4-e2b',\n input: ['text', 'image'],\n output: ['text'],\n apis: { converse: false, chat: true, responses: true },\n },\n] as const\n"],"mappings":";AAEA,IAAa,2BAA2B;CACtC;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAM,WAAW;EAAK;CACtD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAM,WAAW;EAAK;CACtD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,QAAQ,OAAO;EACvB,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,QAAQ,OAAO;EACvB,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAM,MAAM;GAAO,WAAW;EAAM;CACxD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,QAAQ,OAAO;EACvB,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAO,MAAM;GAAM,WAAW;EAAK;CACvD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,QAAQ,OAAO;EACvB,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAO,MAAM;GAAM,WAAW;EAAK;CACvD;CACA;EACE,IAAI;EACJ,OAAO,CAAC,QAAQ,OAAO;EACvB,QAAQ,CAAC,MAAM;EACf,MAAM;GAAE,UAAU;GAAO,MAAM;GAAM,WAAW;EAAK;CACvD;AACF"}
|
package/dist/esm/model-meta.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GENERATED_BEDROCK_MODELS } from "./model-catalog.generated.js";
|
|
2
2
|
//#region src/model-meta.ts
|
|
3
3
|
/** Runtime catalogs. Cast-free narrowing via a type predicate (the ai-bedrock pattern). */
|
|
4
|
-
var BEDROCK_CONVERSE_MODELS = GENERATED_BEDROCK_MODELS.map((m) => m.id);
|
|
4
|
+
var BEDROCK_CONVERSE_MODELS = GENERATED_BEDROCK_MODELS.filter((m) => m.apis.converse).map((m) => m.id);
|
|
5
5
|
var BEDROCK_CHAT_MODELS = GENERATED_BEDROCK_MODELS.filter((m) => m.apis.chat).map((m) => m.id);
|
|
6
6
|
var BEDROCK_RESPONSES_MODELS = GENERATED_BEDROCK_MODELS.filter((m) => m.apis.responses).map((m) => m.id);
|
|
7
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-meta.js","names":[],"sources":["../../src/model-meta.ts"],"sourcesContent":["import { GENERATED_BEDROCK_MODELS } from './model-catalog.generated.js'\nimport type { BedrockTextProviderOptions } from './text/text-provider-options'\nimport type { BedrockConverseProviderOptions } from './converse/provider-options'\nimport type {\n BedrockCohereEmbeddingProviderOptions,\n BedrockEmbeddingProviderOptions,\n BedrockTitanImageEmbeddingProviderOptions,\n BedrockTitanTextEmbeddingProviderOptions,\n} from './embedding/embedding-provider-options'\n\ntype Entry = (typeof GENERATED_BEDROCK_MODELS)[number]\n\n/**\n * Type-level per-API filter over the generated catalog. Because the catalog is\n * `as const`, `Extract` preserves literal `id` unions (no widening to `string`).\n */\ntype IdsWhere<TApi extends 'converse' | 'chat' | 'responses'> = Extract<\n Entry,\n { apis: Record<TApi, true> }\n>['id']\n\nexport type BedrockConverseModels = IdsWhere<'converse'>\nexport type BedrockChatModels = IdsWhere<'chat'>\nexport type BedrockResponsesModels = IdsWhere<'responses'>\n\n/** Runtime catalogs. Cast-free narrowing via a type predicate (the ai-bedrock pattern). */\
|
|
1
|
+
{"version":3,"file":"model-meta.js","names":[],"sources":["../../src/model-meta.ts"],"sourcesContent":["import { GENERATED_BEDROCK_MODELS } from './model-catalog.generated.js'\nimport type { BedrockTextProviderOptions } from './text/text-provider-options'\nimport type { BedrockConverseProviderOptions } from './converse/provider-options'\nimport type {\n BedrockCohereEmbeddingProviderOptions,\n BedrockEmbeddingProviderOptions,\n BedrockTitanImageEmbeddingProviderOptions,\n BedrockTitanTextEmbeddingProviderOptions,\n} from './embedding/embedding-provider-options'\n\ntype Entry = (typeof GENERATED_BEDROCK_MODELS)[number]\n\n/**\n * Type-level per-API filter over the generated catalog. Because the catalog is\n * `as const`, `Extract` preserves literal `id` unions (no widening to `string`).\n */\ntype IdsWhere<TApi extends 'converse' | 'chat' | 'responses'> = Extract<\n Entry,\n { apis: Record<TApi, true> }\n>['id']\n\nexport type BedrockConverseModels = IdsWhere<'converse'>\nexport type BedrockChatModels = IdsWhere<'chat'>\nexport type BedrockResponsesModels = IdsWhere<'responses'>\n\n/** Runtime catalogs. Cast-free narrowing via a type predicate (the ai-bedrock pattern). */\nexport const BEDROCK_CONVERSE_MODELS: ReadonlyArray<BedrockConverseModels> =\n GENERATED_BEDROCK_MODELS.filter(\n (m): m is Extract<Entry, { apis: { converse: true } }> => m.apis.converse,\n ).map((m) => m.id)\n\nexport const BEDROCK_CHAT_MODELS: ReadonlyArray<BedrockChatModels> =\n GENERATED_BEDROCK_MODELS.filter(\n (m): m is Extract<Entry, { apis: { chat: true } }> => m.apis.chat,\n ).map((m) => m.id)\n\nexport const BEDROCK_RESPONSES_MODELS: ReadonlyArray<BedrockResponsesModels> =\n GENERATED_BEDROCK_MODELS.filter(\n (m): m is Extract<Entry, { apis: { responses: true } }> => m.apis.responses,\n ).map((m) => m.id)\n\n/** Per-model input modalities (drives type-safe multimodal content). Covers ALL models. */\nexport type BedrockModelInputModalitiesByName = {\n [E in Entry as E['id']]: E['input']\n}\n\n/** Provider options per model. Same options for every model; keyed over the full catalog. */\nexport type BedrockChatModelProviderOptionsByName = {\n [E in Entry as E['id']]: BedrockTextProviderOptions\n}\n\n/** Converse provider options per model (narrower than the Chat Completions set). */\nexport type BedrockConverseModelProviderOptionsByName = {\n [E in Entry as E['id']]: BedrockConverseProviderOptions\n}\n\n/** No provider-specific tools — empty tuple makes cross-provider ProviderTool a compile error. */\nexport type BedrockChatModelToolCapabilitiesByName = {\n [E in Entry as E['id']]: readonly []\n}\n\nexport type ResolveProviderOptions<TModel extends string> =\n TModel extends keyof BedrockChatModelProviderOptionsByName\n ? BedrockChatModelProviderOptionsByName[TModel]\n : BedrockTextProviderOptions\n\nexport type ResolveConverseProviderOptions<TModel extends string> =\n TModel extends keyof BedrockConverseModelProviderOptionsByName\n ? BedrockConverseModelProviderOptionsByName[TModel]\n : BedrockConverseProviderOptions\n\nexport type ResolveInputModalities<TModel extends string> =\n TModel extends keyof BedrockModelInputModalitiesByName\n ? BedrockModelInputModalitiesByName[TModel]\n : readonly ['text']\n\n// ============================================================================\n// Embedding models\n// ============================================================================\n\n/**\n * Embedding models reachable through Bedrock's `InvokeModel` API. These are\n * not part of the generated Converse catalog (embedding models have no\n * conversational surface), so they're maintained by hand here.\n */\nexport const BEDROCK_EMBEDDING_MODELS = [\n 'amazon.titan-embed-text-v2:0',\n 'amazon.titan-embed-image-v1',\n 'cohere.embed-english-v3',\n 'cohere.embed-multilingual-v3',\n] as const\n\nexport type BedrockEmbeddingModel = (typeof BEDROCK_EMBEDDING_MODELS)[number]\n\n/**\n * Type-only map from embedding model name to its provider options type.\n * The Cohere models make `modelOptions` REQUIRED at the `embed()` call site\n * because `inputType` is a required field.\n */\nexport type BedrockEmbeddingModelProviderOptionsByName = {\n 'amazon.titan-embed-text-v2:0': BedrockTitanTextEmbeddingProviderOptions\n 'amazon.titan-embed-image-v1': BedrockTitanImageEmbeddingProviderOptions\n 'cohere.embed-english-v3': BedrockCohereEmbeddingProviderOptions\n 'cohere.embed-multilingual-v3': BedrockCohereEmbeddingProviderOptions\n}\n\n/**\n * Per-model input modalities for embedding models. Titan Multimodal accepts\n * text and/or images (including fused text+image items embedded into one\n * vector); the rest are text-only, so image inputs fail at compile time.\n */\nexport type BedrockEmbeddingModelInputModalitiesByName = {\n 'amazon.titan-embed-text-v2:0': readonly ['text']\n 'amazon.titan-embed-image-v1': readonly ['text', 'image']\n 'cohere.embed-english-v3': readonly ['text']\n 'cohere.embed-multilingual-v3': readonly ['text']\n}\n\nexport type ResolveEmbeddingProviderOptions<TModel extends string> =\n TModel extends keyof BedrockEmbeddingModelProviderOptionsByName\n ? BedrockEmbeddingModelProviderOptionsByName[TModel]\n : BedrockEmbeddingProviderOptions\n"],"mappings":";;;AA0BA,IAAa,0BACX,yBAAyB,QACtB,MAAyD,EAAE,KAAK,QACnE,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE;AAEnB,IAAa,sBACX,yBAAyB,QACtB,MAAqD,EAAE,KAAK,IAC/D,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE;AAEnB,IAAa,2BACX,yBAAyB,QACtB,MAA0D,EAAE,KAAK,SACpE,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE;;;;;;AA8CnB,IAAa,2BAA2B;CACtC;CACA;CACA;CACA;AACF"}
|
|
@@ -16,4 +16,4 @@ export interface BedrockClientConfig extends Omit<ClientOptions, 'apiKey' | 'bas
|
|
|
16
16
|
baseURL?: string;
|
|
17
17
|
}
|
|
18
18
|
/** Builds OpenAI ClientOptions for the requested endpoint. `forced` pins the endpoint (responses → 'mantle'). */
|
|
19
|
-
export declare function withBedrockDefaults(config: BedrockClientConfig, forced?: BedrockEndpoint): ClientOptions;
|
|
19
|
+
export declare function withBedrockDefaults(config: BedrockClientConfig, forced?: BedrockEndpoint, model?: string): ClientOptions;
|
package/dist/esm/utils/client.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { resolveBedrockAuth } from "./auth.js";
|
|
2
2
|
import { createSigV4Fetch } from "./openai-sigv4-fetch.js";
|
|
3
|
+
import { mantlePathForModel } from "../api-compatibility.js";
|
|
3
4
|
//#region src/utils/client.ts
|
|
4
5
|
var DEFAULT_REGION = "us-east-1";
|
|
5
6
|
/** OpenAI SDK requires a non-empty apiKey even when a signed fetch overrides Authorization. */
|
|
6
7
|
var SIGV4_PLACEHOLDER_KEY = "bedrock-sigv4";
|
|
7
|
-
function buildBaseURL(region, endpoint) {
|
|
8
|
-
return endpoint === "mantle" ? `https://bedrock-mantle.${region}.api.aws
|
|
8
|
+
function buildBaseURL(region, endpoint, model) {
|
|
9
|
+
return endpoint === "mantle" ? `https://bedrock-mantle.${region}.api.aws${mantlePathForModel(model)}` : `https://bedrock-runtime.${region}.amazonaws.com/openai/v1`;
|
|
9
10
|
}
|
|
10
11
|
/** Builds OpenAI ClientOptions for the requested endpoint. `forced` pins the endpoint (responses → 'mantle'). */
|
|
11
|
-
function withBedrockDefaults(config, forced) {
|
|
12
|
+
function withBedrockDefaults(config, forced, model) {
|
|
12
13
|
const { region, endpoint, auth, apiKey, baseURL, fetch, ...rest } = config;
|
|
13
14
|
const resolvedRegion = region ?? DEFAULT_REGION;
|
|
14
15
|
const resolvedEndpoint = forced ?? endpoint ?? "runtime";
|
|
@@ -17,15 +18,16 @@ function withBedrockDefaults(config, forced) {
|
|
|
17
18
|
region: resolvedRegion,
|
|
18
19
|
auth
|
|
19
20
|
}, resolvedEndpoint);
|
|
21
|
+
const resolvedBaseURL = baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint, model);
|
|
20
22
|
if (resolved.kind === "bearer") return {
|
|
21
23
|
...rest,
|
|
22
|
-
baseURL:
|
|
24
|
+
baseURL: resolvedBaseURL,
|
|
23
25
|
apiKey: resolved.token,
|
|
24
26
|
...fetch ? { fetch } : {}
|
|
25
27
|
};
|
|
26
28
|
return {
|
|
27
29
|
...rest,
|
|
28
|
-
baseURL:
|
|
30
|
+
baseURL: resolvedBaseURL,
|
|
29
31
|
apiKey: SIGV4_PLACEHOLDER_KEY,
|
|
30
32
|
fetch: fetch ?? createSigV4Fetch(resolved)
|
|
31
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":[],"sources":["../../../src/utils/client.ts"],"sourcesContent":["import { resolveBedrockAuth } from './auth'\nimport { createSigV4Fetch } from './openai-sigv4-fetch'\nimport type { ClientOptions } from 'openai'\nimport type { BedrockEndpoint } from './auth'\n\nexport type { BedrockEndpoint } from './auth'\nexport { resolveBedrockAuth } from './auth'\nexport type { ResolvedBedrockAuth } from './auth'\n\nexport interface BedrockClientConfig extends Omit<\n ClientOptions,\n 'apiKey' | 'baseURL'\n> {\n /** Bedrock API key (bearer). Optional — falls back to env, then SigV4. */\n apiKey?: string\n /** Full AWS region (e.g. 'us-east-1'). Default 'us-east-1'. */\n region?: string\n /** Chat adapter only; the responses adapter forces 'mantle'. Default 'runtime'. */\n endpoint?: BedrockEndpoint\n /** Auth strategy. Default 'auto' (apiKey → env → SigV4). */\n auth?: 'apikey' | 'sigv4' | 'auto'\n /** Explicit override; wins over the computed endpoint URL (used by E2E → aimock). */\n baseURL?: string\n}\n\nconst DEFAULT_REGION = 'us-east-1'\n/** OpenAI SDK requires a non-empty apiKey even when a signed fetch overrides Authorization. */\nconst SIGV4_PLACEHOLDER_KEY = 'bedrock-sigv4'\n\nfunction buildBaseURL(region: string
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../../src/utils/client.ts"],"sourcesContent":["import { resolveBedrockAuth } from './auth'\nimport { createSigV4Fetch } from './openai-sigv4-fetch'\nimport { mantlePathForModel } from '../api-compatibility'\nimport type { ClientOptions } from 'openai'\nimport type { BedrockEndpoint } from './auth'\n\nexport type { BedrockEndpoint } from './auth'\nexport { resolveBedrockAuth } from './auth'\nexport type { ResolvedBedrockAuth } from './auth'\n\nexport interface BedrockClientConfig extends Omit<\n ClientOptions,\n 'apiKey' | 'baseURL'\n> {\n /** Bedrock API key (bearer). Optional — falls back to env, then SigV4. */\n apiKey?: string\n /** Full AWS region (e.g. 'us-east-1'). Default 'us-east-1'. */\n region?: string\n /** Chat adapter only; the responses adapter forces 'mantle'. Default 'runtime'. */\n endpoint?: BedrockEndpoint\n /** Auth strategy. Default 'auto' (apiKey → env → SigV4). */\n auth?: 'apikey' | 'sigv4' | 'auto'\n /** Explicit override; wins over the computed endpoint URL (used by E2E → aimock). */\n baseURL?: string\n}\n\nconst DEFAULT_REGION = 'us-east-1'\n/** OpenAI SDK requires a non-empty apiKey even when a signed fetch overrides Authorization. */\nconst SIGV4_PLACEHOLDER_KEY = 'bedrock-sigv4'\n\nfunction buildBaseURL(\n region: string,\n endpoint: BedrockEndpoint,\n model?: string,\n): string {\n return endpoint === 'mantle'\n ? `https://bedrock-mantle.${region}.api.aws${mantlePathForModel(model)}`\n : `https://bedrock-runtime.${region}.amazonaws.com/openai/v1`\n}\n\n/** Builds OpenAI ClientOptions for the requested endpoint. `forced` pins the endpoint (responses → 'mantle'). */\nexport function withBedrockDefaults(\n config: BedrockClientConfig,\n forced?: BedrockEndpoint,\n model?: string,\n): ClientOptions {\n const { region, endpoint, auth, apiKey, baseURL, fetch, ...rest } = config\n const resolvedRegion = region ?? DEFAULT_REGION\n const resolvedEndpoint = forced ?? endpoint ?? 'runtime'\n const resolved = resolveBedrockAuth(\n { apiKey, region: resolvedRegion, auth },\n resolvedEndpoint,\n )\n const resolvedBaseURL =\n baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint, model)\n if (resolved.kind === 'bearer') {\n return {\n ...rest,\n baseURL: resolvedBaseURL,\n apiKey: resolved.token,\n ...(fetch ? { fetch } : {}),\n }\n }\n return {\n ...rest,\n baseURL: resolvedBaseURL,\n apiKey: SIGV4_PLACEHOLDER_KEY,\n fetch: fetch ?? createSigV4Fetch(resolved),\n }\n}\n"],"mappings":";;;;AA0BA,IAAM,iBAAiB;;AAEvB,IAAM,wBAAwB;AAE9B,SAAS,aACP,QACA,UACA,OACQ;CACR,OAAO,aAAa,WAChB,0BAA0B,OAAO,UAAU,mBAAmB,KAAK,MACnE,2BAA2B,OAAO;AACxC;;AAGA,SAAgB,oBACd,QACA,QACA,OACe;CACf,MAAM,EAAE,QAAQ,UAAU,MAAM,QAAQ,SAAS,OAAO,GAAG,SAAS;CACpE,MAAM,iBAAiB,UAAU;CACjC,MAAM,mBAAmB,UAAU,YAAY;CAC/C,MAAM,WAAW,mBACf;EAAE;EAAQ,QAAQ;EAAgB;CAAK,GACvC,gBACF;CACA,MAAM,kBACJ,WAAW,aAAa,gBAAgB,kBAAkB,KAAK;CACjE,IAAI,SAAS,SAAS,UACpB,OAAO;EACL,GAAG;EACH,SAAS;EACT,QAAQ,SAAS;EACjB,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;CAC3B;CAEF,OAAO;EACL,GAAG;EACH,SAAS;EACT,QAAQ;EACR,OAAO,SAAS,iBAAiB,QAAQ;CAC3C;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-bedrock",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Amazon Bedrock adapter for TanStack AI — OpenAI-compatible chat, responses, tools, and reasoning.",
|
|
6
6
|
"author": "",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"vite": "^8.2.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@tanstack/ai": "^0.
|
|
46
|
+
"@tanstack/ai": "^0.55.0"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@aws-crypto/sha256-js": "^5.2.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@smithy/signature-v4": "^5.4.5",
|
|
53
53
|
"@smithy/types": "^4.14.2",
|
|
54
54
|
"openai": "^6.41.0",
|
|
55
|
-
"@tanstack/openai-base": "^0.10.
|
|
55
|
+
"@tanstack/openai-base": "^0.10.12"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "vite build",
|
package/src/adapters/text.ts
CHANGED
|
@@ -52,7 +52,11 @@ export class BedrockTextAdapter<
|
|
|
52
52
|
|
|
53
53
|
constructor(config: BedrockTextConfig, model: TModel) {
|
|
54
54
|
// No `forced` -> honors config.endpoint ('runtime' default, 'mantle' allowed).
|
|
55
|
-
super(
|
|
55
|
+
super(
|
|
56
|
+
model,
|
|
57
|
+
'bedrock',
|
|
58
|
+
new OpenAI(withBedrockDefaults(config, undefined, model)),
|
|
59
|
+
)
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
/**
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bedrock API compatibility config. First matching `match` substring wins.
|
|
3
|
+
* Transcribed from:
|
|
4
|
+
* https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html
|
|
5
|
+
* mantlePath is transcribed from each model card's Programmatic Access URL
|
|
6
|
+
* (default /v1). Put more specific matches first.
|
|
7
|
+
*
|
|
8
|
+
* `models` lists ids the AWS ListFoundationModels call does not return so
|
|
9
|
+
* `scripts/fetch-bedrock-models.ts` can still emit them.
|
|
10
|
+
*/
|
|
11
|
+
export type BedrockMantlePath = '/v1' | '/openai/v1'
|
|
12
|
+
|
|
13
|
+
export interface BedrockSeedModel {
|
|
14
|
+
id: string
|
|
15
|
+
input: ReadonlyArray<string>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface BedrockCompatibilityRule {
|
|
19
|
+
match: string
|
|
20
|
+
converse: boolean
|
|
21
|
+
chat: boolean
|
|
22
|
+
responses: boolean
|
|
23
|
+
mantlePath?: BedrockMantlePath
|
|
24
|
+
models?: ReadonlyArray<BedrockSeedModel>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface BedrockCompatibility {
|
|
28
|
+
converse: boolean
|
|
29
|
+
chat: boolean
|
|
30
|
+
responses: boolean
|
|
31
|
+
mantlePath: BedrockMantlePath
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const BEDROCK_API_COMPATIBILITY: ReadonlyArray<BedrockCompatibilityRule> =
|
|
35
|
+
[
|
|
36
|
+
{ match: 'openai.gpt-oss', converse: true, chat: true, responses: true },
|
|
37
|
+
{
|
|
38
|
+
match: 'anthropic.claude',
|
|
39
|
+
converse: true,
|
|
40
|
+
chat: false,
|
|
41
|
+
responses: false,
|
|
42
|
+
},
|
|
43
|
+
{ match: 'amazon.nova', converse: true, chat: false, responses: false },
|
|
44
|
+
{ match: 'meta.llama', converse: true, chat: false, responses: false },
|
|
45
|
+
{ match: 'ai21.jamba', converse: true, chat: false, responses: false },
|
|
46
|
+
{ match: 'cohere.command', converse: true, chat: false, responses: false },
|
|
47
|
+
{ match: 'deepseek.r1', converse: true, chat: false, responses: false },
|
|
48
|
+
{ match: 'deepseek', converse: true, chat: true, responses: false },
|
|
49
|
+
{
|
|
50
|
+
match: 'mistral.pixtral',
|
|
51
|
+
converse: true,
|
|
52
|
+
chat: false,
|
|
53
|
+
responses: false,
|
|
54
|
+
},
|
|
55
|
+
{ match: 'mistral', converse: true, chat: true, responses: false },
|
|
56
|
+
{ match: 'qwen', converse: true, chat: true, responses: false },
|
|
57
|
+
{
|
|
58
|
+
match: 'google.gemma-4-',
|
|
59
|
+
converse: false,
|
|
60
|
+
chat: true,
|
|
61
|
+
responses: true,
|
|
62
|
+
mantlePath: '/openai/v1',
|
|
63
|
+
models: [
|
|
64
|
+
{ id: 'google.gemma-4-31b', input: ['text', 'image'] },
|
|
65
|
+
{ id: 'google.gemma-4-26b-a4b', input: ['text', 'image'] },
|
|
66
|
+
{ id: 'google.gemma-4-e2b', input: ['text', 'image'] },
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
match: 'google.gemma',
|
|
71
|
+
converse: true,
|
|
72
|
+
chat: true,
|
|
73
|
+
responses: false,
|
|
74
|
+
mantlePath: '/v1',
|
|
75
|
+
},
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
const DEFAULT_COMPAT: BedrockCompatibility = {
|
|
79
|
+
converse: true,
|
|
80
|
+
chat: false,
|
|
81
|
+
responses: false,
|
|
82
|
+
mantlePath: '/v1',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function lookupBedrockCompatibility(id: string): BedrockCompatibility {
|
|
86
|
+
for (const rule of BEDROCK_API_COMPATIBILITY) {
|
|
87
|
+
if (id.includes(rule.match)) {
|
|
88
|
+
return {
|
|
89
|
+
converse: rule.converse,
|
|
90
|
+
chat: rule.chat,
|
|
91
|
+
responses: rule.responses,
|
|
92
|
+
mantlePath: rule.mantlePath ?? '/v1',
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return DEFAULT_COMPAT
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Mantle OpenAI path from the compatibility config. Unknown ids stay on `/v1`. */
|
|
100
|
+
export function mantlePathForModel(
|
|
101
|
+
model: string | undefined,
|
|
102
|
+
): BedrockMantlePath {
|
|
103
|
+
if (typeof model !== 'string') return '/v1'
|
|
104
|
+
return lookupBedrockCompatibility(model).mantlePath
|
|
105
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,7 +10,11 @@
|
|
|
10
10
|
import { BedrockTextAdapter } from './adapters/text'
|
|
11
11
|
import { BedrockResponsesTextAdapter } from './adapters/responses-text'
|
|
12
12
|
import { BedrockConverseTextAdapter } from './adapters/converse-text'
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
BEDROCK_CHAT_MODELS,
|
|
15
|
+
BEDROCK_CONVERSE_MODELS,
|
|
16
|
+
BEDROCK_RESPONSES_MODELS,
|
|
17
|
+
} from './model-meta'
|
|
14
18
|
import type { BedrockTextConfig } from './adapters/text'
|
|
15
19
|
import type { BedrockResponsesConfig } from './adapters/responses-text'
|
|
16
20
|
import type { BedrockConverseConfig } from './adapters/converse-text'
|
|
@@ -39,6 +43,12 @@ type AnyBedrockAdapter =
|
|
|
39
43
|
| BedrockTextAdapter<BedrockChatModels>
|
|
40
44
|
| BedrockResponsesTextAdapter<BedrockResponsesModels>
|
|
41
45
|
|
|
46
|
+
/** Any catalog id the branching factory can receive. */
|
|
47
|
+
type BedrockFactoryModel =
|
|
48
|
+
| BedrockConverseModels
|
|
49
|
+
| BedrockChatModels
|
|
50
|
+
| BedrockResponsesModels
|
|
51
|
+
|
|
42
52
|
/** Cast-free runtime guard: is this model in the Responses-capable subset? */
|
|
43
53
|
function isResponsesModel(model: string): model is BedrockResponsesModels {
|
|
44
54
|
return BEDROCK_RESPONSES_MODELS.some((m) => m === model)
|
|
@@ -49,6 +59,11 @@ function isChatModel(model: string): model is BedrockChatModels {
|
|
|
49
59
|
return BEDROCK_CHAT_MODELS.some((m) => m === model)
|
|
50
60
|
}
|
|
51
61
|
|
|
62
|
+
/** Cast-free runtime guard: is this model in the Converse-capable subset? */
|
|
63
|
+
function isConverseModel(model: string): model is BedrockConverseModels {
|
|
64
|
+
return BEDROCK_CONVERSE_MODELS.some((m) => m === model)
|
|
65
|
+
}
|
|
66
|
+
|
|
52
67
|
/** Strip the `api` discriminator from a config without an unused-var lint error. */
|
|
53
68
|
function stripApi<T extends { api?: unknown }>(config: T): Omit<T, 'api'> {
|
|
54
69
|
const { api, ...rest } = config
|
|
@@ -65,7 +80,7 @@ function stripApi<T extends { api?: unknown }>(config: T): Omit<T, 'api'> {
|
|
|
65
80
|
* Default path → Converse adapter; opt-in via `api: 'chat'` or `api: 'responses'`.
|
|
66
81
|
*/
|
|
67
82
|
function build(
|
|
68
|
-
model:
|
|
83
|
+
model: BedrockFactoryModel,
|
|
69
84
|
config?: BedrockClientConfig & { api?: 'converse' | 'chat' | 'responses' },
|
|
70
85
|
): AnyBedrockAdapter {
|
|
71
86
|
if (config?.api === 'responses') {
|
|
@@ -87,7 +102,12 @@ function build(
|
|
|
87
102
|
}
|
|
88
103
|
return new BedrockTextAdapter(stripApi(config), model)
|
|
89
104
|
}
|
|
90
|
-
|
|
105
|
+
if (!isConverseModel(model)) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Model "${model}" is not available on the Bedrock Converse API. ` +
|
|
108
|
+
`Converse-capable models: ${BEDROCK_CONVERSE_MODELS.join(', ')}.`,
|
|
109
|
+
)
|
|
110
|
+
}
|
|
91
111
|
return new BedrockConverseTextAdapter(config ? stripApi(config) : {}, model)
|
|
92
112
|
}
|
|
93
113
|
|
|
@@ -108,7 +128,7 @@ export function createBedrockText<TModel extends BedrockResponsesModels>(
|
|
|
108
128
|
config: BedrockResponsesApiConfig,
|
|
109
129
|
): BedrockResponsesTextAdapter<TModel>
|
|
110
130
|
export function createBedrockText(
|
|
111
|
-
model:
|
|
131
|
+
model: BedrockFactoryModel,
|
|
112
132
|
apiKey: string,
|
|
113
133
|
config?:
|
|
114
134
|
| BedrockConverseApiConfig
|
|
@@ -133,7 +153,7 @@ export function bedrockText<TModel extends BedrockResponsesModels>(
|
|
|
133
153
|
config: BedrockResponsesApiConfig,
|
|
134
154
|
): BedrockResponsesTextAdapter<TModel>
|
|
135
155
|
export function bedrockText(
|
|
136
|
-
model:
|
|
156
|
+
model: BedrockFactoryModel,
|
|
137
157
|
config?:
|
|
138
158
|
| BedrockConverseApiConfig
|
|
139
159
|
| BedrockChatApiConfig
|
|
@@ -85,4 +85,22 @@ export const GENERATED_BEDROCK_MODELS = [
|
|
|
85
85
|
output: ['text'],
|
|
86
86
|
apis: { converse: true, chat: false, responses: false },
|
|
87
87
|
},
|
|
88
|
+
{
|
|
89
|
+
id: 'google.gemma-4-31b',
|
|
90
|
+
input: ['text', 'image'],
|
|
91
|
+
output: ['text'],
|
|
92
|
+
apis: { converse: false, chat: true, responses: true },
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'google.gemma-4-26b-a4b',
|
|
96
|
+
input: ['text', 'image'],
|
|
97
|
+
output: ['text'],
|
|
98
|
+
apis: { converse: false, chat: true, responses: true },
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: 'google.gemma-4-e2b',
|
|
102
|
+
input: ['text', 'image'],
|
|
103
|
+
output: ['text'],
|
|
104
|
+
apis: { converse: false, chat: true, responses: true },
|
|
105
|
+
},
|
|
88
106
|
] as const
|
package/src/model-meta.ts
CHANGED
|
@@ -24,10 +24,10 @@ export type BedrockChatModels = IdsWhere<'chat'>
|
|
|
24
24
|
export type BedrockResponsesModels = IdsWhere<'responses'>
|
|
25
25
|
|
|
26
26
|
/** Runtime catalogs. Cast-free narrowing via a type predicate (the ai-bedrock pattern). */
|
|
27
|
-
// Every catalog entry advertises `converse: true` (Converse is the universal
|
|
28
|
-
// Bedrock surface), so the id list is the full catalog — no runtime filter needed.
|
|
29
27
|
export const BEDROCK_CONVERSE_MODELS: ReadonlyArray<BedrockConverseModels> =
|
|
30
|
-
GENERATED_BEDROCK_MODELS.
|
|
28
|
+
GENERATED_BEDROCK_MODELS.filter(
|
|
29
|
+
(m): m is Extract<Entry, { apis: { converse: true } }> => m.apis.converse,
|
|
30
|
+
).map((m) => m.id)
|
|
31
31
|
|
|
32
32
|
export const BEDROCK_CHAT_MODELS: ReadonlyArray<BedrockChatModels> =
|
|
33
33
|
GENERATED_BEDROCK_MODELS.filter(
|
package/src/utils/client.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolveBedrockAuth } from './auth'
|
|
2
2
|
import { createSigV4Fetch } from './openai-sigv4-fetch'
|
|
3
|
+
import { mantlePathForModel } from '../api-compatibility'
|
|
3
4
|
import type { ClientOptions } from 'openai'
|
|
4
5
|
import type { BedrockEndpoint } from './auth'
|
|
5
6
|
|
|
@@ -27,9 +28,13 @@ const DEFAULT_REGION = 'us-east-1'
|
|
|
27
28
|
/** OpenAI SDK requires a non-empty apiKey even when a signed fetch overrides Authorization. */
|
|
28
29
|
const SIGV4_PLACEHOLDER_KEY = 'bedrock-sigv4'
|
|
29
30
|
|
|
30
|
-
function buildBaseURL(
|
|
31
|
+
function buildBaseURL(
|
|
32
|
+
region: string,
|
|
33
|
+
endpoint: BedrockEndpoint,
|
|
34
|
+
model?: string,
|
|
35
|
+
): string {
|
|
31
36
|
return endpoint === 'mantle'
|
|
32
|
-
? `https://bedrock-mantle.${region}.api.aws
|
|
37
|
+
? `https://bedrock-mantle.${region}.api.aws${mantlePathForModel(model)}`
|
|
33
38
|
: `https://bedrock-runtime.${region}.amazonaws.com/openai/v1`
|
|
34
39
|
}
|
|
35
40
|
|
|
@@ -37,6 +42,7 @@ function buildBaseURL(region: string, endpoint: BedrockEndpoint): string {
|
|
|
37
42
|
export function withBedrockDefaults(
|
|
38
43
|
config: BedrockClientConfig,
|
|
39
44
|
forced?: BedrockEndpoint,
|
|
45
|
+
model?: string,
|
|
40
46
|
): ClientOptions {
|
|
41
47
|
const { region, endpoint, auth, apiKey, baseURL, fetch, ...rest } = config
|
|
42
48
|
const resolvedRegion = region ?? DEFAULT_REGION
|
|
@@ -45,17 +51,19 @@ export function withBedrockDefaults(
|
|
|
45
51
|
{ apiKey, region: resolvedRegion, auth },
|
|
46
52
|
resolvedEndpoint,
|
|
47
53
|
)
|
|
54
|
+
const resolvedBaseURL =
|
|
55
|
+
baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint, model)
|
|
48
56
|
if (resolved.kind === 'bearer') {
|
|
49
57
|
return {
|
|
50
58
|
...rest,
|
|
51
|
-
baseURL:
|
|
59
|
+
baseURL: resolvedBaseURL,
|
|
52
60
|
apiKey: resolved.token,
|
|
53
61
|
...(fetch ? { fetch } : {}),
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
64
|
return {
|
|
57
65
|
...rest,
|
|
58
|
-
baseURL:
|
|
66
|
+
baseURL: resolvedBaseURL,
|
|
59
67
|
apiKey: SIGV4_PLACEHOLDER_KEY,
|
|
60
68
|
fetch: fetch ?? createSigV4Fetch(resolved),
|
|
61
69
|
}
|