@slashfi/agents-sdk 0.16.0 → 0.17.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 (93) hide show
  1. package/dist/agent-definitions/auth.d.ts.map +1 -1
  2. package/dist/agent-definitions/auth.js +44 -11
  3. package/dist/agent-definitions/auth.js.map +1 -1
  4. package/dist/agent-definitions/integrations.d.ts.map +1 -1
  5. package/dist/agent-definitions/integrations.js +106 -45
  6. package/dist/agent-definitions/integrations.js.map +1 -1
  7. package/dist/agent-definitions/remote-registry.d.ts.map +1 -1
  8. package/dist/agent-definitions/remote-registry.js +174 -45
  9. package/dist/agent-definitions/remote-registry.js.map +1 -1
  10. package/dist/agent-definitions/secrets.d.ts.map +1 -1
  11. package/dist/agent-definitions/secrets.js +1 -4
  12. package/dist/agent-definitions/secrets.js.map +1 -1
  13. package/dist/agent-definitions/users.d.ts.map +1 -1
  14. package/dist/agent-definitions/users.js +14 -3
  15. package/dist/agent-definitions/users.js.map +1 -1
  16. package/dist/define-config.d.ts +125 -0
  17. package/dist/define-config.d.ts.map +1 -0
  18. package/dist/define-config.js +75 -0
  19. package/dist/define-config.js.map +1 -0
  20. package/dist/define.d.ts +11 -2
  21. package/dist/define.d.ts.map +1 -1
  22. package/dist/define.js +57 -26
  23. package/dist/define.js.map +1 -1
  24. package/dist/events.d.ts +133 -0
  25. package/dist/events.d.ts.map +1 -0
  26. package/dist/events.js +57 -0
  27. package/dist/events.js.map +1 -0
  28. package/dist/index.d.ts +15 -7
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +9 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/integration-interface.d.ts +3 -3
  33. package/dist/integration-interface.d.ts.map +1 -1
  34. package/dist/integration-interface.js +29 -21
  35. package/dist/integration-interface.js.map +1 -1
  36. package/dist/integrations-store.d.ts +2 -2
  37. package/dist/integrations-store.d.ts.map +1 -1
  38. package/dist/integrations-store.js +3 -3
  39. package/dist/integrations-store.js.map +1 -1
  40. package/dist/jwt.d.ts.map +1 -1
  41. package/dist/jwt.js +7 -5
  42. package/dist/jwt.js.map +1 -1
  43. package/dist/key-manager.d.ts.map +1 -1
  44. package/dist/key-manager.js +5 -3
  45. package/dist/key-manager.js.map +1 -1
  46. package/dist/oidc-signin.d.ts +32 -0
  47. package/dist/oidc-signin.d.ts.map +1 -0
  48. package/dist/oidc-signin.js +138 -0
  49. package/dist/oidc-signin.js.map +1 -0
  50. package/dist/registry-consumer.d.ts +104 -0
  51. package/dist/registry-consumer.d.ts.map +1 -0
  52. package/dist/registry-consumer.js +230 -0
  53. package/dist/registry-consumer.js.map +1 -0
  54. package/dist/registry.d.ts +5 -0
  55. package/dist/registry.d.ts.map +1 -1
  56. package/dist/registry.js +76 -4
  57. package/dist/registry.js.map +1 -1
  58. package/dist/secret-collection.d.ts.map +1 -1
  59. package/dist/secret-collection.js.map +1 -1
  60. package/dist/server.d.ts +3 -0
  61. package/dist/server.d.ts.map +1 -1
  62. package/dist/server.js +222 -27
  63. package/dist/server.js.map +1 -1
  64. package/dist/test-utils/mock-oidc-server.d.ts +36 -0
  65. package/dist/test-utils/mock-oidc-server.d.ts.map +1 -0
  66. package/dist/test-utils/mock-oidc-server.js +96 -0
  67. package/dist/test-utils/mock-oidc-server.js.map +1 -0
  68. package/dist/types.d.ts +17 -0
  69. package/dist/types.d.ts.map +1 -1
  70. package/package.json +1 -1
  71. package/src/agent-definitions/auth.ts +106 -38
  72. package/src/agent-definitions/integrations.ts +201 -73
  73. package/src/agent-definitions/remote-registry.ts +262 -65
  74. package/src/agent-definitions/secrets.ts +22 -8
  75. package/src/agent-definitions/users.ts +16 -4
  76. package/src/consumer.test.ts +536 -0
  77. package/src/define-config.ts +205 -0
  78. package/src/define.ts +134 -46
  79. package/src/events.ts +237 -0
  80. package/src/index.ts +89 -8
  81. package/src/integration-interface.ts +52 -28
  82. package/src/integrations-store.ts +9 -5
  83. package/src/jwt.ts +48 -19
  84. package/src/key-manager.test.ts +22 -13
  85. package/src/key-manager.ts +8 -10
  86. package/src/oidc-signin.ts +223 -0
  87. package/src/registry-consumer.ts +413 -0
  88. package/src/registry.ts +115 -9
  89. package/src/secret-collection.ts +2 -1
  90. package/src/server.test.ts +304 -238
  91. package/src/server.ts +371 -69
  92. package/src/test-utils/mock-oidc-server.ts +123 -0
  93. package/src/types.ts +69 -18
@@ -25,7 +25,13 @@
25
25
  */
26
26
 
27
27
  import { defineAgent, defineTool } from "../define.js";
28
- import { signJwt, generateSigningKey, exportSigningKey, verifyJwtFromIssuer, type ExportedKeyPair } from "../jwt.js";
28
+ import {
29
+ type ExportedKeyPair,
30
+ exportSigningKey,
31
+ generateSigningKey,
32
+ signJwt,
33
+ verifyJwtFromIssuer,
34
+ } from "../jwt.js";
29
35
  import type { AgentDefinition, ToolContext, ToolDefinition } from "../types.js";
30
36
 
31
37
  // ============================================
@@ -81,7 +87,10 @@ export interface AuthTenant {
81
87
 
82
88
  export interface AuthStore {
83
89
  /** Create a tenant. */
84
- createTenant(name: string, externalRef?: { issuer: string; tenantId: string }): Promise<{ tenantId: string }>;
90
+ createTenant(
91
+ name: string,
92
+ externalRef?: { issuer: string; tenantId: string },
93
+ ): Promise<{ tenantId: string }>;
85
94
 
86
95
  /** Get tenant by ID. */
87
96
  getTenant(tenantId: string): Promise<AuthTenant | null>;
@@ -165,9 +174,7 @@ export interface AuthStore {
165
174
  ): Promise<{ tenantId: string; userId: string; clientId: string } | null>;
166
175
 
167
176
  /** Rotate a refresh token. */
168
- rotateRefreshToken(
169
- oldToken: string,
170
- ): Promise<{
177
+ rotateRefreshToken(oldToken: string): Promise<{
171
178
  refreshToken: string;
172
179
  tenantId: string;
173
180
  userId: string;
@@ -177,18 +184,32 @@ export interface AuthStore {
177
184
  // --- Tenant Identity ---
178
185
 
179
186
  /** Store a tenant identity mapping (foreign issuer + ID -> local tenant). */
180
- storeTenantIdentity(tenantId: string, provider: string, providerTenantId: string): Promise<void>;
187
+ storeTenantIdentity(
188
+ tenantId: string,
189
+ provider: string,
190
+ providerTenantId: string,
191
+ ): Promise<void>;
181
192
 
182
193
  /** Resolve a local tenant ID from a foreign identity. */
183
- resolveTenantByIdentity(provider: string, providerTenantId: string): Promise<string | null>;
194
+ resolveTenantByIdentity(
195
+ provider: string,
196
+ providerTenantId: string,
197
+ ): Promise<string | null>;
184
198
 
185
199
  // --- User Identity ---
186
200
 
187
201
  /** Store a user identity mapping (foreign issuer + ID -> local user). */
188
- storeUserIdentity(userId: string, provider: string, providerUserId: string): Promise<void>;
202
+ storeUserIdentity(
203
+ userId: string,
204
+ provider: string,
205
+ providerUserId: string,
206
+ ): Promise<void>;
189
207
 
190
208
  /** Resolve a local user ID from a foreign identity. */
191
- resolveUserByIdentity(provider: string, providerUserId: string): Promise<string | null>;
209
+ resolveUserByIdentity(
210
+ provider: string,
211
+ providerUserId: string,
212
+ ): Promise<string | null>;
192
213
 
193
214
  // --- Transaction ---
194
215
 
@@ -244,7 +265,10 @@ export function createMemoryAuthStore(): AuthStore {
244
265
  const trustedIssuers = new Set<string>();
245
266
  const tenantIdentities = new Map<string, string>(); // "provider:providerTenantId" -> tenantId
246
267
  const userIdentities = new Map<string, string>(); // "provider:providerUserId" -> userId
247
- const refreshTokens = new Map<string, { tenantId: string; userId: string; clientId: string }>();
268
+ const refreshTokens = new Map<
269
+ string,
270
+ { tenantId: string; userId: string; clientId: string }
271
+ >();
248
272
 
249
273
  return {
250
274
  async createTenant(name, _externalRef) {
@@ -339,7 +363,9 @@ export function createMemoryAuthStore(): AuthStore {
339
363
  },
340
364
 
341
365
  async getSigningKeys() {
342
- return Array.from(signingKeys.values()).filter(k => k.status !== "revoked");
366
+ return Array.from(signingKeys.values()).filter(
367
+ (k) => k.status !== "revoked",
368
+ );
343
369
  },
344
370
 
345
371
  async getActiveSigningKey() {
@@ -435,7 +461,6 @@ export interface CreateAuthAgentOptions {
435
461
 
436
462
  /** Custom auth store. Default: in-memory */
437
463
  store?: AuthStore;
438
-
439
464
  }
440
465
 
441
466
  // ============================================
@@ -476,20 +501,33 @@ export function createAuthAgent(
476
501
  name: { type: "string" as const, description: "Tenant name" },
477
502
  externalRef: {
478
503
  type: "object" as const,
479
- description: "Link to a tenant on a remote system (for cross-registry trust)",
504
+ description:
505
+ "Link to a tenant on a remote system (for cross-registry trust)",
480
506
  properties: {
481
- issuer: { type: "string" as const, description: "Issuer URL of the remote system" },
482
- tenantId: { type: "string" as const, description: "Tenant ID on the remote system" },
507
+ issuer: {
508
+ type: "string" as const,
509
+ description: "Issuer URL of the remote system",
510
+ },
511
+ tenantId: {
512
+ type: "string" as const,
513
+ description: "Tenant ID on the remote system",
514
+ },
483
515
  },
484
516
  required: ["issuer", "tenantId"],
485
517
  },
486
518
  },
487
519
  required: ["name"],
488
520
  },
489
- execute: async (input: { name: string; externalRef?: { issuer: string; tenantId: string } }) => {
521
+ execute: async (input: {
522
+ name: string;
523
+ externalRef?: { issuer: string; tenantId: string };
524
+ }) => {
490
525
  const result = await store.createTenant(input.name, input.externalRef);
491
- return { tenantId: result.tenantId, name: input.name, externalRef: input.externalRef };
492
-
526
+ return {
527
+ tenantId: result.tenantId,
528
+ name: input.name,
529
+ externalRef: input.externalRef,
530
+ };
493
531
  },
494
532
  });
495
533
 
@@ -748,12 +786,12 @@ export function createAuthAgent(
748
786
  return {
749
787
  newKid: newKey.kid,
750
788
  deprecatedKid: current?.kid ?? null,
751
- message: "New signing key generated. Old key deprecated but still valid for verification.",
789
+ message:
790
+ "New signing key generated. Old key deprecated but still valid for verification.",
752
791
  };
753
792
  },
754
793
  });
755
794
 
756
-
757
795
  const apiKeyTool = defineTool({
758
796
  name: "api_key",
759
797
  description: "Create or list API keys for MCP access.",
@@ -761,14 +799,25 @@ export function createAuthAgent(
761
799
  inputSchema: {
762
800
  type: "object" as const,
763
801
  properties: {
764
- action: { type: "string", enum: ["create", "list"], description: "Action" },
802
+ action: {
803
+ type: "string",
804
+ enum: ["create", "list"],
805
+ description: "Action",
806
+ },
765
807
  name: { type: "string", description: "Key name" },
766
- scopes: { type: "array", items: { type: "string" }, description: "Scopes" },
808
+ scopes: {
809
+ type: "array",
810
+ items: { type: "string" },
811
+ description: "Scopes",
812
+ },
767
813
  },
768
814
  required: ["action"],
769
815
  },
770
- execute: async (input: { action: string; name?: string; scopes?: string[] }) => {
771
-
816
+ execute: async (input: {
817
+ action: string;
818
+ name?: string;
819
+ scopes?: string[];
820
+ }) => {
772
821
  if (input.action === "create") {
773
822
  const result = await store.createClient(
774
823
  input.name ?? "api-key",
@@ -779,7 +828,13 @@ export function createAuthAgent(
779
828
  }
780
829
  if (input.action === "list") {
781
830
  const clients = await store.listClients();
782
- return { keys: clients.map(c => ({ id: c.clientId, name: c.name, scopes: c.scopes })) };
831
+ return {
832
+ keys: clients.map((c) => ({
833
+ id: c.clientId,
834
+ name: c.name,
835
+ scopes: c.scopes,
836
+ })),
837
+ };
783
838
  }
784
839
  return { error: "Unknown action" };
785
840
  },
@@ -805,19 +860,26 @@ export function createAuthAgent(
805
860
  },
806
861
  required: ["action"],
807
862
  },
808
- execute: async (
809
- input: { action: "add" | "remove" | "list"; issuerUrl?: string },
810
- ) => {
863
+ execute: async (input: {
864
+ action: "add" | "remove" | "list";
865
+ issuerUrl?: string;
866
+ }) => {
811
867
  switch (input.action) {
812
868
  case "add": {
813
869
  if (!input.issuerUrl) throw new Error("issuerUrl is required");
814
870
  await store.addTrustedIssuer(input.issuerUrl);
815
- return { success: true, message: `Added trusted issuer: ${input.issuerUrl}` };
871
+ return {
872
+ success: true,
873
+ message: `Added trusted issuer: ${input.issuerUrl}`,
874
+ };
816
875
  }
817
876
  case "remove": {
818
877
  if (!input.issuerUrl) throw new Error("issuerUrl is required");
819
878
  const removed = await store.removeTrustedIssuer(input.issuerUrl);
820
- return { success: removed, message: removed ? "Removed" : "Not found" };
879
+ return {
880
+ success: removed,
881
+ message: removed ? "Removed" : "Not found",
882
+ };
821
883
  }
822
884
  case "list": {
823
885
  const issuers = await store.listTrustedIssuers();
@@ -827,7 +889,6 @@ export function createAuthAgent(
827
889
  },
828
890
  });
829
891
 
830
-
831
892
  const exchangeTokenTool = defineTool({
832
893
  name: "exchange_token",
833
894
  description:
@@ -842,13 +903,10 @@ export function createAuthAgent(
842
903
  type: "string" as const,
843
904
  description: "JWT signed by a trusted issuer",
844
905
  },
845
-
846
906
  },
847
907
  required: ["token"],
848
908
  },
849
- execute: async (
850
- input: { token: string },
851
- ) => {
909
+ execute: async (input: { token: string }) => {
852
910
  // 1. Decode JWT to read iss claim (no verification yet)
853
911
  const parts = input.token.split(".");
854
912
  if (parts.length !== 3) {
@@ -882,17 +940,27 @@ export function createAuthAgent(
882
940
  return { success: false, error: "JWT verification failed" };
883
941
  }
884
942
  if (!payload) {
885
- return { success: false, error: "JWT verification returned empty payload" };
943
+ return {
944
+ success: false,
945
+ error: "JWT verification returned empty payload",
946
+ };
886
947
  }
887
948
 
888
949
  // 4. Resolve tenant + user inside a transaction for consistency
889
950
  return store.transaction(async () => {
890
951
  const localTenantId = await (async () => {
891
952
  if (!foreignTenantId) return null;
892
- const existing = await store.resolveTenantByIdentity(issuer, foreignTenantId);
953
+ const existing = await store.resolveTenantByIdentity(
954
+ issuer,
955
+ foreignTenantId,
956
+ );
893
957
  if (existing) return existing;
894
958
  // Auto-create tenant identity link on first encounter
895
- await store.storeTenantIdentity(foreignTenantId, issuer, foreignTenantId);
959
+ await store.storeTenantIdentity(
960
+ foreignTenantId,
961
+ issuer,
962
+ foreignTenantId,
963
+ );
896
964
  return foreignTenantId;
897
965
  })();
898
966