librechat-data-provider 0.8.402 → 0.8.404
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/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react-query/index.es.js +1 -1
- package/dist/react-query/index.es.js.map +1 -1
- package/dist/types/accessPermissions.d.ts +744 -0
- package/dist/types/actions.d.ts +118 -0
- package/dist/types/api-endpoints.d.ts +150 -0
- package/dist/types/artifacts.d.ts +97 -0
- package/dist/types/azure.d.ts +22 -0
- package/dist/types/bedrock.d.ts +1220 -0
- package/dist/types/config.d.ts +14849 -0
- package/dist/types/config.spec.d.ts +1 -0
- package/dist/types/createPayload.d.ts +5 -0
- package/dist/types/data-service.d.ts +287 -0
- package/dist/types/feedback.d.ts +36 -0
- package/dist/types/file-config.d.ts +263 -0
- package/dist/types/file-config.spec.d.ts +1 -0
- package/dist/types/generate.d.ts +597 -0
- package/dist/types/headers-helpers.d.ts +2 -0
- package/{src/index.ts → dist/types/index.d.ts} +0 -15
- package/dist/types/keys.d.ts +92 -0
- package/dist/types/mcp.d.ts +2760 -0
- package/dist/types/messages.d.ts +10 -0
- package/dist/types/models.d.ts +1547 -0
- package/dist/types/parameterSettings.d.ts +69 -0
- package/dist/types/parsers.d.ts +110 -0
- package/dist/types/permissions.d.ts +522 -0
- package/dist/types/react-query/react-query-service.d.ts +85 -0
- package/dist/types/request.d.ts +25 -0
- package/dist/types/roles.d.ts +554 -0
- package/dist/types/roles.spec.d.ts +1 -0
- package/dist/types/schemas.d.ts +5110 -0
- package/dist/types/schemas.spec.d.ts +1 -0
- package/dist/types/types/agents.d.ts +433 -0
- package/dist/types/types/assistants.d.ts +547 -0
- package/dist/types/types/files.d.ts +172 -0
- package/dist/types/types/graph.d.ts +135 -0
- package/{src/types/mcpServers.ts → dist/types/types/mcpServers.d.ts} +12 -18
- package/dist/types/types/mutations.d.ts +209 -0
- package/dist/types/types/queries.d.ts +169 -0
- package/dist/types/types/runs.d.ts +36 -0
- package/dist/types/types/web.d.ts +520 -0
- package/dist/types/types.d.ts +503 -0
- package/dist/types/utils.d.ts +12 -0
- package/package.json +5 -1
- package/babel.config.js +0 -4
- package/check_updates.sh +0 -52
- package/jest.config.js +0 -19
- package/react-query/package-lock.json +0 -292
- package/react-query/package.json +0 -10
- package/rollup.config.js +0 -74
- package/server-rollup.config.js +0 -40
- package/specs/actions.spec.ts +0 -2533
- package/specs/api-endpoints-subdir.spec.ts +0 -140
- package/specs/api-endpoints.spec.ts +0 -74
- package/specs/azure.spec.ts +0 -844
- package/specs/bedrock.spec.ts +0 -862
- package/specs/filetypes.spec.ts +0 -175
- package/specs/generate.spec.ts +0 -770
- package/specs/headers-helpers.spec.ts +0 -24
- package/specs/mcp.spec.ts +0 -147
- package/specs/openapiSpecs.ts +0 -524
- package/specs/parsers.spec.ts +0 -601
- package/specs/request-interceptor.spec.ts +0 -304
- package/specs/utils.spec.ts +0 -196
- package/src/accessPermissions.ts +0 -346
- package/src/actions.ts +0 -813
- package/src/api-endpoints.ts +0 -440
- package/src/artifacts.ts +0 -3104
- package/src/azure.ts +0 -328
- package/src/bedrock.ts +0 -425
- package/src/config.spec.ts +0 -315
- package/src/config.ts +0 -2006
- package/src/createPayload.ts +0 -46
- package/src/data-service.ts +0 -1087
- package/src/feedback.ts +0 -141
- package/src/file-config.spec.ts +0 -1248
- package/src/file-config.ts +0 -764
- package/src/generate.ts +0 -634
- package/src/headers-helpers.ts +0 -13
- package/src/keys.ts +0 -99
- package/src/mcp.ts +0 -271
- package/src/messages.ts +0 -50
- package/src/models.ts +0 -69
- package/src/parameterSettings.ts +0 -1111
- package/src/parsers.ts +0 -563
- package/src/permissions.ts +0 -188
- package/src/react-query/react-query-service.ts +0 -566
- package/src/request.ts +0 -171
- package/src/roles.spec.ts +0 -132
- package/src/roles.ts +0 -225
- package/src/schemas.spec.ts +0 -355
- package/src/schemas.ts +0 -1234
- package/src/types/agents.ts +0 -470
- package/src/types/assistants.ts +0 -654
- package/src/types/files.ts +0 -191
- package/src/types/graph.ts +0 -145
- package/src/types/mutations.ts +0 -422
- package/src/types/queries.ts +0 -208
- package/src/types/runs.ts +0 -40
- package/src/types/web.ts +0 -588
- package/src/types.ts +0 -676
- package/src/utils.ts +0 -85
- package/tsconfig.json +0 -28
- package/tsconfig.spec.json +0 -10
- /package/{src/react-query/index.ts → dist/types/react-query/index.d.ts} +0 -0
- /package/{src/types/index.ts → dist/types/types/index.d.ts} +0 -0
package/src/bedrock.ts
DELETED
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import * as s from './schemas';
|
|
3
|
-
|
|
4
|
-
const DEFAULT_ENABLED_MAX_TOKENS = 8192;
|
|
5
|
-
const DEFAULT_THINKING_BUDGET = 2000;
|
|
6
|
-
|
|
7
|
-
const bedrockReasoningConfigValues = new Set<string>(Object.values(s.BedrockReasoningConfig));
|
|
8
|
-
|
|
9
|
-
type ThinkingConfig = { type: 'enabled'; budget_tokens: number } | { type: 'adaptive' };
|
|
10
|
-
|
|
11
|
-
type AnthropicReasoning = {
|
|
12
|
-
thinking?: ThinkingConfig | boolean;
|
|
13
|
-
thinkingBudget?: number;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type AnthropicInput = BedrockConverseInput & {
|
|
17
|
-
additionalModelRequestFields: BedrockConverseInput['additionalModelRequestFields'] &
|
|
18
|
-
AnthropicReasoning;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/** Extracts opus major/minor version from both naming formats */
|
|
22
|
-
function parseOpusVersion(model: string): { major: number; minor: number } | null {
|
|
23
|
-
const nameFirst = model.match(/claude-opus[-.]?(\d+)(?:[-.](\d+))?/);
|
|
24
|
-
if (nameFirst) {
|
|
25
|
-
return {
|
|
26
|
-
major: parseInt(nameFirst[1], 10),
|
|
27
|
-
minor: nameFirst[2] != null ? parseInt(nameFirst[2], 10) : 0,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const numFirst = model.match(/claude-(\d+)(?:[-.](\d+))?-opus/);
|
|
31
|
-
if (numFirst) {
|
|
32
|
-
return {
|
|
33
|
-
major: parseInt(numFirst[1], 10),
|
|
34
|
-
minor: numFirst[2] != null ? parseInt(numFirst[2], 10) : 0,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Extracts sonnet major/minor version from both naming formats.
|
|
41
|
-
* Uses single-digit minor capture to avoid matching date suffixes (e.g., -20250514). */
|
|
42
|
-
function parseSonnetVersion(model: string): { major: number; minor: number } | null {
|
|
43
|
-
const nameFirst = model.match(/claude-sonnet[-.]?(\d+)(?:[-.](\d)(?!\d))?/);
|
|
44
|
-
if (nameFirst) {
|
|
45
|
-
return {
|
|
46
|
-
major: parseInt(nameFirst[1], 10),
|
|
47
|
-
minor: nameFirst[2] != null ? parseInt(nameFirst[2], 10) : 0,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
const numFirst = model.match(/claude-(\d+)(?:[-.](\d)(?!\d))?-sonnet/);
|
|
51
|
-
if (numFirst) {
|
|
52
|
-
return {
|
|
53
|
-
major: parseInt(numFirst[1], 10),
|
|
54
|
-
minor: numFirst[2] != null ? parseInt(numFirst[2], 10) : 0,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Checks if a model supports adaptive thinking (Opus 4.6+, Sonnet 4.6+) */
|
|
61
|
-
export function supportsAdaptiveThinking(model: string): boolean {
|
|
62
|
-
const opus = parseOpusVersion(model);
|
|
63
|
-
if (opus && (opus.major > 4 || (opus.major === 4 && opus.minor >= 6))) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
const sonnet = parseSonnetVersion(model);
|
|
67
|
-
if (sonnet != null && (sonnet.major > 4 || (sonnet.major === 4 && sonnet.minor >= 6))) {
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** Checks if a model qualifies for the context-1m beta header (Sonnet 4+, Opus 4.6+, Opus 5+) */
|
|
74
|
-
export function supportsContext1m(model: string): boolean {
|
|
75
|
-
const sonnet = parseSonnetVersion(model);
|
|
76
|
-
if (sonnet != null && sonnet.major >= 4) {
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
const opus = parseOpusVersion(model);
|
|
80
|
-
if (opus && (opus.major > 4 || (opus.major === 4 && opus.minor >= 6))) {
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Gets the appropriate anthropic_beta headers for Bedrock Anthropic models.
|
|
88
|
-
* Bedrock uses `anthropic_beta` (with underscore) in additionalModelRequestFields.
|
|
89
|
-
*
|
|
90
|
-
* @param model - The Bedrock model identifier (e.g., "anthropic.claude-sonnet-4-20250514-v1:0")
|
|
91
|
-
* @returns Array of beta header strings, or empty array if not applicable
|
|
92
|
-
*/
|
|
93
|
-
function getBedrockAnthropicBetaHeaders(model: string): string[] {
|
|
94
|
-
const betaHeaders: string[] = [];
|
|
95
|
-
|
|
96
|
-
const isClaudeThinkingModel =
|
|
97
|
-
model.includes('anthropic.claude-3-7-sonnet') ||
|
|
98
|
-
/anthropic\.claude-(?:[4-9](?:\.\d+)?(?:-\d+)?-(?:sonnet|opus|haiku)|(?:sonnet|opus|haiku)-[4-9])/.test(
|
|
99
|
-
model,
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
const isSonnet4PlusModel =
|
|
103
|
-
/anthropic\.claude-(?:sonnet-[4-9]|[4-9](?:\.\d+)?(?:-\d+)?-sonnet)/.test(model);
|
|
104
|
-
|
|
105
|
-
if (isClaudeThinkingModel) {
|
|
106
|
-
betaHeaders.push('output-128k-2025-02-19');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (isSonnet4PlusModel || supportsAdaptiveThinking(model)) {
|
|
110
|
-
betaHeaders.push('context-1m-2025-08-07');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return betaHeaders;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export const bedrockInputSchema = s.tConversationSchema
|
|
117
|
-
.pick({
|
|
118
|
-
/* LibreChat params; optionType: 'conversation' */
|
|
119
|
-
modelLabel: true,
|
|
120
|
-
promptPrefix: true,
|
|
121
|
-
resendFiles: true,
|
|
122
|
-
iconURL: true,
|
|
123
|
-
greeting: true,
|
|
124
|
-
spec: true,
|
|
125
|
-
maxOutputTokens: true,
|
|
126
|
-
maxContextTokens: true,
|
|
127
|
-
artifacts: true,
|
|
128
|
-
/* Bedrock params; optionType: 'model' */
|
|
129
|
-
region: true,
|
|
130
|
-
system: true,
|
|
131
|
-
model: true,
|
|
132
|
-
maxTokens: true,
|
|
133
|
-
temperature: true,
|
|
134
|
-
topP: true,
|
|
135
|
-
stop: true,
|
|
136
|
-
thinking: true,
|
|
137
|
-
thinkingBudget: true,
|
|
138
|
-
effort: true,
|
|
139
|
-
reasoning_effort: true,
|
|
140
|
-
promptCache: true,
|
|
141
|
-
/* Catch-all fields */
|
|
142
|
-
topK: true,
|
|
143
|
-
additionalModelRequestFields: true,
|
|
144
|
-
})
|
|
145
|
-
.transform((obj) => {
|
|
146
|
-
if ((obj as AnthropicInput).additionalModelRequestFields?.thinking != null) {
|
|
147
|
-
const _obj = obj as AnthropicInput;
|
|
148
|
-
const thinking = _obj.additionalModelRequestFields.thinking;
|
|
149
|
-
obj.thinking = !!thinking;
|
|
150
|
-
obj.thinkingBudget =
|
|
151
|
-
typeof thinking === 'object' && 'budget_tokens' in thinking
|
|
152
|
-
? thinking.budget_tokens
|
|
153
|
-
: undefined;
|
|
154
|
-
delete obj.additionalModelRequestFields;
|
|
155
|
-
}
|
|
156
|
-
return s.removeNullishValues(obj);
|
|
157
|
-
})
|
|
158
|
-
.catch(() => ({}));
|
|
159
|
-
|
|
160
|
-
export type BedrockConverseInput = z.infer<typeof bedrockInputSchema>;
|
|
161
|
-
|
|
162
|
-
export const bedrockInputParser = s.tConversationSchema
|
|
163
|
-
.pick({
|
|
164
|
-
/* LibreChat params; optionType: 'conversation' */
|
|
165
|
-
modelLabel: true,
|
|
166
|
-
promptPrefix: true,
|
|
167
|
-
resendFiles: true,
|
|
168
|
-
iconURL: true,
|
|
169
|
-
greeting: true,
|
|
170
|
-
spec: true,
|
|
171
|
-
artifacts: true,
|
|
172
|
-
maxOutputTokens: true,
|
|
173
|
-
maxContextTokens: true,
|
|
174
|
-
/* Bedrock params; optionType: 'model' */
|
|
175
|
-
region: true,
|
|
176
|
-
model: true,
|
|
177
|
-
maxTokens: true,
|
|
178
|
-
temperature: true,
|
|
179
|
-
topP: true,
|
|
180
|
-
stop: true,
|
|
181
|
-
thinking: true,
|
|
182
|
-
thinkingBudget: true,
|
|
183
|
-
effort: true,
|
|
184
|
-
reasoning_effort: true,
|
|
185
|
-
promptCache: true,
|
|
186
|
-
/* Catch-all fields */
|
|
187
|
-
topK: true,
|
|
188
|
-
additionalModelRequestFields: true,
|
|
189
|
-
})
|
|
190
|
-
.catchall(z.any())
|
|
191
|
-
.transform((data) => {
|
|
192
|
-
const knownKeys = [
|
|
193
|
-
'modelLabel',
|
|
194
|
-
'promptPrefix',
|
|
195
|
-
'resendFiles',
|
|
196
|
-
'iconURL',
|
|
197
|
-
'greeting',
|
|
198
|
-
'spec',
|
|
199
|
-
'maxOutputTokens',
|
|
200
|
-
'artifacts',
|
|
201
|
-
'additionalModelRequestFields',
|
|
202
|
-
'region',
|
|
203
|
-
'model',
|
|
204
|
-
'maxTokens',
|
|
205
|
-
'temperature',
|
|
206
|
-
'topP',
|
|
207
|
-
'stop',
|
|
208
|
-
'promptCache',
|
|
209
|
-
];
|
|
210
|
-
|
|
211
|
-
const additionalFields: Record<string, unknown> = {};
|
|
212
|
-
const typedData = data as Record<string, unknown>;
|
|
213
|
-
|
|
214
|
-
Object.entries(typedData).forEach(([key, value]) => {
|
|
215
|
-
if (!knownKeys.includes(key)) {
|
|
216
|
-
if (key === 'topK') {
|
|
217
|
-
additionalFields['top_k'] = value;
|
|
218
|
-
} else {
|
|
219
|
-
additionalFields[key] = value;
|
|
220
|
-
}
|
|
221
|
-
delete typedData[key];
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
/** Default thinking and thinkingBudget for 'anthropic.claude-3-7-sonnet' models, if not defined */
|
|
226
|
-
if (
|
|
227
|
-
typeof typedData.model === 'string' &&
|
|
228
|
-
(typedData.model.includes('anthropic.claude-3-7-sonnet') ||
|
|
229
|
-
/anthropic\.claude-(?:[4-9](?:\.\d+)?(?:-\d+)?-(?:sonnet|opus|haiku)|(?:sonnet|opus|haiku)-[4-9])/.test(
|
|
230
|
-
typedData.model,
|
|
231
|
-
))
|
|
232
|
-
) {
|
|
233
|
-
const isAdaptive = supportsAdaptiveThinking(typedData.model as string);
|
|
234
|
-
|
|
235
|
-
if (isAdaptive) {
|
|
236
|
-
const effort = additionalFields.effort;
|
|
237
|
-
if (effort && typeof effort === 'string' && effort !== '') {
|
|
238
|
-
additionalFields.output_config = { effort };
|
|
239
|
-
}
|
|
240
|
-
delete additionalFields.effort;
|
|
241
|
-
|
|
242
|
-
if (additionalFields.thinking === false) {
|
|
243
|
-
delete additionalFields.thinking;
|
|
244
|
-
delete additionalFields.thinkingBudget;
|
|
245
|
-
} else {
|
|
246
|
-
additionalFields.thinking = { type: 'adaptive' };
|
|
247
|
-
delete additionalFields.thinkingBudget;
|
|
248
|
-
}
|
|
249
|
-
} else {
|
|
250
|
-
if (additionalFields.thinking === undefined) {
|
|
251
|
-
additionalFields.thinking = true;
|
|
252
|
-
} else if (additionalFields.thinking === false) {
|
|
253
|
-
delete additionalFields.thinking;
|
|
254
|
-
delete additionalFields.thinkingBudget;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (additionalFields.thinking === true && additionalFields.thinkingBudget === undefined) {
|
|
258
|
-
additionalFields.thinkingBudget = DEFAULT_THINKING_BUDGET;
|
|
259
|
-
}
|
|
260
|
-
delete additionalFields.effort;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/** Anthropic uses 'effort' via output_config, not reasoning_config */
|
|
264
|
-
delete additionalFields.reasoning_effort;
|
|
265
|
-
|
|
266
|
-
if ((typedData.model as string).includes('anthropic.')) {
|
|
267
|
-
const betaHeaders = getBedrockAnthropicBetaHeaders(typedData.model as string);
|
|
268
|
-
if (betaHeaders.length > 0) {
|
|
269
|
-
additionalFields.anthropic_beta = betaHeaders;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
} else {
|
|
273
|
-
delete additionalFields.thinking;
|
|
274
|
-
delete additionalFields.thinkingBudget;
|
|
275
|
-
delete additionalFields.effort;
|
|
276
|
-
delete additionalFields.output_config;
|
|
277
|
-
delete additionalFields.anthropic_beta;
|
|
278
|
-
|
|
279
|
-
const reasoningEffort = additionalFields.reasoning_effort;
|
|
280
|
-
delete additionalFields.reasoning_effort;
|
|
281
|
-
if (
|
|
282
|
-
typeof reasoningEffort === 'string' &&
|
|
283
|
-
bedrockReasoningConfigValues.has(reasoningEffort)
|
|
284
|
-
) {
|
|
285
|
-
additionalFields.reasoning_config = reasoningEffort;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const isAnthropicModel =
|
|
290
|
-
typeof typedData.model === 'string' && typedData.model.includes('anthropic.');
|
|
291
|
-
|
|
292
|
-
/** Strip stale fields from previously-persisted additionalModelRequestFields */
|
|
293
|
-
if (
|
|
294
|
-
typeof typedData.additionalModelRequestFields === 'object' &&
|
|
295
|
-
typedData.additionalModelRequestFields != null
|
|
296
|
-
) {
|
|
297
|
-
const amrf = typedData.additionalModelRequestFields as Record<string, unknown>;
|
|
298
|
-
if (!isAnthropicModel) {
|
|
299
|
-
delete amrf.anthropic_beta;
|
|
300
|
-
delete amrf.thinking;
|
|
301
|
-
delete amrf.thinkingBudget;
|
|
302
|
-
delete amrf.effort;
|
|
303
|
-
delete amrf.output_config;
|
|
304
|
-
delete amrf.reasoning_config;
|
|
305
|
-
} else {
|
|
306
|
-
delete amrf.reasoning_config;
|
|
307
|
-
delete amrf.reasoning_effort;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/** Default promptCache for claude and nova models, if not defined */
|
|
312
|
-
if (
|
|
313
|
-
typeof typedData.model === 'string' &&
|
|
314
|
-
(typedData.model.includes('claude') || typedData.model.includes('nova'))
|
|
315
|
-
) {
|
|
316
|
-
if (typedData.promptCache === undefined) {
|
|
317
|
-
typedData.promptCache = true;
|
|
318
|
-
}
|
|
319
|
-
} else if (typedData.promptCache === true) {
|
|
320
|
-
typedData.promptCache = undefined;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
if (Object.keys(additionalFields).length > 0) {
|
|
324
|
-
typedData.additionalModelRequestFields = {
|
|
325
|
-
...((typedData.additionalModelRequestFields as Record<string, unknown> | undefined) || {}),
|
|
326
|
-
...additionalFields,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (typedData.maxOutputTokens !== undefined) {
|
|
331
|
-
typedData.maxTokens = typedData.maxOutputTokens;
|
|
332
|
-
} else if (typedData.maxTokens !== undefined) {
|
|
333
|
-
typedData.maxOutputTokens = typedData.maxTokens;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return s.removeNullishValues(typedData) as BedrockConverseInput;
|
|
337
|
-
})
|
|
338
|
-
.catch(() => ({}));
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Configures the "thinking" parameter based on given input and thinking options.
|
|
342
|
-
*
|
|
343
|
-
* @param data - The parsed Bedrock request options object
|
|
344
|
-
* @returns The object with thinking configured appropriately
|
|
345
|
-
*/
|
|
346
|
-
function configureThinking(data: AnthropicInput): AnthropicInput {
|
|
347
|
-
const updatedData = { ...data };
|
|
348
|
-
const thinking = updatedData.additionalModelRequestFields?.thinking;
|
|
349
|
-
|
|
350
|
-
if (thinking === true) {
|
|
351
|
-
updatedData.maxTokens =
|
|
352
|
-
updatedData.maxTokens ?? updatedData.maxOutputTokens ?? DEFAULT_ENABLED_MAX_TOKENS;
|
|
353
|
-
delete updatedData.maxOutputTokens;
|
|
354
|
-
const thinkingConfig: ThinkingConfig = {
|
|
355
|
-
type: 'enabled',
|
|
356
|
-
budget_tokens:
|
|
357
|
-
updatedData.additionalModelRequestFields?.thinkingBudget ?? DEFAULT_THINKING_BUDGET,
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
if (thinkingConfig.budget_tokens > updatedData.maxTokens) {
|
|
361
|
-
thinkingConfig.budget_tokens = Math.floor(updatedData.maxTokens * 0.9);
|
|
362
|
-
}
|
|
363
|
-
updatedData.additionalModelRequestFields!.thinking = thinkingConfig;
|
|
364
|
-
delete updatedData.additionalModelRequestFields!.thinkingBudget;
|
|
365
|
-
} else if (
|
|
366
|
-
typeof thinking === 'object' &&
|
|
367
|
-
thinking != null &&
|
|
368
|
-
(thinking as { type: string }).type === 'adaptive'
|
|
369
|
-
) {
|
|
370
|
-
if (updatedData.maxTokens == null && updatedData.maxOutputTokens != null) {
|
|
371
|
-
updatedData.maxTokens = updatedData.maxOutputTokens;
|
|
372
|
-
}
|
|
373
|
-
delete updatedData.maxOutputTokens;
|
|
374
|
-
delete updatedData.additionalModelRequestFields!.thinkingBudget;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
return updatedData;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
export const bedrockOutputParser = (data: Record<string, unknown>) => {
|
|
381
|
-
const knownKeys = [...Object.keys(s.tConversationSchema.shape), 'topK', 'top_k'];
|
|
382
|
-
let result: Record<string, unknown> = {};
|
|
383
|
-
|
|
384
|
-
// Extract known fields from the root level
|
|
385
|
-
Object.entries(data).forEach(([key, value]) => {
|
|
386
|
-
if (knownKeys.includes(key)) {
|
|
387
|
-
result[key] = value;
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
// Extract known fields from additionalModelRequestFields
|
|
392
|
-
if (
|
|
393
|
-
typeof data.additionalModelRequestFields === 'object' &&
|
|
394
|
-
data.additionalModelRequestFields !== null
|
|
395
|
-
) {
|
|
396
|
-
Object.entries(data.additionalModelRequestFields as Record<string, unknown>).forEach(
|
|
397
|
-
([key, value]) => {
|
|
398
|
-
if (knownKeys.includes(key)) {
|
|
399
|
-
if (key === 'top_k') {
|
|
400
|
-
result['topK'] = value;
|
|
401
|
-
} else if (key === 'thinking' || key === 'thinkingBudget') {
|
|
402
|
-
return;
|
|
403
|
-
} else {
|
|
404
|
-
result[key] = value;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
},
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// Handle maxTokens and maxOutputTokens
|
|
412
|
-
if (result.maxTokens !== undefined && result.maxOutputTokens === undefined) {
|
|
413
|
-
result.maxOutputTokens = result.maxTokens;
|
|
414
|
-
} else if (result.maxOutputTokens !== undefined && result.maxTokens === undefined) {
|
|
415
|
-
result.maxTokens = result.maxOutputTokens;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
result = configureThinking(result as AnthropicInput);
|
|
419
|
-
const amrf = result.additionalModelRequestFields as Record<string, unknown> | undefined;
|
|
420
|
-
if (!amrf || Object.keys(amrf).length === 0) {
|
|
421
|
-
delete result.additionalModelRequestFields;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
return result;
|
|
425
|
-
};
|