import { PilotSwarmClient, WebPilotSwarmManagementClient, ModelProviderRegistry, loadAgentFiles, type SharedManagementSurface, type FactStore, type EnhancedFactStore, type GraphStore } from "pilotswarm-sdk"; import { ApiClient } from "pilotswarm-sdk/api"; type AgentConfig = ReturnType[number]; /** * The web-mode handles, present or absent TOGETHER. * * `api` and `web` are the same deployment connection seen two ways, so a * context can never hold one without the other. Expressing that as a union * rather than two independent nullable fields means `if (ctx.api)` narrows * `ctx.web` to non-null for free — no `!` assertions — and a future edit that * sets one without the other stops compiling instead of crashing at runtime. */ type WebHandles = { /** * Web API client. Backs the fact/graph stores and binary artifact * streaming; operation calls go through `web.ops` instead. */ api: ApiClient; /** * The honestly-typed web client — the same instance as `mgmt`. * Carries `web.ops`, the generated wire-shaped method per * protocol-table operation, which is how tools reach operations the * ergonomic surface does not wrap. */ web: WebPilotSwarmManagementClient; } | { api: null; web: null; }; export type ServerContext = ServerContextBase & WebHandles; interface ServerContextBase { client: PilotSwarmClient; /** * The management surface shared by both modes — every method works (or * refuses with a typed WEB_MODE_UNSUPPORTED error) whichever mode this * process runs in. No casts anywhere on this path. */ mgmt: SharedManagementSurface; facts: FactStore; /** * The same store as `facts`, narrowed once at boot via * `isEnhancedFactStore` — null when the provider has no search/embedder * surface. Enhanced tools register iff non-null (per-boot gate, never * sniffed per call). */ enhancedFacts: EnhancedFactStore | null; /** * Optional graph store — a SEPARATE injection (enhancedfactstore 07 D2), * never derived from the fact store. Web mode: capability-probed via * `createWebGraphStore`. Direct mode: constructed from HORIZON_* env. * Graph tools register iff non-null. */ graph: GraphStore | null; /** * Whether this process's credential carries the deployment's admin role. * Web mode: `role === "admin" || role === "anonymous"` from /auth/me * (mirrors the server's isAdminAuth). Direct mode: always true — a * process holding DATABASE_URL is definitionally privileged. * [admin]-tagged tools register iff true. */ admin: boolean; /** Agent-package management tool tier ("off" | "read" | "full"). */ agentMgmt: "off" | "read" | "full"; /** * The caller's normalized role (`admin` | `user` | `anonymous` | null), * and the deployment's ownership/visibility posture. Web mode reads these * from /auth/me and /bootstrap; direct mode is privileged (`admin`) with * enforcement off. Surfaced by get_capabilities so an agent can explain a * refusal instead of retrying blindly. */ role: string | null; authz: { ownershipEnforced: boolean; defaultVisibility: string; systemVisibility: string; adminScope?: string; policyVersion?: number; }; /** True when running over the Web API (`--api-url`); false in direct mode. */ webMode: boolean; models: ModelProviderRegistry | null; skills: Array<{ name: string; description: string; prompt: string; }>; /** * Agent definitions visible to this MCP server. Web mode: the * deployment's creatable-agent catalog (`GET /api/v1/agents`) — the * authoritative set `createSessionForAgent` will accept. Direct mode: * loaded from `/agents/*.agent.md` for each configured plugin * dir (may diverge from any particular worker's catalog). */ registeredAgents: AgentConfig[]; /** * Set of agentIds for sessions where `isSystem === true`, derived from * `mgmt.listSessions()` at startup. Used by resource registrations and * subscription filters that need to enumerate system agents without * hardcoding their names. */ systemAgentIds: Set; /** * Re-query the management API to refresh `systemAgentIds`. Tool/resource * handlers may call this when they suspect the list has drifted (e.g. a * new system agent was registered after server startup). Cheap to call — * shares the same listSessions() call already used elsewhere. */ refreshSystemAgentIds(): Promise; } export interface CreateContextOptions { /** Direct database URL (internal/trusted placement). Mutually exclusive with apiUrl. */ store?: string; /** Web API base URL (supported remote mode). Mutually exclusive with store. */ apiUrl?: string; modelProvidersPath?: string; pluginDirs?: string[]; /** * Agent-package management surface (docs/proposals/agent-packages.md): * "off" registers nothing, "read" only listing/inspection, "full" (the * default) adds publish/sync/scope/pin/delete. */ agentMgmt?: "off" | "read" | "full"; } export declare function createContext(opts: CreateContextOptions): Promise; export {}; //# sourceMappingURL=context.d.ts.map