@slashfi/agents-sdk 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Slash Financial
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,274 @@
1
+ # Agents SDK
2
+
3
+ SDK for building AI agents with tool definitions and JSON-RPC servers.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @slashfi/agents-sdk
9
+ # or
10
+ npm install @slashfi/agents-sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import {
17
+ defineAgent,
18
+ defineTool,
19
+ createAgentRegistry,
20
+ createAgentServer
21
+ } from '@slashfi/agents-sdk';
22
+
23
+ // Define a tool
24
+ const greet = defineTool({
25
+ name: 'greet',
26
+ description: 'Greet a user',
27
+ inputSchema: {
28
+ type: 'object',
29
+ properties: {
30
+ name: { type: 'string', description: 'Name to greet' }
31
+ },
32
+ required: ['name']
33
+ },
34
+ execute: async (input: { name: string }) => {
35
+ return { message: `Hello, ${input.name}!` };
36
+ }
37
+ });
38
+
39
+ // Define an agent
40
+ const agent = defineAgent({
41
+ path: '@my-agent',
42
+ entrypoint: 'You are a helpful assistant.',
43
+ config: {
44
+ name: 'My Agent',
45
+ description: 'A helpful agent that can greet users'
46
+ },
47
+ tools: [greet]
48
+ });
49
+
50
+ // Create registry and register agent
51
+ const registry = createAgentRegistry();
52
+ registry.register(agent);
53
+
54
+ // Start HTTP server
55
+ const server = createAgentServer(registry, { port: 3000 });
56
+ await server.start();
57
+ ```
58
+
59
+ ## API
60
+
61
+ ### `defineTool(options)`
62
+
63
+ Create a tool definition.
64
+
65
+ ```typescript
66
+ const tool = defineTool({
67
+ name: 'tool-name',
68
+ description: 'What the tool does',
69
+ inputSchema: {
70
+ type: 'object',
71
+ properties: {
72
+ param: { type: 'string', description: 'Parameter description' }
73
+ },
74
+ required: ['param']
75
+ },
76
+ execute: async (input, ctx) => {
77
+ // Tool implementation
78
+ return result;
79
+ }
80
+ });
81
+ ```
82
+
83
+ ### `defineAgent(options)`
84
+
85
+ Create an agent definition.
86
+
87
+ ```typescript
88
+ const agent = defineAgent({
89
+ path: '@agent-name',
90
+ entrypoint: 'System prompt for the agent',
91
+ config: {
92
+ name: 'Agent Name',
93
+ description: 'Agent description',
94
+ supportedActions: ['execute_tool', 'describe_tools', 'load']
95
+ },
96
+ tools: [tool1, tool2]
97
+ });
98
+ ```
99
+
100
+ ### `createAgentRegistry(options?)`
101
+
102
+ Create an agent registry to manage agents.
103
+
104
+ ```typescript
105
+ const registry = createAgentRegistry({
106
+ defaultVisibility: 'internal' // 'public' | 'internal' | 'private'
107
+ });
108
+
109
+ registry.register(agent);
110
+ registry.list(); // Returns all registered agents
111
+ registry.get('@agent-name'); // Get agent by path
112
+
113
+ // Call an agent
114
+ const result = await registry.call({
115
+ action: 'execute_tool',
116
+ path: '@agent-name',
117
+ tool: 'tool-name',
118
+ params: { param: 'value' }
119
+ });
120
+ ```
121
+
122
+ ### `createAgentServer(registry, options?)`
123
+
124
+ Create an HTTP server exposing the registry.
125
+
126
+ ```typescript
127
+ const server = createAgentServer(registry, {
128
+ port: 3000,
129
+ hostname: 'localhost',
130
+ basePath: '/api',
131
+ cors: true
132
+ });
133
+
134
+ await server.start();
135
+ // POST /api/call - Execute agent actions
136
+ // GET /api/list - List agents
137
+
138
+ await server.stop();
139
+ ```
140
+
141
+ ## HTTP Endpoints
142
+
143
+ ### POST /call
144
+
145
+ Execute an agent action.
146
+
147
+ **Request:**
148
+ ```json
149
+ {
150
+ "action": "execute_tool",
151
+ "path": "@my-agent",
152
+ "tool": "greet",
153
+ "params": { "name": "World" }
154
+ }
155
+ ```
156
+
157
+ **Response:**
158
+ ```json
159
+ {
160
+ "success": true,
161
+ "result": { "message": "Hello, World!" }
162
+ }
163
+ ```
164
+
165
+ **Actions:**
166
+ - `execute_tool` - Execute a specific tool
167
+ - `describe_tools` - Get tool schemas
168
+ - `load` - Get agent definition
169
+
170
+ ### GET /list
171
+
172
+ List registered agents.
173
+
174
+ **Response:**
175
+ ```json
176
+ {
177
+ "success": true,
178
+ "agents": [
179
+ {
180
+ "path": "@my-agent",
181
+ "name": "My Agent",
182
+ "description": "A helpful agent",
183
+ "supportedActions": ["execute_tool", "describe_tools", "load"]
184
+ }
185
+ ]
186
+ }
187
+ ```
188
+
189
+ ## Access Control
190
+
191
+ Agents and tools support visibility levels:
192
+
193
+ - `public` - Anyone can access
194
+ - `internal` - Only other agents in the same registry
195
+ - `private` - Only the owning agent
196
+
197
+ ```typescript
198
+ const agent = defineAgent({
199
+ path: '@private-agent',
200
+ entrypoint: '...',
201
+ visibility: 'internal',
202
+ allowedCallers: ['@trusted-agent'] // Explicit allowlist
203
+ });
204
+ ```
205
+
206
+ ## Filesystem Convention
207
+
208
+ Organize agents using the filesystem convention:
209
+
210
+ ```
211
+ src/agents/
212
+ ├── @my-agent/
213
+ │ ├── entrypoint.md # System prompt
214
+ │ ├── agent.config.ts # Configuration
215
+ │ ├── greet.tool.ts # Tool (exports greetTool)
216
+ │ └── echo.tool.ts # Tool (exports echoTool)
217
+ └── @another-agent/
218
+ └── ...
219
+ ```
220
+
221
+ ### Build Script
222
+
223
+ Use `buildAgents` to generate the registry at build time:
224
+
225
+ ```typescript
226
+ // scripts/build-agents.ts
227
+ import { buildAgents } from '@slashfi/agents-sdk';
228
+
229
+ const result = await buildAgents({
230
+ agentsDir: './src/agents',
231
+ outFile: './src/agents/_generated-registry.ts',
232
+ });
233
+
234
+ console.log(`Built ${result.agentCount} agents: ${result.agents.join(', ')}`);
235
+ ```
236
+
237
+ Run before TypeScript compilation:
238
+
239
+ ```bash
240
+ bun scripts/build-agents.ts && bun run build
241
+ ```
242
+
243
+ ### File Conventions
244
+
245
+ **entrypoint.md** - System prompt for the agent (markdown)
246
+
247
+ **agent.config.ts** - Agent configuration:
248
+ ```typescript
249
+ import type { AgentConfig } from '@slashfi/agents-sdk';
250
+
251
+ const config: AgentConfig = {
252
+ name: 'My Agent',
253
+ description: 'Does things',
254
+ supportedActions: ['execute_tool', 'describe_tools', 'load'],
255
+ };
256
+
257
+ export default config;
258
+ ```
259
+
260
+ **{name}.tool.ts** - Tool definition (exports `{name}Tool`):
261
+ ```typescript
262
+ import { defineTool } from '@slashfi/agents-sdk';
263
+
264
+ export const greetTool = defineTool({
265
+ name: 'greet',
266
+ description: 'Greet a user',
267
+ inputSchema: { ... },
268
+ execute: async (input) => ({ message: `Hello!` }),
269
+ });
270
+ ```
271
+
272
+ ## License
273
+
274
+ MIT
package/dist/auth.d.ts ADDED
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Auth Agent
3
+ *
4
+ * Built-in agent that provides OAuth2 client_credentials authentication.
5
+ * Register it into any agent registry to enable auth.
6
+ *
7
+ * Features:
8
+ * - Client credentials management (create, rotate, revoke)
9
+ * - OAuth2 client_credentials token exchange
10
+ * - JWT access tokens with scopes
11
+ * - Pluggable AuthStore interface (in-memory default)
12
+ * - Root key for admin operations
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { createAgentRegistry, createAgentServer, createAuthAgent } from '@slashfi/agents-sdk';
17
+ *
18
+ * const registry = createAgentRegistry();
19
+ * registry.register(createAuthAgent({ rootKey: process.env.ROOT_KEY }));
20
+ * registry.register(myAgent);
21
+ *
22
+ * const server = createAgentServer(registry, { port: 3000 });
23
+ * await server.start();
24
+ * ```
25
+ */
26
+ import type { AgentDefinition } from "./types.js";
27
+ /** Registered client */
28
+ export interface AuthClient {
29
+ clientId: string;
30
+ clientSecretHash: string;
31
+ name: string;
32
+ scopes: string[];
33
+ createdAt: number;
34
+ /** If true, this client was created via self-registration */
35
+ selfRegistered?: boolean;
36
+ }
37
+ /** Issued token metadata */
38
+ export interface AuthToken {
39
+ token: string;
40
+ clientId: string;
41
+ scopes: string[];
42
+ expiresAt: number;
43
+ issuedAt: number;
44
+ }
45
+ /** Resolved identity from a token or root key */
46
+ export interface AuthIdentity {
47
+ clientId: string;
48
+ name: string;
49
+ scopes: string[];
50
+ isRoot: boolean;
51
+ }
52
+ /**
53
+ * Pluggable storage for auth state.
54
+ * Implement this interface to use Postgres, Redis, SQLite, etc.
55
+ */
56
+ export interface AuthStore {
57
+ /** Create a new client. Returns the raw (unhashed) secret. */
58
+ createClient(name: string, scopes: string[], selfRegistered?: boolean): Promise<{
59
+ clientId: string;
60
+ clientSecret: string;
61
+ }>;
62
+ /** Validate client credentials. Returns client if valid, null otherwise. */
63
+ validateClient(clientId: string, clientSecret: string): Promise<AuthClient | null>;
64
+ /** Get client by ID. */
65
+ getClient(clientId: string): Promise<AuthClient | null>;
66
+ /** List all clients. */
67
+ listClients(): Promise<AuthClient[]>;
68
+ /** Revoke a client (delete). */
69
+ revokeClient(clientId: string): Promise<boolean>;
70
+ /** Rotate a client's secret. Returns new raw secret. */
71
+ rotateSecret(clientId: string): Promise<{
72
+ clientSecret: string;
73
+ } | null>;
74
+ /** Store a token. */
75
+ storeToken(token: AuthToken): Promise<void>;
76
+ /** Validate and retrieve a token. Returns null if invalid/expired. */
77
+ validateToken(tokenString: string): Promise<AuthToken | null>;
78
+ /** Revoke a specific token. */
79
+ revokeToken(tokenString: string): Promise<boolean>;
80
+ }
81
+ /**
82
+ * Create an in-memory auth store.
83
+ * Suitable for development and testing. Use a persistent store for production.
84
+ */
85
+ export declare function createMemoryAuthStore(): AuthStore;
86
+ export interface CreateAuthAgentOptions {
87
+ /** Root key for admin operations. Required. */
88
+ rootKey: string;
89
+ /** Allow self-registration via public `register` tool. Default: false */
90
+ allowRegistration?: boolean;
91
+ /** Max scopes that self-registered clients can request. Default: [] (no limit) */
92
+ registrationScopes?: string[];
93
+ /** Token TTL in seconds. Default: 3600 (1 hour) */
94
+ tokenTtl?: number;
95
+ /** Custom auth store. Default: in-memory */
96
+ store?: AuthStore;
97
+ }
98
+ /**
99
+ * Create the built-in `@auth` agent.
100
+ *
101
+ * Provides OAuth2 client_credentials authentication as agent tools.
102
+ * The server auto-detects this agent and wires up token validation.
103
+ */
104
+ export declare function createAuthAgent(options: CreateAuthAgentOptions): AgentDefinition & {
105
+ __authStore: AuthStore;
106
+ __rootKey: string;
107
+ __tokenTtl: number;
108
+ };
109
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAA+B,MAAM,YAAY,CAAC;AAM/E,wBAAwB;AACxB,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;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