@mate-academy/llm-gateway 8.8.0 → 8.8.2
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 +8 -4
- package/package.json +1 -1
- package/dist/LLMError.d.ts +0 -12
- package/dist/LLMError.js +0 -36
- package/dist/LLMError.js.map +0 -1
- package/dist/LLMGateway.d.ts +0 -30
- package/dist/LLMGateway.js +0 -56
- package/dist/LLMGateway.js.map +0 -1
- package/dist/LLMGateway.typedefs.d.ts +0 -5
- package/dist/LLMGateway.typedefs.js +0 -3
- package/dist/LLMGateway.typedefs.js.map +0 -1
- package/dist/LLMService.constants.d.ts +0 -26309
- package/dist/LLMService.constants.js +0 -35
- package/dist/LLMService.constants.js.map +0 -1
- package/dist/LLMService.factory.d.ts +0 -71
- package/dist/LLMService.factory.js +0 -102
- package/dist/LLMService.factory.js.map +0 -1
- package/dist/LLMService.typedefs.d.ts +0 -653
- package/dist/LLMService.typedefs.js +0 -72
- package/dist/LLMService.typedefs.js.map +0 -1
- package/dist/advanced.d.ts +0 -11
- package/dist/advanced.js +0 -32
- package/dist/advanced.js.map +0 -1
- package/dist/client/LLMAgent.d.ts +0 -76
- package/dist/client/LLMAgent.js +0 -36
- package/dist/client/LLMAgent.js.map +0 -1
- package/dist/client/LLMClientEngine.d.ts +0 -110
- package/dist/client/LLMClientEngine.js +0 -406
- package/dist/client/LLMClientEngine.js.map +0 -1
- package/dist/client/agentRun.typedefs.d.ts +0 -200
- package/dist/client/agentRun.typedefs.js +0 -25
- package/dist/client/agentRun.typedefs.js.map +0 -1
- package/dist/client/agentRunner.d.ts +0 -161
- package/dist/client/agentRunner.js +0 -517
- package/dist/client/agentRunner.js.map +0 -1
- package/dist/client/codegen/fetchPromptRecords.d.ts +0 -14
- package/dist/client/codegen/fetchPromptRecords.js +0 -90
- package/dist/client/codegen/fetchPromptRecords.js.map +0 -1
- package/dist/client/codegen/generateSnapshot.d.ts +0 -19
- package/dist/client/codegen/generateSnapshot.js +0 -28
- package/dist/client/codegen/generateSnapshot.js.map +0 -1
- package/dist/client/codegen/index.d.ts +0 -6
- package/dist/client/codegen/index.js +0 -23
- package/dist/client/codegen/index.js.map +0 -1
- package/dist/client/codegen/promptCatalog.typedefs.d.ts +0 -51
- package/dist/client/codegen/promptCatalog.typedefs.js +0 -3
- package/dist/client/codegen/promptCatalog.typedefs.js.map +0 -1
- package/dist/client/codegen/promptName.d.ts +0 -8
- package/dist/client/codegen/promptName.js +0 -21
- package/dist/client/codegen/promptName.js.map +0 -1
- package/dist/client/codegen/renderSnapshot.constants.d.ts +0 -7
- package/dist/client/codegen/renderSnapshot.constants.js +0 -16
- package/dist/client/codegen/renderSnapshot.constants.js.map +0 -1
- package/dist/client/codegen/renderSnapshot.d.ts +0 -9
- package/dist/client/codegen/renderSnapshot.js +0 -109
- package/dist/client/codegen/renderSnapshot.js.map +0 -1
- package/dist/client/codegen/renderSnapshot.typedefs.d.ts +0 -19
- package/dist/client/codegen/renderSnapshot.typedefs.js +0 -3
- package/dist/client/codegen/renderSnapshot.typedefs.js.map +0 -1
- package/dist/client/coerceToolResult.d.ts +0 -10
- package/dist/client/coerceToolResult.js +0 -38
- package/dist/client/coerceToolResult.js.map +0 -1
- package/dist/client/createLLMClient.d.ts +0 -10
- package/dist/client/createLLMClient.js +0 -47
- package/dist/client/createLLMClient.js.map +0 -1
- package/dist/client/defineLLMPrompts.d.ts +0 -34
- package/dist/client/defineLLMPrompts.js +0 -13
- package/dist/client/defineLLMPrompts.js.map +0 -1
- package/dist/client/errors.d.ts +0 -57
- package/dist/client/errors.js +0 -70
- package/dist/client/errors.js.map +0 -1
- package/dist/client/index.d.ts +0 -13
- package/dist/client/index.js +0 -30
- package/dist/client/index.js.map +0 -1
- package/dist/client/llmClient.typedefs.d.ts +0 -265
- package/dist/client/llmClient.typedefs.js +0 -11
- package/dist/client/llmClient.typedefs.js.map +0 -1
- package/dist/client/llmConfig.schema.d.ts +0 -53
- package/dist/client/llmConfig.schema.js +0 -49
- package/dist/client/llmConfig.schema.js.map +0 -1
- package/dist/client/plainMessages.d.ts +0 -12
- package/dist/client/plainMessages.js +0 -19
- package/dist/client/plainMessages.js.map +0 -1
- package/dist/client/promptClientPort.typedefs.d.ts +0 -60
- package/dist/client/promptClientPort.typedefs.js +0 -3
- package/dist/client/promptClientPort.typedefs.js.map +0 -1
- package/dist/client/promptRegistry.runtime.d.ts +0 -121
- package/dist/client/promptRegistry.runtime.js +0 -264
- package/dist/client/promptRegistry.runtime.js.map +0 -1
- package/dist/client/promptSnapshot.typedefs.d.ts +0 -55
- package/dist/client/promptSnapshot.typedefs.js +0 -3
- package/dist/client/promptSnapshot.typedefs.js.map +0 -1
- package/dist/client/promptVariables.d.ts +0 -7
- package/dist/client/promptVariables.js +0 -13
- package/dist/client/promptVariables.js.map +0 -1
- package/dist/client/snapshotRuntime.d.ts +0 -17
- package/dist/client/snapshotRuntime.js +0 -42
- package/dist/client/snapshotRuntime.js.map +0 -1
- package/dist/client/snapshotRuntime.typedefs.d.ts +0 -13
- package/dist/client/snapshotRuntime.typedefs.js +0 -3
- package/dist/client/snapshotRuntime.typedefs.js.map +0 -1
- package/dist/client/validationGate.d.ts +0 -24
- package/dist/client/validationGate.js +0 -54
- package/dist/client/validationGate.js.map +0 -1
- package/dist/codegen.d.ts +0 -6
- package/dist/codegen.js +0 -23
- package/dist/codegen.js.map +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -27
- package/dist/index.js.map +0 -1
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.constants.d.ts +0 -873
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.constants.js +0 -269
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.constants.js.map +0 -1
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.entity.d.ts +0 -24
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.entity.js +0 -210
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.entity.js.map +0 -1
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.d.ts +0 -22
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.js +0 -20
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.js.map +0 -1
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAIService.factory.d.ts +0 -6
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAIService.factory.js +0 -18
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAIService.factory.js.map +0 -1
- package/dist/providers/GoogleGenerativeAI/index.d.ts +0 -5
- package/dist/providers/GoogleGenerativeAI/index.js +0 -22
- package/dist/providers/GoogleGenerativeAI/index.js.map +0 -1
- package/dist/providers/GoogleGenerativeAI/schemas/GoogleSchemaAdapter.d.ts +0 -12
- package/dist/providers/GoogleGenerativeAI/schemas/GoogleSchemaAdapter.js +0 -72
- package/dist/providers/GoogleGenerativeAI/schemas/GoogleSchemaAdapter.js.map +0 -1
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.d.ts +0 -71
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js +0 -876
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js.map +0 -1
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.d.ts +0 -25
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js +0 -216
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js.map +0 -1
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.d.ts +0 -10
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js +0 -136
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js.map +0 -1
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAITextToSpeech.service.d.ts +0 -11
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAITextToSpeech.service.js +0 -97
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAITextToSpeech.service.js.map +0 -1
- package/dist/providers/GoogleGenerativeAI/services/index.d.ts +0 -4
- package/dist/providers/GoogleGenerativeAI/services/index.js +0 -21
- package/dist/providers/GoogleGenerativeAI/services/index.js.map +0 -1
- package/dist/providers/LLMAPI/LLMAPI.constants.d.ts +0 -35832
- package/dist/providers/LLMAPI/LLMAPI.constants.js +0 -8601
- package/dist/providers/LLMAPI/LLMAPI.constants.js.map +0 -1
- package/dist/providers/LLMAPI/LLMAPI.entity.d.ts +0 -6
- package/dist/providers/LLMAPI/LLMAPI.entity.js +0 -48
- package/dist/providers/LLMAPI/LLMAPI.entity.js.map +0 -1
- package/dist/providers/LLMAPI/LLMAPI.typedefs.d.ts +0 -516
- package/dist/providers/LLMAPI/LLMAPI.typedefs.js +0 -564
- package/dist/providers/LLMAPI/LLMAPI.typedefs.js.map +0 -1
- package/dist/providers/LLMAPI/LLMAPI.voices.d.ts +0 -376
- package/dist/providers/LLMAPI/LLMAPI.voices.js +0 -739
- package/dist/providers/LLMAPI/LLMAPI.voices.js.map +0 -1
- package/dist/providers/LLMAPI/LLMAPIService.factory.d.ts +0 -6
- package/dist/providers/LLMAPI/LLMAPIService.factory.js +0 -19
- package/dist/providers/LLMAPI/LLMAPIService.factory.js.map +0 -1
- package/dist/providers/LLMAPI/index.d.ts +0 -7
- package/dist/providers/LLMAPI/index.js +0 -24
- package/dist/providers/LLMAPI/index.js.map +0 -1
- package/dist/providers/LLMAPI/schemas/LLMAPISchemaAdapter.d.ts +0 -3
- package/dist/providers/LLMAPI/schemas/LLMAPISchemaAdapter.js +0 -8
- package/dist/providers/LLMAPI/schemas/LLMAPISchemaAdapter.js.map +0 -1
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.d.ts +0 -76
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js +0 -825
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js.map +0 -1
- package/dist/providers/LLMAPI/services/LLMAPICompletion.service.d.ts +0 -25
- package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js +0 -177
- package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js.map +0 -1
- package/dist/providers/LLMAPI/services/LLMAPISpeechToText.service.d.ts +0 -17
- package/dist/providers/LLMAPI/services/LLMAPISpeechToText.service.js +0 -34
- package/dist/providers/LLMAPI/services/LLMAPISpeechToText.service.js.map +0 -1
- package/dist/providers/LLMAPI/services/LLMAPITextToSpeech.service.d.ts +0 -20
- package/dist/providers/LLMAPI/services/LLMAPITextToSpeech.service.js +0 -36
- package/dist/providers/LLMAPI/services/LLMAPITextToSpeech.service.js.map +0 -1
- package/dist/providers/LLMAPI/services/index.d.ts +0 -4
- package/dist/providers/LLMAPI/services/index.js +0 -21
- package/dist/providers/LLMAPI/services/index.js.map +0 -1
- package/dist/providers/LLMAPI/utilities/index.d.ts +0 -4
- package/dist/providers/LLMAPI/utilities/index.js +0 -13
- package/dist/providers/LLMAPI/utilities/index.js.map +0 -1
- package/dist/providers/LLMAPI/utilities/parseXmlToolCalls.d.ts +0 -7
- package/dist/providers/LLMAPI/utilities/parseXmlToolCalls.js +0 -35
- package/dist/providers/LLMAPI/utilities/parseXmlToolCalls.js.map +0 -1
- package/dist/providers/LLMAPI/utilities/stripThinkingTags.d.ts +0 -1
- package/dist/providers/LLMAPI/utilities/stripThinkingTags.js +0 -7
- package/dist/providers/LLMAPI/utilities/stripThinkingTags.js.map +0 -1
- package/dist/providers/LLMAPI/utilities/structuredOutput.d.ts +0 -13
- package/dist/providers/LLMAPI/utilities/structuredOutput.js +0 -29
- package/dist/providers/LLMAPI/utilities/structuredOutput.js.map +0 -1
- package/dist/providers/LLMAPI/utilities/validateStructuredResponse.d.ts +0 -10
- package/dist/providers/LLMAPI/utilities/validateStructuredResponse.js +0 -21
- package/dist/providers/LLMAPI/utilities/validateStructuredResponse.js.map +0 -1
- package/dist/providers/OpenAI/OpenAI.constants.d.ts +0 -1664
- package/dist/providers/OpenAI/OpenAI.constants.js +0 -310
- package/dist/providers/OpenAI/OpenAI.constants.js.map +0 -1
- package/dist/providers/OpenAI/OpenAI.entity.d.ts +0 -15
- package/dist/providers/OpenAI/OpenAI.entity.js +0 -162
- package/dist/providers/OpenAI/OpenAI.entity.js.map +0 -1
- package/dist/providers/OpenAI/OpenAI.typedefs.d.ts +0 -61
- package/dist/providers/OpenAI/OpenAI.typedefs.js +0 -39
- package/dist/providers/OpenAI/OpenAI.typedefs.js.map +0 -1
- package/dist/providers/OpenAI/OpenAIService.factory.d.ts +0 -6
- package/dist/providers/OpenAI/OpenAIService.factory.js +0 -18
- package/dist/providers/OpenAI/OpenAIService.factory.js.map +0 -1
- package/dist/providers/OpenAI/index.d.ts +0 -5
- package/dist/providers/OpenAI/index.js +0 -22
- package/dist/providers/OpenAI/index.js.map +0 -1
- package/dist/providers/OpenAI/schemas/OpenAISchemaAdapter.d.ts +0 -14
- package/dist/providers/OpenAI/schemas/OpenAISchemaAdapter.js +0 -87
- package/dist/providers/OpenAI/schemas/OpenAISchemaAdapter.js.map +0 -1
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.d.ts +0 -42
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.js +0 -712
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.js.map +0 -1
- package/dist/providers/OpenAI/services/OpenAICompletion.service.d.ts +0 -7
- package/dist/providers/OpenAI/services/OpenAICompletion.service.js +0 -12
- package/dist/providers/OpenAI/services/OpenAICompletion.service.js.map +0 -1
- package/dist/providers/OpenAI/services/OpenAISpeechToText.service.d.ts +0 -17
- package/dist/providers/OpenAI/services/OpenAISpeechToText.service.js +0 -40
- package/dist/providers/OpenAI/services/OpenAISpeechToText.service.js.map +0 -1
- package/dist/providers/OpenAI/services/OpenAITextToSpeech.service.d.ts +0 -13
- package/dist/providers/OpenAI/services/OpenAITextToSpeech.service.js +0 -32
- package/dist/providers/OpenAI/services/OpenAITextToSpeech.service.js.map +0 -1
- package/dist/providers/OpenAI/services/buildFunctionCallOutput.d.ts +0 -3
- package/dist/providers/OpenAI/services/buildFunctionCallOutput.js +0 -19
- package/dist/providers/OpenAI/services/buildFunctionCallOutput.js.map +0 -1
- package/dist/providers/OpenAI/services/index.d.ts +0 -4
- package/dist/providers/OpenAI/services/index.js +0 -21
- package/dist/providers/OpenAI/services/index.js.map +0 -1
- package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.d.ts +0 -30
- package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js +0 -233
- package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js.map +0 -1
- package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.d.ts +0 -22
- package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.js +0 -98
- package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.js.map +0 -1
- package/dist/providers/OpenAICompatible/OpenAICompatibleTextToSpeech.service.d.ts +0 -22
- package/dist/providers/OpenAICompatible/OpenAICompatibleTextToSpeech.service.js +0 -67
- package/dist/providers/OpenAICompatible/OpenAICompatibleTextToSpeech.service.js.map +0 -1
- package/dist/providers/index.d.ts +0 -3
- package/dist/providers/index.js +0 -20
- package/dist/providers/index.js.map +0 -1
- package/dist/services/LLMAssistanceService.abstract.d.ts +0 -37
- package/dist/services/LLMAssistanceService.abstract.js +0 -64
- package/dist/services/LLMAssistanceService.abstract.js.map +0 -1
- package/dist/services/LLMBaseService.abstract.d.ts +0 -161
- package/dist/services/LLMBaseService.abstract.js +0 -386
- package/dist/services/LLMBaseService.abstract.js.map +0 -1
- package/dist/services/LLMCompletionService.abstract.d.ts +0 -16
- package/dist/services/LLMCompletionService.abstract.js +0 -12
- package/dist/services/LLMCompletionService.abstract.js.map +0 -1
- package/dist/services/LLMServicePurposeFactory.abstract.d.ts +0 -12
- package/dist/services/LLMServicePurposeFactory.abstract.js +0 -7
- package/dist/services/LLMServicePurposeFactory.abstract.js.map +0 -1
- package/dist/services/LLMSpeechToTextService.abstract.d.ts +0 -8
- package/dist/services/LLMSpeechToTextService.abstract.js +0 -12
- package/dist/services/LLMSpeechToTextService.abstract.js.map +0 -1
- package/dist/services/LLMTextToSpeechService.abstract.d.ts +0 -8
- package/dist/services/LLMTextToSpeechService.abstract.js +0 -12
- package/dist/services/LLMTextToSpeechService.abstract.js.map +0 -1
- package/dist/services/agentRounds/LLMAgentRounds.d.ts +0 -32
- package/dist/services/agentRounds/LLMAgentRounds.js +0 -77
- package/dist/services/agentRounds/LLMAgentRounds.js.map +0 -1
- package/dist/services/agentRounds/agentRounds.typedefs.d.ts +0 -48
- package/dist/services/agentRounds/agentRounds.typedefs.js +0 -3
- package/dist/services/agentRounds/agentRounds.typedefs.js.map +0 -1
- package/dist/services/agentRounds/index.d.ts +0 -2
- package/dist/services/agentRounds/index.js +0 -19
- package/dist/services/agentRounds/index.js.map +0 -1
- package/dist/services/chatState/CompletionsChatState.d.ts +0 -35
- package/dist/services/chatState/CompletionsChatState.js +0 -118
- package/dist/services/chatState/CompletionsChatState.js.map +0 -1
- package/dist/services/chatState/index.d.ts +0 -1
- package/dist/services/chatState/index.js +0 -6
- package/dist/services/chatState/index.js.map +0 -1
- package/dist/services/fileStorage/FileStorageToolExecutor.d.ts +0 -15
- package/dist/services/fileStorage/FileStorageToolExecutor.js +0 -172
- package/dist/services/fileStorage/FileStorageToolExecutor.js.map +0 -1
- package/dist/services/fileStorage/InMemoryFileStorage.d.ts +0 -20
- package/dist/services/fileStorage/InMemoryFileStorage.js +0 -67
- package/dist/services/fileStorage/InMemoryFileStorage.js.map +0 -1
- package/dist/services/fileStorage/fileStorageTools.d.ts +0 -26
- package/dist/services/fileStorage/fileStorageTools.js +0 -68
- package/dist/services/fileStorage/fileStorageTools.js.map +0 -1
- package/dist/services/fileStorage/index.d.ts +0 -4
- package/dist/services/fileStorage/index.js +0 -11
- package/dist/services/fileStorage/index.js.map +0 -1
- package/dist/services/index.d.ts +0 -7
- package/dist/services/index.js +0 -24
- package/dist/services/index.js.map +0 -1
- package/dist/utilities/calculateCosts.d.ts +0 -4
- package/dist/utilities/calculateCosts.js +0 -56
- package/dist/utilities/calculateCosts.js.map +0 -1
- package/dist/utilities/functional.utils.d.ts +0 -1
- package/dist/utilities/functional.utils.js +0 -9
- package/dist/utilities/functional.utils.js.map +0 -1
- package/dist/utilities/index.d.ts +0 -9
- package/dist/utilities/index.js +0 -26
- package/dist/utilities/index.js.map +0 -1
- package/dist/utilities/llmTracing/index.d.ts +0 -3
- package/dist/utilities/llmTracing/index.js +0 -20
- package/dist/utilities/llmTracing/index.js.map +0 -1
- package/dist/utilities/llmTracing/llmTracing.constants.d.ts +0 -7
- package/dist/utilities/llmTracing/llmTracing.constants.js +0 -11
- package/dist/utilities/llmTracing/llmTracing.constants.js.map +0 -1
- package/dist/utilities/llmTracing/llmTracing.typedefs.d.ts +0 -126
- package/dist/utilities/llmTracing/llmTracing.typedefs.js +0 -3
- package/dist/utilities/llmTracing/llmTracing.typedefs.js.map +0 -1
- package/dist/utilities/llmTracing/noopLLMTracing.d.ts +0 -3
- package/dist/utilities/llmTracing/noopLLMTracing.js +0 -36
- package/dist/utilities/llmTracing/noopLLMTracing.js.map +0 -1
- package/dist/utilities/logger/LLMLoggerInterface.d.ts +0 -36
- package/dist/utilities/logger/LLMLoggerInterface.js +0 -3
- package/dist/utilities/logger/LLMLoggerInterface.js.map +0 -1
- package/dist/utilities/logger/index.d.ts +0 -1
- package/dist/utilities/logger/index.js +0 -18
- package/dist/utilities/logger/index.js.map +0 -1
- package/dist/utilities/promptBuilder.d.ts +0 -58
- package/dist/utilities/promptBuilder.js +0 -92
- package/dist/utilities/promptBuilder.js.map +0 -1
- package/dist/utilities/reporter/LLMReporterInterface.d.ts +0 -46
- package/dist/utilities/reporter/LLMReporterInterface.js +0 -3
- package/dist/utilities/reporter/LLMReporterInterface.js.map +0 -1
- package/dist/utilities/reporter/index.d.ts +0 -1
- package/dist/utilities/reporter/index.js +0 -18
- package/dist/utilities/reporter/index.js.map +0 -1
- package/dist/utilities/schema/LLMSchema.d.ts +0 -112
- package/dist/utilities/schema/LLMSchema.js +0 -223
- package/dist/utilities/schema/LLMSchema.js.map +0 -1
- package/dist/utilities/schema/LLMSchema.typedefs.d.ts +0 -55
- package/dist/utilities/schema/LLMSchema.typedefs.js +0 -3
- package/dist/utilities/schema/LLMSchema.typedefs.js.map +0 -1
- package/dist/utilities/schema/SchemaAdapterRegistry.d.ts +0 -26
- package/dist/utilities/schema/SchemaAdapterRegistry.js +0 -32
- package/dist/utilities/schema/SchemaAdapterRegistry.js.map +0 -1
- package/dist/utilities/schema/index.d.ts +0 -2
- package/dist/utilities/schema/index.js +0 -19
- package/dist/utilities/schema/index.js.map +0 -1
- package/dist/utilities/serializeError.d.ts +0 -9
- package/dist/utilities/serializeError.js +0 -69
- package/dist/utilities/serializeError.js.map +0 -1
- package/dist/utilities/tokenizer.d.ts +0 -4
- package/dist/utilities/tokenizer.js +0 -14
- package/dist/utilities/tokenizer.js.map +0 -1
- package/dist/utilities/tools/LLMTool.d.ts +0 -5
- package/dist/utilities/tools/LLMTool.js +0 -10
- package/dist/utilities/tools/LLMTool.js.map +0 -1
- package/dist/utilities/tools/index.d.ts +0 -2
- package/dist/utilities/tools/index.js +0 -8
- package/dist/utilities/tools/index.js.map +0 -1
- package/dist/utilities/tools/normalizeToolResult.d.ts +0 -15
- package/dist/utilities/tools/normalizeToolResult.js +0 -18
- package/dist/utilities/tools/normalizeToolResult.js.map +0 -1
|
@@ -1,712 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenAIAssistanceService = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const openai_1 = require("openai");
|
|
6
|
-
const LLMService_typedefs_1 = require("../../../LLMService.typedefs");
|
|
7
|
-
const LLMService_constants_1 = require("../../../LLMService.constants");
|
|
8
|
-
const serializeError_1 = require("../../../utilities/serializeError");
|
|
9
|
-
const services_1 = require("../../../services");
|
|
10
|
-
const buildFunctionCallOutput_1 = require("./buildFunctionCallOutput");
|
|
11
|
-
const OpenAI_typedefs_1 = require("../../../providers/OpenAI/OpenAI.typedefs");
|
|
12
|
-
const OpenAI_entity_1 = require("../../../providers/OpenAI/OpenAI.entity");
|
|
13
|
-
const uuid_1 = require("uuid");
|
|
14
|
-
class OpenAIAssistanceService extends services_1.LLMAssistanceService {
|
|
15
|
-
uploadedFiles = new Map();
|
|
16
|
-
responseHistory = new Map();
|
|
17
|
-
chatInstructions = new Map();
|
|
18
|
-
constructor(logger, reporter, options) {
|
|
19
|
-
super(LLMService_typedefs_1.LLMProviders.OpenAI, logger, reporter, options);
|
|
20
|
-
}
|
|
21
|
-
get instance() {
|
|
22
|
-
return this.getOrCreateInstance(() => new openai_1.OpenAI(this.options));
|
|
23
|
-
}
|
|
24
|
-
async uploadFile(fileOptions) {
|
|
25
|
-
const { path, name, mimeType, abortSignal, reporterContext, } = fileOptions;
|
|
26
|
-
const writeMetrics = this.reporter?.initWriter(reporterContext);
|
|
27
|
-
try {
|
|
28
|
-
abortSignal?.throwIfAborted();
|
|
29
|
-
const existingFile = await this.getFile(path);
|
|
30
|
-
if (existingFile) {
|
|
31
|
-
this.writeSuccessMetrics({
|
|
32
|
-
method: this.getMethodName(this.uploadFile),
|
|
33
|
-
model: null,
|
|
34
|
-
usage: {},
|
|
35
|
-
writeMetrics,
|
|
36
|
-
});
|
|
37
|
-
return existingFile;
|
|
38
|
-
}
|
|
39
|
-
const readableStream = (0, fs_1.createReadStream)(path, { signal: abortSignal });
|
|
40
|
-
abortSignal?.throwIfAborted();
|
|
41
|
-
const uploadedFile = await this.instance.files.create({
|
|
42
|
-
purpose: 'assistants',
|
|
43
|
-
file: readableStream,
|
|
44
|
-
}, {
|
|
45
|
-
signal: abortSignal,
|
|
46
|
-
});
|
|
47
|
-
abortSignal?.throwIfAborted();
|
|
48
|
-
await this.instance.files.waitForProcessing(uploadedFile.id);
|
|
49
|
-
abortSignal?.throwIfAborted();
|
|
50
|
-
const uploadedFileInfo = {
|
|
51
|
-
name,
|
|
52
|
-
path,
|
|
53
|
-
mimeType,
|
|
54
|
-
fileId: uploadedFile.id,
|
|
55
|
-
};
|
|
56
|
-
this.uploadedFiles.set(path, uploadedFileInfo);
|
|
57
|
-
await this.writeSuccessMetrics({
|
|
58
|
-
method: this.getMethodName(this.uploadFile),
|
|
59
|
-
model: null,
|
|
60
|
-
usage: {},
|
|
61
|
-
writeMetrics,
|
|
62
|
-
});
|
|
63
|
-
return uploadedFileInfo;
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
await this.writeErrorMetrics({
|
|
67
|
-
method: this.getMethodName(this.uploadFile),
|
|
68
|
-
model: null,
|
|
69
|
-
isAborted: abortSignal?.aborted,
|
|
70
|
-
writeMetrics,
|
|
71
|
-
});
|
|
72
|
-
this.logRequestFailure({
|
|
73
|
-
method: this.getMethodName(this.uploadFile),
|
|
74
|
-
message: 'Error uploading file',
|
|
75
|
-
error,
|
|
76
|
-
isAborted: abortSignal?.aborted,
|
|
77
|
-
meta: { file: fileOptions },
|
|
78
|
-
});
|
|
79
|
-
return { error };
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async getFile(path) {
|
|
83
|
-
return this.uploadedFiles.get(path) || null;
|
|
84
|
-
}
|
|
85
|
-
async deleteFile(fileId) {
|
|
86
|
-
await this.instance.files.delete(fileId);
|
|
87
|
-
this.uploadedFiles.delete(fileId);
|
|
88
|
-
}
|
|
89
|
-
async createFileStorage(options) {
|
|
90
|
-
const { uploadedFiles, abortSignal, reporterContext, } = options;
|
|
91
|
-
const writeMetrics = this.reporter?.initWriter(reporterContext);
|
|
92
|
-
try {
|
|
93
|
-
const vectorStore = await this.instance.vectorStores.create({
|
|
94
|
-
expires_after: {
|
|
95
|
-
anchor: 'last_active_at',
|
|
96
|
-
days: 1,
|
|
97
|
-
},
|
|
98
|
-
}, {
|
|
99
|
-
signal: abortSignal,
|
|
100
|
-
});
|
|
101
|
-
abortSignal?.throwIfAborted();
|
|
102
|
-
if (uploadedFiles.length > 0) {
|
|
103
|
-
await this.instance.vectorStores.fileBatches
|
|
104
|
-
.createAndPoll(vectorStore.id, { file_ids: uploadedFiles.map(({ fileId }) => fileId) }, { signal: abortSignal });
|
|
105
|
-
abortSignal?.throwIfAborted();
|
|
106
|
-
}
|
|
107
|
-
await this.writeSuccessMetrics({
|
|
108
|
-
method: this.getMethodName(this.createFileStorage),
|
|
109
|
-
model: null,
|
|
110
|
-
usage: {},
|
|
111
|
-
writeMetrics,
|
|
112
|
-
});
|
|
113
|
-
return {
|
|
114
|
-
storageId: vectorStore.id,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
await this.writeErrorMetrics({
|
|
119
|
-
method: this.getMethodName(this.createFileStorage),
|
|
120
|
-
model: null,
|
|
121
|
-
isAborted: abortSignal?.aborted,
|
|
122
|
-
writeMetrics,
|
|
123
|
-
});
|
|
124
|
-
this.logRequestFailure({
|
|
125
|
-
method: this.getMethodName(this.createFileStorage),
|
|
126
|
-
message: 'Error creating file storage',
|
|
127
|
-
error,
|
|
128
|
-
isAborted: abortSignal?.aborted,
|
|
129
|
-
meta: { uploadedFiles },
|
|
130
|
-
});
|
|
131
|
-
return { error };
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
async deleteFileStorage(fileStorageId) {
|
|
135
|
-
await this.instance.vectorStores.delete(fileStorageId);
|
|
136
|
-
}
|
|
137
|
-
async createChat(options) {
|
|
138
|
-
const { storageId, model, instructions, history = [], abortSignal, reporterContext, } = options;
|
|
139
|
-
const writeMetrics = this.reporter?.initWriter(reporterContext);
|
|
140
|
-
try {
|
|
141
|
-
abortSignal?.throwIfAborted();
|
|
142
|
-
const chatId = (0, uuid_1.v4)();
|
|
143
|
-
if (instructions) {
|
|
144
|
-
this.chatInstructions.set(chatId, instructions);
|
|
145
|
-
}
|
|
146
|
-
let inputTextTokens;
|
|
147
|
-
let inputCachedTextTokens;
|
|
148
|
-
let outputTextTokens;
|
|
149
|
-
if (history.length > 0) {
|
|
150
|
-
const initialInput = history
|
|
151
|
-
.map((msg) => this.convertLLMMessageToResponsesInput(msg))
|
|
152
|
-
.flat();
|
|
153
|
-
const tools = [];
|
|
154
|
-
if (storageId) {
|
|
155
|
-
tools.push({
|
|
156
|
-
type: 'file_search',
|
|
157
|
-
vector_store_ids: [storageId],
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
const response = await this.instance.responses.create({
|
|
161
|
-
model: model.name,
|
|
162
|
-
input: initialInput,
|
|
163
|
-
tools: tools.length > 0
|
|
164
|
-
? tools
|
|
165
|
-
: undefined,
|
|
166
|
-
instructions,
|
|
167
|
-
}, {
|
|
168
|
-
signal: abortSignal,
|
|
169
|
-
});
|
|
170
|
-
this.responseHistory.set(chatId, response.id);
|
|
171
|
-
const totalInputTokens = response.usage?.input_tokens ?? 0;
|
|
172
|
-
const cachedInputTokens = response.usage?.input_tokens_details?.cached_tokens ?? 0;
|
|
173
|
-
const totalOutputTokens = response.usage?.output_tokens ?? 0;
|
|
174
|
-
const reasoningOutputTokens = response.usage?.output_tokens_details?.reasoning_tokens ?? 0;
|
|
175
|
-
inputTextTokens = totalInputTokens - cachedInputTokens;
|
|
176
|
-
inputCachedTextTokens = cachedInputTokens;
|
|
177
|
-
outputTextTokens = totalOutputTokens + reasoningOutputTokens;
|
|
178
|
-
}
|
|
179
|
-
await this.writeSuccessMetrics({
|
|
180
|
-
method: this.getMethodName(this.createChat),
|
|
181
|
-
model,
|
|
182
|
-
usage: {
|
|
183
|
-
inputTextTokens,
|
|
184
|
-
inputCachedTextTokens,
|
|
185
|
-
outputTextTokens,
|
|
186
|
-
},
|
|
187
|
-
writeMetrics,
|
|
188
|
-
});
|
|
189
|
-
return { chatId };
|
|
190
|
-
}
|
|
191
|
-
catch (error) {
|
|
192
|
-
await this.writeErrorMetrics({
|
|
193
|
-
method: this.getMethodName(this.createChat),
|
|
194
|
-
model,
|
|
195
|
-
isAborted: abortSignal?.aborted,
|
|
196
|
-
writeMetrics,
|
|
197
|
-
});
|
|
198
|
-
this.logRequestFailure({
|
|
199
|
-
method: this.getMethodName(this.createChat),
|
|
200
|
-
message: 'Error creating chat',
|
|
201
|
-
error,
|
|
202
|
-
isAborted: abortSignal?.aborted,
|
|
203
|
-
meta: { options },
|
|
204
|
-
});
|
|
205
|
-
return { error };
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
async deleteChat(chatId) {
|
|
209
|
-
this.responseHistory.delete(chatId);
|
|
210
|
-
this.chatInstructions.delete(chatId);
|
|
211
|
-
}
|
|
212
|
-
prepareAssistTools(options) {
|
|
213
|
-
const { message, storageId } = options;
|
|
214
|
-
const customTools = options.tools ?? [];
|
|
215
|
-
const messageInput = this.convertLLMMessageToResponsesInput(message);
|
|
216
|
-
let tools = [];
|
|
217
|
-
if (customTools.length > 0) {
|
|
218
|
-
this.validateToolDefinitions(customTools);
|
|
219
|
-
tools = this.convertCustomToolsToResponsesAPI(customTools);
|
|
220
|
-
}
|
|
221
|
-
if (storageId) {
|
|
222
|
-
tools.push({
|
|
223
|
-
type: 'file_search',
|
|
224
|
-
vector_store_ids: [storageId],
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
return { messageInput, tools };
|
|
228
|
-
}
|
|
229
|
-
extractUsageFromResponse(response) {
|
|
230
|
-
return {
|
|
231
|
-
inputTokens: response.usage?.input_tokens ?? 0,
|
|
232
|
-
cachedInputTokens: response.usage
|
|
233
|
-
?.input_tokens_details
|
|
234
|
-
?.cached_tokens ?? 0,
|
|
235
|
-
outputTokens: response.usage?.output_tokens ?? 0,
|
|
236
|
-
reasoningTokens: response.usage
|
|
237
|
-
?.output_tokens_details
|
|
238
|
-
?.reasoning_tokens ?? 0,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
buildUsageMetrics(usage) {
|
|
242
|
-
return {
|
|
243
|
-
inputTextTokens: usage.inputTokens - usage.cachedInputTokens,
|
|
244
|
-
inputCachedTextTokens: usage.cachedInputTokens,
|
|
245
|
-
outputTextTokens: usage.outputTokens + usage.reasoningTokens,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
buildRoundOutcome = (response) => ({
|
|
249
|
-
output: response.output,
|
|
250
|
-
usage: this.buildUsageMetrics(this.extractUsageFromResponse(response)),
|
|
251
|
-
});
|
|
252
|
-
/**
|
|
253
|
-
* The transcript a traced round of this turn shows. The Responses API keeps
|
|
254
|
-
* earlier turns of the chat server-side and refers to them by
|
|
255
|
-
* `previous_response_id`, so what a round can honestly show is what this call
|
|
256
|
-
* put on the wire: the chat's instructions, this turn's input items, and
|
|
257
|
-
* everything the tool loop appends to them afterwards.
|
|
258
|
-
*/
|
|
259
|
-
startTracedConversation(params) {
|
|
260
|
-
const instructions = this.chatInstructions.get(params.chatId);
|
|
261
|
-
return [
|
|
262
|
-
...(instructions
|
|
263
|
-
? [{
|
|
264
|
-
role: OpenAI_typedefs_1.OpenAIRoles.Developer,
|
|
265
|
-
content: instructions,
|
|
266
|
-
}]
|
|
267
|
-
: []),
|
|
268
|
-
...params.messageInput,
|
|
269
|
-
];
|
|
270
|
-
}
|
|
271
|
-
async assistInChatText(options) {
|
|
272
|
-
const { model, chatId, abortSignal, reporterContext, traceContext, } = options;
|
|
273
|
-
const writeMetrics = this.reporter?.initWriter(reporterContext);
|
|
274
|
-
const method = this.getMethodName(this.assistInChatText);
|
|
275
|
-
const generationStartedAt = Date.now();
|
|
276
|
-
const rounds = this.openAgentRounds({
|
|
277
|
-
method,
|
|
278
|
-
model,
|
|
279
|
-
traceContext,
|
|
280
|
-
modelParameters: model.config,
|
|
281
|
-
});
|
|
282
|
-
try {
|
|
283
|
-
abortSignal?.throwIfAborted();
|
|
284
|
-
const lastResponseId = this.responseHistory.get(chatId);
|
|
285
|
-
const { messageInput, tools } = this.prepareAssistTools(options);
|
|
286
|
-
const customTools = options.tools ?? [];
|
|
287
|
-
const conversation = this.startTracedConversation({
|
|
288
|
-
chatId,
|
|
289
|
-
messageInput,
|
|
290
|
-
});
|
|
291
|
-
const initialResponse = await rounds.run({
|
|
292
|
-
input: [...conversation],
|
|
293
|
-
call: () => this.instance.responses.create({
|
|
294
|
-
model: model.name,
|
|
295
|
-
input: messageInput,
|
|
296
|
-
previous_response_id: lastResponseId,
|
|
297
|
-
tools: tools.length > 0
|
|
298
|
-
? tools
|
|
299
|
-
: undefined,
|
|
300
|
-
instructions: this.chatInstructions.get(chatId),
|
|
301
|
-
}, { signal: abortSignal }),
|
|
302
|
-
describeOutcome: this.buildRoundOutcome,
|
|
303
|
-
});
|
|
304
|
-
this.responseHistory.set(chatId, initialResponse.id);
|
|
305
|
-
const maxIterations = options.maxToolIterations
|
|
306
|
-
?? LLMService_constants_1.DEFAULT_MAX_TOOL_ITERATIONS;
|
|
307
|
-
const toolLoopResult = await this.executeToolLoop({
|
|
308
|
-
response: initialResponse,
|
|
309
|
-
tools: customTools,
|
|
310
|
-
model,
|
|
311
|
-
chatId,
|
|
312
|
-
maxIterations,
|
|
313
|
-
abortSignal,
|
|
314
|
-
allTools: tools,
|
|
315
|
-
rounds,
|
|
316
|
-
conversation,
|
|
317
|
-
onAssistantNarration: options.onAssistantNarration,
|
|
318
|
-
});
|
|
319
|
-
const { response: finalResponse, totalUsage } = toolLoopResult;
|
|
320
|
-
const text = finalResponse.output_text || '';
|
|
321
|
-
await this.writeSuccessMetrics({
|
|
322
|
-
method,
|
|
323
|
-
model,
|
|
324
|
-
usage: this.buildUsageMetrics(totalUsage),
|
|
325
|
-
writeMetrics,
|
|
326
|
-
});
|
|
327
|
-
return {
|
|
328
|
-
text,
|
|
329
|
-
toolIterationsUsed: toolLoopResult.toolIterationsUsed,
|
|
330
|
-
...(toolLoopResult.toolIterationsExhausted && {
|
|
331
|
-
toolIterationsExhausted: true,
|
|
332
|
-
}),
|
|
333
|
-
stopReason: toolLoopResult.stopReason,
|
|
334
|
-
...(toolLoopResult.terminalTool && {
|
|
335
|
-
terminalTool: toolLoopResult.terminalTool,
|
|
336
|
-
}),
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
catch (error) {
|
|
340
|
-
await this.writeErrorMetrics({
|
|
341
|
-
method,
|
|
342
|
-
model,
|
|
343
|
-
isAborted: abortSignal?.aborted,
|
|
344
|
-
writeMetrics,
|
|
345
|
-
error,
|
|
346
|
-
generationTrace: this.buildUnstartedRunTrace({
|
|
347
|
-
rounds,
|
|
348
|
-
method,
|
|
349
|
-
traceContext,
|
|
350
|
-
input: options.message,
|
|
351
|
-
modelParameters: model.config,
|
|
352
|
-
startedAt: generationStartedAt,
|
|
353
|
-
}),
|
|
354
|
-
});
|
|
355
|
-
this.logRequestFailure({
|
|
356
|
-
method,
|
|
357
|
-
message: 'Error assisting in chat with Responses API',
|
|
358
|
-
error,
|
|
359
|
-
isAborted: abortSignal?.aborted,
|
|
360
|
-
meta: { options },
|
|
361
|
-
});
|
|
362
|
-
return {
|
|
363
|
-
error: error instanceof Error
|
|
364
|
-
? error
|
|
365
|
-
: new Error(String(error)),
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
async assistInChatStructured(options) {
|
|
370
|
-
const { model, chatId, abortSignal, schema, reporterContext, traceContext, } = options;
|
|
371
|
-
const writeMetrics = this.reporter?.initWriter(reporterContext);
|
|
372
|
-
const method = this.getMethodName(this.assistInChatStructured);
|
|
373
|
-
const generationStartedAt = Date.now();
|
|
374
|
-
const rounds = this.openAgentRounds({
|
|
375
|
-
method,
|
|
376
|
-
model,
|
|
377
|
-
traceContext,
|
|
378
|
-
modelParameters: model.config,
|
|
379
|
-
});
|
|
380
|
-
try {
|
|
381
|
-
abortSignal?.throwIfAborted();
|
|
382
|
-
const lastResponseId = this.responseHistory.get(chatId);
|
|
383
|
-
const { messageInput, tools } = this.prepareAssistTools(options);
|
|
384
|
-
const customTools = options.tools ?? [];
|
|
385
|
-
const jsonSchema = schema._toProviderSchema(LLMService_typedefs_1.LLMProviders.OpenAI);
|
|
386
|
-
const textFormat = {
|
|
387
|
-
format: {
|
|
388
|
-
type: 'json_schema',
|
|
389
|
-
name: 'structured_response',
|
|
390
|
-
strict: true,
|
|
391
|
-
schema: jsonSchema,
|
|
392
|
-
},
|
|
393
|
-
};
|
|
394
|
-
const conversation = this.startTracedConversation({
|
|
395
|
-
chatId,
|
|
396
|
-
messageInput,
|
|
397
|
-
});
|
|
398
|
-
const initialResponse = await rounds.run({
|
|
399
|
-
input: [...conversation],
|
|
400
|
-
call: () => this.instance.responses.create({
|
|
401
|
-
model: model.name,
|
|
402
|
-
input: messageInput,
|
|
403
|
-
previous_response_id: lastResponseId,
|
|
404
|
-
tools: tools.length > 0
|
|
405
|
-
? tools
|
|
406
|
-
: undefined,
|
|
407
|
-
instructions: this.chatInstructions.get(chatId),
|
|
408
|
-
text: textFormat,
|
|
409
|
-
}, { signal: abortSignal }),
|
|
410
|
-
describeOutcome: this.buildRoundOutcome,
|
|
411
|
-
});
|
|
412
|
-
this.responseHistory.set(chatId, initialResponse.id);
|
|
413
|
-
const maxIterations = options.maxToolIterations
|
|
414
|
-
?? LLMService_constants_1.DEFAULT_MAX_TOOL_ITERATIONS;
|
|
415
|
-
const toolLoopResult = await this.executeToolLoop({
|
|
416
|
-
response: initialResponse,
|
|
417
|
-
tools: customTools,
|
|
418
|
-
model,
|
|
419
|
-
chatId,
|
|
420
|
-
maxIterations,
|
|
421
|
-
abortSignal,
|
|
422
|
-
allTools: tools,
|
|
423
|
-
rounds,
|
|
424
|
-
conversation,
|
|
425
|
-
textFormat,
|
|
426
|
-
onAssistantNarration: options.onAssistantNarration,
|
|
427
|
-
});
|
|
428
|
-
const { response: finalResponse, totalUsage, } = toolLoopResult;
|
|
429
|
-
const content = finalResponse.output_text || '';
|
|
430
|
-
if (toolLoopResult.terminalTool) {
|
|
431
|
-
await this.writeSuccessMetrics({
|
|
432
|
-
method: this.getMethodName(this.assistInChatStructured),
|
|
433
|
-
model,
|
|
434
|
-
usage: this.buildUsageMetrics(totalUsage),
|
|
435
|
-
writeMetrics,
|
|
436
|
-
});
|
|
437
|
-
return {
|
|
438
|
-
text: content,
|
|
439
|
-
toolIterationsUsed: toolLoopResult.toolIterationsUsed,
|
|
440
|
-
stopReason: toolLoopResult.stopReason,
|
|
441
|
-
terminalTool: toolLoopResult.terminalTool,
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
if (!content) {
|
|
445
|
-
throw new Error('Empty response from OpenAI Responses API');
|
|
446
|
-
}
|
|
447
|
-
try {
|
|
448
|
-
const parsed = JSON.parse(content);
|
|
449
|
-
const validation = schema._parse(parsed);
|
|
450
|
-
await this.writeSuccessMetrics({
|
|
451
|
-
method,
|
|
452
|
-
model,
|
|
453
|
-
usage: this.buildUsageMetrics(totalUsage),
|
|
454
|
-
writeMetrics,
|
|
455
|
-
});
|
|
456
|
-
return {
|
|
457
|
-
text: content,
|
|
458
|
-
data: validation.data,
|
|
459
|
-
parseError: validation.error,
|
|
460
|
-
toolIterationsUsed: toolLoopResult.toolIterationsUsed,
|
|
461
|
-
...(toolLoopResult.toolIterationsExhausted && {
|
|
462
|
-
toolIterationsExhausted: true,
|
|
463
|
-
}),
|
|
464
|
-
stopReason: toolLoopResult.stopReason,
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
catch (parseError) {
|
|
468
|
-
const parseErrorMessage = parseError instanceof Error
|
|
469
|
-
? parseError.message
|
|
470
|
-
: String(parseError);
|
|
471
|
-
this.logger
|
|
472
|
-
?.child(this.getMethodName(this.assistInChatStructured))
|
|
473
|
-
.warn('Failed to parse JSON response', {
|
|
474
|
-
content,
|
|
475
|
-
parseError: parseErrorMessage,
|
|
476
|
-
});
|
|
477
|
-
throw parseError;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
catch (error) {
|
|
481
|
-
await this.writeErrorMetrics({
|
|
482
|
-
method,
|
|
483
|
-
model,
|
|
484
|
-
isAborted: abortSignal?.aborted,
|
|
485
|
-
writeMetrics,
|
|
486
|
-
error,
|
|
487
|
-
generationTrace: this.buildUnstartedRunTrace({
|
|
488
|
-
rounds,
|
|
489
|
-
method,
|
|
490
|
-
traceContext,
|
|
491
|
-
input: options.message,
|
|
492
|
-
modelParameters: model.config,
|
|
493
|
-
startedAt: generationStartedAt,
|
|
494
|
-
}),
|
|
495
|
-
});
|
|
496
|
-
this.logRequestFailure({
|
|
497
|
-
method,
|
|
498
|
-
message: 'Error assisting in chat with structured'
|
|
499
|
-
+ ' output using Responses API',
|
|
500
|
-
error,
|
|
501
|
-
isAborted: abortSignal?.aborted,
|
|
502
|
-
meta: { options },
|
|
503
|
-
});
|
|
504
|
-
return {
|
|
505
|
-
text: '',
|
|
506
|
-
error: error instanceof Error
|
|
507
|
-
? error
|
|
508
|
-
: new Error(String(error)),
|
|
509
|
-
parseError: 'Failed to get structured response'
|
|
510
|
-
+ ' from OpenAI Responses API',
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
convertCustomToolsToResponsesAPI(tools) {
|
|
515
|
-
return tools.map((tool) => ({
|
|
516
|
-
type: 'function',
|
|
517
|
-
name: tool.name,
|
|
518
|
-
description: tool.description,
|
|
519
|
-
parameters: tool.parameters._toProviderSchema(LLMService_typedefs_1.LLMProviders.OpenAI),
|
|
520
|
-
strict: true,
|
|
521
|
-
}));
|
|
522
|
-
}
|
|
523
|
-
async executeFunctionCall(call, toolDefinitions) {
|
|
524
|
-
const matchingTool = toolDefinitions.find((tool) => tool.name === call.name);
|
|
525
|
-
if (!matchingTool) {
|
|
526
|
-
const unknownToolMessage = `Unknown tool: '${call.name}'`;
|
|
527
|
-
return {
|
|
528
|
-
outputItem: {
|
|
529
|
-
type: 'function_call_output',
|
|
530
|
-
call_id: call.call_id,
|
|
531
|
-
output: unknownToolMessage,
|
|
532
|
-
},
|
|
533
|
-
toolName: call.name,
|
|
534
|
-
output: unknownToolMessage,
|
|
535
|
-
isTerminal: false,
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
const isTerminal = matchingTool.terminal === true;
|
|
539
|
-
try {
|
|
540
|
-
const parsedArguments = JSON.parse(call.arguments);
|
|
541
|
-
const result = await this.getTracer().withToolObservation(`${this.serviceName}/tool:${call.name}`, parsedArguments, () => Promise.resolve(matchingTool.execute(parsedArguments)));
|
|
542
|
-
return {
|
|
543
|
-
outputItem: {
|
|
544
|
-
type: 'function_call_output',
|
|
545
|
-
call_id: call.call_id,
|
|
546
|
-
output: (0, buildFunctionCallOutput_1.buildFunctionCallOutput)(result),
|
|
547
|
-
},
|
|
548
|
-
toolName: call.name,
|
|
549
|
-
output: result,
|
|
550
|
-
isTerminal,
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
catch (error) {
|
|
554
|
-
const errorMessage = error instanceof Error
|
|
555
|
-
? error.message
|
|
556
|
-
: String(error);
|
|
557
|
-
this.logger
|
|
558
|
-
?.child(this.getMethodName(this.executeFunctionCall))
|
|
559
|
-
.error('Tool execution failed', {
|
|
560
|
-
toolName: call.name,
|
|
561
|
-
error: (0, serializeError_1.serializeError)(error),
|
|
562
|
-
});
|
|
563
|
-
const failureMessage = `Error executing tool '${call.name}':`
|
|
564
|
-
+ ` ${errorMessage}`;
|
|
565
|
-
return {
|
|
566
|
-
outputItem: {
|
|
567
|
-
type: 'function_call_output',
|
|
568
|
-
call_id: call.call_id,
|
|
569
|
-
output: failureMessage,
|
|
570
|
-
},
|
|
571
|
-
toolName: call.name,
|
|
572
|
-
output: failureMessage,
|
|
573
|
-
isTerminal,
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
async executeToolLoop(parameters) {
|
|
578
|
-
const { tools, model, chatId, maxIterations, abortSignal, allTools, rounds, conversation, textFormat, onAssistantNarration, } = parameters;
|
|
579
|
-
const tracedConversation = [...conversation];
|
|
580
|
-
let currentResponse = parameters.response;
|
|
581
|
-
const totalUsage = this.extractUsageFromResponse(currentResponse);
|
|
582
|
-
let toolIterationsUsed = 1;
|
|
583
|
-
let terminalTool;
|
|
584
|
-
for (let iteration = 0; iteration < maxIterations; iteration++) {
|
|
585
|
-
abortSignal?.throwIfAborted();
|
|
586
|
-
const functionCalls = this.getFunctionCallsFromResponse(currentResponse);
|
|
587
|
-
if (functionCalls.length === 0) {
|
|
588
|
-
break;
|
|
589
|
-
}
|
|
590
|
-
if (onAssistantNarration) {
|
|
591
|
-
onAssistantNarration(currentResponse.output_text || '');
|
|
592
|
-
}
|
|
593
|
-
const executedCalls = await Promise.all(functionCalls.map((call) => this.executeFunctionCall(call, tools)));
|
|
594
|
-
const terminalCall = executedCalls.find((executed) => executed.isTerminal);
|
|
595
|
-
if (terminalCall) {
|
|
596
|
-
abortSignal?.throwIfAborted();
|
|
597
|
-
terminalTool = {
|
|
598
|
-
name: terminalCall.toolName,
|
|
599
|
-
output: terminalCall.output,
|
|
600
|
-
};
|
|
601
|
-
break;
|
|
602
|
-
}
|
|
603
|
-
const outputItems = executedCalls.map((executed) => executed.outputItem);
|
|
604
|
-
abortSignal?.throwIfAborted();
|
|
605
|
-
tracedConversation.push(...currentResponse.output, ...outputItems);
|
|
606
|
-
const nextResponse = await rounds.run({
|
|
607
|
-
input: [...tracedConversation],
|
|
608
|
-
call: () => this.instance.responses.create({
|
|
609
|
-
model: model.name,
|
|
610
|
-
input: outputItems,
|
|
611
|
-
previous_response_id: currentResponse.id,
|
|
612
|
-
tools: allTools,
|
|
613
|
-
instructions: this.chatInstructions.get(chatId),
|
|
614
|
-
...(textFormat && { text: textFormat }),
|
|
615
|
-
}, { signal: abortSignal }),
|
|
616
|
-
describeOutcome: this.buildRoundOutcome,
|
|
617
|
-
});
|
|
618
|
-
this.responseHistory.set(chatId, nextResponse.id);
|
|
619
|
-
toolIterationsUsed += 1;
|
|
620
|
-
const iterationUsage = this.extractUsageFromResponse(nextResponse);
|
|
621
|
-
totalUsage.inputTokens +=
|
|
622
|
-
iterationUsage.inputTokens;
|
|
623
|
-
totalUsage.cachedInputTokens +=
|
|
624
|
-
iterationUsage.cachedInputTokens;
|
|
625
|
-
totalUsage.outputTokens +=
|
|
626
|
-
iterationUsage.outputTokens;
|
|
627
|
-
totalUsage.reasoningTokens +=
|
|
628
|
-
iterationUsage.reasoningTokens;
|
|
629
|
-
currentResponse = nextResponse;
|
|
630
|
-
}
|
|
631
|
-
const toolIterationsExhausted = !terminalTool
|
|
632
|
-
&& this.getFunctionCallsFromResponse(currentResponse).length > 0;
|
|
633
|
-
if (toolIterationsExhausted) {
|
|
634
|
-
this.logger
|
|
635
|
-
?.child(this.getMethodName(this.executeToolLoop))
|
|
636
|
-
.warn('Tool loop reached maxToolIterations', {
|
|
637
|
-
maxToolIterations: maxIterations,
|
|
638
|
-
toolIterationsUsed,
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
return {
|
|
642
|
-
response: currentResponse,
|
|
643
|
-
totalUsage,
|
|
644
|
-
toolIterationsUsed,
|
|
645
|
-
toolIterationsExhausted,
|
|
646
|
-
stopReason: this.resolveToolLoopStopReason({
|
|
647
|
-
terminalTool,
|
|
648
|
-
toolIterationsExhausted,
|
|
649
|
-
}),
|
|
650
|
-
terminalTool,
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
getFunctionCallsFromResponse(response) {
|
|
654
|
-
return response.output.filter((item) => item.type === 'function_call');
|
|
655
|
-
}
|
|
656
|
-
convertLLMMessageToResponsesInput(message) {
|
|
657
|
-
const { content, role } = message;
|
|
658
|
-
if (role === LLMService_typedefs_1.LLMRoles.Assistant) {
|
|
659
|
-
const outputContent = content
|
|
660
|
-
.filter((item) => item.type === LLMService_typedefs_1.LLMMessageContentType.TEXT)
|
|
661
|
-
.map((item) => ({
|
|
662
|
-
type: 'output_text',
|
|
663
|
-
text: item.text,
|
|
664
|
-
annotations: [],
|
|
665
|
-
}));
|
|
666
|
-
return [{
|
|
667
|
-
id: `msg_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`,
|
|
668
|
-
role: OpenAI_typedefs_1.OpenAIRoles.Assistant,
|
|
669
|
-
content: outputContent,
|
|
670
|
-
status: 'completed',
|
|
671
|
-
type: 'message',
|
|
672
|
-
}];
|
|
673
|
-
}
|
|
674
|
-
const messageContent = [];
|
|
675
|
-
content.forEach((item) => {
|
|
676
|
-
switch (item.type) {
|
|
677
|
-
case LLMService_typedefs_1.LLMMessageContentType.TEXT:
|
|
678
|
-
messageContent.push({
|
|
679
|
-
type: 'input_text',
|
|
680
|
-
text: item.text,
|
|
681
|
-
});
|
|
682
|
-
break;
|
|
683
|
-
case LLMService_typedefs_1.LLMMessageContentType.IMAGE_URL:
|
|
684
|
-
messageContent.push({
|
|
685
|
-
type: 'input_image',
|
|
686
|
-
image_url: item.image_url.url,
|
|
687
|
-
detail: 'auto',
|
|
688
|
-
});
|
|
689
|
-
break;
|
|
690
|
-
default:
|
|
691
|
-
this.logger
|
|
692
|
-
?.child('convertLLMMessageToResponsesInput')
|
|
693
|
-
.warn('Unsupported message content type', { item });
|
|
694
|
-
break;
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
|
-
return [{
|
|
698
|
-
role: role === LLMService_typedefs_1.LLMRoles.User
|
|
699
|
-
? OpenAI_typedefs_1.OpenAIRoles.User
|
|
700
|
-
: OpenAI_typedefs_1.OpenAIRoles.Developer,
|
|
701
|
-
content: messageContent,
|
|
702
|
-
}];
|
|
703
|
-
}
|
|
704
|
-
async countTokens(messages) {
|
|
705
|
-
const countTokensFn = OpenAI_entity_1.OpenAIEntity
|
|
706
|
-
.getCountTokensFn();
|
|
707
|
-
const messageContents = messages.flatMap((message) => message.content);
|
|
708
|
-
return countTokensFn(messageContents);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
exports.OpenAIAssistanceService = OpenAIAssistanceService;
|
|
712
|
-
//# sourceMappingURL=OpenAIAssistance.service.js.map
|