@tencent-ai/cloud-agent-sdk 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -207,6 +207,19 @@ function redactBody(body) {
207
207
 
208
208
  //#endregion
209
209
  //#region src/v1/rest/client.ts
210
+ /**
211
+ * REST 客户端 — 基于原生 fetch
212
+ *
213
+ * 职责:
214
+ * - 注入认证 / 身份 / 自定义 header(apiKey / source* / user 定制)
215
+ * - 统一解包 `{ code, msg, data, requestId }`,非 0 抛 `CloudAgentError`
216
+ * - 超时控制(AbortController + AbortSignal 合并)
217
+ * - 重试(指数退避 + 抖动;默认仅 GET 重试,非 GET 需显式 `retry`)
218
+ * - 日志:对齐 Anthropic SDK —— 日志行不带自造 ID,只带**服务端 requestId**
219
+ * 作为定位 ID;"是否在重试 / 第几次重试" 通过独立的告警行 + `attempt=N/M`
220
+ * 字段表达,而非自造 logId/retryOf 链
221
+ * - 脱敏:onRequest / onResponse 钩子 + debug 日志里的 headers 自动脱敏
222
+ */
210
223
  /** 默认 baseUrl */
211
224
  const DEFAULT_BASE_URL = "https://www.codebuddy.cn/v2/agentos";
212
225
  /**
@@ -286,7 +299,7 @@ var RestClient = class {
286
299
  };
287
300
  if (this.opts.apiKey) if (this.opts.apiKey.startsWith("pt_")) headers["Authorization"] = `Bearer ${this.opts.apiKey}`;
288
301
  else headers["X-Api-Key"] = this.opts.apiKey;
289
- if (this.opts.sourceApp) headers["X-Source-App"] = this.opts.sourceApp;
302
+ headers["X-Source-App"] = this.opts.sourceApp || "cloud-agent";
290
303
  if (this.opts.sourceTenantId) headers["X-Source-Tenant-Id"] = this.opts.sourceTenantId;
291
304
  if (this.opts.userId) headers["X-User-Id"] = this.opts.userId;
292
305
  if (this.opts.headers) Object.assign(headers, this.opts.headers);
@@ -465,7 +478,7 @@ var RestClient = class {
465
478
  await sleep(delayMs);
466
479
  }
467
480
  }
468
- throw lastError;
481
+ throw lastError ?? /* @__PURE__ */ new Error("Retry exhausted with no captured error");
469
482
  }
470
483
  /** 计算退避时间。 */
471
484
  getBackoffMs(attempt, opts) {