@sema-agent/core
Version:
Stateless, task-oriented AI agent core
29 lines (28 loc) • 1.75 kB
JavaScript
import { createLspTool, gitCheckIgnoreFilter, lspBaseOf, lspListedWithheld, lspReadGateOf, resolveLspPath } from "../lsp.js";
import { pathToUri } from "../lsp-protocol.js";
import { RosterBuilder } from "../tool-roster.js";
export function prepareLsp(input) {
const { spec, deps, executionEnv, taskRootFinal, readFace, sessionId, roster, envHandToolNames } = input;
const lspManager = spec.lspManager ?? deps.lspManager;
if (lspManager && readFace) {
roster.mount(createLspTool(lspManager, { isPathIgnored: gitCheckIgnoreFilter(executionEnv, taskRootFinal), env: executionEnv, readFace }), { source: "builtin", mountedBy: "hands" });
envHandToolNames.add("LSP");
}
const lspDiagnostics = spec.lspDiagnostics !== false && lspManager?.diagnostics !== undefined && readFace !== undefined && spec.handsReadOnly !== true
? lspManager.diagnostics
: undefined;
const lspRunIdent = sessionId;
const nudgeLspOnEdit = lspDiagnostics && readFace
? (rawPath) => {
const filePath = resolveLspPath(rawPath, lspBaseOf(readFace));
lspDiagnostics.fileEdited(lspRunIdent, pathToUri(filePath));
const gate = lspReadGateOf(executionEnv, readFace);
void lspManager
.sessionFor(filePath, undefined, executionEnv)
.then((session) => session?.notifyFileChanged?.(filePath, undefined, gate))
.catch(() => undefined);
}
: undefined;
const withheldDiagnosticsOf = lspDiagnostics && readFace ? (uris) => lspListedWithheld(executionEnv, readFace, uris) : undefined;
return { lspDiagnostics, nudgeLspOnEdit, withheldDiagnosticsOf, lspRunIdent, managerWired: lspManager !== undefined };
}