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.
- package/README.md +216 -54
- package/cli.js +35 -0
- package/install.js +92 -0
- package/package.json +15 -76
- package/LICENSE +0 -63
- package/bin/apteva.js +0 -196
- package/dist/ActivityPage.kxzzb4yc.js +0 -3
- package/dist/ApiDocsPage.zq998hbm.js +0 -4
- package/dist/App.55rea8mn.js +0 -61
- package/dist/App.5ywb23z4.js +0 -53
- package/dist/App.6thds120.js +0 -4
- package/dist/App.9tctxzqm.js +0 -8
- package/dist/App.a8r8ttaz.js +0 -4
- package/dist/App.agsv5bje.js +0 -4
- package/dist/App.cepapqmx.js +0 -4
- package/dist/App.dp041gb3.js +0 -221
- package/dist/App.fds72zb5.js +0 -4
- package/dist/App.fg9qj2dq.js +0 -4
- package/dist/App.ndfejbm9.js +0 -4
- package/dist/App.nxmfmq1h.js +0 -13
- package/dist/App.qdfyt8ba.js +0 -4
- package/dist/App.x2d0ygt6.js +0 -4
- package/dist/App.yt9p4nr3.js +0 -20
- package/dist/App.zn4mw16t.js +0 -1
- package/dist/ConnectionsPage.8r96ryw7.js +0 -3
- package/dist/McpPage.3cwh0gnd.js +0 -3
- package/dist/SettingsPage.ykgdh5ev.js +0 -3
- package/dist/SkillsPage.4np1s65b.js +0 -3
- package/dist/TasksPage.4g08t7p6.js +0 -3
- package/dist/TelemetryPage.72w9pwcp.js +0 -3
- package/dist/TestsPage.z4fk3r7r.js +0 -3
- package/dist/ThreadsPage.63tcajeh.js +0 -3
- package/dist/apteva-kit.css +0 -1
- package/dist/icon.png +0 -0
- package/dist/index.html +0 -16
- package/dist/styles.css +0 -1
- package/scripts/postinstall.mjs +0 -102
- package/src/auth/index.ts +0 -394
- package/src/auth/middleware.ts +0 -213
- package/src/binary.ts +0 -536
- package/src/channels/index.ts +0 -40
- package/src/channels/telegram.ts +0 -311
- package/src/crypto.ts +0 -301
- package/src/db-tests.ts +0 -174
- package/src/db.ts +0 -3133
- package/src/integrations/agentdojo.ts +0 -559
- package/src/integrations/composio.ts +0 -437
- package/src/integrations/index.ts +0 -87
- package/src/integrations/skillsmp.ts +0 -318
- package/src/mcp-client.ts +0 -605
- package/src/mcp-handler.ts +0 -394
- package/src/mcp-platform.ts +0 -2403
- package/src/openapi.ts +0 -2410
- package/src/providers.ts +0 -597
- package/src/routes/api/agent-utils.ts +0 -890
- package/src/routes/api/agents.ts +0 -916
- package/src/routes/api/api-keys.ts +0 -95
- package/src/routes/api/channels.ts +0 -182
- package/src/routes/api/helpers.ts +0 -12
- package/src/routes/api/integrations.ts +0 -639
- package/src/routes/api/mcp.ts +0 -574
- package/src/routes/api/meta-agent.ts +0 -195
- package/src/routes/api/projects.ts +0 -112
- package/src/routes/api/providers.ts +0 -424
- package/src/routes/api/skills.ts +0 -537
- package/src/routes/api/system.ts +0 -333
- package/src/routes/api/telemetry.ts +0 -203
- package/src/routes/api/tests.ts +0 -148
- package/src/routes/api/triggers.ts +0 -518
- package/src/routes/api/users.ts +0 -148
- package/src/routes/api/webhooks.ts +0 -171
- package/src/routes/api.ts +0 -53
- package/src/routes/auth.ts +0 -251
- package/src/routes/share.ts +0 -86
- package/src/routes/static.ts +0 -131
- package/src/server.ts +0 -642
- package/src/test-runner.ts +0 -598
- package/src/triggers/agentdojo.ts +0 -253
- package/src/triggers/composio.ts +0 -264
- package/src/triggers/index.ts +0 -71
- package/src/tui/AgentList.tsx +0 -145
- package/src/tui/App.tsx +0 -102
- package/src/tui/Login.tsx +0 -104
- package/src/tui/api.ts +0 -72
- package/src/tui/index.tsx +0 -7
- package/src/web/App.tsx +0 -455
- package/src/web/components/activity/ActivityPage.tsx +0 -314
- package/src/web/components/activity/index.ts +0 -1
- package/src/web/components/agents/AgentCard.tsx +0 -189
- package/src/web/components/agents/AgentPanel.tsx +0 -2244
- package/src/web/components/agents/AgentsView.tsx +0 -180
- package/src/web/components/agents/CreateAgentModal.tsx +0 -475
- package/src/web/components/agents/index.ts +0 -4
- package/src/web/components/api/ApiDocsPage.tsx +0 -842
- package/src/web/components/auth/CreateAccountStep.tsx +0 -176
- package/src/web/components/auth/LoginPage.tsx +0 -91
- package/src/web/components/auth/index.ts +0 -2
- package/src/web/components/common/Icons.tsx +0 -250
- package/src/web/components/common/LoadingSpinner.tsx +0 -44
- package/src/web/components/common/Modal.tsx +0 -199
- package/src/web/components/common/Select.tsx +0 -97
- package/src/web/components/common/index.ts +0 -20
- package/src/web/components/connections/ConnectionsPage.tsx +0 -54
- package/src/web/components/connections/IntegrationsTab.tsx +0 -170
- package/src/web/components/connections/OverviewTab.tsx +0 -137
- package/src/web/components/connections/TriggersTab.tsx +0 -1346
- package/src/web/components/dashboard/Dashboard.tsx +0 -572
- package/src/web/components/dashboard/index.ts +0 -1
- package/src/web/components/index.ts +0 -21
- package/src/web/components/layout/ErrorBanner.tsx +0 -18
- package/src/web/components/layout/Header.tsx +0 -332
- package/src/web/components/layout/Sidebar.tsx +0 -231
- package/src/web/components/layout/index.ts +0 -3
- package/src/web/components/mcp/IntegrationsPanel.tsx +0 -857
- package/src/web/components/mcp/McpPage.tsx +0 -2515
- package/src/web/components/mcp/index.ts +0 -1
- package/src/web/components/meta-agent/MetaAgent.tsx +0 -245
- package/src/web/components/onboarding/OnboardingWizard.tsx +0 -404
- package/src/web/components/onboarding/index.ts +0 -1
- package/src/web/components/settings/SettingsPage.tsx +0 -2776
- package/src/web/components/settings/index.ts +0 -1
- package/src/web/components/skills/SkillsPage.tsx +0 -1200
- package/src/web/components/tasks/TasksPage.tsx +0 -1116
- package/src/web/components/tasks/index.ts +0 -1
- package/src/web/components/telemetry/TelemetryPage.tsx +0 -1129
- package/src/web/components/tests/TestsPage.tsx +0 -594
- package/src/web/components/threads/ThreadsPage.tsx +0 -315
- package/src/web/context/AuthContext.tsx +0 -242
- package/src/web/context/ProjectContext.tsx +0 -214
- package/src/web/context/TelemetryContext.tsx +0 -299
- package/src/web/context/ThemeContext.tsx +0 -90
- package/src/web/context/UIModeContext.tsx +0 -49
- package/src/web/context/index.ts +0 -12
- package/src/web/hooks/index.ts +0 -3
- package/src/web/hooks/useAgents.ts +0 -115
- package/src/web/hooks/useOnboarding.ts +0 -20
- package/src/web/hooks/useProviders.ts +0 -75
- package/src/web/icon.png +0 -0
- package/src/web/index.html +0 -16
- package/src/web/styles.css +0 -118
- package/src/web/themes.ts +0 -162
- package/src/web/types.ts +0 -298
|
@@ -1,559 +0,0 @@
|
|
|
1
|
-
// AgentDojo Integration Provider
|
|
2
|
-
// Connects to our hosted MCP API
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
IntegrationProvider,
|
|
6
|
-
IntegrationApp,
|
|
7
|
-
ConnectedAccount,
|
|
8
|
-
ConnectionRequest,
|
|
9
|
-
ConnectionCredentials,
|
|
10
|
-
} from "./index";
|
|
11
|
-
|
|
12
|
-
// AgentDojo MCP API base URL
|
|
13
|
-
const AGENTDOJO_API_BASE = process.env.AGENTDOJO_API_BASE || "https://api.agentdojo.dev";
|
|
14
|
-
|
|
15
|
-
// Map MCP API provider_type to IntegrationApp authSchemes
|
|
16
|
-
function mapAuthSchemes(providerType: string): string[] {
|
|
17
|
-
switch (providerType) {
|
|
18
|
-
case "oauth": return ["OAUTH2"];
|
|
19
|
-
case "api_key": return ["API_KEY"];
|
|
20
|
-
case "basic_auth": return ["BASIC"];
|
|
21
|
-
case "none": return ["NONE"];
|
|
22
|
-
default: return ["API_KEY"];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const AgentDojoProvider: IntegrationProvider = {
|
|
27
|
-
id: "agentdojo",
|
|
28
|
-
name: "AgentDojo",
|
|
29
|
-
|
|
30
|
-
// List toolkits + providers from MCP API, merge so we get both
|
|
31
|
-
// no-auth toolkits AND OAuth/API key providers
|
|
32
|
-
async listApps(apiKey: string): Promise<IntegrationApp[]> {
|
|
33
|
-
const headers = { "X-API-Key": apiKey, "Content-Type": "application/json" };
|
|
34
|
-
|
|
35
|
-
// Fetch both in parallel
|
|
36
|
-
const [toolkitsRes, providersRes] = await Promise.all([
|
|
37
|
-
fetch(`${AGENTDOJO_API_BASE}/toolkits?include_tools=true`, { headers }).catch(() => null),
|
|
38
|
-
fetch(`${AGENTDOJO_API_BASE}/providers?is_active=true`, { headers }).catch(() => null),
|
|
39
|
-
]);
|
|
40
|
-
|
|
41
|
-
// Parse toolkits
|
|
42
|
-
let toolkits: any[] = [];
|
|
43
|
-
if (toolkitsRes?.ok) {
|
|
44
|
-
const data = await toolkitsRes.json();
|
|
45
|
-
toolkits = data.toolkits || data.data || [];
|
|
46
|
-
} else if (toolkitsRes) {
|
|
47
|
-
console.error("AgentDojo listApps toolkits error:", toolkitsRes.status);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Parse providers (for auth type info)
|
|
51
|
-
let providers: any[] = [];
|
|
52
|
-
if (providersRes?.ok) {
|
|
53
|
-
const data = await providersRes.json();
|
|
54
|
-
providers = data.providers || data.data || [];
|
|
55
|
-
} else if (providersRes) {
|
|
56
|
-
console.error("AgentDojo listApps providers error:", providersRes.status);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Index providers by id and name for quick lookup
|
|
60
|
-
const providerById = new Map<number, any>();
|
|
61
|
-
const providerByName = new Map<string, any>();
|
|
62
|
-
for (const p of providers) {
|
|
63
|
-
if (p.id) providerById.set(p.id, p);
|
|
64
|
-
providerByName.set(p.name, p);
|
|
65
|
-
if (p.display_name) providerByName.set(p.display_name.toLowerCase(), p);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Map toolkits to apps, enriching auth info from providers.
|
|
69
|
-
// Use auth_provider_id from the toolkit to find the parent provider —
|
|
70
|
-
// one provider can serve many toolkits (e.g. provider "omnikit" id=49
|
|
71
|
-
// serves "omnikit-messaging", "omnikit-cms", "omnikit-billing", etc.)
|
|
72
|
-
const apps: IntegrationApp[] = toolkits.map((toolkit: any) => {
|
|
73
|
-
const name = toolkit.name || toolkit.slug;
|
|
74
|
-
|
|
75
|
-
// Primary: match via auth_provider_id (reliable link from API)
|
|
76
|
-
let provider = toolkit.auth_provider_id
|
|
77
|
-
? providerById.get(toolkit.auth_provider_id)
|
|
78
|
-
: null;
|
|
79
|
-
// Fallback: match by name
|
|
80
|
-
if (!provider) {
|
|
81
|
-
provider = providerByName.get(name) || providerByName.get(name?.toLowerCase());
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let authSchemes: string[];
|
|
85
|
-
if (provider) {
|
|
86
|
-
authSchemes = mapAuthSchemes(provider.provider_type);
|
|
87
|
-
} else if (toolkit.requires_auth) {
|
|
88
|
-
authSchemes = ["API_KEY"]; // Default if no provider found but auth required
|
|
89
|
-
} else {
|
|
90
|
-
authSchemes = ["NONE"];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Build credential fields from provider auth_config
|
|
94
|
-
let credentialFields: IntegrationApp["credentialFields"] | undefined;
|
|
95
|
-
if (provider?.auth_config?.required_fields) {
|
|
96
|
-
const descriptions = provider.auth_config.field_descriptions || {};
|
|
97
|
-
const required = new Set(provider.auth_config.required_fields || []);
|
|
98
|
-
const allFields = [...(provider.auth_config.required_fields || []), ...(provider.auth_config.optional_fields || [])];
|
|
99
|
-
credentialFields = allFields.map((f: string) => ({
|
|
100
|
-
name: f,
|
|
101
|
-
description: descriptions[f] || undefined,
|
|
102
|
-
required: required.has(f),
|
|
103
|
-
}));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
id: String(toolkit.id),
|
|
108
|
-
name: toolkit.display_name || toolkit.name,
|
|
109
|
-
slug: name,
|
|
110
|
-
description: toolkit.description || null,
|
|
111
|
-
logo: provider?.favicon || toolkit.icon_url || null,
|
|
112
|
-
categories: [],
|
|
113
|
-
authSchemes,
|
|
114
|
-
providerSlug: provider?.name || undefined,
|
|
115
|
-
credentialFields,
|
|
116
|
-
};
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// Also add any providers that don't match a toolkit (standalone OAuth providers)
|
|
120
|
-
const toolkitNames = new Set(toolkits.map((t: any) => t.name));
|
|
121
|
-
const toolkitProviderIds = new Set(toolkits.map((t: any) => t.auth_provider_id).filter(Boolean));
|
|
122
|
-
for (const p of providers) {
|
|
123
|
-
if (!toolkitNames.has(p.name) && !toolkitProviderIds.has(p.id)) {
|
|
124
|
-
let credentialFields: IntegrationApp["credentialFields"] | undefined;
|
|
125
|
-
if (p.auth_config?.required_fields) {
|
|
126
|
-
const descriptions = p.auth_config.field_descriptions || {};
|
|
127
|
-
const required = new Set(p.auth_config.required_fields || []);
|
|
128
|
-
const allFields = [...(p.auth_config.required_fields || []), ...(p.auth_config.optional_fields || [])];
|
|
129
|
-
credentialFields = allFields.map((f: string) => ({
|
|
130
|
-
name: f,
|
|
131
|
-
description: descriptions[f] || undefined,
|
|
132
|
-
required: required.has(f),
|
|
133
|
-
}));
|
|
134
|
-
}
|
|
135
|
-
apps.push({
|
|
136
|
-
id: String(p.id),
|
|
137
|
-
name: p.display_name || p.name,
|
|
138
|
-
slug: p.name,
|
|
139
|
-
description: p.description || null,
|
|
140
|
-
logo: p.favicon || p.icon_url || null,
|
|
141
|
-
categories: [],
|
|
142
|
-
authSchemes: mapAuthSchemes(p.provider_type),
|
|
143
|
-
credentialFields,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return apps;
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
// List user's credentials
|
|
152
|
-
async listConnectedAccounts(apiKey: string, userId: string): Promise<ConnectedAccount[]> {
|
|
153
|
-
const res = await fetch(`${AGENTDOJO_API_BASE}/credentials`, {
|
|
154
|
-
headers: {
|
|
155
|
-
"X-API-Key": apiKey,
|
|
156
|
-
"Content-Type": "application/json",
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
if (!res.ok) {
|
|
161
|
-
console.error("AgentDojo listConnectedAccounts error:", res.status, await res.text());
|
|
162
|
-
return [];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const data = await res.json();
|
|
166
|
-
const credentials = data.data || data.credentials || [];
|
|
167
|
-
console.log(`[AgentDojo] listConnectedAccounts: got ${credentials.length} credentials`, JSON.stringify(credentials.map((c: any) => ({ id: c.id, name: c.name, provider_name: c.provider_name, credential_type: c.credential_type }))));
|
|
168
|
-
|
|
169
|
-
return credentials.map((cred: any) => ({
|
|
170
|
-
id: String(cred.id),
|
|
171
|
-
appId: cred.provider_name || cred.toolkit_name || String(cred.provider_id || cred.toolkit_id),
|
|
172
|
-
appName: cred.name || cred.display_name || cred.provider_name || cred.toolkit_name || String(cred.provider_id),
|
|
173
|
-
status: (cred.status === "active" || cred.is_valid !== false) ? "active" as const : "failed" as const,
|
|
174
|
-
createdAt: cred.created_at || new Date().toISOString(),
|
|
175
|
-
metadata: {
|
|
176
|
-
keyHint: cred.key_hint,
|
|
177
|
-
credentialType: cred.credential_type,
|
|
178
|
-
},
|
|
179
|
-
}));
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
// Initiate connection — OAuth (popup redirect) or API key (direct store)
|
|
183
|
-
async initiateConnection(
|
|
184
|
-
apiKey: string,
|
|
185
|
-
userId: string,
|
|
186
|
-
appSlug: string,
|
|
187
|
-
redirectUrl: string,
|
|
188
|
-
credentials?: ConnectionCredentials
|
|
189
|
-
): Promise<ConnectionRequest> {
|
|
190
|
-
// OAuth flow: no credentials provided (neither apiKey nor multi-field)
|
|
191
|
-
const hasCredentials = credentials?.apiKey || (credentials?.fields && Object.keys(credentials.fields).length > 0);
|
|
192
|
-
if (!hasCredentials) {
|
|
193
|
-
// Init OAuth via MCP API
|
|
194
|
-
const res = await fetch(`${AGENTDOJO_API_BASE}/oauth/init`, {
|
|
195
|
-
method: "POST",
|
|
196
|
-
headers: {
|
|
197
|
-
"X-API-Key": apiKey,
|
|
198
|
-
"Content-Type": "application/json",
|
|
199
|
-
},
|
|
200
|
-
body: JSON.stringify({
|
|
201
|
-
provider_name: appSlug,
|
|
202
|
-
}),
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
if (!res.ok) {
|
|
206
|
-
const text = await res.text();
|
|
207
|
-
console.error("AgentDojo OAuth init error:", res.status, text);
|
|
208
|
-
throw new Error(`Failed to initiate OAuth: ${text}`);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const data = await res.json();
|
|
212
|
-
const flowData = data.data || data;
|
|
213
|
-
|
|
214
|
-
if (!flowData.auth_url) {
|
|
215
|
-
throw new Error("No auth URL returned from OAuth init");
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return {
|
|
219
|
-
redirectUrl: flowData.auth_url,
|
|
220
|
-
connectionId: flowData.state_token || flowData.state || flowData.flow_id,
|
|
221
|
-
status: "pending",
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// API key flow: store credential directly
|
|
226
|
-
// Support arbitrary credential fields via credentials.fields, fall back to single api_key
|
|
227
|
-
const credentialData = credentials.fields && Object.keys(credentials.fields).length > 0
|
|
228
|
-
? credentials.fields
|
|
229
|
-
: { api_key: credentials.apiKey };
|
|
230
|
-
|
|
231
|
-
// Resolve toolkit slug to actual provider name/id — the credential API
|
|
232
|
-
// needs the provider (e.g. "pushover" id=26), not the toolkit slug
|
|
233
|
-
// (e.g. "pushover-notifications"). Fetch the toolkit to get auth_provider_id.
|
|
234
|
-
let providerName = appSlug;
|
|
235
|
-
let providerId: string | number = appSlug;
|
|
236
|
-
try {
|
|
237
|
-
const tkRes = await fetch(`${AGENTDOJO_API_BASE}/toolkits?include_tools=false`, {
|
|
238
|
-
headers: { "X-API-Key": apiKey, "Content-Type": "application/json" },
|
|
239
|
-
});
|
|
240
|
-
if (tkRes.ok) {
|
|
241
|
-
const tkData = await tkRes.json();
|
|
242
|
-
const toolkits = tkData.toolkits || tkData.data || [];
|
|
243
|
-
const toolkit = toolkits.find((t: any) => t.name === appSlug || t.slug === appSlug);
|
|
244
|
-
if (toolkit?.auth_provider_id) {
|
|
245
|
-
// Fetch provider details
|
|
246
|
-
const provRes = await fetch(`${AGENTDOJO_API_BASE}/providers?is_active=true`, {
|
|
247
|
-
headers: { "X-API-Key": apiKey, "Content-Type": "application/json" },
|
|
248
|
-
});
|
|
249
|
-
if (provRes.ok) {
|
|
250
|
-
const provData = await provRes.json();
|
|
251
|
-
const providers = provData.providers || provData.data || [];
|
|
252
|
-
const prov = providers.find((p: any) => p.id === toolkit.auth_provider_id);
|
|
253
|
-
if (prov) {
|
|
254
|
-
providerName = prov.name;
|
|
255
|
-
providerId = prov.id;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
} catch (e) {
|
|
261
|
-
console.warn("[AgentDojo] Failed to resolve provider for toolkit:", appSlug, e);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const credBody: Record<string, unknown> = {
|
|
265
|
-
name: providerName,
|
|
266
|
-
provider_id: providerId,
|
|
267
|
-
provider_name: providerName,
|
|
268
|
-
credential_data: credentialData,
|
|
269
|
-
};
|
|
270
|
-
console.log("[AgentDojo] Creating credential:", JSON.stringify(credBody));
|
|
271
|
-
const res = await fetch(`${AGENTDOJO_API_BASE}/credentials`, {
|
|
272
|
-
method: "POST",
|
|
273
|
-
headers: {
|
|
274
|
-
"X-API-Key": apiKey,
|
|
275
|
-
"Content-Type": "application/json",
|
|
276
|
-
},
|
|
277
|
-
body: JSON.stringify(credBody),
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
if (!res.ok) {
|
|
281
|
-
const text = await res.text();
|
|
282
|
-
console.error("AgentDojo credential create error:", res.status, text);
|
|
283
|
-
throw new Error(`Failed to store credentials: ${text}`);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const data = await res.json();
|
|
287
|
-
|
|
288
|
-
return {
|
|
289
|
-
redirectUrl: null,
|
|
290
|
-
connectionId: String(data.data?.id || data.id),
|
|
291
|
-
status: "active",
|
|
292
|
-
};
|
|
293
|
-
},
|
|
294
|
-
|
|
295
|
-
// Check connection/OAuth flow status
|
|
296
|
-
async getConnectionStatus(apiKey: string, connectionId: string): Promise<ConnectedAccount | null> {
|
|
297
|
-
// First try OAuth status poll (connectionId = state_token)
|
|
298
|
-
const oauthRes = await fetch(`${AGENTDOJO_API_BASE}/oauth/status?state=${encodeURIComponent(connectionId)}`, {
|
|
299
|
-
headers: {
|
|
300
|
-
"X-API-Key": apiKey,
|
|
301
|
-
"Content-Type": "application/json",
|
|
302
|
-
},
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
if (oauthRes.ok) {
|
|
306
|
-
const oauthData = await oauthRes.json();
|
|
307
|
-
const status = oauthData.data?.status || oauthData.status;
|
|
308
|
-
|
|
309
|
-
if (status === "completed") {
|
|
310
|
-
return {
|
|
311
|
-
id: connectionId,
|
|
312
|
-
appId: oauthData.data?.provider_name || oauthData.data?.provider_id || "",
|
|
313
|
-
appName: oauthData.data?.provider_name || "",
|
|
314
|
-
status: "active",
|
|
315
|
-
createdAt: new Date().toISOString(),
|
|
316
|
-
};
|
|
317
|
-
} else if (status === "failed") {
|
|
318
|
-
return {
|
|
319
|
-
id: connectionId,
|
|
320
|
-
appId: oauthData.data?.provider_name || "",
|
|
321
|
-
appName: oauthData.data?.provider_name || "",
|
|
322
|
-
status: "failed",
|
|
323
|
-
createdAt: new Date().toISOString(),
|
|
324
|
-
};
|
|
325
|
-
} else if (status === "pending") {
|
|
326
|
-
return null; // Still waiting
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Fallback: check credentials list directly (for API key connections)
|
|
331
|
-
const res = await fetch(`${AGENTDOJO_API_BASE}/credentials`, {
|
|
332
|
-
headers: {
|
|
333
|
-
"X-API-Key": apiKey,
|
|
334
|
-
"Content-Type": "application/json",
|
|
335
|
-
},
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
if (!res.ok) return null;
|
|
339
|
-
|
|
340
|
-
const data = await res.json();
|
|
341
|
-
const credentials = data.data || data.credentials || [];
|
|
342
|
-
const cred = credentials.find((c: any) => String(c.id) === connectionId);
|
|
343
|
-
|
|
344
|
-
if (!cred) return null;
|
|
345
|
-
|
|
346
|
-
return {
|
|
347
|
-
id: String(cred.id),
|
|
348
|
-
appId: String(cred.provider_id || cred.toolkit_id),
|
|
349
|
-
appName: cred.provider_name || cred.name || String(cred.provider_id),
|
|
350
|
-
status: "active",
|
|
351
|
-
createdAt: cred.created_at || new Date().toISOString(),
|
|
352
|
-
};
|
|
353
|
-
},
|
|
354
|
-
|
|
355
|
-
async disconnect(apiKey: string, connectionId: string): Promise<boolean> {
|
|
356
|
-
const res = await fetch(`${AGENTDOJO_API_BASE}/credentials/${connectionId}`, {
|
|
357
|
-
method: "DELETE",
|
|
358
|
-
headers: {
|
|
359
|
-
"X-API-Key": apiKey,
|
|
360
|
-
"Content-Type": "application/json",
|
|
361
|
-
},
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
return res.ok;
|
|
365
|
-
},
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
// ============ AgentDojo MCP Server Management ============
|
|
369
|
-
|
|
370
|
-
export interface AgentDojoServer {
|
|
371
|
-
id: string;
|
|
372
|
-
slug: string;
|
|
373
|
-
name: string;
|
|
374
|
-
description: string | null;
|
|
375
|
-
url: string;
|
|
376
|
-
tools: Array<{
|
|
377
|
-
id: string;
|
|
378
|
-
name: string;
|
|
379
|
-
description: string;
|
|
380
|
-
}>;
|
|
381
|
-
isActive: boolean;
|
|
382
|
-
createdAt: string;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
export interface AgentDojoToolkit {
|
|
386
|
-
id: string;
|
|
387
|
-
name: string;
|
|
388
|
-
displayName: string;
|
|
389
|
-
description: string | null;
|
|
390
|
-
iconUrl: string | null;
|
|
391
|
-
toolsCount: number;
|
|
392
|
-
tools?: Array<{
|
|
393
|
-
id: string;
|
|
394
|
-
name: string;
|
|
395
|
-
displayName: string;
|
|
396
|
-
description: string;
|
|
397
|
-
}>;
|
|
398
|
-
status: string;
|
|
399
|
-
requiresAuth: boolean;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// List available toolkits
|
|
403
|
-
export async function listToolkits(apiKey: string, includeTools = false): Promise<AgentDojoToolkit[]> {
|
|
404
|
-
const res = await fetch(
|
|
405
|
-
`${AGENTDOJO_API_BASE}/toolkits?include_tools=${includeTools}`,
|
|
406
|
-
{
|
|
407
|
-
headers: {
|
|
408
|
-
"X-API-Key": apiKey,
|
|
409
|
-
"Content-Type": "application/json",
|
|
410
|
-
},
|
|
411
|
-
}
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
if (!res.ok) {
|
|
415
|
-
console.error("Failed to list AgentDojo toolkits:", await res.text());
|
|
416
|
-
return [];
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
const data = await res.json();
|
|
420
|
-
const toolkits = data.toolkits || [];
|
|
421
|
-
|
|
422
|
-
return toolkits.map((t: any) => ({
|
|
423
|
-
id: t.id,
|
|
424
|
-
name: t.name,
|
|
425
|
-
displayName: t.display_name || t.name,
|
|
426
|
-
description: t.description,
|
|
427
|
-
iconUrl: t.icon_url,
|
|
428
|
-
toolsCount: t.tools_count || t.tools?.length || 0,
|
|
429
|
-
tools: t.tools?.map((tool: any) => ({
|
|
430
|
-
id: tool.id,
|
|
431
|
-
name: tool.name,
|
|
432
|
-
displayName: tool.display_name || tool.name,
|
|
433
|
-
description: tool.description,
|
|
434
|
-
})),
|
|
435
|
-
status: t.status || "active",
|
|
436
|
-
requiresAuth: t.requires_auth || false,
|
|
437
|
-
}));
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// List user's MCP servers (configs)
|
|
441
|
-
export async function listServers(apiKey: string, includeTools = false): Promise<AgentDojoServer[]> {
|
|
442
|
-
const res = await fetch(
|
|
443
|
-
`${AGENTDOJO_API_BASE}/servers?include_tools=${includeTools}`,
|
|
444
|
-
{
|
|
445
|
-
headers: {
|
|
446
|
-
"X-API-Key": apiKey,
|
|
447
|
-
"Content-Type": "application/json",
|
|
448
|
-
},
|
|
449
|
-
}
|
|
450
|
-
);
|
|
451
|
-
|
|
452
|
-
if (!res.ok) {
|
|
453
|
-
console.error("Failed to list AgentDojo servers:", await res.text());
|
|
454
|
-
return [];
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
const data = await res.json();
|
|
458
|
-
const servers = data.data || [];
|
|
459
|
-
|
|
460
|
-
return servers.map((s: any) => ({
|
|
461
|
-
id: s.id,
|
|
462
|
-
slug: s.slug,
|
|
463
|
-
name: s.name,
|
|
464
|
-
description: s.description,
|
|
465
|
-
url: s.url,
|
|
466
|
-
tools: s.tools || [],
|
|
467
|
-
isActive: s.is_active,
|
|
468
|
-
createdAt: s.created_at,
|
|
469
|
-
}));
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// Create a new MCP server with selected toolkits
|
|
473
|
-
export async function createServer(
|
|
474
|
-
apiKey: string,
|
|
475
|
-
name: string,
|
|
476
|
-
toolkits: string[],
|
|
477
|
-
description?: string
|
|
478
|
-
): Promise<AgentDojoServer | null> {
|
|
479
|
-
const res = await fetch(`${AGENTDOJO_API_BASE}/servers`, {
|
|
480
|
-
method: "POST",
|
|
481
|
-
headers: {
|
|
482
|
-
"X-API-Key": apiKey,
|
|
483
|
-
"Content-Type": "application/json",
|
|
484
|
-
},
|
|
485
|
-
body: JSON.stringify({
|
|
486
|
-
name,
|
|
487
|
-
toolkits,
|
|
488
|
-
description,
|
|
489
|
-
}),
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
if (!res.ok) {
|
|
493
|
-
const errText = await res.text();
|
|
494
|
-
console.error("Failed to create AgentDojo server:", errText);
|
|
495
|
-
throw new Error(`Failed to create server: ${errText}`);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
const data = await res.json();
|
|
499
|
-
const server = data.data || data;
|
|
500
|
-
|
|
501
|
-
return {
|
|
502
|
-
id: server.id,
|
|
503
|
-
slug: server.slug,
|
|
504
|
-
name: server.name,
|
|
505
|
-
description: server.description,
|
|
506
|
-
url: server.url,
|
|
507
|
-
tools: server.tools || [],
|
|
508
|
-
isActive: server.is_active ?? true,
|
|
509
|
-
createdAt: server.created_at,
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
// Get a specific server
|
|
514
|
-
export async function getServer(apiKey: string, serverId: string): Promise<AgentDojoServer | null> {
|
|
515
|
-
const res = await fetch(`${AGENTDOJO_API_BASE}/servers/${serverId}`, {
|
|
516
|
-
headers: {
|
|
517
|
-
"X-API-Key": apiKey,
|
|
518
|
-
"Content-Type": "application/json",
|
|
519
|
-
},
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
if (!res.ok) {
|
|
523
|
-
if (res.status === 404) return null;
|
|
524
|
-
console.error("Failed to get AgentDojo server:", await res.text());
|
|
525
|
-
return null;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
const data = await res.json();
|
|
529
|
-
const server = data.data || data;
|
|
530
|
-
|
|
531
|
-
return {
|
|
532
|
-
id: server.id,
|
|
533
|
-
slug: server.slug,
|
|
534
|
-
name: server.name,
|
|
535
|
-
description: server.description,
|
|
536
|
-
url: server.url,
|
|
537
|
-
tools: server.tools || [],
|
|
538
|
-
isActive: server.is_active ?? true,
|
|
539
|
-
createdAt: server.created_at,
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
// Delete a server
|
|
544
|
-
export async function deleteServer(apiKey: string, serverId: string): Promise<boolean> {
|
|
545
|
-
const res = await fetch(`${AGENTDOJO_API_BASE}/servers/${serverId}`, {
|
|
546
|
-
method: "DELETE",
|
|
547
|
-
headers: {
|
|
548
|
-
"X-API-Key": apiKey,
|
|
549
|
-
"Content-Type": "application/json",
|
|
550
|
-
},
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
return res.ok;
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
// Get the base URL for constructing MCP server URLs
|
|
557
|
-
export function getBaseUrl(): string {
|
|
558
|
-
return AGENTDOJO_API_BASE;
|
|
559
|
-
}
|