apteva 0.4.57 → 0.7.1

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 (142) hide show
  1. package/README.md +216 -54
  2. package/cli.js +35 -0
  3. package/install.js +92 -0
  4. package/package.json +15 -76
  5. package/LICENSE +0 -63
  6. package/bin/apteva.js +0 -196
  7. package/dist/ActivityPage.kxzzb4yc.js +0 -3
  8. package/dist/ApiDocsPage.zq998hbm.js +0 -4
  9. package/dist/App.55rea8mn.js +0 -61
  10. package/dist/App.5ywb23z4.js +0 -53
  11. package/dist/App.6thds120.js +0 -4
  12. package/dist/App.9tctxzqm.js +0 -8
  13. package/dist/App.a8r8ttaz.js +0 -4
  14. package/dist/App.agsv5bje.js +0 -4
  15. package/dist/App.cepapqmx.js +0 -4
  16. package/dist/App.dp041gb3.js +0 -221
  17. package/dist/App.fds72zb5.js +0 -4
  18. package/dist/App.fg9qj2dq.js +0 -4
  19. package/dist/App.ndfejbm9.js +0 -4
  20. package/dist/App.nxmfmq1h.js +0 -13
  21. package/dist/App.qdfyt8ba.js +0 -4
  22. package/dist/App.x2d0ygt6.js +0 -4
  23. package/dist/App.yt9p4nr3.js +0 -20
  24. package/dist/App.zn4mw16t.js +0 -1
  25. package/dist/ConnectionsPage.8r96ryw7.js +0 -3
  26. package/dist/McpPage.3cwh0gnd.js +0 -3
  27. package/dist/SettingsPage.ykgdh5ev.js +0 -3
  28. package/dist/SkillsPage.4np1s65b.js +0 -3
  29. package/dist/TasksPage.4g08t7p6.js +0 -3
  30. package/dist/TelemetryPage.72w9pwcp.js +0 -3
  31. package/dist/TestsPage.z4fk3r7r.js +0 -3
  32. package/dist/ThreadsPage.63tcajeh.js +0 -3
  33. package/dist/apteva-kit.css +0 -1
  34. package/dist/icon.png +0 -0
  35. package/dist/index.html +0 -16
  36. package/dist/styles.css +0 -1
  37. package/scripts/postinstall.mjs +0 -102
  38. package/src/auth/index.ts +0 -394
  39. package/src/auth/middleware.ts +0 -213
  40. package/src/binary.ts +0 -536
  41. package/src/channels/index.ts +0 -40
  42. package/src/channels/telegram.ts +0 -311
  43. package/src/crypto.ts +0 -301
  44. package/src/db-tests.ts +0 -174
  45. package/src/db.ts +0 -3133
  46. package/src/integrations/agentdojo.ts +0 -559
  47. package/src/integrations/composio.ts +0 -437
  48. package/src/integrations/index.ts +0 -87
  49. package/src/integrations/skillsmp.ts +0 -318
  50. package/src/mcp-client.ts +0 -605
  51. package/src/mcp-handler.ts +0 -394
  52. package/src/mcp-platform.ts +0 -2403
  53. package/src/openapi.ts +0 -2410
  54. package/src/providers.ts +0 -597
  55. package/src/routes/api/agent-utils.ts +0 -890
  56. package/src/routes/api/agents.ts +0 -916
  57. package/src/routes/api/api-keys.ts +0 -95
  58. package/src/routes/api/channels.ts +0 -182
  59. package/src/routes/api/helpers.ts +0 -12
  60. package/src/routes/api/integrations.ts +0 -639
  61. package/src/routes/api/mcp.ts +0 -574
  62. package/src/routes/api/meta-agent.ts +0 -195
  63. package/src/routes/api/projects.ts +0 -112
  64. package/src/routes/api/providers.ts +0 -424
  65. package/src/routes/api/skills.ts +0 -537
  66. package/src/routes/api/system.ts +0 -333
  67. package/src/routes/api/telemetry.ts +0 -203
  68. package/src/routes/api/tests.ts +0 -148
  69. package/src/routes/api/triggers.ts +0 -518
  70. package/src/routes/api/users.ts +0 -148
  71. package/src/routes/api/webhooks.ts +0 -171
  72. package/src/routes/api.ts +0 -53
  73. package/src/routes/auth.ts +0 -251
  74. package/src/routes/share.ts +0 -86
  75. package/src/routes/static.ts +0 -131
  76. package/src/server.ts +0 -642
  77. package/src/test-runner.ts +0 -598
  78. package/src/triggers/agentdojo.ts +0 -253
  79. package/src/triggers/composio.ts +0 -264
  80. package/src/triggers/index.ts +0 -71
  81. package/src/tui/AgentList.tsx +0 -145
  82. package/src/tui/App.tsx +0 -102
  83. package/src/tui/Login.tsx +0 -104
  84. package/src/tui/api.ts +0 -72
  85. package/src/tui/index.tsx +0 -7
  86. package/src/web/App.tsx +0 -455
  87. package/src/web/components/activity/ActivityPage.tsx +0 -314
  88. package/src/web/components/activity/index.ts +0 -1
  89. package/src/web/components/agents/AgentCard.tsx +0 -189
  90. package/src/web/components/agents/AgentPanel.tsx +0 -2244
  91. package/src/web/components/agents/AgentsView.tsx +0 -180
  92. package/src/web/components/agents/CreateAgentModal.tsx +0 -475
  93. package/src/web/components/agents/index.ts +0 -4
  94. package/src/web/components/api/ApiDocsPage.tsx +0 -842
  95. package/src/web/components/auth/CreateAccountStep.tsx +0 -176
  96. package/src/web/components/auth/LoginPage.tsx +0 -91
  97. package/src/web/components/auth/index.ts +0 -2
  98. package/src/web/components/common/Icons.tsx +0 -250
  99. package/src/web/components/common/LoadingSpinner.tsx +0 -44
  100. package/src/web/components/common/Modal.tsx +0 -199
  101. package/src/web/components/common/Select.tsx +0 -97
  102. package/src/web/components/common/index.ts +0 -20
  103. package/src/web/components/connections/ConnectionsPage.tsx +0 -54
  104. package/src/web/components/connections/IntegrationsTab.tsx +0 -170
  105. package/src/web/components/connections/OverviewTab.tsx +0 -137
  106. package/src/web/components/connections/TriggersTab.tsx +0 -1346
  107. package/src/web/components/dashboard/Dashboard.tsx +0 -572
  108. package/src/web/components/dashboard/index.ts +0 -1
  109. package/src/web/components/index.ts +0 -21
  110. package/src/web/components/layout/ErrorBanner.tsx +0 -18
  111. package/src/web/components/layout/Header.tsx +0 -332
  112. package/src/web/components/layout/Sidebar.tsx +0 -231
  113. package/src/web/components/layout/index.ts +0 -3
  114. package/src/web/components/mcp/IntegrationsPanel.tsx +0 -857
  115. package/src/web/components/mcp/McpPage.tsx +0 -2515
  116. package/src/web/components/mcp/index.ts +0 -1
  117. package/src/web/components/meta-agent/MetaAgent.tsx +0 -245
  118. package/src/web/components/onboarding/OnboardingWizard.tsx +0 -404
  119. package/src/web/components/onboarding/index.ts +0 -1
  120. package/src/web/components/settings/SettingsPage.tsx +0 -2776
  121. package/src/web/components/settings/index.ts +0 -1
  122. package/src/web/components/skills/SkillsPage.tsx +0 -1200
  123. package/src/web/components/tasks/TasksPage.tsx +0 -1116
  124. package/src/web/components/tasks/index.ts +0 -1
  125. package/src/web/components/telemetry/TelemetryPage.tsx +0 -1129
  126. package/src/web/components/tests/TestsPage.tsx +0 -594
  127. package/src/web/components/threads/ThreadsPage.tsx +0 -315
  128. package/src/web/context/AuthContext.tsx +0 -242
  129. package/src/web/context/ProjectContext.tsx +0 -214
  130. package/src/web/context/TelemetryContext.tsx +0 -299
  131. package/src/web/context/ThemeContext.tsx +0 -90
  132. package/src/web/context/UIModeContext.tsx +0 -49
  133. package/src/web/context/index.ts +0 -12
  134. package/src/web/hooks/index.ts +0 -3
  135. package/src/web/hooks/useAgents.ts +0 -115
  136. package/src/web/hooks/useOnboarding.ts +0 -20
  137. package/src/web/hooks/useProviders.ts +0 -75
  138. package/src/web/icon.png +0 -0
  139. package/src/web/index.html +0 -16
  140. package/src/web/styles.css +0 -118
  141. package/src/web/themes.ts +0 -162
  142. package/src/web/types.ts +0 -298
@@ -1,214 +0,0 @@
1
- import React, { createContext, useContext, useState, useEffect, useCallback, useMemo, type ReactNode } from "react";
2
- import { useAuth } from "./AuthContext";
3
-
4
- export interface Project {
5
- id: string;
6
- name: string;
7
- description: string | null;
8
- color: string;
9
- agentCount: number;
10
- createdAt: string;
11
- updatedAt: string;
12
- }
13
-
14
- interface ProjectContextValue {
15
- projects: Project[];
16
- currentProjectId: string | null; // null = "All Projects", "unassigned" = unassigned agents
17
- currentProject: Project | null;
18
- isLoading: boolean;
19
- error: string | null;
20
- unassignedCount: number;
21
- projectsEnabled: boolean; // Feature flag
22
- metaAgentEnabled: boolean; // Feature flag
23
- costTrackingEnabled: boolean; // Feature flag
24
- setCurrentProjectId: (id: string | null) => void;
25
- createProject: (data: { name: string; description?: string; color?: string }) => Promise<Project | null>;
26
- updateProject: (id: string, data: { name?: string; description?: string; color?: string }) => Promise<Project | null>;
27
- deleteProject: (id: string) => Promise<boolean>;
28
- refreshProjects: () => Promise<void>;
29
- }
30
-
31
- const ProjectContext = createContext<ProjectContextValue | null>(null);
32
-
33
- export function useProjects(): ProjectContextValue {
34
- const context = useContext(ProjectContext);
35
- if (!context) {
36
- throw new Error("useProjects must be used within a ProjectProvider");
37
- }
38
- return context;
39
- }
40
-
41
- interface ProjectProviderProps {
42
- children: ReactNode;
43
- }
44
-
45
- const STORAGE_KEY = "apteva_current_project";
46
-
47
- export function ProjectProvider({ children }: ProjectProviderProps) {
48
- const { authFetch, isAuthenticated, isLoading: authLoading } = useAuth();
49
- const [projects, setProjects] = useState<Project[]>([]);
50
- const [currentProjectId, setCurrentProjectIdState] = useState<string | null>(() => {
51
- // Load from localStorage
52
- if (typeof window !== "undefined") {
53
- return localStorage.getItem(STORAGE_KEY);
54
- }
55
- return null;
56
- });
57
- const [isLoading, setIsLoading] = useState(true);
58
- const [error, setError] = useState<string | null>(null);
59
- const [unassignedCount, setUnassignedCount] = useState(0);
60
- const [projectsEnabled, setProjectsEnabled] = useState(false);
61
- const [metaAgentEnabled, setMetaAgentEnabled] = useState(false);
62
- const [costTrackingEnabled, setCostTrackingEnabled] = useState(true);
63
-
64
- // Fetch feature flags on mount
65
- useEffect(() => {
66
- fetch("/api/features")
67
- .then(res => res.json())
68
- .then(data => {
69
- setProjectsEnabled(data.projects === true);
70
- setMetaAgentEnabled(data.metaAgent === true);
71
- setCostTrackingEnabled(data.costTracking !== false);
72
- })
73
- .catch(() => {
74
- setProjectsEnabled(false);
75
- setMetaAgentEnabled(false);
76
- setCostTrackingEnabled(true);
77
- });
78
- }, []);
79
-
80
- const setCurrentProjectId = useCallback((id: string | null) => {
81
- setCurrentProjectIdState(id);
82
- if (typeof window !== "undefined") {
83
- if (id === null) {
84
- localStorage.removeItem(STORAGE_KEY);
85
- } else {
86
- localStorage.setItem(STORAGE_KEY, id);
87
- }
88
- }
89
- }, []);
90
-
91
- const currentProject = projects.find(p => p.id === currentProjectId) || null;
92
-
93
- const refreshProjects = useCallback(async () => {
94
- // Don't fetch if projects feature is disabled
95
- if (!projectsEnabled) {
96
- setProjects([]);
97
- setIsLoading(false);
98
- return;
99
- }
100
-
101
- if (!isAuthenticated && !authLoading) {
102
- setProjects([]);
103
- setIsLoading(false);
104
- return;
105
- }
106
-
107
- try {
108
- setError(null);
109
- const res = await authFetch("/api/projects");
110
- if (!res.ok) {
111
- throw new Error("Failed to fetch projects");
112
- }
113
- const data = await res.json();
114
- setProjects(data.projects || []);
115
- setUnassignedCount(data.unassignedCount || 0);
116
-
117
- // If current project no longer exists, reset to all
118
- if (currentProjectId && currentProjectId !== "unassigned" && !data.projects.find((p: Project) => p.id === currentProjectId)) {
119
- setCurrentProjectId(null);
120
- }
121
- } catch (e) {
122
- console.error("Failed to fetch projects:", e);
123
- setError("Failed to load projects");
124
- } finally {
125
- setIsLoading(false);
126
- }
127
- }, [authFetch, isAuthenticated, authLoading, currentProjectId, setCurrentProjectId, projectsEnabled]);
128
-
129
- const createProject = useCallback(async (data: { name: string; description?: string; color?: string }): Promise<Project | null> => {
130
- try {
131
- const res = await authFetch("/api/projects", {
132
- method: "POST",
133
- headers: { "Content-Type": "application/json" },
134
- body: JSON.stringify(data),
135
- });
136
- if (!res.ok) {
137
- const err = await res.json();
138
- throw new Error(err.error || "Failed to create project");
139
- }
140
- const result = await res.json();
141
- await refreshProjects();
142
- return result.project;
143
- } catch (e) {
144
- console.error("Failed to create project:", e);
145
- return null;
146
- }
147
- }, [authFetch, refreshProjects]);
148
-
149
- const updateProject = useCallback(async (id: string, data: { name?: string; description?: string; color?: string }): Promise<Project | null> => {
150
- try {
151
- const res = await authFetch(`/api/projects/${id}`, {
152
- method: "PUT",
153
- headers: { "Content-Type": "application/json" },
154
- body: JSON.stringify(data),
155
- });
156
- if (!res.ok) {
157
- const err = await res.json();
158
- throw new Error(err.error || "Failed to update project");
159
- }
160
- const result = await res.json();
161
- await refreshProjects();
162
- return result.project;
163
- } catch (e) {
164
- console.error("Failed to update project:", e);
165
- return null;
166
- }
167
- }, [authFetch, refreshProjects]);
168
-
169
- const deleteProject = useCallback(async (id: string): Promise<boolean> => {
170
- try {
171
- const res = await authFetch(`/api/projects/${id}`, {
172
- method: "DELETE",
173
- });
174
- if (!res.ok) {
175
- const err = await res.json();
176
- throw new Error(err.error || "Failed to delete project");
177
- }
178
- if (currentProjectId === id) {
179
- setCurrentProjectId(null);
180
- }
181
- await refreshProjects();
182
- return true;
183
- } catch (e) {
184
- console.error("Failed to delete project:", e);
185
- return false;
186
- }
187
- }, [authFetch, currentProjectId, setCurrentProjectId, refreshProjects]);
188
-
189
- // Fetch projects when authenticated and feature is enabled
190
- useEffect(() => {
191
- if (!authLoading && projectsEnabled) {
192
- refreshProjects();
193
- }
194
- }, [authLoading, projectsEnabled, refreshProjects]);
195
-
196
- const value = useMemo<ProjectContextValue>(() => ({
197
- projects,
198
- currentProjectId,
199
- currentProject,
200
- isLoading,
201
- error,
202
- unassignedCount,
203
- projectsEnabled,
204
- metaAgentEnabled,
205
- costTrackingEnabled,
206
- setCurrentProjectId,
207
- createProject,
208
- updateProject,
209
- deleteProject,
210
- refreshProjects,
211
- }), [projects, currentProjectId, currentProject, isLoading, error, unassignedCount, projectsEnabled, metaAgentEnabled, costTrackingEnabled, setCurrentProjectId, createProject, updateProject, deleteProject, refreshProjects]);
212
-
213
- return <ProjectContext.Provider value={value}>{children}</ProjectContext.Provider>;
214
- }
@@ -1,299 +0,0 @@
1
- import React, { createContext, useContext, useEffect, useState, useCallback, useRef, useMemo } from "react";
2
-
3
- export interface TelemetryEvent {
4
- id: string;
5
- agent_id: string;
6
- timestamp: string;
7
- category: string;
8
- type: string;
9
- level: string;
10
- trace_id?: string;
11
- thread_id?: string;
12
- data?: Record<string, unknown>;
13
- duration_ms?: number;
14
- error?: string;
15
- cost?: number;
16
- _receivedAt?: number; // Client-side timestamp when event was received via SSE
17
- }
18
-
19
- interface TelemetryContextValue {
20
- connected: boolean;
21
- events: TelemetryEvent[];
22
- lastActivityByAgent: Record<string, { timestamp: string; category: string; type: string }>;
23
- activeAgents: Record<string, { type: string; expiresAt: number }>;
24
- statusChangeCounter: number;
25
- taskChangeCounter: number;
26
- notificationCounter: number;
27
- clearEvents: () => void;
28
- triggerRefresh: () => void;
29
- }
30
-
31
- const TelemetryContext = createContext<TelemetryContextValue | null>(null);
32
-
33
- const MAX_EVENTS = 200; // Keep last 200 events in memory
34
-
35
- export function TelemetryProvider({ children }: { children: React.ReactNode }) {
36
- const [connected, setConnected] = useState(false);
37
- const [events, setEvents] = useState<TelemetryEvent[]>([]);
38
- const [lastActivityByAgent, setLastActivityByAgent] = useState<Record<string, { timestamp: string; category: string; type: string }>>({});
39
- const [activeAgents, setActiveAgents] = useState<Record<string, { type: string; expiresAt: number }>>({});
40
- const [statusChangeCounter, setStatusChangeCounter] = useState(0);
41
- const [taskChangeCounter, setTaskChangeCounter] = useState(0);
42
- const [notificationCounter, setNotificationCounter] = useState(0);
43
- const eventSourceRef = useRef<EventSource | null>(null);
44
- const reconnectTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
45
-
46
- // Clean up expired active states
47
- useEffect(() => {
48
- const interval = setInterval(() => {
49
- const now = Date.now();
50
- setActiveAgents(prev => {
51
- const updated: Record<string, { type: string; expiresAt: number }> = {};
52
- for (const [agentId, state] of Object.entries(prev)) {
53
- if (state.expiresAt > now) {
54
- updated[agentId] = state;
55
- }
56
- }
57
- return updated;
58
- });
59
- }, 500);
60
- return () => clearInterval(interval);
61
- }, []);
62
-
63
- const connect = useCallback(() => {
64
- if (eventSourceRef.current) {
65
- eventSourceRef.current.close();
66
- eventSourceRef.current = null;
67
- }
68
-
69
- try {
70
- const es = new EventSource("/api/telemetry/stream");
71
- eventSourceRef.current = es;
72
-
73
- es.onopen = () => {
74
- setConnected(true);
75
- };
76
-
77
- es.onmessage = (event) => {
78
- // Ignore keepalive pings (comments starting with :)
79
- if (!event.data || event.data.trim() === "") return;
80
-
81
- try {
82
- const data = JSON.parse(event.data);
83
-
84
- // Handle connection message
85
- if (data.connected) {
86
- setConnected(true);
87
- return;
88
- }
89
-
90
- // Handle array of events
91
- if (Array.isArray(data)) {
92
- const now = Date.now();
93
- const stamped = data.map((e: TelemetryEvent) => ({ ...e, _receivedAt: now }));
94
- setEvents(prev => {
95
- const combined = [...stamped, ...prev];
96
- return combined.slice(0, MAX_EVENTS);
97
- });
98
-
99
- // Update last activity per agent
100
- setLastActivityByAgent(prev => {
101
- const updated = { ...prev };
102
- for (const evt of data) {
103
- const existing = updated[evt.agent_id];
104
- if (!existing || new Date(evt.timestamp) > new Date(existing.timestamp)) {
105
- updated[evt.agent_id] = {
106
- timestamp: evt.timestamp,
107
- category: evt.category,
108
- type: evt.type,
109
- };
110
- }
111
- }
112
- return updated;
113
- });
114
-
115
- // Set agents as active for 3 seconds (tracked in context, not component)
116
- setActiveAgents(prev => {
117
- const updated = { ...prev };
118
- const expiresAt = Date.now() + 3000;
119
- for (const evt of data) {
120
- updated[evt.agent_id] = { type: evt.type, expiresAt };
121
- }
122
- return updated;
123
- });
124
-
125
- // Detect agent status change events (system-emitted)
126
- if (data.some((e: TelemetryEvent) => e.category === "system" && (e.type === "agent_started" || e.type === "agent_stopped"))) {
127
- setStatusChangeCounter(c => c + 1);
128
- }
129
-
130
- // Detect task change events
131
- if (data.some((e: TelemetryEvent) => e.category === "TASK" && (e.type === "task_created" || e.type === "task_updated" || e.type === "task_deleted"))) {
132
- setTaskChangeCounter(c => c + 1);
133
- }
134
-
135
- // Detect notification-worthy events (errors, agent crashes)
136
- if (data.some((e: TelemetryEvent) => e.level === "error" || e.category === "ERROR" || (e.category === "system" && e.type === "agent_stopped"))) {
137
- setNotificationCounter(c => c + 1);
138
- }
139
- }
140
- } catch {
141
- // Ignore parse errors (likely keepalive or empty message)
142
- }
143
- };
144
-
145
- es.onerror = () => {
146
- setConnected(false);
147
- es.close();
148
- eventSourceRef.current = null;
149
-
150
- // Reconnect after 2 seconds
151
- if (reconnectTimeoutRef.current) {
152
- clearTimeout(reconnectTimeoutRef.current);
153
- }
154
- reconnectTimeoutRef.current = setTimeout(connect, 2000);
155
- };
156
- } catch {
157
- // Failed to create EventSource, retry
158
- setConnected(false);
159
- if (reconnectTimeoutRef.current) {
160
- clearTimeout(reconnectTimeoutRef.current);
161
- }
162
- reconnectTimeoutRef.current = setTimeout(connect, 2000);
163
- }
164
- }, []);
165
-
166
- useEffect(() => {
167
- connect();
168
-
169
- return () => {
170
- if (eventSourceRef.current) {
171
- eventSourceRef.current.close();
172
- }
173
- if (reconnectTimeoutRef.current) {
174
- clearTimeout(reconnectTimeoutRef.current);
175
- }
176
- };
177
- }, [connect]);
178
-
179
- const clearEvents = useCallback(() => {
180
- setEvents([]);
181
- }, []);
182
-
183
- const triggerRefresh = useCallback(() => {
184
- setStatusChangeCounter(c => c + 1);
185
- setTaskChangeCounter(c => c + 1);
186
- }, []);
187
-
188
- const value = React.useMemo(() => ({
189
- connected, events, lastActivityByAgent, activeAgents, statusChangeCounter, taskChangeCounter, notificationCounter, clearEvents, triggerRefresh,
190
- }), [connected, events, lastActivityByAgent, activeAgents, statusChangeCounter, taskChangeCounter, notificationCounter, clearEvents, triggerRefresh]);
191
-
192
- return (
193
- <TelemetryContext.Provider value={value}>
194
- {children}
195
- </TelemetryContext.Provider>
196
- );
197
- }
198
-
199
- // Hook to access all telemetry
200
- export function useTelemetryContext() {
201
- const context = useContext(TelemetryContext);
202
- if (!context) {
203
- throw new Error("useTelemetryContext must be used within TelemetryProvider");
204
- }
205
- return context;
206
- }
207
-
208
- // Hook to filter telemetry for a specific agent or category
209
- export function useTelemetry(filter?: {
210
- agent_id?: string;
211
- category?: string;
212
- limit?: number;
213
- }) {
214
- const { connected, events, lastActivityByAgent } = useTelemetryContext();
215
-
216
- const filteredEvents = React.useMemo(() => {
217
- let result = events;
218
-
219
- if (filter?.agent_id) {
220
- result = result.filter(e => e.agent_id === filter.agent_id);
221
- }
222
- if (filter?.category) {
223
- result = result.filter(e => e.category === filter.category);
224
- }
225
- if (filter?.limit) {
226
- result = result.slice(0, filter.limit);
227
- }
228
-
229
- return result;
230
- }, [events, filter?.agent_id, filter?.category, filter?.limit]);
231
-
232
- const lastActivity = filter?.agent_id ? lastActivityByAgent[filter.agent_id] : undefined;
233
-
234
- // Check if agent is "active" (had activity in last 10 seconds)
235
- const isActive = React.useMemo(() => {
236
- if (!lastActivity) return false;
237
- const activityTime = new Date(lastActivity.timestamp).getTime();
238
- const now = Date.now();
239
- return now - activityTime < 10000; // 10 seconds
240
- }, [lastActivity]);
241
-
242
- return {
243
- connected,
244
- events: filteredEvents,
245
- lastActivity,
246
- isActive,
247
- };
248
- }
249
-
250
- // Map raw telemetry event types to user-friendly labels
251
- export function getActivityLabel(type: string): string {
252
- switch (type) {
253
- case "llm_request": return "Thinking";
254
- case "tool_invocation": return "Using tools";
255
- case "tool_result": return "Using tools";
256
- case "thread_activity": return "Working";
257
- case "agent_started": return "Starting";
258
- case "agent_stopped": return "Stopped";
259
- default: return "Working";
260
- }
261
- }
262
-
263
- // Hook for agent activity indicator - uses context-level tracking
264
- export function useAgentActivity(agentId: string) {
265
- const { activeAgents } = useTelemetryContext();
266
- const activity = activeAgents[agentId];
267
-
268
- const isActive = !!activity;
269
- const type = activity?.type;
270
- return React.useMemo(() => ({
271
- isActive,
272
- type,
273
- label: isActive ? getActivityLabel(type!) : undefined,
274
- }), [isActive, type]);
275
- }
276
-
277
- // Hook to trigger agent list refetch on status changes (started/stopped/crashed)
278
- export function useAgentStatusChange(): number {
279
- const { statusChangeCounter } = useTelemetryContext();
280
- return statusChangeCounter;
281
- }
282
-
283
- // Hook to trigger task count refetch on task mutations
284
- export function useTaskChange(): number {
285
- const { taskChangeCounter } = useTelemetryContext();
286
- return taskChangeCounter;
287
- }
288
-
289
- // Hook to trigger notification badge refresh
290
- export function useNotificationChange(): number {
291
- const { notificationCounter } = useTelemetryContext();
292
- return notificationCounter;
293
- }
294
-
295
- // Hook to manually trigger data refresh (e.g. after meta agent tool calls)
296
- export function useTriggerRefresh(): () => void {
297
- const { triggerRefresh } = useTelemetryContext();
298
- return triggerRefresh;
299
- }
@@ -1,90 +0,0 @@
1
- import React, { createContext, useContext, useState, useEffect, useCallback, useMemo, type ReactNode } from "react";
2
- import { themes, resolveTheme, type ThemeMode, type ThemeStyle, type Theme } from "../themes";
3
-
4
- interface ThemeContextValue {
5
- mode: ThemeMode;
6
- style: ThemeStyle;
7
- theme: Theme; // resolved theme
8
- setMode: (mode: ThemeMode) => void;
9
- setStyle: (style: ThemeStyle) => void;
10
- }
11
-
12
- const ThemeContext = createContext<ThemeContextValue | null>(null);
13
-
14
- export function useTheme(): ThemeContextValue {
15
- const context = useContext(ThemeContext);
16
- if (!context) {
17
- throw new Error("useTheme must be used within a ThemeProvider");
18
- }
19
- return context;
20
- }
21
-
22
- const MODE_KEY = "apteva_theme_mode";
23
- const STYLE_KEY = "apteva_theme_style";
24
-
25
- function getSystemPrefersDark(): boolean {
26
- if (typeof window === "undefined") return true;
27
- return window.matchMedia("(prefers-color-scheme: dark)").matches;
28
- }
29
-
30
- function applyTheme(theme: Theme, style: ThemeStyle) {
31
- const root = document.documentElement;
32
- for (const [key, value] of Object.entries(theme.colors)) {
33
- root.style.setProperty(key, value);
34
- }
35
- root.setAttribute("data-theme", theme.id);
36
- root.setAttribute("data-style", style);
37
- // Set font directly as inline style — CSS variable alone gets overridden by Tailwind base
38
- document.body.style.fontFamily = style === "professional"
39
- ? "'Inter', system-ui, -apple-system, sans-serif"
40
- : "'JetBrains Mono', monospace";
41
- }
42
-
43
- export function ThemeProvider({ children }: { children: ReactNode }) {
44
- const [mode, setModeState] = useState<ThemeMode>(() => {
45
- if (typeof window !== "undefined") {
46
- const stored = localStorage.getItem(MODE_KEY);
47
- if (stored === "dark" || stored === "light" || stored === "auto") return stored;
48
- }
49
- return "auto";
50
- });
51
-
52
- const [style, setStyleState] = useState<ThemeStyle>(() => {
53
- if (typeof window !== "undefined") {
54
- const stored = localStorage.getItem(STYLE_KEY);
55
- if (stored === "classic" || stored === "professional") return stored;
56
- }
57
- return "classic";
58
- });
59
-
60
- const [prefersDark, setPrefersDark] = useState(getSystemPrefersDark);
61
-
62
- // Listen for system theme changes
63
- useEffect(() => {
64
- const mq = window.matchMedia("(prefers-color-scheme: dark)");
65
- const handler = (e: MediaQueryListEvent) => setPrefersDark(e.matches);
66
- mq.addEventListener("change", handler);
67
- return () => mq.removeEventListener("change", handler);
68
- }, []);
69
-
70
- const theme = useMemo(() => resolveTheme(mode, style, prefersDark), [mode, style, prefersDark]);
71
-
72
- // Apply CSS variables + style attribute whenever theme or style changes
73
- useEffect(() => {
74
- applyTheme(theme, style);
75
- }, [theme, style]);
76
-
77
- const setMode = useCallback((newMode: ThemeMode) => {
78
- setModeState(newMode);
79
- localStorage.setItem(MODE_KEY, newMode);
80
- }, []);
81
-
82
- const setStyle = useCallback((newStyle: ThemeStyle) => {
83
- setStyleState(newStyle);
84
- localStorage.setItem(STYLE_KEY, newStyle);
85
- }, []);
86
-
87
- const value = useMemo(() => ({ mode, style, theme, setMode, setStyle }), [mode, style, theme, setMode, setStyle]);
88
-
89
- return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
90
- }
@@ -1,49 +0,0 @@
1
- import React, { createContext, useContext, useState, useCallback, useMemo, type ReactNode } from "react";
2
-
3
- export type UIMode = "developer" | "business";
4
-
5
- interface UIModeContextValue {
6
- mode: UIMode;
7
- setMode: (mode: UIMode) => void;
8
- isDev: boolean;
9
- isBusiness: boolean;
10
- t: (dev: string, biz: string) => string;
11
- }
12
-
13
- const UIModeContext = createContext<UIModeContextValue | null>(null);
14
-
15
- const STORAGE_KEY = "apteva_ui_mode";
16
-
17
- export function useUIMode(): UIModeContextValue {
18
- const context = useContext(UIModeContext);
19
- if (!context) {
20
- throw new Error("useUIMode must be used within a UIModeProvider");
21
- }
22
- return context;
23
- }
24
-
25
- export function UIModeProvider({ children }: { children: ReactNode }) {
26
- const [mode, setModeState] = useState<UIMode>(() => {
27
- if (typeof window !== "undefined") {
28
- const stored = localStorage.getItem(STORAGE_KEY);
29
- if (stored === "developer" || stored === "business") return stored;
30
- }
31
- return "developer";
32
- });
33
-
34
- const setMode = useCallback((newMode: UIMode) => {
35
- setModeState(newMode);
36
- localStorage.setItem(STORAGE_KEY, newMode);
37
- }, []);
38
-
39
- const isDev = mode === "developer";
40
- const isBusiness = mode === "business";
41
-
42
- const t = useCallback((dev: string, biz: string) => {
43
- return mode === "developer" ? dev : biz;
44
- }, [mode]);
45
-
46
- const value = useMemo(() => ({ mode, setMode, isDev, isBusiness, t }), [mode, setMode, isDev, isBusiness, t]);
47
-
48
- return <UIModeContext.Provider value={value}>{children}</UIModeContext.Provider>;
49
- }
@@ -1,12 +0,0 @@
1
- export { TelemetryProvider, useTelemetryContext, useTelemetry, useAgentActivity, useAgentStatusChange, useTaskChange, useNotificationChange, useTriggerRefresh } from "./TelemetryContext";
2
- export type { TelemetryEvent } from "./TelemetryContext";
3
-
4
- export { AuthProvider, useAuth, useAuthHeaders } from "./AuthContext";
5
-
6
- export { ProjectProvider, useProjects } from "./ProjectContext";
7
- export type { Project } from "./ProjectContext";
8
-
9
- export { ThemeProvider, useTheme } from "./ThemeContext";
10
-
11
- export { UIModeProvider, useUIMode } from "./UIModeContext";
12
- export type { UIMode } from "./UIModeContext";
@@ -1,3 +0,0 @@
1
- export { useAgents } from "./useAgents";
2
- export { useProviders } from "./useProviders";
3
- export { useOnboarding } from "./useOnboarding";