mirror of
https://github.com/johndoe6345789/low-code-react-app-b.git
synced 2026-05-06 11:29:35 +00:00
c7ebafe6a8
Error: src/components/FeatureIdeaCloud.tsx(920,37): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/components/PlaywrightDesigner.tsx(105,37): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/components/StorybookDesigner.tsx(115,37): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/components/TemplateExplorer.tsx(40,31): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/components/TemplateExplorer.tsx(44,32): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/components/UnitTestDesigner.tsx(138,37): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-data.ts(23,19): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-data.ts(30,33): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-data.ts(40,24): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-data.ts(63,19): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-data.ts(71,22): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-data.ts(86,19): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-data.ts(91,33): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-data.ts(95,22): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-templates.ts(87,22): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-templates.ts(102,33): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-templates.ts(104,22): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-templates.ts(126,43): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-templates.ts(129,24): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/data/use-seed-templates.ts(131,24): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/json-ui/use-data-sources.ts(25,40): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/json-ui/use-data-sources.ts(47,20): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/orchestration/use-actions.ts(119,31): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/use-component-tree-loader.ts(22,19): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/use-component-tree-loader.ts(27,42): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/use-component-tree-loader.ts(31,22): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/use-component-tree-loader.ts(43,24): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/use-component-tree-loader.ts(60,17): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/use-component-tree-loader.ts(65,32): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/use-component-tree-loader.ts(90,19): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/hooks/use-component-tree-loader.ts(94,20): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/project-service.ts(21,39): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/project-service.ts(61,18): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/project-service.ts(63,38): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/project-service.ts(66,20): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/project-service.ts(74,36): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/project-service.ts(83,18): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/project-service.ts(85,38): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/project-service.ts(87,18): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/protected-llm-service.ts(39,31): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(199,17): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(200,25): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(204,17): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(205,18): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(209,17): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(210,18): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(214,17): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(215,25): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(219,17): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(220,34): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(221,49): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: src/lib/unified-storage.ts(409,18): error TS2339: Property 'spark' does not exist on type 'Window & typeof globalThis'. Error: Process completed with exit code 2.
84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
/// <reference path="../global.d.ts" />
|
|
|
|
import { aiRateLimiter, scanRateLimiter } from './rate-limiter'
|
|
import { toast } from 'sonner'
|
|
|
|
interface LLMCallOptions {
|
|
model?: 'gpt-4o' | 'gpt-4o-mini'
|
|
jsonMode?: boolean
|
|
priority?: 'low' | 'medium' | 'high'
|
|
category?: string
|
|
}
|
|
|
|
export class ProtectedLLMService {
|
|
private static callCount = 0
|
|
private static errorCount = 0
|
|
private static readonly MAX_ERRORS_BEFORE_PAUSE = 5
|
|
|
|
static async safeLLMCall(
|
|
prompt: string,
|
|
options: LLMCallOptions = {}
|
|
): Promise<string | null> {
|
|
const {
|
|
model = 'gpt-4o',
|
|
jsonMode = false,
|
|
priority = 'medium',
|
|
category = 'general'
|
|
} = options
|
|
|
|
if (this.errorCount >= this.MAX_ERRORS_BEFORE_PAUSE) {
|
|
console.warn('Too many LLM errors detected. Pausing further calls.')
|
|
toast.error('AI service temporarily unavailable due to repeated errors')
|
|
return null
|
|
}
|
|
|
|
try {
|
|
const key = `llm-${category}`
|
|
const result = await aiRateLimiter.throttle(
|
|
key,
|
|
async () => {
|
|
this.callCount++
|
|
return await window.spark.llm(prompt, model, jsonMode)
|
|
},
|
|
priority
|
|
)
|
|
|
|
if (result) {
|
|
this.errorCount = Math.max(0, this.errorCount - 1)
|
|
}
|
|
|
|
return result
|
|
} catch (error) {
|
|
this.errorCount++
|
|
console.error(`LLM call failed (${category}):`, error)
|
|
|
|
if (error instanceof Error) {
|
|
if (error.message.includes('502') || error.message.includes('Bad Gateway')) {
|
|
toast.error('Service temporarily unavailable - please wait a moment')
|
|
} else if (error.message.includes('429') || error.message.includes('rate limit')) {
|
|
toast.error('Too many requests - please slow down')
|
|
} else {
|
|
toast.error('AI service error - please try again')
|
|
}
|
|
}
|
|
|
|
return null
|
|
}
|
|
}
|
|
|
|
static getStats() {
|
|
return {
|
|
totalCalls: this.callCount,
|
|
errorCount: this.errorCount,
|
|
isPaused: this.errorCount >= this.MAX_ERRORS_BEFORE_PAUSE
|
|
}
|
|
}
|
|
|
|
static reset() {
|
|
this.callCount = 0
|
|
this.errorCount = 0
|
|
aiRateLimiter.reset()
|
|
scanRateLimiter.reset()
|
|
}
|
|
}
|