@langgraph-js/pure-graph 1.0.0 → 1.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/package.json +1 -9
- package/src/adapter/hono/runs.ts +0 -1
- package/src/createEndpoint.ts +9 -6
- package/src/graph/stream.ts +1 -1
- package/src/queue/event_message.ts +1 -1
- package/src/storage/memory/queue.ts +14 -6
- package/test/test.ts +10 -0
package/package.json
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langgraph-js/pure-graph",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": {
|
|
8
|
-
"import": "./dist/index.js"
|
|
9
|
-
},
|
|
10
|
-
"/hono": {
|
|
11
|
-
"import": "./dist/adapter/hono/index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
6
|
"keywords": [],
|
|
15
7
|
"author": "",
|
|
16
8
|
"license": "MIT",
|
package/src/adapter/hono/runs.ts
CHANGED
package/src/createEndpoint.ts
CHANGED
|
@@ -78,12 +78,15 @@ export const createEndpoint = (threads: BaseThreadsManager): ILangGraphClient =>
|
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
for await (const data of streamState(
|
|
82
|
+
threads,
|
|
83
|
+
threads.createRun(threadId, assistantId, payload),
|
|
84
|
+
payload,
|
|
85
|
+
{
|
|
86
|
+
attempt: 0,
|
|
87
|
+
getGraph,
|
|
88
|
+
},
|
|
89
|
+
)) {
|
|
87
90
|
yield data;
|
|
88
91
|
}
|
|
89
92
|
},
|
package/src/graph/stream.ts
CHANGED
|
@@ -246,7 +246,7 @@ export async function* streamState(
|
|
|
246
246
|
await threads.set(threadId, { status: 'error' });
|
|
247
247
|
// throw error;
|
|
248
248
|
} finally {
|
|
249
|
-
//
|
|
249
|
+
// 在完成后清理队列
|
|
250
250
|
await threads.set(threadId, { status: 'idle' });
|
|
251
251
|
globalMessageQueue.removeQueue(queueId);
|
|
252
252
|
}
|
|
@@ -21,20 +21,26 @@ export class MemoryStreamQueue extends BaseStreamQueue implements BaseStreamQueu
|
|
|
21
21
|
* 异步生成器:支持 for await...of 方式消费队列数据
|
|
22
22
|
*/
|
|
23
23
|
async *onDataReceive(): AsyncGenerator<EventMessage, void, unknown> {
|
|
24
|
-
|
|
24
|
+
let queue: EventMessage[] = [];
|
|
25
25
|
let pendingResolve: (() => void) | null = null;
|
|
26
26
|
let isStreamEnded = false;
|
|
27
27
|
const handleData = async (item: EventMessage) => {
|
|
28
28
|
const data = this.compressMessages ? ((await this.decodeData(item as any)) as EventMessage) : item;
|
|
29
29
|
queue.push(data);
|
|
30
|
-
|
|
31
30
|
// 检查是否为流结束或错误信号
|
|
32
31
|
if (
|
|
33
32
|
data.event === '__stream_end__' ||
|
|
34
33
|
data.event === '__stream_error__' ||
|
|
35
34
|
data.event === '__stream_cancel__'
|
|
36
35
|
) {
|
|
37
|
-
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
isStreamEnded = true;
|
|
38
|
+
if (pendingResolve) {
|
|
39
|
+
pendingResolve();
|
|
40
|
+
pendingResolve = null;
|
|
41
|
+
}
|
|
42
|
+
}, 300);
|
|
43
|
+
|
|
38
44
|
if (data.event === '__stream_cancel__') {
|
|
39
45
|
this.cancel();
|
|
40
46
|
}
|
|
@@ -45,14 +51,16 @@ export class MemoryStreamQueue extends BaseStreamQueue implements BaseStreamQueu
|
|
|
45
51
|
pendingResolve = null;
|
|
46
52
|
}
|
|
47
53
|
};
|
|
48
|
-
|
|
54
|
+
// todo 这个框架的事件监听的数据返回顺序有误
|
|
49
55
|
this.on('dataChange', handleData as any);
|
|
50
56
|
|
|
51
57
|
try {
|
|
52
58
|
while (!isStreamEnded) {
|
|
53
59
|
if (queue.length > 0) {
|
|
54
|
-
const item
|
|
55
|
-
|
|
60
|
+
for (const item of queue) {
|
|
61
|
+
yield item;
|
|
62
|
+
}
|
|
63
|
+
queue = [];
|
|
56
64
|
} else {
|
|
57
65
|
await new Promise((resolve) => {
|
|
58
66
|
pendingResolve = resolve as () => void;
|
package/test/test.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { registerGraph } from '../src/createEndpoint';
|
|
2
|
+
import { graph } from '/Users/konghayao/code/ai/code-graph/agents/code/graph';
|
|
3
|
+
import { Hono } from 'hono';
|
|
4
|
+
import LangGraphApp from '../src/adapter/hono/index';
|
|
5
|
+
registerGraph('code', graph);
|
|
6
|
+
|
|
7
|
+
const app = new Hono();
|
|
8
|
+
app.route('/', LangGraphApp);
|
|
9
|
+
|
|
10
|
+
export default app;
|