Skip to content

Commit 65c4e17

Browse files
authored
fix(ext/core): missing Supabase namespace (#467)
* fix(ext/core): missing `Supabase` namespace * chore: update `global.d.ts` * chore: update `deno.json`
1 parent 667db65 commit 65c4e17

File tree

5 files changed

+81
-12
lines changed

5 files changed

+81
-12
lines changed

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"proseWrap": "preserve"
1212
},
1313
"imports": {
14-
"npm:@meowmeow/foobar": "npm:is-odd"
14+
"npm:@meowmeow/foobar": "npm:is-odd",
15+
"openai": "npm:openai"
1516
}
1617
}

ext/core/js/bootstrap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ import * as WebGPUSurface from 'ext:deno_webgpu/02_surface.js';
3535
import 'ext:sb_ai/js/onnxruntime/cache_adapter.js';
3636

3737
import { SUPABASE_ENV } from 'ext:sb_env/env.js';
38-
import { USER_WORKER_API as ai } from 'ext:sb_ai/js/ai.js';
3938

4039
import { SupabaseEventListener } from 'ext:sb_user_event_worker/event_worker.js';
41-
import { installEdgeRuntimeNamespace } from 'ext:sb_core_main_js/js/edge_runtime.js';
40+
import { installEdgeRuntimeNamespace, installSupabaseNamespace } from 'ext:sb_core_main_js/js/namespaces.js';
4241
import { promiseRejectMacrotaskCallback } from 'ext:sb_core_main_js/js/promises.js';
4342
import { installPromiseHook } from 'ext:sb_core_main_js/js/async_hook.js';
4443
import { registerErrors } from 'ext:sb_core_main_js/js/errors.js';
@@ -545,6 +544,7 @@ globalThis.bootstrapSBEdge = (opts, ctx) => {
545544

546545
installPromiseHook(kind);
547546
installEdgeRuntimeNamespace(kind, ctx.terminationRequestToken);
547+
installSupabaseNamespace(kind);
548548

549549
ObjectDefineProperty(globalThis, 'SUPABASE_VERSION', readOnly(String(version.runtime)));
550550
ObjectDefineProperty(globalThis, 'DENO_VERSION', readOnly(version.deno));

ext/core/js/edge_runtime.js renamed to ext/core/js/namespaces.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { core, primordials } from "ext:core/mod.js";
22

3-
import { MAIN_WORKER_API as ai } from "ext:sb_ai/js/ai.js";
3+
import { MAIN_WORKER_API, USER_WORKER_API } from "ext:sb_ai/js/ai.js";
44
import { SUPABASE_USER_WORKERS } from "ext:sb_user_workers/user_workers.js";
55
import { applySupabaseTag } from "ext:sb_core_main_js/js/http.js";
66
import { waitUntil } from "ext:sb_core_main_js/js/async_hook.js";
@@ -20,7 +20,7 @@ function installEdgeRuntimeNamespace(kind, terminationRequestTokenRid) {
2020
switch (kind) {
2121
case "main":
2222
props = {
23-
ai,
23+
ai: MAIN_WORKER_API,
2424
userWorkers: SUPABASE_USER_WORKERS,
2525
getRuntimeMetrics: () => /* async */ ops.op_runtime_metrics(),
2626
applySupabaseTag: (src, dest) => applySupabaseTag(src, dest),
@@ -55,6 +55,25 @@ function installEdgeRuntimeNamespace(kind, terminationRequestTokenRid) {
5555
});
5656
}
5757

58+
/**
59+
* @param {"user" | "main" | "event"} kind
60+
*/
61+
function installSupabaseNamespace(kind) {
62+
if (kind === "user") {
63+
const props = {
64+
ai: USER_WORKER_API
65+
};
66+
67+
ObjectDefineProperty(globalThis, "Supabase", {
68+
get() {
69+
return props;
70+
},
71+
configurable: true,
72+
});
73+
}
74+
}
75+
5876
export {
5977
installEdgeRuntimeNamespace,
78+
installSupabaseNamespace,
6079
}

ext/core/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,17 @@ deno_core::extension!(
434434
],
435435
esm_entry_point = "ext:sb_core_main_js/js/bootstrap.js",
436436
esm = [
437-
"js/edge_runtime.js",
437+
"js/00_serve.js",
438+
"js/01_http.js",
438439
"js/async_hook.js",
439-
"js/permissions.js",
440+
"js/bootstrap.js",
441+
"js/denoOverrides.js",
440442
"js/errors.js",
441443
"js/fieldUtils.js",
442-
"js/promises.js",
443444
"js/http.js",
444-
"js/denoOverrides.js",
445+
"js/namespaces.js",
445446
"js/navigator.js",
446-
"js/bootstrap.js",
447-
"js/00_serve.js",
448-
"js/01_http.js"
447+
"js/permissions.js",
448+
"js/promises.js",
449449
]
450450
);

types/global.d.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,55 @@ declare namespace EdgeRuntime {
108108
export { UserWorker as userWorkers };
109109
}
110110

111+
declare namespace Supabase {
112+
export namespace ai {
113+
interface ModelOptions {
114+
/**
115+
* Pool embeddings by taking their mean. Applies only for `gte-small` model
116+
*/
117+
mean_pool?: boolean
118+
119+
/**
120+
* Normalize the embeddings result. Applies only for `gte-small` model
121+
*/
122+
normalize?: boolean
123+
124+
/**
125+
* Stream response from model. Applies only for LLMs like `mistral` (default: false)
126+
*/
127+
stream?: boolean
128+
129+
/**
130+
* Automatically abort the request to the model after specified time (in seconds). Applies only for LLMs like `mistral` (default: 60)
131+
*/
132+
timeout?: number
133+
134+
/**
135+
* Mode for the inference API host. (default: 'ollama')
136+
*/
137+
mode?: 'ollama' | 'openaicompatible'
138+
signal?: AbortSignal
139+
}
140+
141+
export class Session {
142+
/**
143+
* Create a new model session using given model
144+
*/
145+
constructor(model: string);
146+
147+
/**
148+
* Execute the given prompt in model session
149+
*/
150+
run(
151+
prompt:
152+
| string
153+
| Omit<import('openai').OpenAI.Chat.ChatCompletionCreateParams, 'model' | 'stream'>,
154+
modelOptions?: ModelOptions
155+
): unknown
156+
}
157+
}
158+
}
159+
111160
declare namespace Deno {
112161
export namespace errors {
113162
class WorkerRequestCancelled extends Error { }

0 commit comments

Comments
 (0)