@langgraph-js/pure-graph 2.10.0 → 3.0.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/dist/adapter/fetch/assistants.d.ts +42 -0
- package/dist/adapter/fetch/endpoint.d.ts +25 -0
- package/dist/adapter/fetch/index.d.ts +5 -3
- package/dist/adapter/fetch/index.js +858 -25
- package/dist/adapter/fetch/index.js.map +1 -1
- package/dist/adapter/fetch/runs-extended.d.ts +21 -0
- package/dist/adapter/fetch/runs-stateless.d.ts +28 -0
- package/dist/adapter/fetch/runs.d.ts +0 -4
- package/dist/adapter/fetch/threads.d.ts +36 -0
- package/dist/adapter/nextjs/index.js +1 -1
- package/dist/adapter/zod.d.ts +292 -1
- package/dist/agents/ask_subagents.d.ts +1 -1
- package/dist/createEndpoint-BViLxrhh.js +208 -0
- package/dist/createEndpoint-BViLxrhh.js.map +1 -0
- package/dist/createEndpoint.d.ts +25 -0
- package/dist/index.js +2 -2
- package/dist/queue/stream_queue.d.ts +2 -2
- package/dist/queue-CtVch_az.js +153 -0
- package/dist/queue-CtVch_az.js.map +1 -0
- package/dist/remote/index.js +158 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/remote-threads-CrG03ZS7.js +255 -0
- package/dist/remote-threads-CrG03ZS7.js.map +1 -0
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/kysely/index.d.ts +1 -0
- package/dist/storage/kysely/remote-threads.d.ts +124 -0
- package/dist/storage/kysely/threads.d.ts +26 -2
- package/dist/storage/kysely/types.d.ts +10 -0
- package/dist/storage/memory/threads.d.ts +27 -1
- package/dist/storage/redis/queue.d.ts +14 -11
- package/dist/storage/remote/fetch.d.ts +20 -0
- package/dist/storage/remote/remote-server.d.ts +17 -0
- package/dist/storage/remote/server.d.ts +11 -0
- package/dist/storage/remote/types.d.ts +121 -0
- package/dist/{stream-D0YD2Pjq.js → stream-umoA6h4q.js} +502 -78
- package/dist/stream-umoA6h4q.js.map +1 -0
- package/dist/threads/index.d.ts +25 -1
- package/dist/types.d.ts +53 -1
- package/package.json +10 -4
- package/dist/createEndpoint-CN_RHDEd.js +0 -122
- package/dist/createEndpoint-CN_RHDEd.js.map +0 -1
- package/dist/queue-D6tEGCGs.js +0 -146
- package/dist/queue-D6tEGCGs.js.map +0 -1
- package/dist/stream-D0YD2Pjq.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s as serialiseAsDict, L as LangGraphGlobal } from '../../stream-
|
|
2
|
-
import { c as createEndpoint } from '../../createEndpoint-
|
|
1
|
+
import { s as serialiseAsDict, a as streamState, g as getGraph, L as LangGraphGlobal } from '../../stream-umoA6h4q.js';
|
|
2
|
+
import { c as createEndpoint } from '../../createEndpoint-BViLxrhh.js';
|
|
3
3
|
import z from 'zod';
|
|
4
4
|
import camelcaseKeys from 'camelcase-keys';
|
|
5
5
|
|
|
@@ -15,7 +15,7 @@ const AssistantConfig = z.object({
|
|
|
15
15
|
configurable: AssistantConfigurable.optional()
|
|
16
16
|
}).catchall(z.unknown()).describe("The configuration of an assistant.");
|
|
17
17
|
z.object({
|
|
18
|
-
assistant_id: z.string()
|
|
18
|
+
assistant_id: z.string(),
|
|
19
19
|
graph_id: z.string(),
|
|
20
20
|
config: AssistantConfig,
|
|
21
21
|
created_at: z.string(),
|
|
@@ -42,23 +42,44 @@ z.object({
|
|
|
42
42
|
offset: z.number().int().optional()
|
|
43
43
|
});
|
|
44
44
|
const ThreadIdParamSchema = z.object({
|
|
45
|
-
thread_id: z.string()
|
|
45
|
+
thread_id: z.string()
|
|
46
46
|
});
|
|
47
47
|
const RunIdParamSchema = z.object({
|
|
48
|
-
thread_id: z.string()
|
|
49
|
-
run_id: z.string()
|
|
48
|
+
thread_id: z.string(),
|
|
49
|
+
run_id: z.string()
|
|
50
50
|
});
|
|
51
51
|
const AssistantsSearchSchema = z.object({
|
|
52
52
|
graph_id: z.string().optional(),
|
|
53
53
|
metadata: MetadataSchema.optional(),
|
|
54
54
|
limit: z.number().int().optional(),
|
|
55
|
-
offset: z.number().int().optional()
|
|
55
|
+
offset: z.number().int().optional(),
|
|
56
|
+
sort_by: z.enum(["assistant_id", "graph_id", "name", "created_at", "updated_at"]).optional(),
|
|
57
|
+
sort_order: z.enum(["asc", "desc"]).optional()
|
|
58
|
+
});
|
|
59
|
+
const AssistantCountSchema = z.object({
|
|
60
|
+
graph_id: z.string().optional(),
|
|
61
|
+
metadata: MetadataSchema.optional()
|
|
56
62
|
});
|
|
57
63
|
const AssistantGraphQuerySchema = z.object({
|
|
58
|
-
xray: z.string().optional()
|
|
64
|
+
xray: z.union([z.string(), z.boolean(), z.number()]).optional()
|
|
65
|
+
});
|
|
66
|
+
const AssistantPatchSchema = z.object({
|
|
67
|
+
name: z.string().optional(),
|
|
68
|
+
description: z.string().optional(),
|
|
69
|
+
metadata: MetadataSchema.optional(),
|
|
70
|
+
config: AssistantConfig.optional()
|
|
71
|
+
}).optional();
|
|
72
|
+
const AssistantCreateSchema = z.object({
|
|
73
|
+
assistant_id: z.string().optional(),
|
|
74
|
+
graph_id: z.string().describe("The ID of graph to create an assistant from."),
|
|
75
|
+
name: z.string().optional(),
|
|
76
|
+
description: z.string().optional(),
|
|
77
|
+
metadata: MetadataSchema.optional(),
|
|
78
|
+
config: AssistantConfig.optional(),
|
|
79
|
+
if_exists: z.enum(["raise", "do_nothing"]).optional()
|
|
59
80
|
});
|
|
60
81
|
const RunStreamPayloadSchema = z.object({
|
|
61
|
-
assistant_id: z.union([z.string()
|
|
82
|
+
assistant_id: z.union([z.string(), z.string()]),
|
|
62
83
|
checkpoint_id: z.string().optional(),
|
|
63
84
|
input: z.any().optional(),
|
|
64
85
|
command: CommandSchema.optional(),
|
|
@@ -93,11 +114,12 @@ const RunJoinStreamQuerySchema = z.object({
|
|
|
93
114
|
stream_mode: z.enum(["values", "messages", "messages-tuple", "updates", "events", "debug", "custom"]).optional()
|
|
94
115
|
});
|
|
95
116
|
const ThreadCreatePayloadSchema = z.object({
|
|
96
|
-
thread_id: z.string().
|
|
117
|
+
thread_id: z.string().describe("The ID of thread. If not provided, an ID is generated.").optional(),
|
|
97
118
|
metadata: MetadataSchema.optional(),
|
|
98
119
|
if_exists: z.union([z.literal("raise"), z.literal("do_nothing")]).optional()
|
|
99
120
|
}).describe("Payload for creating a thread.");
|
|
100
121
|
const ThreadSearchPayloadSchema = z.object({
|
|
122
|
+
ids: z.array(z.string()).describe("List of thread IDs to include. Others are excluded.").optional(),
|
|
101
123
|
metadata: MetadataSchema.describe("Metadata to search for.").optional(),
|
|
102
124
|
status: z.enum(["idle", "busy", "interrupted", "error"]).describe("Filter by thread status.").optional(),
|
|
103
125
|
values: z.any().describe("Filter by thread values.").optional(),
|
|
@@ -105,14 +127,92 @@ const ThreadSearchPayloadSchema = z.object({
|
|
|
105
127
|
offset: z.number().int().gte(0).describe("Offset to start from.").optional(),
|
|
106
128
|
sort_by: z.enum(["thread_id", "status", "created_at", "updated_at"]).describe("Sort by field.").optional(),
|
|
107
129
|
sort_order: z.enum(["asc", "desc"]).describe("Sort order.").optional(),
|
|
130
|
+
select: z.array(
|
|
131
|
+
z.enum([
|
|
132
|
+
"thread_id",
|
|
133
|
+
"created_at",
|
|
134
|
+
"updated_at",
|
|
135
|
+
"metadata",
|
|
136
|
+
"config",
|
|
137
|
+
"context",
|
|
138
|
+
"status",
|
|
139
|
+
"values",
|
|
140
|
+
"interrupts"
|
|
141
|
+
])
|
|
142
|
+
).describe("Specify which fields to return. If not provided, all fields are returned.").optional(),
|
|
108
143
|
without_details: z.boolean().describe("Whether to return values.").optional()
|
|
109
144
|
}).describe("Payload for listing threads.");
|
|
110
|
-
|
|
145
|
+
z.object({
|
|
111
146
|
values: z.union([z.record(z.string(), z.unknown()), z.array(z.record(z.string(), z.unknown()))]).nullish()
|
|
112
147
|
// as_node: z.string().optional(),
|
|
113
148
|
// checkpoint_id: z.string().optional(),
|
|
114
149
|
// checkpoint: CheckpointSchema.nullish(),
|
|
115
150
|
}).describe("Payload for adding state to a thread.");
|
|
151
|
+
const ThreadPatchSchema = z.object({
|
|
152
|
+
metadata: MetadataSchema.optional(),
|
|
153
|
+
status: z.enum(["idle", "busy", "interrupted", "error"]).optional(),
|
|
154
|
+
values: z.any().optional()
|
|
155
|
+
}).describe("Payload for patching a thread.");
|
|
156
|
+
const RunCreateSchema = z.object({
|
|
157
|
+
assistant_id: z.string(),
|
|
158
|
+
input: z.any().optional(),
|
|
159
|
+
command: CommandSchema.optional(),
|
|
160
|
+
metadata: MetadataSchema.optional(),
|
|
161
|
+
config: AssistantConfig.optional(),
|
|
162
|
+
webhook: z.string().optional(),
|
|
163
|
+
interrupt_before: z.union([z.literal("*"), z.array(z.string())]).optional(),
|
|
164
|
+
interrupt_after: z.union([z.literal("*"), z.array(z.string())]).optional(),
|
|
165
|
+
on_disconnect: z.enum(["cancel", "continue"]).optional().default("continue"),
|
|
166
|
+
multitask_strategy: z.enum(["reject", "rollback", "interrupt", "enqueue"]).optional(),
|
|
167
|
+
stream_mode: z.array(z.enum(["values", "messages", "messages-tuple", "updates", "events", "debug", "custom"])).optional(),
|
|
168
|
+
stream_subgraphs: z.boolean().optional(),
|
|
169
|
+
stream_resumable: z.boolean().optional(),
|
|
170
|
+
after_seconds: z.number().optional(),
|
|
171
|
+
if_not_exists: z.enum(["create", "reject"]).optional(),
|
|
172
|
+
on_completion: z.enum(["complete", "continue"]).optional(),
|
|
173
|
+
feedback_keys: z.array(z.string()).optional(),
|
|
174
|
+
langsmith_tracer: z.unknown().optional()
|
|
175
|
+
}).describe("Payload for creating a run (background/wait).");
|
|
176
|
+
const RunWaitQuerySchema = z.object({
|
|
177
|
+
cancel_on_disconnect: z.coerce.boolean().optional().default(false)
|
|
178
|
+
});
|
|
179
|
+
const RunJoinQuerySchema = z.object({
|
|
180
|
+
cancel_on_disconnect: z.coerce.boolean().optional().default(false)
|
|
181
|
+
});
|
|
182
|
+
const RunCreateStatelessSchema = z.object({
|
|
183
|
+
assistant_id: z.string().describe("The assistant ID or graph name to run."),
|
|
184
|
+
input: z.any().optional().describe("The input to the graph."),
|
|
185
|
+
command: CommandSchema.optional(),
|
|
186
|
+
metadata: MetadataSchema.optional().describe("Metadata to assign to the run."),
|
|
187
|
+
config: AssistantConfig.optional(),
|
|
188
|
+
context: z.object({}).catchall(z.any()).optional().describe("Static context added to the assistant."),
|
|
189
|
+
webhook: z.string().optional(),
|
|
190
|
+
interrupt_before: z.union([z.literal("*"), z.array(z.string())]).optional(),
|
|
191
|
+
interrupt_after: z.union([z.literal("*"), z.array(z.string())]).optional(),
|
|
192
|
+
stream_mode: z.union([
|
|
193
|
+
z.enum(["values", "messages", "messages-tuple", "tasks", "checkpoints", "updates", "events", "debug", "custom"]),
|
|
194
|
+
z.array(z.enum(["values", "messages", "messages-tuple", "tasks", "checkpoints", "updates", "events", "debug", "custom"]))
|
|
195
|
+
]).optional().default(["values"]),
|
|
196
|
+
feedback_keys: z.array(z.string()).optional(),
|
|
197
|
+
stream_subgraphs: z.boolean().optional().default(false),
|
|
198
|
+
stream_resumable: z.boolean().optional().default(false)
|
|
199
|
+
}).describe("Payload for creating a stateless run.");
|
|
200
|
+
const RunBatchCreateSchema = z.array(RunCreateStatelessSchema).min(1).describe("Payload for creating a batch of stateless runs.");
|
|
201
|
+
const RunsCancelQuerySchema = z.object({
|
|
202
|
+
action: z.enum(["interrupt", "rollback"]).optional().default("interrupt").describe("Action to take when cancelling the run."),
|
|
203
|
+
wait: z.coerce.boolean().optional().default(false)
|
|
204
|
+
});
|
|
205
|
+
const RunsCancelSchema = z.union([
|
|
206
|
+
z.object({
|
|
207
|
+
status: z.enum(["pending", "running", "all"]).describe("Filter runs by status to cancel.")
|
|
208
|
+
}),
|
|
209
|
+
z.object({
|
|
210
|
+
thread_id: z.string().describe("The ID of the thread containing runs to cancel.")
|
|
211
|
+
}),
|
|
212
|
+
z.object({
|
|
213
|
+
run_ids: z.array(z.string()).min(1).describe("List of run IDs to cancel.")
|
|
214
|
+
})
|
|
215
|
+
]);
|
|
116
216
|
|
|
117
217
|
function parsePathParams(url, pattern) {
|
|
118
218
|
const patternParts = pattern.split("/").filter((p) => p);
|
|
@@ -305,6 +405,55 @@ async function searchAssistants(req, context) {
|
|
|
305
405
|
return errorResponse(error);
|
|
306
406
|
}
|
|
307
407
|
}
|
|
408
|
+
async function countAssistants(req, context) {
|
|
409
|
+
try {
|
|
410
|
+
const body = await req.json();
|
|
411
|
+
const payload = validate(AssistantCountSchema, body);
|
|
412
|
+
const data = await client.assistants.count(camelcaseKeys(payload));
|
|
413
|
+
return jsonResponse(data);
|
|
414
|
+
} catch (error) {
|
|
415
|
+
return errorResponse(error);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
async function getAssistant(req, context) {
|
|
419
|
+
try {
|
|
420
|
+
const url = new URL(req.url);
|
|
421
|
+
const pathParts = url.pathname.split("/").filter((p) => p);
|
|
422
|
+
const assistant_id = pathParts[1];
|
|
423
|
+
const data = await client.assistants.get(assistant_id);
|
|
424
|
+
return jsonResponse(data);
|
|
425
|
+
} catch (error) {
|
|
426
|
+
return errorResponse(error);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
async function deleteAssistant(req, context) {
|
|
430
|
+
try {
|
|
431
|
+
const url = new URL(req.url);
|
|
432
|
+
const pathParts = url.pathname.split("/").filter((p) => p);
|
|
433
|
+
const assistant_id = pathParts[1];
|
|
434
|
+
await client.assistants.delete(assistant_id);
|
|
435
|
+
return jsonResponse({});
|
|
436
|
+
} catch (error) {
|
|
437
|
+
return errorResponse(error);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
async function patchAssistant(req, context) {
|
|
441
|
+
try {
|
|
442
|
+
const url = new URL(req.url);
|
|
443
|
+
const pathParts = url.pathname.split("/").filter((p) => p);
|
|
444
|
+
const assistant_id = pathParts[1];
|
|
445
|
+
const body = await req.json();
|
|
446
|
+
const payload = validate(AssistantPatchSchema, body);
|
|
447
|
+
const data = await client.assistants.update(
|
|
448
|
+
assistant_id,
|
|
449
|
+
/** @ts-ignore */
|
|
450
|
+
camelcaseKeys(payload)
|
|
451
|
+
);
|
|
452
|
+
return jsonResponse(data);
|
|
453
|
+
} catch (error) {
|
|
454
|
+
return errorResponse(error);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
308
457
|
async function getAssistantGraph(req, context) {
|
|
309
458
|
try {
|
|
310
459
|
const url = new URL(req.url);
|
|
@@ -320,6 +469,71 @@ async function getAssistantGraph(req, context) {
|
|
|
320
469
|
return errorResponse(error);
|
|
321
470
|
}
|
|
322
471
|
}
|
|
472
|
+
async function getAssistantSubgraphs(req, context) {
|
|
473
|
+
return errorResponse(
|
|
474
|
+
{
|
|
475
|
+
},
|
|
476
|
+
501
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
async function getAssistantSubgraphsByNamespace(req, context) {
|
|
480
|
+
return errorResponse(
|
|
481
|
+
{
|
|
482
|
+
},
|
|
483
|
+
501
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
async function getAssistantSchemas(req, context) {
|
|
487
|
+
try {
|
|
488
|
+
const url = new URL(req.url);
|
|
489
|
+
const pathParts = url.pathname.split("/").filter((p) => p);
|
|
490
|
+
const assistant_id = pathParts[1];
|
|
491
|
+
const data = await client.assistants.getSchemas(assistant_id);
|
|
492
|
+
return jsonResponse(data);
|
|
493
|
+
} catch (error) {
|
|
494
|
+
return errorResponse(error);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
async function getAssistantVersions(req, context) {
|
|
498
|
+
try {
|
|
499
|
+
const url = new URL(req.url);
|
|
500
|
+
const pathParts = url.pathname.split("/").filter((p) => p);
|
|
501
|
+
const assistant_id = pathParts[1];
|
|
502
|
+
const body = await req.json();
|
|
503
|
+
const payload = validate(AssistantPatchSchema, body);
|
|
504
|
+
const data = await client.assistants.getVersions(
|
|
505
|
+
assistant_id,
|
|
506
|
+
/** @ts-ignore */
|
|
507
|
+
camelcaseKeys(payload)
|
|
508
|
+
);
|
|
509
|
+
return jsonResponse(data);
|
|
510
|
+
} catch (error) {
|
|
511
|
+
return errorResponse(error);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
async function setLatestAssistantVersion(req, context) {
|
|
515
|
+
try {
|
|
516
|
+
const url = new URL(req.url);
|
|
517
|
+
const pathParts = url.pathname.split("/").filter((p) => p);
|
|
518
|
+
const assistant_id = pathParts[1];
|
|
519
|
+
const queryParams = parseQueryParams(req.url);
|
|
520
|
+
const version = queryParams.version ? parseInt(queryParams.version) : 1;
|
|
521
|
+
const data = await client.assistants.setLatest(assistant_id, version);
|
|
522
|
+
return jsonResponse(data);
|
|
523
|
+
} catch (error) {
|
|
524
|
+
return errorResponse(error);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
async function createAssistant(req, context) {
|
|
528
|
+
try {
|
|
529
|
+
const body = await req.json();
|
|
530
|
+
const payload = validate(AssistantCreateSchema, body);
|
|
531
|
+
const data = await client.assistants.create(camelcaseKeys(payload));
|
|
532
|
+
return jsonResponse(data);
|
|
533
|
+
} catch (error) {
|
|
534
|
+
return errorResponse(error);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
323
537
|
|
|
324
538
|
async function createThread(req, context) {
|
|
325
539
|
try {
|
|
@@ -343,6 +557,16 @@ async function searchThreads(req, context) {
|
|
|
343
557
|
return errorResponse(error);
|
|
344
558
|
}
|
|
345
559
|
}
|
|
560
|
+
async function countThreads(req, context) {
|
|
561
|
+
try {
|
|
562
|
+
const body = await req.json();
|
|
563
|
+
const payload = validate(ThreadSearchPayloadSchema.partial(), body);
|
|
564
|
+
const count = await client.threads.count(camelcaseKeys(payload));
|
|
565
|
+
return jsonResponse(count);
|
|
566
|
+
} catch (error) {
|
|
567
|
+
return errorResponse(error);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
346
570
|
async function getThread(req, context) {
|
|
347
571
|
try {
|
|
348
572
|
const params = parsePathParams(req.url, "/threads/:thread_id");
|
|
@@ -353,6 +577,18 @@ async function getThread(req, context) {
|
|
|
353
577
|
return errorResponse(error);
|
|
354
578
|
}
|
|
355
579
|
}
|
|
580
|
+
async function patchThread(req, context) {
|
|
581
|
+
try {
|
|
582
|
+
const params = parsePathParams(req.url, "/threads/:thread_id");
|
|
583
|
+
const { thread_id } = validate(ThreadIdParamSchema, params);
|
|
584
|
+
const body = await req.json();
|
|
585
|
+
const payload = validate(ThreadPatchSchema, body);
|
|
586
|
+
const thread = await client.threads.patch(thread_id, camelcaseKeys(payload));
|
|
587
|
+
return jsonResponse(thread);
|
|
588
|
+
} catch (error) {
|
|
589
|
+
return errorResponse(error);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
356
592
|
async function deleteThread(req, context) {
|
|
357
593
|
try {
|
|
358
594
|
const params = parsePathParams(req.url, "/threads/:thread_id");
|
|
@@ -363,6 +599,107 @@ async function deleteThread(req, context) {
|
|
|
363
599
|
return errorResponse(error);
|
|
364
600
|
}
|
|
365
601
|
}
|
|
602
|
+
async function getThreadState(req, context) {
|
|
603
|
+
try {
|
|
604
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/state");
|
|
605
|
+
const { thread_id } = validate(ThreadIdParamSchema, params);
|
|
606
|
+
const queryParams = parseQueryParams(req.url);
|
|
607
|
+
const options = {
|
|
608
|
+
subgraphs: queryParams.subgraphs === "true" || queryParams.subgraphs === true
|
|
609
|
+
};
|
|
610
|
+
const state = await client.threads.getState(thread_id, options);
|
|
611
|
+
return jsonResponse(state);
|
|
612
|
+
} catch (error) {
|
|
613
|
+
return errorResponse(error);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
async function updateThreadState(req, context) {
|
|
617
|
+
try {
|
|
618
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/state");
|
|
619
|
+
const { thread_id } = validate(ThreadIdParamSchema, params);
|
|
620
|
+
const body = await req.json();
|
|
621
|
+
const result = await client.threads.updateState(thread_id, camelcaseKeys(body));
|
|
622
|
+
return jsonResponse(result);
|
|
623
|
+
} catch (error) {
|
|
624
|
+
return errorResponse(error);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
async function getThreadStateAtCheckpoint(req, context) {
|
|
628
|
+
try {
|
|
629
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/state/checkpoint");
|
|
630
|
+
const { thread_id } = validate(ThreadIdParamSchema, params);
|
|
631
|
+
const body = await req.json();
|
|
632
|
+
const queryParams = parseQueryParams(req.url);
|
|
633
|
+
const options = {
|
|
634
|
+
subgraphs: queryParams.subgraphs === "true" || queryParams.subgraphs === true,
|
|
635
|
+
...body
|
|
636
|
+
};
|
|
637
|
+
const state = await client.threads.getState(thread_id, options);
|
|
638
|
+
return jsonResponse(state);
|
|
639
|
+
} catch (error) {
|
|
640
|
+
return errorResponse(error);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
async function getThreadHistory(req, context) {
|
|
644
|
+
try {
|
|
645
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/history");
|
|
646
|
+
const { thread_id } = validate(ThreadIdParamSchema, params);
|
|
647
|
+
const queryParams = parseQueryParams(req.url);
|
|
648
|
+
const options = {
|
|
649
|
+
limit: queryParams.limit ? parseInt(queryParams.limit, 10) : void 0,
|
|
650
|
+
before: queryParams.before
|
|
651
|
+
};
|
|
652
|
+
const history = await client.threads.getStateHistory(thread_id, options);
|
|
653
|
+
return jsonResponse(history);
|
|
654
|
+
} catch (error) {
|
|
655
|
+
return errorResponse(error);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
async function getThreadHistoryPost(req, context) {
|
|
659
|
+
try {
|
|
660
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/history");
|
|
661
|
+
const { thread_id } = validate(ThreadIdParamSchema, params);
|
|
662
|
+
const body = await req.json();
|
|
663
|
+
const options = {
|
|
664
|
+
limit: body.limit,
|
|
665
|
+
before: body.before
|
|
666
|
+
};
|
|
667
|
+
const history = await client.threads.getStateHistory(thread_id, options);
|
|
668
|
+
return jsonResponse(history);
|
|
669
|
+
} catch (error) {
|
|
670
|
+
return errorResponse(error);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
async function copyThread(req, context) {
|
|
674
|
+
try {
|
|
675
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/copy");
|
|
676
|
+
const { thread_id } = validate(ThreadIdParamSchema, params);
|
|
677
|
+
const copiedThread = await client.threads.copy(thread_id);
|
|
678
|
+
return jsonResponse(copiedThread);
|
|
679
|
+
} catch (error) {
|
|
680
|
+
return errorResponse(error);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
async function joinThreadStream(req, context) {
|
|
684
|
+
try {
|
|
685
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/stream");
|
|
686
|
+
const { thread_id } = validate(ThreadIdParamSchema, params);
|
|
687
|
+
const queryParams = parseQueryParams(req.url);
|
|
688
|
+
const options = {
|
|
689
|
+
lastEventId: req.headers.get("Last-Event-ID") || queryParams.last_event_id,
|
|
690
|
+
streamModes: queryParams.stream_modes ? Array.isArray(queryParams.stream_modes) ? queryParams.stream_modes : [queryParams.stream_modes] : void 0
|
|
691
|
+
};
|
|
692
|
+
return new Response('data: {"status": "stream_ready"}\n\n', {
|
|
693
|
+
headers: {
|
|
694
|
+
"Content-Type": "text/event-stream",
|
|
695
|
+
"Cache-Control": "no-cache",
|
|
696
|
+
"Connection": "keep-alive"
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
} catch (error) {
|
|
700
|
+
return errorResponse(error);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
366
703
|
|
|
367
704
|
async function streamRun(req, context) {
|
|
368
705
|
try {
|
|
@@ -463,14 +800,367 @@ async function cancelRun(req, context) {
|
|
|
463
800
|
return errorResponse(error);
|
|
464
801
|
}
|
|
465
802
|
}
|
|
466
|
-
|
|
803
|
+
|
|
804
|
+
async function createRun(req, context) {
|
|
805
|
+
try {
|
|
806
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/runs");
|
|
807
|
+
const { thread_id } = validate(ThreadIdParamSchema, params);
|
|
808
|
+
const body = await req.json();
|
|
809
|
+
const payload = validate(RunCreateSchema, body);
|
|
810
|
+
const camelPayload = camelcaseKeys(payload);
|
|
811
|
+
camelPayload.config = camelPayload.config || {};
|
|
812
|
+
camelPayload.config.configurable = camelPayload.config.configurable || {};
|
|
813
|
+
const langgraphContext = context?.langgraph_context;
|
|
814
|
+
if (langgraphContext) {
|
|
815
|
+
Object.assign(camelPayload.config.configurable, langgraphContext);
|
|
816
|
+
}
|
|
817
|
+
camelPayload.config.configurable.graph_id = payload.assistant_id;
|
|
818
|
+
camelPayload.config.configurable.thread_id = thread_id;
|
|
819
|
+
const threads = client.threads;
|
|
820
|
+
const run = await threads.createRun(thread_id, payload.assistant_id, camelPayload);
|
|
821
|
+
(async () => {
|
|
822
|
+
try {
|
|
823
|
+
for await (const _ of streamState(threads, run, camelPayload, {
|
|
824
|
+
attempt: 0,
|
|
825
|
+
getGraph
|
|
826
|
+
})) {
|
|
827
|
+
}
|
|
828
|
+
} catch (error) {
|
|
829
|
+
console.error("Background run error:", error);
|
|
830
|
+
}
|
|
831
|
+
})();
|
|
832
|
+
return jsonResponse(run, 200, {
|
|
833
|
+
"Content-Location": `/threads/${thread_id}/runs/${run.run_id}`
|
|
834
|
+
});
|
|
835
|
+
} catch (error) {
|
|
836
|
+
return errorResponse(error);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
async function waitRun(req, context) {
|
|
840
|
+
try {
|
|
841
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/runs/wait");
|
|
842
|
+
const { thread_id } = validate(ThreadIdParamSchema, params);
|
|
843
|
+
const body = await req.json();
|
|
844
|
+
const payload = validate(RunCreateSchema, body);
|
|
845
|
+
const queryParams = parseQueryParams(req.url);
|
|
846
|
+
const { cancel_on_disconnect } = validate(RunWaitQuerySchema, queryParams);
|
|
847
|
+
const camelPayload = camelcaseKeys(payload);
|
|
848
|
+
camelPayload.config = camelPayload.config || {};
|
|
849
|
+
camelPayload.config.configurable = camelPayload.config.configurable || {};
|
|
850
|
+
const langgraphContext = context?.langgraph_context;
|
|
851
|
+
if (langgraphContext) {
|
|
852
|
+
Object.assign(camelPayload.config.configurable, langgraphContext);
|
|
853
|
+
}
|
|
854
|
+
camelPayload.config.configurable.graph_id = payload.assistant_id;
|
|
855
|
+
camelPayload.config.configurable.thread_id = thread_id;
|
|
856
|
+
const threads = client.threads;
|
|
857
|
+
const run = await threads.createRun(thread_id, payload.assistant_id, camelPayload);
|
|
858
|
+
const stateValues = {};
|
|
859
|
+
for await (const { event, data } of streamState(threads, run, camelPayload, {
|
|
860
|
+
attempt: 0,
|
|
861
|
+
getGraph
|
|
862
|
+
})) {
|
|
863
|
+
if (event === "end" || event === "writes/value") {
|
|
864
|
+
if (data && typeof data === "object") {
|
|
865
|
+
Object.assign(stateValues, data);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return jsonResponse(stateValues, 200, {
|
|
870
|
+
"Content-Location": `/threads/${thread_id}/runs/${run.run_id}`
|
|
871
|
+
});
|
|
872
|
+
} catch (error) {
|
|
873
|
+
return errorResponse(error);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
async function getRun(req, context) {
|
|
877
|
+
try {
|
|
878
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/runs/:run_id");
|
|
879
|
+
const { thread_id, run_id } = validate(RunIdParamSchema, params);
|
|
880
|
+
const runs = await client.runs.list(thread_id, { limit: 1e3 });
|
|
881
|
+
const run = runs.find((r) => r.run_id === run_id);
|
|
882
|
+
if (!run) {
|
|
883
|
+
return errorResponse(new Error("Run not found"), 404);
|
|
884
|
+
}
|
|
885
|
+
return jsonResponse(run);
|
|
886
|
+
} catch (error) {
|
|
887
|
+
return errorResponse(error);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
async function deleteRun(req, context) {
|
|
891
|
+
try {
|
|
892
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/runs/:run_id");
|
|
893
|
+
const { thread_id, run_id } = validate(RunIdParamSchema, params);
|
|
894
|
+
await client.threads.updateRun(run_id, { status: "deleted" });
|
|
895
|
+
return new Response(null, { status: 204 });
|
|
896
|
+
} catch (error) {
|
|
897
|
+
return errorResponse(error);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
async function joinRun(req, context) {
|
|
901
|
+
try {
|
|
902
|
+
const params = parsePathParams(req.url, "/threads/:thread_id/runs/:run_id/join");
|
|
903
|
+
const { thread_id, run_id } = validate(RunIdParamSchema, params);
|
|
904
|
+
const queryParams = parseQueryParams(req.url);
|
|
905
|
+
const { cancel_on_disconnect } = validate(RunJoinQuerySchema, queryParams);
|
|
906
|
+
const runs = await client.runs.list(thread_id, { limit: 1e3 });
|
|
907
|
+
const run = runs.find((r) => r.run_id === run_id);
|
|
908
|
+
if (!run) {
|
|
909
|
+
return errorResponse(new Error("Run not found"), 404);
|
|
910
|
+
}
|
|
911
|
+
if (run.status === "success" || run.status === "error") {
|
|
912
|
+
return jsonResponse({});
|
|
913
|
+
}
|
|
914
|
+
const controller = new AbortController();
|
|
915
|
+
if (cancel_on_disconnect) {
|
|
916
|
+
const cleanup = () => {
|
|
917
|
+
controller.abort("Client disconnected");
|
|
918
|
+
};
|
|
919
|
+
req.signal?.addEventListener("abort", cleanup);
|
|
920
|
+
}
|
|
921
|
+
const stateValues = {};
|
|
922
|
+
for await (const { event, data } of client.runs.joinStream(thread_id, run_id, {
|
|
923
|
+
signal: controller.signal,
|
|
924
|
+
cancelOnDisconnect: cancel_on_disconnect
|
|
925
|
+
})) {
|
|
926
|
+
if (event.event === "end" || event.event === "writes/value") {
|
|
927
|
+
if (data && typeof data === "object") {
|
|
928
|
+
Object.assign(stateValues, data);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
return jsonResponse(stateValues);
|
|
933
|
+
} catch (error) {
|
|
934
|
+
return errorResponse(error);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
async function createStatelessRun(req, context) {
|
|
467
939
|
try {
|
|
468
|
-
const params = parsePathParams(req.url, "/threads/:thread_id/state");
|
|
469
|
-
const { thread_id } = validate(z.object({ thread_id: z.string().uuid() }), params);
|
|
470
940
|
const body = await req.json();
|
|
471
|
-
const payload = validate(
|
|
472
|
-
const
|
|
473
|
-
|
|
941
|
+
const payload = validate(RunCreateStatelessSchema, body);
|
|
942
|
+
const camelPayload = camelcaseKeys(payload);
|
|
943
|
+
camelPayload.config = camelPayload.config || {};
|
|
944
|
+
camelPayload.config.configurable = camelPayload.config.configurable || {};
|
|
945
|
+
const langgraphContext = context?.langgraph_context;
|
|
946
|
+
if (langgraphContext) {
|
|
947
|
+
Object.assign(camelPayload.config.configurable, langgraphContext);
|
|
948
|
+
}
|
|
949
|
+
const threads = client.threads;
|
|
950
|
+
const thread = await threads.create({
|
|
951
|
+
metadata: { ...camelPayload.metadata, temporary: true }
|
|
952
|
+
});
|
|
953
|
+
camelPayload.config.configurable.graph_id = payload.assistant_id;
|
|
954
|
+
camelPayload.config.configurable.thread_id = thread.thread_id;
|
|
955
|
+
camelPayload.temporary = true;
|
|
956
|
+
const run = await threads.createRun(thread.thread_id, payload.assistant_id, camelPayload);
|
|
957
|
+
(async () => {
|
|
958
|
+
try {
|
|
959
|
+
for await (const _ of streamState(threads, run, camelPayload, {
|
|
960
|
+
attempt: 0,
|
|
961
|
+
getGraph
|
|
962
|
+
})) {
|
|
963
|
+
}
|
|
964
|
+
} catch (error) {
|
|
965
|
+
console.error("Stateless run error:", error);
|
|
966
|
+
} finally {
|
|
967
|
+
try {
|
|
968
|
+
await threads.delete(thread.thread_id);
|
|
969
|
+
} catch (e) {
|
|
970
|
+
console.error("Error cleaning up temporary thread:", e);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
})();
|
|
974
|
+
return jsonResponse(run, 200, {
|
|
975
|
+
"Content-Location": `/threads/${thread.thread_id}/runs/${run.run_id}`
|
|
976
|
+
});
|
|
977
|
+
} catch (error) {
|
|
978
|
+
return errorResponse(error);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
async function streamStatelessRun(req, context) {
|
|
982
|
+
try {
|
|
983
|
+
const body = await req.json();
|
|
984
|
+
const payload = validate(RunCreateStatelessSchema, body);
|
|
985
|
+
const camelPayload = camelcaseKeys(payload);
|
|
986
|
+
camelPayload.config = camelPayload.config || {};
|
|
987
|
+
camelPayload.config.configurable = camelPayload.config.configurable || {};
|
|
988
|
+
const langgraphContext = context?.langgraph_context;
|
|
989
|
+
if (langgraphContext) {
|
|
990
|
+
Object.assign(camelPayload.config.configurable, langgraphContext);
|
|
991
|
+
}
|
|
992
|
+
const threads = client.threads;
|
|
993
|
+
const thread = await threads.create({
|
|
994
|
+
metadata: { ...camelPayload.metadata, temporary: true }
|
|
995
|
+
});
|
|
996
|
+
camelPayload.config.configurable.graph_id = payload.assistant_id;
|
|
997
|
+
camelPayload.config.configurable.thread_id = thread.thread_id;
|
|
998
|
+
camelPayload.temporary = true;
|
|
999
|
+
const run = await threads.createRun(thread.thread_id, payload.assistant_id, camelPayload);
|
|
1000
|
+
return createSSEStream(
|
|
1001
|
+
withHeartbeat(async (writer) => {
|
|
1002
|
+
try {
|
|
1003
|
+
for await (const event of streamState(threads, run, camelPayload, {
|
|
1004
|
+
attempt: 0,
|
|
1005
|
+
getGraph
|
|
1006
|
+
})) {
|
|
1007
|
+
await writer.writeSSE({ data: JSON.stringify(event), event: "data" });
|
|
1008
|
+
}
|
|
1009
|
+
} catch (error) {
|
|
1010
|
+
if (error instanceof Error && error.name !== "AbortError") {
|
|
1011
|
+
console.error("Stream error:", error);
|
|
1012
|
+
throw error;
|
|
1013
|
+
}
|
|
1014
|
+
} finally {
|
|
1015
|
+
try {
|
|
1016
|
+
await threads.delete(thread.thread_id);
|
|
1017
|
+
} catch (e) {
|
|
1018
|
+
console.error("Error cleaning up temporary thread:", e);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
})
|
|
1022
|
+
);
|
|
1023
|
+
} catch (error) {
|
|
1024
|
+
return errorResponse(error);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
async function waitStatelessRun(req, context) {
|
|
1028
|
+
try {
|
|
1029
|
+
const body = await req.json();
|
|
1030
|
+
const payload = validate(RunCreateStatelessSchema, body);
|
|
1031
|
+
const camelPayload = camelcaseKeys(payload);
|
|
1032
|
+
camelPayload.config = camelPayload.config || {};
|
|
1033
|
+
camelPayload.config.configurable = camelPayload.config.configurable || {};
|
|
1034
|
+
const langgraphContext = context?.langgraph_context;
|
|
1035
|
+
if (langgraphContext) {
|
|
1036
|
+
Object.assign(camelPayload.config.configurable, langgraphContext);
|
|
1037
|
+
}
|
|
1038
|
+
const threads = client.threads;
|
|
1039
|
+
const thread = await threads.create({
|
|
1040
|
+
metadata: { ...camelPayload.metadata, temporary: true }
|
|
1041
|
+
});
|
|
1042
|
+
camelPayload.config.configurable.graph_id = payload.assistant_id;
|
|
1043
|
+
camelPayload.config.configurable.thread_id = thread.thread_id;
|
|
1044
|
+
camelPayload.temporary = true;
|
|
1045
|
+
const run = await threads.createRun(thread.thread_id, payload.assistant_id, camelPayload);
|
|
1046
|
+
const stateValues = {};
|
|
1047
|
+
try {
|
|
1048
|
+
for await (const { event, data } of streamState(threads, run, camelPayload, {
|
|
1049
|
+
attempt: 0,
|
|
1050
|
+
getGraph
|
|
1051
|
+
})) {
|
|
1052
|
+
if (event === "end" || event === "writes/value") {
|
|
1053
|
+
if (data && typeof data === "object") {
|
|
1054
|
+
Object.assign(stateValues, data);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
} finally {
|
|
1059
|
+
try {
|
|
1060
|
+
await threads.delete(thread.thread_id);
|
|
1061
|
+
} catch (e) {
|
|
1062
|
+
console.error("Error cleaning up temporary thread:", e);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
return jsonResponse(stateValues, 200, {
|
|
1066
|
+
"Content-Location": `/threads/${thread.thread_id}/runs/${run.run_id}`
|
|
1067
|
+
});
|
|
1068
|
+
} catch (error) {
|
|
1069
|
+
return errorResponse(error);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
async function createBatchRuns(req, context) {
|
|
1073
|
+
try {
|
|
1074
|
+
const body = await req.json();
|
|
1075
|
+
const payloads = validate(RunBatchCreateSchema, body);
|
|
1076
|
+
const threads = client.threads;
|
|
1077
|
+
const results = [];
|
|
1078
|
+
const runPromises = payloads.map(async (payload) => {
|
|
1079
|
+
try {
|
|
1080
|
+
const camelPayload = camelcaseKeys(payload);
|
|
1081
|
+
camelPayload.config = camelPayload.config || {};
|
|
1082
|
+
camelPayload.config.configurable = camelPayload.config.configurable || {};
|
|
1083
|
+
const langgraphContext = context?.langgraph_context;
|
|
1084
|
+
if (langgraphContext) {
|
|
1085
|
+
Object.assign(camelPayload.config.configurable, langgraphContext);
|
|
1086
|
+
}
|
|
1087
|
+
const thread = await threads.create({
|
|
1088
|
+
metadata: { ...camelPayload.metadata, temporary: true }
|
|
1089
|
+
});
|
|
1090
|
+
camelPayload.config.configurable.graph_id = payload.assistant_id;
|
|
1091
|
+
camelPayload.config.configurable.thread_id = thread.thread_id;
|
|
1092
|
+
camelPayload.temporary = true;
|
|
1093
|
+
const run = await threads.createRun(thread.thread_id, payload.assistant_id, camelPayload);
|
|
1094
|
+
(async () => {
|
|
1095
|
+
try {
|
|
1096
|
+
for await (const _ of streamState(threads, run, camelPayload, {
|
|
1097
|
+
attempt: 0,
|
|
1098
|
+
getGraph
|
|
1099
|
+
})) {
|
|
1100
|
+
}
|
|
1101
|
+
} catch (error) {
|
|
1102
|
+
console.error("Batch run error:", error);
|
|
1103
|
+
} finally {
|
|
1104
|
+
try {
|
|
1105
|
+
await threads.delete(thread.thread_id);
|
|
1106
|
+
} catch (e) {
|
|
1107
|
+
console.error("Error cleaning up temporary thread:", e);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
})();
|
|
1111
|
+
return { thread_id: thread.thread_id, run_id: run.run_id };
|
|
1112
|
+
} catch (error) {
|
|
1113
|
+
console.error("Batch run creation error:", error);
|
|
1114
|
+
return { error: (error instanceof Error ? error.message : "Unknown error") || "Unknown error" };
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
const runResults = await Promise.all(runPromises);
|
|
1118
|
+
results.push(...runResults);
|
|
1119
|
+
return jsonResponse(results, 200);
|
|
1120
|
+
} catch (error) {
|
|
1121
|
+
return errorResponse(error);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
async function cancelRuns(req, context) {
|
|
1125
|
+
try {
|
|
1126
|
+
const body = await req.json();
|
|
1127
|
+
const payload = validate(RunsCancelSchema, body);
|
|
1128
|
+
const url = new URL(req.url);
|
|
1129
|
+
const queryParams = validate(RunsCancelQuerySchema, {
|
|
1130
|
+
action: url.searchParams.get("action") || "interrupt"
|
|
1131
|
+
});
|
|
1132
|
+
const threads = client.threads;
|
|
1133
|
+
let cancelledRuns = [];
|
|
1134
|
+
if ("run_ids" in payload && payload.run_ids) {
|
|
1135
|
+
for (const runId of payload.run_ids) {
|
|
1136
|
+
try {
|
|
1137
|
+
console.warn(`Cancel by run_id ${runId} not fully implemented yet`);
|
|
1138
|
+
} catch (error) {
|
|
1139
|
+
console.error(`Error cancelling run ${runId}:`, error);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
} else if ("thread_id" in payload && payload.thread_id) {
|
|
1143
|
+
const threadId = payload.thread_id;
|
|
1144
|
+
try {
|
|
1145
|
+
const runs = await threads.listRuns(threadId, {
|
|
1146
|
+
limit: 1e3,
|
|
1147
|
+
offset: 0
|
|
1148
|
+
});
|
|
1149
|
+
for (const run of runs) {
|
|
1150
|
+
try {
|
|
1151
|
+
client.runs.cancel(threadId, run.run_id, queryParams.wait, queryParams.action);
|
|
1152
|
+
cancelledRuns.push(run.run_id);
|
|
1153
|
+
} catch (error) {
|
|
1154
|
+
console.error(`Error cancelling run ${run.run_id}:`, error);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
} catch (error) {
|
|
1158
|
+
console.error(`Error listing runs for thread ${threadId}:`, error);
|
|
1159
|
+
}
|
|
1160
|
+
} else if ("status" in payload && payload.status) {
|
|
1161
|
+
console.warn(`Cancel by status ${payload.status} not fully implemented yet`);
|
|
1162
|
+
}
|
|
1163
|
+
return new Response(null, { status: 204 });
|
|
474
1164
|
} catch (error) {
|
|
475
1165
|
return errorResponse(error);
|
|
476
1166
|
}
|
|
@@ -483,11 +1173,61 @@ const routes = [
|
|
|
483
1173
|
pattern: /^\/assistants\/search$/,
|
|
484
1174
|
handler: searchAssistants
|
|
485
1175
|
},
|
|
1176
|
+
{
|
|
1177
|
+
method: "POST",
|
|
1178
|
+
pattern: /^\/assistants\/count$/,
|
|
1179
|
+
handler: countAssistants
|
|
1180
|
+
},
|
|
1181
|
+
{
|
|
1182
|
+
method: "GET",
|
|
1183
|
+
pattern: /^\/assistants\/[^/]+$/,
|
|
1184
|
+
handler: getAssistant
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
method: "DELETE",
|
|
1188
|
+
pattern: /^\/assistants\/[^/]+$/,
|
|
1189
|
+
handler: deleteAssistant
|
|
1190
|
+
},
|
|
1191
|
+
{
|
|
1192
|
+
method: "PATCH",
|
|
1193
|
+
pattern: /^\/assistants\/[^/]+$/,
|
|
1194
|
+
handler: patchAssistant
|
|
1195
|
+
},
|
|
486
1196
|
{
|
|
487
1197
|
method: "GET",
|
|
488
1198
|
pattern: /^\/assistants\/[^/]+\/graph$/,
|
|
489
1199
|
handler: getAssistantGraph
|
|
490
1200
|
},
|
|
1201
|
+
{
|
|
1202
|
+
method: "GET",
|
|
1203
|
+
pattern: /^\/assistants\/[^/]+\/subgraphs$/,
|
|
1204
|
+
handler: getAssistantSubgraphs
|
|
1205
|
+
},
|
|
1206
|
+
{
|
|
1207
|
+
method: "GET",
|
|
1208
|
+
pattern: /^\/assistants\/[^/]+\/subgraphs\/[^/]+$/,
|
|
1209
|
+
handler: getAssistantSubgraphsByNamespace
|
|
1210
|
+
},
|
|
1211
|
+
{
|
|
1212
|
+
method: "GET",
|
|
1213
|
+
pattern: /^\/assistants\/[^/]+\/schemas$/,
|
|
1214
|
+
handler: getAssistantSchemas
|
|
1215
|
+
},
|
|
1216
|
+
{
|
|
1217
|
+
method: "POST",
|
|
1218
|
+
pattern: /^\/assistants\/[^/]+\/versions$/,
|
|
1219
|
+
handler: getAssistantVersions
|
|
1220
|
+
},
|
|
1221
|
+
{
|
|
1222
|
+
method: "POST",
|
|
1223
|
+
pattern: /^\/assistants\/[^/]+\/latest$/,
|
|
1224
|
+
handler: setLatestAssistantVersion
|
|
1225
|
+
},
|
|
1226
|
+
{
|
|
1227
|
+
method: "POST",
|
|
1228
|
+
pattern: /^\/assistants$/,
|
|
1229
|
+
handler: createAssistant
|
|
1230
|
+
},
|
|
491
1231
|
// Threads
|
|
492
1232
|
{
|
|
493
1233
|
method: "POST",
|
|
@@ -499,41 +1239,134 @@ const routes = [
|
|
|
499
1239
|
pattern: /^\/threads\/search$/,
|
|
500
1240
|
handler: searchThreads
|
|
501
1241
|
},
|
|
1242
|
+
{
|
|
1243
|
+
method: "POST",
|
|
1244
|
+
pattern: /^\/threads\/count$/,
|
|
1245
|
+
handler: countThreads
|
|
1246
|
+
},
|
|
502
1247
|
{
|
|
503
1248
|
method: "GET",
|
|
504
1249
|
pattern: /^\/threads\/[^/]+$/,
|
|
505
1250
|
handler: getThread
|
|
506
1251
|
},
|
|
1252
|
+
{
|
|
1253
|
+
method: "PATCH",
|
|
1254
|
+
pattern: /^\/threads\/[^/]+$/,
|
|
1255
|
+
handler: patchThread
|
|
1256
|
+
},
|
|
507
1257
|
{
|
|
508
1258
|
method: "DELETE",
|
|
509
1259
|
pattern: /^\/threads\/[^/]+$/,
|
|
510
1260
|
handler: deleteThread
|
|
511
1261
|
},
|
|
1262
|
+
{
|
|
1263
|
+
method: "GET",
|
|
1264
|
+
pattern: /^\/threads\/[^/]+\/state$/,
|
|
1265
|
+
handler: getThreadState
|
|
1266
|
+
},
|
|
1267
|
+
{
|
|
1268
|
+
method: "POST",
|
|
1269
|
+
pattern: /^\/threads\/[^/]+\/state$/,
|
|
1270
|
+
handler: updateThreadState
|
|
1271
|
+
},
|
|
1272
|
+
{
|
|
1273
|
+
method: "POST",
|
|
1274
|
+
pattern: /^\/threads\/[^/]+\/state\/checkpoint$/,
|
|
1275
|
+
handler: getThreadStateAtCheckpoint
|
|
1276
|
+
},
|
|
1277
|
+
{
|
|
1278
|
+
method: "GET",
|
|
1279
|
+
pattern: /^\/threads\/[^/]+\/history$/,
|
|
1280
|
+
handler: getThreadHistory
|
|
1281
|
+
},
|
|
1282
|
+
{
|
|
1283
|
+
method: "POST",
|
|
1284
|
+
pattern: /^\/threads\/[^/]+\/history$/,
|
|
1285
|
+
handler: getThreadHistoryPost
|
|
1286
|
+
},
|
|
1287
|
+
{
|
|
1288
|
+
method: "POST",
|
|
1289
|
+
pattern: /^\/threads\/[^/]+\/copy$/,
|
|
1290
|
+
handler: copyThread
|
|
1291
|
+
},
|
|
1292
|
+
{
|
|
1293
|
+
method: "GET",
|
|
1294
|
+
pattern: /^\/threads\/[^/]+\/stream$/,
|
|
1295
|
+
handler: joinThreadStream
|
|
1296
|
+
},
|
|
512
1297
|
// Runs
|
|
1298
|
+
// POST requests must come before GET requests with same path prefix
|
|
1299
|
+
{
|
|
1300
|
+
method: "POST",
|
|
1301
|
+
pattern: /^\/threads\/[^/]+\/runs$/,
|
|
1302
|
+
handler: createRun
|
|
1303
|
+
},
|
|
513
1304
|
{
|
|
514
1305
|
method: "POST",
|
|
515
1306
|
pattern: /^\/threads\/[^/]+\/runs\/stream$/,
|
|
516
1307
|
handler: streamRun
|
|
517
1308
|
},
|
|
518
1309
|
{
|
|
519
|
-
method: "
|
|
520
|
-
pattern: /^\/threads\/[^/]+\/runs\/
|
|
521
|
-
handler:
|
|
1310
|
+
method: "POST",
|
|
1311
|
+
pattern: /^\/threads\/[^/]+\/runs\/wait$/,
|
|
1312
|
+
handler: waitRun
|
|
1313
|
+
},
|
|
1314
|
+
{
|
|
1315
|
+
method: "POST",
|
|
1316
|
+
pattern: /^\/threads\/[^/]+\/runs\/[^/]+\/cancel$/,
|
|
1317
|
+
handler: cancelRun
|
|
522
1318
|
},
|
|
1319
|
+
// GET requests
|
|
523
1320
|
{
|
|
524
1321
|
method: "GET",
|
|
525
1322
|
pattern: /^\/threads\/[^/]+\/runs$/,
|
|
526
1323
|
handler: listRuns
|
|
527
1324
|
},
|
|
1325
|
+
{
|
|
1326
|
+
method: "GET",
|
|
1327
|
+
pattern: /^\/threads\/[^/]+\/runs\/[^/]+$/,
|
|
1328
|
+
handler: getRun
|
|
1329
|
+
},
|
|
1330
|
+
{
|
|
1331
|
+
method: "DELETE",
|
|
1332
|
+
pattern: /^\/threads\/[^/]+\/runs\/[^/]+$/,
|
|
1333
|
+
handler: deleteRun
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
method: "GET",
|
|
1337
|
+
pattern: /^\/threads\/[^/]+\/runs\/[^/]+\/join$/,
|
|
1338
|
+
handler: joinRun
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
method: "GET",
|
|
1342
|
+
pattern: /^\/threads\/[^/]+\/runs\/[^/]+\/stream$/,
|
|
1343
|
+
handler: joinRunStream
|
|
1344
|
+
},
|
|
1345
|
+
// Stateless Runs
|
|
528
1346
|
{
|
|
529
1347
|
method: "POST",
|
|
530
|
-
pattern: /^\/
|
|
531
|
-
handler:
|
|
1348
|
+
pattern: /^\/runs$/,
|
|
1349
|
+
handler: createStatelessRun
|
|
532
1350
|
},
|
|
533
1351
|
{
|
|
534
1352
|
method: "POST",
|
|
535
|
-
pattern: /^\/
|
|
536
|
-
handler:
|
|
1353
|
+
pattern: /^\/runs\/stream$/,
|
|
1354
|
+
handler: streamStatelessRun
|
|
1355
|
+
},
|
|
1356
|
+
{
|
|
1357
|
+
method: "POST",
|
|
1358
|
+
pattern: /^\/runs\/wait$/,
|
|
1359
|
+
handler: waitStatelessRun
|
|
1360
|
+
},
|
|
1361
|
+
{
|
|
1362
|
+
method: "POST",
|
|
1363
|
+
pattern: /^\/runs\/batch$/,
|
|
1364
|
+
handler: createBatchRuns
|
|
1365
|
+
},
|
|
1366
|
+
{
|
|
1367
|
+
method: "POST",
|
|
1368
|
+
pattern: /^\/runs\/cancel$/,
|
|
1369
|
+
handler: cancelRuns
|
|
537
1370
|
}
|
|
538
1371
|
];
|
|
539
1372
|
const replaceRequest = (req) => {
|
|
@@ -570,5 +1403,5 @@ async function handleRequest(req, context = {}) {
|
|
|
570
1403
|
}
|
|
571
1404
|
}
|
|
572
1405
|
|
|
573
|
-
export { cancelRun, createThread, deleteThread, getAssistantGraph, getThread, handleRequest, joinRunStream, listRuns, searchAssistants, searchThreads, streamRun, updateThreadState };
|
|
1406
|
+
export { cancelRun, cancelRuns, copyThread, countAssistants, countThreads, createAssistant, createBatchRuns, createRun, createStatelessRun, createThread, deleteAssistant, deleteRun, deleteThread, getAssistant, getAssistantGraph, getAssistantSchemas, getAssistantSubgraphs, getAssistantSubgraphsByNamespace, getAssistantVersions, getRun, getThread, getThreadHistory, getThreadHistoryPost, getThreadState, getThreadStateAtCheckpoint, handleRequest, joinRun, joinRunStream, joinThreadStream, listRuns, patchAssistant, patchThread, searchAssistants, searchThreads, setLatestAssistantVersion, streamRun, streamStatelessRun, updateThreadState, waitRun, waitStatelessRun };
|
|
574
1407
|
//# sourceMappingURL=index.js.map
|