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,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-agent-resource",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"types": "./src/index.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
|
+
"default": "./src/index.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@earendil-works/pi-ai": "*",
|
|
14
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
15
|
+
"typebox": "*"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { targetsEqual } from "./content-runner.js";
|
|
2
|
+
import {
|
|
3
|
+
CONTENT_CONVERTER_REGISTER_EVENT,
|
|
4
|
+
CONTENT_HOST_READY_EVENT,
|
|
5
|
+
type ContentConverterRegistrationRequest,
|
|
6
|
+
isContentHostReady,
|
|
7
|
+
} from "./plugin-protocol.js";
|
|
8
|
+
import { isContentConverterRegistration } from "./validation.js";
|
|
9
|
+
|
|
10
|
+
import type { ContentConverterRegistration } from "./content-converter.js";
|
|
11
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
12
|
+
|
|
13
|
+
export function connectContentConverter(
|
|
14
|
+
pi: ExtensionAPI,
|
|
15
|
+
registration: ContentConverterRegistration,
|
|
16
|
+
): void | Promise<void>
|
|
17
|
+
{
|
|
18
|
+
if (!isContentConverterRegistration(registration))
|
|
19
|
+
{
|
|
20
|
+
throw new TypeError("Invalid content converter registration");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const announce = (): Promise<void> | undefined =>
|
|
24
|
+
{
|
|
25
|
+
let accepted: Promise<void> | undefined;
|
|
26
|
+
const request = {
|
|
27
|
+
registration,
|
|
28
|
+
accept(result): void
|
|
29
|
+
{
|
|
30
|
+
if (accepted !== undefined)
|
|
31
|
+
{
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Content converter ${registration.converter.id} registration was accepted more than once`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
accepted = result;
|
|
38
|
+
},
|
|
39
|
+
} satisfies ContentConverterRegistrationRequest;
|
|
40
|
+
|
|
41
|
+
pi.events.emit(CONTENT_CONVERTER_REGISTER_EVENT, request);
|
|
42
|
+
return accepted;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let unsubscribe = (): void =>
|
|
46
|
+
{};
|
|
47
|
+
unsubscribe = pi.events.on(CONTENT_HOST_READY_EVENT, (ready) =>
|
|
48
|
+
{
|
|
49
|
+
if (!isContentHostReady(ready))
|
|
50
|
+
{
|
|
51
|
+
throw new Error("Invalid content conversion host readiness event");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!targetsEqual(registration.target, ready.target))
|
|
55
|
+
{
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const accepted = announce();
|
|
60
|
+
|
|
61
|
+
if (accepted === undefined)
|
|
62
|
+
{
|
|
63
|
+
throw new Error(
|
|
64
|
+
`${ready.target.provider}/${ready.target.capability} announced readiness without accepting `
|
|
65
|
+
+ `content converter ${registration.converter.id}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
unsubscribe();
|
|
70
|
+
void accepted.catch(() =>
|
|
71
|
+
{});
|
|
72
|
+
});
|
|
73
|
+
pi.on("session_shutdown", unsubscribe);
|
|
74
|
+
|
|
75
|
+
const accepted = announce();
|
|
76
|
+
|
|
77
|
+
if (accepted === undefined)
|
|
78
|
+
{
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
unsubscribe();
|
|
83
|
+
return accepted;
|
|
84
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AgentContent } from "../content.js";
|
|
2
|
+
|
|
3
|
+
export type ContentCapability = "read" | "write";
|
|
4
|
+
|
|
5
|
+
export interface ContentTarget
|
|
6
|
+
{
|
|
7
|
+
readonly provider: string;
|
|
8
|
+
readonly capability: ContentCapability;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ContentInput
|
|
12
|
+
{
|
|
13
|
+
readonly source: string;
|
|
14
|
+
readonly bytes: Uint8Array;
|
|
15
|
+
readonly mediaType?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ContentConversionContext
|
|
19
|
+
{
|
|
20
|
+
readonly signal?: AbortSignal;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type ContentConversionAttempt =
|
|
24
|
+
| { readonly kind: "not-handled"; }
|
|
25
|
+
| { readonly kind: "converted"; readonly content: AgentContent; }
|
|
26
|
+
| { readonly kind: "failed"; readonly error: unknown; };
|
|
27
|
+
|
|
28
|
+
export interface ContentDescription
|
|
29
|
+
{
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly description: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ContentConverter
|
|
35
|
+
{
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly description: string;
|
|
38
|
+
tryConvert(
|
|
39
|
+
input: ContentInput,
|
|
40
|
+
context: ContentConversionContext,
|
|
41
|
+
): Promise<ContentConversionAttempt>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ContentConverterRegistration
|
|
45
|
+
{
|
|
46
|
+
readonly target: ContentTarget;
|
|
47
|
+
readonly converter: ContentConverter;
|
|
48
|
+
readonly priority?: number;
|
|
49
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ContentDescription } from "./content-converter.js";
|
|
2
|
+
|
|
3
|
+
export function renderContentDescription(
|
|
4
|
+
summary: string,
|
|
5
|
+
descriptions: readonly ContentDescription[],
|
|
6
|
+
): string | undefined
|
|
7
|
+
{
|
|
8
|
+
if (descriptions.length === 0)
|
|
9
|
+
{
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const normalizedSummary = summary.trim();
|
|
14
|
+
|
|
15
|
+
if (normalizedSummary.length === 0 || /[\r\n]/u.test(normalizedSummary))
|
|
16
|
+
{
|
|
17
|
+
throw new TypeError("Content provider summary must be one non-empty line");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return [
|
|
21
|
+
normalizedSummary,
|
|
22
|
+
...descriptions.map(({ id, description }) => `- \`${escapeInlineCode(id)}\` — ${description}`),
|
|
23
|
+
].join("\n");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function escapeInlineCode(value: string): string
|
|
27
|
+
{
|
|
28
|
+
return value.replaceAll("`", "\\`");
|
|
29
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createContentRunner, targetsEqual } from "./content-runner.js";
|
|
2
|
+
import {
|
|
3
|
+
CONTENT_API_VERSION,
|
|
4
|
+
CONTENT_CONVERTER_REGISTER_EVENT,
|
|
5
|
+
CONTENT_HOST_READY_EVENT,
|
|
6
|
+
CONTENT_PROTOCOL,
|
|
7
|
+
isContentConverterRegistrationRequest,
|
|
8
|
+
} from "./plugin-protocol.js";
|
|
9
|
+
|
|
10
|
+
import type { ContentConversionContext, ContentDescription, ContentInput, ContentTarget } from "./content-converter.js";
|
|
11
|
+
import type { AgentContent } from "../content.js";
|
|
12
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
|
|
14
|
+
export interface ContentHost
|
|
15
|
+
{
|
|
16
|
+
readonly target: ContentTarget;
|
|
17
|
+
listDescriptions(): readonly ContentDescription[];
|
|
18
|
+
convert(input: ContentInput, context: ContentConversionContext): Promise<AgentContent>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createContentHost(pi: ExtensionAPI, target: ContentTarget): ContentHost
|
|
22
|
+
{
|
|
23
|
+
const runner = createContentRunner(target);
|
|
24
|
+
|
|
25
|
+
const unsubscribeRegistration = pi.events.on(CONTENT_CONVERTER_REGISTER_EVENT, (request) =>
|
|
26
|
+
{
|
|
27
|
+
if (!isContentConverterRegistrationRequest(request))
|
|
28
|
+
{
|
|
29
|
+
throw new Error("Invalid content converter registration request");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!targetsEqual(runner.target, request.registration.target))
|
|
33
|
+
{
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let registration: Promise<void>;
|
|
38
|
+
|
|
39
|
+
try
|
|
40
|
+
{
|
|
41
|
+
runner.register(request.registration);
|
|
42
|
+
registration = Promise.resolve();
|
|
43
|
+
}
|
|
44
|
+
catch (error)
|
|
45
|
+
{
|
|
46
|
+
registration = Promise.reject(
|
|
47
|
+
error instanceof Error
|
|
48
|
+
? error
|
|
49
|
+
: new Error("Content converter registration failed", { cause: error }),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
request.accept(registration);
|
|
54
|
+
});
|
|
55
|
+
pi.on("session_shutdown", unsubscribeRegistration);
|
|
56
|
+
pi.events.emit(CONTENT_HOST_READY_EVENT, {
|
|
57
|
+
protocol: CONTENT_PROTOCOL,
|
|
58
|
+
apiVersion: CONTENT_API_VERSION,
|
|
59
|
+
target: runner.target,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
target: runner.target,
|
|
64
|
+
listDescriptions(): readonly ContentDescription[]
|
|
65
|
+
{
|
|
66
|
+
return runner.listDescriptions();
|
|
67
|
+
},
|
|
68
|
+
convert(input, context): Promise<AgentContent>
|
|
69
|
+
{
|
|
70
|
+
return runner.convert(input, context);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isContentConversionAttempt,
|
|
3
|
+
isContentConversionContext,
|
|
4
|
+
isContentConverterRegistration,
|
|
5
|
+
isContentInput,
|
|
6
|
+
isContentTarget,
|
|
7
|
+
} from "./validation.js";
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
ContentConversionContext,
|
|
11
|
+
ContentConverter,
|
|
12
|
+
ContentConverterRegistration,
|
|
13
|
+
ContentDescription,
|
|
14
|
+
ContentInput,
|
|
15
|
+
ContentTarget,
|
|
16
|
+
} from "./content-converter.js";
|
|
17
|
+
import type { AgentContent } from "../content.js";
|
|
18
|
+
|
|
19
|
+
interface RegisteredConverter
|
|
20
|
+
{
|
|
21
|
+
readonly converter: ContentConverter;
|
|
22
|
+
readonly priority: number;
|
|
23
|
+
readonly order: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ContentRunner
|
|
27
|
+
{
|
|
28
|
+
readonly target: ContentTarget;
|
|
29
|
+
register(registration: ContentConverterRegistration): void;
|
|
30
|
+
listDescriptions(): readonly ContentDescription[];
|
|
31
|
+
convert(input: ContentInput, context: ContentConversionContext): Promise<AgentContent>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class UnsupportedContentError extends Error
|
|
35
|
+
{
|
|
36
|
+
readonly source: string;
|
|
37
|
+
readonly target: ContentTarget;
|
|
38
|
+
|
|
39
|
+
constructor(source: string, target: ContentTarget)
|
|
40
|
+
{
|
|
41
|
+
super(`No content converter for ${source} in ${target.provider}/${target.capability}`);
|
|
42
|
+
this.name = "UnsupportedContentError";
|
|
43
|
+
this.source = source;
|
|
44
|
+
this.target = target;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createContentRunner(target: ContentTarget): ContentRunner
|
|
49
|
+
{
|
|
50
|
+
if (!isContentTarget(target))
|
|
51
|
+
{
|
|
52
|
+
throw new TypeError("Invalid content target");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const stableTarget: ContentTarget = { ...target };
|
|
56
|
+
const converters: RegisteredConverter[] = [];
|
|
57
|
+
const snapshotConverters = (): RegisteredConverter[] =>
|
|
58
|
+
[...converters].sort((left, right) => left.priority - right.priority || left.order - right.order);
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
target: stableTarget,
|
|
62
|
+
register(registration): void
|
|
63
|
+
{
|
|
64
|
+
if (!isContentConverterRegistration(registration))
|
|
65
|
+
{
|
|
66
|
+
throw new TypeError("Invalid content converter registration");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!targetsEqual(stableTarget, registration.target))
|
|
70
|
+
{
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Content converter ${registration.converter.id} targets `
|
|
73
|
+
+ `${registration.target.provider}/${registration.target.capability}, not `
|
|
74
|
+
+ `${stableTarget.provider}/${stableTarget.capability}`,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (converters.some(({ converter }) => converter.id === registration.converter.id))
|
|
79
|
+
{
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Content converter ${registration.converter.id} is already registered for `
|
|
82
|
+
+ `${stableTarget.provider}/${stableTarget.capability}`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
converters.push({
|
|
87
|
+
converter: registration.converter,
|
|
88
|
+
priority: registration.priority ?? 0,
|
|
89
|
+
order: converters.length,
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
listDescriptions(): readonly ContentDescription[]
|
|
93
|
+
{
|
|
94
|
+
return snapshotConverters()
|
|
95
|
+
.map(({ converter }) => ({
|
|
96
|
+
id: converter.id,
|
|
97
|
+
description: converter.description,
|
|
98
|
+
}));
|
|
99
|
+
},
|
|
100
|
+
async convert(input, context): Promise<AgentContent>
|
|
101
|
+
{
|
|
102
|
+
if (!isContentInput(input))
|
|
103
|
+
{
|
|
104
|
+
throw new TypeError("Invalid content input");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!isContentConversionContext(context))
|
|
108
|
+
{
|
|
109
|
+
throw new TypeError("Invalid content conversion context");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
throwIfAborted(context.signal);
|
|
113
|
+
const snapshot = snapshotConverters();
|
|
114
|
+
|
|
115
|
+
for (const { converter } of snapshot)
|
|
116
|
+
{
|
|
117
|
+
throwIfAborted(context.signal);
|
|
118
|
+
const attempt: unknown = await converter.tryConvert(input, context);
|
|
119
|
+
throwIfAborted(context.signal);
|
|
120
|
+
|
|
121
|
+
if (!isContentConversionAttempt(attempt))
|
|
122
|
+
{
|
|
123
|
+
throw new TypeError(`Content converter ${converter.id} returned an invalid outcome`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (attempt.kind === "not-handled")
|
|
127
|
+
{
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (attempt.kind === "failed")
|
|
132
|
+
{
|
|
133
|
+
throw attempt.error;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return attempt.content;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
throw new UnsupportedContentError(input.source, stableTarget);
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function targetsEqual(left: ContentTarget, right: ContentTarget): boolean
|
|
145
|
+
{
|
|
146
|
+
return left.provider === right.provider && left.capability === right.capability;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function throwIfAborted(signal: AbortSignal | undefined): void
|
|
150
|
+
{
|
|
151
|
+
signal?.throwIfAborted();
|
|
152
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type TSchema, Type } from "typebox";
|
|
2
|
+
import { Value } from "typebox/value";
|
|
3
|
+
|
|
4
|
+
import { isContentConverterRegistration, isContentTarget } from "./validation.js";
|
|
5
|
+
|
|
6
|
+
import type { ContentConverterRegistration, ContentTarget } from "./content-converter.js";
|
|
7
|
+
|
|
8
|
+
export const CONTENT_PROTOCOL = "pi-agent-resource/content-conversion";
|
|
9
|
+
|
|
10
|
+
export const CONTENT_API_VERSION = 2;
|
|
11
|
+
|
|
12
|
+
export const CONTENT_HOST_READY_EVENT = `${CONTENT_PROTOCOL}/host/ready`;
|
|
13
|
+
|
|
14
|
+
export const CONTENT_CONVERTER_REGISTER_EVENT = `${CONTENT_PROTOCOL}/converter/register`;
|
|
15
|
+
|
|
16
|
+
export interface ContentHostReady
|
|
17
|
+
{
|
|
18
|
+
readonly protocol: typeof CONTENT_PROTOCOL;
|
|
19
|
+
readonly apiVersion: typeof CONTENT_API_VERSION;
|
|
20
|
+
readonly target: ContentTarget;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ContentConverterRegistrationRequest
|
|
24
|
+
{
|
|
25
|
+
readonly registration: ContentConverterRegistration;
|
|
26
|
+
accept(result: Promise<void>): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const objectOptions = { additionalProperties: true } as const;
|
|
30
|
+
const functionSchema = Type.Function([], Type.Unknown());
|
|
31
|
+
const readySchema = Type.Object({
|
|
32
|
+
protocol: Type.Literal(CONTENT_PROTOCOL),
|
|
33
|
+
apiVersion: Type.Literal(CONTENT_API_VERSION),
|
|
34
|
+
target: Type.Unknown(),
|
|
35
|
+
}, objectOptions);
|
|
36
|
+
const registrationRequestSchema = Type.Object({
|
|
37
|
+
registration: Type.Unknown(),
|
|
38
|
+
accept: functionSchema,
|
|
39
|
+
}, objectOptions);
|
|
40
|
+
|
|
41
|
+
export function isContentHostReady(value: unknown): value is ContentHostReady
|
|
42
|
+
{
|
|
43
|
+
return safeCheck(readySchema, value)
|
|
44
|
+
&& safeEvaluate(() => isContentTarget((value as ContentHostReady).target));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isContentConverterRegistrationRequest(
|
|
48
|
+
value: unknown,
|
|
49
|
+
): value is ContentConverterRegistrationRequest
|
|
50
|
+
{
|
|
51
|
+
return safeCheck(registrationRequestSchema, value)
|
|
52
|
+
&& safeEvaluate(() =>
|
|
53
|
+
isContentConverterRegistration(
|
|
54
|
+
(value as ContentConverterRegistrationRequest).registration,
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function safeCheck(schema: TSchema, value: unknown): boolean
|
|
60
|
+
{
|
|
61
|
+
return safeEvaluate(() => Value.Check(schema, value));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function safeEvaluate(check: () => boolean): boolean
|
|
65
|
+
{
|
|
66
|
+
try
|
|
67
|
+
{
|
|
68
|
+
return check();
|
|
69
|
+
}
|
|
70
|
+
catch
|
|
71
|
+
{
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type TSchema, Type } from "typebox";
|
|
2
|
+
import { Value } from "typebox/value";
|
|
3
|
+
|
|
4
|
+
import { isAgentContent } from "../validation.js";
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
ContentConversionAttempt,
|
|
8
|
+
ContentConversionContext,
|
|
9
|
+
ContentConverter,
|
|
10
|
+
ContentConverterRegistration,
|
|
11
|
+
ContentInput,
|
|
12
|
+
ContentTarget,
|
|
13
|
+
} from "./content-converter.js";
|
|
14
|
+
|
|
15
|
+
const objectOptions = { additionalProperties: true } as const;
|
|
16
|
+
const functionSchema = Type.Function([], Type.Unknown());
|
|
17
|
+
const nonEmptyStringSchema = Type.String({ minLength: 1 });
|
|
18
|
+
const targetSchema = Type.Object({
|
|
19
|
+
provider: nonEmptyStringSchema,
|
|
20
|
+
capability: Type.Union([Type.Literal("read"), Type.Literal("write")]),
|
|
21
|
+
}, objectOptions);
|
|
22
|
+
const inputSchema = Type.Object({
|
|
23
|
+
source: nonEmptyStringSchema,
|
|
24
|
+
bytes: Type.Unknown(),
|
|
25
|
+
mediaType: Type.Optional(Type.String()),
|
|
26
|
+
}, objectOptions);
|
|
27
|
+
const contextSchema = Type.Object({
|
|
28
|
+
signal: Type.Optional(Type.Unknown()),
|
|
29
|
+
}, objectOptions);
|
|
30
|
+
const converterSchema = Type.Object({
|
|
31
|
+
id: nonEmptyStringSchema,
|
|
32
|
+
description: nonEmptyStringSchema,
|
|
33
|
+
tryConvert: functionSchema,
|
|
34
|
+
}, objectOptions);
|
|
35
|
+
const attemptSchema = Type.Union([
|
|
36
|
+
Type.Object({ kind: Type.Literal("not-handled") }, objectOptions),
|
|
37
|
+
Type.Object({
|
|
38
|
+
kind: Type.Literal("converted"),
|
|
39
|
+
content: Type.Unknown(),
|
|
40
|
+
}, objectOptions),
|
|
41
|
+
Type.Object({
|
|
42
|
+
kind: Type.Literal("failed"),
|
|
43
|
+
error: Type.Unknown(),
|
|
44
|
+
}, objectOptions),
|
|
45
|
+
]);
|
|
46
|
+
const registrationSchema = Type.Object({
|
|
47
|
+
target: Type.Unknown(),
|
|
48
|
+
converter: Type.Unknown(),
|
|
49
|
+
priority: Type.Optional(Type.Number()),
|
|
50
|
+
}, objectOptions);
|
|
51
|
+
|
|
52
|
+
export function isContentTarget(value: unknown): value is ContentTarget
|
|
53
|
+
{
|
|
54
|
+
return safeCheck(targetSchema, value)
|
|
55
|
+
&& safeEvaluate(() => (value as ContentTarget).provider.trim().length > 0);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isContentInput(value: unknown): value is ContentInput
|
|
59
|
+
{
|
|
60
|
+
if (!safeCheck(inputSchema, value))
|
|
61
|
+
{
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return safeEvaluate(() =>
|
|
66
|
+
{
|
|
67
|
+
const input = value as Record<PropertyKey, unknown>;
|
|
68
|
+
return input.bytes instanceof Uint8Array
|
|
69
|
+
&& (!("mediaType" in input) || typeof input.mediaType === "string");
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function isContentConversionContext(value: unknown): value is ContentConversionContext
|
|
74
|
+
{
|
|
75
|
+
if (!safeCheck(contextSchema, value))
|
|
76
|
+
{
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return safeEvaluate(() =>
|
|
81
|
+
{
|
|
82
|
+
const context = value as Record<PropertyKey, unknown>;
|
|
83
|
+
return !("signal" in context) || context.signal instanceof AbortSignal;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function isContentConverter(value: unknown): value is ContentConverter
|
|
88
|
+
{
|
|
89
|
+
if (!safeCheck(converterSchema, value))
|
|
90
|
+
{
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return safeEvaluate(() =>
|
|
95
|
+
{
|
|
96
|
+
const converter = value as ContentConverter;
|
|
97
|
+
return converter.id.trim().length > 0
|
|
98
|
+
&& converter.description.trim().length > 0
|
|
99
|
+
&& !/[\r\n]/u.test(converter.description);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function isContentConversionAttempt(value: unknown): value is ContentConversionAttempt
|
|
104
|
+
{
|
|
105
|
+
if (!safeCheck(attemptSchema, value))
|
|
106
|
+
{
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return safeEvaluate(() =>
|
|
111
|
+
{
|
|
112
|
+
const attempt = value as Record<PropertyKey, unknown>;
|
|
113
|
+
return attempt.kind !== "converted" || isAgentContent(attempt.content);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function isContentConverterRegistration(value: unknown): value is ContentConverterRegistration
|
|
118
|
+
{
|
|
119
|
+
if (!safeCheck(registrationSchema, value))
|
|
120
|
+
{
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return safeEvaluate(() =>
|
|
125
|
+
{
|
|
126
|
+
const registration = value as Record<PropertyKey, unknown>;
|
|
127
|
+
return isContentTarget(registration.target)
|
|
128
|
+
&& isContentConverter(registration.converter)
|
|
129
|
+
&& (!("priority" in registration)
|
|
130
|
+
|| (typeof registration.priority === "number" && Number.isFinite(registration.priority)));
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function safeCheck(schema: TSchema, value: unknown): boolean
|
|
135
|
+
{
|
|
136
|
+
return safeEvaluate(() => Value.Check(schema, value));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function safeEvaluate(check: () => boolean): boolean
|
|
140
|
+
{
|
|
141
|
+
try
|
|
142
|
+
{
|
|
143
|
+
return check();
|
|
144
|
+
}
|
|
145
|
+
catch
|
|
146
|
+
{
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ImageContent, TextContent } from "@earendil-works/pi-ai";
|
|
2
|
+
|
|
3
|
+
export type { ImageContent, TextContent } from "@earendil-works/pi-ai";
|
|
4
|
+
|
|
5
|
+
export interface CustomContent
|
|
6
|
+
{
|
|
7
|
+
readonly type: "custom";
|
|
8
|
+
readonly kind: string;
|
|
9
|
+
readonly data: unknown;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type AgentContentBlock = TextContent | ImageContent | CustomContent;
|
|
13
|
+
|
|
14
|
+
export type AgentContent = readonly [
|
|
15
|
+
AgentContentBlock,
|
|
16
|
+
...AgentContentBlock[],
|
|
17
|
+
];
|