@mcoda/mswarm 0.1.135-codali.4 → 0.1.135-codali.41
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 +5 -0
- package/dist/codali-executor.d.ts +19 -0
- package/dist/codali-executor.d.ts.map +1 -1
- package/dist/codali-executor.js +54 -2
- package/dist/codali-executor.js.map +1 -1
- package/dist/runtime.d.ts +3 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +36 -7
- package/dist/runtime.js.map +1 -1
- package/dist/vendor/codali/cli/TerminalArtifacts.d.ts +5 -0
- package/dist/vendor/codali/cli/TerminalArtifacts.d.ts.map +1 -0
- package/dist/vendor/codali/cli/TerminalArtifacts.js +26 -0
- package/dist/vendor/codali/cli/TerminalCommand.d.ts +2 -1
- package/dist/vendor/codali/cli/TerminalCommand.d.ts.map +1 -1
- package/dist/vendor/codali/cli/TerminalCommand.js +436 -100
- package/dist/vendor/codali/cli/TerminalInput.d.ts +13 -0
- package/dist/vendor/codali/cli/TerminalInput.d.ts.map +1 -1
- package/dist/vendor/codali/cli/TerminalInput.js +55 -7
- package/dist/vendor/codali/cli/TerminalModels.d.ts +6 -0
- package/dist/vendor/codali/cli/TerminalModels.d.ts.map +1 -0
- package/dist/vendor/codali/cli/TerminalModels.js +45 -0
- package/dist/vendor/codali/cli/TerminalPlan.d.ts +40 -0
- package/dist/vendor/codali/cli/TerminalPlan.d.ts.map +1 -0
- package/dist/vendor/codali/cli/TerminalPlan.js +37 -0
- package/dist/vendor/codali/cli/ToolsCommand.d.ts.map +1 -1
- package/dist/vendor/codali/cli/ToolsCommand.js +8 -1
- package/dist/vendor/codali/cli/tui/TerminalCells.d.ts +6 -0
- package/dist/vendor/codali/cli/tui/TerminalCells.d.ts.map +1 -0
- package/dist/vendor/codali/cli/tui/TerminalCells.js +47 -0
- package/dist/vendor/codali/cli/tui/TerminalEditor.d.ts +22 -0
- package/dist/vendor/codali/cli/tui/TerminalEditor.d.ts.map +1 -0
- package/dist/vendor/codali/cli/tui/TerminalEditor.js +88 -0
- package/dist/vendor/codali/cli/tui/TerminalLogo.d.ts +6 -0
- package/dist/vendor/codali/cli/tui/TerminalLogo.d.ts.map +1 -0
- package/dist/vendor/codali/cli/tui/TerminalLogo.js +26 -0
- package/dist/vendor/codali/cli/tui/TerminalMarkdown.d.ts +5 -0
- package/dist/vendor/codali/cli/tui/TerminalMarkdown.d.ts.map +1 -0
- package/dist/vendor/codali/cli/tui/TerminalMarkdown.js +118 -0
- package/dist/vendor/codali/cli/tui/TerminalPresentation.d.ts +6 -0
- package/dist/vendor/codali/cli/tui/TerminalPresentation.d.ts.map +1 -0
- package/dist/vendor/codali/cli/tui/TerminalPresentation.js +152 -0
- package/dist/vendor/codali/cli/tui/TerminalScreen.d.ts +50 -0
- package/dist/vendor/codali/cli/tui/TerminalScreen.d.ts.map +1 -0
- package/dist/vendor/codali/cli/tui/TerminalScreen.js +137 -0
- package/dist/vendor/codali/cli/tui/TerminalSelection.d.ts +15 -0
- package/dist/vendor/codali/cli/tui/TerminalSelection.d.ts.map +1 -0
- package/dist/vendor/codali/cli/tui/TerminalSelection.js +38 -0
- package/dist/vendor/codali/cli/tui/TerminalTui.d.ts +82 -0
- package/dist/vendor/codali/cli/tui/TerminalTui.d.ts.map +1 -0
- package/dist/vendor/codali/cli/tui/TerminalTui.js +564 -0
- package/dist/vendor/codali/cli.d.ts.map +1 -1
- package/dist/vendor/codali/cli.js +5 -3
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts +40 -0
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts.map +1 -1
- package/dist/vendor/codali/config/OrchestrationConfig.js +79 -5
- package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts +2 -1
- package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts.map +1 -1
- package/dist/vendor/codali/connectors/media/MediaJobStore.js +11 -3
- package/dist/vendor/codali/docdex/DocdexCatalog.d.ts +12 -0
- package/dist/vendor/codali/docdex/DocdexCatalog.d.ts.map +1 -0
- package/dist/vendor/codali/docdex/DocdexCatalog.js +30 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts +15 -2
- package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/vendor/codali/docdex/DocdexClient.js +119 -12
- package/dist/vendor/codali/docdex/ManagedDocdex.d.ts +4 -0
- package/dist/vendor/codali/docdex/ManagedDocdex.d.ts.map +1 -1
- package/dist/vendor/codali/docdex/ManagedDocdex.js +42 -5
- package/dist/vendor/codali/eval/EvaluationProcess.d.ts.map +1 -1
- package/dist/vendor/codali/eval/EvaluationProcess.js +4 -0
- package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts +1 -1
- package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts.map +1 -1
- package/dist/vendor/codali/eval/TerminalWorkflowCorpus.js +9 -6
- package/dist/vendor/codali/eval/TrustBenchmark.d.ts +94 -0
- package/dist/vendor/codali/eval/TrustBenchmark.d.ts.map +1 -0
- package/dist/vendor/codali/eval/TrustBenchmark.js +199 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts +4 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts.map +1 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.js +10 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts +6 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts.map +1 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.js +145 -0
- package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.d.ts.map +1 -1
- package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.js +14 -1
- package/dist/vendor/codali/gateway/GroundingMode.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/GroundingMode.js +23 -3
- package/dist/vendor/codali/index.d.ts +1 -0
- package/dist/vendor/codali/index.d.ts.map +1 -1
- package/dist/vendor/codali/index.js +1 -0
- package/dist/vendor/codali/permissions/PermissionGate.d.ts +4 -1
- package/dist/vendor/codali/permissions/PermissionGate.d.ts.map +1 -1
- package/dist/vendor/codali/permissions/PermissionGate.js +50 -5
- package/dist/vendor/codali/permissions/WorkspacePermissions.d.ts +11 -0
- package/dist/vendor/codali/permissions/WorkspacePermissions.d.ts.map +1 -0
- package/dist/vendor/codali/permissions/WorkspacePermissions.js +42 -0
- package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts +1 -0
- package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ConfiguredModelScope.js +19 -2
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts +10 -1
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ConfiguredProvider.js +104 -37
- package/dist/vendor/codali/providers/ModelCapacityWait.d.ts +21 -0
- package/dist/vendor/codali/providers/ModelCapacityWait.d.ts.map +1 -0
- package/dist/vendor/codali/providers/ModelCapacityWait.js +40 -0
- package/dist/vendor/codali/providers/ModelServiceError.d.ts +16 -2
- package/dist/vendor/codali/providers/ModelServiceError.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ModelServiceError.js +37 -5
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts +8 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +38 -3
- package/dist/vendor/codali/providers/ProviderTypes.d.ts +9 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/vendor/codali/providers/RequestSize.d.ts +5 -0
- package/dist/vendor/codali/providers/RequestSize.d.ts.map +1 -0
- package/dist/vendor/codali/providers/RequestSize.js +10 -0
- package/dist/vendor/codali/providers/RequestUsage.d.ts +11 -0
- package/dist/vendor/codali/providers/RequestUsage.d.ts.map +1 -0
- package/dist/vendor/codali/providers/RequestUsage.js +33 -0
- package/dist/vendor/codali/runtime/AnswerVerification.d.ts +31 -0
- package/dist/vendor/codali/runtime/AnswerVerification.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/AnswerVerification.js +65 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +1 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CodaliRuntime.js +1 -0
- package/dist/vendor/codali/runtime/CompletionReport.d.ts +8 -0
- package/dist/vendor/codali/runtime/CompletionReport.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CompletionReport.js +25 -0
- package/dist/vendor/codali/runtime/ComputedAnswer.d.ts +13 -0
- package/dist/vendor/codali/runtime/ComputedAnswer.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ComputedAnswer.js +75 -0
- package/dist/vendor/codali/runtime/ContextCompression.d.ts +41 -0
- package/dist/vendor/codali/runtime/ContextCompression.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ContextCompression.js +292 -0
- package/dist/vendor/codali/runtime/FigureCheck.d.ts +20 -0
- package/dist/vendor/codali/runtime/FigureCheck.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/FigureCheck.js +44 -0
- package/dist/vendor/codali/runtime/GatewayRequest.d.ts +5 -0
- package/dist/vendor/codali/runtime/GatewayRequest.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/GatewayRequest.js +19 -0
- package/dist/vendor/codali/runtime/InspectionBudget.d.ts +11 -0
- package/dist/vendor/codali/runtime/InspectionBudget.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/InspectionBudget.js +23 -0
- package/dist/vendor/codali/runtime/InspectionConvergence.d.ts +24 -0
- package/dist/vendor/codali/runtime/InspectionConvergence.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/InspectionConvergence.js +67 -0
- package/dist/vendor/codali/runtime/InteractionContract.d.ts +51 -0
- package/dist/vendor/codali/runtime/InteractionContract.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/InteractionContract.js +72 -0
- package/dist/vendor/codali/runtime/InteractionRouter.d.ts +73 -0
- package/dist/vendor/codali/runtime/InteractionRouter.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/InteractionRouter.js +139 -0
- package/dist/vendor/codali/runtime/OutageWait.d.ts +14 -0
- package/dist/vendor/codali/runtime/OutageWait.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/OutageWait.js +33 -0
- package/dist/vendor/codali/runtime/PlanCoverage.d.ts +9 -0
- package/dist/vendor/codali/runtime/PlanCoverage.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/PlanCoverage.js +12 -0
- package/dist/vendor/codali/runtime/PreparedDocdex.d.ts +4 -0
- package/dist/vendor/codali/runtime/PreparedDocdex.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/PreparedDocdex.js +55 -0
- package/dist/vendor/codali/runtime/PreparedMemory.d.ts +3 -0
- package/dist/vendor/codali/runtime/PreparedMemory.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/PreparedMemory.js +30 -0
- package/dist/vendor/codali/runtime/ProgressTracker.d.ts +1 -0
- package/dist/vendor/codali/runtime/ProgressTracker.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ProgressTracker.js +25 -5
- package/dist/vendor/codali/runtime/ResearchEvidence.d.ts +25 -0
- package/dist/vendor/codali/runtime/ResearchEvidence.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ResearchEvidence.js +101 -0
- package/dist/vendor/codali/runtime/ReviewContract.d.ts +35 -0
- package/dist/vendor/codali/runtime/ReviewContract.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ReviewContract.js +132 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts +43 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.js +134 -0
- package/dist/vendor/codali/runtime/ReviewSource.d.ts +3 -0
- package/dist/vendor/codali/runtime/ReviewSource.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ReviewSource.js +17 -1
- package/dist/vendor/codali/runtime/Runner.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/Runner.js +6 -1
- package/dist/vendor/codali/runtime/SessionController.d.ts +146 -6
- package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/SessionController.js +2406 -228
- package/dist/vendor/codali/runtime/SpecialistTools.d.ts +8 -0
- package/dist/vendor/codali/runtime/SpecialistTools.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/SpecialistTools.js +85 -0
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts +4 -2
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/StructuralEvidence.js +22 -5
- package/dist/vendor/codali/runtime/TaskReview.d.ts +25 -0
- package/dist/vendor/codali/runtime/TaskReview.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/TaskReview.js +109 -0
- package/dist/vendor/codali/runtime/TaskReviewContext.d.ts +37 -0
- package/dist/vendor/codali/runtime/TaskReviewContext.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/TaskReviewContext.js +18 -2
- package/dist/vendor/codali/runtime/UsageReconciliation.d.ts +28 -0
- package/dist/vendor/codali/runtime/UsageReconciliation.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/UsageReconciliation.js +68 -0
- package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts +15 -0
- package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/VerificationReceiptSelection.js +30 -0
- package/dist/vendor/codali/runtime/WorkspaceLedger.d.ts +2 -0
- package/dist/vendor/codali/runtime/WorkspaceLedger.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/WorkspaceLedger.js +44 -20
- package/dist/vendor/codali/runtime/WorkspaceLock.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/WorkspaceLock.js +9 -1
- package/dist/vendor/codali/runtime/WorkspaceSnapshot.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/WorkspaceSnapshot.js +3 -2
- package/dist/vendor/codali/runtime/WriteSyntaxCheck.d.ts +10 -0
- package/dist/vendor/codali/runtime/WriteSyntaxCheck.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WriteSyntaxCheck.js +34 -0
- package/dist/vendor/codali/session/InstructionLoader.d.ts +5 -1
- package/dist/vendor/codali/session/InstructionLoader.d.ts.map +1 -1
- package/dist/vendor/codali/session/InstructionLoader.js +65 -19
- package/dist/vendor/codali/session/SessionStoragePath.d.ts.map +1 -1
- package/dist/vendor/codali/session/SessionStoragePath.js +34 -17
- package/dist/vendor/codali/session/SessionStore.d.ts +6 -1
- package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -1
- package/dist/vendor/codali/session/SessionStore.js +108 -43
- package/dist/vendor/codali/session/SkillCatalog.d.ts +33 -0
- package/dist/vendor/codali/session/SkillCatalog.d.ts.map +1 -0
- package/dist/vendor/codali/session/SkillCatalog.js +197 -0
- package/dist/vendor/codali/session/WorkState.d.ts +16 -2
- package/dist/vendor/codali/session/WorkState.d.ts.map +1 -1
- package/dist/vendor/codali/session/WorkState.js +55 -5
- package/dist/vendor/codali/session/WorkTypes.d.ts +8 -0
- package/dist/vendor/codali/session/WorkTypes.d.ts.map +1 -1
- package/dist/vendor/codali/session/WorkspaceScope.d.ts +3 -0
- package/dist/vendor/codali/session/WorkspaceScope.d.ts.map +1 -0
- package/dist/vendor/codali/session/WorkspaceScope.js +19 -0
- package/dist/vendor/codali/tools/SemanticToolRetrieval.d.ts +19 -0
- package/dist/vendor/codali/tools/SemanticToolRetrieval.d.ts.map +1 -0
- package/dist/vendor/codali/tools/SemanticToolRetrieval.js +52 -0
- package/dist/vendor/codali/tools/ToolRetrieval.d.ts +7 -0
- package/dist/vendor/codali/tools/ToolRetrieval.d.ts.map +1 -0
- package/dist/vendor/codali/tools/ToolRetrieval.js +25 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts +5 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -1
- package/dist/vendor/codali/tools/browser/BrowserSessionTool.d.ts +16 -0
- package/dist/vendor/codali/tools/browser/BrowserSessionTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/browser/BrowserSessionTool.js +326 -0
- package/dist/vendor/codali/tools/browser/BrowserTool.d.ts +17 -0
- package/dist/vendor/codali/tools/browser/BrowserTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/browser/BrowserTool.js +291 -0
- package/dist/vendor/codali/tools/browser/BrowserWorker.d.ts +2 -0
- package/dist/vendor/codali/tools/browser/BrowserWorker.d.ts.map +1 -0
- package/dist/vendor/codali/tools/browser/BrowserWorker.js +121 -0
- package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts +5 -0
- package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/calculation/CalculatorTool.js +191 -0
- package/dist/vendor/codali/tools/deterministic/DeterministicRuntime.d.ts +39 -0
- package/dist/vendor/codali/tools/deterministic/DeterministicRuntime.d.ts.map +1 -0
- package/dist/vendor/codali/tools/deterministic/DeterministicRuntime.js +98 -0
- package/dist/vendor/codali/tools/deterministic/DeterministicTools.d.ts +8 -0
- package/dist/vendor/codali/tools/deterministic/DeterministicTools.d.ts.map +1 -0
- package/dist/vendor/codali/tools/deterministic/DeterministicTools.js +100 -0
- package/dist/vendor/codali/tools/deterministic/node-worker.cjs +38 -0
- package/dist/vendor/codali/tools/deterministic/python-worker.py +237 -0
- package/dist/vendor/codali/tools/docdex/DocdexCatalogTools.d.ts +4 -0
- package/dist/vendor/codali/tools/docdex/DocdexCatalogTools.d.ts.map +1 -0
- package/dist/vendor/codali/tools/docdex/DocdexCatalogTools.js +59 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts +2 -0
- package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts.map +1 -1
- package/dist/vendor/codali/tools/docdex/DocdexTools.js +81 -106
- package/dist/vendor/codali/tools/documents/DocumentRuntime.d.ts +12 -0
- package/dist/vendor/codali/tools/documents/DocumentRuntime.d.ts.map +1 -0
- package/dist/vendor/codali/tools/documents/DocumentRuntime.js +59 -0
- package/dist/vendor/codali/tools/documents/DocumentTools.d.ts +19 -0
- package/dist/vendor/codali/tools/documents/DocumentTools.d.ts.map +1 -0
- package/dist/vendor/codali/tools/documents/DocumentTools.js +150 -0
- package/dist/vendor/codali/tools/documents/worker.py +267 -0
- package/dist/vendor/codali/tools/entities/AdesTool.d.ts +7 -0
- package/dist/vendor/codali/tools/entities/AdesTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/entities/AdesTool.js +59 -0
- package/dist/vendor/codali/tools/filesystem/FileTools.d.ts.map +1 -1
- package/dist/vendor/codali/tools/filesystem/FileTools.js +62 -11
- package/dist/vendor/codali/tools/research/TnlTool.d.ts +22 -0
- package/dist/vendor/codali/tools/research/TnlTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/research/TnlTool.js +246 -0
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts +4 -0
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/AsyncProcess.js +9 -3
- package/dist/vendor/codali/tools/shell/HostToolchain.d.ts +7 -0
- package/dist/vendor/codali/tools/shell/HostToolchain.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/HostToolchain.js +65 -4
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts +5 -2
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.js +148 -29
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts +2 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/ShellTool.js +19 -4
- package/dist/vendor/codali/tools/system/CalendarTool.d.ts +15 -0
- package/dist/vendor/codali/tools/system/CalendarTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/system/CalendarTool.js +44 -0
- package/dist/vendor/codali/tools/system/TextTool.d.ts +4 -0
- package/dist/vendor/codali/tools/system/TextTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/system/TextTool.js +39 -0
- package/dist/vendor/codali/tools/system/TimeTool.d.ts +4 -0
- package/dist/vendor/codali/tools/system/TimeTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/system/TimeTool.js +22 -0
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.d.ts +47 -0
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.js +71 -0
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationWorker.d.ts +2 -0
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationWorker.d.ts.map +1 -0
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationWorker.js +91 -0
- package/dist/vendor/codali/tools/verification/VitestTool.d.ts +6 -0
- package/dist/vendor/codali/tools/verification/VitestTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/verification/VitestTool.js +184 -0
- package/dist/vendor/config/AGENTS.md +17 -0
- package/dist/vendor/config/deterministic/install-python.mjs +16 -0
- package/dist/vendor/config/deterministic/node-worker.mjs +77 -0
- package/dist/vendor/config/deterministic/python-worker.py +237 -0
- package/dist/vendor/config/deterministic/requirements.txt +6 -0
- package/dist/vendor/config/docdex-runtime.json +21 -0
- package/dist/vendor/config/docdex-tools-0.2.99.json +3977 -0
- package/dist/vendor/config/documents/install-python.mjs +16 -0
- package/dist/vendor/config/documents/requirements.txt +10 -0
- package/dist/vendor/config/documents/worker.py +267 -0
- package/dist/vendor/config/skills/architecture-design/SKILL.md +14 -0
- package/dist/vendor/config/skills/browser-session/SKILL.md +16 -0
- package/dist/vendor/config/skills/browser-use/SKILL.md +14 -0
- package/dist/vendor/config/skills/code-implementation/SKILL.md +18 -0
- package/dist/vendor/config/skills/code-review/SKILL.md +14 -0
- package/dist/vendor/config/skills/docdex-research/SKILL.md +18 -0
- package/dist/vendor/config/skills/docdex-research/references/catalog.md +111 -0
- package/dist/vendor/config/skills/docdex-research/references/memory.md +22 -0
- package/dist/vendor/config/skills/docdex-research/references/operations.md +19 -0
- package/dist/vendor/config/skills/docdex-research/references/retrieval.md +13 -0
- package/dist/vendor/config/skills/planning/SKILL.md +14 -0
- package/dist/vendor/config/skills/system-diagnostics/SKILL.md +14 -0
- package/dist/vendor/config/skills/system-services/SKILL.md +17 -0
- package/dist/vendor/config/skills/system-services/references/docker.md +11 -0
- package/dist/vendor/config/skills/system-services/references/linux.md +9 -0
- package/dist/vendor/config/skills/system-services/references/macos.md +9 -0
- package/dist/vendor/config/skills/systematic-debugging/SKILL.md +14 -0
- package/dist/vendor/config/skills/testing-and-verification/SKILL.md +16 -0
- package/dist/vendor/config/skills/tool-selection/SKILL.md +16 -0
- package/dist/vendor/config/skills/ui-ux-design/SKILL.md +16 -0
- package/dist/vendor/config/skills/ui-ux-design/references/validation.md +13 -0
- package/dist/vendor/config/skills/webapp-testing/SKILL.md +12 -0
- package/package.json +15 -5
- package/scripts/media_gpu_lock.py +2 -2
- package/scripts/native_load_guard.py +257 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { effortBudget, pinOrchestrationConfig, resolveBinding } from "../config/OrchestrationConfig.js";
|
|
3
3
|
import { ConfiguredProvider, normalizeModelCaller } from "./ConfiguredProvider.js";
|
|
4
|
+
import { ModelServiceError } from "./ModelServiceError.js";
|
|
5
|
+
import { estimateProviderInputTokens } from "./RequestSize.js";
|
|
4
6
|
/** Invalid upstream accounting cannot lower a shared budget or turn it into NaN. */
|
|
5
7
|
export const verifiedTokenUsage = (usage) => {
|
|
6
8
|
const valid = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
@@ -20,6 +22,7 @@ export class ConfiguredModelScope {
|
|
|
20
22
|
constructor(resolved, options = {}) {
|
|
21
23
|
this.controller = new AbortController();
|
|
22
24
|
this.pending = new Map();
|
|
25
|
+
this.invocationIds = new Set();
|
|
23
26
|
this.toolCalls = 0;
|
|
24
27
|
this.usage = { modelCalls: 0, inputTokens: 0, outputTokens: 0, totalTokens: 0, estimated: false, pendingCalls: 0 };
|
|
25
28
|
this.id = randomUUID();
|
|
@@ -70,10 +73,13 @@ export class ConfiguredModelScope {
|
|
|
70
73
|
effort: this.options.effort,
|
|
71
74
|
beforeRequest: async (route, bounded) => {
|
|
72
75
|
linked.signal.throwIfAborted();
|
|
73
|
-
|
|
76
|
+
if (this.invocationIds.has(route.id))
|
|
77
|
+
throw new Error("Model requestId has already been used in this scope; use a new UUID for each inference attempt");
|
|
78
|
+
const reservation = estimateProviderInputTokens(bounded) + (bounded.maxTokens ?? this.limits.maxOutputTokens);
|
|
74
79
|
if (this.usage.modelCalls >= this.limits.maxModelCalls || this.usage.totalTokens + reservation > this.limits.maxTotalTokens)
|
|
75
80
|
throw new Error("Shared model budget exhausted");
|
|
76
81
|
invocation = route;
|
|
82
|
+
this.invocationIds.add(route.id);
|
|
77
83
|
this.usage.modelCalls++;
|
|
78
84
|
this.usage.totalTokens += reservation;
|
|
79
85
|
this.pending.set(route.id, reservation);
|
|
@@ -100,7 +106,18 @@ export class ConfiguredModelScope {
|
|
|
100
106
|
catch (error) {
|
|
101
107
|
// A submitted request is never replayed; an unknown bill keeps its reservation.
|
|
102
108
|
if (invocation && this.pending.has(invocation.id)) {
|
|
103
|
-
this.
|
|
109
|
+
const configured = this.resolved.config.providers[this.resolved.config.models[invocation.modelId].provider];
|
|
110
|
+
const nativeRefusal = configured.adapter === "openai-compatible"
|
|
111
|
+
&& ["127.0.0.1", "localhost", "[::1]"].includes(new URL(configured.baseUrl).hostname)
|
|
112
|
+
&& error instanceof ModelServiceError && error.status === 400 && error.nativeContextRefused;
|
|
113
|
+
if (nativeRefusal) {
|
|
114
|
+
// This exact native response precedes generation. Settle only this
|
|
115
|
+
// reservation; earlier usage and uncertain concurrent calls survive.
|
|
116
|
+
this.usage.totalTokens -= this.pending.get(invocation.id);
|
|
117
|
+
this.pending.delete(invocation.id);
|
|
118
|
+
}
|
|
119
|
+
else
|
|
120
|
+
this.usage.estimated = true;
|
|
104
121
|
await this.options.onEvent?.({ type: "receipt", id: invocation.id, binding, configHash: this.resolved.hash, route: invocation, status: "failed", usage: this.snapshot() });
|
|
105
122
|
}
|
|
106
123
|
throw error;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type OrchestrationProvider, type ResolvedOrchestrationConfig, type ModelOperation, type EffortLevel } from "../config/OrchestrationConfig.js";
|
|
2
|
+
import { type RequestUsageReceipt } from "./RequestUsage.js";
|
|
2
3
|
import type { Provider, ProviderRequest, ProviderResponse } from "./ProviderTypes.js";
|
|
3
4
|
export interface CatalogEntry {
|
|
4
5
|
id: string;
|
|
@@ -18,7 +19,10 @@ export interface ModelCallerContext {
|
|
|
18
19
|
export declare const normalizeModelCaller: (caller?: ModelCallerContext) => ModelCallerContext;
|
|
19
20
|
/** Discovery failed before inference; a caller may release its local token reservation. */
|
|
20
21
|
export declare class NativeReasoningTransportError extends Error {
|
|
21
|
-
|
|
22
|
+
readonly cause?: unknown;
|
|
23
|
+
constructor(message: string, options?: {
|
|
24
|
+
cause?: unknown;
|
|
25
|
+
});
|
|
22
26
|
}
|
|
23
27
|
export declare const providerCredential: (provider: OrchestrationProvider) => Promise<string | undefined>;
|
|
24
28
|
export declare class ModelServiceClient {
|
|
@@ -34,8 +38,12 @@ export declare class ModelServiceClient {
|
|
|
34
38
|
body?: unknown;
|
|
35
39
|
timeoutMs?: number;
|
|
36
40
|
}): Promise<unknown>;
|
|
41
|
+
/** Retry only read-only discovery on explicit temporary service failures.
|
|
42
|
+
* Never reuse this for submission, reconciliation mutations or auth denials. */
|
|
43
|
+
private discoveryJson;
|
|
37
44
|
catalog(signal?: AbortSignal, refresh?: boolean): Promise<CatalogEntry[]>;
|
|
38
45
|
usage(signal?: AbortSignal): Promise<unknown>;
|
|
46
|
+
requestUsage(requestId: string, signal?: AbortSignal): Promise<RequestUsageReceipt>;
|
|
39
47
|
/** The proxy and selected node must both advertise this transport contract.
|
|
40
48
|
* A model's supports_reasoning flag alone says nothing about request forwarding. */
|
|
41
49
|
requireNativeReasoning(modelId: string, parameters: string[], signal?: AbortSignal): Promise<void>;
|
|
@@ -48,6 +56,7 @@ export interface ModelInvocation {
|
|
|
48
56
|
catalogId: string;
|
|
49
57
|
backend?: string;
|
|
50
58
|
host?: string;
|
|
59
|
+
resolvedCatalogId?: string;
|
|
51
60
|
nativeReasoningRequest?: Record<string, unknown>;
|
|
52
61
|
}
|
|
53
62
|
export declare class ConfiguredProvider implements Provider {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfiguredProvider.d.ts","sourceRoot":"","sources":["../../src/providers/ConfiguredProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ConfiguredProvider.d.ts","sourceRoot":"","sources":["../../src/providers/ConfiguredProvider.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
3
4
|
import { CryptoHelper, PathHelper, mswarmClientProductHeaders } from "@mcoda/shared";
|
|
4
5
|
import { resolveCredential } from "../runcontext/CredentialFile.js";
|
|
5
6
|
import { resolveBinding } from "../config/OrchestrationConfig.js";
|
|
6
7
|
import { OpenAiCompatibleProvider } from "./OpenAiCompatibleProvider.js";
|
|
7
8
|
import { ModelServiceError } from "./ModelServiceError.js";
|
|
9
|
+
import { parseRequestUsage } from "./RequestUsage.js";
|
|
8
10
|
import { registerSecretValue } from "../runtime/SecretRedaction.js";
|
|
11
|
+
import { estimateProviderInputTokens } from "./RequestSize.js";
|
|
9
12
|
export const normalizeModelCaller = (caller = {}) => {
|
|
10
13
|
const clientIdentity = caller.clientIdentity?.trim();
|
|
11
14
|
const clientProduct = caller.clientProduct?.trim().toLowerCase() ?? "codali";
|
|
@@ -22,8 +25,9 @@ const modelCallerHeaders = (caller) => ({
|
|
|
22
25
|
const record = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
23
26
|
/** Discovery failed before inference; a caller may release its local token reservation. */
|
|
24
27
|
export class NativeReasoningTransportError extends Error {
|
|
25
|
-
constructor(message) { super(message); this.name = "NativeReasoningTransportError"; }
|
|
28
|
+
constructor(message, options) { super(message); this.name = "NativeReasoningTransportError"; this.cause = options?.cause; }
|
|
26
29
|
}
|
|
30
|
+
const advertisedOutput = (entry) => typeof entry.raw.max_output_tokens === "number" && entry.raw.max_output_tokens > 0 ? entry.raw.max_output_tokens : undefined;
|
|
27
31
|
export const providerCredential = async (provider) => {
|
|
28
32
|
if (!provider.credentialRef)
|
|
29
33
|
return undefined;
|
|
@@ -107,25 +111,46 @@ export class ModelServiceClient {
|
|
|
107
111
|
options.signal?.removeEventListener("abort", abort);
|
|
108
112
|
}
|
|
109
113
|
}
|
|
114
|
+
/** Retry only read-only discovery on explicit temporary service failures.
|
|
115
|
+
* Never reuse this for submission, reconciliation mutations or auth denials. */
|
|
116
|
+
async discoveryJson(url, signal) {
|
|
117
|
+
for (let attempt = 0;; attempt++) {
|
|
118
|
+
signal?.throwIfAborted();
|
|
119
|
+
try {
|
|
120
|
+
return await this.json(url, { signal });
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
signal?.throwIfAborted();
|
|
124
|
+
if (!(error instanceof ModelServiceError) || error.code !== "service_unavailable" || attempt >= 2)
|
|
125
|
+
throw error;
|
|
126
|
+
const retryAfterMs = (error.retryAfterSeconds ?? 0) * 1000;
|
|
127
|
+
if (retryAfterMs > 5000)
|
|
128
|
+
throw error;
|
|
129
|
+
await delay(Math.max(attempt === 0 ? 250 : 750, retryAfterMs), undefined, { signal });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
110
133
|
async catalog(signal, refresh = false) {
|
|
111
134
|
const credential = await this.credential();
|
|
112
135
|
const key = createHash("sha256").update(credential ?? "anonymous").digest("hex");
|
|
113
136
|
if (!refresh && this.cache?.key === key && this.cache.expires > Date.now())
|
|
114
137
|
return this.cache.entries;
|
|
115
138
|
const base = new URL(this.provider.baseUrl);
|
|
116
|
-
const url = this.provider.catalogUrl ?? (this.provider.adapter === "mswarm" ? new URL("/v1/swarm/self-hosted/agents", base).toString() : `${this.provider.baseUrl.replace(/\/$/, "")}/models`);
|
|
117
|
-
const payload = record(await this.
|
|
139
|
+
const url = this.provider.catalogUrl ?? (this.provider.adapter === "mswarm" ? new URL("/v1/swarm/self-hosted/agents?include_load_balanced=true", base).toString() : `${this.provider.baseUrl.replace(/\/$/, "")}/models`);
|
|
140
|
+
const payload = record(await this.discoveryJson(url, signal));
|
|
118
141
|
const items = payload.agents ?? payload.data;
|
|
119
142
|
if (!Array.isArray(items))
|
|
120
143
|
throw new Error("Invalid model catalog response");
|
|
121
144
|
const entries = items.map(item => {
|
|
122
145
|
const raw = record(item);
|
|
123
|
-
const aliases = [raw.slug, raw.public_model_id, raw.default_model, raw.id].filter((v) => typeof v === "string" && !!v);
|
|
146
|
+
const aliases = [raw.slug, raw.public_model_id, raw.default_model, raw.id, ...(raw.pool_scope === "owner" ? [raw.canonical_model_id] : [])].filter((v) => typeof v === "string" && !!v);
|
|
124
147
|
return { id: aliases[0] ?? "", aliases, backend: raw.adapter === "strata-local" ? "strata" : typeof raw.backend === "string" ? raw.backend : typeof raw.adapter === "string" ? raw.adapter : undefined,
|
|
125
148
|
health: String(raw.health_status ?? "unknown"), supportsTools: raw.supports_tools === true,
|
|
126
149
|
contextWindow: typeof raw.context_window === "number" ? raw.context_window : undefined,
|
|
127
150
|
operations: Array.isArray(raw.operations) ? raw.operations.map(v => typeof v === "string" ? v : String(record(v).type ?? "")) : [], raw };
|
|
128
151
|
}).filter(x => x.id);
|
|
152
|
+
entries.sort((a, b) => Number(b.raw.pool_scope === "owner") - Number(a.raw.pool_scope === "owner")
|
|
153
|
+
|| Number(b.raw.member_count ?? 0) - Number(a.raw.member_count ?? 0) || a.id.localeCompare(b.id));
|
|
129
154
|
this.cache = { key, expires: Date.now() + 30000, entries };
|
|
130
155
|
return entries;
|
|
131
156
|
}
|
|
@@ -134,6 +159,14 @@ export class ModelServiceClient {
|
|
|
134
159
|
return { available: false };
|
|
135
160
|
return this.json(this.provider.usageUrl ?? new URL("/v1/swarm/runtime/usage-limits", this.provider.baseUrl).toString(), { signal });
|
|
136
161
|
}
|
|
162
|
+
async requestUsage(requestId, signal) {
|
|
163
|
+
if (this.provider.adapter !== "mswarm")
|
|
164
|
+
throw new Error("Provider has no authenticated request receipt contract");
|
|
165
|
+
if (!/^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i.test(requestId))
|
|
166
|
+
throw new Error("Invalid request UUID");
|
|
167
|
+
const url = new URL(`/v1/swarm/self-hosted/requests/${encodeURIComponent(requestId)}/receipts`, this.provider.baseUrl);
|
|
168
|
+
return parseRequestUsage(requestId, await this.json(url.href, { signal, timeoutMs: 10000 }));
|
|
169
|
+
}
|
|
137
170
|
/** The proxy and selected node must both advertise this transport contract.
|
|
138
171
|
* A model's supports_reasoning flag alone says nothing about request forwarding. */
|
|
139
172
|
async requireNativeReasoning(modelId, parameters, signal) {
|
|
@@ -143,8 +176,10 @@ export class ModelServiceClient {
|
|
|
143
176
|
endpoint.pathname = endpoint.pathname.replace(/\/$/, "");
|
|
144
177
|
endpoint.pathname = ["", "/v1"].includes(endpoint.pathname)
|
|
145
178
|
? "/v1/swarm/self-hosted/openai/models" : `${endpoint.pathname}/models`;
|
|
146
|
-
const payload = record(await this.
|
|
147
|
-
|
|
179
|
+
const payload = record(await this.discoveryJson(endpoint.href, signal).catch(error => {
|
|
180
|
+
// Keep the service error as the cause so the controller can tell a
|
|
181
|
+
// temporary outage from a real contract mismatch and wait it out.
|
|
182
|
+
throw new NativeReasoningTransportError(`Native reasoning preflight failed before inference: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
148
183
|
}));
|
|
149
184
|
const models = Array.isArray(payload.data) ? payload.data.map(record) : [];
|
|
150
185
|
const model = models.find(item => [item.id, item.agent_slug, item.remote_slug].includes(modelId));
|
|
@@ -182,57 +217,89 @@ export class ConfiguredProvider {
|
|
|
182
217
|
async select(operation, signal, requireTools = false) {
|
|
183
218
|
const candidates = resolveBinding(this.resolved.config, this.binding, operation);
|
|
184
219
|
const reasons = [];
|
|
220
|
+
const refreshed = new Set();
|
|
185
221
|
for (const candidate of candidates) {
|
|
186
222
|
const { id, model } = candidate;
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
223
|
+
const client = this.client(model.provider);
|
|
224
|
+
let catalog = await client.catalog(signal);
|
|
225
|
+
for (;;) {
|
|
226
|
+
// A canonical model alias can identify several pools/backends. Inspect
|
|
227
|
+
// every matching entry, but never widen an explicitly pinned pool ID.
|
|
228
|
+
const exact = catalog.filter(entry => entry.id === model.catalogId);
|
|
229
|
+
// An alias can also resolve to a pool that advertises less context or
|
|
230
|
+
// output than this model is configured for; such a pool cut answers at
|
|
231
|
+
// 8,192 tokens while 40,960 were requested. Routes that meet the
|
|
232
|
+
// configured limits go first; the order is otherwise unchanged.
|
|
233
|
+
const meetsLimits = (entry) => (entry.contextWindow ?? Infinity) >= model.contextWindow && (advertisedOutput(entry) ?? Infinity) >= model.maxOutputTokens;
|
|
234
|
+
const aliased = exact.length ? exact : catalog.filter(entry => entry.aliases.includes(model.catalogId));
|
|
235
|
+
const matches = [...aliased.filter(meetsLimits), ...aliased.filter(entry => !meetsLimits(entry))];
|
|
236
|
+
let transient = false;
|
|
237
|
+
const failures = [];
|
|
238
|
+
for (const actual of matches) {
|
|
239
|
+
if (model.backend && actual.backend !== model.backend) {
|
|
240
|
+
failures.push("backend identity not verified");
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (actual.operations.length && !actual.operations.includes(operation)) {
|
|
244
|
+
failures.push("unsupported operation");
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (requireTools && (!model.supportsTools || this.resolved.config.providers[model.provider].adapter === "mswarm" && !actual.supportsTools)) {
|
|
248
|
+
failures.push("tools unavailable");
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (!["healthy", "unknown", "ready"].includes(actual.health)) {
|
|
252
|
+
failures.push(actual.health);
|
|
253
|
+
transient || (transient = ["unreachable", "unhealthy", "offline"].includes(actual.health));
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
return { id, model, actual, provider: this.resolved.config.providers[model.provider] };
|
|
257
|
+
}
|
|
258
|
+
// Revalidate temporary health once instead of failing from a stale
|
|
259
|
+
// 30-second cache. Entitlement/quota/capability denials remain final.
|
|
260
|
+
if (transient && !refreshed.has(model.provider)) {
|
|
261
|
+
refreshed.add(model.provider);
|
|
262
|
+
catalog = await client.catalog(signal, true);
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
reasons.push(`${id}: ${failures.join(", ") || "not entitled/advertised"}`);
|
|
266
|
+
break;
|
|
208
267
|
}
|
|
209
|
-
return { id, model, actual, provider: this.resolved.config.providers[model.provider] };
|
|
210
268
|
}
|
|
211
269
|
throw new Error(`No eligible configured ${this.binding} route: ${reasons.join("; ")}`);
|
|
212
270
|
}
|
|
213
271
|
async generate(request) {
|
|
214
272
|
request.signal?.throwIfAborted();
|
|
273
|
+
const requestId = request.requestId ?? randomUUID();
|
|
274
|
+
if (typeof requestId !== "string" || !/^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i.test(requestId)) {
|
|
275
|
+
throw new Error("Model requestId must be a UUID for this inference attempt");
|
|
276
|
+
}
|
|
215
277
|
const { id, model, provider, actual } = await this.select("chat.completions", request.signal, !!request.tools?.length);
|
|
216
|
-
const invocation = { id:
|
|
278
|
+
const invocation = { id: requestId, binding: this.binding, configHash: this.resolved.hash, modelId: id, catalogId: model.catalogId, resolvedCatalogId: actual.id, backend: actual.backend, host: model.host };
|
|
217
279
|
const nativeReasoning = this.options.effort ? model.reasoning?.[this.options.effort] : undefined;
|
|
218
280
|
if (nativeReasoning)
|
|
219
281
|
invocation.nativeReasoningRequest = { ...nativeReasoning };
|
|
220
282
|
if (nativeReasoning)
|
|
221
|
-
await this.client(model.provider).requireNativeReasoning(
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
if (
|
|
283
|
+
await this.client(model.provider).requireNativeReasoning(actual.id, Object.keys(nativeReasoning), request.signal);
|
|
284
|
+
const inputEstimate = estimateProviderInputTokens(request);
|
|
285
|
+
const available = Math.floor(Math.min(model.contextWindow, actual.contextWindow ?? model.contextWindow) - inputEstimate);
|
|
286
|
+
if (available < 128)
|
|
225
287
|
throw new Error("Context budget exceeded; checkpoint and compact before continuing");
|
|
226
|
-
|
|
288
|
+
// Ask only for what the selected route advertises: a larger request is cut
|
|
289
|
+
// at the route's own limit and still reported as a normal finish.
|
|
290
|
+
const maxTokens = Math.min(request.maxTokens ?? model.maxOutputTokens, model.maxOutputTokens, available, advertisedOutput(actual) ?? Infinity);
|
|
291
|
+
const bounded = { ...request, requestId, maxTokens, stream: request.stream === true && model.supportsStreaming === true };
|
|
227
292
|
await this.options.beforeRequest?.(invocation, bounded);
|
|
228
293
|
const adapter = new OpenAiCompatibleProvider({
|
|
229
|
-
model: model.catalogId, baseUrl: provider.baseUrl, apiKey: this.credentials[model.provider] ?? await providerCredential(provider), timeoutMs:
|
|
294
|
+
model: provider.adapter === "mswarm" ? actual.id : model.catalogId, baseUrl: provider.baseUrl, apiKey: this.credentials[model.provider] ?? await providerCredential(provider), timeoutMs: 86400000,
|
|
230
295
|
supportsStreaming: model.supportsStreaming ?? true, supportsTools: model.supportsTools,
|
|
231
|
-
headers: provider.adapter === "mswarm" ? modelCallerHeaders(this.caller) : undefined, retryTransient: false,
|
|
296
|
+
headers: provider.adapter === "mswarm" ? { ...modelCallerHeaders(this.caller), "x-request-id": requestId } : undefined, retryTransient: false,
|
|
232
297
|
extraBody: nativeReasoning,
|
|
233
298
|
});
|
|
234
299
|
const result = await adapter.generate(bounded);
|
|
235
300
|
await this.options.afterRequest?.(invocation, result);
|
|
236
|
-
|
|
301
|
+
const calls = result.toolCalls ?? result.message.toolCalls ?? [];
|
|
302
|
+
const outputLimited = !calls.length && typeof result.usage?.outputTokens === "number" && result.usage.outputTokens >= maxTokens;
|
|
303
|
+
return { ...result, ...(outputLimited ? { outputLimited } : {}), route: invocation };
|
|
237
304
|
}
|
|
238
305
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ModelServiceError } from "./ModelServiceError.js";
|
|
2
|
+
import type { ProviderRequest, ProviderResponse } from "./ProviderTypes.js";
|
|
3
|
+
export declare const MODEL_CAPACITY_WAIT_MS: number;
|
|
4
|
+
/** An explicit shared-pool refusal: the service rejected the request before any
|
|
5
|
+
* inference ran, so it costs nothing and waiting is the correct response. */
|
|
6
|
+
export declare const isCapacityRefusal: (error: unknown) => error is ModelServiceError;
|
|
7
|
+
/** Delay before the next capacity retry, or undefined when waiting should stop.
|
|
8
|
+
* Long Retry-After values remain refusals rather than silent multi-minute stalls. */
|
|
9
|
+
export declare function capacityRetryDelayMs(error: unknown, attempt: number, waitedMs: number, maxWaitMs?: number, random?: () => number): number | undefined;
|
|
10
|
+
/** Shared capacity policy for callers without Codali's session recovery, so a
|
|
11
|
+
* comparison arm is not failed by contention the other arm waits through. */
|
|
12
|
+
export declare function generateWithCapacityWait(generate: (request: ProviderRequest) => Promise<ProviderResponse>, request: ProviderRequest, options?: {
|
|
13
|
+
maxWaitMs?: number;
|
|
14
|
+
onWait?: (details: {
|
|
15
|
+
attempt: number;
|
|
16
|
+
waitMs: number;
|
|
17
|
+
waitedMs: number;
|
|
18
|
+
error: ModelServiceError;
|
|
19
|
+
}) => void | Promise<void>;
|
|
20
|
+
}): Promise<ProviderResponse>;
|
|
21
|
+
//# sourceMappingURL=ModelCapacityWait.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelCapacityWait.d.ts","sourceRoot":"","sources":["../../src/providers/ModelCapacityWait.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE5E,eAAO,MAAM,sBAAsB,QAAc,CAAC;AAIlD;6EAC6E;AAC7E,eAAO,MAAM,iBAAiB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,iBAC4C,CAAC;AAEzG;qFACqF;AACrF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,SAAyB,EAAE,MAAM,eAAc,GAAG,MAAM,GAAG,SAAS,CAOpK;AAED;6EAC6E;AAC7E,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,gBAAgB,CAAC,EAAE,OAAO,EAAE,eAAe,EACxI,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,iBAAiB,CAAA;KAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAa9L"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
2
|
+
import { ModelServiceError } from "./ModelServiceError.js";
|
|
3
|
+
export const MODEL_CAPACITY_WAIT_MS = 30 * 60000;
|
|
4
|
+
const MAX_HONORED_RETRY_AFTER_SECONDS = 30;
|
|
5
|
+
const MAX_BACKOFF_MS = 60000;
|
|
6
|
+
/** An explicit shared-pool refusal: the service rejected the request before any
|
|
7
|
+
* inference ran, so it costs nothing and waiting is the correct response. */
|
|
8
|
+
export const isCapacityRefusal = (error) => error instanceof ModelServiceError
|
|
9
|
+
&& error.code === "rate_limited" && (error.responseReason === "capacity_busy" || error.status === 429);
|
|
10
|
+
/** Delay before the next capacity retry, or undefined when waiting should stop.
|
|
11
|
+
* Long Retry-After values remain refusals rather than silent multi-minute stalls. */
|
|
12
|
+
export function capacityRetryDelayMs(error, attempt, waitedMs, maxWaitMs = MODEL_CAPACITY_WAIT_MS, random = Math.random) {
|
|
13
|
+
if (!isCapacityRefusal(error))
|
|
14
|
+
return undefined;
|
|
15
|
+
const retryAfter = error.retryAfterSeconds ?? 0;
|
|
16
|
+
if (retryAfter > MAX_HONORED_RETRY_AFTER_SECONDS)
|
|
17
|
+
return undefined;
|
|
18
|
+
const backoff = Math.min(MAX_BACKOFF_MS, 2000 * 2 ** Math.min(attempt, 10)) * (0.75 + random() * 0.5);
|
|
19
|
+
const waitMs = Math.round(Math.max(backoff, retryAfter * 1000));
|
|
20
|
+
return waitedMs + waitMs > maxWaitMs ? undefined : waitMs;
|
|
21
|
+
}
|
|
22
|
+
/** Shared capacity policy for callers without Codali's session recovery, so a
|
|
23
|
+
* comparison arm is not failed by contention the other arm waits through. */
|
|
24
|
+
export async function generateWithCapacityWait(generate, request, options = {}) {
|
|
25
|
+
let waitedMs = 0;
|
|
26
|
+
for (let attempt = 0;; attempt++) {
|
|
27
|
+
try {
|
|
28
|
+
return await generate(request);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
const waitMs = capacityRetryDelayMs(error, attempt, waitedMs, options.maxWaitMs);
|
|
32
|
+
if (waitMs === undefined)
|
|
33
|
+
throw error;
|
|
34
|
+
request.signal?.throwIfAborted();
|
|
35
|
+
await options.onWait?.({ attempt: attempt + 1, waitMs, waitedMs, error: error });
|
|
36
|
+
await delay(waitMs, undefined, { signal: request.signal });
|
|
37
|
+
waitedMs += waitMs;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
export type ModelServiceErrorCode = "authentication_failed" | "entitlement_missing" | "quota_exhausted" | "rate_limited" | "service_unavailable" | "model_unavailable" | "invalid_request";
|
|
1
|
+
export type ModelServiceErrorCode = "authentication_failed" | "entitlement_missing" | "quota_exhausted" | "rate_limited" | "service_unavailable" | "model_unavailable" | "invalid_request" | "request_conflict" | "invalid_response" | "context_length_exceeded";
|
|
2
2
|
/** Transport diagnostics contain stable classifications, never an upstream body. */
|
|
3
3
|
export declare class ModelServiceError extends Error {
|
|
4
4
|
readonly code: ModelServiceErrorCode;
|
|
5
5
|
readonly status: number;
|
|
6
6
|
readonly retryAfterSeconds?: number | undefined;
|
|
7
|
-
|
|
7
|
+
readonly nativeContextRefused: boolean;
|
|
8
|
+
readonly responseReason?: "output_limit" | "incomplete_stream" | "capacity_busy" | undefined;
|
|
9
|
+
/** A rejected completion can still carry real usage and recoverable prose.
|
|
10
|
+
* Partial tool arguments are deliberately never exposed for execution. */
|
|
11
|
+
responseUsage?: {
|
|
12
|
+
inputTokens?: number;
|
|
13
|
+
outputTokens?: number;
|
|
14
|
+
totalTokens?: number;
|
|
15
|
+
};
|
|
16
|
+
partialText?: string;
|
|
17
|
+
/** Set by Runner, not inferred from an HTTP status or upstream payload. */
|
|
18
|
+
completedModelCalls?: number;
|
|
19
|
+
constructor(code: ModelServiceErrorCode, status: number, retryAfterSeconds?: number | undefined, nativeContextRefused?: boolean, responseReason?: "output_limit" | "incomplete_stream" | "capacity_busy" | undefined);
|
|
20
|
+
/** A relay may already have sent HTTP 200 headers when the model fails. */
|
|
21
|
+
static fromRelayError(error: unknown): ModelServiceError | undefined;
|
|
8
22
|
static fromResponse(response: Response): Promise<ModelServiceError>;
|
|
9
23
|
}
|
|
10
24
|
//# sourceMappingURL=ModelServiceError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelServiceError.d.ts","sourceRoot":"","sources":["../../src/providers/ModelServiceError.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,GAAG,qBAAqB,GAAG,iBAAiB,GAAG,cAAc,GAAG,qBAAqB,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"ModelServiceError.d.ts","sourceRoot":"","sources":["../../src/providers/ModelServiceError.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,GAAG,qBAAqB,GAAG,iBAAiB,GAAG,cAAc,GAAG,qBAAqB,GAAG,mBAAmB,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,yBAAyB,CAAC;AAUjQ,oFAAoF;AACpF,qBAAa,iBAAkB,SAAQ,KAAK;IAO9B,QAAQ,CAAC,IAAI,EAAE,qBAAqB;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM;IAC5G,QAAQ,CAAC,oBAAoB;IAAU,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,GAAG,mBAAmB,GAAG,eAAe;IAPzH;8EAC0E;IAC1E,aAAa,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,mBAAmB,CAAC,EAAE,MAAM,CAAC;gBACR,IAAI,EAAE,qBAAqB,EAAW,MAAM,EAAE,MAAM,EAAW,iBAAiB,CAAC,EAAE,MAAM,YAAA,EACnG,oBAAoB,UAAQ,EAAW,cAAc,CAAC,EAAE,cAAc,GAAG,mBAAmB,GAAG,eAAe,YAAA;IAOzH,2EAA2E;IAC3E,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,GAAG,SAAS;WAOvD,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA6B1E"}
|
|
@@ -1,14 +1,40 @@
|
|
|
1
|
+
function nativeContextRefusal(error) {
|
|
2
|
+
if (error.type !== "invalid_request_error" || typeof error.message !== "string" || error.message.length > 1024)
|
|
3
|
+
return false;
|
|
4
|
+
// Strata currently emits this pre-generation refusal without a machine code.
|
|
5
|
+
// Match only its bounded numeric diagnostics; never retain prompt text.
|
|
6
|
+
return /^request exceeds the context window: prompt \(\d{1,10} tokens\) leaves no room to answer in the context \(\d{1,10}\); requests are never truncated$/.test(error.message)
|
|
7
|
+
|| /^request exceeds the context window: prompt \(\d{1,10} tokens\) \+ max tokens \(\d{1,10}\) exceeds the context \(\d{1,10}\); requests are never truncated\. Send a smaller max_tokens \(at most \d{1,10} here\), or add "fit_max_tokens": true to the model's strata-<model>\.json to shorten it to the room left \(#545\)$/.test(error.message);
|
|
8
|
+
}
|
|
1
9
|
/** Transport diagnostics contain stable classifications, never an upstream body. */
|
|
2
10
|
export class ModelServiceError extends Error {
|
|
3
|
-
constructor(code, status, retryAfterSeconds) {
|
|
4
|
-
super(`Model service HTTP ${status}: ${code}${code === "authentication_failed" ? "; authenticate with codali login" : ""}`);
|
|
11
|
+
constructor(code, status, retryAfterSeconds, nativeContextRefused = false, responseReason) {
|
|
12
|
+
super(`Model service HTTP ${status}: ${code}${responseReason === "output_limit" ? "; the model reached its per-response output limit before finishing. No partial tool call was executed; continue with smaller file patches" : responseReason === "incomplete_stream" ? "; the response stream ended before completion. No partial tool call was executed" : code === "authentication_failed" ? "; authenticate with codali login" : code === "context_length_exceeded" ? "; checkpoint and reduce context before continuing" : ""}`);
|
|
5
13
|
this.code = code;
|
|
6
14
|
this.status = status;
|
|
7
15
|
this.retryAfterSeconds = retryAfterSeconds;
|
|
16
|
+
this.nativeContextRefused = nativeContextRefused;
|
|
17
|
+
this.responseReason = responseReason;
|
|
8
18
|
this.name = "ModelServiceError";
|
|
19
|
+
if (responseReason === "capacity_busy")
|
|
20
|
+
this.message += "; all compatible model workers are busy; retry after capacity becomes available";
|
|
21
|
+
if (code === "request_conflict")
|
|
22
|
+
this.message += "; the service reported a request conflict. Completion and usage are unconfirmed; inspect request status before retrying";
|
|
23
|
+
}
|
|
24
|
+
/** A relay may already have sent HTTP 200 headers when the model fails. */
|
|
25
|
+
static fromRelayError(error) {
|
|
26
|
+
if (!error || typeof error !== "object")
|
|
27
|
+
return undefined;
|
|
28
|
+
const code = error.code;
|
|
29
|
+
if (code === "context_length_exceeded" || code === "invalid_response" || code === "rate_limited")
|
|
30
|
+
return new ModelServiceError(code, 200);
|
|
31
|
+
return undefined;
|
|
9
32
|
}
|
|
10
33
|
static async fromResponse(response) {
|
|
11
34
|
let serverCode = "";
|
|
35
|
+
let contextRefused = false;
|
|
36
|
+
let nativeRefused = false;
|
|
37
|
+
let capacityBusy = false;
|
|
12
38
|
if (response.body) {
|
|
13
39
|
const reader = response.body.getReader();
|
|
14
40
|
const chunks = [];
|
|
@@ -26,6 +52,9 @@ export class ModelServiceError extends Error {
|
|
|
26
52
|
const payload = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
27
53
|
if (typeof (payload.error?.code ?? payload.code) === "string")
|
|
28
54
|
serverCode = String(payload.error?.code ?? payload.code);
|
|
55
|
+
capacityBusy = response.status === 409 && serverCode === "conflict" && payload.details?.reason_code === "all_compatible_nodes_busy";
|
|
56
|
+
nativeRefused = response.status === 400 && !!payload.error && nativeContextRefusal(payload.error);
|
|
57
|
+
contextRefused = response.status === 400 && (serverCode === "context_length_exceeded" || nativeRefused);
|
|
29
58
|
}
|
|
30
59
|
catch { /* The status still supplies a safe classification. */ }
|
|
31
60
|
finally {
|
|
@@ -36,10 +65,13 @@ export class ModelServiceError extends Error {
|
|
|
36
65
|
const code = response.status === 401 ? "authentication_failed"
|
|
37
66
|
: response.status === 403 ? "entitlement_missing"
|
|
38
67
|
: ["quota_exceeded", "quota_exhausted", "insufficient_quota", "credits_exhausted", "insufficient_credits"].includes(serverCode) || response.status === 402 ? "quota_exhausted"
|
|
39
|
-
: response.status === 429 ? "rate_limited"
|
|
68
|
+
: response.status === 429 || capacityBusy ? "rate_limited"
|
|
40
69
|
: response.status === 404 ? "model_unavailable"
|
|
41
|
-
:
|
|
70
|
+
: contextRefused ? "context_length_exceeded"
|
|
71
|
+
: ["structured_output_failed", "invalid_response"].includes(serverCode) ? "invalid_response"
|
|
72
|
+
: response.status === 409 ? "request_conflict"
|
|
73
|
+
: response.status >= 500 ? "service_unavailable" : "invalid_request";
|
|
42
74
|
const retry = Number(response.headers.get("retry-after"));
|
|
43
|
-
return new ModelServiceError(code, response.status, response.headers.has("retry-after") && Number.isFinite(retry) && retry >= 0 ? Math.min(retry, 3600) : undefined);
|
|
75
|
+
return new ModelServiceError(code, response.status, response.headers.has("retry-after") && Number.isFinite(retry) && retry >= 0 ? Math.min(retry, 3600) : capacityBusy ? 2 : undefined, nativeRefused, capacityBusy ? "capacity_busy" : undefined);
|
|
44
76
|
}
|
|
45
77
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
import { Agent } from "undici";
|
|
1
2
|
import type { Provider, ProviderConfig, ProviderRequest, ProviderResponse } from "./ProviderTypes.js";
|
|
3
|
+
/** The platform fetch gives up after 300 s without response headers, even when
|
|
4
|
+
* the caller allows longer. A long non-streamed request (an answer audit on a
|
|
5
|
+
* large draft) then failed at exactly 300 s and the turn lost its finished
|
|
6
|
+
* answer. Requests allowed more than that use a dispatcher without those
|
|
7
|
+
* limits; the caller's own timeout still bounds them. */
|
|
8
|
+
export declare const FETCH_HEADERS_TIMEOUT_MS = 300000;
|
|
9
|
+
export declare const dispatcherFor: (timeoutMs: number) => Agent | undefined;
|
|
2
10
|
export declare const fetchWithTransientRetry: (url: string, init: RequestInit, controller?: AbortController) => Promise<Response>;
|
|
3
11
|
export declare class OpenAiCompatibleProvider implements Provider {
|
|
4
12
|
private config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiCompatibleProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OpenAiCompatibleProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OpenAiCompatibleProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OpenAiCompatibleProvider.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,eAAe,EACf,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AAmK5B;;;;yDAIyD;AACzD,eAAO,MAAM,wBAAwB,SAAU,CAAC;AAEhD,eAAO,MAAM,aAAa,GAAI,WAAW,MAAM,KAAG,KAAK,GAAG,SACgC,CAAC;AAE3F,eAAO,MAAM,uBAAuB,GAClC,KAAK,MAAM,EACX,MAAM,WAAW,EACjB,aAAa,eAAe,KAC3B,OAAO,CAAC,QAAQ,CAclB,CAAC;AAEF,qBAAa,wBAAyB,YAAW,QAAQ;IAS3C,OAAO,CAAC,MAAM;IAR1B,+EAA+E;IAC/E,QAAQ,CAAC,iBAAiB,QAAQ;IAElC,IAAI,SAAuB;IAC3B,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,sBAAsB,CAAoC;gBAE9C,MAAM,EAAE,cAAc;IAWpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2QnE,OAAO,CAAC,WAAW;CA0BpB"}
|