@mcoda/mswarm 0.1.135-codali.2 → 0.1.135-codali.32
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 +13 -5
- 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/TerminalCredentials.js +2 -2
- 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 +74 -3
- 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 +9 -2
- package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/vendor/codali/docdex/DocdexClient.js +86 -11
- 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/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 +1 -1
- package/dist/vendor/codali/permissions/PermissionGate.d.ts.map +1 -1
- package/dist/vendor/codali/permissions/PermissionGate.js +45 -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 +6 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ConfiguredProvider.js +88 -34
- 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.map +1 -1
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +26 -3
- package/dist/vendor/codali/providers/ProviderTypes.d.ts +6 -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 +17 -0
- package/dist/vendor/codali/runtime/AnswerVerification.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/AnswerVerification.js +39 -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 +2 -0
- package/dist/vendor/codali/runtime/CompletionReport.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CompletionReport.js +17 -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 +38 -0
- package/dist/vendor/codali/runtime/ContextCompression.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ContextCompression.js +263 -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 +44 -0
- package/dist/vendor/codali/runtime/InteractionContract.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/InteractionContract.js +64 -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 +138 -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 +19 -0
- package/dist/vendor/codali/runtime/ResearchEvidence.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/ResearchEvidence.js +55 -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 +71 -5
- package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/SessionController.js +1913 -223
- package/dist/vendor/codali/runtime/SpecialistTools.d.ts +6 -0
- package/dist/vendor/codali/runtime/SpecialistTools.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/SpecialistTools.js +69 -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/VerificationCommand.d.ts +2 -0
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/VerificationCommand.js +28 -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/AtomicState.d.ts.map +1 -1
- package/dist/vendor/codali/session/AtomicState.js +15 -1
- 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 +5 -1
- package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -1
- package/dist/vendor/codali/session/SessionStore.js +11 -2
- 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 +11 -0
- package/dist/vendor/codali/session/WorkState.d.ts.map +1 -1
- package/dist/vendor/codali/session/WorkState.js +46 -2
- 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 +2 -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 +163 -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 +58 -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 +7 -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.map +1 -1
- package/dist/vendor/codali/tools/shell/HostToolchain.js +37 -5
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts +4 -2
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.js +126 -27
- 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 +18 -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
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { execFile, spawn } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { promises as fs } from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { ToolExecutionError } from '../ToolTypes.js';
|
|
9
|
+
import { safeProcessEnvironment } from '../shell/AsyncProcess.js';
|
|
10
|
+
import { browserUrl } from './BrowserTool.js';
|
|
11
|
+
const exec = promisify(execFile);
|
|
12
|
+
const image = 'codali-browser-desktop:1';
|
|
13
|
+
const label = 'org.mcoda.codali.workspace';
|
|
14
|
+
export const browserSessionName = (workspace) => `codali-browser-${createHash('sha256').update(workspace).digest('hex').slice(0, 20)}`;
|
|
15
|
+
const docker = async (args, signal, timeout = 30000) => {
|
|
16
|
+
try {
|
|
17
|
+
return (await exec('docker', args, {
|
|
18
|
+
signal,
|
|
19
|
+
timeout,
|
|
20
|
+
maxBuffer: 1024 * 1024,
|
|
21
|
+
env: { ...safeProcessEnvironment(), HOME: os.homedir() },
|
|
22
|
+
})).stdout.trim();
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new ToolExecutionError('tool_execution_failed', `Managed browser Docker operation failed: ${String(error.message).slice(0, 1200)}. Use browser_session status; do not retry background shell launchers.`, { retryable: false });
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const inspect = async (name) => {
|
|
29
|
+
const ids = await docker(['ps', '-aq', '--filter', `name=^/${name}$`]);
|
|
30
|
+
if (!ids)
|
|
31
|
+
return undefined;
|
|
32
|
+
return JSON.parse(await docker(['inspect', name]))[0];
|
|
33
|
+
};
|
|
34
|
+
const owned = (value, root) => {
|
|
35
|
+
if (value?.Config?.Labels?.[label] !== root)
|
|
36
|
+
throw new Error('Container name belongs to another owner; refusing to modify it');
|
|
37
|
+
};
|
|
38
|
+
export async function browserSessionStatus(workspace) {
|
|
39
|
+
const root = await fs.realpath(workspace), name = browserSessionName(root), value = await inspect(name);
|
|
40
|
+
if (!value)
|
|
41
|
+
return { running: false, name, expiresAfterHours: 8 };
|
|
42
|
+
owned(value, root);
|
|
43
|
+
const port = (p) => value.NetworkSettings?.Ports?.[`${p}/tcp`]?.find((v) => v.HostIp === '127.0.0.1')?.HostPort;
|
|
44
|
+
const web = port(6080), preview = port(8000), cdp = port(9223);
|
|
45
|
+
const running = value.State?.Running === true && !!web && !!preview && !!cdp;
|
|
46
|
+
return {
|
|
47
|
+
running,
|
|
48
|
+
name,
|
|
49
|
+
expiresAfterHours: 8,
|
|
50
|
+
...(running
|
|
51
|
+
? {
|
|
52
|
+
url: `http://127.0.0.1:${web}/vnc.html?autoconnect=true&resize=scale`,
|
|
53
|
+
previewUrl: `http://127.0.0.1:${preview}/`,
|
|
54
|
+
browserPreviewUrl: 'http://127.0.0.1:8000/',
|
|
55
|
+
cdpUrl: `http://127.0.0.1:${cdp}`,
|
|
56
|
+
sshForward: `ssh -N -L ${web}:127.0.0.1:${web} -L ${preview}:127.0.0.1:${preview} ${os.userInfo().username}@${os.hostname()}`,
|
|
57
|
+
}
|
|
58
|
+
: {}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export const checkVnc = async (url) => {
|
|
62
|
+
await new Promise((resolve, reject) => {
|
|
63
|
+
const socket = new WebSocket(new URL('/websockify', url).href.replace(/^http/, 'ws'), ['binary']);
|
|
64
|
+
socket.binaryType = 'arraybuffer';
|
|
65
|
+
const finish = (error) => {
|
|
66
|
+
clearTimeout(timer);
|
|
67
|
+
socket.close();
|
|
68
|
+
error ? reject(error) : resolve();
|
|
69
|
+
};
|
|
70
|
+
const timer = setTimeout(() => finish(new Error('noVNC desktop handshake timed out')), 2000);
|
|
71
|
+
socket.onmessage = (event) => finish(Buffer.from(event.data)
|
|
72
|
+
.toString()
|
|
73
|
+
.startsWith('RFB ')
|
|
74
|
+
? undefined
|
|
75
|
+
: new Error('Invalid VNC handshake'));
|
|
76
|
+
socket.onerror = () => finish(new Error('noVNC desktop connection failed'));
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const ready = async (status, signal) => {
|
|
80
|
+
if (!status.running)
|
|
81
|
+
throw new Error('Managed browser is not running; call browser_session start');
|
|
82
|
+
await checkVnc(status.url);
|
|
83
|
+
for (const url of [status.url, `${status.cdpUrl}/json/version`]) {
|
|
84
|
+
const r = await fetch(url, {
|
|
85
|
+
signal: AbortSignal.any([
|
|
86
|
+
...(signal ? [signal] : []),
|
|
87
|
+
AbortSignal.timeout(2000),
|
|
88
|
+
]),
|
|
89
|
+
});
|
|
90
|
+
if (!r.ok)
|
|
91
|
+
throw new Error(`Browser readiness failed (${r.status})`);
|
|
92
|
+
if (url.endsWith('/json/version') &&
|
|
93
|
+
!(await r.json()).webSocketDebuggerUrl)
|
|
94
|
+
throw new Error('Browser CDP endpoint is not ready');
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const stateHome = (name) => path.join(os.homedir(), '.local', 'state', 'codali', 'browser-sessions', name);
|
|
98
|
+
const runtimeHome = (name) => path.join(os.tmpdir(), `cbu-${process.getuid?.() ?? 'user'}-${name.slice(-20)}`);
|
|
99
|
+
const browserEnvironment = (name) => ({
|
|
100
|
+
...safeProcessEnvironment(),
|
|
101
|
+
HOME: stateHome(name),
|
|
102
|
+
BU_NAME: name,
|
|
103
|
+
BH_RUNTIME_DIR: runtimeHome(name),
|
|
104
|
+
BH_TMP_DIR: stateHome(name),
|
|
105
|
+
BH_RECORD: '0',
|
|
106
|
+
BH_TAB_MARKER: '0',
|
|
107
|
+
ANONYMIZED_TELEMETRY: 'false',
|
|
108
|
+
});
|
|
109
|
+
async function browserUse(status, script, signal) {
|
|
110
|
+
const home = stateHome(status.name);
|
|
111
|
+
await fs.mkdir(home, { recursive: true, mode: 0o700 });
|
|
112
|
+
const runtime = runtimeHome(status.name);
|
|
113
|
+
await fs.mkdir(runtime, { mode: 0o700, recursive: true });
|
|
114
|
+
const stat = await fs.lstat(runtime);
|
|
115
|
+
if (!stat.isDirectory() ||
|
|
116
|
+
stat.isSymbolicLink() ||
|
|
117
|
+
(process.getuid && stat.uid !== process.getuid()) ||
|
|
118
|
+
stat.mode & 0o077)
|
|
119
|
+
throw new Error('Browser Use runtime directory must be private and owned by the current user');
|
|
120
|
+
return new Promise((resolve, reject) => {
|
|
121
|
+
const child = spawn('browser-use', [], {
|
|
122
|
+
cwd: home,
|
|
123
|
+
env: { ...browserEnvironment(status.name), BU_CDP_URL: status.cdpUrl },
|
|
124
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
125
|
+
signal,
|
|
126
|
+
});
|
|
127
|
+
let output = '', error = '';
|
|
128
|
+
const timer = setTimeout(() => child.kill('SIGKILL'), 45000);
|
|
129
|
+
child.stdout.on('data', (b) => {
|
|
130
|
+
output = (output + b).slice(-131072);
|
|
131
|
+
});
|
|
132
|
+
child.stderr.on('data', (b) => {
|
|
133
|
+
error = (error + b).slice(-3000);
|
|
134
|
+
});
|
|
135
|
+
child.once('error', (e) => {
|
|
136
|
+
clearTimeout(timer);
|
|
137
|
+
reject(new Error(`Official browser-use CLI unavailable: ${e.message}. Install browser-use with uv; do not substitute the npm community port.`));
|
|
138
|
+
});
|
|
139
|
+
child.once('close', (code) => {
|
|
140
|
+
clearTimeout(timer);
|
|
141
|
+
code === 0
|
|
142
|
+
? resolve(output)
|
|
143
|
+
: reject(new Error(`Browser Use failed (${code}): ${error || output}`));
|
|
144
|
+
});
|
|
145
|
+
child.stdin.on('error', () => undefined);
|
|
146
|
+
child.stdin.end(script);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
export function createBrowserSessionTools() {
|
|
150
|
+
let busy = false;
|
|
151
|
+
const exclusive = async (job) => {
|
|
152
|
+
if (busy)
|
|
153
|
+
throw new Error('Browser session is busy; wait for the previous operation');
|
|
154
|
+
busy = true;
|
|
155
|
+
try {
|
|
156
|
+
return await job();
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
busy = false;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
return [
|
|
163
|
+
{
|
|
164
|
+
name: 'browser_session',
|
|
165
|
+
capability: 'browser',
|
|
166
|
+
readOnly: false,
|
|
167
|
+
description: "Manage a persistent isolated Chrome/noVNC desktop and read-only workspace web preview. start builds the bundled Docker preset if needed, waits for readiness and returns loopback URLs plus an SSH tunnel command. Survives shell calls and TUI exit, expires after 8h. status checks readiness; stop removes only this workspace's owned container. Requires Docker; no sudo, host browser profile or cloud account. Use this instead of nohup/tmux in run_shell.",
|
|
168
|
+
inputSchema: {
|
|
169
|
+
type: 'object',
|
|
170
|
+
properties: {
|
|
171
|
+
action: { type: 'string', enum: ['start', 'status', 'stop'] },
|
|
172
|
+
},
|
|
173
|
+
required: ['action'],
|
|
174
|
+
additionalProperties: false,
|
|
175
|
+
},
|
|
176
|
+
handler: async (args, context) => exclusive(async () => {
|
|
177
|
+
const { action } = args;
|
|
178
|
+
const root = await fs.realpath(context.workspaceRoot), name = browserSessionName(root);
|
|
179
|
+
await context.checkPath?.(root, 'read');
|
|
180
|
+
let status = await browserSessionStatus(root);
|
|
181
|
+
if (action === 'stop') {
|
|
182
|
+
if (await inspect(name))
|
|
183
|
+
await docker(['rm', '-f', name], context.signal);
|
|
184
|
+
// Stop only our named Browser Use daemon, never the default/user browser.
|
|
185
|
+
await exec('browser-use', ['--reload'], {
|
|
186
|
+
timeout: 10000,
|
|
187
|
+
env: browserEnvironment(name),
|
|
188
|
+
}).catch(() => undefined);
|
|
189
|
+
return {
|
|
190
|
+
output: "Stopped this workspace's managed browser and preview. Other sessions were not changed.",
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
if (action === 'start' && !status.running) {
|
|
194
|
+
if (await inspect(name))
|
|
195
|
+
await docker(['rm', name], context.signal);
|
|
196
|
+
if (!(await docker(['images', '-q', image], context.signal))) {
|
|
197
|
+
context.onOutput?.('stdout', 'Preparing the local browser desktop image (first use only)…\n');
|
|
198
|
+
await docker([
|
|
199
|
+
'build',
|
|
200
|
+
'-t',
|
|
201
|
+
image,
|
|
202
|
+
fileURLToPath(new URL('../../../config/browser-desktop', import.meta.url)),
|
|
203
|
+
], context.signal, 600000);
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
await docker([
|
|
207
|
+
'run',
|
|
208
|
+
'-d',
|
|
209
|
+
'--name',
|
|
210
|
+
name,
|
|
211
|
+
'--label',
|
|
212
|
+
`${label}=${root}`,
|
|
213
|
+
'--cap-drop=ALL',
|
|
214
|
+
'--security-opt',
|
|
215
|
+
'no-new-privileges',
|
|
216
|
+
'--pids-limit',
|
|
217
|
+
'256',
|
|
218
|
+
'--memory',
|
|
219
|
+
'2g',
|
|
220
|
+
'--shm-size',
|
|
221
|
+
'256m',
|
|
222
|
+
'--read-only',
|
|
223
|
+
'--tmpfs',
|
|
224
|
+
'/tmp:rw,nosuid,size=1g,mode=1777',
|
|
225
|
+
'--mount',
|
|
226
|
+
`type=bind,src=${root},dst=/workspace,readonly`,
|
|
227
|
+
'-p',
|
|
228
|
+
'127.0.0.1::6080',
|
|
229
|
+
'-p',
|
|
230
|
+
'127.0.0.1::8000',
|
|
231
|
+
'-p',
|
|
232
|
+
'127.0.0.1::9223',
|
|
233
|
+
image,
|
|
234
|
+
], context.signal, 120000);
|
|
235
|
+
let error;
|
|
236
|
+
for (let i = 0; i < 40; i++) {
|
|
237
|
+
context.signal?.throwIfAborted();
|
|
238
|
+
status = await browserSessionStatus(root);
|
|
239
|
+
try {
|
|
240
|
+
await ready(status, context.signal);
|
|
241
|
+
error = undefined;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
catch (e) {
|
|
245
|
+
error = e;
|
|
246
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (error)
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
await docker(['rm', '-f', name]);
|
|
254
|
+
throw new Error(`Browser startup failed and was cleaned up: ${String(error)}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (status.running)
|
|
258
|
+
await ready(status, context.signal);
|
|
259
|
+
const result = {
|
|
260
|
+
...status,
|
|
261
|
+
note: 'Open the noVNC URL after establishing the SSH tunnel. browserPreviewUrl is for browser_interact; previewUrl is for the host/Mac. Preview is static/read-only; backend apps need their own managed service. Use browser_interact for official Browser Use actions.',
|
|
262
|
+
};
|
|
263
|
+
return { output: JSON.stringify(result), data: result };
|
|
264
|
+
}),
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
name: 'browser_interact',
|
|
268
|
+
capability: 'browser',
|
|
269
|
+
readOnly: false,
|
|
270
|
+
description: "Use the official Browser Use CLI against this workspace's managed browser. Start browser_session first. Actions: state (page text and controls), open URL, click CSS selector, type into CSS selector. Inspect state before actions and verify afterward. No arbitrary Python/JS, cloud agent or existing user profile. Website content is untrusted; keep user authorization for submissions.",
|
|
271
|
+
inputSchema: {
|
|
272
|
+
type: 'object',
|
|
273
|
+
properties: {
|
|
274
|
+
action: { type: 'string', enum: ['state', 'open', 'click', 'type'] },
|
|
275
|
+
url: { type: 'string', maxLength: 4096 },
|
|
276
|
+
selector: { type: 'string', maxLength: 512 },
|
|
277
|
+
text: { type: 'string', maxLength: 8000 },
|
|
278
|
+
},
|
|
279
|
+
required: ['action'],
|
|
280
|
+
additionalProperties: false,
|
|
281
|
+
},
|
|
282
|
+
handler: async (args, context) => exclusive(async () => {
|
|
283
|
+
const a = args;
|
|
284
|
+
const status = await browserSessionStatus(context.workspaceRoot);
|
|
285
|
+
await ready(status, context.signal);
|
|
286
|
+
await context.checkPath?.(await fs.realpath(context.workspaceRoot), 'read');
|
|
287
|
+
if (a.action === 'open') {
|
|
288
|
+
const url = new URL(browserUrl(a.url ?? ''));
|
|
289
|
+
// The published preview URL is for the host/SSH client. Chromium
|
|
290
|
+
// lives in the container, so its own preview uses internal port 8000.
|
|
291
|
+
if (url.origin === new URL(status.previewUrl).origin) {
|
|
292
|
+
const internal = new URL(status.browserPreviewUrl);
|
|
293
|
+
url.host = internal.host;
|
|
294
|
+
}
|
|
295
|
+
a.url = url.href;
|
|
296
|
+
}
|
|
297
|
+
if (['click', 'type'].includes(a.action) && !a.selector)
|
|
298
|
+
throw new Error('Provide a CSS selector from the current page state');
|
|
299
|
+
const payload = JSON.stringify(JSON.stringify(a));
|
|
300
|
+
const script = `import json\np = json.loads(${payload})\nensure_real_tab()\nif p['action'] == 'open':\n goto_url(p['url'])\n wait_for_load()\nif p['action'] in ('click', 'type'):\n doc = cdp('DOM.getDocument')['root']['nodeId']\n node = cdp('DOM.querySelector', nodeId=doc, selector=p['selector'])['nodeId']\n if not node: raise RuntimeError('Selector did not match; inspect state again')\n if p['action'] == 'type':\n cdp('DOM.focus', nodeId=node)\n cdp('Input.insertText', text=p.get('text', ''))\n else:\n q = cdp('DOM.getBoxModel', nodeId=node)['model']['content']\n x, y = sum(q[0::2])/4, sum(q[1::2])/4\n cdp('Input.dispatchMouseEvent', type='mousePressed', x=x, y=y, button='left', clickCount=1)\n cdp('Input.dispatchMouseEvent', type='mouseReleased', x=x, y=y, button='left', clickCount=1)\nprint(js("JSON.stringify({title:document.title,url:location.href,browserError:document.documentURI.startsWith('chrome-error:'),text:document.body.innerText.slice(0,4000),controls:Array.from(document.querySelectorAll('button,input,a,select')).slice(0,30).map(e=>({tag:e.tagName,id:e.id.slice(0,100),name:(e.getAttribute('name')||'').slice(0,100),text:(e.innerText||e.getAttribute('aria-label')||'').slice(0,100)}))})"))\n`;
|
|
301
|
+
const raw = await browserUse(status, script, context.signal);
|
|
302
|
+
const snapshot = JSON.parse(raw.trim());
|
|
303
|
+
if (snapshot.browserError)
|
|
304
|
+
throw new Error(`Browser navigation failed. For this workspace preview use ${status.browserPreviewUrl}; check the URL before retrying. ${String(snapshot.text ?? '').slice(0, 300)}`);
|
|
305
|
+
snapshot.title = String(snapshot.title ?? '').slice(0, 200);
|
|
306
|
+
snapshot.url = String(snapshot.url ?? '').slice(0, 2000);
|
|
307
|
+
snapshot.text = String(snapshot.text ?? '').slice(0, 1400);
|
|
308
|
+
// Preserve valid JSON under the shared tool-result ceiling.
|
|
309
|
+
while (JSON.stringify(snapshot).length > 3800 &&
|
|
310
|
+
snapshot.controls?.length)
|
|
311
|
+
snapshot.controls.pop();
|
|
312
|
+
while (JSON.stringify(snapshot).length > 3800 && snapshot.text.length)
|
|
313
|
+
snapshot.text = snapshot.text.slice(0, -100);
|
|
314
|
+
if (JSON.stringify(snapshot).length > 3800) {
|
|
315
|
+
snapshot.url = null;
|
|
316
|
+
snapshot.urlOmitted = true;
|
|
317
|
+
}
|
|
318
|
+
const output = JSON.stringify(snapshot);
|
|
319
|
+
return {
|
|
320
|
+
output,
|
|
321
|
+
data: { backend: 'official-browser-use', session: status.name },
|
|
322
|
+
};
|
|
323
|
+
}),
|
|
324
|
+
},
|
|
325
|
+
];
|
|
326
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ToolDefinition } from "../ToolTypes.js";
|
|
2
|
+
export declare const browserUrl: (value: string) => string;
|
|
3
|
+
export declare function resolveBrowserBinary(): Promise<string>;
|
|
4
|
+
export declare function findSnapshotText(content: string, query: string, offset?: number): {
|
|
5
|
+
index: number;
|
|
6
|
+
mode: "exact" | "ordered_terms" | "ranked_terms";
|
|
7
|
+
matchedTerms?: string[];
|
|
8
|
+
} | undefined;
|
|
9
|
+
export declare function snapshotSectionContext(content: string, offset: number): string[];
|
|
10
|
+
/** A starting-position hint only: retain the full snapshot for offset reads. */
|
|
11
|
+
export declare function snapshotContentStart(content: string): number;
|
|
12
|
+
/** Short-lived, unauthenticated browser navigation; the model never supplies JS. */
|
|
13
|
+
export declare function createBrowserTools(options?: {
|
|
14
|
+
executablePath?: string;
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
}): ToolDefinition[];
|
|
17
|
+
//# sourceMappingURL=BrowserTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrowserTool.d.ts","sourceRoot":"","sources":["../../../src/tools/browser/BrowserTool.ts"],"names":[],"mappings":"AAKA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE1E,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,MAO1C,CAAC;AAEF,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CA0B5D;AAID,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,SAAI,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,cAAc,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,SAAS,CA4CrL;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAWhF;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAU5D;AAOD,oFAAoF;AACpF,wBAAgB,kBAAkB,CAAC,OAAO,GAAE;IAAE,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,cAAc,EAAE,CAuHlH"}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { promises as fs, constants } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fork } from "node:child_process";
|
|
5
|
+
import { chromium } from "playwright-core";
|
|
6
|
+
import { ToolExecutionError } from "../ToolTypes.js";
|
|
7
|
+
export const browserUrl = (value) => {
|
|
8
|
+
let url;
|
|
9
|
+
try {
|
|
10
|
+
url = new URL(value);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
throw new ToolExecutionError("tool_invalid_args", "Provide a complete http or https URL");
|
|
14
|
+
}
|
|
15
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) {
|
|
16
|
+
throw new ToolExecutionError("tool_invalid_args", "Browser access accepts http/https URLs without embedded credentials");
|
|
17
|
+
}
|
|
18
|
+
return url.href;
|
|
19
|
+
};
|
|
20
|
+
export async function resolveBrowserBinary() {
|
|
21
|
+
const explicit = process.env.CODALI_BROWSER_PATH;
|
|
22
|
+
const candidates = explicit ? [explicit] : [
|
|
23
|
+
...[process.env.DOCDEX_WEB_BROWSER, process.env.CHROME_PATH].filter((value) => !!value),
|
|
24
|
+
...String(process.env.PATH ?? "").split(path.delimiter).filter(Boolean).flatMap(directory => ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser", "chrome.exe"].map(name => path.join(directory, name))),
|
|
25
|
+
// Packaged browsers have OS sandbox profiles that cache downloads may lack.
|
|
26
|
+
chromium.executablePath(),
|
|
27
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
28
|
+
...[process.env.PROGRAMFILES, process.env["PROGRAMFILES(X86)"], process.env.LOCALAPPDATA].filter((value) => !!value)
|
|
29
|
+
.map(directory => path.join(directory, "Google", "Chrome", "Application", "chrome.exe")),
|
|
30
|
+
];
|
|
31
|
+
if (!explicit) {
|
|
32
|
+
for (const root of [path.join(os.homedir(), ".docdex"), path.join(os.homedir(), ".docdex", "state")]) {
|
|
33
|
+
try {
|
|
34
|
+
const value = JSON.parse(await fs.readFile(path.join(root, "bin", "chromium", "manifest.json"), "utf8"));
|
|
35
|
+
if (typeof value.path === "string")
|
|
36
|
+
candidates.push(value.path);
|
|
37
|
+
}
|
|
38
|
+
catch { /* Optional Docdex browser install. */ }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const candidate of candidates) {
|
|
42
|
+
try {
|
|
43
|
+
if (!path.isAbsolute(candidate))
|
|
44
|
+
continue;
|
|
45
|
+
const real = await fs.realpath(candidate);
|
|
46
|
+
if (!(await fs.stat(real)).isFile())
|
|
47
|
+
continue;
|
|
48
|
+
await fs.access(real, process.platform === "win32" ? constants.F_OK : constants.X_OK);
|
|
49
|
+
return real;
|
|
50
|
+
}
|
|
51
|
+
catch { /* Try the next installed browser. */ }
|
|
52
|
+
}
|
|
53
|
+
throw new ToolExecutionError("tool_execution_failed", "Chrome/Chromium was not found. Install it or set CODALI_BROWSER_PATH to its absolute executable path.");
|
|
54
|
+
}
|
|
55
|
+
export function findSnapshotText(content, query, offset = 0) {
|
|
56
|
+
const text = content.toLowerCase(), needle = query.trim().toLowerCase();
|
|
57
|
+
if (!needle)
|
|
58
|
+
return;
|
|
59
|
+
const bodyStart = Math.max(offset, snapshotContentStart(content));
|
|
60
|
+
const bodyExact = text.indexOf(needle, bodyStart);
|
|
61
|
+
const exact = bodyExact >= 0 ? bodyExact : text.indexOf(needle, offset);
|
|
62
|
+
if (exact >= 0) {
|
|
63
|
+
// A documentation title often appears first in navigation. Prefer its
|
|
64
|
+
// actual heading/body occurrence; link-only searches still work.
|
|
65
|
+
let candidate = exact;
|
|
66
|
+
for (let inspected = 0; candidate >= 0 && inspected < 128; inspected++) {
|
|
67
|
+
const line = text.slice(text.lastIndexOf("\n", candidate) + 1, candidate);
|
|
68
|
+
if (!/^\s*-\s*(?:link\b|\/url:)/.test(line))
|
|
69
|
+
return { index: candidate, mode: "exact" };
|
|
70
|
+
candidate = text.indexOf(needle, candidate + Math.max(1, needle.length));
|
|
71
|
+
}
|
|
72
|
+
return { index: exact, mode: "exact" };
|
|
73
|
+
}
|
|
74
|
+
const terms = needle.split(/\s+/);
|
|
75
|
+
if (terms.length < 2 || terms.length > 20)
|
|
76
|
+
return;
|
|
77
|
+
// Bounded literal scanning handles accessibility line breaks and intervening
|
|
78
|
+
// words without regex backtracking or pretending the phrase was quoted.
|
|
79
|
+
for (let start = text.indexOf(terms[0], bodyStart); start >= 0; start = text.indexOf(terms[0], start + 1)) {
|
|
80
|
+
let end = start + terms[0].length;
|
|
81
|
+
const found = terms.slice(1).every(term => {
|
|
82
|
+
const next = text.indexOf(term, end);
|
|
83
|
+
if (next < 0 || next - start > 240)
|
|
84
|
+
return false;
|
|
85
|
+
end = next + term.length;
|
|
86
|
+
return true;
|
|
87
|
+
});
|
|
88
|
+
if (found)
|
|
89
|
+
return { index: start, mode: "ordered_terms" };
|
|
90
|
+
}
|
|
91
|
+
// Models also issue unordered keyword queries. Retrieve a bounded candidate
|
|
92
|
+
// passage without representing lexical overlap as support for the claim.
|
|
93
|
+
const stop = new Set(["the", "and", "for", "with", "that", "this", "from", "are", "was", "were", "does", "not", "can", "must", "should", "have", "has"]);
|
|
94
|
+
const keywords = [...new Set(needle.match(/[\p{L}\p{N}_]{3,}/gu) ?? [])].filter(term => !stop.has(term)).slice(0, 20);
|
|
95
|
+
if (keywords.length < 2)
|
|
96
|
+
return;
|
|
97
|
+
let best;
|
|
98
|
+
for (let start = bodyStart; start < Math.min(text.length, 1000000); start += 600) {
|
|
99
|
+
const window = text.slice(start, start + 1200), words = new Set(window.match(/[\p{L}\p{N}_]{3,}/gu) ?? []);
|
|
100
|
+
const matched = keywords.filter(term => words.has(term));
|
|
101
|
+
if (matched.length < Math.max(2, Math.ceil(keywords.length / 2)))
|
|
102
|
+
continue;
|
|
103
|
+
const score = matched.length + matched.length / Math.max(1, words.size);
|
|
104
|
+
if (!best || score > best.score)
|
|
105
|
+
best = { index: start, matchedTerms: matched, score };
|
|
106
|
+
}
|
|
107
|
+
if (best)
|
|
108
|
+
return { index: best.index, mode: "ranked_terms", matchedTerms: best.matchedTerms };
|
|
109
|
+
}
|
|
110
|
+
export function snapshotSectionContext(content, offset) {
|
|
111
|
+
const prefix = content.slice(0, offset), end = prefix.lastIndexOf("\n");
|
|
112
|
+
const stack = [];
|
|
113
|
+
for (const match of prefix.slice(0, Math.max(0, end)).matchAll(/^\s*- heading (.+?)(?: \[level=(\d+)\])?:?$/gm)) {
|
|
114
|
+
const level = Number(match[2] ?? 1);
|
|
115
|
+
let title = match[1];
|
|
116
|
+
try {
|
|
117
|
+
title = JSON.parse(title);
|
|
118
|
+
}
|
|
119
|
+
catch { /* Unquoted accessibility label. */ }
|
|
120
|
+
while (stack.length && stack.at(-1).level >= level)
|
|
121
|
+
stack.pop();
|
|
122
|
+
stack.push({ level, title: String(title).slice(0, 160) });
|
|
123
|
+
}
|
|
124
|
+
return stack.slice(-4).map(value => value.title);
|
|
125
|
+
}
|
|
126
|
+
/** A starting-position hint only: retain the full snapshot for offset reads. */
|
|
127
|
+
export function snapshotContentStart(content) {
|
|
128
|
+
const heading = /^\s*- heading .+? \[level=[12]\]:?$/m.exec(content.slice(0, 20000));
|
|
129
|
+
if (heading)
|
|
130
|
+
return heading.index;
|
|
131
|
+
// Plain-text specifications commonly indent their contents list but start
|
|
132
|
+
// actual numbered sections at column zero. Keep navigation as a fallback.
|
|
133
|
+
if (/table of contents/i.test(content.slice(0, 20000))) {
|
|
134
|
+
const body = /^\d+(?:\.\d+)*\.\s+\S[^\n]*$/m.exec(content);
|
|
135
|
+
if (body)
|
|
136
|
+
return body.index;
|
|
137
|
+
}
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
const MAX_SNAPSHOTS = 48;
|
|
141
|
+
const MAX_SNAPSHOT_CHARS = 24000000;
|
|
142
|
+
const SNAPSHOT_REUSE_MS = 30 * 60000;
|
|
143
|
+
const isErrorSnapshot = (value) => value.httpStatus === null || value.httpStatus >= 400 || !value.content.trim();
|
|
144
|
+
/** Short-lived, unauthenticated browser navigation; the model never supplies JS. */
|
|
145
|
+
export function createBrowserTools(options = {}) {
|
|
146
|
+
let snapshot;
|
|
147
|
+
const snapshots = new Map();
|
|
148
|
+
// Requested URL and scope to snapshot id. Long research reopened the same
|
|
149
|
+
// page dozens of times, spending a browser launch on evidence already held.
|
|
150
|
+
const captured = new Map();
|
|
151
|
+
let snapshotCount = 0;
|
|
152
|
+
const store = (value, key) => {
|
|
153
|
+
snapshots.set(value.id, value);
|
|
154
|
+
captured.set(key, value.id);
|
|
155
|
+
let chars = [...snapshots.values()].reduce((sum, item) => sum + item.content.length, 0);
|
|
156
|
+
for (const [id, item] of snapshots) {
|
|
157
|
+
if (snapshots.size <= MAX_SNAPSHOTS && chars <= MAX_SNAPSHOT_CHARS)
|
|
158
|
+
break;
|
|
159
|
+
snapshots.delete(id);
|
|
160
|
+
chars -= item.content.length;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const page = (offset = 0, maxChars = 2400, extra = {}) => {
|
|
164
|
+
if (!snapshot)
|
|
165
|
+
throw new ToolExecutionError("tool_invalid_args", "Open a page before reading its snapshot");
|
|
166
|
+
const start = Math.min(snapshot.content.length, offset);
|
|
167
|
+
let end = Math.min(snapshot.content.length, start + Math.min(maxChars, 2400));
|
|
168
|
+
const result = { snapshotId: snapshot.id, url: snapshot.url.slice(0, 1000), title: snapshot.title.slice(0, 200), capturedAt: snapshot.capturedAt,
|
|
169
|
+
httpStatus: snapshot.httpStatus, contentType: snapshot.contentType,
|
|
170
|
+
evidenceStatus: snapshot.httpStatus === null ? "unknown_http_status" : snapshot.httpStatus >= 400 ? "http_error" : !snapshot.content.trim() ? "empty" : "retrieved",
|
|
171
|
+
evidenceNotice: "Retrieval is not claim verification. Error, login/challenge, navigation-only and search/abstract pages do not establish the requested primary-source claims. Cite only claims supported by the actual captured content; otherwise report missing evidence.",
|
|
172
|
+
readHint: "Use browser_read with snapshotId and query to find relevant text before paging. Recent snapshots remain readable without reopening their URLs; reopening an already captured URL returns the saved snapshot.",
|
|
173
|
+
source: snapshot.format === "rendered_text" ? "isolated browser rendered-text snapshot (visual text; use page scope for accessibility-only labels)" : "isolated browser accessibility snapshot", scope: snapshot.scope, sectionContext: snapshotSectionContext(snapshot.content, start), offset: start,
|
|
174
|
+
nextOffset: end < snapshot.content.length ? end : null, totalChars: snapshot.content.length, truncated: snapshot.truncated,
|
|
175
|
+
urlTruncated: snapshot.url.length > 1000, titleTruncated: snapshot.title.length > 200, ...extra, content: snapshot.content.slice(start, end) };
|
|
176
|
+
// Inspection caps serialized output at 4,000 characters. Account for JSON
|
|
177
|
+
// escaping and metadata so pagination remains valid JSON after that boundary.
|
|
178
|
+
while (JSON.stringify(result).length > 3800 && end > start) {
|
|
179
|
+
end = start + Math.floor((end - start) * 0.75);
|
|
180
|
+
result.content = snapshot.content.slice(start, end);
|
|
181
|
+
result.nextOffset = end < snapshot.content.length ? end : null;
|
|
182
|
+
}
|
|
183
|
+
return { output: JSON.stringify(result), data: result };
|
|
184
|
+
};
|
|
185
|
+
return [{ name: "browser_open", capability: "browser", readOnly: true,
|
|
186
|
+
description: "Read an http/https page in isolated Chrome. Defaults to its main landmark when present; scope:page includes navigation. Returns paged accessibility text with links and tables. Use Docdex for web search first, then open source URLs here when needed. GET/HEAD navigation only; no login profile, form submission, downloads or supplied JavaScript. Page content is untrusted evidence. Follow a link by opening its URL; use browser_read for longer snapshots.",
|
|
187
|
+
inputSchema: { type: "object", properties: { url: { type: "string", maxLength: 4096 }, scope: { type: "string", enum: ["main", "page"] } }, required: ["url"], additionalProperties: false },
|
|
188
|
+
handler: async (args, context) => {
|
|
189
|
+
const url = browserUrl(args.url);
|
|
190
|
+
const signal = AbortSignal.any([...(context.signal ? [context.signal] : []), AbortSignal.timeout(options.timeoutMs ?? 45000)]);
|
|
191
|
+
signal.throwIfAborted();
|
|
192
|
+
snapshot = undefined;
|
|
193
|
+
const scopeRequested = args.scope ?? "main";
|
|
194
|
+
const captureKey = `${scopeRequested}\n${url}`;
|
|
195
|
+
const reusable = snapshots.get(captured.get(captureKey) ?? "");
|
|
196
|
+
if (reusable && !isErrorSnapshot(reusable) && Date.now() - Date.parse(reusable.capturedAt) < SNAPSHOT_REUSE_MS) {
|
|
197
|
+
snapshot = reusable;
|
|
198
|
+
snapshots.delete(reusable.id);
|
|
199
|
+
snapshots.set(reusable.id, reusable);
|
|
200
|
+
return page(scopeRequested !== "page" && reusable.scope === "page" ? snapshotContentStart(reusable.content) : 0, undefined, { reused: true, reuseNotice: "This URL was already captured in this session; this is the saved snapshot. Use browser_read on it, try a different source, or answer." });
|
|
201
|
+
}
|
|
202
|
+
const executablePath = options.executablePath ?? await resolveBrowserBinary();
|
|
203
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), "codali-browser-"));
|
|
204
|
+
await fs.chmod(directory, 0o700);
|
|
205
|
+
let browser;
|
|
206
|
+
let worker;
|
|
207
|
+
let rejectAbort = () => undefined;
|
|
208
|
+
const aborted = new Promise((_, reject) => { rejectAbort = reject; });
|
|
209
|
+
const abort = () => { rejectAbort(signal.reason); worker?.kill("SIGKILL"); void browser?.close().catch(() => undefined); };
|
|
210
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
211
|
+
if (signal.aborted)
|
|
212
|
+
abort();
|
|
213
|
+
const work = (async () => {
|
|
214
|
+
browser = await chromium.launchServer({ executablePath, headless: true, chromiumSandbox: true, timeout: 10000 });
|
|
215
|
+
if (signal.aborted) {
|
|
216
|
+
await browser.close();
|
|
217
|
+
signal.throwIfAborted();
|
|
218
|
+
}
|
|
219
|
+
// The CLI owns Chrome; cancellation closes it even if the worker dies.
|
|
220
|
+
// Do not let browser-use import a workspace .env or inherit API keys.
|
|
221
|
+
worker = fork(new URL("./BrowserWorker.js", import.meta.url), [], { cwd: directory, execArgv: [],
|
|
222
|
+
env: { PATH: process.env.PATH, SYSTEMROOT: process.env.SYSTEMROOT, WINDIR: process.env.WINDIR,
|
|
223
|
+
HOME: directory, USERPROFILE: directory, TMPDIR: directory, TMP: directory, TEMP: directory,
|
|
224
|
+
XDG_CONFIG_HOME: directory, XDG_CACHE_HOME: directory, XDG_DATA_HOME: directory,
|
|
225
|
+
LANG: "C.UTF-8", ANONYMIZED_TELEMETRY: "false" },
|
|
226
|
+
stdio: ["ignore", "ignore", "ignore", "ipc"] });
|
|
227
|
+
const result = await new Promise((resolve, reject) => {
|
|
228
|
+
worker.once("error", reject);
|
|
229
|
+
worker.once("exit", code => reject(new Error(`Browser worker exited before returning evidence (${code})`)));
|
|
230
|
+
worker.once("message", (message) => {
|
|
231
|
+
const reply = message;
|
|
232
|
+
const value = reply?.value;
|
|
233
|
+
if (!reply?.ok)
|
|
234
|
+
return reject(new Error(typeof reply?.message === "string" ? reply.message.slice(0, 2000) : "Browser navigation failed"));
|
|
235
|
+
if (!value || typeof value.url !== "string" || typeof value.title !== "string" || typeof value.content !== "string" || value.content.length > 1000000 || !["main", "page"].includes(value.scope) || typeof value.truncated !== "boolean")
|
|
236
|
+
return reject(new Error("Browser worker returned invalid evidence"));
|
|
237
|
+
if (!(value.httpStatus === null || Number.isInteger(value.httpStatus) && value.httpStatus >= 100 && value.httpStatus <= 599) || !(value.contentType === null || typeof value.contentType === "string"))
|
|
238
|
+
return reject(new Error("Browser worker returned invalid HTTP evidence"));
|
|
239
|
+
resolve(value);
|
|
240
|
+
});
|
|
241
|
+
worker.send({ endpoint: browser.wsEndpoint(), url, scope: args.scope ?? "main" }, error => { if (error)
|
|
242
|
+
reject(error); });
|
|
243
|
+
});
|
|
244
|
+
signal.throwIfAborted();
|
|
245
|
+
snapshot = { ...result, id: `snap-${++snapshotCount}`, url: browserUrl(result.url), capturedAt: new Date().toISOString() };
|
|
246
|
+
store(snapshot, captureKey);
|
|
247
|
+
const start = args.scope !== "page" && snapshot.scope === "page" ? snapshotContentStart(snapshot.content) : 0;
|
|
248
|
+
return page(start);
|
|
249
|
+
})().finally(async () => {
|
|
250
|
+
worker?.kill("SIGKILL");
|
|
251
|
+
await browser?.close().catch(() => undefined);
|
|
252
|
+
await fs.rm(directory, { recursive: true, force: true });
|
|
253
|
+
});
|
|
254
|
+
try {
|
|
255
|
+
return await Promise.race([work, aborted]);
|
|
256
|
+
}
|
|
257
|
+
finally {
|
|
258
|
+
signal.removeEventListener("abort", abort);
|
|
259
|
+
if (signal.aborted) {
|
|
260
|
+
snapshot = undefined;
|
|
261
|
+
snapshots.clear();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
}, { name: "browser_read", capability: "browser_snapshot", readOnly: true,
|
|
266
|
+
description: "Find a short phrase/heading in a saved snapshot; keyword queries fall back to explicitly labeled approximate passage matches. Or page using offset/nextOffset. Recent snapshots stay readable. No network or script execution.",
|
|
267
|
+
inputSchema: { type: "object", properties: { snapshotId: { type: "string" }, query: { type: "string", minLength: 1, maxLength: 200 }, offset: { type: "integer", minimum: 0, maximum: 1000000 }, maxChars: { type: "integer", minimum: 100, maximum: 8000 } }, required: ["snapshotId"], additionalProperties: false },
|
|
268
|
+
handler: async (args, context) => {
|
|
269
|
+
context.signal?.throwIfAborted();
|
|
270
|
+
const input = args;
|
|
271
|
+
snapshot = snapshots.get(input.snapshotId);
|
|
272
|
+
if (!snapshot)
|
|
273
|
+
throw new ToolExecutionError("tool_invalid_args", `This browser snapshot is unavailable; open its URL again. Readable snapshots: ${JSON.stringify([...snapshots.values()].slice(-12).map(item => ({ snapshotId: item.id, url: item.url.slice(0, 160) })))}`);
|
|
274
|
+
snapshots.delete(snapshot.id);
|
|
275
|
+
snapshots.set(snapshot.id, snapshot);
|
|
276
|
+
if (input.query !== undefined) {
|
|
277
|
+
if (!input.query.trim() || input.query.length > 200)
|
|
278
|
+
throw new ToolExecutionError("tool_invalid_args", "Supply a nonempty literal search query of up to200 characters");
|
|
279
|
+
const found = findSnapshotText(snapshot.content, input.query, input.offset ?? 0);
|
|
280
|
+
if (!found)
|
|
281
|
+
return { output: JSON.stringify({ snapshotId: snapshot.id, url: snapshot.url, query: input.query, matchFound: false,
|
|
282
|
+
notice: "No matching passage in this captured snapshot; this does not prove the fact is absent from the underlying source. Try fewer distinctive words or another source page." }) };
|
|
283
|
+
return page(Math.max(0, found.index - (found.mode === "ranked_terms" ? 0 : 200)), input.maxChars, {
|
|
284
|
+
matchFound: true, matchMode: found.mode,
|
|
285
|
+
...(found.mode === "ranked_terms" ? { matchedTerms: found.matchedTerms, matchNotice: "Approximate keyword overlap, not a literal quotation or verification of the query's claim." } : {}),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return page(input.offset, input.maxChars);
|
|
289
|
+
},
|
|
290
|
+
}];
|
|
291
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrowserWorker.d.ts","sourceRoot":"","sources":["../../../src/tools/browser/BrowserWorker.ts"],"names":[],"mappings":""}
|