@tanstack/ai-bedrock 0.0.1
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 +95 -0
- package/dist/esm/adapters/converse-text.d.ts +93 -0
- package/dist/esm/adapters/converse-text.js +430 -0
- package/dist/esm/adapters/converse-text.js.map +1 -0
- package/dist/esm/adapters/responses-text.d.ts +23 -0
- package/dist/esm/adapters/responses-text.js +22 -0
- package/dist/esm/adapters/responses-text.js.map +1 -0
- package/dist/esm/adapters/text.d.ts +30 -0
- package/dist/esm/adapters/text.js +38 -0
- package/dist/esm/adapters/text.js.map +1 -0
- package/dist/esm/converse/message-converter.d.ts +14 -0
- package/dist/esm/converse/message-converter.js +181 -0
- package/dist/esm/converse/message-converter.js.map +1 -0
- package/dist/esm/converse/provider-options.d.ts +19 -0
- package/dist/esm/converse/stream-processor.d.ts +46 -0
- package/dist/esm/converse/stream-processor.js +203 -0
- package/dist/esm/converse/stream-processor.js.map +1 -0
- package/dist/esm/converse/structured-output.d.ts +8 -0
- package/dist/esm/converse/structured-output.js +20 -0
- package/dist/esm/converse/structured-output.js.map +1 -0
- package/dist/esm/converse/tool-converter.d.ts +11 -0
- package/dist/esm/converse/tool-converter.js +21 -0
- package/dist/esm/converse/tool-converter.js.map +1 -0
- package/dist/esm/index.d.ts +29 -0
- package/dist/esm/index.js +62 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/message-types.d.ts +25 -0
- package/dist/esm/model-catalog.generated.d.ts +127 -0
- package/dist/esm/model-catalog.generated.js +90 -0
- package/dist/esm/model-catalog.generated.js.map +1 -0
- package/dist/esm/model-meta.d.ts +38 -0
- package/dist/esm/model-meta.js +14 -0
- package/dist/esm/model-meta.js.map +1 -0
- package/dist/esm/text/responses-provider-options.d.ts +29 -0
- package/dist/esm/text/text-provider-options.d.ts +36 -0
- package/dist/esm/utils/auth.d.ts +20 -0
- package/dist/esm/utils/auth.js +49 -0
- package/dist/esm/utils/auth.js.map +1 -0
- package/dist/esm/utils/client.d.ts +19 -0
- package/dist/esm/utils/client.js +35 -0
- package/dist/esm/utils/client.js.map +1 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/openai-sigv4-fetch.d.ts +10 -0
- package/dist/esm/utils/openai-sigv4-fetch.js +35 -0
- package/dist/esm/utils/openai-sigv4-fetch.js.map +1 -0
- package/package.json +67 -0
- package/src/adapters/converse-text.ts +603 -0
- package/src/adapters/responses-text.ts +73 -0
- package/src/adapters/text.ts +97 -0
- package/src/converse/message-converter.ts +268 -0
- package/src/converse/provider-options.ts +19 -0
- package/src/converse/stream-processor.ts +309 -0
- package/src/converse/structured-output.ts +24 -0
- package/src/converse/tool-converter.ts +49 -0
- package/src/index.ts +190 -0
- package/src/message-types.ts +24 -0
- package/src/model-catalog.generated.ts +88 -0
- package/src/model-meta.ts +69 -0
- package/src/text/responses-provider-options.ts +28 -0
- package/src/text/text-provider-options.ts +33 -0
- package/src/utils/auth.ts +80 -0
- package/src/utils/client.ts +62 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/openai-sigv4-fetch.ts +55 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const GENERATED_BEDROCK_MODELS = [
|
|
2
|
+
{
|
|
3
|
+
id: "openai.gpt-oss-120b-1:0",
|
|
4
|
+
input: ["text"],
|
|
5
|
+
output: ["text"],
|
|
6
|
+
apis: { converse: true, chat: true, responses: true }
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
id: "openai.gpt-oss-20b-1:0",
|
|
10
|
+
input: ["text"],
|
|
11
|
+
output: ["text"],
|
|
12
|
+
apis: { converse: true, chat: true, responses: true }
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
|
|
16
|
+
input: ["text", "image", "document"],
|
|
17
|
+
output: ["text"],
|
|
18
|
+
apis: { converse: true, chat: false, responses: false }
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "us.anthropic.claude-haiku-4-5-20251001-v1:0",
|
|
22
|
+
input: ["text", "image", "document"],
|
|
23
|
+
output: ["text"],
|
|
24
|
+
apis: { converse: true, chat: false, responses: false }
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
|
|
28
|
+
input: ["text", "image", "document"],
|
|
29
|
+
output: ["text"],
|
|
30
|
+
apis: { converse: true, chat: false, responses: false }
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "us.anthropic.claude-3-5-sonnet-20241022-v2:0",
|
|
34
|
+
input: ["text", "image", "document"],
|
|
35
|
+
output: ["text"],
|
|
36
|
+
apis: { converse: true, chat: false, responses: false }
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "us.anthropic.claude-3-5-haiku-20241022-v1:0",
|
|
40
|
+
input: ["text"],
|
|
41
|
+
output: ["text"],
|
|
42
|
+
apis: { converse: true, chat: false, responses: false }
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "us.amazon.nova-pro-v1:0",
|
|
46
|
+
input: ["text", "image", "document"],
|
|
47
|
+
output: ["text"],
|
|
48
|
+
apis: { converse: true, chat: false, responses: false }
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: "us.amazon.nova-lite-v1:0",
|
|
52
|
+
input: ["text", "image", "document"],
|
|
53
|
+
output: ["text"],
|
|
54
|
+
apis: { converse: true, chat: false, responses: false }
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "us.amazon.nova-micro-v1:0",
|
|
58
|
+
input: ["text"],
|
|
59
|
+
output: ["text"],
|
|
60
|
+
apis: { converse: true, chat: false, responses: false }
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: "us.meta.llama3-3-70b-instruct-v1:0",
|
|
64
|
+
input: ["text"],
|
|
65
|
+
output: ["text"],
|
|
66
|
+
apis: { converse: true, chat: false, responses: false }
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "us.meta.llama4-maverick-17b-instruct-v1:0",
|
|
70
|
+
input: ["text", "image"],
|
|
71
|
+
output: ["text"],
|
|
72
|
+
apis: { converse: true, chat: false, responses: false }
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: "us.mistral.pixtral-large-2502-v1:0",
|
|
76
|
+
input: ["text", "image"],
|
|
77
|
+
output: ["text"],
|
|
78
|
+
apis: { converse: true, chat: false, responses: false }
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "us.deepseek.r1-v1:0",
|
|
82
|
+
input: ["text"],
|
|
83
|
+
output: ["text"],
|
|
84
|
+
apis: { converse: true, chat: false, responses: false }
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
export {
|
|
88
|
+
GENERATED_BEDROCK_MODELS
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=model-catalog.generated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-catalog.generated.js","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"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { GENERATED_BEDROCK_MODELS } from './model-catalog.generated';
|
|
2
|
+
import { BedrockTextProviderOptions } from './text/text-provider-options.js';
|
|
3
|
+
import { BedrockConverseProviderOptions } from './converse/provider-options.js';
|
|
4
|
+
type Entry = (typeof GENERATED_BEDROCK_MODELS)[number];
|
|
5
|
+
/**
|
|
6
|
+
* Type-level per-API filter over the generated catalog. Because the catalog is
|
|
7
|
+
* `as const`, `Extract` preserves literal `id` unions (no widening to `string`).
|
|
8
|
+
*/
|
|
9
|
+
type IdsWhere<TApi extends 'converse' | 'chat' | 'responses'> = Extract<Entry, {
|
|
10
|
+
apis: Record<TApi, true>;
|
|
11
|
+
}>['id'];
|
|
12
|
+
export type BedrockConverseModels = IdsWhere<'converse'>;
|
|
13
|
+
export type BedrockChatModels = IdsWhere<'chat'>;
|
|
14
|
+
export type BedrockResponsesModels = IdsWhere<'responses'>;
|
|
15
|
+
/** Runtime catalogs. Cast-free narrowing via a type predicate (the ai-bedrock pattern). */
|
|
16
|
+
export declare const BEDROCK_CONVERSE_MODELS: ReadonlyArray<BedrockConverseModels>;
|
|
17
|
+
export declare const BEDROCK_CHAT_MODELS: ReadonlyArray<BedrockChatModels>;
|
|
18
|
+
export declare const BEDROCK_RESPONSES_MODELS: ReadonlyArray<BedrockResponsesModels>;
|
|
19
|
+
/** Per-model input modalities (drives type-safe multimodal content). Covers ALL models. */
|
|
20
|
+
export type BedrockModelInputModalitiesByName = {
|
|
21
|
+
[E in Entry as E['id']]: E['input'];
|
|
22
|
+
};
|
|
23
|
+
/** Provider options per model. Same options for every model; keyed over the full catalog. */
|
|
24
|
+
export type BedrockChatModelProviderOptionsByName = {
|
|
25
|
+
[E in Entry as E['id']]: BedrockTextProviderOptions;
|
|
26
|
+
};
|
|
27
|
+
/** Converse provider options per model (narrower than the Chat Completions set). */
|
|
28
|
+
export type BedrockConverseModelProviderOptionsByName = {
|
|
29
|
+
[E in Entry as E['id']]: BedrockConverseProviderOptions;
|
|
30
|
+
};
|
|
31
|
+
/** No provider-specific tools — empty tuple makes cross-provider ProviderTool a compile error. */
|
|
32
|
+
export type BedrockChatModelToolCapabilitiesByName = {
|
|
33
|
+
[E in Entry as E['id']]: readonly [];
|
|
34
|
+
};
|
|
35
|
+
export type ResolveProviderOptions<TModel extends string> = TModel extends keyof BedrockChatModelProviderOptionsByName ? BedrockChatModelProviderOptionsByName[TModel] : BedrockTextProviderOptions;
|
|
36
|
+
export type ResolveConverseProviderOptions<TModel extends string> = TModel extends keyof BedrockConverseModelProviderOptionsByName ? BedrockConverseModelProviderOptionsByName[TModel] : BedrockConverseProviderOptions;
|
|
37
|
+
export type ResolveInputModalities<TModel extends string> = TModel extends keyof BedrockModelInputModalitiesByName ? BedrockModelInputModalitiesByName[TModel] : readonly ['text'];
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GENERATED_BEDROCK_MODELS } from "./model-catalog.generated.js";
|
|
2
|
+
const BEDROCK_CONVERSE_MODELS = GENERATED_BEDROCK_MODELS.map((m) => m.id);
|
|
3
|
+
const BEDROCK_CHAT_MODELS = GENERATED_BEDROCK_MODELS.filter(
|
|
4
|
+
(m) => m.apis.chat
|
|
5
|
+
).map((m) => m.id);
|
|
6
|
+
const BEDROCK_RESPONSES_MODELS = GENERATED_BEDROCK_MODELS.filter(
|
|
7
|
+
(m) => m.apis.responses
|
|
8
|
+
).map((m) => m.id);
|
|
9
|
+
export {
|
|
10
|
+
BEDROCK_CHAT_MODELS,
|
|
11
|
+
BEDROCK_CONVERSE_MODELS,
|
|
12
|
+
BEDROCK_RESPONSES_MODELS
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=model-meta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-meta.js","sources":["../../src/model-meta.ts"],"sourcesContent":["import { GENERATED_BEDROCK_MODELS } from './model-catalog.generated'\nimport type { BedrockTextProviderOptions } from './text/text-provider-options'\nimport type { BedrockConverseProviderOptions } from './converse/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). */\n// Every catalog entry advertises `converse: true` (Converse is the universal\n// Bedrock surface), so the id list is the full catalog — no runtime filter needed.\nexport const BEDROCK_CONVERSE_MODELS: ReadonlyArray<BedrockConverseModels> =\n GENERATED_BEDROCK_MODELS.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"],"names":[],"mappings":";AAsBO,MAAM,0BACX,yBAAyB,IAAI,CAAC,MAAM,EAAE,EAAE;AAEnC,MAAM,sBACX,yBAAyB;AAAA,EACvB,CAAC,MAAqD,EAAE,KAAK;AAC/D,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE;AAEZ,MAAM,2BACX,yBAAyB;AAAA,EACvB,CAAC,MAA0D,EAAE,KAAK;AACpE,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bedrock Responses API provider options. Mantle's Responses endpoint adds
|
|
3
|
+
* stateful conversation management on top of the OpenAI Responses fields.
|
|
4
|
+
*
|
|
5
|
+
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-mantle.html
|
|
6
|
+
*/
|
|
7
|
+
export interface BedrockResponsesProviderOptions {
|
|
8
|
+
/** Continue a stored conversation from a prior response. */
|
|
9
|
+
previous_response_id?: string | null;
|
|
10
|
+
/** Whether Bedrock retains the response for 30 days (default true). Set false to opt out. */
|
|
11
|
+
store?: boolean | null;
|
|
12
|
+
metadata?: {
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
} | null;
|
|
15
|
+
max_output_tokens?: number | null;
|
|
16
|
+
temperature?: number | null;
|
|
17
|
+
top_p?: number | null;
|
|
18
|
+
parallel_tool_calls?: boolean | null;
|
|
19
|
+
tool_choice?: 'none' | 'auto' | 'required' | {
|
|
20
|
+
type: 'function';
|
|
21
|
+
name: string;
|
|
22
|
+
} | null;
|
|
23
|
+
/** Reasoning controls for reasoning-capable models. */
|
|
24
|
+
reasoning?: {
|
|
25
|
+
effort?: 'low' | 'medium' | 'high';
|
|
26
|
+
} | null;
|
|
27
|
+
user?: string | null;
|
|
28
|
+
}
|
|
29
|
+
export type ExternalResponsesProviderOptions = BedrockResponsesProviderOptions;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bedrock Chat Completions provider options. Bedrock accepts the standard
|
|
3
|
+
* OpenAI Chat Completions request fields; we surface the commonly-used ones
|
|
4
|
+
* plus `reasoning_effort` (supported by gpt-oss and reasoning models).
|
|
5
|
+
*
|
|
6
|
+
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-openai.html
|
|
7
|
+
*/
|
|
8
|
+
export interface BedrockTextProviderOptions {
|
|
9
|
+
frequency_penalty?: number | null;
|
|
10
|
+
presence_penalty?: number | null;
|
|
11
|
+
logit_bias?: {
|
|
12
|
+
[token: string]: number;
|
|
13
|
+
} | null;
|
|
14
|
+
logprobs?: boolean | null;
|
|
15
|
+
top_logprobs?: number | null;
|
|
16
|
+
max_completion_tokens?: number | null;
|
|
17
|
+
metadata?: {
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
} | null;
|
|
20
|
+
n?: number | null;
|
|
21
|
+
parallel_tool_calls?: boolean | null;
|
|
22
|
+
/** gpt-oss / reasoning models: 'low' | 'medium' (default) | 'high'. */
|
|
23
|
+
reasoning_effort?: 'low' | 'medium' | 'high' | null;
|
|
24
|
+
seed?: number | null;
|
|
25
|
+
stop?: string | Array<string> | null;
|
|
26
|
+
temperature?: number | null;
|
|
27
|
+
tool_choice?: 'none' | 'auto' | 'required' | {
|
|
28
|
+
type: 'function';
|
|
29
|
+
function: {
|
|
30
|
+
name: string;
|
|
31
|
+
};
|
|
32
|
+
} | null;
|
|
33
|
+
top_p?: number | null;
|
|
34
|
+
user?: string | null;
|
|
35
|
+
}
|
|
36
|
+
export type ExternalTextProviderOptions = BedrockTextProviderOptions;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AwsCredentialIdentityProvider } from '@smithy/types';
|
|
2
|
+
export type BedrockEndpoint = 'runtime' | 'mantle';
|
|
3
|
+
/** SigV4 service name differs per endpoint. */
|
|
4
|
+
export declare function sigv4Service(endpoint: BedrockEndpoint): string;
|
|
5
|
+
export type ResolvedBedrockAuth = {
|
|
6
|
+
kind: 'bearer';
|
|
7
|
+
token: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'sigv4';
|
|
10
|
+
region: string;
|
|
11
|
+
service: string;
|
|
12
|
+
credentials: AwsCredentialIdentityProvider;
|
|
13
|
+
};
|
|
14
|
+
export interface BedrockAuthConfig {
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
region?: string;
|
|
17
|
+
auth?: 'apikey' | 'sigv4' | 'auto';
|
|
18
|
+
}
|
|
19
|
+
/** apiKey -> BEDROCK_API_KEY -> AWS_BEARER_TOKEN_BEDROCK -> SigV4 (credential chain). */
|
|
20
|
+
export declare function resolveBedrockAuth(config: BedrockAuthConfig, endpoint: BedrockEndpoint): ResolvedBedrockAuth;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
function sigv4Service(endpoint) {
|
|
2
|
+
return endpoint === "mantle" ? "bedrock-mantle" : "bedrock";
|
|
3
|
+
}
|
|
4
|
+
const DEFAULT_REGION = "us-east-1";
|
|
5
|
+
function readApiKeyFromEnv() {
|
|
6
|
+
const env = typeof process !== "undefined" ? process.env : void 0;
|
|
7
|
+
for (const value of [env?.BEDROCK_API_KEY, env?.AWS_BEARER_TOKEN_BEDROCK]) {
|
|
8
|
+
if (value && value.trim() !== "") return value;
|
|
9
|
+
}
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
function resolveBedrockAuth(config, endpoint) {
|
|
13
|
+
const mode = config.auth ?? "auto";
|
|
14
|
+
const region = config.region ?? DEFAULT_REGION;
|
|
15
|
+
if (mode !== "sigv4") {
|
|
16
|
+
const token = config.apiKey ?? readApiKeyFromEnv();
|
|
17
|
+
if (token) return { kind: "bearer", token };
|
|
18
|
+
if (mode === "apikey") {
|
|
19
|
+
throw new Error(
|
|
20
|
+
'No Bedrock API key found. Set BEDROCK_API_KEY (or AWS_BEARER_TOKEN_BEDROCK), pass `apiKey`, or use auth: "sigv4".'
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
kind: "sigv4",
|
|
26
|
+
region,
|
|
27
|
+
service: sigv4Service(endpoint),
|
|
28
|
+
// Lazy credential provider: the AWS SDK is Node/server-only, so we defer the
|
|
29
|
+
// dynamic import until SigV4 actually needs to resolve credentials. The
|
|
30
|
+
// specifier is held in a variable (not a string literal) so bundler dep
|
|
31
|
+
// scanners (e.g. Vite/esbuild optimizeDeps) cannot statically discover the
|
|
32
|
+
// AWS SDK and try to pre-bundle it for the browser — it would fail on the
|
|
33
|
+
// SDK's Node-only `fromTokenFile` export chain. `typeof import(...)` is a
|
|
34
|
+
// type-only reference (erased at emit) so we keep full typing.
|
|
35
|
+
credentials: async (...args) => {
|
|
36
|
+
const mod = "@aws-sdk/credential-providers";
|
|
37
|
+
const { fromNodeProviderChain } = await import(
|
|
38
|
+
/* @vite-ignore */
|
|
39
|
+
mod
|
|
40
|
+
);
|
|
41
|
+
return fromNodeProviderChain()(...args);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
resolveBedrockAuth,
|
|
47
|
+
sigv4Service
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","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\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 } = (await import(\n /* @vite-ignore */ mod\n )) as typeof CredentialProviders\n return fromNodeProviderChain()(...args)\n },\n }\n}\n"],"names":[],"mappings":"AAMO,SAAS,aAAa,UAAmC;AAC9D,SAAO,aAAa,WAAW,mBAAmB;AACpD;AAWA,MAAM,iBAAiB;AAEvB,SAAS,oBAAwC;AAO/C,QAAM,MAAM,OAAO,YAAY,cAAc,QAAQ,MAAM;AAC3D,aAAW,SAAS,CAAC,KAAK,iBAAiB,KAAK,wBAAwB,GAAG;AACzE,QAAI,SAAS,MAAM,KAAA,MAAW,GAAI,QAAO;AAAA,EAC3C;AACA,SAAO;AACT;AASO,SAAS,mBACd,QACA,UACqB;AACrB,QAAM,OAAO,OAAO,QAAQ;AAC5B,QAAM,SAAS,OAAO,UAAU;AAEhC,MAAI,SAAS,SAAS;AACpB,UAAM,QAAQ,OAAO,UAAU,kBAAA;AAC/B,QAAI,MAAO,QAAO,EAAE,MAAM,UAAU,MAAA;AACpC,QAAI,SAAS,UAAU;AACrB,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,IAGJ;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA,SAAS,aAAa,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQ9B,aAAa,UAAU,SAAS;AAC9B,YAAM,MAAM;AACZ,YAAM,EAAE,sBAAA,IAA2B,MAAM;AAAA;AAAA,QACpB;AAAA;AAErB,aAAO,sBAAA,EAAwB,GAAG,IAAI;AAAA,IACxC;AAAA,EAAA;AAEJ;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ClientOptions } from 'openai';
|
|
2
|
+
import { BedrockEndpoint } from './auth.js';
|
|
3
|
+
export type { BedrockEndpoint } from './auth.js';
|
|
4
|
+
export { resolveBedrockAuth } from './auth.js';
|
|
5
|
+
export type { ResolvedBedrockAuth } from './auth.js';
|
|
6
|
+
export interface BedrockClientConfig extends Omit<ClientOptions, 'apiKey' | 'baseURL'> {
|
|
7
|
+
/** Bedrock API key (bearer). Optional — falls back to env, then SigV4. */
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
/** Full AWS region (e.g. 'us-east-1'). Default 'us-east-1'. */
|
|
10
|
+
region?: string;
|
|
11
|
+
/** Chat adapter only; the responses adapter forces 'mantle'. Default 'runtime'. */
|
|
12
|
+
endpoint?: BedrockEndpoint;
|
|
13
|
+
/** Auth strategy. Default 'auto' (apiKey → env → SigV4). */
|
|
14
|
+
auth?: 'apikey' | 'sigv4' | 'auto';
|
|
15
|
+
/** Explicit override; wins over the computed endpoint URL (used by E2E → aimock). */
|
|
16
|
+
baseURL?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Builds OpenAI ClientOptions for the requested endpoint. `forced` pins the endpoint (responses → 'mantle'). */
|
|
19
|
+
export declare function withBedrockDefaults(config: BedrockClientConfig, forced?: BedrockEndpoint): ClientOptions;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { resolveBedrockAuth } from "./auth.js";
|
|
2
|
+
import { createSigV4Fetch } from "./openai-sigv4-fetch.js";
|
|
3
|
+
const DEFAULT_REGION = "us-east-1";
|
|
4
|
+
const SIGV4_PLACEHOLDER_KEY = "bedrock-sigv4";
|
|
5
|
+
function buildBaseURL(region, endpoint) {
|
|
6
|
+
return endpoint === "mantle" ? `https://bedrock-mantle.${region}.api.aws/v1` : `https://bedrock-runtime.${region}.amazonaws.com/openai/v1`;
|
|
7
|
+
}
|
|
8
|
+
function withBedrockDefaults(config, forced) {
|
|
9
|
+
const { region, endpoint, auth, apiKey, baseURL, fetch, ...rest } = config;
|
|
10
|
+
const resolvedRegion = region ?? DEFAULT_REGION;
|
|
11
|
+
const resolvedEndpoint = forced ?? endpoint ?? "runtime";
|
|
12
|
+
const resolved = resolveBedrockAuth(
|
|
13
|
+
{ apiKey, region: resolvedRegion, auth },
|
|
14
|
+
resolvedEndpoint
|
|
15
|
+
);
|
|
16
|
+
if (resolved.kind === "bearer") {
|
|
17
|
+
return {
|
|
18
|
+
...rest,
|
|
19
|
+
baseURL: baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint),
|
|
20
|
+
apiKey: resolved.token,
|
|
21
|
+
...fetch ? { fetch } : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
...rest,
|
|
26
|
+
baseURL: baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint),
|
|
27
|
+
apiKey: SIGV4_PLACEHOLDER_KEY,
|
|
28
|
+
fetch: fetch ?? createSigV4Fetch(resolved)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
resolveBedrockAuth,
|
|
33
|
+
withBedrockDefaults
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","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, endpoint: BedrockEndpoint): string {\n return endpoint === 'mantle'\n ? `https://bedrock-mantle.${region}.api.aws/v1`\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): 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 if (resolved.kind === 'bearer') {\n return {\n ...rest,\n baseURL: baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint),\n apiKey: resolved.token,\n ...(fetch ? { fetch } : {}),\n }\n }\n return {\n ...rest,\n baseURL: baseURL ?? buildBaseURL(resolvedRegion, resolvedEndpoint),\n apiKey: SIGV4_PLACEHOLDER_KEY,\n fetch: fetch ?? createSigV4Fetch(resolved),\n }\n}\n"],"names":[],"mappings":";;AAyBA,MAAM,iBAAiB;AAEvB,MAAM,wBAAwB;AAE9B,SAAS,aAAa,QAAgB,UAAmC;AACvE,SAAO,aAAa,WAChB,0BAA0B,MAAM,gBAChC,2BAA2B,MAAM;AACvC;AAGO,SAAS,oBACd,QACA,QACe;AACf,QAAM,EAAE,QAAQ,UAAU,MAAM,QAAQ,SAAS,OAAO,GAAG,KAAA,IAAS;AACpE,QAAM,iBAAiB,UAAU;AACjC,QAAM,mBAAmB,UAAU,YAAY;AAC/C,QAAM,WAAW;AAAA,IACf,EAAE,QAAQ,QAAQ,gBAAgB,KAAA;AAAA,IAClC;AAAA,EAAA;AAEF,MAAI,SAAS,SAAS,UAAU;AAC9B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,SAAS,WAAW,aAAa,gBAAgB,gBAAgB;AAAA,MACjE,QAAQ,SAAS;AAAA,MACjB,GAAI,QAAQ,EAAE,UAAU,CAAA;AAAA,IAAC;AAAA,EAE7B;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,SAAS,WAAW,aAAa,gBAAgB,gBAAgB;AAAA,IACjE,QAAQ;AAAA,IACR,OAAO,SAAS,iBAAiB,QAAQ;AAAA,EAAA;AAE7C;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveBedrockAuth, withBedrockDefaults, type BedrockClientConfig, type BedrockEndpoint, type ResolvedBedrockAuth, } from './client.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ResolvedBedrockAuth } from './auth.js';
|
|
2
|
+
type FetchLike = typeof fetch;
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a fetch so each request is SigV4-signed via the AWS signer that ships
|
|
5
|
+
* with `@aws-sdk/client-bedrock-runtime`. Replaces the old aws-sigv4-fetch peer.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createSigV4Fetch(auth: Extract<ResolvedBedrockAuth, {
|
|
8
|
+
kind: 'sigv4';
|
|
9
|
+
}>, baseFetch?: FetchLike): FetchLike;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SignatureV4 } from "@smithy/signature-v4";
|
|
2
|
+
import { Sha256 } from "@aws-crypto/sha256-js";
|
|
3
|
+
function createSigV4Fetch(auth, baseFetch = fetch) {
|
|
4
|
+
const signer = new SignatureV4({
|
|
5
|
+
service: auth.service,
|
|
6
|
+
region: auth.region,
|
|
7
|
+
credentials: auth.credentials,
|
|
8
|
+
sha256: Sha256
|
|
9
|
+
});
|
|
10
|
+
return async (input, init) => {
|
|
11
|
+
const href = typeof input === "string" ? input : input instanceof Request ? input.url : input.toString();
|
|
12
|
+
const url = new URL(href);
|
|
13
|
+
const headers = {};
|
|
14
|
+
new Headers(init?.headers).forEach((v, k) => headers[k] = v);
|
|
15
|
+
headers["host"] = url.host;
|
|
16
|
+
const body = init?.body ?? void 0;
|
|
17
|
+
const request = {
|
|
18
|
+
method: init?.method ?? "GET",
|
|
19
|
+
protocol: url.protocol,
|
|
20
|
+
hostname: url.hostname,
|
|
21
|
+
path: url.pathname + url.search,
|
|
22
|
+
headers,
|
|
23
|
+
body
|
|
24
|
+
};
|
|
25
|
+
const signed = await signer.sign(request);
|
|
26
|
+
return baseFetch(url.toString(), {
|
|
27
|
+
...init,
|
|
28
|
+
headers: signed.headers
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
createSigV4Fetch
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=openai-sigv4-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-sigv4-fetch.js","sources":["../../../src/utils/openai-sigv4-fetch.ts"],"sourcesContent":["import { SignatureV4 } from '@smithy/signature-v4'\nimport { Sha256 } from '@aws-crypto/sha256-js'\nimport type { HttpRequest } from '@smithy/types'\nimport type { ResolvedBedrockAuth } from './auth'\n\ntype FetchLike = typeof fetch\n\n/**\n * Wraps a fetch so each request is SigV4-signed via the AWS signer that ships\n * with `@aws-sdk/client-bedrock-runtime`. Replaces the old aws-sigv4-fetch peer.\n */\nexport function createSigV4Fetch(\n auth: Extract<ResolvedBedrockAuth, { kind: 'sigv4' }>,\n baseFetch: FetchLike = fetch,\n): FetchLike {\n const signer = new SignatureV4({\n service: auth.service,\n region: auth.region,\n credentials: auth.credentials,\n sha256: Sha256,\n })\n\n return async (input, init) => {\n // Request.toString() returns '[object Request]', not the URL — use .url instead.\n const href =\n typeof input === 'string'\n ? input\n : input instanceof Request\n ? input.url\n : input.toString()\n const url = new URL(href)\n const headers: Record<string, string> = {}\n new Headers(init?.headers).forEach((v, k) => (headers[k] = v))\n headers['host'] = url.host\n\n const body = init?.body ?? undefined\n\n // Construct a plain object satisfying the @smithy/types HttpRequest interface —\n // no @smithy/protocol-http needed.\n const request: HttpRequest = {\n method: init?.method ?? 'GET',\n protocol: url.protocol,\n hostname: url.hostname,\n path: url.pathname + url.search,\n headers,\n body,\n }\n\n const signed = await signer.sign(request)\n return baseFetch(url.toString(), {\n ...init,\n headers: signed.headers as Record<string, string>,\n })\n }\n}\n"],"names":[],"mappings":";;AAWO,SAAS,iBACd,MACA,YAAuB,OACZ;AACX,QAAM,SAAS,IAAI,YAAY;AAAA,IAC7B,SAAS,KAAK;AAAA,IACd,QAAQ,KAAK;AAAA,IACb,aAAa,KAAK;AAAA,IAClB,QAAQ;AAAA,EAAA,CACT;AAED,SAAO,OAAO,OAAO,SAAS;AAE5B,UAAM,OACJ,OAAO,UAAU,WACb,QACA,iBAAiB,UACf,MAAM,MACN,MAAM,SAAA;AACd,UAAM,MAAM,IAAI,IAAI,IAAI;AACxB,UAAM,UAAkC,CAAA;AACxC,QAAI,QAAQ,MAAM,OAAO,EAAE,QAAQ,CAAC,GAAG,MAAO,QAAQ,CAAC,IAAI,CAAE;AAC7D,YAAQ,MAAM,IAAI,IAAI;AAEtB,UAAM,OAAO,MAAM,QAAQ;AAI3B,UAAM,UAAuB;AAAA,MAC3B,QAAQ,MAAM,UAAU;AAAA,MACxB,UAAU,IAAI;AAAA,MACd,UAAU,IAAI;AAAA,MACd,MAAM,IAAI,WAAW,IAAI;AAAA,MACzB;AAAA,MACA;AAAA,IAAA;AAGF,UAAM,SAAS,MAAM,OAAO,KAAK,OAAO;AACxC,WAAO,UAAU,IAAI,YAAY;AAAA,MAC/B,GAAG;AAAA,MACH,SAAS,OAAO;AAAA,IAAA,CACjB;AAAA,EACH;AACF;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tanstack/ai-bedrock",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Amazon Bedrock adapter for TanStack AI — OpenAI-compatible chat, responses, tools, and reasoning.",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/TanStack/ai.git",
|
|
11
|
+
"directory": "packages/ai-bedrock"
|
|
12
|
+
},
|
|
13
|
+
"module": "./dist/esm/index.js",
|
|
14
|
+
"types": "./dist/esm/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/esm/index.d.ts",
|
|
18
|
+
"import": "./dist/esm/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"src"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "vite build",
|
|
27
|
+
"clean": "premove ./build ./dist",
|
|
28
|
+
"lint:fix": "eslint ./src --fix",
|
|
29
|
+
"test:build": "publint --strict",
|
|
30
|
+
"test:eslint": "eslint ./src",
|
|
31
|
+
"test:lib": "vitest run",
|
|
32
|
+
"test:lib:dev": "pnpm test:lib --watch",
|
|
33
|
+
"test:types": "tsc"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"ai",
|
|
37
|
+
"ai-sdk",
|
|
38
|
+
"typescript",
|
|
39
|
+
"tanstack",
|
|
40
|
+
"bedrock",
|
|
41
|
+
"aws",
|
|
42
|
+
"adapter",
|
|
43
|
+
"llm",
|
|
44
|
+
"chat",
|
|
45
|
+
"tool-calling"
|
|
46
|
+
],
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@vitest/coverage-v8": "4.0.14",
|
|
49
|
+
"vite": "^7.3.3"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@tanstack/ai": "workspace:*",
|
|
53
|
+
"zod": "^4.0.0"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@aws-crypto/sha256-js": "^5.2.0",
|
|
57
|
+
"@aws-sdk/client-bedrock-runtime": "^3.1057.0",
|
|
58
|
+
"@aws-sdk/credential-providers": "^3.1057.0",
|
|
59
|
+
"@smithy/signature-v4": "^5.4.5",
|
|
60
|
+
"@smithy/types": "^4.14.2",
|
|
61
|
+
"@tanstack/openai-base": "workspace:*",
|
|
62
|
+
"openai": "^6.41.0"
|
|
63
|
+
},
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"access": "public"
|
|
66
|
+
}
|
|
67
|
+
}
|