@loonylabs/llm-middleware 2.27.1 → 2.29.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.
Files changed (65) hide show
  1. package/.env.example +13 -0
  2. package/README.md +4 -2
  3. package/dist/middleware/services/llm/llm.service.d.ts.map +1 -1
  4. package/dist/middleware/services/llm/llm.service.js +4 -0
  5. package/dist/middleware/services/llm/llm.service.js.map +1 -1
  6. package/dist/middleware/services/llm/providers/azure-openai-capabilities.d.ts +33 -0
  7. package/dist/middleware/services/llm/providers/azure-openai-capabilities.d.ts.map +1 -0
  8. package/dist/middleware/services/llm/providers/azure-openai-capabilities.js +66 -0
  9. package/dist/middleware/services/llm/providers/azure-openai-capabilities.js.map +1 -0
  10. package/dist/middleware/services/llm/providers/azure-openai-provider.d.ts +53 -0
  11. package/dist/middleware/services/llm/providers/azure-openai-provider.d.ts.map +1 -0
  12. package/dist/middleware/services/llm/providers/azure-openai-provider.js +333 -0
  13. package/dist/middleware/services/llm/providers/azure-openai-provider.js.map +1 -0
  14. package/dist/middleware/services/llm/providers/bedrock-provider.d.ts +43 -0
  15. package/dist/middleware/services/llm/providers/bedrock-provider.d.ts.map +1 -0
  16. package/dist/middleware/services/llm/providers/bedrock-provider.js +328 -0
  17. package/dist/middleware/services/llm/providers/bedrock-provider.js.map +1 -0
  18. package/dist/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.factory.d.ts +21 -0
  19. package/dist/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.factory.d.ts.map +1 -0
  20. package/dist/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.factory.js +36 -0
  21. package/dist/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.factory.js.map +1 -0
  22. package/dist/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.types.d.ts +53 -0
  23. package/dist/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.types.d.ts.map +1 -0
  24. package/dist/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.types.js +18 -0
  25. package/dist/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.types.js.map +1 -0
  26. package/dist/middleware/services/llm/providers/bedrock-reasoning/index.d.ts +6 -0
  27. package/dist/middleware/services/llm/providers/bedrock-reasoning/index.d.ts.map +1 -0
  28. package/dist/middleware/services/llm/providers/bedrock-reasoning/index.js +22 -0
  29. package/dist/middleware/services/llm/providers/bedrock-reasoning/index.js.map +1 -0
  30. package/dist/middleware/services/llm/providers/bedrock-reasoning/noop-reasoning.strategy.d.ts +17 -0
  31. package/dist/middleware/services/llm/providers/bedrock-reasoning/noop-reasoning.strategy.d.ts.map +1 -0
  32. package/dist/middleware/services/llm/providers/bedrock-reasoning/noop-reasoning.strategy.js +24 -0
  33. package/dist/middleware/services/llm/providers/bedrock-reasoning/noop-reasoning.strategy.js.map +1 -0
  34. package/dist/middleware/services/llm/providers/bedrock-reasoning/nova-reasoning.strategy.d.ts +16 -0
  35. package/dist/middleware/services/llm/providers/bedrock-reasoning/nova-reasoning.strategy.d.ts.map +1 -0
  36. package/dist/middleware/services/llm/providers/bedrock-reasoning/nova-reasoning.strategy.js +40 -0
  37. package/dist/middleware/services/llm/providers/bedrock-reasoning/nova-reasoning.strategy.js.map +1 -0
  38. package/dist/middleware/services/llm/providers/bedrock-reasoning/reasoning-effort.strategy.d.ts +15 -0
  39. package/dist/middleware/services/llm/providers/bedrock-reasoning/reasoning-effort.strategy.d.ts.map +1 -0
  40. package/dist/middleware/services/llm/providers/bedrock-reasoning/reasoning-effort.strategy.js +32 -0
  41. package/dist/middleware/services/llm/providers/bedrock-reasoning/reasoning-effort.strategy.js.map +1 -0
  42. package/dist/middleware/services/llm/providers/index.d.ts +3 -0
  43. package/dist/middleware/services/llm/providers/index.d.ts.map +1 -1
  44. package/dist/middleware/services/llm/providers/index.js +3 -0
  45. package/dist/middleware/services/llm/providers/index.js.map +1 -1
  46. package/dist/middleware/services/llm/types/azure-openai.types.d.ts +135 -0
  47. package/dist/middleware/services/llm/types/azure-openai.types.d.ts.map +1 -0
  48. package/dist/middleware/services/llm/types/azure-openai.types.js +19 -0
  49. package/dist/middleware/services/llm/types/azure-openai.types.js.map +1 -0
  50. package/dist/middleware/services/llm/types/bedrock.types.d.ts +114 -0
  51. package/dist/middleware/services/llm/types/bedrock.types.d.ts.map +1 -0
  52. package/dist/middleware/services/llm/types/bedrock.types.js +14 -0
  53. package/dist/middleware/services/llm/types/bedrock.types.js.map +1 -0
  54. package/dist/middleware/services/llm/types/common.types.d.ts +12 -1
  55. package/dist/middleware/services/llm/types/common.types.d.ts.map +1 -1
  56. package/dist/middleware/services/llm/types/common.types.js +4 -0
  57. package/dist/middleware/services/llm/types/common.types.js.map +1 -1
  58. package/dist/middleware/services/llm/types/index.d.ts +2 -0
  59. package/dist/middleware/services/llm/types/index.d.ts.map +1 -1
  60. package/dist/middleware/services/llm/types/index.js +2 -0
  61. package/dist/middleware/services/llm/types/index.js.map +1 -1
  62. package/dist/middleware/services/llm/utils/debug-llm.utils.d.ts.map +1 -1
  63. package/dist/middleware/services/llm/utils/debug-llm.utils.js +4 -0
  64. package/dist/middleware/services/llm/utils/debug-llm.utils.js.map +1 -1
  65. package/package.json +3 -1
@@ -0,0 +1,43 @@
1
+ import { BaseLLMProvider } from './base-llm-provider';
2
+ import { CommonLLMResponse } from '../types';
3
+ import { BedrockRequestOptions } from '../types/bedrock.types';
4
+ import { MultimodalContent } from '../types/multimodal.types';
5
+ /**
6
+ * AWS Bedrock provider implementation using the Converse API.
7
+ *
8
+ * Why Converse (not InvokeModel): Converse provides a single, model-agnostic
9
+ * request/response shape across Claude, Nova, Llama, Mistral, Qwen, etc. — so
10
+ * switching models is just a different `model` string, no per-model payload code.
11
+ *
12
+ * Why Bearer auth (not AWS SDK / SigV4): Bedrock accepts an API key as a Bearer
13
+ * token directly over REST, mirroring the existing axios-based providers. No
14
+ * heavy @aws-sdk dependency and no request signing required.
15
+ *
16
+ * Auth: Authorization: Bearer <BEDROCK_API_KEY>
17
+ * Region: BEDROCK_REGION (default eu-central-1 / Frankfurt for EU data residency)
18
+ * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html
19
+ */
20
+ export declare class BedrockProvider extends BaseLLMProvider {
21
+ private dataFlowLogger;
22
+ private readonly DEFAULT_REGION;
23
+ private readonly DEFAULT_TIMEOUT;
24
+ constructor();
25
+ /**
26
+ * Build the bedrock-runtime Converse endpoint for a given region and model.
27
+ * The model id is used as-is (model ids such as `qwen.qwen3-32b-v1:0` are
28
+ * valid path segments and must not be percent-encoded).
29
+ */
30
+ private buildEndpoint;
31
+ /**
32
+ * Call the AWS Bedrock Converse API with a custom system message.
33
+ * @param userPrompt - The user's prompt (text; image input is a planned follow-up)
34
+ * @param systemMessage - The system message defining AI behavior
35
+ * @param options - Options for the API call
36
+ * @returns The API response or null on error
37
+ */
38
+ callWithSystemMessage(userPrompt: MultimodalContent, systemMessage: string, options?: BedrockRequestOptions): Promise<CommonLLMResponse | null>;
39
+ }
40
+ export declare const bedrockProvider: BedrockProvider;
41
+ export { BedrockProvider as BedrockService };
42
+ export { bedrockProvider as bedrockService };
43
+ //# sourceMappingURL=bedrock-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bedrock-provider.d.ts","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/providers/bedrock-provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAe,iBAAiB,EAAc,MAAM,UAAU,CAAC;AACtE,OAAO,EACL,qBAAqB,EAKtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAmB,MAAM,2BAA2B,CAAC;AAQ/E;;;;;;;;;;;;;;GAcG;AACH,qBAAa,eAAgB,SAAQ,eAAe;IAClD,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAkB;IACjD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAU;;IAO1C;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;;;OAMG;IACU,qBAAqB,CAChC,UAAU,EAAE,iBAAiB,EAC7B,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;CA8VrC;AAGD,eAAO,MAAM,eAAe,iBAAwB,CAAC;AAGrD,OAAO,EAAE,eAAe,IAAI,cAAc,EAAE,CAAC;AAC7C,OAAO,EAAE,eAAe,IAAI,cAAc,EAAE,CAAC"}
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.bedrockService = exports.BedrockService = exports.bedrockProvider = exports.BedrockProvider = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const uuid_1 = require("uuid");
9
+ const logging_utils_1 = require("../../../shared/utils/logging.utils");
10
+ const base_llm_provider_1 = require("./base-llm-provider");
11
+ const types_1 = require("../types");
12
+ const debug_llm_utils_1 = require("../utils/debug-llm.utils");
13
+ const data_flow_logger_1 = require("../../data-flow-logger");
14
+ const thinking_1 = require("../thinking");
15
+ const retry_utils_1 = require("../utils/retry.utils");
16
+ const multimodal_utils_1 = require("../utils/multimodal.utils");
17
+ const bedrock_reasoning_1 = require("./bedrock-reasoning");
18
+ /**
19
+ * AWS Bedrock provider implementation using the Converse API.
20
+ *
21
+ * Why Converse (not InvokeModel): Converse provides a single, model-agnostic
22
+ * request/response shape across Claude, Nova, Llama, Mistral, Qwen, etc. — so
23
+ * switching models is just a different `model` string, no per-model payload code.
24
+ *
25
+ * Why Bearer auth (not AWS SDK / SigV4): Bedrock accepts an API key as a Bearer
26
+ * token directly over REST, mirroring the existing axios-based providers. No
27
+ * heavy @aws-sdk dependency and no request signing required.
28
+ *
29
+ * Auth: Authorization: Bearer <BEDROCK_API_KEY>
30
+ * Region: BEDROCK_REGION (default eu-central-1 / Frankfurt for EU data residency)
31
+ * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html
32
+ */
33
+ class BedrockProvider extends base_llm_provider_1.BaseLLMProvider {
34
+ constructor() {
35
+ super(types_1.LLMProvider.BEDROCK);
36
+ this.DEFAULT_REGION = 'eu-central-1';
37
+ this.DEFAULT_TIMEOUT = 180000;
38
+ this.dataFlowLogger = data_flow_logger_1.DataFlowLoggerService.getInstance();
39
+ }
40
+ /**
41
+ * Build the bedrock-runtime Converse endpoint for a given region and model.
42
+ * The model id is used as-is (model ids such as `qwen.qwen3-32b-v1:0` are
43
+ * valid path segments and must not be percent-encoded).
44
+ */
45
+ buildEndpoint(region, model) {
46
+ return `https://bedrock-runtime.${region}.amazonaws.com/model/${model}/converse`;
47
+ }
48
+ /**
49
+ * Call the AWS Bedrock Converse API with a custom system message.
50
+ * @param userPrompt - The user's prompt (text; image input is a planned follow-up)
51
+ * @param systemMessage - The system message defining AI behavior
52
+ * @param options - Options for the API call
53
+ * @returns The API response or null on error
54
+ */
55
+ async callWithSystemMessage(userPrompt, systemMessage, options = {}) {
56
+ const { authToken = process.env.BEDROCK_API_KEY, model = process.env.BEDROCK_MODEL, region = process.env.BEDROCK_REGION || this.DEFAULT_REGION, temperature = 0.7, maxTokens = 4096, topP, stopSequences, timeout = this.DEFAULT_TIMEOUT, debugContext, sessionId = (0, uuid_1.v4)(), chapterNumber, pageNumber, pageName, reasoningEffort } = options;
57
+ // Validate that the API key is provided
58
+ if (!authToken) {
59
+ throw new Error('AWS Bedrock API key is required but not provided. ' +
60
+ 'Please set BEDROCK_API_KEY in your .env file or pass authToken in options.');
61
+ }
62
+ // Validate that the model is provided
63
+ if (!model) {
64
+ throw new Error('Model name is required but not provided. ' +
65
+ 'Please set BEDROCK_MODEL in your .env file or pass model in options.');
66
+ }
67
+ // Bedrock Converse text-block extraction. Image input (Converse image blocks)
68
+ // is a planned follow-up — for now we extract the text parts only.
69
+ if ((0, multimodal_utils_1.hasImages)(userPrompt)) {
70
+ logging_utils_1.logger.warn('Image input is not yet supported by the Bedrock provider; using text parts only', {
71
+ context: 'BedrockProvider',
72
+ metadata: { model }
73
+ });
74
+ }
75
+ let userText = typeof userPrompt === 'string'
76
+ ? userPrompt
77
+ : (0, multimodal_utils_1.normalizeContent)(userPrompt)
78
+ .filter((p) => p.type === 'text')
79
+ .map(p => p.text)
80
+ .join('\n');
81
+ // Build Converse inferenceConfig (standardized inference parameters)
82
+ const inferenceConfig = {
83
+ maxTokens,
84
+ temperature,
85
+ ...(topP !== undefined && { topP }),
86
+ ...(stopSequences && { stopSequences })
87
+ };
88
+ // Apply model-specific reasoning mapping. The consumer always sets the
89
+ // provider-agnostic `reasoningEffort`; the strategy translates it to the
90
+ // right mechanism for this model family (reasoning_effort / reasoningConfig /
91
+ // prompt suffix / no-op) and reports inference-parameter constraints to honor.
92
+ let additionalModelRequestFields;
93
+ if (reasoningEffort) {
94
+ const reasoning = bedrock_reasoning_1.BedrockReasoningFactory.forModel(model).apply(reasoningEffort);
95
+ if (reasoning.additionalModelRequestFields) {
96
+ additionalModelRequestFields = { ...reasoning.additionalModelRequestFields };
97
+ }
98
+ if (reasoning.removeInferenceConfigKeys) {
99
+ for (const key of reasoning.removeInferenceConfigKeys) {
100
+ delete inferenceConfig[key];
101
+ }
102
+ }
103
+ if (reasoning.promptSuffix) {
104
+ userText = `${userText}${reasoning.promptSuffix}`;
105
+ }
106
+ (reasoning.warnings ?? []).forEach(w => logging_utils_1.logger.warn(w, { context: 'BedrockProvider', metadata: { model, reasoningEffort } }));
107
+ }
108
+ // Build the Converse request payload
109
+ const requestPayload = {
110
+ messages: [
111
+ { role: 'user', content: [{ text: userText }] }
112
+ ],
113
+ // Converse expects `system` as an array of text blocks at the top level
114
+ ...(systemMessage && { system: [{ text: systemMessage }] }),
115
+ inferenceConfig,
116
+ ...(additionalModelRequestFields && { additionalModelRequestFields })
117
+ };
118
+ const endpoint = this.buildEndpoint(region, model);
119
+ const headers = {
120
+ 'Content-Type': 'application/json',
121
+ 'Accept': 'application/json',
122
+ 'Authorization': `Bearer ${authToken}`
123
+ };
124
+ // Get client request body from global scope (optional, for richer logs)
125
+ let clientRequestBody = undefined;
126
+ try {
127
+ clientRequestBody = global.currentRequestBody;
128
+ }
129
+ catch {
130
+ // Ignore — optional
131
+ }
132
+ // Use debug string to avoid base64 blobs in logs
133
+ const userMessageDebug = (0, multimodal_utils_1.contentToDebugString)(userPrompt);
134
+ const debugInfo = {
135
+ timestamp: new Date(),
136
+ provider: this.providerName,
137
+ model,
138
+ baseUrl: endpoint,
139
+ systemMessage,
140
+ userMessage: userMessageDebug,
141
+ requestData: requestPayload,
142
+ useCase: debugContext,
143
+ clientRequestBody,
144
+ sessionId,
145
+ chapterNumber,
146
+ pageNumber,
147
+ pageName,
148
+ temperature,
149
+ reasoningEffort
150
+ };
151
+ await debug_llm_utils_1.LLMDebugger.logRequest(debugInfo);
152
+ const contextForLogger = {
153
+ currentChapterNr: chapterNumber,
154
+ currentPage: pageNumber,
155
+ debugContext
156
+ };
157
+ const requestId = this.dataFlowLogger.startRequest(debugContext || 'bedrock-converse', contextForLogger);
158
+ this.dataFlowLogger.logLLMRequest({
159
+ stage: debugContext || 'bedrock-converse',
160
+ prompt: userMessageDebug,
161
+ systemMessage,
162
+ modelName: model,
163
+ temperature,
164
+ contextInfo: {
165
+ sessionId,
166
+ chapterNumber,
167
+ pageNumber,
168
+ pageName,
169
+ parameters: { maxTokens, topP, stopSequences, region }
170
+ }
171
+ }, contextForLogger, requestId);
172
+ const requestStartTime = Date.now();
173
+ try {
174
+ logging_utils_1.logger.info('Sending request to AWS Bedrock (Converse)', {
175
+ context: 'BedrockProvider',
176
+ metadata: {
177
+ url: endpoint,
178
+ model,
179
+ region,
180
+ promptLength: (0, multimodal_utils_1.contentLength)(userPrompt),
181
+ maxTokens
182
+ }
183
+ });
184
+ const response = await (0, retry_utils_1.retryWithBackoff)(() => axios_1.default.post(endpoint, requestPayload, { headers, timeout }), this.constructor.name, options.retry);
185
+ const requestDuration = Date.now() - requestStartTime;
186
+ if (response && response.status === 200) {
187
+ const apiResponse = response.data;
188
+ const blocks = apiResponse.output?.message?.content ?? [];
189
+ // Extract generated text from text blocks
190
+ const rawResponseText = blocks
191
+ .filter(block => block.text !== undefined)
192
+ .map(block => block.text)
193
+ .join('\n');
194
+ // Native reasoning text (reasoning-capable models like Qwen3, Claude thinking)
195
+ const nativeReasoning = blocks
196
+ .map(block => block.reasoningContent?.reasoningText?.text)
197
+ .filter((t) => !!t)
198
+ .join('\n');
199
+ // Fall back to tag-based extraction (<think>...) for models that inline
200
+ // their reasoning in the text. Native reasoningContent takes priority.
201
+ const extractor = thinking_1.ThinkingExtractorFactory.forModel(model);
202
+ const { content: responseText, thinking: extractedThinking } = extractor.extract(rawResponseText);
203
+ const thinking = nativeReasoning || extractedThinking;
204
+ // Normalize token usage to the provider-agnostic format
205
+ const tokenUsage = {
206
+ inputTokens: apiResponse.usage.inputTokens,
207
+ outputTokens: apiResponse.usage.outputTokens,
208
+ totalTokens: apiResponse.usage.totalTokens,
209
+ // Include cache metadata if the model reported cached tokens
210
+ ...((apiResponse.usage.cacheReadInputTokens || apiResponse.usage.cacheWriteInputTokens) ? {
211
+ cacheMetadata: {
212
+ cacheReadTokens: apiResponse.usage.cacheReadInputTokens,
213
+ cacheCreationTokens: apiResponse.usage.cacheWriteInputTokens
214
+ }
215
+ } : {})
216
+ };
217
+ const normalizedResponse = {
218
+ message: {
219
+ content: responseText,
220
+ ...(thinking && { thinking })
221
+ },
222
+ sessionId,
223
+ metadata: {
224
+ provider: this.providerName,
225
+ model,
226
+ tokensUsed: tokenUsage.totalTokens,
227
+ processingTime: requestDuration,
228
+ region
229
+ },
230
+ usage: tokenUsage,
231
+ stopReason: apiResponse.stopReason
232
+ };
233
+ debugInfo.responseTimestamp = new Date();
234
+ debugInfo.response = responseText;
235
+ debugInfo.rawResponseData = apiResponse;
236
+ if (thinking) {
237
+ debugInfo.thinking = thinking;
238
+ }
239
+ await debug_llm_utils_1.LLMDebugger.logResponse(debugInfo);
240
+ this.dataFlowLogger.logLLMResponse(debugContext || 'bedrock-converse', { rawResponse: responseText, processingTime: requestDuration }, contextForLogger, requestId);
241
+ return normalizedResponse;
242
+ }
243
+ else {
244
+ const error = new Error(`Status ${response?.status || 'unknown'}`);
245
+ logging_utils_1.logger.error('Error calling AWS Bedrock', {
246
+ context: this.constructor.name,
247
+ error: error.message,
248
+ metadata: response?.data || {}
249
+ });
250
+ this.dataFlowLogger.logLLMResponse(debugContext || 'bedrock-converse', { rawResponse: '', processingTime: Date.now() - requestStartTime, error }, contextForLogger, requestId);
251
+ return null;
252
+ }
253
+ }
254
+ catch (error) {
255
+ let errorMessage = 'Unknown error';
256
+ let errorDetails = {};
257
+ if (error instanceof Error) {
258
+ errorMessage = error.message;
259
+ }
260
+ if (error &&
261
+ typeof error === 'object' &&
262
+ 'isAxiosError' in error &&
263
+ error.isAxiosError === true) {
264
+ const axiosError = error;
265
+ if (axiosError.response) {
266
+ errorDetails = {
267
+ statusCode: axiosError.response.status,
268
+ statusText: axiosError.response.statusText,
269
+ data: axiosError.response.data
270
+ };
271
+ if (axiosError.response.status === 401) {
272
+ logging_utils_1.logger.error('Authentication error with AWS Bedrock', {
273
+ context: this.constructor.name,
274
+ error: 'Invalid or expired Bedrock API key',
275
+ metadata: { statusCode: 401, message: axiosError.response.data?.message }
276
+ });
277
+ }
278
+ else if (axiosError.response.status === 403) {
279
+ logging_utils_1.logger.error('Access denied by AWS Bedrock', {
280
+ context: this.constructor.name,
281
+ error: 'Model access not granted, or model not available in this region',
282
+ metadata: {
283
+ statusCode: 403,
284
+ model,
285
+ region,
286
+ hint: 'Check "Model access" in the Bedrock console for this region.'
287
+ }
288
+ });
289
+ }
290
+ else if (axiosError.response.status === 429) {
291
+ logging_utils_1.logger.error('Rate limit / quota exceeded on AWS Bedrock', {
292
+ context: this.constructor.name,
293
+ error: 'Too many requests',
294
+ metadata: { statusCode: 429, retryAfter: axiosError.response.headers?.['retry-after'] }
295
+ });
296
+ }
297
+ else if (axiosError.response.status === 400) {
298
+ logging_utils_1.logger.error('Bad request to AWS Bedrock', {
299
+ context: this.constructor.name,
300
+ error: axiosError.response.data?.message || 'Invalid request',
301
+ metadata: { model, details: axiosError.response.data }
302
+ });
303
+ }
304
+ }
305
+ }
306
+ logging_utils_1.logger.error('Error in Bedrock API request', {
307
+ context: this.constructor.name,
308
+ error: errorMessage,
309
+ metadata: { ...errorDetails, requestModel: model, region, sessionId }
310
+ });
311
+ this.dataFlowLogger.logLLMResponse(debugContext || 'bedrock-converse', {
312
+ rawResponse: '',
313
+ processingTime: Date.now() - requestStartTime,
314
+ error: error instanceof Error ? error : new Error(errorMessage)
315
+ }, contextForLogger, requestId);
316
+ debugInfo.responseTimestamp = new Date();
317
+ debugInfo.error = { message: errorMessage, details: errorDetails };
318
+ await debug_llm_utils_1.LLMDebugger.logError(debugInfo);
319
+ return null;
320
+ }
321
+ }
322
+ }
323
+ exports.BedrockProvider = BedrockProvider;
324
+ exports.BedrockService = BedrockProvider;
325
+ // Export singleton instance
326
+ exports.bedrockProvider = new BedrockProvider();
327
+ exports.bedrockService = exports.bedrockProvider;
328
+ //# sourceMappingURL=bedrock-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bedrock-provider.js","sourceRoot":"","sources":["../../../../../src/middleware/services/llm/providers/bedrock-provider.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,+BAAoC;AACpC,uEAA6D;AAC7D,2DAAsD;AACtD,oCAAsE;AAStE,8DAAqE;AACrE,6DAA+D;AAC/D,0CAAuD;AACvD,sDAAwD;AACxD,gEAA6G;AAC7G,2DAA8D;AAE9D;;;;;;;;;;;;;;GAcG;AACH,MAAa,eAAgB,SAAQ,mCAAe;IAKlD;QACE,KAAK,CAAC,mBAAW,CAAC,OAA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AE;yBACvD,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;YAED,sBAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE;gBAC3C,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;gBAC9B,KAAK,EAAE,YAAY;gBACnB,QAAQ,EAAE,EAAE,GAAG,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE;aACtE,CAAC,CAAC;YAEH,IAAI,CAAC,cAAc,CAAC,cAAc,CAChC,YAAY,IAAI,kBAAkB,EAClC;gBACE,WAAW,EAAE,EAAE;gBACf,cAAc,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,gBAAgB;gBAC7C,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC;aAChE,EACD,gBAAgB,EAChB,SAAS,CACV,CAAC;YAEF,SAAS,CAAC,iBAAiB,GAAG,IAAI,IAAI,EAAE,CAAC;YACzC,SAAS,CAAC,KAAK,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;YACnE,MAAM,6BAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;YAEtC,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA5XD,0CA4XC;AAM2B,yCAAc;AAJ1C,4BAA4B;AACf,QAAA,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AAIzB,yBAJf,uBAAe,CAIc"}
@@ -0,0 +1,21 @@
1
+ import { BedrockReasoningStrategy } from './bedrock-reasoning.types';
2
+ /**
3
+ * Selects the {@link BedrockReasoningStrategy} for a given Bedrock model id.
4
+ *
5
+ * Mapping (by model-id substring):
6
+ * - `nova` → reasoningConfig (Amazon Nova 2)
7
+ * - `minimax` → no-op (always-on interleaved thinking, no toggle)
8
+ * - `anthropic` / `claude` → no-op (uses `thinking` budget, not reasoning_effort — follow-up)
9
+ * - everything else → reasoning_effort (Qwen, Kimi, gpt-oss, GLM, DeepSeek, …)
10
+ *
11
+ * `reasoning_effort` is the default because it is supported by every open-weight
12
+ * model verified on Bedrock Converse, which keeps behavior uniform "regardless of model".
13
+ */
14
+ export declare class BedrockReasoningFactory {
15
+ private static readonly reasoningEffort;
16
+ private static readonly nova;
17
+ private static readonly minimax;
18
+ private static readonly claude;
19
+ static forModel(model: string): BedrockReasoningStrategy;
20
+ }
21
+ //# sourceMappingURL=bedrock-reasoning.factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bedrock-reasoning.factory.d.ts","sourceRoot":"","sources":["../../../../../../src/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAKrE;;;;;;;;;;;GAWG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAiC;IACxE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAA+B;IAC3D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAG7B;IACF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAG5B;IAEF,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,wBAAwB;CAOzD"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BedrockReasoningFactory = void 0;
4
+ const reasoning_effort_strategy_1 = require("./reasoning-effort.strategy");
5
+ const nova_reasoning_strategy_1 = require("./nova-reasoning.strategy");
6
+ const noop_reasoning_strategy_1 = require("./noop-reasoning.strategy");
7
+ /**
8
+ * Selects the {@link BedrockReasoningStrategy} for a given Bedrock model id.
9
+ *
10
+ * Mapping (by model-id substring):
11
+ * - `nova` → reasoningConfig (Amazon Nova 2)
12
+ * - `minimax` → no-op (always-on interleaved thinking, no toggle)
13
+ * - `anthropic` / `claude` → no-op (uses `thinking` budget, not reasoning_effort — follow-up)
14
+ * - everything else → reasoning_effort (Qwen, Kimi, gpt-oss, GLM, DeepSeek, …)
15
+ *
16
+ * `reasoning_effort` is the default because it is supported by every open-weight
17
+ * model verified on Bedrock Converse, which keeps behavior uniform "regardless of model".
18
+ */
19
+ class BedrockReasoningFactory {
20
+ static forModel(model) {
21
+ const m = model.toLowerCase();
22
+ if (m.includes('nova'))
23
+ return this.nova;
24
+ if (m.includes('minimax'))
25
+ return this.minimax;
26
+ if (m.includes('anthropic') || m.includes('claude'))
27
+ return this.claude;
28
+ return this.reasoningEffort;
29
+ }
30
+ }
31
+ exports.BedrockReasoningFactory = BedrockReasoningFactory;
32
+ BedrockReasoningFactory.reasoningEffort = new reasoning_effort_strategy_1.ReasoningEffortStrategy();
33
+ BedrockReasoningFactory.nova = new nova_reasoning_strategy_1.NovaReasoningStrategy();
34
+ BedrockReasoningFactory.minimax = new noop_reasoning_strategy_1.NoOpReasoningStrategy('MiniMax uses always-on interleaved thinking with no Converse toggle', 'noop-minimax');
35
+ BedrockReasoningFactory.claude = new noop_reasoning_strategy_1.NoOpReasoningStrategy("Claude on Bedrock uses a 'thinking' token budget, not reasoning_effort (mapping is a planned follow-up)", 'noop-claude');
36
+ //# sourceMappingURL=bedrock-reasoning.factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bedrock-reasoning.factory.js","sourceRoot":"","sources":["../../../../../../src/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.factory.ts"],"names":[],"mappings":";;;AACA,2EAAsE;AACtE,uEAAkE;AAClE,uEAAkE;AAElE;;;;;;;;;;;GAWG;AACH,MAAa,uBAAuB;IAYlC,MAAM,CAAC,QAAQ,CAAC,KAAa;QAC3B,MAAM,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QAC9B,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,OAAO,IAAI,CAAC,IAAI,CAAC;QACzC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC;QAC/C,IAAI,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,IAAI,CAAC,MAAM,CAAC;QACxE,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;;AAlBH,0DAmBC;AAlByB,uCAAe,GAAG,IAAI,mDAAuB,EAAE,CAAC;AAChD,4BAAI,GAAG,IAAI,+CAAqB,EAAE,CAAC;AACnC,+BAAO,GAAG,IAAI,+CAAqB,CACzD,qEAAqE,EACrE,cAAc,CACf,CAAC;AACsB,8BAAM,GAAG,IAAI,+CAAqB,CACxD,yGAAyG,EACzG,aAAa,CACd,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Reasoning strategy abstraction for the AWS Bedrock provider.
3
+ *
4
+ * Bedrock has no unified reasoning parameter across model families:
5
+ * - Most open-weight models (Kimi, gpt-oss, GLM, DeepSeek) accept the
6
+ * OpenAI-style `reasoning_effort` (low/medium/high) → verified live.
7
+ * - Amazon Nova uses `reasoningConfig` ({ type, maxReasoningEffort }) and forbids
8
+ * some inference parameters at maxReasoningEffort=high.
9
+ * - Qwen toggles thinking via a prompt suffix (`/no_think`).
10
+ * - Some models (MiniMax) have no reasoning control at all.
11
+ *
12
+ * This Strategy Pattern (mirroring the ThinkingExtractor pattern) hides that
13
+ * heterogeneity: the consumer always sets the provider-agnostic `reasoningEffort`,
14
+ * and the provider applies the right mechanism per model.
15
+ */
16
+ import { ReasoningEffort } from '../../types';
17
+ import { BedrockInferenceConfig } from '../../types/bedrock.types';
18
+ /**
19
+ * The set of request modifications a strategy produces for a given effort.
20
+ * The provider merges these into the outgoing Converse request.
21
+ */
22
+ export interface BedrockReasoningApplication {
23
+ /**
24
+ * Fields to merge into the request's `additionalModelRequestFields`
25
+ * (model-specific reasoning toggles, e.g. `{ reasoning_effort: 'high' }`).
26
+ */
27
+ additionalModelRequestFields?: Record<string, unknown>;
28
+ /**
29
+ * `inferenceConfig` keys the model forbids while reasoning is active and that
30
+ * the provider must remove (e.g. Nova at maxReasoningEffort=high forbids
31
+ * temperature/topP/maxTokens). The provider removes them and logs a warning.
32
+ */
33
+ removeInferenceConfigKeys?: (keyof BedrockInferenceConfig)[];
34
+ /** Text appended to the user prompt (e.g. Qwen `/no_think` to disable thinking). */
35
+ promptSuffix?: string;
36
+ /** Human-readable warnings the provider should surface via the logger. */
37
+ warnings?: string[];
38
+ }
39
+ /**
40
+ * Maps the provider-agnostic {@link ReasoningEffort} to a specific model family's
41
+ * reasoning mechanism on the Bedrock Converse API.
42
+ */
43
+ export interface BedrockReasoningStrategy {
44
+ /** Strategy name, used for logging/debugging. */
45
+ readonly name: string;
46
+ /**
47
+ * Produces the request modifications for the requested effort.
48
+ * Only called when `reasoningEffort` is defined; when it is undefined the
49
+ * provider leaves reasoning untouched (each model uses its own default).
50
+ */
51
+ apply(effort: ReasoningEffort): BedrockReasoningApplication;
52
+ }
53
+ //# sourceMappingURL=bedrock-reasoning.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bedrock-reasoning.types.d.ts","sourceRoot":"","sources":["../../../../../../src/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,4BAA4B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEvD;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,CAAC,MAAM,sBAAsB,CAAC,EAAE,CAAC;IAE7D,oFAAoF;IACpF,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,iDAAiD;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,eAAe,GAAG,2BAA2B,CAAC;CAC7D"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /**
3
+ * Reasoning strategy abstraction for the AWS Bedrock provider.
4
+ *
5
+ * Bedrock has no unified reasoning parameter across model families:
6
+ * - Most open-weight models (Kimi, gpt-oss, GLM, DeepSeek) accept the
7
+ * OpenAI-style `reasoning_effort` (low/medium/high) → verified live.
8
+ * - Amazon Nova uses `reasoningConfig` ({ type, maxReasoningEffort }) and forbids
9
+ * some inference parameters at maxReasoningEffort=high.
10
+ * - Qwen toggles thinking via a prompt suffix (`/no_think`).
11
+ * - Some models (MiniMax) have no reasoning control at all.
12
+ *
13
+ * This Strategy Pattern (mirroring the ThinkingExtractor pattern) hides that
14
+ * heterogeneity: the consumer always sets the provider-agnostic `reasoningEffort`,
15
+ * and the provider applies the right mechanism per model.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ //# sourceMappingURL=bedrock-reasoning.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bedrock-reasoning.types.js","sourceRoot":"","sources":["../../../../../../src/middleware/services/llm/providers/bedrock-reasoning/bedrock-reasoning.types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG"}
@@ -0,0 +1,6 @@
1
+ export * from './bedrock-reasoning.types';
2
+ export * from './reasoning-effort.strategy';
3
+ export * from './nova-reasoning.strategy';
4
+ export * from './noop-reasoning.strategy';
5
+ export * from './bedrock-reasoning.factory';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/middleware/services/llm/providers/bedrock-reasoning/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./bedrock-reasoning.types"), exports);
18
+ __exportStar(require("./reasoning-effort.strategy"), exports);
19
+ __exportStar(require("./nova-reasoning.strategy"), exports);
20
+ __exportStar(require("./noop-reasoning.strategy"), exports);
21
+ __exportStar(require("./bedrock-reasoning.factory"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/middleware/services/llm/providers/bedrock-reasoning/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,8DAA4C;AAC5C,4DAA0C;AAC1C,4DAA0C;AAC1C,8DAA4C"}
@@ -0,0 +1,17 @@
1
+ import { ReasoningEffort } from '../../types';
2
+ import { BedrockReasoningStrategy, BedrockReasoningApplication } from './bedrock-reasoning.types';
3
+ /**
4
+ * No-op reasoning strategy for models without configurable reasoning on Converse.
5
+ *
6
+ * Used for MiniMax (always-on "interleaved thinking", no toggle) and for model
7
+ * families whose reasoning is not yet mapped (e.g. Anthropic Claude, which uses a
8
+ * `thinking` token budget instead of `reasoning_effort`). Emits a warning so the
9
+ * consumer knows the requested effort had no effect.
10
+ */
11
+ export declare class NoOpReasoningStrategy implements BedrockReasoningStrategy {
12
+ private readonly reason;
13
+ readonly name: string;
14
+ constructor(reason: string, name?: string);
15
+ apply(effort: ReasoningEffort): BedrockReasoningApplication;
16
+ }
17
+ //# sourceMappingURL=noop-reasoning.strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noop-reasoning.strategy.d.ts","sourceRoot":"","sources":["../../../../../../src/middleware/services/llm/providers/bedrock-reasoning/noop-reasoning.strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAElG;;;;;;;GAOG;AACH,qBAAa,qBAAsB,YAAW,wBAAwB;IAGxD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEO,MAAM,EAAE,MAAM,EAAE,IAAI,SAAS;IAI1D,KAAK,CAAC,MAAM,EAAE,eAAe,GAAG,2BAA2B;CAK5D"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoOpReasoningStrategy = void 0;
4
+ /**
5
+ * No-op reasoning strategy for models without configurable reasoning on Converse.
6
+ *
7
+ * Used for MiniMax (always-on "interleaved thinking", no toggle) and for model
8
+ * families whose reasoning is not yet mapped (e.g. Anthropic Claude, which uses a
9
+ * `thinking` token budget instead of `reasoning_effort`). Emits a warning so the
10
+ * consumer knows the requested effort had no effect.
11
+ */
12
+ class NoOpReasoningStrategy {
13
+ constructor(reason, name = 'noop') {
14
+ this.reason = reason;
15
+ this.name = name;
16
+ }
17
+ apply(effort) {
18
+ return {
19
+ warnings: [`reasoningEffort '${effort}' is not applied: ${this.reason}`]
20
+ };
21
+ }
22
+ }
23
+ exports.NoOpReasoningStrategy = NoOpReasoningStrategy;
24
+ //# sourceMappingURL=noop-reasoning.strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noop-reasoning.strategy.js","sourceRoot":"","sources":["../../../../../../src/middleware/services/llm/providers/bedrock-reasoning/noop-reasoning.strategy.ts"],"names":[],"mappings":";;;AAGA;;;;;;;GAOG;AACH,MAAa,qBAAqB;IAGhC,YAA6B,MAAc,EAAE,IAAI,GAAG,MAAM;QAA7B,WAAM,GAAN,MAAM,CAAQ;QACzC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,MAAuB;QAC3B,OAAO;YACL,QAAQ,EAAE,CAAC,oBAAoB,MAAM,qBAAqB,IAAI,CAAC,MAAM,EAAE,CAAC;SACzE,CAAC;IACJ,CAAC;CACF;AAZD,sDAYC"}