Skip to content

Commit f7db497

Browse files
authored
chore: update edge-runtime.d.ts
1 parent 51a4004 commit f7db497

File tree

1 file changed

+201
-54
lines changed

1 file changed

+201
-54
lines changed
Lines changed: 201 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,209 @@
1-
declare namespace Supabase {
2-
export interface ModelOptions {
3-
/**
4-
* Pool embeddings by taking their mean. Applies only for `gte-small` model
5-
*/
6-
mean_pool?: boolean
7-
8-
/**
9-
* Normalize the embeddings result. Applies only for `gte-small` model
10-
*/
11-
normalize?: boolean
12-
13-
/**
14-
* Stream response from model. Applies only for LLMs like `mistral` (default: false)
15-
*/
16-
stream?: boolean
17-
18-
/**
19-
* Automatically abort the request to the model after specified time (in seconds). Applies only for LLMs like `mistral` (default: 60)
20-
*/
21-
timeout?: number
22-
23-
/**
24-
* Mode for the inference API host. (default: 'ollama')
25-
*/
26-
mode?: 'ollama' | 'openaicompatible'
27-
signal?: AbortSignal
28-
}
1+
declare type BeforeunloadReason =
2+
| "cpu"
3+
| "memory"
4+
| "wall_clock"
5+
| "early_drop"
6+
| "termination";
297

30-
export class Session {
31-
/**
32-
* Create a new model session using given model
33-
*/
34-
constructor(model: string, sessionOptions?: unknown)
35-
36-
/**
37-
* Execute the given prompt in model session
38-
*/
39-
run(
40-
prompt:
41-
| string
42-
| Omit<import('openai').OpenAI.Chat.ChatCompletionCreateParams, 'model' | 'stream'>,
43-
modelOptions?: ModelOptions
44-
): unknown
45-
}
8+
declare interface WindowEventMap {
9+
"load": Event;
10+
"unload": Event;
11+
"beforeunload": CustomEvent<BeforeunloadReason>;
12+
"drain": Event;
13+
}
4614

47-
/**
48-
* Provides AI related APIs
49-
*/
50-
export interface Ai {
51-
readonly Session: typeof Session
52-
}
15+
// TODO(Nyannyacha): These two type defs will be provided later.
16+
17+
// deno-lint-ignore no-explicit-any
18+
type S3FsConfig = any;
19+
20+
// deno-lint-ignore no-explicit-any
21+
type TmpFsConfig = any;
22+
23+
type OtelPropagators = "TraceContext" | "Baggage";
24+
type OtelConsoleConfig = "Ignore" | "Capture" | "Replace";
25+
type OtelConfig = {
26+
tracing_enabled?: boolean;
27+
metrics_enabled?: boolean;
28+
console?: OtelConsoleConfig;
29+
propagators?: OtelPropagators[];
30+
};
31+
32+
interface UserWorkerFetchOptions {
33+
signal?: AbortSignal;
34+
}
35+
36+
interface PermissionsOptions {
37+
allow_all?: boolean | null;
38+
allow_env?: string[] | null;
39+
deny_env?: string[] | null;
40+
allow_net?: string[] | null;
41+
deny_net?: string[] | null;
42+
allow_ffi?: string[] | null;
43+
deny_ffi?: string[] | null;
44+
allow_read?: string[] | null;
45+
deny_read?: string[] | null;
46+
allow_run?: string[] | null;
47+
deny_run?: string[] | null;
48+
allow_sys?: string[] | null;
49+
deny_sys?: string[] | null;
50+
allow_write?: string[] | null;
51+
deny_write?: string[] | null;
52+
allow_import?: string[] | null;
53+
}
54+
55+
interface UserWorkerCreateContext {
56+
sourceMap?: boolean | null;
57+
importMapPath?: string | null;
58+
shouldBootstrapMockFnThrowError?: boolean | null;
59+
suppressEszipMigrationWarning?: boolean | null;
60+
useReadSyncFileAPI?: boolean | null;
61+
supervisor?: {
62+
requestAbsentTimeoutMs?: number | null;
63+
};
64+
otel?: {
65+
[attribute: string]: string;
66+
};
67+
}
68+
69+
interface UserWorkerCreateOptions {
70+
servicePath?: string | null;
71+
envVars?: string[][] | [string, string][] | null;
72+
noModuleCache?: boolean | null;
73+
74+
forceCreate?: boolean | null;
75+
allowRemoteModules?: boolean | null;
76+
customModuleRoot?: string | null;
77+
permissions?: PermissionsOptions | null;
78+
79+
maybeEszip?: Uint8Array | null;
80+
maybeEntrypoint?: string | null;
81+
maybeModuleCode?: string | null;
82+
83+
memoryLimitMb?: number | null;
84+
lowMemoryMultiplier?: number | null;
85+
workerTimeoutMs?: number | null;
86+
cpuTimeSoftLimitMs?: number | null;
87+
cpuTimeHardLimitMs?: number | null;
88+
staticPatterns?: string[] | null;
89+
90+
s3FsConfig?: S3FsConfig | null;
91+
tmpFsConfig?: TmpFsConfig | null;
92+
otelConfig?: OtelConfig | null;
93+
94+
context?: UserWorkerCreateContext | null;
95+
}
96+
97+
interface HeapStatistics {
98+
totalHeapSize: number;
99+
totalHeapSizeExecutable: number;
100+
totalPhysicalSize: number;
101+
totalAvailableSize: number;
102+
totalGlobalHandlesSize: number;
103+
usedGlobalHandlesSize: number;
104+
usedHeapSize: number;
105+
mallocedMemory: number;
106+
externalMemory: number;
107+
peakMallocedMemory: number;
108+
}
53109

54-
/**
55-
* Provides AI related APIs
56-
*/
57-
export const ai: Ai
110+
interface RuntimeMetrics {
111+
mainWorkerHeapStats: HeapStatistics;
112+
eventWorkerHeapStats?: HeapStatistics;
113+
}
114+
115+
interface MemInfo {
116+
total: number;
117+
free: number;
118+
available: number;
119+
buffers: number;
120+
cached: number;
121+
swapTotal: number;
122+
swapFree: number;
58123
}
59124

60125
declare namespace EdgeRuntime {
126+
export namespace ai {
127+
function tryCleanupUnusedSession(): Promise<number>;
128+
}
129+
130+
class UserWorker {
131+
constructor(key: string);
132+
133+
fetch(
134+
request: Request,
135+
options?: UserWorkerFetchOptions,
136+
): Promise<Response>;
137+
138+
static create(opts: UserWorkerCreateOptions): Promise<UserWorker>;
139+
static tryCleanupIdleWorkers(timeoutMs: number): Promise<number>;
140+
}
141+
142+
export function scheduleTermination(): void;
61143
export function waitUntil<T>(promise: Promise<T>): Promise<T>;
144+
export function getRuntimeMetrics(): Promise<RuntimeMetrics>;
145+
export function applySupabaseTag(src: Request, dest: Request): void;
146+
export function systemMemoryInfo(): MemInfo;
147+
export function raiseSegfault(): void;
148+
149+
export { UserWorker as userWorkers };
150+
}
151+
152+
declare namespace Supabase {
153+
export namespace ai {
154+
interface ModelOptions {
155+
/**
156+
* Pool embeddings by taking their mean. Applies only for `gte-small` model
157+
*/
158+
mean_pool?: boolean;
159+
160+
/**
161+
* Normalize the embeddings result. Applies only for `gte-small` model
162+
*/
163+
normalize?: boolean;
164+
165+
/**
166+
* Stream response from model. Applies only for LLMs like `mistral` (default: false)
167+
*/
168+
stream?: boolean;
169+
170+
/**
171+
* Automatically abort the request to the model after specified time (in seconds). Applies only for LLMs like `mistral` (default: 60)
172+
*/
173+
timeout?: number;
174+
175+
/**
176+
* Mode for the inference API host. (default: 'ollama')
177+
*/
178+
mode?: "ollama" | "openaicompatible";
179+
signal?: AbortSignal;
180+
}
181+
182+
export class Session {
183+
/**
184+
* Create a new model session using given model
185+
*/
186+
constructor(model: string);
187+
188+
/**
189+
* Execute the given prompt in model session
190+
*/
191+
run(
192+
prompt:
193+
| string
194+
| Omit<
195+
import("openai").OpenAI.Chat.ChatCompletionCreateParams,
196+
"model" | "stream"
197+
>,
198+
modelOptions?: ModelOptions,
199+
): unknown;
200+
}
201+
}
202+
}
203+
204+
declare namespace Deno {
205+
export namespace errors {
206+
class WorkerRequestCancelled extends Error {}
207+
class WorkerAlreadyRetired extends Error {}
208+
}
62209
}

0 commit comments

Comments
 (0)