From 4343fc87aff96c8cd6f9e95792086de65247ff74 Mon Sep 17 00:00:00 2001 From: "zeyu.fz" Date: Tue, 11 Aug 2026 14:20:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20=E6=B7=BB=E5=8A=A0=E5=B9=B6?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=AE=A1=E7=90=86=20x-dashscope-openapisourc?= =?UTF-8?q?e=20=E8=AF=B7=E6=B1=82=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 headers.ts 中新增 OPEN_API_SOURCE 常量,作为静态的 OpenAPI 源标识 - 在 trackingHeaders 函数中添加 x-dashscope-openapisource 请求头 - 更新 client/index.ts 以导出 OPEN_API_SOURCE - 在 instrumented-fetch.test.ts 中添加对应请求头的测试,确保其正确添加或省略 - 修改文档注释,明确 x-dashscope-openapisource 与 x-dashscope-source-config 的用途和区别 --- packages/core/src/client/headers.ts | 11 ++++++++--- packages/core/src/client/index.ts | 8 +++++++- packages/core/tests/instrumented-fetch.test.ts | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/core/src/client/headers.ts b/packages/core/src/client/headers.ts index 9d84d39..5f8d30e 100644 --- a/packages/core/src/client/headers.ts +++ b/packages/core/src/client/headers.ts @@ -1,15 +1,19 @@ /** * Shared HTTP request headers for all outgoing requests. * - * Centralises the `x-dashscope-source-config` header so Bailian/DashScope API - * transports use the same product identity. Generic npm, OSS, and result-file - * transfers deliberately do not send this gateway-consumed metadata. + * Centralises the `x-dashscope-source-config` and `x-dashscope-openapisource` + * headers so Bailian/DashScope API transports use the same product identity. + * Generic npm, OSS, and result-file transfers deliberately do not send this + * gateway-consumed metadata. */ import type { Identity } from "../config/schema.ts"; export const CHANNEL = "bailian-cli"; +/** Static source identifier advertised to the DashScope/Bailian OpenAPI gateway. */ +export const OPEN_API_SOURCE = "BailianCLI"; + export type TrackingIdentity = Pick; export function sourceConfig(identity: TrackingIdentity): string { @@ -27,5 +31,6 @@ export function sourceConfig(identity: TrackingIdentity): string { export function trackingHeaders(identity: TrackingIdentity): Record { return { "x-dashscope-source-config": sourceConfig(identity), + "x-dashscope-openapisource": OPEN_API_SOURCE, }; } diff --git a/packages/core/src/client/index.ts b/packages/core/src/client/index.ts index 76b8615..6ad05dc 100644 --- a/packages/core/src/client/index.ts +++ b/packages/core/src/client/index.ts @@ -36,7 +36,13 @@ export { type ImageInputStyle, type ImageSizeProfile, } from "./image-routes.ts"; -export { CHANNEL, sourceConfig, trackingHeaders, type TrackingIdentity } from "./headers.ts"; +export { + CHANNEL, + OPEN_API_SOURCE, + sourceConfig, + trackingHeaders, + type TrackingIdentity, +} from "./headers.ts"; export type { HttpDeps, RequestOpts } from "./http.ts"; export { request, requestJson } from "./http.ts"; export { createInstrumentedFetch, type FetchImplementation } from "./instrumented-fetch.ts"; diff --git a/packages/core/tests/instrumented-fetch.test.ts b/packages/core/tests/instrumented-fetch.test.ts index ccecf99..51eb180 100644 --- a/packages/core/tests/instrumented-fetch.test.ts +++ b/packages/core/tests/instrumented-fetch.test.ts @@ -57,6 +57,7 @@ test("adds UA and tracking header on Alibaba Cloud hosts", async () => { tags: { t1: "public", t2: "bl", t3: "1.2.3" }, }), ); + expect(headers.get("x-dashscope-openapisource")).toBe("BailianCLI"); expect(headers.get("authorization")).toBe("Bearer k"); }); @@ -66,6 +67,7 @@ test("adds UA but no tracking header on third-party hosts", async () => { }); expect(headers.get("user-agent")).toBe("bailian-cli/1.2.3"); expect(headers.get("x-dashscope-source-config")).toBeNull(); + expect(headers.get("x-dashscope-openapisource")).toBeNull(); }); test("does not override a caller-provided User-Agent", async () => { @@ -86,6 +88,7 @@ test("passes non-URL-parseable inputs through without tracking headers", async ( const { url, headers } = await capture("/relative/path"); expect(url).toBe("/relative/path"); expect(headers.get("x-dashscope-source-config")).toBeNull(); + expect(headers.get("x-dashscope-openapisource")).toBeNull(); }); test("uses kscli identity and version in source config", () => {