@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/dist/define.js ADDED
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Define Agent and Tool Functions
3
+ *
4
+ * Factory functions for creating agent and tool definitions.
5
+ */
6
+ /**
7
+ * Create a tool definition.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const greet = defineTool({
12
+ * name: 'greet',
13
+ * description: 'Greet a user',
14
+ * inputSchema: {
15
+ * type: 'object',
16
+ * properties: {
17
+ * name: { type: 'string', description: 'Name to greet' }
18
+ * },
19
+ * required: ['name']
20
+ * },
21
+ * execute: async (input) => ({ message: `Hello, ${input.name}!` })
22
+ * });
23
+ * ```
24
+ */
25
+ export function defineTool(options) {
26
+ return {
27
+ name: options.name,
28
+ description: options.description,
29
+ inputSchema: options.inputSchema,
30
+ outputSchema: options.outputSchema,
31
+ visibility: options.visibility,
32
+ allowedCallers: options.allowedCallers,
33
+ execute: options.execute,
34
+ };
35
+ }
36
+ /**
37
+ * Create an agent definition.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const agent = defineAgent({
42
+ * path: '@my-agent',
43
+ * entrypoint: 'You are a helpful assistant.',
44
+ * config: {
45
+ * name: 'My Agent',
46
+ * description: 'A helpful agent'
47
+ * },
48
+ * tools: [greet, echo],
49
+ * runtime: () => ({
50
+ * onInvoke: async (ctx) => {
51
+ * console.log(`Invoked with: ${ctx.prompt}`);
52
+ * },
53
+ * onTick: async (ctx) => {
54
+ * console.log(`Tick at ${ctx.timestamp}`);
55
+ * }
56
+ * })
57
+ * });
58
+ * ```
59
+ */
60
+ export function defineAgent(options) {
61
+ return {
62
+ path: options.path,
63
+ entrypoint: options.entrypoint,
64
+ config: options.config,
65
+ tools: options.tools ?? [],
66
+ runtime: options.runtime,
67
+ visibility: options.visibility,
68
+ allowedCallers: options.allowedCallers,
69
+ };
70
+ }
71
+ //# sourceMappingURL=define.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2CH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,UAAU,CAKxB,OAAqD;IAErD,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC;AAkCD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,WAAW,CACzB,OAAqC;IAErC,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;QAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,cAAc,EAAE,OAAO,CAAC,cAAc;KACvC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Agents SDK
3
+ *
4
+ * SDK for building AI agents with tool definitions, JSON-RPC servers,
5
+ * and built-in OAuth2 authentication.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import {
10
+ * defineAgent,
11
+ * defineTool,
12
+ * createAgentRegistry,
13
+ * createAgentServer,
14
+ * createAuthAgent,
15
+ * } from '@slashfi/agents-sdk';
16
+ *
17
+ * // Define a tool
18
+ * const greet = defineTool({
19
+ * name: 'greet',
20
+ * description: 'Greet a user',
21
+ * inputSchema: {
22
+ * type: 'object',
23
+ * properties: {
24
+ * name: { type: 'string', description: 'Name to greet' }
25
+ * },
26
+ * required: ['name']
27
+ * },
28
+ * execute: async (input) => ({ message: `Hello, ${input.name}!` })
29
+ * });
30
+ *
31
+ * // Define an agent
32
+ * const agent = defineAgent({
33
+ * path: '@my-agent',
34
+ * entrypoint: 'You are a helpful assistant.',
35
+ * tools: [greet]
36
+ * });
37
+ *
38
+ * // Create registry with auth
39
+ * const registry = createAgentRegistry();
40
+ * registry.register(createAuthAgent({ rootKey: process.env.ROOT_KEY! }));
41
+ * registry.register(agent);
42
+ *
43
+ * // Start server - auth auto-detected
44
+ * const server = createAgentServer(registry, { port: 3000 });
45
+ * await server.start();
46
+ * ```
47
+ *
48
+ * @packageDocumentation
49
+ */
50
+ export type { AgentAction, AgentConfig, AgentDefinition, AgentRuntime, CallAgentAskRequest, CallAgentAskResponse, CallAgentDescribeToolsRequest, CallAgentDescribeToolsResponse, CallAgentErrorResponse, CallAgentExecuteToolRequest, CallAgentExecuteToolResponse, CallAgentInvokeRequest, CallAgentInvokeResponse, CallAgentLearnRequest, CallAgentLearnResponse, CallAgentLoadRequest, CallAgentLoadResponse, CallAgentRequest, CallAgentResponse, CallerType, CoreContext, InvokeContext, JsonSchema, LearnContext, MessageContext, StepContext, TickContext, ToolContext, ToolDefinition, ToolSchema, ToolSelectionContext, Visibility, } from "./types.js";
51
+ export { defineAgent, defineTool } from "./define.js";
52
+ export type { DefineAgentOptions, DefineToolOptions } from "./define.js";
53
+ export { createAgentRegistry } from "./registry.js";
54
+ export type { AgentRegistry, AgentRegistryOptions } from "./registry.js";
55
+ export { createAgentServer } from "./server.js";
56
+ export type { AgentServer, AgentServerOptions } from "./server.js";
57
+ export { createAuthAgent, createMemoryAuthStore } from "./auth.js";
58
+ export type { AuthClient, AuthIdentity, AuthStore, AuthToken, CreateAuthAgentOptions, } from "./auth.js";
59
+ export { buildAgents } from "./build.js";
60
+ export type { BuildAgentsOptions, BuildAgentsResult } from "./build.js";
61
+ //# sourceMappingURL=index.d.ts.map
@@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js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Agents SDK
3
+ *
4
+ * SDK for building AI agents with tool definitions, JSON-RPC servers,
5
+ * and built-in OAuth2 authentication.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import {
10
+ * defineAgent,
11
+ * defineTool,
12
+ * createAgentRegistry,
13
+ * createAgentServer,
14
+ * createAuthAgent,
15
+ * } from '@slashfi/agents-sdk';
16
+ *
17
+ * // Define a tool
18
+ * const greet = defineTool({
19
+ * name: 'greet',
20
+ * description: 'Greet a user',
21
+ * inputSchema: {
22
+ * type: 'object',
23
+ * properties: {
24
+ * name: { type: 'string', description: 'Name to greet' }
25
+ * },
26
+ * required: ['name']
27
+ * },
28
+ * execute: async (input) => ({ message: `Hello, ${input.name}!` })
29
+ * });
30
+ *
31
+ * // Define an agent
32
+ * const agent = defineAgent({
33
+ * path: '@my-agent',
34
+ * entrypoint: 'You are a helpful assistant.',
35
+ * tools: [greet]
36
+ * });
37
+ *
38
+ * // Create registry with auth
39
+ * const registry = createAgentRegistry();
40
+ * registry.register(createAuthAgent({ rootKey: process.env.ROOT_KEY! }));
41
+ * registry.register(agent);
42
+ *
43
+ * // Start server - auth auto-detected
44
+ * const server = createAgentServer(registry, { port: 3000 });
45
+ * await server.start();
46
+ * ```
47
+ *
48
+ * @packageDocumentation
49
+ */
50
+ // Define functions
51
+ export { defineAgent, defineTool } from "./define.js";
52
+ // Registry
53
+ export { createAgentRegistry } from "./registry.js";
54
+ // Server
55
+ export { createAgentServer } from "./server.js";
56
+ // Auth
57
+ export { createAuthAgent, createMemoryAuthStore } from "./auth.js";
58
+ // Build
59
+ export { buildAgents } from "./build.js";
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAsCH,mBAAmB;AACnB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGtD,WAAW;AACX,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGpD,SAAS;AACT,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO;AACP,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AASnE,QAAQ;AACR,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Agent Registry Implementation
3
+ *
4
+ * Manages registered agents and handles callAgent requests.
5
+ */
6
+ import type { AgentDefinition, CallAgentRequest, CallAgentResponse, Visibility } from "./types.js";
7
+ /**
8
+ * Options for creating an agent registry.
9
+ */
10
+ export interface AgentRegistryOptions {
11
+ /** Default visibility for agents without explicit visibility */
12
+ defaultVisibility?: Visibility;
13
+ }
14
+ /**
15
+ * Agent registry interface.
16
+ */
17
+ export interface AgentRegistry {
18
+ /** Register an agent */
19
+ register(agent: AgentDefinition): void;
20
+ /** Get an agent by path */
21
+ get(path: string): AgentDefinition | undefined;
22
+ /** Check if an agent exists */
23
+ has(path: string): boolean;
24
+ /** List all registered agents */
25
+ list(): AgentDefinition[];
26
+ /** List all registered agent paths */
27
+ listPaths(): string[];
28
+ /** Call an agent (execute action) */
29
+ call(request: CallAgentRequest): Promise<CallAgentResponse>;
30
+ }
31
+ /**
32
+ * Create an agent registry.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const registry = createAgentRegistry();
37
+ * registry.register(myAgent);
38
+ *
39
+ * const result = await registry.call({
40
+ * action: 'execute_tool',
41
+ * path: '@my-agent',
42
+ * tool: 'greet',
43
+ * params: { name: 'World' }
44
+ * });
45
+ * ```
46
+ */
47
+ export declare function createAgentRegistry(options?: AgentRegistryOptions): AgentRegistry;
48
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAEV,eAAe,EAMf,gBAAgB,EAChB,iBAAiB,EAIjB,UAAU,EACX,MAAM,YAAY,CAAC;AAapB;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,iBAAiB,CAAC,EAAE,UAAU,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,wBAAwB;IACxB,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IAEvC,2BAA2B;IAC3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IAE/C,+BAA+B;IAC/B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAE3B,iCAAiC;IACjC,IAAI,IAAI,eAAe,EAAE,CAAC;IAE1B,sCAAsC;IACtC,SAAS,IAAI,MAAM,EAAE,CAAC;IAEtB,qCAAqC;IACrC,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC7D;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,oBAAyB,GACjC,aAAa,CA4Tf"}
@@ -0,0 +1,274 @@
1
+ /**
2
+ * Agent Registry Implementation
3
+ *
4
+ * Manages registered agents and handles callAgent requests.
5
+ */
6
+ /** Default supported actions if not specified */
7
+ const DEFAULT_SUPPORTED_ACTIONS = [
8
+ "execute_tool",
9
+ "describe_tools",
10
+ "load",
11
+ ];
12
+ // ============================================
13
+ // Create Registry
14
+ // ============================================
15
+ /**
16
+ * Create an agent registry.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const registry = createAgentRegistry();
21
+ * registry.register(myAgent);
22
+ *
23
+ * const result = await registry.call({
24
+ * action: 'execute_tool',
25
+ * path: '@my-agent',
26
+ * tool: 'greet',
27
+ * params: { name: 'World' }
28
+ * });
29
+ * ```
30
+ */
31
+ export function createAgentRegistry(options = {}) {
32
+ const { defaultVisibility = "internal" } = options;
33
+ const agents = new Map();
34
+ /**
35
+ * Check if agent supports the requested action.
36
+ */
37
+ function checkActionSupported(agent, action) {
38
+ const supported = agent.config?.supportedActions ?? DEFAULT_SUPPORTED_ACTIONS;
39
+ return supported.includes(action);
40
+ }
41
+ /**
42
+ * Check if caller is allowed to access the agent.
43
+ */
44
+ function checkAgentAccess(agent, callerId, callerType) {
45
+ const visibility = agent.visibility ?? defaultVisibility;
46
+ // System callers can access everything
47
+ if (callerType === "system")
48
+ return true;
49
+ // Check explicit allowlist first
50
+ if (agent.allowedCallers && callerId) {
51
+ if (agent.allowedCallers.includes(callerId))
52
+ return true;
53
+ }
54
+ // Check visibility
55
+ switch (visibility) {
56
+ case "public":
57
+ return true;
58
+ case "internal":
59
+ // Authenticated callers (agents or users with a callerId) can access
60
+ return (callerType === "agent" || (callerType != null && callerId != null));
61
+ case "private":
62
+ // Only self can access
63
+ return callerId === agent.path;
64
+ default:
65
+ return false;
66
+ }
67
+ }
68
+ /**
69
+ * Check if caller is allowed to use a tool.
70
+ */
71
+ function checkToolAccess(agent, toolName, callerId, callerType) {
72
+ const tool = agent.tools.find((t) => t.name === toolName);
73
+ if (!tool)
74
+ return false;
75
+ const visibility = tool.visibility ?? "public";
76
+ // System callers can access everything
77
+ if (callerType === "system")
78
+ return true;
79
+ // Check explicit allowlist first
80
+ if (tool.allowedCallers && callerId) {
81
+ if (tool.allowedCallers.includes(callerId))
82
+ return true;
83
+ }
84
+ // Check visibility
85
+ switch (visibility) {
86
+ case "public":
87
+ return true;
88
+ case "internal":
89
+ return (callerType === "agent" || (callerType != null && callerId != null));
90
+ case "private":
91
+ return callerId === agent.path;
92
+ default:
93
+ return false;
94
+ }
95
+ }
96
+ const registry = {
97
+ register(agent) {
98
+ agents.set(agent.path, agent);
99
+ },
100
+ get(path) {
101
+ return agents.get(path);
102
+ },
103
+ has(path) {
104
+ return agents.has(path);
105
+ },
106
+ list() {
107
+ return Array.from(agents.values());
108
+ },
109
+ listPaths() {
110
+ return Array.from(agents.keys());
111
+ },
112
+ async call(request) {
113
+ const agent = agents.get(request.path);
114
+ if (!agent) {
115
+ return {
116
+ success: false,
117
+ error: `Agent not found: ${request.path}`,
118
+ code: "AGENT_NOT_FOUND",
119
+ };
120
+ }
121
+ // Check agent access
122
+ if (!checkAgentAccess(agent, request.callerId, request.callerType)) {
123
+ return {
124
+ success: false,
125
+ error: `Access denied to agent: ${request.path}`,
126
+ code: "ACCESS_DENIED",
127
+ };
128
+ }
129
+ // Check action is supported
130
+ if (!checkActionSupported(agent, request.action)) {
131
+ const supported = agent.config?.supportedActions ?? DEFAULT_SUPPORTED_ACTIONS;
132
+ return {
133
+ success: false,
134
+ error: `Action '${request.action}' not supported by agent. Supported: ${supported.join(", ")}`,
135
+ code: "ACTION_NOT_SUPPORTED",
136
+ };
137
+ }
138
+ switch (request.action) {
139
+ case "invoke":
140
+ case "ask": {
141
+ // Get runtime if available
142
+ const runtime = agent.runtime?.();
143
+ // Call onInvoke hook if defined
144
+ if (runtime?.onInvoke) {
145
+ await runtime.onInvoke({
146
+ tenantId: "default",
147
+ agentPath: request.path,
148
+ prompt: request.prompt,
149
+ sessionId: request.sessionId,
150
+ callerId: request.callerId ?? "unknown",
151
+ callerType: request.callerType ?? "system",
152
+ metadata: request.metadata,
153
+ });
154
+ }
155
+ // These actions require an LLM runtime which this SDK doesn't provide
156
+ // Users can implement their own invoke/ask handlers or use a full runtime
157
+ return {
158
+ success: false,
159
+ error: `Action '${request.action}' requires an LLM runtime. Use execute_tool for direct tool calls.`,
160
+ code: "RUNTIME_REQUIRED",
161
+ };
162
+ }
163
+ case "execute_tool": {
164
+ const tool = agent.tools.find((t) => t.name === request.tool);
165
+ if (!tool) {
166
+ return {
167
+ success: false,
168
+ error: `Tool not found: ${request.tool}`,
169
+ code: "TOOL_NOT_FOUND",
170
+ };
171
+ }
172
+ // Check tool access
173
+ if (!checkToolAccess(agent, request.tool, request.callerId, request.callerType)) {
174
+ return {
175
+ success: false,
176
+ error: `Access denied to tool: ${request.tool}`,
177
+ code: "ACCESS_DENIED",
178
+ };
179
+ }
180
+ const ctx = {
181
+ tenantId: "default",
182
+ agentPath: agent.path,
183
+ callerId: request.callerId ?? "unknown",
184
+ callerType: request.callerType ?? "system",
185
+ metadata: request.metadata,
186
+ };
187
+ try {
188
+ const result = await tool.execute(request.params, ctx);
189
+ return {
190
+ success: true,
191
+ result,
192
+ };
193
+ }
194
+ catch (err) {
195
+ return {
196
+ success: false,
197
+ error: err instanceof Error ? err.message : String(err),
198
+ code: "TOOL_EXECUTION_ERROR",
199
+ };
200
+ }
201
+ }
202
+ case "describe_tools": {
203
+ const toolSchemas = agent.tools
204
+ .filter((t) => checkToolAccess(agent, t.name, request.callerId, request.callerType))
205
+ .filter((t) => request.tools ? request.tools.includes(t.name) : true)
206
+ .map((t) => ({
207
+ name: t.name,
208
+ description: t.description,
209
+ inputSchema: t.inputSchema,
210
+ ...(t.outputSchema && { outputSchema: t.outputSchema }),
211
+ }));
212
+ return {
213
+ success: true,
214
+ tools: toolSchemas,
215
+ };
216
+ }
217
+ case "load": {
218
+ const toolSchemas = agent.tools
219
+ .filter((t) => checkToolAccess(agent, t.name, request.callerId, request.callerType))
220
+ .map((t) => ({
221
+ name: t.name,
222
+ description: t.description,
223
+ inputSchema: t.inputSchema,
224
+ ...(t.outputSchema && { outputSchema: t.outputSchema }),
225
+ }));
226
+ return {
227
+ success: true,
228
+ result: {
229
+ path: agent.path,
230
+ entrypoint: agent.entrypoint,
231
+ config: agent.config,
232
+ tools: toolSchemas,
233
+ },
234
+ };
235
+ }
236
+ case "learn": {
237
+ // Get runtime if available
238
+ const runtime = agent.runtime?.();
239
+ // Call onLearn hook if defined
240
+ if (runtime?.onLearn) {
241
+ await runtime.onLearn({
242
+ tenantId: "default",
243
+ agentPath: request.path,
244
+ content: request.content,
245
+ scope: request.scope ?? "session",
246
+ category: request.category,
247
+ callerId: request.callerId ?? "unknown",
248
+ });
249
+ return {
250
+ success: true,
251
+ action: "stored",
252
+ };
253
+ }
254
+ // No runtime or no onLearn hook - ignore
255
+ return {
256
+ success: true,
257
+ action: "ignored",
258
+ };
259
+ }
260
+ default: {
261
+ // TypeScript exhaustiveness check
262
+ const _exhaustive = request;
263
+ return {
264
+ success: false,
265
+ error: `Unknown action: ${_exhaustive.action}`,
266
+ code: "UNKNOWN_ACTION",
267
+ };
268
+ }
269
+ }
270
+ },
271
+ };
272
+ return registry;
273
+ }
274
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,iDAAiD;AACjD,MAAM,yBAAyB,GAAkB;IAC/C,cAAc;IACd,gBAAgB;IAChB,MAAM;CACP,CAAC;AAqCF,+CAA+C;AAC/C,kBAAkB;AAClB,+CAA+C;AAE/C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAgC,EAAE;IAElC,MAAM,EAAE,iBAAiB,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IACnD,MAAM,MAAM,GAAG,IAAI,GAAG,EAA2B,CAAC;IAElD;;OAEG;IACH,SAAS,oBAAoB,CAC3B,KAAsB,EACtB,MAAmB;QAEnB,MAAM,SAAS,GACb,KAAK,CAAC,MAAM,EAAE,gBAAgB,IAAI,yBAAyB,CAAC;QAC9D,OAAO,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,SAAS,gBAAgB,CACvB,KAAsB,EACtB,QAAiB,EACjB,UAAmB;QAEnB,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,iBAAiB,CAAC;QAEzD,uCAAuC;QACvC,IAAI,UAAU,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAEzC,iCAAiC;QACjC,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AAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Agent Server
3
+ *
4
+ * HTTP server that exposes the agent registry via JSON-RPC endpoints.
5
+ * Compatible with MCP (Model Context Protocol) over HTTP.
6
+ *
7
+ * Endpoints:
8
+ * - POST /call - Execute agent actions (execute_tool, describe_tools, load)
9
+ * - GET /list - List registered agents
10
+ * - POST /oauth/token - OAuth2 token endpoint (when @auth is registered)
11
+ *
12
+ * Auth Integration:
13
+ * When an `@auth` agent is registered, the server automatically:
14
+ * - Validates Bearer tokens on requests
15
+ * - Resolves tokens to identity + scopes
16
+ * - Populates callerId, callerType in the request context
17
+ * - Recognizes the root key for admin access
18
+ * - Mounts the /oauth/token endpoint
19
+ */
20
+ import type { AgentRegistry } from "./registry.js";
21
+ /**
22
+ * Server configuration options.
23
+ */
24
+ export interface AgentServerOptions {
25
+ /** Port to listen on (default: 3000) */
26
+ port?: number;
27
+ /** Hostname to bind to (default: 'localhost') */
28
+ hostname?: string;
29
+ /** Base path for endpoints (default: '') */
30
+ basePath?: string;
31
+ /** Enable CORS (default: true) */
32
+ cors?: boolean;
33
+ /** Custom request handler for unmatched routes */
34
+ onNotFound?: (req: Request) => Response | Promise<Response>;
35
+ }
36
+ /**
37
+ * Agent server instance.
38
+ */
39
+ export interface AgentServer {
40
+ /** Start the server */
41
+ start(): Promise<void>;
42
+ /** Stop the server */
43
+ stop(): Promise<void>;
44
+ /** Handle a request (for custom integrations) */
45
+ fetch(req: Request): Promise<Response>;
46
+ /** Get the server URL (only available after start) */
47
+ url: string | null;
48
+ }
49
+ /**
50
+ * Create an HTTP server for the agent registry.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const registry = createAgentRegistry();
55
+ * registry.register(createAuthAgent({ rootKey: 'rk_xxx' }));
56
+ * registry.register(myAgent);
57
+ *
58
+ * const server = createAgentServer(registry, { port: 3000 });
59
+ * await server.start();
60
+ * // POST /call - Execute agent actions
61
+ * // GET /list - List agents (filtered by auth)
62
+ * // POST /oauth/token - OAuth2 token endpoint
63
+ * ```
64
+ */
65
+ export declare function createAgentServer(registry: AgentRegistry, options?: AgentServerOptions): AgentServer;
66
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAOnD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,kCAAkC;IAClC,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,kDAAkD;IAClD,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC7D;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,uBAAuB;IACvB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,sBAAsB;IACtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB,iDAAiD;IACjD,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEvC,sDAAsD;IACtD,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAqHD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,aAAa,EACvB,OAAO,GAAE,kBAAuB,GAC/B,WAAW,CAoQb"}