@tanstack/ai-bedrock 1.2.1 → 1.4.0
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/README.md +21 -2
- package/dist/esm/adapters/converse-text.js +6 -5
- package/dist/esm/adapters/converse-text.js.map +1 -1
- package/dist/esm/adapters/embedding.js +1 -2
- package/dist/esm/adapters/rerank.d.ts +33 -0
- package/dist/esm/adapters/rerank.js +122 -0
- package/dist/esm/adapters/rerank.js.map +1 -0
- package/dist/esm/adapters/responses-text.js +1 -2
- package/dist/esm/adapters/text.js +1 -2
- package/dist/esm/api-compatibility.js +1 -2
- package/dist/esm/byok.js +1 -2
- package/dist/esm/converse/message-converter.js +1 -2
- package/dist/esm/converse/prompt-cache.js +1 -2
- package/dist/esm/converse/provider-options.d.ts +8 -3
- package/dist/esm/converse/reasoning.js +1 -2
- package/dist/esm/converse/stream-processor.js +1 -2
- package/dist/esm/converse/structured-output.js +1 -2
- package/dist/esm/converse/tool-converter.js +1 -2
- package/dist/esm/converse/usage.js +1 -2
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +8 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/model-catalog.generated.js +1 -2
- package/dist/esm/model-meta.d.ts +4 -0
- package/dist/esm/model-meta.js +4 -3
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/utils/auth.d.ts +5 -0
- package/dist/esm/utils/auth.js +1 -3
- package/dist/esm/utils/auth.js.map +1 -1
- package/dist/esm/utils/client.js +1 -2
- package/dist/esm/utils/openai-sigv4-fetch.js +1 -2
- package/dist/esm/utils/sigv4.js +1 -2
- package/package.json +6 -6
- package/src/adapters/converse-text.ts +6 -0
- package/src/adapters/rerank.ts +188 -0
- package/src/converse/provider-options.ts +9 -3
- package/src/index.ts +11 -4
- package/src/model-meta.ts +9 -0
- package/src/utils/auth.ts +8 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildConverseUsage } from "./usage.js";
|
|
2
2
|
import { EventType } from "@tanstack/ai";
|
|
3
|
-
|
|
3
|
+
// src/converse/stream-processor.ts
|
|
4
4
|
/**
|
|
5
5
|
* Converse delivers server-side failures — throttling, request validation,
|
|
6
6
|
* mid-stream model faults, and service-unavailable — as in-band stream events
|
|
@@ -232,7 +232,6 @@ async function* processConverseStream(stream, newMessageId, lifecycle) {
|
|
|
232
232
|
...usage && { usage }
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
|
-
//#endregion
|
|
236
235
|
export { processConverseStream, throwIfConverseStreamError };
|
|
237
236
|
|
|
238
237
|
//# sourceMappingURL=stream-processor.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/converse/structured-output.ts
|
|
2
2
|
var STRUCTURED_TOOL_NAME = "structured_output";
|
|
3
3
|
/**
|
|
4
4
|
* Converse has no native json_schema response_format. Structured output is
|
|
@@ -15,7 +15,6 @@ function buildStructuredToolConfig(schema) {
|
|
|
15
15
|
toolChoice: { tool: { name: STRUCTURED_TOOL_NAME } }
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
//#endregion
|
|
19
18
|
export { STRUCTURED_TOOL_NAME, buildStructuredToolConfig };
|
|
20
19
|
|
|
21
20
|
//# sourceMappingURL=structured-output.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/converse/tool-converter.ts
|
|
2
2
|
function toToolConfig(tools, choice) {
|
|
3
3
|
if (!tools.length) return void 0;
|
|
4
4
|
if (choice === "none") return void 0;
|
|
@@ -18,7 +18,6 @@ function mapChoice(choice) {
|
|
|
18
18
|
if (choice === "none") return void 0;
|
|
19
19
|
return { tool: { name: choice.name } };
|
|
20
20
|
}
|
|
21
|
-
//#endregion
|
|
22
21
|
export { toToolConfig };
|
|
23
22
|
|
|
24
23
|
//# sourceMappingURL=tool-converter.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { buildBaseUsage } from "@tanstack/ai";
|
|
2
|
-
|
|
2
|
+
// src/converse/usage.ts
|
|
3
3
|
/**
|
|
4
4
|
* Build normalized {@link TokenUsage} from a Converse `usage` object.
|
|
5
5
|
*
|
|
@@ -29,7 +29,6 @@ function buildConverseUsage(usage) {
|
|
|
29
29
|
if (Object.keys(promptTokensDetails).length > 0) result.promptTokensDetails = promptTokensDetails;
|
|
30
30
|
return result;
|
|
31
31
|
}
|
|
32
|
-
//#endregion
|
|
33
32
|
export { buildConverseUsage };
|
|
34
33
|
|
|
35
34
|
//# sourceMappingURL=usage.js.map
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -24,8 +24,9 @@ export { BedrockTextAdapter, createBedrockChat, type BedrockTextConfig, type Bed
|
|
|
24
24
|
export { BedrockResponsesTextAdapter, createBedrockResponsesText, type BedrockResponsesConfig, type BedrockResponsesProviderOptions, } from './adapters/responses-text.js';
|
|
25
25
|
export { BedrockConverseTextAdapter, createBedrockConverse, type BedrockConverseConfig, } from './adapters/converse-text.js';
|
|
26
26
|
export { BedrockEmbeddingAdapter, bedrockEmbedding, createBedrockEmbedding, type BedrockEmbeddingConfig, } from './adapters/embedding.js';
|
|
27
|
+
export { BedrockRerankAdapter, bedrockRerank, type BedrockRerankConfig, type BedrockRerankProviderOptions, } from './adapters/rerank.js';
|
|
27
28
|
export type { BedrockCohereEmbeddingInputType, BedrockCohereEmbeddingProviderOptions, BedrockEmbeddingProviderOptions, BedrockTitanImageEmbeddingProviderOptions, BedrockTitanTextEmbeddingProviderOptions, } from './embedding/embedding-provider-options.js';
|
|
28
29
|
export type { BedrockConverseProviderOptions } from './converse/provider-options.js';
|
|
29
30
|
export { resolveBedrockAuth, withBedrockDefaults, type BedrockClientConfig, type BedrockEndpoint, type ResolvedBedrockAuth, } from './utils/client.js';
|
|
30
|
-
export { BEDROCK_CHAT_MODELS, BEDROCK_RESPONSES_MODELS, BEDROCK_CONVERSE_MODELS, BEDROCK_EMBEDDING_MODELS, type BedrockEmbeddingModel, type BedrockEmbeddingModelProviderOptionsByName, type BedrockEmbeddingModelInputModalitiesByName, type BedrockChatModels, type BedrockResponsesModels, type BedrockConverseModels, type BedrockChatModelProviderOptionsByName, type BedrockChatModelToolCapabilitiesByName, type BedrockModelInputModalitiesByName, } from './model-meta.js';
|
|
31
|
+
export { BEDROCK_CHAT_MODELS, BEDROCK_RESPONSES_MODELS, BEDROCK_CONVERSE_MODELS, BEDROCK_EMBEDDING_MODELS, BEDROCK_RERANK_MODELS, type BedrockRerankModel, type BedrockEmbeddingModel, type BedrockEmbeddingModelProviderOptionsByName, type BedrockEmbeddingModelInputModalitiesByName, type BedrockChatModels, type BedrockResponsesModels, type BedrockConverseModels, type BedrockChatModelProviderOptionsByName, type BedrockChatModelToolCapabilitiesByName, type BedrockModelInputModalitiesByName, } from './model-meta.js';
|
|
31
32
|
export type { BedrockCachePoint, BedrockSystemPromptMetadata, BedrockToolMetadata, BedrockMessageMetadataByModality, BedrockTextMetadata, BedrockImageMetadata, BedrockAudioMetadata, BedrockVideoMetadata, BedrockDocumentMetadata, } from './message-types.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { resolveBedrockAuth } from "./utils/auth.js";
|
|
2
|
-
import { withBedrockDefaults } from "./utils/client.js";
|
|
3
|
-
import { BEDROCK_CHAT_MODELS, BEDROCK_CONVERSE_MODELS, BEDROCK_EMBEDDING_MODELS, BEDROCK_RESPONSES_MODELS } from "./model-meta.js";
|
|
4
2
|
import { BedrockTextAdapter, createBedrockChat } from "./adapters/text.js";
|
|
5
3
|
import { BedrockResponsesTextAdapter, createBedrockResponsesText } from "./adapters/responses-text.js";
|
|
6
4
|
import { BedrockConverseTextAdapter, createBedrockConverse } from "./adapters/converse-text.js";
|
|
5
|
+
import { BEDROCK_CHAT_MODELS, BEDROCK_CONVERSE_MODELS, BEDROCK_EMBEDDING_MODELS, BEDROCK_RERANK_MODELS, BEDROCK_RESPONSES_MODELS } from "./model-meta.js";
|
|
7
6
|
import { BedrockEmbeddingAdapter, bedrockEmbedding, createBedrockEmbedding } from "./adapters/embedding.js";
|
|
8
|
-
|
|
7
|
+
import { BedrockRerankAdapter, bedrockRerank } from "./adapters/rerank.js";
|
|
8
|
+
import { withBedrockDefaults } from "./utils/client.js";
|
|
9
|
+
// src/index.ts
|
|
9
10
|
/**
|
|
10
11
|
* @module @tanstack/ai-bedrock
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* adapter (`api: 'chat'`), and the Responses adapter (`api: 'responses'`).
|
|
13
|
+
* Bedrock chat uses Converse by default, or the OpenAI-compatible APIs with
|
|
14
|
+
* `api: 'chat'` or `api: 'responses'`. Embeddings and reranking use
|
|
15
|
+
* `bedrockEmbedding` and `bedrockRerank`.
|
|
16
16
|
*/
|
|
17
17
|
/** Cast-free runtime guard: is this model in the Responses-capable subset? */
|
|
18
18
|
function isResponsesModel(model) {
|
|
@@ -61,7 +61,6 @@ function createBedrockText(model, apiKey, config) {
|
|
|
61
61
|
function bedrockText(model, config) {
|
|
62
62
|
return build(model, config);
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
export { BEDROCK_CHAT_MODELS, BEDROCK_CONVERSE_MODELS, BEDROCK_EMBEDDING_MODELS, BEDROCK_RESPONSES_MODELS, BedrockConverseTextAdapter, BedrockEmbeddingAdapter, BedrockResponsesTextAdapter, BedrockTextAdapter, bedrockEmbedding, bedrockText, createBedrockChat, createBedrockConverse, createBedrockEmbedding, createBedrockResponsesText, createBedrockText, resolveBedrockAuth, withBedrockDefaults };
|
|
64
|
+
export { BEDROCK_CHAT_MODELS, BEDROCK_CONVERSE_MODELS, BEDROCK_EMBEDDING_MODELS, BEDROCK_RERANK_MODELS, BEDROCK_RESPONSES_MODELS, BedrockConverseTextAdapter, BedrockEmbeddingAdapter, BedrockRerankAdapter, BedrockResponsesTextAdapter, BedrockTextAdapter, bedrockEmbedding, bedrockRerank, bedrockText, createBedrockChat, createBedrockConverse, createBedrockEmbedding, createBedrockResponsesText, createBedrockText, resolveBedrockAuth, withBedrockDefaults };
|
|
66
65
|
|
|
67
66
|
//# sourceMappingURL=index.js.map
|
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 *
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/**\n * @module @tanstack/ai-bedrock\n *\n * Bedrock chat uses Converse by default, or the OpenAI-compatible APIs with\n * `api: 'chat'` or `api: 'responses'`. Embeddings and reranking use\n * `bedrockEmbedding` and `bedrockRerank`.\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 {\n BedrockRerankAdapter,\n bedrockRerank,\n type BedrockRerankConfig,\n type BedrockRerankProviderOptions,\n} from './adapters/rerank'\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 BEDROCK_RERANK_MODELS,\n type BedrockRerankModel,\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 BedrockCachePoint,\n BedrockSystemPromptMetadata,\n BedrockToolMetadata,\n BedrockMessageMetadataByModality,\n BedrockTextMetadata,\n BedrockImageMetadata,\n BedrockAudioMetadata,\n BedrockVideoMetadata,\n BedrockDocumentMetadata,\n} from './message-types'\n"],"mappings":";;;;;;;;;;;;;;;;;AAmDA,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/model-catalog.generated.ts
|
|
2
2
|
var GENERATED_BEDROCK_MODELS = [
|
|
3
3
|
{
|
|
4
4
|
id: "openai.gpt-oss-120b-1:0",
|
|
@@ -195,7 +195,6 @@ var GENERATED_BEDROCK_MODELS = [
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
];
|
|
198
|
-
//#endregion
|
|
199
198
|
export { GENERATED_BEDROCK_MODELS };
|
|
200
199
|
|
|
201
200
|
//# sourceMappingURL=model-catalog.generated.js.map
|
package/dist/esm/model-meta.d.ts
CHANGED
|
@@ -116,6 +116,10 @@ export declare const BEDROCK_MODEL_REASONING: Readonly<Record<string, ModelReaso
|
|
|
116
116
|
* entry for these models yet. Move it to the catalog when it has them.
|
|
117
117
|
*/
|
|
118
118
|
export declare const BEDROCK_CLAUDE_NO_FORCED_TOOL_FAMILIES: ReadonlyArray<string>;
|
|
119
|
+
/** Models supported by the Bedrock Rerank API, separate from the chat catalog. */
|
|
120
|
+
export declare const BEDROCK_RERANK_MODELS: readonly ["amazon.rerank-v1:0", "cohere.rerank-v3-5:0"];
|
|
121
|
+
/** Short model IDs accepted by the Bedrock rerank adapter. */
|
|
122
|
+
export type BedrockRerankModel = (typeof BEDROCK_RERANK_MODELS)[number];
|
|
119
123
|
/**
|
|
120
124
|
* Embedding models reachable through Bedrock's `InvokeModel` API. These are
|
|
121
125
|
* not part of the generated Converse catalog (embedding models have no
|
package/dist/esm/model-meta.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GENERATED_BEDROCK_MODELS } from "./model-catalog.generated.js";
|
|
2
|
-
|
|
2
|
+
// src/model-meta.ts
|
|
3
3
|
var BUDGET_OFF_HIGH = {
|
|
4
4
|
levels: {
|
|
5
5
|
off: "off",
|
|
@@ -57,6 +57,8 @@ var BEDROCK_CLAUDE_NO_FORCED_TOOL_FAMILIES = [
|
|
|
57
57
|
"claude-opus-5-5",
|
|
58
58
|
"claude-sonnet-5-5"
|
|
59
59
|
];
|
|
60
|
+
/** Models supported by the Bedrock Rerank API, separate from the chat catalog. */
|
|
61
|
+
var BEDROCK_RERANK_MODELS = ["amazon.rerank-v1:0", "cohere.rerank-v3-5:0"];
|
|
60
62
|
/**
|
|
61
63
|
* Embedding models reachable through Bedrock's `InvokeModel` API. These are
|
|
62
64
|
* not part of the generated Converse catalog (embedding models have no
|
|
@@ -68,7 +70,6 @@ var BEDROCK_EMBEDDING_MODELS = [
|
|
|
68
70
|
"cohere.embed-english-v3",
|
|
69
71
|
"cohere.embed-multilingual-v3"
|
|
70
72
|
];
|
|
71
|
-
|
|
72
|
-
export { BEDROCK_CHAT_MODELS, BEDROCK_CLAUDE_NO_FORCED_TOOL_FAMILIES, BEDROCK_CONVERSE_MODELS, BEDROCK_EMBEDDING_MODELS, BEDROCK_MODEL_INPUT_MODALITIES, BEDROCK_MODEL_REASONING, BEDROCK_RESPONSES_MODELS };
|
|
73
|
+
export { BEDROCK_CHAT_MODELS, BEDROCK_CLAUDE_NO_FORCED_TOOL_FAMILIES, BEDROCK_CONVERSE_MODELS, BEDROCK_EMBEDDING_MODELS, BEDROCK_MODEL_INPUT_MODALITIES, BEDROCK_MODEL_REASONING, BEDROCK_RERANK_MODELS, BEDROCK_RESPONSES_MODELS };
|
|
73
74
|
|
|
74
75
|
//# sourceMappingURL=model-meta.js.map
|
|
@@ -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 { Modality, ModelReasoning } from '@tanstack/ai'\nimport type { ModelReasoningCapability } from '@tanstack/ai/adapter-internals'\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\n// Reasoning shapes: the levels a model has for `chat({ reasoning })`, and\n// the provider value to send for each. Each model points at one of them.\nconst BUDGET_OFF_HIGH = {\n levels: { off: 'off', high: 'high' },\n budget: true,\n} as const\nconst EFFORT_LOW_TO_HIGH = {\n levels: { low: 'low', medium: 'medium', high: 'high' },\n budget: false,\n} as const\nconst EFFORT_NONE_HIGH = {\n levels: { off: 'none', high: 'high' },\n budget: false,\n} as const\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/**\n * Runtime map from model id to its input modalities, for the text adapters'\n * `inputModalities`. An unknown id gives `undefined`.\n */\nexport const BEDROCK_MODEL_INPUT_MODALITIES: Readonly<\n Record<string, ReadonlyArray<Modality>>\n> = Object.fromEntries(GENERATED_BEDROCK_MODELS.map((m) => [m.id, m.input]))\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// Reasoning\n// ============================================================================\n//\n// Each model's data for `chat({ reasoning })`: the levels it has, with the\n// provider value for each, and whether it takes a thinking token budget. The\n// data comes from models.dev. The generator that writes it comes with the model\n// catalog later. Until then, edit these entries by hand.\n// scripts/fetch-bedrock-models.ts does not touch them.\n\nconst BEDROCK_REASONING = {\n 'openai.gpt-oss-120b-1:0': EFFORT_LOW_TO_HIGH,\n 'openai.gpt-oss-20b-1:0': EFFORT_LOW_TO_HIGH,\n 'us.anthropic.claude-sonnet-4-5-20250929-v1:0': BUDGET_OFF_HIGH,\n 'us.anthropic.claude-haiku-4-5-20251001-v1:0': BUDGET_OFF_HIGH,\n 'google.gemma-4-31b': EFFORT_NONE_HIGH,\n 'google.gemma-4-26b-a4b': EFFORT_NONE_HIGH,\n 'google.gemma-4-e2b': EFFORT_NONE_HIGH,\n} satisfies Partial<Record<Entry['id'], ModelReasoning>>\n\n/**\n * Each model's reasoning levels, and whether it takes a token budget, for\n * `chat({ reasoning })`. A model that is not here does not reason.\n */\nexport type BedrockModelReasoningByName = {\n [K in keyof typeof BEDROCK_REASONING]: ModelReasoningCapability<\n (typeof BEDROCK_REASONING)[K]\n >\n}\n\n/**\n * Runtime map from model id to its reasoning data, for the text adapters. An\n * unknown id gives `undefined`: the adapter sends no reasoning field.\n */\nexport const BEDROCK_MODEL_REASONING: Readonly<Record<string, ModelReasoning>> =\n BEDROCK_REASONING\n\n/**\n * The Claude families that reject a forced tool (`any` or a named `tool`) on\n * every request, with or without thinking. A Bedrock id has the family name\n * inside it, for example `us.anthropic.claude-opus-5-5-...`.\n * ponytail: names, not catalog entries, because the generated catalog has no\n * entry for these models yet. Move it to the catalog when it has them.\n */\nexport const BEDROCK_CLAUDE_NO_FORCED_TOOL_FAMILIES: ReadonlyArray<string> = [\n 'claude-fable-5-1',\n 'claude-mythos-5-1',\n 'claude-opus-5-5',\n 'claude-sonnet-5-5',\n]\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":";;AAcA,IAAM,kBAAkB;CACtB,QAAQ;EAAE,KAAK;EAAO,MAAM;CAAO;CACnC,QAAQ;AACV;AACA,IAAM,qBAAqB;CACzB,QAAQ;EAAE,KAAK;EAAO,QAAQ;EAAU,MAAM;CAAO;CACrD,QAAQ;AACV;AACA,IAAM,mBAAmB;CACvB,QAAQ;EAAE,KAAK;EAAQ,MAAM;CAAO;CACpC,QAAQ;AACV;;AAkBA,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;;;;;AAWnB,IAAa,iCAET,OAAO,YAAY,yBAAyB,KAAK,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;;;;;AAkE3E,IAAa,0BACX;CAxBA,2BAA2B;CAC3B,0BAA0B;CAC1B,gDAAgD;CAChD,+CAA+C;CAC/C,sBAAsB;CACtB,0BAA0B;CAC1B,sBAAsB;AAkBtB;;;;;;;;AASF,IAAa,yCAAgE;CAC3E;CACA;CACA;CACA;AACF;;;;;;
|
|
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 { Modality, ModelReasoning } from '@tanstack/ai'\nimport type { ModelReasoningCapability } from '@tanstack/ai/adapter-internals'\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\n// Reasoning shapes: the levels a model has for `chat({ reasoning })`, and\n// the provider value to send for each. Each model points at one of them.\nconst BUDGET_OFF_HIGH = {\n levels: { off: 'off', high: 'high' },\n budget: true,\n} as const\nconst EFFORT_LOW_TO_HIGH = {\n levels: { low: 'low', medium: 'medium', high: 'high' },\n budget: false,\n} as const\nconst EFFORT_NONE_HIGH = {\n levels: { off: 'none', high: 'high' },\n budget: false,\n} as const\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/**\n * Runtime map from model id to its input modalities, for the text adapters'\n * `inputModalities`. An unknown id gives `undefined`.\n */\nexport const BEDROCK_MODEL_INPUT_MODALITIES: Readonly<\n Record<string, ReadonlyArray<Modality>>\n> = Object.fromEntries(GENERATED_BEDROCK_MODELS.map((m) => [m.id, m.input]))\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// Reasoning\n// ============================================================================\n//\n// Each model's data for `chat({ reasoning })`: the levels it has, with the\n// provider value for each, and whether it takes a thinking token budget. The\n// data comes from models.dev. The generator that writes it comes with the model\n// catalog later. Until then, edit these entries by hand.\n// scripts/fetch-bedrock-models.ts does not touch them.\n\nconst BEDROCK_REASONING = {\n 'openai.gpt-oss-120b-1:0': EFFORT_LOW_TO_HIGH,\n 'openai.gpt-oss-20b-1:0': EFFORT_LOW_TO_HIGH,\n 'us.anthropic.claude-sonnet-4-5-20250929-v1:0': BUDGET_OFF_HIGH,\n 'us.anthropic.claude-haiku-4-5-20251001-v1:0': BUDGET_OFF_HIGH,\n 'google.gemma-4-31b': EFFORT_NONE_HIGH,\n 'google.gemma-4-26b-a4b': EFFORT_NONE_HIGH,\n 'google.gemma-4-e2b': EFFORT_NONE_HIGH,\n} satisfies Partial<Record<Entry['id'], ModelReasoning>>\n\n/**\n * Each model's reasoning levels, and whether it takes a token budget, for\n * `chat({ reasoning })`. A model that is not here does not reason.\n */\nexport type BedrockModelReasoningByName = {\n [K in keyof typeof BEDROCK_REASONING]: ModelReasoningCapability<\n (typeof BEDROCK_REASONING)[K]\n >\n}\n\n/**\n * Runtime map from model id to its reasoning data, for the text adapters. An\n * unknown id gives `undefined`: the adapter sends no reasoning field.\n */\nexport const BEDROCK_MODEL_REASONING: Readonly<Record<string, ModelReasoning>> =\n BEDROCK_REASONING\n\n/**\n * The Claude families that reject a forced tool (`any` or a named `tool`) on\n * every request, with or without thinking. A Bedrock id has the family name\n * inside it, for example `us.anthropic.claude-opus-5-5-...`.\n * ponytail: names, not catalog entries, because the generated catalog has no\n * entry for these models yet. Move it to the catalog when it has them.\n */\nexport const BEDROCK_CLAUDE_NO_FORCED_TOOL_FAMILIES: ReadonlyArray<string> = [\n 'claude-fable-5-1',\n 'claude-mythos-5-1',\n 'claude-opus-5-5',\n 'claude-sonnet-5-5',\n]\n\n/** Models supported by the Bedrock Rerank API, separate from the chat catalog. */\nexport const BEDROCK_RERANK_MODELS = [\n 'amazon.rerank-v1:0',\n 'cohere.rerank-v3-5:0',\n] as const\n\n/** Short model IDs accepted by the Bedrock rerank adapter. */\nexport type BedrockRerankModel = (typeof BEDROCK_RERANK_MODELS)[number]\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":";;AAcA,IAAM,kBAAkB;CACtB,QAAQ;EAAE,KAAK;EAAO,MAAM;CAAO;CACnC,QAAQ;AACV;AACA,IAAM,qBAAqB;CACzB,QAAQ;EAAE,KAAK;EAAO,QAAQ;EAAU,MAAM;CAAO;CACrD,QAAQ;AACV;AACA,IAAM,mBAAmB;CACvB,QAAQ;EAAE,KAAK;EAAQ,MAAM;CAAO;CACpC,QAAQ;AACV;;AAkBA,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;;;;;AAWnB,IAAa,iCAET,OAAO,YAAY,yBAAyB,KAAK,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;;;;;AAkE3E,IAAa,0BACX;CAxBA,2BAA2B;CAC3B,0BAA0B;CAC1B,gDAAgD;CAChD,+CAA+C;CAC/C,sBAAsB;CACtB,0BAA0B;CAC1B,sBAAsB;AAkBtB;;;;;;;;AASF,IAAa,yCAAgE;CAC3E;CACA;CACA;CACA;AACF;;AAGA,IAAa,wBAAwB,CACnC,sBACA,sBACF;;;;;;AAcA,IAAa,2BAA2B;CACtC;CACA;CACA;CACA;AACF"}
|
package/dist/esm/utils/auth.d.ts
CHANGED
|
@@ -23,4 +23,9 @@ export interface BedrockAuthConfig {
|
|
|
23
23
|
auth?: 'apikey' | 'sigv4' | 'auto';
|
|
24
24
|
}
|
|
25
25
|
/** apiKey -> BEDROCK_API_KEY -> AWS_BEARER_TOKEN_BEDROCK -> SigV4 (credential chain). */
|
|
26
|
+
export declare function resolveBedrockAuth(config: BedrockAuthConfig & {
|
|
27
|
+
auth: 'sigv4';
|
|
28
|
+
}, endpoint: BedrockEndpoint): Extract<ResolvedBedrockAuth, {
|
|
29
|
+
kind: 'sigv4';
|
|
30
|
+
}>;
|
|
26
31
|
export declare function resolveBedrockAuth(config: BedrockAuthConfig, endpoint: BedrockEndpoint): ResolvedBedrockAuth;
|
package/dist/esm/utils/auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/utils/auth.ts
|
|
2
2
|
/** SigV4 service name differs per endpoint. */
|
|
3
3
|
function sigv4Service(endpoint) {
|
|
4
4
|
return endpoint === "mantle" ? "bedrock-mantle" : "bedrock";
|
|
@@ -23,7 +23,6 @@ function readApiKeyFromEnv() {
|
|
|
23
23
|
const env = typeof process !== "undefined" ? process.env : void 0;
|
|
24
24
|
for (const value of [env?.BEDROCK_API_KEY, env?.AWS_BEARER_TOKEN_BEDROCK]) if (value && value.trim() !== "") return value;
|
|
25
25
|
}
|
|
26
|
-
/** apiKey -> BEDROCK_API_KEY -> AWS_BEARER_TOKEN_BEDROCK -> SigV4 (credential chain). */
|
|
27
26
|
function resolveBedrockAuth(config, endpoint) {
|
|
28
27
|
const mode = config.auth ?? "auto";
|
|
29
28
|
const region = config.region ?? DEFAULT_REGION;
|
|
@@ -45,7 +44,6 @@ function resolveBedrockAuth(config, endpoint) {
|
|
|
45
44
|
}
|
|
46
45
|
};
|
|
47
46
|
}
|
|
48
|
-
//#endregion
|
|
49
47
|
export { importOptionalPeer, resolveBedrockAuth, sigv4Service };
|
|
50
48
|
|
|
51
49
|
//# sourceMappingURL=auth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","names":[],"sources":["../../../src/utils/auth.ts"],"sourcesContent":["import type { AwsCredentialIdentityProvider } from '@smithy/types'\nimport type * as CredentialProviders from '@aws-sdk/credential-providers'\n\nexport type BedrockEndpoint = 'runtime' | 'mantle'\n\n/** SigV4 service name differs per endpoint. */\nexport function sigv4Service(endpoint: BedrockEndpoint): string {\n return endpoint === 'mantle' ? 'bedrock-mantle' : 'bedrock'\n}\n\nexport type ResolvedBedrockAuth =\n | { kind: 'bearer'; token: string }\n | {\n kind: 'sigv4'\n region: string\n service: string\n credentials: AwsCredentialIdentityProvider\n }\n\n/**\n * Loads an optional peer dependency of this package (the AWS SDK parts). If\n * the import fails, throws an error that names the package to install. The\n * original error is kept as `cause`.\n */\nexport async function importOptionalPeer<T>(mod: string): Promise<T> {\n try {\n return (await import(/* @vite-ignore */ mod)) as T\n } catch (cause) {\n throw new Error(\n `@tanstack/ai-bedrock could not load \"${mod}\". It is an optional peer ` +\n `dependency. Install it: npm install ${mod}`,\n { cause },\n )\n }\n}\n\nconst DEFAULT_REGION = 'us-east-1'\n\nfunction readApiKeyFromEnv(): string | undefined {\n // Bedrock is server-only (the AWS SDK is Node-only), so the key always comes\n // from process.env. Read it directly: a property access never throws, so —\n // unlike the previous try/catch around getApiKeyFromEnv — we no longer swallow\n // unrelated errors as \"key not set\". Each var is blank-checked independently\n // so a present-but-blank BEDROCK_API_KEY falls through to\n // AWS_BEARER_TOKEN_BEDROCK (and only then to SigV4) rather than masking it.\n const env = typeof process !== 'undefined' ? process.env : undefined\n for (const value of [env?.BEDROCK_API_KEY, env?.AWS_BEARER_TOKEN_BEDROCK]) {\n if (value && value.trim() !== '') return value\n }\n return undefined\n}\n\nexport interface BedrockAuthConfig {\n apiKey?: string\n region?: string\n auth?: 'apikey' | 'sigv4' | 'auto'\n}\n\n/** apiKey -> BEDROCK_API_KEY -> AWS_BEARER_TOKEN_BEDROCK -> SigV4 (credential chain). */\nexport function resolveBedrockAuth(\n config: BedrockAuthConfig,\n endpoint: BedrockEndpoint,\n): ResolvedBedrockAuth {\n const mode = config.auth ?? 'auto'\n const region = config.region ?? DEFAULT_REGION\n\n if (mode !== 'sigv4') {\n const token = config.apiKey ?? readApiKeyFromEnv()\n if (token) return { kind: 'bearer', token }\n if (mode === 'apikey') {\n throw new Error(\n 'No Bedrock API key found. Set BEDROCK_API_KEY (or ' +\n 'AWS_BEARER_TOKEN_BEDROCK), pass `apiKey`, or use auth: \"sigv4\".',\n )\n }\n }\n\n return {\n kind: 'sigv4',\n region,\n service: sigv4Service(endpoint),\n // Lazy credential provider: the AWS SDK is Node/server-only, so we defer the\n // dynamic import until SigV4 actually needs to resolve credentials. The\n // specifier is held in a variable (not a string literal) so bundler dep\n // scanners (e.g. Vite/esbuild optimizeDeps) cannot statically discover the\n // AWS SDK and try to pre-bundle it for the browser — it would fail on the\n // SDK's Node-only `fromTokenFile` export chain. `typeof import(...)` is a\n // type-only reference (erased at emit) so we keep full typing.\n credentials: async (...args) => {\n const mod = '@aws-sdk/credential-providers'\n const { fromNodeProviderChain } =\n await importOptionalPeer<typeof CredentialProviders>(mod)\n return fromNodeProviderChain()(...args)\n },\n }\n}\n"],"mappings":";;AAMA,SAAgB,aAAa,UAAmC;CAC9D,OAAO,aAAa,WAAW,mBAAmB;AACpD;;;;;;AAgBA,eAAsB,mBAAsB,KAAyB;CACnE,IAAI;EACF,OAAQ,MAAM;;GAA0B;;CAC1C,SAAS,OAAO;EACd,MAAM,IAAI,MACR,wCAAwC,IAAI,gEACH,OACzC,EAAE,MAAM,CACV;CACF;AACF;AAEA,IAAM,iBAAiB;AAEvB,SAAS,oBAAwC;CAO/C,MAAM,MAAM,OAAO,YAAY,cAAc,QAAQ,MAAM,KAAA;CAC3D,KAAK,MAAM,SAAS,CAAC,KAAK,iBAAiB,KAAK,wBAAwB,GACtE,IAAI,SAAS,MAAM,KAAK,MAAM,IAAI,OAAO;AAG7C
|
|
1
|
+
{"version":3,"file":"auth.js","names":[],"sources":["../../../src/utils/auth.ts"],"sourcesContent":["import type { AwsCredentialIdentityProvider } from '@smithy/types'\nimport type * as CredentialProviders from '@aws-sdk/credential-providers'\n\nexport type BedrockEndpoint = 'runtime' | 'mantle'\n\n/** SigV4 service name differs per endpoint. */\nexport function sigv4Service(endpoint: BedrockEndpoint): string {\n return endpoint === 'mantle' ? 'bedrock-mantle' : 'bedrock'\n}\n\nexport type ResolvedBedrockAuth =\n | { kind: 'bearer'; token: string }\n | {\n kind: 'sigv4'\n region: string\n service: string\n credentials: AwsCredentialIdentityProvider\n }\n\n/**\n * Loads an optional peer dependency of this package (the AWS SDK parts). If\n * the import fails, throws an error that names the package to install. The\n * original error is kept as `cause`.\n */\nexport async function importOptionalPeer<T>(mod: string): Promise<T> {\n try {\n return (await import(/* @vite-ignore */ mod)) as T\n } catch (cause) {\n throw new Error(\n `@tanstack/ai-bedrock could not load \"${mod}\". It is an optional peer ` +\n `dependency. Install it: npm install ${mod}`,\n { cause },\n )\n }\n}\n\nconst DEFAULT_REGION = 'us-east-1'\n\nfunction readApiKeyFromEnv(): string | undefined {\n // Bedrock is server-only (the AWS SDK is Node-only), so the key always comes\n // from process.env. Read it directly: a property access never throws, so —\n // unlike the previous try/catch around getApiKeyFromEnv — we no longer swallow\n // unrelated errors as \"key not set\". Each var is blank-checked independently\n // so a present-but-blank BEDROCK_API_KEY falls through to\n // AWS_BEARER_TOKEN_BEDROCK (and only then to SigV4) rather than masking it.\n const env = typeof process !== 'undefined' ? process.env : undefined\n for (const value of [env?.BEDROCK_API_KEY, env?.AWS_BEARER_TOKEN_BEDROCK]) {\n if (value && value.trim() !== '') return value\n }\n return undefined\n}\n\nexport interface BedrockAuthConfig {\n apiKey?: string\n region?: string\n auth?: 'apikey' | 'sigv4' | 'auto'\n}\n\n/** apiKey -> BEDROCK_API_KEY -> AWS_BEARER_TOKEN_BEDROCK -> SigV4 (credential chain). */\nexport function resolveBedrockAuth(\n config: BedrockAuthConfig & { auth: 'sigv4' },\n endpoint: BedrockEndpoint,\n): Extract<ResolvedBedrockAuth, { kind: 'sigv4' }>\nexport function resolveBedrockAuth(\n config: BedrockAuthConfig,\n endpoint: BedrockEndpoint,\n): ResolvedBedrockAuth\nexport function resolveBedrockAuth(\n config: BedrockAuthConfig,\n endpoint: BedrockEndpoint,\n): ResolvedBedrockAuth {\n const mode = config.auth ?? 'auto'\n const region = config.region ?? DEFAULT_REGION\n\n if (mode !== 'sigv4') {\n const token = config.apiKey ?? readApiKeyFromEnv()\n if (token) return { kind: 'bearer', token }\n if (mode === 'apikey') {\n throw new Error(\n 'No Bedrock API key found. Set BEDROCK_API_KEY (or ' +\n 'AWS_BEARER_TOKEN_BEDROCK), pass `apiKey`, or use auth: \"sigv4\".',\n )\n }\n }\n\n return {\n kind: 'sigv4',\n region,\n service: sigv4Service(endpoint),\n // Lazy credential provider: the AWS SDK is Node/server-only, so we defer the\n // dynamic import until SigV4 actually needs to resolve credentials. The\n // specifier is held in a variable (not a string literal) so bundler dep\n // scanners (e.g. Vite/esbuild optimizeDeps) cannot statically discover the\n // AWS SDK and try to pre-bundle it for the browser — it would fail on the\n // SDK's Node-only `fromTokenFile` export chain. `typeof import(...)` is a\n // type-only reference (erased at emit) so we keep full typing.\n credentials: async (...args) => {\n const mod = '@aws-sdk/credential-providers'\n const { fromNodeProviderChain } =\n await importOptionalPeer<typeof CredentialProviders>(mod)\n return fromNodeProviderChain()(...args)\n },\n }\n}\n"],"mappings":";;AAMA,SAAgB,aAAa,UAAmC;CAC9D,OAAO,aAAa,WAAW,mBAAmB;AACpD;;;;;;AAgBA,eAAsB,mBAAsB,KAAyB;CACnE,IAAI;EACF,OAAQ,MAAM;;GAA0B;;CAC1C,SAAS,OAAO;EACd,MAAM,IAAI,MACR,wCAAwC,IAAI,gEACH,OACzC,EAAE,MAAM,CACV;CACF;AACF;AAEA,IAAM,iBAAiB;AAEvB,SAAS,oBAAwC;CAO/C,MAAM,MAAM,OAAO,YAAY,cAAc,QAAQ,MAAM,KAAA;CAC3D,KAAK,MAAM,SAAS,CAAC,KAAK,iBAAiB,KAAK,wBAAwB,GACtE,IAAI,SAAS,MAAM,KAAK,MAAM,IAAI,OAAO;AAG7C;AAiBA,SAAgB,mBACd,QACA,UACqB;CACrB,MAAM,OAAO,OAAO,QAAQ;CAC5B,MAAM,SAAS,OAAO,UAAU;CAEhC,IAAI,SAAS,SAAS;EACpB,MAAM,QAAQ,OAAO,UAAU,kBAAkB;EACjD,IAAI,OAAO,OAAO;GAAE,MAAM;GAAU;EAAM;EAC1C,IAAI,SAAS,UACX,MAAM,IAAI,MACR,qHAEF;CAEJ;CAEA,OAAO;EACL,MAAM;EACN;EACA,SAAS,aAAa,QAAQ;EAQ9B,aAAa,OAAO,GAAG,SAAS;GAE9B,MAAM,EAAE,0BACN,MAAM,mBAA+C,+BAAG;GAC1D,OAAO,sBAAsB,CAAC,CAAC,GAAG,IAAI;EACxC;CACF;AACF"}
|
package/dist/esm/utils/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveBedrockAuth } from "./auth.js";
|
|
2
2
|
import { createSigV4Fetch } from "./openai-sigv4-fetch.js";
|
|
3
3
|
import { mantlePathForModel } from "../api-compatibility.js";
|
|
4
|
-
|
|
4
|
+
// src/utils/client.ts
|
|
5
5
|
var DEFAULT_REGION = "us-east-1";
|
|
6
6
|
/** The OpenAI client requires a non-empty apiKey even when a signed fetch overrides Authorization. */
|
|
7
7
|
var SIGV4_PLACEHOLDER_KEY = "bedrock-sigv4";
|
|
@@ -41,7 +41,6 @@ function withBedrockDefaults(config, forced, model) {
|
|
|
41
41
|
function isBedrockOpenAIContextOverflow(error) {
|
|
42
42
|
return error.code === "validation_error" && error.message.includes("maximum context length");
|
|
43
43
|
}
|
|
44
|
-
//#endregion
|
|
45
44
|
export { isBedrockOpenAIContextOverflow, resolveBedrockAuth, withBedrockDefaults };
|
|
46
45
|
|
|
47
46
|
//# sourceMappingURL=client.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { signSigV4 } from "./sigv4.js";
|
|
2
|
-
|
|
2
|
+
// src/utils/openai-sigv4-fetch.ts
|
|
3
3
|
/**
|
|
4
4
|
* Wraps a fetch so each request is SigV4-signed with the resolved AWS
|
|
5
5
|
* credentials (WebCrypto signer in `./sigv4`).
|
|
@@ -23,7 +23,6 @@ function createSigV4Fetch(auth, baseFetch = fetch) {
|
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
//#endregion
|
|
27
26
|
export { createSigV4Fetch };
|
|
28
27
|
|
|
29
28
|
//# sourceMappingURL=openai-sigv4-fetch.js.map
|
package/dist/esm/utils/sigv4.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/utils/sigv4.ts
|
|
2
2
|
var EMPTY_SHA256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
|
|
3
3
|
var UNSIGNABLE_HEADERS = /* @__PURE__ */ new Set([
|
|
4
4
|
"authorization",
|
|
@@ -127,7 +127,6 @@ async function signSigV4(request, credentials, options) {
|
|
|
127
127
|
headers.set("authorization", `AWS4-HMAC-SHA256 Credential=${credentials.accessKeyId}/${scope}, SignedHeaders=${signedHeaders}, Signature=${signature}`);
|
|
128
128
|
return headers;
|
|
129
129
|
}
|
|
130
|
-
//#endregion
|
|
131
130
|
export { signSigV4 };
|
|
132
131
|
|
|
133
132
|
//# sourceMappingURL=sigv4.js.map
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-bedrock",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Amazon Bedrock adapter for TanStack AI
|
|
5
|
+
"description": "Amazon Bedrock adapter for TanStack AI with chat, tools, reasoning, embeddings, and reranking.",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
"@aws-sdk/credential-providers": "^3.1057.0",
|
|
46
46
|
"@smithy/signature-v4": "^5.4.5",
|
|
47
47
|
"@smithy/types": "^4.14.2",
|
|
48
|
-
"@vitest/coverage-v8": "4.1.
|
|
49
|
-
"vite": "^8.
|
|
48
|
+
"@vitest/coverage-v8": "4.1.12",
|
|
49
|
+
"vite": "^8.3.8"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@aws-sdk/client-bedrock-runtime": "^3.1057.0",
|
|
53
53
|
"@aws-sdk/credential-providers": "^3.1057.0",
|
|
54
54
|
"@smithy/types": "^4.14.2",
|
|
55
|
-
"@tanstack/ai": "^1.
|
|
55
|
+
"@tanstack/ai": "^1.5.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@aws-sdk/client-bedrock-runtime": {
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"openai": "^7.30.0",
|
|
70
|
-
"@tanstack/openai-base": "^1.0.
|
|
70
|
+
"@tanstack/openai-base": "^1.0.4"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "vite build",
|
|
@@ -730,6 +730,12 @@ export class BedrockConverseTextAdapter<
|
|
|
730
730
|
...(toolConfig && { toolConfig }),
|
|
731
731
|
...(inferenceConfig && { inferenceConfig }),
|
|
732
732
|
...(additionalModelRequestFields && { additionalModelRequestFields }),
|
|
733
|
+
...(modelOptions?.requestMetadata !== undefined && {
|
|
734
|
+
requestMetadata: modelOptions.requestMetadata,
|
|
735
|
+
}),
|
|
736
|
+
...(modelOptions?.serviceTier !== undefined && {
|
|
737
|
+
serviceTier: { type: modelOptions.serviceTier },
|
|
738
|
+
}),
|
|
733
739
|
}
|
|
734
740
|
return addPromptCachePoints(this.model, input, options.promptCache)
|
|
735
741
|
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { BaseRerankAdapter } from '@tanstack/ai/adapters'
|
|
2
|
+
import { toRunErrorPayload } from '@tanstack/ai/adapter-internals'
|
|
3
|
+
import { resolveBedrockAuth } from '../utils/auth'
|
|
4
|
+
import { createSigV4Fetch } from '../utils/openai-sigv4-fetch'
|
|
5
|
+
import type { RerankAdapterResult, RerankOptions } from '@tanstack/ai'
|
|
6
|
+
import type { BedrockRerankModel } from '../model-meta'
|
|
7
|
+
|
|
8
|
+
/** Bedrock rerank uses AWS credentials, not Bedrock API keys. */
|
|
9
|
+
export interface BedrockRerankConfig {
|
|
10
|
+
/** AWS region; defaults to us-east-1. Amazon Rerank requires another region. */
|
|
11
|
+
region?: string
|
|
12
|
+
/** Overrides the agent-runtime base URL, without the /rerank suffix. */
|
|
13
|
+
baseURL?: string
|
|
14
|
+
/** Headers added before SigV4 signing. */
|
|
15
|
+
defaultHeaders?: Record<string, string>
|
|
16
|
+
/** Custom transport; requests are still SigV4-signed. */
|
|
17
|
+
fetch?: typeof fetch
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Additional inference fields for the selected Bedrock rerank model. */
|
|
21
|
+
export interface BedrockRerankProviderOptions {
|
|
22
|
+
additionalModelRequestFields?: Record<string, unknown>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface BedrockRerankResponse {
|
|
26
|
+
results: Array<{ index: number; relevanceScore: number }>
|
|
27
|
+
nextToken?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isBedrockRerankResponse(
|
|
31
|
+
value: unknown,
|
|
32
|
+
): value is BedrockRerankResponse {
|
|
33
|
+
return (
|
|
34
|
+
typeof value === 'object' &&
|
|
35
|
+
value !== null &&
|
|
36
|
+
'results' in value &&
|
|
37
|
+
Array.isArray(value.results) &&
|
|
38
|
+
value.results.every(
|
|
39
|
+
(result) =>
|
|
40
|
+
typeof result === 'object' &&
|
|
41
|
+
result !== null &&
|
|
42
|
+
Number.isInteger(result.index) &&
|
|
43
|
+
Number.isFinite(result.relevanceScore),
|
|
44
|
+
) &&
|
|
45
|
+
(!('nextToken' in value) ||
|
|
46
|
+
(typeof value.nextToken === 'string' &&
|
|
47
|
+
value.nextToken.length > 0 &&
|
|
48
|
+
value.nextToken.length <= 2048 &&
|
|
49
|
+
!/\s/.test(value.nextToken)))
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Bedrock rerank adapter; core maps scored indices to original documents. */
|
|
54
|
+
export class BedrockRerankAdapter<
|
|
55
|
+
TModel extends BedrockRerankModel,
|
|
56
|
+
> extends BaseRerankAdapter<TModel, BedrockRerankProviderOptions> {
|
|
57
|
+
readonly name = 'bedrock' as const
|
|
58
|
+
private readonly region: string
|
|
59
|
+
private readonly baseURL: string
|
|
60
|
+
private readonly clientConfig: BedrockRerankConfig
|
|
61
|
+
|
|
62
|
+
constructor(config: BedrockRerankConfig, model: TModel) {
|
|
63
|
+
super({}, model)
|
|
64
|
+
this.clientConfig = config
|
|
65
|
+
this.region = config.region ?? 'us-east-1'
|
|
66
|
+
this.baseURL = (
|
|
67
|
+
config.baseURL ??
|
|
68
|
+
`https://bedrock-agent-runtime.${this.region}.amazonaws.com`
|
|
69
|
+
).replace(/\/+$/, '')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async rerank(
|
|
73
|
+
options: RerankOptions<BedrockRerankProviderOptions>,
|
|
74
|
+
): Promise<RerankAdapterResult> {
|
|
75
|
+
const { model, query, documents, topN, modelOptions, abortSignal, logger } =
|
|
76
|
+
options
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
if (documents.length < 1 || documents.length > 1000) {
|
|
80
|
+
throw new Error('Bedrock rerank requires between 1 and 1000 documents')
|
|
81
|
+
}
|
|
82
|
+
const numberOfResults = topN ?? documents.length
|
|
83
|
+
if (
|
|
84
|
+
!Number.isInteger(numberOfResults) ||
|
|
85
|
+
numberOfResults < 1 ||
|
|
86
|
+
numberOfResults > 1000
|
|
87
|
+
) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
'Bedrock rerank topN must be an integer between 1 and 1000',
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const body = {
|
|
94
|
+
queries: [{ type: 'TEXT', textQuery: { text: query } }],
|
|
95
|
+
sources: documents.map((text) => ({
|
|
96
|
+
type: 'INLINE',
|
|
97
|
+
inlineDocumentSource: { type: 'TEXT', textDocument: { text } },
|
|
98
|
+
})),
|
|
99
|
+
rerankingConfiguration: {
|
|
100
|
+
type: 'BEDROCK_RERANKING_MODEL',
|
|
101
|
+
bedrockRerankingConfiguration: {
|
|
102
|
+
modelConfiguration: {
|
|
103
|
+
modelArn: `arn:aws:bedrock:${this.region}::foundation-model/${model}`,
|
|
104
|
+
additionalModelRequestFields:
|
|
105
|
+
modelOptions?.additionalModelRequestFields,
|
|
106
|
+
},
|
|
107
|
+
numberOfResults,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
const signedFetch = createSigV4Fetch(
|
|
112
|
+
resolveBedrockAuth({ region: this.region, auth: 'sigv4' }, 'runtime'),
|
|
113
|
+
this.clientConfig.fetch,
|
|
114
|
+
)
|
|
115
|
+
const ranking: RerankAdapterResult['ranking'] = []
|
|
116
|
+
const seenTokens = new Set<string>()
|
|
117
|
+
let nextToken: string | undefined
|
|
118
|
+
let id: string | undefined
|
|
119
|
+
|
|
120
|
+
do {
|
|
121
|
+
abortSignal?.throwIfAborted()
|
|
122
|
+
logger.request(
|
|
123
|
+
`activity=rerank provider=${this.name} model=${model} documents=${documents.length}`,
|
|
124
|
+
{ provider: this.name, model },
|
|
125
|
+
)
|
|
126
|
+
const response = await signedFetch(`${this.baseURL}/rerank`, {
|
|
127
|
+
method: 'POST',
|
|
128
|
+
headers: {
|
|
129
|
+
'Content-Type': 'application/json',
|
|
130
|
+
...this.clientConfig.defaultHeaders,
|
|
131
|
+
},
|
|
132
|
+
body: JSON.stringify({ ...body, nextToken }),
|
|
133
|
+
signal: abortSignal,
|
|
134
|
+
})
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
const detail = await response.text()
|
|
137
|
+
throw new Error(
|
|
138
|
+
`Bedrock rerank request failed: ${response.status} ${response.statusText}${detail ? `: ${detail}` : ''}`,
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
const page: unknown = await response.json()
|
|
142
|
+
abortSignal?.throwIfAborted()
|
|
143
|
+
if (!isBedrockRerankResponse(page)) {
|
|
144
|
+
throw new Error('Bedrock rerank response had an unexpected shape')
|
|
145
|
+
}
|
|
146
|
+
id ??= response.headers.get('x-amzn-requestid') ?? undefined
|
|
147
|
+
ranking.push(
|
|
148
|
+
...page.results.map((result) => ({
|
|
149
|
+
index: result.index,
|
|
150
|
+
score: result.relevanceScore,
|
|
151
|
+
})),
|
|
152
|
+
)
|
|
153
|
+
nextToken = page.nextToken
|
|
154
|
+
if (nextToken) {
|
|
155
|
+
if (seenTokens.has(nextToken)) {
|
|
156
|
+
throw new Error('Bedrock rerank pagination did not advance')
|
|
157
|
+
}
|
|
158
|
+
seenTokens.add(nextToken)
|
|
159
|
+
}
|
|
160
|
+
} while (nextToken && ranking.length < numberOfResults)
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
id: id ?? this.generateId(),
|
|
164
|
+
ranking: ranking.slice(0, numberOfResults),
|
|
165
|
+
// The Bedrock Rerank API reports neither token counts nor billed units.
|
|
166
|
+
usage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
logger.errors(`${this.name}.rerank fatal`, {
|
|
170
|
+
error: toRunErrorPayload(error, 'Bedrock rerank failed'),
|
|
171
|
+
source: `${this.name}.rerank`,
|
|
172
|
+
})
|
|
173
|
+
throw error
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Creates a Bedrock rerank adapter using the AWS credential chain (SigV4).
|
|
180
|
+
* Install `@aws-sdk/credential-providers`; Bedrock API keys are not supported.
|
|
181
|
+
* For `amazon.rerank-v1:0`, select a supported region such as `us-west-2`.
|
|
182
|
+
*/
|
|
183
|
+
export function bedrockRerank<TModel extends BedrockRerankModel>(
|
|
184
|
+
model: TModel,
|
|
185
|
+
config?: BedrockRerankConfig,
|
|
186
|
+
): BedrockRerankAdapter<TModel> {
|
|
187
|
+
return new BedrockRerankAdapter(config ?? {}, model)
|
|
188
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import type { ServiceTierType } from '@aws-sdk/client-bedrock-runtime'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Provider options honored by the Bedrock **Converse** path. Deliberately
|
|
3
5
|
* narrower than the OpenAI-compatible `BedrockTextProviderOptions`: the Converse
|
|
4
|
-
* API
|
|
5
|
-
*
|
|
6
|
+
* API accepts these sampling knobs (mapped into `inferenceConfig`) and request
|
|
7
|
+
* options. Advertising the full Chat Completions option set would promise fields —
|
|
6
8
|
* `frequency_penalty`, `seed`, `logit_bias`, `tool_choice`, `reasoning_effort`,
|
|
7
|
-
* etc. — that Converse silently ignores.
|
|
9
|
+
* etc. — that Converse silently ignores. Sampling field names mirror the Chat
|
|
8
10
|
* Completions shape so callers have one mental model across the three APIs.
|
|
9
11
|
*/
|
|
10
12
|
export interface BedrockConverseProviderOptions {
|
|
@@ -16,4 +18,8 @@ export interface BedrockConverseProviderOptions {
|
|
|
16
18
|
max_completion_tokens?: number | null
|
|
17
19
|
/** Forwarded to Converse `inferenceConfig.stopSequences`. */
|
|
18
20
|
stop?: string | Array<string> | null
|
|
21
|
+
/** Request metadata for filtering Bedrock model invocation logs. */
|
|
22
|
+
requestMetadata?: Record<string, string>
|
|
23
|
+
/** Inference service tier, forwarded to Converse `serviceTier.type`. */
|
|
24
|
+
serviceTier?: ServiceTierType
|
|
19
25
|
}
|