返回 CodeWhale
thread-events.types.ts
根目录 / npm / runtime-sdk / test / thread-events.types.ts
1 // Checked by npm test (or npm run test:types).
2 import { CodeWhaleRuntimeClient, isThreadStreamEnd } from '../index.js';
3 import type { ThreadRuntimeEvent, ThreadStreamEnd } from '../index.js';
4
5 async function checkThreadEvents(client: CodeWhaleRuntimeClient, includeProgress: boolean) {
6 for await (const item of client.threadEvents('thread')) {
7 if (isThreadStreamEnd(item)) {
8 const end: ThreadStreamEnd = item;
9 const cursor: number = item.last_seq;
10 const retryable: boolean = item.retryable;
11 if (retryable) client.threadEvents(end.thread_id, { sinceSeq: cursor });
12 } else {
13 const journal: ThreadRuntimeEvent = item;
14 journal.payload;
15 }
16 }
17 for await (const item of client.threadEvents('thread', { includeProgress: true })) {
18 if (isThreadStreamEnd(item)) {
19 const end: ThreadStreamEnd = item;
20 end.last_seq;
21 end.retryable;
22 } else {
23 const cursor: number = item.seq;
24 client.threadEvents(item.thread_id, { sinceSeq: cursor });
25 }
26 }
27 for await (const item of client.threadEvents('thread', { includeProgress })) {
28 if (isThreadStreamEnd(item)) {
29 const end: ThreadStreamEnd = item;
30 end.last_seq;
31 end.retryable;
32 }
33 }
34 }
35
36 // Future journal names must remain accepted without closing the protocol union.
37 const future: ThreadRuntimeEvent = {
38 event: 'future.journal.event', seq: 1, thread_id: 'thread', timestamp: '', payload: {},
39 };
40 isThreadStreamEnd(future);
41 void checkThreadEvents;
42
42 lines TYPESCRIPT