import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js"; import type { DrizzleExecutor } from "../drizzle.js"; import type { MutationHint } from "../chat/types.js"; import type { PubSub } from "../realtime/index.js"; import type { WebhookUrlPolicy } from "../integrations/ssrf.js"; import type { WebhookTransport } from "../integrations/types.js"; import type { TokenService } from "../auth/tokens.js"; import type { DocumentHostSummary, DocumentSnapshot } from "../document/types.js"; import { type ChatMetadataSummary } from "../chat/chatUpdateMetadata.js"; import type { WorkspaceService } from "../workspace/index.js"; import { type PluginButtonControl } from "./impl/surfaceDefinition.js"; import type { PluginCatalog } from "./catalog.js"; import type { PluginPackageStore } from "./packageStore.js"; import type { PluginPackageLinkDownloader } from "./packageLinkDownloader.js"; import type { PluginMcpRuntime } from "./runtime.js"; import type { PluginSecretProtector } from "./secrets.js"; import { type PluginArchiveDownloader } from "./source.js"; import { type PluginFunctionDefinition, type PluginFunctionResult, type PluginAgentCallContext, type PluginCallContext, type PluginHostPermission, type PluginInstallationSummary, type PreparedPluginSummary, type PluginManagementRequestSummary, type PluginSkillDefinition, type PluginUserCapability, type PluginUpdateCheck, type PluginUpdateResult } from "./types.js"; interface PluginAgentRuntime { modelRequireAvailable(modelId: string): Promise; prepareTurns(input: { actorUserId: string; agentUserIds: readonly string[]; chatId: string; }): Promise>; startTurn(chatId: string): void; } /** Coordinates durable plugin installs with asynchronous container preparation, MCP health probes, restart recovery, and local connection creation. */ export declare class PluginService { private readonly executor; private readonly pubsub; private readonly catalog; private readonly packages; private readonly packageLinks; private readonly secrets; private readonly runtime; private readonly tokens; private readonly urlPolicy; private readonly remoteTransport; private readonly hostApiUrl; private readonly archiveDownloader; private readonly workspaces; private readonly onError; private readonly activations; private readonly commandHandles; private readonly preparations; private readonly activeMcpAppOperationsByActor; private readonly activeFunctionDocumentWriteWaits; private closed; constructor(executor: DrizzleExecutor, pubsub: PubSub, catalog: PluginCatalog, packages: PluginPackageStore, packageLinks: PluginPackageLinkDownloader, secrets: PluginSecretProtector, runtime: PluginMcpRuntime, tokens: TokenService, urlPolicy: WebhookUrlPolicy, remoteTransport: WebhookTransport, hostApiUrl: string, archiveDownloader: PluginArchiveDownloader, workspaces: WorkspaceService, onError: (error: unknown) => void); start(): Promise; install(input: { actorUserId?: string; actorInstallationId?: string; shortName: string; variables: Readonly>; permissions: readonly PluginHostPermission[]; containerImageId?: string; }): Promise; installArchive(input: { actorUserId: string; archive: Buffer; variables: Readonly>; containerImageId?: string; }): Promise; installLink(input: { actorUserId: string; url: string; variables: Readonly>; containerImageId?: string; }): Promise; private installPackage; prepareUpload(actorUserId: string, archive: Buffer, onProgress: (stage: string, detail: string, bytes?: { receivedBytes: number; totalBytes?: number; }) => void): Promise<{ selectionRequired: false; candidates: PreparedPluginSummary[]; }>; prepareRemote(actorUserId: string, input: { kind: "github" | "zip_url"; url: string; }, onProgress: (stage: string, detail: string, bytes?: { receivedBytes: number; totalBytes?: number; }) => void, signal?: AbortSignal): Promise<{ selectionRequired: boolean; candidates: PreparedPluginSummary[]; }>; installPrepared(input: { actorUserId: string; preparedToken: string; variables: Readonly>; permissions: readonly PluginHostPermission[]; containerImageId?: string; }): Promise; uninstall(actorUserId: string, pluginId: string): Promise<{ installationIds: string[]; pluginId: string; }>; checkForUpdate(actorUserId: string, installationId: string, onProgress: (stage: string, detail: string, bytes?: { receivedBytes: number; totalBytes?: number; }) => void, signal?: AbortSignal): Promise; updatePlugin(actorUserId: string, installationId: string, onProgress: (stage: string, detail: string, bytes?: { receivedBytes: number; totalBytes?: number; }) => void, signal?: AbortSignal): Promise; updatePermissions(input: { actorUserId: string; installationId: string; permissions: readonly PluginHostPermission[]; }): Promise; uninstallInstallation(input: { installationId: string; actorUserId?: string; actorInstallationId?: string; }): Promise; retryInstallation(input: { actorUserId: string; installationId: string; }): Promise; private downloadPackage; private updatePackageResolve; private prepareRequestedArchive; image(actorUserId: string, pluginId: string): Promise<{ body: Buffer; contentType: string; checksumSha256: string; }>; requestInstallLink(input: { requesterInstallationId: string; agentCall: PluginAgentCallContext; url: string; reason?: string; }): Promise; requestUninstall(input: { requesterInstallationId: string; agentCall: PluginAgentCallContext; targetInstallationId: string; reason?: string; }): Promise; listManagementRequests(actorUserId: string, chatId: string): Promise; listDocumentsForHost(actorUserId: string, chatId: string): Promise; getDocumentForHost(actorUserId: string, chatId: string, documentId: string): Promise<{ document: DocumentHostSummary; snapshot: DocumentSnapshot; }>; documentCreateForHost(input: { actorUserId: string; agentUserId: string; chatId: string; title: string; initialUpdate?: string; }): Promise; requestDocumentWriteForHost(input: { actorUserId: string; agentUserId: string; requesterInstallationId: string; sessionId: string; callId: string; chatId: string; documentId: string; clientUpdateId: string; baseSequence: string; updates: readonly unknown[]; }, signal?: AbortSignal): Promise<{ status: "approved"; requestId: string; documentId: string; acceptedSequence: string; } | { status: "denied" | "failed"; requestId: string; documentId: string; message: string; }>; managementRequestImage(input: { actorUserId: string; chatId: string; requestId: string; }): Promise; approveManagementRequest(input: { actorUserId: string; chatId: string; requestId: string; }): Promise; denyManagementRequest(input: { actorUserId: string; chatId: string; requestId: string; action: "install" | "uninstall"; }): Promise; approveUninstallManagementRequest(input: { actorUserId: string; chatId: string; requestId: string; }): Promise; openLocal(installationId: string): Promise; listFunctions(signal?: AbortSignal): Promise; listSkills(signal?: AbortSignal): Promise; readSkill(skill: PluginSkillDefinition, signal?: AbortSignal): Promise; callFunction(functionName: string, args: unknown, context: PluginCallContext, signal?: AbortSignal): Promise; private callFunctionWithSignal; getMcpApp(input: { actorUserId: string; assistantMessageId: string; callId: string; signal?: AbortSignal; }): Promise<{ app: { callId: string; toolName: string; resourceUri: string; arguments: Record; status: "completed" | "failed" | "in_progress"; result?: Record | undefined; }; resource: { html: string; contentHashSha256: string; meta: { ui: { csp?: { connectDomains?: string[]; resourceDomains?: string[]; frameDomains?: string[]; baseUriDomains?: string[]; } | undefined; permissions?: Record> | undefined; domain?: string | undefined; prefersBorder?: boolean | undefined; }; }; }; }>; callMcpAppTool(input: { actorUserId: string; assistantMessageId: string; callId: string; name: string; arguments: Readonly>; signal?: AbortSignal; }): Promise<{ [x: string]: unknown; content: ({ type: "text"; text: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { type: "image"; data: string; mimeType: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { type: "audio"; data: string; mimeType: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { type: "resource"; resource: { uri: string; text: string; mimeType?: string | undefined; _meta?: Record | undefined; } | { uri: string; blob: string; mimeType?: string | undefined; _meta?: Record | undefined; }; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { uri: string; name: string; type: "resource_link"; description?: string | undefined; mimeType?: string | undefined; size?: number | undefined; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: { [x: string]: unknown; } | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; theme?: "light" | "dark" | undefined; }[] | undefined; title?: string | undefined; })[]; _meta?: { [x: string]: unknown; progressToken?: string | number | undefined; "io.modelcontextprotocol/related-task"?: { taskId: string; } | undefined; } | undefined; structuredContent?: Record | undefined; isError?: boolean | undefined; } | { [x: string]: unknown; toolResult: unknown; _meta?: { [x: string]: unknown; progressToken?: string | number | undefined; "io.modelcontextprotocol/related-task"?: { taskId: string; } | undefined; } | undefined; }>; readMcpAppResource(input: { actorUserId: string; assistantMessageId: string; callId: string; uri: string; signal?: AbortSignal; }): Promise<{ [x: string]: unknown; contents: ({ uri: string; text: string; mimeType?: string | undefined; _meta?: Record | undefined; } | { uri: string; blob: string; mimeType?: string | undefined; _meta?: Record | undefined; })[]; _meta?: { [x: string]: unknown; progressToken?: string | number | undefined; "io.modelcontextprotocol/related-task"?: { taskId: string; } | undefined; } | undefined; }>; hostAppInstancePut(input: { runtimeToken: string; viewerToken?: string; chatToken?: string; definition: unknown; }): Promise<{ created: boolean; id: string; revision: number; dataRevision: number; hint: MutationHint; sync: MutationHint; }>; hostAppInstanceContextUpdate(input: { runtimeToken: string; viewerToken?: string; chatToken?: string; instanceKey: unknown; context: unknown; }): Promise<{ dataRevision: number; hint: MutationHint; id: string; sync: MutationHint; }>; hostAppInstanceDelete(input: { runtimeToken: string; viewerToken?: string; chatToken?: string; instanceKey: unknown; }): Promise<{ deleted: boolean; hint?: MutationHint; sync?: MutationHint | undefined; }>; hostContributionPut(input: { runtimeToken: string; viewerToken?: string; chatToken?: string; definition: unknown; }): Promise<{ created: boolean; id: string; revision: number; hint: MutationHint; sync: MutationHint; }>; hostContributionDelete(input: { runtimeToken: string; viewerToken?: string; chatToken?: string; externalKey: unknown; }): Promise<{ deleted: boolean; hint?: MutationHint; sync?: MutationHint | undefined; }>; listAppInstances(viewerUserId: string): Promise; getAppInstance(viewerUserId: string, instanceId: string): Promise<{ app: import("./impl/surfaceProjection.js").PluginAppInstanceSummary; resource: { html: string; contentHashSha256: string; csp?: { connectDomains?: string[]; resourceDomains?: string[]; frameDomains?: string[]; baseUriDomains?: string[]; } | undefined; permissions?: Record> | undefined; domain?: string | undefined; prefersBorder?: boolean | undefined; }; hostContext: { "happy2/instance": { id: string; key: string; context: import("./impl/surfaceDefinition.js").JsonObject; dataRevision: number; definitionRevision: number; }; }; }>; callAppInstanceTool(input: { viewerUserId: string; instanceId: string; toolName: string; arguments: Readonly>; signal?: AbortSignal; }): Promise<{ [x: string]: unknown; content: ({ type: "text"; text: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { type: "image"; data: string; mimeType: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { type: "audio"; data: string; mimeType: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { type: "resource"; resource: { uri: string; text: string; mimeType?: string | undefined; _meta?: Record | undefined; } | { uri: string; blob: string; mimeType?: string | undefined; _meta?: Record | undefined; }; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { uri: string; name: string; type: "resource_link"; description?: string | undefined; mimeType?: string | undefined; size?: number | undefined; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: { [x: string]: unknown; } | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; theme?: "light" | "dark" | undefined; }[] | undefined; title?: string | undefined; })[]; _meta?: { [x: string]: unknown; progressToken?: string | number | undefined; "io.modelcontextprotocol/related-task"?: { taskId: string; } | undefined; } | undefined; structuredContent?: Record | undefined; isError?: boolean | undefined; } | { [x: string]: unknown; toolResult: unknown; _meta?: { [x: string]: unknown; progressToken?: string | number | undefined; "io.modelcontextprotocol/related-task"?: { taskId: string; } | undefined; } | undefined; }>; readAppInstanceResource(input: { viewerUserId: string; instanceId: string; uri: string; signal?: AbortSignal; }): Promise<{ [x: string]: unknown; contents: ({ uri: string; text: string; mimeType?: string | undefined; _meta?: Record | undefined; } | { uri: string; blob: string; mimeType?: string | undefined; _meta?: Record | undefined; })[]; _meta?: { [x: string]: unknown; progressToken?: string | number | undefined; "io.modelcontextprotocol/related-task"?: { taskId: string; } | undefined; } | undefined; }>; listContributions(input: { viewerUserId: string; chatId?: string; }): Promise; invokeContribution(input: { viewerUserId: string; contributionId: string; actionId: string; value?: unknown; chatId?: string; messageId?: string; signal?: AbortSignal; }): Promise<{ result: { [x: string]: unknown; content: ({ type: "text"; text: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { type: "image"; data: string; mimeType: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { type: "audio"; data: string; mimeType: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { type: "resource"; resource: { uri: string; text: string; mimeType?: string | undefined; _meta?: Record | undefined; } | { uri: string; blob: string; mimeType?: string | undefined; _meta?: Record | undefined; }; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: Record | undefined; } | { uri: string; name: string; type: "resource_link"; description?: string | undefined; mimeType?: string | undefined; size?: number | undefined; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: { [x: string]: unknown; } | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; theme?: "light" | "dark" | undefined; }[] | undefined; title?: string | undefined; })[]; _meta?: { [x: string]: unknown; progressToken?: string | number | undefined; "io.modelcontextprotocol/related-task"?: { taskId: string; } | undefined; } | undefined; structuredContent?: Record | undefined; isError?: boolean | undefined; } | { [x: string]: unknown; toolResult: unknown; _meta?: { [x: string]: unknown; progressToken?: string | number | undefined; "io.modelcontextprotocol/related-task"?: { taskId: string; } | undefined; } | undefined; }; openApp?: { instanceId: string; presentation: "primary" | "modal" | "fullscreen"; } | undefined; }>; resolveContributionMenu(input: { viewerUserId: string; contributionId: string; chatId?: string; messageId?: string; signal?: AbortSignal; }): Promise<{ items: PluginButtonControl[]; revision: number; }>; updateAppPresentation(viewerUserId: string, input: { instanceId: unknown; hidden: unknown; position?: unknown; }): Promise<{ app: import("./impl/surfaceProjection.js").PluginAppInstanceSummary; sync: MutationHint; }>; getUiAsset(viewerUserId: string, installationId: string, assetId: string): Promise<{ body: Buffer; contentType: string; checksumSha256: string; }>; private authorizeSurfaceHost; private contributionContext; private contributionAction; private resolveMenuItems; private contributionAppOpen; private callSurfaceTool; private surfaceCallMeta; private skillSources; authorizeHost(token: string, permission: PluginHostPermission): Promise>>; private authorizeHostPermissions; chatUpdate(runtimeToken: string, chatToken: string, input: { title?: string; description?: string | null; }): Promise<{ chat: ChatMetadataSummary; sync: MutationHint; }>; chatArchive(runtimeToken: string, chatToken: string): Promise<{ chat: import("../chat/types.js").ChatSummary; sync: MutationHint; }>; messageSend(runtimeToken: string, chatToken: string, input: { text: string; audience: "people" | "agents"; idempotencyKey?: string; }, agents?: PluginAgentRuntime): Promise<{ message: import("../chat/types.js").MessageSummary; token: string; sync: MutationHint; }>; messageHistory(runtimeToken: string, chatToken: string, input: { beforeSequence?: number; afterSequence?: number; limit: number; }): Promise<{ messages: import("../chat/types.js").MessageSummary[]; chatPts: string; hasMore: boolean; }>; messageRead(runtimeToken: string, messageId: string, messageToken: string): Promise<{ message: import("../chat/types.js").MessageSummary; }>; messageDelete(runtimeToken: string, messageId: string, messageToken: string): Promise<{ message: import("../chat/types.js").MessageSummary; sync: MutationHint; }>; messageReactionSet(runtimeToken: string, messageId: string, messageToken: string, input: { emoji?: string; customEmojiId?: string; active: boolean; }): Promise<{ message: import("../chat/types.js").MessageSummary; sync: MutationHint; }>; search(runtimeToken: string, chatToken: string, input: { query: string; types: readonly ("user" | "message" | "chat")[]; cursor?: string; limit: number; }): Promise<{ nextCursor?: string; results: ({ type: "user"; score: number; user: import("../chat/types.js").UserSummary; token: string; } | { type: "channel"; score: number; channel: import("../chat/types.js").ChatSummary; token: string; } | { type: "message"; score: number; message: import("../chat/types.js").MessageSummary; token: string; })[]; }>; workspaceFileRead(runtimeToken: string, chatToken: string, path: string): Promise<{ file: import("../workspace/types.js").WorkspaceHashedTextFile; }>; workspaceFileWrite(runtimeToken: string, chatToken: string, input: { path: string; expectedHash: string | null; content: string; }): Promise<{ file: import("../workspace/types.js").WorkspaceHashedFileWriteResult; }>; workspaceCommandRun(runtimeToken: string, chatToken: string, input: { command: string; environment: Readonly>; }): Promise<{ command: import("../workspace/types.js").WorkspaceCommandResult; }>; channelMembersUpdate(runtimeToken: string, chatToken: string, input: { add: readonly PluginUserCapability[]; remove: readonly PluginUserCapability[]; }): Promise<{ addedUserIds: string[]; chatId: string; removedUserIds: string[]; sync: MutationHint[]; }>; projectCreate(runtimeToken: string, chatToken: string, input: { name: string; description?: string; owner?: PluginUserCapability; people: readonly PluginUserCapability[]; channels: readonly { visibility: "public" | "private"; name: string; description?: string; }[]; idempotencyKey?: string; }): Promise<{ project: import("../project/types.js").ProjectSummary; channels: { chat: import("../chat/types.js").ChatSummary; token: string; }[]; sync: MutationHint[]; }>; channelCreate(runtimeToken: string, chatToken: string, input: { visibility: "public" | "private"; name: string; description?: string; idempotencyKey?: string; members: readonly PluginUserCapability[]; initialMessage?: { audience: "agents" | "people"; text: string; }; }, agents?: PluginAgentRuntime): Promise<{ chat: import("../chat/types.js").ChatSummary; token: string; initialMessage?: import("../chat/types.js").MessageSummary | undefined; sync: MutationHint[]; }>; channelCreateChild(runtimeToken: string, chatToken: string, input: { name: string; description?: string; agentModelId?: string; initialMessage?: { audience: "agents" | "people"; text: string; }; }, agents?: PluginAgentRuntime): Promise<{ chat: import("../chat/types.js").ChatSummary; token: string; initialMessage?: import("../chat/types.js").MessageSummary | undefined; sync: MutationHint[]; }>; /** Authorizes one installation-bound chat capability for a dedicated host API route. */ authorizeChatHost(runtimeToken: string, chatToken: string, permissions: PluginHostPermission | readonly PluginHostPermission[]): Promise; private authorizeChat; private authorizeMessage; private authorizeUsers; private publishHints; close(): Promise; private prepareArchive; private preparationTake; private preparationsExpire; private activate; private stopActivation; private withClient; private runActivation; private probeLocal; private discoverTools; private probeRemote; private withMcpAppOperation; private status; private publish; private closeCommand; private monitorCommand; private runtimeEnvironment; private pluginRuntimeToken; } export {}; //# sourceMappingURL=service.d.ts.map