apteva 0.4.56 → 0.7.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 (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 +12 -79
  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 -2370
  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,394 +0,0 @@
1
- // Local MCP server handler
2
- // Handles JSON-RPC requests for servers of type "local"
3
- // Tools are stored in the database with configurable handler types: mock, http, javascript
4
-
5
- import { McpServerDB, McpServerToolDB, type McpServerTool } from "./db";
6
-
7
- const PROTOCOL_VERSION = "2024-11-05";
8
-
9
- interface JsonRpcRequest {
10
- jsonrpc: "2.0";
11
- id: number;
12
- method: string;
13
- params?: any;
14
- }
15
-
16
- interface JsonRpcResponse {
17
- jsonrpc: "2.0";
18
- id: number;
19
- result?: unknown;
20
- error?: { code: number; message: string; data?: unknown };
21
- }
22
-
23
- // Template helpers available in mock_response and javascript handlers
24
- function templateHelpers() {
25
- return {
26
- uuid: () => crypto.randomUUID(),
27
- now: new Date().toISOString(),
28
- timestamp: Date.now(),
29
- random_int: (min: number, max: number) =>
30
- Math.floor(Math.random() * (max - min + 1)) + min,
31
- random_float: (min: number, max: number) =>
32
- Math.random() * (max - min) + min,
33
- };
34
- }
35
-
36
- // Render mock response template with variable substitution
37
- // Supports: {{args.field}}, {{uuid()}}, {{now}}, {{timestamp}}, {{random_int(min,max)}}
38
- function renderTemplate(template: any, args: Record<string, any>): any {
39
- const helpers = templateHelpers();
40
-
41
- if (typeof template === "string") {
42
- // Check if entire string is a single expression
43
- const fullMatch = template.match(/^\{\{(.+)\}\}$/);
44
- if (fullMatch) {
45
- return evaluateExpression(fullMatch[1].trim(), args, helpers);
46
- }
47
- // Replace embedded expressions
48
- return template.replace(/\{\{([^}]+)\}\}/g, (_, expr) => {
49
- const result = evaluateExpression(expr.trim(), args, helpers);
50
- if (result === null || result === undefined) return "";
51
- if (typeof result === "object") return JSON.stringify(result);
52
- return String(result);
53
- });
54
- }
55
-
56
- if (Array.isArray(template)) {
57
- return template.map((item) => renderTemplate(item, args));
58
- }
59
-
60
- if (template !== null && typeof template === "object") {
61
- const result: Record<string, any> = {};
62
- for (const [key, val] of Object.entries(template)) {
63
- result[key] = renderTemplate(val, args);
64
- }
65
- return result;
66
- }
67
-
68
- return template;
69
- }
70
-
71
- function evaluateExpression(
72
- expr: string,
73
- args: Record<string, any>,
74
- helpers: ReturnType<typeof templateHelpers>,
75
- ): any {
76
- // Handle args.* references (e.g. args.name, args.query)
77
- if (expr.startsWith("args.")) {
78
- const key = expr.slice(5);
79
- return args[key] ?? null;
80
- }
81
-
82
- // Handle known helper values
83
- if (expr === "now") return helpers.now;
84
- if (expr === "timestamp") return helpers.timestamp;
85
-
86
- // Handle known helper function calls
87
- const uuidMatch = expr.match(/^uuid\(\)$/);
88
- if (uuidMatch) return helpers.uuid();
89
-
90
- const randIntMatch = expr.match(/^random_int\(\s*(\d+)\s*,\s*(\d+)\s*\)$/);
91
- if (randIntMatch) return helpers.random_int(Number(randIntMatch[1]), Number(randIntMatch[2]));
92
-
93
- const randFloatMatch = expr.match(/^random_float\(\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/);
94
- if (randFloatMatch) return helpers.random_float(Number(randFloatMatch[1]), Number(randFloatMatch[2]));
95
-
96
- // Return expression as-is if not recognized — never execute arbitrary code
97
- return expr;
98
- }
99
-
100
- // Execute a mock handler — returns the rendered mock_response
101
- function executeMock(
102
- tool: McpServerTool,
103
- args: Record<string, any>,
104
- ): { content: Array<{ type: "text"; text: string }>; isError?: boolean } {
105
- const mockResponse = tool.mock_response || {};
106
- const rendered = renderTemplate(mockResponse, args);
107
- return {
108
- content: [{ type: "text", text: JSON.stringify(rendered, null, 2) }],
109
- };
110
- }
111
-
112
- // Execute an HTTP handler — makes a real API call
113
- async function executeHttp(
114
- tool: McpServerTool,
115
- args: Record<string, any>,
116
- credentials: Record<string, string>,
117
- ): Promise<{ content: Array<{ type: "text"; text: string }>; isError?: boolean }> {
118
- const config = tool.http_config;
119
- if (!config || !config.url) {
120
- return {
121
- content: [{ type: "text", text: "Error: No HTTP config or URL defined" }],
122
- isError: true,
123
- };
124
- }
125
-
126
- const { method = "GET", url, headers = {}, body } = config;
127
-
128
- // Render templates in URL, headers, and body
129
- const renderedUrl = renderTemplate(url, args) as string;
130
- const renderedHeaders = renderTemplate(headers, args) as Record<string, string>;
131
-
132
- // Substitute credential references in headers
133
- const finalHeaders: Record<string, string> = { "Content-Type": "application/json" };
134
- for (const [k, v] of Object.entries(renderedHeaders)) {
135
- let val = String(v);
136
- // Replace {{credential.*}} references
137
- val = val.replace(/\{\{credential\.([^}]+)\}\}/g, (_, key) => credentials[key] || "");
138
- finalHeaders[k] = val;
139
- }
140
-
141
- const fetchOptions: RequestInit = {
142
- method: method.toUpperCase(),
143
- headers: finalHeaders,
144
- };
145
-
146
- if (["POST", "PUT", "PATCH"].includes(fetchOptions.method!)) {
147
- if (body) {
148
- const renderedBody = renderTemplate(body, args);
149
- fetchOptions.body = JSON.stringify(renderedBody);
150
- } else {
151
- fetchOptions.body = JSON.stringify(args);
152
- }
153
- }
154
-
155
- try {
156
- const response = await fetch(renderedUrl, fetchOptions);
157
- const text = await response.text();
158
-
159
- let data;
160
- try {
161
- data = JSON.parse(text);
162
- } catch {
163
- data = text;
164
- }
165
-
166
- if (!response.ok) {
167
- return {
168
- content: [
169
- {
170
- type: "text",
171
- text: `HTTP ${response.status}: ${typeof data === "string" ? data : JSON.stringify(data, null, 2)}`,
172
- },
173
- ],
174
- isError: true,
175
- };
176
- }
177
-
178
- return {
179
- content: [
180
- {
181
- type: "text",
182
- text: typeof data === "string" ? data : JSON.stringify(data, null, 2),
183
- },
184
- ],
185
- };
186
- } catch (err) {
187
- return {
188
- content: [{ type: "text", text: `HTTP error: ${err}` }],
189
- isError: true,
190
- };
191
- }
192
- }
193
-
194
- // Execute a JavaScript handler — runs user-defined code in a restricted scope.
195
- // SECURITY NOTE: This intentionally allows authenticated admins to define custom tool logic.
196
- // The code runs in a restricted Function scope with only args, credentials, and helpers exposed.
197
- // process, require, import, Bun, fetch etc. are NOT passed in — but note that new Function()
198
- // still has access to globalThis. For full sandboxing, consider using a Worker or subprocess.
199
- function executeJavascript(
200
- tool: McpServerTool,
201
- args: Record<string, any>,
202
- credentials: Record<string, string>,
203
- ): { content: Array<{ type: "text"; text: string }>; isError?: boolean } {
204
- if (!tool.code) {
205
- return {
206
- content: [{ type: "text", text: "Error: No code defined for this tool" }],
207
- isError: true,
208
- };
209
- }
210
-
211
- // Basic static checks — block obvious dangerous patterns
212
- const dangerous = /\b(process|require|import|Bun|Deno|eval|Function|child_process|exec|spawn)\b/;
213
- if (dangerous.test(tool.code)) {
214
- return {
215
- content: [{ type: "text", text: "Error: Tool code contains disallowed keywords (process, require, import, eval, exec, spawn)" }],
216
- isError: true,
217
- };
218
- }
219
-
220
- try {
221
- const helpers = templateHelpers();
222
- const fn = new Function(
223
- "args",
224
- "credentials",
225
- "uuid",
226
- "now",
227
- "timestamp",
228
- "random_int",
229
- "random_float",
230
- tool.code,
231
- );
232
- const result = fn(
233
- args,
234
- credentials,
235
- helpers.uuid,
236
- helpers.now,
237
- helpers.timestamp,
238
- helpers.random_int,
239
- helpers.random_float,
240
- );
241
- const text =
242
- typeof result === "string" ? result : JSON.stringify(result, null, 2);
243
- return { content: [{ type: "text", text }] };
244
- } catch (err) {
245
- return {
246
- content: [{ type: "text", text: `JavaScript error: ${err}` }],
247
- isError: true,
248
- };
249
- }
250
- }
251
-
252
- // Execute a tool based on its handler_type
253
- async function executeTool(
254
- tool: McpServerTool,
255
- args: Record<string, any>,
256
- credentials: Record<string, string>,
257
- ): Promise<{ content: Array<{ type: "text"; text: string }>; isError?: boolean }> {
258
- switch (tool.handler_type) {
259
- case "http":
260
- return executeHttp(tool, args, credentials);
261
- case "javascript":
262
- return executeJavascript(tool, args, credentials);
263
- case "mock":
264
- default:
265
- return executeMock(tool, args);
266
- }
267
- }
268
-
269
- // Main JSON-RPC handler for local MCP servers
270
- export async function handleLocalMcpRequest(
271
- req: Request,
272
- serverId: string,
273
- ): Promise<Response> {
274
- const corsHeaders = {
275
- "Access-Control-Allow-Origin": "*",
276
- "Access-Control-Allow-Methods": "POST, OPTIONS",
277
- "Access-Control-Allow-Headers": "Content-Type, Mcp-Session-Id",
278
- };
279
-
280
- if (req.method === "OPTIONS") {
281
- return new Response(null, { headers: corsHeaders });
282
- }
283
-
284
- const server = McpServerDB.findById(serverId);
285
- if (!server || server.type !== "local") {
286
- return new Response(
287
- JSON.stringify({
288
- jsonrpc: "2.0",
289
- id: 0,
290
- error: { code: -32600, message: "Server not found or not a local server" },
291
- }),
292
- { headers: { ...corsHeaders, "Content-Type": "application/json" } },
293
- );
294
- }
295
-
296
- let body: JsonRpcRequest;
297
- try {
298
- body = (await req.json()) as JsonRpcRequest;
299
- } catch {
300
- return new Response(
301
- JSON.stringify({
302
- jsonrpc: "2.0",
303
- id: 0,
304
- error: { code: -32700, message: "Parse error" },
305
- }),
306
- { headers: { ...corsHeaders, "Content-Type": "application/json" } },
307
- );
308
- }
309
-
310
- const { method, params, id } = body;
311
- let result: unknown;
312
- let error: { code: number; message: string } | undefined;
313
-
314
- // Parse server credentials
315
- let credentials: Record<string, string> = {};
316
- try {
317
- if (server.env && Object.keys(server.env).length > 0) {
318
- credentials = server.env;
319
- }
320
- } catch {
321
- // ignore
322
- }
323
-
324
- switch (method) {
325
- case "initialize": {
326
- result = {
327
- protocolVersion: PROTOCOL_VERSION,
328
- capabilities: {
329
- tools: { listChanged: false },
330
- },
331
- serverInfo: {
332
- name: server.name,
333
- version: "1.0.0",
334
- },
335
- };
336
- break;
337
- }
338
-
339
- case "notifications/initialized": {
340
- result = {};
341
- break;
342
- }
343
-
344
- case "tools/list": {
345
- const tools = McpServerToolDB.findByServer(serverId);
346
- result = {
347
- tools: tools
348
- .filter((t) => t.enabled)
349
- .map((t) => ({
350
- name: t.name,
351
- description: t.description,
352
- inputSchema: t.input_schema,
353
- })),
354
- };
355
- break;
356
- }
357
-
358
- case "tools/call": {
359
- const { name, arguments: args } = params as {
360
- name: string;
361
- arguments: Record<string, any>;
362
- };
363
- const tool = McpServerToolDB.findByServerAndName(serverId, name);
364
- if (!tool) {
365
- result = {
366
- content: [{ type: "text", text: `Tool '${name}' not found` }],
367
- isError: true,
368
- };
369
- } else if (!tool.enabled) {
370
- result = {
371
- content: [{ type: "text", text: `Tool '${name}' is disabled` }],
372
- isError: true,
373
- };
374
- } else {
375
- result = await executeTool(tool, args || {}, credentials);
376
- }
377
- break;
378
- }
379
-
380
- default: {
381
- error = { code: -32601, message: `Method not found: ${method}` };
382
- }
383
- }
384
-
385
- const response: JsonRpcResponse = {
386
- jsonrpc: "2.0",
387
- id: id || 0,
388
- ...(error ? { error } : { result }),
389
- };
390
-
391
- return new Response(JSON.stringify(response), {
392
- headers: { ...corsHeaders, "Content-Type": "application/json" },
393
- });
394
- }