@slashfi/agents-sdk 0.11.2 → 0.13.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.
- package/dist/agent-definitions/auth.d.ts +17 -1
- package/dist/agent-definitions/auth.d.ts.map +1 -1
- package/dist/agent-definitions/auth.js +123 -4
- package/dist/agent-definitions/auth.js.map +1 -1
- package/dist/agent-definitions/integrations.d.ts +2 -14
- package/dist/agent-definitions/integrations.d.ts.map +1 -1
- package/dist/agent-definitions/integrations.js +64 -19
- package/dist/agent-definitions/integrations.js.map +1 -1
- package/dist/agent-definitions/remote-registry.d.ts +19 -14
- package/dist/agent-definitions/remote-registry.d.ts.map +1 -1
- package/dist/agent-definitions/remote-registry.js +219 -381
- package/dist/agent-definitions/remote-registry.js.map +1 -1
- package/dist/agent-definitions/users.d.ts.map +1 -1
- package/dist/agent-definitions/users.js +29 -1
- package/dist/agent-definitions/users.js.map +1 -1
- package/dist/define.d.ts +6 -4
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +82 -3
- package/dist/define.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/jwt.js +1 -1
- package/dist/jwt.js.map +1 -1
- package/dist/key-manager.d.ts +76 -0
- package/dist/key-manager.d.ts.map +1 -0
- package/dist/key-manager.js +156 -0
- package/dist/key-manager.js.map +1 -0
- package/dist/server.d.ts +39 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +228 -52
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +53 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/agent-definitions/auth.ts +165 -6
- package/src/agent-definitions/integrations.ts +59 -28
- package/src/agent-definitions/remote-registry.ts +219 -513
- package/src/agent-definitions/users.ts +35 -1
- package/src/define.ts +98 -6
- package/src/index.ts +3 -1
- package/src/jwt.ts +1 -1
- package/src/key-manager.test.ts +273 -0
- package/src/key-manager.ts +257 -0
- package/src/server.test.ts +284 -0
- package/src/server.ts +334 -60
- package/src/types.ts +44 -1
|
@@ -342,7 +342,10 @@ export async function exchangeCodeForToken(
|
|
|
342
342
|
throw new Error(`Token exchange failed (${response.status}): ${text}`);
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
-
const
|
|
345
|
+
const responseText = await response.text();
|
|
346
|
+
console.log("[token-exchange] Slack response:", responseText.substring(0, 500));
|
|
347
|
+
let data: Record<string, unknown>;
|
|
348
|
+
try { data = JSON.parse(responseText); } catch (e) { throw new Error(`Failed to parse JSON: ${responseText.substring(0, 200)}`); }
|
|
346
349
|
|
|
347
350
|
return {
|
|
348
351
|
accessToken: String(data[oauth.accessTokenField ?? "access_token"] ?? ""),
|
|
@@ -408,7 +411,10 @@ export async function refreshAccessToken(
|
|
|
408
411
|
throw new Error(`Token refresh failed (${response.status}): ${text}`);
|
|
409
412
|
}
|
|
410
413
|
|
|
411
|
-
const
|
|
414
|
+
const responseText = await response.text();
|
|
415
|
+
console.log("[token-exchange] Slack response:", responseText.substring(0, 500));
|
|
416
|
+
let data: Record<string, unknown>;
|
|
417
|
+
try { data = JSON.parse(responseText); } catch (e) { throw new Error(`Failed to parse JSON: ${responseText.substring(0, 200)}`); }
|
|
412
418
|
|
|
413
419
|
return {
|
|
414
420
|
accessToken: String(data[oauth.accessTokenField ?? "access_token"] ?? ""),
|
|
@@ -489,21 +495,13 @@ export interface IntegrationsAgentOptions {
|
|
|
489
495
|
store: IntegrationStore;
|
|
490
496
|
|
|
491
497
|
/**
|
|
492
|
-
* Callback to list all registered agents.
|
|
493
|
-
* Used by list_integrations to discover agents with integrationMethods.
|
|
494
|
-
* Typically wired to registry.list().
|
|
495
|
-
*/
|
|
496
|
-
getAgents?: () => AgentDefinition[];
|
|
497
498
|
|
|
498
499
|
/** Registry instance for calling other agents' internal tools */
|
|
499
500
|
registry?: {
|
|
501
|
+
list?(): AgentDefinition[];
|
|
500
502
|
call(request: any): Promise<any>;
|
|
501
503
|
};
|
|
502
504
|
|
|
503
|
-
/** Integrations store for tracking installed integrations */
|
|
504
|
-
integrationsStore?: {
|
|
505
|
-
create(input: { agentPath: string; config: Record<string, unknown>; installedBy?: string; tenantId?: string }): Promise<any>;
|
|
506
|
-
};
|
|
507
505
|
|
|
508
506
|
/** Secret store for storing/resolving client credentials and tokens */
|
|
509
507
|
secretStore: {
|
|
@@ -535,7 +533,7 @@ const SYSTEM_OWNER = "__integrations__";
|
|
|
535
533
|
export function createIntegrationsAgent(
|
|
536
534
|
options: IntegrationsAgentOptions,
|
|
537
535
|
): AgentDefinition {
|
|
538
|
-
const { store, callbackBaseUrl, secretStore
|
|
536
|
+
const { store, callbackBaseUrl, secretStore } = options;
|
|
539
537
|
|
|
540
538
|
// ---- setup_integration ----
|
|
541
539
|
const setupTool = defineTool({
|
|
@@ -681,15 +679,20 @@ export function createIntegrationsAgent(
|
|
|
681
679
|
|
|
682
680
|
await store.upsertProvider(config);
|
|
683
681
|
|
|
684
|
-
//
|
|
685
|
-
if (
|
|
682
|
+
// Delegate to agent's setup_integration tool via registry.call()
|
|
683
|
+
if (config.agentPath && options.registry) {
|
|
686
684
|
try {
|
|
687
|
-
await
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
685
|
+
const setupResult = await options.registry.call({
|
|
686
|
+
action: 'execute_tool',
|
|
687
|
+
path: config.agentPath,
|
|
688
|
+
tool: 'setup_integration',
|
|
689
|
+
params: input.config ?? input,
|
|
690
|
+
callerType: 'system',
|
|
691
691
|
});
|
|
692
|
-
|
|
692
|
+
result.setupResult = (setupResult as any)?.result ?? setupResult;
|
|
693
|
+
} catch (err) {
|
|
694
|
+
result.setupError = err instanceof Error ? err.message : String(err);
|
|
695
|
+
}
|
|
693
696
|
}
|
|
694
697
|
|
|
695
698
|
result.provider = config;
|
|
@@ -736,8 +739,8 @@ export function createIntegrationsAgent(
|
|
|
736
739
|
}> = [];
|
|
737
740
|
|
|
738
741
|
// 1. Agent-backed integrations
|
|
739
|
-
if (
|
|
740
|
-
for (const agent of
|
|
742
|
+
if (options.registry) {
|
|
743
|
+
for (const agent of (options.registry.list?.() ?? [])) {
|
|
741
744
|
if (agent.config?.integration) {
|
|
742
745
|
const ic = agent.config.integration;
|
|
743
746
|
catalog.push({
|
|
@@ -831,11 +834,12 @@ export function createIntegrationsAgent(
|
|
|
831
834
|
});
|
|
832
835
|
}
|
|
833
836
|
|
|
834
|
-
// 2. Agent-backed integrations (agents with config.integration +
|
|
835
|
-
if (
|
|
836
|
-
const agents =
|
|
837
|
+
// 2. Agent-backed integrations (agents with config.integration + list_integrations tool)
|
|
838
|
+
if (options.registry) {
|
|
839
|
+
const agents = options.registry.list?.() ?? [];
|
|
837
840
|
for (const agent of agents) {
|
|
838
|
-
|
|
841
|
+
const hasListTool = agent.tools?.some((t: any) => t.name === 'list_integrations');
|
|
842
|
+
if (hasListTool && agent.config?.integration) {
|
|
839
843
|
const meta = {
|
|
840
844
|
provider: agent.config.integration.provider,
|
|
841
845
|
agentPath: agent.path,
|
|
@@ -845,7 +849,8 @@ export function createIntegrationsAgent(
|
|
|
845
849
|
description: agent.config.integration.description,
|
|
846
850
|
};
|
|
847
851
|
try {
|
|
848
|
-
const
|
|
852
|
+
const callResult = options.registry ? await options.registry.call({ action: 'execute_tool', path: agent.path!, tool: 'list_integrations', params: {}, callerType: 'system' }) : null;
|
|
853
|
+
const result = (callResult as any)?.result ?? callResult ?? { success: false };
|
|
849
854
|
if (result.success && result.data) {
|
|
850
855
|
// Flatten: if data has an array field, each item becomes an integration
|
|
851
856
|
const items = Array.isArray(result.data)
|
|
@@ -929,6 +934,19 @@ export function createIntegrationsAgent(
|
|
|
929
934
|
) => {
|
|
930
935
|
const config = await store.getProvider(input.provider);
|
|
931
936
|
if (!config) return { error: `Provider '${input.provider}' not found` };
|
|
937
|
+
|
|
938
|
+
// Delegate to agent's connect_integration tool via registry.call()
|
|
939
|
+
if (config.agentPath && options.registry) {
|
|
940
|
+
const connectResult = await options.registry.call({
|
|
941
|
+
action: 'execute_tool',
|
|
942
|
+
path: config.agentPath,
|
|
943
|
+
tool: 'connect_integration',
|
|
944
|
+
params: { ...input, registryId: config.id },
|
|
945
|
+
callerType: 'system',
|
|
946
|
+
});
|
|
947
|
+
return (connectResult as any)?.result ?? connectResult;
|
|
948
|
+
}
|
|
949
|
+
|
|
932
950
|
if (!config.auth)
|
|
933
951
|
return { error: `Provider '${input.provider}' has no OAuth config` };
|
|
934
952
|
if (!callbackBaseUrl)
|
|
@@ -1158,6 +1176,19 @@ export function createIntegrationsAgent(
|
|
|
1158
1176
|
) => {
|
|
1159
1177
|
const config = await store.getProvider(input.provider);
|
|
1160
1178
|
if (!config) return { error: `Provider '${input.provider}' not found` };
|
|
1179
|
+
|
|
1180
|
+
// Delegate to agent's connect_integration tool via registry.call()
|
|
1181
|
+
if (config.agentPath && options.registry) {
|
|
1182
|
+
const connectResult = await options.registry.call({
|
|
1183
|
+
action: 'execute_tool',
|
|
1184
|
+
path: config.agentPath,
|
|
1185
|
+
tool: 'connect_integration',
|
|
1186
|
+
params: { ...input, registryId: config.id },
|
|
1187
|
+
callerType: 'system',
|
|
1188
|
+
});
|
|
1189
|
+
return (connectResult as any)?.result ?? connectResult;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1161
1192
|
if (!config.auth)
|
|
1162
1193
|
return { error: `Provider '${input.provider}' has no OAuth config` };
|
|
1163
1194
|
if (!callbackBaseUrl) return { error: "No callbackBaseUrl configured" };
|
|
@@ -1347,7 +1378,7 @@ export function createIntegrationsAgent(
|
|
|
1347
1378
|
visibility: "public" as const,
|
|
1348
1379
|
inputSchema: { type: "object" as const, properties: {} },
|
|
1349
1380
|
execute: async () => {
|
|
1350
|
-
const agents =
|
|
1381
|
+
const agents = options.registry?.list?.() ?? [];
|
|
1351
1382
|
const results: any[] = [];
|
|
1352
1383
|
if (options.registry) {
|
|
1353
1384
|
for (const agent of agents) {
|
|
@@ -1385,7 +1416,7 @@ export function createIntegrationsAgent(
|
|
|
1385
1416
|
},
|
|
1386
1417
|
},
|
|
1387
1418
|
execute: async (input: { agent_path?: string }) => {
|
|
1388
|
-
const agents =
|
|
1419
|
+
const agents = options.registry?.list?.() ?? [];
|
|
1389
1420
|
const results: any[] = [];
|
|
1390
1421
|
if (options.registry) {
|
|
1391
1422
|
const targetAgents = input.agent_path
|