pi-agent-ide 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/assets/banner.png +0 -0
- package/docs/architecture.md +100 -0
- package/docs/configuration.md +104 -0
- package/docs/development.md +102 -0
- package/docs/evaluation.md +14 -0
- package/docs/extensions.md +298 -0
- package/docs/tools.md +104 -0
- package/node_modules/pi-agent-filesystem/index.ts +60 -0
- package/node_modules/pi-agent-filesystem/package.json +23 -0
- package/node_modules/pi-agent-filesystem/src/resolver.ts +175 -0
- package/node_modules/pi-agent-filesystem-image/index.ts +14 -0
- package/node_modules/pi-agent-filesystem-image/package.json +20 -0
- package/node_modules/pi-agent-filesystem-pdf/index.ts +14 -0
- package/node_modules/pi-agent-filesystem-pdf/package.json +17 -0
- package/node_modules/pi-agent-filesystem-text/index.ts +23 -0
- package/node_modules/pi-agent-filesystem-text/package.json +20 -0
- package/node_modules/pi-agent-ide-ast/index.ts +1 -0
- package/node_modules/pi-agent-ide-ast/package.json +39 -0
- package/node_modules/pi-agent-ide-ast/src/api/scope.ts +1 -0
- package/node_modules/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +374 -0
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +813 -0
- package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +85 -0
- package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +221 -0
- package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +141 -0
- package/node_modules/pi-agent-ide-changes/index.ts +68 -0
- package/node_modules/pi-agent-ide-changes/package.json +29 -0
- package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +103 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
- package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
- package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
- package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
- package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
- package/node_modules/pi-agent-ide-formatter/index.ts +33 -0
- package/node_modules/pi-agent-ide-formatter/package.json +14 -0
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +50 -0
- package/node_modules/pi-agent-ide-formatter/src/registry.ts +30 -0
- package/node_modules/pi-agent-ide-formatter/src/types.ts +10 -0
- package/node_modules/pi-agent-ide-lint/index.ts +237 -0
- package/node_modules/pi-agent-ide-lint/package.json +19 -0
- package/node_modules/pi-agent-ide-lint/src/command-linter.ts +160 -0
- package/node_modules/pi-agent-ide-lint/src/command-runner.ts +51 -0
- package/node_modules/pi-agent-ide-lint/src/registry.ts +30 -0
- package/node_modules/pi-agent-ide-lint/src/types.ts +10 -0
- package/node_modules/pi-agent-ide-lsp/index.ts +250 -0
- package/node_modules/pi-agent-ide-lsp/package.json +23 -0
- package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
- package/node_modules/pi-agent-image/package.json +18 -0
- package/node_modules/pi-agent-image/src/image-converter.ts +318 -0
- package/node_modules/pi-agent-image/src/index.ts +6 -0
- package/node_modules/pi-agent-pdf/package.json +16 -0
- package/node_modules/pi-agent-pdf/src/index.ts +5 -0
- package/node_modules/pi-agent-pdf/src/pdf-converter.ts +197 -0
- package/node_modules/pi-agent-read/index.ts +1 -0
- package/node_modules/pi-agent-read/package.json +41 -0
- package/node_modules/pi-agent-read/src/api/connect-plugin.ts +67 -0
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +67 -0
- package/node_modules/pi-agent-read/src/api/rendering.ts +11 -0
- package/node_modules/pi-agent-read/src/api/tools/read.ts +208 -0
- package/node_modules/pi-agent-read/src/core/extension.ts +40 -0
- package/node_modules/pi-agent-read/src/core/read-core.ts +390 -0
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
- package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +828 -0
- package/node_modules/pi-agent-resource/package.json +17 -0
- package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +84 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +49 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +29 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +73 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +152 -0
- package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +74 -0
- package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +149 -0
- package/node_modules/pi-agent-resource/src/content.ts +17 -0
- package/node_modules/pi-agent-resource/src/index.ts +65 -0
- package/node_modules/pi-agent-resource/src/resolver.ts +23 -0
- package/node_modules/pi-agent-resource/src/resource.ts +41 -0
- package/node_modules/pi-agent-resource/src/validation.ts +139 -0
- package/node_modules/pi-agent-search/index.ts +1 -0
- package/node_modules/pi-agent-search/package.json +35 -0
- package/node_modules/pi-agent-search/src/api/connect-plugin.ts +61 -0
- package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +60 -0
- package/node_modules/pi-agent-search/src/api/search.ts +91 -0
- package/node_modules/pi-agent-search/src/core/extension.ts +126 -0
- package/node_modules/pi-agent-search/src/core/search-core.ts +400 -0
- package/node_modules/pi-agent-search-semantic/index.ts +105 -0
- package/node_modules/pi-agent-search-semantic/package.json +17 -0
- package/node_modules/pi-agent-search-text/index.ts +54 -0
- package/node_modules/pi-agent-search-text/package.json +33 -0
- package/node_modules/pi-agent-search-text/src/file-search.ts +105 -0
- package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +192 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +295 -0
- package/node_modules/pi-agent-search-text/src/search-query.ts +139 -0
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +420 -0
- package/node_modules/pi-agent-search-text/src/search-result.ts +193 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +338 -0
- package/node_modules/pi-agent-search-web/index.ts +74 -0
- package/node_modules/pi-agent-search-web/package.json +19 -0
- package/node_modules/pi-agent-search-web/src/config.ts +499 -0
- package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
- package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +89 -0
- package/node_modules/pi-agent-search-web/src/providers/request.ts +430 -0
- package/node_modules/pi-agent-search-web/src/providers/response.ts +402 -0
- package/node_modules/pi-agent-search-web/src/search-format.ts +29 -0
- package/node_modules/pi-agent-search-web/src/search.ts +434 -0
- package/node_modules/pi-agent-search-web/src/types.ts +153 -0
- package/node_modules/pi-agent-text/package.json +18 -0
- package/node_modules/pi-agent-text/src/index.ts +31 -0
- package/node_modules/pi-agent-text/src/presented-text.ts +24 -0
- package/node_modules/pi-agent-text/src/source-line.ts +49 -0
- package/node_modules/pi-agent-text/src/text-anchor.ts +157 -0
- package/node_modules/pi-agent-text/src/text-converter.ts +109 -0
- package/node_modules/pi-agent-text/src/text-document.ts +149 -0
- package/node_modules/pi-agent-text-anchor-constant/index.ts +30 -0
- package/node_modules/pi-agent-text-anchor-constant/package.json +17 -0
- package/node_modules/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +48 -0
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +24 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
- package/node_modules/pi-agent-text-editor/index.ts +19 -0
- package/node_modules/pi-agent-text-editor/package.json +92 -0
- package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
- package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
- package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +147 -0
- package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
- package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +150 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +16 -0
- package/node_modules/pi-agent-text-editor/src/tools/extension.ts +19 -0
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
- package/node_modules/pi-agent-text-editor-argument-order/index.ts +29 -0
- package/node_modules/pi-agent-text-editor-argument-order/package.json +16 -0
- package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
- package/node_modules/pi-agent-text-editor-overwrite/index.ts +391 -0
- package/node_modules/pi-agent-text-editor-overwrite/package.json +16 -0
- package/node_modules/pi-agent-text-editor-renderer/index.ts +22 -0
- package/node_modules/pi-agent-text-editor-renderer/package.json +21 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
- package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
- package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
- package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +375 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +17 -0
- package/node_modules/pi-agent-tool-call-interception/package.json +17 -0
- package/node_modules/pi-agent-tool-call-interception/src/index.ts +418 -0
- package/node_modules/pi-agent-web/index.ts +37 -0
- package/node_modules/pi-agent-web/package.json +24 -0
- package/node_modules/pi-agent-web/src/resolver.ts +182 -0
- package/node_modules/pi-agent-web-html/index.ts +15 -0
- package/node_modules/pi-agent-web-html/package.json +18 -0
- package/node_modules/pi-agent-web-html/src/extract-readable-html.ts +101 -0
- package/node_modules/pi-agent-web-html/src/html-converter.ts +91 -0
- package/node_modules/pi-agent-web-image/index.ts +14 -0
- package/node_modules/pi-agent-web-image/package.json +17 -0
- package/node_modules/pi-agent-web-pdf/index.ts +14 -0
- package/node_modules/pi-agent-web-pdf/package.json +17 -0
- package/node_modules/pi-agent-web-text/index.ts +14 -0
- package/node_modules/pi-agent-web-text/package.json +17 -0
- package/package.json +176 -0
- package/src/api/code-view.ts +25 -0
- package/src/api/connect-plugin.ts +64 -0
- package/src/api/plugin-protocol.ts +63 -0
- package/src/api/read.ts +5 -0
- package/src/api/resource.ts +2 -0
- package/src/api/search.ts +4 -0
- package/src/api/text-editor.ts +3 -0
- package/src/api/text.ts +2 -0
- package/src/api/toolchain.ts +24 -0
- package/src/code-view/diagnostic-view.ts +82 -0
- package/src/code-view/reference.ts +113 -0
- package/src/code-view/source-view.ts +229 -0
- package/src/composite/builtin-extensions.ts +68 -0
- package/src/composite/config.ts +94 -0
- package/src/composite/selection.ts +66 -0
- package/src/core/extension.ts +48 -0
- package/src/core/ide-core.ts +117 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +60 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +20 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/index.ts +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +20 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +175 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +37 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +24 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +15 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +18 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/extract-readable-html.ts +101 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +91 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +182 -0
- package/src/extensions/pi-agent-read/index.ts +1 -0
- package/src/extensions/pi-agent-read/package.json +41 -0
- package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +67 -0
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +67 -0
- package/src/extensions/pi-agent-read/src/api/rendering.ts +11 -0
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +208 -0
- package/src/extensions/pi-agent-read/src/core/extension.ts +40 -0
- package/src/extensions/pi-agent-read/src/core/read-core.ts +390 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +828 -0
- package/src/extensions/pi-agent-search/index.ts +1 -0
- package/src/extensions/pi-agent-search/package.json +35 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +105 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/package.json +17 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +54 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +33 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +105 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +192 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +295 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +139 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +420 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +193 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +338 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +74 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +19 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +499 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +89 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +430 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +402 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +29 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +434 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +153 -0
- package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +61 -0
- package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +60 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +91 -0
- package/src/extensions/pi-agent-search/src/core/extension.ts +126 -0
- package/src/extensions/pi-agent-search/src/core/search-core.ts +400 -0
- package/src/extensions/pi-agent-text-editor/index.ts +19 -0
- package/src/extensions/pi-agent-text-editor/package.json +92 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +30 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +17 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +48 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +24 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +29 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +16 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +391 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +16 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +22 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +21 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +375 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +17 -0
- package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
- package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
- package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +147 -0
- package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
- package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +150 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +16 -0
- package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +19 -0
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
- package/src/index.ts +1 -0
- package/src/pi-agent-ide.ts +17 -0
- package/src/plugins/pi-agent-ide-ast/index.ts +1 -0
- package/src/plugins/pi-agent-ide-ast/package.json +39 -0
- package/src/plugins/pi-agent-ide-ast/src/api/scope.ts +1 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +374 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +813 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +85 -0
- package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +221 -0
- package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +141 -0
- package/src/plugins/pi-agent-ide-changes/index.ts +68 -0
- package/src/plugins/pi-agent-ide-changes/package.json +29 -0
- package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +103 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
- package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
- package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
- package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
- package/src/plugins/pi-agent-ide-formatter/index.ts +33 -0
- package/src/plugins/pi-agent-ide-formatter/package.json +14 -0
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +50 -0
- package/src/plugins/pi-agent-ide-formatter/src/registry.ts +30 -0
- package/src/plugins/pi-agent-ide-formatter/src/types.ts +10 -0
- package/src/plugins/pi-agent-ide-lint/index.ts +237 -0
- package/src/plugins/pi-agent-ide-lint/package.json +19 -0
- package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +160 -0
- package/src/plugins/pi-agent-ide-lint/src/command-runner.ts +51 -0
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +30 -0
- package/src/plugins/pi-agent-ide-lint/src/types.ts +10 -0
- package/src/plugins/pi-agent-ide-lsp/index.ts +250 -0
- package/src/plugins/pi-agent-ide-lsp/package.json +23 -0
- package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
- package/src/post-edit/gate.ts +153 -0
- package/src/toolchain/diagnostic.ts +7 -0
- package/src/toolchain/gate.ts +322 -0
- package/src/toolchain/registry.ts +223 -0
- package/src/toolchain/types.ts +164 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { buildSearchRequest } from "./providers/request.ts";
|
|
2
|
+
import { normalizeSearchResponse } from "./providers/response.ts";
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
JsonObject,
|
|
6
|
+
RoutingStrategy,
|
|
7
|
+
SearchAttempt,
|
|
8
|
+
SearchDetails,
|
|
9
|
+
SearchProviderEntry,
|
|
10
|
+
SearchRequest,
|
|
11
|
+
WebsearchConfig,
|
|
12
|
+
} from "./types.ts";
|
|
13
|
+
|
|
14
|
+
export { formatSearchText } from "./search-format.ts";
|
|
15
|
+
|
|
16
|
+
const MAX_ERROR_DETAIL_LENGTH = 500;
|
|
17
|
+
|
|
18
|
+
function isJsonObject(value: unknown): value is JsonObject
|
|
19
|
+
{
|
|
20
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isWebUrl(value: string): boolean
|
|
24
|
+
{
|
|
25
|
+
try
|
|
26
|
+
{
|
|
27
|
+
const url = new URL(value);
|
|
28
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
29
|
+
}
|
|
30
|
+
catch
|
|
31
|
+
{
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function truncate(value: string, max: number): string
|
|
37
|
+
{
|
|
38
|
+
return value.length > max ? `${value.slice(0, max - 1)}…` : value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function extractErrorDetail(payload: unknown, bodyText: string): string
|
|
42
|
+
{
|
|
43
|
+
if (isJsonObject(payload))
|
|
44
|
+
{
|
|
45
|
+
const obj = payload;
|
|
46
|
+
const error = obj.error;
|
|
47
|
+
|
|
48
|
+
if (typeof error === "string" && error.length > 0)
|
|
49
|
+
{
|
|
50
|
+
return truncate(error, MAX_ERROR_DETAIL_LENGTH);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (isJsonObject(error))
|
|
54
|
+
{
|
|
55
|
+
const message = error.message;
|
|
56
|
+
|
|
57
|
+
if (typeof message === "string" && message.length > 0)
|
|
58
|
+
{
|
|
59
|
+
return truncate(message, MAX_ERROR_DETAIL_LENGTH);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const message = obj.message;
|
|
64
|
+
|
|
65
|
+
if (typeof message === "string" && message.length > 0)
|
|
66
|
+
{
|
|
67
|
+
return truncate(message, MAX_ERROR_DETAIL_LENGTH);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const trimmed = bodyText.trim();
|
|
72
|
+
|
|
73
|
+
if (!trimmed)
|
|
74
|
+
{
|
|
75
|
+
return "";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return truncate(trimmed, MAX_ERROR_DETAIL_LENGTH);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function httpErrorMessage(status: number, payload: unknown, bodyText: string): string
|
|
82
|
+
{
|
|
83
|
+
const detail = extractErrorDetail(payload, bodyText);
|
|
84
|
+
return detail ? `Search failed with HTTP ${status}: ${detail}` : `Search failed with HTTP ${status}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface SearchRoutingState
|
|
88
|
+
{
|
|
89
|
+
roundRobinCursor: number;
|
|
90
|
+
successCounts: number[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function createSearchRoutingState(providerCount: number): SearchRoutingState
|
|
94
|
+
{
|
|
95
|
+
return { roundRobinCursor: 0, successCounts: Array.from({ length: providerCount }, () => 0) };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function entryLabel(entry: Pick<SearchProviderEntry, "provider" | "id"> | SearchAttempt): string
|
|
99
|
+
{
|
|
100
|
+
if ("entryId" in entry && entry.entryId)
|
|
101
|
+
{
|
|
102
|
+
return `${entry.provider}/${entry.entryId}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if ("id" in entry && entry.id)
|
|
106
|
+
{
|
|
107
|
+
return `${entry.provider}/${entry.id}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return entry.provider;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function sortedPriorityIndices(providers: SearchProviderEntry[]): number[]
|
|
114
|
+
{
|
|
115
|
+
return providers
|
|
116
|
+
.map((provider, index) => ({ index, priority: provider.priority ?? index }))
|
|
117
|
+
.sort((left, right) => left.priority - right.priority || left.index - right.index)
|
|
118
|
+
.map((item) => item.index);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function weightedIndices(providers: SearchProviderEntry[]): number[]
|
|
122
|
+
{
|
|
123
|
+
const indices: number[] = [];
|
|
124
|
+
|
|
125
|
+
for (const [index, provider] of providers.entries())
|
|
126
|
+
{
|
|
127
|
+
const weight = Math.max(1, Math.trunc(provider.weight ?? 1));
|
|
128
|
+
|
|
129
|
+
for (let count = 0; count < weight; count += 1)
|
|
130
|
+
{
|
|
131
|
+
indices.push(index);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return indices.length > 0 ? indices : providers.map((_provider, index) => index);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function rotateUnique(indices: number[], start: number, providerCount: number): number[]
|
|
139
|
+
{
|
|
140
|
+
const order: number[] = [];
|
|
141
|
+
|
|
142
|
+
for (let offset = 0; offset < indices.length; offset += 1)
|
|
143
|
+
{
|
|
144
|
+
const index = indices[(start + offset) % indices.length];
|
|
145
|
+
|
|
146
|
+
if (index !== undefined && !order.includes(index))
|
|
147
|
+
{
|
|
148
|
+
order.push(index);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for (let index = 0; index < providerCount; index += 1)
|
|
153
|
+
{
|
|
154
|
+
if (!order.includes(index))
|
|
155
|
+
{
|
|
156
|
+
order.push(index);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return order;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function selectOrder(strategy: RoutingStrategy, providers: SearchProviderEntry[], state: SearchRoutingState): number[]
|
|
164
|
+
{
|
|
165
|
+
if (strategy === "priority")
|
|
166
|
+
{
|
|
167
|
+
return sortedPriorityIndices(providers);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (strategy === "round-robin")
|
|
171
|
+
{
|
|
172
|
+
const indices = weightedIndices(providers);
|
|
173
|
+
const order = rotateUnique(indices, state.roundRobinCursor % indices.length, providers.length);
|
|
174
|
+
state.roundRobinCursor = (state.roundRobinCursor + 1) % indices.length;
|
|
175
|
+
return order;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let selected = 0;
|
|
179
|
+
let selectedCount = state.successCounts[0] ?? 0;
|
|
180
|
+
|
|
181
|
+
for (let index = 1; index < providers.length; index += 1)
|
|
182
|
+
{
|
|
183
|
+
const count = state.successCounts[index] ?? 0;
|
|
184
|
+
|
|
185
|
+
if (count < selectedCount)
|
|
186
|
+
{
|
|
187
|
+
selected = index;
|
|
188
|
+
selectedCount = count;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return [selected, ...providers.map((_provider, index) => index).filter((index) => index !== selected)];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function performProviderSearch(
|
|
196
|
+
config: SearchProviderEntry,
|
|
197
|
+
request: SearchRequest,
|
|
198
|
+
signal?: AbortSignal,
|
|
199
|
+
): Promise<SearchDetails>
|
|
200
|
+
{
|
|
201
|
+
const startedAt = Date.now();
|
|
202
|
+
const built = buildSearchRequest(config, request);
|
|
203
|
+
let response: Response;
|
|
204
|
+
|
|
205
|
+
try
|
|
206
|
+
{
|
|
207
|
+
const init: RequestInit = {
|
|
208
|
+
...built.init,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
if (built.body !== undefined)
|
|
212
|
+
{
|
|
213
|
+
init.body = JSON.stringify(built.body);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (signal !== undefined)
|
|
217
|
+
{
|
|
218
|
+
init.signal = signal;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
response = await fetch(built.url, init);
|
|
222
|
+
}
|
|
223
|
+
catch (error)
|
|
224
|
+
{
|
|
225
|
+
signal?.throwIfAborted();
|
|
226
|
+
const details: SearchDetails = {
|
|
227
|
+
provider: config.provider,
|
|
228
|
+
query: request.query,
|
|
229
|
+
results: [],
|
|
230
|
+
durationMs: Date.now() - startedAt,
|
|
231
|
+
truncated: false,
|
|
232
|
+
error: error instanceof Error ? error.message : "Search request failed",
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
if (config.id !== undefined)
|
|
236
|
+
{
|
|
237
|
+
details.entryId = config.id;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return details;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
let bodyText = "";
|
|
244
|
+
|
|
245
|
+
try
|
|
246
|
+
{
|
|
247
|
+
bodyText = await response.text();
|
|
248
|
+
}
|
|
249
|
+
catch
|
|
250
|
+
{
|
|
251
|
+
signal?.throwIfAborted();
|
|
252
|
+
bodyText = "";
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
let payload: unknown = {};
|
|
256
|
+
|
|
257
|
+
if (config.provider === "duckduckgo-html")
|
|
258
|
+
{
|
|
259
|
+
payload = { html: bodyText };
|
|
260
|
+
}
|
|
261
|
+
else if (bodyText.length > 0)
|
|
262
|
+
{
|
|
263
|
+
try
|
|
264
|
+
{
|
|
265
|
+
payload = JSON.parse(bodyText);
|
|
266
|
+
}
|
|
267
|
+
catch
|
|
268
|
+
{
|
|
269
|
+
payload = {};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (!response.ok)
|
|
274
|
+
{
|
|
275
|
+
const details: SearchDetails = {
|
|
276
|
+
provider: config.provider,
|
|
277
|
+
query: request.query,
|
|
278
|
+
results: [],
|
|
279
|
+
durationMs: Date.now() - startedAt,
|
|
280
|
+
truncated: false,
|
|
281
|
+
error: httpErrorMessage(response.status, payload, bodyText),
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
if (config.id !== undefined)
|
|
285
|
+
{
|
|
286
|
+
details.entryId = config.id;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return details;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const results = normalizeSearchResponse(config.provider, payload).filter((item) => isWebUrl(item.url));
|
|
293
|
+
const max = request.maxResults;
|
|
294
|
+
const details: SearchDetails = {
|
|
295
|
+
provider: config.provider,
|
|
296
|
+
query: request.query,
|
|
297
|
+
results: results.slice(0, max),
|
|
298
|
+
durationMs: Date.now() - startedAt,
|
|
299
|
+
truncated: results.length > max,
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
if (config.id !== undefined)
|
|
303
|
+
{
|
|
304
|
+
details.entryId = config.id;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return details;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function attemptFromDetails(details: SearchDetails): SearchAttempt
|
|
311
|
+
{
|
|
312
|
+
const attempt: SearchAttempt = {
|
|
313
|
+
provider: details.provider,
|
|
314
|
+
durationMs: details.durationMs,
|
|
315
|
+
resultsCount: details.results.length,
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
if (details.entryId)
|
|
319
|
+
{
|
|
320
|
+
attempt.entryId = details.entryId;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (details.error)
|
|
324
|
+
{
|
|
325
|
+
attempt.error = details.error;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return attempt;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export async function performSearch(
|
|
332
|
+
config: WebsearchConfig,
|
|
333
|
+
request: SearchRequest,
|
|
334
|
+
signal?: AbortSignal,
|
|
335
|
+
routingState?: SearchRoutingState,
|
|
336
|
+
): Promise<SearchDetails>
|
|
337
|
+
{
|
|
338
|
+
const startedAt = Date.now();
|
|
339
|
+
const state = routingState ?? createSearchRoutingState(config.providers.length);
|
|
340
|
+
const order = selectOrder(config.strategy, config.providers, state);
|
|
341
|
+
const attempts: SearchAttempt[] = [];
|
|
342
|
+
const collected = new Map<string, SearchDetails["results"][number]>();
|
|
343
|
+
let selectedDetails: SearchDetails | undefined;
|
|
344
|
+
|
|
345
|
+
for (const index of order)
|
|
346
|
+
{
|
|
347
|
+
signal?.throwIfAborted();
|
|
348
|
+
const provider = config.providers[index];
|
|
349
|
+
|
|
350
|
+
if (!provider)
|
|
351
|
+
{
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const details = await performProviderSearch(provider, request, signal);
|
|
356
|
+
attempts.push(attemptFromDetails(details));
|
|
357
|
+
|
|
358
|
+
if (details.error || details.results.length === 0)
|
|
359
|
+
{
|
|
360
|
+
if (!config.fallback)
|
|
361
|
+
{
|
|
362
|
+
return { ...details, strategy: config.strategy, attempts };
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
selectedDetails = details;
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
state.successCounts[index] = (state.successCounts[index] ?? 0) + 1;
|
|
370
|
+
|
|
371
|
+
if (config.strategy !== "fill-first")
|
|
372
|
+
{
|
|
373
|
+
return { ...details, strategy: config.strategy, attempts };
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
selectedDetails = details;
|
|
377
|
+
|
|
378
|
+
for (const item of details.results)
|
|
379
|
+
{
|
|
380
|
+
if (collected.size >= request.maxResults)
|
|
381
|
+
{
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
collected.set(item.url, item);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (collected.size >= request.maxResults)
|
|
389
|
+
{
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (collected.size > 0 && selectedDetails)
|
|
395
|
+
{
|
|
396
|
+
const results = [...collected.values()];
|
|
397
|
+
const details: SearchDetails = {
|
|
398
|
+
provider: selectedDetails.provider,
|
|
399
|
+
query: request.query,
|
|
400
|
+
results,
|
|
401
|
+
durationMs: Date.now() - startedAt,
|
|
402
|
+
truncated: results.length >= request.maxResults,
|
|
403
|
+
strategy: config.strategy,
|
|
404
|
+
attempts,
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
if (selectedDetails.entryId !== undefined)
|
|
408
|
+
{
|
|
409
|
+
details.entryId = selectedDetails.entryId;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return details;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const failed = selectedDetails ?? {
|
|
416
|
+
provider: config.providers[0]?.provider ?? "exa",
|
|
417
|
+
query: request.query,
|
|
418
|
+
results: [],
|
|
419
|
+
durationMs: Date.now() - startedAt,
|
|
420
|
+
truncated: false,
|
|
421
|
+
error: "All configured search providers failed.",
|
|
422
|
+
};
|
|
423
|
+
return {
|
|
424
|
+
...failed,
|
|
425
|
+
durationMs: Date.now() - startedAt,
|
|
426
|
+
strategy: config.strategy,
|
|
427
|
+
attempts,
|
|
428
|
+
error: `All configured search providers failed: ${
|
|
429
|
+
attempts
|
|
430
|
+
.map((attempt) => `${entryLabel(attempt)} ${attempt.error ?? "returned no usable results"}`)
|
|
431
|
+
.join("; ")
|
|
432
|
+
}`,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export type SearchProvider =
|
|
2
|
+
| "exa"
|
|
3
|
+
| "tavily"
|
|
4
|
+
| "brave"
|
|
5
|
+
| "duckduckgo-html"
|
|
6
|
+
| "serper"
|
|
7
|
+
| "parallel"
|
|
8
|
+
| "google-cse"
|
|
9
|
+
| "z-ai"
|
|
10
|
+
| "openai"
|
|
11
|
+
| "codex"
|
|
12
|
+
| "anthropic"
|
|
13
|
+
| "perplexity"
|
|
14
|
+
| "xai"
|
|
15
|
+
| "kimi";
|
|
16
|
+
|
|
17
|
+
export type SearchContextSize = "low" | "medium" | "high";
|
|
18
|
+
|
|
19
|
+
export type CodexSearchMode = "cached" | "live";
|
|
20
|
+
|
|
21
|
+
export type RoutingStrategy = "priority" | "round-robin" | "fill-first";
|
|
22
|
+
|
|
23
|
+
export interface SearchProviderConfig
|
|
24
|
+
{
|
|
25
|
+
id?: string;
|
|
26
|
+
provider: SearchProvider;
|
|
27
|
+
apiKey?: string;
|
|
28
|
+
baseUrl?: string;
|
|
29
|
+
searchEngineId?: string;
|
|
30
|
+
maxResults?: number;
|
|
31
|
+
model?: string;
|
|
32
|
+
codexMode?: CodexSearchMode;
|
|
33
|
+
searchContextSize?: SearchContextSize;
|
|
34
|
+
allowedDomains?: string[];
|
|
35
|
+
blockedDomains?: string[];
|
|
36
|
+
userLocation?: SearchUserLocation;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SearchProviderEntry extends SearchProviderConfig
|
|
40
|
+
{
|
|
41
|
+
priority?: number;
|
|
42
|
+
weight?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface WebsearchConfig
|
|
46
|
+
{
|
|
47
|
+
strategy: RoutingStrategy;
|
|
48
|
+
fallback: boolean;
|
|
49
|
+
providers: SearchProviderEntry[];
|
|
50
|
+
providerOrder?: string[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface SearchUserLocation
|
|
54
|
+
{
|
|
55
|
+
country?: string;
|
|
56
|
+
region?: string;
|
|
57
|
+
city?: string;
|
|
58
|
+
timezone?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface SearchRequest
|
|
62
|
+
{
|
|
63
|
+
query: string;
|
|
64
|
+
maxResults: number;
|
|
65
|
+
allowedDomains?: string[];
|
|
66
|
+
blockedDomains?: string[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface BuiltSearchRequest
|
|
70
|
+
{
|
|
71
|
+
url: string;
|
|
72
|
+
init: {
|
|
73
|
+
method: "GET" | "POST";
|
|
74
|
+
headers: Record<string, string>;
|
|
75
|
+
};
|
|
76
|
+
body?: JsonObject;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface SearchResultItem
|
|
80
|
+
{
|
|
81
|
+
title: string;
|
|
82
|
+
url: string;
|
|
83
|
+
snippet?: string;
|
|
84
|
+
score?: number;
|
|
85
|
+
source?: string;
|
|
86
|
+
publishedAt?: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface SearchDetails
|
|
90
|
+
{
|
|
91
|
+
provider: SearchProvider;
|
|
92
|
+
entryId?: string;
|
|
93
|
+
query: string;
|
|
94
|
+
results: SearchResultItem[];
|
|
95
|
+
durationMs: number;
|
|
96
|
+
truncated: boolean;
|
|
97
|
+
strategy?: RoutingStrategy;
|
|
98
|
+
attempts?: SearchAttempt[];
|
|
99
|
+
answer?: string;
|
|
100
|
+
error?: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface SearchProgressDetails
|
|
104
|
+
{
|
|
105
|
+
phase: "searching";
|
|
106
|
+
query: string;
|
|
107
|
+
providerLabels: string[];
|
|
108
|
+
maxResults: number;
|
|
109
|
+
strategy?: RoutingStrategy;
|
|
110
|
+
allowedDomains?: string[];
|
|
111
|
+
blockedDomains?: string[];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type ConfigLoadFailureReason = "invalid_config" | "missing_api_key";
|
|
115
|
+
|
|
116
|
+
export interface SearchErrorDetails
|
|
117
|
+
{
|
|
118
|
+
phase: "error";
|
|
119
|
+
query: string;
|
|
120
|
+
error: string;
|
|
121
|
+
reason?: ConfigLoadFailureReason;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type SearchRenderDetails = SearchDetails | SearchProgressDetails | SearchErrorDetails;
|
|
125
|
+
|
|
126
|
+
export interface SearchAttempt
|
|
127
|
+
{
|
|
128
|
+
provider: SearchProvider;
|
|
129
|
+
entryId?: string;
|
|
130
|
+
durationMs: number;
|
|
131
|
+
resultsCount: number;
|
|
132
|
+
error?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type JsonValue = string | number | boolean | null | JsonObject | JsonValue[];
|
|
136
|
+
|
|
137
|
+
export interface JsonObject
|
|
138
|
+
{
|
|
139
|
+
[key: string]: JsonValue;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export type ConfigLoadResult =
|
|
143
|
+
| { ok: true; config: WebsearchConfig; source: string; }
|
|
144
|
+
| {
|
|
145
|
+
ok: false;
|
|
146
|
+
reason: ConfigLoadFailureReason;
|
|
147
|
+
message: string;
|
|
148
|
+
source?: string;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export type ProviderValidationResult =
|
|
152
|
+
| { ok: true; config: SearchProviderEntry; }
|
|
153
|
+
| { ok: false; reason: "invalid_config" | "missing_api_key"; message: string; };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isSearchCoreReady,
|
|
3
|
+
SEARCH_CORE_READY_EVENT,
|
|
4
|
+
SEARCH_PLUGIN_REGISTER_EVENT,
|
|
5
|
+
type SearchPlugin,
|
|
6
|
+
type SearchPluginRegistrationRequest,
|
|
7
|
+
} from "#src/api/plugin-protocol.js";
|
|
8
|
+
|
|
9
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
10
|
+
|
|
11
|
+
export function connectSearchPlugin(pi: ExtensionAPI, plugin: SearchPlugin): void | Promise<void>
|
|
12
|
+
{
|
|
13
|
+
const announce = (): Promise<void> | undefined =>
|
|
14
|
+
{
|
|
15
|
+
let registration: Promise<void> | undefined;
|
|
16
|
+
const request = {
|
|
17
|
+
plugin,
|
|
18
|
+
accept(value): void
|
|
19
|
+
{
|
|
20
|
+
if (registration !== undefined)
|
|
21
|
+
{
|
|
22
|
+
throw new Error(`Plugin ${plugin.id} registration was accepted more than once`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
registration = value;
|
|
26
|
+
},
|
|
27
|
+
} satisfies SearchPluginRegistrationRequest;
|
|
28
|
+
pi.events.emit(SEARCH_PLUGIN_REGISTER_EVENT, request);
|
|
29
|
+
return registration;
|
|
30
|
+
};
|
|
31
|
+
let unsubscribe = (): void =>
|
|
32
|
+
{};
|
|
33
|
+
unsubscribe = pi.events.on(SEARCH_CORE_READY_EVENT, (ready) =>
|
|
34
|
+
{
|
|
35
|
+
if (!isSearchCoreReady(ready))
|
|
36
|
+
{
|
|
37
|
+
throw new Error("Invalid pi-agent-search core readiness event");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const registration = announce();
|
|
41
|
+
|
|
42
|
+
if (registration === undefined)
|
|
43
|
+
{
|
|
44
|
+
throw new Error("pi-agent-search core announced readiness without accepting the plugin");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
unsubscribe();
|
|
48
|
+
void registration.catch(() =>
|
|
49
|
+
{});
|
|
50
|
+
});
|
|
51
|
+
pi.on("session_shutdown", unsubscribe);
|
|
52
|
+
const registration = announce();
|
|
53
|
+
|
|
54
|
+
if (registration === undefined)
|
|
55
|
+
{
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
unsubscribe();
|
|
60
|
+
return registration;
|
|
61
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { Value } from "typebox/value";
|
|
3
|
+
|
|
4
|
+
import type { SearchPluginApi } from "#src/api/search.js";
|
|
5
|
+
|
|
6
|
+
export const SEARCH_PROTOCOL = "pi-agent-search" as const;
|
|
7
|
+
|
|
8
|
+
export const SEARCH_API_VERSION = 1 as const;
|
|
9
|
+
|
|
10
|
+
export const SEARCH_CORE_READY_EVENT = "pi-agent-search/core/ready" as const;
|
|
11
|
+
|
|
12
|
+
export const SEARCH_PLUGIN_REGISTER_EVENT = "pi-agent-search/plugin/register" as const;
|
|
13
|
+
|
|
14
|
+
export interface SearchCoreReady
|
|
15
|
+
{
|
|
16
|
+
readonly protocol: typeof SEARCH_PROTOCOL;
|
|
17
|
+
readonly apiVersion: typeof SEARCH_API_VERSION;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SearchPlugin
|
|
21
|
+
{
|
|
22
|
+
readonly protocol: typeof SEARCH_PROTOCOL;
|
|
23
|
+
readonly apiVersion: typeof SEARCH_API_VERSION;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly setup: (api: SearchPluginApi) => void | Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SearchPluginRegistrationRequest
|
|
29
|
+
{
|
|
30
|
+
readonly plugin: SearchPlugin;
|
|
31
|
+
accept(registration: Promise<void>): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const functionSchema = Type.Unsafe<(...args: never[]) => unknown>({ type: "Function" });
|
|
35
|
+
const coreReadySchema = Type.Object({
|
|
36
|
+
protocol: Type.Literal(SEARCH_PROTOCOL),
|
|
37
|
+
apiVersion: Type.Literal(SEARCH_API_VERSION),
|
|
38
|
+
});
|
|
39
|
+
const pluginSchema = Type.Object({
|
|
40
|
+
protocol: Type.Literal(SEARCH_PROTOCOL),
|
|
41
|
+
apiVersion: Type.Literal(SEARCH_API_VERSION),
|
|
42
|
+
id: Type.String({ minLength: 1 }),
|
|
43
|
+
setup: functionSchema,
|
|
44
|
+
});
|
|
45
|
+
const registrationSchema = Type.Object({ plugin: pluginSchema, accept: functionSchema });
|
|
46
|
+
|
|
47
|
+
export function isSearchCoreReady(value: unknown): value is SearchCoreReady
|
|
48
|
+
{
|
|
49
|
+
return Value.Check(coreReadySchema, value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function isSearchPlugin(value: unknown): value is SearchPlugin
|
|
53
|
+
{
|
|
54
|
+
return Value.Check(pluginSchema, value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isSearchPluginRegistrationRequest(value: unknown): value is SearchPluginRegistrationRequest
|
|
58
|
+
{
|
|
59
|
+
return Value.Check(registrationSchema, value);
|
|
60
|
+
}
|