@assistant-ui/core 0.1.2 → 0.1.3
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/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +2 -4
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +97 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +111 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +115 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +444 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts +18 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts.map +1 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.js +14 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.js.map +1 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +5 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +528 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +15 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +83 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts +62 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/auiV0.js +74 -0
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -0
- package/dist/react/runtimes/cloud/index.d.ts +4 -0
- package/dist/react/runtimes/cloud/index.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/index.js +4 -0
- package/dist/react/runtimes/cloud/index.js.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts +13 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +102 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -0
- package/dist/react/runtimes/createMessageConverter.d.ts +17 -0
- package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -0
- package/dist/react/runtimes/createMessageConverter.js +50 -0
- package/dist/react/runtimes/createMessageConverter.js.map +1 -0
- package/dist/react/runtimes/external-message-converter.d.ts +34 -0
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -0
- package/dist/react/runtimes/external-message-converter.js +309 -0
- package/dist/react/runtimes/external-message-converter.js.map +1 -0
- package/dist/react/runtimes/index.d.ts +10 -0
- package/dist/react/runtimes/index.d.ts.map +1 -0
- package/dist/react/runtimes/index.js +10 -0
- package/dist/react/runtimes/index.js.map +1 -0
- package/dist/react/runtimes/useExternalStoreRuntime.d.ts +4 -0
- package/dist/react/runtimes/useExternalStoreRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/useExternalStoreRuntime.js +19 -0
- package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts +4 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +48 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -0
- package/dist/react/runtimes/useToolInvocations.d.ts +38 -0
- package/dist/react/runtimes/useToolInvocations.d.ts.map +1 -0
- package/dist/react/runtimes/useToolInvocations.js +411 -0
- package/dist/react/runtimes/useToolInvocations.js.map +1 -0
- package/dist/react/types/store-augmentation.d.ts +0 -1
- package/dist/react/types/store-augmentation.d.ts.map +1 -1
- package/dist/react/types/store-augmentation.js +1 -1
- package/dist/react/types/store-augmentation.js.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +2 -0
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -2
- package/dist/store/index.js.map +1 -1
- package/dist/utils/json/is-json-equal.d.ts +2 -0
- package/dist/utils/json/is-json-equal.d.ts.map +1 -0
- package/dist/utils/json/is-json-equal.js +31 -0
- package/dist/utils/json/is-json-equal.js.map +1 -0
- package/dist/utils/json/is-json.d.ts +6 -0
- package/dist/utils/json/is-json.d.ts.map +1 -0
- package/dist/utils/json/is-json.js +33 -0
- package/dist/utils/json/is-json.js.map +1 -0
- package/package.json +10 -9
- package/src/model-context/frame/provider.ts +2 -6
- package/src/react/index.ts +2 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +176 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +534 -0
- package/src/react/runtimes/RuntimeAdapterProvider.tsx +40 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +785 -0
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +101 -0
- package/src/react/runtimes/cloud/auiV0.ts +160 -0
- package/src/react/runtimes/cloud/index.ts +3 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +152 -0
- package/src/react/runtimes/createMessageConverter.ts +77 -0
- package/src/react/runtimes/external-message-converter.ts +487 -0
- package/src/react/runtimes/index.ts +30 -0
- package/src/react/runtimes/useExternalStoreRuntime.ts +27 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +76 -0
- package/src/react/runtimes/useToolInvocations.ts +594 -0
- package/src/react/types/store-augmentation.ts +0 -2
- package/src/runtime/base/base-composer-runtime-core.ts +2 -0
- package/src/store/index.ts +1 -2
- package/src/utils/json/is-json-equal.ts +48 -0
- package/src/utils/json/is-json.ts +58 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function isRecord(value) {
|
|
2
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
export function isJSONValue(value, currentDepth = 0) {
|
|
5
|
+
// Protect against too deep recursion
|
|
6
|
+
if (currentDepth > 100) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (value === null ||
|
|
10
|
+
typeof value === "string" ||
|
|
11
|
+
typeof value === "boolean") {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
// Handle special number cases
|
|
15
|
+
if (typeof value === "number") {
|
|
16
|
+
return !Number.isNaN(value) && Number.isFinite(value);
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
return value.every((item) => isJSONValue(item, currentDepth + 1));
|
|
20
|
+
}
|
|
21
|
+
if (isRecord(value)) {
|
|
22
|
+
return Object.entries(value).every(([key, val]) => typeof key === "string" && isJSONValue(val, currentDepth + 1));
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
export function isJSONArray(value) {
|
|
27
|
+
return Array.isArray(value) && value.every(isJSONValue);
|
|
28
|
+
}
|
|
29
|
+
export function isJSONObject(value) {
|
|
30
|
+
return (isRecord(value) &&
|
|
31
|
+
Object.entries(value).every(([key, val]) => typeof key === "string" && isJSONValue(val)));
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=is-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-json.js","sourceRoot":"","sources":["../../../src/utils/json/is-json.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,KAAc,EACd,eAAuB,CAAC;IAExB,qCAAqC;IACrC,IAAI,YAAY,GAAG,GAAG,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IACE,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,SAAS,EAC1B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8BAA8B;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAChC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CACb,OAAO,GAAG,KAAK,QAAQ,IAAI,WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,CAAC,CAAC,CAChE,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC;QACf,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CACzB,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,WAAW,CAAC,GAAG,CAAC,CAC5D,CACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Framework-agnostic core runtime for assistant-ui",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"assistant",
|
|
@@ -57,21 +57,21 @@
|
|
|
57
57
|
"nanoid": "^5.1.6"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@assistant-ui/store": "^0.2.
|
|
61
|
-
"@assistant-ui/tap": "^0.5.
|
|
60
|
+
"@assistant-ui/store": "^0.2.2",
|
|
61
|
+
"@assistant-ui/tap": "^0.5.2",
|
|
62
62
|
"@types/react": "*",
|
|
63
63
|
"react": "^18 || ^19",
|
|
64
|
-
"
|
|
64
|
+
"assistant-cloud": "^0.1.21",
|
|
65
65
|
"zustand": "^5.0.11"
|
|
66
66
|
},
|
|
67
67
|
"peerDependenciesMeta": {
|
|
68
68
|
"@types/react": {
|
|
69
69
|
"optional": true
|
|
70
70
|
},
|
|
71
|
-
"
|
|
71
|
+
"assistant-cloud": {
|
|
72
72
|
"optional": true
|
|
73
73
|
},
|
|
74
|
-
"
|
|
74
|
+
"react": {
|
|
75
75
|
"optional": true
|
|
76
76
|
},
|
|
77
77
|
"zustand": {
|
|
@@ -83,9 +83,10 @@
|
|
|
83
83
|
"react": "^19.2.4",
|
|
84
84
|
"vitest": "^4.0.18",
|
|
85
85
|
"zustand": "^5.0.11",
|
|
86
|
-
"
|
|
87
|
-
"@assistant-ui/
|
|
88
|
-
"@assistant-ui/
|
|
86
|
+
"assistant-cloud": "0.1.21",
|
|
87
|
+
"@assistant-ui/store": "0.2.2",
|
|
88
|
+
"@assistant-ui/tap": "0.5.2",
|
|
89
|
+
"@assistant-ui/x-buildutils": "0.0.2"
|
|
89
90
|
},
|
|
90
91
|
"publishConfig": {
|
|
91
92
|
"access": "public",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ModelContextProvider, ModelContext } from "../types";
|
|
2
2
|
import type { Unsubscribe } from "../../types";
|
|
3
|
-
import { Tool } from "assistant-stream";
|
|
4
|
-
import { z } from "zod";
|
|
3
|
+
import { Tool, toJSONSchema } from "assistant-stream";
|
|
5
4
|
import {
|
|
6
5
|
FrameMessage,
|
|
7
6
|
FRAME_MESSAGE_CHANNEL,
|
|
@@ -11,10 +10,7 @@ import {
|
|
|
11
10
|
|
|
12
11
|
const serializeTool = (tool: Tool<any, any>): SerializedTool => ({
|
|
13
12
|
...(tool.description && { description: tool.description }),
|
|
14
|
-
parameters:
|
|
15
|
-
tool.parameters instanceof z.ZodType
|
|
16
|
-
? ((z as any).toJSONSchema?.(tool.parameters) ?? tool.parameters)
|
|
17
|
-
: tool.parameters,
|
|
13
|
+
parameters: tool.parameters ? toJSONSchema(tool.parameters) : undefined,
|
|
18
14
|
...(tool.disabled !== undefined && { disabled: tool.disabled }),
|
|
19
15
|
...(tool.type && { type: tool.type }),
|
|
20
16
|
});
|
package/src/react/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference path="./types/store-augmentation.ts" />
|
|
2
2
|
|
|
3
3
|
export * from "./model-context";
|
|
4
4
|
export * from "./client";
|
|
5
5
|
export * from "./types";
|
|
6
6
|
export * from "./providers";
|
|
7
7
|
export { RuntimeAdapter } from "./RuntimeAdapter";
|
|
8
|
+
export * from "./runtimes";
|
|
8
9
|
|
|
9
10
|
// AssistantProvider base
|
|
10
11
|
export {
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FC,
|
|
3
|
+
useCallback,
|
|
4
|
+
useRef,
|
|
5
|
+
useEffect,
|
|
6
|
+
memo,
|
|
7
|
+
PropsWithChildren,
|
|
8
|
+
ComponentType,
|
|
9
|
+
useMemo,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { UseBoundStore, StoreApi, create } from "zustand";
|
|
12
|
+
import { useAui } from "@assistant-ui/store";
|
|
13
|
+
import { ThreadListItemRuntimeProvider } from "../providers/ThreadListItemRuntimeProvider";
|
|
14
|
+
import type { ThreadRuntimeCore } from "../../runtime/interfaces/thread-runtime-core";
|
|
15
|
+
import type { ThreadListRuntimeCore } from "../../runtime/interfaces/thread-list-runtime-core";
|
|
16
|
+
import type { AssistantRuntime } from "../../runtime/api/assistant-runtime";
|
|
17
|
+
import { BaseSubscribable } from "../../subscribable";
|
|
18
|
+
import { ThreadRuntimeImpl } from "../../runtime/api/thread-runtime";
|
|
19
|
+
import { ThreadListRuntimeImpl } from "../../runtime/api/thread-list-runtime";
|
|
20
|
+
|
|
21
|
+
type RemoteThreadListHook = () => AssistantRuntime;
|
|
22
|
+
|
|
23
|
+
type RemoteThreadListHookInstance = {
|
|
24
|
+
runtime?: ThreadRuntimeCore;
|
|
25
|
+
};
|
|
26
|
+
export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
27
|
+
private useRuntimeHook: UseBoundStore<
|
|
28
|
+
StoreApi<{ useRuntime: RemoteThreadListHook }>
|
|
29
|
+
>;
|
|
30
|
+
private instances = new Map<string, RemoteThreadListHookInstance>();
|
|
31
|
+
private useAliveThreadsKeysChanged = create(() => ({}));
|
|
32
|
+
private parent: ThreadListRuntimeCore;
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
runtimeHook: RemoteThreadListHook,
|
|
36
|
+
parent: ThreadListRuntimeCore,
|
|
37
|
+
) {
|
|
38
|
+
super();
|
|
39
|
+
this.parent = parent;
|
|
40
|
+
this.useRuntimeHook = create(() => ({ useRuntime: runtimeHook }));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public startThreadRuntime(threadId: string) {
|
|
44
|
+
if (!this.instances.has(threadId)) {
|
|
45
|
+
this.instances.set(threadId, {});
|
|
46
|
+
this.useAliveThreadsKeysChanged.setState({}, true);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return new Promise<ThreadRuntimeCore>((resolve, reject) => {
|
|
50
|
+
const callback = () => {
|
|
51
|
+
const instance = this.instances.get(threadId);
|
|
52
|
+
if (!instance) {
|
|
53
|
+
dispose();
|
|
54
|
+
reject(new Error("Thread was deleted before runtime was started"));
|
|
55
|
+
} else if (!instance.runtime) {
|
|
56
|
+
return; // misc update
|
|
57
|
+
} else {
|
|
58
|
+
dispose();
|
|
59
|
+
resolve(instance.runtime);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const dispose = this.subscribe(callback);
|
|
63
|
+
callback();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public getThreadRuntimeCore(threadId: string) {
|
|
68
|
+
const instance = this.instances.get(threadId);
|
|
69
|
+
if (!instance) return undefined;
|
|
70
|
+
return instance.runtime;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public stopThreadRuntime(threadId: string) {
|
|
74
|
+
this.instances.delete(threadId);
|
|
75
|
+
this.useAliveThreadsKeysChanged.setState({}, true);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public setRuntimeHook(newRuntimeHook: RemoteThreadListHook) {
|
|
79
|
+
const prevRuntimeHook = this.useRuntimeHook.getState().useRuntime;
|
|
80
|
+
if (prevRuntimeHook !== newRuntimeHook) {
|
|
81
|
+
this.useRuntimeHook.setState({ useRuntime: newRuntimeHook }, true);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private _InnerActiveThreadProvider: FC<{
|
|
86
|
+
threadId: string;
|
|
87
|
+
}> = ({ threadId }) => {
|
|
88
|
+
const { useRuntime } = this.useRuntimeHook();
|
|
89
|
+
const runtime = useRuntime();
|
|
90
|
+
|
|
91
|
+
const threadBinding = (runtime.thread as ThreadRuntimeImpl)
|
|
92
|
+
.__internal_threadBinding;
|
|
93
|
+
|
|
94
|
+
const updateRuntime = useCallback(() => {
|
|
95
|
+
const aliveThread = this.instances.get(threadId);
|
|
96
|
+
if (!aliveThread)
|
|
97
|
+
throw new Error("Thread not found. This is a bug in assistant-ui.");
|
|
98
|
+
|
|
99
|
+
aliveThread.runtime = threadBinding.getState();
|
|
100
|
+
this._notifySubscribers();
|
|
101
|
+
}, [threadId, threadBinding]);
|
|
102
|
+
|
|
103
|
+
const isMounted = useRef(false);
|
|
104
|
+
if (!isMounted.current) {
|
|
105
|
+
updateRuntime();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
isMounted.current = true;
|
|
110
|
+
updateRuntime();
|
|
111
|
+
return threadBinding.outerSubscribe(updateRuntime);
|
|
112
|
+
}, [threadBinding, updateRuntime]);
|
|
113
|
+
|
|
114
|
+
const aui = useAui();
|
|
115
|
+
const initPromiseRef = useRef<Promise<unknown> | undefined>(undefined);
|
|
116
|
+
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
const runtimeCore = threadBinding.getState();
|
|
119
|
+
const setGetInitializePromise = (runtimeCore as Record<string, unknown>)[
|
|
120
|
+
"__internal_setGetInitializePromise"
|
|
121
|
+
];
|
|
122
|
+
if (typeof setGetInitializePromise === "function") {
|
|
123
|
+
setGetInitializePromise.call(runtimeCore, () => initPromiseRef.current);
|
|
124
|
+
}
|
|
125
|
+
}, [threadBinding]);
|
|
126
|
+
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
return runtime.threads.main.unstable_on("initialize", () => {
|
|
129
|
+
const state = aui.threadListItem().getState();
|
|
130
|
+
if (state.status === "new") {
|
|
131
|
+
initPromiseRef.current = aui.threadListItem().initialize();
|
|
132
|
+
|
|
133
|
+
const dispose = runtime.thread.unstable_on("runEnd", () => {
|
|
134
|
+
dispose();
|
|
135
|
+
|
|
136
|
+
aui.threadListItem().generateTitle();
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}, [runtime, aui]);
|
|
141
|
+
|
|
142
|
+
return null;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
private _OuterActiveThreadProvider: FC<{
|
|
146
|
+
threadId: string;
|
|
147
|
+
provider: ComponentType<PropsWithChildren>;
|
|
148
|
+
}> = memo(({ threadId, provider: Provider }) => {
|
|
149
|
+
const runtime = useMemo(
|
|
150
|
+
() => new ThreadListRuntimeImpl(this.parent).getItemById(threadId),
|
|
151
|
+
[threadId],
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<ThreadListItemRuntimeProvider runtime={runtime}>
|
|
156
|
+
<Provider>
|
|
157
|
+
<this._InnerActiveThreadProvider threadId={threadId} />
|
|
158
|
+
</Provider>
|
|
159
|
+
</ThreadListItemRuntimeProvider>
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
public __internal_RenderThreadRuntimes: FC<{
|
|
164
|
+
provider: ComponentType<PropsWithChildren>;
|
|
165
|
+
}> = ({ provider }) => {
|
|
166
|
+
this.useAliveThreadsKeysChanged(); // trigger re-render on alive threads change
|
|
167
|
+
|
|
168
|
+
return Array.from(this.instances.keys()).map((threadId) => (
|
|
169
|
+
<this._OuterActiveThreadProvider
|
|
170
|
+
key={threadId}
|
|
171
|
+
threadId={threadId}
|
|
172
|
+
provider={provider}
|
|
173
|
+
/>
|
|
174
|
+
));
|
|
175
|
+
};
|
|
176
|
+
}
|