@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.
Files changed (102) hide show
  1. package/README.md +76 -4
  2. package/dist/LLMGateway.d.ts +2 -2
  3. package/dist/LLMGateway.js.map +1 -1
  4. package/dist/LLMGateway.typedefs.d.ts +2 -2
  5. package/dist/LLMService.typedefs.d.ts +20 -0
  6. package/dist/LLMService.typedefs.js.map +1 -1
  7. package/dist/client/LLMAgent.d.ts +17 -4
  8. package/dist/client/LLMAgent.js +4 -0
  9. package/dist/client/LLMAgent.js.map +1 -1
  10. package/dist/client/LLMClientEngine.d.ts +81 -0
  11. package/dist/client/LLMClientEngine.js +350 -0
  12. package/dist/client/LLMClientEngine.js.map +1 -0
  13. package/dist/client/agentRun.typedefs.d.ts +18 -3
  14. package/dist/client/agentRun.typedefs.js +1 -0
  15. package/dist/client/agentRun.typedefs.js.map +1 -1
  16. package/dist/client/agentRunner.d.ts +38 -3
  17. package/dist/client/agentRunner.js +206 -80
  18. package/dist/client/agentRunner.js.map +1 -1
  19. package/dist/client/codegen/fetchPromptRecords.d.ts +1 -1
  20. package/dist/client/codegen/index.d.ts +1 -0
  21. package/dist/client/codegen/index.js +1 -0
  22. package/dist/client/codegen/index.js.map +1 -1
  23. package/dist/client/codegen/renderSnapshot.constants.d.ts +12 -0
  24. package/dist/client/codegen/renderSnapshot.constants.js +21 -0
  25. package/dist/client/codegen/renderSnapshot.constants.js.map +1 -0
  26. package/dist/client/codegen/renderSnapshot.d.ts +6 -18
  27. package/dist/client/codegen/renderSnapshot.js +152 -125
  28. package/dist/client/codegen/renderSnapshot.js.map +1 -1
  29. package/dist/client/codegen/renderSnapshot.typedefs.d.ts +20 -0
  30. package/dist/client/codegen/renderSnapshot.typedefs.js +3 -0
  31. package/dist/client/codegen/renderSnapshot.typedefs.js.map +1 -0
  32. package/dist/client/coerceToolResult.d.ts +10 -0
  33. package/dist/client/coerceToolResult.js +38 -0
  34. package/dist/client/coerceToolResult.js.map +1 -0
  35. package/dist/client/createLLMClient.d.ts +1 -40
  36. package/dist/client/createLLMClient.js +5 -329
  37. package/dist/client/createLLMClient.js.map +1 -1
  38. package/dist/client/index.d.ts +3 -1
  39. package/dist/client/index.js +3 -1
  40. package/dist/client/index.js.map +1 -1
  41. package/dist/client/llmClient.typedefs.d.ts +180 -0
  42. package/dist/client/{createLLMClient.typedefs.js → llmClient.typedefs.js} +1 -1
  43. package/dist/client/llmClient.typedefs.js.map +1 -0
  44. package/dist/client/plainMessages.d.ts +1 -1
  45. package/dist/client/promptRegistry.runtime.d.ts +2 -2
  46. package/dist/client/promptRegistry.runtime.js.map +1 -1
  47. package/dist/client/promptVariables.d.ts +7 -0
  48. package/dist/client/promptVariables.js +13 -0
  49. package/dist/client/promptVariables.js.map +1 -0
  50. package/dist/client/snapshotRuntime.d.ts +17 -0
  51. package/dist/client/snapshotRuntime.js +42 -0
  52. package/dist/client/snapshotRuntime.js.map +1 -0
  53. package/dist/client/snapshotRuntime.typedefs.d.ts +13 -0
  54. package/dist/client/snapshotRuntime.typedefs.js +3 -0
  55. package/dist/client/snapshotRuntime.typedefs.js.map +1 -0
  56. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js +6 -0
  57. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js.map +1 -1
  58. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js +6 -0
  59. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js.map +1 -1
  60. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js +3 -0
  61. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js.map +1 -1
  62. package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.d.ts +0 -2
  63. package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js +43 -25
  64. package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js.map +1 -1
  65. package/dist/providers/LLMAPI/services/LLMAPICompletion.service.d.ts +0 -2
  66. package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js +18 -17
  67. package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js.map +1 -1
  68. package/dist/providers/LLMAPI/utilities/index.d.ts +1 -1
  69. package/dist/providers/LLMAPI/utilities/index.js +3 -4
  70. package/dist/providers/LLMAPI/utilities/index.js.map +1 -1
  71. package/dist/providers/LLMAPI/utilities/validateStructuredResponse.d.ts +10 -0
  72. package/dist/providers/LLMAPI/utilities/validateStructuredResponse.js +21 -0
  73. package/dist/providers/LLMAPI/utilities/validateStructuredResponse.js.map +1 -0
  74. package/dist/providers/OpenAI/services/OpenAIAssistance.service.js +6 -0
  75. package/dist/providers/OpenAI/services/OpenAIAssistance.service.js.map +1 -1
  76. package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js +6 -0
  77. package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js.map +1 -1
  78. package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.js +3 -0
  79. package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.js.map +1 -1
  80. package/dist/services/LLMBaseService.abstract.d.ts +4 -3
  81. package/dist/services/LLMBaseService.abstract.js +6 -3
  82. package/dist/services/LLMBaseService.abstract.js.map +1 -1
  83. package/dist/utilities/index.d.ts +0 -1
  84. package/dist/utilities/index.js +0 -1
  85. package/dist/utilities/index.js.map +1 -1
  86. package/dist/utilities/llmTracing/llmTracing.constants.d.ts +5 -4
  87. package/dist/utilities/llmTracing/llmTracing.constants.js +6 -5
  88. package/dist/utilities/llmTracing/llmTracing.constants.js.map +1 -1
  89. package/dist/utilities/llmTracing/llmTracing.typedefs.d.ts +18 -9
  90. package/dist/utilities/llmTracing/noopLLMTracing.d.ts +2 -2
  91. package/dist/utilities/llmTracing/noopLLMTracing.js.map +1 -1
  92. package/dist/utilities/tools/LLMTool.d.ts +3 -12
  93. package/dist/utilities/tools/LLMTool.js.map +1 -1
  94. package/package.json +2 -1
  95. package/dist/client/createLLMClient.typedefs.d.ts +0 -91
  96. package/dist/client/createLLMClient.typedefs.js.map +0 -1
  97. package/dist/providers/LLMAPI/utilities/LLMAPIJsonFixer.d.ts +0 -24
  98. package/dist/providers/LLMAPI/utilities/LLMAPIJsonFixer.js +0 -237
  99. package/dist/providers/LLMAPI/utilities/LLMAPIJsonFixer.js.map +0 -1
  100. package/dist/utilities/traceIO.d.ts +0 -17
  101. package/dist/utilities/traceIO.js +0 -48
  102. package/dist/utilities/traceIO.js.map +0 -1
@@ -0,0 +1,350 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LLMClientEngine = void 0;
4
+ const LLMService_typedefs_1 = require("../LLMService.typedefs");
5
+ const LLMAgent_1 = require("../client/LLMAgent");
6
+ const agentRunner_1 = require("../client/agentRunner");
7
+ const plainMessages_1 = require("../client/plainMessages");
8
+ const coerceToolResult_1 = require("../client/coerceToolResult");
9
+ const promptVariables_1 = require("../client/promptVariables");
10
+ const errors_1 = require("../client/errors");
11
+ /**
12
+ * The client's single implementation. `createLLMClient` owns its construction
13
+ * and exposes only the `LLMClient` surface, so every call path — `generate`,
14
+ * `countTokens`, `runAgent`, `describePrompt` — shares one prompt resolution,
15
+ * one credentials lookup, one reporter/trace context, and one error taxonomy.
16
+ */
17
+ class LLMClientEngine {
18
+ gateway;
19
+ registry;
20
+ runtime;
21
+ credentials;
22
+ reporter;
23
+ logger;
24
+ staticContext;
25
+ mode;
26
+ toolResultNormalizer;
27
+ agentRunner;
28
+ constructor(config) {
29
+ this.gateway = config.gateway;
30
+ this.registry = config.registry;
31
+ this.runtime = config.runtime;
32
+ this.credentials = config.credentials;
33
+ this.reporter = config.reporter;
34
+ this.logger = config.logger;
35
+ this.staticContext = config.staticContext;
36
+ this.mode = config.mode;
37
+ this.toolResultNormalizer = config.normalizeToolResult;
38
+ this.agentRunner = new agentRunner_1.LLMAgentRunner(this, config.logger);
39
+ }
40
+ async generate(prompt, options) {
41
+ const promptName = String(prompt);
42
+ const binding = this.registry[prompt];
43
+ const schema = options.schema ?? binding.schema;
44
+ this.assertOverridesAllowed(promptName, options.overrides);
45
+ const resolved = await this.resolvePrompt(promptName, binding, options.variables, {
46
+ purpose: LLMService_typedefs_1.LLMPurposes.Completion,
47
+ overrides: options.overrides,
48
+ });
49
+ return this.runCompletion(resolved, schema, options);
50
+ }
51
+ defineAgent(definition) {
52
+ return new LLMAgent_1.LLMAgent(definition);
53
+ }
54
+ async runAgent(promptOrAgent, options) {
55
+ const agent = promptOrAgent instanceof LLMAgent_1.LLMAgent ? promptOrAgent : undefined;
56
+ const promptKey = (agent ? agent.prompt : promptOrAgent);
57
+ const promptName = String(promptKey);
58
+ const binding = this.registry[promptKey];
59
+ this.assertOverridesAllowed(promptName, options.overrides);
60
+ const runResult = await this.agentRunner.run({
61
+ agentName: agent?.name ?? promptName,
62
+ promptName,
63
+ binding,
64
+ variables: { ...agent?.variables, ...options.variables },
65
+ input: options.input,
66
+ history: options.history,
67
+ tools: agent ? agent.tools : options.tools,
68
+ subagents: (agent ? agent.subagents : options.subagents),
69
+ maxToolIterations: agent
70
+ ? agent.maxToolIterations
71
+ : options.maxToolIterations,
72
+ context: options.context,
73
+ abortSignal: options.abortSignal,
74
+ overrides: options.overrides,
75
+ onEvent: options.onEvent,
76
+ });
77
+ return runResult;
78
+ }
79
+ async countTokens(prompt, options) {
80
+ const promptName = String(prompt);
81
+ const binding = this.registry[prompt];
82
+ const resolved = await this.resolvePrompt(promptName, binding, options.variables, { purpose: LLMService_typedefs_1.LLMPurposes.Completion });
83
+ const service = await this.buildCompletionService(resolved, promptName);
84
+ const envelope = this.buildMessageEnvelope(resolved, options.history);
85
+ return service.countTokens([...envelope.history, envelope.message], resolved.model);
86
+ }
87
+ async describePrompt(prompt) {
88
+ const promptName = String(prompt);
89
+ const binding = this.registry[prompt];
90
+ const metadata = await this.runtime.describe({
91
+ name: promptName,
92
+ kind: binding.kind === 'chat' ? 'chat' : 'text',
93
+ requires: binding.requires ?? [],
94
+ purpose: LLMService_typedefs_1.LLMPurposes.Completion,
95
+ });
96
+ if (!metadata) {
97
+ throw new errors_1.LLMConfigError(`unable to resolve routing metadata for "${promptName}" (live and `
98
+ + 'fallback both unusable)', { promptName });
99
+ }
100
+ return {
101
+ provider: metadata.provider,
102
+ model: metadata.model,
103
+ promptVersion: metadata.promptVersion,
104
+ isFallback: metadata.isFallback,
105
+ };
106
+ }
107
+ async resolvePrompt(promptName, binding, variables, call) {
108
+ const resolved = await this.runtime.resolve({
109
+ name: promptName,
110
+ kind: binding.kind === 'chat' ? 'chat' : 'text',
111
+ variables: (0, promptVariables_1.stringifyPromptVariables)(variables),
112
+ requires: [
113
+ ...(binding.requires ?? []),
114
+ ...(call.additionalRequires ?? []),
115
+ ],
116
+ purpose: call.purpose,
117
+ versionOverride: call.overrides?.promptVersion,
118
+ labelOverride: call.overrides?.promptLabel,
119
+ });
120
+ if (!resolved) {
121
+ throw new errors_1.LLMConfigError(`unable to resolve a valid prompt for "${promptName}" (live and fallback unusable)`, { promptName });
122
+ }
123
+ return resolved;
124
+ }
125
+ /**
126
+ * The single place a tool's return value becomes what the model reads. The
127
+ * package's own coercion always runs first, so a client-supplied normalizer
128
+ * never sees a malformed value and cannot reintroduce one.
129
+ */
130
+ normalizeToolResult(context) {
131
+ const coerced = (0, coerceToolResult_1.coerceToolResult)(context.result);
132
+ if (!this.toolResultNormalizer) {
133
+ return coerced;
134
+ }
135
+ return (0, coerceToolResult_1.coerceToolResult)(this.toolResultNormalizer({ ...context, result: coerced }));
136
+ }
137
+ async runCompletion(resolved, schema, options) {
138
+ const service = await this.buildCompletionService(resolved, resolved.name);
139
+ const envelope = this.buildMessageEnvelope(resolved, options.history);
140
+ const reporterContext = this.buildReporterContext(resolved, options.context);
141
+ const traceContext = this.buildTraceContext(resolved, options.context);
142
+ const sendResult = await this.callProvider(() => (schema
143
+ ? service.sendMessage({
144
+ message: envelope.message,
145
+ model: resolved.model,
146
+ history: envelope.history,
147
+ instructions: envelope.instructions,
148
+ schema,
149
+ abortSignal: options.abortSignal,
150
+ reporterContext,
151
+ traceContext,
152
+ })
153
+ : service.sendMessage({
154
+ message: envelope.message,
155
+ model: resolved.model,
156
+ history: envelope.history,
157
+ instructions: envelope.instructions,
158
+ abortSignal: options.abortSignal,
159
+ reporterContext,
160
+ traceContext,
161
+ })), resolved, options.abortSignal);
162
+ return this.unwrapResult(resolved, schema, sendResult);
163
+ }
164
+ /**
165
+ * Builds the provider message envelope from the resolved prompt. A `text`
166
+ * prompt is one user message. A `chat` prompt preserves the structure the
167
+ * prompt declares: a leading `system` message maps to `instructions`, the final
168
+ * `user` message is the request, and any messages between them join the
169
+ * call-supplied history in order.
170
+ */
171
+ buildMessageEnvelope(resolved, callHistory) {
172
+ if (resolved.kind !== 'chat') {
173
+ return {
174
+ message: this.buildUserMessage(resolved.text),
175
+ history: this.buildHistory(callHistory),
176
+ instructions: undefined,
177
+ };
178
+ }
179
+ const systemMessage = resolved.messages.find((message) => message.role === 'system');
180
+ const conversation = resolved.messages.filter((message) => message.role !== 'system');
181
+ const lastUserIndex = this.findLastUserIndex(conversation);
182
+ const promptHistory = conversation
183
+ .filter((_, index) => index !== lastUserIndex)
184
+ .map((message) => this.toCompletionMessage(message.role, message.content));
185
+ const requestText = lastUserIndex >= 0
186
+ ? conversation[lastUserIndex].content
187
+ : resolved.text;
188
+ return {
189
+ message: this.buildUserMessage(requestText),
190
+ history: [...promptHistory, ...this.buildHistory(callHistory)],
191
+ instructions: systemMessage?.content,
192
+ };
193
+ }
194
+ findLastUserIndex(messages) {
195
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
196
+ if (messages[index].role === 'user') {
197
+ return index;
198
+ }
199
+ }
200
+ return -1;
201
+ }
202
+ async callProvider(send, resolved, abortSignal) {
203
+ try {
204
+ const result = await send();
205
+ if (result && typeof result === 'object' && 'error' in result) {
206
+ throw result.error;
207
+ }
208
+ return result;
209
+ }
210
+ catch (error) {
211
+ throw this.toTaxonomyError(error, resolved, abortSignal);
212
+ }
213
+ }
214
+ unwrapResult(resolved, schema, sendResult) {
215
+ if (!schema) {
216
+ return sendResult.text ?? '';
217
+ }
218
+ if (sendResult.parseError || sendResult.data === undefined) {
219
+ throw new errors_1.LLMSchemaValidationError(`structured output for "${resolved.name}" failed schema validation`, {
220
+ promptName: resolved.name,
221
+ provider: resolved.config.provider,
222
+ model: resolved.config.model,
223
+ rawText: sendResult.text ?? '',
224
+ parseDetails: sendResult.parseError ?? 'no data returned',
225
+ });
226
+ }
227
+ return sendResult.data;
228
+ }
229
+ toTaxonomyError(error, resolved, abortSignal) {
230
+ const context = {
231
+ promptName: resolved.name,
232
+ provider: resolved.config.provider,
233
+ model: resolved.config.model,
234
+ cause: error,
235
+ };
236
+ if (abortSignal?.aborted) {
237
+ return new errors_1.LLMAbortedError('LLM call aborted', context);
238
+ }
239
+ const status = this.extractStatus(error);
240
+ return new errors_1.LLMProviderError(error instanceof Error ? error.message : String(error), { ...context, retryable: this.isRetryableStatus(status), status });
241
+ }
242
+ async buildAssistanceService(resolved, promptName) {
243
+ const providerOptions = await this.resolveProviderOptions(resolved, promptName);
244
+ return this.gateway.getAssistanceService({
245
+ provider: resolved.config.provider,
246
+ options: providerOptions,
247
+ logger: this.logger,
248
+ reporter: this.reporter,
249
+ });
250
+ }
251
+ getBinding(promptName) {
252
+ return this.registry[promptName];
253
+ }
254
+ async buildCompletionService(resolved, promptName) {
255
+ const providerOptions = await this.resolveProviderOptions(resolved, promptName);
256
+ return this.gateway.getCompletionService({
257
+ provider: resolved.config.provider,
258
+ options: providerOptions,
259
+ logger: this.logger,
260
+ reporter: this.reporter,
261
+ });
262
+ }
263
+ async resolveProviderOptions(resolved, promptName) {
264
+ return this.credentials({
265
+ provider: resolved.config.provider,
266
+ promptName,
267
+ product: this.staticContext.product,
268
+ });
269
+ }
270
+ buildUserMessage(text) {
271
+ return this.toCompletionMessage('user', text);
272
+ }
273
+ buildHistory(history) {
274
+ return (0, plainMessages_1.plainMessagesToContentMessages)(history);
275
+ }
276
+ toCompletionMessage(role, text) {
277
+ return {
278
+ role: role === 'assistant' ? LLMService_typedefs_1.LLMRoles.Assistant : LLMService_typedefs_1.LLMRoles.User,
279
+ content: [{ type: LLMService_typedefs_1.LLMMessageContentType.TEXT, text }],
280
+ };
281
+ }
282
+ buildReporterContext(resolved, callContext) {
283
+ if (!this.reporter) {
284
+ return undefined;
285
+ }
286
+ return {
287
+ ...this.staticContext,
288
+ ...this.serializeCallContext(callContext),
289
+ promptName: resolved.name,
290
+ promptVersion: resolved.version,
291
+ };
292
+ }
293
+ /**
294
+ * Builds the per-call trace context every client path threads into the gateway
295
+ * service. The structural `prompt` names the observation and carries the
296
+ * managed prompt version, so the generation the service records on success and
297
+ * on error is the single one Langfuse links to that prompt — the client never
298
+ * records a second observation of its own.
299
+ */
300
+ buildTraceContext(resolved, callContext) {
301
+ const metadata = {
302
+ promptVersion: resolved.version,
303
+ isFallback: resolved.isFallback,
304
+ };
305
+ const userId = callContext?.userId;
306
+ if (userId !== undefined && userId !== null) {
307
+ metadata.userId = userId;
308
+ }
309
+ return {
310
+ prompt: {
311
+ name: resolved.name,
312
+ version: resolved.version,
313
+ isFallback: resolved.isFallback,
314
+ },
315
+ metadata,
316
+ };
317
+ }
318
+ assertOverridesAllowed(promptName, overrides) {
319
+ if (this.mode === 'experiment' || !overrides) {
320
+ return;
321
+ }
322
+ const hasOverride = Object.values(overrides).some((value) => value !== undefined);
323
+ if (hasOverride) {
324
+ throw new errors_1.LLMConfigError(`per-call overrides are rejected by a production-mode client for "${promptName}"`, { promptName });
325
+ }
326
+ }
327
+ serializeCallContext(callContext) {
328
+ if (!callContext) {
329
+ return {};
330
+ }
331
+ return Object.fromEntries(Object.entries(callContext).filter((entry) => (entry[1] !== undefined && entry[1] !== null)));
332
+ }
333
+ extractStatus(error) {
334
+ if (error
335
+ && typeof error === 'object'
336
+ && 'status' in error
337
+ && typeof error.status === 'number') {
338
+ return error.status;
339
+ }
340
+ return null;
341
+ }
342
+ isRetryableStatus(status) {
343
+ if (status === null) {
344
+ return true;
345
+ }
346
+ return status === 429 || status >= 500;
347
+ }
348
+ }
349
+ exports.LLMClientEngine = LLMClientEngine;
350
+ //# sourceMappingURL=LLMClientEngine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LLMClientEngine.js","sourceRoot":"","sources":["../../src/client/LLMClientEngine.ts"],"names":[],"mappings":";;;AAAA,+DAO+B;AAa/B,gDAAsE;AACtE,sDAK8B;AAC9B,0DAAwE;AACxE,gEAA6D;AAC7D,8DAAoE;AAmBpE,4CAKyB;AAEzB;;;;;GAKG;AACH,MAAa,eAAe;IAET,OAAO,CAAa;IAEpB,QAAQ,CAAW;IAEnB,OAAO,CAAwB;IAE/B,WAAW,CAAyB;IAEpC,QAAQ,CAAwC;IAEhD,MAAM,CAAiC;IAEvC,aAAa,CAAqC;IAElD,IAAI,CAAgB;IAEpB,oBAAoB,CAAsC;IAE1D,WAAW,CAAiB;IAE7C,YAAY,MAAuC;QACjD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,mBAAmB,CAAC;QACvD,IAAI,CAAC,WAA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ACE,KAAK;eACF,OAAO,KAAK,KAAK,QAAQ;eACzB,QAAQ,IAAI,KAAK;eACjB,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,EACnC,CAAC;YACD,OAAO,KAAK,CAAC,MAAM,CAAC;QACtB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,iBAAiB,CAAC,MAAqB;QAC7C,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,MAAM,KAAK,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC;IACzC,CAAC;CACF;AAlhBD,0CAkhBC"}
@@ -1,7 +1,7 @@
1
1
  import { type LLMToolDefinition, type LLMToolResult, type LLMTerminalToolOutcome, type LLMToolLoopStopReasons } from '../LLMService.typedefs';
2
2
  import { type LLMPromptRegistry } from '../client/defineLLMPrompts';
3
3
  import { type LLMVariableValue } from '../client/promptSnapshot.typedefs';
4
- import { type LLMCallOverrides, type LLMClientCallContext, type LLMPlainMessage } from '../client/createLLMClient.typedefs';
4
+ import { type LLMCallOverrides, type LLMClientCallContext, type LLMPlainMessage } from '../client/llmClient.typedefs';
5
5
  import { type LLMAgentSubagent } from '../client/LLMAgent';
6
6
  /**
7
7
  * Structured progress events an agent run emits while it works. They exist for
@@ -18,6 +18,7 @@ export declare enum LLMAgentEventTypes {
18
18
  ToolCallStarted = "tool_call_started",
19
19
  ToolCallCompleted = "tool_call_completed",
20
20
  ToolCallFailed = "tool_call_failed",
21
+ ToolCallDenied = "tool_call_denied",
21
22
  SubagentStarted = "subagent_started",
22
23
  SubagentCompleted = "subagent_completed",
23
24
  SubagentFailed = "subagent_failed"
@@ -88,13 +89,27 @@ export interface LLMAgentToolCallFailedEvent extends LLMAgentInvocationEventBase
88
89
  error: string;
89
90
  durationMs: number;
90
91
  }
92
+ /**
93
+ * A call the model made that never ran: the tool's `canExecute` precondition
94
+ * refused it. It replaces the `tool_call_completed` of that invocation (the
95
+ * `tool_call_started` before it shares the `invocationId`), and the run
96
+ * continues — the `reason` goes back to the model as the call's result. A
97
+ * refused delegation reports here too, with `tool` naming the subagent; the
98
+ * `subagent_started` that precedes it has no nested run because the subagent
99
+ * never started.
100
+ */
101
+ export interface LLMAgentToolCallDeniedEvent extends LLMAgentInvocationEventBase {
102
+ type: LLMAgentEventTypes.ToolCallDenied;
103
+ tool: string;
104
+ reason: string;
105
+ }
91
106
  export interface LLMAgentSubagentStartedEvent extends LLMAgentSubagentEventBase {
92
107
  type: LLMAgentEventTypes.SubagentStarted;
93
108
  input: string;
94
109
  }
95
110
  export interface LLMAgentSubagentCompletedEvent extends LLMAgentSubagentEventBase {
96
111
  type: LLMAgentEventTypes.SubagentCompleted;
97
- output: string;
112
+ output: LLMToolResult;
98
113
  durationMs: number;
99
114
  }
100
115
  export interface LLMAgentSubagentFailedEvent extends LLMAgentSubagentEventBase {
@@ -102,7 +117,7 @@ export interface LLMAgentSubagentFailedEvent extends LLMAgentSubagentEventBase {
102
117
  error: string;
103
118
  durationMs: number;
104
119
  }
105
- export type LLMAgentEvent = LLMAgentStartedEvent | LLMAgentMessageEvent | LLMAgentCompletedEvent | LLMAgentFailedEvent | LLMAgentToolCallStartedEvent | LLMAgentToolCallCompletedEvent | LLMAgentToolCallFailedEvent | LLMAgentSubagentStartedEvent | LLMAgentSubagentCompletedEvent | LLMAgentSubagentFailedEvent;
120
+ export type LLMAgentEvent = LLMAgentStartedEvent | LLMAgentMessageEvent | LLMAgentCompletedEvent | LLMAgentFailedEvent | LLMAgentToolCallStartedEvent | LLMAgentToolCallCompletedEvent | LLMAgentToolCallFailedEvent | LLMAgentToolCallDeniedEvent | LLMAgentSubagentStartedEvent | LLMAgentSubagentCompletedEvent | LLMAgentSubagentFailedEvent;
106
121
  /**
107
122
  * May be async: a returned promise's rejection is caught and logged, so a
108
123
  * failing listener (WS publish, DB persist) never affects the agent run.
@@ -17,6 +17,7 @@ var LLMAgentEventTypes;
17
17
  LLMAgentEventTypes["ToolCallStarted"] = "tool_call_started";
18
18
  LLMAgentEventTypes["ToolCallCompleted"] = "tool_call_completed";
19
19
  LLMAgentEventTypes["ToolCallFailed"] = "tool_call_failed";
20
+ LLMAgentEventTypes["ToolCallDenied"] = "tool_call_denied";
20
21
  LLMAgentEventTypes["SubagentStarted"] = "subagent_started";
21
22
  LLMAgentEventTypes["SubagentCompleted"] = "subagent_completed";
22
23
  LLMAgentEventTypes["SubagentFailed"] = "subagent_failed";
@@ -1 +1 @@
1
- {"version":3,"file":"agentRun.typedefs.js","sourceRoot":"","sources":["../../src/client/agentRun.typedefs.ts"],"names":[],"mappings":";;;AAeA;;;;;;GAMG;AACH,IAAY,kBAWX;AAXD,WAAY,kBAAkB;IAC5B,oDAA8B,CAAA;IAC9B,oDAA8B,CAAA;IAC9B,wDAAkC,CAAA;IAClC,kDAA4B,CAAA;IAC5B,2DAAqC,CAAA;IACrC,+DAAyC,CAAA;IACzC,yDAAmC,CAAA;IACnC,0DAAoC,CAAA;IACpC,8DAAwC,CAAA;IACxC,wDAAkC,CAAA;AACpC,CAAC,EAXW,kBAAkB,kCAAlB,kBAAkB,QAW7B"}
1
+ {"version":3,"file":"agentRun.typedefs.js","sourceRoot":"","sources":["../../src/client/agentRun.typedefs.ts"],"names":[],"mappings":";;;AAeA;;;;;;GAMG;AACH,IAAY,kBAYX;AAZD,WAAY,kBAAkB;IAC5B,oDAA8B,CAAA;IAC9B,oDAA8B,CAAA;IAC9B,wDAAkC,CAAA;IAClC,kDAA4B,CAAA;IAC5B,2DAAqC,CAAA;IACrC,+DAAyC,CAAA;IACzC,yDAAmC,CAAA;IACnC,yDAAmC,CAAA;IACnC,0DAAoC,CAAA;IACpC,8DAAwC,CAAA;IACxC,wDAAkC,CAAA;AACpC,CAAC,EAZW,kBAAkB,kCAAlB,kBAAkB,QAY7B"}
@@ -1,4 +1,4 @@
1
- import { LLMPurposes, LLMToolLoopStopReasons, type LLMCallTraceContext, type LLMProviders, type LLMTerminalToolOutcome, type LLMToolDefinition } from '../LLMService.typedefs';
1
+ import { LLMPurposes, LLMToolLoopStopReasons, type LLMCallTraceContext, type LLMProviders, type LLMTerminalToolOutcome, type LLMToolDefinition, type LLMToolResult } from '../LLMService.typedefs';
2
2
  import { type LLMAssistanceService } from '../services';
3
3
  import { type LLMLoggerInterface } from '../utilities/logger';
4
4
  import { type LLMReporterInterface } from '../utilities/reporter';
@@ -6,7 +6,7 @@ import { type LLMSchemaInterface } from '../utilities/schema';
6
6
  import { type LLMCapabilityRequirement, type LLMPromptBinding } from '../client/defineLLMPrompts';
7
7
  import { type LLMVariableValue } from '../client/promptSnapshot.typedefs';
8
8
  import { type ResolvedPrompt } from '../client/promptRegistry.runtime';
9
- import { type LLMCallOverrides, type LLMClientCallContext, type LLMPlainMessage } from '../client/createLLMClient.typedefs';
9
+ import { type LLMCallOverrides, type LLMClientCallContext, type LLMDelegationGate, type LLMPlainMessage, type LLMToolResultContext } from '../client/llmClient.typedefs';
10
10
  import { LLMAgent } from '../client/LLMAgent';
11
11
  import { type LLMAgentEventListener, type LLMAgentRunResult } from '../client/agentRun.typedefs';
12
12
  type AgentAssistanceService = LLMAssistanceService<LLMProviders, LLMReporterInterface<any> | undefined>;
@@ -39,6 +39,7 @@ export interface LLMAgentCallServices {
39
39
  toTaxonomyError(error: unknown, resolved: ResolvedPrompt, abortSignal?: AbortSignal): Error;
40
40
  unwrapResult(resolved: ResolvedPrompt, schema: LLMSchemaInterface | undefined, sendResult: AgentSendResult): unknown;
41
41
  getBinding(promptName: string): LLMPromptBinding | undefined;
42
+ normalizeToolResult(context: LLMToolResultContext): LLMToolResult;
42
43
  }
43
44
  /**
44
45
  * A plain-object subagent with the registry generics erased: the engine
@@ -49,8 +50,10 @@ export interface LLMAgentSubagentSpec {
49
50
  prompt: string;
50
51
  name: string;
51
52
  description: string;
52
- variables: Record<string, LLMVariableValue>;
53
+ variables?: Record<string, LLMVariableValue>;
53
54
  tools?: LLMToolDefinition[];
55
+ inputSchema?: LLMSchemaInterface;
56
+ canExecute?: LLMDelegationGate;
54
57
  maxToolIterations?: number;
55
58
  }
56
59
  type SubagentEntry = LLMAgentSubagentSpec | LLMAgent;
@@ -95,7 +98,39 @@ export declare class LLMAgentRunner {
95
98
  private assistInChat;
96
99
  private buildTools;
97
100
  private wrapToolWithEvents;
101
+ /**
102
+ * The lifecycle of one tool invocation. The completion event depends on what
103
+ * the invocation produced: a refused call reports `tool_call_denied` in place
104
+ * of `tool_call_completed`, so a listener never records a side effect that
105
+ * did not happen.
106
+ */
107
+ private buildToolCallLifecycle;
108
+ private executeGatedTool;
109
+ private resolveToolGate;
110
+ /**
111
+ * What a refused call hands back to the model. It names the tool and the
112
+ * reason so the model can adapt instead of retrying the same call, and it
113
+ * never passes through the client's normalizer — a denial is the package's
114
+ * own control flow, not a tool's output.
115
+ */
116
+ private buildDenial;
98
117
  private buildSubagentTool;
118
+ private buildDelegationLifecycle;
119
+ private delegateToSubagent;
120
+ /**
121
+ * A typed delegation hands the whole argument object to the subagent as its
122
+ * request, since the parent model filled a schema rather than writing a
123
+ * task sentence. Without a schema the single `prompt` argument is the
124
+ * request, exactly as before.
125
+ */
126
+ private buildDelegationInput;
127
+ /**
128
+ * Typed delegation arguments join the subagent's own variables (and win over
129
+ * them), so the delegated Langfuse prompt can reference what the parent model
130
+ * supplied as `{{argument}}` and the validation gate covers it like any other
131
+ * variable.
132
+ */
133
+ private buildDelegationVariables;
99
134
  /**
100
135
  * Flattens a nested run back into the string its delegation tool returns to
101
136
  * the parent model. A delegation tool is never itself terminal, so a