@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.js
CHANGED
|
@@ -23,6 +23,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
23
23
|
var index_exports = {};
|
|
24
24
|
__export(index_exports, {
|
|
25
25
|
AgentsClient: () => AgentsClient,
|
|
26
|
+
PostgrestDeleteBuilder: () => PostgrestDeleteBuilder,
|
|
27
|
+
PostgrestInsertBuilder: () => PostgrestInsertBuilder,
|
|
28
|
+
PostgrestSelectBuilder: () => PostgrestSelectBuilder,
|
|
29
|
+
PostgrestTableApi: () => PostgrestTableApi,
|
|
30
|
+
PostgrestUpdateBuilder: () => PostgrestUpdateBuilder,
|
|
26
31
|
Ragable: () => Ragable,
|
|
27
32
|
RagableBrowser: () => RagableBrowser,
|
|
28
33
|
RagableBrowserAgentsClient: () => RagableBrowserAgentsClient,
|
|
@@ -31,9 +36,13 @@ __export(index_exports, {
|
|
|
31
36
|
RagableError: () => RagableError,
|
|
32
37
|
RagableRequestClient: () => RagableRequestClient,
|
|
33
38
|
ShiftClient: () => ShiftClient,
|
|
39
|
+
asPostgrestResponse: () => asPostgrestResponse,
|
|
40
|
+
bindFetch: () => bindFetch,
|
|
34
41
|
createBrowserClient: () => createBrowserClient,
|
|
35
42
|
createClient: () => createClient,
|
|
36
43
|
createRagPipeline: () => createRagPipeline,
|
|
44
|
+
createRagableBrowserClient: () => createRagableBrowserClient,
|
|
45
|
+
createRagableServerClient: () => createRagableServerClient,
|
|
37
46
|
extractErrorMessage: () => extractErrorMessage,
|
|
38
47
|
formatRetrievalContext: () => formatRetrievalContext,
|
|
39
48
|
normalizeBrowserApiBase: () => normalizeBrowserApiBase,
|
|
@@ -43,6 +52,12 @@ __export(index_exports, {
|
|
|
43
52
|
module.exports = __toCommonJS(index_exports);
|
|
44
53
|
|
|
45
54
|
// src/request-client.ts
|
|
55
|
+
function bindFetch(custom) {
|
|
56
|
+
return (input, init) => {
|
|
57
|
+
const f = custom ?? globalThis.fetch;
|
|
58
|
+
return f.call(globalThis, input, init);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
46
61
|
var RagableError = class extends Error {
|
|
47
62
|
constructor(message, status, body) {
|
|
48
63
|
super(message);
|
|
@@ -75,7 +90,7 @@ var RagableRequestClient = class {
|
|
|
75
90
|
__publicField(this, "defaultHeaders");
|
|
76
91
|
this.apiKey = options.apiKey;
|
|
77
92
|
this.baseUrl = options.baseUrl ?? "http://localhost:8080/api";
|
|
78
|
-
this.fetchImpl = options.fetch
|
|
93
|
+
this.fetchImpl = bindFetch(options.fetch);
|
|
79
94
|
this.defaultHeaders = options.headers;
|
|
80
95
|
}
|
|
81
96
|
toUrl(path) {
|
|
@@ -378,6 +393,356 @@ var AgentsClient = class {
|
|
|
378
393
|
}
|
|
379
394
|
};
|
|
380
395
|
|
|
396
|
+
// src/browser-postgrest.ts
|
|
397
|
+
function assertIdent(name, ctx) {
|
|
398
|
+
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
|
|
399
|
+
throw new RagableError(
|
|
400
|
+
`Invalid ${ctx} identifier "${name}" (use letters, numbers, underscore)`,
|
|
401
|
+
400,
|
|
402
|
+
null
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function quoteIdent(name) {
|
|
407
|
+
assertIdent(name, "column");
|
|
408
|
+
return `"${name}"`;
|
|
409
|
+
}
|
|
410
|
+
var OP_SQL = {
|
|
411
|
+
eq: "=",
|
|
412
|
+
neq: "<>",
|
|
413
|
+
gt: ">",
|
|
414
|
+
gte: ">=",
|
|
415
|
+
lt: "<",
|
|
416
|
+
lte: "<=",
|
|
417
|
+
like: "LIKE",
|
|
418
|
+
ilike: "ILIKE"
|
|
419
|
+
};
|
|
420
|
+
async function asPostgrestResponse(fn) {
|
|
421
|
+
try {
|
|
422
|
+
const data = await fn();
|
|
423
|
+
return { data, error: null };
|
|
424
|
+
} catch (e) {
|
|
425
|
+
const err = e instanceof RagableError ? e : new RagableError(e.message, 500, null);
|
|
426
|
+
return { data: null, error: err };
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
function buildWhere(filters, params) {
|
|
430
|
+
if (filters.length === 0) return { clause: "", nextIdx: 1 };
|
|
431
|
+
const parts = [];
|
|
432
|
+
let i = params.length;
|
|
433
|
+
for (const f of filters) {
|
|
434
|
+
assertIdent(f.column, "filter");
|
|
435
|
+
i += 1;
|
|
436
|
+
parts.push(`${quoteIdent(f.column)} ${OP_SQL[f.op]} $${i}`);
|
|
437
|
+
params.push(f.value);
|
|
438
|
+
}
|
|
439
|
+
return { clause: ` WHERE ${parts.join(" AND ")}`, nextIdx: i };
|
|
440
|
+
}
|
|
441
|
+
var PostgrestSelectBuilder = class {
|
|
442
|
+
constructor(run, databaseInstanceId, table, columns) {
|
|
443
|
+
this.run = run;
|
|
444
|
+
this.databaseInstanceId = databaseInstanceId;
|
|
445
|
+
this.table = table;
|
|
446
|
+
this.columns = columns;
|
|
447
|
+
__publicField(this, "filters", []);
|
|
448
|
+
__publicField(this, "_limit");
|
|
449
|
+
__publicField(this, "_order");
|
|
450
|
+
assertIdent(table, "table");
|
|
451
|
+
}
|
|
452
|
+
eq(column, value) {
|
|
453
|
+
this.filters.push({ op: "eq", column, value });
|
|
454
|
+
return this;
|
|
455
|
+
}
|
|
456
|
+
neq(column, value) {
|
|
457
|
+
this.filters.push({ op: "neq", column, value });
|
|
458
|
+
return this;
|
|
459
|
+
}
|
|
460
|
+
gt(column, value) {
|
|
461
|
+
this.filters.push({ op: "gt", column, value });
|
|
462
|
+
return this;
|
|
463
|
+
}
|
|
464
|
+
gte(column, value) {
|
|
465
|
+
this.filters.push({ op: "gte", column, value });
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
468
|
+
lt(column, value) {
|
|
469
|
+
this.filters.push({ op: "lt", column, value });
|
|
470
|
+
return this;
|
|
471
|
+
}
|
|
472
|
+
lte(column, value) {
|
|
473
|
+
this.filters.push({ op: "lte", column, value });
|
|
474
|
+
return this;
|
|
475
|
+
}
|
|
476
|
+
like(column, value) {
|
|
477
|
+
this.filters.push({ op: "like", column, value });
|
|
478
|
+
return this;
|
|
479
|
+
}
|
|
480
|
+
ilike(column, value) {
|
|
481
|
+
this.filters.push({ op: "ilike", column, value });
|
|
482
|
+
return this;
|
|
483
|
+
}
|
|
484
|
+
limit(n) {
|
|
485
|
+
this._limit = n;
|
|
486
|
+
return this;
|
|
487
|
+
}
|
|
488
|
+
order(column, options) {
|
|
489
|
+
this._order = { column, ascending: options?.ascending !== false };
|
|
490
|
+
return this;
|
|
491
|
+
}
|
|
492
|
+
/** @param includeUserLimit when false, omit `.limit()` (for `.single()` / `.maybeSingle()`). */
|
|
493
|
+
buildSelectCore(params, includeUserLimit) {
|
|
494
|
+
const tbl = quoteIdent(this.table);
|
|
495
|
+
const { clause } = buildWhere(this.filters, params);
|
|
496
|
+
let sql = `SELECT ${this.columns} FROM ${tbl}${clause}`;
|
|
497
|
+
if (this._order) {
|
|
498
|
+
sql += ` ORDER BY ${quoteIdent(this._order.column)} ${this._order.ascending ? "ASC" : "DESC"}`;
|
|
499
|
+
}
|
|
500
|
+
if (includeUserLimit && this._limit != null) {
|
|
501
|
+
sql += ` LIMIT ${Math.max(0, Math.floor(this._limit))}`;
|
|
502
|
+
}
|
|
503
|
+
return sql;
|
|
504
|
+
}
|
|
505
|
+
then(onfulfilled, onrejected) {
|
|
506
|
+
return this.executeMany().then(onfulfilled, onrejected);
|
|
507
|
+
}
|
|
508
|
+
async executeMany() {
|
|
509
|
+
return asPostgrestResponse(async () => {
|
|
510
|
+
const params = [];
|
|
511
|
+
const sql = this.buildSelectCore(params, true);
|
|
512
|
+
const res = await this.run({
|
|
513
|
+
databaseInstanceId: this.databaseInstanceId,
|
|
514
|
+
sql,
|
|
515
|
+
params,
|
|
516
|
+
readOnly: true
|
|
517
|
+
});
|
|
518
|
+
return res.rows;
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
async single() {
|
|
522
|
+
return asPostgrestResponse(async () => {
|
|
523
|
+
const params = [];
|
|
524
|
+
const base = this.buildSelectCore(params, false);
|
|
525
|
+
const sql = `${base} LIMIT 2`;
|
|
526
|
+
const res = await this.run({
|
|
527
|
+
databaseInstanceId: this.databaseInstanceId,
|
|
528
|
+
sql,
|
|
529
|
+
params,
|
|
530
|
+
readOnly: true
|
|
531
|
+
});
|
|
532
|
+
if (res.rows.length === 0) {
|
|
533
|
+
throw new RagableError("JSON object requested, multiple (or no) rows returned", 406, {
|
|
534
|
+
code: "PGRST116"
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
if (res.rows.length > 1) {
|
|
538
|
+
throw new RagableError("JSON object requested, multiple (or no) rows returned", 406, {
|
|
539
|
+
code: "PGRST116"
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
return res.rows[0];
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
async maybeSingle() {
|
|
546
|
+
return asPostgrestResponse(async () => {
|
|
547
|
+
const params = [];
|
|
548
|
+
const base = this.buildSelectCore(params, false);
|
|
549
|
+
const sql = `${base} LIMIT 2`;
|
|
550
|
+
const res = await this.run({
|
|
551
|
+
databaseInstanceId: this.databaseInstanceId,
|
|
552
|
+
sql,
|
|
553
|
+
params,
|
|
554
|
+
readOnly: true
|
|
555
|
+
});
|
|
556
|
+
if (res.rows.length > 1) {
|
|
557
|
+
throw new RagableError("JSON object requested, multiple (or no) rows returned", 406, {
|
|
558
|
+
code: "PGRST116"
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
return res.rows[0] ?? null;
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
var PostgrestInsertBuilder = class {
|
|
566
|
+
constructor(run, databaseInstanceId, table, rows) {
|
|
567
|
+
this.run = run;
|
|
568
|
+
this.databaseInstanceId = databaseInstanceId;
|
|
569
|
+
this.table = table;
|
|
570
|
+
this.rows = rows;
|
|
571
|
+
__publicField(this, "returning", "*");
|
|
572
|
+
assertIdent(table, "table");
|
|
573
|
+
}
|
|
574
|
+
select(columns = "*") {
|
|
575
|
+
this.returning = columns;
|
|
576
|
+
return this;
|
|
577
|
+
}
|
|
578
|
+
then(onfulfilled, onrejected) {
|
|
579
|
+
return this.execute().then(onfulfilled, onrejected);
|
|
580
|
+
}
|
|
581
|
+
async execute() {
|
|
582
|
+
return asPostgrestResponse(async () => {
|
|
583
|
+
if (this.rows.length === 0) return [];
|
|
584
|
+
const keys = Object.keys(this.rows[0]);
|
|
585
|
+
for (const k of keys) assertIdent(k, "column");
|
|
586
|
+
const tbl = quoteIdent(this.table);
|
|
587
|
+
const params = [];
|
|
588
|
+
const valueGroups = [];
|
|
589
|
+
for (const row of this.rows) {
|
|
590
|
+
const placeholders = [];
|
|
591
|
+
for (const k of keys) {
|
|
592
|
+
params.push(row[k]);
|
|
593
|
+
placeholders.push(`$${params.length}`);
|
|
594
|
+
}
|
|
595
|
+
valueGroups.push(`(${placeholders.join(", ")})`);
|
|
596
|
+
}
|
|
597
|
+
const cols = keys.map(quoteIdent).join(", ");
|
|
598
|
+
const sql = `INSERT INTO ${tbl} (${cols}) VALUES ${valueGroups.join(", ")} RETURNING ${this.returning}`;
|
|
599
|
+
const res = await this.run({
|
|
600
|
+
databaseInstanceId: this.databaseInstanceId,
|
|
601
|
+
sql,
|
|
602
|
+
params,
|
|
603
|
+
readOnly: false
|
|
604
|
+
});
|
|
605
|
+
return res.rows;
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
var PostgrestUpdateBuilder = class {
|
|
610
|
+
constructor(run, databaseInstanceId, table, patch) {
|
|
611
|
+
this.run = run;
|
|
612
|
+
this.databaseInstanceId = databaseInstanceId;
|
|
613
|
+
this.table = table;
|
|
614
|
+
this.patch = patch;
|
|
615
|
+
__publicField(this, "filters", []);
|
|
616
|
+
__publicField(this, "returning", "*");
|
|
617
|
+
assertIdent(table, "table");
|
|
618
|
+
}
|
|
619
|
+
eq(column, value) {
|
|
620
|
+
this.filters.push({ op: "eq", column, value });
|
|
621
|
+
return this;
|
|
622
|
+
}
|
|
623
|
+
select(columns = "*") {
|
|
624
|
+
this.returning = columns;
|
|
625
|
+
return this;
|
|
626
|
+
}
|
|
627
|
+
then(onfulfilled, onrejected) {
|
|
628
|
+
return this.execute().then(onfulfilled, onrejected);
|
|
629
|
+
}
|
|
630
|
+
async execute() {
|
|
631
|
+
return asPostgrestResponse(async () => {
|
|
632
|
+
const keys = Object.keys(this.patch);
|
|
633
|
+
if (keys.length === 0) {
|
|
634
|
+
throw new RagableError("Empty update payload", 400, null);
|
|
635
|
+
}
|
|
636
|
+
for (const k of keys) assertIdent(k, "column");
|
|
637
|
+
if (this.filters.length === 0) {
|
|
638
|
+
throw new RagableError(
|
|
639
|
+
"UPDATE requires a filter (e.g. .eq('id', value)) \u2014 refusing unscoped update",
|
|
640
|
+
400,
|
|
641
|
+
null
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
const params = [];
|
|
645
|
+
const sets = [];
|
|
646
|
+
for (const k of keys) {
|
|
647
|
+
params.push(this.patch[k]);
|
|
648
|
+
sets.push(`${quoteIdent(k)} = $${params.length}`);
|
|
649
|
+
}
|
|
650
|
+
const { clause } = buildWhere(this.filters, params);
|
|
651
|
+
const tbl = quoteIdent(this.table);
|
|
652
|
+
const sql = `UPDATE ${tbl} SET ${sets.join(", ")}${clause} RETURNING ${this.returning}`;
|
|
653
|
+
const res = await this.run({
|
|
654
|
+
databaseInstanceId: this.databaseInstanceId,
|
|
655
|
+
sql,
|
|
656
|
+
params,
|
|
657
|
+
readOnly: false
|
|
658
|
+
});
|
|
659
|
+
return res.rows;
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
var PostgrestDeleteBuilder = class {
|
|
664
|
+
constructor(run, databaseInstanceId, table) {
|
|
665
|
+
this.run = run;
|
|
666
|
+
this.databaseInstanceId = databaseInstanceId;
|
|
667
|
+
this.table = table;
|
|
668
|
+
__publicField(this, "filters", []);
|
|
669
|
+
__publicField(this, "returning", "*");
|
|
670
|
+
assertIdent(table, "table");
|
|
671
|
+
}
|
|
672
|
+
eq(column, value) {
|
|
673
|
+
this.filters.push({ op: "eq", column, value });
|
|
674
|
+
return this;
|
|
675
|
+
}
|
|
676
|
+
select(columns = "*") {
|
|
677
|
+
this.returning = columns;
|
|
678
|
+
return this;
|
|
679
|
+
}
|
|
680
|
+
then(onfulfilled, onrejected) {
|
|
681
|
+
return this.execute().then(onfulfilled, onrejected);
|
|
682
|
+
}
|
|
683
|
+
async execute() {
|
|
684
|
+
return asPostgrestResponse(async () => {
|
|
685
|
+
if (this.filters.length === 0) {
|
|
686
|
+
throw new RagableError(
|
|
687
|
+
"DELETE requires a filter (e.g. .eq('id', value)) \u2014 refusing unscoped delete",
|
|
688
|
+
400,
|
|
689
|
+
null
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
const params = [];
|
|
693
|
+
const { clause } = buildWhere(this.filters, params);
|
|
694
|
+
const tbl = quoteIdent(this.table);
|
|
695
|
+
const sql = `DELETE FROM ${tbl}${clause} RETURNING ${this.returning}`;
|
|
696
|
+
const res = await this.run({
|
|
697
|
+
databaseInstanceId: this.databaseInstanceId,
|
|
698
|
+
sql,
|
|
699
|
+
params,
|
|
700
|
+
readOnly: false
|
|
701
|
+
});
|
|
702
|
+
return res.rows;
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
var PostgrestTableApi = class {
|
|
707
|
+
constructor(run, databaseInstanceId, table) {
|
|
708
|
+
this.run = run;
|
|
709
|
+
this.databaseInstanceId = databaseInstanceId;
|
|
710
|
+
this.table = table;
|
|
711
|
+
}
|
|
712
|
+
select(columns = "*") {
|
|
713
|
+
return new PostgrestSelectBuilder(
|
|
714
|
+
this.run,
|
|
715
|
+
this.databaseInstanceId,
|
|
716
|
+
this.table,
|
|
717
|
+
columns
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
insert(values) {
|
|
721
|
+
const rows = Array.isArray(values) ? values : [values];
|
|
722
|
+
return new PostgrestInsertBuilder(
|
|
723
|
+
this.run,
|
|
724
|
+
this.databaseInstanceId,
|
|
725
|
+
this.table,
|
|
726
|
+
rows
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
update(patch) {
|
|
730
|
+
return new PostgrestUpdateBuilder(
|
|
731
|
+
this.run,
|
|
732
|
+
this.databaseInstanceId,
|
|
733
|
+
this.table,
|
|
734
|
+
patch
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
delete() {
|
|
738
|
+
return new PostgrestDeleteBuilder(
|
|
739
|
+
this.run,
|
|
740
|
+
this.databaseInstanceId,
|
|
741
|
+
this.table
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
|
|
381
746
|
// src/browser.ts
|
|
382
747
|
function normalizeBrowserApiBase(baseUrl) {
|
|
383
748
|
return (baseUrl ?? "http://localhost:8080/api").replace(/\/+$/, "");
|
|
@@ -412,12 +777,32 @@ async function parseJsonOrThrow(response) {
|
|
|
412
777
|
}
|
|
413
778
|
return payload;
|
|
414
779
|
}
|
|
780
|
+
function parseExpiresInSeconds(expiresIn) {
|
|
781
|
+
const s = expiresIn.trim().toLowerCase();
|
|
782
|
+
const m = /^(\d+)([smhd])?$/.exec(s);
|
|
783
|
+
if (m) {
|
|
784
|
+
const n = Number(m[1]);
|
|
785
|
+
const u = m[2] ?? "s";
|
|
786
|
+
const mult = u === "s" ? 1 : u === "m" ? 60 : u === "h" ? 3600 : u === "d" ? 86400 : 1;
|
|
787
|
+
return n * mult;
|
|
788
|
+
}
|
|
789
|
+
const asNum = Number(s);
|
|
790
|
+
return Number.isFinite(asNum) ? asNum : 0;
|
|
791
|
+
}
|
|
792
|
+
function toSupabaseSession(s) {
|
|
793
|
+
return {
|
|
794
|
+
access_token: s.accessToken,
|
|
795
|
+
refresh_token: s.refreshToken,
|
|
796
|
+
expires_in: parseExpiresInSeconds(s.expiresIn),
|
|
797
|
+
token_type: "bearer",
|
|
798
|
+
user: s.user
|
|
799
|
+
};
|
|
800
|
+
}
|
|
415
801
|
var RagableBrowserAuthClient = class {
|
|
416
802
|
constructor(options) {
|
|
417
803
|
this.options = options;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
return this.options.fetch ?? fetch;
|
|
804
|
+
__publicField(this, "fetchImpl");
|
|
805
|
+
this.fetchImpl = bindFetch(options.fetch);
|
|
421
806
|
}
|
|
422
807
|
toUrl(path) {
|
|
423
808
|
return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
|
|
@@ -433,6 +818,69 @@ var RagableBrowserAuthClient = class {
|
|
|
433
818
|
const gid = requireAuthGroupId(this.options);
|
|
434
819
|
return `/auth-groups/${gid}/auth`;
|
|
435
820
|
}
|
|
821
|
+
/** Supabase: `signUp` → `{ data: { user, session }, error }` */
|
|
822
|
+
async signUp(credentials) {
|
|
823
|
+
return asPostgrestResponse(async () => {
|
|
824
|
+
const name = typeof credentials.options?.data?.name === "string" ? credentials.options.data.name : void 0;
|
|
825
|
+
const session = await this.register({
|
|
826
|
+
email: credentials.email,
|
|
827
|
+
password: credentials.password,
|
|
828
|
+
name
|
|
829
|
+
});
|
|
830
|
+
return { user: session.user, session: toSupabaseSession(session) };
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
/** Supabase: `signInWithPassword` */
|
|
834
|
+
async signInWithPassword(credentials) {
|
|
835
|
+
return asPostgrestResponse(async () => {
|
|
836
|
+
const session = await this.login(credentials);
|
|
837
|
+
return { user: session.user, session: toSupabaseSession(session) };
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
/** Supabase: `refreshSession` */
|
|
841
|
+
async refreshSession(refreshToken) {
|
|
842
|
+
return asPostgrestResponse(async () => {
|
|
843
|
+
const tokens = await this.refresh({ refreshToken });
|
|
844
|
+
const me = await this.getUserFromToken(tokens.accessToken);
|
|
845
|
+
const session = {
|
|
846
|
+
access_token: tokens.accessToken,
|
|
847
|
+
refresh_token: tokens.refreshToken,
|
|
848
|
+
expires_in: parseExpiresInSeconds(tokens.expiresIn),
|
|
849
|
+
token_type: "bearer",
|
|
850
|
+
user: me.user
|
|
851
|
+
};
|
|
852
|
+
return { session, user: me.user };
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
/** Supabase: `getUser()` — needs `getAccessToken` on the client */
|
|
856
|
+
async getUser() {
|
|
857
|
+
return asPostgrestResponse(() => this.getMe());
|
|
858
|
+
}
|
|
859
|
+
/** Supabase: `updateUser` */
|
|
860
|
+
async updateUser(attributes) {
|
|
861
|
+
return asPostgrestResponse(
|
|
862
|
+
() => this.updateMe({
|
|
863
|
+
password: attributes.password,
|
|
864
|
+
name: attributes.data?.name
|
|
865
|
+
})
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Supabase/Firebase: no server call — clear tokens in your app.
|
|
870
|
+
* Returns `{ error: null }` for API compatibility.
|
|
871
|
+
*/
|
|
872
|
+
async signOut(_options) {
|
|
873
|
+
return { error: null };
|
|
874
|
+
}
|
|
875
|
+
async getUserFromToken(accessToken) {
|
|
876
|
+
const headers = this.baseHeaders(false);
|
|
877
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
878
|
+
const response = await this.fetchImpl(`${this.toUrl(this.authPrefix())}/me`, {
|
|
879
|
+
method: "GET",
|
|
880
|
+
headers
|
|
881
|
+
});
|
|
882
|
+
return parseJsonOrThrow(response);
|
|
883
|
+
}
|
|
436
884
|
async register(body) {
|
|
437
885
|
const response = await this.fetchImpl(`${this.toUrl(this.authPrefix())}/register`, {
|
|
438
886
|
method: "POST",
|
|
@@ -482,9 +930,8 @@ var RagableBrowserAuthClient = class {
|
|
|
482
930
|
var RagableBrowserDatabaseClient = class {
|
|
483
931
|
constructor(options) {
|
|
484
932
|
this.options = options;
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
return this.options.fetch ?? fetch;
|
|
933
|
+
__publicField(this, "fetchImpl");
|
|
934
|
+
this.fetchImpl = bindFetch(options.fetch);
|
|
488
935
|
}
|
|
489
936
|
toUrl(path) {
|
|
490
937
|
return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
|
|
@@ -504,6 +951,7 @@ var RagableBrowserDatabaseClient = class {
|
|
|
504
951
|
databaseInstanceId: params.databaseInstanceId,
|
|
505
952
|
sql: params.sql,
|
|
506
953
|
...params.params !== void 0 ? { params: params.params } : {},
|
|
954
|
+
...params.readOnly === false ? { readOnly: false } : {},
|
|
507
955
|
...params.timeoutMs !== void 0 ? { timeoutMs: params.timeoutMs } : {},
|
|
508
956
|
...params.rowLimit !== void 0 ? { rowLimit: params.rowLimit } : {}
|
|
509
957
|
})
|
|
@@ -518,9 +966,8 @@ var RagableBrowserDatabaseClient = class {
|
|
|
518
966
|
var RagableBrowserAgentsClient = class {
|
|
519
967
|
constructor(options) {
|
|
520
968
|
this.options = options;
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
return this.options.fetch ?? fetch;
|
|
969
|
+
__publicField(this, "fetchImpl");
|
|
970
|
+
this.fetchImpl = bindFetch(options.fetch);
|
|
524
971
|
}
|
|
525
972
|
toUrl(path) {
|
|
526
973
|
return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
|
|
@@ -563,14 +1010,31 @@ var RagableBrowser = class {
|
|
|
563
1010
|
__publicField(this, "agents");
|
|
564
1011
|
__publicField(this, "auth");
|
|
565
1012
|
__publicField(this, "database");
|
|
1013
|
+
__publicField(this, "options");
|
|
1014
|
+
this.options = options;
|
|
566
1015
|
this.agents = new RagableBrowserAgentsClient(options);
|
|
567
1016
|
this.auth = new RagableBrowserAuthClient(options);
|
|
568
1017
|
this.database = new RagableBrowserDatabaseClient(options);
|
|
569
1018
|
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Supabase-style table API: `.from('items').select().eq('id', 1).single()`.
|
|
1021
|
+
* Pass `databaseInstanceId` here or set `databaseInstanceId` on the client options.
|
|
1022
|
+
*/
|
|
1023
|
+
from(table, databaseInstanceId) {
|
|
1024
|
+
const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
|
|
1025
|
+
if (!id) {
|
|
1026
|
+
throw new Error(
|
|
1027
|
+
"RagableBrowser.from() requires databaseInstanceId in client options or as the second argument"
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
const run = (p) => this.database.query(p);
|
|
1031
|
+
return new PostgrestTableApi(run, id, table);
|
|
1032
|
+
}
|
|
570
1033
|
};
|
|
571
1034
|
function createBrowserClient(options) {
|
|
572
1035
|
return new RagableBrowser(options);
|
|
573
1036
|
}
|
|
1037
|
+
var createRagableBrowserClient = createBrowserClient;
|
|
574
1038
|
|
|
575
1039
|
// src/rag.ts
|
|
576
1040
|
function formatRetrievalContext(results, options = {}) {
|
|
@@ -628,12 +1092,46 @@ var Ragable = class {
|
|
|
628
1092
|
};
|
|
629
1093
|
}
|
|
630
1094
|
};
|
|
631
|
-
function
|
|
1095
|
+
function isServerClientOptions(o) {
|
|
1096
|
+
return typeof o === "object" && o !== null && "apiKey" in o && typeof o.apiKey === "string" && o.apiKey.length > 0;
|
|
1097
|
+
}
|
|
1098
|
+
function createClient(urlOrOptions, browserOptions) {
|
|
1099
|
+
if (typeof urlOrOptions === "string") {
|
|
1100
|
+
if (!browserOptions) {
|
|
1101
|
+
throw new Error(
|
|
1102
|
+
"createClient(url, options) requires options with at least organizationId"
|
|
1103
|
+
);
|
|
1104
|
+
}
|
|
1105
|
+
const raw = urlOrOptions.trim().replace(/\/+$/, "");
|
|
1106
|
+
const baseUrl = raw.endsWith("/api") ? raw : `${raw}/api`;
|
|
1107
|
+
return createBrowserClient({
|
|
1108
|
+
...browserOptions,
|
|
1109
|
+
baseUrl: normalizeBrowserApiBase(baseUrl)
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
if (isServerClientOptions(urlOrOptions)) {
|
|
1113
|
+
return new Ragable(urlOrOptions);
|
|
1114
|
+
}
|
|
1115
|
+
if (typeof urlOrOptions === "object" && urlOrOptions !== null && "organizationId" in urlOrOptions && typeof urlOrOptions.organizationId === "string") {
|
|
1116
|
+
return createBrowserClient(
|
|
1117
|
+
urlOrOptions
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
throw new Error(
|
|
1121
|
+
"createClient(options) requires apiKey (server) or organizationId (browser)"
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
function createRagableServerClient(options) {
|
|
632
1125
|
return new Ragable(options);
|
|
633
1126
|
}
|
|
634
1127
|
// Annotate the CommonJS export names for ESM import in node:
|
|
635
1128
|
0 && (module.exports = {
|
|
636
1129
|
AgentsClient,
|
|
1130
|
+
PostgrestDeleteBuilder,
|
|
1131
|
+
PostgrestInsertBuilder,
|
|
1132
|
+
PostgrestSelectBuilder,
|
|
1133
|
+
PostgrestTableApi,
|
|
1134
|
+
PostgrestUpdateBuilder,
|
|
637
1135
|
Ragable,
|
|
638
1136
|
RagableBrowser,
|
|
639
1137
|
RagableBrowserAgentsClient,
|
|
@@ -642,9 +1140,13 @@ function createClient(options) {
|
|
|
642
1140
|
RagableError,
|
|
643
1141
|
RagableRequestClient,
|
|
644
1142
|
ShiftClient,
|
|
1143
|
+
asPostgrestResponse,
|
|
1144
|
+
bindFetch,
|
|
645
1145
|
createBrowserClient,
|
|
646
1146
|
createClient,
|
|
647
1147
|
createRagPipeline,
|
|
1148
|
+
createRagableBrowserClient,
|
|
1149
|
+
createRagableServerClient,
|
|
648
1150
|
extractErrorMessage,
|
|
649
1151
|
formatRetrievalContext,
|
|
650
1152
|
normalizeBrowserApiBase,
|