@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.
Files changed (48) hide show
  1. package/dist/agent-definitions/auth.d.ts +17 -1
  2. package/dist/agent-definitions/auth.d.ts.map +1 -1
  3. package/dist/agent-definitions/auth.js +123 -4
  4. package/dist/agent-definitions/auth.js.map +1 -1
  5. package/dist/agent-definitions/integrations.d.ts +2 -14
  6. package/dist/agent-definitions/integrations.d.ts.map +1 -1
  7. package/dist/agent-definitions/integrations.js +64 -19
  8. package/dist/agent-definitions/integrations.js.map +1 -1
  9. package/dist/agent-definitions/remote-registry.d.ts +19 -14
  10. package/dist/agent-definitions/remote-registry.d.ts.map +1 -1
  11. package/dist/agent-definitions/remote-registry.js +219 -381
  12. package/dist/agent-definitions/remote-registry.js.map +1 -1
  13. package/dist/agent-definitions/users.d.ts.map +1 -1
  14. package/dist/agent-definitions/users.js +29 -1
  15. package/dist/agent-definitions/users.js.map +1 -1
  16. package/dist/define.d.ts +6 -4
  17. package/dist/define.d.ts.map +1 -1
  18. package/dist/define.js +82 -3
  19. package/dist/define.js.map +1 -1
  20. package/dist/index.d.ts +3 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +1 -0
  23. package/dist/index.js.map +1 -1
  24. package/dist/jwt.js +1 -1
  25. package/dist/jwt.js.map +1 -1
  26. package/dist/key-manager.d.ts +76 -0
  27. package/dist/key-manager.d.ts.map +1 -0
  28. package/dist/key-manager.js +156 -0
  29. package/dist/key-manager.js.map +1 -0
  30. package/dist/server.d.ts +39 -0
  31. package/dist/server.d.ts.map +1 -1
  32. package/dist/server.js +228 -52
  33. package/dist/server.js.map +1 -1
  34. package/dist/types.d.ts +53 -1
  35. package/dist/types.d.ts.map +1 -1
  36. package/package.json +1 -1
  37. package/src/agent-definitions/auth.ts +165 -6
  38. package/src/agent-definitions/integrations.ts +59 -28
  39. package/src/agent-definitions/remote-registry.ts +219 -513
  40. package/src/agent-definitions/users.ts +35 -1
  41. package/src/define.ts +98 -6
  42. package/src/index.ts +3 -1
  43. package/src/jwt.ts +1 -1
  44. package/src/key-manager.test.ts +273 -0
  45. package/src/key-manager.ts +257 -0
  46. package/src/server.test.ts +284 -0
  47. package/src/server.ts +334 -60
  48. 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 data = (await response.json()) as Record<string, unknown>;
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 data = (await response.json()) as Record<string, unknown>;
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, getAgents, integrationsStore } = options;
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
- // Also track in integrations table
685
- if (integrationsStore) {
682
+ // Delegate to agent's setup_integration tool via registry.call()
683
+ if (config.agentPath && options.registry) {
686
684
  try {
687
- await integrationsStore.create({
688
- agentPath: config.agentPath ?? `@${config.id}`,
689
- config: { providerId: config.id, ...input },
690
- installedBy: _ctx.callerId,
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
- } catch {}
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 (getAgents) {
740
- for (const agent of getAgents()) {
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 + integrationMethods)
835
- if (getAgents) {
836
- const agents = getAgents();
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
- if (agent.integrationMethods?.list && agent.config?.integration) {
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 result = await agent.integrationMethods.list({}, { ...ctx, provider: agent.config.integration.provider });
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 = getAgents?.() ?? [];
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 = getAgents?.() ?? [];
1419
+ const agents = options.registry?.list?.() ?? [];
1389
1420
  const results: any[] = [];
1390
1421
  if (options.registry) {
1391
1422
  const targetAgents = input.agent_path