fix: honor telemetry for Cloudflare attribution headers
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Removed generated Cloudflare Workers AI `User-Agent` model headers so attribution can be controlled by callers.
|
||||||
|
|
||||||
## [0.70.5] - 2026-04-27
|
## [0.70.5] - 2026-04-27
|
||||||
|
|
||||||
## [0.70.4] - 2026-04-27
|
## [0.70.4] - 2026-04-27
|
||||||
|
|||||||
@@ -64,10 +64,6 @@ const KIMI_STATIC_HEADERS = {
|
|||||||
"User-Agent": "KimiCLI/1.5",
|
"User-Agent": "KimiCLI/1.5",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const CLOUDFLARE_STATIC_HEADERS = {
|
|
||||||
"User-Agent": "pi-coding-agent",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
const AI_GATEWAY_MODELS_URL = "https://ai-gateway.vercel.sh/v1";
|
const AI_GATEWAY_MODELS_URL = "https://ai-gateway.vercel.sh/v1";
|
||||||
const AI_GATEWAY_BASE_URL = "https://ai-gateway.vercel.sh";
|
const AI_GATEWAY_BASE_URL = "https://ai-gateway.vercel.sh";
|
||||||
const ZAI_TOOL_STREAM_UNSUPPORTED_MODELS = new Set(["glm-4.5", "glm-4.5-air", "glm-4.5-flash", "glm-4.5v"]);
|
const ZAI_TOOL_STREAM_UNSUPPORTED_MODELS = new Set(["glm-4.5", "glm-4.5-air", "glm-4.5-flash", "glm-4.5v"]);
|
||||||
@@ -403,7 +399,6 @@ async function loadModelsDevData(): Promise<Model<any>[]> {
|
|||||||
},
|
},
|
||||||
contextWindow: m.limit?.context || 4096,
|
contextWindow: m.limit?.context || 4096,
|
||||||
maxTokens: m.limit?.output || 4096,
|
maxTokens: m.limit?.output || 4096,
|
||||||
headers: { ...CLOUDFLARE_STATIC_HEADERS },
|
|
||||||
compat: { sendSessionAffinityHeaders: true },
|
compat: { sendSessionAffinityHeaders: true },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15381,7 +15381,6 @@ export const MODELS = {
|
|||||||
api: "openai-completions",
|
api: "openai-completions",
|
||||||
provider: "cloudflare-workers-ai",
|
provider: "cloudflare-workers-ai",
|
||||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||||
headers: {"User-Agent":"pi-coding-agent"},
|
|
||||||
compat: {"sendSessionAffinityHeaders":true},
|
compat: {"sendSessionAffinityHeaders":true},
|
||||||
reasoning: true,
|
reasoning: true,
|
||||||
input: ["text", "image"],
|
input: ["text", "image"],
|
||||||
@@ -15400,7 +15399,6 @@ export const MODELS = {
|
|||||||
api: "openai-completions",
|
api: "openai-completions",
|
||||||
provider: "cloudflare-workers-ai",
|
provider: "cloudflare-workers-ai",
|
||||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||||
headers: {"User-Agent":"pi-coding-agent"},
|
|
||||||
compat: {"sendSessionAffinityHeaders":true},
|
compat: {"sendSessionAffinityHeaders":true},
|
||||||
reasoning: false,
|
reasoning: false,
|
||||||
input: ["text", "image"],
|
input: ["text", "image"],
|
||||||
@@ -15419,7 +15417,6 @@ export const MODELS = {
|
|||||||
api: "openai-completions",
|
api: "openai-completions",
|
||||||
provider: "cloudflare-workers-ai",
|
provider: "cloudflare-workers-ai",
|
||||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||||
headers: {"User-Agent":"pi-coding-agent"},
|
|
||||||
compat: {"sendSessionAffinityHeaders":true},
|
compat: {"sendSessionAffinityHeaders":true},
|
||||||
reasoning: true,
|
reasoning: true,
|
||||||
input: ["text", "image"],
|
input: ["text", "image"],
|
||||||
@@ -15438,7 +15435,6 @@ export const MODELS = {
|
|||||||
api: "openai-completions",
|
api: "openai-completions",
|
||||||
provider: "cloudflare-workers-ai",
|
provider: "cloudflare-workers-ai",
|
||||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||||
headers: {"User-Agent":"pi-coding-agent"},
|
|
||||||
compat: {"sendSessionAffinityHeaders":true},
|
compat: {"sendSessionAffinityHeaders":true},
|
||||||
reasoning: true,
|
reasoning: true,
|
||||||
input: ["text", "image"],
|
input: ["text", "image"],
|
||||||
@@ -15457,7 +15453,6 @@ export const MODELS = {
|
|||||||
api: "openai-completions",
|
api: "openai-completions",
|
||||||
provider: "cloudflare-workers-ai",
|
provider: "cloudflare-workers-ai",
|
||||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||||
headers: {"User-Agent":"pi-coding-agent"},
|
|
||||||
compat: {"sendSessionAffinityHeaders":true},
|
compat: {"sendSessionAffinityHeaders":true},
|
||||||
reasoning: true,
|
reasoning: true,
|
||||||
input: ["text"],
|
input: ["text"],
|
||||||
@@ -15476,7 +15471,6 @@ export const MODELS = {
|
|||||||
api: "openai-completions",
|
api: "openai-completions",
|
||||||
provider: "cloudflare-workers-ai",
|
provider: "cloudflare-workers-ai",
|
||||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||||
headers: {"User-Agent":"pi-coding-agent"},
|
|
||||||
compat: {"sendSessionAffinityHeaders":true},
|
compat: {"sendSessionAffinityHeaders":true},
|
||||||
reasoning: true,
|
reasoning: true,
|
||||||
input: ["text"],
|
input: ["text"],
|
||||||
@@ -15495,7 +15489,6 @@ export const MODELS = {
|
|||||||
api: "openai-completions",
|
api: "openai-completions",
|
||||||
provider: "cloudflare-workers-ai",
|
provider: "cloudflare-workers-ai",
|
||||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||||
headers: {"User-Agent":"pi-coding-agent"},
|
|
||||||
compat: {"sendSessionAffinityHeaders":true},
|
compat: {"sendSessionAffinityHeaders":true},
|
||||||
reasoning: true,
|
reasoning: true,
|
||||||
input: ["text"],
|
input: ["text"],
|
||||||
@@ -15514,7 +15507,6 @@ export const MODELS = {
|
|||||||
api: "openai-completions",
|
api: "openai-completions",
|
||||||
provider: "cloudflare-workers-ai",
|
provider: "cloudflare-workers-ai",
|
||||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||||
headers: {"User-Agent":"pi-coding-agent"},
|
|
||||||
compat: {"sendSessionAffinityHeaders":true},
|
compat: {"sendSessionAffinityHeaders":true},
|
||||||
reasoning: true,
|
reasoning: true,
|
||||||
input: ["text"],
|
input: ["text"],
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed Cloudflare Workers AI attribution headers to honor the install telemetry setting.
|
||||||
|
|
||||||
## [0.70.5] - 2026-04-27
|
## [0.70.5] - 2026-04-27
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -125,21 +125,29 @@ function getDefaultAgentDir(): string {
|
|||||||
return getAgentDir();
|
return getAgentDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOpenRouterAttributionHeaders(
|
function getAttributionHeaders(
|
||||||
model: Model<any>,
|
model: Model<any>,
|
||||||
settingsManager: SettingsManager,
|
settingsManager: SettingsManager,
|
||||||
): Record<string, string> | undefined {
|
): Record<string, string> | undefined {
|
||||||
if (!isInstallTelemetryEnabled(settingsManager)) {
|
if (!isInstallTelemetryEnabled(settingsManager)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (model.provider !== "openrouter" && !model.baseUrl.includes("openrouter.ai")) {
|
|
||||||
return undefined;
|
if (model.provider === "openrouter" || model.baseUrl.includes("openrouter.ai")) {
|
||||||
|
return {
|
||||||
|
"HTTP-Referer": "https://pi.dev",
|
||||||
|
"X-OpenRouter-Title": "pi",
|
||||||
|
"X-OpenRouter-Categories": "cli-agent",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
"HTTP-Referer": "https://pi.dev",
|
if (model.provider === "cloudflare-workers-ai" || model.baseUrl.includes("api.cloudflare.com")) {
|
||||||
"X-OpenRouter-Title": "pi",
|
return {
|
||||||
"X-OpenRouter-Categories": "cli-agent",
|
"User-Agent": "pi-coding-agent",
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -316,7 +324,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|||||||
throw new Error(auth.error);
|
throw new Error(auth.error);
|
||||||
}
|
}
|
||||||
const providerRetrySettings = settingsManager.getProviderRetrySettings();
|
const providerRetrySettings = settingsManager.getProviderRetrySettings();
|
||||||
const openRouterAttributionHeaders = getOpenRouterAttributionHeaders(model, settingsManager);
|
const attributionHeaders = getAttributionHeaders(model, settingsManager);
|
||||||
return streamSimple(model, context, {
|
return streamSimple(model, context, {
|
||||||
...options,
|
...options,
|
||||||
apiKey: auth.apiKey,
|
apiKey: auth.apiKey,
|
||||||
@@ -324,8 +332,8 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|||||||
maxRetries: options?.maxRetries ?? providerRetrySettings.maxRetries,
|
maxRetries: options?.maxRetries ?? providerRetrySettings.maxRetries,
|
||||||
maxRetryDelayMs: options?.maxRetryDelayMs ?? providerRetrySettings.maxRetryDelayMs,
|
maxRetryDelayMs: options?.maxRetryDelayMs ?? providerRetrySettings.maxRetryDelayMs,
|
||||||
headers:
|
headers:
|
||||||
openRouterAttributionHeaders || auth.headers || options?.headers
|
attributionHeaders || auth.headers || options?.headers
|
||||||
? { ...openRouterAttributionHeaders, ...auth.headers, ...options?.headers }
|
? { ...attributionHeaders, ...auth.headers, ...options?.headers }
|
||||||
: undefined,
|
: undefined,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user