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", () => {