@flutchai/flutch-sdk 0.1.5 → 0.1.6

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/README.md CHANGED
@@ -4,7 +4,9 @@ Base infrastructure package for building graph microservices with LangGraph and
4
4
 
5
5
  ## Overview
6
6
 
7
- `@flutchai/flutch-sdk` is a self-contained foundation package that provides all the essential components needed to build, run, and manage LangGraph-based microservices using NestJS framework.
7
+ `@flutchai/flutch-sdk` is a self-contained foundation package that **turns your graph logic into a production-ready microservice**. Write your graph builder, and the SDK handles everything else: REST API, streaming, health checks, metrics, callbacks, and versioning.
8
+
9
+ The SDK is designed to be **framework-agnostic** - while it currently provides first-class support for LangGraph.js with NestJS, the architecture allows for supporting other graph frameworks (LlamaIndex, custom implementations, etc.) in the future.
8
10
 
9
11
  ## What's Included
10
12
 
@@ -63,37 +65,170 @@ or
63
65
  yarn add @flutchai/flutch-sdk
64
66
  ```
65
67
 
66
- ## Usage
68
+ ## Quick Start
69
+
70
+ The SDK provides everything you need to quickly launch a production-ready graph service. With minimal setup, you get a fully functional NestJS application with REST API, health checks, metrics, and more.
67
71
 
68
- ### Creating a Graph Service
72
+ ### 1. Create Your Graph Builder
69
73
 
70
74
  ```typescript
71
- import {
72
- UniversalGraphModule,
73
- AbstractGraphBuilder,
74
- IGraphRunnableConfig,
75
- } from "@flutchai/flutch-sdk";
75
+ import { Injectable } from "@nestjs/common";
76
+ import { AbstractGraphBuilder } from "@flutchai/flutch-sdk";
77
+ import { StateGraph, START, END } from "@langchain/langgraph";
76
78
 
77
79
  @Injectable()
78
80
  export class MyGraphBuilder extends AbstractGraphBuilder<"myGraph"> {
79
81
  async buildGraph(config?: any): Promise<CompiledGraphFor<"myGraph">> {
80
- // Build your LangGraph here
81
- return compiledGraph;
82
+ // Define your graph logic
83
+ const graph = new StateGraph(MyState)
84
+ .addNode("process", async state => {
85
+ // Your processing logic
86
+ return { result: "processed" };
87
+ })
88
+ .addEdge(START, "process")
89
+ .addEdge("process", END)
90
+ .compile();
91
+
92
+ return graph;
82
93
  }
83
94
  }
95
+ ```
96
+
97
+ ### 2. Register the Module
98
+
99
+ ```typescript
100
+ import { Module } from "@nestjs/common";
101
+ import { UniversalGraphModule } from "@flutchai/flutch-sdk";
84
102
 
85
103
  @Module({
86
104
  imports: [
87
105
  UniversalGraphModule.register({
88
106
  graphType: "myGraph",
89
107
  builder: MyGraphBuilder,
90
- // ... other config
91
108
  }),
92
109
  ],
93
110
  })
94
- export class MyGraphModule {}
111
+ export class AppModule {}
112
+ ```
113
+
114
+ ### 3. Bootstrap Your Application
115
+
116
+ ```typescript
117
+ import { NestFactory } from "@nestjs/core";
118
+ import { AppModule } from "./app.module";
119
+
120
+ async function bootstrap() {
121
+ const app = await NestFactory.create(AppModule);
122
+ await app.listen(3000);
123
+ }
124
+ bootstrap();
125
+ ```
126
+
127
+ That's it! Your graph service is now running with a complete REST API.
128
+
129
+ ## What You Get Out of the Box
130
+
131
+ Once your service is running, you automatically get:
132
+
133
+ ### REST API Endpoints
134
+
135
+ The SDK provides ready-to-use controllers with standard endpoints:
136
+
137
+ #### Graph Execution (`GraphController`)
138
+
139
+ - `GET /health` - Service health check
140
+ - `GET /graph-types` - List supported graph types
141
+ - `POST /generate` - Non-streaming generation
142
+ - `POST /stream` - Server-Sent Events (SSE) streaming
143
+ - `POST /cancel/:requestId` - Cancel running generation
144
+ - `GET /registry` - View registered graphs
145
+ - `GET /registry/stats` - Registry statistics
146
+
147
+ #### Callbacks (`CallbackController`)
148
+
149
+ - `POST /callback` - Handle user callbacks with token-based security
150
+
151
+ #### UI Dispatch (`UIDispatchController`)
152
+
153
+ - `POST /api/graph/ui/dispatch` - Dispatch requests to custom UI endpoints
154
+ - `GET /api/graph/:graphType/manifest` - Get graph manifest with UI config
155
+ - `GET /api/graph/:graphType/endpoints` - List available UI endpoints
156
+ - `GET /api/graph/catalog` - Get catalog of all graphs
157
+
158
+ ### Monitoring & Observability
159
+
160
+ - Prometheus metrics at `/metrics`
161
+ - Health checks with `@nestjs/terminus`
162
+ - Request/response logging
163
+ - API call tracing with sanitization
164
+
165
+ ### Production Features
166
+
167
+ - Helmet security headers
168
+ - Compression middleware
169
+ - Redis-backed callback system
170
+ - OpenAPI/Swagger documentation
171
+ - Error handling and validation
172
+
173
+ ## API Usage Examples
174
+
175
+ ### Non-Streaming Generation
176
+
177
+ ```bash
178
+ curl -X POST http://localhost:3000/generate \
179
+ -H "Content-Type: application/json" \
180
+ -d '{
181
+ "requestId": "req-123",
182
+ "graphType": "myGraph",
183
+ "messages": [
184
+ { "role": "user", "content": "Hello!" }
185
+ ]
186
+ }'
187
+ ```
188
+
189
+ ### Streaming Generation (SSE)
190
+
191
+ ```bash
192
+ curl -X POST http://localhost:3000/stream \
193
+ -H "Content-Type: application/json" \
194
+ -d '{
195
+ "requestId": "req-456",
196
+ "graphType": "myGraph",
197
+ "messages": [
198
+ { "role": "user", "content": "Tell me a story" }
199
+ ]
200
+ }'
201
+ ```
202
+
203
+ The stream returns Server-Sent Events:
204
+
205
+ ```
206
+ event: stream_event
207
+ data: {"type":"chunk","content":"Once upon"}
208
+
209
+ event: stream_event
210
+ data: {"type":"chunk","content":" a time"}
211
+
212
+ event: final
213
+ data: {"text":"Once upon a time...","attachments":[],"metadata":{}}
214
+ ```
215
+
216
+ ### Check Health
217
+
218
+ ```bash
219
+ curl http://localhost:3000/health
220
+ # Response: {"status":"healthy","timestamp":"2025-11-03T12:00:00.000Z"}
95
221
  ```
96
222
 
223
+ ### View Registered Graphs
224
+
225
+ ```bash
226
+ curl http://localhost:3000/registry
227
+ # Response: {"total":1,"graphs":[{"graphType":"myGraph","builderName":"MyGraphBuilder"}]}
228
+ ```
229
+
230
+ ## Advanced Usage
231
+
97
232
  ### Using GraphTypeUtils
98
233
 
99
234
  ```typescript
@@ -294,13 +429,98 @@ npm run lint
294
429
  - **Graph versioning** utilities
295
430
  - **Manifest validation** for graph configurations
296
431
 
432
+ ## Flutch Platform Integration
433
+
434
+ The SDK is designed to seamlessly integrate with the **Flutch Platform**, giving you enterprise-grade capabilities out of the box:
435
+
436
+ ### One-Line Platform Connection
437
+
438
+ ```typescript
439
+ UniversalGraphModule.register({
440
+ graphType: "myGraph",
441
+ builder: MyGraphBuilder,
442
+ flutch: {
443
+ apiKey: process.env.FLUTCH_API_KEY,
444
+ endpoint: "https://api.flutch.ai",
445
+ },
446
+ });
447
+ ```
448
+
449
+ ### What You Get with Flutch Platform
450
+
451
+ **Tracing & Analytics**
452
+
453
+ - Distributed tracing across all graph executions
454
+ - Performance metrics and bottleneck detection
455
+ - Cost analytics per request and model
456
+ - Token usage tracking
457
+
458
+ **Multi-Channel UI**
459
+
460
+ - Web, Telegram, Slack, WhatsApp support
461
+ - Unified UI components across channels
462
+ - Channel-specific adaptations
463
+ - Custom branding
464
+
465
+ **Governance & Control**
466
+
467
+ - Rate limiting and quota management
468
+ - User-level and company-level limits
469
+ - Budget controls and alerts
470
+ - Usage analytics
471
+
472
+ **Testing & Quality**
473
+
474
+ - A/B testing for graph versions
475
+ - Acceptance testing automation
476
+ - AI-powered test generation
477
+ - Regression testing
478
+
479
+ **Run Standalone or with Platform**
480
+
481
+ The SDK works perfectly standalone for self-hosted deployments, or connect to Flutch Platform for advanced features. Your choice.
482
+
483
+ ## Key Benefits
484
+
485
+ ### Instant Service Deployment
486
+
487
+ Go from graph logic to deployed microservice in minutes. No need to build REST APIs, implement streaming, or set up monitoring - it's all included.
488
+
489
+ ### Graph Versioning
490
+
491
+ Built-in support for versioning your graphs. Run multiple versions simultaneously, test new versions, and roll back safely.
492
+
493
+ ### Framework Flexibility
494
+
495
+ Currently supports LangGraph.js. The architecture is designed to support other graph frameworks like LlamaIndex, ensuring your investment is future-proof.
496
+
497
+ ### Developer Experience
498
+
499
+ - Type-safe graph definitions with TypeScript
500
+ - Hot reload during development
501
+ - OpenAPI/Swagger documentation auto-generated
502
+ - Comprehensive error handling
503
+
504
+ ### Interactive Capabilities
505
+
506
+ - **Callbacks**: Add interactive buttons and user interactions to your graphs
507
+ - **UI Endpoints**: Create custom UI endpoints for dynamic interfaces
508
+ - **Streaming**: Real-time responses with Server-Sent Events
509
+
510
+ ### Production Ready
511
+
512
+ - Prometheus metrics for monitoring
513
+ - Health checks for orchestration
514
+ - Redis-backed state management
515
+ - Security headers and compression
516
+
297
517
  ## Use Cases
298
518
 
299
- - Building AI agent microservices with LangGraph
300
- - Creating conversational AI applications
301
- - Implementing RAG (Retrieval-Augmented Generation) systems
302
- - Developing multi-step AI workflows
303
- - Building interactive AI assistants with callbacks
519
+ - **AI Agent Microservices**: Deploy autonomous agents as scalable services
520
+ - **Conversational AI**: Build chatbots and virtual assistants
521
+ - **RAG Systems**: Implement retrieval-augmented generation workflows
522
+ - **Multi-step Workflows**: Orchestrate complex AI pipelines
523
+ - **Interactive Assistants**: Create agents with callbacks and dynamic UIs
304
524
 
305
525
  ## Links
306
526