claude-gemini-multimodal-bridge
Version:
Enterprise-grade AI integration bridge connecting Claude Code, Gemini CLI, and Google AI Studio with intelligent routing and advanced multimodal processing capabilities
107 lines (106 loc) • 4.78 kB
JavaScript
import { logger } from '../utils/logger.js';
export class IntelligentRouter {
static shouldDisableSearch(prompt) {
const lowerCasePrompt = prompt.toLowerCase().trim();
const nonSearchPatterns = [
/^(summarize|要約|まとめ).*(this|これ|この)/,
/^(translate|翻訳|訳).*(following|以下|次の)/,
/^(format|整形|フォーマット).*(document|文書|ドキュメント)/,
/^(explain|説明|解説).*(code|コード|プログラム)/,
/^(analyze|分析|解析).*(attached|添付|provided|提供)/,
/^(review|レビュー|確認).*(document|文書|file|ファイル)/,
/^(check|チェック|確認).*(grammar|文法|syntax|構文)/,
/^(hello|hi|こんにちは|はじめまして)/,
/^(thanks|thank you|ありがとう|感謝)/,
/^(help|ヘルプ|助け|手伝)/,
/^(calculate|計算|compute|算出)/,
/^(solve|解く|解決).*(equation|方程式|problem|問題)/
];
const shouldDisable = nonSearchPatterns.some(pattern => pattern.test(lowerCasePrompt));
if (shouldDisable) {
logger.debug('IntelligentRouter: High confidence - disabling search', {
prompt: prompt.substring(0, 50) + '...',
reason: 'Matched non-search pattern'
});
}
return shouldDisable;
}
static shouldEnableSearch(prompt) {
const lowerCasePrompt = prompt.toLowerCase();
const temporalKeywords = [
'latest', 'current', 'recent', 'today', 'yesterday', 'this week', 'this month',
'this year', 'now', 'currently', 'breaking', 'update', 'news', 'trend',
'最新', '現在', '今', '今日', '昨日', '今週', '今月', '今年', '最近',
'トレンド', 'ニュース', '更新', '動向', '状況',
'最新', '当前', '现在', '今天', '昨天', '本周', '本月', '今年', '最近', '趋势'
];
const yearPattern = /20[2-3][0-9]/;
const questionWords = ['what', 'who', 'when', 'where', 'how', 'why', '何', 'いつ', 'どこ', 'なぜ', 'どう'];
const hasTemporalKeywords = temporalKeywords.some(keyword => lowerCasePrompt.includes(keyword));
const hasYearMention = yearPattern.test(prompt);
const hasQuestionWords = questionWords.some(word => lowerCasePrompt.includes(word));
const webIndicators = ['stock price', 'weather', 'stock market', '株価', '天気', '市場', '价格', '天气'];
const hasWebIndicators = webIndicators.some(indicator => lowerCasePrompt.includes(indicator));
const shouldEnable = hasTemporalKeywords || hasYearMention || hasWebIndicators ||
(hasQuestionWords && prompt.length > 20);
if (shouldEnable) {
logger.debug('IntelligentRouter: High confidence - enabling search', {
prompt: prompt.substring(0, 50) + '...',
reasons: {
hasTemporalKeywords,
hasYearMention,
hasWebIndicators,
hasQuestionWords: hasQuestionWords && prompt.length > 20
}
});
}
return shouldEnable;
}
static determineSearchStrategy(prompt) {
if (this.shouldDisableSearch(prompt)) {
return false;
}
if (this.shouldEnableSearch(prompt)) {
return true;
}
logger.debug('IntelligentRouter: Ambiguous case - using default search strategy', {
prompt: prompt.substring(0, 50) + '...'
});
return null;
}
static getRoutingStats() {
return {
totalAnalyzed: 0,
searchEnabled: 0,
searchDisabled: 0,
ambiguous: 0
};
}
static validatePrompt(prompt) {
return typeof prompt === 'string' && prompt.trim().length > 0;
}
static routeByTaskType(taskType, prompt) {
switch (taskType) {
case 'document_analysis':
case 'code_review':
case 'translation':
case 'summarization':
return false;
case 'research':
case 'fact_checking':
case 'current_events':
case 'market_analysis':
return true;
case 'text_processing':
default:
const result = this.determineSearchStrategy(prompt);
return result !== null ? result : true;
}
}
}
export class LLMBasedRouter {
async shouldUseSearch(prompt) {
const result = IntelligentRouter.determineSearchStrategy(prompt);
return result !== null ? result : true;
}
}