fix(web): add prompt cache affinity to canvas agent (#74)

Co-authored-by: Tiantianr <260026737+Tiantianr@users.noreply.github.com>
This commit is contained in:
Tiantianr
2026-08-02 05:28:02 +08:00
committed by GitHub
parent c574e2d72e
commit e37c1114b3
4 changed files with 64 additions and 10 deletions

View File

@@ -0,0 +1,17 @@
export const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
export function clampOpenAIPromptCacheKey(value?: string) {
const key = value?.trim();
if (!key) return undefined;
return Array.from(key).slice(0, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH).join("");
}
export function canvasAgentPromptCacheKey(sessionId: string) {
const value = sessionId.trim();
return value ? clampOpenAIPromptCacheKey(`canvas-agent:${value}`) : undefined;
}
export function withOpenAIPromptCacheKey<T extends Record<string, unknown>>(body: T, value?: string): T & { prompt_cache_key?: string } {
const key = clampOpenAIPromptCacheKey(value);
return key ? { ...body, prompt_cache_key: key } : body;
}