@ragable/sdk 0.7.10 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +224 -102
- package/dist/index.d.ts +224 -102
- package/dist/index.js +361 -179
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +360 -176
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -708,7 +708,7 @@ declare class AuthBroadcastChannel {
|
|
|
708
708
|
close(): void;
|
|
709
709
|
}
|
|
710
710
|
|
|
711
|
-
type AuthChangeEvent = "INITIAL_SESSION" | "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "USER_UPDATED";
|
|
711
|
+
type AuthChangeEvent = "INITIAL_SESSION" | "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "TOKEN_REFRESH_FAILED" | "USER_UPDATED";
|
|
712
712
|
type AuthUserMetadata = Record<string, unknown>;
|
|
713
713
|
interface DefaultAuthUser<Metadata extends AuthUserMetadata = AuthUserMetadata> {
|
|
714
714
|
id: string;
|
|
@@ -783,10 +783,26 @@ declare class RagableAuth<U extends object = DefaultAuthUser> {
|
|
|
783
783
|
private listeners;
|
|
784
784
|
private broadcast;
|
|
785
785
|
private visibilityHandler;
|
|
786
|
-
|
|
786
|
+
/** Memoizes the one-shot restore so concurrent callers (constructor eager init,
|
|
787
|
+
* every `onAuthStateChange` subscriber, `getSession`) share a single result.
|
|
788
|
+
* Non-null also means "restore has started", replacing the old boolean flag. */
|
|
789
|
+
private initializePromise;
|
|
790
|
+
/** Bumped on every explicit session change (sign-in/out, refresh). The async
|
|
791
|
+
* restore captures this and refuses to overwrite a newer session op that
|
|
792
|
+
* landed while it was reading storage (e.g. a sign-out during page load). */
|
|
793
|
+
private sessionEpoch;
|
|
787
794
|
constructor(config: RagableAuthConfig);
|
|
788
795
|
private log;
|
|
796
|
+
/**
|
|
797
|
+
* Restore a persisted session (once). Memoized: every caller awaits the same
|
|
798
|
+
* promise, so the eager constructor init, `getSession`, and each
|
|
799
|
+
* `onAuthStateChange` subscriber's INITIAL_SESSION replay never race or
|
|
800
|
+
* double-restore. Does NOT emit `INITIAL_SESSION` globally — that event is
|
|
801
|
+
* delivered per-subscriber by `onAuthStateChange` (Supabase-parity), so a
|
|
802
|
+
* listener attached after restore still sees the existing session.
|
|
803
|
+
*/
|
|
789
804
|
initialize(): Promise<AuthSession<U> | null>;
|
|
805
|
+
private _initialize;
|
|
790
806
|
signUp(credentials: AuthSignUpCredentials<MetadataForUser<U>>): Promise<PostgrestResult<{
|
|
791
807
|
user: U;
|
|
792
808
|
session: AuthSession<U>;
|
|
@@ -835,7 +851,14 @@ declare class RagableAuth<U extends object = DefaultAuthUser> {
|
|
|
835
851
|
};
|
|
836
852
|
};
|
|
837
853
|
getAccessToken(): string | null;
|
|
838
|
-
|
|
854
|
+
/**
|
|
855
|
+
* Returns an access token guaranteed fresh for at least `refreshSkewSeconds`,
|
|
856
|
+
* refreshing (single-flight) if needed. Pass `force: true` to bypass the skew
|
|
857
|
+
* check and refresh now — used by the transport's 401 handler so a token the
|
|
858
|
+
* server rejected (key rotation, clock skew, early revocation) self-heals on
|
|
859
|
+
* retry instead of failing the call.
|
|
860
|
+
*/
|
|
861
|
+
getValidAccessToken(force?: boolean): Promise<string | null>;
|
|
839
862
|
getCurrentSession(): AuthSession<U> | null;
|
|
840
863
|
register(body: {
|
|
841
864
|
email: string;
|
|
@@ -891,7 +914,17 @@ declare class RagableAuth<U extends object = DefaultAuthUser> {
|
|
|
891
914
|
private emit;
|
|
892
915
|
private scheduleRefresh;
|
|
893
916
|
private clearRefreshTimer;
|
|
917
|
+
/**
|
|
918
|
+
* Refresh the session, deduplicating concurrent callers onto one in-flight
|
|
919
|
+
* request. Side effects (persisting the new session, or clearing it and
|
|
920
|
+
* emitting SIGNED_OUT / TOKEN_REFRESH_FAILED) run exactly once inside the
|
|
921
|
+
* shared promise, so two callers can't double-emit. Resolves to the new
|
|
922
|
+
* session, or `null` when the refresh failed.
|
|
923
|
+
*/
|
|
894
924
|
singleFlightRefresh(refreshToken: string): Promise<AuthSession<U> | null>;
|
|
925
|
+
/** Clear the session locally and emit SIGNED_OUT after a definitively-rejected
|
|
926
|
+
* refresh, so onAuthStateChange-driven UI redirects to login. */
|
|
927
|
+
private handleTerminalRefreshFailure;
|
|
895
928
|
private _doRefresh;
|
|
896
929
|
private setupVisibilityListener;
|
|
897
930
|
}
|
|
@@ -981,53 +1014,10 @@ type StreamPart = {
|
|
|
981
1014
|
type: "error";
|
|
982
1015
|
error: unknown;
|
|
983
1016
|
};
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
type: "text";
|
|
987
|
-
text: string;
|
|
988
|
-
}
|
|
989
|
-
/**
|
|
990
|
-
* Image segment inside a multimodal user message. Mirrors Vercel AI SDK's
|
|
991
|
-
* `ImagePart` shape — the discriminator is `"image"` and the data field is
|
|
992
|
-
* `image` (not `image_url`). The SDK converts to the OpenAI `image_url`
|
|
993
|
-
* wire format internally.
|
|
994
|
-
*/
|
|
995
|
-
interface ImagePart {
|
|
996
|
-
type: "image";
|
|
997
|
-
/**
|
|
998
|
-
* Accepted forms:
|
|
999
|
-
* - HTTP(S) URL string (`"https://…"`) — passed through; the provider fetches it.
|
|
1000
|
-
* - Data URL string (`"data:image/png;base64,…"`) — passed through.
|
|
1001
|
-
* - Raw base64 string (no `data:` prefix) — `mediaType` then required.
|
|
1002
|
-
* - `Uint8Array` / `ArrayBuffer` — base64-encoded; `mediaType` required.
|
|
1003
|
-
* - `URL` instance — `href` is passed through.
|
|
1004
|
-
*/
|
|
1005
|
-
image: string | Uint8Array | ArrayBuffer | URL;
|
|
1006
|
-
/** IANA media type, e.g. `"image/png"`. Required when `image` is binary or a raw base64 string. */
|
|
1007
|
-
mediaType?: string;
|
|
1008
|
-
/** OpenAI-compatible detail hint; forwarded as `image_url.detail`. */
|
|
1009
|
-
detail?: "auto" | "low" | "high";
|
|
1010
|
-
}
|
|
1011
|
-
/**
|
|
1012
|
-
* Content for a user message — either a plain string (back-compat with the
|
|
1013
|
-
* original text-only shape) or an array of text/image parts.
|
|
1014
|
-
*/
|
|
1015
|
-
type UserContent = string | Array<TextPart | ImagePart>;
|
|
1016
|
-
/**
|
|
1017
|
-
* Chat message. `user` messages may carry multimodal content; `system` and
|
|
1018
|
-
* `assistant` are text-only (vision models consume images on user turns,
|
|
1019
|
-
* and image *output* isn't supported here).
|
|
1020
|
-
*/
|
|
1021
|
-
type Message = {
|
|
1022
|
-
role: "system";
|
|
1017
|
+
interface Message {
|
|
1018
|
+
role: "system" | "user" | "assistant";
|
|
1023
1019
|
content: string;
|
|
1024
|
-
}
|
|
1025
|
-
role: "user";
|
|
1026
|
-
content: UserContent;
|
|
1027
|
-
} | {
|
|
1028
|
-
role: "assistant";
|
|
1029
|
-
content: string;
|
|
1030
|
-
};
|
|
1020
|
+
}
|
|
1031
1021
|
/**
|
|
1032
1022
|
* OpenAI/Fireworks SSE chunk shape, only the fields we actually consume.
|
|
1033
1023
|
* Kept as a local type so we don't depend on backend internals.
|
|
@@ -1289,15 +1279,117 @@ declare function streamObjectFromContext<T = unknown>(ctx: InferenceRequestConte
|
|
|
1289
1279
|
*/
|
|
1290
1280
|
declare function wrapStreamTextAsObject<T = unknown>(inner: StreamTextResult): StreamObjectResult<T>;
|
|
1291
1281
|
|
|
1282
|
+
/**
|
|
1283
|
+
* Backend "edge functions".
|
|
1284
|
+
*
|
|
1285
|
+
* A function is a single file in the project's `/functions` folder whose name is
|
|
1286
|
+
* the function name and whose **default export is the handler**:
|
|
1287
|
+
*
|
|
1288
|
+
* ```ts
|
|
1289
|
+
* // /functions/getUsers.ts
|
|
1290
|
+
* import type { RagableFunctionContext } from "@ragable/sdk";
|
|
1291
|
+
*
|
|
1292
|
+
* export default async function getUsers(
|
|
1293
|
+
* input: { limit?: number },
|
|
1294
|
+
* context: RagableFunctionContext,
|
|
1295
|
+
* ) {
|
|
1296
|
+
* const res = await fetch("https://api.example.com/users", {
|
|
1297
|
+
* headers: { Authorization: `Bearer ${context.env.API_KEY}` },
|
|
1298
|
+
* });
|
|
1299
|
+
* return (await res.json()).slice(0, input.limit ?? 20);
|
|
1300
|
+
* }
|
|
1301
|
+
* ```
|
|
1302
|
+
*
|
|
1303
|
+
* Saving the file deploys it (near-instant). It runs **server-side** — so secrets
|
|
1304
|
+
* stay off the client and there are no browser CORS limits — and is invoked from
|
|
1305
|
+
* the browser with `client.functions.getUsers({ limit: 5 })`.
|
|
1306
|
+
*
|
|
1307
|
+
* The handler's second argument (`context`) is injected by the server; callers
|
|
1308
|
+
* pass only `input`.
|
|
1309
|
+
*/
|
|
1310
|
+
/**
|
|
1311
|
+
* Server-injected second argument to every function handler. Never constructed
|
|
1312
|
+
* on the client — the values come from the backend at invocation time.
|
|
1313
|
+
*/
|
|
1314
|
+
interface RagableFunctionContext {
|
|
1315
|
+
/**
|
|
1316
|
+
* Secrets for this function, parsed from the project's `/functions/.env`.
|
|
1317
|
+
* Server-only: this file is read at invoke time and never bundled into the
|
|
1318
|
+
* browser app. Empty when no `/functions/.env` exists.
|
|
1319
|
+
*/
|
|
1320
|
+
env: Record<string, string>;
|
|
1321
|
+
/** Metadata about the invoking HTTP request. */
|
|
1322
|
+
request: {
|
|
1323
|
+
method: string;
|
|
1324
|
+
headers: Record<string, string>;
|
|
1325
|
+
};
|
|
1326
|
+
/**
|
|
1327
|
+
* End-user auth forwarded from the caller. `token` is the bearer the browser
|
|
1328
|
+
* client was holding (an end-user access token or the data static key), or
|
|
1329
|
+
* `null` for anonymous calls.
|
|
1330
|
+
*/
|
|
1331
|
+
auth: {
|
|
1332
|
+
token: string | null;
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* The shape a `/functions/<name>.ts` default export must satisfy. Type the
|
|
1337
|
+
* `input` parameter as optional (`input?: Foo`) when callers may omit it.
|
|
1338
|
+
*/
|
|
1339
|
+
type RagableFunctionHandler<Input = any, Output = any> = (input: Input, context: RagableFunctionContext) => Output | Promise<Output>;
|
|
1340
|
+
/**
|
|
1341
|
+
* A project's function map: function name → handler. Generated as `AppFunctions`.
|
|
1342
|
+
* The constraint is intentionally loose (any function shape) so a handler that
|
|
1343
|
+
* deviates from `(input, context)` never breaks the generated client as a whole;
|
|
1344
|
+
* the per-call typing in {@link RagableFunctionCall} adapts to each signature.
|
|
1345
|
+
*/
|
|
1346
|
+
type RagableFunctions = Record<string, (...args: any[]) => any>;
|
|
1347
|
+
/** Permissive default used when no generated `AppFunctions` is supplied. */
|
|
1348
|
+
interface DefaultRagableFunctions {
|
|
1349
|
+
[name: string]: (...args: any[]) => any;
|
|
1350
|
+
}
|
|
1351
|
+
/** Per-call options for an invocation. */
|
|
1352
|
+
interface RagableFunctionInvokeOptions {
|
|
1353
|
+
signal?: AbortSignal;
|
|
1354
|
+
headers?: HeadersInit;
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* The browser-side call signature derived from a server handler `H`: the server
|
|
1358
|
+
* injects `context`, so the caller passes only `input`. `input` is optional when
|
|
1359
|
+
* the handler's input type permits `undefined`.
|
|
1360
|
+
*/
|
|
1361
|
+
type RagableFunctionCall<H> = H extends (input: infer I, ...rest: any[]) => infer R ? undefined extends I ? (input?: I, options?: RagableFunctionInvokeOptions) => Promise<Awaited<R>> : (input: I, options?: RagableFunctionInvokeOptions) => Promise<Awaited<R>> : (input?: unknown, options?: RagableFunctionInvokeOptions) => Promise<unknown>;
|
|
1362
|
+
/**
|
|
1363
|
+
* The type of `client.functions`: a typed callable per function in `F`, plus an
|
|
1364
|
+
* `invoke(name, input?)` escape hatch for dynamic dispatch. (A function literally
|
|
1365
|
+
* named `invoke` is therefore reserved.)
|
|
1366
|
+
*/
|
|
1367
|
+
type FunctionInvoker<F extends RagableFunctions = DefaultRagableFunctions> = {
|
|
1368
|
+
[K in keyof F]: RagableFunctionCall<F[K]>;
|
|
1369
|
+
} & {
|
|
1370
|
+
/** Invoke a function by name. Useful when the name is dynamic. */
|
|
1371
|
+
invoke<Result = unknown>(name: string, input?: unknown, options?: RagableFunctionInvokeOptions): Promise<Result>;
|
|
1372
|
+
};
|
|
1373
|
+
|
|
1292
1374
|
/** Canonical browser/server API base (`…/api`, no trailing slash). */
|
|
1293
1375
|
declare function normalizeBrowserApiBase(): string;
|
|
1294
|
-
type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
|
|
1376
|
+
type BrowserDataAuthMode = "user" | "publicAnon" | "admin" | "auto";
|
|
1295
1377
|
/**
|
|
1296
|
-
* Resolves how database requests are authorized.
|
|
1297
|
-
*
|
|
1298
|
-
*
|
|
1299
|
-
*
|
|
1300
|
-
*
|
|
1378
|
+
* Resolves how database / storage requests are authorized.
|
|
1379
|
+
*
|
|
1380
|
+
* Default (when `dataAuth` is omitted):
|
|
1381
|
+
* - **`auto`** when BOTH a static data key AND user auth (an `authGroupId` or a
|
|
1382
|
+
* `getAccessToken` callback) are configured — the generated-site case. This is
|
|
1383
|
+
* the Supabase model: send the signed-in user's JWT when a session exists, and
|
|
1384
|
+
* fall back to the public anon key for logged-out visitors. Without this, a
|
|
1385
|
+
* shipped anon key permanently shadows the user session, so owner/group/claim/
|
|
1386
|
+
* authenticated collection grants can never match a signed-in user.
|
|
1387
|
+
* - **`publicAnon`** when only a static key is configured (no auth group) — a
|
|
1388
|
+
* purely public app.
|
|
1389
|
+
* - **`user`** when neither — JWT-only.
|
|
1390
|
+
*
|
|
1391
|
+
* Set `dataAuth` explicitly to override: `"user"` (JWT required), `"publicAnon"`
|
|
1392
|
+
* (anon key only, never upgrade), or `"admin"` (the static key is a data-admin key).
|
|
1301
1393
|
*/
|
|
1302
1394
|
declare function effectiveDataAuth(options: RagableBrowserClientOptions): BrowserDataAuthMode;
|
|
1303
1395
|
interface RagableBrowserClientOptions {
|
|
@@ -1412,6 +1504,12 @@ declare class RagableBrowserAuthClient<AuthUser extends object = DefaultAuthUser
|
|
|
1412
1504
|
getSession(): Promise<PostgrestResult<{
|
|
1413
1505
|
session: AuthSession<AuthUser> | null;
|
|
1414
1506
|
}>>;
|
|
1507
|
+
/**
|
|
1508
|
+
* Returns a valid (auto-refreshed) access token for the current session, or
|
|
1509
|
+
* `null` if signed out. The sanctioned way to obtain a token for a hand-rolled
|
|
1510
|
+
* `fetch` to a custom endpoint — never read tokens out of storage yourself.
|
|
1511
|
+
*/
|
|
1512
|
+
getValidAccessToken(): Promise<string | null>;
|
|
1415
1513
|
}
|
|
1416
1514
|
interface BrowserSqlQueryParams {
|
|
1417
1515
|
databaseInstanceId?: string;
|
|
@@ -1507,6 +1605,15 @@ type CollectionRowWithMeta<Row extends Record<string, unknown> = Record<string,
|
|
|
1507
1605
|
};
|
|
1508
1606
|
declare function collectionRecordToRowWithMeta<Row extends Record<string, unknown>>(record: BrowserCollectionRecord<Row>): CollectionRowWithMeta<Row>;
|
|
1509
1607
|
declare function collectionRecordsToRowWithMeta<Row extends Record<string, unknown>>(records: BrowserCollectionRecord<Row>[]): CollectionRowWithMeta<Row>[];
|
|
1608
|
+
/**
|
|
1609
|
+
* Rows returned by a find: {@link CollectionRowWithMeta} when the params carry
|
|
1610
|
+
* a literal `return: "flat"`, envelope {@link BrowserCollectionRecord}s
|
|
1611
|
+
* otherwise. Keeps the default (envelope) call sites free of union-narrowing —
|
|
1612
|
+
* `res.data[0].data` typechecks without a cast.
|
|
1613
|
+
*/
|
|
1614
|
+
type CollectionFindResult<Row extends Record<string, unknown>, Params> = Params extends {
|
|
1615
|
+
return: "flat";
|
|
1616
|
+
} ? CollectionRowWithMeta<Row>[] : BrowserCollectionRecord<Row>[];
|
|
1510
1617
|
type BrowserCollectionFindParams<Row extends Record<string, unknown> = Record<string, unknown>> = {
|
|
1511
1618
|
where?: WhereInput<Row>;
|
|
1512
1619
|
filters?: Array<{
|
|
@@ -1537,11 +1644,11 @@ declare class BrowserCollectionApi<Row extends Record<string, unknown> = Record<
|
|
|
1537
1644
|
* Query collection rows. Prefer this over the deprecated `find` alias.
|
|
1538
1645
|
* Use `return: "flat"` to get {@link CollectionRowWithMeta} without nested `.data`.
|
|
1539
1646
|
*/
|
|
1540
|
-
findMany:
|
|
1647
|
+
findMany: <Params extends WhereInput<RowD<Row>> | BrowserCollectionFindParams<RowD<Row>>>(whereOrParams?: Params) => Promise<PostgrestResult<CollectionFindResult<RowD<Row>, Params>>>;
|
|
1541
1648
|
/**
|
|
1542
1649
|
* @deprecated Use {@link BrowserCollectionApi.findMany} — same behavior.
|
|
1543
1650
|
*/
|
|
1544
|
-
find:
|
|
1651
|
+
find: <Params extends WhereInput<RowD<Row>> | BrowserCollectionFindParams<RowD<Row>>>(whereOrParams?: Params) => Promise<PostgrestResult<CollectionFindResult<RowD<Row>, Params>>>;
|
|
1545
1652
|
/**
|
|
1546
1653
|
* At most one row, `data` is the record or `null` if none match (not an error).
|
|
1547
1654
|
*/
|
|
@@ -1762,10 +1869,24 @@ declare class BrowserStorageBucketClient {
|
|
|
1762
1869
|
private readonly options;
|
|
1763
1870
|
private readonly fetchImpl;
|
|
1764
1871
|
private readonly bucketId;
|
|
1765
|
-
|
|
1872
|
+
private readonly ragableAuth;
|
|
1873
|
+
constructor(options: RagableBrowserClientOptions, fetchImpl: typeof fetch, bucketId: string, ragableAuth?: RagableAuth | null);
|
|
1766
1874
|
private get authGroupId();
|
|
1767
1875
|
private base;
|
|
1876
|
+
/**
|
|
1877
|
+
* Same credential resolution as the database client (see resolveDatabaseAuthBearer):
|
|
1878
|
+
* in the generated-site default (`auto`), a signed-in user's auto-refreshed JWT
|
|
1879
|
+
* is used so storage calls carry the user's identity; logged-out visitors fall
|
|
1880
|
+
* back to the anon key. Previously storage ignored the managed session entirely.
|
|
1881
|
+
*/
|
|
1768
1882
|
private bearerToken;
|
|
1883
|
+
/**
|
|
1884
|
+
* The storage backend has historically returned HTTP 200 with an `{ error }`
|
|
1885
|
+
* body on some failures; without this guard the SDK would resolve those as
|
|
1886
|
+
* successful uploads/deletes. Treat any 2xx whose body carries a non-empty
|
|
1887
|
+
* `error` as a failure.
|
|
1888
|
+
*/
|
|
1889
|
+
private assertNoEmbeddedError;
|
|
1769
1890
|
private req;
|
|
1770
1891
|
list(params?: {
|
|
1771
1892
|
prefix?: string;
|
|
@@ -1834,7 +1955,8 @@ declare class BrowserStorageBucketClient {
|
|
|
1834
1955
|
declare class RagableBrowserStorageClient {
|
|
1835
1956
|
private readonly options;
|
|
1836
1957
|
private readonly fetchImpl;
|
|
1837
|
-
|
|
1958
|
+
private readonly ragableAuth;
|
|
1959
|
+
constructor(options: RagableBrowserClientOptions, fetchImpl: typeof fetch, ragableAuth?: RagableAuth | null);
|
|
1838
1960
|
from(bucketId: string): BrowserStorageBucketClient;
|
|
1839
1961
|
}
|
|
1840
1962
|
interface MailSendParams {
|
|
@@ -1930,6 +2052,33 @@ declare class RagableBrowserMailClient {
|
|
|
1930
2052
|
/** Fetch a single message in full (headers + decoded text/html body). */
|
|
1931
2053
|
getMessage(messageId: string): Promise<MailMessageDetail>;
|
|
1932
2054
|
}
|
|
2055
|
+
/**
|
|
2056
|
+
* Invokes the project's backend edge functions (handlers in `/functions/<name>.ts`).
|
|
2057
|
+
*
|
|
2058
|
+
* Exposed on the client as a typed Proxy — `client.functions.<name>(input)` — so
|
|
2059
|
+
* each generated function name is a direct callable. Functions run server-side,
|
|
2060
|
+
* so calls can use secrets and reach any external API without browser CORS limits.
|
|
2061
|
+
*/
|
|
2062
|
+
declare class RagableBrowserFunctionsClient {
|
|
2063
|
+
private readonly options;
|
|
2064
|
+
private readonly auth;
|
|
2065
|
+
private readonly fetchImpl;
|
|
2066
|
+
constructor(options: RagableBrowserClientOptions, auth: RagableAuth | null);
|
|
2067
|
+
private requireWebsiteId;
|
|
2068
|
+
private toUrl;
|
|
2069
|
+
/**
|
|
2070
|
+
* Best-effort end-user bearer, forwarded to the function as `context.auth.token`.
|
|
2071
|
+
* Functions are public, so this never throws — anonymous calls send no token.
|
|
2072
|
+
*/
|
|
2073
|
+
private getOptionalToken;
|
|
2074
|
+
/**
|
|
2075
|
+
* Invoke a function by name. Prefer the typed `client.functions.<name>(input)`
|
|
2076
|
+
* accessors; use this when the name is dynamic.
|
|
2077
|
+
*/
|
|
2078
|
+
invoke<Result = unknown>(name: string, input?: unknown, options?: RagableFunctionInvokeOptions): Promise<Result>;
|
|
2079
|
+
/** Build the typed Proxy exposed as `client.functions`. */
|
|
2080
|
+
asInvoker<F extends RagableFunctions = DefaultRagableFunctions>(): FunctionInvoker<F>;
|
|
2081
|
+
}
|
|
1933
2082
|
interface AgentConversationMessage {
|
|
1934
2083
|
role: "user" | "assistant";
|
|
1935
2084
|
content: string;
|
|
@@ -2062,7 +2211,7 @@ interface AgentPublicChatParams extends AgentChatParams {
|
|
|
2062
2211
|
triggerSubtype?: string;
|
|
2063
2212
|
triggerNodeId?: string;
|
|
2064
2213
|
}
|
|
2065
|
-
declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser> {
|
|
2214
|
+
declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions> {
|
|
2066
2215
|
readonly agents: RagableBrowserAgentsClient;
|
|
2067
2216
|
readonly ai: RagableBrowserAiClient;
|
|
2068
2217
|
readonly auth: RagableBrowserAuthClient<AuthUser>;
|
|
@@ -2070,14 +2219,26 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
|
|
|
2070
2219
|
readonly db: RagableBrowserDatabaseClient<Database>;
|
|
2071
2220
|
readonly storage: RagableBrowserStorageClient;
|
|
2072
2221
|
readonly mail: RagableBrowserMailClient;
|
|
2222
|
+
/**
|
|
2223
|
+
* Backend edge functions — call a `/functions/<name>.ts` handler with
|
|
2224
|
+
* `client.functions.<name>(input)`. Runs server-side. See {@link FunctionInvoker}.
|
|
2225
|
+
*/
|
|
2226
|
+
readonly functions: FunctionInvoker<Functions>;
|
|
2073
2227
|
readonly transport: Transport;
|
|
2074
2228
|
private readonly _ragableAuth;
|
|
2075
2229
|
constructor(options: RagableBrowserClientOptions);
|
|
2076
2230
|
/** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
|
|
2077
2231
|
from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
|
|
2232
|
+
/**
|
|
2233
|
+
* Resolves once the persisted session has been restored (and refreshed if it
|
|
2234
|
+
* was expired). Await this before reading auth state at startup to avoid a
|
|
2235
|
+
* logged-out flash, e.g. `const session = await client.ready()`. Resolves
|
|
2236
|
+
* `null` when no auth group is configured or no session is stored.
|
|
2237
|
+
*/
|
|
2238
|
+
ready(): Promise<AuthSession<AuthUser> | null>;
|
|
2078
2239
|
destroy(): void;
|
|
2079
2240
|
}
|
|
2080
|
-
declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
2241
|
+
declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser, Functions>;
|
|
2081
2242
|
declare const createRagableBrowserClient: typeof createBrowserClient;
|
|
2082
2243
|
|
|
2083
2244
|
/**
|
|
@@ -2092,45 +2253,6 @@ declare function parseSseDataLine(line: string): SseJsonEvent | null;
|
|
|
2092
2253
|
*/
|
|
2093
2254
|
declare function readSseStream(body: ReadableStream<Uint8Array>): AsyncGenerator<SseJsonEvent, void, undefined>;
|
|
2094
2255
|
|
|
2095
|
-
/**
|
|
2096
|
-
* Convert SDK-shape multimodal content to the OpenAI/Fireworks `image_url`
|
|
2097
|
-
* wire format the Ragable inference proxy expects. Keeps the public SDK
|
|
2098
|
-
* types Vercel-AI-SDK-shaped (`{ type: "image", image: ... }`) while the
|
|
2099
|
-
* over-the-wire shape stays OpenAI canonical.
|
|
2100
|
-
*/
|
|
2101
|
-
|
|
2102
|
-
/** OpenAI/Fireworks image content part — what flows on the wire. */
|
|
2103
|
-
interface WireImagePart {
|
|
2104
|
-
type: "image_url";
|
|
2105
|
-
image_url: {
|
|
2106
|
-
url: string;
|
|
2107
|
-
detail?: "auto" | "low" | "high";
|
|
2108
|
-
};
|
|
2109
|
-
}
|
|
2110
|
-
type WireTextPart = {
|
|
2111
|
-
type: "text";
|
|
2112
|
-
text: string;
|
|
2113
|
-
};
|
|
2114
|
-
type WireContentPart = WireTextPart | WireImagePart;
|
|
2115
|
-
type WireUserContent = string | WireContentPart[];
|
|
2116
|
-
/**
|
|
2117
|
-
* Convert a single `UserContent` value to wire shape. Strings pass through
|
|
2118
|
-
* unchanged so existing callers keep producing byte-identical request bodies.
|
|
2119
|
-
*/
|
|
2120
|
-
declare function toWireUserContent(content: UserContent): WireUserContent;
|
|
2121
|
-
/**
|
|
2122
|
-
* Resolve an `ImagePart.image` value into a URL string suitable for
|
|
2123
|
-
* `image_url.url`. URLs pass through; binary and raw base64 are wrapped
|
|
2124
|
-
* into a data URL.
|
|
2125
|
-
*/
|
|
2126
|
-
declare function imagePartToUrl(part: ImagePart): string;
|
|
2127
|
-
/**
|
|
2128
|
-
* Cross-runtime `Uint8Array → base64`. `btoa(String.fromCharCode(...bytes))`
|
|
2129
|
-
* trips the JS call-stack limit on large payloads, so we chunk the binary
|
|
2130
|
-
* string. Works in browser, Node 18+, Edge, and Bun.
|
|
2131
|
-
*/
|
|
2132
|
-
declare function bytesToBase64(bytes: Uint8Array): string;
|
|
2133
|
-
|
|
2134
2256
|
/**
|
|
2135
2257
|
* Best-effort parser for incomplete JSON streamed token-by-token from an LLM.
|
|
2136
2258
|
*
|
|
@@ -2147,6 +2269,6 @@ declare function bytesToBase64(bytes: Uint8Array): string;
|
|
|
2147
2269
|
*/
|
|
2148
2270
|
declare function tryParsePartialJson(text: string): unknown | undefined;
|
|
2149
2271
|
|
|
2150
|
-
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
2272
|
+
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser, Functions>;
|
|
2151
2273
|
|
|
2152
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FinishReason, type
|
|
2274
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type DefaultRagableFunctions, type FinishReason, type FunctionInvoker, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserFunctionsClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, type RagableFunctionCall, type RagableFunctionContext, type RagableFunctionHandler, type RagableFunctionInvokeOptions, type RagableFunctions, RagableNetworkError, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
|