From a82719f5f5805a43671b02403e241cff0ba31c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=83=A5=EB=83=90=EC=B1=A0?= Date: Tue, 16 Sep 2025 09:38:37 +0900 Subject: [PATCH] chore: update `edge-runtime.d.ts` --- src/edge-runtime.d.ts | 255 +++++++++++++++++++++++++++++++++--------- 1 file changed, 201 insertions(+), 54 deletions(-) diff --git a/src/edge-runtime.d.ts b/src/edge-runtime.d.ts index 8e3e89b..7810e23 100644 --- a/src/edge-runtime.d.ts +++ b/src/edge-runtime.d.ts @@ -1,62 +1,209 @@ -declare namespace Supabase { - export interface ModelOptions { - /** - * Pool embeddings by taking their mean. Applies only for `gte-small` model - */ - mean_pool?: boolean - - /** - * Normalize the embeddings result. Applies only for `gte-small` model - */ - normalize?: boolean - - /** - * Stream response from model. Applies only for LLMs like `mistral` (default: false) - */ - stream?: boolean - - /** - * Automatically abort the request to the model after specified time (in seconds). Applies only for LLMs like `mistral` (default: 60) - */ - timeout?: number - - /** - * Mode for the inference API host. (default: 'ollama') - */ - mode?: 'ollama' | 'openaicompatible' - signal?: AbortSignal - } +declare type BeforeunloadReason = + | "cpu" + | "memory" + | "wall_clock" + | "early_drop" + | "termination"; - export class Session { - /** - * Create a new model session using given model - */ - constructor(model: string, sessionOptions?: unknown) - - /** - * Execute the given prompt in model session - */ - run( - prompt: - | string - | Omit, - modelOptions?: ModelOptions - ): unknown - } +declare interface WindowEventMap { + "load": Event; + "unload": Event; + "beforeunload": CustomEvent; + "drain": Event; +} - /** - * Provides AI related APIs - */ - export interface Ai { - readonly Session: typeof Session - } +// TODO(Nyannyacha): These two type defs will be provided later. + +// deno-lint-ignore no-explicit-any +type S3FsConfig = any; + +// deno-lint-ignore no-explicit-any +type TmpFsConfig = any; + +type OtelPropagators = "TraceContext" | "Baggage"; +type OtelConsoleConfig = "Ignore" | "Capture" | "Replace"; +type OtelConfig = { + tracing_enabled?: boolean; + metrics_enabled?: boolean; + console?: OtelConsoleConfig; + propagators?: OtelPropagators[]; +}; + +interface UserWorkerFetchOptions { + signal?: AbortSignal; +} + +interface PermissionsOptions { + allow_all?: boolean | null; + allow_env?: string[] | null; + deny_env?: string[] | null; + allow_net?: string[] | null; + deny_net?: string[] | null; + allow_ffi?: string[] | null; + deny_ffi?: string[] | null; + allow_read?: string[] | null; + deny_read?: string[] | null; + allow_run?: string[] | null; + deny_run?: string[] | null; + allow_sys?: string[] | null; + deny_sys?: string[] | null; + allow_write?: string[] | null; + deny_write?: string[] | null; + allow_import?: string[] | null; +} + +interface UserWorkerCreateContext { + sourceMap?: boolean | null; + importMapPath?: string | null; + shouldBootstrapMockFnThrowError?: boolean | null; + suppressEszipMigrationWarning?: boolean | null; + useReadSyncFileAPI?: boolean | null; + supervisor?: { + requestAbsentTimeoutMs?: number | null; + }; + otel?: { + [attribute: string]: string; + }; +} + +interface UserWorkerCreateOptions { + servicePath?: string | null; + envVars?: string[][] | [string, string][] | null; + noModuleCache?: boolean | null; + + forceCreate?: boolean | null; + allowRemoteModules?: boolean | null; + customModuleRoot?: string | null; + permissions?: PermissionsOptions | null; + + maybeEszip?: Uint8Array | null; + maybeEntrypoint?: string | null; + maybeModuleCode?: string | null; + + memoryLimitMb?: number | null; + lowMemoryMultiplier?: number | null; + workerTimeoutMs?: number | null; + cpuTimeSoftLimitMs?: number | null; + cpuTimeHardLimitMs?: number | null; + staticPatterns?: string[] | null; + + s3FsConfig?: S3FsConfig | null; + tmpFsConfig?: TmpFsConfig | null; + otelConfig?: OtelConfig | null; + + context?: UserWorkerCreateContext | null; +} + +interface HeapStatistics { + totalHeapSize: number; + totalHeapSizeExecutable: number; + totalPhysicalSize: number; + totalAvailableSize: number; + totalGlobalHandlesSize: number; + usedGlobalHandlesSize: number; + usedHeapSize: number; + mallocedMemory: number; + externalMemory: number; + peakMallocedMemory: number; +} - /** - * Provides AI related APIs - */ - export const ai: Ai +interface RuntimeMetrics { + mainWorkerHeapStats: HeapStatistics; + eventWorkerHeapStats?: HeapStatistics; +} + +interface MemInfo { + total: number; + free: number; + available: number; + buffers: number; + cached: number; + swapTotal: number; + swapFree: number; } declare namespace EdgeRuntime { + export namespace ai { + function tryCleanupUnusedSession(): Promise; + } + + class UserWorker { + constructor(key: string); + + fetch( + request: Request, + options?: UserWorkerFetchOptions, + ): Promise; + + static create(opts: UserWorkerCreateOptions): Promise; + static tryCleanupIdleWorkers(timeoutMs: number): Promise; + } + + export function scheduleTermination(): void; export function waitUntil(promise: Promise): Promise; + export function getRuntimeMetrics(): Promise; + export function applySupabaseTag(src: Request, dest: Request): void; + export function systemMemoryInfo(): MemInfo; + export function raiseSegfault(): void; + + export { UserWorker as userWorkers }; +} + +declare namespace Supabase { + export namespace ai { + interface ModelOptions { + /** + * Pool embeddings by taking their mean. Applies only for `gte-small` model + */ + mean_pool?: boolean; + + /** + * Normalize the embeddings result. Applies only for `gte-small` model + */ + normalize?: boolean; + + /** + * Stream response from model. Applies only for LLMs like `mistral` (default: false) + */ + stream?: boolean; + + /** + * Automatically abort the request to the model after specified time (in seconds). Applies only for LLMs like `mistral` (default: 60) + */ + timeout?: number; + + /** + * Mode for the inference API host. (default: 'ollama') + */ + mode?: "ollama" | "openaicompatible"; + signal?: AbortSignal; + } + + export class Session { + /** + * Create a new model session using given model + */ + constructor(model: string); + + /** + * Execute the given prompt in model session + */ + run( + prompt: + | string + | Omit< + import("openai").OpenAI.Chat.ChatCompletionCreateParams, + "model" | "stream" + >, + modelOptions?: ModelOptions, + ): unknown; + } + } +} + +declare namespace Deno { + export namespace errors { + class WorkerRequestCancelled extends Error {} + class WorkerAlreadyRetired extends Error {} + } }