@slashfi/agents-sdk 0.16.0 → 0.18.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.map +1 -1
- package/dist/agent-definitions/auth.js +44 -11
- package/dist/agent-definitions/auth.js.map +1 -1
- package/dist/agent-definitions/integrations.d.ts.map +1 -1
- package/dist/agent-definitions/integrations.js +106 -45
- package/dist/agent-definitions/integrations.js.map +1 -1
- package/dist/agent-definitions/remote-registry.d.ts.map +1 -1
- package/dist/agent-definitions/remote-registry.js +174 -45
- package/dist/agent-definitions/remote-registry.js.map +1 -1
- package/dist/agent-definitions/secrets.d.ts.map +1 -1
- package/dist/agent-definitions/secrets.js +1 -4
- package/dist/agent-definitions/secrets.js.map +1 -1
- package/dist/agent-definitions/users.d.ts.map +1 -1
- package/dist/agent-definitions/users.js +14 -3
- package/dist/agent-definitions/users.js.map +1 -1
- package/dist/define-config.d.ts +125 -0
- package/dist/define-config.d.ts.map +1 -0
- package/dist/define-config.js +75 -0
- package/dist/define-config.js.map +1 -0
- package/dist/define.d.ts +11 -2
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +57 -26
- package/dist/define.js.map +1 -1
- package/dist/events.d.ts +133 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +57 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +16 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -3
- package/dist/index.js.map +1 -1
- package/dist/integration-interface.d.ts +3 -3
- package/dist/integration-interface.d.ts.map +1 -1
- package/dist/integration-interface.js +29 -21
- package/dist/integration-interface.js.map +1 -1
- package/dist/integrations-store.d.ts +2 -2
- package/dist/integrations-store.d.ts.map +1 -1
- package/dist/integrations-store.js +3 -3
- package/dist/integrations-store.js.map +1 -1
- package/dist/jwt.d.ts.map +1 -1
- package/dist/jwt.js +7 -5
- package/dist/jwt.js.map +1 -1
- package/dist/key-manager.d.ts.map +1 -1
- package/dist/key-manager.js +5 -3
- package/dist/key-manager.js.map +1 -1
- package/dist/oidc-signin.d.ts +32 -0
- package/dist/oidc-signin.d.ts.map +1 -0
- package/dist/oidc-signin.js +138 -0
- package/dist/oidc-signin.js.map +1 -0
- package/dist/registry-consumer.d.ts +104 -0
- package/dist/registry-consumer.d.ts.map +1 -0
- package/dist/registry-consumer.js +230 -0
- package/dist/registry-consumer.js.map +1 -0
- package/dist/registry.d.ts +5 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +76 -4
- package/dist/registry.js.map +1 -1
- package/dist/secret-collection.d.ts.map +1 -1
- package/dist/secret-collection.js.map +1 -1
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +222 -27
- package/dist/server.js.map +1 -1
- package/dist/test-utils/mock-oidc-server.d.ts +36 -0
- package/dist/test-utils/mock-oidc-server.d.ts.map +1 -0
- package/dist/test-utils/mock-oidc-server.js +96 -0
- package/dist/test-utils/mock-oidc-server.js.map +1 -0
- package/dist/types.d.ts +106 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/agent-definitions/auth.ts +106 -38
- package/src/agent-definitions/integrations.ts +201 -73
- package/src/agent-definitions/remote-registry.ts +262 -65
- package/src/agent-definitions/secrets.ts +22 -8
- package/src/agent-definitions/users.ts +16 -4
- package/src/cli.ts +293 -0
- package/src/codegen.test.ts +527 -0
- package/src/codegen.ts +1348 -0
- package/src/consumer.test.ts +536 -0
- package/src/define-config.ts +205 -0
- package/src/define.ts +134 -46
- package/src/events.ts +237 -0
- package/src/index.ts +107 -8
- package/src/integration-interface.ts +52 -28
- package/src/integrations-store.ts +9 -5
- package/src/jwt.ts +48 -19
- package/src/key-manager.test.ts +22 -13
- package/src/key-manager.ts +8 -10
- package/src/oidc-signin.ts +223 -0
- package/src/registry-consumer.ts +413 -0
- package/src/registry.ts +115 -9
- package/src/secret-collection.ts +2 -1
- package/src/server.test.ts +304 -238
- package/src/server.ts +371 -69
- package/src/test-utils/mock-oidc-server.ts +123 -0
- package/src/types.ts +172 -18
|
@@ -25,7 +25,13 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { defineAgent, defineTool } from "../define.js";
|
|
28
|
-
import {
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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<
|
|
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(
|
|
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:
|
|
504
|
+
description:
|
|
505
|
+
"Link to a tenant on a remote system (for cross-registry trust)",
|
|
480
506
|
properties: {
|
|
481
|
-
issuer: {
|
|
482
|
-
|
|
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: {
|
|
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 {
|
|
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:
|
|
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: {
|
|
802
|
+
action: {
|
|
803
|
+
type: "string",
|
|
804
|
+
enum: ["create", "list"],
|
|
805
|
+
description: "Action",
|
|
806
|
+
},
|
|
765
807
|
name: { type: "string", description: "Key name" },
|
|
766
|
-
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: {
|
|
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 {
|
|
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
|
-
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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(
|
|
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(
|
|
959
|
+
await store.storeTenantIdentity(
|
|
960
|
+
foreignTenantId,
|
|
961
|
+
issuer,
|
|
962
|
+
foreignTenantId,
|
|
963
|
+
);
|
|
896
964
|
return foreignTenantId;
|
|
897
965
|
})();
|
|
898
966
|
|