import { t as Volume } from "./volume-C3ZPZJ79.js";
import { _ as Message, a as ActionMeta, c as AppHandle, d as InstalledApp, f as RawAppHandle, g as safeBundlePath, h as appBundleFromMemory, i as defineApp, l as AppManifest, m as Subscription, n as Transport, p as RuntimeContext, r as createClient, s as AppBundle, t as Client, u as DispatchResult } from "./sdk-eksYUmch.js";

//#region ../app/capabilities/types.d.ts
interface CapabilityCall {
  appId: string;
  capability: string;
  method: string;
  args: readonly unknown[];
  scopes: readonly string[];
  actor?: string;
}
type Emit = (event: unknown) => void;
type Unsubscribe$1 = () => void;
interface Capabilities {
  invoke(call: CapabilityCall): Promise<unknown>;
  subscribe(call: CapabilityCall, emit: Emit): Promise<Unsubscribe$1>;
}
//#endregion
//#region ../app/kernel.app.d.ts
type FetchAsset = ((url: string) => Promise<Uint8Array>) & {
  evict?: (url: string) => Promise<void>;
};
//#endregion
//#region ../app/kernel.d.ts
interface System {
  fs: Volume;
  sandbox: GetSandbox;
  clock: Clock;
  fetchAsset?: FetchAsset;
  capabilities?: Capabilities | ((kernel: Kernel) => Capabilities);
}
type GetSandbox = (input: {
  appId: string;
  code: string;
}) => Promise<Sandbox>;
type Sandbox = {
  run(message: Message, ctx: RuntimeContext): Promise<DispatchResult<unknown>>;
  initialState?(): Promise<unknown>;
  actions?(): Promise<Record<string, ActionMeta>>;
  capabilities?(): Promise<Record<string, {
    id: string;
    scopes: readonly string[];
  }>>;
  runProcedure?(name: string, params: unknown, app: RawAppHandle): Promise<unknown>;
  subscriptions?(state: unknown): Promise<Subscription[]>;
};
type Clock = object;
type AppId = string;
type Unsubscribe = () => void;
interface Kernel {
  install: (app: AppBundle) => Promise<AppId>;
  uninstall: (appId: AppId) => Promise<void>;
  subscribe: (handler: KernelEventHandler) => Unsubscribe;
  dispatch: (appId: AppId, message: Message) => Promise<unknown>;
  settled: (appId: AppId, seq: number, opts?: {
    timeout?: number;
  }) => Promise<unknown>;
  state: (appId: AppId) => Promise<unknown>;
  reload: (appId: AppId) => Promise<void>;
  actions: (appId: AppId) => Promise<Record<string, ActionMeta>>;
  app: (appId: AppId) => Promise<InstalledApp>;
  list: () => Promise<AppManifest[]>;
  dispose: () => void;
}
type AppState = object;
type KernelEventHandler = (event: Event) => void;
type Event = {
  type: 'app.update';
  appId: string;
  state: AppState;
  seq: number;
} | {
  type: 'app.error';
  appId: string;
  error: string;
} | {
  type: 'app.installed';
  appId: string;
} | {
  type: 'app.uninstalled';
  appId: string;
} | {
  type: 'system.error';
  error: string;
};
declare function kernel({
  fs,
  sandbox,
  capabilities,
  fetchAsset
}: System): Kernel;
//#endregion
//#region ../app/app-bundle.d.ts
declare function bundleFromZip(zip: Uint8Array): AppBundle;
//#endregion
//#region ../app/app-controller.d.ts
interface AppSummary {
  id: string;
  name: string;
  description?: string;
}
interface AppInspection extends AppSummary {
  state: unknown;
  actions: Record<string, ActionMeta>;
}
interface AppController {
  list(): Promise<AppSummary[]>;
  launch(id: string): Promise<AppInspection>;
  close(id?: string): Promise<void>;
  current(): Promise<AppInspection | undefined>;
  inspect(id: string): Promise<AppInspection>;
  state(id: string): Promise<unknown>;
  run(id: string, action: string, params: unknown): Promise<unknown>;
}
interface AppControllerPorts {
  windows: {
    open(id: string, name: string): void;
    close(id: string, name: string): void;
  };
  focus?: () => Promise<string | undefined>;
}
declare function createAppController(kernel: Kernel | (() => Promise<Kernel>), ports: AppControllerPorts): AppController;
//#endregion
//#region ../app/trash.d.ts
declare const DEFAULT_TRASH_RETENTION_MS: number;
declare function sweepTrash(fs: Volume, retentionMs?: number, now?: number): Promise<void>;
//#endregion
export { type ActionMeta, type AppBundle, type AppController, type AppControllerPorts, type AppHandle, type AppInspection, type AppManifest, type AppSummary, type Client, DEFAULT_TRASH_RETENTION_MS, type GetSandbox, type InstalledApp, type Kernel, type Message, type RawAppHandle, type Sandbox, type Transport, appBundleFromMemory, bundleFromZip, createAppController, createClient, defineApp, kernel, safeBundlePath, sweepTrash };
//# sourceMappingURL=index.d.ts.map