@tencent-ai/cloud-agent-sdk 0.3.1 → 0.3.2-next.9adedf5.20260509
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 +17 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +17 -3
- package/dist/index.mjs.map +1 -1
- package/dist/tencent-ai-cloud-agent-sdk-0.3.2-next.9adedf5.20260509.tgz +0 -0
- package/package.json +4 -3
- package/dist/tencent-ai-cloud-agent-sdk-0.3.1.tgz +0 -0
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
|
/**
|
|
@@ -284,8 +297,9 @@ var RestClient = class {
|
|
|
284
297
|
"Content-Type": "application/json",
|
|
285
298
|
"Accept": "application/json"
|
|
286
299
|
};
|
|
287
|
-
if (this.opts.apiKey) headers["
|
|
288
|
-
|
|
300
|
+
if (this.opts.apiKey) if (this.opts.apiKey.startsWith("pt_")) headers["Authorization"] = `Bearer ${this.opts.apiKey}`;
|
|
301
|
+
else headers["X-Api-Key"] = this.opts.apiKey;
|
|
302
|
+
headers["X-Source-App"] = this.opts.sourceApp || "cloud-agent";
|
|
289
303
|
if (this.opts.sourceTenantId) headers["X-Source-Tenant-Id"] = this.opts.sourceTenantId;
|
|
290
304
|
if (this.opts.userId) headers["X-User-Id"] = this.opts.userId;
|
|
291
305
|
if (this.opts.headers) Object.assign(headers, this.opts.headers);
|
|
@@ -464,7 +478,7 @@ var RestClient = class {
|
|
|
464
478
|
await sleep(delayMs);
|
|
465
479
|
}
|
|
466
480
|
}
|
|
467
|
-
throw lastError;
|
|
481
|
+
throw lastError ?? /* @__PURE__ */ new Error("Retry exhausted with no captured error");
|
|
468
482
|
}
|
|
469
483
|
/** 计算退避时间。 */
|
|
470
484
|
getBackoffMs(attempt, opts) {
|