@dainprotocol/service-sdk 2.0.53 → 2.0.55
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 +78 -0
- package/dist/client/client.d.ts +14 -1
- package/dist/client/client.js +21 -2
- package/dist/client/client.js.map +1 -1
- package/dist/client/types.d.ts +38 -0
- package/dist/client/types.js +35 -1
- package/dist/client/types.js.map +1 -1
- package/dist/lib/schemaStructure.d.ts +2 -1
- package/dist/lib/schemaStructure.js +25 -11
- package/dist/lib/schemaStructure.js.map +1 -1
- package/dist/service/actionable-tools.d.ts +135 -0
- package/dist/service/actionable-tools.js +144 -0
- package/dist/service/actionable-tools.js.map +1 -0
- package/dist/service/direct-auth-setup.d.ts +154 -0
- package/dist/service/direct-auth-setup.js +308 -0
- package/dist/service/direct-auth-setup.js.map +1 -0
- package/dist/service/index.d.ts +3 -1
- package/dist/service/index.js +10 -1
- package/dist/service/index.js.map +1 -1
- package/dist/service/nodeService.js +2 -0
- package/dist/service/nodeService.js.map +1 -1
- package/dist/service/oauth2.d.ts +40 -1
- package/dist/service/oauth2.js +46 -0
- package/dist/service/oauth2.js.map +1 -1
- package/dist/service/oauth2Manager.d.ts +31 -4
- package/dist/service/oauth2Manager.js +119 -8
- package/dist/service/oauth2Manager.js.map +1 -1
- package/dist/service/server.js +93 -19
- package/dist/service/server.js.map +1 -1
- package/dist/service/service.js +6 -1
- package/dist/service/service.js.map +1 -1
- package/dist/service/types.d.ts +59 -0
- package/package.json +1 -1
|
@@ -2,17 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OAuth2Manager = void 0;
|
|
4
4
|
const oauth2_token_manager_1 = require("@dainprotocol/oauth2-token-manager");
|
|
5
|
+
const direct_auth_setup_1 = require("./direct-auth-setup");
|
|
5
6
|
/**
|
|
6
7
|
* OAuth2Manager - A clean integration with @dainprotocol/oauth2-token-manager
|
|
8
|
+
* Supports both OAuth2 and direct configuration providers
|
|
7
9
|
*/
|
|
8
10
|
class OAuth2Manager {
|
|
9
11
|
client;
|
|
12
|
+
setupManager;
|
|
13
|
+
storage;
|
|
10
14
|
baseUrl;
|
|
11
15
|
providerConfigs = {};
|
|
16
|
+
directProviders = new Map();
|
|
12
17
|
constructor(baseUrl, storage) {
|
|
13
18
|
this.baseUrl = baseUrl;
|
|
19
|
+
this.storage = storage || new oauth2_token_manager_1.InMemoryStorageAdapter();
|
|
14
20
|
this.client = new oauth2_token_manager_1.OAuth2Client({
|
|
15
|
-
storage: storage
|
|
21
|
+
storage: this.storage,
|
|
16
22
|
// Ensure auto-refresh is enabled with appropriate settings
|
|
17
23
|
autoRefresh: {
|
|
18
24
|
enabled: true,
|
|
@@ -22,13 +28,14 @@ class OAuth2Manager {
|
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
});
|
|
31
|
+
this.setupManager = new direct_auth_setup_1.DirectAuthSetupManager(this.storage);
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
27
|
-
* Register
|
|
34
|
+
* Register an OAuth2 provider
|
|
28
35
|
*/
|
|
29
36
|
registerProvider(name, config) {
|
|
30
|
-
// Store
|
|
31
|
-
this.providerConfigs[name] = config;
|
|
37
|
+
// Store with type discriminator
|
|
38
|
+
this.providerConfigs[name] = { ...config, type: 'oauth2' };
|
|
32
39
|
// Convert to OAuth2Config format expected by the library
|
|
33
40
|
const oauth2Config = {
|
|
34
41
|
clientId: config.clientId,
|
|
@@ -56,6 +63,16 @@ class OAuth2Manager {
|
|
|
56
63
|
};
|
|
57
64
|
this.client.registerProvider(name, oauth2Config);
|
|
58
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Register a direct configuration provider (non-OAuth2)
|
|
68
|
+
* Users provide config directly (e.g., Telegram chat ID) without external OAuth flow
|
|
69
|
+
*/
|
|
70
|
+
registerDirectProvider(name, config) {
|
|
71
|
+
// Store with type discriminator - no OAuth2Client registration needed
|
|
72
|
+
this.providerConfigs[name] = { ...config, type: 'direct' };
|
|
73
|
+
// Track separately for automatic context generation
|
|
74
|
+
this.directProviders.set(name, config);
|
|
75
|
+
}
|
|
59
76
|
/**
|
|
60
77
|
* Generate authorization URL
|
|
61
78
|
*/
|
|
@@ -121,16 +138,30 @@ class OAuth2Manager {
|
|
|
121
138
|
await this.client.deleteToken(provider, `${agentId}@dain.local`);
|
|
122
139
|
}
|
|
123
140
|
/**
|
|
124
|
-
* Get all configured providers
|
|
141
|
+
* Get all configured OAuth2 providers (legacy - returns only OAuth2, not direct providers)
|
|
142
|
+
* @deprecated Use getAuthenticationProviders() for full provider list
|
|
125
143
|
*/
|
|
126
144
|
getProviders() {
|
|
127
|
-
|
|
145
|
+
const oauth2Only = {};
|
|
146
|
+
for (const [name, config] of Object.entries(this.providerConfigs)) {
|
|
147
|
+
if (config.type === 'oauth2') {
|
|
148
|
+
const { type, ...oauth2Config } = config;
|
|
149
|
+
oauth2Only[name] = oauth2Config;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return oauth2Only;
|
|
128
153
|
}
|
|
129
154
|
/**
|
|
130
|
-
* Get a specific provider config
|
|
155
|
+
* Get a specific OAuth2 provider config (legacy - only returns OAuth2 providers)
|
|
156
|
+
* @deprecated Use getAuthenticationProviders() for full provider info
|
|
131
157
|
*/
|
|
132
158
|
getProvider(name) {
|
|
133
|
-
|
|
159
|
+
const config = this.providerConfigs[name];
|
|
160
|
+
if (config && config.type === 'oauth2') {
|
|
161
|
+
const { type, ...oauth2Config } = config;
|
|
162
|
+
return oauth2Config;
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
134
165
|
}
|
|
135
166
|
/**
|
|
136
167
|
* Get all accounts (tokens) for a user and provider with auto-refresh
|
|
@@ -153,6 +184,86 @@ class OAuth2Manager {
|
|
|
153
184
|
return [];
|
|
154
185
|
}
|
|
155
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Get all authentication providers (OAuth2 + Direct) with connection status
|
|
189
|
+
* Returns unified provider information with type discrimination
|
|
190
|
+
*
|
|
191
|
+
* @param agentId Agent/user ID
|
|
192
|
+
* @returns Array of provider info with auth methods
|
|
193
|
+
*/
|
|
194
|
+
async getAuthenticationProviders(agentId) {
|
|
195
|
+
const results = [];
|
|
196
|
+
for (const [name, config] of Object.entries(this.providerConfigs)) {
|
|
197
|
+
const connected = await this.hasValidTokens(name, agentId);
|
|
198
|
+
const baseInfo = {
|
|
199
|
+
name,
|
|
200
|
+
type: config.type,
|
|
201
|
+
connected,
|
|
202
|
+
reason: config.reason,
|
|
203
|
+
requiredTools: config.requiredTools,
|
|
204
|
+
scopes: config.scopes,
|
|
205
|
+
logoUrl: config.logoUrl,
|
|
206
|
+
};
|
|
207
|
+
if (config.type === 'oauth2') {
|
|
208
|
+
// OAuth2 provider - generate auth URL if not connected
|
|
209
|
+
results.push({
|
|
210
|
+
...baseInfo,
|
|
211
|
+
authMethod: connected ? null : {
|
|
212
|
+
type: 'oauth2',
|
|
213
|
+
authUrl: await this.generateAuthUrl(name, agentId)
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
else if (config.type === 'direct') {
|
|
218
|
+
// Direct provider - return onboarding tool if not connected
|
|
219
|
+
results.push({
|
|
220
|
+
...baseInfo,
|
|
221
|
+
authMethod: connected ? null : {
|
|
222
|
+
type: 'direct',
|
|
223
|
+
onboardingTool: config.onboardingTool
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return results;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get auto-generated contexts for direct providers
|
|
232
|
+
* Automatically creates contexts that expose setup values to AI
|
|
233
|
+
*
|
|
234
|
+
* @returns Array of ServiceContext objects, one per direct provider
|
|
235
|
+
*/
|
|
236
|
+
getDirectProviderContexts() {
|
|
237
|
+
const contexts = [];
|
|
238
|
+
for (const [providerName, config] of this.directProviders) {
|
|
239
|
+
contexts.push({
|
|
240
|
+
id: `${providerName}-config`,
|
|
241
|
+
name: `${config.reason || providerName} Configuration`,
|
|
242
|
+
description: `Auto-generated context for ${providerName} setup values. Access via {{config.${providerName}}}`,
|
|
243
|
+
getContextData: async (agentInfo, extraData) => {
|
|
244
|
+
try {
|
|
245
|
+
const oauth2Client = extraData?.oauth2Client;
|
|
246
|
+
if (!oauth2Client) {
|
|
247
|
+
return {};
|
|
248
|
+
}
|
|
249
|
+
// Query token storage for this provider's metadata
|
|
250
|
+
const tokens = await oauth2Client.getTokensByUserId(agentInfo.id);
|
|
251
|
+
const providerToken = tokens?.find((t) => t.provider === providerName);
|
|
252
|
+
if (!providerToken?.metadata) {
|
|
253
|
+
return {};
|
|
254
|
+
}
|
|
255
|
+
// Return metadata as context (e.g., { chatId: "123456" } for Telegram)
|
|
256
|
+
return providerToken.metadata;
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
console.error(`[OAuth2Manager] Failed to get context for ${providerName}:`, error);
|
|
260
|
+
return {};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return contexts;
|
|
266
|
+
}
|
|
156
267
|
}
|
|
157
268
|
exports.OAuth2Manager = OAuth2Manager;
|
|
158
269
|
//# sourceMappingURL=oauth2Manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth2Manager.js","sourceRoot":"","sources":["../../src/service/oauth2Manager.ts"],"names":[],"mappings":";;;AAAA,6EAQ4C;
|
|
1
|
+
{"version":3,"file":"oauth2Manager.js","sourceRoot":"","sources":["../../src/service/oauth2Manager.ts"],"names":[],"mappings":";;;AAAA,6EAQ4C;AAU5C,2DAA6D;AAG7D;;;GAGG;AACH,MAAa,aAAa;IACR,MAAM,CAAe;IACrB,YAAY,CAAyB;IACrC,OAAO,CAAiB;IAChC,OAAO,CAAS;IAChB,eAAe,GAAuC,EAAE,CAAC;IACzD,eAAe,GAAsC,IAAI,GAAG,EAAE,CAAC;IAEvE,YAA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er(config, tools, services, toolboxes, metadata, privateKe
|
|
|
310
310
|
}
|
|
311
311
|
// Setup default ping route
|
|
312
312
|
app.get("/ping", (c) => c.json({ message: "pong", platform: "DAIN", service_version: metadata.version, dain_sdk_version: package_json_1.default.version }));
|
|
313
|
-
// Metadata endpoint
|
|
314
|
-
app.get("/metadata", (c) =>
|
|
313
|
+
// Metadata endpoint - includes computed supportsUserActions from tools
|
|
314
|
+
app.get("/metadata", (c) => {
|
|
315
|
+
// Compute service-level capability: does ANY tool support user actions (HITL)?
|
|
316
|
+
const supportsUserActions = tools.some((tool) => tool.supportsUserActions === true);
|
|
317
|
+
return c.json({
|
|
318
|
+
...metadata,
|
|
319
|
+
supportsUserActions,
|
|
320
|
+
});
|
|
321
|
+
});
|
|
315
322
|
// Tools list endpoint
|
|
316
323
|
app.get("/tools", (c) => {
|
|
317
324
|
const toolInfo = tools.map((tool) => {
|
|
@@ -328,6 +335,7 @@ function setupHttpServer(config, tools, services, toolboxes, metadata, privateKe
|
|
|
328
335
|
outputSchema,
|
|
329
336
|
interface: tool.interface,
|
|
330
337
|
suggestConfirmation: tool.suggestConfirmation,
|
|
338
|
+
supportsUserActions: tool.supportsUserActions,
|
|
331
339
|
};
|
|
332
340
|
});
|
|
333
341
|
console.log(`[Service SDK Server] Returning ${toolInfo.length} tools`);
|
|
@@ -346,7 +354,10 @@ function setupHttpServer(config, tools, services, toolboxes, metadata, privateKe
|
|
|
346
354
|
}
|
|
347
355
|
// Process plugins for the request
|
|
348
356
|
const processedPluginData = await processPluginsForRequest(body, agentInfo);
|
|
349
|
-
|
|
357
|
+
// Merge manual contexts with auto-generated direct provider contexts
|
|
358
|
+
const autoContexts = app.oauth2?.getDirectProviderContexts?.() || [];
|
|
359
|
+
const allContexts = [...contexts, ...autoContexts];
|
|
360
|
+
const contextInfo = allContexts.map((context) => ({
|
|
350
361
|
id: context.id,
|
|
351
362
|
name: context.name,
|
|
352
363
|
description: context.description,
|
|
@@ -357,7 +368,10 @@ function setupHttpServer(config, tools, services, toolboxes, metadata, privateKe
|
|
|
357
368
|
});
|
|
358
369
|
// Primary endpoint for getting a context's data with plugin support
|
|
359
370
|
app.post("/contexts/:contextId", async (c) => {
|
|
360
|
-
|
|
371
|
+
// Merge manual contexts with auto-generated direct provider contexts
|
|
372
|
+
const autoContexts = app.oauth2?.getDirectProviderContexts?.() || [];
|
|
373
|
+
const allContexts = [...contexts, ...autoContexts];
|
|
374
|
+
const context = allContexts.find((context) => context.id === c.req.param("contextId"));
|
|
361
375
|
if (context) {
|
|
362
376
|
const agentInfo = await getAgentInfo(c);
|
|
363
377
|
// Get plugin data from request body
|
|
@@ -407,8 +421,11 @@ function setupHttpServer(config, tools, services, toolboxes, metadata, privateKe
|
|
|
407
421
|
const processedPluginData = await processPluginsForRequest(body, agentInfo);
|
|
408
422
|
// Get oauth2 client if available
|
|
409
423
|
const oauth2Client = app.oauth2 ? app.oauth2.getClient() : undefined;
|
|
424
|
+
// Merge manual contexts with auto-generated direct provider contexts
|
|
425
|
+
const autoContexts = app.oauth2?.getDirectProviderContexts?.() || [];
|
|
426
|
+
const allContexts = [...contexts, ...autoContexts];
|
|
410
427
|
// Get all contexts with plugins and oauth2Client
|
|
411
|
-
const contextsFull = await Promise.all(
|
|
428
|
+
const contextsFull = await Promise.all(allContexts.map(async (context) => ({
|
|
412
429
|
id: context.id,
|
|
413
430
|
name: context.name,
|
|
414
431
|
description: context.description,
|
|
@@ -483,7 +500,8 @@ function setupHttpServer(config, tools, services, toolboxes, metadata, privateKe
|
|
|
483
500
|
return null;
|
|
484
501
|
const widgetData = await widget.getWidget(agentInfo, {
|
|
485
502
|
plugins: processedPluginData.plugins,
|
|
486
|
-
oauth2Client: oauth2Client
|
|
503
|
+
oauth2Client: oauth2Client,
|
|
504
|
+
app: app // Pass app for access to setupManager via app.oauth2.getSetupManager()
|
|
487
505
|
});
|
|
488
506
|
return {
|
|
489
507
|
id: widget.id,
|
|
@@ -544,7 +562,8 @@ function setupHttpServer(config, tools, services, toolboxes, metadata, privateKe
|
|
|
544
562
|
const oauth2Client = app.oauth2 ? app.oauth2.getClient() : undefined;
|
|
545
563
|
const widgetData = await widget.getWidget(agentInfo, {
|
|
546
564
|
plugins: processedPluginData.plugins,
|
|
547
|
-
oauth2Client: oauth2Client
|
|
565
|
+
oauth2Client: oauth2Client,
|
|
566
|
+
app: app // Pass app for access to setupManager via app.oauth2.getSetupManager()
|
|
548
567
|
});
|
|
549
568
|
// Create the response
|
|
550
569
|
const response = {
|
|
@@ -809,6 +828,7 @@ function setupHttpServer(config, tools, services, toolboxes, metadata, privateKe
|
|
|
809
828
|
outputSchema,
|
|
810
829
|
interface: tool.interface,
|
|
811
830
|
suggestConfirmation: tool.suggestConfirmation,
|
|
831
|
+
supportsUserActions: tool.supportsUserActions,
|
|
812
832
|
};
|
|
813
833
|
});
|
|
814
834
|
console.log(`[getAllToolsAsJsonSchema GET] Returning ${toolInfo.length} tools`);
|
|
@@ -869,6 +889,7 @@ function setupHttpServer(config, tools, services, toolboxes, metadata, privateKe
|
|
|
869
889
|
outputSchema,
|
|
870
890
|
interface: tool.interface,
|
|
871
891
|
suggestConfirmation: tool.suggestConfirmation,
|
|
892
|
+
supportsUserActions: tool.supportsUserActions,
|
|
872
893
|
};
|
|
873
894
|
});
|
|
874
895
|
const response = {
|
|
@@ -1049,26 +1070,36 @@ function setupHttpServer(config, tools, services, toolboxes, metadata, privateKe
|
|
|
1049
1070
|
if (config.routes) {
|
|
1050
1071
|
config.routes(app);
|
|
1051
1072
|
}
|
|
1052
|
-
if
|
|
1073
|
+
// Initialize OAuth2/DirectAuth if either providers or directProviders are configured
|
|
1074
|
+
if (config.oauth2?.providers || config.oauth2?.directProviders) {
|
|
1053
1075
|
if (!config.oauth2?.baseUrl) {
|
|
1054
|
-
throw new Error("config.oauth2.baseUrl is required for OAuth2");
|
|
1076
|
+
throw new Error("config.oauth2.baseUrl is required for OAuth2/DirectAuth");
|
|
1055
1077
|
}
|
|
1056
1078
|
const oauth2Handler = new oauth2_1.OAuth2Handler(bs58_1.default.encode(privateKey), config.oauth2.baseUrl, config.oauth2.tokenStore);
|
|
1057
1079
|
// Auto-generate service slug from metadata title
|
|
1058
1080
|
const serviceSlug = (0, core_1.toSlug)(metadata.title);
|
|
1059
1081
|
// Register providers and auto-create OAuth tools
|
|
1060
1082
|
const autoOAuth2Tools = [];
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1083
|
+
if (config.oauth2.providers) {
|
|
1084
|
+
Object.entries(config.oauth2.providers).forEach(([providerName, providerConfig]) => {
|
|
1085
|
+
oauth2Handler.registerProvider(providerName, providerConfig);
|
|
1086
|
+
// Auto-create OAuth tool for this provider
|
|
1087
|
+
debugLog(`[OAuth Auto-Registration] Creating OAuth tool: oauth2-${serviceSlug}-${providerName}`);
|
|
1088
|
+
const oauthTool = (0, core_1.createOAuth2Tool)(providerName, serviceSlug, {
|
|
1089
|
+
logoUrl: providerConfig.logoUrl,
|
|
1090
|
+
reason: providerConfig.reason,
|
|
1091
|
+
requiredTools: providerConfig.requiredTools
|
|
1092
|
+
});
|
|
1093
|
+
autoOAuth2Tools.push(oauthTool);
|
|
1069
1094
|
});
|
|
1070
|
-
|
|
1071
|
-
|
|
1095
|
+
}
|
|
1096
|
+
// Register direct providers (non-OAuth2)
|
|
1097
|
+
if (config.oauth2.directProviders) {
|
|
1098
|
+
Object.entries(config.oauth2.directProviders).forEach(([providerName, providerConfig]) => {
|
|
1099
|
+
oauth2Handler.registerDirectProvider(providerName, providerConfig);
|
|
1100
|
+
debugLog(`[Direct Provider Auto-Registration] Registered direct provider: ${providerName} with onboarding tool: ${providerConfig.onboardingTool}`);
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1072
1103
|
// Inject auto-created OAuth tools into the tools array
|
|
1073
1104
|
if (autoOAuth2Tools.length > 0) {
|
|
1074
1105
|
debugLog(`[OAuth Auto-Registration] Injecting ${autoOAuth2Tools.length} OAuth tool(s) into tools array`);
|
|
@@ -1150,6 +1181,15 @@ function setupHttpServer(config, tools, services, toolboxes, metadata, privateKe
|
|
|
1150
1181
|
})));
|
|
1151
1182
|
return c.json(providersWithStatus);
|
|
1152
1183
|
});
|
|
1184
|
+
// Get all authentication providers (OAuth2 + Direct) with unified info
|
|
1185
|
+
app.get("/oauth2/authentication-providers", async (c) => {
|
|
1186
|
+
if (!app.oauth2) {
|
|
1187
|
+
return c.json([]);
|
|
1188
|
+
}
|
|
1189
|
+
const agentInfo = await getAgentInfo(c);
|
|
1190
|
+
const providers = await app.oauth2.getAuthenticationProviders(agentInfo.id);
|
|
1191
|
+
return c.json(providers);
|
|
1192
|
+
});
|
|
1153
1193
|
// Get auth URL for specific provider
|
|
1154
1194
|
app.get("/oauth2/connect/:provider", async (c) => {
|
|
1155
1195
|
debugLog("[OAuth2 Connect] Route hit - START");
|
|
@@ -1189,6 +1229,40 @@ function setupHttpServer(config, tools, services, toolboxes, metadata, privateKe
|
|
|
1189
1229
|
});
|
|
1190
1230
|
}
|
|
1191
1231
|
});
|
|
1232
|
+
// Direct auth setup status polling endpoint (RFC 8628 Device Authorization Grant pattern)
|
|
1233
|
+
// Used when user completes authorization on external device/app (e.g., Telegram bot)
|
|
1234
|
+
app.get("/oauth2/direct-setup-status/:provider", async (c) => {
|
|
1235
|
+
if (!app.oauth2) {
|
|
1236
|
+
throw new http_exception_1.HTTPException(404, { message: "OAuth2 not configured" });
|
|
1237
|
+
}
|
|
1238
|
+
const provider = c.req.param("provider");
|
|
1239
|
+
const agentInfo = await getAgentInfo(c);
|
|
1240
|
+
const setupManager = app.oauth2.getSetupManager();
|
|
1241
|
+
// Check if setup is already complete
|
|
1242
|
+
const isComplete = await setupManager.isSetupComplete(agentInfo.id, provider);
|
|
1243
|
+
if (isComplete) {
|
|
1244
|
+
const config = await setupManager.getProviderConfig(agentInfo.id, provider);
|
|
1245
|
+
return c.json({
|
|
1246
|
+
status: 'complete',
|
|
1247
|
+
config: config ? { configuredAt: config.configuredAt } : undefined
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
// Check if there's a pending setup
|
|
1251
|
+
const pendingSetup = await setupManager.getPendingSetup(agentInfo.id, provider);
|
|
1252
|
+
if (pendingSetup) {
|
|
1253
|
+
const expiresIn = Math.max(0, Math.floor((pendingSetup.expiresAt - Date.now()) / 1000));
|
|
1254
|
+
return c.json({
|
|
1255
|
+
status: 'authorization_pending',
|
|
1256
|
+
expires_in: expiresIn,
|
|
1257
|
+
interval: 5 // Poll every 5 seconds
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
// No setup in progress
|
|
1261
|
+
return c.json({
|
|
1262
|
+
status: 'not_found',
|
|
1263
|
+
error: 'No setup in progress for this provider'
|
|
1264
|
+
});
|
|
1265
|
+
});
|
|
1192
1266
|
// Get all human actions for a process
|
|
1193
1267
|
app.get("/processes/:processId/human-actions", async (c) => {
|
|
1194
1268
|
const processId = c.req.param("processId");
|