import type { AuthScope } from './token-registry.js'; import type { DatabaseHostConsole } from '@zhin.js/plugin-runtime'; import { type ConsoleConfigSource, type ConsoleEndpointSummary } from '@zhin.js/console-protocol'; import { type ConsoleRpcExtendedCtx } from './console-rpc-extended/index.js'; /** * Console RPC 请求结构:未锚定 endpoint 的会话地址(结构对齐 * `Omit`;host/http 架构分层不允许依赖 * `@zhin.js/im-contract`,故本地结构化声明,endpoint 由 ImRuntime 锚定)。 */ export interface ConversationAddress { readonly kind: 'private' | 'group' | 'channel'; readonly id: string; readonly parent?: Readonly<{ readonly kind: 'group' | 'channel'; readonly id: string; }>; readonly threadId?: string; } export type RuntimeConsoleRpcMessage = { readonly type?: unknown; readonly requestId?: unknown; readonly [key: string]: unknown; }; export type RuntimeConsoleRpcReply = Record; export interface PluginInstallPlan { readonly packageName: string; readonly instanceKey: string; readonly alreadyDeclared: boolean; readonly alreadyInstalled: boolean; readonly restartRequired: boolean; readonly changes: Readonly<{ readonly packageManifest: 'unchanged' | 'add-plugin'; readonly config: 'unchanged' | 'create-entry' | 'schema-required'; }>; readonly warnings: readonly string[]; } export interface PluginUninstallPlan { readonly packageName: string; readonly instanceKey: string; readonly installed: boolean; readonly declared: boolean; readonly hasConfig: boolean; readonly restartRequired: boolean; } export interface PluginUpdatePlan { readonly packageName: string; readonly instanceKey: string; readonly currentVersion: string | null; readonly targetVersion: string; readonly installed: boolean; readonly declared: boolean; readonly alreadyCurrent: boolean; readonly restartRequired: boolean; } export interface PluginManagementPort { planInstall(packageName: string): Promise; install?(packageName: string, expectedRevision?: string): Promise>; planUninstall?(packageName: string): Promise; uninstall?(packageName: string, expectedRevision?: string): Promise>; planUpdate?(packageName: string, targetVersion: string): Promise; update?(packageName: string, targetVersion: string, expectedRevision?: string): Promise>; } export interface PluginConfigValidation { readonly valid: boolean; readonly errors: readonly { readonly path: string; readonly message: string; }[]; readonly missingEnv: readonly string[]; } export type RuntimeConsolePage = { readonly id: string; readonly localName: string; readonly title: string; readonly route: string; readonly module: string; readonly order: number; readonly hash: string; }; export type RuntimeConsoleRpcContext = { readonly authScope: AuthScope; listPages(): Promise; /** Optional project config accessors for read-only config RPCs. */ readConfigSource?(): Promise; readConfigDocument?(): Promise>; /** Full-scope, revision-checked replacement of the active Root config source. */ replaceConfigSource?(source: string, expectedRevision: string): Promise<{ readonly revision: string; readonly restartRequired: boolean; }>; /** * Full-scope write: set `document[pluginName] = data` and persist. * Returns whether a process restart is required. */ setConfigKey?(pluginName: string, data: unknown): Promise<{ restartRequired: boolean; }>; /** Persist a declared child Plugin lifecycle state. Takes effect after restart. */ setPluginEnabled?(instanceKey: string, enabled: boolean): Promise>; /** Read-only install planning shared by Console Web and CLI surfaces. */ pluginManagement?: PluginManagementPort; validatePluginConfig?(pluginName: string, data: unknown): Promise; diagnosePlugin?(pluginName: string): Promise; /** Atomic, revision-checked runtime Workroom Catalog read/write. */ readWorkroomCatalog?(): Promise>; workrooms: Readonly>; revision: string; /** Principal bound to the authenticated Console token, never caller supplied. */ principalId?: string; }>>; setWorkroomCatalog?(workrooms: unknown, expectedRevision: string): Promise>; /** Project file manager (allowlisted paths under project root). */ listProjectFiles?(): Promise; readProjectFile?(filePath: string): Promise<{ content: string; size: number; }>; saveProjectFile?(filePath: string, content: string): Promise; listEnvFiles?(): Promise; readEnvFile?(filename: string): Promise; writeEnvFile?(filename: string, content: string): Promise; /** Optional schema accessors (plugin schema.json / Runtime schema registry). */ getSchema?(pluginName?: string): Promise; getAllSchemas?(): Promise>; /** Optional Adapter endpoint Console surface (Sandbox / Remote Console). */ listEndpoints?(): Promise; getEndpoint?(adapter: string, endpointKey: string): Promise; sendEndpointMessage?(input: RuntimeEndpointSendInput): Promise<{ messageId: string; }>; /** Optional Database host surface (CLI wires DatabaseHost from plugin-runtime). */ dbInfo?(): Promise | RuntimeDatabaseInfo; dbTables?(): Promise | readonly string[]; database?: DatabaseHostConsole; /** Full-scope: request process restart (CLI daemon watches exit code). */ requestRestart?(): Promise | void; /** * Optional console event sink (`/api/events` SSE fan-out). Called after * successful mutations: `config:updated` / `system:restarting`. */ publishEvent?(type: string, data: unknown): void; /** Extended RPC surface(cron/schedule、endpoint 社交/inbox),fullScope 由 authScope 推导。 */ extended?: Omit; }; export type RuntimeDatabaseInfo = { readonly dialect: string | null; readonly connected: boolean; readonly tables: number; }; export type RuntimeEndpointSendInput = { readonly adapter: string; readonly endpointKey: string; readonly conversation: ConversationAddress; readonly content: unknown; }; export declare function pickRpcReply(message: RuntimeConsoleRpcMessage, payloads: readonly RuntimeConsoleRpcReply[]): RuntimeConsoleRpcReply | null; export declare function dispatchRuntimeConsoleRpc(message: RuntimeConsoleRpcMessage, ctx: RuntimeConsoleRpcContext): Promise; /** HTTP paths under apiBase that demo scope may call (ADR 0016). */ export declare function isDemoHttpAllowed(method: string, pathname: string, apiBase: string): boolean;