feat: 统一鉴权清理 + Langfuse session 追踪

- src/index.ts: VisionConfig 新增 sessionId,createVisionModel 注入 x-langfuse-session-id / x-langfuse-tags headers
- src/product-detector.ts: createVisionModel 同步注入 session headers
- src/post-filter.ts: createModel 同步注入 session headers
- scripts/run.ts: 支持 --session-id CLI 参数,fallback 自动生成
- 删除 VISION_API_KEY / VISION_API_BASE / ONEBOUND_* 死代码(统一由 auth-rt client-config 下发)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
ywkj 2026-04-26 18:35:55 +08:00
parent 6bc4e1d3b4
commit c7e14ca396
4 changed files with 25 additions and 3 deletions

View File

@ -81,6 +81,8 @@ async function main(): Promise<void> {
dryRun = true; dryRun = true;
} else if (arg.startsWith('--api-base=')) { } else if (arg.startsWith('--api-base=')) {
process.env.API_BASE = arg.slice('--api-base='.length).trim(); 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') { } else if (arg === '-h' || arg === '--help') {
printUsage(); process.exit(0); printUsage(); process.exit(0);
} else { } else {

View File

@ -12,6 +12,7 @@ export interface VisionConfig {
apiKey: string; apiKey: string;
baseURL?: string; baseURL?: string;
model: string; model: string;
sessionId?: string;
} }
async function loadVisionConfig(client: ReturnType<typeof createSkillClient>): Promise<VisionConfig> { async function loadVisionConfig(client: ReturnType<typeof createSkillClient>): Promise<VisionConfig> {
@ -22,6 +23,7 @@ async function loadVisionConfig(client: ReturnType<typeof createSkillClient>): P
apiKey, apiKey,
baseURL: cfg.metadata?.provider?.base_url, baseURL: cfg.metadata?.provider?.base_url,
model: process.env.VISION_MODEL ?? cfg.metadata?.provider?.model ?? 'aliyun-cp-multimodal', 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) { function createVisionModel(config: VisionConfig) {
const openai = createOpenAI({ apiKey: config.apiKey, baseURL: config.baseURL }); const headers: Record<string, string> = {
'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); return openai(config.model);
} }

View File

@ -34,7 +34,13 @@ const FILTER_PROMPT = (count: number, description?: string) => {
}; };
function createModel(config: VisionConfig) { function createModel(config: VisionConfig) {
const provider = createOpenAI({ apiKey: config.apiKey, baseURL: config.baseURL }); const headers: Record<string, string> = {
'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); return provider(config.model);
} }

View File

@ -78,7 +78,13 @@ Return:
- boundingBox: tight box of the PRODUCT ONLY as [x1, y1, x2, y2] normalized 0.01.0, top-left origin. Exclude hands, background, and unrelated objects. The product is near the center of the frame.`; - boundingBox: tight box of the PRODUCT ONLY as [x1, y1, x2, y2] normalized 0.01.0, top-left origin. Exclude hands, background, and unrelated objects. The product is near the center of the frame.`;
function createVisionModel(config: VisionConfig) { function createVisionModel(config: VisionConfig) {
const provider = createOpenAI({ apiKey: config.apiKey, baseURL: config.baseURL }); const headers: Record<string, string> = {
'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); return provider(config.model);
} }