@tencent-ai/workbuddy-cloud-sdk 0.1.0-dev.dee063d.202608201621 → 0.1.1-dev.111acaf.202609102031

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/lib/index.cjs CHANGED
@@ -39,6 +39,8 @@ __export(index_exports, {
39
39
  anonymousTokenProvider: () => anonymousTokenProvider,
40
40
  createMemoryStorage: () => createMemoryStorage,
41
41
  createWorkBuddyCloud: () => createWorkBuddyCloud,
42
+ getModelCapability: () => getModelCapability,
43
+ getModelDisplayName: () => getModelDisplayName,
42
44
  shouldClearCredentials: () => shouldClearCredentials
43
45
  });
44
46
  module.exports = __toCommonJS(index_exports);
@@ -73,6 +75,17 @@ function normalizeHttpUrl(value, field) {
73
75
  return trimmed.replace(/\/+$/, "");
74
76
  }
75
77
  __name(normalizeHttpUrl, "normalizeHttpUrl");
78
+ function resolveEndpoint(value) {
79
+ if (value !== void 0 && value !== null && value !== "") {
80
+ return normalizeHttpUrl(value, "endpoint");
81
+ }
82
+ const origin = globalThis.location?.origin;
83
+ if (typeof origin !== "string" || origin === "") {
84
+ throw new WorkBuddyCloudConfigError("endpoint is required outside browsers (no location.origin to fall back to).");
85
+ }
86
+ return origin.replace(/\/+$/, "");
87
+ }
88
+ __name(resolveEndpoint, "resolveEndpoint");
76
89
  function normalizePublishableKey(publishableKey) {
77
90
  if (typeof publishableKey !== "string" || publishableKey.trim() === "") {
78
91
  throw new WorkBuddyCloudConfigError("publishableKey is required and must be a non-empty string.");
@@ -96,11 +109,11 @@ function resolveFetch(candidate) {
96
109
  __name(resolveFetch, "resolveFetch");
97
110
  function resolveRuntimeConfig(options) {
98
111
  if (!options || typeof options !== "object") {
99
- throw new WorkBuddyCloudConfigError("createWorkBuddyCloud requires endpoint, oauthRelayBaseUrl and publishableKey.");
112
+ throw new WorkBuddyCloudConfigError("createWorkBuddyCloud requires publishableKey.");
100
113
  }
101
114
  return Object.freeze({
102
- endpoint: normalizeHttpUrl(options.endpoint, "endpoint"),
103
- oauthRelayBaseUrl: normalizeHttpUrl(options.oauthRelayBaseUrl, "oauthRelayBaseUrl"),
115
+ endpoint: resolveEndpoint(options.endpoint),
116
+ oauthRelayBaseUrl: options.oauthRelayBaseUrl ? normalizeHttpUrl(options.oauthRelayBaseUrl, "oauthRelayBaseUrl") : "",
104
117
  publishableKey: normalizePublishableKey(options.publishableKey),
105
118
  fetch: resolveFetch(options.fetch)
106
119
  });
@@ -144,6 +157,8 @@ var AUTH_PATHS = {
144
157
  signInWithProvider: "/v1/signin/with/provider",
145
158
  /** 本地续期端点(服务端不转发上游)。 */
146
159
  token: "/v1/token",
160
+ /** 小程序微信登录:本地认人后仍需用 custom 票据换取 TCB session。 */
161
+ loginWechat: "/v1/login-wechat",
147
162
  signOut: "/v1/user/signout",
148
163
  userMe: "/v1/user/me",
149
164
  /** 发码。 */
@@ -569,15 +584,34 @@ var AuthModule = class {
569
584
  password: credentials.password
570
585
  });
571
586
  }
587
+ /**
588
+ * 小程序 wx.login 的 code 换 Genie session。
589
+ * 试用与正式是两套独立小程序,必须带当前账号的 appid
590
+ *(`wx.getAccountInfoSync().miniProgram.appId`)。
591
+ */
592
+ async signInWithWechat(code, appid) {
593
+ if (!code) {
594
+ return fail(badRequest("signInWithWechat requires code"));
595
+ }
596
+ if (!appid) {
597
+ return fail(badRequest("signInWithWechat requires appid"));
598
+ }
599
+ return this.postForSession(AUTH_PATHS.loginWechat, {
600
+ code,
601
+ appid
602
+ });
603
+ }
572
604
  /**
573
605
  * 注册。
574
606
  *
575
607
  * 上游要求先完成验证码验证,所以必须带一个 `verificationToken`(来自
576
608
  * `verifyOtp`)。只有用户名+密码的注册会被上游明确拒绝。
609
+ *
610
+ * 账号标识用 `email` 或 `phone`(二选一,与发码渠道一致)。
577
611
  */
578
612
  async signUp(credentials) {
579
- if (!credentials.email) {
580
- return fail(badRequest("signUp requires email"));
613
+ if (!credentials.email && !credentials.phone) {
614
+ return fail(badRequest("signUp requires email or phone"));
581
615
  }
582
616
  if (!credentials.verificationToken) {
583
617
  return fail(badRequest("signUp requires a verificationToken; run sendOtp + verifyOtp first (the provider rejects username+password-only signup)"));
@@ -585,28 +619,40 @@ var AuthModule = class {
585
619
  const body = {
586
620
  verification_token: credentials.verificationToken
587
621
  };
588
- body.email = credentials.email;
622
+ if (credentials.phone) body.phone_number = normalizePhone(credentials.phone);
623
+ if (credentials.email) body.email = credentials.email;
589
624
  if (credentials.password) body.password = credentials.password;
590
625
  return this.postForSession(AUTH_PATHS.signUp, body);
591
626
  }
592
627
  /**
593
- * 发邮箱验证码。
628
+ * 发验证码(邮箱或短信,由 `credentials` 传的字段决定)。
594
629
  *
595
630
  * 这一步**不产生会话**,只返回一个 `verificationId`。发码由上游完成,
596
631
  * 我方不实现发码逻辑。
597
632
  *
598
633
  * 返回的 `isExistingUser` 决定验码之后走登录还是注册 —— 该判断由上游给出,
599
634
  * SDK 不猜。
635
+ *
636
+ * 两条渠道的请求体差异是刻意的(runtime-auth-design §3.1):
637
+ * - 邮箱:`{ email, usage: 'EMAIL' }`
638
+ * - 手机:`{ phone_number, target: 'ANY' }` —— **不带 `usage`**(普通短信登录
639
+ * 发码时省略即可,上游没有对应的短信枚举值),`target: 'ANY'` 表示新老用户
640
+ * 都允许发码。
600
641
  */
601
642
  async sendOtp(credentials) {
602
- if (!credentials.email) {
603
- return fail(badRequest("sendOtp requires email"));
643
+ const body = {};
644
+ if (credentials.phone) {
645
+ body.phone_number = normalizePhone(credentials.phone);
646
+ body.target = "ANY";
647
+ } else if (credentials.email) {
648
+ body.email = credentials.email;
649
+ body.usage = "EMAIL";
650
+ if (credentials.emailRedirectTo) {
651
+ body.email_redirect_to = credentials.emailRedirectTo;
652
+ }
653
+ } else {
654
+ return fail(badRequest("sendOtp requires email or phone"));
604
655
  }
605
- const body = {
606
- email: credentials.email,
607
- usage: "EMAIL"
608
- };
609
- if (credentials.emailRedirectTo) body.email_redirect_to = credentials.emailRedirectTo;
610
656
  const res = await this.request(AUTH_PATHS.verification, {
611
657
  method: "POST",
612
658
  body
@@ -631,15 +677,18 @@ var AuthModule = class {
631
677
  return fail(sent.error);
632
678
  }
633
679
  const { verificationId, isExistingUser } = sent.data;
680
+ const phone = credentials.phone ? normalizePhone(credentials.phone) : void 0;
634
681
  return ok({
635
682
  verificationId,
636
683
  isExistingUser,
637
684
  isUser: isExistingUser,
638
- verify: /* @__PURE__ */ __name(({ token }) => this.verifyOtp({
685
+ verify: /* @__PURE__ */ __name(({ token, password }) => this.verifyOtp({
639
686
  verificationId,
640
687
  token,
641
688
  email: credentials.email,
642
- isExistingUser
689
+ phone,
690
+ isExistingUser,
691
+ password
643
692
  }), "verify")
644
693
  });
645
694
  }
@@ -652,10 +701,14 @@ var AuthModule = class {
652
701
  * 走登录还是注册由 `isExistingUser` 决定(`sendOtp` 的返回值)。刻意不做
653
702
  * 「先试登录失败再试注册」的兜底:那会把「密码错」这类真实错误掩盖成一次
654
703
  * 莫名的注册尝试。
704
+ *
705
+ * 登录侧邮箱与手机号共用 `username` 字段 —— 上游 `SignInRequest.username`
706
+ * 承载邮箱/手机/用户名三种形态(runtime-auth-design §3.2)。
655
707
  */
656
708
  async verifyOtp(params) {
657
- if (!params.verificationId || !params.token || !params.email) {
658
- return fail(badRequest("verifyOtp requires verificationId, token and email"));
709
+ const identifier = params.phone ? normalizePhone(params.phone) : params.email ?? "";
710
+ if (!params.verificationId || !params.token || !identifier) {
711
+ return fail(badRequest("verifyOtp requires verificationId, token and either email or phone"));
659
712
  }
660
713
  const verified = await this.request(AUTH_PATHS.verificationVerify, {
661
714
  method: "POST",
@@ -674,12 +727,13 @@ var AuthModule = class {
674
727
  }
675
728
  if (params.isExistingUser) {
676
729
  return this.postForSession(AUTH_PATHS.signIn, {
677
- username: params.email,
730
+ username: identifier,
678
731
  verification_token: verificationToken
679
732
  });
680
733
  }
681
734
  return this.signUp({
682
735
  email: params.email,
736
+ phone: params.phone,
683
737
  password: params.password ?? "",
684
738
  verificationToken
685
739
  });
@@ -696,8 +750,13 @@ var AuthModule = class {
696
750
  *
697
751
  * SDK 不自己跳转(不写 `location.href`):跳转时机应由应用决定 —— 有的要
698
752
  * 先存草稿,有的在 iframe 里要开弹窗。返回 url 交调用方处置。
753
+ *
754
+ * @deprecated Google 登录已下线,新应用不应再调用该方法。
699
755
  */
700
756
  async signInWithOAuth(options) {
757
+ if (!this.oauthRelayBaseUrl) {
758
+ return fail(badRequest("signInWithOAuth requires oauthRelayBaseUrl"));
759
+ }
701
760
  if (options.provider !== "google") {
702
761
  return fail(badRequest("signInWithOAuth currently supports only google"));
703
762
  }
@@ -712,6 +771,8 @@ var AuthModule = class {
712
771
  *
713
772
  * 在回调落地页调一次即可。`code` 缺失时返回 `null` 数据而**不是**错误 ——
714
773
  * 落地页可能被直接访问(用户收藏了它),那不是失败。
774
+ *
775
+ * @deprecated Google 登录已下线,新应用不应再调用该方法。
715
776
  */
716
777
  async handleOAuthCallback(search) {
717
778
  const callbackInput = search ?? currentPageSearch();
@@ -946,7 +1007,11 @@ var AuthModule = class {
946
1007
  // ------------------------------------------------------------------
947
1008
  // 内部
948
1009
  // ------------------------------------------------------------------
949
- /** 拼出平台 Relay 授权地址;state 由 Relay 自己签发、校验并一次性消费。 */
1010
+ /**
1011
+ * 拼出平台 Relay 授权地址;state 由 Relay 自己签发、校验并一次性消费。
1012
+ *
1013
+ * @deprecated Google 登录已下线,仅保留给存量应用的回调落地页。
1014
+ */
950
1015
  async startRelayOAuth(options, redirectTo) {
951
1016
  const callback = new URL(redirectTo);
952
1017
  const relay = new URL(`${this.oauthRelayBaseUrl}/authorize`);
@@ -1042,6 +1107,17 @@ function badRequest(message) {
1042
1107
  };
1043
1108
  }
1044
1109
  __name(badRequest, "badRequest");
1110
+ function normalizePhone(phone) {
1111
+ const digits = phone.replace(/\D/g, "");
1112
+ let local = digits;
1113
+ if (local.startsWith("0086")) {
1114
+ local = local.slice(4);
1115
+ } else if (local.startsWith("86") && local.length === 13) {
1116
+ local = local.slice(2);
1117
+ }
1118
+ return /^1\d{10}$/.test(local) ? `+86 ${local}` : phone;
1119
+ }
1120
+ __name(normalizePhone, "normalizePhone");
1045
1121
  function isCloudError(v) {
1046
1122
  return !!v && typeof v === "object" && typeof v.kind === "string";
1047
1123
  }
@@ -5140,9 +5216,42 @@ function pricingField(value) {
5140
5216
  return Object.keys(pricing).length ? pricing : void 0;
5141
5217
  }
5142
5218
  __name(pricingField, "pricingField");
5219
+ function reasoningField(value) {
5220
+ if (!value || typeof value !== "object") return void 0;
5221
+ const raw = value;
5222
+ const result = {};
5223
+ const effort = stringField(raw.effort);
5224
+ if (effort !== void 0) result.effort = effort;
5225
+ const defaultEffort = stringField(raw.defaultEffort);
5226
+ if (defaultEffort !== void 0) result.defaultEffort = defaultEffort;
5227
+ if (Array.isArray(raw.supportedEfforts)) {
5228
+ result.supportedEfforts = raw.supportedEfforts.filter((item) => typeof item === "string");
5229
+ }
5230
+ const rawSummary = stringField(raw.summary);
5231
+ if (rawSummary !== void 0 && (rawSummary === "auto" || rawSummary === "concise" || rawSummary === "detailed")) {
5232
+ result.summary = rawSummary;
5233
+ }
5234
+ const canDisable = booleanField(raw.canDisableThinking);
5235
+ if (canDisable !== void 0) result.canDisableThinking = canDisable;
5236
+ return Object.keys(result).length > 0 ? result : void 0;
5237
+ }
5238
+ __name(reasoningField, "reasoningField");
5143
5239
  function normalizeModel(raw) {
5144
5240
  const id = stringField(raw.id, raw.ID);
5145
5241
  if (!id) return null;
5242
+ const serverEnabled = booleanField(raw.enabled, raw.Enabled);
5243
+ const serverDisabled = booleanField(raw.disabled, raw.Disabled);
5244
+ let enabled;
5245
+ let disabled;
5246
+ if (serverEnabled !== void 0) {
5247
+ enabled = serverEnabled;
5248
+ if (serverDisabled !== void 0) disabled = serverDisabled;
5249
+ } else if (serverDisabled !== void 0) {
5250
+ disabled = serverDisabled;
5251
+ enabled = !serverDisabled;
5252
+ } else {
5253
+ enabled = true;
5254
+ }
5146
5255
  return {
5147
5256
  id,
5148
5257
  name: stringField(raw.name, raw.Name) ?? id,
@@ -5185,7 +5294,10 @@ function normalizeModel(raw) {
5185
5294
  ...capabilitiesField(raw.capabilities ?? raw.Capabilities) ? {
5186
5295
  capabilities: capabilitiesField(raw.capabilities ?? raw.Capabilities)
5187
5296
  } : {},
5188
- enabled: booleanField(raw.enabled, raw.Enabled) ?? true,
5297
+ enabled,
5298
+ ...disabled !== void 0 ? {
5299
+ disabled
5300
+ } : {},
5189
5301
  ...booleanField(raw.isDefault, raw.IsDefault) !== void 0 ? {
5190
5302
  isDefault: booleanField(raw.isDefault, raw.IsDefault)
5191
5303
  } : {},
@@ -5194,10 +5306,55 @@ function normalizeModel(raw) {
5194
5306
  } : {},
5195
5307
  ...pricingField(raw.pricing ?? raw.Pricing) ? {
5196
5308
  pricing: pricingField(raw.pricing ?? raw.Pricing)
5309
+ } : {},
5310
+ // User-specified sparse fields: preserve explicit false/0, omit only when absent.
5311
+ ...stringField(raw.credits, raw.Credits) ? {
5312
+ credits: stringField(raw.credits, raw.Credits)
5313
+ } : {},
5314
+ ...numberField(raw.maxAllowedSize, raw.MaxAllowedSize) !== void 0 ? {
5315
+ maxAllowedSize: numberField(raw.maxAllowedSize, raw.MaxAllowedSize)
5316
+ } : {},
5317
+ ...booleanField(raw.disabledMultimodal, raw.DisabledMultimodal) !== void 0 ? {
5318
+ disabledMultimodal: booleanField(raw.disabledMultimodal, raw.DisabledMultimodal)
5319
+ } : {},
5320
+ ...booleanField(raw.supportsImages, raw.SupportsImages) !== void 0 ? {
5321
+ supportsImages: booleanField(raw.supportsImages, raw.SupportsImages)
5322
+ } : {},
5323
+ ...booleanField(raw.supportsToolCall, raw.SupportsToolCall) !== void 0 ? {
5324
+ supportsToolCall: booleanField(raw.supportsToolCall, raw.SupportsToolCall)
5325
+ } : {},
5326
+ ...booleanField(raw.supportsReasoning, raw.SupportsReasoning) !== void 0 ? {
5327
+ supportsReasoning: booleanField(raw.supportsReasoning, raw.SupportsReasoning)
5328
+ } : {},
5329
+ ...booleanField(raw.onlyReasoning, raw.OnlyReasoning) !== void 0 ? {
5330
+ onlyReasoning: booleanField(raw.onlyReasoning, raw.OnlyReasoning)
5331
+ } : {},
5332
+ ...reasoningField(raw.reasoning ?? raw.Reasoning) ? {
5333
+ reasoning: reasoningField(raw.reasoning ?? raw.Reasoning)
5334
+ } : {},
5335
+ ...numberField(raw.temperature, raw.Temperature) !== void 0 ? {
5336
+ temperature: numberField(raw.temperature, raw.Temperature)
5337
+ } : {},
5338
+ ...numberField(raw.top_k, raw.Top_K) !== void 0 ? {
5339
+ top_k: numberField(raw.top_k, raw.Top_K)
5340
+ } : {},
5341
+ ...numberField(raw.top_p, raw.Top_P) !== void 0 ? {
5342
+ top_p: numberField(raw.top_p, raw.Top_P)
5343
+ } : {},
5344
+ ...numberField(raw.repetition_penalty, raw.Repetition_Penalty) !== void 0 ? {
5345
+ repetition_penalty: numberField(raw.repetition_penalty, raw.Repetition_Penalty)
5197
5346
  } : {}
5198
5347
  };
5199
5348
  }
5200
5349
  __name(normalizeModel, "normalizeModel");
5350
+ function getModelDisplayName(model) {
5351
+ return model.name || model.id;
5352
+ }
5353
+ __name(getModelDisplayName, "getModelDisplayName");
5354
+ function getModelCapability(model, capability) {
5355
+ return model.capabilities?.[capability];
5356
+ }
5357
+ __name(getModelCapability, "getModelCapability");
5201
5358
  var ModelsAPI = class {
5202
5359
  static {
5203
5360
  __name(this, "ModelsAPI");
@@ -5213,8 +5370,8 @@ var ModelsAPI = class {
5213
5370
  *
5214
5371
  * `id` is the value to pass as `model` to `chat.completions.create()`.
5215
5372
  * Optional metadata is included only when the server explicitly provides
5216
- * it; absence means unknown, not unsupported. The server remains the
5217
- * final allowlist authority for chat requests.
5373
+ * it; absence means unknown, not unsupported. The actual call result
5374
+ * is determined by the response, not by the directory entry.
5218
5375
  */
5219
5376
  async list(signal) {
5220
5377
  let response;
@@ -5487,7 +5644,10 @@ async function* iterSSEEvents(body, signal) {
5487
5644
  __name(iterSSEEvents, "iterSSEEvents");
5488
5645
 
5489
5646
  // src/modules/llm/chat.ts
5490
- function extractSSEError(data) {
5647
+ function extractSSEError(data, requestId) {
5648
+ const init = requestId ? {
5649
+ requestId
5650
+ } : {};
5491
5651
  try {
5492
5652
  const parsed = JSON.parse(data);
5493
5653
  if (parsed && typeof parsed === "object") {
@@ -5498,7 +5658,7 @@ function extractSSEError(data) {
5498
5658
  type: typeof errorObj.type === "string" ? errorObj.type : "server_error",
5499
5659
  param: errorObj.param === void 0 ? null : errorObj.param,
5500
5660
  code: errorObj.code === void 0 ? null : errorObj.code
5501
- });
5661
+ }, init);
5502
5662
  }
5503
5663
  }
5504
5664
  } catch {
@@ -5508,7 +5668,7 @@ function extractSSEError(data) {
5508
5668
  type: "server_error",
5509
5669
  param: null,
5510
5670
  code: null
5511
- });
5671
+ }, init);
5512
5672
  }
5513
5673
  __name(extractSSEError, "extractSSEError");
5514
5674
  var ChatCompletionsAPI = class {
@@ -5522,72 +5682,28 @@ var ChatCompletionsAPI = class {
5522
5682
  this.fetch = fetch2;
5523
5683
  }
5524
5684
  create(input) {
5525
- if (input.stream === true) {
5526
- return this.createStreaming(input);
5527
- }
5528
- return this.createNonStreaming(input);
5529
- }
5530
- /**
5531
- * Non-streaming chat completion.
5532
- */
5533
- async createNonStreaming(input) {
5534
- if (input.stream_options) {
5685
+ if (input.stream !== true) {
5535
5686
  throw new CloudOpenAIError({
5536
- message: "stream_options can only be used with stream=true",
5687
+ message: "stream must be true; non-streaming chat completions are not supported",
5537
5688
  type: "invalid_request_error",
5538
- param: "stream_options",
5539
- code: "request_invalid_parameter"
5540
- });
5541
- }
5542
- const { signal, ...body } = input;
5543
- if (body.stream === void 0) {
5544
- delete body.stream;
5545
- } else {
5546
- body.stream = false;
5547
- }
5548
- let response;
5549
- try {
5550
- response = await this.fetch(`${this.baseUrl}/chat/completions`, {
5551
- method: "POST",
5552
- headers: {
5553
- Accept: "application/json",
5554
- "Content-Type": "application/json"
5555
- },
5556
- body: JSON.stringify(body),
5557
- signal
5558
- });
5559
- } catch (err) {
5560
- if (err instanceof Error && err.name === "AbortError") {
5561
- throw err;
5562
- }
5563
- throw new CloudOpenAIError({
5564
- message: `Network error: ${err?.message ?? "unknown"}`,
5565
- type: "server_error",
5566
- param: null,
5567
- code: "gateway_network_error"
5568
- }, {
5569
- cause: err
5570
- });
5571
- }
5572
- if (!response.ok) {
5573
- throw await httpError(response);
5574
- }
5575
- const text = await response.text();
5576
- try {
5577
- return JSON.parse(text);
5578
- } catch {
5579
- throw new CloudOpenAIError({
5580
- message: "Failed to parse chat completion response: invalid JSON",
5581
- type: "server_error",
5582
- param: null,
5583
- code: "gateway_invalid_response"
5689
+ param: "stream",
5690
+ code: "request_stream_required"
5584
5691
  });
5585
5692
  }
5693
+ return this.createStreaming(input);
5586
5694
  }
5587
5695
  /**
5588
5696
  * Streaming chat completion — returns an async generator of chunks.
5589
5697
  *
5590
5698
  * Reads the SSE stream incrementally, yielding ChatCompletionChunk objects.
5699
+ * `stream_options` is passed through unchanged when present.
5700
+ *
5701
+ * The `X-Request-Id` response header is captured and attached (as
5702
+ * `requestId`) to every `CloudOpenAIError` thrown from within the stream:
5703
+ * `event: error`, chunk-embedded error, JSON parse failure, and missing
5704
+ * `[DONE]` interruption. Non-2xx HTTP errors continue to go through
5705
+ * `httpError`, which independently extracts `X-Request-Id`.
5706
+ *
5591
5707
  * Throws CloudOpenAIError on:
5592
5708
  * - `event: error` in the stream
5593
5709
  * - Stream ends without `[DONE]` (gateway_stream_interrupted)
@@ -5595,7 +5711,7 @@ var ChatCompletionsAPI = class {
5595
5711
  * - Caller abort (AbortSignal) — exits silently, no throw
5596
5712
  */
5597
5713
  async *createStreaming(input) {
5598
- const { signal, ...body } = input;
5714
+ const { signal, conversationId, ...body } = input;
5599
5715
  body.stream = true;
5600
5716
  let response;
5601
5717
  try {
@@ -5603,7 +5719,10 @@ var ChatCompletionsAPI = class {
5603
5719
  method: "POST",
5604
5720
  headers: {
5605
5721
  Accept: "text/event-stream",
5606
- "Content-Type": "application/json"
5722
+ "Content-Type": "application/json",
5723
+ ...conversationId !== void 0 ? {
5724
+ "X-Conversation-ID": conversationId
5725
+ } : {}
5607
5726
  },
5608
5727
  body: JSON.stringify(body),
5609
5728
  signal
@@ -5630,15 +5749,18 @@ var ChatCompletionsAPI = class {
5630
5749
  type: "server_error",
5631
5750
  param: null,
5632
5751
  code: "gateway_invalid_response"
5752
+ }, {
5753
+ requestId: response.headers.get("x-request-id") ?? void 0
5633
5754
  });
5634
5755
  }
5756
+ const requestId = response.headers.get("x-request-id") ?? void 0;
5635
5757
  let receivedDone = false;
5636
5758
  let threw = false;
5637
5759
  try {
5638
5760
  for await (const sseEvent of iterSSEEvents(response.body, signal)) {
5639
5761
  if (sseEvent.event === "error") {
5640
5762
  threw = true;
5641
- throw extractSSEError(sseEvent.data);
5763
+ throw extractSSEError(sseEvent.data, requestId);
5642
5764
  }
5643
5765
  if (sseEvent.event === null || sseEvent.event === "") {
5644
5766
  if (sseEvent.data === SSE_DONE) {
@@ -5658,6 +5780,8 @@ var ChatCompletionsAPI = class {
5658
5780
  type: "server_error",
5659
5781
  param: null,
5660
5782
  code: "gateway_invalid_response"
5783
+ }, {
5784
+ requestId
5661
5785
  });
5662
5786
  }
5663
5787
  if (chunk && typeof chunk === "object" && "error" in chunk) {
@@ -5668,6 +5792,8 @@ var ChatCompletionsAPI = class {
5668
5792
  type: typeof errObj?.type === "string" ? errObj.type : "server_error",
5669
5793
  param: errObj?.param === void 0 ? null : errObj.param,
5670
5794
  code: errObj?.code === void 0 ? null : errObj.code
5795
+ }, {
5796
+ requestId
5671
5797
  });
5672
5798
  }
5673
5799
  yield chunk;
@@ -5686,6 +5812,8 @@ var ChatCompletionsAPI = class {
5686
5812
  type: "server_error",
5687
5813
  param: null,
5688
5814
  code: "gateway_stream_interrupted"
5815
+ }, {
5816
+ requestId
5689
5817
  });
5690
5818
  }
5691
5819
  }
@@ -5832,22 +5960,6 @@ var recursiveToCamel = /* @__PURE__ */ __name((item) => {
5832
5960
  });
5833
5961
  return result;
5834
5962
  }, "recursiveToCamel");
5835
- var isValidBucketName = /* @__PURE__ */ __name((bucketName) => {
5836
- if (!bucketName || typeof bucketName !== "string") {
5837
- return false;
5838
- }
5839
- if (bucketName.length === 0 || bucketName.length > 100) {
5840
- return false;
5841
- }
5842
- if (bucketName.trim() !== bucketName) {
5843
- return false;
5844
- }
5845
- if (bucketName.includes("/") || bucketName.includes("\\")) {
5846
- return false;
5847
- }
5848
- const bucketNameRegex = /^[\w!.\*'() &$@=;:+,?-]+$/;
5849
- return bucketNameRegex.test(bucketName);
5850
- }, "isValidBucketName");
5851
5963
  var encodeStoragePath = /* @__PURE__ */ __name((path) => path.split("/").map(encodeURIComponent).join("/"), "encodeStoragePath");
5852
5964
 
5853
5965
  // src/vendor/storage/lib/common/fetch.ts
@@ -7398,1562 +7510,32 @@ var DEFAULT_HEADERS = {
7398
7510
  "X-Client-Info": `storage-js/${version}`
7399
7511
  };
7400
7512
 
7401
- // src/vendor/storage/packages/StorageBucketApi.ts
7402
- var StorageBucketApi = class extends BaseApiClient {
7513
+ // src/modules/storage.ts
7514
+ var RUNTIME_STORAGE_BUCKET = "runtime";
7515
+ var DEFAULT_SIGNED_URL_TTL_SECONDS = 10 * 60;
7516
+ var MAX_SIGNED_URL_TTL_SECONDS = 60 * 60;
7517
+ var CloudStoragePathError = class extends Error {
7403
7518
  static {
7404
- __name(this, "StorageBucketApi");
7405
- }
7406
- constructor(url, headers = {}, fetch2, opts) {
7407
- const baseUrl = new URL(url);
7408
- if (opts?.useNewHostname) {
7409
- const isSupabaseHost = /supabase\.(co|in|red)$/.test(baseUrl.hostname);
7410
- if (isSupabaseHost && !baseUrl.hostname.includes("storage.supabase.")) {
7411
- baseUrl.hostname = baseUrl.hostname.replace("supabase.", "storage.supabase.");
7412
- }
7413
- }
7414
- const finalUrl = baseUrl.href.replace(/\/$/, "");
7415
- const finalHeaders = {
7416
- ...DEFAULT_HEADERS,
7417
- ...headers
7418
- };
7419
- super(finalUrl, finalHeaders, fetch2, "storage");
7519
+ __name(this, "CloudStoragePathError");
7420
7520
  }
7421
- /**
7422
- * Retrieves the details of all Storage buckets within an existing project.
7423
- *
7424
- * @category Storage
7425
- * @subcategory File Buckets
7426
- * @param options Query parameters for listing buckets
7427
- * @param options.limit Maximum number of buckets to return
7428
- * @param options.offset Number of buckets to skip
7429
- * @param options.sortColumn Column to sort by ('id', 'name', 'created_at', 'updated_at')
7430
- * @param options.sortOrder Sort order ('asc' or 'desc')
7431
- * @param options.search Search term to filter bucket names
7432
- * @returns Promise with response containing array of buckets or error
7433
- *
7434
- * @example List buckets
7435
- * ```js
7436
- * const { data, error } = await supabase
7437
- * .storage
7438
- * .listBuckets()
7439
- * ```
7440
- *
7441
- * @example List buckets with options
7442
- * ```js
7443
- * const { data, error } = await supabase
7444
- * .storage
7445
- * .listBuckets({
7446
- * limit: 10,
7447
- * offset: 0,
7448
- * sortColumn: 'created_at',
7449
- * sortOrder: 'desc',
7450
- * search: 'prod'
7451
- * })
7452
- * ```
7453
- *
7454
- * @remarks
7455
- * - RLS policy permissions required:
7456
- * - `buckets` table permissions: `select`
7457
- * - `objects` table permissions: none
7458
- * - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
7459
- */
7460
- async listBuckets(options) {
7461
- return this.handleOperation(async () => {
7462
- const queryString = this.listBucketOptionsToQueryString(options);
7463
- return await get(this.fetch, `${this.url}/bucket${queryString}`, {
7464
- headers: this.headers
7465
- });
7466
- });
7521
+ constructor(message) {
7522
+ super(message);
7523
+ this.name = "CloudStoragePathError";
7467
7524
  }
7468
- /**
7469
- * Retrieves the details of an existing Storage bucket.
7470
- *
7471
- * @category Storage
7472
- * @subcategory File Buckets
7473
- * @param id The unique identifier of the bucket you would like to retrieve.
7474
- * @returns Promise with response containing bucket details or error
7475
- *
7476
- * @example Get bucket
7477
- * ```js
7478
- * const { data, error } = await supabase
7479
- * .storage
7480
- * .getBucket('avatars')
7481
- * ```
7482
- *
7483
- * Response:
7484
- * ```json
7485
- * {
7486
- * "data": {
7487
- * "id": "avatars",
7488
- * "name": "avatars",
7489
- * "owner": "",
7490
- * "public": false,
7491
- * "file_size_limit": 1024,
7492
- * "allowed_mime_types": [
7493
- * "image/png"
7494
- * ],
7495
- * "created_at": "2024-05-22T22:26:05.100Z",
7496
- * "updated_at": "2024-05-22T22:26:05.100Z"
7497
- * },
7498
- * "error": null
7499
- * }
7500
- * ```
7501
- *
7502
- * @remarks
7503
- * - RLS policy permissions required:
7504
- * - `buckets` table permissions: `select`
7505
- * - `objects` table permissions: none
7506
- * - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
7507
- */
7508
- async getBucket(id) {
7509
- return this.handleOperation(async () => {
7510
- return await get(this.fetch, `${this.url}/bucket/${id}`, {
7511
- headers: this.headers
7512
- });
7513
- });
7525
+ };
7526
+ var WorkBuddyStorageDownload = class {
7527
+ static {
7528
+ __name(this, "WorkBuddyStorageDownload");
7514
7529
  }
7515
- /**
7516
- * Creates a new Storage bucket
7517
- *
7518
- * @category Storage
7519
- * @subcategory File Buckets
7520
- * @param id A unique identifier for the bucket you are creating.
7521
- * @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations. By default, buckets are private.
7522
- * @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
7523
- * The global file size limit takes precedence over this value.
7524
- * The default value is null, which doesn't set a per bucket file size limit.
7525
- * @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
7526
- * The default value is null, which allows files with all mime types to be uploaded.
7527
- * Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
7528
- * @param options.type (private-beta) specifies the bucket type. see `BucketType` for more details.
7529
- * - default bucket type is `STANDARD`
7530
- * @returns Promise with response containing newly created bucket name or error
7531
- *
7532
- * @example Create bucket
7533
- * ```js
7534
- * const { data, error } = await supabase
7535
- * .storage
7536
- * .createBucket('avatars', {
7537
- * public: false,
7538
- * allowedMimeTypes: ['image/png'],
7539
- * fileSizeLimit: 1024
7540
- * })
7541
- * ```
7542
- *
7543
- * Response:
7544
- * ```json
7545
- * {
7546
- * "data": {
7547
- * "name": "avatars"
7548
- * },
7549
- * "error": null
7550
- * }
7551
- * ```
7552
- *
7553
- * @remarks
7554
- * - RLS policy permissions required:
7555
- * - `buckets` table permissions: `insert`
7556
- * - `objects` table permissions: none
7557
- * - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
7558
- */
7559
- async createBucket(id, options = {
7560
- public: false
7561
- }) {
7562
- return this.handleOperation(async () => {
7563
- return await post(this.fetch, `${this.url}/bucket`, {
7564
- id,
7565
- name: id,
7566
- type: options.type,
7567
- public: options.public,
7568
- file_size_limit: options.fileSizeLimit,
7569
- allowed_mime_types: options.allowedMimeTypes
7570
- }, {
7571
- headers: this.headers
7572
- });
7573
- });
7530
+ blob;
7531
+ stream;
7532
+ [Symbol.toStringTag] = "WorkBuddyStorageDownload";
7533
+ constructor(blob, stream) {
7534
+ this.blob = blob;
7535
+ this.stream = stream;
7574
7536
  }
7575
- /**
7576
- * Updates a Storage bucket
7577
- *
7578
- * @category Storage
7579
- * @subcategory File Buckets
7580
- * @param id A unique identifier for the bucket you are updating.
7581
- * @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations.
7582
- * @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
7583
- * The global file size limit takes precedence over this value.
7584
- * The default value is null, which doesn't set a per bucket file size limit.
7585
- * @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
7586
- * The default value is null, which allows files with all mime types to be uploaded.
7587
- * Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
7588
- * @returns Promise with response containing success message or error
7589
- *
7590
- * @example Update bucket
7591
- * ```js
7592
- * const { data, error } = await supabase
7593
- * .storage
7594
- * .updateBucket('avatars', {
7595
- * public: false,
7596
- * allowedMimeTypes: ['image/png'],
7597
- * fileSizeLimit: 1024
7598
- * })
7599
- * ```
7600
- *
7601
- * Response:
7602
- * ```json
7603
- * {
7604
- * "data": {
7605
- * "message": "Successfully updated"
7606
- * },
7607
- * "error": null
7608
- * }
7609
- * ```
7610
- *
7611
- * @remarks
7612
- * - RLS policy permissions required:
7613
- * - `buckets` table permissions: `select` and `update`
7614
- * - `objects` table permissions: none
7615
- * - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
7616
- */
7617
- async updateBucket(id, options) {
7618
- return this.handleOperation(async () => {
7619
- return await put(this.fetch, `${this.url}/bucket/${id}`, {
7620
- id,
7621
- name: id,
7622
- public: options.public,
7623
- file_size_limit: options.fileSizeLimit,
7624
- allowed_mime_types: options.allowedMimeTypes
7625
- }, {
7626
- headers: this.headers
7627
- });
7628
- });
7629
- }
7630
- /**
7631
- * Removes all objects inside a single bucket.
7632
- *
7633
- * @category Storage
7634
- * @subcategory File Buckets
7635
- * @param id The unique identifier of the bucket you would like to empty.
7636
- * @returns Promise with success message or error
7637
- *
7638
- * @example Empty bucket
7639
- * ```js
7640
- * const { data, error } = await supabase
7641
- * .storage
7642
- * .emptyBucket('avatars')
7643
- * ```
7644
- *
7645
- * Response:
7646
- * ```json
7647
- * {
7648
- * "data": {
7649
- * "message": "Successfully emptied"
7650
- * },
7651
- * "error": null
7652
- * }
7653
- * ```
7654
- *
7655
- * @remarks
7656
- * - RLS policy permissions required:
7657
- * - `buckets` table permissions: `select`
7658
- * - `objects` table permissions: `select` and `delete`
7659
- * - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
7660
- */
7661
- async emptyBucket(id) {
7662
- return this.handleOperation(async () => {
7663
- return await post(this.fetch, `${this.url}/bucket/${id}/empty`, {}, {
7664
- headers: this.headers
7665
- });
7666
- });
7667
- }
7668
- /**
7669
- * Deletes an existing bucket. A bucket can't be deleted with existing objects inside it.
7670
- * You must first `empty()` the bucket.
7671
- *
7672
- * @category Storage
7673
- * @subcategory File Buckets
7674
- * @param id The unique identifier of the bucket you would like to delete.
7675
- * @returns Promise with success message or error
7676
- *
7677
- * @example Delete bucket
7678
- * ```js
7679
- * const { data, error } = await supabase
7680
- * .storage
7681
- * .deleteBucket('avatars')
7682
- * ```
7683
- *
7684
- * Response:
7685
- * ```json
7686
- * {
7687
- * "data": {
7688
- * "message": "Successfully deleted"
7689
- * },
7690
- * "error": null
7691
- * }
7692
- * ```
7693
- *
7694
- * @remarks
7695
- * - RLS policy permissions required:
7696
- * - `buckets` table permissions: `select` and `delete`
7697
- * - `objects` table permissions: none
7698
- * - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
7699
- */
7700
- async deleteBucket(id) {
7701
- return this.handleOperation(async () => {
7702
- return await remove(this.fetch, `${this.url}/bucket/${id}`, {}, {
7703
- headers: this.headers
7704
- });
7705
- });
7706
- }
7707
- /**
7708
- * Purges the CDN cache for an entire bucket.
7709
- *
7710
- * Maps to `DELETE /cdn/{bucket}` on the Storage API. The server
7711
- * issues a CDN invalidation for the bucket and returns `{ message: 'success' }`.
7712
- *
7713
- * **Requires the `service_role` key.** The underlying endpoint enforces
7714
- * `service_role` JWT — calls made with the anon key or a user JWT will be
7715
- * rejected by the server.
7716
- *
7717
- * **Hosted CDN feature.** On self-hosted Supabase, the Storage service must
7718
- * have `CDN_PURGE_ENDPOINT_URL` configured and the `purgeCache` tenant
7719
- * feature enabled, otherwise the server returns an error.
7720
- *
7721
- * @category Storage
7722
- * @subcategory File Buckets
7723
- * @param id The unique identifier of the bucket you would like to purge from cache.
7724
- * @param options Optional purge cache options.
7725
- * @param options.transformations If true, purges only transformations (resized/formatted variants), leaving original cached files intact.
7726
- * @param parameters Optional fetch parameters such as an `AbortController` signal.
7727
- * @returns Promise with `{ data: { message }, error: null }` on success or `{ data: null, error }` on failure.
7728
- *
7729
- * @example Purge cache for an entire bucket
7730
- * ```js
7731
- * const { data, error } = await supabase
7732
- * .storage
7733
- * .purgeBucketCache('avatars')
7734
- * ```
7735
- *
7736
- * @example Purge only transformations for an entire bucket
7737
- * ```js
7738
- * const { data, error } = await supabase
7739
- * .storage
7740
- * .purgeBucketCache('avatars', { transformations: true })
7741
- * ```
7742
- */
7743
- async purgeBucketCache(id, options, parameters) {
7744
- return this.handleOperation(async () => {
7745
- const query = new URLSearchParams();
7746
- if (options?.transformations) {
7747
- query.set("transformations", "true");
7748
- }
7749
- const queryString = query.toString();
7750
- return await remove(this.fetch, `${this.url}/cdn/${encodeStoragePath(id)}${queryString ? `?${queryString}` : ""}`, {}, {
7751
- headers: this.headers
7752
- }, parameters);
7753
- });
7754
- }
7755
- listBucketOptionsToQueryString(options) {
7756
- const params = {};
7757
- if (options) {
7758
- if ("limit" in options) {
7759
- params.limit = String(options.limit);
7760
- }
7761
- if ("offset" in options) {
7762
- params.offset = String(options.offset);
7763
- }
7764
- if (options.search) {
7765
- params.search = options.search;
7766
- }
7767
- if (options.sortColumn) {
7768
- params.sortColumn = options.sortColumn;
7769
- }
7770
- if (options.sortOrder) {
7771
- params.sortOrder = options.sortOrder;
7772
- }
7773
- }
7774
- return Object.keys(params).length > 0 ? "?" + new URLSearchParams(params).toString() : "";
7775
- }
7776
- };
7777
-
7778
- // src/vendor/storage/packages/StorageAnalyticsClient.ts
7779
- var import_iceberg_js = require("iceberg-js");
7780
- var StorageAnalyticsClient = class extends BaseApiClient {
7781
- static {
7782
- __name(this, "StorageAnalyticsClient");
7783
- }
7784
- /**
7785
- * @alpha
7786
- *
7787
- * Creates a new StorageAnalyticsClient instance
7788
- *
7789
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
7790
- *
7791
- * @category Storage
7792
- * @subcategory Analytics Buckets
7793
- * @param url - The base URL for the storage API
7794
- * @param headers - HTTP headers to include in requests
7795
- * @param fetch - Optional custom fetch implementation
7796
- *
7797
- * @example Using supabase-js (recommended)
7798
- * ```typescript
7799
- * import { createClient } from '@supabase/supabase-js'
7800
- *
7801
- * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
7802
- * const { data, error } = await supabase.storage.analytics.listBuckets()
7803
- * ```
7804
- *
7805
- * @example Standalone import for bundle-sensitive environments
7806
- * ```typescript
7807
- * import { StorageAnalyticsClient } from '@supabase/storage-js'
7808
- *
7809
- * const client = new StorageAnalyticsClient(url, headers)
7810
- * ```
7811
- */
7812
- constructor(url, headers = {}, fetch2) {
7813
- const finalUrl = url.replace(/\/$/, "");
7814
- const finalHeaders = {
7815
- ...DEFAULT_HEADERS,
7816
- ...headers
7817
- };
7818
- super(finalUrl, finalHeaders, fetch2, "storage");
7819
- }
7820
- /**
7821
- * @alpha
7822
- *
7823
- * Creates a new analytics bucket using Iceberg tables
7824
- * Analytics buckets are optimized for analytical queries and data processing
7825
- *
7826
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
7827
- *
7828
- * @category Storage
7829
- * @subcategory Analytics Buckets
7830
- * @param name A unique name for the bucket you are creating
7831
- * @returns Promise with response containing newly created analytics bucket or error
7832
- *
7833
- * @example Create analytics bucket
7834
- * ```js
7835
- * const { data, error } = await supabase
7836
- * .storage
7837
- * .analytics
7838
- * .createBucket('analytics-data')
7839
- * ```
7840
- *
7841
- * Response:
7842
- * ```json
7843
- * {
7844
- * "data": {
7845
- * "name": "analytics-data",
7846
- * "type": "ANALYTICS",
7847
- * "format": "iceberg",
7848
- * "created_at": "2024-05-22T22:26:05.100Z",
7849
- * "updated_at": "2024-05-22T22:26:05.100Z"
7850
- * },
7851
- * "error": null
7852
- * }
7853
- * ```
7854
- *
7855
- * @remarks
7856
- * - Creates a new analytics bucket using Iceberg tables
7857
- * - Analytics buckets are optimized for analytical queries and data processing
7858
- */
7859
- async createBucket(name) {
7860
- return this.handleOperation(async () => {
7861
- return await post(this.fetch, `${this.url}/bucket`, {
7862
- name
7863
- }, {
7864
- headers: this.headers
7865
- });
7866
- });
7867
- }
7868
- /**
7869
- * @alpha
7870
- *
7871
- * Retrieves the details of all Analytics Storage buckets within an existing project
7872
- * Only returns buckets of type 'ANALYTICS'
7873
- *
7874
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
7875
- *
7876
- * @category Storage
7877
- * @subcategory Analytics Buckets
7878
- * @param options Query parameters for listing buckets
7879
- * @param options.limit Maximum number of buckets to return
7880
- * @param options.offset Number of buckets to skip
7881
- * @param options.sortColumn Column to sort by ('name', 'created_at', 'updated_at')
7882
- * @param options.sortOrder Sort order ('asc' or 'desc')
7883
- * @param options.search Search term to filter bucket names
7884
- * @returns Promise with response containing array of analytics buckets or error
7885
- *
7886
- * @example List analytics buckets
7887
- * ```js
7888
- * const { data, error } = await supabase
7889
- * .storage
7890
- * .analytics
7891
- * .listBuckets({
7892
- * limit: 10,
7893
- * offset: 0,
7894
- * sortColumn: 'created_at',
7895
- * sortOrder: 'desc'
7896
- * })
7897
- * ```
7898
- *
7899
- * Response:
7900
- * ```json
7901
- * {
7902
- * "data": [
7903
- * {
7904
- * "name": "analytics-data",
7905
- * "type": "ANALYTICS",
7906
- * "format": "iceberg",
7907
- * "created_at": "2024-05-22T22:26:05.100Z",
7908
- * "updated_at": "2024-05-22T22:26:05.100Z"
7909
- * }
7910
- * ],
7911
- * "error": null
7912
- * }
7913
- * ```
7914
- *
7915
- * @remarks
7916
- * - Retrieves the details of all Analytics Storage buckets within an existing project
7917
- * - Only returns buckets of type 'ANALYTICS'
7918
- */
7919
- async listBuckets(options) {
7920
- return this.handleOperation(async () => {
7921
- const queryParams = new URLSearchParams();
7922
- if (options?.limit !== void 0) queryParams.set("limit", options.limit.toString());
7923
- if (options?.offset !== void 0) queryParams.set("offset", options.offset.toString());
7924
- if (options?.sortColumn) queryParams.set("sortColumn", options.sortColumn);
7925
- if (options?.sortOrder) queryParams.set("sortOrder", options.sortOrder);
7926
- if (options?.search) queryParams.set("search", options.search);
7927
- const queryString = queryParams.toString();
7928
- const url = queryString ? `${this.url}/bucket?${queryString}` : `${this.url}/bucket`;
7929
- return await get(this.fetch, url, {
7930
- headers: this.headers
7931
- });
7932
- });
7933
- }
7934
- /**
7935
- * @alpha
7936
- *
7937
- * Deletes an existing analytics bucket
7938
- * A bucket can't be deleted with existing objects inside it
7939
- * You must first empty the bucket before deletion
7940
- *
7941
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
7942
- *
7943
- * @category Storage
7944
- * @subcategory Analytics Buckets
7945
- * @param bucketName The unique identifier of the bucket you would like to delete
7946
- * @returns Promise with response containing success message or error
7947
- *
7948
- * @example Delete analytics bucket
7949
- * ```js
7950
- * const { data, error } = await supabase
7951
- * .storage
7952
- * .analytics
7953
- * .deleteBucket('analytics-data')
7954
- * ```
7955
- *
7956
- * Response:
7957
- * ```json
7958
- * {
7959
- * "data": {
7960
- * "message": "Successfully deleted"
7961
- * },
7962
- * "error": null
7963
- * }
7964
- * ```
7965
- *
7966
- * @remarks
7967
- * - Deletes an analytics bucket
7968
- */
7969
- async deleteBucket(bucketName) {
7970
- return this.handleOperation(async () => {
7971
- return await remove(this.fetch, `${this.url}/bucket/${bucketName}`, {}, {
7972
- headers: this.headers
7973
- });
7974
- });
7975
- }
7976
- /**
7977
- * @alpha
7978
- *
7979
- * Get an Iceberg REST Catalog client configured for a specific analytics bucket
7980
- * Use this to perform advanced table and namespace operations within the bucket
7981
- * The returned client provides full access to the Apache Iceberg REST Catalog API
7982
- * with the Supabase `{ data, error }` pattern for consistent error handling on all operations.
7983
- *
7984
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
7985
- *
7986
- * @category Storage
7987
- * @subcategory Analytics Buckets
7988
- * @param bucketName - The name of the analytics bucket (warehouse) to connect to
7989
- * @returns The wrapped Iceberg catalog client
7990
- * @throws {StorageError} If the bucket name is invalid
7991
- *
7992
- * @example Get catalog and create table
7993
- * ```js
7994
- * // First, create an analytics bucket
7995
- * const { data: bucket, error: bucketError } = await supabase
7996
- * .storage
7997
- * .analytics
7998
- * .createBucket('analytics-data')
7999
- *
8000
- * // Get the Iceberg catalog for that bucket
8001
- * const catalog = supabase.storage.analytics.from('analytics-data')
8002
- *
8003
- * // Create a namespace
8004
- * const { error: nsError } = await catalog.createNamespace({ namespace: ['default'] })
8005
- *
8006
- * // Create a table with schema
8007
- * const { data: tableMetadata, error: tableError } = await catalog.createTable(
8008
- * { namespace: ['default'] },
8009
- * {
8010
- * name: 'events',
8011
- * schema: {
8012
- * type: 'struct',
8013
- * fields: [
8014
- * { id: 1, name: 'id', type: 'long', required: true },
8015
- * { id: 2, name: 'timestamp', type: 'timestamp', required: true },
8016
- * { id: 3, name: 'user_id', type: 'string', required: false }
8017
- * ],
8018
- * 'schema-id': 0,
8019
- * 'identifier-field-ids': [1]
8020
- * },
8021
- * 'partition-spec': {
8022
- * 'spec-id': 0,
8023
- * fields: []
8024
- * },
8025
- * 'write-order': {
8026
- * 'order-id': 0,
8027
- * fields: []
8028
- * },
8029
- * properties: {
8030
- * 'write.format.default': 'parquet'
8031
- * }
8032
- * }
8033
- * )
8034
- * ```
8035
- *
8036
- * @example List tables in namespace
8037
- * ```js
8038
- * const catalog = supabase.storage.analytics.from('analytics-data')
8039
- *
8040
- * // List all tables in the default namespace
8041
- * const { data: tables, error: listError } = await catalog.listTables({ namespace: ['default'] })
8042
- * if (listError) {
8043
- * if (listError.isNotFound()) {
8044
- * console.log('Namespace not found')
8045
- * }
8046
- * return
8047
- * }
8048
- * console.log(tables) // [{ namespace: ['default'], name: 'events' }]
8049
- * ```
8050
- *
8051
- * @example Working with namespaces
8052
- * ```js
8053
- * const catalog = supabase.storage.analytics.from('analytics-data')
8054
- *
8055
- * // List all namespaces
8056
- * const { data: namespaces } = await catalog.listNamespaces()
8057
- *
8058
- * // Create namespace with properties
8059
- * await catalog.createNamespace(
8060
- * { namespace: ['production'] },
8061
- * { properties: { owner: 'data-team', env: 'prod' } }
8062
- * )
8063
- * ```
8064
- *
8065
- * @example Cleanup operations
8066
- * ```js
8067
- * const catalog = supabase.storage.analytics.from('analytics-data')
8068
- *
8069
- * // Drop table with purge option (removes all data)
8070
- * const { error: dropError } = await catalog.dropTable(
8071
- * { namespace: ['default'], name: 'events' },
8072
- * { purge: true }
8073
- * )
8074
- *
8075
- * if (dropError?.isNotFound()) {
8076
- * console.log('Table does not exist')
8077
- * }
8078
- *
8079
- * // Drop namespace (must be empty)
8080
- * await catalog.dropNamespace({ namespace: ['default'] })
8081
- * ```
8082
- *
8083
- * @remarks
8084
- * This method provides a bridge between Supabase's bucket management and the standard
8085
- * Apache Iceberg REST Catalog API. The bucket name maps to the Iceberg warehouse parameter.
8086
- * All authentication and configuration is handled automatically using your Supabase credentials.
8087
- *
8088
- * **Error Handling**: Invalid bucket names throw immediately. All catalog
8089
- * operations return `{ data, error }` where errors are `IcebergError` instances from iceberg-js.
8090
- * Use helper methods like `error.isNotFound()` or check `error.status` for specific error handling.
8091
- * Use `.throwOnError()` on the analytics client if you prefer exceptions for catalog operations.
8092
- *
8093
- * **Cleanup Operations**: When using `dropTable`, the `purge: true` option permanently
8094
- * deletes all table data. Without it, the table is marked as deleted but data remains.
8095
- *
8096
- * **Library Dependency**: The returned catalog wraps `IcebergRestCatalog` from iceberg-js.
8097
- * For complete API documentation and advanced usage, refer to the
8098
- * [iceberg-js documentation](https://supabase.github.io/iceberg-js/).
8099
- */
8100
- from(bucketName) {
8101
- if (!isValidBucketName(bucketName)) {
8102
- throw new StorageError("Invalid bucket name: File, folder, and bucket names must follow AWS object key naming guidelines and should avoid the use of any other characters.");
8103
- }
8104
- const catalog = new import_iceberg_js.IcebergRestCatalog({
8105
- baseUrl: this.url,
8106
- catalogName: bucketName,
8107
- auth: {
8108
- type: "custom",
8109
- getHeaders: /* @__PURE__ */ __name(async () => this.headers, "getHeaders")
8110
- },
8111
- fetch: this.fetch
8112
- });
8113
- const shouldThrowOnError = this.shouldThrowOnError;
8114
- const wrappedCatalog = new Proxy(catalog, {
8115
- get(target, prop) {
8116
- const value = target[prop];
8117
- if (typeof value !== "function") {
8118
- return value;
8119
- }
8120
- return async (...args) => {
8121
- try {
8122
- const data = await value.apply(target, args);
8123
- return {
8124
- data,
8125
- error: null
8126
- };
8127
- } catch (error) {
8128
- if (shouldThrowOnError) {
8129
- throw error;
8130
- }
8131
- return {
8132
- data: null,
8133
- error
8134
- };
8135
- }
8136
- };
8137
- }
8138
- });
8139
- return wrappedCatalog;
8140
- }
8141
- };
8142
-
8143
- // src/vendor/storage/packages/VectorIndexApi.ts
8144
- var VectorIndexApi = class extends BaseApiClient {
8145
- static {
8146
- __name(this, "VectorIndexApi");
8147
- }
8148
- /** Creates a new VectorIndexApi instance */
8149
- constructor(url, headers = {}, fetch2) {
8150
- const finalUrl = url.replace(/\/$/, "");
8151
- const finalHeaders = {
8152
- ...DEFAULT_HEADERS,
8153
- "Content-Type": "application/json",
8154
- ...headers
8155
- };
8156
- super(finalUrl, finalHeaders, fetch2, "vectors");
8157
- }
8158
- /** Creates a new vector index within a bucket */
8159
- async createIndex(options) {
8160
- return this.handleOperation(async () => {
8161
- const data = await vectorsApi.post(this.fetch, `${this.url}/CreateIndex`, options, {
8162
- headers: this.headers
8163
- });
8164
- return data || {};
8165
- });
8166
- }
8167
- /** Retrieves metadata for a specific vector index */
8168
- async getIndex(vectorBucketName, indexName) {
8169
- return this.handleOperation(async () => {
8170
- return await vectorsApi.post(this.fetch, `${this.url}/GetIndex`, {
8171
- vectorBucketName,
8172
- indexName
8173
- }, {
8174
- headers: this.headers
8175
- });
8176
- });
8177
- }
8178
- /** Lists vector indexes within a bucket with optional filtering and pagination */
8179
- async listIndexes(options) {
8180
- return this.handleOperation(async () => {
8181
- return await vectorsApi.post(this.fetch, `${this.url}/ListIndexes`, options, {
8182
- headers: this.headers
8183
- });
8184
- });
8185
- }
8186
- /** Deletes a vector index and all its data */
8187
- async deleteIndex(vectorBucketName, indexName) {
8188
- return this.handleOperation(async () => {
8189
- const data = await vectorsApi.post(this.fetch, `${this.url}/DeleteIndex`, {
8190
- vectorBucketName,
8191
- indexName
8192
- }, {
8193
- headers: this.headers
8194
- });
8195
- return data || {};
8196
- });
8197
- }
8198
- };
8199
-
8200
- // src/vendor/storage/packages/VectorDataApi.ts
8201
- var VectorDataApi = class extends BaseApiClient {
8202
- static {
8203
- __name(this, "VectorDataApi");
8204
- }
8205
- /** Creates a new VectorDataApi instance */
8206
- constructor(url, headers = {}, fetch2) {
8207
- const finalUrl = url.replace(/\/$/, "");
8208
- const finalHeaders = {
8209
- ...DEFAULT_HEADERS,
8210
- "Content-Type": "application/json",
8211
- ...headers
8212
- };
8213
- super(finalUrl, finalHeaders, fetch2, "vectors");
8214
- }
8215
- /** Inserts or updates vectors in batch (1-500 per request) */
8216
- async putVectors(options) {
8217
- if (options.vectors.length < 1 || options.vectors.length > 500) {
8218
- throw new Error("Vector batch size must be between 1 and 500 items");
8219
- }
8220
- return this.handleOperation(async () => {
8221
- const data = await vectorsApi.post(this.fetch, `${this.url}/PutVectors`, options, {
8222
- headers: this.headers
8223
- });
8224
- return data || {};
8225
- });
8226
- }
8227
- /** Retrieves vectors by their keys in batch */
8228
- async getVectors(options) {
8229
- return this.handleOperation(async () => {
8230
- return await vectorsApi.post(this.fetch, `${this.url}/GetVectors`, options, {
8231
- headers: this.headers
8232
- });
8233
- });
8234
- }
8235
- /** Lists vectors in an index with pagination */
8236
- async listVectors(options) {
8237
- if (options.segmentCount !== void 0) {
8238
- if (options.segmentCount < 1 || options.segmentCount > 16) {
8239
- throw new Error("segmentCount must be between 1 and 16");
8240
- }
8241
- if (options.segmentIndex !== void 0) {
8242
- if (options.segmentIndex < 0 || options.segmentIndex >= options.segmentCount) {
8243
- throw new Error(`segmentIndex must be between 0 and ${options.segmentCount - 1}`);
8244
- }
8245
- }
8246
- }
8247
- return this.handleOperation(async () => {
8248
- return await vectorsApi.post(this.fetch, `${this.url}/ListVectors`, options, {
8249
- headers: this.headers
8250
- });
8251
- });
8252
- }
8253
- /** Queries for similar vectors using approximate nearest neighbor search */
8254
- async queryVectors(options) {
8255
- return this.handleOperation(async () => {
8256
- return await vectorsApi.post(this.fetch, `${this.url}/QueryVectors`, options, {
8257
- headers: this.headers
8258
- });
8259
- });
8260
- }
8261
- /** Deletes vectors by their keys in batch (1-500 per request) */
8262
- async deleteVectors(options) {
8263
- if (options.keys.length < 1 || options.keys.length > 500) {
8264
- throw new Error("Keys batch size must be between 1 and 500 items");
8265
- }
8266
- return this.handleOperation(async () => {
8267
- const data = await vectorsApi.post(this.fetch, `${this.url}/DeleteVectors`, options, {
8268
- headers: this.headers
8269
- });
8270
- return data || {};
8271
- });
8272
- }
8273
- };
8274
-
8275
- // src/vendor/storage/packages/VectorBucketApi.ts
8276
- var VectorBucketApi = class extends BaseApiClient {
8277
- static {
8278
- __name(this, "VectorBucketApi");
8279
- }
8280
- /** Creates a new VectorBucketApi instance */
8281
- constructor(url, headers = {}, fetch2) {
8282
- const finalUrl = url.replace(/\/$/, "");
8283
- const finalHeaders = {
8284
- ...DEFAULT_HEADERS,
8285
- "Content-Type": "application/json",
8286
- ...headers
8287
- };
8288
- super(finalUrl, finalHeaders, fetch2, "vectors");
8289
- }
8290
- /** Creates a new vector bucket */
8291
- async createBucket(vectorBucketName) {
8292
- return this.handleOperation(async () => {
8293
- const data = await vectorsApi.post(this.fetch, `${this.url}/CreateVectorBucket`, {
8294
- vectorBucketName
8295
- }, {
8296
- headers: this.headers
8297
- });
8298
- return data || {};
8299
- });
8300
- }
8301
- /** Retrieves metadata for a specific vector bucket */
8302
- async getBucket(vectorBucketName) {
8303
- return this.handleOperation(async () => {
8304
- return await vectorsApi.post(this.fetch, `${this.url}/GetVectorBucket`, {
8305
- vectorBucketName
8306
- }, {
8307
- headers: this.headers
8308
- });
8309
- });
8310
- }
8311
- /** Lists vector buckets with optional filtering and pagination */
8312
- async listBuckets(options = {}) {
8313
- return this.handleOperation(async () => {
8314
- return await vectorsApi.post(this.fetch, `${this.url}/ListVectorBuckets`, options, {
8315
- headers: this.headers
8316
- });
8317
- });
8318
- }
8319
- /** Deletes a vector bucket (must be empty first) */
8320
- async deleteBucket(vectorBucketName) {
8321
- return this.handleOperation(async () => {
8322
- const data = await vectorsApi.post(this.fetch, `${this.url}/DeleteVectorBucket`, {
8323
- vectorBucketName
8324
- }, {
8325
- headers: this.headers
8326
- });
8327
- return data || {};
8328
- });
8329
- }
8330
- };
8331
-
8332
- // src/vendor/storage/packages/StorageVectorsClient.ts
8333
- var StorageVectorsClient = class extends VectorBucketApi {
8334
- static {
8335
- __name(this, "StorageVectorsClient");
8336
- }
8337
- /**
8338
- * @alpha
8339
- *
8340
- * Creates a StorageVectorsClient that can manage buckets, indexes, and vectors.
8341
- *
8342
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8343
- *
8344
- * @category Storage
8345
- * @subcategory Vector Buckets
8346
- * @param url - Base URL of the Storage Vectors REST API.
8347
- * @param options.headers - Optional headers (for example `Authorization`) applied to every request.
8348
- * @param options.fetch - Optional custom `fetch` implementation for non-browser runtimes.
8349
- *
8350
- * @example Using supabase-js (recommended)
8351
- * ```typescript
8352
- * import { createClient } from '@supabase/supabase-js'
8353
- *
8354
- * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
8355
- * const bucket = supabase.storage.vectors.from('embeddings-prod')
8356
- * ```
8357
- *
8358
- * @example Standalone import for bundle-sensitive environments
8359
- * ```typescript
8360
- * import { StorageVectorsClient } from '@supabase/storage-js'
8361
- *
8362
- * const client = new StorageVectorsClient(url, options)
8363
- * ```
8364
- */
8365
- constructor(url, options = {}) {
8366
- super(url, options.headers || {}, options.fetch);
8367
- }
8368
- /**
8369
- *
8370
- * @alpha
8371
- *
8372
- * Access operations for a specific vector bucket
8373
- * Returns a scoped client for index and vector operations within the bucket
8374
- *
8375
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8376
- *
8377
- * @category Storage
8378
- * @subcategory Vector Buckets
8379
- * @param vectorBucketName - Name of the vector bucket
8380
- * @returns Bucket-scoped client with index and vector operations
8381
- *
8382
- * @example Accessing a vector bucket
8383
- * ```typescript
8384
- * const bucket = supabase.storage.vectors.from('embeddings-prod')
8385
- * ```
8386
- */
8387
- from(vectorBucketName) {
8388
- return new VectorBucketScope(this.url, this.headers, vectorBucketName, this.fetch);
8389
- }
8390
- /**
8391
- *
8392
- * @alpha
8393
- *
8394
- * Creates a new vector bucket
8395
- * Vector buckets are containers for vector indexes and their data
8396
- *
8397
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8398
- *
8399
- * @category Storage
8400
- * @subcategory Vector Buckets
8401
- * @param vectorBucketName - Unique name for the vector bucket
8402
- * @returns Promise with empty response on success or error
8403
- *
8404
- * @example Creating a vector bucket
8405
- * ```typescript
8406
- * const { data, error } = await supabase
8407
- * .storage
8408
- * .vectors
8409
- * .createBucket('embeddings-prod')
8410
- * ```
8411
- */
8412
- async createBucket(vectorBucketName) {
8413
- return super.createBucket(vectorBucketName);
8414
- }
8415
- /**
8416
- *
8417
- * @alpha
8418
- *
8419
- * Retrieves metadata for a specific vector bucket
8420
- *
8421
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8422
- *
8423
- * @category Storage
8424
- * @subcategory Vector Buckets
8425
- * @param vectorBucketName - Name of the vector bucket
8426
- * @returns Promise with bucket metadata or error
8427
- *
8428
- * @example Get bucket metadata
8429
- * ```typescript
8430
- * const { data, error } = await supabase
8431
- * .storage
8432
- * .vectors
8433
- * .getBucket('embeddings-prod')
8434
- *
8435
- * console.log('Bucket created:', data?.vectorBucket.creationTime)
8436
- * ```
8437
- */
8438
- async getBucket(vectorBucketName) {
8439
- return super.getBucket(vectorBucketName);
8440
- }
8441
- /**
8442
- *
8443
- * @alpha
8444
- *
8445
- * Lists all vector buckets with optional filtering and pagination
8446
- *
8447
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8448
- *
8449
- * @category Storage
8450
- * @subcategory Vector Buckets
8451
- * @param options - Optional filters (prefix, maxResults, nextToken)
8452
- * @returns Promise with list of buckets or error
8453
- *
8454
- * @example List vector buckets
8455
- * ```typescript
8456
- * const { data, error } = await supabase
8457
- * .storage
8458
- * .vectors
8459
- * .listBuckets({ prefix: 'embeddings-' })
8460
- *
8461
- * data?.vectorBuckets.forEach(bucket => {
8462
- * console.log(bucket.vectorBucketName)
8463
- * })
8464
- * ```
8465
- */
8466
- async listBuckets(options = {}) {
8467
- return super.listBuckets(options);
8468
- }
8469
- /**
8470
- *
8471
- * @alpha
8472
- *
8473
- * Deletes a vector bucket (bucket must be empty)
8474
- * All indexes must be deleted before deleting the bucket
8475
- *
8476
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8477
- *
8478
- * @category Storage
8479
- * @subcategory Vector Buckets
8480
- * @param vectorBucketName - Name of the vector bucket to delete
8481
- * @returns Promise with empty response on success or error
8482
- *
8483
- * @example Delete a vector bucket
8484
- * ```typescript
8485
- * const { data, error } = await supabase
8486
- * .storage
8487
- * .vectors
8488
- * .deleteBucket('embeddings-old')
8489
- * ```
8490
- */
8491
- async deleteBucket(vectorBucketName) {
8492
- return super.deleteBucket(vectorBucketName);
8493
- }
8494
- };
8495
- var VectorBucketScope = class extends VectorIndexApi {
8496
- static {
8497
- __name(this, "VectorBucketScope");
8498
- }
8499
- vectorBucketName;
8500
- /**
8501
- * @alpha
8502
- *
8503
- * Creates a helper that automatically scopes all index operations to the provided bucket.
8504
- *
8505
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8506
- *
8507
- * @category Storage
8508
- * @subcategory Vector Buckets
8509
- * @example Creating a vector bucket scope
8510
- * ```typescript
8511
- * const bucket = supabase.storage.vectors.from('embeddings-prod')
8512
- * ```
8513
- */
8514
- constructor(url, headers, vectorBucketName, fetch2) {
8515
- super(url, headers, fetch2);
8516
- this.vectorBucketName = vectorBucketName;
8517
- }
8518
- /**
8519
- *
8520
- * @alpha
8521
- *
8522
- * Creates a new vector index in this bucket
8523
- * Convenience method that automatically includes the bucket name
8524
- *
8525
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8526
- *
8527
- * @category Storage
8528
- * @subcategory Vector Buckets
8529
- * @param options - Index configuration (vectorBucketName is automatically set)
8530
- * @returns Promise with empty response on success or error
8531
- *
8532
- * @example Creating a vector index
8533
- * ```typescript
8534
- * const bucket = supabase.storage.vectors.from('embeddings-prod')
8535
- * await bucket.createIndex({
8536
- * indexName: 'documents-openai',
8537
- * dataType: 'float32',
8538
- * dimension: 1536,
8539
- * distanceMetric: 'cosine',
8540
- * metadataConfiguration: {
8541
- * nonFilterableMetadataKeys: ['raw_text']
8542
- * }
8543
- * })
8544
- * ```
8545
- */
8546
- async createIndex(options) {
8547
- return super.createIndex({
8548
- ...options,
8549
- vectorBucketName: this.vectorBucketName
8550
- });
8551
- }
8552
- /**
8553
- *
8554
- * @alpha
8555
- *
8556
- * Lists indexes in this bucket
8557
- * Convenience method that automatically includes the bucket name
8558
- *
8559
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8560
- *
8561
- * @category Storage
8562
- * @subcategory Vector Buckets
8563
- * @param options - Listing options (vectorBucketName is automatically set)
8564
- * @returns Promise with response containing indexes array and pagination token or error
8565
- *
8566
- * @example List indexes
8567
- * ```typescript
8568
- * const bucket = supabase.storage.vectors.from('embeddings-prod')
8569
- * const { data } = await bucket.listIndexes({ prefix: 'documents-' })
8570
- * ```
8571
- */
8572
- async listIndexes(options = {}) {
8573
- return super.listIndexes({
8574
- ...options,
8575
- vectorBucketName: this.vectorBucketName
8576
- });
8577
- }
8578
- /**
8579
- *
8580
- * @alpha
8581
- *
8582
- * Retrieves metadata for a specific index in this bucket
8583
- * Convenience method that automatically includes the bucket name
8584
- *
8585
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8586
- *
8587
- * @category Storage
8588
- * @subcategory Vector Buckets
8589
- * @param indexName - Name of the index to retrieve
8590
- * @returns Promise with index metadata or error
8591
- *
8592
- * @example Get index metadata
8593
- * ```typescript
8594
- * const bucket = supabase.storage.vectors.from('embeddings-prod')
8595
- * const { data } = await bucket.getIndex('documents-openai')
8596
- * console.log('Dimension:', data?.index.dimension)
8597
- * ```
8598
- */
8599
- async getIndex(indexName) {
8600
- return super.getIndex(this.vectorBucketName, indexName);
8601
- }
8602
- /**
8603
- *
8604
- * @alpha
8605
- *
8606
- * Deletes an index from this bucket
8607
- * Convenience method that automatically includes the bucket name
8608
- *
8609
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8610
- *
8611
- * @category Storage
8612
- * @subcategory Vector Buckets
8613
- * @param indexName - Name of the index to delete
8614
- * @returns Promise with empty response on success or error
8615
- *
8616
- * @example Delete an index
8617
- * ```typescript
8618
- * const bucket = supabase.storage.vectors.from('embeddings-prod')
8619
- * await bucket.deleteIndex('old-index')
8620
- * ```
8621
- */
8622
- async deleteIndex(indexName) {
8623
- return super.deleteIndex(this.vectorBucketName, indexName);
8624
- }
8625
- /**
8626
- *
8627
- * @alpha
8628
- *
8629
- * Access operations for a specific index within this bucket
8630
- * Returns a scoped client for vector data operations
8631
- *
8632
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8633
- *
8634
- * @category Storage
8635
- * @subcategory Vector Buckets
8636
- * @param indexName - Name of the index
8637
- * @returns Index-scoped client with vector data operations
8638
- *
8639
- * @example Accessing an index
8640
- * ```typescript
8641
- * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
8642
- *
8643
- * // Insert vectors
8644
- * await index.putVectors({
8645
- * vectors: [
8646
- * { key: 'doc-1', data: { float32: [...] }, metadata: { title: 'Intro' } }
8647
- * ]
8648
- * })
8649
- *
8650
- * // Query similar vectors
8651
- * const { data } = await index.queryVectors({
8652
- * queryVector: { float32: [...] },
8653
- * topK: 5
8654
- * })
8655
- * ```
8656
- */
8657
- index(indexName) {
8658
- return new VectorIndexScope(this.url, this.headers, this.vectorBucketName, indexName, this.fetch);
8659
- }
8660
- };
8661
- var VectorIndexScope = class extends VectorDataApi {
8662
- static {
8663
- __name(this, "VectorIndexScope");
8664
- }
8665
- vectorBucketName;
8666
- indexName;
8667
- /**
8668
- *
8669
- * @alpha
8670
- *
8671
- * Creates a helper that automatically scopes all vector operations to the provided bucket/index names.
8672
- *
8673
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8674
- *
8675
- * @category Storage
8676
- * @subcategory Vector Buckets
8677
- * @example Creating a vector index scope
8678
- * ```typescript
8679
- * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
8680
- * ```
8681
- */
8682
- constructor(url, headers, vectorBucketName, indexName, fetch2) {
8683
- super(url, headers, fetch2);
8684
- this.vectorBucketName = vectorBucketName;
8685
- this.indexName = indexName;
8686
- }
8687
- /**
8688
- *
8689
- * @alpha
8690
- *
8691
- * Inserts or updates vectors in this index
8692
- * Convenience method that automatically includes bucket and index names
8693
- *
8694
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8695
- *
8696
- * @category Storage
8697
- * @subcategory Vector Buckets
8698
- * @param options - Vector insertion options (bucket and index names automatically set)
8699
- * @returns Promise with empty response on success or error
8700
- *
8701
- * @example Insert vectors into an index
8702
- * ```typescript
8703
- * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
8704
- * await index.putVectors({
8705
- * vectors: [
8706
- * {
8707
- * key: 'doc-1',
8708
- * data: { float32: [0.1, 0.2, ...] },
8709
- * metadata: { title: 'Introduction', page: 1 }
8710
- * }
8711
- * ]
8712
- * })
8713
- * ```
8714
- */
8715
- async putVectors(options) {
8716
- return super.putVectors({
8717
- ...options,
8718
- vectorBucketName: this.vectorBucketName,
8719
- indexName: this.indexName
8720
- });
8721
- }
8722
- /**
8723
- *
8724
- * @alpha
8725
- *
8726
- * Retrieves vectors by keys from this index
8727
- * Convenience method that automatically includes bucket and index names
8728
- *
8729
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8730
- *
8731
- * @category Storage
8732
- * @subcategory Vector Buckets
8733
- * @param options - Vector retrieval options (bucket and index names automatically set)
8734
- * @returns Promise with response containing vectors array or error
8735
- *
8736
- * @example Get vectors by keys
8737
- * ```typescript
8738
- * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
8739
- * const { data } = await index.getVectors({
8740
- * keys: ['doc-1', 'doc-2'],
8741
- * returnMetadata: true
8742
- * })
8743
- * ```
8744
- */
8745
- async getVectors(options) {
8746
- return super.getVectors({
8747
- ...options,
8748
- vectorBucketName: this.vectorBucketName,
8749
- indexName: this.indexName
8750
- });
8751
- }
8752
- /**
8753
- *
8754
- * @alpha
8755
- *
8756
- * Lists vectors in this index with pagination
8757
- * Convenience method that automatically includes bucket and index names
8758
- *
8759
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8760
- *
8761
- * @category Storage
8762
- * @subcategory Vector Buckets
8763
- * @param options - Listing options (bucket and index names automatically set)
8764
- * @returns Promise with response containing vectors array and pagination token or error
8765
- *
8766
- * @example List vectors with pagination
8767
- * ```typescript
8768
- * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
8769
- * const { data } = await index.listVectors({
8770
- * maxResults: 500,
8771
- * returnMetadata: true
8772
- * })
8773
- * ```
8774
- */
8775
- async listVectors(options = {}) {
8776
- return super.listVectors({
8777
- ...options,
8778
- vectorBucketName: this.vectorBucketName,
8779
- indexName: this.indexName
8780
- });
8781
- }
8782
- /**
8783
- *
8784
- * @alpha
8785
- *
8786
- * Queries for similar vectors in this index
8787
- * Convenience method that automatically includes bucket and index names
8788
- *
8789
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8790
- *
8791
- * @category Storage
8792
- * @subcategory Vector Buckets
8793
- * @param options - Query options (bucket and index names automatically set)
8794
- * @returns Promise with response containing matches array of similar vectors ordered by distance or error
8795
- *
8796
- * @example Query similar vectors
8797
- * ```typescript
8798
- * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
8799
- * const { data } = await index.queryVectors({
8800
- * queryVector: { float32: [0.1, 0.2, ...] },
8801
- * topK: 5,
8802
- * filter: { category: 'technical' },
8803
- * returnDistance: true,
8804
- * returnMetadata: true
8805
- * })
8806
- * ```
8807
- */
8808
- async queryVectors(options) {
8809
- return super.queryVectors({
8810
- ...options,
8811
- vectorBucketName: this.vectorBucketName,
8812
- indexName: this.indexName
8813
- });
8814
- }
8815
- /**
8816
- *
8817
- * @alpha
8818
- *
8819
- * Deletes vectors by keys from this index
8820
- * Convenience method that automatically includes bucket and index names
8821
- *
8822
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8823
- *
8824
- * @category Storage
8825
- * @subcategory Vector Buckets
8826
- * @param options - Deletion options (bucket and index names automatically set)
8827
- * @returns Promise with empty response on success or error
8828
- *
8829
- * @example Delete vectors by keys
8830
- * ```typescript
8831
- * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
8832
- * await index.deleteVectors({
8833
- * keys: ['doc-1', 'doc-2', 'doc-3']
8834
- * })
8835
- * ```
8836
- */
8837
- async deleteVectors(options) {
8838
- return super.deleteVectors({
8839
- ...options,
8840
- vectorBucketName: this.vectorBucketName,
8841
- indexName: this.indexName
8842
- });
8843
- }
8844
- };
8845
-
8846
- // src/vendor/storage/StorageClient.ts
8847
- var StorageClient = class extends StorageBucketApi {
8848
- static {
8849
- __name(this, "StorageClient");
8850
- }
8851
- /**
8852
- * Creates a client for Storage buckets, files, analytics, and vectors.
8853
- *
8854
- * @category Storage
8855
- * @subcategory File Buckets
8856
- *
8857
- * @example Using supabase-js (recommended)
8858
- * ```ts
8859
- * import { createClient } from '@supabase/supabase-js'
8860
- *
8861
- * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
8862
- * const avatars = supabase.storage.from('avatars')
8863
- * ```
8864
- *
8865
- * @example Standalone import for bundle-sensitive environments
8866
- * ```ts
8867
- * import { StorageClient } from '@supabase/storage-js'
8868
- *
8869
- * const storage = new StorageClient('https://xyzcompany.supabase.co/storage/v1', {
8870
- * apikey: 'your-publishable-key',
8871
- * })
8872
- * const avatars = storage.from('avatars')
8873
- * ```
8874
- */
8875
- constructor(url, headers = {}, fetch2, opts) {
8876
- super(url, headers, fetch2, opts);
8877
- }
8878
- /**
8879
- * Perform file operation in a bucket.
8880
- *
8881
- * @category Storage
8882
- * @subcategory File Buckets
8883
- *
8884
- * @param id The bucket id to operate on.
8885
- *
8886
- * @example Accessing a bucket
8887
- * ```typescript
8888
- * const avatars = supabase.storage.from('avatars')
8889
- * ```
8890
- */
8891
- from(id) {
8892
- return new StorageFileApi(this.url, this.headers, id, this.fetch);
8893
- }
8894
- /**
8895
- *
8896
- * @alpha
8897
- *
8898
- * Access vector storage operations.
8899
- *
8900
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8901
- *
8902
- * @category Storage
8903
- * @subcategory Vector Buckets
8904
- *
8905
- * @returns A StorageVectorsClient instance configured with the current storage settings.
8906
- */
8907
- get vectors() {
8908
- return new StorageVectorsClient(this.url + "/vector", {
8909
- headers: this.headers,
8910
- fetch: this.fetch
8911
- });
8912
- }
8913
- /**
8914
- *
8915
- * @alpha
8916
- *
8917
- * Access analytics storage operations using Iceberg tables.
8918
- *
8919
- * **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
8920
- *
8921
- * @category Storage
8922
- * @subcategory Analytics Buckets
8923
- *
8924
- * @returns A StorageAnalyticsClient instance configured with the current storage settings.
8925
- */
8926
- get analytics() {
8927
- return new StorageAnalyticsClient(this.url + "/iceberg", this.headers, this.fetch);
8928
- }
8929
- };
8930
-
8931
- // src/modules/storage.ts
8932
- var RUNTIME_STORAGE_BUCKET = "runtime";
8933
- var DEFAULT_SIGNED_URL_TTL_SECONDS = 10 * 60;
8934
- var MAX_SIGNED_URL_TTL_SECONDS = 60 * 60;
8935
- var CloudStoragePathError = class extends Error {
8936
- static {
8937
- __name(this, "CloudStoragePathError");
8938
- }
8939
- constructor(message) {
8940
- super(message);
8941
- this.name = "CloudStoragePathError";
8942
- }
8943
- };
8944
- var WorkBuddyStorageDownload = class {
8945
- static {
8946
- __name(this, "WorkBuddyStorageDownload");
8947
- }
8948
- blob;
8949
- stream;
8950
- [Symbol.toStringTag] = "WorkBuddyStorageDownload";
8951
- constructor(blob, stream) {
8952
- this.blob = blob;
8953
- this.stream = stream;
8954
- }
8955
- asStream() {
8956
- return this.stream();
7537
+ asStream() {
7538
+ return this.stream();
8957
7539
  }
8958
7540
  then(onfulfilled, onrejected) {
8959
7541
  return this.blob().then(onfulfilled, onrejected);
@@ -9070,7 +7652,9 @@ var WorkBuddyStorageModule = class extends WorkBuddyStorageBucket {
9070
7652
  }
9071
7653
  };
9072
7654
  function createStorageModule(config, fetch2) {
9073
- const client = new StorageClient(`${config.endpoint}${CLOUD_MODULE_PATHS.storage}`, {}, fetch2);
7655
+ const client = {
7656
+ from: /* @__PURE__ */ __name((bucketID) => new StorageFileApi(`${config.endpoint}${CLOUD_MODULE_PATHS.storage}`, DEFAULT_HEADERS, bucketID, fetch2), "from")
7657
+ };
9074
7658
  return new WorkBuddyStorageModule(client);
9075
7659
  }
9076
7660
  __name(createStorageModule, "createStorageModule");
@@ -9266,6 +7850,8 @@ __name(shouldClearCredentials, "shouldClearCredentials");
9266
7850
  anonymousTokenProvider,
9267
7851
  createMemoryStorage,
9268
7852
  createWorkBuddyCloud,
7853
+ getModelCapability,
7854
+ getModelDisplayName,
9269
7855
  shouldClearCredentials
9270
7856
  });
9271
7857
  //# sourceMappingURL=index.cjs.map