@tanstack/ai-bedrock 0.5.1 → 0.6.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/dist/esm/adapters/converse-text.d.ts +9 -2
- package/dist/esm/adapters/converse-text.js +115 -29
- package/dist/esm/adapters/converse-text.js.map +1 -1
- package/dist/esm/adapters/responses-text.d.ts +11 -2
- package/dist/esm/adapters/responses-text.js +10 -1
- package/dist/esm/adapters/responses-text.js.map +1 -1
- package/dist/esm/adapters/text.d.ts +11 -2
- package/dist/esm/adapters/text.js +10 -1
- package/dist/esm/adapters/text.js.map +1 -1
- package/dist/esm/converse/message-converter.d.ts +12 -1
- package/dist/esm/converse/message-converter.js +91 -22
- package/dist/esm/converse/message-converter.js.map +1 -1
- package/dist/esm/converse/prompt-cache.d.ts +16 -0
- package/dist/esm/converse/prompt-cache.js +43 -0
- package/dist/esm/converse/prompt-cache.js.map +1 -0
- package/dist/esm/converse/reasoning.d.ts +28 -0
- package/dist/esm/converse/reasoning.js +42 -0
- package/dist/esm/converse/reasoning.js.map +1 -0
- package/dist/esm/converse/stream-processor.d.ts +3 -29
- package/dist/esm/converse/stream-processor.js +93 -52
- package/dist/esm/converse/stream-processor.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/model-meta.d.ts +80 -0
- package/dist/esm/model-meta.js +54 -1
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/text/responses-provider-options.d.ts +0 -4
- package/dist/esm/text/text-provider-options.d.ts +2 -4
- package/dist/esm/utils/client.d.ts +10 -0
- package/dist/esm/utils/client.js +10 -1
- package/dist/esm/utils/client.js.map +1 -1
- package/package.json +3 -3
- package/src/adapters/converse-text.ts +213 -20
- package/src/adapters/responses-text.ts +32 -2
- package/src/adapters/text.ts +33 -3
- package/src/converse/message-converter.ts +168 -36
- package/src/converse/prompt-cache.ts +53 -0
- package/src/converse/reasoning.ts +62 -0
- package/src/converse/stream-processor.ts +122 -52
- package/src/model-meta.ts +76 -0
- package/src/text/responses-provider-options.ts +0 -2
- package/src/text/text-provider-options.ts +2 -4
- package/src/utils/client.ts +16 -0
package/src/model-meta.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { GENERATED_BEDROCK_MODELS } from './model-catalog.generated.js'
|
|
2
|
+
import type { Modality, ModelReasoning } from '@tanstack/ai'
|
|
3
|
+
import type { ModelReasoningCapability } from '@tanstack/ai/adapter-internals'
|
|
2
4
|
import type { BedrockTextProviderOptions } from './text/text-provider-options'
|
|
3
5
|
import type { BedrockConverseProviderOptions } from './converse/provider-options'
|
|
4
6
|
import type {
|
|
@@ -8,6 +10,21 @@ import type {
|
|
|
8
10
|
BedrockTitanTextEmbeddingProviderOptions,
|
|
9
11
|
} from './embedding/embedding-provider-options'
|
|
10
12
|
|
|
13
|
+
// Reasoning shapes: the levels a model has for `chat({ reasoning })`, and
|
|
14
|
+
// the provider value to send for each. Each model points at one of them.
|
|
15
|
+
const BUDGET_OFF_HIGH = {
|
|
16
|
+
levels: { off: 'off', high: 'high' },
|
|
17
|
+
budget: true,
|
|
18
|
+
} as const
|
|
19
|
+
const EFFORT_LOW_TO_HIGH = {
|
|
20
|
+
levels: { low: 'low', medium: 'medium', high: 'high' },
|
|
21
|
+
budget: false,
|
|
22
|
+
} as const
|
|
23
|
+
const EFFORT_NONE_HIGH = {
|
|
24
|
+
levels: { off: 'none', high: 'high' },
|
|
25
|
+
budget: false,
|
|
26
|
+
} as const
|
|
27
|
+
|
|
11
28
|
type Entry = (typeof GENERATED_BEDROCK_MODELS)[number]
|
|
12
29
|
|
|
13
30
|
/**
|
|
@@ -44,6 +61,14 @@ export type BedrockModelInputModalitiesByName = {
|
|
|
44
61
|
[E in Entry as E['id']]: E['input']
|
|
45
62
|
}
|
|
46
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Runtime map from model id to its input modalities, for the text adapters'
|
|
66
|
+
* `inputModalities`. An unknown id gives `undefined`.
|
|
67
|
+
*/
|
|
68
|
+
export const BEDROCK_MODEL_INPUT_MODALITIES: Readonly<
|
|
69
|
+
Record<string, ReadonlyArray<Modality>>
|
|
70
|
+
> = Object.fromEntries(GENERATED_BEDROCK_MODELS.map((m) => [m.id, m.input]))
|
|
71
|
+
|
|
47
72
|
/** Provider options per model. Same options for every model; keyed over the full catalog. */
|
|
48
73
|
export type BedrockChatModelProviderOptionsByName = {
|
|
49
74
|
[E in Entry as E['id']]: BedrockTextProviderOptions
|
|
@@ -74,6 +99,57 @@ export type ResolveInputModalities<TModel extends string> =
|
|
|
74
99
|
? BedrockModelInputModalitiesByName[TModel]
|
|
75
100
|
: readonly ['text']
|
|
76
101
|
|
|
102
|
+
// ============================================================================
|
|
103
|
+
// Reasoning
|
|
104
|
+
// ============================================================================
|
|
105
|
+
//
|
|
106
|
+
// Each model's data for `chat({ reasoning })`: the levels it has, with the
|
|
107
|
+
// provider value for each, and whether it takes a thinking token budget. The
|
|
108
|
+
// data comes from models.dev. The generator that writes it comes with the model
|
|
109
|
+
// catalog later. Until then, edit these entries by hand.
|
|
110
|
+
// scripts/fetch-bedrock-models.ts does not touch them.
|
|
111
|
+
|
|
112
|
+
const BEDROCK_REASONING = {
|
|
113
|
+
'openai.gpt-oss-120b-1:0': EFFORT_LOW_TO_HIGH,
|
|
114
|
+
'openai.gpt-oss-20b-1:0': EFFORT_LOW_TO_HIGH,
|
|
115
|
+
'us.anthropic.claude-sonnet-4-5-20250929-v1:0': BUDGET_OFF_HIGH,
|
|
116
|
+
'us.anthropic.claude-haiku-4-5-20251001-v1:0': BUDGET_OFF_HIGH,
|
|
117
|
+
'google.gemma-4-31b': EFFORT_NONE_HIGH,
|
|
118
|
+
'google.gemma-4-26b-a4b': EFFORT_NONE_HIGH,
|
|
119
|
+
'google.gemma-4-e2b': EFFORT_NONE_HIGH,
|
|
120
|
+
} satisfies Partial<Record<Entry['id'], ModelReasoning>>
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Each model's reasoning levels, and whether it takes a token budget, for
|
|
124
|
+
* `chat({ reasoning })`. A model that is not here does not reason.
|
|
125
|
+
*/
|
|
126
|
+
export type BedrockModelReasoningByName = {
|
|
127
|
+
[K in keyof typeof BEDROCK_REASONING]: ModelReasoningCapability<
|
|
128
|
+
(typeof BEDROCK_REASONING)[K]
|
|
129
|
+
>
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Runtime map from model id to its reasoning data, for the text adapters. An
|
|
134
|
+
* unknown id gives `undefined`: the adapter sends no reasoning field.
|
|
135
|
+
*/
|
|
136
|
+
export const BEDROCK_MODEL_REASONING: Readonly<Record<string, ModelReasoning>> =
|
|
137
|
+
BEDROCK_REASONING
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The Claude families that reject a forced tool (`any` or a named `tool`) on
|
|
141
|
+
* every request, with or without thinking. A Bedrock id has the family name
|
|
142
|
+
* inside it, for example `us.anthropic.claude-opus-5-5-...`.
|
|
143
|
+
* ponytail: names, not catalog entries, because the generated catalog has no
|
|
144
|
+
* entry for these models yet. Move it to the catalog when it has them.
|
|
145
|
+
*/
|
|
146
|
+
export const BEDROCK_CLAUDE_NO_FORCED_TOOL_FAMILIES: ReadonlyArray<string> = [
|
|
147
|
+
'claude-fable-5-1',
|
|
148
|
+
'claude-mythos-5-1',
|
|
149
|
+
'claude-opus-5-5',
|
|
150
|
+
'claude-sonnet-5-5',
|
|
151
|
+
]
|
|
152
|
+
|
|
77
153
|
// ============================================================================
|
|
78
154
|
// Embedding models
|
|
79
155
|
// ============================================================================
|
|
@@ -20,8 +20,6 @@ export interface BedrockResponsesProviderOptions {
|
|
|
20
20
|
| 'required'
|
|
21
21
|
| { type: 'function'; name: string }
|
|
22
22
|
| null
|
|
23
|
-
/** Reasoning controls for reasoning-capable models. */
|
|
24
|
-
reasoning?: { effort?: 'low' | 'medium' | 'high' } | null
|
|
25
23
|
user?: string | null
|
|
26
24
|
}
|
|
27
25
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bedrock Chat Completions provider options. Bedrock accepts the standard
|
|
3
|
-
* OpenAI Chat Completions request fields; we surface the commonly-used ones
|
|
4
|
-
*
|
|
3
|
+
* OpenAI Chat Completions request fields; we surface the commonly-used ones.
|
|
4
|
+
* Reasoning effort is set with `chat({ reasoning })`.
|
|
5
5
|
*
|
|
6
6
|
* @see https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-openai.html
|
|
7
7
|
*/
|
|
@@ -15,8 +15,6 @@ export interface BedrockTextProviderOptions {
|
|
|
15
15
|
metadata?: { [key: string]: string } | null
|
|
16
16
|
n?: number | null
|
|
17
17
|
parallel_tool_calls?: boolean | null
|
|
18
|
-
/** gpt-oss / reasoning models: 'low' | 'medium' (default) | 'high'. */
|
|
19
|
-
reasoning_effort?: 'low' | 'medium' | 'high' | null
|
|
20
18
|
seed?: number | null
|
|
21
19
|
stop?: string | Array<string> | null
|
|
22
20
|
temperature?: number | null
|
package/src/utils/client.ts
CHANGED
|
@@ -68,3 +68,19 @@ export function withBedrockDefaults(
|
|
|
68
68
|
fetch: fetch ?? createSigV4Fetch(resolved),
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* True when an error from Bedrock's OpenAI-compatible endpoints says the input
|
|
74
|
+
* does not fit in the model's context window. They have no error code for it.
|
|
75
|
+
* They answer `validation_error` for every bad request, so the message text
|
|
76
|
+
* is the only signal.
|
|
77
|
+
*/
|
|
78
|
+
export function isBedrockOpenAIContextOverflow(error: {
|
|
79
|
+
message: string
|
|
80
|
+
code: string | undefined
|
|
81
|
+
}): boolean {
|
|
82
|
+
return (
|
|
83
|
+
error.code === 'validation_error' &&
|
|
84
|
+
error.message.includes('maximum context length')
|
|
85
|
+
)
|
|
86
|
+
}
|