mirror of
https://github.com/langchain-ai/langgraphjs-api.git
synced 2026-07-19 13:25:54 -04:00
Use updated (not-released) client
This commit is contained in:
@@ -2597,35 +2597,34 @@ it("resumable streams", { timeout: 10_000 }, async () => {
|
||||
const assistant = await client.assistants.create({ graphId: "agent" });
|
||||
const thread = await client.threads.create();
|
||||
|
||||
const [monitor, stream] = ReadableStream.from(
|
||||
client.runs.stream(thread.thread_id, assistant.assistant_id, {
|
||||
input: {
|
||||
messages: [{ role: "human", content: "input" }],
|
||||
sleep: { steps: 3, ms: 1000 },
|
||||
},
|
||||
streamMode: ["values", "custom"],
|
||||
config: globalConfig,
|
||||
}),
|
||||
).tee();
|
||||
type RunMetadata = { run_id: string; thread_id?: string };
|
||||
|
||||
const metadata = await new Promise<{ run_id: string; thread_id: string }>(
|
||||
async (resolve, reject) => {
|
||||
for await (const chunk of monitor)
|
||||
if (chunk.event === "metadata") resolve(chunk.data);
|
||||
setTimeout(() => reject(new Error("Timeout waiting for metadata")), 1000);
|
||||
let onRunCreated: ((params: RunMetadata) => void) | undefined = undefined;
|
||||
const waitRun = new Promise<RunMetadata>((r) => (onRunCreated = r));
|
||||
|
||||
const stream = client.runs.stream(thread.thread_id, assistant.assistant_id, {
|
||||
input: {
|
||||
messages: [{ role: "human", content: "input" }],
|
||||
sleep: { steps: 3, ms: 1000 },
|
||||
},
|
||||
);
|
||||
streamMode: ["values", "custom"],
|
||||
config: globalConfig,
|
||||
|
||||
onRunCreated,
|
||||
});
|
||||
|
||||
const [join, source] = await Promise.all([
|
||||
new Promise((resolve) => setTimeout(resolve, 1500)).then(() =>
|
||||
gatherIterator(
|
||||
new Client<any>({
|
||||
apiUrl: API_URL,
|
||||
// TODO: expose the `lastEventId` option
|
||||
defaultHeaders: { "Last-Event-Id": "0" },
|
||||
}).runs.joinStream(thread.thread_id, metadata.run_id),
|
||||
),
|
||||
),
|
||||
(async () => {
|
||||
const [{ thread_id, run_id }] = await Promise.all([
|
||||
waitRun,
|
||||
new Promise((resolve) => setTimeout(resolve, 1500)),
|
||||
]);
|
||||
|
||||
return gatherIterator(
|
||||
client.runs.joinStream(thread_id, run_id, { lastEventId: "0" }),
|
||||
);
|
||||
})(),
|
||||
|
||||
gatherIterator(stream),
|
||||
]);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["ESNext"],
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
|
||||
Reference in New Issue
Block a user