@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
73 lines (72 loc) • 4.23 kB
TypeScript
/**
* Trust for a project's `.mcp-config.json`.
*
* A directory is not a trust boundary. Every tool-enabled `generate()` and
* `stream()` used to load `<cwd>/.mcp-config.json` and start what it named,
* so cloning a repository and running anything built on this SDK inside it
* ran that repository's commands with the user's credentials. This module
* is the one place that decides whether a project config may be loaded:
*
* - **SDK**: never implicitly. `new NeuroLink({ mcp: { configPath } })` names
* a file; `mcp: { trustProjectConfig: true }` opts into the working
* directory. `ProviderRegistry.setOptions({ enableManualMCP: true })` is the
* legacy opt-in and is honoured for the first time.
* - **CLI**: the entry point hashes the file, compares it with the accepted
* hashes in `~/.neurolink/trusted-mcp-configs.json`, and registers a hook
* here. The hook runs only when a `NeuroLink` instance is about to load
* the file, so `neurolink --version` in a hostile directory costs nothing
* and `neurolink generate` there is refused.
*/
import type { ProjectMcpConfigPathResolution, ProjectMcpConfigSummary, ProjectMcpConfigTrustHook, ProjectMcpConfigTrustStatus, ProjectMcpConfigTrustStore } from "../types/index.js";
export declare const PROJECT_MCP_CONFIG_FILENAME = ".mcp-config.json";
export declare const TRUSTED_MCP_CONFIGS_FILENAME = "trusted-mcp-configs.json";
/** `1` trusts the working directory's config for this run; `0` ignores it. */
export declare const TRUST_MCP_CONFIG_ENV = "NEUROLINK_TRUST_MCP_CONFIG";
/** CLI flag with the same meaning as `NEUROLINK_TRUST_MCP_CONFIG=1`. */
export declare const TRUST_MCP_CONFIG_FLAG = "--trust-mcp-config";
export declare function getTrustedMcpConfigStorePath(): string;
export declare function hashProjectMcpConfig(content: string | Buffer): string;
/**
* Read the store. A missing, unreadable or malformed file reads as empty:
* the only consequence is that every config has to be accepted again, which
* is the safe direction.
*/
export declare function readProjectMcpConfigTrustStore(storePath?: string): ProjectMcpConfigTrustStore;
export declare function getProjectMcpConfigTrustStatus(configPath: string, sha256: string, storePath?: string): ProjectMcpConfigTrustStatus;
/**
* Record an acceptance. The store directory is created `0700`, the file is
* written `0600` through a uniquely named temporary file opened with `wx`
* and renamed into place, so a concurrent writer or a pre-planted symlink
* cannot redirect the write or leave a torn file.
*/
export declare function recordTrustedProjectMcpConfig(configPath: string, sha256: string, storePath?: string): void;
/**
* Read and describe a project config without evaluating any of it. Values
* under `env` and `headers` are never included — a summary is printed to a
* terminal and must not echo a secret the file happens to inline.
*/
export declare function summarizeProjectMcpConfig(configPath: string): ProjectMcpConfigSummary;
/** Render a summary as the lines the CLI prints before asking for trust. */
export declare function formatProjectMcpConfigSummary(summary: ProjectMcpConfigSummary): string[];
/**
* Register (or clear, with `null`) the process-wide hook the CLI uses to hand
* its trust decision to every `NeuroLink` instance built afterwards. SDK
* hosts do not need this: they pass `mcp.configPath` or
* `mcp.trustProjectConfig` to the constructor instead.
*/
export declare function setProjectMcpConfigTrustHook(hook: ProjectMcpConfigTrustHook | null): void;
export declare function getProjectMcpConfigTrustHook(): ProjectMcpConfigTrustHook | null;
/**
* Decide which project config, if any, a `NeuroLink` instance loads.
*
* Precedence: an explicit `configPath`; `trustProjectConfig` for
* `<cwd>/.mcp-config.json`; the CLI's registered hook; the legacy
* `enableManualMCP` registry option. With none of them the answer is `null`
* and nothing is read from the working directory — the SDK default.
*/
export declare function resolveProjectMcpConfigPath(options: {
cwd?: string;
configPath?: string;
trustProjectConfig?: boolean;
enableManualMCP?: boolean;
}): Promise<ProjectMcpConfigPathResolution | null>;