/** Notes a tool answer carries, read from the state of the server. */ import { configDisagrees } from '../config-pin.js'; import type { RuntimeEndpoint } from '../runtime-client.js'; import type { GodotServer } from '../server.js'; import { runtimeMismatch, SERVER_VERSION } from '../server-version.js'; import { installedAddonVersion, installedRuntimeDigest, shippedRuntimeDigest } from '../setup.js'; /** [param lists] without the ones that are empty, so an answer holds no field with nothing in it. */ export function nonEmpty>(lists: T): Partial { const kept: Partial = { ...lists }; for (const key in kept) { if (Object.hasOwn(kept, key) && kept[key]?.length === 0) { delete kept[key]; } } return kept; } /** * What the project's addons say they are, when that is not what this server is. * * Read from disk rather than from the editor, so it is true whether or not an editor is open, * and cheap enough to ask on the same schedule as the update notice. Only a server that knows * its project can ask at all, which is the same thing that lets it announce its bridge. */ export function projectHasMovedOn(server: GodotServer): string | null { if (server.ownProject === null) { return null; } const installed = installedAddonVersion(server.ownProject); return installed === null || installed === SERVER_VERSION ? null : installed; } /** What to do about the runtime addon [param endpoint] loaded, or undefined when it is this server's. */ export function runtimeStaleNote(endpoint: RuntimeEndpoint): string | undefined { const project = endpoint.project.path; return runtimeMismatch( endpoint.pid, endpoint.addon, SERVER_VERSION, shippedRuntimeDigest(), project === '' ? undefined : installedRuntimeDigest(project), project, ); } /** What the project's own MCP config asks for, when it is not what is answering. */ export function configDisagreement(server: GodotServer): string | null { return server.ownProject === null ? null : configDisagrees(server.ownProject, SERVER_VERSION); } /** [param list] itself, or undefined when it is empty, so an answer leaves the field out. */ export function orNothing(list: T[]): T[] | undefined { return list.length > 0 ? list : undefined; }