@ragable/sdk 0.3.0 → 0.4.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 +204 -23
- package/dist/index.d.ts +204 -23
- package/dist/index.js +513 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +504 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -54,6 +54,11 @@ type TablesUpdate<D extends RagableDatabase, TableName extends keyof D["public"]
|
|
|
54
54
|
Update: infer U;
|
|
55
55
|
} ? U extends Record<string, unknown> ? U : Record<string, unknown> : Partial<Tables<D, TableName>>;
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Native `fetch` must not be called as a detached reference (`const f = fetch; f(url)`),
|
|
59
|
+
* or the browser throws **Illegal invocation**. Use this for defaults and for `options.fetch`.
|
|
60
|
+
*/
|
|
61
|
+
declare function bindFetch(custom?: typeof fetch): typeof fetch;
|
|
57
62
|
interface RagableClientOptions {
|
|
58
63
|
apiKey: string;
|
|
59
64
|
baseUrl?: string;
|
|
@@ -222,6 +227,107 @@ declare class AgentsClient {
|
|
|
222
227
|
chatStream(agentId: string, params: AgentChatParams): AsyncGenerator<AgentStreamEvent, void, undefined>;
|
|
223
228
|
}
|
|
224
229
|
|
|
230
|
+
/** Shared with {@link RagableBrowserDatabaseClient.query} — duplicated to avoid circular imports. */
|
|
231
|
+
interface BrowserSqlExecParams {
|
|
232
|
+
databaseInstanceId: string;
|
|
233
|
+
sql: string;
|
|
234
|
+
params?: unknown[];
|
|
235
|
+
readOnly?: boolean;
|
|
236
|
+
timeoutMs?: number;
|
|
237
|
+
rowLimit?: number;
|
|
238
|
+
}
|
|
239
|
+
interface BrowserSqlExecResult<Row extends Record<string, unknown> = Record<string, unknown>> {
|
|
240
|
+
command: string;
|
|
241
|
+
rowCount: number;
|
|
242
|
+
truncated: boolean;
|
|
243
|
+
rows: Row[];
|
|
244
|
+
}
|
|
245
|
+
type PostgrestResult<T> = {
|
|
246
|
+
data: T;
|
|
247
|
+
error: null;
|
|
248
|
+
} | {
|
|
249
|
+
data: null;
|
|
250
|
+
error: RagableError;
|
|
251
|
+
};
|
|
252
|
+
/** Map async throws to `{ data, error }` like Supabase JS client. */
|
|
253
|
+
declare function asPostgrestResponse<T>(fn: () => Promise<T>): Promise<PostgrestResult<T>>;
|
|
254
|
+
type RunQuery = <R extends Record<string, unknown> = Record<string, unknown>>(p: BrowserSqlExecParams) => Promise<BrowserSqlExecResult<R>>;
|
|
255
|
+
/** Supabase/PostgREST-style read builder: `.from('t').select().eq().single()` */
|
|
256
|
+
declare class PostgrestSelectBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
|
|
257
|
+
private readonly run;
|
|
258
|
+
private readonly databaseInstanceId;
|
|
259
|
+
private readonly table;
|
|
260
|
+
private readonly columns;
|
|
261
|
+
private filters;
|
|
262
|
+
private _limit?;
|
|
263
|
+
private _order?;
|
|
264
|
+
constructor(run: RunQuery, databaseInstanceId: string, table: string, columns: string);
|
|
265
|
+
eq(column: string, value: unknown): this;
|
|
266
|
+
neq(column: string, value: unknown): this;
|
|
267
|
+
gt(column: string, value: unknown): this;
|
|
268
|
+
gte(column: string, value: unknown): this;
|
|
269
|
+
lt(column: string, value: unknown): this;
|
|
270
|
+
lte(column: string, value: unknown): this;
|
|
271
|
+
like(column: string, value: unknown): this;
|
|
272
|
+
ilike(column: string, value: unknown): this;
|
|
273
|
+
limit(n: number): this;
|
|
274
|
+
order(column: string, options?: {
|
|
275
|
+
ascending?: boolean;
|
|
276
|
+
}): this;
|
|
277
|
+
/** @param includeUserLimit when false, omit `.limit()` (for `.single()` / `.maybeSingle()`). */
|
|
278
|
+
private buildSelectCore;
|
|
279
|
+
then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
280
|
+
private executeMany;
|
|
281
|
+
single(): Promise<PostgrestResult<Row>>;
|
|
282
|
+
maybeSingle(): Promise<PostgrestResult<Row | null>>;
|
|
283
|
+
}
|
|
284
|
+
declare class PostgrestInsertBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
|
|
285
|
+
private readonly run;
|
|
286
|
+
private readonly databaseInstanceId;
|
|
287
|
+
private readonly table;
|
|
288
|
+
private readonly rows;
|
|
289
|
+
private returning;
|
|
290
|
+
constructor(run: RunQuery, databaseInstanceId: string, table: string, rows: Record<string, unknown>[]);
|
|
291
|
+
select(columns?: string): this;
|
|
292
|
+
then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
293
|
+
private execute;
|
|
294
|
+
}
|
|
295
|
+
declare class PostgrestUpdateBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
|
|
296
|
+
private readonly run;
|
|
297
|
+
private readonly databaseInstanceId;
|
|
298
|
+
private readonly table;
|
|
299
|
+
private readonly patch;
|
|
300
|
+
private filters;
|
|
301
|
+
private returning;
|
|
302
|
+
constructor(run: RunQuery, databaseInstanceId: string, table: string, patch: Record<string, unknown>);
|
|
303
|
+
eq(column: string, value: unknown): this;
|
|
304
|
+
select(columns?: string): this;
|
|
305
|
+
then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
306
|
+
private execute;
|
|
307
|
+
}
|
|
308
|
+
declare class PostgrestDeleteBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
|
|
309
|
+
private readonly run;
|
|
310
|
+
private readonly databaseInstanceId;
|
|
311
|
+
private readonly table;
|
|
312
|
+
private filters;
|
|
313
|
+
private returning;
|
|
314
|
+
constructor(run: RunQuery, databaseInstanceId: string, table: string);
|
|
315
|
+
eq(column: string, value: unknown): this;
|
|
316
|
+
select(columns?: string): this;
|
|
317
|
+
then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
318
|
+
private execute;
|
|
319
|
+
}
|
|
320
|
+
declare class PostgrestTableApi<Row extends Record<string, unknown> = Record<string, unknown>> {
|
|
321
|
+
private readonly run;
|
|
322
|
+
private readonly databaseInstanceId;
|
|
323
|
+
private readonly table;
|
|
324
|
+
constructor(run: RunQuery, databaseInstanceId: string, table: string);
|
|
325
|
+
select(columns?: string): PostgrestSelectBuilder<Row>;
|
|
326
|
+
insert(values: Record<string, unknown> | Record<string, unknown>[]): PostgrestInsertBuilder<Row>;
|
|
327
|
+
update(patch: Record<string, unknown>): PostgrestUpdateBuilder<Row>;
|
|
328
|
+
delete(): PostgrestDeleteBuilder<Row>;
|
|
329
|
+
}
|
|
330
|
+
|
|
225
331
|
declare function normalizeBrowserApiBase(baseUrl?: string): string;
|
|
226
332
|
interface RagableBrowserClientOptions {
|
|
227
333
|
/** Organization id (UUID) — public agent chat URLs. */
|
|
@@ -231,6 +337,10 @@ interface RagableBrowserClientOptions {
|
|
|
231
337
|
* {@link RagableBrowserDatabaseClient}.
|
|
232
338
|
*/
|
|
233
339
|
authGroupId?: string;
|
|
340
|
+
/**
|
|
341
|
+
* Default Backspace SQL instance id for {@link RagableBrowser.from} (Supabase-style table API).
|
|
342
|
+
*/
|
|
343
|
+
databaseInstanceId?: string;
|
|
234
344
|
/**
|
|
235
345
|
* Returns the end-user access JWT (from login/register/refresh).
|
|
236
346
|
* Required for `auth.getMe`, `auth.updateMe`, and `database.query`.
|
|
@@ -256,14 +366,72 @@ interface BrowserAuthTokens {
|
|
|
256
366
|
refreshToken: string;
|
|
257
367
|
expiresIn: string;
|
|
258
368
|
}
|
|
259
|
-
/**
|
|
369
|
+
/** Supabase-compatible session shape (snake_case tokens). */
|
|
370
|
+
interface SupabaseCompatSession<AuthUser extends Record<string, unknown> = Record<string, unknown>> {
|
|
371
|
+
access_token: string;
|
|
372
|
+
refresh_token: string;
|
|
373
|
+
/** Best-effort seconds from Ragable `expiresIn` (e.g. `7d`, `3600`). */
|
|
374
|
+
expires_in: number;
|
|
375
|
+
token_type: "bearer";
|
|
376
|
+
user: AuthUser;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** End-user auth — Ragable names + Supabase/Firebase-style aliases returning `{ data, error }`. */
|
|
260
380
|
declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown> = Record<string, unknown>> {
|
|
261
381
|
private readonly options;
|
|
382
|
+
private readonly fetchImpl;
|
|
262
383
|
constructor(options: RagableBrowserClientOptions);
|
|
263
|
-
private get fetchImpl();
|
|
264
384
|
private toUrl;
|
|
265
385
|
private baseHeaders;
|
|
266
386
|
private authPrefix;
|
|
387
|
+
/** Supabase: `signUp` → `{ data: { user, session }, error }` */
|
|
388
|
+
signUp(credentials: {
|
|
389
|
+
email: string;
|
|
390
|
+
password: string;
|
|
391
|
+
options?: {
|
|
392
|
+
data?: Record<string, unknown>;
|
|
393
|
+
};
|
|
394
|
+
}): Promise<PostgrestResult<{
|
|
395
|
+
user: AuthUser;
|
|
396
|
+
session: SupabaseCompatSession<AuthUser>;
|
|
397
|
+
}>>;
|
|
398
|
+
/** Supabase: `signInWithPassword` */
|
|
399
|
+
signInWithPassword(credentials: {
|
|
400
|
+
email: string;
|
|
401
|
+
password: string;
|
|
402
|
+
}): Promise<PostgrestResult<{
|
|
403
|
+
user: AuthUser;
|
|
404
|
+
session: SupabaseCompatSession<AuthUser>;
|
|
405
|
+
}>>;
|
|
406
|
+
/** Supabase: `refreshSession` */
|
|
407
|
+
refreshSession(refreshToken: string): Promise<PostgrestResult<{
|
|
408
|
+
session: SupabaseCompatSession<AuthUser>;
|
|
409
|
+
user: AuthUser;
|
|
410
|
+
}>>;
|
|
411
|
+
/** Supabase: `getUser()` — needs `getAccessToken` on the client */
|
|
412
|
+
getUser(): Promise<PostgrestResult<{
|
|
413
|
+
user: AuthUser;
|
|
414
|
+
}>>;
|
|
415
|
+
/** Supabase: `updateUser` */
|
|
416
|
+
updateUser(attributes: {
|
|
417
|
+
email?: string;
|
|
418
|
+
password?: string;
|
|
419
|
+
data?: {
|
|
420
|
+
name?: string | null;
|
|
421
|
+
};
|
|
422
|
+
}): Promise<PostgrestResult<{
|
|
423
|
+
user: AuthUser;
|
|
424
|
+
}>>;
|
|
425
|
+
/**
|
|
426
|
+
* Supabase/Firebase: no server call — clear tokens in your app.
|
|
427
|
+
* Returns `{ error: null }` for API compatibility.
|
|
428
|
+
*/
|
|
429
|
+
signOut(_options?: {
|
|
430
|
+
scope?: "global" | "local";
|
|
431
|
+
}): Promise<{
|
|
432
|
+
error: null;
|
|
433
|
+
}>;
|
|
434
|
+
private getUserFromToken;
|
|
267
435
|
register(body: {
|
|
268
436
|
email: string;
|
|
269
437
|
password: string;
|
|
@@ -290,8 +458,11 @@ interface BrowserSqlQueryParams {
|
|
|
290
458
|
databaseInstanceId: string;
|
|
291
459
|
sql: string;
|
|
292
460
|
params?: unknown[];
|
|
293
|
-
/**
|
|
294
|
-
|
|
461
|
+
/**
|
|
462
|
+
* Default `true`. When `false`, the API allows INSERT/UPDATE/DELETE (and existing safe reads);
|
|
463
|
+
* DDL (`CREATE`/`DROP`/`ALTER`/…) and privilege changes remain blocked.
|
|
464
|
+
*/
|
|
465
|
+
readOnly?: boolean;
|
|
295
466
|
timeoutMs?: number;
|
|
296
467
|
rowLimit?: number;
|
|
297
468
|
}
|
|
@@ -302,16 +473,13 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
|
|
|
302
473
|
rows: Row[];
|
|
303
474
|
}
|
|
304
475
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
* Pass `createBrowserClient<YourDatabase>()` and use `query<Tables<YourDatabase, 't'>>()`
|
|
309
|
-
* for Supabase-style row typing.
|
|
476
|
+
* Raw SQL against linked Postgres (escape hatch). Prefer {@link RagableBrowser.from} for
|
|
477
|
+
* Supabase-style `.select()` / `.insert()` / `.update()` / `.delete()`.
|
|
310
478
|
*/
|
|
311
479
|
declare class RagableBrowserDatabaseClient<_Schema extends RagableDatabase = DefaultRagableDatabase> {
|
|
312
480
|
private readonly options;
|
|
481
|
+
private readonly fetchImpl;
|
|
313
482
|
constructor(options: RagableBrowserClientOptions);
|
|
314
|
-
private get fetchImpl();
|
|
315
483
|
private toUrl;
|
|
316
484
|
query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row>>;
|
|
317
485
|
private baseHeaders;
|
|
@@ -322,8 +490,8 @@ declare class RagableBrowserDatabaseClient<_Schema extends RagableDatabase = Def
|
|
|
322
490
|
*/
|
|
323
491
|
declare class RagableBrowserAgentsClient {
|
|
324
492
|
private readonly options;
|
|
493
|
+
private readonly fetchImpl;
|
|
325
494
|
constructor(options: RagableBrowserClientOptions);
|
|
326
|
-
private get fetchImpl();
|
|
327
495
|
private toUrl;
|
|
328
496
|
/**
|
|
329
497
|
* Stream agent execution as SSE (`POST /public/organizations/:orgId/agents/:agentId/chat/stream`).
|
|
@@ -336,24 +504,28 @@ interface AgentPublicChatParams extends AgentChatParams {
|
|
|
336
504
|
triggerNodeId?: string;
|
|
337
505
|
}
|
|
338
506
|
/**
|
|
339
|
-
* Browser client
|
|
340
|
-
*
|
|
507
|
+
* Browser client: mirrors **Supabase JS** (`createClient`, `.from()`, `.auth.signInWithPassword`, `{ data, error }`)
|
|
508
|
+
* plus Ragable **`agents.chatStream`**. Server secrets: {@link createRagableServerClient} / {@link createClient} with `apiKey`.
|
|
341
509
|
*/
|
|
342
510
|
declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>> {
|
|
343
511
|
readonly agents: RagableBrowserAgentsClient;
|
|
344
512
|
readonly auth: RagableBrowserAuthClient<AuthUser>;
|
|
345
513
|
readonly database: RagableBrowserDatabaseClient<Database>;
|
|
514
|
+
private readonly options;
|
|
346
515
|
constructor(options: RagableBrowserClientOptions);
|
|
516
|
+
/**
|
|
517
|
+
* Supabase-style table API: `.from('items').select().eq('id', 1).single()`.
|
|
518
|
+
* Pass `databaseInstanceId` here or set `databaseInstanceId` on the client options.
|
|
519
|
+
*/
|
|
520
|
+
from<Row extends Record<string, unknown> = Record<string, unknown>>(table: string, databaseInstanceId?: string): PostgrestTableApi<Row>;
|
|
347
521
|
}
|
|
348
522
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* - {@link RagableBrowser.auth} / {@link RagableBrowser.database} — need `authGroupId` (+ `getAccessToken` for protected calls).
|
|
352
|
-
*
|
|
353
|
-
* Pass schema and user types like Supabase: `createBrowserClient<Database, AuthUser>({ ... })`.
|
|
354
|
-
* For Shift and `/v1/*`, use {@link createClient} on a server.
|
|
523
|
+
* **Supabase-equivalent** browser client factory (no org API key).
|
|
524
|
+
* Same as {@link createRagableBrowserClient}.
|
|
355
525
|
*/
|
|
356
526
|
declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
527
|
+
/** Alias for {@link createBrowserClient} — matches Supabase `createClient` naming. */
|
|
528
|
+
declare const createRagableBrowserClient: typeof createBrowserClient;
|
|
357
529
|
|
|
358
530
|
/**
|
|
359
531
|
* Shared SSE parsing for `data: {json}` lines (Ragable agent streams).
|
|
@@ -427,10 +599,19 @@ declare class Ragable {
|
|
|
427
599
|
constructor(options: RagableClientOptions);
|
|
428
600
|
}
|
|
429
601
|
/**
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
602
|
+
* **Supabase-style overloads**
|
|
603
|
+
* - `createClient(RAGABLE_URL, { organizationId, authGroupId, … })` — browser (no API key)
|
|
604
|
+
* - `createClient({ apiKey, baseUrl })` — server / Engine (secret key)
|
|
605
|
+
*
|
|
606
|
+
* Prefer {@link createRagableServerClient} in backend code if the dual overload is confusing.
|
|
433
607
|
*/
|
|
608
|
+
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(url: string, options: Omit<RagableBrowserClientOptions, "baseUrl">): RagableBrowser<Database, AuthUser>;
|
|
434
609
|
declare function createClient(options: RagableClientOptions): Ragable;
|
|
610
|
+
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
611
|
+
/**
|
|
612
|
+
* Explicit **server** factory — same as `createClient({ apiKey, baseUrl })`.
|
|
613
|
+
* Use in the Engine; never import alongside browser `createClient(url, …)` if you want tree-shaking clarity.
|
|
614
|
+
*/
|
|
615
|
+
declare function createRagableServerClient(options: RagableClientOptions): Ragable;
|
|
435
616
|
|
|
436
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type DefaultRagableDatabase, type FormatContextOptions, type Json, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RequestOptions, type RetrieveParams, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type Tables, type TablesInsert, type TablesUpdate, createBrowserClient, createClient, createRagPipeline, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };
|
|
617
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type DefaultRagableDatabase, type FormatContextOptions, type Json, PostgrestDeleteBuilder, PostgrestInsertBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RequestOptions, type RetrieveParams, type RunQuery, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type Tables, type TablesInsert, type TablesUpdate, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };
|
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,11 @@ type TablesUpdate<D extends RagableDatabase, TableName extends keyof D["public"]
|
|
|
54
54
|
Update: infer U;
|
|
55
55
|
} ? U extends Record<string, unknown> ? U : Record<string, unknown> : Partial<Tables<D, TableName>>;
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Native `fetch` must not be called as a detached reference (`const f = fetch; f(url)`),
|
|
59
|
+
* or the browser throws **Illegal invocation**. Use this for defaults and for `options.fetch`.
|
|
60
|
+
*/
|
|
61
|
+
declare function bindFetch(custom?: typeof fetch): typeof fetch;
|
|
57
62
|
interface RagableClientOptions {
|
|
58
63
|
apiKey: string;
|
|
59
64
|
baseUrl?: string;
|
|
@@ -222,6 +227,107 @@ declare class AgentsClient {
|
|
|
222
227
|
chatStream(agentId: string, params: AgentChatParams): AsyncGenerator<AgentStreamEvent, void, undefined>;
|
|
223
228
|
}
|
|
224
229
|
|
|
230
|
+
/** Shared with {@link RagableBrowserDatabaseClient.query} — duplicated to avoid circular imports. */
|
|
231
|
+
interface BrowserSqlExecParams {
|
|
232
|
+
databaseInstanceId: string;
|
|
233
|
+
sql: string;
|
|
234
|
+
params?: unknown[];
|
|
235
|
+
readOnly?: boolean;
|
|
236
|
+
timeoutMs?: number;
|
|
237
|
+
rowLimit?: number;
|
|
238
|
+
}
|
|
239
|
+
interface BrowserSqlExecResult<Row extends Record<string, unknown> = Record<string, unknown>> {
|
|
240
|
+
command: string;
|
|
241
|
+
rowCount: number;
|
|
242
|
+
truncated: boolean;
|
|
243
|
+
rows: Row[];
|
|
244
|
+
}
|
|
245
|
+
type PostgrestResult<T> = {
|
|
246
|
+
data: T;
|
|
247
|
+
error: null;
|
|
248
|
+
} | {
|
|
249
|
+
data: null;
|
|
250
|
+
error: RagableError;
|
|
251
|
+
};
|
|
252
|
+
/** Map async throws to `{ data, error }` like Supabase JS client. */
|
|
253
|
+
declare function asPostgrestResponse<T>(fn: () => Promise<T>): Promise<PostgrestResult<T>>;
|
|
254
|
+
type RunQuery = <R extends Record<string, unknown> = Record<string, unknown>>(p: BrowserSqlExecParams) => Promise<BrowserSqlExecResult<R>>;
|
|
255
|
+
/** Supabase/PostgREST-style read builder: `.from('t').select().eq().single()` */
|
|
256
|
+
declare class PostgrestSelectBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
|
|
257
|
+
private readonly run;
|
|
258
|
+
private readonly databaseInstanceId;
|
|
259
|
+
private readonly table;
|
|
260
|
+
private readonly columns;
|
|
261
|
+
private filters;
|
|
262
|
+
private _limit?;
|
|
263
|
+
private _order?;
|
|
264
|
+
constructor(run: RunQuery, databaseInstanceId: string, table: string, columns: string);
|
|
265
|
+
eq(column: string, value: unknown): this;
|
|
266
|
+
neq(column: string, value: unknown): this;
|
|
267
|
+
gt(column: string, value: unknown): this;
|
|
268
|
+
gte(column: string, value: unknown): this;
|
|
269
|
+
lt(column: string, value: unknown): this;
|
|
270
|
+
lte(column: string, value: unknown): this;
|
|
271
|
+
like(column: string, value: unknown): this;
|
|
272
|
+
ilike(column: string, value: unknown): this;
|
|
273
|
+
limit(n: number): this;
|
|
274
|
+
order(column: string, options?: {
|
|
275
|
+
ascending?: boolean;
|
|
276
|
+
}): this;
|
|
277
|
+
/** @param includeUserLimit when false, omit `.limit()` (for `.single()` / `.maybeSingle()`). */
|
|
278
|
+
private buildSelectCore;
|
|
279
|
+
then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
280
|
+
private executeMany;
|
|
281
|
+
single(): Promise<PostgrestResult<Row>>;
|
|
282
|
+
maybeSingle(): Promise<PostgrestResult<Row | null>>;
|
|
283
|
+
}
|
|
284
|
+
declare class PostgrestInsertBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
|
|
285
|
+
private readonly run;
|
|
286
|
+
private readonly databaseInstanceId;
|
|
287
|
+
private readonly table;
|
|
288
|
+
private readonly rows;
|
|
289
|
+
private returning;
|
|
290
|
+
constructor(run: RunQuery, databaseInstanceId: string, table: string, rows: Record<string, unknown>[]);
|
|
291
|
+
select(columns?: string): this;
|
|
292
|
+
then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
293
|
+
private execute;
|
|
294
|
+
}
|
|
295
|
+
declare class PostgrestUpdateBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
|
|
296
|
+
private readonly run;
|
|
297
|
+
private readonly databaseInstanceId;
|
|
298
|
+
private readonly table;
|
|
299
|
+
private readonly patch;
|
|
300
|
+
private filters;
|
|
301
|
+
private returning;
|
|
302
|
+
constructor(run: RunQuery, databaseInstanceId: string, table: string, patch: Record<string, unknown>);
|
|
303
|
+
eq(column: string, value: unknown): this;
|
|
304
|
+
select(columns?: string): this;
|
|
305
|
+
then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
306
|
+
private execute;
|
|
307
|
+
}
|
|
308
|
+
declare class PostgrestDeleteBuilder<Row extends Record<string, unknown> = Record<string, unknown>> implements PromiseLike<PostgrestResult<Row[]>> {
|
|
309
|
+
private readonly run;
|
|
310
|
+
private readonly databaseInstanceId;
|
|
311
|
+
private readonly table;
|
|
312
|
+
private filters;
|
|
313
|
+
private returning;
|
|
314
|
+
constructor(run: RunQuery, databaseInstanceId: string, table: string);
|
|
315
|
+
eq(column: string, value: unknown): this;
|
|
316
|
+
select(columns?: string): this;
|
|
317
|
+
then<TResult1 = PostgrestResult<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResult<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
318
|
+
private execute;
|
|
319
|
+
}
|
|
320
|
+
declare class PostgrestTableApi<Row extends Record<string, unknown> = Record<string, unknown>> {
|
|
321
|
+
private readonly run;
|
|
322
|
+
private readonly databaseInstanceId;
|
|
323
|
+
private readonly table;
|
|
324
|
+
constructor(run: RunQuery, databaseInstanceId: string, table: string);
|
|
325
|
+
select(columns?: string): PostgrestSelectBuilder<Row>;
|
|
326
|
+
insert(values: Record<string, unknown> | Record<string, unknown>[]): PostgrestInsertBuilder<Row>;
|
|
327
|
+
update(patch: Record<string, unknown>): PostgrestUpdateBuilder<Row>;
|
|
328
|
+
delete(): PostgrestDeleteBuilder<Row>;
|
|
329
|
+
}
|
|
330
|
+
|
|
225
331
|
declare function normalizeBrowserApiBase(baseUrl?: string): string;
|
|
226
332
|
interface RagableBrowserClientOptions {
|
|
227
333
|
/** Organization id (UUID) — public agent chat URLs. */
|
|
@@ -231,6 +337,10 @@ interface RagableBrowserClientOptions {
|
|
|
231
337
|
* {@link RagableBrowserDatabaseClient}.
|
|
232
338
|
*/
|
|
233
339
|
authGroupId?: string;
|
|
340
|
+
/**
|
|
341
|
+
* Default Backspace SQL instance id for {@link RagableBrowser.from} (Supabase-style table API).
|
|
342
|
+
*/
|
|
343
|
+
databaseInstanceId?: string;
|
|
234
344
|
/**
|
|
235
345
|
* Returns the end-user access JWT (from login/register/refresh).
|
|
236
346
|
* Required for `auth.getMe`, `auth.updateMe`, and `database.query`.
|
|
@@ -256,14 +366,72 @@ interface BrowserAuthTokens {
|
|
|
256
366
|
refreshToken: string;
|
|
257
367
|
expiresIn: string;
|
|
258
368
|
}
|
|
259
|
-
/**
|
|
369
|
+
/** Supabase-compatible session shape (snake_case tokens). */
|
|
370
|
+
interface SupabaseCompatSession<AuthUser extends Record<string, unknown> = Record<string, unknown>> {
|
|
371
|
+
access_token: string;
|
|
372
|
+
refresh_token: string;
|
|
373
|
+
/** Best-effort seconds from Ragable `expiresIn` (e.g. `7d`, `3600`). */
|
|
374
|
+
expires_in: number;
|
|
375
|
+
token_type: "bearer";
|
|
376
|
+
user: AuthUser;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** End-user auth — Ragable names + Supabase/Firebase-style aliases returning `{ data, error }`. */
|
|
260
380
|
declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown> = Record<string, unknown>> {
|
|
261
381
|
private readonly options;
|
|
382
|
+
private readonly fetchImpl;
|
|
262
383
|
constructor(options: RagableBrowserClientOptions);
|
|
263
|
-
private get fetchImpl();
|
|
264
384
|
private toUrl;
|
|
265
385
|
private baseHeaders;
|
|
266
386
|
private authPrefix;
|
|
387
|
+
/** Supabase: `signUp` → `{ data: { user, session }, error }` */
|
|
388
|
+
signUp(credentials: {
|
|
389
|
+
email: string;
|
|
390
|
+
password: string;
|
|
391
|
+
options?: {
|
|
392
|
+
data?: Record<string, unknown>;
|
|
393
|
+
};
|
|
394
|
+
}): Promise<PostgrestResult<{
|
|
395
|
+
user: AuthUser;
|
|
396
|
+
session: SupabaseCompatSession<AuthUser>;
|
|
397
|
+
}>>;
|
|
398
|
+
/** Supabase: `signInWithPassword` */
|
|
399
|
+
signInWithPassword(credentials: {
|
|
400
|
+
email: string;
|
|
401
|
+
password: string;
|
|
402
|
+
}): Promise<PostgrestResult<{
|
|
403
|
+
user: AuthUser;
|
|
404
|
+
session: SupabaseCompatSession<AuthUser>;
|
|
405
|
+
}>>;
|
|
406
|
+
/** Supabase: `refreshSession` */
|
|
407
|
+
refreshSession(refreshToken: string): Promise<PostgrestResult<{
|
|
408
|
+
session: SupabaseCompatSession<AuthUser>;
|
|
409
|
+
user: AuthUser;
|
|
410
|
+
}>>;
|
|
411
|
+
/** Supabase: `getUser()` — needs `getAccessToken` on the client */
|
|
412
|
+
getUser(): Promise<PostgrestResult<{
|
|
413
|
+
user: AuthUser;
|
|
414
|
+
}>>;
|
|
415
|
+
/** Supabase: `updateUser` */
|
|
416
|
+
updateUser(attributes: {
|
|
417
|
+
email?: string;
|
|
418
|
+
password?: string;
|
|
419
|
+
data?: {
|
|
420
|
+
name?: string | null;
|
|
421
|
+
};
|
|
422
|
+
}): Promise<PostgrestResult<{
|
|
423
|
+
user: AuthUser;
|
|
424
|
+
}>>;
|
|
425
|
+
/**
|
|
426
|
+
* Supabase/Firebase: no server call — clear tokens in your app.
|
|
427
|
+
* Returns `{ error: null }` for API compatibility.
|
|
428
|
+
*/
|
|
429
|
+
signOut(_options?: {
|
|
430
|
+
scope?: "global" | "local";
|
|
431
|
+
}): Promise<{
|
|
432
|
+
error: null;
|
|
433
|
+
}>;
|
|
434
|
+
private getUserFromToken;
|
|
267
435
|
register(body: {
|
|
268
436
|
email: string;
|
|
269
437
|
password: string;
|
|
@@ -290,8 +458,11 @@ interface BrowserSqlQueryParams {
|
|
|
290
458
|
databaseInstanceId: string;
|
|
291
459
|
sql: string;
|
|
292
460
|
params?: unknown[];
|
|
293
|
-
/**
|
|
294
|
-
|
|
461
|
+
/**
|
|
462
|
+
* Default `true`. When `false`, the API allows INSERT/UPDATE/DELETE (and existing safe reads);
|
|
463
|
+
* DDL (`CREATE`/`DROP`/`ALTER`/…) and privilege changes remain blocked.
|
|
464
|
+
*/
|
|
465
|
+
readOnly?: boolean;
|
|
295
466
|
timeoutMs?: number;
|
|
296
467
|
rowLimit?: number;
|
|
297
468
|
}
|
|
@@ -302,16 +473,13 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
|
|
|
302
473
|
rows: Row[];
|
|
303
474
|
}
|
|
304
475
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
* Pass `createBrowserClient<YourDatabase>()` and use `query<Tables<YourDatabase, 't'>>()`
|
|
309
|
-
* for Supabase-style row typing.
|
|
476
|
+
* Raw SQL against linked Postgres (escape hatch). Prefer {@link RagableBrowser.from} for
|
|
477
|
+
* Supabase-style `.select()` / `.insert()` / `.update()` / `.delete()`.
|
|
310
478
|
*/
|
|
311
479
|
declare class RagableBrowserDatabaseClient<_Schema extends RagableDatabase = DefaultRagableDatabase> {
|
|
312
480
|
private readonly options;
|
|
481
|
+
private readonly fetchImpl;
|
|
313
482
|
constructor(options: RagableBrowserClientOptions);
|
|
314
|
-
private get fetchImpl();
|
|
315
483
|
private toUrl;
|
|
316
484
|
query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row>>;
|
|
317
485
|
private baseHeaders;
|
|
@@ -322,8 +490,8 @@ declare class RagableBrowserDatabaseClient<_Schema extends RagableDatabase = Def
|
|
|
322
490
|
*/
|
|
323
491
|
declare class RagableBrowserAgentsClient {
|
|
324
492
|
private readonly options;
|
|
493
|
+
private readonly fetchImpl;
|
|
325
494
|
constructor(options: RagableBrowserClientOptions);
|
|
326
|
-
private get fetchImpl();
|
|
327
495
|
private toUrl;
|
|
328
496
|
/**
|
|
329
497
|
* Stream agent execution as SSE (`POST /public/organizations/:orgId/agents/:agentId/chat/stream`).
|
|
@@ -336,24 +504,28 @@ interface AgentPublicChatParams extends AgentChatParams {
|
|
|
336
504
|
triggerNodeId?: string;
|
|
337
505
|
}
|
|
338
506
|
/**
|
|
339
|
-
* Browser client
|
|
340
|
-
*
|
|
507
|
+
* Browser client: mirrors **Supabase JS** (`createClient`, `.from()`, `.auth.signInWithPassword`, `{ data, error }`)
|
|
508
|
+
* plus Ragable **`agents.chatStream`**. Server secrets: {@link createRagableServerClient} / {@link createClient} with `apiKey`.
|
|
341
509
|
*/
|
|
342
510
|
declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>> {
|
|
343
511
|
readonly agents: RagableBrowserAgentsClient;
|
|
344
512
|
readonly auth: RagableBrowserAuthClient<AuthUser>;
|
|
345
513
|
readonly database: RagableBrowserDatabaseClient<Database>;
|
|
514
|
+
private readonly options;
|
|
346
515
|
constructor(options: RagableBrowserClientOptions);
|
|
516
|
+
/**
|
|
517
|
+
* Supabase-style table API: `.from('items').select().eq('id', 1).single()`.
|
|
518
|
+
* Pass `databaseInstanceId` here or set `databaseInstanceId` on the client options.
|
|
519
|
+
*/
|
|
520
|
+
from<Row extends Record<string, unknown> = Record<string, unknown>>(table: string, databaseInstanceId?: string): PostgrestTableApi<Row>;
|
|
347
521
|
}
|
|
348
522
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* - {@link RagableBrowser.auth} / {@link RagableBrowser.database} — need `authGroupId` (+ `getAccessToken` for protected calls).
|
|
352
|
-
*
|
|
353
|
-
* Pass schema and user types like Supabase: `createBrowserClient<Database, AuthUser>({ ... })`.
|
|
354
|
-
* For Shift and `/v1/*`, use {@link createClient} on a server.
|
|
523
|
+
* **Supabase-equivalent** browser client factory (no org API key).
|
|
524
|
+
* Same as {@link createRagableBrowserClient}.
|
|
355
525
|
*/
|
|
356
526
|
declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
527
|
+
/** Alias for {@link createBrowserClient} — matches Supabase `createClient` naming. */
|
|
528
|
+
declare const createRagableBrowserClient: typeof createBrowserClient;
|
|
357
529
|
|
|
358
530
|
/**
|
|
359
531
|
* Shared SSE parsing for `data: {json}` lines (Ragable agent streams).
|
|
@@ -427,10 +599,19 @@ declare class Ragable {
|
|
|
427
599
|
constructor(options: RagableClientOptions);
|
|
428
600
|
}
|
|
429
601
|
/**
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
602
|
+
* **Supabase-style overloads**
|
|
603
|
+
* - `createClient(RAGABLE_URL, { organizationId, authGroupId, … })` — browser (no API key)
|
|
604
|
+
* - `createClient({ apiKey, baseUrl })` — server / Engine (secret key)
|
|
605
|
+
*
|
|
606
|
+
* Prefer {@link createRagableServerClient} in backend code if the dual overload is confusing.
|
|
433
607
|
*/
|
|
608
|
+
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(url: string, options: Omit<RagableBrowserClientOptions, "baseUrl">): RagableBrowser<Database, AuthUser>;
|
|
434
609
|
declare function createClient(options: RagableClientOptions): Ragable;
|
|
610
|
+
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
611
|
+
/**
|
|
612
|
+
* Explicit **server** factory — same as `createClient({ apiKey, baseUrl })`.
|
|
613
|
+
* Use in the Engine; never import alongside browser `createClient(url, …)` if you want tree-shaking clarity.
|
|
614
|
+
*/
|
|
615
|
+
declare function createRagableServerClient(options: RagableClientOptions): Ragable;
|
|
435
616
|
|
|
436
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type DefaultRagableDatabase, type FormatContextOptions, type Json, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RequestOptions, type RetrieveParams, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type Tables, type TablesInsert, type TablesUpdate, createBrowserClient, createClient, createRagPipeline, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };
|
|
617
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type DefaultRagableDatabase, type FormatContextOptions, type Json, PostgrestDeleteBuilder, PostgrestInsertBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RequestOptions, type RetrieveParams, type RunQuery, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type Tables, type TablesInsert, type TablesUpdate, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };
|