@invect/nestjs 0.0.1

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) 2025 @robase
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,269 @@
1
+ # invect Backend
2
+
3
+ # @invect/nestjs
4
+
5
+ A NestJS module that provides Invect workflow execution capabilities as a thin wrapper over the core Invect engine.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @invect/nestjs @invect/core
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Basic Usage
16
+
17
+ Import the `InvectModule` in your application module:
18
+
19
+ ```typescript
20
+ import { Module } from '@nestjs/common';
21
+ import { InvectModule } from '@invect/nestjs';
22
+
23
+ @Module({
24
+ imports: [
25
+ InvectModule.forRoot({
26
+ // Invect configuration
27
+ database: {
28
+ type: 'sqlite',
29
+ url: 'file:./dev.db'
30
+ },
31
+ execution: {
32
+ maxConcurrentFlows: 10,
33
+ maxConcurrentNodes: 50
34
+ },
35
+ logging: {
36
+ level: 'info'
37
+ }
38
+ })
39
+ ],
40
+ controllers: [],
41
+ providers: [],
42
+ })
43
+ export class AppModule {}
44
+ ```
45
+
46
+ ### Async Configuration
47
+
48
+ For dynamic configuration (e.g., from environment variables or config service):
49
+
50
+ ```typescript
51
+ import { Module } from '@nestjs/common';
52
+ import { ConfigModule, ConfigService } from '@nestjs/config';
53
+ import { InvectModule } from '@invect/nestjs';
54
+
55
+ @Module({
56
+ imports: [
57
+ ConfigModule.forRoot(),
58
+ InvectModule.forRootAsync({
59
+ useFactory: (configService: ConfigService) => ({
60
+ database: {
61
+ type: 'postgres',
62
+ url: configService.get('DATABASE_URL')
63
+ },
64
+ execution: {
65
+ maxConcurrentFlows: configService.get('MAX_CONCURRENT_FLOWS', 10),
66
+ maxConcurrentNodes: configService.get('MAX_CONCURRENT_NODES', 50)
67
+ },
68
+ logging: {
69
+ level: configService.get('LOG_LEVEL', 'info')
70
+ }
71
+ }),
72
+ inject: [ConfigService],
73
+ }),
74
+ ],
75
+ })
76
+ export class AppModule {}
77
+ ```
78
+
79
+ ### Using the Invect Service
80
+
81
+ If you need to access the Invect core instance programmatically in your own services:
82
+
83
+ ```typescript
84
+ import { Injectable } from '@nestjs/common';
85
+ import { InvectService } from '@invect/nestjs';
86
+
87
+ @Injectable()
88
+ export class MyService {
89
+ constructor(private readonly invectService: InvectService) {}
90
+
91
+ async executeMyFlow() {
92
+ const core = this.invectService.getCore();
93
+
94
+ // Use the core Invect instance
95
+ const flows = await core.listFlows();
96
+ return flows;
97
+ }
98
+ }
99
+ ```
100
+
101
+ ## API Endpoints
102
+
103
+ The module automatically provides a REST API with the following endpoints:
104
+
105
+ ### Flow Management
106
+ - `GET /flows` - List flows with optional filtering and pagination
107
+ - `POST /flows` - Create a new flow
108
+ - `GET /flows/:id` - Get flow by ID
109
+ - `PUT /flows/:id` - Update flow (not yet implemented)
110
+ - `DELETE /flows/:id` - Delete flow (not yet implemented)
111
+ - `POST /validate-flow` - Validate flow definition
112
+
113
+ ### Flow Version Management
114
+ - `GET /flows/:id/versions` - Get flow versions
115
+ - `POST /flows/:id/versions` - Create flow version
116
+
117
+ ### Flow Run Execution
118
+ - `POST /flows/:flowId/run` - Start flow execution
119
+ - `GET /flow-runs` - Get all flow runs
120
+ - `GET /flow-runs/:flowRunId` - Get specific flow run
121
+ - `GET /flows/:flowId/flow-runs` - Get flow runs for a specific flow
122
+ - `POST /flow-runs/:flowRunId/resume` - Resume paused flow execution
123
+ - `POST /flow-runs/:flowRunId/cancel` - Cancel flow execution (not yet implemented)
124
+ - `POST /flow-runs/:flowRunId/pause` - Pause flow execution (not yet implemented)
125
+
126
+ ### Node Execution
127
+ - `GET /flow-runs/:flowRunId/node-executions` - Get node executions for a flow run
128
+ - `GET /node-executions` - Get all node executions
129
+
130
+ ### Node Data & Testing
131
+ - `POST /node-data/sql-query` - Execute SQL query for testing
132
+ - `POST /node-data/jq-query` - Execute JQ query for testing
133
+ - `POST /node-data/model-query` - Test model prompt
134
+ - `GET /node-data/models` - Get available AI models
135
+ - `GET /node-data/databases` - Get available databases
136
+
137
+ ## Custom Route Prefix
138
+
139
+ To add a custom route prefix for all Invect endpoints, modify the controller registration:
140
+
141
+ ```typescript
142
+ @Controller('api/v1/invect')
143
+ export class CustomInvectController extends InvectController {}
144
+ ```
145
+
146
+ ## Features
147
+
148
+ - **Functionally identical to Express package**: Same API endpoints and behavior
149
+ - **Dependency injection**: Invect core instance is properly injected
150
+ - **Async configuration**: Support for dynamic configuration
151
+ - **Service access**: Direct access to Invect core through `InvectService`
152
+ - **Error handling**: Proper NestJS exception handling
153
+ - **TypeScript support**: Full type safety
154
+
155
+ ## License
156
+
157
+ MIT
158
+
159
+ ## Installation
160
+
161
+ ```bash
162
+ npm install @robase/@invect/nestjs
163
+ ```
164
+
165
+ ## Usage
166
+
167
+ Import and configure the `invectModule` in your NestJS application:
168
+
169
+ ```typescript
170
+ import { Module } from '@nestjs/common';
171
+ import { invectModule, InvectConfig } from '@robase/@invect/nestjs';
172
+
173
+ const config: InvectConfig = {
174
+ openAIKey: process.env.OPENAI_API_KEY,
175
+ anthropicKey: process.env.ANTHROPIC_API_KEY,
176
+ modelId: 'claude-3-sonnet-20240229',
177
+ databaseType: 'sqlite',
178
+ databaseConnectionString: 'file:./dev.db',
179
+ // Database for SQL query nodes to execute user queries
180
+ DEFAULT_SQL_NODE_DB_CONNECTION_STRING: 'postgresql://user:password@localhost:5432/userdata',
181
+ // Optional: Named databases for specific SQL query nodes
182
+ sqlQueryDatabases: {
183
+ 'analytics': 'postgresql://user:password@localhost:5432/analytics',
184
+ 'reporting': 'postgresql://user:password@localhost:5432/reporting',
185
+ 'warehouse': 'postgresql://user:password@localhost:5432/warehouse'
186
+ }
187
+ };
188
+
189
+ @Module({
190
+ imports: [
191
+ invectModule.forRoot(config)
192
+ ],
193
+ })
194
+ export class AppModule {}
195
+ ```
196
+
197
+ ## Configuration
198
+
199
+ The `InvectConfig` interface accepts the following options:
200
+
201
+ - `openAIKey?: string` - OpenAI API key (optional if anthropicKey is provided)
202
+ - `anthropicKey?: string` - Anthropic API key (optional if openAIKey is provided)
203
+ - `modelId: string` - Model identifier to use for text generation
204
+ - `databaseType: 'sqlite' | 'postgresql' | 'mysql'` - Database type
205
+ - `databaseConnectionString: string` - Database connection string for Invect application data
206
+ - `DEFAULT_SQL_NODE_DB_CONNECTION_STRING: string` - Database connection string for SQL query nodes (required)
207
+ - `sqlQueryDatabases?: Record<string, string>` - Named database connections for SQL query nodes (optional)
208
+
209
+ At least one of `openAIKey` or `anthropicKey` must be provided.
210
+
211
+ ### Database Configuration
212
+
213
+ Invect uses two separate database connections:
214
+
215
+ 1. **Application Database** (`databaseConnectionString`): Stores Invect's internal data including flows, executions, and traces
216
+ 2. **SQL Query Node Database** (`DEFAULT_SQL_NODE_DB_CONNECTION_STRING`): Default database for SQL query nodes to execute user queries against. If not provided, SQL query nodes will fall back to using the environment variable `SQL_CONFIG`
217
+
218
+ #### Using Named Databases
219
+
220
+ SQL query nodes can specify which database to use via the `database_id` parameter:
221
+
222
+ - **Default behavior**: If no `database_id` is specified, the SQL query node uses `DEFAULT_SQL_NODE_DB_CONNECTION_STRING`
223
+ - **Named database**: If `database_id` is specified (e.g., 'analytics'), the node uses the corresponding connection string from `sqlQueryDatabases`
224
+
225
+ The frontend provides a dropdown in the SQL query node editor to select from available databases.
226
+
227
+ Example SQL query node configuration:
228
+ ```json
229
+ {
230
+ "type": "sqlQueryNode",
231
+ "data": {
232
+ "query": "SELECT * FROM users WHERE created_at > NOW() - INTERVAL '7 days'",
233
+ "database_type": "postgresql",
234
+ "database_id": "analytics"
235
+ }
236
+ }
237
+ ```
238
+
239
+ ## Features
240
+
241
+ - **Flow Management**: Create, update, and manage Invect workflows
242
+ - **Batch Processing**: Execute workflows with optimized batch processing for AI APIs
243
+ - **Multiple Node Types**: Support for template, model, SQL query, and conditional nodes
244
+ - **Database Support**: Compatible with SQLite, PostgreSQL, and MySQL
245
+ - **Execution Tracking**: Full execution history and tracing
246
+ - **Pause/Resume**: Control flow execution with pause and resume capabilities
247
+
248
+ ## API Endpoints
249
+
250
+ Once imported, the module provides the following REST endpoints:
251
+
252
+ - `GET /api/flows` - List all flows
253
+ - `POST /api/flows` - Create a new flow
254
+ - `GET /api/flows/:id` - Get flow details
255
+ - `POST /api/flows/:id/versions` - Create new flow version
256
+ - `POST /api/executions` - Execute a flow
257
+ - `GET /api/executions/:id` - Get execution details
258
+
259
+ ## Database Setup
260
+
261
+ The module uses Prisma for database operations. Make sure to run migrations after installation:
262
+
263
+ ```bash
264
+ npx prisma migrate deploy
265
+ ```
266
+
267
+ ## License
268
+
269
+ MIT
@@ -0,0 +1,9 @@
1
+ //#region \0@oxc-project+runtime@0.115.0/helpers/decorate.js
2
+ function __decorate(decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ }
8
+ //#endregion
9
+ exports.__decorate = __decorate;
@@ -0,0 +1,9 @@
1
+ //#region \0@oxc-project+runtime@0.115.0/helpers/decorate.js
2
+ function __decorate(decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ }
8
+ //#endregion
9
+ export { __decorate };
@@ -0,0 +1,6 @@
1
+ //#region \0@oxc-project+runtime@0.115.0/helpers/decorateMetadata.js
2
+ function __decorateMetadata(k, v) {
3
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4
+ }
5
+ //#endregion
6
+ exports.__decorateMetadata = __decorateMetadata;
@@ -0,0 +1,6 @@
1
+ //#region \0@oxc-project+runtime@0.115.0/helpers/decorateMetadata.js
2
+ function __decorateMetadata(k, v) {
3
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4
+ }
5
+ //#endregion
6
+ export { __decorateMetadata };
@@ -0,0 +1,8 @@
1
+ //#region \0@oxc-project+runtime@0.115.0/helpers/decorateParam.js
2
+ function __decorateParam(paramIndex, decorator) {
3
+ return function(target, key) {
4
+ decorator(target, key, paramIndex);
5
+ };
6
+ }
7
+ //#endregion
8
+ exports.__decorateParam = __decorateParam;
@@ -0,0 +1,8 @@
1
+ //#region \0@oxc-project+runtime@0.115.0/helpers/decorateParam.js
2
+ function __decorateParam(paramIndex, decorator) {
3
+ return function(target, key) {
4
+ decorator(target, key, paramIndex);
5
+ };
6
+ }
7
+ //#endregion
8
+ export { __decorateParam };
@@ -0,0 +1,4 @@
1
+ export declare class AppModule {
2
+ }
3
+ export declare class AsyncAppModule {
4
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,29 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_invect_nestjs_controller = require("./invect-nestjs.controller.cjs");
3
+ const require_invect_nestjs_service = require("./invect-nestjs.service.cjs");
4
+ const require_invect_nestjs_module = require("./invect-nestjs.module.cjs");
5
+ let _invect_core = require("@invect/core");
6
+ Object.defineProperty(exports, "Invect", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return _invect_core.Invect;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "InvectController", {
13
+ enumerable: true,
14
+ get: function() {
15
+ return require_invect_nestjs_controller.InvectController;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "InvectModule", {
19
+ enumerable: true,
20
+ get: function() {
21
+ return require_invect_nestjs_module.InvectModule;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "InvectService", {
25
+ enumerable: true,
26
+ get: function() {
27
+ return require_invect_nestjs_service.InvectService;
28
+ }
29
+ });
@@ -0,0 +1,5 @@
1
+ export { InvectModule } from './invect-nestjs.module';
2
+ export { InvectController } from './invect-nestjs.controller';
3
+ export { InvectService } from './invect-nestjs.service';
4
+ export { Invect } from '@invect/core';
5
+ export type { InvectConfig } from '@invect/core';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { InvectController } from "./invect-nestjs.controller.js";
2
+ import { InvectService } from "./invect-nestjs.service.js";
3
+ import { InvectModule } from "./invect-nestjs.module.js";
4
+ import { Invect } from "@invect/core";
5
+ export { Invect, InvectController, InvectModule, InvectService };