@slashfi/agents-sdk 0.5.0 → 0.6.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 +16 -3
- package/dist/agent-definitions/auth.js.map +1 -1
- package/dist/agent-definitions/integrations.d.ts +162 -0
- package/dist/agent-definitions/integrations.d.ts.map +1 -0
- package/dist/agent-definitions/integrations.js +861 -0
- package/dist/agent-definitions/integrations.js.map +1 -0
- package/dist/agent-definitions/secrets.d.ts.map +1 -1
- package/dist/agent-definitions/secrets.js +8 -25
- package/dist/agent-definitions/secrets.js.map +1 -1
- package/dist/agent-definitions/users.d.ts +80 -0
- package/dist/agent-definitions/users.d.ts.map +1 -0
- package/dist/agent-definitions/users.js +397 -0
- package/dist/agent-definitions/users.js.map +1 -0
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js.map +1 -1
- package/dist/define.d.ts +6 -1
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +1 -0
- package/dist/define.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/jwt.d.ts.map +1 -1
- package/dist/jwt.js.map +1 -1
- package/dist/server.d.ts +28 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +477 -26
- package/dist/server.js.map +1 -1
- package/dist/slack-oauth.d.ts +27 -0
- package/dist/slack-oauth.d.ts.map +1 -0
- package/dist/slack-oauth.js +48 -0
- package/dist/slack-oauth.js.map +1 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/web-pages.d.ts +8 -0
- package/dist/web-pages.d.ts.map +1 -0
- package/dist/web-pages.js +169 -0
- package/dist/web-pages.js.map +1 -0
- package/package.json +2 -1
- package/src/agent-definitions/auth.ts +37 -14
- package/src/agent-definitions/integrations.ts +1209 -0
- package/src/agent-definitions/secrets.ts +24 -30
- package/src/agent-definitions/users.ts +533 -0
- package/src/crypto.ts +3 -1
- package/src/define.ts +8 -0
- package/src/index.ts +56 -3
- package/src/jwt.ts +7 -5
- package/src/server.ts +565 -33
- package/src/slack-oauth.ts +66 -0
- package/src/types.ts +83 -0
- 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<{
|
|
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 {
|
|
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:
|
|
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)
|
|
368
|
-
|
|
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
|
-
{
|
|
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(
|
|
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: {
|
|
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 {
|
|
486
|
+
return {
|
|
487
|
+
clientId,
|
|
488
|
+
clientSecret: { $agent_type: "secret", value: clientSecret },
|
|
489
|
+
scopes,
|
|
490
|
+
} as any;
|
|
468
491
|
},
|
|
469
492
|
});
|
|
470
493
|
|