@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/README.md +28 -0
- package/lib/index.cjs +240 -1654
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +280 -44
- package/lib/index.d.ts +280 -44
- package/lib/index.global.js +5 -5
- package/lib/index.global.js.map +1 -1
- package/lib/index.js +238 -1654
- package/lib/index.js.map +1 -1
- package/lib/miniprogram.cjs +8220 -0
- package/lib/miniprogram.cjs.map +1 -0
- package/lib/miniprogram.d.cts +6794 -0
- package/lib/miniprogram.d.ts +6794 -0
- package/lib/miniprogram.js +8190 -0
- package/lib/miniprogram.js.map +1 -0
- package/miniprogram_dist/miniprogram.js +12579 -0
- package/package.json +36 -10
package/lib/index.js
CHANGED
|
@@ -31,6 +31,17 @@ function normalizeHttpUrl(value, field) {
|
|
|
31
31
|
return trimmed.replace(/\/+$/, "");
|
|
32
32
|
}
|
|
33
33
|
__name(normalizeHttpUrl, "normalizeHttpUrl");
|
|
34
|
+
function resolveEndpoint(value) {
|
|
35
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
36
|
+
return normalizeHttpUrl(value, "endpoint");
|
|
37
|
+
}
|
|
38
|
+
const origin = globalThis.location?.origin;
|
|
39
|
+
if (typeof origin !== "string" || origin === "") {
|
|
40
|
+
throw new WorkBuddyCloudConfigError("endpoint is required outside browsers (no location.origin to fall back to).");
|
|
41
|
+
}
|
|
42
|
+
return origin.replace(/\/+$/, "");
|
|
43
|
+
}
|
|
44
|
+
__name(resolveEndpoint, "resolveEndpoint");
|
|
34
45
|
function normalizePublishableKey(publishableKey) {
|
|
35
46
|
if (typeof publishableKey !== "string" || publishableKey.trim() === "") {
|
|
36
47
|
throw new WorkBuddyCloudConfigError("publishableKey is required and must be a non-empty string.");
|
|
@@ -54,11 +65,11 @@ function resolveFetch(candidate) {
|
|
|
54
65
|
__name(resolveFetch, "resolveFetch");
|
|
55
66
|
function resolveRuntimeConfig(options) {
|
|
56
67
|
if (!options || typeof options !== "object") {
|
|
57
|
-
throw new WorkBuddyCloudConfigError("createWorkBuddyCloud requires
|
|
68
|
+
throw new WorkBuddyCloudConfigError("createWorkBuddyCloud requires publishableKey.");
|
|
58
69
|
}
|
|
59
70
|
return Object.freeze({
|
|
60
|
-
endpoint:
|
|
61
|
-
oauthRelayBaseUrl: normalizeHttpUrl(options.oauthRelayBaseUrl, "oauthRelayBaseUrl"),
|
|
71
|
+
endpoint: resolveEndpoint(options.endpoint),
|
|
72
|
+
oauthRelayBaseUrl: options.oauthRelayBaseUrl ? normalizeHttpUrl(options.oauthRelayBaseUrl, "oauthRelayBaseUrl") : "",
|
|
62
73
|
publishableKey: normalizePublishableKey(options.publishableKey),
|
|
63
74
|
fetch: resolveFetch(options.fetch)
|
|
64
75
|
});
|
|
@@ -102,6 +113,8 @@ var AUTH_PATHS = {
|
|
|
102
113
|
signInWithProvider: "/v1/signin/with/provider",
|
|
103
114
|
/** 本地续期端点(服务端不转发上游)。 */
|
|
104
115
|
token: "/v1/token",
|
|
116
|
+
/** 小程序微信登录:本地认人后仍需用 custom 票据换取 TCB session。 */
|
|
117
|
+
loginWechat: "/v1/login-wechat",
|
|
105
118
|
signOut: "/v1/user/signout",
|
|
106
119
|
userMe: "/v1/user/me",
|
|
107
120
|
/** 发码。 */
|
|
@@ -527,15 +540,34 @@ var AuthModule = class {
|
|
|
527
540
|
password: credentials.password
|
|
528
541
|
});
|
|
529
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* 小程序 wx.login 的 code 换 Genie session。
|
|
545
|
+
* 试用与正式是两套独立小程序,必须带当前账号的 appid
|
|
546
|
+
*(`wx.getAccountInfoSync().miniProgram.appId`)。
|
|
547
|
+
*/
|
|
548
|
+
async signInWithWechat(code, appid) {
|
|
549
|
+
if (!code) {
|
|
550
|
+
return fail(badRequest("signInWithWechat requires code"));
|
|
551
|
+
}
|
|
552
|
+
if (!appid) {
|
|
553
|
+
return fail(badRequest("signInWithWechat requires appid"));
|
|
554
|
+
}
|
|
555
|
+
return this.postForSession(AUTH_PATHS.loginWechat, {
|
|
556
|
+
code,
|
|
557
|
+
appid
|
|
558
|
+
});
|
|
559
|
+
}
|
|
530
560
|
/**
|
|
531
561
|
* 注册。
|
|
532
562
|
*
|
|
533
563
|
* 上游要求先完成验证码验证,所以必须带一个 `verificationToken`(来自
|
|
534
564
|
* `verifyOtp`)。只有用户名+密码的注册会被上游明确拒绝。
|
|
565
|
+
*
|
|
566
|
+
* 账号标识用 `email` 或 `phone`(二选一,与发码渠道一致)。
|
|
535
567
|
*/
|
|
536
568
|
async signUp(credentials) {
|
|
537
|
-
if (!credentials.email) {
|
|
538
|
-
return fail(badRequest("signUp requires email"));
|
|
569
|
+
if (!credentials.email && !credentials.phone) {
|
|
570
|
+
return fail(badRequest("signUp requires email or phone"));
|
|
539
571
|
}
|
|
540
572
|
if (!credentials.verificationToken) {
|
|
541
573
|
return fail(badRequest("signUp requires a verificationToken; run sendOtp + verifyOtp first (the provider rejects username+password-only signup)"));
|
|
@@ -543,28 +575,40 @@ var AuthModule = class {
|
|
|
543
575
|
const body = {
|
|
544
576
|
verification_token: credentials.verificationToken
|
|
545
577
|
};
|
|
546
|
-
body.
|
|
578
|
+
if (credentials.phone) body.phone_number = normalizePhone(credentials.phone);
|
|
579
|
+
if (credentials.email) body.email = credentials.email;
|
|
547
580
|
if (credentials.password) body.password = credentials.password;
|
|
548
581
|
return this.postForSession(AUTH_PATHS.signUp, body);
|
|
549
582
|
}
|
|
550
583
|
/**
|
|
551
|
-
*
|
|
584
|
+
* 发验证码(邮箱或短信,由 `credentials` 传的字段决定)。
|
|
552
585
|
*
|
|
553
586
|
* 这一步**不产生会话**,只返回一个 `verificationId`。发码由上游完成,
|
|
554
587
|
* 我方不实现发码逻辑。
|
|
555
588
|
*
|
|
556
589
|
* 返回的 `isExistingUser` 决定验码之后走登录还是注册 —— 该判断由上游给出,
|
|
557
590
|
* SDK 不猜。
|
|
591
|
+
*
|
|
592
|
+
* 两条渠道的请求体差异是刻意的(runtime-auth-design §3.1):
|
|
593
|
+
* - 邮箱:`{ email, usage: 'EMAIL' }`
|
|
594
|
+
* - 手机:`{ phone_number, target: 'ANY' }` —— **不带 `usage`**(普通短信登录
|
|
595
|
+
* 发码时省略即可,上游没有对应的短信枚举值),`target: 'ANY'` 表示新老用户
|
|
596
|
+
* 都允许发码。
|
|
558
597
|
*/
|
|
559
598
|
async sendOtp(credentials) {
|
|
560
|
-
|
|
561
|
-
|
|
599
|
+
const body = {};
|
|
600
|
+
if (credentials.phone) {
|
|
601
|
+
body.phone_number = normalizePhone(credentials.phone);
|
|
602
|
+
body.target = "ANY";
|
|
603
|
+
} else if (credentials.email) {
|
|
604
|
+
body.email = credentials.email;
|
|
605
|
+
body.usage = "EMAIL";
|
|
606
|
+
if (credentials.emailRedirectTo) {
|
|
607
|
+
body.email_redirect_to = credentials.emailRedirectTo;
|
|
608
|
+
}
|
|
609
|
+
} else {
|
|
610
|
+
return fail(badRequest("sendOtp requires email or phone"));
|
|
562
611
|
}
|
|
563
|
-
const body = {
|
|
564
|
-
email: credentials.email,
|
|
565
|
-
usage: "EMAIL"
|
|
566
|
-
};
|
|
567
|
-
if (credentials.emailRedirectTo) body.email_redirect_to = credentials.emailRedirectTo;
|
|
568
612
|
const res = await this.request(AUTH_PATHS.verification, {
|
|
569
613
|
method: "POST",
|
|
570
614
|
body
|
|
@@ -589,15 +633,18 @@ var AuthModule = class {
|
|
|
589
633
|
return fail(sent.error);
|
|
590
634
|
}
|
|
591
635
|
const { verificationId, isExistingUser } = sent.data;
|
|
636
|
+
const phone = credentials.phone ? normalizePhone(credentials.phone) : void 0;
|
|
592
637
|
return ok({
|
|
593
638
|
verificationId,
|
|
594
639
|
isExistingUser,
|
|
595
640
|
isUser: isExistingUser,
|
|
596
|
-
verify: /* @__PURE__ */ __name(({ token }) => this.verifyOtp({
|
|
641
|
+
verify: /* @__PURE__ */ __name(({ token, password }) => this.verifyOtp({
|
|
597
642
|
verificationId,
|
|
598
643
|
token,
|
|
599
644
|
email: credentials.email,
|
|
600
|
-
|
|
645
|
+
phone,
|
|
646
|
+
isExistingUser,
|
|
647
|
+
password
|
|
601
648
|
}), "verify")
|
|
602
649
|
});
|
|
603
650
|
}
|
|
@@ -610,10 +657,14 @@ var AuthModule = class {
|
|
|
610
657
|
* 走登录还是注册由 `isExistingUser` 决定(`sendOtp` 的返回值)。刻意不做
|
|
611
658
|
* 「先试登录失败再试注册」的兜底:那会把「密码错」这类真实错误掩盖成一次
|
|
612
659
|
* 莫名的注册尝试。
|
|
660
|
+
*
|
|
661
|
+
* 登录侧邮箱与手机号共用 `username` 字段 —— 上游 `SignInRequest.username`
|
|
662
|
+
* 承载邮箱/手机/用户名三种形态(runtime-auth-design §3.2)。
|
|
613
663
|
*/
|
|
614
664
|
async verifyOtp(params) {
|
|
615
|
-
|
|
616
|
-
|
|
665
|
+
const identifier = params.phone ? normalizePhone(params.phone) : params.email ?? "";
|
|
666
|
+
if (!params.verificationId || !params.token || !identifier) {
|
|
667
|
+
return fail(badRequest("verifyOtp requires verificationId, token and either email or phone"));
|
|
617
668
|
}
|
|
618
669
|
const verified = await this.request(AUTH_PATHS.verificationVerify, {
|
|
619
670
|
method: "POST",
|
|
@@ -632,12 +683,13 @@ var AuthModule = class {
|
|
|
632
683
|
}
|
|
633
684
|
if (params.isExistingUser) {
|
|
634
685
|
return this.postForSession(AUTH_PATHS.signIn, {
|
|
635
|
-
username:
|
|
686
|
+
username: identifier,
|
|
636
687
|
verification_token: verificationToken
|
|
637
688
|
});
|
|
638
689
|
}
|
|
639
690
|
return this.signUp({
|
|
640
691
|
email: params.email,
|
|
692
|
+
phone: params.phone,
|
|
641
693
|
password: params.password ?? "",
|
|
642
694
|
verificationToken
|
|
643
695
|
});
|
|
@@ -654,8 +706,13 @@ var AuthModule = class {
|
|
|
654
706
|
*
|
|
655
707
|
* SDK 不自己跳转(不写 `location.href`):跳转时机应由应用决定 —— 有的要
|
|
656
708
|
* 先存草稿,有的在 iframe 里要开弹窗。返回 url 交调用方处置。
|
|
709
|
+
*
|
|
710
|
+
* @deprecated Google 登录已下线,新应用不应再调用该方法。
|
|
657
711
|
*/
|
|
658
712
|
async signInWithOAuth(options) {
|
|
713
|
+
if (!this.oauthRelayBaseUrl) {
|
|
714
|
+
return fail(badRequest("signInWithOAuth requires oauthRelayBaseUrl"));
|
|
715
|
+
}
|
|
659
716
|
if (options.provider !== "google") {
|
|
660
717
|
return fail(badRequest("signInWithOAuth currently supports only google"));
|
|
661
718
|
}
|
|
@@ -670,6 +727,8 @@ var AuthModule = class {
|
|
|
670
727
|
*
|
|
671
728
|
* 在回调落地页调一次即可。`code` 缺失时返回 `null` 数据而**不是**错误 ——
|
|
672
729
|
* 落地页可能被直接访问(用户收藏了它),那不是失败。
|
|
730
|
+
*
|
|
731
|
+
* @deprecated Google 登录已下线,新应用不应再调用该方法。
|
|
673
732
|
*/
|
|
674
733
|
async handleOAuthCallback(search) {
|
|
675
734
|
const callbackInput = search ?? currentPageSearch();
|
|
@@ -904,7 +963,11 @@ var AuthModule = class {
|
|
|
904
963
|
// ------------------------------------------------------------------
|
|
905
964
|
// 内部
|
|
906
965
|
// ------------------------------------------------------------------
|
|
907
|
-
/**
|
|
966
|
+
/**
|
|
967
|
+
* 拼出平台 Relay 授权地址;state 由 Relay 自己签发、校验并一次性消费。
|
|
968
|
+
*
|
|
969
|
+
* @deprecated Google 登录已下线,仅保留给存量应用的回调落地页。
|
|
970
|
+
*/
|
|
908
971
|
async startRelayOAuth(options, redirectTo) {
|
|
909
972
|
const callback = new URL(redirectTo);
|
|
910
973
|
const relay = new URL(`${this.oauthRelayBaseUrl}/authorize`);
|
|
@@ -1000,6 +1063,17 @@ function badRequest(message) {
|
|
|
1000
1063
|
};
|
|
1001
1064
|
}
|
|
1002
1065
|
__name(badRequest, "badRequest");
|
|
1066
|
+
function normalizePhone(phone) {
|
|
1067
|
+
const digits = phone.replace(/\D/g, "");
|
|
1068
|
+
let local = digits;
|
|
1069
|
+
if (local.startsWith("0086")) {
|
|
1070
|
+
local = local.slice(4);
|
|
1071
|
+
} else if (local.startsWith("86") && local.length === 13) {
|
|
1072
|
+
local = local.slice(2);
|
|
1073
|
+
}
|
|
1074
|
+
return /^1\d{10}$/.test(local) ? `+86 ${local}` : phone;
|
|
1075
|
+
}
|
|
1076
|
+
__name(normalizePhone, "normalizePhone");
|
|
1003
1077
|
function isCloudError(v) {
|
|
1004
1078
|
return !!v && typeof v === "object" && typeof v.kind === "string";
|
|
1005
1079
|
}
|
|
@@ -5098,9 +5172,42 @@ function pricingField(value) {
|
|
|
5098
5172
|
return Object.keys(pricing).length ? pricing : void 0;
|
|
5099
5173
|
}
|
|
5100
5174
|
__name(pricingField, "pricingField");
|
|
5175
|
+
function reasoningField(value) {
|
|
5176
|
+
if (!value || typeof value !== "object") return void 0;
|
|
5177
|
+
const raw = value;
|
|
5178
|
+
const result = {};
|
|
5179
|
+
const effort = stringField(raw.effort);
|
|
5180
|
+
if (effort !== void 0) result.effort = effort;
|
|
5181
|
+
const defaultEffort = stringField(raw.defaultEffort);
|
|
5182
|
+
if (defaultEffort !== void 0) result.defaultEffort = defaultEffort;
|
|
5183
|
+
if (Array.isArray(raw.supportedEfforts)) {
|
|
5184
|
+
result.supportedEfforts = raw.supportedEfforts.filter((item) => typeof item === "string");
|
|
5185
|
+
}
|
|
5186
|
+
const rawSummary = stringField(raw.summary);
|
|
5187
|
+
if (rawSummary !== void 0 && (rawSummary === "auto" || rawSummary === "concise" || rawSummary === "detailed")) {
|
|
5188
|
+
result.summary = rawSummary;
|
|
5189
|
+
}
|
|
5190
|
+
const canDisable = booleanField(raw.canDisableThinking);
|
|
5191
|
+
if (canDisable !== void 0) result.canDisableThinking = canDisable;
|
|
5192
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
5193
|
+
}
|
|
5194
|
+
__name(reasoningField, "reasoningField");
|
|
5101
5195
|
function normalizeModel(raw) {
|
|
5102
5196
|
const id = stringField(raw.id, raw.ID);
|
|
5103
5197
|
if (!id) return null;
|
|
5198
|
+
const serverEnabled = booleanField(raw.enabled, raw.Enabled);
|
|
5199
|
+
const serverDisabled = booleanField(raw.disabled, raw.Disabled);
|
|
5200
|
+
let enabled;
|
|
5201
|
+
let disabled;
|
|
5202
|
+
if (serverEnabled !== void 0) {
|
|
5203
|
+
enabled = serverEnabled;
|
|
5204
|
+
if (serverDisabled !== void 0) disabled = serverDisabled;
|
|
5205
|
+
} else if (serverDisabled !== void 0) {
|
|
5206
|
+
disabled = serverDisabled;
|
|
5207
|
+
enabled = !serverDisabled;
|
|
5208
|
+
} else {
|
|
5209
|
+
enabled = true;
|
|
5210
|
+
}
|
|
5104
5211
|
return {
|
|
5105
5212
|
id,
|
|
5106
5213
|
name: stringField(raw.name, raw.Name) ?? id,
|
|
@@ -5143,7 +5250,10 @@ function normalizeModel(raw) {
|
|
|
5143
5250
|
...capabilitiesField(raw.capabilities ?? raw.Capabilities) ? {
|
|
5144
5251
|
capabilities: capabilitiesField(raw.capabilities ?? raw.Capabilities)
|
|
5145
5252
|
} : {},
|
|
5146
|
-
enabled
|
|
5253
|
+
enabled,
|
|
5254
|
+
...disabled !== void 0 ? {
|
|
5255
|
+
disabled
|
|
5256
|
+
} : {},
|
|
5147
5257
|
...booleanField(raw.isDefault, raw.IsDefault) !== void 0 ? {
|
|
5148
5258
|
isDefault: booleanField(raw.isDefault, raw.IsDefault)
|
|
5149
5259
|
} : {},
|
|
@@ -5152,10 +5262,55 @@ function normalizeModel(raw) {
|
|
|
5152
5262
|
} : {},
|
|
5153
5263
|
...pricingField(raw.pricing ?? raw.Pricing) ? {
|
|
5154
5264
|
pricing: pricingField(raw.pricing ?? raw.Pricing)
|
|
5265
|
+
} : {},
|
|
5266
|
+
// User-specified sparse fields: preserve explicit false/0, omit only when absent.
|
|
5267
|
+
...stringField(raw.credits, raw.Credits) ? {
|
|
5268
|
+
credits: stringField(raw.credits, raw.Credits)
|
|
5269
|
+
} : {},
|
|
5270
|
+
...numberField(raw.maxAllowedSize, raw.MaxAllowedSize) !== void 0 ? {
|
|
5271
|
+
maxAllowedSize: numberField(raw.maxAllowedSize, raw.MaxAllowedSize)
|
|
5272
|
+
} : {},
|
|
5273
|
+
...booleanField(raw.disabledMultimodal, raw.DisabledMultimodal) !== void 0 ? {
|
|
5274
|
+
disabledMultimodal: booleanField(raw.disabledMultimodal, raw.DisabledMultimodal)
|
|
5275
|
+
} : {},
|
|
5276
|
+
...booleanField(raw.supportsImages, raw.SupportsImages) !== void 0 ? {
|
|
5277
|
+
supportsImages: booleanField(raw.supportsImages, raw.SupportsImages)
|
|
5278
|
+
} : {},
|
|
5279
|
+
...booleanField(raw.supportsToolCall, raw.SupportsToolCall) !== void 0 ? {
|
|
5280
|
+
supportsToolCall: booleanField(raw.supportsToolCall, raw.SupportsToolCall)
|
|
5281
|
+
} : {},
|
|
5282
|
+
...booleanField(raw.supportsReasoning, raw.SupportsReasoning) !== void 0 ? {
|
|
5283
|
+
supportsReasoning: booleanField(raw.supportsReasoning, raw.SupportsReasoning)
|
|
5284
|
+
} : {},
|
|
5285
|
+
...booleanField(raw.onlyReasoning, raw.OnlyReasoning) !== void 0 ? {
|
|
5286
|
+
onlyReasoning: booleanField(raw.onlyReasoning, raw.OnlyReasoning)
|
|
5287
|
+
} : {},
|
|
5288
|
+
...reasoningField(raw.reasoning ?? raw.Reasoning) ? {
|
|
5289
|
+
reasoning: reasoningField(raw.reasoning ?? raw.Reasoning)
|
|
5290
|
+
} : {},
|
|
5291
|
+
...numberField(raw.temperature, raw.Temperature) !== void 0 ? {
|
|
5292
|
+
temperature: numberField(raw.temperature, raw.Temperature)
|
|
5293
|
+
} : {},
|
|
5294
|
+
...numberField(raw.top_k, raw.Top_K) !== void 0 ? {
|
|
5295
|
+
top_k: numberField(raw.top_k, raw.Top_K)
|
|
5296
|
+
} : {},
|
|
5297
|
+
...numberField(raw.top_p, raw.Top_P) !== void 0 ? {
|
|
5298
|
+
top_p: numberField(raw.top_p, raw.Top_P)
|
|
5299
|
+
} : {},
|
|
5300
|
+
...numberField(raw.repetition_penalty, raw.Repetition_Penalty) !== void 0 ? {
|
|
5301
|
+
repetition_penalty: numberField(raw.repetition_penalty, raw.Repetition_Penalty)
|
|
5155
5302
|
} : {}
|
|
5156
5303
|
};
|
|
5157
5304
|
}
|
|
5158
5305
|
__name(normalizeModel, "normalizeModel");
|
|
5306
|
+
function getModelDisplayName(model) {
|
|
5307
|
+
return model.name || model.id;
|
|
5308
|
+
}
|
|
5309
|
+
__name(getModelDisplayName, "getModelDisplayName");
|
|
5310
|
+
function getModelCapability(model, capability) {
|
|
5311
|
+
return model.capabilities?.[capability];
|
|
5312
|
+
}
|
|
5313
|
+
__name(getModelCapability, "getModelCapability");
|
|
5159
5314
|
var ModelsAPI = class {
|
|
5160
5315
|
static {
|
|
5161
5316
|
__name(this, "ModelsAPI");
|
|
@@ -5171,8 +5326,8 @@ var ModelsAPI = class {
|
|
|
5171
5326
|
*
|
|
5172
5327
|
* `id` is the value to pass as `model` to `chat.completions.create()`.
|
|
5173
5328
|
* Optional metadata is included only when the server explicitly provides
|
|
5174
|
-
* it; absence means unknown, not unsupported. The
|
|
5175
|
-
*
|
|
5329
|
+
* it; absence means unknown, not unsupported. The actual call result
|
|
5330
|
+
* is determined by the response, not by the directory entry.
|
|
5176
5331
|
*/
|
|
5177
5332
|
async list(signal) {
|
|
5178
5333
|
let response;
|
|
@@ -5445,7 +5600,10 @@ async function* iterSSEEvents(body, signal) {
|
|
|
5445
5600
|
__name(iterSSEEvents, "iterSSEEvents");
|
|
5446
5601
|
|
|
5447
5602
|
// src/modules/llm/chat.ts
|
|
5448
|
-
function extractSSEError(data) {
|
|
5603
|
+
function extractSSEError(data, requestId) {
|
|
5604
|
+
const init = requestId ? {
|
|
5605
|
+
requestId
|
|
5606
|
+
} : {};
|
|
5449
5607
|
try {
|
|
5450
5608
|
const parsed = JSON.parse(data);
|
|
5451
5609
|
if (parsed && typeof parsed === "object") {
|
|
@@ -5456,7 +5614,7 @@ function extractSSEError(data) {
|
|
|
5456
5614
|
type: typeof errorObj.type === "string" ? errorObj.type : "server_error",
|
|
5457
5615
|
param: errorObj.param === void 0 ? null : errorObj.param,
|
|
5458
5616
|
code: errorObj.code === void 0 ? null : errorObj.code
|
|
5459
|
-
});
|
|
5617
|
+
}, init);
|
|
5460
5618
|
}
|
|
5461
5619
|
}
|
|
5462
5620
|
} catch {
|
|
@@ -5466,7 +5624,7 @@ function extractSSEError(data) {
|
|
|
5466
5624
|
type: "server_error",
|
|
5467
5625
|
param: null,
|
|
5468
5626
|
code: null
|
|
5469
|
-
});
|
|
5627
|
+
}, init);
|
|
5470
5628
|
}
|
|
5471
5629
|
__name(extractSSEError, "extractSSEError");
|
|
5472
5630
|
var ChatCompletionsAPI = class {
|
|
@@ -5480,72 +5638,28 @@ var ChatCompletionsAPI = class {
|
|
|
5480
5638
|
this.fetch = fetch2;
|
|
5481
5639
|
}
|
|
5482
5640
|
create(input) {
|
|
5483
|
-
if (input.stream
|
|
5484
|
-
return this.createStreaming(input);
|
|
5485
|
-
}
|
|
5486
|
-
return this.createNonStreaming(input);
|
|
5487
|
-
}
|
|
5488
|
-
/**
|
|
5489
|
-
* Non-streaming chat completion.
|
|
5490
|
-
*/
|
|
5491
|
-
async createNonStreaming(input) {
|
|
5492
|
-
if (input.stream_options) {
|
|
5641
|
+
if (input.stream !== true) {
|
|
5493
5642
|
throw new CloudOpenAIError({
|
|
5494
|
-
message: "
|
|
5643
|
+
message: "stream must be true; non-streaming chat completions are not supported",
|
|
5495
5644
|
type: "invalid_request_error",
|
|
5496
|
-
param: "
|
|
5497
|
-
code: "
|
|
5498
|
-
});
|
|
5499
|
-
}
|
|
5500
|
-
const { signal, ...body } = input;
|
|
5501
|
-
if (body.stream === void 0) {
|
|
5502
|
-
delete body.stream;
|
|
5503
|
-
} else {
|
|
5504
|
-
body.stream = false;
|
|
5505
|
-
}
|
|
5506
|
-
let response;
|
|
5507
|
-
try {
|
|
5508
|
-
response = await this.fetch(`${this.baseUrl}/chat/completions`, {
|
|
5509
|
-
method: "POST",
|
|
5510
|
-
headers: {
|
|
5511
|
-
Accept: "application/json",
|
|
5512
|
-
"Content-Type": "application/json"
|
|
5513
|
-
},
|
|
5514
|
-
body: JSON.stringify(body),
|
|
5515
|
-
signal
|
|
5516
|
-
});
|
|
5517
|
-
} catch (err) {
|
|
5518
|
-
if (err instanceof Error && err.name === "AbortError") {
|
|
5519
|
-
throw err;
|
|
5520
|
-
}
|
|
5521
|
-
throw new CloudOpenAIError({
|
|
5522
|
-
message: `Network error: ${err?.message ?? "unknown"}`,
|
|
5523
|
-
type: "server_error",
|
|
5524
|
-
param: null,
|
|
5525
|
-
code: "gateway_network_error"
|
|
5526
|
-
}, {
|
|
5527
|
-
cause: err
|
|
5528
|
-
});
|
|
5529
|
-
}
|
|
5530
|
-
if (!response.ok) {
|
|
5531
|
-
throw await httpError(response);
|
|
5532
|
-
}
|
|
5533
|
-
const text = await response.text();
|
|
5534
|
-
try {
|
|
5535
|
-
return JSON.parse(text);
|
|
5536
|
-
} catch {
|
|
5537
|
-
throw new CloudOpenAIError({
|
|
5538
|
-
message: "Failed to parse chat completion response: invalid JSON",
|
|
5539
|
-
type: "server_error",
|
|
5540
|
-
param: null,
|
|
5541
|
-
code: "gateway_invalid_response"
|
|
5645
|
+
param: "stream",
|
|
5646
|
+
code: "request_stream_required"
|
|
5542
5647
|
});
|
|
5543
5648
|
}
|
|
5649
|
+
return this.createStreaming(input);
|
|
5544
5650
|
}
|
|
5545
5651
|
/**
|
|
5546
5652
|
* Streaming chat completion — returns an async generator of chunks.
|
|
5547
5653
|
*
|
|
5548
5654
|
* Reads the SSE stream incrementally, yielding ChatCompletionChunk objects.
|
|
5655
|
+
* `stream_options` is passed through unchanged when present.
|
|
5656
|
+
*
|
|
5657
|
+
* The `X-Request-Id` response header is captured and attached (as
|
|
5658
|
+
* `requestId`) to every `CloudOpenAIError` thrown from within the stream:
|
|
5659
|
+
* `event: error`, chunk-embedded error, JSON parse failure, and missing
|
|
5660
|
+
* `[DONE]` interruption. Non-2xx HTTP errors continue to go through
|
|
5661
|
+
* `httpError`, which independently extracts `X-Request-Id`.
|
|
5662
|
+
*
|
|
5549
5663
|
* Throws CloudOpenAIError on:
|
|
5550
5664
|
* - `event: error` in the stream
|
|
5551
5665
|
* - Stream ends without `[DONE]` (gateway_stream_interrupted)
|
|
@@ -5553,7 +5667,7 @@ var ChatCompletionsAPI = class {
|
|
|
5553
5667
|
* - Caller abort (AbortSignal) — exits silently, no throw
|
|
5554
5668
|
*/
|
|
5555
5669
|
async *createStreaming(input) {
|
|
5556
|
-
const { signal, ...body } = input;
|
|
5670
|
+
const { signal, conversationId, ...body } = input;
|
|
5557
5671
|
body.stream = true;
|
|
5558
5672
|
let response;
|
|
5559
5673
|
try {
|
|
@@ -5561,7 +5675,10 @@ var ChatCompletionsAPI = class {
|
|
|
5561
5675
|
method: "POST",
|
|
5562
5676
|
headers: {
|
|
5563
5677
|
Accept: "text/event-stream",
|
|
5564
|
-
"Content-Type": "application/json"
|
|
5678
|
+
"Content-Type": "application/json",
|
|
5679
|
+
...conversationId !== void 0 ? {
|
|
5680
|
+
"X-Conversation-ID": conversationId
|
|
5681
|
+
} : {}
|
|
5565
5682
|
},
|
|
5566
5683
|
body: JSON.stringify(body),
|
|
5567
5684
|
signal
|
|
@@ -5588,15 +5705,18 @@ var ChatCompletionsAPI = class {
|
|
|
5588
5705
|
type: "server_error",
|
|
5589
5706
|
param: null,
|
|
5590
5707
|
code: "gateway_invalid_response"
|
|
5708
|
+
}, {
|
|
5709
|
+
requestId: response.headers.get("x-request-id") ?? void 0
|
|
5591
5710
|
});
|
|
5592
5711
|
}
|
|
5712
|
+
const requestId = response.headers.get("x-request-id") ?? void 0;
|
|
5593
5713
|
let receivedDone = false;
|
|
5594
5714
|
let threw = false;
|
|
5595
5715
|
try {
|
|
5596
5716
|
for await (const sseEvent of iterSSEEvents(response.body, signal)) {
|
|
5597
5717
|
if (sseEvent.event === "error") {
|
|
5598
5718
|
threw = true;
|
|
5599
|
-
throw extractSSEError(sseEvent.data);
|
|
5719
|
+
throw extractSSEError(sseEvent.data, requestId);
|
|
5600
5720
|
}
|
|
5601
5721
|
if (sseEvent.event === null || sseEvent.event === "") {
|
|
5602
5722
|
if (sseEvent.data === SSE_DONE) {
|
|
@@ -5616,6 +5736,8 @@ var ChatCompletionsAPI = class {
|
|
|
5616
5736
|
type: "server_error",
|
|
5617
5737
|
param: null,
|
|
5618
5738
|
code: "gateway_invalid_response"
|
|
5739
|
+
}, {
|
|
5740
|
+
requestId
|
|
5619
5741
|
});
|
|
5620
5742
|
}
|
|
5621
5743
|
if (chunk && typeof chunk === "object" && "error" in chunk) {
|
|
@@ -5626,6 +5748,8 @@ var ChatCompletionsAPI = class {
|
|
|
5626
5748
|
type: typeof errObj?.type === "string" ? errObj.type : "server_error",
|
|
5627
5749
|
param: errObj?.param === void 0 ? null : errObj.param,
|
|
5628
5750
|
code: errObj?.code === void 0 ? null : errObj.code
|
|
5751
|
+
}, {
|
|
5752
|
+
requestId
|
|
5629
5753
|
});
|
|
5630
5754
|
}
|
|
5631
5755
|
yield chunk;
|
|
@@ -5644,6 +5768,8 @@ var ChatCompletionsAPI = class {
|
|
|
5644
5768
|
type: "server_error",
|
|
5645
5769
|
param: null,
|
|
5646
5770
|
code: "gateway_stream_interrupted"
|
|
5771
|
+
}, {
|
|
5772
|
+
requestId
|
|
5647
5773
|
});
|
|
5648
5774
|
}
|
|
5649
5775
|
}
|
|
@@ -5790,22 +5916,6 @@ var recursiveToCamel = /* @__PURE__ */ __name((item) => {
|
|
|
5790
5916
|
});
|
|
5791
5917
|
return result;
|
|
5792
5918
|
}, "recursiveToCamel");
|
|
5793
|
-
var isValidBucketName = /* @__PURE__ */ __name((bucketName) => {
|
|
5794
|
-
if (!bucketName || typeof bucketName !== "string") {
|
|
5795
|
-
return false;
|
|
5796
|
-
}
|
|
5797
|
-
if (bucketName.length === 0 || bucketName.length > 100) {
|
|
5798
|
-
return false;
|
|
5799
|
-
}
|
|
5800
|
-
if (bucketName.trim() !== bucketName) {
|
|
5801
|
-
return false;
|
|
5802
|
-
}
|
|
5803
|
-
if (bucketName.includes("/") || bucketName.includes("\\")) {
|
|
5804
|
-
return false;
|
|
5805
|
-
}
|
|
5806
|
-
const bucketNameRegex = /^[\w!.\*'() &$@=;:+,?-]+$/;
|
|
5807
|
-
return bucketNameRegex.test(bucketName);
|
|
5808
|
-
}, "isValidBucketName");
|
|
5809
5919
|
var encodeStoragePath = /* @__PURE__ */ __name((path) => path.split("/").map(encodeURIComponent).join("/"), "encodeStoragePath");
|
|
5810
5920
|
|
|
5811
5921
|
// src/vendor/storage/lib/common/fetch.ts
|
|
@@ -7356,1562 +7466,32 @@ var DEFAULT_HEADERS = {
|
|
|
7356
7466
|
"X-Client-Info": `storage-js/${version}`
|
|
7357
7467
|
};
|
|
7358
7468
|
|
|
7359
|
-
// src/
|
|
7360
|
-
var
|
|
7469
|
+
// src/modules/storage.ts
|
|
7470
|
+
var RUNTIME_STORAGE_BUCKET = "runtime";
|
|
7471
|
+
var DEFAULT_SIGNED_URL_TTL_SECONDS = 10 * 60;
|
|
7472
|
+
var MAX_SIGNED_URL_TTL_SECONDS = 60 * 60;
|
|
7473
|
+
var CloudStoragePathError = class extends Error {
|
|
7361
7474
|
static {
|
|
7362
|
-
__name(this, "
|
|
7363
|
-
}
|
|
7364
|
-
constructor(url, headers = {}, fetch2, opts) {
|
|
7365
|
-
const baseUrl = new URL(url);
|
|
7366
|
-
if (opts?.useNewHostname) {
|
|
7367
|
-
const isSupabaseHost = /supabase\.(co|in|red)$/.test(baseUrl.hostname);
|
|
7368
|
-
if (isSupabaseHost && !baseUrl.hostname.includes("storage.supabase.")) {
|
|
7369
|
-
baseUrl.hostname = baseUrl.hostname.replace("supabase.", "storage.supabase.");
|
|
7370
|
-
}
|
|
7371
|
-
}
|
|
7372
|
-
const finalUrl = baseUrl.href.replace(/\/$/, "");
|
|
7373
|
-
const finalHeaders = {
|
|
7374
|
-
...DEFAULT_HEADERS,
|
|
7375
|
-
...headers
|
|
7376
|
-
};
|
|
7377
|
-
super(finalUrl, finalHeaders, fetch2, "storage");
|
|
7475
|
+
__name(this, "CloudStoragePathError");
|
|
7378
7476
|
}
|
|
7379
|
-
|
|
7380
|
-
|
|
7381
|
-
|
|
7382
|
-
* @category Storage
|
|
7383
|
-
* @subcategory File Buckets
|
|
7384
|
-
* @param options Query parameters for listing buckets
|
|
7385
|
-
* @param options.limit Maximum number of buckets to return
|
|
7386
|
-
* @param options.offset Number of buckets to skip
|
|
7387
|
-
* @param options.sortColumn Column to sort by ('id', 'name', 'created_at', 'updated_at')
|
|
7388
|
-
* @param options.sortOrder Sort order ('asc' or 'desc')
|
|
7389
|
-
* @param options.search Search term to filter bucket names
|
|
7390
|
-
* @returns Promise with response containing array of buckets or error
|
|
7391
|
-
*
|
|
7392
|
-
* @example List buckets
|
|
7393
|
-
* ```js
|
|
7394
|
-
* const { data, error } = await supabase
|
|
7395
|
-
* .storage
|
|
7396
|
-
* .listBuckets()
|
|
7397
|
-
* ```
|
|
7398
|
-
*
|
|
7399
|
-
* @example List buckets with options
|
|
7400
|
-
* ```js
|
|
7401
|
-
* const { data, error } = await supabase
|
|
7402
|
-
* .storage
|
|
7403
|
-
* .listBuckets({
|
|
7404
|
-
* limit: 10,
|
|
7405
|
-
* offset: 0,
|
|
7406
|
-
* sortColumn: 'created_at',
|
|
7407
|
-
* sortOrder: 'desc',
|
|
7408
|
-
* search: 'prod'
|
|
7409
|
-
* })
|
|
7410
|
-
* ```
|
|
7411
|
-
*
|
|
7412
|
-
* @remarks
|
|
7413
|
-
* - RLS policy permissions required:
|
|
7414
|
-
* - `buckets` table permissions: `select`
|
|
7415
|
-
* - `objects` table permissions: none
|
|
7416
|
-
* - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
|
|
7417
|
-
*/
|
|
7418
|
-
async listBuckets(options) {
|
|
7419
|
-
return this.handleOperation(async () => {
|
|
7420
|
-
const queryString = this.listBucketOptionsToQueryString(options);
|
|
7421
|
-
return await get(this.fetch, `${this.url}/bucket${queryString}`, {
|
|
7422
|
-
headers: this.headers
|
|
7423
|
-
});
|
|
7424
|
-
});
|
|
7477
|
+
constructor(message) {
|
|
7478
|
+
super(message);
|
|
7479
|
+
this.name = "CloudStoragePathError";
|
|
7425
7480
|
}
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
* @subcategory File Buckets
|
|
7431
|
-
* @param id The unique identifier of the bucket you would like to retrieve.
|
|
7432
|
-
* @returns Promise with response containing bucket details or error
|
|
7433
|
-
*
|
|
7434
|
-
* @example Get bucket
|
|
7435
|
-
* ```js
|
|
7436
|
-
* const { data, error } = await supabase
|
|
7437
|
-
* .storage
|
|
7438
|
-
* .getBucket('avatars')
|
|
7439
|
-
* ```
|
|
7440
|
-
*
|
|
7441
|
-
* Response:
|
|
7442
|
-
* ```json
|
|
7443
|
-
* {
|
|
7444
|
-
* "data": {
|
|
7445
|
-
* "id": "avatars",
|
|
7446
|
-
* "name": "avatars",
|
|
7447
|
-
* "owner": "",
|
|
7448
|
-
* "public": false,
|
|
7449
|
-
* "file_size_limit": 1024,
|
|
7450
|
-
* "allowed_mime_types": [
|
|
7451
|
-
* "image/png"
|
|
7452
|
-
* ],
|
|
7453
|
-
* "created_at": "2024-05-22T22:26:05.100Z",
|
|
7454
|
-
* "updated_at": "2024-05-22T22:26:05.100Z"
|
|
7455
|
-
* },
|
|
7456
|
-
* "error": null
|
|
7457
|
-
* }
|
|
7458
|
-
* ```
|
|
7459
|
-
*
|
|
7460
|
-
* @remarks
|
|
7461
|
-
* - RLS policy permissions required:
|
|
7462
|
-
* - `buckets` table permissions: `select`
|
|
7463
|
-
* - `objects` table permissions: none
|
|
7464
|
-
* - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
|
|
7465
|
-
*/
|
|
7466
|
-
async getBucket(id) {
|
|
7467
|
-
return this.handleOperation(async () => {
|
|
7468
|
-
return await get(this.fetch, `${this.url}/bucket/${id}`, {
|
|
7469
|
-
headers: this.headers
|
|
7470
|
-
});
|
|
7471
|
-
});
|
|
7481
|
+
};
|
|
7482
|
+
var WorkBuddyStorageDownload = class {
|
|
7483
|
+
static {
|
|
7484
|
+
__name(this, "WorkBuddyStorageDownload");
|
|
7472
7485
|
}
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
* @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.
|
|
7480
|
-
* @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
|
|
7481
|
-
* The global file size limit takes precedence over this value.
|
|
7482
|
-
* The default value is null, which doesn't set a per bucket file size limit.
|
|
7483
|
-
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
|
|
7484
|
-
* The default value is null, which allows files with all mime types to be uploaded.
|
|
7485
|
-
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
7486
|
-
* @param options.type (private-beta) specifies the bucket type. see `BucketType` for more details.
|
|
7487
|
-
* - default bucket type is `STANDARD`
|
|
7488
|
-
* @returns Promise with response containing newly created bucket name or error
|
|
7489
|
-
*
|
|
7490
|
-
* @example Create bucket
|
|
7491
|
-
* ```js
|
|
7492
|
-
* const { data, error } = await supabase
|
|
7493
|
-
* .storage
|
|
7494
|
-
* .createBucket('avatars', {
|
|
7495
|
-
* public: false,
|
|
7496
|
-
* allowedMimeTypes: ['image/png'],
|
|
7497
|
-
* fileSizeLimit: 1024
|
|
7498
|
-
* })
|
|
7499
|
-
* ```
|
|
7500
|
-
*
|
|
7501
|
-
* Response:
|
|
7502
|
-
* ```json
|
|
7503
|
-
* {
|
|
7504
|
-
* "data": {
|
|
7505
|
-
* "name": "avatars"
|
|
7506
|
-
* },
|
|
7507
|
-
* "error": null
|
|
7508
|
-
* }
|
|
7509
|
-
* ```
|
|
7510
|
-
*
|
|
7511
|
-
* @remarks
|
|
7512
|
-
* - RLS policy permissions required:
|
|
7513
|
-
* - `buckets` table permissions: `insert`
|
|
7514
|
-
* - `objects` table permissions: none
|
|
7515
|
-
* - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
|
|
7516
|
-
*/
|
|
7517
|
-
async createBucket(id, options = {
|
|
7518
|
-
public: false
|
|
7519
|
-
}) {
|
|
7520
|
-
return this.handleOperation(async () => {
|
|
7521
|
-
return await post(this.fetch, `${this.url}/bucket`, {
|
|
7522
|
-
id,
|
|
7523
|
-
name: id,
|
|
7524
|
-
type: options.type,
|
|
7525
|
-
public: options.public,
|
|
7526
|
-
file_size_limit: options.fileSizeLimit,
|
|
7527
|
-
allowed_mime_types: options.allowedMimeTypes
|
|
7528
|
-
}, {
|
|
7529
|
-
headers: this.headers
|
|
7530
|
-
});
|
|
7531
|
-
});
|
|
7486
|
+
blob;
|
|
7487
|
+
stream;
|
|
7488
|
+
[Symbol.toStringTag] = "WorkBuddyStorageDownload";
|
|
7489
|
+
constructor(blob, stream) {
|
|
7490
|
+
this.blob = blob;
|
|
7491
|
+
this.stream = stream;
|
|
7532
7492
|
}
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
*
|
|
7536
|
-
* @category Storage
|
|
7537
|
-
* @subcategory File Buckets
|
|
7538
|
-
* @param id A unique identifier for the bucket you are updating.
|
|
7539
|
-
* @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.
|
|
7540
|
-
* @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
|
|
7541
|
-
* The global file size limit takes precedence over this value.
|
|
7542
|
-
* The default value is null, which doesn't set a per bucket file size limit.
|
|
7543
|
-
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
|
|
7544
|
-
* The default value is null, which allows files with all mime types to be uploaded.
|
|
7545
|
-
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
7546
|
-
* @returns Promise with response containing success message or error
|
|
7547
|
-
*
|
|
7548
|
-
* @example Update bucket
|
|
7549
|
-
* ```js
|
|
7550
|
-
* const { data, error } = await supabase
|
|
7551
|
-
* .storage
|
|
7552
|
-
* .updateBucket('avatars', {
|
|
7553
|
-
* public: false,
|
|
7554
|
-
* allowedMimeTypes: ['image/png'],
|
|
7555
|
-
* fileSizeLimit: 1024
|
|
7556
|
-
* })
|
|
7557
|
-
* ```
|
|
7558
|
-
*
|
|
7559
|
-
* Response:
|
|
7560
|
-
* ```json
|
|
7561
|
-
* {
|
|
7562
|
-
* "data": {
|
|
7563
|
-
* "message": "Successfully updated"
|
|
7564
|
-
* },
|
|
7565
|
-
* "error": null
|
|
7566
|
-
* }
|
|
7567
|
-
* ```
|
|
7568
|
-
*
|
|
7569
|
-
* @remarks
|
|
7570
|
-
* - RLS policy permissions required:
|
|
7571
|
-
* - `buckets` table permissions: `select` and `update`
|
|
7572
|
-
* - `objects` table permissions: none
|
|
7573
|
-
* - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
|
|
7574
|
-
*/
|
|
7575
|
-
async updateBucket(id, options) {
|
|
7576
|
-
return this.handleOperation(async () => {
|
|
7577
|
-
return await put(this.fetch, `${this.url}/bucket/${id}`, {
|
|
7578
|
-
id,
|
|
7579
|
-
name: id,
|
|
7580
|
-
public: options.public,
|
|
7581
|
-
file_size_limit: options.fileSizeLimit,
|
|
7582
|
-
allowed_mime_types: options.allowedMimeTypes
|
|
7583
|
-
}, {
|
|
7584
|
-
headers: this.headers
|
|
7585
|
-
});
|
|
7586
|
-
});
|
|
7587
|
-
}
|
|
7588
|
-
/**
|
|
7589
|
-
* Removes all objects inside a single bucket.
|
|
7590
|
-
*
|
|
7591
|
-
* @category Storage
|
|
7592
|
-
* @subcategory File Buckets
|
|
7593
|
-
* @param id The unique identifier of the bucket you would like to empty.
|
|
7594
|
-
* @returns Promise with success message or error
|
|
7595
|
-
*
|
|
7596
|
-
* @example Empty bucket
|
|
7597
|
-
* ```js
|
|
7598
|
-
* const { data, error } = await supabase
|
|
7599
|
-
* .storage
|
|
7600
|
-
* .emptyBucket('avatars')
|
|
7601
|
-
* ```
|
|
7602
|
-
*
|
|
7603
|
-
* Response:
|
|
7604
|
-
* ```json
|
|
7605
|
-
* {
|
|
7606
|
-
* "data": {
|
|
7607
|
-
* "message": "Successfully emptied"
|
|
7608
|
-
* },
|
|
7609
|
-
* "error": null
|
|
7610
|
-
* }
|
|
7611
|
-
* ```
|
|
7612
|
-
*
|
|
7613
|
-
* @remarks
|
|
7614
|
-
* - RLS policy permissions required:
|
|
7615
|
-
* - `buckets` table permissions: `select`
|
|
7616
|
-
* - `objects` table permissions: `select` and `delete`
|
|
7617
|
-
* - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
|
|
7618
|
-
*/
|
|
7619
|
-
async emptyBucket(id) {
|
|
7620
|
-
return this.handleOperation(async () => {
|
|
7621
|
-
return await post(this.fetch, `${this.url}/bucket/${id}/empty`, {}, {
|
|
7622
|
-
headers: this.headers
|
|
7623
|
-
});
|
|
7624
|
-
});
|
|
7625
|
-
}
|
|
7626
|
-
/**
|
|
7627
|
-
* Deletes an existing bucket. A bucket can't be deleted with existing objects inside it.
|
|
7628
|
-
* You must first `empty()` the bucket.
|
|
7629
|
-
*
|
|
7630
|
-
* @category Storage
|
|
7631
|
-
* @subcategory File Buckets
|
|
7632
|
-
* @param id The unique identifier of the bucket you would like to delete.
|
|
7633
|
-
* @returns Promise with success message or error
|
|
7634
|
-
*
|
|
7635
|
-
* @example Delete bucket
|
|
7636
|
-
* ```js
|
|
7637
|
-
* const { data, error } = await supabase
|
|
7638
|
-
* .storage
|
|
7639
|
-
* .deleteBucket('avatars')
|
|
7640
|
-
* ```
|
|
7641
|
-
*
|
|
7642
|
-
* Response:
|
|
7643
|
-
* ```json
|
|
7644
|
-
* {
|
|
7645
|
-
* "data": {
|
|
7646
|
-
* "message": "Successfully deleted"
|
|
7647
|
-
* },
|
|
7648
|
-
* "error": null
|
|
7649
|
-
* }
|
|
7650
|
-
* ```
|
|
7651
|
-
*
|
|
7652
|
-
* @remarks
|
|
7653
|
-
* - RLS policy permissions required:
|
|
7654
|
-
* - `buckets` table permissions: `select` and `delete`
|
|
7655
|
-
* - `objects` table permissions: none
|
|
7656
|
-
* - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
|
|
7657
|
-
*/
|
|
7658
|
-
async deleteBucket(id) {
|
|
7659
|
-
return this.handleOperation(async () => {
|
|
7660
|
-
return await remove(this.fetch, `${this.url}/bucket/${id}`, {}, {
|
|
7661
|
-
headers: this.headers
|
|
7662
|
-
});
|
|
7663
|
-
});
|
|
7664
|
-
}
|
|
7665
|
-
/**
|
|
7666
|
-
* Purges the CDN cache for an entire bucket.
|
|
7667
|
-
*
|
|
7668
|
-
* Maps to `DELETE /cdn/{bucket}` on the Storage API. The server
|
|
7669
|
-
* issues a CDN invalidation for the bucket and returns `{ message: 'success' }`.
|
|
7670
|
-
*
|
|
7671
|
-
* **Requires the `service_role` key.** The underlying endpoint enforces
|
|
7672
|
-
* `service_role` JWT — calls made with the anon key or a user JWT will be
|
|
7673
|
-
* rejected by the server.
|
|
7674
|
-
*
|
|
7675
|
-
* **Hosted CDN feature.** On self-hosted Supabase, the Storage service must
|
|
7676
|
-
* have `CDN_PURGE_ENDPOINT_URL` configured and the `purgeCache` tenant
|
|
7677
|
-
* feature enabled, otherwise the server returns an error.
|
|
7678
|
-
*
|
|
7679
|
-
* @category Storage
|
|
7680
|
-
* @subcategory File Buckets
|
|
7681
|
-
* @param id The unique identifier of the bucket you would like to purge from cache.
|
|
7682
|
-
* @param options Optional purge cache options.
|
|
7683
|
-
* @param options.transformations If true, purges only transformations (resized/formatted variants), leaving original cached files intact.
|
|
7684
|
-
* @param parameters Optional fetch parameters such as an `AbortController` signal.
|
|
7685
|
-
* @returns Promise with `{ data: { message }, error: null }` on success or `{ data: null, error }` on failure.
|
|
7686
|
-
*
|
|
7687
|
-
* @example Purge cache for an entire bucket
|
|
7688
|
-
* ```js
|
|
7689
|
-
* const { data, error } = await supabase
|
|
7690
|
-
* .storage
|
|
7691
|
-
* .purgeBucketCache('avatars')
|
|
7692
|
-
* ```
|
|
7693
|
-
*
|
|
7694
|
-
* @example Purge only transformations for an entire bucket
|
|
7695
|
-
* ```js
|
|
7696
|
-
* const { data, error } = await supabase
|
|
7697
|
-
* .storage
|
|
7698
|
-
* .purgeBucketCache('avatars', { transformations: true })
|
|
7699
|
-
* ```
|
|
7700
|
-
*/
|
|
7701
|
-
async purgeBucketCache(id, options, parameters) {
|
|
7702
|
-
return this.handleOperation(async () => {
|
|
7703
|
-
const query = new URLSearchParams();
|
|
7704
|
-
if (options?.transformations) {
|
|
7705
|
-
query.set("transformations", "true");
|
|
7706
|
-
}
|
|
7707
|
-
const queryString = query.toString();
|
|
7708
|
-
return await remove(this.fetch, `${this.url}/cdn/${encodeStoragePath(id)}${queryString ? `?${queryString}` : ""}`, {}, {
|
|
7709
|
-
headers: this.headers
|
|
7710
|
-
}, parameters);
|
|
7711
|
-
});
|
|
7712
|
-
}
|
|
7713
|
-
listBucketOptionsToQueryString(options) {
|
|
7714
|
-
const params = {};
|
|
7715
|
-
if (options) {
|
|
7716
|
-
if ("limit" in options) {
|
|
7717
|
-
params.limit = String(options.limit);
|
|
7718
|
-
}
|
|
7719
|
-
if ("offset" in options) {
|
|
7720
|
-
params.offset = String(options.offset);
|
|
7721
|
-
}
|
|
7722
|
-
if (options.search) {
|
|
7723
|
-
params.search = options.search;
|
|
7724
|
-
}
|
|
7725
|
-
if (options.sortColumn) {
|
|
7726
|
-
params.sortColumn = options.sortColumn;
|
|
7727
|
-
}
|
|
7728
|
-
if (options.sortOrder) {
|
|
7729
|
-
params.sortOrder = options.sortOrder;
|
|
7730
|
-
}
|
|
7731
|
-
}
|
|
7732
|
-
return Object.keys(params).length > 0 ? "?" + new URLSearchParams(params).toString() : "";
|
|
7733
|
-
}
|
|
7734
|
-
};
|
|
7735
|
-
|
|
7736
|
-
// src/vendor/storage/packages/StorageAnalyticsClient.ts
|
|
7737
|
-
import { IcebergRestCatalog } from "iceberg-js";
|
|
7738
|
-
var StorageAnalyticsClient = class extends BaseApiClient {
|
|
7739
|
-
static {
|
|
7740
|
-
__name(this, "StorageAnalyticsClient");
|
|
7741
|
-
}
|
|
7742
|
-
/**
|
|
7743
|
-
* @alpha
|
|
7744
|
-
*
|
|
7745
|
-
* Creates a new StorageAnalyticsClient instance
|
|
7746
|
-
*
|
|
7747
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
7748
|
-
*
|
|
7749
|
-
* @category Storage
|
|
7750
|
-
* @subcategory Analytics Buckets
|
|
7751
|
-
* @param url - The base URL for the storage API
|
|
7752
|
-
* @param headers - HTTP headers to include in requests
|
|
7753
|
-
* @param fetch - Optional custom fetch implementation
|
|
7754
|
-
*
|
|
7755
|
-
* @example Using supabase-js (recommended)
|
|
7756
|
-
* ```typescript
|
|
7757
|
-
* import { createClient } from '@supabase/supabase-js'
|
|
7758
|
-
*
|
|
7759
|
-
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
|
|
7760
|
-
* const { data, error } = await supabase.storage.analytics.listBuckets()
|
|
7761
|
-
* ```
|
|
7762
|
-
*
|
|
7763
|
-
* @example Standalone import for bundle-sensitive environments
|
|
7764
|
-
* ```typescript
|
|
7765
|
-
* import { StorageAnalyticsClient } from '@supabase/storage-js'
|
|
7766
|
-
*
|
|
7767
|
-
* const client = new StorageAnalyticsClient(url, headers)
|
|
7768
|
-
* ```
|
|
7769
|
-
*/
|
|
7770
|
-
constructor(url, headers = {}, fetch2) {
|
|
7771
|
-
const finalUrl = url.replace(/\/$/, "");
|
|
7772
|
-
const finalHeaders = {
|
|
7773
|
-
...DEFAULT_HEADERS,
|
|
7774
|
-
...headers
|
|
7775
|
-
};
|
|
7776
|
-
super(finalUrl, finalHeaders, fetch2, "storage");
|
|
7777
|
-
}
|
|
7778
|
-
/**
|
|
7779
|
-
* @alpha
|
|
7780
|
-
*
|
|
7781
|
-
* Creates a new analytics bucket using Iceberg tables
|
|
7782
|
-
* Analytics buckets are optimized for analytical queries and data processing
|
|
7783
|
-
*
|
|
7784
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
7785
|
-
*
|
|
7786
|
-
* @category Storage
|
|
7787
|
-
* @subcategory Analytics Buckets
|
|
7788
|
-
* @param name A unique name for the bucket you are creating
|
|
7789
|
-
* @returns Promise with response containing newly created analytics bucket or error
|
|
7790
|
-
*
|
|
7791
|
-
* @example Create analytics bucket
|
|
7792
|
-
* ```js
|
|
7793
|
-
* const { data, error } = await supabase
|
|
7794
|
-
* .storage
|
|
7795
|
-
* .analytics
|
|
7796
|
-
* .createBucket('analytics-data')
|
|
7797
|
-
* ```
|
|
7798
|
-
*
|
|
7799
|
-
* Response:
|
|
7800
|
-
* ```json
|
|
7801
|
-
* {
|
|
7802
|
-
* "data": {
|
|
7803
|
-
* "name": "analytics-data",
|
|
7804
|
-
* "type": "ANALYTICS",
|
|
7805
|
-
* "format": "iceberg",
|
|
7806
|
-
* "created_at": "2024-05-22T22:26:05.100Z",
|
|
7807
|
-
* "updated_at": "2024-05-22T22:26:05.100Z"
|
|
7808
|
-
* },
|
|
7809
|
-
* "error": null
|
|
7810
|
-
* }
|
|
7811
|
-
* ```
|
|
7812
|
-
*
|
|
7813
|
-
* @remarks
|
|
7814
|
-
* - Creates a new analytics bucket using Iceberg tables
|
|
7815
|
-
* - Analytics buckets are optimized for analytical queries and data processing
|
|
7816
|
-
*/
|
|
7817
|
-
async createBucket(name) {
|
|
7818
|
-
return this.handleOperation(async () => {
|
|
7819
|
-
return await post(this.fetch, `${this.url}/bucket`, {
|
|
7820
|
-
name
|
|
7821
|
-
}, {
|
|
7822
|
-
headers: this.headers
|
|
7823
|
-
});
|
|
7824
|
-
});
|
|
7825
|
-
}
|
|
7826
|
-
/**
|
|
7827
|
-
* @alpha
|
|
7828
|
-
*
|
|
7829
|
-
* Retrieves the details of all Analytics Storage buckets within an existing project
|
|
7830
|
-
* Only returns buckets of type 'ANALYTICS'
|
|
7831
|
-
*
|
|
7832
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
7833
|
-
*
|
|
7834
|
-
* @category Storage
|
|
7835
|
-
* @subcategory Analytics Buckets
|
|
7836
|
-
* @param options Query parameters for listing buckets
|
|
7837
|
-
* @param options.limit Maximum number of buckets to return
|
|
7838
|
-
* @param options.offset Number of buckets to skip
|
|
7839
|
-
* @param options.sortColumn Column to sort by ('name', 'created_at', 'updated_at')
|
|
7840
|
-
* @param options.sortOrder Sort order ('asc' or 'desc')
|
|
7841
|
-
* @param options.search Search term to filter bucket names
|
|
7842
|
-
* @returns Promise with response containing array of analytics buckets or error
|
|
7843
|
-
*
|
|
7844
|
-
* @example List analytics buckets
|
|
7845
|
-
* ```js
|
|
7846
|
-
* const { data, error } = await supabase
|
|
7847
|
-
* .storage
|
|
7848
|
-
* .analytics
|
|
7849
|
-
* .listBuckets({
|
|
7850
|
-
* limit: 10,
|
|
7851
|
-
* offset: 0,
|
|
7852
|
-
* sortColumn: 'created_at',
|
|
7853
|
-
* sortOrder: 'desc'
|
|
7854
|
-
* })
|
|
7855
|
-
* ```
|
|
7856
|
-
*
|
|
7857
|
-
* Response:
|
|
7858
|
-
* ```json
|
|
7859
|
-
* {
|
|
7860
|
-
* "data": [
|
|
7861
|
-
* {
|
|
7862
|
-
* "name": "analytics-data",
|
|
7863
|
-
* "type": "ANALYTICS",
|
|
7864
|
-
* "format": "iceberg",
|
|
7865
|
-
* "created_at": "2024-05-22T22:26:05.100Z",
|
|
7866
|
-
* "updated_at": "2024-05-22T22:26:05.100Z"
|
|
7867
|
-
* }
|
|
7868
|
-
* ],
|
|
7869
|
-
* "error": null
|
|
7870
|
-
* }
|
|
7871
|
-
* ```
|
|
7872
|
-
*
|
|
7873
|
-
* @remarks
|
|
7874
|
-
* - Retrieves the details of all Analytics Storage buckets within an existing project
|
|
7875
|
-
* - Only returns buckets of type 'ANALYTICS'
|
|
7876
|
-
*/
|
|
7877
|
-
async listBuckets(options) {
|
|
7878
|
-
return this.handleOperation(async () => {
|
|
7879
|
-
const queryParams = new URLSearchParams();
|
|
7880
|
-
if (options?.limit !== void 0) queryParams.set("limit", options.limit.toString());
|
|
7881
|
-
if (options?.offset !== void 0) queryParams.set("offset", options.offset.toString());
|
|
7882
|
-
if (options?.sortColumn) queryParams.set("sortColumn", options.sortColumn);
|
|
7883
|
-
if (options?.sortOrder) queryParams.set("sortOrder", options.sortOrder);
|
|
7884
|
-
if (options?.search) queryParams.set("search", options.search);
|
|
7885
|
-
const queryString = queryParams.toString();
|
|
7886
|
-
const url = queryString ? `${this.url}/bucket?${queryString}` : `${this.url}/bucket`;
|
|
7887
|
-
return await get(this.fetch, url, {
|
|
7888
|
-
headers: this.headers
|
|
7889
|
-
});
|
|
7890
|
-
});
|
|
7891
|
-
}
|
|
7892
|
-
/**
|
|
7893
|
-
* @alpha
|
|
7894
|
-
*
|
|
7895
|
-
* Deletes an existing analytics bucket
|
|
7896
|
-
* A bucket can't be deleted with existing objects inside it
|
|
7897
|
-
* You must first empty the bucket before deletion
|
|
7898
|
-
*
|
|
7899
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
7900
|
-
*
|
|
7901
|
-
* @category Storage
|
|
7902
|
-
* @subcategory Analytics Buckets
|
|
7903
|
-
* @param bucketName The unique identifier of the bucket you would like to delete
|
|
7904
|
-
* @returns Promise with response containing success message or error
|
|
7905
|
-
*
|
|
7906
|
-
* @example Delete analytics bucket
|
|
7907
|
-
* ```js
|
|
7908
|
-
* const { data, error } = await supabase
|
|
7909
|
-
* .storage
|
|
7910
|
-
* .analytics
|
|
7911
|
-
* .deleteBucket('analytics-data')
|
|
7912
|
-
* ```
|
|
7913
|
-
*
|
|
7914
|
-
* Response:
|
|
7915
|
-
* ```json
|
|
7916
|
-
* {
|
|
7917
|
-
* "data": {
|
|
7918
|
-
* "message": "Successfully deleted"
|
|
7919
|
-
* },
|
|
7920
|
-
* "error": null
|
|
7921
|
-
* }
|
|
7922
|
-
* ```
|
|
7923
|
-
*
|
|
7924
|
-
* @remarks
|
|
7925
|
-
* - Deletes an analytics bucket
|
|
7926
|
-
*/
|
|
7927
|
-
async deleteBucket(bucketName) {
|
|
7928
|
-
return this.handleOperation(async () => {
|
|
7929
|
-
return await remove(this.fetch, `${this.url}/bucket/${bucketName}`, {}, {
|
|
7930
|
-
headers: this.headers
|
|
7931
|
-
});
|
|
7932
|
-
});
|
|
7933
|
-
}
|
|
7934
|
-
/**
|
|
7935
|
-
* @alpha
|
|
7936
|
-
*
|
|
7937
|
-
* Get an Iceberg REST Catalog client configured for a specific analytics bucket
|
|
7938
|
-
* Use this to perform advanced table and namespace operations within the bucket
|
|
7939
|
-
* The returned client provides full access to the Apache Iceberg REST Catalog API
|
|
7940
|
-
* with the Supabase `{ data, error }` pattern for consistent error handling on all operations.
|
|
7941
|
-
*
|
|
7942
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
7943
|
-
*
|
|
7944
|
-
* @category Storage
|
|
7945
|
-
* @subcategory Analytics Buckets
|
|
7946
|
-
* @param bucketName - The name of the analytics bucket (warehouse) to connect to
|
|
7947
|
-
* @returns The wrapped Iceberg catalog client
|
|
7948
|
-
* @throws {StorageError} If the bucket name is invalid
|
|
7949
|
-
*
|
|
7950
|
-
* @example Get catalog and create table
|
|
7951
|
-
* ```js
|
|
7952
|
-
* // First, create an analytics bucket
|
|
7953
|
-
* const { data: bucket, error: bucketError } = await supabase
|
|
7954
|
-
* .storage
|
|
7955
|
-
* .analytics
|
|
7956
|
-
* .createBucket('analytics-data')
|
|
7957
|
-
*
|
|
7958
|
-
* // Get the Iceberg catalog for that bucket
|
|
7959
|
-
* const catalog = supabase.storage.analytics.from('analytics-data')
|
|
7960
|
-
*
|
|
7961
|
-
* // Create a namespace
|
|
7962
|
-
* const { error: nsError } = await catalog.createNamespace({ namespace: ['default'] })
|
|
7963
|
-
*
|
|
7964
|
-
* // Create a table with schema
|
|
7965
|
-
* const { data: tableMetadata, error: tableError } = await catalog.createTable(
|
|
7966
|
-
* { namespace: ['default'] },
|
|
7967
|
-
* {
|
|
7968
|
-
* name: 'events',
|
|
7969
|
-
* schema: {
|
|
7970
|
-
* type: 'struct',
|
|
7971
|
-
* fields: [
|
|
7972
|
-
* { id: 1, name: 'id', type: 'long', required: true },
|
|
7973
|
-
* { id: 2, name: 'timestamp', type: 'timestamp', required: true },
|
|
7974
|
-
* { id: 3, name: 'user_id', type: 'string', required: false }
|
|
7975
|
-
* ],
|
|
7976
|
-
* 'schema-id': 0,
|
|
7977
|
-
* 'identifier-field-ids': [1]
|
|
7978
|
-
* },
|
|
7979
|
-
* 'partition-spec': {
|
|
7980
|
-
* 'spec-id': 0,
|
|
7981
|
-
* fields: []
|
|
7982
|
-
* },
|
|
7983
|
-
* 'write-order': {
|
|
7984
|
-
* 'order-id': 0,
|
|
7985
|
-
* fields: []
|
|
7986
|
-
* },
|
|
7987
|
-
* properties: {
|
|
7988
|
-
* 'write.format.default': 'parquet'
|
|
7989
|
-
* }
|
|
7990
|
-
* }
|
|
7991
|
-
* )
|
|
7992
|
-
* ```
|
|
7993
|
-
*
|
|
7994
|
-
* @example List tables in namespace
|
|
7995
|
-
* ```js
|
|
7996
|
-
* const catalog = supabase.storage.analytics.from('analytics-data')
|
|
7997
|
-
*
|
|
7998
|
-
* // List all tables in the default namespace
|
|
7999
|
-
* const { data: tables, error: listError } = await catalog.listTables({ namespace: ['default'] })
|
|
8000
|
-
* if (listError) {
|
|
8001
|
-
* if (listError.isNotFound()) {
|
|
8002
|
-
* console.log('Namespace not found')
|
|
8003
|
-
* }
|
|
8004
|
-
* return
|
|
8005
|
-
* }
|
|
8006
|
-
* console.log(tables) // [{ namespace: ['default'], name: 'events' }]
|
|
8007
|
-
* ```
|
|
8008
|
-
*
|
|
8009
|
-
* @example Working with namespaces
|
|
8010
|
-
* ```js
|
|
8011
|
-
* const catalog = supabase.storage.analytics.from('analytics-data')
|
|
8012
|
-
*
|
|
8013
|
-
* // List all namespaces
|
|
8014
|
-
* const { data: namespaces } = await catalog.listNamespaces()
|
|
8015
|
-
*
|
|
8016
|
-
* // Create namespace with properties
|
|
8017
|
-
* await catalog.createNamespace(
|
|
8018
|
-
* { namespace: ['production'] },
|
|
8019
|
-
* { properties: { owner: 'data-team', env: 'prod' } }
|
|
8020
|
-
* )
|
|
8021
|
-
* ```
|
|
8022
|
-
*
|
|
8023
|
-
* @example Cleanup operations
|
|
8024
|
-
* ```js
|
|
8025
|
-
* const catalog = supabase.storage.analytics.from('analytics-data')
|
|
8026
|
-
*
|
|
8027
|
-
* // Drop table with purge option (removes all data)
|
|
8028
|
-
* const { error: dropError } = await catalog.dropTable(
|
|
8029
|
-
* { namespace: ['default'], name: 'events' },
|
|
8030
|
-
* { purge: true }
|
|
8031
|
-
* )
|
|
8032
|
-
*
|
|
8033
|
-
* if (dropError?.isNotFound()) {
|
|
8034
|
-
* console.log('Table does not exist')
|
|
8035
|
-
* }
|
|
8036
|
-
*
|
|
8037
|
-
* // Drop namespace (must be empty)
|
|
8038
|
-
* await catalog.dropNamespace({ namespace: ['default'] })
|
|
8039
|
-
* ```
|
|
8040
|
-
*
|
|
8041
|
-
* @remarks
|
|
8042
|
-
* This method provides a bridge between Supabase's bucket management and the standard
|
|
8043
|
-
* Apache Iceberg REST Catalog API. The bucket name maps to the Iceberg warehouse parameter.
|
|
8044
|
-
* All authentication and configuration is handled automatically using your Supabase credentials.
|
|
8045
|
-
*
|
|
8046
|
-
* **Error Handling**: Invalid bucket names throw immediately. All catalog
|
|
8047
|
-
* operations return `{ data, error }` where errors are `IcebergError` instances from iceberg-js.
|
|
8048
|
-
* Use helper methods like `error.isNotFound()` or check `error.status` for specific error handling.
|
|
8049
|
-
* Use `.throwOnError()` on the analytics client if you prefer exceptions for catalog operations.
|
|
8050
|
-
*
|
|
8051
|
-
* **Cleanup Operations**: When using `dropTable`, the `purge: true` option permanently
|
|
8052
|
-
* deletes all table data. Without it, the table is marked as deleted but data remains.
|
|
8053
|
-
*
|
|
8054
|
-
* **Library Dependency**: The returned catalog wraps `IcebergRestCatalog` from iceberg-js.
|
|
8055
|
-
* For complete API documentation and advanced usage, refer to the
|
|
8056
|
-
* [iceberg-js documentation](https://supabase.github.io/iceberg-js/).
|
|
8057
|
-
*/
|
|
8058
|
-
from(bucketName) {
|
|
8059
|
-
if (!isValidBucketName(bucketName)) {
|
|
8060
|
-
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.");
|
|
8061
|
-
}
|
|
8062
|
-
const catalog = new IcebergRestCatalog({
|
|
8063
|
-
baseUrl: this.url,
|
|
8064
|
-
catalogName: bucketName,
|
|
8065
|
-
auth: {
|
|
8066
|
-
type: "custom",
|
|
8067
|
-
getHeaders: /* @__PURE__ */ __name(async () => this.headers, "getHeaders")
|
|
8068
|
-
},
|
|
8069
|
-
fetch: this.fetch
|
|
8070
|
-
});
|
|
8071
|
-
const shouldThrowOnError = this.shouldThrowOnError;
|
|
8072
|
-
const wrappedCatalog = new Proxy(catalog, {
|
|
8073
|
-
get(target, prop) {
|
|
8074
|
-
const value = target[prop];
|
|
8075
|
-
if (typeof value !== "function") {
|
|
8076
|
-
return value;
|
|
8077
|
-
}
|
|
8078
|
-
return async (...args) => {
|
|
8079
|
-
try {
|
|
8080
|
-
const data = await value.apply(target, args);
|
|
8081
|
-
return {
|
|
8082
|
-
data,
|
|
8083
|
-
error: null
|
|
8084
|
-
};
|
|
8085
|
-
} catch (error) {
|
|
8086
|
-
if (shouldThrowOnError) {
|
|
8087
|
-
throw error;
|
|
8088
|
-
}
|
|
8089
|
-
return {
|
|
8090
|
-
data: null,
|
|
8091
|
-
error
|
|
8092
|
-
};
|
|
8093
|
-
}
|
|
8094
|
-
};
|
|
8095
|
-
}
|
|
8096
|
-
});
|
|
8097
|
-
return wrappedCatalog;
|
|
8098
|
-
}
|
|
8099
|
-
};
|
|
8100
|
-
|
|
8101
|
-
// src/vendor/storage/packages/VectorIndexApi.ts
|
|
8102
|
-
var VectorIndexApi = class extends BaseApiClient {
|
|
8103
|
-
static {
|
|
8104
|
-
__name(this, "VectorIndexApi");
|
|
8105
|
-
}
|
|
8106
|
-
/** Creates a new VectorIndexApi instance */
|
|
8107
|
-
constructor(url, headers = {}, fetch2) {
|
|
8108
|
-
const finalUrl = url.replace(/\/$/, "");
|
|
8109
|
-
const finalHeaders = {
|
|
8110
|
-
...DEFAULT_HEADERS,
|
|
8111
|
-
"Content-Type": "application/json",
|
|
8112
|
-
...headers
|
|
8113
|
-
};
|
|
8114
|
-
super(finalUrl, finalHeaders, fetch2, "vectors");
|
|
8115
|
-
}
|
|
8116
|
-
/** Creates a new vector index within a bucket */
|
|
8117
|
-
async createIndex(options) {
|
|
8118
|
-
return this.handleOperation(async () => {
|
|
8119
|
-
const data = await vectorsApi.post(this.fetch, `${this.url}/CreateIndex`, options, {
|
|
8120
|
-
headers: this.headers
|
|
8121
|
-
});
|
|
8122
|
-
return data || {};
|
|
8123
|
-
});
|
|
8124
|
-
}
|
|
8125
|
-
/** Retrieves metadata for a specific vector index */
|
|
8126
|
-
async getIndex(vectorBucketName, indexName) {
|
|
8127
|
-
return this.handleOperation(async () => {
|
|
8128
|
-
return await vectorsApi.post(this.fetch, `${this.url}/GetIndex`, {
|
|
8129
|
-
vectorBucketName,
|
|
8130
|
-
indexName
|
|
8131
|
-
}, {
|
|
8132
|
-
headers: this.headers
|
|
8133
|
-
});
|
|
8134
|
-
});
|
|
8135
|
-
}
|
|
8136
|
-
/** Lists vector indexes within a bucket with optional filtering and pagination */
|
|
8137
|
-
async listIndexes(options) {
|
|
8138
|
-
return this.handleOperation(async () => {
|
|
8139
|
-
return await vectorsApi.post(this.fetch, `${this.url}/ListIndexes`, options, {
|
|
8140
|
-
headers: this.headers
|
|
8141
|
-
});
|
|
8142
|
-
});
|
|
8143
|
-
}
|
|
8144
|
-
/** Deletes a vector index and all its data */
|
|
8145
|
-
async deleteIndex(vectorBucketName, indexName) {
|
|
8146
|
-
return this.handleOperation(async () => {
|
|
8147
|
-
const data = await vectorsApi.post(this.fetch, `${this.url}/DeleteIndex`, {
|
|
8148
|
-
vectorBucketName,
|
|
8149
|
-
indexName
|
|
8150
|
-
}, {
|
|
8151
|
-
headers: this.headers
|
|
8152
|
-
});
|
|
8153
|
-
return data || {};
|
|
8154
|
-
});
|
|
8155
|
-
}
|
|
8156
|
-
};
|
|
8157
|
-
|
|
8158
|
-
// src/vendor/storage/packages/VectorDataApi.ts
|
|
8159
|
-
var VectorDataApi = class extends BaseApiClient {
|
|
8160
|
-
static {
|
|
8161
|
-
__name(this, "VectorDataApi");
|
|
8162
|
-
}
|
|
8163
|
-
/** Creates a new VectorDataApi instance */
|
|
8164
|
-
constructor(url, headers = {}, fetch2) {
|
|
8165
|
-
const finalUrl = url.replace(/\/$/, "");
|
|
8166
|
-
const finalHeaders = {
|
|
8167
|
-
...DEFAULT_HEADERS,
|
|
8168
|
-
"Content-Type": "application/json",
|
|
8169
|
-
...headers
|
|
8170
|
-
};
|
|
8171
|
-
super(finalUrl, finalHeaders, fetch2, "vectors");
|
|
8172
|
-
}
|
|
8173
|
-
/** Inserts or updates vectors in batch (1-500 per request) */
|
|
8174
|
-
async putVectors(options) {
|
|
8175
|
-
if (options.vectors.length < 1 || options.vectors.length > 500) {
|
|
8176
|
-
throw new Error("Vector batch size must be between 1 and 500 items");
|
|
8177
|
-
}
|
|
8178
|
-
return this.handleOperation(async () => {
|
|
8179
|
-
const data = await vectorsApi.post(this.fetch, `${this.url}/PutVectors`, options, {
|
|
8180
|
-
headers: this.headers
|
|
8181
|
-
});
|
|
8182
|
-
return data || {};
|
|
8183
|
-
});
|
|
8184
|
-
}
|
|
8185
|
-
/** Retrieves vectors by their keys in batch */
|
|
8186
|
-
async getVectors(options) {
|
|
8187
|
-
return this.handleOperation(async () => {
|
|
8188
|
-
return await vectorsApi.post(this.fetch, `${this.url}/GetVectors`, options, {
|
|
8189
|
-
headers: this.headers
|
|
8190
|
-
});
|
|
8191
|
-
});
|
|
8192
|
-
}
|
|
8193
|
-
/** Lists vectors in an index with pagination */
|
|
8194
|
-
async listVectors(options) {
|
|
8195
|
-
if (options.segmentCount !== void 0) {
|
|
8196
|
-
if (options.segmentCount < 1 || options.segmentCount > 16) {
|
|
8197
|
-
throw new Error("segmentCount must be between 1 and 16");
|
|
8198
|
-
}
|
|
8199
|
-
if (options.segmentIndex !== void 0) {
|
|
8200
|
-
if (options.segmentIndex < 0 || options.segmentIndex >= options.segmentCount) {
|
|
8201
|
-
throw new Error(`segmentIndex must be between 0 and ${options.segmentCount - 1}`);
|
|
8202
|
-
}
|
|
8203
|
-
}
|
|
8204
|
-
}
|
|
8205
|
-
return this.handleOperation(async () => {
|
|
8206
|
-
return await vectorsApi.post(this.fetch, `${this.url}/ListVectors`, options, {
|
|
8207
|
-
headers: this.headers
|
|
8208
|
-
});
|
|
8209
|
-
});
|
|
8210
|
-
}
|
|
8211
|
-
/** Queries for similar vectors using approximate nearest neighbor search */
|
|
8212
|
-
async queryVectors(options) {
|
|
8213
|
-
return this.handleOperation(async () => {
|
|
8214
|
-
return await vectorsApi.post(this.fetch, `${this.url}/QueryVectors`, options, {
|
|
8215
|
-
headers: this.headers
|
|
8216
|
-
});
|
|
8217
|
-
});
|
|
8218
|
-
}
|
|
8219
|
-
/** Deletes vectors by their keys in batch (1-500 per request) */
|
|
8220
|
-
async deleteVectors(options) {
|
|
8221
|
-
if (options.keys.length < 1 || options.keys.length > 500) {
|
|
8222
|
-
throw new Error("Keys batch size must be between 1 and 500 items");
|
|
8223
|
-
}
|
|
8224
|
-
return this.handleOperation(async () => {
|
|
8225
|
-
const data = await vectorsApi.post(this.fetch, `${this.url}/DeleteVectors`, options, {
|
|
8226
|
-
headers: this.headers
|
|
8227
|
-
});
|
|
8228
|
-
return data || {};
|
|
8229
|
-
});
|
|
8230
|
-
}
|
|
8231
|
-
};
|
|
8232
|
-
|
|
8233
|
-
// src/vendor/storage/packages/VectorBucketApi.ts
|
|
8234
|
-
var VectorBucketApi = class extends BaseApiClient {
|
|
8235
|
-
static {
|
|
8236
|
-
__name(this, "VectorBucketApi");
|
|
8237
|
-
}
|
|
8238
|
-
/** Creates a new VectorBucketApi instance */
|
|
8239
|
-
constructor(url, headers = {}, fetch2) {
|
|
8240
|
-
const finalUrl = url.replace(/\/$/, "");
|
|
8241
|
-
const finalHeaders = {
|
|
8242
|
-
...DEFAULT_HEADERS,
|
|
8243
|
-
"Content-Type": "application/json",
|
|
8244
|
-
...headers
|
|
8245
|
-
};
|
|
8246
|
-
super(finalUrl, finalHeaders, fetch2, "vectors");
|
|
8247
|
-
}
|
|
8248
|
-
/** Creates a new vector bucket */
|
|
8249
|
-
async createBucket(vectorBucketName) {
|
|
8250
|
-
return this.handleOperation(async () => {
|
|
8251
|
-
const data = await vectorsApi.post(this.fetch, `${this.url}/CreateVectorBucket`, {
|
|
8252
|
-
vectorBucketName
|
|
8253
|
-
}, {
|
|
8254
|
-
headers: this.headers
|
|
8255
|
-
});
|
|
8256
|
-
return data || {};
|
|
8257
|
-
});
|
|
8258
|
-
}
|
|
8259
|
-
/** Retrieves metadata for a specific vector bucket */
|
|
8260
|
-
async getBucket(vectorBucketName) {
|
|
8261
|
-
return this.handleOperation(async () => {
|
|
8262
|
-
return await vectorsApi.post(this.fetch, `${this.url}/GetVectorBucket`, {
|
|
8263
|
-
vectorBucketName
|
|
8264
|
-
}, {
|
|
8265
|
-
headers: this.headers
|
|
8266
|
-
});
|
|
8267
|
-
});
|
|
8268
|
-
}
|
|
8269
|
-
/** Lists vector buckets with optional filtering and pagination */
|
|
8270
|
-
async listBuckets(options = {}) {
|
|
8271
|
-
return this.handleOperation(async () => {
|
|
8272
|
-
return await vectorsApi.post(this.fetch, `${this.url}/ListVectorBuckets`, options, {
|
|
8273
|
-
headers: this.headers
|
|
8274
|
-
});
|
|
8275
|
-
});
|
|
8276
|
-
}
|
|
8277
|
-
/** Deletes a vector bucket (must be empty first) */
|
|
8278
|
-
async deleteBucket(vectorBucketName) {
|
|
8279
|
-
return this.handleOperation(async () => {
|
|
8280
|
-
const data = await vectorsApi.post(this.fetch, `${this.url}/DeleteVectorBucket`, {
|
|
8281
|
-
vectorBucketName
|
|
8282
|
-
}, {
|
|
8283
|
-
headers: this.headers
|
|
8284
|
-
});
|
|
8285
|
-
return data || {};
|
|
8286
|
-
});
|
|
8287
|
-
}
|
|
8288
|
-
};
|
|
8289
|
-
|
|
8290
|
-
// src/vendor/storage/packages/StorageVectorsClient.ts
|
|
8291
|
-
var StorageVectorsClient = class extends VectorBucketApi {
|
|
8292
|
-
static {
|
|
8293
|
-
__name(this, "StorageVectorsClient");
|
|
8294
|
-
}
|
|
8295
|
-
/**
|
|
8296
|
-
* @alpha
|
|
8297
|
-
*
|
|
8298
|
-
* Creates a StorageVectorsClient that can manage buckets, indexes, and vectors.
|
|
8299
|
-
*
|
|
8300
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8301
|
-
*
|
|
8302
|
-
* @category Storage
|
|
8303
|
-
* @subcategory Vector Buckets
|
|
8304
|
-
* @param url - Base URL of the Storage Vectors REST API.
|
|
8305
|
-
* @param options.headers - Optional headers (for example `Authorization`) applied to every request.
|
|
8306
|
-
* @param options.fetch - Optional custom `fetch` implementation for non-browser runtimes.
|
|
8307
|
-
*
|
|
8308
|
-
* @example Using supabase-js (recommended)
|
|
8309
|
-
* ```typescript
|
|
8310
|
-
* import { createClient } from '@supabase/supabase-js'
|
|
8311
|
-
*
|
|
8312
|
-
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
|
|
8313
|
-
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
8314
|
-
* ```
|
|
8315
|
-
*
|
|
8316
|
-
* @example Standalone import for bundle-sensitive environments
|
|
8317
|
-
* ```typescript
|
|
8318
|
-
* import { StorageVectorsClient } from '@supabase/storage-js'
|
|
8319
|
-
*
|
|
8320
|
-
* const client = new StorageVectorsClient(url, options)
|
|
8321
|
-
* ```
|
|
8322
|
-
*/
|
|
8323
|
-
constructor(url, options = {}) {
|
|
8324
|
-
super(url, options.headers || {}, options.fetch);
|
|
8325
|
-
}
|
|
8326
|
-
/**
|
|
8327
|
-
*
|
|
8328
|
-
* @alpha
|
|
8329
|
-
*
|
|
8330
|
-
* Access operations for a specific vector bucket
|
|
8331
|
-
* Returns a scoped client for index and vector operations within the bucket
|
|
8332
|
-
*
|
|
8333
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8334
|
-
*
|
|
8335
|
-
* @category Storage
|
|
8336
|
-
* @subcategory Vector Buckets
|
|
8337
|
-
* @param vectorBucketName - Name of the vector bucket
|
|
8338
|
-
* @returns Bucket-scoped client with index and vector operations
|
|
8339
|
-
*
|
|
8340
|
-
* @example Accessing a vector bucket
|
|
8341
|
-
* ```typescript
|
|
8342
|
-
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
8343
|
-
* ```
|
|
8344
|
-
*/
|
|
8345
|
-
from(vectorBucketName) {
|
|
8346
|
-
return new VectorBucketScope(this.url, this.headers, vectorBucketName, this.fetch);
|
|
8347
|
-
}
|
|
8348
|
-
/**
|
|
8349
|
-
*
|
|
8350
|
-
* @alpha
|
|
8351
|
-
*
|
|
8352
|
-
* Creates a new vector bucket
|
|
8353
|
-
* Vector buckets are containers for vector indexes and their data
|
|
8354
|
-
*
|
|
8355
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8356
|
-
*
|
|
8357
|
-
* @category Storage
|
|
8358
|
-
* @subcategory Vector Buckets
|
|
8359
|
-
* @param vectorBucketName - Unique name for the vector bucket
|
|
8360
|
-
* @returns Promise with empty response on success or error
|
|
8361
|
-
*
|
|
8362
|
-
* @example Creating a vector bucket
|
|
8363
|
-
* ```typescript
|
|
8364
|
-
* const { data, error } = await supabase
|
|
8365
|
-
* .storage
|
|
8366
|
-
* .vectors
|
|
8367
|
-
* .createBucket('embeddings-prod')
|
|
8368
|
-
* ```
|
|
8369
|
-
*/
|
|
8370
|
-
async createBucket(vectorBucketName) {
|
|
8371
|
-
return super.createBucket(vectorBucketName);
|
|
8372
|
-
}
|
|
8373
|
-
/**
|
|
8374
|
-
*
|
|
8375
|
-
* @alpha
|
|
8376
|
-
*
|
|
8377
|
-
* Retrieves metadata for a specific vector bucket
|
|
8378
|
-
*
|
|
8379
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8380
|
-
*
|
|
8381
|
-
* @category Storage
|
|
8382
|
-
* @subcategory Vector Buckets
|
|
8383
|
-
* @param vectorBucketName - Name of the vector bucket
|
|
8384
|
-
* @returns Promise with bucket metadata or error
|
|
8385
|
-
*
|
|
8386
|
-
* @example Get bucket metadata
|
|
8387
|
-
* ```typescript
|
|
8388
|
-
* const { data, error } = await supabase
|
|
8389
|
-
* .storage
|
|
8390
|
-
* .vectors
|
|
8391
|
-
* .getBucket('embeddings-prod')
|
|
8392
|
-
*
|
|
8393
|
-
* console.log('Bucket created:', data?.vectorBucket.creationTime)
|
|
8394
|
-
* ```
|
|
8395
|
-
*/
|
|
8396
|
-
async getBucket(vectorBucketName) {
|
|
8397
|
-
return super.getBucket(vectorBucketName);
|
|
8398
|
-
}
|
|
8399
|
-
/**
|
|
8400
|
-
*
|
|
8401
|
-
* @alpha
|
|
8402
|
-
*
|
|
8403
|
-
* Lists all vector buckets with optional filtering and pagination
|
|
8404
|
-
*
|
|
8405
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8406
|
-
*
|
|
8407
|
-
* @category Storage
|
|
8408
|
-
* @subcategory Vector Buckets
|
|
8409
|
-
* @param options - Optional filters (prefix, maxResults, nextToken)
|
|
8410
|
-
* @returns Promise with list of buckets or error
|
|
8411
|
-
*
|
|
8412
|
-
* @example List vector buckets
|
|
8413
|
-
* ```typescript
|
|
8414
|
-
* const { data, error } = await supabase
|
|
8415
|
-
* .storage
|
|
8416
|
-
* .vectors
|
|
8417
|
-
* .listBuckets({ prefix: 'embeddings-' })
|
|
8418
|
-
*
|
|
8419
|
-
* data?.vectorBuckets.forEach(bucket => {
|
|
8420
|
-
* console.log(bucket.vectorBucketName)
|
|
8421
|
-
* })
|
|
8422
|
-
* ```
|
|
8423
|
-
*/
|
|
8424
|
-
async listBuckets(options = {}) {
|
|
8425
|
-
return super.listBuckets(options);
|
|
8426
|
-
}
|
|
8427
|
-
/**
|
|
8428
|
-
*
|
|
8429
|
-
* @alpha
|
|
8430
|
-
*
|
|
8431
|
-
* Deletes a vector bucket (bucket must be empty)
|
|
8432
|
-
* All indexes must be deleted before deleting the bucket
|
|
8433
|
-
*
|
|
8434
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8435
|
-
*
|
|
8436
|
-
* @category Storage
|
|
8437
|
-
* @subcategory Vector Buckets
|
|
8438
|
-
* @param vectorBucketName - Name of the vector bucket to delete
|
|
8439
|
-
* @returns Promise with empty response on success or error
|
|
8440
|
-
*
|
|
8441
|
-
* @example Delete a vector bucket
|
|
8442
|
-
* ```typescript
|
|
8443
|
-
* const { data, error } = await supabase
|
|
8444
|
-
* .storage
|
|
8445
|
-
* .vectors
|
|
8446
|
-
* .deleteBucket('embeddings-old')
|
|
8447
|
-
* ```
|
|
8448
|
-
*/
|
|
8449
|
-
async deleteBucket(vectorBucketName) {
|
|
8450
|
-
return super.deleteBucket(vectorBucketName);
|
|
8451
|
-
}
|
|
8452
|
-
};
|
|
8453
|
-
var VectorBucketScope = class extends VectorIndexApi {
|
|
8454
|
-
static {
|
|
8455
|
-
__name(this, "VectorBucketScope");
|
|
8456
|
-
}
|
|
8457
|
-
vectorBucketName;
|
|
8458
|
-
/**
|
|
8459
|
-
* @alpha
|
|
8460
|
-
*
|
|
8461
|
-
* Creates a helper that automatically scopes all index operations to the provided bucket.
|
|
8462
|
-
*
|
|
8463
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8464
|
-
*
|
|
8465
|
-
* @category Storage
|
|
8466
|
-
* @subcategory Vector Buckets
|
|
8467
|
-
* @example Creating a vector bucket scope
|
|
8468
|
-
* ```typescript
|
|
8469
|
-
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
8470
|
-
* ```
|
|
8471
|
-
*/
|
|
8472
|
-
constructor(url, headers, vectorBucketName, fetch2) {
|
|
8473
|
-
super(url, headers, fetch2);
|
|
8474
|
-
this.vectorBucketName = vectorBucketName;
|
|
8475
|
-
}
|
|
8476
|
-
/**
|
|
8477
|
-
*
|
|
8478
|
-
* @alpha
|
|
8479
|
-
*
|
|
8480
|
-
* Creates a new vector index in this bucket
|
|
8481
|
-
* Convenience method that automatically includes the bucket name
|
|
8482
|
-
*
|
|
8483
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8484
|
-
*
|
|
8485
|
-
* @category Storage
|
|
8486
|
-
* @subcategory Vector Buckets
|
|
8487
|
-
* @param options - Index configuration (vectorBucketName is automatically set)
|
|
8488
|
-
* @returns Promise with empty response on success or error
|
|
8489
|
-
*
|
|
8490
|
-
* @example Creating a vector index
|
|
8491
|
-
* ```typescript
|
|
8492
|
-
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
8493
|
-
* await bucket.createIndex({
|
|
8494
|
-
* indexName: 'documents-openai',
|
|
8495
|
-
* dataType: 'float32',
|
|
8496
|
-
* dimension: 1536,
|
|
8497
|
-
* distanceMetric: 'cosine',
|
|
8498
|
-
* metadataConfiguration: {
|
|
8499
|
-
* nonFilterableMetadataKeys: ['raw_text']
|
|
8500
|
-
* }
|
|
8501
|
-
* })
|
|
8502
|
-
* ```
|
|
8503
|
-
*/
|
|
8504
|
-
async createIndex(options) {
|
|
8505
|
-
return super.createIndex({
|
|
8506
|
-
...options,
|
|
8507
|
-
vectorBucketName: this.vectorBucketName
|
|
8508
|
-
});
|
|
8509
|
-
}
|
|
8510
|
-
/**
|
|
8511
|
-
*
|
|
8512
|
-
* @alpha
|
|
8513
|
-
*
|
|
8514
|
-
* Lists indexes in this bucket
|
|
8515
|
-
* Convenience method that automatically includes the bucket name
|
|
8516
|
-
*
|
|
8517
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8518
|
-
*
|
|
8519
|
-
* @category Storage
|
|
8520
|
-
* @subcategory Vector Buckets
|
|
8521
|
-
* @param options - Listing options (vectorBucketName is automatically set)
|
|
8522
|
-
* @returns Promise with response containing indexes array and pagination token or error
|
|
8523
|
-
*
|
|
8524
|
-
* @example List indexes
|
|
8525
|
-
* ```typescript
|
|
8526
|
-
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
8527
|
-
* const { data } = await bucket.listIndexes({ prefix: 'documents-' })
|
|
8528
|
-
* ```
|
|
8529
|
-
*/
|
|
8530
|
-
async listIndexes(options = {}) {
|
|
8531
|
-
return super.listIndexes({
|
|
8532
|
-
...options,
|
|
8533
|
-
vectorBucketName: this.vectorBucketName
|
|
8534
|
-
});
|
|
8535
|
-
}
|
|
8536
|
-
/**
|
|
8537
|
-
*
|
|
8538
|
-
* @alpha
|
|
8539
|
-
*
|
|
8540
|
-
* Retrieves metadata for a specific index in this bucket
|
|
8541
|
-
* Convenience method that automatically includes the bucket name
|
|
8542
|
-
*
|
|
8543
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8544
|
-
*
|
|
8545
|
-
* @category Storage
|
|
8546
|
-
* @subcategory Vector Buckets
|
|
8547
|
-
* @param indexName - Name of the index to retrieve
|
|
8548
|
-
* @returns Promise with index metadata or error
|
|
8549
|
-
*
|
|
8550
|
-
* @example Get index metadata
|
|
8551
|
-
* ```typescript
|
|
8552
|
-
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
8553
|
-
* const { data } = await bucket.getIndex('documents-openai')
|
|
8554
|
-
* console.log('Dimension:', data?.index.dimension)
|
|
8555
|
-
* ```
|
|
8556
|
-
*/
|
|
8557
|
-
async getIndex(indexName) {
|
|
8558
|
-
return super.getIndex(this.vectorBucketName, indexName);
|
|
8559
|
-
}
|
|
8560
|
-
/**
|
|
8561
|
-
*
|
|
8562
|
-
* @alpha
|
|
8563
|
-
*
|
|
8564
|
-
* Deletes an index from this bucket
|
|
8565
|
-
* Convenience method that automatically includes the bucket name
|
|
8566
|
-
*
|
|
8567
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8568
|
-
*
|
|
8569
|
-
* @category Storage
|
|
8570
|
-
* @subcategory Vector Buckets
|
|
8571
|
-
* @param indexName - Name of the index to delete
|
|
8572
|
-
* @returns Promise with empty response on success or error
|
|
8573
|
-
*
|
|
8574
|
-
* @example Delete an index
|
|
8575
|
-
* ```typescript
|
|
8576
|
-
* const bucket = supabase.storage.vectors.from('embeddings-prod')
|
|
8577
|
-
* await bucket.deleteIndex('old-index')
|
|
8578
|
-
* ```
|
|
8579
|
-
*/
|
|
8580
|
-
async deleteIndex(indexName) {
|
|
8581
|
-
return super.deleteIndex(this.vectorBucketName, indexName);
|
|
8582
|
-
}
|
|
8583
|
-
/**
|
|
8584
|
-
*
|
|
8585
|
-
* @alpha
|
|
8586
|
-
*
|
|
8587
|
-
* Access operations for a specific index within this bucket
|
|
8588
|
-
* Returns a scoped client for vector data operations
|
|
8589
|
-
*
|
|
8590
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8591
|
-
*
|
|
8592
|
-
* @category Storage
|
|
8593
|
-
* @subcategory Vector Buckets
|
|
8594
|
-
* @param indexName - Name of the index
|
|
8595
|
-
* @returns Index-scoped client with vector data operations
|
|
8596
|
-
*
|
|
8597
|
-
* @example Accessing an index
|
|
8598
|
-
* ```typescript
|
|
8599
|
-
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
8600
|
-
*
|
|
8601
|
-
* // Insert vectors
|
|
8602
|
-
* await index.putVectors({
|
|
8603
|
-
* vectors: [
|
|
8604
|
-
* { key: 'doc-1', data: { float32: [...] }, metadata: { title: 'Intro' } }
|
|
8605
|
-
* ]
|
|
8606
|
-
* })
|
|
8607
|
-
*
|
|
8608
|
-
* // Query similar vectors
|
|
8609
|
-
* const { data } = await index.queryVectors({
|
|
8610
|
-
* queryVector: { float32: [...] },
|
|
8611
|
-
* topK: 5
|
|
8612
|
-
* })
|
|
8613
|
-
* ```
|
|
8614
|
-
*/
|
|
8615
|
-
index(indexName) {
|
|
8616
|
-
return new VectorIndexScope(this.url, this.headers, this.vectorBucketName, indexName, this.fetch);
|
|
8617
|
-
}
|
|
8618
|
-
};
|
|
8619
|
-
var VectorIndexScope = class extends VectorDataApi {
|
|
8620
|
-
static {
|
|
8621
|
-
__name(this, "VectorIndexScope");
|
|
8622
|
-
}
|
|
8623
|
-
vectorBucketName;
|
|
8624
|
-
indexName;
|
|
8625
|
-
/**
|
|
8626
|
-
*
|
|
8627
|
-
* @alpha
|
|
8628
|
-
*
|
|
8629
|
-
* Creates a helper that automatically scopes all vector operations to the provided bucket/index names.
|
|
8630
|
-
*
|
|
8631
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8632
|
-
*
|
|
8633
|
-
* @category Storage
|
|
8634
|
-
* @subcategory Vector Buckets
|
|
8635
|
-
* @example Creating a vector index scope
|
|
8636
|
-
* ```typescript
|
|
8637
|
-
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
8638
|
-
* ```
|
|
8639
|
-
*/
|
|
8640
|
-
constructor(url, headers, vectorBucketName, indexName, fetch2) {
|
|
8641
|
-
super(url, headers, fetch2);
|
|
8642
|
-
this.vectorBucketName = vectorBucketName;
|
|
8643
|
-
this.indexName = indexName;
|
|
8644
|
-
}
|
|
8645
|
-
/**
|
|
8646
|
-
*
|
|
8647
|
-
* @alpha
|
|
8648
|
-
*
|
|
8649
|
-
* Inserts or updates vectors in this index
|
|
8650
|
-
* Convenience method that automatically includes bucket and index names
|
|
8651
|
-
*
|
|
8652
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8653
|
-
*
|
|
8654
|
-
* @category Storage
|
|
8655
|
-
* @subcategory Vector Buckets
|
|
8656
|
-
* @param options - Vector insertion options (bucket and index names automatically set)
|
|
8657
|
-
* @returns Promise with empty response on success or error
|
|
8658
|
-
*
|
|
8659
|
-
* @example Insert vectors into an index
|
|
8660
|
-
* ```typescript
|
|
8661
|
-
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
8662
|
-
* await index.putVectors({
|
|
8663
|
-
* vectors: [
|
|
8664
|
-
* {
|
|
8665
|
-
* key: 'doc-1',
|
|
8666
|
-
* data: { float32: [0.1, 0.2, ...] },
|
|
8667
|
-
* metadata: { title: 'Introduction', page: 1 }
|
|
8668
|
-
* }
|
|
8669
|
-
* ]
|
|
8670
|
-
* })
|
|
8671
|
-
* ```
|
|
8672
|
-
*/
|
|
8673
|
-
async putVectors(options) {
|
|
8674
|
-
return super.putVectors({
|
|
8675
|
-
...options,
|
|
8676
|
-
vectorBucketName: this.vectorBucketName,
|
|
8677
|
-
indexName: this.indexName
|
|
8678
|
-
});
|
|
8679
|
-
}
|
|
8680
|
-
/**
|
|
8681
|
-
*
|
|
8682
|
-
* @alpha
|
|
8683
|
-
*
|
|
8684
|
-
* Retrieves vectors by keys from this index
|
|
8685
|
-
* Convenience method that automatically includes bucket and index names
|
|
8686
|
-
*
|
|
8687
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8688
|
-
*
|
|
8689
|
-
* @category Storage
|
|
8690
|
-
* @subcategory Vector Buckets
|
|
8691
|
-
* @param options - Vector retrieval options (bucket and index names automatically set)
|
|
8692
|
-
* @returns Promise with response containing vectors array or error
|
|
8693
|
-
*
|
|
8694
|
-
* @example Get vectors by keys
|
|
8695
|
-
* ```typescript
|
|
8696
|
-
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
8697
|
-
* const { data } = await index.getVectors({
|
|
8698
|
-
* keys: ['doc-1', 'doc-2'],
|
|
8699
|
-
* returnMetadata: true
|
|
8700
|
-
* })
|
|
8701
|
-
* ```
|
|
8702
|
-
*/
|
|
8703
|
-
async getVectors(options) {
|
|
8704
|
-
return super.getVectors({
|
|
8705
|
-
...options,
|
|
8706
|
-
vectorBucketName: this.vectorBucketName,
|
|
8707
|
-
indexName: this.indexName
|
|
8708
|
-
});
|
|
8709
|
-
}
|
|
8710
|
-
/**
|
|
8711
|
-
*
|
|
8712
|
-
* @alpha
|
|
8713
|
-
*
|
|
8714
|
-
* Lists vectors in this index with pagination
|
|
8715
|
-
* Convenience method that automatically includes bucket and index names
|
|
8716
|
-
*
|
|
8717
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8718
|
-
*
|
|
8719
|
-
* @category Storage
|
|
8720
|
-
* @subcategory Vector Buckets
|
|
8721
|
-
* @param options - Listing options (bucket and index names automatically set)
|
|
8722
|
-
* @returns Promise with response containing vectors array and pagination token or error
|
|
8723
|
-
*
|
|
8724
|
-
* @example List vectors with pagination
|
|
8725
|
-
* ```typescript
|
|
8726
|
-
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
8727
|
-
* const { data } = await index.listVectors({
|
|
8728
|
-
* maxResults: 500,
|
|
8729
|
-
* returnMetadata: true
|
|
8730
|
-
* })
|
|
8731
|
-
* ```
|
|
8732
|
-
*/
|
|
8733
|
-
async listVectors(options = {}) {
|
|
8734
|
-
return super.listVectors({
|
|
8735
|
-
...options,
|
|
8736
|
-
vectorBucketName: this.vectorBucketName,
|
|
8737
|
-
indexName: this.indexName
|
|
8738
|
-
});
|
|
8739
|
-
}
|
|
8740
|
-
/**
|
|
8741
|
-
*
|
|
8742
|
-
* @alpha
|
|
8743
|
-
*
|
|
8744
|
-
* Queries for similar vectors in this index
|
|
8745
|
-
* Convenience method that automatically includes bucket and index names
|
|
8746
|
-
*
|
|
8747
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8748
|
-
*
|
|
8749
|
-
* @category Storage
|
|
8750
|
-
* @subcategory Vector Buckets
|
|
8751
|
-
* @param options - Query options (bucket and index names automatically set)
|
|
8752
|
-
* @returns Promise with response containing matches array of similar vectors ordered by distance or error
|
|
8753
|
-
*
|
|
8754
|
-
* @example Query similar vectors
|
|
8755
|
-
* ```typescript
|
|
8756
|
-
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
8757
|
-
* const { data } = await index.queryVectors({
|
|
8758
|
-
* queryVector: { float32: [0.1, 0.2, ...] },
|
|
8759
|
-
* topK: 5,
|
|
8760
|
-
* filter: { category: 'technical' },
|
|
8761
|
-
* returnDistance: true,
|
|
8762
|
-
* returnMetadata: true
|
|
8763
|
-
* })
|
|
8764
|
-
* ```
|
|
8765
|
-
*/
|
|
8766
|
-
async queryVectors(options) {
|
|
8767
|
-
return super.queryVectors({
|
|
8768
|
-
...options,
|
|
8769
|
-
vectorBucketName: this.vectorBucketName,
|
|
8770
|
-
indexName: this.indexName
|
|
8771
|
-
});
|
|
8772
|
-
}
|
|
8773
|
-
/**
|
|
8774
|
-
*
|
|
8775
|
-
* @alpha
|
|
8776
|
-
*
|
|
8777
|
-
* Deletes vectors by keys from this index
|
|
8778
|
-
* Convenience method that automatically includes bucket and index names
|
|
8779
|
-
*
|
|
8780
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8781
|
-
*
|
|
8782
|
-
* @category Storage
|
|
8783
|
-
* @subcategory Vector Buckets
|
|
8784
|
-
* @param options - Deletion options (bucket and index names automatically set)
|
|
8785
|
-
* @returns Promise with empty response on success or error
|
|
8786
|
-
*
|
|
8787
|
-
* @example Delete vectors by keys
|
|
8788
|
-
* ```typescript
|
|
8789
|
-
* const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai')
|
|
8790
|
-
* await index.deleteVectors({
|
|
8791
|
-
* keys: ['doc-1', 'doc-2', 'doc-3']
|
|
8792
|
-
* })
|
|
8793
|
-
* ```
|
|
8794
|
-
*/
|
|
8795
|
-
async deleteVectors(options) {
|
|
8796
|
-
return super.deleteVectors({
|
|
8797
|
-
...options,
|
|
8798
|
-
vectorBucketName: this.vectorBucketName,
|
|
8799
|
-
indexName: this.indexName
|
|
8800
|
-
});
|
|
8801
|
-
}
|
|
8802
|
-
};
|
|
8803
|
-
|
|
8804
|
-
// src/vendor/storage/StorageClient.ts
|
|
8805
|
-
var StorageClient = class extends StorageBucketApi {
|
|
8806
|
-
static {
|
|
8807
|
-
__name(this, "StorageClient");
|
|
8808
|
-
}
|
|
8809
|
-
/**
|
|
8810
|
-
* Creates a client for Storage buckets, files, analytics, and vectors.
|
|
8811
|
-
*
|
|
8812
|
-
* @category Storage
|
|
8813
|
-
* @subcategory File Buckets
|
|
8814
|
-
*
|
|
8815
|
-
* @example Using supabase-js (recommended)
|
|
8816
|
-
* ```ts
|
|
8817
|
-
* import { createClient } from '@supabase/supabase-js'
|
|
8818
|
-
*
|
|
8819
|
-
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
|
|
8820
|
-
* const avatars = supabase.storage.from('avatars')
|
|
8821
|
-
* ```
|
|
8822
|
-
*
|
|
8823
|
-
* @example Standalone import for bundle-sensitive environments
|
|
8824
|
-
* ```ts
|
|
8825
|
-
* import { StorageClient } from '@supabase/storage-js'
|
|
8826
|
-
*
|
|
8827
|
-
* const storage = new StorageClient('https://xyzcompany.supabase.co/storage/v1', {
|
|
8828
|
-
* apikey: 'your-publishable-key',
|
|
8829
|
-
* })
|
|
8830
|
-
* const avatars = storage.from('avatars')
|
|
8831
|
-
* ```
|
|
8832
|
-
*/
|
|
8833
|
-
constructor(url, headers = {}, fetch2, opts) {
|
|
8834
|
-
super(url, headers, fetch2, opts);
|
|
8835
|
-
}
|
|
8836
|
-
/**
|
|
8837
|
-
* Perform file operation in a bucket.
|
|
8838
|
-
*
|
|
8839
|
-
* @category Storage
|
|
8840
|
-
* @subcategory File Buckets
|
|
8841
|
-
*
|
|
8842
|
-
* @param id The bucket id to operate on.
|
|
8843
|
-
*
|
|
8844
|
-
* @example Accessing a bucket
|
|
8845
|
-
* ```typescript
|
|
8846
|
-
* const avatars = supabase.storage.from('avatars')
|
|
8847
|
-
* ```
|
|
8848
|
-
*/
|
|
8849
|
-
from(id) {
|
|
8850
|
-
return new StorageFileApi(this.url, this.headers, id, this.fetch);
|
|
8851
|
-
}
|
|
8852
|
-
/**
|
|
8853
|
-
*
|
|
8854
|
-
* @alpha
|
|
8855
|
-
*
|
|
8856
|
-
* Access vector storage operations.
|
|
8857
|
-
*
|
|
8858
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8859
|
-
*
|
|
8860
|
-
* @category Storage
|
|
8861
|
-
* @subcategory Vector Buckets
|
|
8862
|
-
*
|
|
8863
|
-
* @returns A StorageVectorsClient instance configured with the current storage settings.
|
|
8864
|
-
*/
|
|
8865
|
-
get vectors() {
|
|
8866
|
-
return new StorageVectorsClient(this.url + "/vector", {
|
|
8867
|
-
headers: this.headers,
|
|
8868
|
-
fetch: this.fetch
|
|
8869
|
-
});
|
|
8870
|
-
}
|
|
8871
|
-
/**
|
|
8872
|
-
*
|
|
8873
|
-
* @alpha
|
|
8874
|
-
*
|
|
8875
|
-
* Access analytics storage operations using Iceberg tables.
|
|
8876
|
-
*
|
|
8877
|
-
* **Public alpha:** This API is part of a public alpha release and may not be available to your account type.
|
|
8878
|
-
*
|
|
8879
|
-
* @category Storage
|
|
8880
|
-
* @subcategory Analytics Buckets
|
|
8881
|
-
*
|
|
8882
|
-
* @returns A StorageAnalyticsClient instance configured with the current storage settings.
|
|
8883
|
-
*/
|
|
8884
|
-
get analytics() {
|
|
8885
|
-
return new StorageAnalyticsClient(this.url + "/iceberg", this.headers, this.fetch);
|
|
8886
|
-
}
|
|
8887
|
-
};
|
|
8888
|
-
|
|
8889
|
-
// src/modules/storage.ts
|
|
8890
|
-
var RUNTIME_STORAGE_BUCKET = "runtime";
|
|
8891
|
-
var DEFAULT_SIGNED_URL_TTL_SECONDS = 10 * 60;
|
|
8892
|
-
var MAX_SIGNED_URL_TTL_SECONDS = 60 * 60;
|
|
8893
|
-
var CloudStoragePathError = class extends Error {
|
|
8894
|
-
static {
|
|
8895
|
-
__name(this, "CloudStoragePathError");
|
|
8896
|
-
}
|
|
8897
|
-
constructor(message) {
|
|
8898
|
-
super(message);
|
|
8899
|
-
this.name = "CloudStoragePathError";
|
|
8900
|
-
}
|
|
8901
|
-
};
|
|
8902
|
-
var WorkBuddyStorageDownload = class {
|
|
8903
|
-
static {
|
|
8904
|
-
__name(this, "WorkBuddyStorageDownload");
|
|
8905
|
-
}
|
|
8906
|
-
blob;
|
|
8907
|
-
stream;
|
|
8908
|
-
[Symbol.toStringTag] = "WorkBuddyStorageDownload";
|
|
8909
|
-
constructor(blob, stream) {
|
|
8910
|
-
this.blob = blob;
|
|
8911
|
-
this.stream = stream;
|
|
8912
|
-
}
|
|
8913
|
-
asStream() {
|
|
8914
|
-
return this.stream();
|
|
7493
|
+
asStream() {
|
|
7494
|
+
return this.stream();
|
|
8915
7495
|
}
|
|
8916
7496
|
then(onfulfilled, onrejected) {
|
|
8917
7497
|
return this.blob().then(onfulfilled, onrejected);
|
|
@@ -9028,7 +7608,9 @@ var WorkBuddyStorageModule = class extends WorkBuddyStorageBucket {
|
|
|
9028
7608
|
}
|
|
9029
7609
|
};
|
|
9030
7610
|
function createStorageModule(config, fetch2) {
|
|
9031
|
-
const client =
|
|
7611
|
+
const client = {
|
|
7612
|
+
from: /* @__PURE__ */ __name((bucketID) => new StorageFileApi(`${config.endpoint}${CLOUD_MODULE_PATHS.storage}`, DEFAULT_HEADERS, bucketID, fetch2), "from")
|
|
7613
|
+
};
|
|
9032
7614
|
return new WorkBuddyStorageModule(client);
|
|
9033
7615
|
}
|
|
9034
7616
|
__name(createStorageModule, "createStorageModule");
|
|
@@ -9223,6 +7805,8 @@ export {
|
|
|
9223
7805
|
anonymousTokenProvider,
|
|
9224
7806
|
createMemoryStorage,
|
|
9225
7807
|
createWorkBuddyCloud,
|
|
7808
|
+
getModelCapability,
|
|
7809
|
+
getModelDisplayName,
|
|
9226
7810
|
shouldClearCredentials
|
|
9227
7811
|
};
|
|
9228
7812
|
//# sourceMappingURL=index.js.map
|