@decido/plugin-chameleon 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/.turbo/turbo-build.log +13 -0
  2. package/package.json +47 -0
  3. package/src/App.tsx +116 -0
  4. package/src/components/DatawayDashboard.tsx +152 -0
  5. package/src/components/DatawayFilterModal.tsx +132 -0
  6. package/src/components/DatawayMathModal.tsx +120 -0
  7. package/src/components/DatawayOrchestratorCanvas.tsx +345 -0
  8. package/src/components/DatawayPipelineManager.tsx +227 -0
  9. package/src/components/DatawaySchemaMapper.tsx +291 -0
  10. package/src/components/FormulaBar.tsx +242 -0
  11. package/src/hooks/useSocketSync.ts +104 -0
  12. package/src/index.css +18 -0
  13. package/src/index.ts +121 -0
  14. package/src/logic/rules.ts +39 -0
  15. package/src/logic/workflowGuard.ts +45 -0
  16. package/src/main.tsx +10 -0
  17. package/src/services/gemini.ts +110 -0
  18. package/src/store/datawayStore.ts +26 -0
  19. package/src/stores/authStore.ts +26 -0
  20. package/src/stores/orderStore.ts +263 -0
  21. package/src/stores/uiStore.ts +19 -0
  22. package/src/types.ts +39 -0
  23. package/src/useAgent.ts +89 -0
  24. package/src/utils/sounds.ts +52 -0
  25. package/src/views/DatabaseAdminView.tsx +707 -0
  26. package/src/views/DatawayStudioView.tsx +959 -0
  27. package/src/views/DiscoveryAdminView.tsx +59 -0
  28. package/src/views/KuspideDashboardView.tsx +144 -0
  29. package/src/views/LoginView.tsx +122 -0
  30. package/src/views/MadefrontChatView.tsx +174 -0
  31. package/src/views/MadefrontExcelView.tsx +95 -0
  32. package/src/views/MadefrontKanbanView.tsx +292 -0
  33. package/src/views/roles/CajaView.tsx +76 -0
  34. package/src/views/roles/DespachoView.tsx +100 -0
  35. package/src/views/roles/PlantaView.tsx +83 -0
  36. package/src/views/roles/VentasView.tsx +101 -0
  37. package/src/views/roles/WorkflowAdminView.tsx +62 -0
  38. package/tsconfig.json +34 -0
package/src/types.ts ADDED
@@ -0,0 +1,39 @@
1
+ // 1. Vistas Disponibles en la App
2
+ export type ViewType = 'login' | 'madefront_chat' | 'madefront_kanban' | 'madefront_excel' | 'workflow_admin' | 'kuspide_dashboard' | 'discovery_admin' | 'database_admin' | 'dataway_studio';
3
+
4
+ // 2. Roles del Sistema (Los Cortex)
5
+ export type Role = 'NONE' | 'GERENCIA' | 'CAJA' | 'PLANTA' | 'DESPACHO';
6
+
7
+ // 3. Estados del Pedido (El Flujo)
8
+ export type OrderStatus = 'DISEÑO' | 'OPTIMIZACION' | 'CAJA' | 'PRODUCCION' | 'DESPACHO' | 'ENTREGADO';
9
+
10
+ // 4. Máquinas Disponibles
11
+ export type MachineType = 'SIGMA' | 'GABBIANI' | 'HOMAG' | 'PENDIENTE';
12
+
13
+ // 5. El Pedido Maestro
14
+ export interface MadefrontOrder {
15
+ id: string; // MF-2026-001
16
+ client: string;
17
+ whatsapp: string; // +57...
18
+ material: string; // Ej: Rh 15mm Blanco
19
+ measurements: string; // Texto o Link
20
+ sheets: number; // Cantidad de láminas (Para el SLA)
21
+
22
+ // Datos Calculados por el "Agente"
23
+ status: OrderStatus;
24
+ rawStage?: string;
25
+ machine: MachineType;
26
+ slaHours: number; // 24 o 72
27
+ createdAt: string; // ISO Date
28
+ isUrgent?: boolean; // Bandera de prioridad
29
+
30
+ // Trazabilidad
31
+ isPaid: boolean; // Bloqueo de Caja
32
+ logs: string[]; // Historial de cambios
33
+ }
34
+
35
+ export interface AgentCommand {
36
+ action: 'CHANGE_VIEW' | 'SEARCH_ORDER' | 'UPDATE_STATUS' | 'UNKNOWN';
37
+ payload?: any;
38
+ message?: string;
39
+ }
@@ -0,0 +1,89 @@
1
+ import { useState, useCallback, useRef } from 'react';
2
+ import { AgentCommand } from './types';
3
+
4
+ export function useAgent(onCommand: (command: AgentCommand) => void) {
5
+ const [isListening, setIsListening] = useState(false);
6
+ const [transcript, setTranscript] = useState('');
7
+ const [isProcessing, setIsProcessing] = useState(false);
8
+ const recognitionRef = useRef<any>(null);
9
+
10
+ const processInput = useCallback(async (text: string) => {
11
+ setIsProcessing(true);
12
+ try {
13
+ const baseUrl = (import.meta as any).env?.VITE_API_BASE_URL || 'http://localhost:3001';
14
+ const response = await fetch(`${baseUrl}/api/copilot/ask`, {
15
+ method: 'POST',
16
+ headers: {
17
+ 'Content-Type': 'application/json',
18
+ 'x-api-key': 'dev_ak_chameleon_studio_99x'
19
+ },
20
+ body: JSON.stringify({ message: text })
21
+ });
22
+
23
+ if (!response.ok) {
24
+ throw new Error(`Failed to process input: ${response.statusText}`);
25
+ }
26
+
27
+ const commandString = await response.text();
28
+ const command = JSON.parse(commandString) as AgentCommand;
29
+
30
+ onCommand(command);
31
+ } catch (error) {
32
+ console.error("Error processing input with Backend Copilot:", error);
33
+ onCommand({ action: 'UNKNOWN', message: 'Lo siento, tuve problemas para procesar eso con el servidor.' });
34
+ } finally {
35
+ setIsProcessing(false);
36
+ }
37
+ }, [onCommand]);
38
+
39
+ const startListening = useCallback(() => {
40
+ if (!('webkitSpeechRecognition' in window) && !('SpeechRecognition' in window)) {
41
+ alert("Speech recognition is not supported in this browser.");
42
+ return;
43
+ }
44
+
45
+ const SpeechRecognition = (window as any).SpeechRecognition || (window as any).webkitSpeechRecognition;
46
+ const recognition = new SpeechRecognition();
47
+ recognition.lang = 'es-ES'; // Spanish as requested by user
48
+ recognition.interimResults = false;
49
+ recognition.maxAlternatives = 1;
50
+
51
+ recognition.onstart = () => {
52
+ setIsListening(true);
53
+ setTranscript('');
54
+ };
55
+
56
+ recognition.onresult = (event: any) => {
57
+ const speechResult = event.results[0][0].transcript;
58
+ setTranscript(speechResult);
59
+ processInput(speechResult);
60
+ };
61
+
62
+ recognition.onerror = (event: any) => {
63
+ console.error("Speech recognition error", event.error);
64
+ setIsListening(false);
65
+ };
66
+
67
+ recognition.onend = () => {
68
+ setIsListening(false);
69
+ };
70
+
71
+ recognitionRef.current = recognition;
72
+ recognition.start();
73
+ }, [processInput]);
74
+
75
+ const stopListening = useCallback(() => {
76
+ if (recognitionRef.current) {
77
+ recognitionRef.current.stop();
78
+ }
79
+ }, []);
80
+
81
+ return {
82
+ isListening,
83
+ isProcessing,
84
+ transcript,
85
+ startListening,
86
+ stopListening,
87
+ processInput
88
+ };
89
+ }
@@ -0,0 +1,52 @@
1
+ export const playUISound = (type: 'pop' | 'swoosh' | 'success' | 'error') => {
2
+ try {
3
+ const AudioContextClass = window.AudioContext || (window as any).webkitAudioContext;
4
+ if (!AudioContextClass) return;
5
+
6
+ const ctx = new AudioContextClass();
7
+ const osc = ctx.createOscillator();
8
+ const gain = ctx.createGain();
9
+
10
+ osc.connect(gain);
11
+ gain.connect(ctx.destination);
12
+
13
+ const now = ctx.currentTime;
14
+
15
+ if (type === 'pop') {
16
+ osc.type = 'sine';
17
+ osc.frequency.setValueAtTime(400, now);
18
+ osc.frequency.exponentialRampToValueAtTime(600, now + 0.1);
19
+ gain.gain.setValueAtTime(0.1, now);
20
+ gain.gain.exponentialRampToValueAtTime(0.01, now + 0.1);
21
+ osc.start(now);
22
+ osc.stop(now + 0.1);
23
+ } else if (type === 'swoosh') {
24
+ osc.type = 'triangle';
25
+ osc.frequency.setValueAtTime(150, now);
26
+ osc.frequency.exponentialRampToValueAtTime(300, now + 0.25);
27
+ gain.gain.setValueAtTime(0.05, now);
28
+ gain.gain.exponentialRampToValueAtTime(0.01, now + 0.25);
29
+ osc.start(now);
30
+ osc.stop(now + 0.25);
31
+ } else if (type === 'success') {
32
+ osc.type = 'sine';
33
+ osc.frequency.setValueAtTime(440, now); // A4
34
+ osc.frequency.setValueAtTime(554.37, now + 0.1); // C#5
35
+ gain.gain.setValueAtTime(0.1, now);
36
+ gain.gain.setValueAtTime(0.1, now + 0.1);
37
+ gain.gain.linearRampToValueAtTime(0, now + 0.3);
38
+ osc.start(now);
39
+ osc.stop(now + 0.3);
40
+ } else if (type === 'error') {
41
+ osc.type = 'sawtooth';
42
+ osc.frequency.setValueAtTime(200, now);
43
+ osc.frequency.exponentialRampToValueAtTime(100, now + 0.2);
44
+ gain.gain.setValueAtTime(0.1, now);
45
+ gain.gain.linearRampToValueAtTime(0, now + 0.2);
46
+ osc.start(now);
47
+ osc.stop(now + 0.2);
48
+ }
49
+ } catch (e) {
50
+ console.error("Audio playback failed", e);
51
+ }
52
+ };