mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 08:59:16 +00:00
feat: enhance Claude Code client detection with similarity matching
- Add string-similarity library for robust prompt comparison - Extract Claude Code system prompts to separate contents module - Implement similarity-based validation with configurable thresholds - Support different validation logic for Haiku vs other Claude models - Fix validation to properly handle array format system prompts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
18
src/utils/text-similarity.js
Normal file
18
src/utils/text-similarity.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import stringSimilarity from 'string-similarity'
|
||||
|
||||
function normalize(value) {
|
||||
return value.replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
|
||||
export function simple(actual, expected, threshold) {
|
||||
if (typeof expected !== 'string' || !expected.trim()) {
|
||||
throw new Error('Expected prompt text must be a non-empty string')
|
||||
}
|
||||
|
||||
if (typeof actual !== 'string' || !actual.trim()) {
|
||||
return { score: 0, threshold, passed: false }
|
||||
}
|
||||
|
||||
const score = stringSimilarity.compareTwoStrings(normalize(actual), normalize(expected))
|
||||
return { score, threshold, passed: score >= threshold }
|
||||
}
|
||||
Reference in New Issue
Block a user