UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

29 lines (28 loc) • 1.53 kB
import { createLspTool, gitCheckIgnoreFilter, 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, handsEnabled, sessionId, handsCwdRef, roster, envHandToolNames } = input; const lspManager = spec.lspManager ?? deps.lspManager; if (lspManager) { const lspRoot = taskRootFinal; roster.mount(createLspTool(lspManager, { isPathIgnored: gitCheckIgnoreFilter(executionEnv, lspRoot), env: executionEnv }), { source: "builtin", mountedBy: "optional" }); envHandToolNames.add("LSP"); } const lspDiagnostics = spec.lspDiagnostics !== false && lspManager?.diagnostics !== undefined && handsEnabled && spec.handsReadOnly !== true ? lspManager.diagnostics : undefined; const lspRunIdent = sessionId; const nudgeLspOnEdit = lspDiagnostics ? (rawPath) => { const baseDir = handsCwdRef?.current ?? taskRootFinal; const filePath = resolveLspPath(rawPath, baseDir); lspDiagnostics.fileEdited(lspRunIdent, pathToUri(filePath)); void lspManager .sessionFor(filePath, undefined, executionEnv) .then((session) => session?.notifyFileChanged?.(filePath)) .catch(() => undefined); } : undefined; return { lspDiagnostics, nudgeLspOnEdit, lspRunIdent, managerWired: lspManager !== undefined }; }