@slashfi/agents-sdk 0.5.0 → 0.7.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 (54) hide show
  1. package/dist/agent-definitions/auth.d.ts.map +1 -1
  2. package/dist/agent-definitions/auth.js +16 -3
  3. package/dist/agent-definitions/auth.js.map +1 -1
  4. package/dist/agent-definitions/integrations.d.ts +162 -0
  5. package/dist/agent-definitions/integrations.d.ts.map +1 -0
  6. package/dist/agent-definitions/integrations.js +861 -0
  7. package/dist/agent-definitions/integrations.js.map +1 -0
  8. package/dist/agent-definitions/secrets.d.ts +26 -3
  9. package/dist/agent-definitions/secrets.d.ts.map +1 -1
  10. package/dist/agent-definitions/secrets.js +34 -28
  11. package/dist/agent-definitions/secrets.js.map +1 -1
  12. package/dist/agent-definitions/users.d.ts +80 -0
  13. package/dist/agent-definitions/users.d.ts.map +1 -0
  14. package/dist/agent-definitions/users.js +397 -0
  15. package/dist/agent-definitions/users.js.map +1 -0
  16. package/dist/crypto.d.ts.map +1 -1
  17. package/dist/crypto.js.map +1 -1
  18. package/dist/define.d.ts +6 -1
  19. package/dist/define.d.ts.map +1 -1
  20. package/dist/define.js +1 -0
  21. package/dist/define.js.map +1 -1
  22. package/dist/index.d.ts +8 -4
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +6 -2
  25. package/dist/index.js.map +1 -1
  26. package/dist/jwt.d.ts.map +1 -1
  27. package/dist/jwt.js.map +1 -1
  28. package/dist/server.d.ts +28 -1
  29. package/dist/server.d.ts.map +1 -1
  30. package/dist/server.js +477 -26
  31. package/dist/server.js.map +1 -1
  32. package/dist/slack-oauth.d.ts +27 -0
  33. package/dist/slack-oauth.d.ts.map +1 -0
  34. package/dist/slack-oauth.js +48 -0
  35. package/dist/slack-oauth.js.map +1 -0
  36. package/dist/types.d.ts +66 -0
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/web-pages.d.ts +8 -0
  39. package/dist/web-pages.d.ts.map +1 -0
  40. package/dist/web-pages.js +169 -0
  41. package/dist/web-pages.js.map +1 -0
  42. package/package.json +2 -1
  43. package/src/agent-definitions/auth.ts +37 -14
  44. package/src/agent-definitions/integrations.ts +1209 -0
  45. package/src/agent-definitions/secrets.ts +85 -36
  46. package/src/agent-definitions/users.ts +533 -0
  47. package/src/crypto.ts +3 -1
  48. package/src/define.ts +8 -0
  49. package/src/index.ts +57 -3
  50. package/src/jwt.ts +7 -5
  51. package/src/server.ts +565 -33
  52. package/src/slack-oauth.ts +66 -0
  53. package/src/types.ts +83 -0
  54. package/src/web-pages.ts +178 -0
@@ -25,8 +25,8 @@
25
25
  */
26
26
 
27
27
  import { defineAgent, defineTool } from "../define.js";
28
- import type { AgentDefinition, ToolContext, ToolDefinition } from "../types.js";
29
28
  import { signJwt } from "../jwt.js";
29
+ import type { AgentDefinition, ToolContext, ToolDefinition } from "../types.js";
30
30
 
31
31
  // ============================================
32
32
  // Auth Types
@@ -139,7 +139,12 @@ export interface AuthStore {
139
139
  /** Rotate a refresh token. */
140
140
  rotateRefreshToken?(
141
141
  oldToken: string,
142
- ): Promise<{ refreshToken: string; tenantId: string; userId: string; clientId: string } | null>;
142
+ ): Promise<{
143
+ refreshToken: string;
144
+ tenantId: string;
145
+ userId: string;
146
+ clientId: string;
147
+ } | null>;
143
148
  }
144
149
 
145
150
  // ============================================
@@ -165,8 +170,6 @@ function generateSecret(): string {
165
170
  return secret;
166
171
  }
167
172
 
168
-
169
-
170
173
  /** Simple hash for storing secrets (not for production - use bcrypt/argon2) */
171
174
  async function hashSecret(secret: string): Promise<string> {
172
175
  const encoder = new TextEncoder();
@@ -249,7 +252,9 @@ export function createMemoryAuthStore(): AuthStore {
249
252
  if (!client) return null;
250
253
  const clientSecret = generateSecret();
251
254
  client.clientSecretHash = await hashSecret(clientSecret);
252
- return { clientSecret: { $agent_type: "secret", value: clientSecret } } as any;
255
+ return {
256
+ clientSecret: { $agent_type: "secret", value: clientSecret },
257
+ } as any;
253
258
  },
254
259
 
255
260
  async storeToken(token) {
@@ -320,10 +325,10 @@ export function createAuthAgent(
320
325
 
321
326
  // --- Public Tools ---
322
327
 
323
-
324
328
  const createTenantTool = defineTool({
325
329
  name: "create_tenant",
326
- description: "Create a new tenant (organizational unit). All clients and resources are scoped to a tenant.",
330
+ description:
331
+ "Create a new tenant (organizational unit). All clients and resources are scoped to a tenant.",
327
332
  visibility: "public" as const,
328
333
  inputSchema: {
329
334
  type: "object" as const,
@@ -364,13 +369,22 @@ export function createAuthAgent(
364
369
  refreshToken?: string;
365
370
  }) => {
366
371
  if (input.grantType === "refresh_token") {
367
- if (!input.refreshToken) throw new Error("refreshToken is required for refresh_token grant");
368
- if (!store.rotateRefreshToken) throw new Error("Refresh tokens not supported by this store");
372
+ if (!input.refreshToken)
373
+ throw new Error("refreshToken is required for refresh_token grant");
374
+ if (!store.rotateRefreshToken)
375
+ throw new Error("Refresh tokens not supported by this store");
369
376
  const result = await store.rotateRefreshToken(input.refreshToken);
370
377
  if (!result) throw new Error("Invalid or expired refresh token");
371
378
  const now = Math.floor(Date.now() / 1000);
372
379
  const jwt = await signJwt(
373
- { sub: result.clientId, name: result.userId, tenantId: result.tenantId, scopes: [], iat: now, exp: now + tokenTtl },
380
+ {
381
+ sub: result.clientId,
382
+ name: result.userId,
383
+ tenantId: result.tenantId,
384
+ scopes: [],
385
+ iat: now,
386
+ exp: now + tokenTtl,
387
+ },
374
388
  (await store.getClient(result.clientId))?.clientSecretHash ?? "",
375
389
  );
376
390
  return {
@@ -382,7 +396,9 @@ export function createAuthAgent(
382
396
  }
383
397
 
384
398
  if (input.grantType !== "client_credentials") {
385
- throw new Error("Unsupported grant type. Use 'client_credentials' or 'refresh_token'.");
399
+ throw new Error(
400
+ "Unsupported grant type. Use 'client_credentials' or 'refresh_token'.",
401
+ );
386
402
  }
387
403
 
388
404
  const client = await store.validateClient(
@@ -415,7 +431,6 @@ export function createAuthAgent(
415
431
  },
416
432
  });
417
433
 
418
-
419
434
  const whoamiTool = defineTool({
420
435
  name: "whoami",
421
436
  description: "Introspect the current authentication context",
@@ -449,7 +464,11 @@ export function createAuthAgent(
449
464
  },
450
465
  required: ["name"],
451
466
  },
452
- execute: async (input: { name: string; tenantId: string; scopes?: string[] }) => {
467
+ execute: async (input: {
468
+ name: string;
469
+ tenantId: string;
470
+ scopes?: string[];
471
+ }) => {
453
472
  let scopes = input.scopes ?? [];
454
473
 
455
474
  // If registration scopes are restricted, filter
@@ -464,7 +483,11 @@ export function createAuthAgent(
464
483
  input.tenantId,
465
484
  );
466
485
 
467
- return { clientId, clientSecret: { $agent_type: "secret", value: clientSecret }, scopes } as any;
486
+ return {
487
+ clientId,
488
+ clientSecret: { $agent_type: "secret", value: clientSecret },
489
+ scopes,
490
+ } as any;
468
491
  },
469
492
  });
470
493