pi-agent-ide 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -9
- package/docs/architecture.md +18 -6
- package/docs/configuration.md +70 -40
- package/docs/development.md +14 -2
- package/docs/extensions.md +132 -150
- package/docs/generated/tool-catalog/c.md +9 -0
- package/docs/generated/tool-catalog/cmake.md +9 -0
- package/docs/generated/tool-catalog/cpp.md +9 -0
- package/docs/generated/tool-catalog/csharp.md +9 -0
- package/docs/generated/tool-catalog/css.md +10 -0
- package/docs/generated/tool-catalog/dockerfile.md +9 -0
- package/docs/generated/tool-catalog/go.md +10 -0
- package/docs/generated/tool-catalog/html.md +9 -0
- package/docs/generated/tool-catalog/index.md +30 -0
- package/docs/generated/tool-catalog/java.md +9 -0
- package/docs/generated/tool-catalog/javascript.md +10 -0
- package/docs/generated/tool-catalog/json.md +10 -0
- package/docs/generated/tool-catalog/kotlin.md +9 -0
- package/docs/generated/tool-catalog/lua.md +9 -0
- package/docs/generated/tool-catalog/markdown.md +9 -0
- package/docs/generated/tool-catalog/php.md +9 -0
- package/docs/generated/tool-catalog/python.md +10 -0
- package/docs/generated/tool-catalog/ruby.md +9 -0
- package/docs/generated/tool-catalog/rust.md +9 -0
- package/docs/generated/tool-catalog/shell.md +9 -0
- package/docs/generated/tool-catalog/sql.md +9 -0
- package/docs/generated/tool-catalog/swift.md +9 -0
- package/docs/generated/tool-catalog/terraform.md +9 -0
- package/docs/generated/tool-catalog/toml.md +9 -0
- package/docs/generated/tool-catalog/typescript.md +10 -0
- package/docs/generated/tool-catalog/xml.md +9 -0
- package/docs/generated/tool-catalog/yaml.md +9 -0
- package/node_modules/pi-agent-doctor/package.json +26 -0
- package/node_modules/pi-agent-doctor/src/catalog.ts +55 -0
- package/node_modules/pi-agent-doctor/src/connect-plugin.ts +53 -0
- package/node_modules/pi-agent-doctor/src/executable.ts +47 -0
- package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +121 -0
- package/node_modules/pi-agent-filesystem/index.ts +42 -44
- package/node_modules/pi-agent-filesystem/package.json +11 -11
- package/node_modules/pi-agent-filesystem/src/resolver.ts +112 -135
- package/node_modules/pi-agent-filesystem-image/index.ts +5 -6
- package/node_modules/pi-agent-filesystem-image/package.json +8 -8
- package/node_modules/pi-agent-filesystem-pdf/index.ts +5 -6
- package/node_modules/pi-agent-filesystem-pdf/package.json +5 -5
- package/node_modules/pi-agent-filesystem-text/index.ts +11 -12
- package/node_modules/pi-agent-filesystem-text/package.json +8 -8
- package/node_modules/pi-agent-ide-ast/index.ts +1 -1
- package/node_modules/pi-agent-ide-ast/package.json +13 -12
- package/node_modules/pi-agent-ide-ast/src/ast/collect-files.ts +11 -16
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +292 -322
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +591 -656
- package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +15 -19
- package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +105 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +67 -64
- package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +51 -54
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +168 -185
- package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +30 -36
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +118 -129
- package/node_modules/pi-agent-ide-changes/index.ts +53 -51
- package/node_modules/pi-agent-ide-changes/package.json +12 -11
- package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +68 -78
- package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +230 -245
- package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +189 -192
- package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +75 -79
- package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +258 -276
- package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +164 -190
- package/node_modules/pi-agent-ide-changes/src/doctor-plugin.ts +29 -0
- package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +10 -9
- package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +49 -62
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +93 -93
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +124 -126
- package/node_modules/pi-agent-ide-formatter/index.ts +22 -23
- package/node_modules/pi-agent-ide-formatter/package.json +5 -2
- package/node_modules/pi-agent-ide-formatter/src/catalog.ts +247 -0
- package/node_modules/pi-agent-ide-formatter/src/doctor-plugin.ts +104 -0
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +38 -40
- package/node_modules/pi-agent-ide-formatter/src/registry.ts +45 -21
- package/node_modules/pi-agent-ide-languages/index.ts +24 -0
- package/node_modules/pi-agent-ide-languages/package.json +16 -0
- package/node_modules/pi-agent-ide-languages/src/languages.ts +84 -0
- package/node_modules/pi-agent-ide-lint/index.ts +164 -198
- package/node_modules/pi-agent-ide-lint/package.json +8 -7
- package/node_modules/pi-agent-ide-lint/src/catalog.ts +283 -0
- package/node_modules/pi-agent-ide-lint/src/command-linter.ts +50 -152
- package/node_modules/pi-agent-ide-lint/src/diagnostics.ts +180 -0
- package/node_modules/pi-agent-ide-lint/src/doctor-plugin.ts +104 -0
- package/node_modules/pi-agent-ide-lint/src/registry.ts +43 -21
- package/node_modules/pi-agent-ide-lsp/index.ts +187 -208
- package/node_modules/pi-agent-ide-lsp/package.json +12 -11
- package/node_modules/pi-agent-ide-lsp/src/catalog.ts +248 -0
- package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +109 -116
- package/node_modules/pi-agent-ide-lsp/src/doctor-plugin.ts +108 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +361 -385
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +420 -458
- package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +128 -137
- package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +25 -20
- package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +31 -33
- package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +48 -56
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +369 -411
- package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +58 -63
- package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +153 -70
- package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +36 -36
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +117 -127
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +108 -107
- package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +74 -57
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +36 -32
- package/node_modules/pi-agent-image/package.json +2 -2
- package/node_modules/pi-agent-image/src/image-converter.ts +210 -249
- package/node_modules/pi-agent-image/src/index.ts +4 -4
- package/node_modules/pi-agent-pdf/package.json +2 -2
- package/node_modules/pi-agent-pdf/src/index.ts +1 -5
- package/node_modules/pi-agent-pdf/src/pdf-converter.ts +130 -153
- package/node_modules/pi-agent-read/index.ts +1 -1
- package/node_modules/pi-agent-read/package.json +9 -9
- package/node_modules/pi-agent-read/src/api/connect-plugin.ts +38 -51
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +26 -32
- package/node_modules/pi-agent-read/src/api/rendering.ts +3 -4
- package/node_modules/pi-agent-read/src/api/tools/read.ts +124 -132
- package/node_modules/pi-agent-read/src/core/extension.ts +28 -29
- package/node_modules/pi-agent-read/src/core/read-core.ts +281 -330
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +153 -156
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +294 -316
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +146 -155
- package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +165 -187
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +644 -693
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +50 -62
- package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +27 -33
- package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +16 -20
- package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +52 -57
- package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +115 -134
- package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +38 -39
- package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +117 -107
- package/node_modules/pi-agent-resource/src/content.ts +5 -9
- package/node_modules/pi-agent-resource/src/index.ts +51 -40
- package/node_modules/pi-agent-resource/src/resolver.ts +11 -13
- package/node_modules/pi-agent-resource/src/resource.ts +17 -24
- package/node_modules/pi-agent-resource/src/validation.ts +106 -92
- package/node_modules/pi-agent-search/package.json +7 -7
- package/node_modules/pi-agent-search/src/api/connect-plugin.ts +37 -47
- package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +26 -30
- package/node_modules/pi-agent-search/src/api/search.ts +61 -67
- package/node_modules/pi-agent-search/src/core/extension.ts +112 -92
- package/node_modules/pi-agent-search/src/core/search-core.ts +330 -359
- package/node_modules/pi-agent-search-semantic/index.ts +75 -83
- package/node_modules/pi-agent-search-semantic/package.json +5 -5
- package/node_modules/pi-agent-search-text/index.ts +40 -38
- package/node_modules/pi-agent-search-text/package.json +10 -9
- package/node_modules/pi-agent-search-text/src/doctor-plugin.ts +29 -0
- package/node_modules/pi-agent-search-text/src/file-search.ts +90 -86
- package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +17 -19
- package/node_modules/pi-agent-search-text/src/resolvers.ts +152 -157
- package/node_modules/pi-agent-search-text/src/ripgrep.ts +16 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +215 -249
- package/node_modules/pi-agent-search-text/src/search-query.ts +85 -108
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +310 -334
- package/node_modules/pi-agent-search-text/src/search-result.ts +151 -157
- package/node_modules/pi-agent-search-text/src/search-session.ts +255 -261
- package/node_modules/pi-agent-search-web/index.ts +65 -57
- package/node_modules/pi-agent-search-web/package.json +8 -7
- package/node_modules/pi-agent-search-web/src/config.ts +470 -409
- package/node_modules/pi-agent-search-web/src/doctor-plugin.ts +40 -0
- package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +56 -60
- package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +60 -68
- package/node_modules/pi-agent-search-web/src/providers/request.ts +359 -362
- package/node_modules/pi-agent-search-web/src/providers/response.ts +296 -345
- package/node_modules/pi-agent-search-web/src/search-format.ts +15 -20
- package/node_modules/pi-agent-search-web/src/search.ts +289 -347
- package/node_modules/pi-agent-search-web/src/types.ts +99 -111
- package/node_modules/pi-agent-text/package.json +2 -2
- package/node_modules/pi-agent-text/src/index.ts +30 -22
- package/node_modules/pi-agent-text/src/presented-text.ts +15 -17
- package/node_modules/pi-agent-text/src/source-line.ts +33 -36
- package/node_modules/pi-agent-text/src/text-anchor.ts +120 -117
- package/node_modules/pi-agent-text/src/text-converter.ts +71 -84
- package/node_modules/pi-agent-text/src/text-document.ts +99 -110
- package/node_modules/pi-agent-text-anchor-constant/index.ts +18 -20
- package/node_modules/pi-agent-text-anchor-constant/package.json +5 -5
- package/node_modules/pi-agent-text-anchor-constant/src/resolver.ts +29 -36
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +34 -36
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +11 -11
- package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +75 -85
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +35 -42
- package/node_modules/pi-agent-text-editor/index.ts +7 -9
- package/node_modules/pi-agent-text-editor/package.json +10 -10
- package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +16 -18
- package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +40 -50
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +10 -13
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +31 -36
- package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +25 -27
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +26 -31
- package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +18 -21
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +19 -19
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +117 -132
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +155 -141
- package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +93 -103
- package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -14
- package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +84 -95
- package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +9 -9
- package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +18 -22
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +41 -47
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +115 -120
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +273 -311
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +85 -95
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +232 -289
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +534 -580
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +86 -98
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +12 -11
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +282 -336
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +181 -214
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +476 -511
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +93 -105
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +31 -33
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +367 -372
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +82 -88
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +1837 -2035
- package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +19 -22
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +629 -631
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +982 -1031
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +19 -23
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +270 -273
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +353 -403
- package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +9 -11
- package/node_modules/pi-agent-text-editor/src/tools/extension.ts +7 -8
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +69 -77
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +109 -95
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +69 -61
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +52 -39
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +121 -115
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +71 -54
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +24 -17
- package/node_modules/pi-agent-text-editor-argument-order/index.ts +16 -19
- package/node_modules/pi-agent-text-editor-argument-order/package.json +4 -4
- package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +79 -91
- package/node_modules/pi-agent-text-editor-overwrite/index.ts +297 -323
- package/node_modules/pi-agent-text-editor-overwrite/package.json +4 -4
- package/node_modules/pi-agent-text-editor-renderer/index.ts +11 -12
- package/node_modules/pi-agent-text-editor-renderer/package.json +7 -7
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +347 -359
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +203 -219
- package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +297 -329
- package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +19 -25
- package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +160 -168
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +170 -182
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +330 -340
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +115 -118
- package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +3 -4
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +582 -629
- package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +144 -167
- package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +317 -333
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-tool-call-interception/package.json +1 -1
- package/node_modules/pi-agent-tool-call-interception/src/index.ts +334 -354
- package/node_modules/pi-agent-web/index.ts +24 -25
- package/node_modules/pi-agent-web/package.json +10 -10
- package/node_modules/pi-agent-web/src/resolver.ts +133 -155
- package/node_modules/pi-agent-web-html/index.ts +5 -6
- package/node_modules/pi-agent-web-html/package.json +6 -6
- package/node_modules/pi-agent-web-html/src/extract-readable-html.ts +58 -76
- package/node_modules/pi-agent-web-html/src/html-converter.ts +62 -75
- package/node_modules/pi-agent-web-image/index.ts +5 -6
- package/node_modules/pi-agent-web-image/package.json +5 -5
- package/node_modules/pi-agent-web-pdf/index.ts +5 -6
- package/node_modules/pi-agent-web-pdf/package.json +5 -5
- package/node_modules/pi-agent-web-text/index.ts +5 -6
- package/node_modules/pi-agent-web-text/package.json +5 -5
- package/package.json +72 -52
- package/src/api/code-view.ts +17 -17
- package/src/api/connect-doctor-plugin.ts +1 -0
- package/src/api/connect-plugin.ts +38 -48
- package/src/api/doctor.ts +1 -0
- package/src/api/plugin-protocol.ts +30 -38
- package/src/api/read.ts +6 -1
- package/src/api/resource.ts +3 -1
- package/src/api/search.ts +5 -1
- package/src/api/text-editor.ts +4 -1
- package/src/api/text.ts +3 -1
- package/src/api/tool-catalog.ts +1 -0
- package/src/api/tool-config.ts +365 -0
- package/src/api/toolchain.ts +18 -18
- package/src/code-view/diagnostic-view.ts +59 -58
- package/src/code-view/reference.ts +64 -82
- package/src/code-view/source-view.ts +159 -180
- package/src/composite/builtin-extensions.ts +39 -35
- package/src/composite/config.ts +75 -69
- package/src/composite/selection.ts +54 -52
- package/src/core/extension.ts +32 -36
- package/src/core/ide-core.ts +76 -93
- package/src/doctor/config-writer.ts +115 -0
- package/src/doctor/core.ts +174 -0
- package/src/doctor/discovery.ts +215 -0
- package/src/doctor/extension.ts +108 -0
- package/src/doctor/index.ts +1 -0
- package/src/doctor/inventory.ts +91 -0
- package/src/doctor/run.ts +196 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +42 -44
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +11 -11
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +8 -8
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/index.ts +11 -12
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +8 -8
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +112 -135
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +24 -25
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +10 -10
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +6 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/extract-readable-html.ts +58 -76
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +62 -75
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +133 -155
- package/src/extensions/pi-agent-read/index.ts +1 -1
- package/src/extensions/pi-agent-read/package.json +9 -9
- package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +38 -51
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +26 -32
- package/src/extensions/pi-agent-read/src/api/rendering.ts +3 -4
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +124 -132
- package/src/extensions/pi-agent-read/src/core/extension.ts +28 -29
- package/src/extensions/pi-agent-read/src/core/read-core.ts +281 -330
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +153 -156
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +294 -316
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +146 -155
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +165 -187
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +644 -693
- package/src/extensions/pi-agent-search/package.json +7 -7
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +75 -83
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/package.json +5 -5
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +40 -38
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +10 -9
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/doctor-plugin.ts +29 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +90 -86
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +17 -19
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +152 -157
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/ripgrep.ts +16 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +215 -249
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +85 -108
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +310 -334
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +151 -157
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +255 -261
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +65 -57
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +8 -7
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +470 -409
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/doctor-plugin.ts +40 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +56 -60
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +60 -68
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +359 -362
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +296 -345
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +15 -20
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +289 -347
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +99 -111
- package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +37 -47
- package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +26 -30
- package/src/extensions/pi-agent-search/src/api/search.ts +61 -67
- package/src/extensions/pi-agent-search/src/core/extension.ts +112 -92
- package/src/extensions/pi-agent-search/src/core/search-core.ts +330 -359
- package/src/extensions/pi-agent-text-editor/index.ts +7 -9
- package/src/extensions/pi-agent-text-editor/package.json +10 -10
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +18 -20
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/src/resolver.ts +29 -36
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +34 -36
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +11 -11
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +75 -85
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +35 -42
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +16 -19
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +4 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +79 -91
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +297 -323
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +4 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +11 -12
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +7 -7
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +347 -359
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +203 -219
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +297 -329
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +19 -25
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +160 -168
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +170 -182
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +330 -340
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +115 -118
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +3 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +582 -629
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +144 -167
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +317 -333
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +16 -18
- package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +40 -50
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +10 -13
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +31 -36
- package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +25 -27
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +26 -31
- package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +18 -21
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +19 -19
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +117 -132
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +155 -141
- package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +93 -103
- package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -14
- package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +84 -95
- package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +9 -9
- package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +18 -22
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +41 -47
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +115 -120
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +273 -311
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +85 -95
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +232 -289
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +534 -580
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +86 -98
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +12 -11
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +282 -336
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +181 -214
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +476 -511
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +93 -105
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +31 -33
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +367 -372
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +82 -88
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +1837 -2035
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +19 -22
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +629 -631
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +982 -1031
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +19 -23
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +270 -273
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +353 -403
- package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +9 -11
- package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +7 -8
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +69 -77
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +109 -95
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +69 -61
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +52 -39
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +121 -115
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +71 -54
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +24 -17
- package/src/pi-agent-ide.ts +10 -10
- package/src/plugins/pi-agent-ide-ast/index.ts +1 -1
- package/src/plugins/pi-agent-ide-ast/package.json +13 -12
- package/src/plugins/pi-agent-ide-ast/src/ast/collect-files.ts +11 -16
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +292 -322
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +591 -656
- package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +15 -19
- package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +105 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +67 -64
- package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +51 -54
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +168 -185
- package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +30 -36
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +118 -129
- package/src/plugins/pi-agent-ide-changes/index.ts +53 -51
- package/src/plugins/pi-agent-ide-changes/package.json +12 -11
- package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +68 -78
- package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +230 -245
- package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +189 -192
- package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +75 -79
- package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +258 -276
- package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +164 -190
- package/src/plugins/pi-agent-ide-changes/src/doctor-plugin.ts +29 -0
- package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +10 -9
- package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +49 -62
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +93 -93
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +124 -126
- package/src/plugins/pi-agent-ide-formatter/index.ts +22 -23
- package/src/plugins/pi-agent-ide-formatter/package.json +5 -2
- package/src/plugins/pi-agent-ide-formatter/src/catalog.ts +247 -0
- package/src/plugins/pi-agent-ide-formatter/src/doctor-plugin.ts +104 -0
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +38 -40
- package/src/plugins/pi-agent-ide-formatter/src/registry.ts +45 -21
- package/src/plugins/pi-agent-ide-languages/index.ts +24 -0
- package/src/plugins/pi-agent-ide-languages/package.json +16 -0
- package/src/plugins/pi-agent-ide-languages/src/languages.ts +84 -0
- package/src/plugins/pi-agent-ide-lint/index.ts +164 -198
- package/src/plugins/pi-agent-ide-lint/package.json +8 -7
- package/src/plugins/pi-agent-ide-lint/src/catalog.ts +283 -0
- package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +50 -152
- package/src/plugins/pi-agent-ide-lint/src/diagnostics.ts +180 -0
- package/src/plugins/pi-agent-ide-lint/src/doctor-plugin.ts +104 -0
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +43 -21
- package/src/plugins/pi-agent-ide-lsp/index.ts +187 -208
- package/src/plugins/pi-agent-ide-lsp/package.json +12 -11
- package/src/plugins/pi-agent-ide-lsp/src/catalog.ts +248 -0
- package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +109 -116
- package/src/plugins/pi-agent-ide-lsp/src/doctor-plugin.ts +108 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +361 -385
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +420 -458
- package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +128 -137
- package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +25 -20
- package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +31 -33
- package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +48 -56
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +369 -411
- package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +58 -63
- package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +153 -70
- package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +36 -36
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +117 -127
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +108 -107
- package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +74 -57
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +36 -32
- package/src/post-edit/gate.ts +114 -122
- package/src/toolchain/diagnostic.ts +3 -4
- package/src/toolchain/gate.ts +278 -295
- package/src/toolchain/registry.ts +143 -165
- package/src/toolchain/types.ts +126 -103
- package/src/utils/required-value.ts +8 -0
- package/node_modules/pi-agent-ide-formatter/src/types.ts +0 -10
- package/node_modules/pi-agent-ide-lint/src/command-runner.ts +0 -51
- package/node_modules/pi-agent-ide-lint/src/types.ts +0 -10
- package/src/plugins/pi-agent-ide-formatter/src/types.ts +0 -10
- package/src/plugins/pi-agent-ide-lint/src/command-runner.ts +0 -51
- package/src/plugins/pi-agent-ide-lint/src/types.ts +0 -10
|
@@ -6,494 +6,555 @@ import { CONFIG_DIR_NAME, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
|
6
6
|
import { isAllowedProviderBaseUrl } from "./providers/endpoints.ts";
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
CodexSearchMode,
|
|
10
|
+
ConfigLoadResult,
|
|
11
|
+
JsonObject,
|
|
12
|
+
JsonValue,
|
|
13
|
+
ProviderValidationResult,
|
|
14
|
+
RoutingStrategy,
|
|
15
|
+
SearchContextSize,
|
|
16
|
+
SearchProvider,
|
|
17
|
+
SearchProviderConfig,
|
|
18
|
+
SearchProviderEntry,
|
|
19
|
+
SearchUserLocation,
|
|
20
|
+
WebsearchConfig,
|
|
21
21
|
} from "./types.ts";
|
|
22
22
|
|
|
23
23
|
export const SEARCH_PROVIDERS: readonly SearchProvider[] = [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
"exa",
|
|
25
|
+
"tavily",
|
|
26
|
+
"brave",
|
|
27
|
+
"duckduckgo-html",
|
|
28
|
+
"serper",
|
|
29
|
+
"parallel",
|
|
30
|
+
"google-cse",
|
|
31
|
+
"z-ai",
|
|
32
|
+
"openai",
|
|
33
|
+
"codex",
|
|
34
|
+
"anthropic",
|
|
35
|
+
"perplexity",
|
|
36
|
+
"xai",
|
|
37
|
+
"kimi",
|
|
38
38
|
];
|
|
39
39
|
const CONTEXT_SIZES: readonly SearchContextSize[] = ["low", "medium", "high"];
|
|
40
40
|
const CODEX_MODES: readonly CodexSearchMode[] = ["cached", "live"];
|
|
41
41
|
const STRATEGIES: readonly RoutingStrategy[] = ["priority", "round-robin", "fill-first"];
|
|
42
42
|
const DEFAULT_MAX_RESULTS = 10;
|
|
43
43
|
const DEFAULT_FREE_CONFIG: WebsearchConfig = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
strategy: "priority",
|
|
45
|
+
fallback: true,
|
|
46
|
+
providers: [{ id: "default", provider: "duckduckgo-html", maxResults: DEFAULT_MAX_RESULTS }],
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
export interface ConfigLoadOptions
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
export interface ConfigLoadOptions {
|
|
50
|
+
cwd: string;
|
|
51
|
+
/**
|
|
52
|
+
Global Pi agent directory. Defaults to `~/.pi/agent`.
|
|
53
|
+
*/
|
|
54
|
+
agentDirectory?: string;
|
|
55
|
+
env?: NodeJS.ProcessEnv;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
function isJsonObject(value: unknown): value is JsonObject
|
|
56
|
-
|
|
57
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
58
|
+
function isJsonObject(value: unknown): value is JsonObject {
|
|
59
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
function oneOf<TValue extends string>(values: readonly TValue[], value: unknown): value is TValue
|
|
61
|
-
|
|
62
|
-
return typeof value === "string" && (values as readonly string[]).includes(value);
|
|
62
|
+
function oneOf<TValue extends string>(values: readonly TValue[], value: unknown): value is TValue {
|
|
63
|
+
return typeof value === "string" && (values as readonly string[]).includes(value);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
function isStringArray(value: JsonValue | undefined): value is string[]
|
|
66
|
-
|
|
67
|
-
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
66
|
+
function isStringArray(value: JsonValue | undefined): value is string[] {
|
|
67
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
function optionalString(value: JsonValue | undefined): string | undefined
|
|
71
|
-
|
|
72
|
-
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
70
|
+
function optionalString(value: JsonValue | undefined): string | undefined {
|
|
71
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
function optionalNumber(value: JsonValue | undefined): number | undefined
|
|
76
|
-
|
|
77
|
-
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
74
|
+
function optionalNumber(value: JsonValue | undefined): number | undefined {
|
|
75
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
78
76
|
}
|
|
79
77
|
|
|
80
|
-
function optionalBoolean(value: JsonValue | undefined): boolean | undefined
|
|
81
|
-
|
|
82
|
-
return typeof value === "boolean" ? value : undefined;
|
|
78
|
+
function optionalBoolean(value: JsonValue | undefined): boolean | undefined {
|
|
79
|
+
return typeof value === "boolean" ? value : undefined;
|
|
83
80
|
}
|
|
84
81
|
|
|
85
|
-
function optionalProvider(value: JsonValue | undefined): SearchProvider | undefined
|
|
86
|
-
|
|
87
|
-
return oneOf(SEARCH_PROVIDERS, value) ? value : undefined;
|
|
82
|
+
function optionalProvider(value: JsonValue | undefined): SearchProvider | undefined {
|
|
83
|
+
return oneOf(SEARCH_PROVIDERS, value) ? value : undefined;
|
|
88
84
|
}
|
|
89
85
|
|
|
90
|
-
function optionalContextSize(value: JsonValue | undefined): SearchContextSize | undefined
|
|
91
|
-
|
|
92
|
-
return oneOf(CONTEXT_SIZES, value) ? value : undefined;
|
|
86
|
+
function optionalContextSize(value: JsonValue | undefined): SearchContextSize | undefined {
|
|
87
|
+
return oneOf(CONTEXT_SIZES, value) ? value : undefined;
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
function optionalCodexMode(value: JsonValue | undefined): CodexSearchMode | undefined
|
|
96
|
-
|
|
97
|
-
return oneOf(CODEX_MODES, value) ? value : undefined;
|
|
90
|
+
function optionalCodexMode(value: JsonValue | undefined): CodexSearchMode | undefined {
|
|
91
|
+
return oneOf(CODEX_MODES, value) ? value : undefined;
|
|
98
92
|
}
|
|
99
93
|
|
|
100
|
-
function optionalStrategy(value: JsonValue | undefined): RoutingStrategy | undefined
|
|
101
|
-
|
|
102
|
-
return oneOf(STRATEGIES, value) ? value : undefined;
|
|
94
|
+
function optionalStrategy(value: JsonValue | undefined): RoutingStrategy | undefined {
|
|
95
|
+
return oneOf(STRATEGIES, value) ? value : undefined;
|
|
103
96
|
}
|
|
104
97
|
|
|
105
|
-
function optionalLocation(value: JsonValue | undefined): SearchUserLocation | undefined
|
|
106
|
-
{
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
98
|
+
function optionalLocation(value: JsonValue | undefined): SearchUserLocation | undefined {
|
|
99
|
+
if (!isJsonObject(value)) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
111
102
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
103
|
+
const location: SearchUserLocation = {};
|
|
104
|
+
const country = optionalString(value.country);
|
|
105
|
+
const region = optionalString(value.region);
|
|
106
|
+
const city = optionalString(value.city);
|
|
107
|
+
const timezone = optionalString(value.timezone);
|
|
117
108
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
109
|
+
if (country) {
|
|
110
|
+
location.country = country;
|
|
111
|
+
}
|
|
122
112
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
113
|
+
if (region) {
|
|
114
|
+
location.region = region;
|
|
115
|
+
}
|
|
127
116
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
117
|
+
if (city) {
|
|
118
|
+
location.city = city;
|
|
119
|
+
}
|
|
132
120
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
121
|
+
if (timezone) {
|
|
122
|
+
location.timezone = timezone;
|
|
123
|
+
}
|
|
137
124
|
|
|
138
|
-
|
|
125
|
+
return Object.keys(location).length > 0 ? location : undefined;
|
|
139
126
|
}
|
|
140
127
|
|
|
141
|
-
function normalizedProviderOrder(values: readonly string[]): string[] | undefined
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const seen = new Set<string>();
|
|
128
|
+
function normalizedProviderOrder(values: readonly string[]): string[] | undefined {
|
|
129
|
+
const order: string[] = [];
|
|
130
|
+
const seen = new Set<string>();
|
|
145
131
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const normalized = trimmed.toLowerCase();
|
|
132
|
+
for (const value of values) {
|
|
133
|
+
const trimmed = value.trim();
|
|
134
|
+
const normalized = trimmed.toLowerCase();
|
|
150
135
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
seen.add(normalized);
|
|
157
|
-
order.push(trimmed);
|
|
136
|
+
if (!trimmed || seen.has(normalized)) {
|
|
137
|
+
continue;
|
|
158
138
|
}
|
|
159
139
|
|
|
160
|
-
|
|
140
|
+
seen.add(normalized);
|
|
141
|
+
order.push(trimmed);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return order.length > 0 ? order : undefined;
|
|
161
145
|
}
|
|
162
146
|
|
|
163
|
-
function optionalProviderOrder(value: JsonValue | undefined): string[] | undefined
|
|
164
|
-
|
|
165
|
-
return isStringArray(value) ? normalizedProviderOrder(value) : undefined;
|
|
147
|
+
function optionalProviderOrder(value: JsonValue | undefined): string[] | undefined {
|
|
148
|
+
return isStringArray(value) ? normalizedProviderOrder(value) : undefined;
|
|
166
149
|
}
|
|
167
150
|
|
|
168
|
-
function matchesProviderOrder(provider: SearchProviderEntry, selector: string): boolean
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
151
|
+
function matchesProviderOrder(provider: SearchProviderEntry, selector: string): boolean {
|
|
152
|
+
const normalized = selector.trim().toLowerCase();
|
|
153
|
+
return (
|
|
154
|
+
provider.provider.toLowerCase() === normalized || provider.id?.toLowerCase() === normalized
|
|
155
|
+
);
|
|
172
156
|
}
|
|
173
157
|
|
|
174
158
|
function applyProviderOrder(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
): SearchProviderEntry[]
|
|
178
|
-
{
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return providers;
|
|
182
|
-
}
|
|
159
|
+
providers: SearchProviderEntry[],
|
|
160
|
+
providerOrder?: readonly string[],
|
|
161
|
+
): SearchProviderEntry[] {
|
|
162
|
+
if (!providerOrder?.length) {
|
|
163
|
+
return providers;
|
|
164
|
+
}
|
|
183
165
|
|
|
184
|
-
|
|
185
|
-
|
|
166
|
+
const remaining = [...providers];
|
|
167
|
+
const ordered: SearchProviderEntry[] = [];
|
|
186
168
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const index = remaining.findIndex((provider) => matchesProviderOrder(provider, selector));
|
|
169
|
+
for (const selector of providerOrder) {
|
|
170
|
+
const index = remaining.findIndex((provider) => matchesProviderOrder(provider, selector));
|
|
190
171
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
ordered.push(...remaining.splice(index, 1));
|
|
194
|
-
}
|
|
172
|
+
if (index !== -1) {
|
|
173
|
+
ordered.push(...remaining.splice(index, 1));
|
|
195
174
|
}
|
|
175
|
+
}
|
|
196
176
|
|
|
197
|
-
|
|
177
|
+
return [...ordered, ...remaining];
|
|
198
178
|
}
|
|
199
179
|
|
|
200
|
-
function parseJsonObject(content: string): JsonObject | null
|
|
201
|
-
|
|
202
|
-
let parsed: unknown;
|
|
180
|
+
function parseJsonObject(content: string): JsonObject | null {
|
|
181
|
+
let parsed: unknown;
|
|
203
182
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
{
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return isJsonObject(parsed) ? parsed : null;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function providerEntryFromObject(raw: JsonObject): SearchProviderEntry | null
|
|
217
|
-
{
|
|
218
|
-
const provider = optionalProvider(raw.provider);
|
|
219
|
-
|
|
220
|
-
if (!provider)
|
|
221
|
-
{
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const config: SearchProviderEntry = { provider };
|
|
226
|
-
const id = optionalString(raw.id);
|
|
227
|
-
const apiKey = optionalString(raw.apiKey);
|
|
228
|
-
const baseUrl = optionalString(raw.baseUrl);
|
|
229
|
-
const searchEngineId = optionalString(raw.searchEngineId);
|
|
230
|
-
const maxResults = optionalNumber(raw.maxResults);
|
|
231
|
-
const model = optionalString(raw.model);
|
|
232
|
-
const codexMode = optionalCodexMode(raw.codexMode);
|
|
233
|
-
const searchContextSize = optionalContextSize(raw.searchContextSize);
|
|
234
|
-
const rawAllowedDomains = raw.allowedDomains;
|
|
235
|
-
const rawBlockedDomains = raw.blockedDomains;
|
|
236
|
-
const allowedDomains = isStringArray(rawAllowedDomains) ? rawAllowedDomains : undefined;
|
|
237
|
-
const blockedDomains = isStringArray(rawBlockedDomains) ? rawBlockedDomains : undefined;
|
|
238
|
-
const userLocation = optionalLocation(raw.userLocation);
|
|
239
|
-
const priority = optionalNumber(raw.priority);
|
|
240
|
-
const weight = optionalNumber(raw.weight);
|
|
241
|
-
|
|
242
|
-
if (id)
|
|
243
|
-
{
|
|
244
|
-
config.id = id;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (apiKey)
|
|
248
|
-
{
|
|
249
|
-
config.apiKey = apiKey;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (baseUrl)
|
|
253
|
-
{
|
|
254
|
-
config.baseUrl = baseUrl;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (searchEngineId)
|
|
258
|
-
{
|
|
259
|
-
config.searchEngineId = searchEngineId;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (maxResults)
|
|
263
|
-
{
|
|
264
|
-
config.maxResults = maxResults;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (model)
|
|
268
|
-
{
|
|
269
|
-
config.model = model;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (codexMode)
|
|
273
|
-
{
|
|
274
|
-
config.codexMode = codexMode;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (searchContextSize)
|
|
278
|
-
{
|
|
279
|
-
config.searchContextSize = searchContextSize;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (allowedDomains)
|
|
283
|
-
{
|
|
284
|
-
config.allowedDomains = allowedDomains;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (blockedDomains)
|
|
288
|
-
{
|
|
289
|
-
config.blockedDomains = blockedDomains;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if (userLocation)
|
|
293
|
-
{
|
|
294
|
-
config.userLocation = userLocation;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (priority !== undefined)
|
|
298
|
-
{
|
|
299
|
-
config.priority = priority;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (weight !== undefined)
|
|
303
|
-
{
|
|
304
|
-
config.weight = weight;
|
|
305
|
-
}
|
|
183
|
+
try {
|
|
184
|
+
parsed = JSON.parse(content);
|
|
185
|
+
} catch {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
306
188
|
|
|
307
|
-
|
|
189
|
+
return isJsonObject(parsed) ? parsed : null;
|
|
308
190
|
}
|
|
309
191
|
|
|
310
|
-
function
|
|
311
|
-
|
|
312
|
-
const strategy = optionalStrategy(raw.strategy) ?? "priority";
|
|
313
|
-
const fallback = optionalBoolean(raw.fallback) ?? true;
|
|
314
|
-
const providerOrder = optionalProviderOrder(raw.providerOrder);
|
|
315
|
-
const providersValue = raw.providers;
|
|
316
|
-
const rawProviders = Array.isArray(providersValue) ? providersValue : undefined;
|
|
317
|
-
|
|
318
|
-
if (rawProviders)
|
|
319
|
-
{
|
|
320
|
-
if (optionalProvider(raw.provider))
|
|
321
|
-
{
|
|
322
|
-
return null;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
const providers = rawProviders
|
|
326
|
-
.map((value) => (isJsonObject(value) ? providerEntryFromObject(value) : null))
|
|
327
|
-
.filter((entry): entry is SearchProviderEntry => entry !== null);
|
|
328
|
-
const orderedProviders = applyProviderOrder(providers, providerOrder);
|
|
329
|
-
return { strategy, fallback, providers: orderedProviders, ...(providerOrder ? { providerOrder } : {}) };
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
const provider = providerEntryFromObject(raw);
|
|
333
|
-
|
|
334
|
-
if (provider)
|
|
335
|
-
{
|
|
336
|
-
return { strategy, fallback, providers: [provider], ...(providerOrder ? { providerOrder } : {}) };
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (providerOrder || raw.strategy !== undefined || raw.fallback !== undefined)
|
|
340
|
-
{
|
|
341
|
-
return { strategy, fallback, providers: [], ...(providerOrder ? { providerOrder } : {}) };
|
|
342
|
-
}
|
|
192
|
+
function providerEntryFromObject(raw: JsonObject): SearchProviderEntry | null {
|
|
193
|
+
const provider = optionalProvider(raw.provider);
|
|
343
194
|
|
|
195
|
+
if (!provider) {
|
|
344
196
|
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const config: SearchProviderEntry = { provider };
|
|
200
|
+
const id = optionalString(raw.id);
|
|
201
|
+
const apiKey = optionalString(raw.apiKey);
|
|
202
|
+
const baseUrl = optionalString(raw.baseUrl);
|
|
203
|
+
const searchEngineId = optionalString(raw.searchEngineId);
|
|
204
|
+
const maxResults = optionalNumber(raw.maxResults);
|
|
205
|
+
const model = optionalString(raw.model);
|
|
206
|
+
const codexMode = optionalCodexMode(raw.codexMode);
|
|
207
|
+
const searchContextSize = optionalContextSize(raw.searchContextSize);
|
|
208
|
+
const rawAllowedDomains = raw.allowedDomains;
|
|
209
|
+
const rawBlockedDomains = raw.blockedDomains;
|
|
210
|
+
const allowedDomains = isStringArray(rawAllowedDomains) ? rawAllowedDomains : undefined;
|
|
211
|
+
const blockedDomains = isStringArray(rawBlockedDomains) ? rawBlockedDomains : undefined;
|
|
212
|
+
const userLocation = optionalLocation(raw.userLocation);
|
|
213
|
+
const priority = optionalNumber(raw.priority);
|
|
214
|
+
const weight = optionalNumber(raw.weight);
|
|
215
|
+
|
|
216
|
+
if (id) {
|
|
217
|
+
config.id = id;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (apiKey) {
|
|
221
|
+
config.apiKey = apiKey;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (baseUrl) {
|
|
225
|
+
config.baseUrl = baseUrl;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (searchEngineId) {
|
|
229
|
+
config.searchEngineId = searchEngineId;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (maxResults) {
|
|
233
|
+
config.maxResults = maxResults;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (model) {
|
|
237
|
+
config.model = model;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (codexMode) {
|
|
241
|
+
config.codexMode = codexMode;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (searchContextSize) {
|
|
245
|
+
config.searchContextSize = searchContextSize;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (allowedDomains) {
|
|
249
|
+
config.allowedDomains = allowedDomains;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (blockedDomains) {
|
|
253
|
+
config.blockedDomains = blockedDomains;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (userLocation) {
|
|
257
|
+
config.userLocation = userLocation;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (priority !== undefined) {
|
|
261
|
+
config.priority = priority;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (weight !== undefined) {
|
|
265
|
+
config.weight = weight;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return config;
|
|
345
269
|
}
|
|
346
270
|
|
|
347
|
-
function
|
|
348
|
-
|
|
349
|
-
|
|
271
|
+
function configFromObject(raw: JsonObject): WebsearchConfig | null {
|
|
272
|
+
const strategy = optionalStrategy(raw.strategy) ?? "priority";
|
|
273
|
+
const isFallback = optionalBoolean(raw.fallback) ?? true;
|
|
274
|
+
const providerOrder = optionalProviderOrder(raw.providerOrder);
|
|
275
|
+
const providersValue = raw.providers;
|
|
276
|
+
const rawProviders = Array.isArray(providersValue) ? providersValue : undefined;
|
|
277
|
+
|
|
278
|
+
if (rawProviders) {
|
|
279
|
+
if (optionalProvider(raw.provider)) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const providers = rawProviders
|
|
284
|
+
.map((value) => (isJsonObject(value) ? providerEntryFromObject(value) : null))
|
|
285
|
+
.filter((entry): entry is SearchProviderEntry => entry !== null);
|
|
286
|
+
const orderedProviders = applyProviderOrder(providers, providerOrder);
|
|
287
|
+
return {
|
|
288
|
+
strategy,
|
|
289
|
+
fallback: isFallback,
|
|
290
|
+
providers: orderedProviders,
|
|
291
|
+
...(providerOrder && { providerOrder }),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const provider = providerEntryFromObject(raw);
|
|
296
|
+
|
|
297
|
+
if (provider) {
|
|
298
|
+
return {
|
|
299
|
+
strategy,
|
|
300
|
+
fallback: isFallback,
|
|
301
|
+
providers: [provider],
|
|
302
|
+
...(providerOrder && { providerOrder }),
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (providerOrder || raw.strategy !== undefined || raw.fallback !== undefined) {
|
|
307
|
+
return {
|
|
308
|
+
strategy,
|
|
309
|
+
fallback: isFallback,
|
|
310
|
+
providers: [],
|
|
311
|
+
...(providerOrder && { providerOrder }),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return null;
|
|
350
316
|
}
|
|
351
317
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
{
|
|
356
|
-
return { ok: false, reason: "invalid_config", message: `Unsupported provider: ${config.provider}` };
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (config.allowedDomains && config.blockedDomains)
|
|
360
|
-
{
|
|
361
|
-
return {
|
|
362
|
-
ok: false,
|
|
363
|
-
reason: "invalid_config",
|
|
364
|
-
message: "Provider config cannot specify both allowedDomains and blockedDomains.",
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if (config.weight !== undefined && config.weight <= 0)
|
|
369
|
-
{
|
|
370
|
-
return { ok: false, reason: "invalid_config", message: "Provider weight must be greater than 0." };
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (config.baseUrl && !isAllowedProviderBaseUrl(config.baseUrl))
|
|
374
|
-
{
|
|
375
|
-
return {
|
|
376
|
-
ok: false,
|
|
377
|
-
reason: "invalid_config",
|
|
378
|
-
message: `Provider ${config.provider} baseUrl must be a public HTTPS URL without credentials.`,
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
if (config.provider === "google-cse" && !config.searchEngineId)
|
|
383
|
-
{
|
|
384
|
-
return { ok: false, reason: "missing_api_key", message: "Provider google-cse requires searchEngineId." };
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if ((config.provider === "codex" || config.provider === "openai") && !hasApiKey(config))
|
|
388
|
-
{
|
|
389
|
-
return {
|
|
390
|
-
ok: false,
|
|
391
|
-
reason: "missing_api_key",
|
|
392
|
-
message: `Provider ${config.provider} requires apiKey for hosted Responses API search.`,
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
if (
|
|
397
|
-
config.provider !== "codex"
|
|
398
|
-
&& config.provider !== "openai"
|
|
399
|
-
&& config.provider !== "duckduckgo-html"
|
|
400
|
-
&& !hasApiKey(config)
|
|
401
|
-
)
|
|
402
|
-
{
|
|
403
|
-
return { ok: false, reason: "missing_api_key", message: `Provider ${config.provider} requires apiKey.` };
|
|
404
|
-
}
|
|
318
|
+
function hasApiKey(config: SearchProviderConfig): boolean {
|
|
319
|
+
return typeof config.apiKey === "string" && config.apiKey.length > 0;
|
|
320
|
+
}
|
|
405
321
|
|
|
406
|
-
|
|
322
|
+
export function validateProviderConfig(config: SearchProviderEntry): ProviderValidationResult {
|
|
323
|
+
if (!SEARCH_PROVIDERS.includes(config.provider)) {
|
|
324
|
+
return {
|
|
325
|
+
ok: false,
|
|
326
|
+
reason: "invalid_config",
|
|
327
|
+
message: `Unsupported provider: ${config.provider}`,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (config.allowedDomains && config.blockedDomains) {
|
|
332
|
+
return {
|
|
333
|
+
ok: false,
|
|
334
|
+
reason: "invalid_config",
|
|
335
|
+
message: "Provider config cannot specify both allowedDomains and blockedDomains.",
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (config.weight !== undefined && config.weight <= 0) {
|
|
340
|
+
return {
|
|
341
|
+
ok: false,
|
|
342
|
+
reason: "invalid_config",
|
|
343
|
+
message: "Provider weight must be greater than 0.",
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (config.baseUrl && !isAllowedProviderBaseUrl(config.baseUrl)) {
|
|
348
|
+
return {
|
|
349
|
+
ok: false,
|
|
350
|
+
reason: "invalid_config",
|
|
351
|
+
message: `Provider ${config.provider} baseUrl must be a public HTTPS URL without credentials.`,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (config.provider === "google-cse" && !config.searchEngineId) {
|
|
356
|
+
return {
|
|
357
|
+
ok: false,
|
|
358
|
+
reason: "missing_api_key",
|
|
359
|
+
message: "Provider google-cse requires searchEngineId.",
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if ((config.provider === "codex" || config.provider === "openai") && !hasApiKey(config)) {
|
|
364
|
+
return {
|
|
365
|
+
ok: false,
|
|
366
|
+
reason: "missing_api_key",
|
|
367
|
+
message: `Provider ${config.provider} requires apiKey for hosted Responses API search.`,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (
|
|
372
|
+
config.provider !== "codex" &&
|
|
373
|
+
config.provider !== "openai" &&
|
|
374
|
+
config.provider !== "duckduckgo-html" &&
|
|
375
|
+
!hasApiKey(config)
|
|
376
|
+
) {
|
|
377
|
+
return {
|
|
378
|
+
ok: false,
|
|
379
|
+
reason: "missing_api_key",
|
|
380
|
+
message: `Provider ${config.provider} requires apiKey.`,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return { ok: true, config };
|
|
407
385
|
}
|
|
408
386
|
|
|
409
387
|
export function validateWebsearchConfig(
|
|
410
|
-
|
|
411
|
-
): ProviderValidationResult | { ok: true; config: WebsearchConfig
|
|
412
|
-
{
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
388
|
+
config: WebsearchConfig,
|
|
389
|
+
): ProviderValidationResult | { ok: true; config: WebsearchConfig } {
|
|
390
|
+
if (!STRATEGIES.includes(config.strategy)) {
|
|
391
|
+
return {
|
|
392
|
+
ok: false,
|
|
393
|
+
reason: "invalid_config",
|
|
394
|
+
message: `Unsupported routing strategy: ${config.strategy}`,
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (config.providers.length === 0) {
|
|
399
|
+
return {
|
|
400
|
+
ok: false,
|
|
401
|
+
reason: "invalid_config",
|
|
402
|
+
message: "Websearch config requires at least one provider.",
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
for (const provider of config.providers) {
|
|
407
|
+
const validation = validateProviderConfig(provider);
|
|
408
|
+
|
|
409
|
+
if (!validation.ok) {
|
|
410
|
+
return validation;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return { ok: true, config };
|
|
415
|
+
}
|
|
422
416
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
417
|
+
async function fileExists(path: string): Promise<boolean> {
|
|
418
|
+
try {
|
|
419
|
+
await access(path);
|
|
420
|
+
return true;
|
|
421
|
+
} catch {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
426
425
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
426
|
+
export async function loadWebsearchConfig(options: ConfigLoadOptions): Promise<ConfigLoadResult> {
|
|
427
|
+
const globalDirectory = options.agentDirectory ?? getAgentDir();
|
|
428
|
+
const localPath = path.join(options.cwd, CONFIG_DIR_NAME, "websearch.json");
|
|
429
|
+
const globalPath = path.join(globalDirectory, "websearch.json");
|
|
430
|
+
const local = await readOptionalConfig(localPath);
|
|
431
|
+
|
|
432
|
+
if (local !== undefined && !local.ok) {
|
|
433
|
+
return local;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const global = await readOptionalConfig(globalPath);
|
|
437
|
+
|
|
438
|
+
if (global !== undefined && !global.ok) {
|
|
439
|
+
return global;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const localConfig = local?.ok === true ? local.config : undefined;
|
|
443
|
+
const globalConfig = global?.ok === true ? global.config : undefined;
|
|
444
|
+
const base = localConfig ?? globalConfig ?? DEFAULT_FREE_CONFIG;
|
|
445
|
+
const config = mergeCredentials(base, globalConfig, localConfig, options.env ?? process.env);
|
|
446
|
+
const validation = validateWebsearchConfig(config);
|
|
447
|
+
const source =
|
|
448
|
+
localConfig === undefined
|
|
449
|
+
? globalConfig === undefined
|
|
450
|
+
? "default:duckduckgo-html"
|
|
451
|
+
: globalPath
|
|
452
|
+
: localPath;
|
|
453
|
+
return validation.ok ? { ok: true, config, source } : { ...validation, source };
|
|
454
|
+
}
|
|
432
455
|
|
|
433
|
-
|
|
456
|
+
async function readOptionalConfig(configPath: string): Promise<ConfigLoadResult | undefined> {
|
|
457
|
+
if (!(await fileExists(configPath))) {
|
|
458
|
+
return undefined;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const raw = parseJsonObject(await readFile(configPath, "utf8"));
|
|
462
|
+
|
|
463
|
+
if (raw === null) {
|
|
464
|
+
return {
|
|
465
|
+
ok: false,
|
|
466
|
+
reason: "invalid_config",
|
|
467
|
+
message: `Invalid JSON object in ${configPath}`,
|
|
468
|
+
source: configPath,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const config = configFromObject(raw);
|
|
473
|
+
|
|
474
|
+
if (config === null) {
|
|
475
|
+
return {
|
|
476
|
+
ok: false,
|
|
477
|
+
reason: "invalid_config",
|
|
478
|
+
message: `Invalid provider config in ${configPath}`,
|
|
479
|
+
source: configPath,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return { ok: true, config, source: configPath };
|
|
434
484
|
}
|
|
435
485
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
{
|
|
445
|
-
|
|
446
|
-
|
|
486
|
+
function mergeCredentials(
|
|
487
|
+
base: WebsearchConfig,
|
|
488
|
+
global: WebsearchConfig | undefined,
|
|
489
|
+
local: WebsearchConfig | undefined,
|
|
490
|
+
environment: NodeJS.ProcessEnv,
|
|
491
|
+
): WebsearchConfig {
|
|
492
|
+
return {
|
|
493
|
+
...base,
|
|
494
|
+
providers: base.providers.map((provider) => {
|
|
495
|
+
const globalProvider = findProvider(global, provider);
|
|
496
|
+
const localProvider = findProvider(local, provider);
|
|
497
|
+
const environmentKey = providerEnvironmentKey(provider, environment);
|
|
498
|
+
const apiKey =
|
|
499
|
+
environmentKey ?? globalProvider?.apiKey ?? localProvider?.apiKey ?? provider.apiKey;
|
|
500
|
+
const searchEngineId =
|
|
501
|
+
provider.provider === "google-cse"
|
|
502
|
+
? (environment.GOOGLE_SEARCH_ENGINE_ID ??
|
|
503
|
+
globalProvider?.searchEngineId ??
|
|
504
|
+
localProvider?.searchEngineId ??
|
|
505
|
+
provider.searchEngineId)
|
|
506
|
+
: provider.searchEngineId;
|
|
507
|
+
return {
|
|
508
|
+
...globalProvider,
|
|
509
|
+
...provider,
|
|
510
|
+
...(apiKey && { apiKey }),
|
|
511
|
+
...(searchEngineId && { searchEngineId }),
|
|
512
|
+
};
|
|
513
|
+
}),
|
|
514
|
+
};
|
|
447
515
|
}
|
|
448
516
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
if (!(await fileExists(configPath)))
|
|
460
|
-
{
|
|
461
|
-
continue;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
const raw = parseJsonObject(await readFile(configPath, "utf8"));
|
|
465
|
-
|
|
466
|
-
if (!raw)
|
|
467
|
-
{
|
|
468
|
-
return {
|
|
469
|
-
ok: false,
|
|
470
|
-
reason: "invalid_config",
|
|
471
|
-
message: `Invalid JSON object in ${configPath}`,
|
|
472
|
-
source: configPath,
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
const config = configFromObject(raw);
|
|
477
|
-
|
|
478
|
-
if (!config)
|
|
479
|
-
{
|
|
480
|
-
return {
|
|
481
|
-
ok: false,
|
|
482
|
-
reason: "invalid_config",
|
|
483
|
-
message: `Invalid provider config in ${configPath}`,
|
|
484
|
-
source: configPath,
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
const validation = validateWebsearchConfig(config);
|
|
489
|
-
|
|
490
|
-
if (!validation.ok)
|
|
491
|
-
{
|
|
492
|
-
return { ...validation, source: configPath };
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
return { ok: true, config, source: configPath };
|
|
496
|
-
}
|
|
517
|
+
function findProvider(
|
|
518
|
+
config: WebsearchConfig | undefined,
|
|
519
|
+
target: SearchProviderEntry,
|
|
520
|
+
): SearchProviderEntry | undefined {
|
|
521
|
+
return config?.providers.find((provider) =>
|
|
522
|
+
target.id !== undefined && provider.id === target.id
|
|
523
|
+
? true
|
|
524
|
+
: provider.provider === target.provider,
|
|
525
|
+
);
|
|
526
|
+
}
|
|
497
527
|
|
|
498
|
-
|
|
528
|
+
function providerEnvironmentKey(
|
|
529
|
+
provider: SearchProviderEntry,
|
|
530
|
+
environment: NodeJS.ProcessEnv,
|
|
531
|
+
): string | undefined {
|
|
532
|
+
const customName = `PI_AGENT_IDE_SEARCH_${(provider.id ?? provider.provider)
|
|
533
|
+
.replaceAll(/[^a-z0-9]/giu, "_")
|
|
534
|
+
.toUpperCase()}_API_KEY`;
|
|
535
|
+
const standard: Partial<Record<SearchProvider, readonly string[]>> = {
|
|
536
|
+
exa: ["EXA_API_KEY"],
|
|
537
|
+
tavily: ["TAVILY_API_KEY"],
|
|
538
|
+
brave: ["BRAVE_SEARCH_API_KEY", "BRAVE_API_KEY"],
|
|
539
|
+
serper: ["SERPER_API_KEY"],
|
|
540
|
+
parallel: ["PARALLEL_API_KEY"],
|
|
541
|
+
"google-cse": ["GOOGLE_API_KEY"],
|
|
542
|
+
"z-ai": ["ZAI_API_KEY"],
|
|
543
|
+
openai: ["OPENAI_API_KEY"],
|
|
544
|
+
codex: ["OPENAI_API_KEY"],
|
|
545
|
+
anthropic: ["ANTHROPIC_API_KEY"],
|
|
546
|
+
perplexity: ["PERPLEXITY_API_KEY"],
|
|
547
|
+
xai: ["XAI_API_KEY"],
|
|
548
|
+
kimi: ["KIMI_API_KEY"],
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
for (const name of [customName, ...(standard[provider.provider] ?? [])]) {
|
|
552
|
+
const value = environment[name]?.trim();
|
|
553
|
+
|
|
554
|
+
if (value) {
|
|
555
|
+
return value;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
return undefined;
|
|
499
560
|
}
|