@tencent-ai/workbuddy-cloud-sdk 0.1.0-dev.dee063d.202608201621 → 0.1.1-dev.520de95.202609090209

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.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 endpoint, oauthRelayBaseUrl and publishableKey.");
68
+ throw new WorkBuddyCloudConfigError("createWorkBuddyCloud requires publishableKey.");
58
69
  }
59
70
  return Object.freeze({
60
- endpoint: normalizeHttpUrl(options.endpoint, "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.email = credentials.email;
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
- if (!credentials.email) {
561
- return fail(badRequest("sendOtp requires email"));
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
- isExistingUser
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
- if (!params.verificationId || !params.token || !params.email) {
616
- return fail(badRequest("verifyOtp requires verificationId, token and email"));
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: params.email,
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
- /** 拼出平台 Relay 授权地址;state 由 Relay 自己签发、校验并一次性消费。 */
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: booleanField(raw.enabled, raw.Enabled) ?? true,
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 server remains the
5175
- * final allowlist authority for chat requests.
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 === true) {
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: "stream_options can only be used with stream=true",
5643
+ message: "stream must be true; non-streaming chat completions are not supported",
5495
5644
  type: "invalid_request_error",
5496
- param: "stream_options",
5497
- code: "request_invalid_parameter"
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
  }
@@ -9223,6 +9349,8 @@ export {
9223
9349
  anonymousTokenProvider,
9224
9350
  createMemoryStorage,
9225
9351
  createWorkBuddyCloud,
9352
+ getModelCapability,
9353
+ getModelDisplayName,
9226
9354
  shouldClearCredentials
9227
9355
  };
9228
9356
  //# sourceMappingURL=index.js.map