@lov3kaizen/agentsea-nestjs 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) 2024 lovekaizen
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,110 @@
1
+ # @agentsea/nestjs
2
+
3
+ NestJS integration for AgentSea - Unite and orchestrate AI agents in your NestJS applications.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@agentsea/nestjs.svg)](https://www.npmjs.com/package/@agentsea/nestjs)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
8
+
9
+ ## Features
10
+
11
+ - Decorators for agents and tools (`@Agent`, `@Tool`)
12
+ - REST API endpoints for agent execution
13
+ - WebSocket gateway for real-time streaming
14
+ - Rate limiting guard
15
+ - Full dependency injection support
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @agentsea/nestjs @agentsea/core
21
+ # or
22
+ pnpm add @agentsea/nestjs @agentsea/core
23
+ # or
24
+ yarn add @agentsea/nestjs @agentsea/core
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```typescript
30
+ import { Module } from '@nestjs/common';
31
+ import { AgenticModule } from '@agentsea/nestjs';
32
+ import { AnthropicProvider } from '@agentsea/core';
33
+
34
+ @Module({
35
+ imports: [
36
+ AgenticModule.forRoot({
37
+ provider: new AnthropicProvider(),
38
+ defaultConfig: {
39
+ model: 'claude-sonnet-4-20250514',
40
+ provider: 'anthropic',
41
+ },
42
+ enableRestApi: true,
43
+ enableWebSocket: true,
44
+ }),
45
+ ],
46
+ })
47
+ export class AppModule {}
48
+ ```
49
+
50
+ ## REST API Endpoints
51
+
52
+ When `enableRestApi` is set to `true`:
53
+
54
+ - `GET /agents` - List all agents
55
+ - `GET /agents/:name` - Get agent details
56
+ - `POST /agents/:name/execute` - Execute agent
57
+ - `POST /agents/:name/stream` - Stream agent response (SSE)
58
+
59
+ ## WebSocket Events
60
+
61
+ When `enableWebSocket` is set to `true`:
62
+
63
+ - `execute` - Execute an agent
64
+ - `stream` - Real-time streaming events
65
+ - `listAgents` - Get available agents
66
+ - `getAgent` - Get agent info
67
+
68
+ ## Creating Agents with Decorators
69
+
70
+ ```typescript
71
+ import { Injectable } from '@nestjs/common';
72
+ import { Agent, Tool } from '@agentsea/nestjs';
73
+
74
+ @Injectable()
75
+ @Agent({
76
+ name: 'assistant',
77
+ description: 'A helpful assistant',
78
+ model: 'claude-sonnet-4-20250514',
79
+ provider: 'anthropic',
80
+ })
81
+ export class AssistantAgent {
82
+ @Tool({
83
+ name: 'greet',
84
+ description: 'Greet a user by name',
85
+ parameters: {
86
+ name: { type: 'string', description: 'The name to greet' },
87
+ },
88
+ })
89
+ greet(params: { name: string }) {
90
+ return `Hello, ${params.name}!`;
91
+ }
92
+ }
93
+ ```
94
+
95
+ ## Documentation
96
+
97
+ Full documentation available at [agentsea.dev](https://agentsea.dev)
98
+
99
+ - [NestJS Integration](https://agentsea.dev/docs/nestjs)
100
+ - [API Reference](https://agentsea.dev/api)
101
+
102
+ ## Related Packages
103
+
104
+ - [@agentsea/core](https://www.npmjs.com/package/@agentsea/core) - Core library
105
+ - [@agentsea/cli](https://www.npmjs.com/package/@agentsea/cli) - Command-line interface
106
+ - [@agentsea/react](https://www.npmjs.com/package/@agentsea/react) - React components
107
+
108
+ ## License
109
+
110
+ MIT License - see [LICENSE](../../LICENSE) for details
@@ -0,0 +1,203 @@
1
+ import * as _lov3kaizen_agentsea_core from '@lov3kaizen/agentsea-core';
2
+ import { AgentConfig, LLMProvider, MemoryStore, TenantManager, Message, OutputFormat, FormatOptions, Agent as Agent$1, Tenant as Tenant$1, TenantStatus } from '@lov3kaizen/agentsea-core';
3
+ export * from '@lov3kaizen/agentsea-core';
4
+ import { DynamicModule, CanActivate, ExecutionContext } from '@nestjs/common';
5
+ import { Reflector } from '@nestjs/core';
6
+ import { Observable } from 'rxjs';
7
+ import { Server, Socket } from 'socket.io';
8
+
9
+ declare const AGENT_METADATA = "agentsea:agent";
10
+ declare function Agent(config: Partial<AgentConfig>): ClassDecorator;
11
+
12
+ declare const TOOL_METADATA = "agentsea:tool";
13
+ interface ToolOptions {
14
+ name: string;
15
+ description: string;
16
+ }
17
+ declare function Tool(options: ToolOptions): MethodDecorator;
18
+
19
+ declare const Tenant: (...dataOrPipes: unknown[]) => ParameterDecorator;
20
+ declare const TenantId: (...dataOrPipes: unknown[]) => ParameterDecorator;
21
+
22
+ interface AgenticModuleOptions {
23
+ provider: 'anthropic' | 'openai' | LLMProvider;
24
+ apiKey?: string;
25
+ memory?: MemoryStore;
26
+ defaultAgentConfig?: Partial<AgentConfig>;
27
+ enableRestApi?: boolean;
28
+ enableWebSocket?: boolean;
29
+ }
30
+ declare class AgenticModule {
31
+ static forRoot(options: AgenticModuleOptions): DynamicModule;
32
+ static forRootAsync(options: {
33
+ imports?: any[];
34
+ useFactory: (...args: any[]) => Promise<AgenticModuleOptions> | AgenticModuleOptions;
35
+ inject?: any[];
36
+ }): DynamicModule;
37
+ }
38
+
39
+ declare const RATE_LIMIT_METADATA = "agentsea:rate-limit";
40
+ interface RateLimitOptions {
41
+ maxRequests: number;
42
+ windowMs: number;
43
+ keyExtractor?: (context: ExecutionContext) => string;
44
+ }
45
+ declare class RateLimitGuard implements CanActivate {
46
+ private reflector;
47
+ private limiters;
48
+ constructor(reflector: Reflector);
49
+ canActivate(context: ExecutionContext): boolean;
50
+ private getDefaultKey;
51
+ }
52
+ declare function RateLimit(options: RateLimitOptions): MethodDecorator;
53
+
54
+ interface TenantGuardOptions {
55
+ tenantManager: TenantManager;
56
+ apiKeyHeader?: string;
57
+ tenantIdHeader?: string;
58
+ tenantQuery?: string;
59
+ useSubdomain?: boolean;
60
+ allowAnonymous?: boolean;
61
+ }
62
+ declare class TenantGuard implements CanActivate {
63
+ private tenantManager;
64
+ private apiKeyHeader;
65
+ private tenantIdHeader;
66
+ private tenantQuery;
67
+ private useSubdomain;
68
+ private allowAnonymous;
69
+ constructor(options: TenantGuardOptions);
70
+ canActivate(context: ExecutionContext): Promise<boolean>;
71
+ }
72
+
73
+ declare class ExecuteAgentDto {
74
+ input: string;
75
+ conversationId?: string;
76
+ userId?: string;
77
+ sessionData?: Record<string, any>;
78
+ history?: Message[];
79
+ metadata?: Record<string, any>;
80
+ outputFormat?: OutputFormat;
81
+ formatOptions?: FormatOptions;
82
+ }
83
+
84
+ declare class AgentService {
85
+ private agents;
86
+ registerAgent(agent: Agent$1): void;
87
+ getAgent(name: string): Agent$1 | undefined;
88
+ getAllAgents(): Agent$1[];
89
+ hasAgent(name: string): boolean;
90
+ unregisterAgent(name: string): boolean;
91
+ }
92
+
93
+ declare class AgentController {
94
+ private readonly agentService;
95
+ constructor(agentService: AgentService);
96
+ execute(name: string, dto: ExecuteAgentDto): Promise<{
97
+ success: boolean;
98
+ data: _lov3kaizen_agentsea_core.AgentResponse;
99
+ conversationId: string;
100
+ }>;
101
+ stream(name: string, dto: ExecuteAgentDto): Observable<MessageEvent>;
102
+ listAgents(): {
103
+ success: boolean;
104
+ data: {
105
+ name: string;
106
+ description: string;
107
+ model: string;
108
+ provider: string;
109
+ tools: string[];
110
+ }[];
111
+ };
112
+ getAgent(name: string): {
113
+ success: boolean;
114
+ data: {
115
+ name: string;
116
+ description: string;
117
+ model: string;
118
+ provider: string;
119
+ systemPrompt: string | undefined;
120
+ tools: {
121
+ name: string;
122
+ description: string;
123
+ }[];
124
+ temperature: number | undefined;
125
+ maxTokens: number | undefined;
126
+ maxIterations: number | undefined;
127
+ };
128
+ };
129
+ deleteConversation(_name: string, conversationId: string): {
130
+ success: boolean;
131
+ message: string;
132
+ };
133
+ }
134
+
135
+ declare class CreateTenantDto {
136
+ name: string;
137
+ slug: string;
138
+ metadata?: Record<string, unknown>;
139
+ settings?: Tenant$1['settings'];
140
+ }
141
+ declare class UpdateTenantDto {
142
+ name?: string;
143
+ slug?: string;
144
+ metadata?: Record<string, unknown>;
145
+ settings?: Tenant$1['settings'];
146
+ status?: TenantStatus;
147
+ }
148
+ declare class CreateApiKeyDto {
149
+ name: string;
150
+ scopes?: string[];
151
+ expiresAt?: Date;
152
+ }
153
+ declare class ListTenantsQuery {
154
+ limit?: number;
155
+ offset?: number;
156
+ status?: TenantStatus;
157
+ }
158
+ declare class TenantController {
159
+ private readonly tenantManager;
160
+ constructor(tenantManager: TenantManager);
161
+ createTenant(dto: CreateTenantDto): Promise<Tenant$1>;
162
+ listTenants(query: ListTenantsQuery): Promise<{
163
+ tenants: Tenant$1[];
164
+ total: number;
165
+ }>;
166
+ getTenant(id: string): Promise<Tenant$1 | null>;
167
+ updateTenant(id: string, dto: UpdateTenantDto): Promise<Tenant$1>;
168
+ deleteTenant(id: string): Promise<void>;
169
+ suspendTenant(id: string): Promise<Tenant$1>;
170
+ activateTenant(id: string): Promise<Tenant$1>;
171
+ createApiKey(id: string, dto: CreateApiKeyDto): Promise<{
172
+ apiKey: string;
173
+ name: string;
174
+ scopes: string[];
175
+ }>;
176
+ checkQuota(id: string, resource: string): Promise<{
177
+ allowed: boolean;
178
+ remaining: number;
179
+ }>;
180
+ }
181
+
182
+ declare class AgentGateway {
183
+ private readonly agentService;
184
+ server: Server;
185
+ constructor(agentService: AgentService);
186
+ handleExecute(client: Socket, data: {
187
+ agentName: string;
188
+ input: string;
189
+ conversationId?: string;
190
+ userId?: string;
191
+ sessionData?: Record<string, any>;
192
+ history?: any[];
193
+ metadata?: Record<string, any>;
194
+ }): Promise<void>;
195
+ handleGetAgent(client: Socket, data: {
196
+ agentName: string;
197
+ }): void;
198
+ handleListAgents(client: Socket): void;
199
+ }
200
+
201
+ declare const AGENTSEA_NESTJS_VERSION = "0.1.0";
202
+
203
+ export { AGENTSEA_NESTJS_VERSION, AGENT_METADATA, AgentController, Agent as AgentDecorator, AgentGateway, AgentService, AgenticModule, type AgenticModuleOptions, CreateApiKeyDto, CreateTenantDto, ExecuteAgentDto, ListTenantsQuery, RATE_LIMIT_METADATA, RateLimit, RateLimitGuard, type RateLimitOptions, TOOL_METADATA, Tenant, TenantController, TenantGuard, type TenantGuardOptions, TenantId, Tool as ToolDecorator, type ToolOptions, UpdateTenantDto };
@@ -0,0 +1,203 @@
1
+ import * as _lov3kaizen_agentsea_core from '@lov3kaizen/agentsea-core';
2
+ import { AgentConfig, LLMProvider, MemoryStore, TenantManager, Message, OutputFormat, FormatOptions, Agent as Agent$1, Tenant as Tenant$1, TenantStatus } from '@lov3kaizen/agentsea-core';
3
+ export * from '@lov3kaizen/agentsea-core';
4
+ import { DynamicModule, CanActivate, ExecutionContext } from '@nestjs/common';
5
+ import { Reflector } from '@nestjs/core';
6
+ import { Observable } from 'rxjs';
7
+ import { Server, Socket } from 'socket.io';
8
+
9
+ declare const AGENT_METADATA = "agentsea:agent";
10
+ declare function Agent(config: Partial<AgentConfig>): ClassDecorator;
11
+
12
+ declare const TOOL_METADATA = "agentsea:tool";
13
+ interface ToolOptions {
14
+ name: string;
15
+ description: string;
16
+ }
17
+ declare function Tool(options: ToolOptions): MethodDecorator;
18
+
19
+ declare const Tenant: (...dataOrPipes: unknown[]) => ParameterDecorator;
20
+ declare const TenantId: (...dataOrPipes: unknown[]) => ParameterDecorator;
21
+
22
+ interface AgenticModuleOptions {
23
+ provider: 'anthropic' | 'openai' | LLMProvider;
24
+ apiKey?: string;
25
+ memory?: MemoryStore;
26
+ defaultAgentConfig?: Partial<AgentConfig>;
27
+ enableRestApi?: boolean;
28
+ enableWebSocket?: boolean;
29
+ }
30
+ declare class AgenticModule {
31
+ static forRoot(options: AgenticModuleOptions): DynamicModule;
32
+ static forRootAsync(options: {
33
+ imports?: any[];
34
+ useFactory: (...args: any[]) => Promise<AgenticModuleOptions> | AgenticModuleOptions;
35
+ inject?: any[];
36
+ }): DynamicModule;
37
+ }
38
+
39
+ declare const RATE_LIMIT_METADATA = "agentsea:rate-limit";
40
+ interface RateLimitOptions {
41
+ maxRequests: number;
42
+ windowMs: number;
43
+ keyExtractor?: (context: ExecutionContext) => string;
44
+ }
45
+ declare class RateLimitGuard implements CanActivate {
46
+ private reflector;
47
+ private limiters;
48
+ constructor(reflector: Reflector);
49
+ canActivate(context: ExecutionContext): boolean;
50
+ private getDefaultKey;
51
+ }
52
+ declare function RateLimit(options: RateLimitOptions): MethodDecorator;
53
+
54
+ interface TenantGuardOptions {
55
+ tenantManager: TenantManager;
56
+ apiKeyHeader?: string;
57
+ tenantIdHeader?: string;
58
+ tenantQuery?: string;
59
+ useSubdomain?: boolean;
60
+ allowAnonymous?: boolean;
61
+ }
62
+ declare class TenantGuard implements CanActivate {
63
+ private tenantManager;
64
+ private apiKeyHeader;
65
+ private tenantIdHeader;
66
+ private tenantQuery;
67
+ private useSubdomain;
68
+ private allowAnonymous;
69
+ constructor(options: TenantGuardOptions);
70
+ canActivate(context: ExecutionContext): Promise<boolean>;
71
+ }
72
+
73
+ declare class ExecuteAgentDto {
74
+ input: string;
75
+ conversationId?: string;
76
+ userId?: string;
77
+ sessionData?: Record<string, any>;
78
+ history?: Message[];
79
+ metadata?: Record<string, any>;
80
+ outputFormat?: OutputFormat;
81
+ formatOptions?: FormatOptions;
82
+ }
83
+
84
+ declare class AgentService {
85
+ private agents;
86
+ registerAgent(agent: Agent$1): void;
87
+ getAgent(name: string): Agent$1 | undefined;
88
+ getAllAgents(): Agent$1[];
89
+ hasAgent(name: string): boolean;
90
+ unregisterAgent(name: string): boolean;
91
+ }
92
+
93
+ declare class AgentController {
94
+ private readonly agentService;
95
+ constructor(agentService: AgentService);
96
+ execute(name: string, dto: ExecuteAgentDto): Promise<{
97
+ success: boolean;
98
+ data: _lov3kaizen_agentsea_core.AgentResponse;
99
+ conversationId: string;
100
+ }>;
101
+ stream(name: string, dto: ExecuteAgentDto): Observable<MessageEvent>;
102
+ listAgents(): {
103
+ success: boolean;
104
+ data: {
105
+ name: string;
106
+ description: string;
107
+ model: string;
108
+ provider: string;
109
+ tools: string[];
110
+ }[];
111
+ };
112
+ getAgent(name: string): {
113
+ success: boolean;
114
+ data: {
115
+ name: string;
116
+ description: string;
117
+ model: string;
118
+ provider: string;
119
+ systemPrompt: string | undefined;
120
+ tools: {
121
+ name: string;
122
+ description: string;
123
+ }[];
124
+ temperature: number | undefined;
125
+ maxTokens: number | undefined;
126
+ maxIterations: number | undefined;
127
+ };
128
+ };
129
+ deleteConversation(_name: string, conversationId: string): {
130
+ success: boolean;
131
+ message: string;
132
+ };
133
+ }
134
+
135
+ declare class CreateTenantDto {
136
+ name: string;
137
+ slug: string;
138
+ metadata?: Record<string, unknown>;
139
+ settings?: Tenant$1['settings'];
140
+ }
141
+ declare class UpdateTenantDto {
142
+ name?: string;
143
+ slug?: string;
144
+ metadata?: Record<string, unknown>;
145
+ settings?: Tenant$1['settings'];
146
+ status?: TenantStatus;
147
+ }
148
+ declare class CreateApiKeyDto {
149
+ name: string;
150
+ scopes?: string[];
151
+ expiresAt?: Date;
152
+ }
153
+ declare class ListTenantsQuery {
154
+ limit?: number;
155
+ offset?: number;
156
+ status?: TenantStatus;
157
+ }
158
+ declare class TenantController {
159
+ private readonly tenantManager;
160
+ constructor(tenantManager: TenantManager);
161
+ createTenant(dto: CreateTenantDto): Promise<Tenant$1>;
162
+ listTenants(query: ListTenantsQuery): Promise<{
163
+ tenants: Tenant$1[];
164
+ total: number;
165
+ }>;
166
+ getTenant(id: string): Promise<Tenant$1 | null>;
167
+ updateTenant(id: string, dto: UpdateTenantDto): Promise<Tenant$1>;
168
+ deleteTenant(id: string): Promise<void>;
169
+ suspendTenant(id: string): Promise<Tenant$1>;
170
+ activateTenant(id: string): Promise<Tenant$1>;
171
+ createApiKey(id: string, dto: CreateApiKeyDto): Promise<{
172
+ apiKey: string;
173
+ name: string;
174
+ scopes: string[];
175
+ }>;
176
+ checkQuota(id: string, resource: string): Promise<{
177
+ allowed: boolean;
178
+ remaining: number;
179
+ }>;
180
+ }
181
+
182
+ declare class AgentGateway {
183
+ private readonly agentService;
184
+ server: Server;
185
+ constructor(agentService: AgentService);
186
+ handleExecute(client: Socket, data: {
187
+ agentName: string;
188
+ input: string;
189
+ conversationId?: string;
190
+ userId?: string;
191
+ sessionData?: Record<string, any>;
192
+ history?: any[];
193
+ metadata?: Record<string, any>;
194
+ }): Promise<void>;
195
+ handleGetAgent(client: Socket, data: {
196
+ agentName: string;
197
+ }): void;
198
+ handleListAgents(client: Socket): void;
199
+ }
200
+
201
+ declare const AGENTSEA_NESTJS_VERSION = "0.1.0";
202
+
203
+ export { AGENTSEA_NESTJS_VERSION, AGENT_METADATA, AgentController, Agent as AgentDecorator, AgentGateway, AgentService, AgenticModule, type AgenticModuleOptions, CreateApiKeyDto, CreateTenantDto, ExecuteAgentDto, ListTenantsQuery, RATE_LIMIT_METADATA, RateLimit, RateLimitGuard, type RateLimitOptions, TOOL_METADATA, Tenant, TenantController, TenantGuard, type TenantGuardOptions, TenantId, Tool as ToolDecorator, type ToolOptions, UpdateTenantDto };