mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-05-23 04:27:50 +00:00
fix: honor telemetry for Cloudflare attribution headers
Some checks are pending
CI / build-check-test (push) Waiting to run
Some checks are pending
CI / build-check-test (push) Waiting to run
This commit is contained in:
parent
d6e08b3da0
commit
fbb5eed191
5 changed files with 27 additions and 24 deletions
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
## [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.4] - 2026-04-27
|
||||
|
|
|
|||
|
|
@ -64,10 +64,6 @@ const KIMI_STATIC_HEADERS = {
|
|||
"User-Agent": "KimiCLI/1.5",
|
||||
} 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_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"]);
|
||||
|
|
@ -403,7 +399,6 @@ async function loadModelsDevData(): Promise<Model<any>[]> {
|
|||
},
|
||||
contextWindow: m.limit?.context || 4096,
|
||||
maxTokens: m.limit?.output || 4096,
|
||||
headers: { ...CLOUDFLARE_STATIC_HEADERS },
|
||||
compat: { sendSessionAffinityHeaders: true },
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15381,7 +15381,6 @@ export const MODELS = {
|
|||
api: "openai-completions",
|
||||
provider: "cloudflare-workers-ai",
|
||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||
headers: {"User-Agent":"pi-coding-agent"},
|
||||
compat: {"sendSessionAffinityHeaders":true},
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
|
|
@ -15400,7 +15399,6 @@ export const MODELS = {
|
|||
api: "openai-completions",
|
||||
provider: "cloudflare-workers-ai",
|
||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||
headers: {"User-Agent":"pi-coding-agent"},
|
||||
compat: {"sendSessionAffinityHeaders":true},
|
||||
reasoning: false,
|
||||
input: ["text", "image"],
|
||||
|
|
@ -15419,7 +15417,6 @@ export const MODELS = {
|
|||
api: "openai-completions",
|
||||
provider: "cloudflare-workers-ai",
|
||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||
headers: {"User-Agent":"pi-coding-agent"},
|
||||
compat: {"sendSessionAffinityHeaders":true},
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
|
|
@ -15438,7 +15435,6 @@ export const MODELS = {
|
|||
api: "openai-completions",
|
||||
provider: "cloudflare-workers-ai",
|
||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||
headers: {"User-Agent":"pi-coding-agent"},
|
||||
compat: {"sendSessionAffinityHeaders":true},
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
|
|
@ -15457,7 +15453,6 @@ export const MODELS = {
|
|||
api: "openai-completions",
|
||||
provider: "cloudflare-workers-ai",
|
||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||
headers: {"User-Agent":"pi-coding-agent"},
|
||||
compat: {"sendSessionAffinityHeaders":true},
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
|
|
@ -15476,7 +15471,6 @@ export const MODELS = {
|
|||
api: "openai-completions",
|
||||
provider: "cloudflare-workers-ai",
|
||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||
headers: {"User-Agent":"pi-coding-agent"},
|
||||
compat: {"sendSessionAffinityHeaders":true},
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
|
|
@ -15495,7 +15489,6 @@ export const MODELS = {
|
|||
api: "openai-completions",
|
||||
provider: "cloudflare-workers-ai",
|
||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||
headers: {"User-Agent":"pi-coding-agent"},
|
||||
compat: {"sendSessionAffinityHeaders":true},
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
|
|
@ -15514,7 +15507,6 @@ export const MODELS = {
|
|||
api: "openai-completions",
|
||||
provider: "cloudflare-workers-ai",
|
||||
baseUrl: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1",
|
||||
headers: {"User-Agent":"pi-coding-agent"},
|
||||
compat: {"sendSessionAffinityHeaders":true},
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed Cloudflare Workers AI attribution headers to honor the install telemetry setting.
|
||||
|
||||
## [0.70.5] - 2026-04-27
|
||||
|
||||
### Fixed
|
||||
|
|
|
|||
|
|
@ -125,21 +125,29 @@ function getDefaultAgentDir(): string {
|
|||
return getAgentDir();
|
||||
}
|
||||
|
||||
function getOpenRouterAttributionHeaders(
|
||||
function getAttributionHeaders(
|
||||
model: Model<any>,
|
||||
settingsManager: SettingsManager,
|
||||
): Record<string, string> | undefined {
|
||||
if (!isInstallTelemetryEnabled(settingsManager)) {
|
||||
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",
|
||||
"X-OpenRouter-Title": "pi",
|
||||
"X-OpenRouter-Categories": "cli-agent",
|
||||
};
|
||||
|
||||
if (model.provider === "cloudflare-workers-ai" || model.baseUrl.includes("api.cloudflare.com")) {
|
||||
return {
|
||||
"User-Agent": "pi-coding-agent",
|
||||
};
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -316,7 +324,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|||
throw new Error(auth.error);
|
||||
}
|
||||
const providerRetrySettings = settingsManager.getProviderRetrySettings();
|
||||
const openRouterAttributionHeaders = getOpenRouterAttributionHeaders(model, settingsManager);
|
||||
const attributionHeaders = getAttributionHeaders(model, settingsManager);
|
||||
return streamSimple(model, context, {
|
||||
...options,
|
||||
apiKey: auth.apiKey,
|
||||
|
|
@ -324,8 +332,8 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|||
maxRetries: options?.maxRetries ?? providerRetrySettings.maxRetries,
|
||||
maxRetryDelayMs: options?.maxRetryDelayMs ?? providerRetrySettings.maxRetryDelayMs,
|
||||
headers:
|
||||
openRouterAttributionHeaders || auth.headers || options?.headers
|
||||
? { ...openRouterAttributionHeaders, ...auth.headers, ...options?.headers }
|
||||
attributionHeaders || auth.headers || options?.headers
|
||||
? { ...attributionHeaders, ...auth.headers, ...options?.headers }
|
||||
: undefined,
|
||||
});
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue