@yuva-devlab/ai-client 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +170 -2
- package/dist/index.cjs +1266 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1256 -0
- package/dist/index.d.ts +1256 -0
- package/dist/index.js +1233 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1266 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
var errors = require('@yuva-devlab/errors');
|
|
5
|
+
var logger$1 = require('@yuva-devlab/logger');
|
|
6
|
+
|
|
7
|
+
// src/constants/endpoints.constants.ts
|
|
8
|
+
var AI_ENDPOINTS = Object.freeze({
|
|
9
|
+
/** Local or edge Ollama REST service endpoint */
|
|
10
|
+
OLLAMA_DEFAULT_BASE_URL: "http://127.0.0.1:11434",
|
|
11
|
+
/** Groq OpenAI-compatible v1 chat completions endpoint */
|
|
12
|
+
GROQ_DEFAULT_BASE_URL: "https://api.groq.com/openai/v1",
|
|
13
|
+
/** OpenAI standard v1 REST API endpoint */
|
|
14
|
+
OPENAI_DEFAULT_BASE_URL: "https://api.openai.com/v1",
|
|
15
|
+
/** Anthropic Claude v1 REST messages API endpoint */
|
|
16
|
+
ANTHROPIC_DEFAULT_BASE_URL: "https://api.anthropic.com/v1",
|
|
17
|
+
/** Google Gemini Generative Language v1beta endpoint */
|
|
18
|
+
GOOGLE_GEMINI_DEFAULT_BASE_URL: "https://generativelanguage.googleapis.com/v1beta",
|
|
19
|
+
/** Required Anthropic API version header value */
|
|
20
|
+
ANTHROPIC_VERSION_HEADER: "2023-06-01"
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// src/constants/models.constants.ts
|
|
24
|
+
var AI_DEFAULT_MODELS = Object.freeze({
|
|
25
|
+
/** Default Ollama local model */
|
|
26
|
+
OLLAMA: "qwen2.5:7b",
|
|
27
|
+
/** Default Groq ultra-low latency model */
|
|
28
|
+
GROQ: "llama-3.3-70b-versatile",
|
|
29
|
+
/** Default Google Gemini model */
|
|
30
|
+
GOOGLE: "gemini-2.5-flash",
|
|
31
|
+
/** Default OpenAI model */
|
|
32
|
+
OPENAI: "gpt-4o-mini",
|
|
33
|
+
/** Default Anthropic Claude model */
|
|
34
|
+
ANTHROPIC: "claude-3-5-haiku-latest"
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// src/constants/execution.constants.ts
|
|
38
|
+
var AI_EXECUTION_DEFAULTS = Object.freeze({
|
|
39
|
+
/** Default sampling temperature for balanced determinism and coherence */
|
|
40
|
+
DEFAULT_TEMPERATURE: 0.7,
|
|
41
|
+
/** Default per-request completion timeout in milliseconds (60 seconds) */
|
|
42
|
+
DEFAULT_TIMEOUT_MS: 6e4,
|
|
43
|
+
/** Default upper bound for output token generation */
|
|
44
|
+
DEFAULT_MAX_OUTPUT_TOKENS: 4096,
|
|
45
|
+
/** Default retry limit for self-healing structured JSON output extraction */
|
|
46
|
+
DEFAULT_MAX_REPAIR_RETRIES: 2
|
|
47
|
+
});
|
|
48
|
+
var MessageRole = {
|
|
49
|
+
/** System directives establishing model persona, safety guidelines, and tool catalog */
|
|
50
|
+
SYSTEM: "SYSTEM",
|
|
51
|
+
/** End-user input turn */
|
|
52
|
+
USER: "USER",
|
|
53
|
+
/** Assistant generative completion turn or previous reasoning trace */
|
|
54
|
+
ASSISTANT: "ASSISTANT",
|
|
55
|
+
/** Return output payload from an executed tool or external function */
|
|
56
|
+
TOOL: "TOOL"
|
|
57
|
+
};
|
|
58
|
+
var ToolCallSchema = zod.z.object({
|
|
59
|
+
/** Unique tool call identifier assigned by the model provider */
|
|
60
|
+
id: zod.z.string().describe("Unique tool call ID assigned by the model"),
|
|
61
|
+
/** Name of the tool or function requested to execute */
|
|
62
|
+
name: zod.z.string().describe("Name of the tool requested"),
|
|
63
|
+
/** Parsed arguments dictionary conforming to the tool's input schema */
|
|
64
|
+
arguments: zod.z.record(zod.z.string(), zod.z.unknown()).describe("Parsed arguments dictionary")
|
|
65
|
+
});
|
|
66
|
+
var AIMessageSchema = zod.z.object({
|
|
67
|
+
/** Conversational role of the turn */
|
|
68
|
+
role: zod.z.enum([
|
|
69
|
+
MessageRole.SYSTEM,
|
|
70
|
+
MessageRole.USER,
|
|
71
|
+
MessageRole.ASSISTANT,
|
|
72
|
+
MessageRole.TOOL
|
|
73
|
+
]),
|
|
74
|
+
/** Primary text content of the message */
|
|
75
|
+
content: zod.z.string().describe("Primary text content of the message turn"),
|
|
76
|
+
/** Optional author username, agent name, or tool identifier */
|
|
77
|
+
name: zod.z.string().optional().describe("Optional author name or tool identifier"),
|
|
78
|
+
/** Optional structured tool calls emitted by the model */
|
|
79
|
+
toolCalls: zod.z.array(ToolCallSchema).optional().describe("Tool calls invoked by the model"),
|
|
80
|
+
/** Associated tool call ID when role is TOOL */
|
|
81
|
+
toolCallId: zod.z.string().optional().describe("Associated tool call ID for TOOL responses")
|
|
82
|
+
});
|
|
83
|
+
function createUserMessage(content, name) {
|
|
84
|
+
return { role: MessageRole.USER, content, name };
|
|
85
|
+
}
|
|
86
|
+
function createSystemMessage(content) {
|
|
87
|
+
return { role: MessageRole.SYSTEM, content };
|
|
88
|
+
}
|
|
89
|
+
function createAssistantMessage(content, toolCalls) {
|
|
90
|
+
return { role: MessageRole.ASSISTANT, content, toolCalls };
|
|
91
|
+
}
|
|
92
|
+
function createToolResultMessage(toolCallId, content, name) {
|
|
93
|
+
return { role: MessageRole.TOOL, content, toolCallId, name };
|
|
94
|
+
}
|
|
95
|
+
var LLMRequestOptionsSchema = zod.z.object({
|
|
96
|
+
/** Model identifier string (e.g. "gemma4:31b-cloud", "qwen2.5:7b", "llama-3.3-70b-versatile") */
|
|
97
|
+
model: zod.z.string().min(1).describe("Target model name or slug"),
|
|
98
|
+
/** Sampling temperature: 0.0 deterministic to 1.0+ creative (defaults to AI_EXECUTION_DEFAULTS.DEFAULT_TEMPERATURE) */
|
|
99
|
+
temperature: zod.z.number().min(0).max(2).default(AI_EXECUTION_DEFAULTS.DEFAULT_TEMPERATURE).describe("Sampling temperature"),
|
|
100
|
+
/** Maximum completion output tokens */
|
|
101
|
+
maxTokens: zod.z.number().int().positive().optional().describe("Output token limit"),
|
|
102
|
+
/** Nucleus sampling probability cutoff */
|
|
103
|
+
topP: zod.z.number().min(0).max(1).optional().describe("Top-P nucleus sampling"),
|
|
104
|
+
/** Optional stop sequences causing generation to cease */
|
|
105
|
+
stop: zod.z.array(zod.z.string()).optional().describe("Stop sequences"),
|
|
106
|
+
/** Response format enforcement (e.g. json_object or text) */
|
|
107
|
+
responseFormat: zod.z.enum(["text", "json_object"]).default("text").describe("Output format"),
|
|
108
|
+
/** Per-request timeout limit in milliseconds (defaults to AI_EXECUTION_DEFAULTS.DEFAULT_TIMEOUT_MS) */
|
|
109
|
+
timeoutMs: zod.z.number().int().positive().default(AI_EXECUTION_DEFAULTS.DEFAULT_TIMEOUT_MS).describe("Timeout limit in ms")
|
|
110
|
+
});
|
|
111
|
+
var LLMRequestSchema = LLMRequestOptionsSchema.extend({
|
|
112
|
+
/** Ordered conversation history */
|
|
113
|
+
messages: zod.z.array(AIMessageSchema).min(1).describe("Conversation history turns")
|
|
114
|
+
});
|
|
115
|
+
var FinishReason = {
|
|
116
|
+
/** Generation finished naturally at a stop sequence or end of turn */
|
|
117
|
+
STOP: "STOP",
|
|
118
|
+
/** Generation stopped due to hitting maxTokens limit */
|
|
119
|
+
LENGTH: "LENGTH",
|
|
120
|
+
/** Model emitted one or more structured tool calls */
|
|
121
|
+
TOOL_CALLS: "TOOL_CALLS",
|
|
122
|
+
/** Generation blocked by safety filters or policy guardrails */
|
|
123
|
+
CONTENT_FILTER: "CONTENT_FILTER",
|
|
124
|
+
/** Generation aborted due to an internal execution error */
|
|
125
|
+
ERROR: "ERROR"
|
|
126
|
+
};
|
|
127
|
+
var LLMUsageSchema = zod.z.object({
|
|
128
|
+
/** Prompt / context tokens evaluated */
|
|
129
|
+
promptTokens: zod.z.number().int().nonnegative().default(0),
|
|
130
|
+
/** Tokens generated in completion */
|
|
131
|
+
completionTokens: zod.z.number().int().nonnegative().default(0),
|
|
132
|
+
/** Total tokens processed */
|
|
133
|
+
totalTokens: zod.z.number().int().nonnegative().default(0)
|
|
134
|
+
});
|
|
135
|
+
var LLMResponseSchema = zod.z.object({
|
|
136
|
+
/** Generated completion text */
|
|
137
|
+
text: zod.z.string().describe("Generated completion text"),
|
|
138
|
+
/** Canonical termination reason */
|
|
139
|
+
finishReason: zod.z.enum([
|
|
140
|
+
FinishReason.STOP,
|
|
141
|
+
FinishReason.LENGTH,
|
|
142
|
+
FinishReason.TOOL_CALLS,
|
|
143
|
+
FinishReason.CONTENT_FILTER,
|
|
144
|
+
FinishReason.ERROR
|
|
145
|
+
]),
|
|
146
|
+
/** Token usage statistics */
|
|
147
|
+
usage: LLMUsageSchema,
|
|
148
|
+
/** Optional tool invocations emitted by the model */
|
|
149
|
+
toolCalls: zod.z.array(ToolCallSchema).optional(),
|
|
150
|
+
/** Model that generated the completion */
|
|
151
|
+
model: zod.z.string().describe("Model that generated the completion"),
|
|
152
|
+
/** Wall-clock execution time in milliseconds */
|
|
153
|
+
durationMs: zod.z.number().nonnegative().optional()
|
|
154
|
+
});
|
|
155
|
+
var MissingCredentialError = class extends errors.DomainError {
|
|
156
|
+
constructor(providerName, envVarHint) {
|
|
157
|
+
super(
|
|
158
|
+
`Missing credentials for provider '${providerName}'. Pass an explicit apiKey in the adapter config or provide a CredentialResolver. Hint: If running locally in Node.js, ensure '${envVarHint}' is set in your application environment.`,
|
|
159
|
+
errors.ErrorCode.UNAUTHORIZED,
|
|
160
|
+
401,
|
|
161
|
+
{ providerName, envVarHint }
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// src/config/env-resolver.ts
|
|
167
|
+
function safeGetEnv(key) {
|
|
168
|
+
if (typeof process !== "undefined" && process?.env) {
|
|
169
|
+
return process.env[key];
|
|
170
|
+
}
|
|
171
|
+
return void 0;
|
|
172
|
+
}
|
|
173
|
+
function resolveEnvCredentials(provider) {
|
|
174
|
+
const norm = provider.toLowerCase();
|
|
175
|
+
switch (norm) {
|
|
176
|
+
case "ollama":
|
|
177
|
+
return {
|
|
178
|
+
baseUrl: safeGetEnv("OLLAMA_BASE_URL") ?? AI_ENDPOINTS.OLLAMA_DEFAULT_BASE_URL,
|
|
179
|
+
defaultModel: safeGetEnv("OLLAMA_MODEL") ?? AI_DEFAULT_MODELS.OLLAMA
|
|
180
|
+
};
|
|
181
|
+
case "groq":
|
|
182
|
+
return {
|
|
183
|
+
apiKey: safeGetEnv("GROQ_API_KEY"),
|
|
184
|
+
baseUrl: safeGetEnv("GROQ_BASE_URL") ?? AI_ENDPOINTS.GROQ_DEFAULT_BASE_URL,
|
|
185
|
+
defaultModel: safeGetEnv("GROQ_MODEL") ?? AI_DEFAULT_MODELS.GROQ
|
|
186
|
+
};
|
|
187
|
+
case "google":
|
|
188
|
+
return {
|
|
189
|
+
apiKey: safeGetEnv("GEMINI_API_KEY") ?? safeGetEnv("GOOGLE_AI_API_KEY"),
|
|
190
|
+
defaultModel: safeGetEnv("GEMINI_MODEL") ?? AI_DEFAULT_MODELS.GOOGLE
|
|
191
|
+
};
|
|
192
|
+
case "openai":
|
|
193
|
+
return {
|
|
194
|
+
apiKey: safeGetEnv("OPENAI_API_KEY"),
|
|
195
|
+
baseUrl: safeGetEnv("OPENAI_BASE_URL") ?? AI_ENDPOINTS.OPENAI_DEFAULT_BASE_URL,
|
|
196
|
+
defaultModel: safeGetEnv("OPENAI_MODEL") ?? AI_DEFAULT_MODELS.OPENAI
|
|
197
|
+
};
|
|
198
|
+
case "anthropic":
|
|
199
|
+
return {
|
|
200
|
+
apiKey: safeGetEnv("ANTHROPIC_API_KEY"),
|
|
201
|
+
baseUrl: safeGetEnv("ANTHROPIC_BASE_URL") ?? AI_ENDPOINTS.ANTHROPIC_DEFAULT_BASE_URL,
|
|
202
|
+
defaultModel: safeGetEnv("ANTHROPIC_MODEL") ?? AI_DEFAULT_MODELS.ANTHROPIC
|
|
203
|
+
};
|
|
204
|
+
default:
|
|
205
|
+
return {};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/adapters/ollama/ollama.types.ts
|
|
210
|
+
function mapOllamaMessages(messages) {
|
|
211
|
+
return messages.map((m) => {
|
|
212
|
+
let role = "user";
|
|
213
|
+
if (m.role === MessageRole.SYSTEM) role = "system";
|
|
214
|
+
else if (m.role === MessageRole.ASSISTANT) role = "assistant";
|
|
215
|
+
else if (m.role === MessageRole.TOOL) role = "tool";
|
|
216
|
+
return {
|
|
217
|
+
role,
|
|
218
|
+
content: m.content,
|
|
219
|
+
tool_name: m.role === MessageRole.TOOL ? m.name : void 0
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
var logger = logger$1.loggerWithConfig(new logger$1.Logger("OllamaAdapter"));
|
|
224
|
+
var OllamaAdapter = class {
|
|
225
|
+
name = "ollama";
|
|
226
|
+
config;
|
|
227
|
+
/**
|
|
228
|
+
* Initializes the Ollama adapter with optional configuration.
|
|
229
|
+
*
|
|
230
|
+
* @param config - Adapter connection and model configuration.
|
|
231
|
+
*/
|
|
232
|
+
constructor(config = {}) {
|
|
233
|
+
this.config = config;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Resolves effective connection parameters from explicit config, dynamic resolver, or ambient environment.
|
|
237
|
+
*/
|
|
238
|
+
async resolveCredentials() {
|
|
239
|
+
const dynamic = this.config.credentials ? await this.config.credentials() : {};
|
|
240
|
+
const env = resolveEnvCredentials(this.name);
|
|
241
|
+
const baseUrl = (this.config.baseUrl ?? dynamic.baseUrl ?? env.baseUrl ?? AI_ENDPOINTS.OLLAMA_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
242
|
+
const defaultModel = this.config.defaultModel ?? dynamic.defaultModel ?? env.defaultModel ?? AI_DEFAULT_MODELS.OLLAMA;
|
|
243
|
+
return { baseUrl, defaultModel };
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Executes a full non-streaming completion request against Ollama's /api/chat endpoint.
|
|
247
|
+
*
|
|
248
|
+
* @param request - Validated completion request.
|
|
249
|
+
* @returns Complete model response with token usage metrics.
|
|
250
|
+
*/
|
|
251
|
+
async complete(request) {
|
|
252
|
+
const { baseUrl, defaultModel } = await this.resolveCredentials();
|
|
253
|
+
const startTime = Date.now();
|
|
254
|
+
const model = request.model || defaultModel;
|
|
255
|
+
logger.debug("[complete] Executing Ollama completion", {
|
|
256
|
+
model,
|
|
257
|
+
baseUrl,
|
|
258
|
+
messageCount: request.messages.length
|
|
259
|
+
});
|
|
260
|
+
const controller = new AbortController();
|
|
261
|
+
const timeout = setTimeout(() => controller.abort(), request.timeoutMs);
|
|
262
|
+
try {
|
|
263
|
+
const response = await fetch(`${baseUrl}/api/chat`, {
|
|
264
|
+
method: "POST",
|
|
265
|
+
headers: { "Content-Type": "application/json" },
|
|
266
|
+
body: JSON.stringify({
|
|
267
|
+
model,
|
|
268
|
+
messages: mapOllamaMessages(request.messages),
|
|
269
|
+
stream: false,
|
|
270
|
+
options: {
|
|
271
|
+
temperature: request.temperature,
|
|
272
|
+
num_predict: request.maxTokens,
|
|
273
|
+
top_p: request.topP,
|
|
274
|
+
stop: request.stop
|
|
275
|
+
},
|
|
276
|
+
format: request.responseFormat === "json_object" ? "json" : void 0
|
|
277
|
+
}),
|
|
278
|
+
signal: controller.signal
|
|
279
|
+
});
|
|
280
|
+
if (!response.ok) {
|
|
281
|
+
const errorText = await response.text().catch(() => "");
|
|
282
|
+
logger.error("[complete] Ollama API error response", {
|
|
283
|
+
status: response.status,
|
|
284
|
+
errorText
|
|
285
|
+
});
|
|
286
|
+
throw new errors.DomainError(
|
|
287
|
+
`Ollama returned HTTP ${response.status}: ${errorText}`,
|
|
288
|
+
errors.ErrorCode.MODEL_PROVIDER_ERROR,
|
|
289
|
+
502
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
const data = await response.json();
|
|
293
|
+
const text = data.message?.content ?? "";
|
|
294
|
+
const durationMs = Date.now() - startTime;
|
|
295
|
+
logger.info("[complete] Ollama completion finished", {
|
|
296
|
+
model,
|
|
297
|
+
durationMs,
|
|
298
|
+
tokensOut: data.eval_count
|
|
299
|
+
});
|
|
300
|
+
return {
|
|
301
|
+
text,
|
|
302
|
+
finishReason: data.done_reason === "length" ? FinishReason.LENGTH : FinishReason.STOP,
|
|
303
|
+
usage: {
|
|
304
|
+
promptTokens: data.prompt_eval_count ?? 0,
|
|
305
|
+
completionTokens: data.eval_count ?? 0,
|
|
306
|
+
totalTokens: (data.prompt_eval_count ?? 0) + (data.eval_count ?? 0)
|
|
307
|
+
},
|
|
308
|
+
model,
|
|
309
|
+
durationMs
|
|
310
|
+
};
|
|
311
|
+
} catch (err) {
|
|
312
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
313
|
+
logger.warn("[complete] Ollama request timed out", {
|
|
314
|
+
model,
|
|
315
|
+
timeoutMs: request.timeoutMs
|
|
316
|
+
});
|
|
317
|
+
throw new errors.ModelTimeoutError(model, request.timeoutMs);
|
|
318
|
+
}
|
|
319
|
+
throw err;
|
|
320
|
+
} finally {
|
|
321
|
+
clearTimeout(timeout);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Initiates an NDJSON stream for token-by-token completion generation.
|
|
326
|
+
*
|
|
327
|
+
* @param request - Validated completion request.
|
|
328
|
+
* @returns Async iterable emitting token delta chunks.
|
|
329
|
+
*/
|
|
330
|
+
async *stream(request) {
|
|
331
|
+
const { baseUrl, defaultModel } = await this.resolveCredentials();
|
|
332
|
+
const model = request.model || defaultModel;
|
|
333
|
+
const response = await fetch(`${baseUrl}/api/chat`, {
|
|
334
|
+
method: "POST",
|
|
335
|
+
headers: { "Content-Type": "application/json" },
|
|
336
|
+
body: JSON.stringify({
|
|
337
|
+
model,
|
|
338
|
+
messages: mapOllamaMessages(request.messages),
|
|
339
|
+
stream: true,
|
|
340
|
+
options: {
|
|
341
|
+
temperature: request.temperature,
|
|
342
|
+
num_predict: request.maxTokens,
|
|
343
|
+
top_p: request.topP
|
|
344
|
+
},
|
|
345
|
+
format: request.responseFormat === "json_object" ? "json" : void 0
|
|
346
|
+
})
|
|
347
|
+
});
|
|
348
|
+
if (!response.ok || !response.body) {
|
|
349
|
+
throw new errors.DomainError(
|
|
350
|
+
`Ollama streaming error HTTP ${response.status}`,
|
|
351
|
+
errors.ErrorCode.MODEL_PROVIDER_ERROR,
|
|
352
|
+
502
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
const reader = response.body.getReader();
|
|
356
|
+
const decoder = new TextDecoder();
|
|
357
|
+
let buffer = "";
|
|
358
|
+
try {
|
|
359
|
+
while (true) {
|
|
360
|
+
const { done, value } = await reader.read();
|
|
361
|
+
if (done) break;
|
|
362
|
+
buffer += decoder.decode(value, { stream: true });
|
|
363
|
+
const lines = buffer.split("\n");
|
|
364
|
+
buffer = lines.pop() ?? "";
|
|
365
|
+
for (const line of lines) {
|
|
366
|
+
const trimmed = line.trim();
|
|
367
|
+
if (!trimmed) continue;
|
|
368
|
+
try {
|
|
369
|
+
const chunk = JSON.parse(trimmed);
|
|
370
|
+
const delta = chunk.message?.content ?? "";
|
|
371
|
+
yield {
|
|
372
|
+
delta,
|
|
373
|
+
finishReason: chunk.done ? FinishReason.STOP : void 0,
|
|
374
|
+
usage: chunk.done ? {
|
|
375
|
+
promptTokens: chunk.prompt_eval_count ?? 0,
|
|
376
|
+
completionTokens: chunk.eval_count ?? 0,
|
|
377
|
+
totalTokens: (chunk.prompt_eval_count ?? 0) + (chunk.eval_count ?? 0)
|
|
378
|
+
} : void 0
|
|
379
|
+
};
|
|
380
|
+
} catch {
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
} finally {
|
|
385
|
+
reader.releaseLock();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// src/adapters/groq/groq.types.ts
|
|
391
|
+
function mapGroqMessages(messages) {
|
|
392
|
+
return messages.map((m) => {
|
|
393
|
+
let role = "user";
|
|
394
|
+
if (m.role === MessageRole.SYSTEM) role = "system";
|
|
395
|
+
else if (m.role === MessageRole.ASSISTANT) role = "assistant";
|
|
396
|
+
return { role, content: m.content };
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
var logger2 = logger$1.loggerWithConfig(new logger$1.Logger("GroqAdapter"));
|
|
400
|
+
var GroqAdapter = class {
|
|
401
|
+
name = "groq";
|
|
402
|
+
config;
|
|
403
|
+
/**
|
|
404
|
+
* Initializes the Groq adapter.
|
|
405
|
+
*
|
|
406
|
+
* @param config - Connection options and credentials.
|
|
407
|
+
*/
|
|
408
|
+
constructor(config = {}) {
|
|
409
|
+
this.config = config;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Resolves authentication credentials and connection endpoint.
|
|
413
|
+
*/
|
|
414
|
+
async resolveCredentials() {
|
|
415
|
+
const dynamic = this.config.credentials ? await this.config.credentials() : {};
|
|
416
|
+
const env = resolveEnvCredentials(this.name);
|
|
417
|
+
const apiKey = this.config.apiKey ?? dynamic.apiKey ?? env.apiKey;
|
|
418
|
+
const baseUrl = (this.config.baseUrl ?? dynamic.baseUrl ?? env.baseUrl ?? AI_ENDPOINTS.GROQ_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
419
|
+
const defaultModel = this.config.defaultModel ?? dynamic.defaultModel ?? env.defaultModel ?? AI_DEFAULT_MODELS.GROQ;
|
|
420
|
+
if (!apiKey) {
|
|
421
|
+
throw new MissingCredentialError("Groq", "GROQ_API_KEY");
|
|
422
|
+
}
|
|
423
|
+
return { apiKey, baseUrl, defaultModel };
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Executes a full non-streaming completion request.
|
|
427
|
+
*
|
|
428
|
+
* @param request - Validated completion request.
|
|
429
|
+
* @returns Complete model response.
|
|
430
|
+
*/
|
|
431
|
+
async complete(request) {
|
|
432
|
+
const { apiKey, baseUrl, defaultModel } = await this.resolveCredentials();
|
|
433
|
+
const startTime = Date.now();
|
|
434
|
+
const model = request.model || defaultModel;
|
|
435
|
+
logger2.debug("[complete] Executing Groq completion", { model, baseUrl });
|
|
436
|
+
const controller = new AbortController();
|
|
437
|
+
const timeout = setTimeout(() => controller.abort(), request.timeoutMs);
|
|
438
|
+
try {
|
|
439
|
+
const response = await fetch(`${baseUrl}/chat/completions`, {
|
|
440
|
+
method: "POST",
|
|
441
|
+
headers: {
|
|
442
|
+
"Content-Type": "application/json",
|
|
443
|
+
Authorization: `Bearer ${apiKey}`
|
|
444
|
+
},
|
|
445
|
+
body: JSON.stringify({
|
|
446
|
+
model,
|
|
447
|
+
messages: mapGroqMessages(request.messages),
|
|
448
|
+
temperature: request.temperature,
|
|
449
|
+
max_tokens: request.maxTokens,
|
|
450
|
+
top_p: request.topP,
|
|
451
|
+
stop: request.stop,
|
|
452
|
+
response_format: request.responseFormat === "json_object" ? { type: "json_object" } : void 0
|
|
453
|
+
}),
|
|
454
|
+
signal: controller.signal
|
|
455
|
+
});
|
|
456
|
+
if (!response.ok) {
|
|
457
|
+
const errorText = await response.text().catch(() => "");
|
|
458
|
+
logger2.error("[complete] Groq API error response", {
|
|
459
|
+
status: response.status,
|
|
460
|
+
errorText
|
|
461
|
+
});
|
|
462
|
+
throw new errors.DomainError(
|
|
463
|
+
`Groq returned HTTP ${response.status}: ${errorText}`,
|
|
464
|
+
response.status === 429 ? errors.ErrorCode.MODEL_RATE_LIMIT : errors.ErrorCode.MODEL_PROVIDER_ERROR,
|
|
465
|
+
response.status
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
const data = await response.json();
|
|
469
|
+
const choice = data.choices[0];
|
|
470
|
+
const text = choice?.message?.content ?? "";
|
|
471
|
+
const durationMs = Date.now() - startTime;
|
|
472
|
+
logger2.info("[complete] Groq completion finished", {
|
|
473
|
+
model,
|
|
474
|
+
durationMs,
|
|
475
|
+
tokensOut: data.usage?.completion_tokens
|
|
476
|
+
});
|
|
477
|
+
return {
|
|
478
|
+
text,
|
|
479
|
+
finishReason: choice?.finish_reason === "length" ? FinishReason.LENGTH : FinishReason.STOP,
|
|
480
|
+
usage: {
|
|
481
|
+
promptTokens: data.usage?.prompt_tokens ?? 0,
|
|
482
|
+
completionTokens: data.usage?.completion_tokens ?? 0,
|
|
483
|
+
totalTokens: data.usage?.total_tokens ?? 0
|
|
484
|
+
},
|
|
485
|
+
model,
|
|
486
|
+
durationMs
|
|
487
|
+
};
|
|
488
|
+
} catch (err) {
|
|
489
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
490
|
+
logger2.warn("[complete] Groq request timed out", {
|
|
491
|
+
model,
|
|
492
|
+
timeoutMs: request.timeoutMs
|
|
493
|
+
});
|
|
494
|
+
throw new errors.ModelTimeoutError(model, request.timeoutMs);
|
|
495
|
+
}
|
|
496
|
+
throw err;
|
|
497
|
+
} finally {
|
|
498
|
+
clearTimeout(timeout);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Initiates an SSE stream emitting token deltas incrementally.
|
|
503
|
+
*
|
|
504
|
+
* @param request - Validated completion request.
|
|
505
|
+
* @returns Async iterable emitting token deltas.
|
|
506
|
+
*/
|
|
507
|
+
async *stream(request) {
|
|
508
|
+
const { apiKey, baseUrl, defaultModel } = await this.resolveCredentials();
|
|
509
|
+
const model = request.model || defaultModel;
|
|
510
|
+
const response = await fetch(`${baseUrl}/chat/completions`, {
|
|
511
|
+
method: "POST",
|
|
512
|
+
headers: {
|
|
513
|
+
"Content-Type": "application/json",
|
|
514
|
+
Authorization: `Bearer ${apiKey}`
|
|
515
|
+
},
|
|
516
|
+
body: JSON.stringify({
|
|
517
|
+
model,
|
|
518
|
+
messages: mapGroqMessages(request.messages),
|
|
519
|
+
temperature: request.temperature,
|
|
520
|
+
stream: true
|
|
521
|
+
})
|
|
522
|
+
});
|
|
523
|
+
if (!response.ok || !response.body) {
|
|
524
|
+
throw new errors.DomainError(
|
|
525
|
+
`Groq streaming error HTTP ${response.status}`,
|
|
526
|
+
errors.ErrorCode.MODEL_PROVIDER_ERROR,
|
|
527
|
+
502
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
const reader = response.body.getReader();
|
|
531
|
+
const decoder = new TextDecoder();
|
|
532
|
+
let buffer = "";
|
|
533
|
+
try {
|
|
534
|
+
while (true) {
|
|
535
|
+
const { done, value } = await reader.read();
|
|
536
|
+
if (done) break;
|
|
537
|
+
buffer += decoder.decode(value, { stream: true });
|
|
538
|
+
const lines = buffer.split("\n");
|
|
539
|
+
buffer = lines.pop() ?? "";
|
|
540
|
+
for (const line of lines) {
|
|
541
|
+
const trimmed = line.trim();
|
|
542
|
+
if (!trimmed || !trimmed.startsWith("data:")) continue;
|
|
543
|
+
const payload = trimmed.slice(5).trim();
|
|
544
|
+
if (payload === "[DONE]") break;
|
|
545
|
+
try {
|
|
546
|
+
const parsed = JSON.parse(payload);
|
|
547
|
+
const delta = parsed.choices[0]?.delta?.content ?? "";
|
|
548
|
+
if (delta) {
|
|
549
|
+
yield { delta };
|
|
550
|
+
}
|
|
551
|
+
} catch {
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
} finally {
|
|
556
|
+
reader.releaseLock();
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
// src/adapters/google/google.types.ts
|
|
562
|
+
function buildGeminiRequestBody(request) {
|
|
563
|
+
const contents = [];
|
|
564
|
+
let systemInstruction;
|
|
565
|
+
for (const msg of request.messages) {
|
|
566
|
+
if (msg.role === MessageRole.SYSTEM) {
|
|
567
|
+
systemInstruction = { parts: [{ text: msg.content }] };
|
|
568
|
+
} else {
|
|
569
|
+
contents.push({
|
|
570
|
+
role: msg.role === MessageRole.ASSISTANT ? "model" : "user",
|
|
571
|
+
parts: [{ text: msg.content }]
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return {
|
|
576
|
+
contents,
|
|
577
|
+
systemInstruction,
|
|
578
|
+
generationConfig: {
|
|
579
|
+
temperature: request.temperature,
|
|
580
|
+
maxOutputTokens: request.maxTokens,
|
|
581
|
+
topP: request.topP,
|
|
582
|
+
stopSequences: request.stop,
|
|
583
|
+
responseMimeType: request.responseFormat === "json_object" ? "application/json" : "text/plain"
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
var logger3 = logger$1.loggerWithConfig(new logger$1.Logger("GoogleAdapter"));
|
|
588
|
+
var GoogleAdapter = class {
|
|
589
|
+
name = "google";
|
|
590
|
+
config;
|
|
591
|
+
/**
|
|
592
|
+
* Initializes the Google Gemini adapter.
|
|
593
|
+
*
|
|
594
|
+
* @param config - Connection options and credentials.
|
|
595
|
+
*/
|
|
596
|
+
constructor(config = {}) {
|
|
597
|
+
this.config = config;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Resolves authentication credentials and model defaults.
|
|
601
|
+
*/
|
|
602
|
+
async resolveCredentials() {
|
|
603
|
+
const dynamic = this.config.credentials ? await this.config.credentials() : {};
|
|
604
|
+
const env = resolveEnvCredentials(this.name);
|
|
605
|
+
const apiKey = this.config.apiKey ?? dynamic.apiKey ?? env.apiKey;
|
|
606
|
+
const baseUrl = (this.config.baseUrl ?? dynamic.baseUrl ?? env.baseUrl ?? AI_ENDPOINTS.GOOGLE_GEMINI_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
607
|
+
const defaultModel = this.config.defaultModel ?? dynamic.defaultModel ?? env.defaultModel ?? "gemini-2.5-flash";
|
|
608
|
+
if (!apiKey) {
|
|
609
|
+
throw new MissingCredentialError("Google Gemini", "GEMINI_API_KEY");
|
|
610
|
+
}
|
|
611
|
+
return { apiKey, baseUrl, defaultModel };
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Executes a full non-streaming completion via Google AI Studio generateContent.
|
|
615
|
+
*
|
|
616
|
+
* @param request - Validated completion request.
|
|
617
|
+
* @returns Complete model response.
|
|
618
|
+
*/
|
|
619
|
+
async complete(request) {
|
|
620
|
+
const { apiKey, baseUrl, defaultModel } = await this.resolveCredentials();
|
|
621
|
+
const startTime = Date.now();
|
|
622
|
+
const model = request.model || defaultModel;
|
|
623
|
+
logger3.debug("[complete] Executing Gemini completion", { model });
|
|
624
|
+
const controller = new AbortController();
|
|
625
|
+
const timeout = setTimeout(() => controller.abort(), request.timeoutMs);
|
|
626
|
+
try {
|
|
627
|
+
const url = `${baseUrl}/models/${model}:generateContent?key=${apiKey}`;
|
|
628
|
+
const response = await fetch(url, {
|
|
629
|
+
method: "POST",
|
|
630
|
+
headers: { "Content-Type": "application/json" },
|
|
631
|
+
body: JSON.stringify(buildGeminiRequestBody(request)),
|
|
632
|
+
signal: controller.signal
|
|
633
|
+
});
|
|
634
|
+
if (!response.ok) {
|
|
635
|
+
const errorText = await response.text().catch(() => "");
|
|
636
|
+
logger3.error("[complete] Gemini API error response", {
|
|
637
|
+
status: response.status,
|
|
638
|
+
errorText
|
|
639
|
+
});
|
|
640
|
+
throw new errors.DomainError(
|
|
641
|
+
`Gemini API returned HTTP ${response.status}: ${errorText}`,
|
|
642
|
+
errors.ErrorCode.MODEL_PROVIDER_ERROR,
|
|
643
|
+
response.status
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
const data = await response.json();
|
|
647
|
+
const candidate = data.candidates?.[0];
|
|
648
|
+
const text = candidate?.content?.parts?.[0]?.text ?? "";
|
|
649
|
+
const durationMs = Date.now() - startTime;
|
|
650
|
+
logger3.info("[complete] Gemini completion finished", {
|
|
651
|
+
model,
|
|
652
|
+
durationMs,
|
|
653
|
+
tokensOut: data.usageMetadata?.candidatesTokenCount
|
|
654
|
+
});
|
|
655
|
+
return {
|
|
656
|
+
text,
|
|
657
|
+
finishReason: candidate?.finishReason === "MAX_TOKENS" ? FinishReason.LENGTH : FinishReason.STOP,
|
|
658
|
+
usage: {
|
|
659
|
+
promptTokens: data.usageMetadata?.promptTokenCount ?? 0,
|
|
660
|
+
completionTokens: data.usageMetadata?.candidatesTokenCount ?? 0,
|
|
661
|
+
totalTokens: data.usageMetadata?.totalTokenCount ?? 0
|
|
662
|
+
},
|
|
663
|
+
model,
|
|
664
|
+
durationMs
|
|
665
|
+
};
|
|
666
|
+
} catch (err) {
|
|
667
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
668
|
+
logger3.warn("[complete] Gemini request timed out", {
|
|
669
|
+
model,
|
|
670
|
+
timeoutMs: request.timeoutMs
|
|
671
|
+
});
|
|
672
|
+
throw new errors.ModelTimeoutError(model, request.timeoutMs);
|
|
673
|
+
}
|
|
674
|
+
throw err;
|
|
675
|
+
} finally {
|
|
676
|
+
clearTimeout(timeout);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Streams token chunks incrementally using Server-Sent Events.
|
|
681
|
+
*
|
|
682
|
+
* @param request - Validated completion request.
|
|
683
|
+
* @returns Async iterable yielding token delta chunks.
|
|
684
|
+
*/
|
|
685
|
+
async *stream(request) {
|
|
686
|
+
const { apiKey, baseUrl, defaultModel } = await this.resolveCredentials();
|
|
687
|
+
const model = request.model || defaultModel;
|
|
688
|
+
const url = `${baseUrl}/models/${model}:streamGenerateContent?alt=sse&key=${apiKey}`;
|
|
689
|
+
const response = await fetch(url, {
|
|
690
|
+
method: "POST",
|
|
691
|
+
headers: { "Content-Type": "application/json" },
|
|
692
|
+
body: JSON.stringify(buildGeminiRequestBody(request))
|
|
693
|
+
});
|
|
694
|
+
if (!response.ok || !response.body) {
|
|
695
|
+
throw new errors.DomainError(
|
|
696
|
+
`Gemini streaming error HTTP ${response.status}`,
|
|
697
|
+
errors.ErrorCode.MODEL_PROVIDER_ERROR,
|
|
698
|
+
502
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
const reader = response.body.getReader();
|
|
702
|
+
const decoder = new TextDecoder();
|
|
703
|
+
let buffer = "";
|
|
704
|
+
try {
|
|
705
|
+
while (true) {
|
|
706
|
+
const { done, value } = await reader.read();
|
|
707
|
+
if (done) break;
|
|
708
|
+
buffer += decoder.decode(value, { stream: true });
|
|
709
|
+
const lines = buffer.split("\n");
|
|
710
|
+
buffer = lines.pop() ?? "";
|
|
711
|
+
for (const line of lines) {
|
|
712
|
+
const trimmed = line.trim();
|
|
713
|
+
if (!trimmed || !trimmed.startsWith("data:")) continue;
|
|
714
|
+
const jsonStr = trimmed.slice(5).trim();
|
|
715
|
+
try {
|
|
716
|
+
const chunk = JSON.parse(jsonStr);
|
|
717
|
+
const delta = chunk.candidates?.[0]?.content?.parts?.[0]?.text ?? "";
|
|
718
|
+
if (delta) {
|
|
719
|
+
yield { delta };
|
|
720
|
+
}
|
|
721
|
+
} catch {
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
} finally {
|
|
726
|
+
reader.releaseLock();
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
// src/adapters/openai/openai.types.ts
|
|
732
|
+
function mapOpenAiMessages(messages) {
|
|
733
|
+
return messages.map((m) => ({
|
|
734
|
+
role: m.role === MessageRole.SYSTEM ? "system" : m.role === MessageRole.ASSISTANT ? "assistant" : "user",
|
|
735
|
+
content: m.content
|
|
736
|
+
}));
|
|
737
|
+
}
|
|
738
|
+
var logger4 = logger$1.loggerWithConfig(new logger$1.Logger("OpenAiAdapter"));
|
|
739
|
+
var OpenAIAdapter = class {
|
|
740
|
+
name = "openai";
|
|
741
|
+
config;
|
|
742
|
+
/**
|
|
743
|
+
* Initializes the OpenAI adapter.
|
|
744
|
+
*
|
|
745
|
+
* @param config - Connection options and credentials.
|
|
746
|
+
*/
|
|
747
|
+
constructor(config = {}) {
|
|
748
|
+
this.config = config;
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Resolves authentication credentials and endpoint.
|
|
752
|
+
*/
|
|
753
|
+
async resolveCredentials() {
|
|
754
|
+
const dynamic = this.config.credentials ? await this.config.credentials() : {};
|
|
755
|
+
const env = resolveEnvCredentials(this.name);
|
|
756
|
+
const apiKey = this.config.apiKey ?? dynamic.apiKey ?? env.apiKey;
|
|
757
|
+
const baseUrl = (this.config.baseUrl ?? dynamic.baseUrl ?? env.baseUrl ?? AI_ENDPOINTS.OPENAI_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
758
|
+
const defaultModel = this.config.defaultModel ?? dynamic.defaultModel ?? env.defaultModel ?? AI_DEFAULT_MODELS.OPENAI;
|
|
759
|
+
if (!apiKey) {
|
|
760
|
+
throw new MissingCredentialError("OpenAI", "OPENAI_API_KEY");
|
|
761
|
+
}
|
|
762
|
+
return { apiKey, baseUrl, defaultModel };
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Executes a full non-streaming completion request.
|
|
766
|
+
*
|
|
767
|
+
* @param request - Validated completion request.
|
|
768
|
+
* @returns Complete model response.
|
|
769
|
+
*/
|
|
770
|
+
async complete(request) {
|
|
771
|
+
const { apiKey, baseUrl, defaultModel } = await this.resolveCredentials();
|
|
772
|
+
const startTime = Date.now();
|
|
773
|
+
const model = request.model || defaultModel;
|
|
774
|
+
logger4.debug("[complete] Executing OpenAI completion", { model, baseUrl });
|
|
775
|
+
const controller = new AbortController();
|
|
776
|
+
const timeout = setTimeout(() => controller.abort(), request.timeoutMs);
|
|
777
|
+
try {
|
|
778
|
+
const response = await fetch(`${baseUrl}/chat/completions`, {
|
|
779
|
+
method: "POST",
|
|
780
|
+
headers: {
|
|
781
|
+
"Content-Type": "application/json",
|
|
782
|
+
Authorization: `Bearer ${apiKey}`
|
|
783
|
+
},
|
|
784
|
+
body: JSON.stringify({
|
|
785
|
+
model,
|
|
786
|
+
messages: mapOpenAiMessages(request.messages),
|
|
787
|
+
temperature: request.temperature,
|
|
788
|
+
max_tokens: request.maxTokens,
|
|
789
|
+
top_p: request.topP,
|
|
790
|
+
stop: request.stop,
|
|
791
|
+
response_format: request.responseFormat === "json_object" ? { type: "json_object" } : void 0
|
|
792
|
+
}),
|
|
793
|
+
signal: controller.signal
|
|
794
|
+
});
|
|
795
|
+
if (!response.ok) {
|
|
796
|
+
const errorText = await response.text().catch(() => "");
|
|
797
|
+
logger4.error("[complete] OpenAI API error response", {
|
|
798
|
+
status: response.status,
|
|
799
|
+
errorText
|
|
800
|
+
});
|
|
801
|
+
throw new errors.DomainError(
|
|
802
|
+
`OpenAI returned HTTP ${response.status}: ${errorText}`,
|
|
803
|
+
response.status === 429 ? errors.ErrorCode.MODEL_RATE_LIMIT : errors.ErrorCode.MODEL_PROVIDER_ERROR,
|
|
804
|
+
response.status
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
const data = await response.json();
|
|
808
|
+
const choice = data.choices[0];
|
|
809
|
+
const text = choice?.message?.content ?? "";
|
|
810
|
+
const durationMs = Date.now() - startTime;
|
|
811
|
+
logger4.info("[complete] OpenAI completion finished", {
|
|
812
|
+
model,
|
|
813
|
+
durationMs,
|
|
814
|
+
tokensOut: data.usage?.completion_tokens
|
|
815
|
+
});
|
|
816
|
+
return {
|
|
817
|
+
text,
|
|
818
|
+
finishReason: choice?.finish_reason === "length" ? FinishReason.LENGTH : FinishReason.STOP,
|
|
819
|
+
usage: {
|
|
820
|
+
promptTokens: data.usage?.prompt_tokens ?? 0,
|
|
821
|
+
completionTokens: data.usage?.completion_tokens ?? 0,
|
|
822
|
+
totalTokens: data.usage?.total_tokens ?? 0
|
|
823
|
+
},
|
|
824
|
+
model,
|
|
825
|
+
durationMs
|
|
826
|
+
};
|
|
827
|
+
} catch (err) {
|
|
828
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
829
|
+
logger4.warn("[complete] OpenAI request timed out", {
|
|
830
|
+
model,
|
|
831
|
+
timeoutMs: request.timeoutMs
|
|
832
|
+
});
|
|
833
|
+
throw new errors.ModelTimeoutError(model, request.timeoutMs);
|
|
834
|
+
}
|
|
835
|
+
throw err;
|
|
836
|
+
} finally {
|
|
837
|
+
clearTimeout(timeout);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Initiates an SSE stream emitting token deltas incrementally.
|
|
842
|
+
*
|
|
843
|
+
* @param request - Validated completion request.
|
|
844
|
+
* @returns Async iterable emitting token deltas.
|
|
845
|
+
*/
|
|
846
|
+
async *stream(request) {
|
|
847
|
+
const { apiKey, baseUrl, defaultModel } = await this.resolveCredentials();
|
|
848
|
+
const model = request.model || defaultModel;
|
|
849
|
+
const response = await fetch(`${baseUrl}/chat/completions`, {
|
|
850
|
+
method: "POST",
|
|
851
|
+
headers: {
|
|
852
|
+
"Content-Type": "application/json",
|
|
853
|
+
Authorization: `Bearer ${apiKey}`
|
|
854
|
+
},
|
|
855
|
+
body: JSON.stringify({
|
|
856
|
+
model,
|
|
857
|
+
messages: mapOpenAiMessages(request.messages),
|
|
858
|
+
temperature: request.temperature,
|
|
859
|
+
stream: true
|
|
860
|
+
})
|
|
861
|
+
});
|
|
862
|
+
if (!response.ok || !response.body) {
|
|
863
|
+
throw new errors.DomainError(
|
|
864
|
+
`OpenAI streaming error HTTP ${response.status}`,
|
|
865
|
+
errors.ErrorCode.MODEL_PROVIDER_ERROR,
|
|
866
|
+
502
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
const reader = response.body.getReader();
|
|
870
|
+
const decoder = new TextDecoder();
|
|
871
|
+
let buffer = "";
|
|
872
|
+
try {
|
|
873
|
+
while (true) {
|
|
874
|
+
const { done, value } = await reader.read();
|
|
875
|
+
if (done) break;
|
|
876
|
+
buffer += decoder.decode(value, { stream: true });
|
|
877
|
+
const lines = buffer.split("\n");
|
|
878
|
+
buffer = lines.pop() ?? "";
|
|
879
|
+
for (const line of lines) {
|
|
880
|
+
const trimmed = line.trim();
|
|
881
|
+
if (!trimmed || !trimmed.startsWith("data:")) continue;
|
|
882
|
+
const payload = trimmed.slice(5).trim();
|
|
883
|
+
if (payload === "[DONE]") break;
|
|
884
|
+
try {
|
|
885
|
+
const parsed = JSON.parse(payload);
|
|
886
|
+
const delta = parsed.choices[0]?.delta?.content ?? "";
|
|
887
|
+
if (delta) {
|
|
888
|
+
yield { delta };
|
|
889
|
+
}
|
|
890
|
+
} catch {
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
} finally {
|
|
895
|
+
reader.releaseLock();
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
// src/adapters/anthropic/anthropic.types.ts
|
|
901
|
+
function extractAnthropicSystemAndMessages(messages) {
|
|
902
|
+
let system;
|
|
903
|
+
const turns = [];
|
|
904
|
+
for (const msg of messages) {
|
|
905
|
+
if (msg.role === MessageRole.SYSTEM) {
|
|
906
|
+
system = system ? `${system}
|
|
907
|
+
|
|
908
|
+
${msg.content}` : msg.content;
|
|
909
|
+
} else {
|
|
910
|
+
turns.push({
|
|
911
|
+
role: msg.role === MessageRole.ASSISTANT ? "assistant" : "user",
|
|
912
|
+
content: msg.content
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return { system, messages: turns };
|
|
917
|
+
}
|
|
918
|
+
var logger5 = logger$1.loggerWithConfig(new logger$1.Logger("AnthropicAdapter"));
|
|
919
|
+
var AnthropicAdapter = class {
|
|
920
|
+
name = "anthropic";
|
|
921
|
+
config;
|
|
922
|
+
/**
|
|
923
|
+
* Initializes the Anthropic adapter.
|
|
924
|
+
*
|
|
925
|
+
* @param config - Connection options and credentials.
|
|
926
|
+
*/
|
|
927
|
+
constructor(config = {}) {
|
|
928
|
+
this.config = config;
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Resolves authentication credentials and endpoint.
|
|
932
|
+
*/
|
|
933
|
+
async resolveCredentials() {
|
|
934
|
+
const dynamic = this.config.credentials ? await this.config.credentials() : {};
|
|
935
|
+
const env = resolveEnvCredentials(this.name);
|
|
936
|
+
const apiKey = this.config.apiKey ?? dynamic.apiKey ?? env.apiKey;
|
|
937
|
+
const baseUrl = (this.config.baseUrl ?? dynamic.baseUrl ?? env.baseUrl ?? AI_ENDPOINTS.ANTHROPIC_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
938
|
+
const defaultModel = this.config.defaultModel ?? dynamic.defaultModel ?? env.defaultModel ?? AI_DEFAULT_MODELS.ANTHROPIC;
|
|
939
|
+
if (!apiKey) {
|
|
940
|
+
throw new MissingCredentialError("Anthropic", "ANTHROPIC_API_KEY");
|
|
941
|
+
}
|
|
942
|
+
return { apiKey, baseUrl, defaultModel };
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* Executes a full non-streaming completion request.
|
|
946
|
+
*
|
|
947
|
+
* @param request - Validated completion request.
|
|
948
|
+
* @returns Complete model response.
|
|
949
|
+
*/
|
|
950
|
+
async complete(request) {
|
|
951
|
+
const { apiKey, baseUrl, defaultModel } = await this.resolveCredentials();
|
|
952
|
+
const startTime = Date.now();
|
|
953
|
+
const model = request.model || defaultModel;
|
|
954
|
+
logger5.debug("[complete] Executing Anthropic completion", {
|
|
955
|
+
model,
|
|
956
|
+
baseUrl
|
|
957
|
+
});
|
|
958
|
+
const controller = new AbortController();
|
|
959
|
+
const timeout = setTimeout(() => controller.abort(), request.timeoutMs);
|
|
960
|
+
try {
|
|
961
|
+
const { system, messages } = extractAnthropicSystemAndMessages(
|
|
962
|
+
request.messages
|
|
963
|
+
);
|
|
964
|
+
const response = await fetch(`${baseUrl}/messages`, {
|
|
965
|
+
method: "POST",
|
|
966
|
+
headers: {
|
|
967
|
+
"Content-Type": "application/json",
|
|
968
|
+
"x-api-key": apiKey,
|
|
969
|
+
"anthropic-version": AI_ENDPOINTS.ANTHROPIC_VERSION_HEADER
|
|
970
|
+
},
|
|
971
|
+
body: JSON.stringify({
|
|
972
|
+
model,
|
|
973
|
+
system,
|
|
974
|
+
messages,
|
|
975
|
+
max_tokens: request.maxTokens ?? AI_EXECUTION_DEFAULTS.DEFAULT_MAX_OUTPUT_TOKENS,
|
|
976
|
+
temperature: request.temperature,
|
|
977
|
+
stop_sequences: request.stop
|
|
978
|
+
}),
|
|
979
|
+
signal: controller.signal
|
|
980
|
+
});
|
|
981
|
+
if (!response.ok) {
|
|
982
|
+
const errorText = await response.text().catch(() => "");
|
|
983
|
+
logger5.error("[complete] Anthropic API error response", {
|
|
984
|
+
status: response.status,
|
|
985
|
+
errorText
|
|
986
|
+
});
|
|
987
|
+
throw new errors.DomainError(
|
|
988
|
+
`Anthropic returned HTTP ${response.status}: ${errorText}`,
|
|
989
|
+
response.status === 429 ? errors.ErrorCode.MODEL_RATE_LIMIT : errors.ErrorCode.MODEL_PROVIDER_ERROR,
|
|
990
|
+
response.status
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
const data = await response.json();
|
|
994
|
+
const text = data.content.find((c) => c.type === "text")?.text ?? "";
|
|
995
|
+
const durationMs = Date.now() - startTime;
|
|
996
|
+
logger5.info("[complete] Anthropic completion finished", {
|
|
997
|
+
model,
|
|
998
|
+
durationMs,
|
|
999
|
+
tokensOut: data.usage.output_tokens
|
|
1000
|
+
});
|
|
1001
|
+
return {
|
|
1002
|
+
text,
|
|
1003
|
+
finishReason: data.stop_reason === "max_tokens" ? FinishReason.LENGTH : FinishReason.STOP,
|
|
1004
|
+
usage: {
|
|
1005
|
+
promptTokens: data.usage.input_tokens,
|
|
1006
|
+
completionTokens: data.usage.output_tokens,
|
|
1007
|
+
totalTokens: data.usage.input_tokens + data.usage.output_tokens
|
|
1008
|
+
},
|
|
1009
|
+
model,
|
|
1010
|
+
durationMs
|
|
1011
|
+
};
|
|
1012
|
+
} catch (err) {
|
|
1013
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
1014
|
+
logger5.warn("[complete] Anthropic request timed out", {
|
|
1015
|
+
model,
|
|
1016
|
+
timeoutMs: request.timeoutMs
|
|
1017
|
+
});
|
|
1018
|
+
throw new errors.ModelTimeoutError(model, request.timeoutMs);
|
|
1019
|
+
}
|
|
1020
|
+
throw err;
|
|
1021
|
+
} finally {
|
|
1022
|
+
clearTimeout(timeout);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Streams completion tokens.
|
|
1027
|
+
*
|
|
1028
|
+
* @param request - Validated completion request.
|
|
1029
|
+
* @returns Async iterable yielding token deltas.
|
|
1030
|
+
*/
|
|
1031
|
+
async *stream(request) {
|
|
1032
|
+
const res = await this.complete(request);
|
|
1033
|
+
yield {
|
|
1034
|
+
delta: res.text,
|
|
1035
|
+
finishReason: res.finishReason,
|
|
1036
|
+
usage: res.usage
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
var logger6 = logger$1.loggerWithConfig(new logger$1.Logger("FallbackCascade"));
|
|
1041
|
+
var FallbackCascade = class {
|
|
1042
|
+
name = "fallback-cascade";
|
|
1043
|
+
providers;
|
|
1044
|
+
/**
|
|
1045
|
+
* Initializes the cascade with candidate providers.
|
|
1046
|
+
*
|
|
1047
|
+
* @param options - Cascade options containing providers array.
|
|
1048
|
+
*/
|
|
1049
|
+
constructor(options) {
|
|
1050
|
+
if (!options.providers || options.providers.length === 0) {
|
|
1051
|
+
throw new errors.DomainError(
|
|
1052
|
+
"FallbackCascade requires at least one provider",
|
|
1053
|
+
errors.ErrorCode.VALIDATION_ERROR,
|
|
1054
|
+
400
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
this.providers = [...options.providers];
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Attempts completion through the provider cascade until one succeeds.
|
|
1061
|
+
*
|
|
1062
|
+
* @param request - Validated completion request.
|
|
1063
|
+
* @returns Successful LLMResponse from the first healthy provider.
|
|
1064
|
+
*/
|
|
1065
|
+
async complete(request) {
|
|
1066
|
+
const errors$1 = [];
|
|
1067
|
+
for (const provider of this.providers) {
|
|
1068
|
+
try {
|
|
1069
|
+
logger6.debug(
|
|
1070
|
+
`[complete] Attempting provider '${provider.name}' in FallbackCascade`
|
|
1071
|
+
);
|
|
1072
|
+
const response = await provider.complete(request);
|
|
1073
|
+
return response;
|
|
1074
|
+
} catch (err) {
|
|
1075
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
1076
|
+
errors$1.push({ provider: provider.name, error: errorMsg });
|
|
1077
|
+
logger6.warn(
|
|
1078
|
+
`[complete] Provider '${provider.name}' failed in FallbackCascade, cascading to next candidate`,
|
|
1079
|
+
{
|
|
1080
|
+
provider: provider.name,
|
|
1081
|
+
error: errorMsg
|
|
1082
|
+
}
|
|
1083
|
+
);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
logger6.error("[complete] All providers in FallbackCascade exhausted", {
|
|
1087
|
+
errors: errors$1
|
|
1088
|
+
});
|
|
1089
|
+
throw new errors.DomainError(
|
|
1090
|
+
`All providers in FallbackCascade failed: ${errors$1.map((e) => `[${e.provider}: ${e.error}]`).join(", ")}`,
|
|
1091
|
+
errors.ErrorCode.MODEL_PROVIDER_ERROR,
|
|
1092
|
+
502,
|
|
1093
|
+
{ errors: errors$1 }
|
|
1094
|
+
);
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Attempts streaming through the provider cascade until one connects.
|
|
1098
|
+
*
|
|
1099
|
+
* @param request - Validated completion request.
|
|
1100
|
+
* @returns Async iterable emitting token chunks from the first healthy provider.
|
|
1101
|
+
*/
|
|
1102
|
+
async *stream(request) {
|
|
1103
|
+
let lastError;
|
|
1104
|
+
for (const provider of this.providers) {
|
|
1105
|
+
try {
|
|
1106
|
+
yield* provider.stream(request);
|
|
1107
|
+
return;
|
|
1108
|
+
} catch (err) {
|
|
1109
|
+
lastError = err;
|
|
1110
|
+
logger6.warn(
|
|
1111
|
+
`[stream] Provider '${provider.name}' failed streaming, attempting next provider in cascade`
|
|
1112
|
+
);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
var logger7 = logger$1.loggerWithConfig(new logger$1.Logger("StructuredOutput"));
|
|
1119
|
+
function cleanJsonText(raw) {
|
|
1120
|
+
const match = /```(?:json)?\s*([\s\S]*?)\s*```/i.exec(raw);
|
|
1121
|
+
if (match && match[1]) {
|
|
1122
|
+
return match[1].trim();
|
|
1123
|
+
}
|
|
1124
|
+
return raw.trim();
|
|
1125
|
+
}
|
|
1126
|
+
async function extractStructuredOutput(options) {
|
|
1127
|
+
const {
|
|
1128
|
+
provider,
|
|
1129
|
+
request,
|
|
1130
|
+
schema,
|
|
1131
|
+
maxRepairRetries = AI_EXECUTION_DEFAULTS.DEFAULT_MAX_REPAIR_RETRIES
|
|
1132
|
+
} = options;
|
|
1133
|
+
let currentRequest = {
|
|
1134
|
+
...request,
|
|
1135
|
+
responseFormat: "json_object"
|
|
1136
|
+
};
|
|
1137
|
+
let attempts = 0;
|
|
1138
|
+
while (attempts <= maxRepairRetries) {
|
|
1139
|
+
attempts++;
|
|
1140
|
+
const response = await provider.complete(currentRequest);
|
|
1141
|
+
const cleaned = cleanJsonText(response.text);
|
|
1142
|
+
try {
|
|
1143
|
+
const parsedJson = JSON.parse(cleaned);
|
|
1144
|
+
return schema.parse(parsedJson);
|
|
1145
|
+
} catch (parseOrValidationError) {
|
|
1146
|
+
const errorDetail = parseOrValidationError instanceof Error ? parseOrValidationError.message : String(parseOrValidationError);
|
|
1147
|
+
logger7.warn(
|
|
1148
|
+
`[extractStructuredOutput] Structured output parsing failed (attempt ${attempts}/${maxRepairRetries + 1})`,
|
|
1149
|
+
{
|
|
1150
|
+
error: errorDetail
|
|
1151
|
+
}
|
|
1152
|
+
);
|
|
1153
|
+
if (attempts > maxRepairRetries) {
|
|
1154
|
+
throw new errors.DomainError(
|
|
1155
|
+
`Failed to parse valid structured output after ${attempts} attempts: ${errorDetail}`,
|
|
1156
|
+
errors.ErrorCode.MODEL_OUTPUT_INVALID,
|
|
1157
|
+
422,
|
|
1158
|
+
{ rawOutput: response.text, errorDetail }
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
1161
|
+
currentRequest = {
|
|
1162
|
+
...currentRequest,
|
|
1163
|
+
messages: [
|
|
1164
|
+
...currentRequest.messages,
|
|
1165
|
+
createAssistantMessage(response.text),
|
|
1166
|
+
createUserMessage(
|
|
1167
|
+
`The previous response failed schema validation with error: ${errorDetail}. Please provide ONLY a valid JSON object matching the requested schema. Do not include markdown fences or explanation.`
|
|
1168
|
+
)
|
|
1169
|
+
]
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
throw new errors.DomainError(
|
|
1174
|
+
"Exhausted retries in extractStructuredOutput",
|
|
1175
|
+
errors.ErrorCode.MODEL_OUTPUT_INVALID,
|
|
1176
|
+
422
|
|
1177
|
+
);
|
|
1178
|
+
}
|
|
1179
|
+
var logger8 = logger$1.loggerWithConfig(new logger$1.Logger("ProviderFactory"));
|
|
1180
|
+
function createProvider(type, config = {}) {
|
|
1181
|
+
logger8.debug(`[createProvider] Creating LLM provider instance: ${type}`);
|
|
1182
|
+
switch (type) {
|
|
1183
|
+
case "ollama":
|
|
1184
|
+
return new OllamaAdapter(config);
|
|
1185
|
+
case "groq":
|
|
1186
|
+
return new GroqAdapter(config);
|
|
1187
|
+
case "google":
|
|
1188
|
+
return new GoogleAdapter(config);
|
|
1189
|
+
case "openai":
|
|
1190
|
+
return new OpenAIAdapter(config);
|
|
1191
|
+
case "anthropic":
|
|
1192
|
+
return new AnthropicAdapter(config);
|
|
1193
|
+
case "cascade": {
|
|
1194
|
+
const providers = config.providers ?? createCascadeCandidates();
|
|
1195
|
+
return new FallbackCascade({ providers });
|
|
1196
|
+
}
|
|
1197
|
+
default:
|
|
1198
|
+
throw new errors.DomainError(
|
|
1199
|
+
`Unknown provider type: '${String(type)}'`,
|
|
1200
|
+
errors.ErrorCode.VALIDATION_ERROR,
|
|
1201
|
+
400
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
function createCascadeCandidates() {
|
|
1206
|
+
const candidates = [];
|
|
1207
|
+
candidates.push(new OllamaAdapter());
|
|
1208
|
+
if (typeof process !== "undefined" && process?.env?.GROQ_API_KEY) {
|
|
1209
|
+
candidates.push(new GroqAdapter());
|
|
1210
|
+
}
|
|
1211
|
+
if (typeof process !== "undefined" && (process?.env?.GEMINI_API_KEY || process?.env?.GOOGLE_AI_API_KEY)) {
|
|
1212
|
+
candidates.push(new GoogleAdapter());
|
|
1213
|
+
}
|
|
1214
|
+
if (typeof process !== "undefined" && process?.env?.OPENAI_API_KEY) {
|
|
1215
|
+
candidates.push(new OpenAIAdapter());
|
|
1216
|
+
}
|
|
1217
|
+
if (typeof process !== "undefined" && process?.env?.ANTHROPIC_API_KEY) {
|
|
1218
|
+
candidates.push(new AnthropicAdapter());
|
|
1219
|
+
}
|
|
1220
|
+
return candidates;
|
|
1221
|
+
}
|
|
1222
|
+
function createDefaultProvider() {
|
|
1223
|
+
const envProvider = typeof process !== "undefined" ? process?.env?.AI_PROVIDER : void 0;
|
|
1224
|
+
if (envProvider) {
|
|
1225
|
+
logger8.info(
|
|
1226
|
+
`[createDefaultProvider] Using explicitly configured provider: ${envProvider}`
|
|
1227
|
+
);
|
|
1228
|
+
return createProvider(envProvider);
|
|
1229
|
+
}
|
|
1230
|
+
return new FallbackCascade({ providers: createCascadeCandidates() });
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
exports.AIMessageSchema = AIMessageSchema;
|
|
1234
|
+
exports.AI_DEFAULT_MODELS = AI_DEFAULT_MODELS;
|
|
1235
|
+
exports.AI_ENDPOINTS = AI_ENDPOINTS;
|
|
1236
|
+
exports.AI_EXECUTION_DEFAULTS = AI_EXECUTION_DEFAULTS;
|
|
1237
|
+
exports.AnthropicAdapter = AnthropicAdapter;
|
|
1238
|
+
exports.FallbackCascade = FallbackCascade;
|
|
1239
|
+
exports.FinishReason = FinishReason;
|
|
1240
|
+
exports.GoogleAdapter = GoogleAdapter;
|
|
1241
|
+
exports.GroqAdapter = GroqAdapter;
|
|
1242
|
+
exports.LLMRequestOptionsSchema = LLMRequestOptionsSchema;
|
|
1243
|
+
exports.LLMRequestSchema = LLMRequestSchema;
|
|
1244
|
+
exports.LLMResponseSchema = LLMResponseSchema;
|
|
1245
|
+
exports.LLMUsageSchema = LLMUsageSchema;
|
|
1246
|
+
exports.MessageRole = MessageRole;
|
|
1247
|
+
exports.MissingCredentialError = MissingCredentialError;
|
|
1248
|
+
exports.OllamaAdapter = OllamaAdapter;
|
|
1249
|
+
exports.OpenAIAdapter = OpenAIAdapter;
|
|
1250
|
+
exports.ToolCallSchema = ToolCallSchema;
|
|
1251
|
+
exports.buildGeminiRequestBody = buildGeminiRequestBody;
|
|
1252
|
+
exports.createAssistantMessage = createAssistantMessage;
|
|
1253
|
+
exports.createCascadeCandidates = createCascadeCandidates;
|
|
1254
|
+
exports.createDefaultProvider = createDefaultProvider;
|
|
1255
|
+
exports.createProvider = createProvider;
|
|
1256
|
+
exports.createSystemMessage = createSystemMessage;
|
|
1257
|
+
exports.createToolResultMessage = createToolResultMessage;
|
|
1258
|
+
exports.createUserMessage = createUserMessage;
|
|
1259
|
+
exports.extractAnthropicSystemAndMessages = extractAnthropicSystemAndMessages;
|
|
1260
|
+
exports.extractStructuredOutput = extractStructuredOutput;
|
|
1261
|
+
exports.mapGroqMessages = mapGroqMessages;
|
|
1262
|
+
exports.mapOllamaMessages = mapOllamaMessages;
|
|
1263
|
+
exports.mapOpenAiMessages = mapOpenAiMessages;
|
|
1264
|
+
exports.resolveEnvCredentials = resolveEnvCredentials;
|
|
1265
|
+
//# sourceMappingURL=index.cjs.map
|
|
1266
|
+
//# sourceMappingURL=index.cjs.map
|