@herbertgao/pi-extensions 2026.9.10 → 2026.9.12
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 +1 -0
- package/THIRD_PARTY_NOTICES.md +26 -0
- package/node_modules/@herbertgao/pi-bark/package.json +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +3 -2
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/package.json +2 -2
- package/node_modules/@herbertgao/resume-from/package.json +1 -1
- package/node_modules/@herbertgao/sol-pi/README.md +3 -3
- package/node_modules/@herbertgao/sol-pi/THIRD_PARTY_NOTICES.md +4 -4
- package/node_modules/@herbertgao/sol-pi/agents-install.md +4 -4
- package/node_modules/@herbertgao/sol-pi/docs/compatibility.md +6 -6
- package/node_modules/@herbertgao/sol-pi/package.json +2 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +2 -2
- package/node_modules/@narumitw/pi-btw/dist/index.ts +39 -89
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +3 -3
- package/node_modules/@narumitw/pi-btw/package.json +4 -4
- package/node_modules/@narumitw/pi-btw/src/btw.ts +28 -87
- package/node_modules/@narumitw/pi-btw/src/main-tree-picker.ts +8 -0
- package/node_modules/@narumitw/pi-btw/src/side-thread.ts +40 -37
- package/node_modules/@narumitw/pi-caffeinate/README.md +21 -66
- package/node_modules/@narumitw/pi-caffeinate/dist/index.ts +10 -41
- package/node_modules/@narumitw/pi-caffeinate/dist/index.ts.map +2 -2
- package/node_modules/@narumitw/pi-caffeinate/package.json +50 -51
- package/node_modules/@narumitw/pi-caffeinate/src/caffeinate.ts +637 -663
- package/node_modules/@narumitw/pi-caffeinate/src/dbus-inhibit.ts +114 -120
- package/node_modules/@narumitw/pi-caffeinate/src/inhibitor-process.ts +29 -29
- package/node_modules/@narumitw/pi-caffeinate/src/inhibitors.ts +108 -126
- package/node_modules/@narumitw/pi-caffeinate/src/settings.ts +124 -128
- package/node_modules/pi-mcp-adapter/CHANGELOG.md +62 -0
- package/node_modules/pi-mcp-adapter/README.md +75 -7
- package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +193 -0
- package/node_modules/pi-mcp-adapter/cli.js +56 -5
- package/node_modules/pi-mcp-adapter/commands.ts +96 -5
- package/node_modules/pi-mcp-adapter/config.ts +73 -6
- package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +22 -28
- package/node_modules/pi-mcp-adapter/direct-tools.ts +13 -5
- package/node_modules/pi-mcp-adapter/dist/abort.d.ts +2 -0
- package/node_modules/pi-mcp-adapter/dist/abort.js +36 -0
- package/node_modules/pi-mcp-adapter/dist/abort.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +6 -0
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +194 -0
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/config.d.ts +5 -0
- package/node_modules/pi-mcp-adapter/dist/config.js +75 -6
- package/node_modules/pi-mcp-adapter/dist/config.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +18 -0
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js +88 -0
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +17 -0
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +316 -0
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/errors.d.ts +131 -0
- package/node_modules/pi-mcp-adapter/dist/errors.js +278 -0
- package/node_modules/pi-mcp-adapter/dist/errors.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +8 -0
- package/node_modules/pi-mcp-adapter/dist/http-ca.js +88 -0
- package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +15 -0
- package/node_modules/pi-mcp-adapter/dist/jev-client.js +340 -0
- package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +77 -0
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +2 -0
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +22 -0
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +85 -0
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +2 -0
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +55 -0
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +56 -0
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js +410 -0
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/logger.d.ts +51 -0
- package/node_modules/pi-mcp-adapter/dist/logger.js +131 -0
- package/node_modules/pi-mcp-adapter/dist/logger.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +26 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +103 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +118 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +1098 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +168 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +1117 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +7 -140
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +53 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +441 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +148 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +689 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +6 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +166 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +102 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +369 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +95 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +242 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +2 -11
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +6 -0
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +505 -0
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +10 -0
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +312 -0
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +13 -0
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +97 -0
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +17 -0
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +203 -0
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +11 -0
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +172 -0
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +157 -0
- package/node_modules/pi-mcp-adapter/dist/server-manager.js +1743 -0
- package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +34 -0
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js +140 -0
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +26 -0
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js +142 -0
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/state.d.ts +73 -0
- package/node_modules/pi-mcp-adapter/dist/state.js +2 -0
- package/node_modules/pi-mcp-adapter/dist/state.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/types.d.ts +36 -0
- package/node_modules/pi-mcp-adapter/dist/types.js +18 -0
- package/node_modules/pi-mcp-adapter/dist/types.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +17 -0
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +219 -0
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +15 -0
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +85 -0
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/utils.d.ts +1 -0
- package/node_modules/pi-mcp-adapter/dist/utils.js +13 -0
- package/node_modules/pi-mcp-adapter/dist/utils.js.map +1 -1
- package/node_modules/pi-mcp-adapter/elicitation-handler.ts +29 -19
- package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +85 -0
- package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +34 -0
- package/node_modules/pi-mcp-adapter/index.ts +129 -6
- package/node_modules/pi-mcp-adapter/init.ts +6 -19
- package/node_modules/pi-mcp-adapter/jev-client.ts +273 -0
- package/node_modules/pi-mcp-adapter/jev-contracts.ts +53 -0
- package/node_modules/pi-mcp-adapter/jev-key-store.ts +79 -0
- package/node_modules/pi-mcp-adapter/lifecycle.ts +14 -3
- package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +7 -142
- package/node_modules/pi-mcp-adapter/mcp-code.ts +119 -11
- package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +4 -0
- package/node_modules/pi-mcp-adapter/mcp-references.ts +5 -3
- package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +5 -0
- package/node_modules/pi-mcp-adapter/mcp-tasks.ts +467 -0
- package/node_modules/pi-mcp-adapter/metadata-cache.ts +2 -13
- package/node_modules/pi-mcp-adapter/namespace-tools.ts +1 -1
- package/node_modules/pi-mcp-adapter/package.json +17 -9
- package/node_modules/pi-mcp-adapter/proxy-modes.ts +319 -166
- package/node_modules/pi-mcp-adapter/request-headers-command.ts +6 -3
- package/node_modules/pi-mcp-adapter/search-ranking.ts +38 -7
- package/node_modules/pi-mcp-adapter/secure-keyring.ts +170 -0
- package/node_modules/pi-mcp-adapter/semantic-search.ts +186 -0
- package/node_modules/pi-mcp-adapter/server-manager.ts +293 -50
- package/node_modules/pi-mcp-adapter/session-approvals.ts +14 -0
- package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +2 -0
- package/node_modules/pi-mcp-adapter/state.ts +3 -1
- package/node_modules/pi-mcp-adapter/tool-approval.ts +26 -4
- package/node_modules/pi-mcp-adapter/tool-metadata.ts +6 -14
- package/node_modules/pi-mcp-adapter/tool-registrar.ts +8 -6
- package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +4 -1
- package/node_modules/pi-mcp-adapter/types.ts +53 -0
- package/node_modules/pi-mcp-adapter/ui-server.ts +17 -9
- package/node_modules/pi-mcp-adapter/utils.ts +16 -0
- package/node_modules/pi-multi-account/CHANGELOG.md +1209 -0
- package/node_modules/pi-multi-account/CONTRIBUTING.md +61 -0
- package/node_modules/pi-multi-account/LICENSE +21 -0
- package/node_modules/pi-multi-account/README.md +197 -0
- package/node_modules/pi-multi-account/SECURITY.md +27 -0
- package/node_modules/pi-multi-account/auth-file-transaction.ts +56 -0
- package/node_modules/pi-multi-account/child-usability.ts +233 -0
- package/node_modules/pi-multi-account/compaction-summary.ts +32 -0
- package/node_modules/pi-multi-account/completion-route-planner.ts +224 -0
- package/node_modules/pi-multi-account/context-guard.ts +420 -0
- package/node_modules/pi-multi-account/cursor/LICENSE +21 -0
- package/node_modules/pi-multi-account/cursor/NOTICE +2 -0
- package/node_modules/pi-multi-account/cursor/auth.ts +165 -0
- package/node_modules/pi-multi-account/cursor/bridge-handle.ts +155 -0
- package/node_modules/pi-multi-account/cursor/conversation-registry.ts +104 -0
- package/node_modules/pi-multi-account/cursor/cursor-models-raw.json +611 -0
- package/node_modules/pi-multi-account/cursor/cursor-shared.ts +192 -0
- package/node_modules/pi-multi-account/cursor/h2-bridge.mjs +175 -0
- package/node_modules/pi-multi-account/cursor/index.ts +572 -0
- package/node_modules/pi-multi-account/cursor/message-parsing.ts +323 -0
- package/node_modules/pi-multi-account/cursor/prompt-usage.ts +53 -0
- package/node_modules/pi-multi-account/cursor/proto/agent_pb.ts +15294 -0
- package/node_modules/pi-multi-account/cursor/proxy.ts +2510 -0
- package/node_modules/pi-multi-account/cursor/session-lifecycle.ts +40 -0
- package/node_modules/pi-multi-account/cursor/sse-keepalive.ts +24 -0
- package/node_modules/pi-multi-account/cursor/stream-lifecycle.ts +193 -0
- package/node_modules/pi-multi-account/cursor/upstream-watchdog.ts +88 -0
- package/node_modules/pi-multi-account/cursor-bridge.ts +240 -0
- package/node_modules/pi-multi-account/cursor-model-name.ts +12 -0
- package/node_modules/pi-multi-account/index.ts +11825 -0
- package/node_modules/pi-multi-account/model-catalog.ts +354 -0
- package/node_modules/pi-multi-account/package.json +101 -0
- package/node_modules/pi-multi-account/pi-contract.ts +281 -0
- package/node_modules/pi-multi-account/provider-payload-stream.ts +44 -0
- package/node_modules/pi-multi-account/provider-priority.ts +189 -0
- package/node_modules/pi-multi-account/slot-proxy-auth.ts +167 -0
- package/node_modules/pi-multi-account/slot-proxy.ts +344 -0
- package/node_modules/pi-multi-account/state-file-transaction.ts +67 -0
- package/node_modules/pi-multi-account/usage.ts +1099 -0
- package/node_modules/pi-typesafe/README.md +6 -2
- package/node_modules/pi-typesafe/dist/client.d.ts +11 -0
- package/node_modules/pi-typesafe/dist/client.js +45 -10
- package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/index.js +1 -1
- package/node_modules/pi-typesafe/package.json +2 -2
- package/node_modules/pi-web-access/CHANGELOG.md +36 -0
- package/node_modules/pi-web-access/README.md +75 -18
- package/node_modules/pi-web-access/anysearch.ts +4 -15
- package/node_modules/pi-web-access/bocha.ts +3 -22
- package/node_modules/pi-web-access/brave.ts +3 -21
- package/node_modules/pi-web-access/brightdata.ts +5 -32
- package/node_modules/pi-web-access/content-find.ts +168 -53
- package/node_modules/pi-web-access/curator-page.ts +4 -1
- package/node_modules/pi-web-access/curator-run.ts +2 -1
- package/node_modules/pi-web-access/curator-server.ts +1 -0
- package/node_modules/pi-web-access/dist/index.js +24620 -0
- package/node_modules/pi-web-access/domain-filter-normalization.ts +14 -0
- package/node_modules/pi-web-access/duckduckgo.ts +3 -21
- package/node_modules/pi-web-access/extract.ts +3 -1
- package/node_modules/pi-web-access/firecrawl.ts +5 -29
- package/node_modules/pi-web-access/gemini-search.ts +81 -32
- package/node_modules/pi-web-access/index.ts +149 -148
- package/node_modules/pi-web-access/jina-search.ts +4 -15
- package/node_modules/pi-web-access/kagi.ts +4 -13
- package/node_modules/pi-web-access/kimi-search.ts +5 -30
- package/node_modules/pi-web-access/mistral-search.ts +1 -15
- package/node_modules/pi-web-access/ollama.ts +2 -7
- package/node_modules/pi-web-access/openai-search.ts +174 -36
- package/node_modules/pi-web-access/opencode-session-headers.ts +24 -0
- package/node_modules/pi-web-access/package.json +10 -4
- package/node_modules/pi-web-access/page-query.ts +10 -2
- package/node_modules/pi-web-access/parallel.ts +1 -15
- package/node_modules/pi-web-access/pdf-extract.ts +3 -0
- package/node_modules/pi-web-access/querit.ts +5 -29
- package/node_modules/pi-web-access/search-answer-formatting.ts +11 -0
- package/node_modules/pi-web-access/search-result-count-normalization.ts +4 -0
- package/node_modules/pi-web-access/search1api.ts +5 -29
- package/node_modules/pi-web-access/searchinfinity.ts +5 -29
- package/node_modules/pi-web-access/searxng.ts +3 -21
- package/node_modules/pi-web-access/serpapi.ts +5 -28
- package/node_modules/pi-web-access/serpbase.ts +3 -22
- package/node_modules/pi-web-access/serpdive.ts +3 -21
- package/node_modules/pi-web-access/serper.ts +5 -28
- package/node_modules/pi-web-access/serply.ts +197 -0
- package/node_modules/pi-web-access/source-check.ts +11 -47
- package/node_modules/pi-web-access/summary-review.ts +7 -3
- package/node_modules/pi-web-access/tavily.ts +3 -21
- package/node_modules/pi-web-access/tinyfish.ts +5 -29
- package/node_modules/pi-web-access/utils.ts +9 -1
- package/node_modules/pi-web-access/valyu.ts +5 -28
- package/node_modules/pi-web-access/xai-search.ts +1 -15
- package/node_modules/pi-web-access/xcrawl.ts +5 -32
- package/package.json +23 -16
|
@@ -5,7 +5,7 @@ import type { DirectToolSpec, McpContent } from "./types.ts";
|
|
|
5
5
|
import { lazyConnect, getFailureAgeSeconds, clearFailure } from "./init.ts";
|
|
6
6
|
import { abortable, throwIfAborted } from "./abort.ts";
|
|
7
7
|
import { formatSchema } from "./tool-metadata.ts";
|
|
8
|
-
import { resolveMcpResultContent,
|
|
8
|
+
import { resolveMcpResultContent, transformMcpResourceContents } from "./tool-registrar.ts";
|
|
9
9
|
import { guardMcpOutput, guardedMcpDetails, resolveMcpOutputGuardOptions } from "./mcp-output-guard.ts";
|
|
10
10
|
import { maybeStartUiSession, summarizeUiSessionResult, type UiSessionRuntime } from "./ui-session.ts";
|
|
11
11
|
import { isServerDisabled } from "./types.ts";
|
|
@@ -13,6 +13,7 @@ import { authenticate, supportsOAuth } from "./mcp-auth-flow.ts";
|
|
|
13
13
|
import { formatAuthRequiredMessage, normalizeToolArguments, resolveServerUrl } from "./utils.ts";
|
|
14
14
|
import { SessionRecoveryAuthRequiredError, withSessionRecovery } from "./session-recovery.ts";
|
|
15
15
|
import { combineAbortSignals, isAbortError } from "./runtime-owner.ts";
|
|
16
|
+
import { callToolViaTaskSession } from "./mcp-tasks.ts";
|
|
16
17
|
import { ensureToolCallApproved } from "./tool-approval.ts";
|
|
17
18
|
import { getInputRequiredNeedsUiDetails } from "./errors.ts";
|
|
18
19
|
|
|
@@ -27,6 +28,7 @@ type DirectAutoAuthResult =
|
|
|
27
28
|
export {
|
|
28
29
|
DIRECT_TOOLS_ADVISORY_THRESHOLD,
|
|
29
30
|
buildProxyDescription,
|
|
31
|
+
getLargeDirectToolsAdvisory,
|
|
30
32
|
getMissingConfiguredDirectToolServers,
|
|
31
33
|
prepareDirectToolArguments,
|
|
32
34
|
resolveDirectTools,
|
|
@@ -310,6 +312,15 @@ export function createDirectToolExecutor(
|
|
|
310
312
|
spec.serverName,
|
|
311
313
|
async (conn) => {
|
|
312
314
|
await state.manager.ensureListen?.(spec.serverName, conn);
|
|
315
|
+
if (conn.taskSession) {
|
|
316
|
+
return await callToolViaTaskSession(conn.taskSession, {
|
|
317
|
+
name: spec.originalName,
|
|
318
|
+
args: normalizedParams ?? {},
|
|
319
|
+
meta: uiSession?.requestMeta,
|
|
320
|
+
signal: ownedSignal,
|
|
321
|
+
requestTimeoutMs: requestOptions?.timeout,
|
|
322
|
+
}) as unknown as ClientCallToolResult;
|
|
323
|
+
}
|
|
313
324
|
return abortable(conn.client.callTool({
|
|
314
325
|
name: spec.originalName,
|
|
315
326
|
arguments: normalizedParams,
|
|
@@ -320,14 +331,11 @@ export function createDirectToolExecutor(
|
|
|
320
331
|
uiSession?.sendToolResult(result as unknown as import("@modelcontextprotocol/client").CallToolResult);
|
|
321
332
|
|
|
322
333
|
if (result.isError) {
|
|
323
|
-
const
|
|
324
|
-
const content = transformMcpContent(mcpContent, state.owner?.signal);
|
|
334
|
+
const content = resolveMcpResultContent(result as Record<string, unknown>, state.owner?.signal);
|
|
325
335
|
const outputContent = content.length > 0 ? content : [{ type: "text" as const, text: "(empty result)" }];
|
|
326
|
-
const schemaText = spec.inputSchema ? `\n\nExpected parameters:\n${formatSchema(spec.inputSchema)}` : "";
|
|
327
336
|
const guarded = await guardMcpOutput(outputContent, {
|
|
328
337
|
...outputGuardOptions,
|
|
329
338
|
prefix: "Error: ",
|
|
330
|
-
suffix: schemaText,
|
|
331
339
|
emptyTextFallback: "Tool execution failed",
|
|
332
340
|
...(state.config.settings?.directToolResultDetails === "bounded" ? { rawMcpResult: result } : {}),
|
|
333
341
|
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function throwIfAborted(signal) {
|
|
2
|
+
if (!signal?.aborted)
|
|
3
|
+
return;
|
|
4
|
+
throw signal.reason instanceof Error ? signal.reason : new Error(String(signal.reason ?? "MCP request aborted"));
|
|
5
|
+
}
|
|
6
|
+
export async function abortable(promise, signal) {
|
|
7
|
+
if (!signal)
|
|
8
|
+
return promise;
|
|
9
|
+
throwIfAborted(signal);
|
|
10
|
+
return await new Promise((resolve, reject) => {
|
|
11
|
+
let settled = false;
|
|
12
|
+
const cleanup = () => signal.removeEventListener("abort", onAbort);
|
|
13
|
+
const onAbort = () => {
|
|
14
|
+
if (settled)
|
|
15
|
+
return;
|
|
16
|
+
settled = true;
|
|
17
|
+
cleanup();
|
|
18
|
+
reject(signal.reason instanceof Error ? signal.reason : new Error(String(signal.reason ?? "MCP request aborted")));
|
|
19
|
+
};
|
|
20
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
21
|
+
promise.then(value => {
|
|
22
|
+
if (settled)
|
|
23
|
+
return;
|
|
24
|
+
settled = true;
|
|
25
|
+
cleanup();
|
|
26
|
+
resolve(value);
|
|
27
|
+
}, error => {
|
|
28
|
+
if (settled)
|
|
29
|
+
return;
|
|
30
|
+
settled = true;
|
|
31
|
+
cleanup();
|
|
32
|
+
reject(error);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=abort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.js","sourceRoot":"","sources":["../abort.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAC,MAAoB;IACjD,IAAI,CAAC,MAAM,EAAE,OAAO;QAAE,OAAO;IAC7B,MAAM,MAAM,CAAC,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,qBAAqB,CAAC,CAAC,CAAC;AACnH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,OAAmB,EAAE,MAAoB;IAC1E,IAAI,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC;IAC5B,cAAc,CAAC,MAAM,CAAC,CAAC;IACvB,OAAO,MAAM,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9C,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACnE,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,EAAE,CAAC;YACV,MAAM,CAAC,MAAM,CAAC,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACrH,CAAC,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CACV,KAAK,CAAC,EAAE;YACN,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,EAAE,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC,EACD,KAAK,CAAC,EAAE;YACN,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,EAAE,CAAC;YACV,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
const DEFAULT_TTL_MS = 5 * 60_000;
|
|
3
|
+
const ENV_TTL_MS = "PI_MCP_ADAPTER_BEARER_COMMAND_TTL_MS";
|
|
4
|
+
const COMMAND_TIMEOUT_MS = 10_000;
|
|
5
|
+
const COMMAND_MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
6
|
+
const USE_PROCESS_GROUP = process.platform !== "win32";
|
|
7
|
+
function resolveDefaultTtlMs() {
|
|
8
|
+
const parsed = Number(process.env[ENV_TTL_MS] || DEFAULT_TTL_MS);
|
|
9
|
+
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : DEFAULT_TTL_MS;
|
|
10
|
+
}
|
|
11
|
+
function abortReason(signal) {
|
|
12
|
+
return signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
13
|
+
}
|
|
14
|
+
function runCommand(command, context, signal) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
let output = Buffer.alloc(0);
|
|
17
|
+
let settled = false;
|
|
18
|
+
let terminating = false;
|
|
19
|
+
const child = spawn(command.slice(1), {
|
|
20
|
+
shell: true,
|
|
21
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
22
|
+
windowsHide: true,
|
|
23
|
+
detached: USE_PROCESS_GROUP,
|
|
24
|
+
});
|
|
25
|
+
const kill = async () => {
|
|
26
|
+
if (child.pid === undefined)
|
|
27
|
+
return;
|
|
28
|
+
if (!USE_PROCESS_GROUP) {
|
|
29
|
+
await new Promise((resolveKill, rejectKill) => {
|
|
30
|
+
const killer = spawn("taskkill", ["/pid", String(child.pid), "/T", "/F"], {
|
|
31
|
+
stdio: "ignore",
|
|
32
|
+
windowsHide: true,
|
|
33
|
+
});
|
|
34
|
+
killer.on("error", () => rejectKill(new Error("Failed to stop bearer token command")));
|
|
35
|
+
killer.on("close", code => {
|
|
36
|
+
if (code === 0 || code === 128)
|
|
37
|
+
resolveKill();
|
|
38
|
+
else
|
|
39
|
+
rejectKill(new Error(`Failed to stop bearer token command: taskkill exited with code ${code ?? "unknown"}`));
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
process.kill(-child.pid, "SIGKILL");
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error.code !== "ESRCH")
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const finish = (error, token) => {
|
|
53
|
+
if (settled)
|
|
54
|
+
return;
|
|
55
|
+
settled = true;
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
signal.removeEventListener("abort", onAbort);
|
|
58
|
+
if (error !== undefined)
|
|
59
|
+
reject(error);
|
|
60
|
+
else
|
|
61
|
+
resolve(token);
|
|
62
|
+
};
|
|
63
|
+
const terminate = async (error) => {
|
|
64
|
+
if (settled || terminating)
|
|
65
|
+
return;
|
|
66
|
+
terminating = true;
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
signal.removeEventListener("abort", onAbort);
|
|
69
|
+
try {
|
|
70
|
+
await kill();
|
|
71
|
+
finish(error);
|
|
72
|
+
}
|
|
73
|
+
catch (cleanupError) {
|
|
74
|
+
finish(cleanupError);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const onAbort = () => {
|
|
78
|
+
void terminate(abortReason(signal));
|
|
79
|
+
};
|
|
80
|
+
const timer = setTimeout(() => {
|
|
81
|
+
void terminate(new Error(`Failed to resolve ${context}: command timed out after ${COMMAND_TIMEOUT_MS}ms`));
|
|
82
|
+
}, COMMAND_TIMEOUT_MS);
|
|
83
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
84
|
+
if (signal.aborted) {
|
|
85
|
+
onAbort();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
child.on("error", () => {
|
|
89
|
+
if (!terminating)
|
|
90
|
+
finish(new Error(`Failed to resolve ${context}: command failed to start`));
|
|
91
|
+
});
|
|
92
|
+
child.stdout.on("data", (chunk) => {
|
|
93
|
+
if (settled || terminating)
|
|
94
|
+
return;
|
|
95
|
+
output = Buffer.concat([output, Buffer.from(chunk)]);
|
|
96
|
+
if (output.byteLength > COMMAND_MAX_OUTPUT_BYTES) {
|
|
97
|
+
void terminate(new Error(`Failed to resolve ${context}: command output exceeded 1 MiB`));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
child.on("close", code => {
|
|
101
|
+
if (settled || terminating)
|
|
102
|
+
return;
|
|
103
|
+
if (code !== 0) {
|
|
104
|
+
finish(new Error(`Failed to resolve ${context}: command exited with code ${code ?? "unknown"}`));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const token = output.toString("utf8").trim();
|
|
108
|
+
if (!token) {
|
|
109
|
+
finish(new Error(`Failed to resolve ${context}: command returned empty output`));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
finish(undefined, token);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** Resolve and periodically refresh one command-backed bearer token. */
|
|
117
|
+
export class BearerCommandResolver {
|
|
118
|
+
#command;
|
|
119
|
+
#context;
|
|
120
|
+
#ttlMs;
|
|
121
|
+
#cached;
|
|
122
|
+
#failure;
|
|
123
|
+
#inflight;
|
|
124
|
+
constructor(command, context, ttlMs = resolveDefaultTtlMs()) {
|
|
125
|
+
this.#command = command;
|
|
126
|
+
this.#context = context;
|
|
127
|
+
this.#ttlMs = ttlMs;
|
|
128
|
+
}
|
|
129
|
+
resolve(signal) {
|
|
130
|
+
if (signal?.aborted)
|
|
131
|
+
return Promise.reject(abortReason(signal));
|
|
132
|
+
const now = Date.now();
|
|
133
|
+
if (this.#cached !== undefined && now < this.#cached.expiresAt) {
|
|
134
|
+
return Promise.resolve(this.#cached.token);
|
|
135
|
+
}
|
|
136
|
+
if (this.#failure !== undefined && now < this.#failure.retryAt) {
|
|
137
|
+
return this.#cached !== undefined
|
|
138
|
+
? Promise.resolve(this.#cached.token)
|
|
139
|
+
: Promise.reject(this.#failure.error);
|
|
140
|
+
}
|
|
141
|
+
let inflight = this.#inflight;
|
|
142
|
+
if (inflight === undefined) {
|
|
143
|
+
const controller = new AbortController();
|
|
144
|
+
let current;
|
|
145
|
+
const promise = runCommand(this.#command, this.#context, controller.signal)
|
|
146
|
+
.then(token => {
|
|
147
|
+
this.#cached = { token, expiresAt: Date.now() + this.#ttlMs };
|
|
148
|
+
this.#failure = undefined;
|
|
149
|
+
return token;
|
|
150
|
+
})
|
|
151
|
+
.catch(error => {
|
|
152
|
+
// Request cancellation is not a helper outage. Do not let one
|
|
153
|
+
// cancelled request suppress refresh attempts for the next caller.
|
|
154
|
+
if (!controller.signal.aborted) {
|
|
155
|
+
this.#failure = { error, retryAt: Date.now() + this.#ttlMs };
|
|
156
|
+
}
|
|
157
|
+
if (this.#cached !== undefined)
|
|
158
|
+
return this.#cached.token;
|
|
159
|
+
throw error;
|
|
160
|
+
})
|
|
161
|
+
.finally(() => {
|
|
162
|
+
if (this.#inflight === current)
|
|
163
|
+
this.#inflight = undefined;
|
|
164
|
+
});
|
|
165
|
+
current = { controller, promise, waiters: 0 };
|
|
166
|
+
this.#inflight = current;
|
|
167
|
+
inflight = current;
|
|
168
|
+
}
|
|
169
|
+
return this.#wait(inflight, signal);
|
|
170
|
+
}
|
|
171
|
+
#wait(inflight, signal) {
|
|
172
|
+
inflight.waiters++;
|
|
173
|
+
let onAbort;
|
|
174
|
+
const result = signal === undefined
|
|
175
|
+
? inflight.promise
|
|
176
|
+
: Promise.race([
|
|
177
|
+
inflight.promise,
|
|
178
|
+
new Promise((_resolve, reject) => {
|
|
179
|
+
onAbort = () => reject(abortReason(signal));
|
|
180
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
181
|
+
}),
|
|
182
|
+
]);
|
|
183
|
+
return result.finally(() => {
|
|
184
|
+
if (onAbort)
|
|
185
|
+
signal.removeEventListener("abort", onAbort);
|
|
186
|
+
inflight.waiters--;
|
|
187
|
+
if (this.#inflight === inflight && inflight.waiters === 0) {
|
|
188
|
+
this.#inflight = undefined;
|
|
189
|
+
inflight.controller.abort(signal?.reason);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=bearer-command-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bearer-command-resolver.js","sourceRoot":"","sources":["../bearer-command-resolver.ts"],"names":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AAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;oBAC5C,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC5D,CAAC,CAAC;aACH,CAAC,CAAC;QACP,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE;YACzB,IAAI,OAAO;gBAAE,MAAO,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC3D,QAAQ,CAAC,OAAO,EAAE,CAAC;YACnB,IAAI,IAAI,CAAC,SAAS,KAAK,QAAQ,IAAI,QAAQ,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;gBAC1D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;gBAC3B,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -101,6 +101,11 @@ export declare function cloneMcpConfig(config: McpConfig): McpConfig;
|
|
|
101
101
|
export declare function loadMcpConfig(overridePath?: string, cwd?: string): McpConfig;
|
|
102
102
|
export declare function resolveConfiguredClaudePluginMcp(config: McpConfig, cwd?: string): McpConfig;
|
|
103
103
|
export declare function discoverConfiguredClaudePluginSkills(config: McpConfig, cwd?: string): string[];
|
|
104
|
+
export declare function writeSharedConfigText(filePath: string, text: string): void;
|
|
105
|
+
export declare function writeJevSemanticSearchConfig(overridePath: string | undefined, cwd: string, allowedServers: string[], effectiveJev?: unknown): {
|
|
106
|
+
path: string;
|
|
107
|
+
changed: boolean;
|
|
108
|
+
};
|
|
104
109
|
export interface ServerDisabledOverrideResult {
|
|
105
110
|
path: string;
|
|
106
111
|
changed: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// config.ts - Config loading with import support
|
|
2
|
-
import { existsSync, readFileSync, realpathSync, statSync, writeFileSync, mkdirSync, renameSync } from "node:fs";
|
|
2
|
+
import { chmodSync, existsSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, mkdirSync, renameSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
5
|
import { parse as parseToml } from "smol-toml";
|
|
@@ -9,6 +9,7 @@ import { getAgentPluginSummaries, loadAgentPluginConfigs } from "./agent-plugin-
|
|
|
9
9
|
import { cloneBuiltInAgentPluginEntry, isBuiltInAgentPlugin, mergeBuiltInAgentPluginEntries } from "./agent-plugin-provenance.js";
|
|
10
10
|
import { loadClaudePluginBundles } from "./claude-plugin-loader.js";
|
|
11
11
|
import { loadPackageMcpConfigs } from "./package-mcp-loader.js";
|
|
12
|
+
import { validateJevSettings } from "./jev-client.js";
|
|
12
13
|
import { formatServerNamespace, isServerDisabled } from "./types.js";
|
|
13
14
|
import { parseJsonWithComments, toStringRecord } from "./utils.js";
|
|
14
15
|
const GENERIC_GLOBAL_CONFIG_PATH = join(homedir(), ".config", "mcp", "mcp.json");
|
|
@@ -696,10 +697,20 @@ function validateConfig(raw) {
|
|
|
696
697
|
return {
|
|
697
698
|
mcpServers: toServerEntries(raw.mcpServers ?? raw["mcp-servers"]),
|
|
698
699
|
...(Array.isArray(raw.imports) ? { imports: raw.imports } : {}),
|
|
699
|
-
...(raw.settings !== undefined ? { settings: raw.settings } : {}),
|
|
700
|
+
...(raw.settings !== undefined ? { settings: parseSettings(raw.settings) } : {}),
|
|
700
701
|
...(raw.claudePlugins !== undefined ? { claudePlugins: parseClaudePlugins(raw.claudePlugins) } : {}),
|
|
701
702
|
};
|
|
702
703
|
}
|
|
704
|
+
function parseSettings(value) {
|
|
705
|
+
if (!isRecord(value))
|
|
706
|
+
throw new Error("settings must be an object");
|
|
707
|
+
const settings = { ...value };
|
|
708
|
+
if (value.jev !== undefined) {
|
|
709
|
+
validateJevSettings(value.jev);
|
|
710
|
+
settings.jev = value.jev;
|
|
711
|
+
}
|
|
712
|
+
return settings;
|
|
713
|
+
}
|
|
703
714
|
function parseClaudePlugins(value) {
|
|
704
715
|
if (!Array.isArray(value)) {
|
|
705
716
|
console.warn("Invalid claudePlugins config: expected an array");
|
|
@@ -970,11 +981,69 @@ function readRawConfigObject(filePath) {
|
|
|
970
981
|
return {};
|
|
971
982
|
}
|
|
972
983
|
}
|
|
984
|
+
function writeConfigText(writePath, text) {
|
|
985
|
+
let mode;
|
|
986
|
+
try {
|
|
987
|
+
writePath = realpathSync(writePath);
|
|
988
|
+
mode = statSync(writePath).mode & 0o777;
|
|
989
|
+
}
|
|
990
|
+
catch { }
|
|
991
|
+
mkdirSync(dirname(writePath), { recursive: true });
|
|
992
|
+
const tmpPath = `${writePath}.${process.pid}.tmp`;
|
|
993
|
+
rmSync(tmpPath, { force: true });
|
|
994
|
+
try {
|
|
995
|
+
writeFileSync(tmpPath, text, mode === undefined ? "utf-8" : { encoding: "utf-8", mode });
|
|
996
|
+
if (mode !== undefined)
|
|
997
|
+
chmodSync(tmpPath, mode);
|
|
998
|
+
renameSync(tmpPath, writePath);
|
|
999
|
+
}
|
|
1000
|
+
catch (error) {
|
|
1001
|
+
try {
|
|
1002
|
+
rmSync(tmpPath, { force: true });
|
|
1003
|
+
}
|
|
1004
|
+
catch { }
|
|
1005
|
+
throw error;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
973
1008
|
function writeRawConfigObject(filePath, raw) {
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1009
|
+
writeConfigText(filePath, `${JSON.stringify(raw, null, 2)}\n`);
|
|
1010
|
+
}
|
|
1011
|
+
export function writeSharedConfigText(filePath, text) {
|
|
1012
|
+
if (!isRecord(parseJsonWithComments(text)))
|
|
1013
|
+
throw new Error("top-level value must be an object");
|
|
1014
|
+
writeConfigText(filePath, text);
|
|
1015
|
+
}
|
|
1016
|
+
export function writeJevSemanticSearchConfig(overridePath, cwd, allowedServers, effectiveJev) {
|
|
1017
|
+
const filePath = overridePath ? getPiGlobalConfigPath(overridePath) : getProjectPiConfigPath(cwd);
|
|
1018
|
+
let raw = {};
|
|
1019
|
+
if (existsSync(filePath)) {
|
|
1020
|
+
try {
|
|
1021
|
+
const parsed = parseJsonWithComments(readFileSync(filePath, "utf8"));
|
|
1022
|
+
if (!isRecord(parsed))
|
|
1023
|
+
throw new Error("top-level value must be an object");
|
|
1024
|
+
raw = parsed;
|
|
1025
|
+
}
|
|
1026
|
+
catch (error) {
|
|
1027
|
+
throw new Error(`Failed to update Jev settings at ${filePath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
if (raw.settings !== undefined && !isRecord(raw.settings)) {
|
|
1031
|
+
throw new Error(`Failed to update Jev settings at ${filePath}: settings must be an object`);
|
|
1032
|
+
}
|
|
1033
|
+
const settings = raw.settings;
|
|
1034
|
+
const currentJev = settings?.jev;
|
|
1035
|
+
if (currentJev !== undefined && currentJev !== false && !isRecord(currentJev)) {
|
|
1036
|
+
throw new Error(`Failed to update Jev settings at ${filePath}: settings.jev must be an object or false`);
|
|
1037
|
+
}
|
|
1038
|
+
const jev = isRecord(effectiveJev) ? effectiveJev : isRecord(currentJev) ? currentJev : {};
|
|
1039
|
+
const nextServers = [...new Set(allowedServers)].sort((a, b) => a.localeCompare(b));
|
|
1040
|
+
const nextJev = { ...jev, semanticSearch: true, allowedServers: nextServers };
|
|
1041
|
+
validateJevSettings(nextJev);
|
|
1042
|
+
if (isRecord(currentJev) && JSON.stringify(currentJev) === JSON.stringify(nextJev))
|
|
1043
|
+
return { path: filePath, changed: false };
|
|
1044
|
+
raw.settings = { ...settings, jev: nextJev };
|
|
1045
|
+
writeRawConfigObject(filePath, raw);
|
|
1046
|
+
return { path: filePath, changed: true };
|
|
978
1047
|
}
|
|
979
1048
|
function getServersObject(raw) {
|
|
980
1049
|
const existing = raw.mcpServers ?? raw["mcp-servers"] ?? {};
|