diff --git a/server/modules/openclaw/PatternDetector.ts b/server/modules/openclaw/PatternDetector.ts index ecf57f6..37e2169 100644 --- a/server/modules/openclaw/PatternDetector.ts +++ b/server/modules/openclaw/PatternDetector.ts @@ -8,8 +8,8 @@ * Fase 4: OpenClaw Embutido */ -import { db } from "@/db"; -import { detectedPatterns, skillSuggestions } from "@/shared/schema"; +import { db } from "../../../db"; +import { detectedPatterns, skillSuggestions } from "../../../shared/schema"; import { eq, and, gte } from "drizzle-orm"; import { EventEmitter } from "events"; diff --git a/server/modules/openclaw/SkillEmergence.ts b/server/modules/openclaw/SkillEmergence.ts index 954fefc..b4ffdf9 100644 --- a/server/modules/openclaw/SkillEmergence.ts +++ b/server/modules/openclaw/SkillEmergence.ts @@ -7,9 +7,8 @@ * Fase 4: OpenClaw Embutido */ -import { db } from "@/db"; -import { skills } from "@/shared/schema"; -import axios, { AxiosError } from "axios"; +import { db } from "../../../db"; +import { skills } from "../../../shared/schema"; interface SkillSuggestion { id: string; @@ -155,45 +154,48 @@ Código: */ private async callBlackboard(prompt: string, suggestion: SkillSuggestion): Promise { try { - const response = await axios.post( + const controller = new AbortController(); + const timeout = setTimeout(() => controller.abort(), 30000); + + const response = await fetch( `${this.blackboardUrl}/generate-skill`, { - prompt, - skill_name: suggestion.suggested_skill_name, - context: { - pattern_type: suggestion.pattern.action_type, - confidence: suggestion.confidence, - metadata: suggestion.pattern.metadata, - }, - }, - { + method: "POST", headers: { "Content-Type": "application/json", "X-API-Key": this.apiKey, }, - timeout: 30000, // 30 segundos timeout + body: JSON.stringify({ + prompt, + skill_name: suggestion.suggested_skill_name, + context: { + pattern_type: suggestion.pattern.action_type, + confidence: suggestion.confidence, + metadata: suggestion.pattern.metadata, + }, + }), + signal: controller.signal, } ); + clearTimeout(timeout); + + const data = await response.json() as any; console.log("[SkillEmergence] Resposta do Blackboard recebida"); return { success: true, - code: response.data.code, - language: response.data.language || "typescript", + code: data.code, + language: data.language || "typescript", }; } catch (error) { - const axiosError = error as AxiosError; + const err = error as Error; - console.error("[SkillEmergence] Erro ao chamar Blackboard:", { - status: axiosError.response?.status, - data: axiosError.response?.data, - message: axiosError.message, - }); + console.error("[SkillEmergence] Erro ao chamar Blackboard:", err.message); return { success: false, - error: axiosError.message, + error: err.message, }; } } diff --git a/server/openclaw/pattern-detector.ts b/server/openclaw/pattern-detector.ts index 7fe6c14..e7e15c0 100644 --- a/server/openclaw/pattern-detector.ts +++ b/server/openclaw/pattern-detector.ts @@ -11,7 +11,7 @@ import crypto from "crypto"; import OpenAI from "openai"; import { db } from "../../db/index"; import { - arcadiaSkills, + skills as arcadiaSkills, skillExecutions, detectedPatterns, skillSuggestions, diff --git a/server/openclaw/routes.ts b/server/openclaw/routes.ts index 07a3a8f..8e8b879 100644 --- a/server/openclaw/routes.ts +++ b/server/openclaw/routes.ts @@ -9,7 +9,7 @@ import type { Express, Request, Response } from "express"; import { db } from "../../db/index"; -import { arcadiaSkills, detectedPatterns, skillSuggestions } from "@shared/schema"; +import { skills as arcadiaSkills, detectedPatterns, skillSuggestions } from "@shared/schema"; import { eq, and, desc } from "drizzle-orm"; export function registerOpenClawRoutes(app: Express): void { diff --git a/server/skills/routes.ts b/server/skills/routes.ts index 2478abf..f9a826f 100644 --- a/server/skills/routes.ts +++ b/server/skills/routes.ts @@ -111,3 +111,7 @@ router.get("/:id/executions", async (req, res) => { }); export default router; + +export function registerSkillRoutes(app: any): void { + app.use("/api/skills", router); +}