@ragable/sdk 0.6.24 → 0.7.5

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.js CHANGED
@@ -54,6 +54,7 @@ __export(index_exports, {
54
54
  RagableTimeoutError: () => RagableTimeoutError,
55
55
  SessionStorageAdapter: () => SessionStorageAdapter,
56
56
  ShiftClient: () => ShiftClient,
57
+ StorageClient: () => StorageClient,
57
58
  Transport: () => Transport,
58
59
  asPostgrestResponse: () => asPostgrestResponse,
59
60
  assertPostgrestSuccess: () => assertPostgrestSuccess,
@@ -82,7 +83,6 @@ __export(index_exports, {
82
83
  parseSseDataLine: () => parseSseDataLine,
83
84
  parseTransportResponse: () => parseTransportResponse,
84
85
  readSseStream: () => readSseStream,
85
- resolveRagableApiBase: () => resolveRagableApiBase,
86
86
  runAgentChatStream: () => runAgentChatStream,
87
87
  runAgentChatStreamForUi: () => runAgentChatStreamForUi,
88
88
  runAgentChatStreamLenient: () => runAgentChatStreamLenient,
@@ -99,10 +99,6 @@ function bindFetch(custom) {
99
99
  };
100
100
  }
101
101
  var DEFAULT_RAGABLE_API_BASE = "https://ragable-341305259977.asia-southeast1.run.app/api";
102
- function resolveRagableApiBase(explicitBaseUrl) {
103
- const raw = typeof explicitBaseUrl === "string" && explicitBaseUrl.trim().length > 0 ? explicitBaseUrl.trim() : DEFAULT_RAGABLE_API_BASE.trim();
104
- return raw.replace(/\/+$/, "");
105
- }
106
102
  var RagableSdkError = class extends Error {
107
103
  constructor(message) {
108
104
  super(message);
@@ -231,7 +227,7 @@ var RagableRequestClient = class {
231
227
  __publicField(this, "fetchImpl");
232
228
  __publicField(this, "defaultHeaders");
233
229
  this.apiKey = options.apiKey;
234
- this.baseUrl = resolveRagableApiBase(options.baseUrl);
230
+ this.baseUrl = DEFAULT_RAGABLE_API_BASE.replace(/\/+$/, "");
235
231
  this.fetchImpl = bindFetch(options.fetch);
236
232
  this.defaultHeaders = options.headers;
237
233
  }
@@ -2255,7 +2251,7 @@ var RagableAuth = class {
2255
2251
  __publicField(this, "broadcast", null);
2256
2252
  __publicField(this, "visibilityHandler", null);
2257
2253
  __publicField(this, "initialized", false);
2258
- this.baseUrl = resolveRagableApiBase(config.baseUrl);
2254
+ this.baseUrl = DEFAULT_RAGABLE_API_BASE.replace(/\/+$/, "");
2259
2255
  this.authGroupId = config.authGroupId;
2260
2256
  this.fetchImpl = bindFetch(config.fetch);
2261
2257
  this.defaultHeaders = config.headers;
@@ -2624,8 +2620,8 @@ function decodeJwtExpiry(jwt) {
2624
2620
  }
2625
2621
 
2626
2622
  // src/browser.ts
2627
- function normalizeBrowserApiBase(explicitBaseUrl) {
2628
- return resolveRagableApiBase(explicitBaseUrl);
2623
+ function normalizeBrowserApiBase() {
2624
+ return DEFAULT_RAGABLE_API_BASE.replace(/\/+$/, "");
2629
2625
  }
2630
2626
  function effectiveDataAuth(options) {
2631
2627
  if (options.dataAuth) return options.dataAuth;
@@ -2916,7 +2912,6 @@ var RagableBrowserDatabaseClient = class {
2916
2912
  this.options = options;
2917
2913
  this.ragableAuth = ragableAuth;
2918
2914
  __publicField(this, "fetchImpl");
2919
- __publicField(this, "apiBase");
2920
2915
  __publicField(this, "_transport", null);
2921
2916
  __publicField(this, "collections");
2922
2917
  __publicField(this, "collection");
@@ -2940,7 +2935,7 @@ var RagableBrowserDatabaseClient = class {
2940
2935
  }
2941
2936
  const gid = requireAuthGroupId(opts);
2942
2937
  const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
2943
- const apiBase = this.apiBase;
2938
+ const apiBase = normalizeBrowserApiBase();
2944
2939
  const qs = params.searchParams.toString();
2945
2940
  const url = `${apiBase}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
2946
2941
  const headers = new Headers(opts.headers);
@@ -3055,7 +3050,6 @@ var RagableBrowserDatabaseClient = class {
3055
3050
  )
3056
3051
  });
3057
3052
  this.fetchImpl = bindFetch(options.fetch);
3058
- this.apiBase = resolveRagableApiBase(options.baseUrl);
3059
3053
  this.collections = new Proxy(
3060
3054
  {},
3061
3055
  {
@@ -3077,7 +3071,7 @@ var RagableBrowserDatabaseClient = class {
3077
3071
  this._transport = transport;
3078
3072
  }
3079
3073
  toUrl(path) {
3080
- return `${this.apiBase}${path.startsWith("/") ? path : `/${path}`}`;
3074
+ return `${normalizeBrowserApiBase()}${path.startsWith("/") ? path : `/${path}`}`;
3081
3075
  }
3082
3076
  async _requestCollection(method, path, body, databaseInstanceId) {
3083
3077
  const gid = requireAuthGroupId(this.options);
@@ -3168,7 +3162,7 @@ async function subscribeBrowserRealtime(options, ragableAuth, fetchImpl, params)
3168
3162
  headers.set("Authorization", `Bearer ${token}`);
3169
3163
  headers.set("Content-Type", "application/json");
3170
3164
  const response = await fetchImpl(
3171
- `${resolveRagableApiBase(options.baseUrl)}/auth-groups/${gid}/data/realtime/stream`,
3165
+ `${normalizeBrowserApiBase()}/auth-groups/${gid}/data/realtime/stream`,
3172
3166
  {
3173
3167
  method: "POST",
3174
3168
  headers,
@@ -3301,12 +3295,10 @@ var RagableBrowserAgentsClient = class {
3301
3295
  constructor(options) {
3302
3296
  this.options = options;
3303
3297
  __publicField(this, "fetchImpl");
3304
- __publicField(this, "apiBase");
3305
3298
  this.fetchImpl = bindFetch(options.fetch);
3306
- this.apiBase = resolveRagableApiBase(options.baseUrl);
3307
3299
  }
3308
3300
  toUrl(path) {
3309
- return `${this.apiBase}${path.startsWith("/") ? path : `/${path}`}`;
3301
+ return `${normalizeBrowserApiBase()}${path.startsWith("/") ? path : `/${path}`}`;
3310
3302
  }
3311
3303
  requireWebsiteId() {
3312
3304
  const websiteId = this.options.websiteId?.trim();
@@ -3506,7 +3498,6 @@ var RagableBrowser = class {
3506
3498
  if (options.authGroupId) {
3507
3499
  this._ragableAuth = new RagableAuth({
3508
3500
  authGroupId: options.authGroupId,
3509
- baseUrl: options.baseUrl,
3510
3501
  fetch: options.fetch,
3511
3502
  headers: options.headers,
3512
3503
  auth: options.auth
@@ -3582,15 +3573,171 @@ function createRagPipeline(client, options) {
3582
3573
  };
3583
3574
  }
3584
3575
 
3576
+ // src/storage.ts
3577
+ function normalizeUploadFile2(file, contentType) {
3578
+ if (file instanceof Blob) return file;
3579
+ const u8 = file instanceof ArrayBuffer ? new Uint8Array(file) : new Uint8Array(file);
3580
+ return new Blob([u8.buffer], contentType ? { type: contentType } : {});
3581
+ }
3582
+ var StorageClient = class {
3583
+ constructor(client) {
3584
+ this.client = client;
3585
+ /**
3586
+ * Bucket-level CRUD — list, create and delete buckets for this organisation.
3587
+ */
3588
+ __publicField(this, "buckets");
3589
+ this.buckets = {
3590
+ list: async (params) => {
3591
+ const qs = new URLSearchParams();
3592
+ if (params?.q) qs.set("q", params.q);
3593
+ if (params?.status) qs.set("status", params.status);
3594
+ if (params?.sort) qs.set("sort", params.sort);
3595
+ const query = qs.toString();
3596
+ return this.client.request(
3597
+ `/v1/storage/buckets${query ? `?${query}` : ""}`
3598
+ );
3599
+ },
3600
+ create: async (name) => {
3601
+ return this.client.request("/v1/storage/buckets", {
3602
+ method: "POST",
3603
+ body: { name }
3604
+ });
3605
+ },
3606
+ delete: async (bucketId) => {
3607
+ return this.client.request(
3608
+ `/v1/storage/buckets/${encodeURIComponent(bucketId)}`,
3609
+ { method: "DELETE" }
3610
+ );
3611
+ }
3612
+ };
3613
+ }
3614
+ /**
3615
+ * Returns a {@link StorageBucketClient} scoped to the given bucket ID.
3616
+ *
3617
+ * All object operations (upload, download, list, copy, move, signed URLs, …)
3618
+ * are performed through the returned client.
3619
+ *
3620
+ * @param bucketId The Ragable bucket ID obtained from `buckets.list()` or `buckets.create()`.
3621
+ */
3622
+ from(bucketId) {
3623
+ const { client } = this;
3624
+ const base = `/v1/storage/buckets/${encodeURIComponent(bucketId)}`;
3625
+ return {
3626
+ list: async (params) => {
3627
+ const qs = new URLSearchParams();
3628
+ if (params?.prefix) qs.set("prefix", params.prefix);
3629
+ if (params?.delimiter) qs.set("delimiter", params.delimiter);
3630
+ if (params?.maxResults != null)
3631
+ qs.set("maxResults", String(params.maxResults));
3632
+ if (params?.pageToken) qs.set("pageToken", params.pageToken);
3633
+ const query = qs.toString();
3634
+ return client.request(
3635
+ `${base}/contents${query ? `?${query}` : ""}`
3636
+ );
3637
+ },
3638
+ createFolder: async (folderPath) => {
3639
+ return client.request(
3640
+ `${base}/folders`,
3641
+ { method: "POST", body: { folderPath } }
3642
+ );
3643
+ },
3644
+ deleteFolder: async (folderPath) => {
3645
+ return client.request(
3646
+ `${base}/folders`,
3647
+ { method: "DELETE", body: { folderPath } }
3648
+ );
3649
+ },
3650
+ upload: async (params) => {
3651
+ const formData = new FormData();
3652
+ const blob = normalizeUploadFile2(params.file, params.contentType);
3653
+ const fileName = params.fileName ?? "upload";
3654
+ formData.set("file", blob, fileName);
3655
+ formData.set("objectPath", params.objectPath);
3656
+ if (params.cacheControl) {
3657
+ formData.set("cacheControl", params.cacheControl);
3658
+ }
3659
+ return client.request(`${base}/upload`, {
3660
+ method: "POST",
3661
+ body: formData
3662
+ });
3663
+ },
3664
+ delete: async (objectPath) => {
3665
+ return client.request(
3666
+ `${base}/objects`,
3667
+ { method: "DELETE", body: { objectPath } }
3668
+ );
3669
+ },
3670
+ bulkDelete: async (objectPaths) => {
3671
+ return client.request(
3672
+ `${base}/objects/delete-bulk`,
3673
+ { method: "POST", body: { objectPaths } }
3674
+ );
3675
+ },
3676
+ getMetadata: async (objectPath) => {
3677
+ const qs = new URLSearchParams({ objectPath });
3678
+ return client.request(
3679
+ `${base}/objects/metadata?${qs}`
3680
+ );
3681
+ },
3682
+ updateMetadata: async (params) => {
3683
+ return client.request(
3684
+ `${base}/objects/metadata`,
3685
+ { method: "PATCH", body: params }
3686
+ );
3687
+ },
3688
+ download: async (params) => {
3689
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3690
+ if (params.asText != null) qs.set("asText", String(params.asText));
3691
+ if (params.maxTextBytes != null)
3692
+ qs.set("maxTextBytes", String(params.maxTextBytes));
3693
+ return client.request(
3694
+ `${base}/objects/download?${qs}`
3695
+ );
3696
+ },
3697
+ copy: async (params) => {
3698
+ return client.request(`${base}/objects/copy`, { method: "POST", body: params });
3699
+ },
3700
+ move: async (params) => {
3701
+ return client.request(`${base}/objects/move`, { method: "POST", body: params });
3702
+ },
3703
+ getSignedUploadUrl: async (params) => {
3704
+ return client.request(
3705
+ `${base}/signed-upload-url`,
3706
+ { method: "POST", body: params }
3707
+ );
3708
+ },
3709
+ getSignedDownloadUrl: async (params) => {
3710
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3711
+ if (params.expiresInSeconds != null)
3712
+ qs.set("expiresInSeconds", String(params.expiresInSeconds));
3713
+ return client.request(
3714
+ `${base}/signed-download-url?${qs}`
3715
+ );
3716
+ },
3717
+ getSettings: async () => {
3718
+ return client.request(`${base}/settings`);
3719
+ },
3720
+ updateSettings: async (params) => {
3721
+ return client.request(`${base}/settings`, {
3722
+ method: "PATCH",
3723
+ body: params
3724
+ });
3725
+ }
3726
+ };
3727
+ }
3728
+ };
3729
+
3585
3730
  // src/index.ts
3586
3731
  var Ragable = class {
3587
3732
  constructor(options) {
3588
3733
  __publicField(this, "shift");
3589
3734
  __publicField(this, "agents");
3735
+ __publicField(this, "storage");
3590
3736
  __publicField(this, "infrastructure");
3591
3737
  const client = new RagableRequestClient(options);
3592
3738
  this.shift = new ShiftClient(client);
3593
3739
  this.agents = new AgentsClient(client);
3740
+ this.storage = new StorageClient(client);
3594
3741
  this.infrastructure = {
3595
3742
  shift: this.shift
3596
3743
  };
@@ -3654,6 +3801,7 @@ function createRagableServerClient(options) {
3654
3801
  RagableTimeoutError,
3655
3802
  SessionStorageAdapter,
3656
3803
  ShiftClient,
3804
+ StorageClient,
3657
3805
  Transport,
3658
3806
  asPostgrestResponse,
3659
3807
  assertPostgrestSuccess,
@@ -3682,7 +3830,6 @@ function createRagableServerClient(options) {
3682
3830
  parseSseDataLine,
3683
3831
  parseTransportResponse,
3684
3832
  readSseStream,
3685
- resolveRagableApiBase,
3686
3833
  runAgentChatStream,
3687
3834
  runAgentChatStreamForUi,
3688
3835
  runAgentChatStreamLenient,