@mate-academy/llm-gateway 8.0.0 → 8.2.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.
- package/README.md +76 -4
- package/dist/LLMGateway.d.ts +2 -2
- package/dist/LLMGateway.js.map +1 -1
- package/dist/LLMGateway.typedefs.d.ts +2 -2
- package/dist/LLMService.typedefs.d.ts +20 -0
- package/dist/LLMService.typedefs.js.map +1 -1
- package/dist/client/LLMAgent.d.ts +17 -4
- package/dist/client/LLMAgent.js +4 -0
- package/dist/client/LLMAgent.js.map +1 -1
- package/dist/client/LLMClientEngine.d.ts +81 -0
- package/dist/client/LLMClientEngine.js +350 -0
- package/dist/client/LLMClientEngine.js.map +1 -0
- package/dist/client/agentRun.typedefs.d.ts +18 -3
- package/dist/client/agentRun.typedefs.js +1 -0
- package/dist/client/agentRun.typedefs.js.map +1 -1
- package/dist/client/agentRunner.d.ts +38 -3
- package/dist/client/agentRunner.js +206 -80
- package/dist/client/agentRunner.js.map +1 -1
- package/dist/client/codegen/fetchPromptRecords.d.ts +1 -1
- package/dist/client/codegen/index.d.ts +1 -0
- package/dist/client/codegen/index.js +1 -0
- package/dist/client/codegen/index.js.map +1 -1
- package/dist/client/codegen/renderSnapshot.constants.d.ts +12 -0
- package/dist/client/codegen/renderSnapshot.constants.js +21 -0
- package/dist/client/codegen/renderSnapshot.constants.js.map +1 -0
- package/dist/client/codegen/renderSnapshot.d.ts +6 -18
- package/dist/client/codegen/renderSnapshot.js +152 -125
- package/dist/client/codegen/renderSnapshot.js.map +1 -1
- package/dist/client/codegen/renderSnapshot.typedefs.d.ts +20 -0
- package/dist/client/codegen/renderSnapshot.typedefs.js +3 -0
- package/dist/client/codegen/renderSnapshot.typedefs.js.map +1 -0
- package/dist/client/coerceToolResult.d.ts +10 -0
- package/dist/client/coerceToolResult.js +38 -0
- package/dist/client/coerceToolResult.js.map +1 -0
- package/dist/client/createLLMClient.d.ts +1 -40
- package/dist/client/createLLMClient.js +5 -329
- package/dist/client/createLLMClient.js.map +1 -1
- package/dist/client/index.d.ts +3 -1
- package/dist/client/index.js +3 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/llmClient.typedefs.d.ts +180 -0
- package/dist/client/{createLLMClient.typedefs.js → llmClient.typedefs.js} +1 -1
- package/dist/client/llmClient.typedefs.js.map +1 -0
- package/dist/client/plainMessages.d.ts +1 -1
- package/dist/client/promptRegistry.runtime.d.ts +2 -2
- package/dist/client/promptRegistry.runtime.js.map +1 -1
- package/dist/client/promptVariables.d.ts +7 -0
- package/dist/client/promptVariables.js +13 -0
- package/dist/client/promptVariables.js.map +1 -0
- package/dist/client/snapshotRuntime.d.ts +17 -0
- package/dist/client/snapshotRuntime.js +42 -0
- package/dist/client/snapshotRuntime.js.map +1 -0
- package/dist/client/snapshotRuntime.typedefs.d.ts +13 -0
- package/dist/client/snapshotRuntime.typedefs.js +3 -0
- package/dist/client/snapshotRuntime.typedefs.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js +6 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js.map +1 -1
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js +6 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js.map +1 -1
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js +3 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js.map +1 -1
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.d.ts +0 -2
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js +43 -25
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js.map +1 -1
- package/dist/providers/LLMAPI/services/LLMAPICompletion.service.d.ts +0 -2
- package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js +18 -17
- package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js.map +1 -1
- package/dist/providers/LLMAPI/utilities/index.d.ts +1 -1
- package/dist/providers/LLMAPI/utilities/index.js +3 -4
- package/dist/providers/LLMAPI/utilities/index.js.map +1 -1
- package/dist/providers/LLMAPI/utilities/validateStructuredResponse.d.ts +10 -0
- package/dist/providers/LLMAPI/utilities/validateStructuredResponse.js +21 -0
- package/dist/providers/LLMAPI/utilities/validateStructuredResponse.js.map +1 -0
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.js +6 -0
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.js.map +1 -1
- package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js +6 -0
- package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js.map +1 -1
- package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.js +3 -0
- package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.js.map +1 -1
- package/dist/services/LLMBaseService.abstract.d.ts +4 -3
- package/dist/services/LLMBaseService.abstract.js +6 -3
- package/dist/services/LLMBaseService.abstract.js.map +1 -1
- package/dist/utilities/index.d.ts +0 -1
- package/dist/utilities/index.js +0 -1
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/llmTracing/llmTracing.constants.d.ts +5 -4
- package/dist/utilities/llmTracing/llmTracing.constants.js +6 -5
- package/dist/utilities/llmTracing/llmTracing.constants.js.map +1 -1
- package/dist/utilities/llmTracing/llmTracing.typedefs.d.ts +18 -9
- package/dist/utilities/llmTracing/noopLLMTracing.d.ts +2 -2
- package/dist/utilities/llmTracing/noopLLMTracing.js.map +1 -1
- package/dist/utilities/tools/LLMTool.d.ts +3 -12
- package/dist/utilities/tools/LLMTool.js.map +1 -1
- package/package.json +2 -1
- package/dist/client/createLLMClient.typedefs.d.ts +0 -91
- package/dist/client/createLLMClient.typedefs.js.map +0 -1
- package/dist/providers/LLMAPI/utilities/LLMAPIJsonFixer.d.ts +0 -24
- package/dist/providers/LLMAPI/utilities/LLMAPIJsonFixer.js +0 -237
- package/dist/providers/LLMAPI/utilities/LLMAPIJsonFixer.js.map +0 -1
- package/dist/utilities/traceIO.d.ts +0 -17
- package/dist/utilities/traceIO.js +0 -48
- package/dist/utilities/traceIO.js.map +0 -1
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createLLMClient = createLLMClient;
|
|
4
|
-
const
|
|
5
|
-
const LLMAgent_1 = require("../client/LLMAgent");
|
|
6
|
-
const agentRunner_1 = require("../client/agentRunner");
|
|
7
|
-
const plainMessages_1 = require("../client/plainMessages");
|
|
8
|
-
const createLLMClient_typedefs_1 = require("../client/createLLMClient.typedefs");
|
|
4
|
+
const LLMClientEngine_1 = require("../client/LLMClientEngine");
|
|
9
5
|
const promptRegistry_runtime_1 = require("../client/promptRegistry.runtime");
|
|
10
|
-
const
|
|
6
|
+
const llmClient_typedefs_1 = require("../client/llmClient.typedefs");
|
|
11
7
|
/**
|
|
12
8
|
* Builds the v2 gateway client once at the composition root. The client is
|
|
13
9
|
* generic over `typeof registry` (and the generated variable map), so call sites
|
|
@@ -17,7 +13,7 @@ const errors_1 = require("../client/errors");
|
|
|
17
13
|
*/
|
|
18
14
|
function createLLMClient(config) {
|
|
19
15
|
const mode = config.mode ?? 'production';
|
|
20
|
-
const reporter = config.reporting ===
|
|
16
|
+
const reporter = config.reporting === llmClient_typedefs_1.ReportingDisabled
|
|
21
17
|
? undefined
|
|
22
18
|
: config.reporting.reporter;
|
|
23
19
|
const runtime = new promptRegistry_runtime_1.PromptRegistryRuntime({
|
|
@@ -28,7 +24,7 @@ function createLLMClient(config) {
|
|
|
28
24
|
cacheTtlSeconds: config.cacheTtlSeconds,
|
|
29
25
|
logger: config.logger,
|
|
30
26
|
});
|
|
31
|
-
const engine = new LLMClientEngine({
|
|
27
|
+
const engine = new LLMClientEngine_1.LLMClientEngine({
|
|
32
28
|
gateway: config.gateway,
|
|
33
29
|
registry: config.registry,
|
|
34
30
|
runtime,
|
|
@@ -37,6 +33,7 @@ function createLLMClient(config) {
|
|
|
37
33
|
logger: config.logger,
|
|
38
34
|
staticContext: config.context ?? {},
|
|
39
35
|
mode,
|
|
36
|
+
normalizeToolResult: config.normalizeToolResult,
|
|
40
37
|
});
|
|
41
38
|
return {
|
|
42
39
|
generate: (prompt, options) => engine.generate(prompt, options),
|
|
@@ -46,325 +43,4 @@ function createLLMClient(config) {
|
|
|
46
43
|
describePrompt: (prompt) => engine.describePrompt(prompt),
|
|
47
44
|
};
|
|
48
45
|
}
|
|
49
|
-
class LLMClientEngine {
|
|
50
|
-
gateway;
|
|
51
|
-
registry;
|
|
52
|
-
runtime;
|
|
53
|
-
credentials;
|
|
54
|
-
reporter;
|
|
55
|
-
logger;
|
|
56
|
-
staticContext;
|
|
57
|
-
mode;
|
|
58
|
-
agentRunner;
|
|
59
|
-
constructor(config) {
|
|
60
|
-
this.gateway = config.gateway;
|
|
61
|
-
this.registry = config.registry;
|
|
62
|
-
this.runtime = config.runtime;
|
|
63
|
-
this.credentials = config.credentials;
|
|
64
|
-
this.reporter = config.reporter;
|
|
65
|
-
this.logger = config.logger;
|
|
66
|
-
this.staticContext = config.staticContext;
|
|
67
|
-
this.mode = config.mode;
|
|
68
|
-
this.agentRunner = new agentRunner_1.LLMAgentRunner(this, config.logger);
|
|
69
|
-
}
|
|
70
|
-
async generate(prompt, options) {
|
|
71
|
-
const promptName = String(prompt);
|
|
72
|
-
const binding = this.registry[prompt];
|
|
73
|
-
const schema = options.schema ?? binding.schema;
|
|
74
|
-
this.assertOverridesAllowed(promptName, options.overrides);
|
|
75
|
-
const resolved = await this.resolvePrompt(promptName, binding, options.variables, {
|
|
76
|
-
purpose: LLMService_typedefs_1.LLMPurposes.Completion,
|
|
77
|
-
overrides: options.overrides,
|
|
78
|
-
});
|
|
79
|
-
return this.runCompletion(resolved, schema, options);
|
|
80
|
-
}
|
|
81
|
-
defineAgent(definition) {
|
|
82
|
-
return new LLMAgent_1.LLMAgent(definition);
|
|
83
|
-
}
|
|
84
|
-
async runAgent(promptOrAgent, options) {
|
|
85
|
-
const agent = promptOrAgent instanceof LLMAgent_1.LLMAgent ? promptOrAgent : undefined;
|
|
86
|
-
const promptKey = (agent ? agent.prompt : promptOrAgent);
|
|
87
|
-
const promptName = String(promptKey);
|
|
88
|
-
const binding = this.registry[promptKey];
|
|
89
|
-
this.assertOverridesAllowed(promptName, options.overrides);
|
|
90
|
-
const runResult = await this.agentRunner.run({
|
|
91
|
-
agentName: agent?.name ?? promptName,
|
|
92
|
-
promptName,
|
|
93
|
-
binding,
|
|
94
|
-
variables: { ...agent?.variables, ...options.variables },
|
|
95
|
-
input: options.input,
|
|
96
|
-
history: options.history,
|
|
97
|
-
tools: agent ? agent.tools : options.tools,
|
|
98
|
-
subagents: (agent ? agent.subagents : options.subagents),
|
|
99
|
-
maxToolIterations: agent
|
|
100
|
-
? agent.maxToolIterations
|
|
101
|
-
: options.maxToolIterations,
|
|
102
|
-
context: options.context,
|
|
103
|
-
abortSignal: options.abortSignal,
|
|
104
|
-
overrides: options.overrides,
|
|
105
|
-
onEvent: options.onEvent,
|
|
106
|
-
});
|
|
107
|
-
return runResult;
|
|
108
|
-
}
|
|
109
|
-
async countTokens(prompt, options) {
|
|
110
|
-
const promptName = String(prompt);
|
|
111
|
-
const binding = this.registry[prompt];
|
|
112
|
-
const resolved = await this.resolvePrompt(promptName, binding, options.variables, { purpose: LLMService_typedefs_1.LLMPurposes.Completion });
|
|
113
|
-
const service = await this.buildCompletionService(resolved, promptName);
|
|
114
|
-
const envelope = this.buildMessageEnvelope(resolved, options.history);
|
|
115
|
-
return service.countTokens([...envelope.history, envelope.message], resolved.model);
|
|
116
|
-
}
|
|
117
|
-
async describePrompt(prompt) {
|
|
118
|
-
const promptName = String(prompt);
|
|
119
|
-
const binding = this.registry[prompt];
|
|
120
|
-
const metadata = await this.runtime.describe({
|
|
121
|
-
name: promptName,
|
|
122
|
-
kind: binding.kind === 'chat' ? 'chat' : 'text',
|
|
123
|
-
requires: binding.requires ?? [],
|
|
124
|
-
purpose: LLMService_typedefs_1.LLMPurposes.Completion,
|
|
125
|
-
});
|
|
126
|
-
if (!metadata) {
|
|
127
|
-
throw new errors_1.LLMConfigError(`unable to resolve routing metadata for "${promptName}" (live and `
|
|
128
|
-
+ 'fallback both unusable)', { promptName });
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
provider: metadata.provider,
|
|
132
|
-
model: metadata.model,
|
|
133
|
-
promptVersion: metadata.promptVersion,
|
|
134
|
-
isFallback: metadata.isFallback,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
async resolvePrompt(promptName, binding, variables, call) {
|
|
138
|
-
const resolved = await this.runtime.resolve({
|
|
139
|
-
name: promptName,
|
|
140
|
-
kind: binding.kind === 'chat' ? 'chat' : 'text',
|
|
141
|
-
variables: this.stringifyVariables(variables),
|
|
142
|
-
requires: [
|
|
143
|
-
...(binding.requires ?? []),
|
|
144
|
-
...(call.additionalRequires ?? []),
|
|
145
|
-
],
|
|
146
|
-
purpose: call.purpose,
|
|
147
|
-
versionOverride: call.overrides?.promptVersion,
|
|
148
|
-
labelOverride: call.overrides?.promptLabel,
|
|
149
|
-
});
|
|
150
|
-
if (!resolved) {
|
|
151
|
-
throw new errors_1.LLMConfigError(`unable to resolve a valid prompt for "${promptName}" (live and fallback unusable)`, { promptName });
|
|
152
|
-
}
|
|
153
|
-
return resolved;
|
|
154
|
-
}
|
|
155
|
-
async runCompletion(resolved, schema, options) {
|
|
156
|
-
const service = await this.buildCompletionService(resolved, resolved.name);
|
|
157
|
-
const envelope = this.buildMessageEnvelope(resolved, options.history);
|
|
158
|
-
const reporterContext = this.buildReporterContext(resolved, options.context);
|
|
159
|
-
const traceContext = this.buildTraceContext(resolved, options.context);
|
|
160
|
-
const sendResult = await this.callProvider(() => (schema
|
|
161
|
-
? service.sendMessage({
|
|
162
|
-
message: envelope.message,
|
|
163
|
-
model: resolved.model,
|
|
164
|
-
history: envelope.history,
|
|
165
|
-
instructions: envelope.instructions,
|
|
166
|
-
schema,
|
|
167
|
-
abortSignal: options.abortSignal,
|
|
168
|
-
reporterContext,
|
|
169
|
-
traceContext,
|
|
170
|
-
})
|
|
171
|
-
: service.sendMessage({
|
|
172
|
-
message: envelope.message,
|
|
173
|
-
model: resolved.model,
|
|
174
|
-
history: envelope.history,
|
|
175
|
-
instructions: envelope.instructions,
|
|
176
|
-
abortSignal: options.abortSignal,
|
|
177
|
-
reporterContext,
|
|
178
|
-
traceContext,
|
|
179
|
-
})), resolved, options.abortSignal);
|
|
180
|
-
return this.unwrapResult(resolved, schema, sendResult);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Builds the provider message envelope from the resolved prompt. A `text`
|
|
184
|
-
* prompt is one user message. A `chat` prompt preserves the structure the
|
|
185
|
-
* prompt declares: a leading `system` message maps to `instructions`, the final
|
|
186
|
-
* `user` message is the request, and any messages between them join the
|
|
187
|
-
* call-supplied history in order.
|
|
188
|
-
*/
|
|
189
|
-
buildMessageEnvelope(resolved, callHistory) {
|
|
190
|
-
if (resolved.kind !== 'chat') {
|
|
191
|
-
return {
|
|
192
|
-
message: this.buildUserMessage(resolved.text),
|
|
193
|
-
history: this.buildHistory(callHistory),
|
|
194
|
-
instructions: undefined,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
const systemMessage = resolved.messages.find((message) => message.role === 'system');
|
|
198
|
-
const conversation = resolved.messages.filter((message) => message.role !== 'system');
|
|
199
|
-
const lastUserIndex = this.findLastUserIndex(conversation);
|
|
200
|
-
const promptHistory = conversation
|
|
201
|
-
.filter((_, index) => index !== lastUserIndex)
|
|
202
|
-
.map((message) => this.toCompletionMessage(message.role, message.content));
|
|
203
|
-
const requestText = lastUserIndex >= 0
|
|
204
|
-
? conversation[lastUserIndex].content
|
|
205
|
-
: resolved.text;
|
|
206
|
-
return {
|
|
207
|
-
message: this.buildUserMessage(requestText),
|
|
208
|
-
history: [...promptHistory, ...this.buildHistory(callHistory)],
|
|
209
|
-
instructions: systemMessage?.content,
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
findLastUserIndex(messages) {
|
|
213
|
-
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
214
|
-
if (messages[index].role === 'user') {
|
|
215
|
-
return index;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return -1;
|
|
219
|
-
}
|
|
220
|
-
async callProvider(send, resolved, abortSignal) {
|
|
221
|
-
try {
|
|
222
|
-
const result = await send();
|
|
223
|
-
if (result && typeof result === 'object' && 'error' in result) {
|
|
224
|
-
throw result.error;
|
|
225
|
-
}
|
|
226
|
-
return result;
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
throw this.toTaxonomyError(error, resolved, abortSignal);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
unwrapResult(resolved, schema, sendResult) {
|
|
233
|
-
if (!schema) {
|
|
234
|
-
return sendResult.text ?? '';
|
|
235
|
-
}
|
|
236
|
-
if (sendResult.parseError || sendResult.data === undefined) {
|
|
237
|
-
throw new errors_1.LLMSchemaValidationError(`structured output for "${resolved.name}" failed schema validation`, {
|
|
238
|
-
promptName: resolved.name,
|
|
239
|
-
provider: resolved.config.provider,
|
|
240
|
-
model: resolved.config.model,
|
|
241
|
-
rawText: sendResult.text ?? '',
|
|
242
|
-
parseDetails: sendResult.parseError ?? 'no data returned',
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
return sendResult.data;
|
|
246
|
-
}
|
|
247
|
-
toTaxonomyError(error, resolved, abortSignal) {
|
|
248
|
-
const context = {
|
|
249
|
-
promptName: resolved.name,
|
|
250
|
-
provider: resolved.config.provider,
|
|
251
|
-
model: resolved.config.model,
|
|
252
|
-
cause: error,
|
|
253
|
-
};
|
|
254
|
-
if (abortSignal?.aborted) {
|
|
255
|
-
return new errors_1.LLMAbortedError('LLM call aborted', context);
|
|
256
|
-
}
|
|
257
|
-
const status = this.extractStatus(error);
|
|
258
|
-
return new errors_1.LLMProviderError(error instanceof Error ? error.message : String(error), { ...context, retryable: this.isRetryableStatus(status), status });
|
|
259
|
-
}
|
|
260
|
-
async buildAssistanceService(resolved, promptName) {
|
|
261
|
-
const providerOptions = await this.resolveProviderOptions(resolved, promptName);
|
|
262
|
-
return this.gateway.getAssistanceService({
|
|
263
|
-
provider: resolved.config.provider,
|
|
264
|
-
options: providerOptions,
|
|
265
|
-
logger: this.logger,
|
|
266
|
-
reporter: this.reporter,
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
getBinding(promptName) {
|
|
270
|
-
return this.registry[promptName];
|
|
271
|
-
}
|
|
272
|
-
async buildCompletionService(resolved, promptName) {
|
|
273
|
-
const providerOptions = await this.resolveProviderOptions(resolved, promptName);
|
|
274
|
-
return this.gateway.getCompletionService({
|
|
275
|
-
provider: resolved.config.provider,
|
|
276
|
-
options: providerOptions,
|
|
277
|
-
logger: this.logger,
|
|
278
|
-
reporter: this.reporter,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
async resolveProviderOptions(resolved, promptName) {
|
|
282
|
-
return this.credentials({
|
|
283
|
-
provider: resolved.config.provider,
|
|
284
|
-
promptName,
|
|
285
|
-
product: this.staticContext.product,
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
buildUserMessage(text) {
|
|
289
|
-
return this.toCompletionMessage('user', text);
|
|
290
|
-
}
|
|
291
|
-
buildHistory(history) {
|
|
292
|
-
return (0, plainMessages_1.plainMessagesToContentMessages)(history);
|
|
293
|
-
}
|
|
294
|
-
toCompletionMessage(role, text) {
|
|
295
|
-
return {
|
|
296
|
-
role: role === 'assistant' ? LLMService_typedefs_1.LLMRoles.Assistant : LLMService_typedefs_1.LLMRoles.User,
|
|
297
|
-
content: [{ type: LLMService_typedefs_1.LLMMessageContentType.TEXT, text }],
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
buildReporterContext(resolved, callContext) {
|
|
301
|
-
if (!this.reporter) {
|
|
302
|
-
return undefined;
|
|
303
|
-
}
|
|
304
|
-
return {
|
|
305
|
-
...this.staticContext,
|
|
306
|
-
...this.serializeCallContext(callContext),
|
|
307
|
-
promptName: resolved.name,
|
|
308
|
-
promptVersion: resolved.version,
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Builds the per-call trace context every client path threads into the gateway
|
|
313
|
-
* service. The structural `prompt` names the observation and carries the
|
|
314
|
-
* managed prompt version, so the generation the service records on success and
|
|
315
|
-
* on error is the single one Langfuse links to that prompt — the client never
|
|
316
|
-
* records a second observation of its own.
|
|
317
|
-
*/
|
|
318
|
-
buildTraceContext(resolved, callContext) {
|
|
319
|
-
const metadata = {
|
|
320
|
-
promptVersion: resolved.version,
|
|
321
|
-
isFallback: resolved.isFallback,
|
|
322
|
-
};
|
|
323
|
-
const userId = callContext?.userId;
|
|
324
|
-
if (userId !== undefined && userId !== null) {
|
|
325
|
-
metadata.userId = userId;
|
|
326
|
-
}
|
|
327
|
-
return {
|
|
328
|
-
prompt: {
|
|
329
|
-
name: resolved.name,
|
|
330
|
-
version: resolved.version,
|
|
331
|
-
isFallback: resolved.isFallback,
|
|
332
|
-
},
|
|
333
|
-
metadata,
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
assertOverridesAllowed(promptName, overrides) {
|
|
337
|
-
if (this.mode === 'experiment' || !overrides) {
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
const hasOverride = Object.values(overrides).some((value) => value !== undefined);
|
|
341
|
-
if (hasOverride) {
|
|
342
|
-
throw new errors_1.LLMConfigError(`per-call overrides are rejected by a production-mode client for "${promptName}"`, { promptName });
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
stringifyVariables(variables) {
|
|
346
|
-
return Object.fromEntries(Object.entries(variables).map(([key, value]) => [key, String(value)]));
|
|
347
|
-
}
|
|
348
|
-
serializeCallContext(callContext) {
|
|
349
|
-
if (!callContext) {
|
|
350
|
-
return {};
|
|
351
|
-
}
|
|
352
|
-
return Object.fromEntries(Object.entries(callContext).filter((entry) => (entry[1] !== undefined && entry[1] !== null)));
|
|
353
|
-
}
|
|
354
|
-
extractStatus(error) {
|
|
355
|
-
if (error
|
|
356
|
-
&& typeof error === 'object'
|
|
357
|
-
&& 'status' in error
|
|
358
|
-
&& typeof error.status === 'number') {
|
|
359
|
-
return error.status;
|
|
360
|
-
}
|
|
361
|
-
return null;
|
|
362
|
-
}
|
|
363
|
-
isRetryableStatus(status) {
|
|
364
|
-
if (status === null) {
|
|
365
|
-
return true;
|
|
366
|
-
}
|
|
367
|
-
return status === 429 || status >= 500;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
46
|
//# sourceMappingURL=createLLMClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLLMClient.js","sourceRoot":"","sources":["../../src/client/createLLMClient.ts"],"names":[],"mappings":";;AA+HA,0CAwCC;AAvKD,+DAO+B;AAc/B,gDAAsE;AACtE,sDAK8B;AAC9B,0DAAwE;AACxE,gFAU2C;AAE3C,4EAGyC;AACzC,4CAKyB;AAsEzB;;;;;;GAMG;AACH,SAAgB,eAAe,CAI7B,MAAuC;IAEvC,MAAM,IAAI,GAAkB,MAAM,CAAC,IAAI,IAAI,YAAY,CAAC;IACxD,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,KAAK,4CAAiB;QACrD,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;IAE9B,MAAM,OAAO,GAAG,IAAI,8CAAqB,CAAC;QACxC,qBAAqB,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,CACrC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAC9C;QACD,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,YAAY,EAAE,MAAM,CAAC,YA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4
|
+
export * from './snapshotRuntime.typedefs';
|
|
5
|
+
export * from './snapshotRuntime';
|
|
4
6
|
export * from './promptClientPort.typedefs';
|
|
5
7
|
export * from './defineLLMPrompts';
|
|
6
8
|
export * from './validationGate';
|
|
7
9
|
export * from './promptRegistry.runtime';
|
|
8
|
-
export * from './
|
|
10
|
+
export * from './llmClient.typedefs';
|
|
9
11
|
export * from './createLLMClient';
|
|
10
12
|
export * from './agentRun.typedefs';
|
|
11
13
|
export * from './LLMAgent';
|
package/dist/client/index.js
CHANGED
|
@@ -17,11 +17,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./errors"), exports);
|
|
18
18
|
__exportStar(require("./llmConfig.schema"), exports);
|
|
19
19
|
__exportStar(require("./promptSnapshot.typedefs"), exports);
|
|
20
|
+
__exportStar(require("./snapshotRuntime.typedefs"), exports);
|
|
21
|
+
__exportStar(require("./snapshotRuntime"), exports);
|
|
20
22
|
__exportStar(require("./promptClientPort.typedefs"), exports);
|
|
21
23
|
__exportStar(require("./defineLLMPrompts"), exports);
|
|
22
24
|
__exportStar(require("./validationGate"), exports);
|
|
23
25
|
__exportStar(require("./promptRegistry.runtime"), exports);
|
|
24
|
-
__exportStar(require("./
|
|
26
|
+
__exportStar(require("./llmClient.typedefs"), exports);
|
|
25
27
|
__exportStar(require("./createLLMClient"), exports);
|
|
26
28
|
__exportStar(require("./agentRun.typedefs"), exports);
|
|
27
29
|
__exportStar(require("./LLMAgent"), exports);
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,qDAAmC;AACnC,4DAA0C;AAC1C,8DAA4C;AAC5C,qDAAmC;AACnC,mDAAiC;AACjC,2DAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,qDAAmC;AACnC,4DAA0C;AAC1C,6DAA2C;AAC3C,oDAAkC;AAClC,8DAA4C;AAC5C,qDAAmC;AACnC,mDAAiC;AACjC,2DAAyC;AACzC,uDAAqC;AACrC,oDAAkC;AAClC,sDAAoC;AACpC,6CAA2B"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { type LLMInstanceOptions, type LLMProviders, type LLMToolGateResult, type LLMToolResult } from '../LLMService.typedefs';
|
|
2
|
+
import { type LLMGateway } from '../LLMGateway';
|
|
3
|
+
import { type LLMLoggerInterface } from '../utilities/logger';
|
|
4
|
+
import { type LLMReporterInterface } from '../utilities/reporter';
|
|
5
|
+
import { type InferSchema, type LLMSchemaInterface } from '../utilities/schema';
|
|
6
|
+
import { type LLMGatewayPromptClient } from '../client/promptClientPort.typedefs';
|
|
7
|
+
import { type LLMPromptBinding, type LLMPromptRegistry } from '../client/defineLLMPrompts';
|
|
8
|
+
import { type LLMPromptSnapshot, type LLMVariableValue } from '../client/promptSnapshot.typedefs';
|
|
9
|
+
import { type PromptRegistryRuntime } from '../client/promptRegistry.runtime';
|
|
10
|
+
import { type LLMAgent, type LLMAgentDefinition } from '../client/LLMAgent';
|
|
11
|
+
import { type LLMAgentInlineRunOptions, type LLMAgentRunOptions, type LLMAgentRunResult } from '../client/agentRun.typedefs';
|
|
12
|
+
export type LLMClientMode = 'production' | 'experiment';
|
|
13
|
+
/**
|
|
14
|
+
* The explicit opt-out for the reporter pipeline; unlike tracing/prompts,
|
|
15
|
+
* reporting has no safe silent default, so tests must opt out loudly. Passed
|
|
16
|
+
* where `reporting` is expected to disable the Reporter/DWHSync wiring (tests,
|
|
17
|
+
* scripts).
|
|
18
|
+
*/
|
|
19
|
+
export declare const ReportingDisabled: unique symbol;
|
|
20
|
+
export type ReportingDisabledToken = typeof ReportingDisabled;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves provider credentials for one call, scoped by provider + prompt +
|
|
23
|
+
* product, preserving the existing per-feature Secrets Manager layout.
|
|
24
|
+
*/
|
|
25
|
+
export type LLMCredentialsResolver = <Provider extends LLMProviders>(scope: {
|
|
26
|
+
provider: Provider;
|
|
27
|
+
promptName: string;
|
|
28
|
+
product?: string;
|
|
29
|
+
}) => Promise<LLMInstanceOptions[Provider]>;
|
|
30
|
+
export interface LLMClientStaticContext {
|
|
31
|
+
product?: string;
|
|
32
|
+
appEnvironment?: string;
|
|
33
|
+
[key: string]: string | undefined;
|
|
34
|
+
}
|
|
35
|
+
export interface LLMClientCallContext {
|
|
36
|
+
userId?: string | number | null;
|
|
37
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
38
|
+
}
|
|
39
|
+
export interface LLMReportingConfig {
|
|
40
|
+
reporter: LLMReporterInterface<any>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* One tool call's outcome, as it stands before the client hands it to the
|
|
44
|
+
* model. `tool` is the tool (or subagent delegation) name, `agent` the run that
|
|
45
|
+
* called it, `input` the arguments the model supplied, and `result` the value
|
|
46
|
+
* the tool returned after the package's own coercion.
|
|
47
|
+
*/
|
|
48
|
+
export interface LLMToolResultContext {
|
|
49
|
+
tool: string;
|
|
50
|
+
agent: string;
|
|
51
|
+
input: unknown;
|
|
52
|
+
result: LLMToolResult;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A client-wide hook that rewrites every tool result before it reaches the
|
|
56
|
+
* model. It runs after the package coerces the raw return value, so it always
|
|
57
|
+
* receives a well-formed result; its own return is coerced again. Use it to
|
|
58
|
+
* apply one truncation, redaction, or envelope policy across every tool
|
|
59
|
+
* instead of repeating it in each `execute`.
|
|
60
|
+
*/
|
|
61
|
+
export type LLMToolResultNormalizer = (context: LLMToolResultContext) => LLMToolResult;
|
|
62
|
+
/**
|
|
63
|
+
* The precondition a delegation tool may declare, checked before the subagent
|
|
64
|
+
* starts. The `subagents` list erases the input schema's generic, so the
|
|
65
|
+
* arguments arrive untyped here: they are the subagent's `inputSchema` shape
|
|
66
|
+
* when it declares one, and `{ prompt }` otherwise.
|
|
67
|
+
*/
|
|
68
|
+
export type LLMDelegationGate = (args: Record<string, unknown>) => Promise<LLMToolGateResult> | LLMToolGateResult;
|
|
69
|
+
export interface CreateLLMClientConfig<Registry extends LLMPromptRegistry> {
|
|
70
|
+
gateway: LLMGateway;
|
|
71
|
+
registry: Registry;
|
|
72
|
+
snapshot: LLMPromptSnapshot;
|
|
73
|
+
credentials: LLMCredentialsResolver;
|
|
74
|
+
reporting: LLMReportingConfig | ReportingDisabledToken;
|
|
75
|
+
logger?: LLMLoggerInterface;
|
|
76
|
+
context?: LLMClientStaticContext;
|
|
77
|
+
mode?: LLMClientMode;
|
|
78
|
+
promptClient?: LLMGatewayPromptClient;
|
|
79
|
+
defaultLabel?: string;
|
|
80
|
+
cacheTtlSeconds?: number;
|
|
81
|
+
normalizeToolResult?: LLMToolResultNormalizer;
|
|
82
|
+
}
|
|
83
|
+
export interface LLMClientEngineConfig<Registry extends LLMPromptRegistry> {
|
|
84
|
+
gateway: LLMGateway;
|
|
85
|
+
registry: Registry;
|
|
86
|
+
runtime: PromptRegistryRuntime;
|
|
87
|
+
credentials: LLMCredentialsResolver;
|
|
88
|
+
reporter: LLMReporterInterface<any> | undefined;
|
|
89
|
+
logger: LLMLoggerInterface | undefined;
|
|
90
|
+
staticContext: Record<string, string | undefined>;
|
|
91
|
+
mode: LLMClientMode;
|
|
92
|
+
normalizeToolResult: LLMToolResultNormalizer | undefined;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The variables a prompt requires. Strict on required keys, tolerant of extras
|
|
96
|
+
* (`& Record<string, LLMVariableValue>`) so a Langfuse edit that drops a variable
|
|
97
|
+
* can never break a build — the stale extra is accepted, never rejected.
|
|
98
|
+
*/
|
|
99
|
+
export type LLMPromptVariables<RequiredKeys extends string> = Record<RequiredKeys, LLMVariableValue> & Record<string, LLMVariableValue>;
|
|
100
|
+
/**
|
|
101
|
+
* Where a subagent's prompt variables come from. Without an `inputSchema` the
|
|
102
|
+
* parent model supplies only a task string, so the definition must carry every
|
|
103
|
+
* variable the prompt requires. With one, the model fills the rest at call
|
|
104
|
+
* time — the definition's own variables become a partial base and the runtime
|
|
105
|
+
* validation gate is what proves the set complete.
|
|
106
|
+
*/
|
|
107
|
+
export type LLMSubagentVariableSource<RequiredKeys extends string> = {
|
|
108
|
+
inputSchema?: undefined;
|
|
109
|
+
variables: LLMPromptVariables<RequiredKeys>;
|
|
110
|
+
} | {
|
|
111
|
+
inputSchema: LLMSchemaInterface;
|
|
112
|
+
variables?: Partial<LLMPromptVariables<RequiredKeys>>;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* The return type of `generate` for one prompt: the bound schema's inferred type
|
|
116
|
+
* when a schema is present, else the raw completion string.
|
|
117
|
+
*/
|
|
118
|
+
export type LLMGenerateResult<Binding extends LLMPromptBinding> = Binding extends {
|
|
119
|
+
schema: infer Schema;
|
|
120
|
+
} ? Schema extends LLMSchemaInterface ? InferSchema<Schema> : string : string;
|
|
121
|
+
export interface LLMGenerateOptions<Variables extends Record<string, LLMVariableValue>, Schema extends LLMSchemaInterface = never> {
|
|
122
|
+
variables: Variables;
|
|
123
|
+
context?: LLMClientCallContext;
|
|
124
|
+
history?: LLMPlainMessage[];
|
|
125
|
+
abortSignal?: AbortSignal;
|
|
126
|
+
overrides?: LLMCallOverrides;
|
|
127
|
+
/**
|
|
128
|
+
* Per-call structured-output schema. Overrides the registry binding's `schema`
|
|
129
|
+
* for this call and drives the return type (`InferSchema<Schema>`). Use it when
|
|
130
|
+
* the output contract is dynamic per call (e.g. a schema whose shape depends on
|
|
131
|
+
* runtime input). The schema is the code-owned output contract, not a routing
|
|
132
|
+
* control, so it is honored in every mode.
|
|
133
|
+
*/
|
|
134
|
+
schema?: Schema;
|
|
135
|
+
}
|
|
136
|
+
export interface LLMCallOverrides {
|
|
137
|
+
model?: string;
|
|
138
|
+
provider?: LLMProviders;
|
|
139
|
+
promptVersion?: number;
|
|
140
|
+
promptLabel?: string;
|
|
141
|
+
}
|
|
142
|
+
export type LLMPlainMessageRole = 'user' | 'assistant';
|
|
143
|
+
export interface LLMPlainMessage {
|
|
144
|
+
role: LLMPlainMessageRole;
|
|
145
|
+
text: string;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Maps each registry key to the union of variable names its prompt requires. The
|
|
149
|
+
* generated snapshot supplies this map; defaulting to `string` keeps the client
|
|
150
|
+
* usable before codegen has run (every variable is then tolerated).
|
|
151
|
+
*/
|
|
152
|
+
export type LLMPromptVariableMap<Registry extends LLMPromptRegistry> = {
|
|
153
|
+
[Key in keyof Registry]: string;
|
|
154
|
+
};
|
|
155
|
+
export interface LLMClient<Registry extends LLMPromptRegistry, VariableMap extends Record<keyof Registry, string>> {
|
|
156
|
+
generate<Key extends keyof Registry, Schema extends LLMSchemaInterface = never>(prompt: Key, options: LLMGenerateOptions<Record<VariableMap[Key], LLMVariableValue> & Record<string, LLMVariableValue>, Schema>): Promise<[
|
|
157
|
+
Schema
|
|
158
|
+
] extends [never] ? LLMGenerateResult<Registry[Key]> : InferSchema<Schema>>;
|
|
159
|
+
countTokens<Key extends keyof Registry>(prompt: Key, options: {
|
|
160
|
+
variables: Record<string, LLMVariableValue>;
|
|
161
|
+
history?: LLMPlainMessage[];
|
|
162
|
+
}): Promise<number>;
|
|
163
|
+
defineAgent<Key extends keyof Registry>(definition: LLMAgentDefinition<Registry, VariableMap, Key>): LLMAgent<Registry, VariableMap, Key>;
|
|
164
|
+
runAgent<Key extends keyof Registry>(prompt: Key, options: LLMAgentInlineRunOptions<Record<VariableMap[Key], LLMVariableValue> & Record<string, LLMVariableValue>, Registry, VariableMap>): Promise<LLMAgentRunResult<LLMGenerateResult<Registry[Key]>>>;
|
|
165
|
+
runAgent<Key extends keyof Registry>(agent: LLMAgent<Registry, VariableMap, Key>, options: LLMAgentRunOptions<Record<VariableMap[Key], LLMVariableValue> & Record<string, LLMVariableValue>>): Promise<LLMAgentRunResult<LLMGenerateResult<Registry[Key]>>>;
|
|
166
|
+
describePrompt<Key extends keyof Registry>(prompt: Key): Promise<LLMPromptDescription>;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Read-only routing metadata for a prompt — the `{ provider, model,
|
|
170
|
+
* promptVersion }` the runtime would serve right now (same resolve/cache/fallback
|
|
171
|
+
* path `generate` uses). Lets analytics events record the resolved model without
|
|
172
|
+
* coupling to `generate`'s data-only return. `isFallback` flags the snapshot
|
|
173
|
+
* config was used because the live fetch was unreachable or failed the gate.
|
|
174
|
+
*/
|
|
175
|
+
export interface LLMPromptDescription {
|
|
176
|
+
provider: LLMProviders;
|
|
177
|
+
model: string;
|
|
178
|
+
promptVersion: number;
|
|
179
|
+
isFallback: boolean;
|
|
180
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llmClient.typedefs.js","sourceRoot":"","sources":["../../src/client/llmClient.typedefs.ts"],"names":[],"mappings":";;;AA6BA;;;;;GAKG;AACU,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LLMRoles, type LLMMessageTextContent } from '../LLMService.typedefs';
|
|
2
|
-
import { type LLMPlainMessage } from '../client/
|
|
2
|
+
import { type LLMPlainMessage } from '../client/llmClient.typedefs';
|
|
3
3
|
export interface LLMPlainTextContentMessage {
|
|
4
4
|
role: LLMRoles;
|
|
5
5
|
content: LLMMessageTextContent[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LLMPurposes, type LLMModel, type LLMProviders } from '../LLMService.typedefs';
|
|
2
2
|
import { type LLMLoggerInterface } from '../utilities/logger';
|
|
3
|
-
import { type
|
|
3
|
+
import { type LLMFallbackMetricEmitter } from '../utilities/llmTracing';
|
|
4
4
|
import { type LLMGatewayPromptClient } from '../client/promptClientPort.typedefs';
|
|
5
5
|
import { type LLMPromptKind, type LLMPromptMessage, type LLMPromptSnapshot } from '../client/promptSnapshot.typedefs';
|
|
6
6
|
import { type LLMPromptConfig } from '../client/llmConfig.schema';
|
|
@@ -60,7 +60,7 @@ export interface PromptRegistryRuntimeConfig {
|
|
|
60
60
|
defaultLabel: string;
|
|
61
61
|
cacheTtlSeconds?: number;
|
|
62
62
|
logger?: LLMLoggerInterface;
|
|
63
|
-
fallbackMetricEmitter?:
|
|
63
|
+
fallbackMetricEmitter?: LLMFallbackMetricEmitter;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Owns prompt resolution at runtime: a live SDK fetch (cached 60s,
|