(content: string, filePath?: string)
| 188 | } |
| 189 | |
| 190 | static detectWorkflow(content: string, filePath?: string): boolean { |
| 191 | // Two-pass detection: AST-based (accurate) → Direct LLM patterns (fallback) |
| 192 | |
| 193 | // Pass 1: AST-based detection (most accurate) |
| 194 | if (filePath) { |
| 195 | try { |
| 196 | const analysis = staticAnalyzer.analyze(content, filePath); |
| 197 | if (analysis.locations.length > 0 || analysis.llmRelatedVariables.size > 0) { |
| 198 | return true; |
| 199 | } |
| 200 | } catch (error) { |
| 201 | console.warn('AST parsing failed, falling back to regex:', error); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // Pass 2: Direct LLM usage detection (regex fallback) |
| 206 | const hasLLMClient = ALL_IMPORT_PATTERNS.some(pattern => pattern.test(content)); |
| 207 | const hasLLMCalls = ALL_CALL_PATTERNS.some(pattern => pattern.test(content)); |
| 208 | const hasFramework = LLM_FRAMEWORKS.some(f => f.importPatterns.some(p => p.test(content))); |
| 209 | |
| 210 | if ((hasLLMClient && hasLLMCalls) || hasFramework) { |
| 211 | return true; |
| 212 | } |
| 213 | |
| 214 | // Pass 3: AI Service API detection (non-LLM AI services using HTTP) |
| 215 | const hasAIServiceDomain = AI_SERVICE_DOMAINS.some(pattern => pattern.test(content)); |
| 216 | const hasAIEndpoint = AI_ENDPOINT_PATTERNS.some(pattern => pattern.test(content)); |
| 217 | |
| 218 | if (hasAIServiceDomain || hasAIEndpoint) { |
| 219 | return true; |
| 220 | } |
| 221 | |
| 222 | return false; |
| 223 | } |
| 224 | |
| 225 | static detectFramework(content: string): string | null { |
| 226 | // Check each provider's import patterns |
no test coverage detected