import { Hono, type Env as HonoEnv, type Handler, type MiddlewareHandler } from "hono"; import type { AnyHandler, RuntimePlan, AuditSink } from "@aotter/mantle-runtime"; import type { PublicPathResolver, TemplateRegistry } from "@aotter/mantle-web"; import { createRuntimeClient } from "@aotter/mantle-web/client-runtime"; import type { SiteDefaults } from "@aotter/mantle-spec"; import { type ConventionalAuthEnv } from "../auth/conventionalAuth.js"; import type { MantleAuth as Auth } from "@aotter/mantle-auth"; import { type MantleWorkerBindings } from "../bindings/conventionalBindings.js"; import { type CloudflareMantleRuntime, type MantleRuntimeRef } from "../mount/bootRuntimeOnce.js"; import type { MantleCloudflareConfig } from "../mount/cmsConfig.js"; import { type ConsumerCredentialResolver } from "../mount/resolveCaller.js"; /** Fixed namespaces owned by Mantle's standard Worker surfaces. */ export declare const MANTLE_RESERVED_PATH_PREFIXES: readonly ["/admin", "/_mantle", "/api/auth", "/api/views", "/oauth", "/mcp"]; /** OAuth discovery paths share this prefix but not a slash boundary. */ export declare const MANTLE_RESERVED_WELL_KNOWN_PREFIX: "/.well-known/oauth"; /** Exact registrations extensions may not claim. */ export declare const MANTLE_RESERVED_EXACT_PATHS: readonly ["*", "/*"]; type ReservedPrefix = (typeof MANTLE_RESERVED_PATH_PREFIXES)[number]; type ReservedExact = (typeof MANTLE_RESERVED_EXACT_PATHS)[number]; type ReservedPath = ReservedExact | ReservedPrefix | `${ReservedPrefix}${"/" | "*" | "{"}${string}` | `${typeof MANTLE_RESERVED_WELL_KNOWN_PREFIX}${string}`; /** Static literals under Core-owned paths fail during consumer typecheck/build. */ export type MantleExtensionPath = string extends Path ? Path : Path extends ReservedPath ? never : Path; type WorkerHonoEnv = { Bindings: Bindings; }; type ExtensionHandler = Handler, Path> | MiddlewareHandler, Path>; type SafePath = Path & MantleExtensionPath; type ExtensionRoute = (path: SafePath, ...handlers: [ExtensionHandler, ...ExtensionHandler[]]) => MantleExtensionApp; /** * A restricted view of the real Hono app. It keeps Hono handlers and routing, * but omits global error/not-found hooks and rejects literal reserved paths. */ export interface MantleExtensionApp { readonly get: ExtensionRoute; readonly post: ExtensionRoute; readonly put: ExtensionRoute; readonly patch: ExtensionRoute; readonly delete: ExtensionRoute; readonly options: ExtensionRoute; readonly all: ExtensionRoute; on(method: string | readonly string[], path: SafePath, ...handlers: [ExtensionHandler, ...ExtensionHandler[]]): MantleExtensionApp; use(path: SafePath, ...handlers: [MiddlewareHandler, Path>, ...MiddlewareHandler, Path>[]]): MantleExtensionApp; route(path: SafePath, app: Hono): MantleExtensionApp; } export interface MantleCloudflareEnv extends ConventionalAuthEnv { readonly ASSETS?: Fetcher; /** Optional derived MCP catalog snapshot. D1 remains canonical. */ readonly MANTLE_KV?: KVNamespace; } export interface MantleWorkerBootstrapContext { readonly env: Env; readonly auth: Auth; readonly bindings: MantleWorkerBindings; /** Safe to retain and call later; do not call synchronously inside `extend`. */ readonly getRuntime: () => Promise; } export interface MantleWorkerMountContext extends MantleWorkerBootstrapContext { readonly app: MantleExtensionApp; readonly ref: MantleRuntimeRef; } /** The one opt-in seam for application handlers, auth inputs and routes. */ export interface MantleWorkerExtension { readonly handlers?: Readonly>; readonly credentialResolver?: ConsumerCredentialResolver; readonly jwtBearer?: MantleCloudflareConfig["jwtBearer"]; /** Standard routes mount first; extension routes may only add new paths. */ readonly mount?: (context: MantleWorkerMountContext) => void; } export interface CreateMantleWorkerOptions { /** Sealed generated plan imported from `.mantle/generated/mantle.js`. */ readonly plan: RuntimePlan; readonly handlers?: Readonly>; readonly siteDefaults?: SiteDefaults | ((env: Env) => SiteDefaults); /** Stable deployment/site identifier used by public cache tags and optional KV. */ readonly cacheScope?: string | ((env: Env) => string); /** Exact external browser origins. Never grants a principal or cookie access. */ readonly frontendOrigins?: readonly string[] | ((env: Env) => readonly string[]); /** Fallback for app-owned paths after native routes; one authorized client per request. */ readonly frontend?: (request: Request, context: { readonly env: Env; readonly client: ReturnType; readonly executionCtx: ExecutionContext; }) => Response | Promise; readonly templates?: TemplateRegistry; readonly publicPathResolver?: PublicPathResolver; readonly mediaAllowSvg?: boolean | ((env: Env) => boolean); /** Replace only Auth construction; standard Auth routes remain Core-owned. */ readonly auth?: (env: Env) => Auth; /** MCP tools/call audit trail, e.g. `env => analyticsEngineAuditSink(env.AUDIT, { index: env.PUBLIC_ORIGIN })`. */ readonly audit?: AuditSink | ((env: Env) => AuditSink | undefined); /** Augment conventional adapters for a proven capability such as R2 media. */ readonly bindings?: (env: Env, conventional: MantleWorkerBindings) => MantleWorkerBindings; /** May rerun after initialization fails; keep external side effects out of assembly. */ readonly extend?: (context: MantleWorkerBootstrapContext) => MantleWorkerExtension | void; } export interface MantleWorkerHandler { /** Boot and return the same runtime used by fetch. Queue/scheduled handlers * use this instead of constructing a second runtime or bypassing it. */ getRuntime(env: Env): Promise; fetch(request: Request, env: Env, ctx: ExecutionContext): Promise; } /** Assemble Mantle's conventional Worker once per isolate. */ export declare function createMantleWorker(options: CreateMantleWorkerOptions): MantleWorkerHandler; /** Redacted fail-closed boundary for facade and low-level Worker assembly failures. */ export declare function runMantleWorkerRequest(run: () => Response | Promise): Promise; export declare function isMantleReservedPath(path: string, authBasePath?: string): boolean; export {}; //# sourceMappingURL=createMantleWorker.d.ts.map