import type { Metadata } from '@devvit/protos/lib/Types.js'; import type { LinkedBundle } from '@devvit/protos/types/devvit/runtime/bundle.js'; import type { CircuitBreakerResponse } from '@devvit/shared-types/CircuitBreaker.js'; import type { AppLog } from '../console/AppConsole.js'; import type { WorkerBox } from '../types/WorkerBox.js'; /** * App executor. Implementation may support sandboxing JavaScript execution in a * virtual machine. * * Runtimes are interacted with via RuntimeLiteWorker. */ export type RuntimeLite = { /** * Cease standard Console logging and start posting logs in command responses. * Does not impact runtime logging but app logs may intermingle in unsandboxed * runtimes. */ enableAppLogging(): void; /** * Get data associated with the last invocation of loadBundle() or call(). * * Call state could be returned from each call() response but it would need to * be wrapped which is a breaking change for client integrations. */ getCallState(): CallState; /** * Initialize runtime, if needed. */ init(): Promise; /** * Specify the services that should be handled locally * Each entry should be the full name of the service, such as `devvit.plugin.clock.Clock` */ setPluginList: (plugins: string[]) => void; /** * Provide additional metadata from the local environment to be included with every call */ setLocalMetadata: (meta: Metadata) => void; /** * Inject app code from bundle and create an instance of the app * @param bundle App bundle to load */ loadBundle(bundle: LinkedBundle): void; /** * Execute a method on the instantiated app. This method should never throw. * @param method Name of the app method to execute. Eg, 'HandleUIEvent' for a * devvit.ui.events.v1alpha.UIEventHandler. * @param args Protobuf message for method. Eg, PingMessage. * @param meta Metadata to include with the call * @param binary Deprecated, use callBinary(). If true, decode args into a message and encode the response with application/protobuf */ call(method: string, args: unknown, meta: Metadata, binary?: boolean): Promise; /** * Decode args and encode the response before executing the call with application/protobuf encoding * @param method Name of the app method to execute * @param args Binary encoded protobuf message for method * @param meta Metadata to include with the call */ callBinary(method: string, args: Uint8Array, meta: Metadata): Promise; /** * Return the result of a plugin call to the app * @param id The original call ID from the app * @param result The result from the call */ onPluginResponse(id: number, result: CallResponse): void; /** * Shutdown the app and terminate the worker */ quit(): void; }; /** The current state of the runtime. State is cleared on call() or loadBundle(). */ export type CallState = { /** Most recent sandbox logs. */ logs: AppLog[]; }; export type CallResponse = SuccessCallResponse | FailureCallResponse; export type SuccessCallResponse = { error: undefined; success: true; value: Uint8Array | unknown; }; export type FailureCallResponse = { error: Error | CircuitBreakerResponse; success: false; value: Uint8Array | undefined; }; type BoxType = RuntimeLite & WorkerBox; export declare const box: BoxType; export type PluginCallback = (id: number, serviceName: string, method: string, args: unknown, meta: unknown) => void; export type PluginOptions = { callback: PluginCallback; plugins: string[]; }; export {}; //# sourceMappingURL=RuntimeLite.d.ts.map