@langgraph-js/pure-graph 2.6.0 → 2.7.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/README.md +183 -15
- package/dist/adapter/fetch/assistants.d.ts +9 -0
- package/dist/adapter/fetch/context.d.ts +4 -0
- package/dist/adapter/fetch/index.d.ts +8 -0
- package/dist/adapter/fetch/runs.d.ts +21 -0
- package/dist/adapter/fetch/threads.d.ts +17 -0
- package/dist/adapter/fetch/utils.d.ts +44 -0
- package/dist/adapter/hono/index.js +7 -209
- package/dist/adapter/hono/index.js.map +1 -1
- package/dist/adapter/nextjs/index.js +2 -2
- package/dist/adapter/nextjs/router.d.ts +3 -3
- package/dist/{createEndpoint-BMYbyDjM.js → createEndpoint-BEEfOyPg.js} +2 -2
- package/dist/{createEndpoint-BMYbyDjM.js.map → createEndpoint-BEEfOyPg.js.map} +1 -1
- package/dist/index-B-gojNlM.js +557 -0
- package/dist/index-B-gojNlM.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/{queue-D1FBVnEa.js → queue-g6fOz7D5.js} +2 -2
- package/dist/{queue-D1FBVnEa.js.map → queue-g6fOz7D5.js.map} +1 -1
- package/dist/router-Dk7saRUW.js +30 -0
- package/dist/router-Dk7saRUW.js.map +1 -0
- package/dist/{stream-Bgw3QUMg.js → stream-Blquv56P.js} +3 -3
- package/dist/{stream-Bgw3QUMg.js.map → stream-Blquv56P.js.map} +1 -1
- package/package.json +1 -1
- package/dist/adapter/hono/assistants.d.ts +0 -3
- package/dist/adapter/hono/runs.d.ts +0 -6
- package/dist/adapter/hono/threads.d.ts +0 -3
- package/dist/adapter/nextjs/endpoint.d.ts +0 -35
- package/dist/router-BfL7mrw7.js +0 -218
- package/dist/router-BfL7mrw7.js.map +0 -1
- package/dist/zod-B6xyK6pu.js +0 -112
- package/dist/zod-B6xyK6pu.js.map +0 -1
- /package/dist/adapter/{hono → fetch}/endpoint.d.ts +0 -0
package/README.md
CHANGED
|
@@ -20,7 +20,9 @@ This document will guide you on how to use Open LangGraph Server in your project
|
|
|
20
20
|
- **Multiple Storage Backends**: Support for SQLite, PostgreSQL, Redis, and in-memory storage
|
|
21
21
|
- **Message Queue**: Redis-based stream queue with TTL support
|
|
22
22
|
- **Thread Management**: Comprehensive thread lifecycle management with status tracking
|
|
23
|
-
- **Framework
|
|
23
|
+
- **Framework Agnostic**: Core implementation uses standard Web APIs (Request/Response)
|
|
24
|
+
- **Framework Integration**: Native support for Next.js, Hono.js, and any platform supporting standard fetch handlers
|
|
25
|
+
- **Easy Migration**: All adapters use the same core implementation, making it easy to switch platforms
|
|
24
26
|
|
|
25
27
|
## Installation
|
|
26
28
|
|
|
@@ -38,6 +40,60 @@ yarn add @langgraph-js/pure-graph
|
|
|
38
40
|
|
|
39
41
|
## Usage
|
|
40
42
|
|
|
43
|
+
### Architecture
|
|
44
|
+
|
|
45
|
+
Open LangGraph Server uses a layered architecture:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
┌─────────────────────────────────────────┐
|
|
49
|
+
│ Framework Adapters (Hono, Next.js) │ ← Thin wrapper layer
|
|
50
|
+
├─────────────────────────────────────────┤
|
|
51
|
+
│ Fetch Handler (Standard Web APIs) │ ← Core implementation
|
|
52
|
+
├─────────────────────────────────────────┤
|
|
53
|
+
│ LangGraph Core Logic │ ← Graph execution
|
|
54
|
+
└─────────────────────────────────────────┘
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
All framework adapters (Hono, Next.js) use the same core `fetch` implementation, which is based on standard Web APIs (`Request`/`Response`). This means:
|
|
58
|
+
|
|
59
|
+
- **Easy Migration**: Switch between platforms without rewriting API logic
|
|
60
|
+
- **Platform Agnostic**: Works on any platform supporting standard fetch handlers (Cloudflare Workers, Deno Deploy, Vercel Edge, etc.)
|
|
61
|
+
- **Single Source of Truth**: All adapters share the same behavior and bug fixes
|
|
62
|
+
|
|
63
|
+
### Standard Fetch Handler
|
|
64
|
+
|
|
65
|
+
For platforms supporting standard `(req: Request, context?: any) => Response` handlers:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { handleRequest } from '@langgraph-js/pure-graph/dist/adapter/fetch';
|
|
69
|
+
import { registerGraph } from '@langgraph-js/pure-graph';
|
|
70
|
+
import { graph } from './agent/graph';
|
|
71
|
+
|
|
72
|
+
// Register your graph
|
|
73
|
+
registerGraph('my-graph', graph);
|
|
74
|
+
|
|
75
|
+
// Use the handler
|
|
76
|
+
export default async function handler(req: Request) {
|
|
77
|
+
// Optional: Add custom context
|
|
78
|
+
const context = {
|
|
79
|
+
langgraph_context: {
|
|
80
|
+
userId: req.headers.get('x-user-id'),
|
|
81
|
+
// ... other context data
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return await handleRequest(req, context);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
This works on:
|
|
90
|
+
|
|
91
|
+
- **Cloudflare Workers**
|
|
92
|
+
- **Deno Deploy**
|
|
93
|
+
- **Vercel Edge Functions**
|
|
94
|
+
- **Bun**
|
|
95
|
+
- Any platform with standard Web APIs
|
|
96
|
+
|
|
41
97
|
### Next.js Example
|
|
42
98
|
|
|
43
99
|
```text
|
|
@@ -127,16 +183,28 @@ To integrate Open LangGraph Server into a Hono.js project, follow these steps:
|
|
|
127
183
|
import { Hono } from 'hono';
|
|
128
184
|
import LangGraphApp, { type LangGraphServerContext } from '@langgraph-js/pure-graph/dist/adapter/hono/index';
|
|
129
185
|
import { cors } from 'hono/cors';
|
|
186
|
+
|
|
130
187
|
registerGraph('test', graph);
|
|
131
188
|
|
|
132
189
|
const app = new Hono<{ Variables: LangGraphServerContext }>();
|
|
133
|
-
app.use(cors())
|
|
134
|
-
app.route('/', LangGraphApp);
|
|
135
190
|
|
|
191
|
+
// Optional: Add context middleware
|
|
192
|
+
app.use('/api/*', async (c, next) => {
|
|
193
|
+
c.set('langgraph_context', {
|
|
194
|
+
userId: c.req.header('x-user-id'),
|
|
195
|
+
// ... other context data
|
|
196
|
+
});
|
|
197
|
+
await next();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
app.use(cors());
|
|
201
|
+
app.route('/api', LangGraphApp);
|
|
136
202
|
|
|
137
203
|
export default app;
|
|
138
204
|
```
|
|
139
205
|
|
|
206
|
+
> **Note**: The Hono adapter is a thin wrapper around the standard fetch handler. It extracts the `langgraph_context` from Hono's context and passes it to the core implementation.
|
|
207
|
+
|
|
140
208
|
2. **Using LangGraph Entrypoint (Recommended)**
|
|
141
209
|
|
|
142
210
|
For more advanced use cases, you can use LangGraph's `entrypoint` function to create reusable workflows:
|
|
@@ -335,16 +403,36 @@ export const config = {
|
|
|
335
403
|
|
|
336
404
|
```ts
|
|
337
405
|
// app/api/langgraph/[...path]/route.ts
|
|
338
|
-
import {
|
|
339
|
-
import {
|
|
340
|
-
import { graph as contextAwareGraph } from '@/agent/context-aware-graph';
|
|
406
|
+
import { NextRequest } from 'next/server';
|
|
407
|
+
import { ensureInitialized } from '@langgraph-js/pure-graph/dist/adapter/nextjs/index';
|
|
341
408
|
|
|
342
|
-
|
|
343
|
-
|
|
409
|
+
export const dynamic = 'force-dynamic';
|
|
410
|
+
export const revalidate = 0;
|
|
344
411
|
|
|
345
|
-
|
|
412
|
+
const registerGraph = async () => {
|
|
413
|
+
const { registerGraph } = await import('@langgraph-js/pure-graph');
|
|
414
|
+
const { graph as contextAwareGraph } = await import('@/agent/context-aware-graph');
|
|
415
|
+
registerGraph('context-aware', contextAwareGraph);
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
export const GET = async (req: NextRequest) => {
|
|
419
|
+
const { GET } = await ensureInitialized(registerGraph);
|
|
420
|
+
return GET(req);
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
export const POST = async (req: NextRequest) => {
|
|
424
|
+
const { POST } = await ensureInitialized(registerGraph);
|
|
425
|
+
return POST(req);
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
export const DELETE = async (req: NextRequest) => {
|
|
429
|
+
const { DELETE } = await ensureInitialized(registerGraph);
|
|
430
|
+
return DELETE(req);
|
|
431
|
+
};
|
|
346
432
|
```
|
|
347
433
|
|
|
434
|
+
> **Note**: The Next.js adapter extracts context from the `x-langgraph-context` header and passes it to the core fetch handler.
|
|
435
|
+
|
|
348
436
|
## Environment Configuration
|
|
349
437
|
|
|
350
438
|
Here are the environment variables you need to configure:
|
|
@@ -491,23 +579,103 @@ Storage backends are selected in this priority order:
|
|
|
491
579
|
3. **SQLite** (if `SQLITE_DATABASE_URI` set)
|
|
492
580
|
4. **Memory** (fallback default)
|
|
493
581
|
|
|
582
|
+
## Platform Support
|
|
583
|
+
|
|
584
|
+
Open LangGraph Server's fetch-based architecture makes it compatible with multiple platforms:
|
|
585
|
+
|
|
586
|
+
| Platform | Adapter | Status |
|
|
587
|
+
| ---------------------- | --------------------------------- | ------------------ |
|
|
588
|
+
| **Next.js** | `adapter/nextjs` | ✅ Fully Supported |
|
|
589
|
+
| **Hono.js** | `adapter/hono` | ✅ Fully Supported |
|
|
590
|
+
| **Cloudflare Workers** | `adapter/fetch` | ✅ Fully Supported |
|
|
591
|
+
| **Deno Deploy** | `adapter/fetch` | ✅ Fully Supported |
|
|
592
|
+
| **Vercel Edge** | `adapter/fetch` | ✅ Fully Supported |
|
|
593
|
+
| **Bun** | `adapter/fetch` | ✅ Fully Supported |
|
|
594
|
+
| **Node.js** | `adapter/hono` or `adapter/fetch` | ✅ Fully Supported |
|
|
595
|
+
|
|
596
|
+
### Platform-Specific Examples
|
|
597
|
+
|
|
598
|
+
#### Cloudflare Workers
|
|
599
|
+
|
|
600
|
+
```ts
|
|
601
|
+
import { handleRequest } from '@langgraph-js/pure-graph/dist/adapter/fetch';
|
|
602
|
+
import { registerGraph } from '@langgraph-js/pure-graph';
|
|
603
|
+
import { graph } from './agent/graph';
|
|
604
|
+
|
|
605
|
+
registerGraph('my-graph', graph);
|
|
606
|
+
|
|
607
|
+
export default {
|
|
608
|
+
async fetch(request: Request, env: any, ctx: any) {
|
|
609
|
+
const context = {
|
|
610
|
+
langgraph_context: {
|
|
611
|
+
userId: request.headers.get('x-user-id'),
|
|
612
|
+
},
|
|
613
|
+
};
|
|
614
|
+
return await handleRequest(request, context);
|
|
615
|
+
},
|
|
616
|
+
};
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
#### Deno Deploy
|
|
620
|
+
|
|
621
|
+
```ts
|
|
622
|
+
import { handleRequest } from '@langgraph-js/pure-graph/dist/adapter/fetch';
|
|
623
|
+
import { registerGraph } from '@langgraph-js/pure-graph';
|
|
624
|
+
import { graph } from './agent/graph.ts';
|
|
625
|
+
|
|
626
|
+
registerGraph('my-graph', graph);
|
|
627
|
+
|
|
628
|
+
Deno.serve(async (req) => {
|
|
629
|
+
const context = {
|
|
630
|
+
langgraph_context: {
|
|
631
|
+
userId: req.headers.get('x-user-id'),
|
|
632
|
+
},
|
|
633
|
+
};
|
|
634
|
+
return await handleRequest(req, context);
|
|
635
|
+
});
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
#### Vercel Edge Functions
|
|
639
|
+
|
|
640
|
+
```ts
|
|
641
|
+
import { handleRequest } from '@langgraph-js/pure-graph/dist/adapter/fetch';
|
|
642
|
+
import { registerGraph } from '@langgraph-js/pure-graph';
|
|
643
|
+
import { graph } from './agent/graph';
|
|
644
|
+
|
|
645
|
+
registerGraph('my-graph', graph);
|
|
646
|
+
|
|
647
|
+
export const config = {
|
|
648
|
+
runtime: 'edge',
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
export default async function handler(req: Request) {
|
|
652
|
+
const context = {
|
|
653
|
+
langgraph_context: {
|
|
654
|
+
userId: req.headers.get('x-user-id'),
|
|
655
|
+
},
|
|
656
|
+
};
|
|
657
|
+
return await handleRequest(req, context);
|
|
658
|
+
}
|
|
659
|
+
```
|
|
660
|
+
|
|
494
661
|
## API Endpoints
|
|
495
662
|
|
|
496
663
|
### Assistants
|
|
497
664
|
|
|
498
|
-
- **
|
|
499
|
-
- **GET /assistants/{assistantId}**: Retrieve a specific assistant graph.
|
|
665
|
+
- **POST /assistants/search**: Search for assistants.
|
|
666
|
+
- **GET /assistants/{assistantId}/graph**: Retrieve a specific assistant graph.
|
|
500
667
|
|
|
501
668
|
### Threads
|
|
502
669
|
|
|
503
670
|
- **POST /threads**: Create a new thread.
|
|
504
|
-
- **
|
|
671
|
+
- **POST /threads/search**: Search for threads.
|
|
505
672
|
- **GET /threads/{threadId}**: Retrieve a specific thread.
|
|
506
673
|
- **DELETE /threads/{threadId}**: Delete a specific thread.
|
|
674
|
+
- **POST /threads/{threadId}/state**: Update thread state.
|
|
507
675
|
|
|
508
676
|
### Runs
|
|
509
677
|
|
|
510
678
|
- **GET /threads/{threadId}/runs**: List runs in a thread.
|
|
511
|
-
- **POST /threads/{threadId}/runs**: Create a new run.
|
|
512
|
-
- **
|
|
513
|
-
- **
|
|
679
|
+
- **POST /threads/{threadId}/runs/stream**: Create and stream a new run (most commonly used).
|
|
680
|
+
- **GET /threads/{threadId}/runs/{runId}/stream**: Join an existing run stream.
|
|
681
|
+
- **POST /threads/{threadId}/runs/{runId}/cancel**: Cancel a specific run.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LangGraphServerContext } from './context';
|
|
2
|
+
/**
|
|
3
|
+
* POST /assistants/search
|
|
4
|
+
*/
|
|
5
|
+
export declare function searchAssistants(req: Request, context: LangGraphServerContext): Promise<Response>;
|
|
6
|
+
/**
|
|
7
|
+
* GET /assistants/:assistant_id/graph
|
|
8
|
+
*/
|
|
9
|
+
export declare function getAssistantGraph(req: Request, context: LangGraphServerContext): Promise<Response>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LangGraphServerContext } from './context';
|
|
2
|
+
/**
|
|
3
|
+
* 主路由处理器
|
|
4
|
+
*/
|
|
5
|
+
export declare function handleRequest(req: Request, context?: LangGraphServerContext): Promise<Response>;
|
|
6
|
+
export * from './assistants';
|
|
7
|
+
export * from './threads';
|
|
8
|
+
export * from './runs';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LangGraphServerContext } from './context';
|
|
2
|
+
/**
|
|
3
|
+
* POST /threads/:thread_id/runs/stream
|
|
4
|
+
*/
|
|
5
|
+
export declare function streamRun(req: Request, context: LangGraphServerContext): Promise<Response>;
|
|
6
|
+
/**
|
|
7
|
+
* GET /threads/:thread_id/runs/:run_id/stream
|
|
8
|
+
*/
|
|
9
|
+
export declare function joinRunStream(req: Request, context: LangGraphServerContext): Promise<Response>;
|
|
10
|
+
/**
|
|
11
|
+
* GET /threads/:thread_id/runs
|
|
12
|
+
*/
|
|
13
|
+
export declare function listRuns(req: Request, context: LangGraphServerContext): Promise<Response>;
|
|
14
|
+
/**
|
|
15
|
+
* POST /threads/:thread_id/runs/:run_id/cancel
|
|
16
|
+
*/
|
|
17
|
+
export declare function cancelRun(req: Request, context: LangGraphServerContext): Promise<Response>;
|
|
18
|
+
/**
|
|
19
|
+
* POST /threads/:thread_id/state
|
|
20
|
+
*/
|
|
21
|
+
export declare function updateThreadState(req: Request, context: LangGraphServerContext): Promise<Response>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LangGraphServerContext } from './context';
|
|
2
|
+
/**
|
|
3
|
+
* POST /threads
|
|
4
|
+
*/
|
|
5
|
+
export declare function createThread(req: Request, context: LangGraphServerContext): Promise<Response>;
|
|
6
|
+
/**
|
|
7
|
+
* POST /threads/search
|
|
8
|
+
*/
|
|
9
|
+
export declare function searchThreads(req: Request, context: LangGraphServerContext): Promise<Response>;
|
|
10
|
+
/**
|
|
11
|
+
* GET /threads/:thread_id
|
|
12
|
+
*/
|
|
13
|
+
export declare function getThread(req: Request, context: LangGraphServerContext): Promise<Response>;
|
|
14
|
+
/**
|
|
15
|
+
* DELETE /threads/:thread_id
|
|
16
|
+
*/
|
|
17
|
+
export declare function deleteThread(req: Request, context: LangGraphServerContext): Promise<Response>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* 解析 URL 路径参数
|
|
4
|
+
*/
|
|
5
|
+
export declare function parsePathParams(url: string, pattern: string): Record<string, string>;
|
|
6
|
+
/**
|
|
7
|
+
* 解析查询参数并转换类型
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseQueryParams(url: string): Record<string, string | number | boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* 验证数据
|
|
12
|
+
*/
|
|
13
|
+
export declare function validate<T>(schema: z.ZodSchema<T>, data: unknown): T;
|
|
14
|
+
/**
|
|
15
|
+
* 验证错误
|
|
16
|
+
*/
|
|
17
|
+
export declare class ValidationError extends Error {
|
|
18
|
+
errors: z.ZodIssue[];
|
|
19
|
+
constructor(errors: z.ZodIssue[]);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 创建 JSON 响应
|
|
23
|
+
*/
|
|
24
|
+
export declare function jsonResponse(data: any, status?: number, headers?: Record<string, string>): Response;
|
|
25
|
+
/**
|
|
26
|
+
* 创建错误响应
|
|
27
|
+
*/
|
|
28
|
+
export declare function errorResponse(error: unknown, status?: number): Response;
|
|
29
|
+
/**
|
|
30
|
+
* 创建 SSE 流响应
|
|
31
|
+
*/
|
|
32
|
+
export declare function createSSEStream(streamFn: (writer: SSEWriter) => Promise<void>): Response;
|
|
33
|
+
export interface SSEWriter {
|
|
34
|
+
writeSSE: (data: {
|
|
35
|
+
data: string;
|
|
36
|
+
event?: string;
|
|
37
|
+
id?: string;
|
|
38
|
+
}) => Promise<void>;
|
|
39
|
+
close: () => void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 为 SSE 流添加心跳功能
|
|
43
|
+
*/
|
|
44
|
+
export declare function withHeartbeat(streamFn: (writer: SSEWriter) => Promise<void>, heartbeatInterval?: number): (writer: SSEWriter) => Promise<void>;
|
|
@@ -1,216 +1,14 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
|
-
import {
|
|
3
|
-
import { c as createEndpoint } from '../../createEndpoint-BMYbyDjM.js';
|
|
4
|
-
import { A as AssistantsSearchSchema, a as AssistantGraphQuerySchema, T as ThreadIdParamSchema, R as RunStreamPayloadSchema, b as RunIdParamSchema, c as RunJoinStreamQuerySchema, d as RunListQuerySchema, e as RunCancelQuerySchema, f as ThreadStateUpdate, g as ThreadCreatePayloadSchema, h as ThreadSearchPayloadSchema } from '../../zod-B6xyK6pu.js';
|
|
5
|
-
import camelcaseKeys from 'camelcase-keys';
|
|
6
|
-
import { streamSSE } from 'hono/streaming';
|
|
7
|
-
import { s as serialiseAsDict, L as LangGraphGlobal } from '../../stream-Bgw3QUMg.js';
|
|
8
|
-
import z from 'zod';
|
|
9
|
-
|
|
10
|
-
const client = createEndpoint();
|
|
11
|
-
|
|
12
|
-
const api$2 = new Hono();
|
|
13
|
-
api$2.post("/assistants/search", zValidator("json", AssistantsSearchSchema), async (c) => {
|
|
14
|
-
const payload = c.req.valid("json");
|
|
15
|
-
let total = 0;
|
|
16
|
-
const data = await client.assistants.search(camelcaseKeys(payload));
|
|
17
|
-
c.res.headers.set("X-Pagination-Total", total.toString());
|
|
18
|
-
return c.json(data);
|
|
19
|
-
});
|
|
20
|
-
api$2.get("/assistants/:assistant_id/graph", zValidator("query", AssistantGraphQuerySchema), async (c) => {
|
|
21
|
-
const xray = c.req.valid("query").xray;
|
|
22
|
-
const data = await client.assistants.getGraph(c.req.param("assistant_id"), {
|
|
23
|
-
xray: xray !== void 0 ? xray === "true" : void 0
|
|
24
|
-
});
|
|
25
|
-
return c.json(data);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
function withHeartbeat(streamFn, heartbeatInterval = process.env.HEARTBEAT_INTERVAL ? parseInt(process.env.HEARTBEAT_INTERVAL) : 1500) {
|
|
29
|
-
return async (stream) => {
|
|
30
|
-
let heartbeatTimer = null;
|
|
31
|
-
const startHeartbeat = () => {
|
|
32
|
-
if (heartbeatTimer) {
|
|
33
|
-
clearInterval(heartbeatTimer);
|
|
34
|
-
}
|
|
35
|
-
heartbeatTimer = setInterval(async () => {
|
|
36
|
-
try {
|
|
37
|
-
await stream.writeSSE({ event: "ping", data: "{}" });
|
|
38
|
-
} catch (error) {
|
|
39
|
-
if (heartbeatTimer) {
|
|
40
|
-
clearInterval(heartbeatTimer);
|
|
41
|
-
heartbeatTimer = null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}, heartbeatInterval);
|
|
45
|
-
};
|
|
46
|
-
const stopHeartbeat = () => {
|
|
47
|
-
if (heartbeatTimer) {
|
|
48
|
-
clearInterval(heartbeatTimer);
|
|
49
|
-
heartbeatTimer = null;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const proxiedStream = new Proxy(stream, {
|
|
53
|
-
get(target, prop) {
|
|
54
|
-
if (prop === "writeSSE") {
|
|
55
|
-
return async (...args) => {
|
|
56
|
-
stopHeartbeat();
|
|
57
|
-
const result = await target[prop](...args);
|
|
58
|
-
startHeartbeat();
|
|
59
|
-
return result;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return target[prop];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
startHeartbeat();
|
|
66
|
-
try {
|
|
67
|
-
await streamFn(proxiedStream);
|
|
68
|
-
} finally {
|
|
69
|
-
stopHeartbeat();
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
const api$1 = new Hono();
|
|
74
|
-
api$1.post(
|
|
75
|
-
"/threads/:thread_id/runs/stream",
|
|
76
|
-
zValidator("param", ThreadIdParamSchema),
|
|
77
|
-
zValidator("json", RunStreamPayloadSchema),
|
|
78
|
-
async (c) => {
|
|
79
|
-
const { thread_id } = c.req.valid("param");
|
|
80
|
-
const payload = c.req.valid("json");
|
|
81
|
-
return streamSSE(
|
|
82
|
-
c,
|
|
83
|
-
withHeartbeat(async (stream) => {
|
|
84
|
-
payload.config = payload.config || {};
|
|
85
|
-
payload.config.configurable = payload.config.configurable || {};
|
|
86
|
-
const langgraphContext = c.get("langgraph_context");
|
|
87
|
-
if (langgraphContext) {
|
|
88
|
-
Object.assign(payload.config.configurable, langgraphContext);
|
|
89
|
-
}
|
|
90
|
-
for await (const { event, data } of client.runs.stream(
|
|
91
|
-
thread_id,
|
|
92
|
-
payload.assistant_id,
|
|
93
|
-
camelcaseKeys(payload)
|
|
94
|
-
)) {
|
|
95
|
-
await stream.writeSSE({ data: serialiseAsDict(data) ?? "", event });
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
);
|
|
101
|
-
api$1.get(
|
|
102
|
-
"/threads/:thread_id/runs/:run_id/stream",
|
|
103
|
-
zValidator("param", RunIdParamSchema),
|
|
104
|
-
zValidator("query", RunJoinStreamQuerySchema),
|
|
105
|
-
async (c) => {
|
|
106
|
-
const { thread_id, run_id } = c.req.valid("param");
|
|
107
|
-
const { cancel_on_disconnect, last_event_id, stream_mode } = c.req.valid("query");
|
|
108
|
-
return streamSSE(
|
|
109
|
-
c,
|
|
110
|
-
withHeartbeat(async (stream) => {
|
|
111
|
-
const controller = new AbortController();
|
|
112
|
-
if (cancel_on_disconnect) {
|
|
113
|
-
const cleanup = () => {
|
|
114
|
-
controller.abort("Client disconnected");
|
|
115
|
-
};
|
|
116
|
-
c.req.raw.signal?.addEventListener("abort", cleanup);
|
|
117
|
-
stream.onAbort = cleanup;
|
|
118
|
-
}
|
|
119
|
-
try {
|
|
120
|
-
for await (const { event, data, id } of client.runs.joinStream(thread_id, run_id, {
|
|
121
|
-
signal: controller.signal,
|
|
122
|
-
cancelOnDisconnect: cancel_on_disconnect,
|
|
123
|
-
lastEventId: last_event_id,
|
|
124
|
-
streamMode: stream_mode ? [stream_mode] : void 0
|
|
125
|
-
})) {
|
|
126
|
-
await stream.writeSSE({
|
|
127
|
-
data: serialiseAsDict(data) ?? "",
|
|
128
|
-
event,
|
|
129
|
-
id
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
} catch (error) {
|
|
133
|
-
if (!(error instanceof Error) || !error.message.includes("user cancel")) {
|
|
134
|
-
console.error("Join stream error:", error);
|
|
135
|
-
await stream.writeSSE({
|
|
136
|
-
event: "error",
|
|
137
|
-
data: JSON.stringify({
|
|
138
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
139
|
-
})
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
);
|
|
147
|
-
api$1.get(
|
|
148
|
-
"/threads/:thread_id/runs",
|
|
149
|
-
zValidator("param", ThreadIdParamSchema),
|
|
150
|
-
zValidator("query", RunListQuerySchema),
|
|
151
|
-
async (c) => {
|
|
152
|
-
const { thread_id } = c.req.valid("param");
|
|
153
|
-
const { limit, offset, status } = c.req.valid("query");
|
|
154
|
-
const runs = await client.runs.list(thread_id, { limit, offset, status });
|
|
155
|
-
return c.json(runs);
|
|
156
|
-
}
|
|
157
|
-
);
|
|
158
|
-
api$1.post(
|
|
159
|
-
"/threads/:thread_id/runs/:run_id/cancel",
|
|
160
|
-
zValidator("param", RunIdParamSchema),
|
|
161
|
-
zValidator("query", RunCancelQuerySchema),
|
|
162
|
-
async (c) => {
|
|
163
|
-
const { thread_id, run_id } = c.req.valid("param");
|
|
164
|
-
const { wait, action } = c.req.valid("query");
|
|
165
|
-
const cancel = client.runs.cancel(thread_id, run_id, wait, action);
|
|
166
|
-
if (wait) {
|
|
167
|
-
await cancel;
|
|
168
|
-
}
|
|
169
|
-
return c.body(null, wait ? 204 : 202);
|
|
170
|
-
}
|
|
171
|
-
);
|
|
172
|
-
api$1.post(
|
|
173
|
-
"/threads/:thread_id/state",
|
|
174
|
-
zValidator("param", z.object({ thread_id: z.string().uuid() })),
|
|
175
|
-
zValidator("json", ThreadStateUpdate),
|
|
176
|
-
async (c) => {
|
|
177
|
-
const { thread_id } = c.req.valid("param");
|
|
178
|
-
const payload = c.req.valid("json");
|
|
179
|
-
const inserted = await client.threads.updateState(thread_id, payload);
|
|
180
|
-
return c.json(inserted);
|
|
181
|
-
}
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
const api = new Hono();
|
|
185
|
-
api.post("/threads", zValidator("json", ThreadCreatePayloadSchema), async (c) => {
|
|
186
|
-
const payload = c.req.valid("json");
|
|
187
|
-
const thread = await client.threads.create(camelcaseKeys(payload));
|
|
188
|
-
return c.json(thread);
|
|
189
|
-
});
|
|
190
|
-
api.post("/threads/search", zValidator("json", ThreadSearchPayloadSchema), async (c) => {
|
|
191
|
-
const payload = c.req.valid("json");
|
|
192
|
-
const result = await client.threads.search(camelcaseKeys(payload));
|
|
193
|
-
c.res.headers.set("X-Pagination-Total", result.length.toString());
|
|
194
|
-
return c.json(result);
|
|
195
|
-
});
|
|
196
|
-
api.get("/threads/:thread_id", zValidator("param", ThreadIdParamSchema), async (c) => {
|
|
197
|
-
const { thread_id } = c.req.valid("param");
|
|
198
|
-
return c.json(await client.threads.get(thread_id));
|
|
199
|
-
});
|
|
200
|
-
api.delete("/threads/:thread_id", zValidator("param", ThreadIdParamSchema), async (c) => {
|
|
201
|
-
const { thread_id } = c.req.valid("param");
|
|
202
|
-
await client.threads.delete(thread_id);
|
|
203
|
-
return new Response(null, { status: 204 });
|
|
204
|
-
});
|
|
2
|
+
import { h as handleRequest } from '../../index-B-gojNlM.js';
|
|
205
3
|
|
|
206
4
|
const app = new Hono();
|
|
207
|
-
app.
|
|
208
|
-
|
|
209
|
-
|
|
5
|
+
app.all("*", async (c) => {
|
|
6
|
+
const context = {
|
|
7
|
+
langgraph_context: c.get("langgraph_context")
|
|
8
|
+
};
|
|
9
|
+
const response = await handleRequest(c.req.raw, context);
|
|
10
|
+
return response;
|
|
210
11
|
});
|
|
211
|
-
app.route("/", api$2);
|
|
212
|
-
app.route("/", api$1);
|
|
213
|
-
app.route("/", api);
|
|
214
12
|
|
|
215
13
|
export { app as default };
|
|
216
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/adapter/hono/endpoint.ts","../../../src/adapter/hono/assistants.ts","../../../src/adapter/hono/runs.ts","../../../src/adapter/hono/threads.ts","../../../src/adapter/hono/index.ts"],"sourcesContent":["import { createEndpoint } from '../../createEndpoint.js';\n\nexport const client = createEndpoint();\n","import { zValidator } from '@hono/zod-validator';\nimport { Hono } from 'hono';\nimport { client } from './endpoint';\nimport { AssistantsSearchSchema, AssistantGraphQuerySchema } from '../zod';\nimport camelcaseKeys from 'camelcase-keys';\nconst api = new Hono();\n\napi.post('/assistants/search', zValidator('json', AssistantsSearchSchema), async (c) => {\n // Search Assistants\n const payload = c.req.valid('json');\n let total = 0;\n const data = await client.assistants.search(camelcaseKeys(payload));\n c.res.headers.set('X-Pagination-Total', total.toString());\n return c.json(data);\n});\n\napi.get('/assistants/:assistant_id/graph', zValidator('query', AssistantGraphQuerySchema), async (c) => {\n const xray = c.req.valid('query').xray;\n const data = await client.assistants.getGraph(c.req.param('assistant_id'), {\n xray: xray !== undefined ? xray === 'true' : undefined,\n });\n return c.json(data);\n});\n\nexport default api;\n","import { zValidator } from '@hono/zod-validator';\nimport { Hono } from 'hono';\nimport { SSEStreamingApi, streamSSE } from 'hono/streaming';\nimport { client } from './endpoint';\nimport {\n ThreadIdParamSchema,\n RunIdParamSchema,\n RunStreamPayloadSchema,\n RunListQuerySchema,\n RunCancelQuerySchema,\n RunJoinStreamQuerySchema,\n ThreadStateUpdate,\n} from '../zod';\nimport { serialiseAsDict } from '../../graph/stream';\nimport z from 'zod';\nimport type { LangGraphServerContext } from './index';\nimport camelcaseKeys from 'camelcase-keys';\n\n/**\n * 为 streamSSE 添加心跳功能的 wrapper 函数\n * @param streamFn 原始的 async stream 函数\n * @param heartbeatInterval 心跳间隔,默认 3 秒\n * @returns 包裹后的 async stream 函数\n */\nfunction withHeartbeat(\n streamFn: (stream: SSEStreamingApi) => Promise<void>,\n heartbeatInterval: number = process.env.HEARTBEAT_INTERVAL ? parseInt(process.env.HEARTBEAT_INTERVAL) : 1500,\n): (stream: SSEStreamingApi) => Promise<void> {\n return async (stream: SSEStreamingApi) => {\n let heartbeatTimer: NodeJS.Timeout | null = null;\n\n // 启动心跳定时器的函数\n const startHeartbeat = () => {\n if (heartbeatTimer) {\n clearInterval(heartbeatTimer);\n }\n heartbeatTimer = setInterval(async () => {\n try {\n await stream.writeSSE({ event: 'ping', data: '{}' });\n } catch (error) {\n if (heartbeatTimer) {\n clearInterval(heartbeatTimer);\n heartbeatTimer = null;\n }\n }\n }, heartbeatInterval);\n };\n\n // 停止心跳定时器的函数\n const stopHeartbeat = () => {\n if (heartbeatTimer) {\n clearInterval(heartbeatTimer);\n heartbeatTimer = null;\n }\n };\n\n // 创建代理 stream 对象,在每次写入时重置心跳\n const proxiedStream = new Proxy(stream, {\n get(target, prop) {\n if (prop === 'writeSSE') {\n return async (...args: any[]) => {\n // 每次有数据写入时,先停止当前心跳,然后重新启动\n stopHeartbeat();\n const result = await (target as any)[prop](...args);\n startHeartbeat();\n return result;\n };\n }\n return (target as any)[prop];\n },\n });\n\n // 启动初始心跳\n startHeartbeat();\n\n try {\n await streamFn(proxiedStream);\n } finally {\n stopHeartbeat();\n }\n };\n}\n\nconst api = new Hono<{ Variables: LangGraphServerContext }>();\n\n// 最常用的对话接口\napi.post(\n '/threads/:thread_id/runs/stream',\n zValidator('param', ThreadIdParamSchema),\n zValidator('json', RunStreamPayloadSchema),\n async (c) => {\n // Stream Run\n const { thread_id } = c.req.valid('param');\n const payload = c.req.valid('json');\n\n // c.header('Content-Location', `/threads/${thread_id}/runs/${run.run_id}`);\n return streamSSE(\n c,\n withHeartbeat(async (stream) => {\n payload.config = payload.config || {};\n payload.config.configurable = payload.config.configurable || {};\n const langgraphContext = c.get('langgraph_context');\n if (langgraphContext) {\n Object.assign(payload.config.configurable, langgraphContext);\n }\n /** @ts-ignore zod v3 的问题,与 ts 类型不一致 */\n for await (const { event, data } of client.runs.stream(\n thread_id,\n payload.assistant_id,\n camelcaseKeys(payload) as any,\n )) {\n await stream.writeSSE({ data: serialiseAsDict(data) ?? '', event });\n }\n }),\n );\n },\n);\n\n// 加入现有流的 GET 接口\napi.get(\n '/threads/:thread_id/runs/:run_id/stream',\n zValidator('param', RunIdParamSchema),\n zValidator('query', RunJoinStreamQuerySchema),\n async (c) => {\n const { thread_id, run_id } = c.req.valid('param');\n const { cancel_on_disconnect, last_event_id, stream_mode } = c.req.valid('query');\n\n return streamSSE(\n c,\n withHeartbeat(async (stream) => {\n // 创建 AbortController 用于处理取消信号\n const controller = new AbortController();\n\n // 如果需要断开连接时取消,则监听连接断开事件\n if (cancel_on_disconnect) {\n const cleanup = () => {\n controller.abort('Client disconnected');\n };\n\n // 监听连接断开事件\n c.req.raw.signal?.addEventListener('abort', cleanup);\n stream.onAbort = cleanup;\n }\n\n try {\n // 使用 joinStream 方法加入现有流\n for await (const { event, data, id } of client.runs.joinStream(thread_id, run_id, {\n signal: controller.signal,\n cancelOnDisconnect: cancel_on_disconnect,\n lastEventId: last_event_id,\n streamMode: stream_mode ? [stream_mode] : undefined,\n })) {\n // 发送 SSE 事件\n await stream.writeSSE({\n data: serialiseAsDict(data) ?? '',\n event: event as unknown as string,\n id,\n });\n }\n } catch (error) {\n // 如果不是用户取消导致的错误,则发送错误事件\n if (!(error instanceof Error) || !error.message.includes('user cancel')) {\n console.error('Join stream error:', error);\n await stream.writeSSE({\n event: 'error',\n data: JSON.stringify({\n error: error instanceof Error ? error.message : 'Unknown error',\n }),\n });\n }\n }\n }),\n );\n },\n);\n\napi.get(\n '/threads/:thread_id/runs',\n zValidator('param', ThreadIdParamSchema),\n zValidator('query', RunListQuerySchema),\n async (c) => {\n const { thread_id } = c.req.valid('param');\n const { limit, offset, status } = c.req.valid('query');\n const runs = await client.runs.list(thread_id, { limit, offset, status });\n return c.json(runs);\n },\n);\n\napi.post(\n '/threads/:thread_id/runs/:run_id/cancel',\n zValidator('param', RunIdParamSchema),\n zValidator('query', RunCancelQuerySchema),\n async (c) => {\n // Cancel Run Http\n const { thread_id, run_id } = c.req.valid('param');\n const { wait, action } = c.req.valid('query');\n const cancel = client.runs.cancel(thread_id, run_id, wait, action);\n if (wait) {\n await cancel;\n }\n return c.body(null, wait ? 204 : 202);\n },\n);\n\napi.post(\n '/threads/:thread_id/state',\n zValidator('param', z.object({ thread_id: z.string().uuid() })),\n zValidator('json', ThreadStateUpdate),\n async (c) => {\n // Update Thread State\n const { thread_id } = c.req.valid('param');\n const payload = c.req.valid('json');\n // const config: RunnableConfig = { configurable: { thread_id } };\n\n // if (payload.checkpoint_id) {\n // config.configurable ??= {};\n // config.configurable.checkpoint_id = payload.checkpoint_id;\n // }\n // if (payload.checkpoint) {\n // config.configurable ??= {};\n // Object.assign(config.configurable, payload.checkpoint);\n // }\n\n const inserted = await client.threads.updateState(thread_id, payload);\n\n return c.json(inserted);\n },\n);\nexport default api;\n","import { zValidator } from '@hono/zod-validator';\nimport { Hono } from 'hono';\nimport { client } from './endpoint';\nimport { ThreadIdParamSchema, ThreadCreatePayloadSchema, ThreadSearchPayloadSchema } from '../zod';\nimport camelcaseKeys from 'camelcase-keys';\n\nconst api = new Hono();\n\n// Threads Routes\napi.post('/threads', zValidator('json', ThreadCreatePayloadSchema), async (c) => {\n const payload = c.req.valid('json');\n const thread = await client.threads.create(camelcaseKeys(payload));\n\n return c.json(thread);\n});\n\napi.post('/threads/search', zValidator('json', ThreadSearchPayloadSchema), async (c) => {\n // Search Threads\n const payload = c.req.valid('json');\n const result = await client.threads.search(camelcaseKeys(payload));\n c.res.headers.set('X-Pagination-Total', result.length.toString());\n return c.json(result);\n});\n\napi.get('/threads/:thread_id', zValidator('param', ThreadIdParamSchema), async (c) => {\n // Get Thread\n const { thread_id } = c.req.valid('param');\n return c.json(await client.threads.get(thread_id));\n});\n\napi.delete('/threads/:thread_id', zValidator('param', ThreadIdParamSchema), async (c) => {\n // Delete Thread\n const { thread_id } = c.req.valid('param');\n await client.threads.delete(thread_id);\n return new Response(null, { status: 204 });\n});\n\nexport default api;\n","import { Hono } from 'hono';\nimport Assistants from './assistants';\nimport Runs from './runs';\nimport Threads from './threads';\n// import { cors } from 'hono/cors';\nimport { LangGraphGlobal } from '../../global';\n\nexport interface LangGraphServerContext {\n langgraph_context: any;\n}\nconst app = new Hono<{ Variables: LangGraphServerContext }>();\napp.use('*', async (c, next) => {\n await LangGraphGlobal.initGlobal();\n return next();\n});\n// app.use(cors());\n\napp.route('/', Assistants);\napp.route('/', Runs);\napp.route('/', Threads);\n\nexport default app;\n"],"names":["api","Assistants","Runs","Threads"],"mappings":";;;;;;;;;AAEO,MAAM,SAAS,cAAA,EAAe;;ACGrC,MAAMA,KAAA,GAAM,IAAI,IAAA,EAAK;AAErBA,KAAA,CAAI,KAAK,oBAAA,EAAsB,UAAA,CAAW,QAAQ,sBAAsB,CAAA,EAAG,OAAO,CAAA,KAAM;AAEpF,EAAA,MAAM,OAAA,GAAU,CAAA,CAAE,GAAA,CAAI,KAAA,CAAM,MAAM,CAAA;AAClC,EAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,EAAA,MAAM,OAAO,MAAM,MAAA,CAAO,WAAW,MAAA,CAAO,aAAA,CAAc,OAAO,CAAC,CAAA;AAClE,EAAA,CAAA,CAAE,IAAI,OAAA,CAAQ,GAAA,CAAI,oBAAA,EAAsB,KAAA,CAAM,UAAU,CAAA;AACxD,EAAA,OAAO,CAAA,CAAE,KAAK,IAAI,CAAA;AACtB,CAAC,CAAA;AAEDA,KAAA,CAAI,IAAI,iCAAA,EAAmC,UAAA,CAAW,SAAS,yBAAyB,CAAA,EAAG,OAAO,CAAA,KAAM;AACpG,EAAA,MAAM,IAAA,GAAO,CAAA,CAAE,GAAA,CAAI,KAAA,CAAM,OAAO,CAAA,CAAE,IAAA;AAClC,EAAA,MAAM,IAAA,GAAO,MAAM,MAAA,CAAO,UAAA,CAAW,SAAS,CAAA,CAAE,GAAA,CAAI,KAAA,CAAM,cAAc,CAAA,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CAAA,EAAG,OAAO,CAAA,KAAM;AAErF,EAAA,MAAM,EAAE,SAAA,EAAU,GAAI,CAAA,CAAE,GAAA,CAAI,MAAM,OAAO,CAAA;AACzC,EAAA,MAAM,MAAA,CAAO,OAAA,CAAQ,MAAA,CAAO,SAAS,CAAA;AACrC,EAAA,OAAO,IAAI,QAAA,CAAS,IAAA,EAAM,EAAE,MAAA,EAAQ,KAAK,CAAA;AAC7C,CAAC,CAAA;;ACzBD,MAAM,GAAA,GAAM,IAAI,IAAA;AAChB,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,OAAO,CAAA,EAAG,IAAA,KAAS;AAC5B,EAAA,MAAM,gBAAgB,UAAA,EAAW;AACjC,EAAA,OAAO,IAAA,EAAK;AAChB,CAAC,CAAA;AAGD,GAAA,CAAI,KAAA,CAAM,KAAKC,KAAU,CAAA;AACzB,GAAA,CAAI,KAAA,CAAM,KAAKC,KAAI,CAAA;AACnB,GAAA,CAAI,KAAA,CAAM,KAAKC,GAAO,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/adapter/hono/index.ts"],"sourcesContent":["import { Hono } from 'hono';\nimport { handleRequest } from '../fetch';\n// import { cors } from 'hono/cors';\n\nexport interface LangGraphServerContext {\n langgraph_context: any;\n}\n\nconst app = new Hono<{ Variables: LangGraphServerContext }>();\n\n// app.use(cors());\n\n// 使用 fetch 实现的 handleRequest 统一处理所有请求\napp.all('*', async (c) => {\n // 从 hono context 中提取 langgraph_context\n const context = {\n langgraph_context: c.get('langgraph_context'),\n };\n\n // 调用标准的 fetch handleRequest\n const response = await handleRequest(c.req.raw, context);\n\n return response;\n});\n\nexport default app;\n"],"names":[],"mappings":";;;AAQA,MAAM,GAAA,GAAM,IAAI,IAAA;AAKhB,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,OAAO,CAAA,KAAM;AAEtB,EAAA,MAAM,OAAA,GAAU;AAAA,IACZ,iBAAA,EAAmB,CAAA,CAAE,GAAA,CAAI,mBAAmB;AAAA,GAChD;AAGA,EAAA,MAAM,WAAW,MAAM,aAAA,CAAc,CAAA,CAAE,GAAA,CAAI,KAAK,OAAO,CAAA;AAEvD,EAAA,OAAO,QAAA;AACX,CAAC,CAAA;;;;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { L as LangGraphGlobal } from '../../stream-
|
|
1
|
+
import { L as LangGraphGlobal } from '../../stream-Blquv56P.js';
|
|
2
2
|
|
|
3
3
|
async function ensureInitialized(attachGraphPromise) {
|
|
4
4
|
if (globalThis.LG_INIT_PROMISE === void 0) {
|
|
5
5
|
globalThis.LG_INIT_PROMISE = (async () => {
|
|
6
6
|
await LangGraphGlobal.initGlobal();
|
|
7
7
|
await attachGraphPromise();
|
|
8
|
-
const { GET, POST, DELETE } = await import('../../router-
|
|
8
|
+
const { GET, POST, DELETE } = await import('../../router-Dk7saRUW.js');
|
|
9
9
|
return {
|
|
10
10
|
GET,
|
|
11
11
|
POST,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @ts-ignore */
|
|
2
2
|
import { NextRequest } from 'next/server';
|
|
3
|
-
export declare function GET(req: NextRequest): Promise<
|
|
4
|
-
export declare function POST(req: NextRequest): Promise<
|
|
5
|
-
export declare function DELETE(req: NextRequest): Promise<
|
|
3
|
+
export declare function GET(req: NextRequest): Promise<Response>;
|
|
4
|
+
export declare function POST(req: NextRequest): Promise<Response>;
|
|
5
|
+
export declare function DELETE(req: NextRequest): Promise<Response>;
|