Plugins: integrate LSP tool runtime into Pi embedded runner

This commit is contained in:
Vincent Koc
2026-03-18 00:23:13 -07:00
parent 8193af6d4e
commit 80e681a60c
2 changed files with 35 additions and 8 deletions

View File

@@ -53,6 +53,7 @@ import { supportsModelTools } from "../model-tool-support.js";
import { ensureOpenClawModelsJson } from "../models-config.js";
import { createConfiguredOllamaStreamFn } from "../ollama-stream.js";
import { resolveOwnerDisplaySetting } from "../owner-display.js";
import { createBundleLspToolRuntime } from "../pi-bundle-lsp-runtime.js";
import { createBundleMcpToolRuntime } from "../pi-bundle-mcp-tools.js";
import {
ensureSessionHeader,
@@ -603,10 +604,21 @@ export async function compactEmbeddedPiSessionDirect(
reservedToolNames: tools.map((tool) => tool.name),
})
: undefined;
const effectiveTools =
bundleMcpRuntime && bundleMcpRuntime.tools.length > 0
? [...tools, ...bundleMcpRuntime.tools]
: tools;
const bundleLspRuntime = toolsEnabled
? await createBundleLspToolRuntime({
workspaceDir: effectiveWorkspace,
cfg: params.config,
reservedToolNames: [
...tools.map((tool) => tool.name),
...(bundleMcpRuntime?.tools.map((tool) => tool.name) ?? []),
],
})
: undefined;
const effectiveTools = [
...tools,
...(bundleMcpRuntime?.tools ?? []),
...(bundleLspRuntime?.tools ?? []),
];
const allowedToolNames = collectAllowedToolNames({ tools: effectiveTools });
logToolSchemasForGoogle({ tools: effectiveTools, provider });
const machineName = await getMachineDisplayName();
@@ -1092,6 +1104,7 @@ export async function compactEmbeddedPiSessionDirect(
});
session.dispose();
await bundleMcpRuntime?.dispose();
await bundleLspRuntime?.dispose();
}
} finally {
await sessionLock.release();

View File

@@ -61,6 +61,7 @@ import { supportsModelTools } from "../../model-tool-support.js";
import { createConfiguredOllamaStreamFn } from "../../ollama-stream.js";
import { createOpenAIWebSocketStreamFn, releaseWsSession } from "../../openai-ws-stream.js";
import { resolveOwnerDisplaySetting } from "../../owner-display.js";
import { createBundleLspToolRuntime } from "../../pi-bundle-lsp-runtime.js";
import { createBundleMcpToolRuntime } from "../../pi-bundle-mcp-tools.js";
import {
downgradeOpenAIFunctionCallReasoningPairs,
@@ -1570,10 +1571,22 @@ export async function runEmbeddedAttempt(
],
})
: undefined;
const effectiveTools =
bundleMcpRuntime && bundleMcpRuntime.tools.length > 0
? [...tools, ...bundleMcpRuntime.tools]
: tools;
const bundleLspRuntime = toolsEnabled
? await createBundleLspToolRuntime({
workspaceDir: effectiveWorkspace,
cfg: params.config,
reservedToolNames: [
...tools.map((tool) => tool.name),
...(clientTools?.map((tool) => tool.function.name) ?? []),
...(bundleMcpRuntime?.tools.map((tool) => tool.name) ?? []),
],
})
: undefined;
const effectiveTools = [
...tools,
...(bundleMcpRuntime?.tools ?? []),
...(bundleLspRuntime?.tools ?? []),
];
const allowedToolNames = collectAllowedToolNames({
tools: effectiveTools,
clientTools,
@@ -2913,6 +2926,7 @@ export async function runEmbeddedAttempt(
session?.dispose();
releaseWsSession(params.sessionId);
await bundleMcpRuntime?.dispose();
await bundleLspRuntime?.dispose();
await sessionLock.release();
}
} finally {