mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
feat(core): 添加并统一管理 x-dashscope-openapisource 请求头
- 在 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 的用途和区别
This commit is contained in:
@@ -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<Identity, "binName" | "version">;
|
||||
|
||||
export function sourceConfig(identity: TrackingIdentity): string {
|
||||
@@ -27,5 +31,6 @@ export function sourceConfig(identity: TrackingIdentity): string {
|
||||
export function trackingHeaders(identity: TrackingIdentity): Record<string, string> {
|
||||
return {
|
||||
"x-dashscope-source-config": sourceConfig(identity),
|
||||
"x-dashscope-openapisource": OPEN_API_SOURCE,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user