@mate-academy/llm-gateway 8.8.2 → 8.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LLMError.d.ts +12 -0
- package/dist/LLMError.js +36 -0
- package/dist/LLMError.js.map +1 -0
- package/dist/LLMGateway.d.ts +30 -0
- package/dist/LLMGateway.js +56 -0
- package/dist/LLMGateway.js.map +1 -0
- package/dist/LLMGateway.typedefs.d.ts +5 -0
- package/dist/LLMGateway.typedefs.js +3 -0
- package/dist/LLMGateway.typedefs.js.map +1 -0
- package/dist/LLMService.constants.d.ts +26309 -0
- package/dist/LLMService.constants.js +35 -0
- package/dist/LLMService.constants.js.map +1 -0
- package/dist/LLMService.factory.d.ts +71 -0
- package/dist/LLMService.factory.js +102 -0
- package/dist/LLMService.factory.js.map +1 -0
- package/dist/LLMService.typedefs.d.ts +655 -0
- package/dist/LLMService.typedefs.js +72 -0
- package/dist/LLMService.typedefs.js.map +1 -0
- package/dist/advanced.d.ts +11 -0
- package/dist/advanced.js +32 -0
- package/dist/advanced.js.map +1 -0
- package/dist/client/LLMAgent.d.ts +76 -0
- package/dist/client/LLMAgent.js +36 -0
- package/dist/client/LLMAgent.js.map +1 -0
- package/dist/client/LLMClientEngine.d.ts +110 -0
- package/dist/client/LLMClientEngine.js +406 -0
- package/dist/client/LLMClientEngine.js.map +1 -0
- package/dist/client/agentRun.typedefs.d.ts +200 -0
- package/dist/client/agentRun.typedefs.js +25 -0
- package/dist/client/agentRun.typedefs.js.map +1 -0
- package/dist/client/agentRunner.d.ts +161 -0
- package/dist/client/agentRunner.js +517 -0
- package/dist/client/agentRunner.js.map +1 -0
- package/dist/client/codegen/fetchPromptRecords.d.ts +14 -0
- package/dist/client/codegen/fetchPromptRecords.js +90 -0
- package/dist/client/codegen/fetchPromptRecords.js.map +1 -0
- package/dist/client/codegen/generateSnapshot.d.ts +19 -0
- package/dist/client/codegen/generateSnapshot.js +28 -0
- package/dist/client/codegen/generateSnapshot.js.map +1 -0
- package/dist/client/codegen/index.d.ts +6 -0
- package/dist/client/codegen/index.js +23 -0
- package/dist/client/codegen/index.js.map +1 -0
- package/dist/client/codegen/promptCatalog.typedefs.d.ts +51 -0
- package/dist/client/codegen/promptCatalog.typedefs.js +3 -0
- package/dist/client/codegen/promptCatalog.typedefs.js.map +1 -0
- package/dist/client/codegen/promptName.d.ts +8 -0
- package/dist/client/codegen/promptName.js +21 -0
- package/dist/client/codegen/promptName.js.map +1 -0
- package/dist/client/codegen/renderSnapshot.constants.d.ts +7 -0
- package/dist/client/codegen/renderSnapshot.constants.js +16 -0
- package/dist/client/codegen/renderSnapshot.constants.js.map +1 -0
- package/dist/client/codegen/renderSnapshot.d.ts +9 -0
- package/dist/client/codegen/renderSnapshot.js +109 -0
- package/dist/client/codegen/renderSnapshot.js.map +1 -0
- package/dist/client/codegen/renderSnapshot.typedefs.d.ts +19 -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 +10 -0
- package/dist/client/createLLMClient.js +47 -0
- package/dist/client/createLLMClient.js.map +1 -0
- package/dist/client/defineLLMPrompts.d.ts +34 -0
- package/dist/client/defineLLMPrompts.js +13 -0
- package/dist/client/defineLLMPrompts.js.map +1 -0
- package/dist/client/errors.d.ts +57 -0
- package/dist/client/errors.js +70 -0
- package/dist/client/errors.js.map +1 -0
- package/dist/client/index.d.ts +13 -0
- package/dist/client/index.js +30 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/llmClient.typedefs.d.ts +265 -0
- package/dist/client/llmClient.typedefs.js +11 -0
- package/dist/client/llmClient.typedefs.js.map +1 -0
- package/dist/client/llmConfig.schema.d.ts +53 -0
- package/dist/client/llmConfig.schema.js +49 -0
- package/dist/client/llmConfig.schema.js.map +1 -0
- package/dist/client/plainMessages.d.ts +12 -0
- package/dist/client/plainMessages.js +19 -0
- package/dist/client/plainMessages.js.map +1 -0
- package/dist/client/promptClientPort.typedefs.d.ts +60 -0
- package/dist/client/promptClientPort.typedefs.js +3 -0
- package/dist/client/promptClientPort.typedefs.js.map +1 -0
- package/dist/client/promptRegistry.runtime.d.ts +121 -0
- package/dist/client/promptRegistry.runtime.js +264 -0
- package/dist/client/promptRegistry.runtime.js.map +1 -0
- package/dist/client/promptSnapshot.typedefs.d.ts +55 -0
- package/dist/client/promptSnapshot.typedefs.js +3 -0
- package/dist/client/promptSnapshot.typedefs.js.map +1 -0
- 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/client/validationGate.d.ts +24 -0
- package/dist/client/validationGate.js +54 -0
- package/dist/client/validationGate.js.map +1 -0
- package/dist/codegen.d.ts +6 -0
- package/dist/codegen.js +23 -0
- package/dist/codegen.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.constants.d.ts +873 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.constants.js +269 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.constants.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.entity.d.ts +24 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.entity.js +210 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.entity.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.d.ts +22 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.js +20 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAIService.factory.d.ts +6 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAIService.factory.js +18 -0
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAIService.factory.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/index.d.ts +5 -0
- package/dist/providers/GoogleGenerativeAI/index.js +22 -0
- package/dist/providers/GoogleGenerativeAI/index.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/schemas/GoogleSchemaAdapter.d.ts +12 -0
- package/dist/providers/GoogleGenerativeAI/schemas/GoogleSchemaAdapter.js +72 -0
- package/dist/providers/GoogleGenerativeAI/schemas/GoogleSchemaAdapter.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.d.ts +71 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js +876 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.d.ts +25 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js +216 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.d.ts +10 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js +136 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAITextToSpeech.service.d.ts +11 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAITextToSpeech.service.js +97 -0
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAITextToSpeech.service.js.map +1 -0
- package/dist/providers/GoogleGenerativeAI/services/index.d.ts +4 -0
- package/dist/providers/GoogleGenerativeAI/services/index.js +21 -0
- package/dist/providers/GoogleGenerativeAI/services/index.js.map +1 -0
- package/dist/providers/LLMAPI/LLMAPI.constants.d.ts +35832 -0
- package/dist/providers/LLMAPI/LLMAPI.constants.js +8601 -0
- package/dist/providers/LLMAPI/LLMAPI.constants.js.map +1 -0
- package/dist/providers/LLMAPI/LLMAPI.entity.d.ts +6 -0
- package/dist/providers/LLMAPI/LLMAPI.entity.js +48 -0
- package/dist/providers/LLMAPI/LLMAPI.entity.js.map +1 -0
- package/dist/providers/LLMAPI/LLMAPI.typedefs.d.ts +516 -0
- package/dist/providers/LLMAPI/LLMAPI.typedefs.js +564 -0
- package/dist/providers/LLMAPI/LLMAPI.typedefs.js.map +1 -0
- package/dist/providers/LLMAPI/LLMAPI.voices.d.ts +376 -0
- package/dist/providers/LLMAPI/LLMAPI.voices.js +739 -0
- package/dist/providers/LLMAPI/LLMAPI.voices.js.map +1 -0
- package/dist/providers/LLMAPI/LLMAPIService.factory.d.ts +6 -0
- package/dist/providers/LLMAPI/LLMAPIService.factory.js +19 -0
- package/dist/providers/LLMAPI/LLMAPIService.factory.js.map +1 -0
- package/dist/providers/LLMAPI/index.d.ts +7 -0
- package/dist/providers/LLMAPI/index.js +24 -0
- package/dist/providers/LLMAPI/index.js.map +1 -0
- package/dist/providers/LLMAPI/schemas/LLMAPISchemaAdapter.d.ts +3 -0
- package/dist/providers/LLMAPI/schemas/LLMAPISchemaAdapter.js +8 -0
- package/dist/providers/LLMAPI/schemas/LLMAPISchemaAdapter.js.map +1 -0
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.d.ts +76 -0
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js +825 -0
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js.map +1 -0
- package/dist/providers/LLMAPI/services/LLMAPICompletion.service.d.ts +25 -0
- package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js +177 -0
- package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js.map +1 -0
- package/dist/providers/LLMAPI/services/LLMAPISpeechToText.service.d.ts +17 -0
- package/dist/providers/LLMAPI/services/LLMAPISpeechToText.service.js +34 -0
- package/dist/providers/LLMAPI/services/LLMAPISpeechToText.service.js.map +1 -0
- package/dist/providers/LLMAPI/services/LLMAPITextToSpeech.service.d.ts +20 -0
- package/dist/providers/LLMAPI/services/LLMAPITextToSpeech.service.js +36 -0
- package/dist/providers/LLMAPI/services/LLMAPITextToSpeech.service.js.map +1 -0
- package/dist/providers/LLMAPI/services/index.d.ts +4 -0
- package/dist/providers/LLMAPI/services/index.js +21 -0
- package/dist/providers/LLMAPI/services/index.js.map +1 -0
- package/dist/providers/LLMAPI/utilities/index.d.ts +4 -0
- package/dist/providers/LLMAPI/utilities/index.js +13 -0
- package/dist/providers/LLMAPI/utilities/index.js.map +1 -0
- package/dist/providers/LLMAPI/utilities/parseXmlToolCalls.d.ts +7 -0
- package/dist/providers/LLMAPI/utilities/parseXmlToolCalls.js +35 -0
- package/dist/providers/LLMAPI/utilities/parseXmlToolCalls.js.map +1 -0
- package/dist/providers/LLMAPI/utilities/stripThinkingTags.d.ts +1 -0
- package/dist/providers/LLMAPI/utilities/stripThinkingTags.js +7 -0
- package/dist/providers/LLMAPI/utilities/stripThinkingTags.js.map +1 -0
- package/dist/providers/LLMAPI/utilities/structuredOutput.d.ts +13 -0
- package/dist/providers/LLMAPI/utilities/structuredOutput.js +29 -0
- package/dist/providers/LLMAPI/utilities/structuredOutput.js.map +1 -0
- 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/OpenAI.constants.d.ts +1664 -0
- package/dist/providers/OpenAI/OpenAI.constants.js +310 -0
- package/dist/providers/OpenAI/OpenAI.constants.js.map +1 -0
- package/dist/providers/OpenAI/OpenAI.entity.d.ts +15 -0
- package/dist/providers/OpenAI/OpenAI.entity.js +162 -0
- package/dist/providers/OpenAI/OpenAI.entity.js.map +1 -0
- package/dist/providers/OpenAI/OpenAI.typedefs.d.ts +61 -0
- package/dist/providers/OpenAI/OpenAI.typedefs.js +39 -0
- package/dist/providers/OpenAI/OpenAI.typedefs.js.map +1 -0
- package/dist/providers/OpenAI/OpenAIService.factory.d.ts +6 -0
- package/dist/providers/OpenAI/OpenAIService.factory.js +18 -0
- package/dist/providers/OpenAI/OpenAIService.factory.js.map +1 -0
- package/dist/providers/OpenAI/index.d.ts +5 -0
- package/dist/providers/OpenAI/index.js +22 -0
- package/dist/providers/OpenAI/index.js.map +1 -0
- package/dist/providers/OpenAI/schemas/OpenAISchemaAdapter.d.ts +14 -0
- package/dist/providers/OpenAI/schemas/OpenAISchemaAdapter.js +87 -0
- package/dist/providers/OpenAI/schemas/OpenAISchemaAdapter.js.map +1 -0
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.d.ts +42 -0
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.js +712 -0
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.js.map +1 -0
- package/dist/providers/OpenAI/services/OpenAICompletion.service.d.ts +7 -0
- package/dist/providers/OpenAI/services/OpenAICompletion.service.js +12 -0
- package/dist/providers/OpenAI/services/OpenAICompletion.service.js.map +1 -0
- package/dist/providers/OpenAI/services/OpenAISpeechToText.service.d.ts +17 -0
- package/dist/providers/OpenAI/services/OpenAISpeechToText.service.js +40 -0
- package/dist/providers/OpenAI/services/OpenAISpeechToText.service.js.map +1 -0
- package/dist/providers/OpenAI/services/OpenAITextToSpeech.service.d.ts +13 -0
- package/dist/providers/OpenAI/services/OpenAITextToSpeech.service.js +32 -0
- package/dist/providers/OpenAI/services/OpenAITextToSpeech.service.js.map +1 -0
- package/dist/providers/OpenAI/services/buildFunctionCallOutput.d.ts +3 -0
- package/dist/providers/OpenAI/services/buildFunctionCallOutput.js +19 -0
- package/dist/providers/OpenAI/services/buildFunctionCallOutput.js.map +1 -0
- package/dist/providers/OpenAI/services/index.d.ts +4 -0
- package/dist/providers/OpenAI/services/index.js +21 -0
- package/dist/providers/OpenAI/services/index.js.map +1 -0
- package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.d.ts +30 -0
- package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js +233 -0
- package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js.map +1 -0
- package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.d.ts +22 -0
- package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.js +98 -0
- package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.js.map +1 -0
- package/dist/providers/OpenAICompatible/OpenAICompatibleTextToSpeech.service.d.ts +22 -0
- package/dist/providers/OpenAICompatible/OpenAICompatibleTextToSpeech.service.js +67 -0
- package/dist/providers/OpenAICompatible/OpenAICompatibleTextToSpeech.service.js.map +1 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.js +20 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/services/LLMAssistanceService.abstract.d.ts +39 -0
- package/dist/services/LLMAssistanceService.abstract.js +101 -0
- package/dist/services/LLMAssistanceService.abstract.js.map +1 -0
- package/dist/services/LLMBaseService.abstract.d.ts +161 -0
- package/dist/services/LLMBaseService.abstract.js +392 -0
- package/dist/services/LLMBaseService.abstract.js.map +1 -0
- package/dist/services/LLMCompletionService.abstract.d.ts +16 -0
- package/dist/services/LLMCompletionService.abstract.js +12 -0
- package/dist/services/LLMCompletionService.abstract.js.map +1 -0
- package/dist/services/LLMServicePurposeFactory.abstract.d.ts +12 -0
- package/dist/services/LLMServicePurposeFactory.abstract.js +7 -0
- package/dist/services/LLMServicePurposeFactory.abstract.js.map +1 -0
- package/dist/services/LLMSpeechToTextService.abstract.d.ts +8 -0
- package/dist/services/LLMSpeechToTextService.abstract.js +12 -0
- package/dist/services/LLMSpeechToTextService.abstract.js.map +1 -0
- package/dist/services/LLMTextToSpeechService.abstract.d.ts +8 -0
- package/dist/services/LLMTextToSpeechService.abstract.js +12 -0
- package/dist/services/LLMTextToSpeechService.abstract.js.map +1 -0
- package/dist/services/agentRounds/LLMAgentRounds.d.ts +32 -0
- package/dist/services/agentRounds/LLMAgentRounds.js +77 -0
- package/dist/services/agentRounds/LLMAgentRounds.js.map +1 -0
- package/dist/services/agentRounds/agentRounds.typedefs.d.ts +48 -0
- package/dist/services/agentRounds/agentRounds.typedefs.js +3 -0
- package/dist/services/agentRounds/agentRounds.typedefs.js.map +1 -0
- package/dist/services/agentRounds/index.d.ts +2 -0
- package/dist/services/agentRounds/index.js +19 -0
- package/dist/services/agentRounds/index.js.map +1 -0
- package/dist/services/chatState/CompletionsChatState.d.ts +35 -0
- package/dist/services/chatState/CompletionsChatState.js +118 -0
- package/dist/services/chatState/CompletionsChatState.js.map +1 -0
- package/dist/services/chatState/index.d.ts +1 -0
- package/dist/services/chatState/index.js +6 -0
- package/dist/services/chatState/index.js.map +1 -0
- package/dist/services/fileStorage/FileStorageToolExecutor.d.ts +15 -0
- package/dist/services/fileStorage/FileStorageToolExecutor.js +172 -0
- package/dist/services/fileStorage/FileStorageToolExecutor.js.map +1 -0
- package/dist/services/fileStorage/InMemoryFileStorage.d.ts +20 -0
- package/dist/services/fileStorage/InMemoryFileStorage.js +67 -0
- package/dist/services/fileStorage/InMemoryFileStorage.js.map +1 -0
- package/dist/services/fileStorage/fileStorageTools.d.ts +26 -0
- package/dist/services/fileStorage/fileStorageTools.js +68 -0
- package/dist/services/fileStorage/fileStorageTools.js.map +1 -0
- package/dist/services/fileStorage/index.d.ts +4 -0
- package/dist/services/fileStorage/index.js +11 -0
- package/dist/services/fileStorage/index.js.map +1 -0
- package/dist/services/index.d.ts +7 -0
- package/dist/services/index.js +24 -0
- package/dist/services/index.js.map +1 -0
- package/dist/utilities/calculateCosts.d.ts +4 -0
- package/dist/utilities/calculateCosts.js +56 -0
- package/dist/utilities/calculateCosts.js.map +1 -0
- package/dist/utilities/functional.utils.d.ts +1 -0
- package/dist/utilities/functional.utils.js +9 -0
- package/dist/utilities/functional.utils.js.map +1 -0
- package/dist/utilities/index.d.ts +9 -0
- package/dist/utilities/index.js +26 -0
- package/dist/utilities/index.js.map +1 -0
- package/dist/utilities/llmTracing/index.d.ts +3 -0
- package/dist/utilities/llmTracing/index.js +20 -0
- package/dist/utilities/llmTracing/index.js.map +1 -0
- package/dist/utilities/llmTracing/llmTracing.constants.d.ts +7 -0
- package/dist/utilities/llmTracing/llmTracing.constants.js +11 -0
- package/dist/utilities/llmTracing/llmTracing.constants.js.map +1 -0
- package/dist/utilities/llmTracing/llmTracing.typedefs.d.ts +126 -0
- package/dist/utilities/llmTracing/llmTracing.typedefs.js +3 -0
- package/dist/utilities/llmTracing/llmTracing.typedefs.js.map +1 -0
- package/dist/utilities/llmTracing/noopLLMTracing.d.ts +3 -0
- package/dist/utilities/llmTracing/noopLLMTracing.js +36 -0
- package/dist/utilities/llmTracing/noopLLMTracing.js.map +1 -0
- package/dist/utilities/logger/LLMLoggerInterface.d.ts +36 -0
- package/dist/utilities/logger/LLMLoggerInterface.js +3 -0
- package/dist/utilities/logger/LLMLoggerInterface.js.map +1 -0
- package/dist/utilities/logger/index.d.ts +1 -0
- package/dist/utilities/logger/index.js +18 -0
- package/dist/utilities/logger/index.js.map +1 -0
- package/dist/utilities/promptBuilder.d.ts +58 -0
- package/dist/utilities/promptBuilder.js +92 -0
- package/dist/utilities/promptBuilder.js.map +1 -0
- package/dist/utilities/reporter/LLMReporterInterface.d.ts +46 -0
- package/dist/utilities/reporter/LLMReporterInterface.js +3 -0
- package/dist/utilities/reporter/LLMReporterInterface.js.map +1 -0
- package/dist/utilities/reporter/index.d.ts +1 -0
- package/dist/utilities/reporter/index.js +18 -0
- package/dist/utilities/reporter/index.js.map +1 -0
- package/dist/utilities/schema/LLMSchema.d.ts +112 -0
- package/dist/utilities/schema/LLMSchema.js +223 -0
- package/dist/utilities/schema/LLMSchema.js.map +1 -0
- package/dist/utilities/schema/LLMSchema.typedefs.d.ts +55 -0
- package/dist/utilities/schema/LLMSchema.typedefs.js +3 -0
- package/dist/utilities/schema/LLMSchema.typedefs.js.map +1 -0
- package/dist/utilities/schema/SchemaAdapterRegistry.d.ts +26 -0
- package/dist/utilities/schema/SchemaAdapterRegistry.js +32 -0
- package/dist/utilities/schema/SchemaAdapterRegistry.js.map +1 -0
- package/dist/utilities/schema/index.d.ts +2 -0
- package/dist/utilities/schema/index.js +19 -0
- package/dist/utilities/schema/index.js.map +1 -0
- package/dist/utilities/serializeError.d.ts +9 -0
- package/dist/utilities/serializeError.js +69 -0
- package/dist/utilities/serializeError.js.map +1 -0
- package/dist/utilities/tokenizer.d.ts +4 -0
- package/dist/utilities/tokenizer.js +14 -0
- package/dist/utilities/tokenizer.js.map +1 -0
- package/dist/utilities/tools/LLMTool.d.ts +5 -0
- package/dist/utilities/tools/LLMTool.js +10 -0
- package/dist/utilities/tools/LLMTool.js.map +1 -0
- package/dist/utilities/tools/index.d.ts +2 -0
- package/dist/utilities/tools/index.js +8 -0
- package/dist/utilities/tools/index.js.map +1 -0
- package/dist/utilities/tools/normalizeToolResult.d.ts +15 -0
- package/dist/utilities/tools/normalizeToolResult.js +18 -0
- package/dist/utilities/tools/normalizeToolResult.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { LLMPurposes, LLMToolLoopStopReasons, type LLMCallTraceContext, type LLMProviders, type LLMTerminalToolOutcome, type LLMToolDefinition, type LLMToolResult } from '../LLMService.typedefs';
|
|
2
|
+
import { type LLMAssistanceService } from '../services';
|
|
3
|
+
import { type LLMLoggerInterface } from '../utilities/logger';
|
|
4
|
+
import { type LLMReporterInterface } from '../utilities/reporter';
|
|
5
|
+
import { type LLMSchemaInterface } from '../utilities/schema';
|
|
6
|
+
import { type LLMCapabilityRequirement, type LLMPromptBinding } from '../client/defineLLMPrompts';
|
|
7
|
+
import { type LLMVariableValue } from '../client/promptSnapshot.typedefs';
|
|
8
|
+
import { type ResolvedPrompt } from '../client/promptRegistry.runtime';
|
|
9
|
+
import { type LLMCallOverrides, type LLMClientCallContext, type LLMDelegationGate, type LLMPlainMessage, type LLMProviderServiceScope, type LLMToolResultContext, type LLMTraceContextScope } from '../client/llmClient.typedefs';
|
|
10
|
+
import { LLMAgent } from '../client/LLMAgent';
|
|
11
|
+
import { type LLMAgentEventListener, type LLMAgentRunResult } from '../client/agentRun.typedefs';
|
|
12
|
+
type AgentAssistanceService = LLMAssistanceService<LLMProviders, LLMReporterInterface<any> | undefined>;
|
|
13
|
+
type AgentSendResult = {
|
|
14
|
+
text: string;
|
|
15
|
+
data?: unknown;
|
|
16
|
+
parseError?: string;
|
|
17
|
+
stopReason?: LLMToolLoopStopReasons;
|
|
18
|
+
terminalTool?: LLMTerminalToolOutcome;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* How one prompt resolution should run: the model-map purpose, extra
|
|
22
|
+
* capability requirements beyond the binding's own, and per-call overrides.
|
|
23
|
+
*/
|
|
24
|
+
export interface LLMPromptResolutionCall {
|
|
25
|
+
purpose: LLMPurposes;
|
|
26
|
+
additionalRequires?: LLMCapabilityRequirement[];
|
|
27
|
+
overrides?: LLMCallOverrides;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The prompt-resolution and call-plumbing surface the agent runner borrows from
|
|
31
|
+
* the client engine, so both `generate` and `runAgent` share one gate, one
|
|
32
|
+
* credentials path, one context shape, and one error taxonomy.
|
|
33
|
+
*/
|
|
34
|
+
export interface LLMAgentCallServices {
|
|
35
|
+
resolvePrompt(promptName: string, binding: LLMPromptBinding, variables: Record<string, LLMVariableValue>, call: LLMPromptResolutionCall): Promise<ResolvedPrompt>;
|
|
36
|
+
buildAssistanceService(scope: LLMProviderServiceScope): Promise<AgentAssistanceService>;
|
|
37
|
+
buildReporterContext(resolved: ResolvedPrompt, callContext: LLMClientCallContext | undefined): unknown;
|
|
38
|
+
buildTraceContext(scope: LLMTraceContextScope): LLMCallTraceContext;
|
|
39
|
+
toTaxonomyError(error: unknown, resolved: ResolvedPrompt, abortSignal?: AbortSignal): Error;
|
|
40
|
+
unwrapResult(resolved: ResolvedPrompt, schema: LLMSchemaInterface | undefined, sendResult: AgentSendResult): unknown;
|
|
41
|
+
getBinding(promptName: string): LLMPromptBinding | undefined;
|
|
42
|
+
normalizeToolResult(context: LLMToolResultContext): LLMToolResult;
|
|
43
|
+
withAgentObservation<Result>(name: string, input: unknown, fn: () => Promise<Result>): Promise<Result>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A plain-object subagent with the registry generics erased: the engine
|
|
47
|
+
* narrows the typed definition at the `runAgent` boundary, the runner only
|
|
48
|
+
* needs the runtime shape.
|
|
49
|
+
*/
|
|
50
|
+
export interface LLMAgentSubagentSpec {
|
|
51
|
+
prompt: string;
|
|
52
|
+
name: string;
|
|
53
|
+
description: string;
|
|
54
|
+
variables?: Record<string, LLMVariableValue>;
|
|
55
|
+
tools?: LLMToolDefinition[];
|
|
56
|
+
inputSchema?: LLMSchemaInterface;
|
|
57
|
+
canExecute?: LLMDelegationGate;
|
|
58
|
+
maxToolIterations?: number;
|
|
59
|
+
}
|
|
60
|
+
type SubagentEntry = LLMAgentSubagentSpec | LLMAgent;
|
|
61
|
+
export interface LLMAgentRunInput {
|
|
62
|
+
agentName: string;
|
|
63
|
+
promptName: string;
|
|
64
|
+
binding: LLMPromptBinding;
|
|
65
|
+
variables: Record<string, LLMVariableValue>;
|
|
66
|
+
input: string;
|
|
67
|
+
history?: LLMPlainMessage[];
|
|
68
|
+
tools?: LLMToolDefinition[];
|
|
69
|
+
subagents?: SubagentEntry[];
|
|
70
|
+
maxToolIterations?: number;
|
|
71
|
+
context?: LLMClientCallContext;
|
|
72
|
+
/**
|
|
73
|
+
* The Langfuse session every generation of this run belongs to. Copied onto
|
|
74
|
+
* delegated subagent runs, so one anchor covers the whole run tree.
|
|
75
|
+
*/
|
|
76
|
+
sessionId?: string;
|
|
77
|
+
traceTags?: string[];
|
|
78
|
+
abortSignal?: AbortSignal;
|
|
79
|
+
overrides?: LLMCallOverrides;
|
|
80
|
+
onEvent?: LLMAgentEventListener;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Runs one agent: instructions resolved from the prompt registry (Langfuse is
|
|
84
|
+
* the source of the instructions text and the model routing), the provider
|
|
85
|
+
* assistance tool loop does the model⇄tool rounds, subagents join as tools,
|
|
86
|
+
* and every step emits an `LLMAgentEvent` for live progress and persistence.
|
|
87
|
+
* Langfuse observability needs no extra wiring here — the provider services
|
|
88
|
+
* already record generation and tool observations under the active trace.
|
|
89
|
+
*/
|
|
90
|
+
export declare class LLMAgentRunner {
|
|
91
|
+
private readonly services;
|
|
92
|
+
private readonly logger;
|
|
93
|
+
constructor(services: LLMAgentCallServices, logger: LLMLoggerInterface | undefined);
|
|
94
|
+
run(run: LLMAgentRunInput): Promise<LLMAgentRunResult<unknown>>;
|
|
95
|
+
private runAgentTree;
|
|
96
|
+
/**
|
|
97
|
+
* A terminal tool ends the turn without a model answer, so the bound schema
|
|
98
|
+
* is deliberately not applied — there is nothing to validate, and unwrapping
|
|
99
|
+
* would fail a legitimate outcome. Any other stop carries the model's answer
|
|
100
|
+
* and unwraps exactly like `generate`.
|
|
101
|
+
*/
|
|
102
|
+
private buildRunResult;
|
|
103
|
+
private executeRun;
|
|
104
|
+
private runInChat;
|
|
105
|
+
private assistInChat;
|
|
106
|
+
private buildTools;
|
|
107
|
+
private wrapToolWithEvents;
|
|
108
|
+
/**
|
|
109
|
+
* The lifecycle of one tool invocation. The completion event depends on what
|
|
110
|
+
* the invocation produced: a refused call reports `tool_call_denied` in place
|
|
111
|
+
* of `tool_call_completed`, so a listener never records a side effect that
|
|
112
|
+
* did not happen.
|
|
113
|
+
*/
|
|
114
|
+
private buildToolCallLifecycle;
|
|
115
|
+
private executeGatedTool;
|
|
116
|
+
private resolveToolGate;
|
|
117
|
+
/**
|
|
118
|
+
* What a refused call hands back to the model. It names the tool and the
|
|
119
|
+
* reason so the model can adapt instead of retrying the same call, and it
|
|
120
|
+
* never passes through the client's normalizer — a denial is the package's
|
|
121
|
+
* own control flow, not a tool's output.
|
|
122
|
+
*/
|
|
123
|
+
private buildDenial;
|
|
124
|
+
private buildSubagentTool;
|
|
125
|
+
private buildDelegationLifecycle;
|
|
126
|
+
private delegateToSubagent;
|
|
127
|
+
/**
|
|
128
|
+
* A typed delegation hands the whole argument object to the subagent as its
|
|
129
|
+
* request, since the parent model filled a schema rather than writing a
|
|
130
|
+
* task sentence. Without a schema the single `prompt` argument is the
|
|
131
|
+
* request, exactly as before.
|
|
132
|
+
*/
|
|
133
|
+
private buildDelegationInput;
|
|
134
|
+
/**
|
|
135
|
+
* Typed delegation arguments join the subagent's own variables (and win over
|
|
136
|
+
* them), so the delegated Langfuse prompt can reference what the parent model
|
|
137
|
+
* supplied as `{{argument}}` and the validation gate covers it like any other
|
|
138
|
+
* variable.
|
|
139
|
+
*/
|
|
140
|
+
private buildDelegationVariables;
|
|
141
|
+
/**
|
|
142
|
+
* Flattens a nested run back into the string its delegation tool returns to
|
|
143
|
+
* the parent model. A delegation tool is never itself terminal, so a
|
|
144
|
+
* subagent that stopped on its own terminal tool hands that tool's output
|
|
145
|
+
* back as the delegation result and the parent's loop continues.
|
|
146
|
+
*/
|
|
147
|
+
private stringifySubagentOutcome;
|
|
148
|
+
private normalizeSubagent;
|
|
149
|
+
private withLifecycleEvents;
|
|
150
|
+
/**
|
|
151
|
+
* Emit an `agent_message` for visible assistant text the model produced
|
|
152
|
+
* between tool rounds. Attributed to the emitting run via `agent`/`runId`,
|
|
153
|
+
* so a subagent's narration carries the subagent's identity. Empty or
|
|
154
|
+
* whitespace-only text is skipped — an `agent_message` always carries real
|
|
155
|
+
* narration.
|
|
156
|
+
*/
|
|
157
|
+
private emitAgentMessage;
|
|
158
|
+
private emit;
|
|
159
|
+
private warnListenerFailure;
|
|
160
|
+
}
|
|
161
|
+
export {};
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LLMAgentRunner = void 0;
|
|
4
|
+
const LLMService_typedefs_1 = require("../LLMService.typedefs");
|
|
5
|
+
const serializeError_1 = require("../utilities/serializeError");
|
|
6
|
+
const schema_1 = require("../utilities/schema");
|
|
7
|
+
const tools_1 = require("../utilities/tools");
|
|
8
|
+
const plainMessages_1 = require("../client/plainMessages");
|
|
9
|
+
const promptVariables_1 = require("../client/promptVariables");
|
|
10
|
+
const LLMAgent_1 = require("../client/LLMAgent");
|
|
11
|
+
const agentRun_typedefs_1 = require("../client/agentRun.typedefs");
|
|
12
|
+
const errors_1 = require("../client/errors");
|
|
13
|
+
const TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
14
|
+
/**
|
|
15
|
+
* The delegation-tool parameters a subagent gets when it declares no
|
|
16
|
+
* `inputSchema`: one free-form task string, which also becomes the nested
|
|
17
|
+
* run's input.
|
|
18
|
+
*/
|
|
19
|
+
const DELEGATION_PROMPT_SCHEMA = schema_1.LLMSchema.object({
|
|
20
|
+
prompt: schema_1.LLMSchema.string().describe('The task or question to delegate to this agent'),
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Allocates the `runId`/`invocationId` values that correlate events within one
|
|
24
|
+
* root run. One sequence spans the whole run tree so every id is unique across
|
|
25
|
+
* the root agent, its subagents, and all tool invocations.
|
|
26
|
+
*/
|
|
27
|
+
class AgentRunIdSequence {
|
|
28
|
+
currentId = 0;
|
|
29
|
+
next() {
|
|
30
|
+
this.currentId += 1;
|
|
31
|
+
return this.currentId;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function toErrorMessage(error) {
|
|
35
|
+
return error instanceof Error ? error.message : String(error);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Runs one agent: instructions resolved from the prompt registry (Langfuse is
|
|
39
|
+
* the source of the instructions text and the model routing), the provider
|
|
40
|
+
* assistance tool loop does the model⇄tool rounds, subagents join as tools,
|
|
41
|
+
* and every step emits an `LLMAgentEvent` for live progress and persistence.
|
|
42
|
+
* Langfuse observability needs no extra wiring here — the provider services
|
|
43
|
+
* already record generation and tool observations under the active trace.
|
|
44
|
+
*/
|
|
45
|
+
class LLMAgentRunner {
|
|
46
|
+
services;
|
|
47
|
+
logger;
|
|
48
|
+
constructor(services, logger) {
|
|
49
|
+
this.services = services;
|
|
50
|
+
this.logger = logger?.child('LLMAgentRunner');
|
|
51
|
+
}
|
|
52
|
+
async run(run) {
|
|
53
|
+
const sequence = new AgentRunIdSequence();
|
|
54
|
+
return this.runAgentTree(run, sequence, sequence.next());
|
|
55
|
+
}
|
|
56
|
+
async runAgentTree(run, sequence, runId) {
|
|
57
|
+
return this.services.withAgentObservation(run.agentName, run.input, async () => {
|
|
58
|
+
const completedRun = await this.withLifecycleEvents(run.onEvent, {
|
|
59
|
+
started: {
|
|
60
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.AgentStarted,
|
|
61
|
+
agent: run.agentName,
|
|
62
|
+
runId,
|
|
63
|
+
input: run.input,
|
|
64
|
+
},
|
|
65
|
+
completed: (workResult, durationMs) => ({
|
|
66
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.AgentCompleted,
|
|
67
|
+
agent: run.agentName,
|
|
68
|
+
runId,
|
|
69
|
+
output: workResult.text,
|
|
70
|
+
durationMs,
|
|
71
|
+
}),
|
|
72
|
+
failed: (errorMessage, durationMs) => ({
|
|
73
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.AgentFailed,
|
|
74
|
+
agent: run.agentName,
|
|
75
|
+
runId,
|
|
76
|
+
error: errorMessage,
|
|
77
|
+
durationMs,
|
|
78
|
+
}),
|
|
79
|
+
}, async () => {
|
|
80
|
+
const { resolved, sendResult } = await this.executeRun(run, sequence, runId);
|
|
81
|
+
return {
|
|
82
|
+
text: sendResult.text,
|
|
83
|
+
result: this.buildRunResult(run, resolved, sendResult),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
return completedRun.result;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A terminal tool ends the turn without a model answer, so the bound schema
|
|
91
|
+
* is deliberately not applied — there is nothing to validate, and unwrapping
|
|
92
|
+
* would fail a legitimate outcome. Any other stop carries the model's answer
|
|
93
|
+
* and unwraps exactly like `generate`.
|
|
94
|
+
*/
|
|
95
|
+
buildRunResult(run, resolved, sendResult) {
|
|
96
|
+
if (sendResult.terminalTool) {
|
|
97
|
+
return {
|
|
98
|
+
stopReason: LLMService_typedefs_1.LLMToolLoopStopReasons.TerminalTool,
|
|
99
|
+
terminalTool: sendResult.terminalTool,
|
|
100
|
+
text: sendResult.text,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
stopReason: sendResult.stopReason === LLMService_typedefs_1.LLMToolLoopStopReasons.MaxIterations
|
|
105
|
+
? LLMService_typedefs_1.LLMToolLoopStopReasons.MaxIterations
|
|
106
|
+
: LLMService_typedefs_1.LLMToolLoopStopReasons.Completed,
|
|
107
|
+
output: this.services.unwrapResult(resolved, run.binding.schema, sendResult),
|
|
108
|
+
text: sendResult.text,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async executeRun(run, sequence, runId) {
|
|
112
|
+
const tools = this.buildTools(run, sequence, runId);
|
|
113
|
+
const resolved = await this.services.resolvePrompt(run.promptName, run.binding, run.variables, {
|
|
114
|
+
purpose: LLMService_typedefs_1.LLMPurposes.Assistance,
|
|
115
|
+
additionalRequires: tools.length > 0 ? ['tools'] : [],
|
|
116
|
+
overrides: run.overrides,
|
|
117
|
+
});
|
|
118
|
+
const service = await this.services.buildAssistanceService({
|
|
119
|
+
resolved,
|
|
120
|
+
callContext: run.context,
|
|
121
|
+
});
|
|
122
|
+
const sendResult = await this.runInChat(service, resolved, run, tools, runId);
|
|
123
|
+
return { resolved, sendResult };
|
|
124
|
+
}
|
|
125
|
+
async runInChat(service, resolved, run, tools, runId) {
|
|
126
|
+
const reporterContext = this.services.buildReporterContext(resolved, run.context);
|
|
127
|
+
const traceContext = this.services.buildTraceContext({
|
|
128
|
+
resolved,
|
|
129
|
+
callContext: run.context,
|
|
130
|
+
sessionId: run.sessionId,
|
|
131
|
+
traceTags: run.traceTags,
|
|
132
|
+
});
|
|
133
|
+
const chatOptions = {
|
|
134
|
+
model: resolved.model,
|
|
135
|
+
instructions: resolved.text,
|
|
136
|
+
history: run.history?.length
|
|
137
|
+
? (0, plainMessages_1.plainMessagesToContentMessages)(run.history)
|
|
138
|
+
: undefined,
|
|
139
|
+
abortSignal: run.abortSignal,
|
|
140
|
+
reporterContext,
|
|
141
|
+
traceContext,
|
|
142
|
+
};
|
|
143
|
+
const chatResult = await service.createChat(chatOptions);
|
|
144
|
+
if ('error' in chatResult) {
|
|
145
|
+
throw this.services.toTaxonomyError(chatResult.error, resolved, run.abortSignal);
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
return await this.assistInChat(service, resolved, run, {
|
|
149
|
+
chatId: chatResult.chatId,
|
|
150
|
+
tools,
|
|
151
|
+
reporterContext,
|
|
152
|
+
traceContext,
|
|
153
|
+
runId,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
await service.deleteChat(chatResult.chatId).catch((deleteError) => {
|
|
158
|
+
this.logger?.warn('Failed to delete agent chat', {
|
|
159
|
+
agent: run.agentName,
|
|
160
|
+
chatId: chatResult.chatId,
|
|
161
|
+
error: (0, serializeError_1.serializeError)(deleteError),
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async assistInChat(service, resolved, run, session) {
|
|
167
|
+
const assistOptions = {
|
|
168
|
+
chatId: session.chatId,
|
|
169
|
+
model: resolved.model,
|
|
170
|
+
message: {
|
|
171
|
+
role: LLMService_typedefs_1.LLMRoles.User,
|
|
172
|
+
content: [{
|
|
173
|
+
type: LLMService_typedefs_1.LLMMessageContentType.TEXT,
|
|
174
|
+
text: run.input,
|
|
175
|
+
}],
|
|
176
|
+
},
|
|
177
|
+
...(session.tools.length > 0 && { tools: session.tools }),
|
|
178
|
+
...(run.maxToolIterations !== undefined && {
|
|
179
|
+
maxToolIterations: run.maxToolIterations,
|
|
180
|
+
}),
|
|
181
|
+
...(run.binding.schema && { schema: run.binding.schema }),
|
|
182
|
+
abortSignal: run.abortSignal,
|
|
183
|
+
reporterContext: session.reporterContext,
|
|
184
|
+
traceContext: session.traceContext,
|
|
185
|
+
onAssistantNarration: run.onEvent
|
|
186
|
+
? (text) => {
|
|
187
|
+
this.emitAgentMessage(run, session.runId, text);
|
|
188
|
+
}
|
|
189
|
+
: undefined,
|
|
190
|
+
};
|
|
191
|
+
try {
|
|
192
|
+
const sendResult = await service.assistInChat(assistOptions);
|
|
193
|
+
if ('error' in sendResult) {
|
|
194
|
+
throw sendResult.error;
|
|
195
|
+
}
|
|
196
|
+
return sendResult;
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
throw this.services.toTaxonomyError(error, resolved, run.abortSignal);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
buildTools(run, sequence, runId) {
|
|
203
|
+
const explicitTools = (run.tools ?? []).map((tool) => this.wrapToolWithEvents(tool, run, sequence, runId));
|
|
204
|
+
const subagentTools = (run.subagents ?? []).map((subagent) => this.buildSubagentTool(subagent, run, sequence, runId));
|
|
205
|
+
return [...explicitTools, ...subagentTools];
|
|
206
|
+
}
|
|
207
|
+
wrapToolWithEvents(tool, run, sequence, runId) {
|
|
208
|
+
return {
|
|
209
|
+
...tool,
|
|
210
|
+
execute: async (toolInput) => {
|
|
211
|
+
const invocationId = sequence.next();
|
|
212
|
+
const outcome = await this.withLifecycleEvents(run.onEvent, this.buildToolCallLifecycle({
|
|
213
|
+
toolName: tool.name,
|
|
214
|
+
input: toolInput,
|
|
215
|
+
run,
|
|
216
|
+
runId,
|
|
217
|
+
invocationId,
|
|
218
|
+
}), async () => this.executeGatedTool({
|
|
219
|
+
tool,
|
|
220
|
+
args: toolInput,
|
|
221
|
+
agentName: run.agentName,
|
|
222
|
+
}));
|
|
223
|
+
return outcome.result;
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The lifecycle of one tool invocation. The completion event depends on what
|
|
229
|
+
* the invocation produced: a refused call reports `tool_call_denied` in place
|
|
230
|
+
* of `tool_call_completed`, so a listener never records a side effect that
|
|
231
|
+
* did not happen.
|
|
232
|
+
*/
|
|
233
|
+
buildToolCallLifecycle(invocation) {
|
|
234
|
+
const correlation = {
|
|
235
|
+
agent: invocation.run.agentName,
|
|
236
|
+
runId: invocation.runId,
|
|
237
|
+
tool: invocation.toolName,
|
|
238
|
+
invocationId: invocation.invocationId,
|
|
239
|
+
};
|
|
240
|
+
return {
|
|
241
|
+
started: {
|
|
242
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.ToolCallStarted,
|
|
243
|
+
...correlation,
|
|
244
|
+
input: invocation.input,
|
|
245
|
+
},
|
|
246
|
+
completed: (outcome, durationMs) => (outcome.denialReason === undefined
|
|
247
|
+
? {
|
|
248
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.ToolCallCompleted,
|
|
249
|
+
...correlation,
|
|
250
|
+
output: outcome.result,
|
|
251
|
+
durationMs,
|
|
252
|
+
}
|
|
253
|
+
: {
|
|
254
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.ToolCallDenied,
|
|
255
|
+
...correlation,
|
|
256
|
+
reason: outcome.denialReason,
|
|
257
|
+
}),
|
|
258
|
+
failed: (errorMessage, durationMs) => ({
|
|
259
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.ToolCallFailed,
|
|
260
|
+
...correlation,
|
|
261
|
+
error: errorMessage,
|
|
262
|
+
durationMs,
|
|
263
|
+
}),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
async executeGatedTool(execution) {
|
|
267
|
+
const gate = await this.resolveToolGate(execution.tool.canExecute, execution.args);
|
|
268
|
+
if (!gate.allowed) {
|
|
269
|
+
return this.buildDenial(execution.tool.name, gate.reason);
|
|
270
|
+
}
|
|
271
|
+
const rawResult = await execution.tool.execute(execution.args);
|
|
272
|
+
return {
|
|
273
|
+
result: this.services.normalizeToolResult({
|
|
274
|
+
tool: execution.tool.name,
|
|
275
|
+
agent: execution.agentName,
|
|
276
|
+
input: execution.args,
|
|
277
|
+
result: rawResult,
|
|
278
|
+
}),
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
async resolveToolGate(gate, args) {
|
|
282
|
+
if (!gate) {
|
|
283
|
+
return { allowed: true };
|
|
284
|
+
}
|
|
285
|
+
return gate(args);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* What a refused call hands back to the model. It names the tool and the
|
|
289
|
+
* reason so the model can adapt instead of retrying the same call, and it
|
|
290
|
+
* never passes through the client's normalizer — a denial is the package's
|
|
291
|
+
* own control flow, not a tool's output.
|
|
292
|
+
*/
|
|
293
|
+
buildDenial(toolName, reason) {
|
|
294
|
+
return {
|
|
295
|
+
result: `The "${toolName}" call was not executed. Reason: ${reason}`,
|
|
296
|
+
denialReason: reason,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
buildSubagentTool(subagentEntry, run, sequence, runId) {
|
|
300
|
+
const subagent = this.normalizeSubagent(subagentEntry);
|
|
301
|
+
const binding = this.services.getBinding(subagent.prompt);
|
|
302
|
+
if (!binding) {
|
|
303
|
+
throw new errors_1.LLMConfigError(`subagent "${subagent.name}" references prompt "${subagent.prompt}"`
|
|
304
|
+
+ ' that is not in the registry', { promptName: subagent.prompt });
|
|
305
|
+
}
|
|
306
|
+
if (!TOOL_NAME_PATTERN.test(subagent.name)) {
|
|
307
|
+
throw new errors_1.LLMConfigError(`subagent name "${subagent.name}" cannot be used as a tool name:`
|
|
308
|
+
+ ' it must match [a-zA-Z0-9_-]+', { promptName: subagent.prompt });
|
|
309
|
+
}
|
|
310
|
+
return tools_1.LLMTool.create({
|
|
311
|
+
name: subagent.name,
|
|
312
|
+
description: subagent.description,
|
|
313
|
+
parameters: subagent.inputSchema ?? DELEGATION_PROMPT_SCHEMA,
|
|
314
|
+
execute: async (args) => {
|
|
315
|
+
const invocationId = sequence.next();
|
|
316
|
+
const subagentRunId = sequence.next();
|
|
317
|
+
const input = this.buildDelegationInput(subagent, args);
|
|
318
|
+
const outcome = await this.withLifecycleEvents(run.onEvent, this.buildDelegationLifecycle({
|
|
319
|
+
subagentName: subagent.name,
|
|
320
|
+
input,
|
|
321
|
+
run,
|
|
322
|
+
runId,
|
|
323
|
+
invocationId,
|
|
324
|
+
subagentRunId,
|
|
325
|
+
}), async () => this.delegateToSubagent({
|
|
326
|
+
subagent,
|
|
327
|
+
binding,
|
|
328
|
+
args,
|
|
329
|
+
input,
|
|
330
|
+
run,
|
|
331
|
+
sequence,
|
|
332
|
+
subagentRunId,
|
|
333
|
+
}));
|
|
334
|
+
return outcome.result;
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
buildDelegationLifecycle(delegation) {
|
|
339
|
+
const correlation = {
|
|
340
|
+
agent: delegation.run.agentName,
|
|
341
|
+
runId: delegation.runId,
|
|
342
|
+
subagent: delegation.subagentName,
|
|
343
|
+
invocationId: delegation.invocationId,
|
|
344
|
+
subagentRunId: delegation.subagentRunId,
|
|
345
|
+
};
|
|
346
|
+
return {
|
|
347
|
+
started: {
|
|
348
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.SubagentStarted,
|
|
349
|
+
...correlation,
|
|
350
|
+
input: delegation.input,
|
|
351
|
+
},
|
|
352
|
+
completed: (outcome, durationMs) => (outcome.denialReason === undefined
|
|
353
|
+
? {
|
|
354
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.SubagentCompleted,
|
|
355
|
+
...correlation,
|
|
356
|
+
output: outcome.result,
|
|
357
|
+
durationMs,
|
|
358
|
+
}
|
|
359
|
+
: {
|
|
360
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.ToolCallDenied,
|
|
361
|
+
agent: delegation.run.agentName,
|
|
362
|
+
runId: delegation.runId,
|
|
363
|
+
tool: delegation.subagentName,
|
|
364
|
+
invocationId: delegation.invocationId,
|
|
365
|
+
reason: outcome.denialReason,
|
|
366
|
+
}),
|
|
367
|
+
failed: (errorMessage, durationMs) => ({
|
|
368
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.SubagentFailed,
|
|
369
|
+
...correlation,
|
|
370
|
+
error: errorMessage,
|
|
371
|
+
durationMs,
|
|
372
|
+
}),
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
async delegateToSubagent(delegation) {
|
|
376
|
+
const { subagent, args, run } = delegation;
|
|
377
|
+
const gate = await this.resolveToolGate(subagent.canExecute, args);
|
|
378
|
+
if (!gate.allowed) {
|
|
379
|
+
return this.buildDenial(subagent.name, gate.reason);
|
|
380
|
+
}
|
|
381
|
+
const subagentResult = await this.runAgentTree({
|
|
382
|
+
agentName: subagent.name,
|
|
383
|
+
promptName: subagent.prompt,
|
|
384
|
+
binding: delegation.binding,
|
|
385
|
+
variables: this.buildDelegationVariables(subagent, args),
|
|
386
|
+
input: delegation.input,
|
|
387
|
+
tools: subagent.tools,
|
|
388
|
+
subagents: subagent.subagents,
|
|
389
|
+
maxToolIterations: subagent.maxToolIterations,
|
|
390
|
+
context: run.context,
|
|
391
|
+
sessionId: run.sessionId,
|
|
392
|
+
traceTags: run.traceTags,
|
|
393
|
+
abortSignal: run.abortSignal,
|
|
394
|
+
overrides: run.overrides,
|
|
395
|
+
onEvent: run.onEvent,
|
|
396
|
+
}, delegation.sequence, delegation.subagentRunId);
|
|
397
|
+
return {
|
|
398
|
+
result: this.services.normalizeToolResult({
|
|
399
|
+
tool: subagent.name,
|
|
400
|
+
agent: run.agentName,
|
|
401
|
+
input: args,
|
|
402
|
+
result: this.stringifySubagentOutcome(subagentResult),
|
|
403
|
+
}),
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* A typed delegation hands the whole argument object to the subagent as its
|
|
408
|
+
* request, since the parent model filled a schema rather than writing a
|
|
409
|
+
* task sentence. Without a schema the single `prompt` argument is the
|
|
410
|
+
* request, exactly as before.
|
|
411
|
+
*/
|
|
412
|
+
buildDelegationInput(subagent, args) {
|
|
413
|
+
if (!subagent.inputSchema) {
|
|
414
|
+
return String(args.prompt ?? '');
|
|
415
|
+
}
|
|
416
|
+
return JSON.stringify(args);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Typed delegation arguments join the subagent's own variables (and win over
|
|
420
|
+
* them), so the delegated Langfuse prompt can reference what the parent model
|
|
421
|
+
* supplied as `{{argument}}` and the validation gate covers it like any other
|
|
422
|
+
* variable.
|
|
423
|
+
*/
|
|
424
|
+
buildDelegationVariables(subagent, args) {
|
|
425
|
+
if (!subagent.inputSchema) {
|
|
426
|
+
return subagent.variables;
|
|
427
|
+
}
|
|
428
|
+
return { ...subagent.variables, ...(0, promptVariables_1.stringifyPromptVariables)(args) };
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Flattens a nested run back into the string its delegation tool returns to
|
|
432
|
+
* the parent model. A delegation tool is never itself terminal, so a
|
|
433
|
+
* subagent that stopped on its own terminal tool hands that tool's output
|
|
434
|
+
* back as the delegation result and the parent's loop continues.
|
|
435
|
+
*/
|
|
436
|
+
stringifySubagentOutcome(subagentResult) {
|
|
437
|
+
const outcome = subagentResult.terminalTool
|
|
438
|
+
? subagentResult.terminalTool.output
|
|
439
|
+
: subagentResult.output;
|
|
440
|
+
return typeof outcome === 'string'
|
|
441
|
+
? outcome
|
|
442
|
+
: JSON.stringify(outcome);
|
|
443
|
+
}
|
|
444
|
+
normalizeSubagent(subagentEntry) {
|
|
445
|
+
if (!(subagentEntry instanceof LLMAgent_1.LLMAgent)) {
|
|
446
|
+
return { ...subagentEntry, variables: subagentEntry.variables ?? {} };
|
|
447
|
+
}
|
|
448
|
+
const promptName = String(subagentEntry.prompt);
|
|
449
|
+
if (!subagentEntry.name || !subagentEntry.description) {
|
|
450
|
+
throw new errors_1.LLMConfigError(`agent for prompt "${promptName}" needs both "name" and "description"`
|
|
451
|
+
+ ' to be used as a subagent', { promptName });
|
|
452
|
+
}
|
|
453
|
+
return {
|
|
454
|
+
prompt: promptName,
|
|
455
|
+
name: subagentEntry.name,
|
|
456
|
+
description: subagentEntry.description,
|
|
457
|
+
variables: subagentEntry.variables ?? {},
|
|
458
|
+
tools: subagentEntry.tools,
|
|
459
|
+
subagents: subagentEntry.subagents,
|
|
460
|
+
inputSchema: subagentEntry.inputSchema,
|
|
461
|
+
canExecute: subagentEntry.canExecute,
|
|
462
|
+
maxToolIterations: subagentEntry.maxToolIterations,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
async withLifecycleEvents(listener, lifecycle, work) {
|
|
466
|
+
const startedAt = Date.now();
|
|
467
|
+
this.emit(listener, lifecycle.started);
|
|
468
|
+
try {
|
|
469
|
+
const workResult = await work();
|
|
470
|
+
this.emit(listener, lifecycle.completed(workResult, Date.now() - startedAt));
|
|
471
|
+
return workResult;
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
this.emit(listener, lifecycle.failed(toErrorMessage(error), Date.now() - startedAt));
|
|
475
|
+
throw error;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Emit an `agent_message` for visible assistant text the model produced
|
|
480
|
+
* between tool rounds. Attributed to the emitting run via `agent`/`runId`,
|
|
481
|
+
* so a subagent's narration carries the subagent's identity. Empty or
|
|
482
|
+
* whitespace-only text is skipped — an `agent_message` always carries real
|
|
483
|
+
* narration.
|
|
484
|
+
*/
|
|
485
|
+
emitAgentMessage(run, runId, text) {
|
|
486
|
+
if (text.trim().length === 0) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
this.emit(run.onEvent, {
|
|
490
|
+
type: agentRun_typedefs_1.LLMAgentEventTypes.AgentMessage,
|
|
491
|
+
agent: run.agentName,
|
|
492
|
+
runId,
|
|
493
|
+
text,
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
emit(listener, event) {
|
|
497
|
+
if (!listener) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
try {
|
|
501
|
+
void Promise.resolve(listener(event)).catch((listenerError) => {
|
|
502
|
+
this.warnListenerFailure(event, listenerError);
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
catch (listenerError) {
|
|
506
|
+
this.warnListenerFailure(event, listenerError);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
warnListenerFailure(event, error) {
|
|
510
|
+
this.logger?.warn('Agent event listener failed', {
|
|
511
|
+
eventType: event.type,
|
|
512
|
+
error: toErrorMessage(error),
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
exports.LLMAgentRunner = LLMAgentRunner;
|
|
517
|
+
//# sourceMappingURL=agentRunner.js.map
|