diff --git a/scripts/run.ts b/scripts/run.ts index 6042442..f1572fc 100644 --- a/scripts/run.ts +++ b/scripts/run.ts @@ -81,6 +81,8 @@ async function main(): Promise { dryRun = true; } else if (arg.startsWith('--api-base=')) { process.env.API_BASE = arg.slice('--api-base='.length).trim(); + } else if (arg.startsWith('--session-id=')) { + process.env.SKILL_SESSION_ID = arg.slice('--session-id='.length).trim(); } else if (arg === '-h' || arg === '--help') { printUsage(); process.exit(0); } else { diff --git a/src/index.ts b/src/index.ts index c1de23e..2a92092 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ export interface VisionConfig { apiKey: string; baseURL?: string; model: string; + sessionId?: string; } async function loadVisionConfig(client: ReturnType): Promise { @@ -22,6 +23,7 @@ async function loadVisionConfig(client: ReturnType): P apiKey, baseURL: cfg.metadata?.provider?.base_url, model: process.env.VISION_MODEL ?? cfg.metadata?.provider?.model ?? 'aliyun-cp-multimodal', + sessionId: process.env.SKILL_SESSION_ID || `skill_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`, }; } @@ -415,7 +417,13 @@ function getFlag(args: string[], flag: string): string | undefined { } function createVisionModel(config: VisionConfig) { - const openai = createOpenAI({ apiKey: config.apiKey, baseURL: config.baseURL }); + const headers: Record = { + 'x-langfuse-tags': 'skill:video-product-snapshot', + }; + if (config.sessionId) { + headers['x-langfuse-session-id'] = config.sessionId; + } + const openai = createOpenAI({ apiKey: config.apiKey, baseURL: config.baseURL, headers }); return openai(config.model); } diff --git a/src/post-filter.ts b/src/post-filter.ts index 719a324..b87e8b0 100644 --- a/src/post-filter.ts +++ b/src/post-filter.ts @@ -34,7 +34,13 @@ const FILTER_PROMPT = (count: number, description?: string) => { }; function createModel(config: VisionConfig) { - const provider = createOpenAI({ apiKey: config.apiKey, baseURL: config.baseURL }); + const headers: Record = { + 'x-langfuse-tags': 'skill:video-product-snapshot', + }; + if (config.sessionId) { + headers['x-langfuse-session-id'] = config.sessionId; + } + const provider = createOpenAI({ apiKey: config.apiKey, baseURL: config.baseURL, headers }); return provider(config.model); } diff --git a/src/product-detector.ts b/src/product-detector.ts index cfebd44..1e971aa 100644 --- a/src/product-detector.ts +++ b/src/product-detector.ts @@ -78,7 +78,13 @@ Return: - boundingBox: tight box of the PRODUCT ONLY as [x1, y1, x2, y2] normalized 0.0–1.0, top-left origin. Exclude hands, background, and unrelated objects. The product is near the center of the frame.`; function createVisionModel(config: VisionConfig) { - const provider = createOpenAI({ apiKey: config.apiKey, baseURL: config.baseURL }); + const headers: Record = { + 'x-langfuse-tags': 'skill:video-product-snapshot', + }; + if (config.sessionId) { + headers['x-langfuse-session-id'] = config.sessionId; + } + const provider = createOpenAI({ apiKey: config.apiKey, baseURL: config.baseURL, headers }); return provider(config.model); }