@assistant-ui/react 0.7.9 → 0.7.10
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/api/AssistantRuntime.d.ts +4 -5
- package/dist/api/AssistantRuntime.d.ts.map +1 -1
- package/dist/api/AssistantRuntime.js +16 -19
- package/dist/api/AssistantRuntime.js.map +1 -1
- package/dist/api/AssistantRuntime.mjs +16 -19
- package/dist/api/AssistantRuntime.mjs.map +1 -1
- package/dist/api/ThreadListItemRuntime.d.ts +11 -2
- package/dist/api/ThreadListItemRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListItemRuntime.js +16 -5
- package/dist/api/ThreadListItemRuntime.js.map +1 -1
- package/dist/api/ThreadListItemRuntime.mjs +16 -5
- package/dist/api/ThreadListItemRuntime.mjs.map +1 -1
- package/dist/api/ThreadListRuntime.d.ts +3 -0
- package/dist/api/ThreadListRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListRuntime.js +27 -8
- package/dist/api/ThreadListRuntime.js.map +1 -1
- package/dist/api/ThreadListRuntime.mjs +27 -8
- package/dist/api/ThreadListRuntime.mjs.map +1 -1
- package/dist/api/ThreadRuntime.d.ts +10 -7
- package/dist/api/ThreadRuntime.d.ts.map +1 -1
- package/dist/api/ThreadRuntime.js +16 -6
- package/dist/api/ThreadRuntime.js.map +1 -1
- package/dist/api/ThreadRuntime.mjs +16 -6
- package/dist/api/ThreadRuntime.mjs.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.js +8 -1
- package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.mjs +8 -1
- package/dist/context/providers/AssistantRuntimeProvider.mjs.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.d.ts +2 -0
- package/dist/context/providers/ThreadRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.js +3 -2
- package/dist/context/providers/ThreadRuntimeProvider.js.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.mjs +3 -2
- package/dist/context/providers/ThreadRuntimeProvider.mjs.map +1 -1
- package/dist/internal.d.ts +1 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +0 -3
- package/dist/internal.js.map +1 -1
- package/dist/internal.mjs +0 -2
- package/dist/internal.mjs.map +1 -1
- package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +3 -1
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.mjs +3 -1
- package/dist/primitives/composer/ComposerInput.mjs.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts +2 -4
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.js +1 -5
- package/dist/runtimes/core/BaseThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.mjs +1 -5
- package/dist/runtimes/core/BaseThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts +14 -6
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts +1 -15
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/index.d.ts +1 -1
- package/dist/runtimes/core/index.d.ts.map +1 -1
- package/dist/runtimes/core/index.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts +20 -3
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.d.ts +0 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js +3 -10
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.mjs +3 -10
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts +9 -11
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js +19 -27
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs +19 -27
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts +2 -2
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js +4 -7
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs +4 -7
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.d.ts +0 -1
- package/dist/runtimes/local/LocalRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.js +3 -12
- package/dist/runtimes/local/LocalRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.mjs +3 -12
- package/dist/runtimes/local/LocalRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts +17 -15
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js +94 -92
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs +94 -92
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts +4 -3
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.js +11 -10
- package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +11 -10
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.js +4 -7
- package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.mjs +4 -7
- package/dist/runtimes/local/useLocalRuntime.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/AssistantRuntime.ts +21 -25
- package/src/api/ThreadListItemRuntime.ts +36 -7
- package/src/api/ThreadListRuntime.ts +31 -9
- package/src/api/ThreadRuntime.ts +38 -10
- package/src/context/providers/AssistantRuntimeProvider.tsx +4 -1
- package/src/context/providers/ThreadRuntimeProvider.tsx +9 -2
- package/src/internal.ts +1 -1
- package/src/primitives/composer/ComposerInput.tsx +3 -1
- package/src/runtimes/core/BaseThreadRuntimeCore.tsx +1 -9
- package/src/runtimes/core/ThreadListRuntimeCore.tsx +16 -7
- package/src/runtimes/core/ThreadRuntimeCore.tsx +1 -19
- package/src/runtimes/core/index.ts +0 -1
- package/src/runtimes/external-store/ExternalStoreAdapter.tsx +20 -3
- package/src/runtimes/external-store/ExternalStoreRuntimeCore.tsx +5 -12
- package/src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx +22 -35
- package/src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx +3 -7
- package/src/runtimes/local/LocalRuntimeCore.tsx +7 -14
- package/src/runtimes/local/LocalThreadListRuntimeCore.tsx +110 -103
- package/src/runtimes/local/LocalThreadRuntimeCore.tsx +11 -10
- package/src/runtimes/local/useLocalRuntime.tsx +5 -12
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.d.ts +0 -19
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.d.ts.map +0 -1
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.js +0 -87
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.js.map +0 -1
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.mjs +0 -62
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.mjs.map +0 -1
- package/src/runtimes/local/LocalThreadMetadataRuntimeCore.tsx +0 -79
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalRuntimeCore.tsx"],"sourcesContent":["import type { CoreMessage } from \"../../types/AssistantTypes\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { LocalThreadRuntimeCore } from \"./LocalThreadRuntimeCore\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport { fromCoreMessages } from \"../edge/converters/fromCoreMessage\";\nimport { LocalThreadListRuntimeCore } from \"./LocalThreadListRuntimeCore\";\nimport { ExportedMessageRepository } from \"../utils/MessageRepository\";\n\nconst getExportFromInitialMessages = (\n initialMessages: readonly CoreMessage[],\n): ExportedMessageRepository => {\n const messages = fromCoreMessages(initialMessages);\n return {\n messages: messages.map((m, idx) => ({\n parentId: messages[idx - 1]?.id ?? null,\n message: m,\n })),\n };\n};\n\nexport class LocalRuntimeCore extends BaseAssistantRuntimeCore {\n public readonly threadList;\n\n private _options: LocalRuntimeOptionsBase;\n\n constructor(\n options: LocalRuntimeOptionsBase,\n initialMessages: readonly CoreMessage[] | undefined,\n ) {\n super();\n\n this._options = options;\n\n this.threadList = new LocalThreadListRuntimeCore((
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalRuntimeCore.tsx"],"sourcesContent":["import type { CoreMessage } from \"../../types/AssistantTypes\";\nimport { BaseAssistantRuntimeCore } from \"../core/BaseAssistantRuntimeCore\";\nimport { LocalThreadRuntimeCore } from \"./LocalThreadRuntimeCore\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport { fromCoreMessages } from \"../edge/converters/fromCoreMessage\";\nimport { LocalThreadListRuntimeCore } from \"./LocalThreadListRuntimeCore\";\nimport { ExportedMessageRepository } from \"../utils/MessageRepository\";\n\nconst getExportFromInitialMessages = (\n initialMessages: readonly CoreMessage[],\n): ExportedMessageRepository => {\n const messages = fromCoreMessages(initialMessages);\n return {\n messages: messages.map((m, idx) => ({\n parentId: messages[idx - 1]?.id ?? null,\n message: m,\n })),\n };\n};\n\nexport class LocalRuntimeCore extends BaseAssistantRuntimeCore {\n public readonly threadList;\n\n private _options: LocalRuntimeOptionsBase;\n\n constructor(\n options: LocalRuntimeOptionsBase,\n initialMessages: readonly CoreMessage[] | undefined,\n ) {\n super();\n\n this._options = options;\n\n this.threadList = new LocalThreadListRuntimeCore((data) => {\n const thread = new LocalThreadRuntimeCore(\n this._proxyConfigProvider,\n this._options,\n );\n thread.import(data);\n return thread;\n });\n\n if (initialMessages) {\n this.threadList\n .getMainThreadRuntimeCore()\n .import(getExportFromInitialMessages(initialMessages));\n }\n }\n\n public reset({\n initialMessages,\n }: {\n initialMessages?: readonly CoreMessage[] | undefined;\n } = {}) {\n this.threadList.switchToNewThread();\n if (!initialMessages) return;\n\n this.threadList\n .getMainThreadRuntimeCore()\n .import(getExportFromInitialMessages(initialMessages));\n }\n}\n"],"mappings":";AACA,SAAS,gCAAgC;AACzC,SAAS,8BAA8B;AAEvC,SAAS,wBAAwB;AACjC,SAAS,kCAAkC;AAG3C,IAAM,+BAA+B,CACnC,oBAC8B;AAC9B,QAAM,WAAW,iBAAiB,eAAe;AACjD,SAAO;AAAA,IACL,UAAU,SAAS,IAAI,CAAC,GAAG,SAAS;AAAA,MAClC,UAAU,SAAS,MAAM,CAAC,GAAG,MAAM;AAAA,MACnC,SAAS;AAAA,IACX,EAAE;AAAA,EACJ;AACF;AAEO,IAAM,mBAAN,cAA+B,yBAAyB;AAAA,EAC7C;AAAA,EAER;AAAA,EAER,YACE,SACA,iBACA;AACA,UAAM;AAEN,SAAK,WAAW;AAEhB,SAAK,aAAa,IAAI,2BAA2B,CAAC,SAAS;AACzD,YAAM,SAAS,IAAI;AAAA,QACjB,KAAK;AAAA,QACL,KAAK;AAAA,MACP;AACA,aAAO,OAAO,IAAI;AAClB,aAAO;AAAA,IACT,CAAC;AAED,QAAI,iBAAiB;AACnB,WAAK,WACF,yBAAyB,EACzB,OAAO,6BAA6B,eAAe,CAAC;AAAA,IACzD;AAAA,EACF;AAAA,EAEO,MAAM;AAAA,IACX;AAAA,EACF,IAEI,CAAC,GAAG;AACN,SAAK,WAAW,kBAAkB;AAClC,QAAI,CAAC,gBAAiB;AAEtB,SAAK,WACF,yBAAyB,EACzB,OAAO,6BAA6B,eAAe,CAAC;AAAA,EACzD;AACF;","names":[]}
|
|
@@ -2,32 +2,34 @@ import type { Unsubscribe } from "../../types";
|
|
|
2
2
|
import { ThreadListRuntimeCore } from "../core/ThreadListRuntimeCore";
|
|
3
3
|
import { ExportedMessageRepository } from "../utils/MessageRepository";
|
|
4
4
|
import { LocalThreadRuntimeCore } from "./LocalThreadRuntimeCore";
|
|
5
|
-
import { ThreadMetadata } from "../core/ThreadRuntimeCore";
|
|
6
5
|
export type ThreadListAdapter = {
|
|
7
6
|
subscribe(callback: () => void): Unsubscribe;
|
|
8
7
|
};
|
|
9
8
|
export type LocalThreadData = {
|
|
10
|
-
runtime: LocalThreadRuntimeCore;
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
readonly runtime: LocalThreadRuntimeCore;
|
|
10
|
+
readonly state: "new" | "regular" | "archived";
|
|
11
|
+
readonly threadId: string;
|
|
12
|
+
readonly title?: string | undefined;
|
|
13
|
+
dispose(): void;
|
|
13
14
|
};
|
|
14
|
-
export type LocalThreadFactory = (
|
|
15
|
+
export type LocalThreadFactory = (data: ExportedMessageRepository) => LocalThreadRuntimeCore;
|
|
15
16
|
export declare class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {
|
|
16
17
|
private _threadFactory;
|
|
17
18
|
private _threadData;
|
|
18
|
-
private
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
get
|
|
22
|
-
get
|
|
23
|
-
get
|
|
24
|
-
private
|
|
25
|
-
get
|
|
19
|
+
private _threadIds;
|
|
20
|
+
private _archivedThreadIds;
|
|
21
|
+
private _newThreadId;
|
|
22
|
+
get newThreadId(): string | undefined;
|
|
23
|
+
get threadIds(): readonly string[];
|
|
24
|
+
get archivedThreadIds(): readonly string[];
|
|
25
|
+
private _mainThreadId;
|
|
26
|
+
get mainThreadId(): string;
|
|
26
27
|
constructor(_threadFactory: LocalThreadFactory);
|
|
27
|
-
|
|
28
|
+
getMainThreadRuntimeCore(): LocalThreadRuntimeCore;
|
|
29
|
+
getItemById(threadId: string): LocalThreadData | undefined;
|
|
28
30
|
switchToThread(threadId: string): Promise<void>;
|
|
29
31
|
switchToNewThread(): Promise<void>;
|
|
30
|
-
private
|
|
32
|
+
private _stateOp;
|
|
31
33
|
rename(threadId: string, newTitle: string): Promise<void>;
|
|
32
34
|
archive(threadId: string): Promise<void>;
|
|
33
35
|
unarchive(threadId: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalThreadListRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAEvE,OAAO,EAAE,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BAAwB;IAOxB,WAAW,CAAC,QAAQ,EAAE,MAAM;IAItB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYrD,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;YA2B3B,QAAQ;IAyEf,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYzD,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1C,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU9C,OAAO,CAAC,cAAc,CAAyB;IAExC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,WAAW;IAKnD,OAAO,CAAC,kBAAkB;CAG3B"}
|
|
@@ -30,146 +30,148 @@ var LocalThreadListRuntimeCore = class {
|
|
|
30
30
|
this.switchToNewThread();
|
|
31
31
|
}
|
|
32
32
|
_threadData = /* @__PURE__ */ new Map();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
get
|
|
37
|
-
return this.
|
|
33
|
+
_threadIds = [];
|
|
34
|
+
_archivedThreadIds = [];
|
|
35
|
+
_newThreadId;
|
|
36
|
+
get newThreadId() {
|
|
37
|
+
return this._newThreadId;
|
|
38
38
|
}
|
|
39
|
-
get
|
|
40
|
-
return this.
|
|
39
|
+
get threadIds() {
|
|
40
|
+
return this._threadIds;
|
|
41
41
|
}
|
|
42
|
-
get
|
|
43
|
-
return this.
|
|
42
|
+
get archivedThreadIds() {
|
|
43
|
+
return this._archivedThreadIds;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
get
|
|
47
|
-
return this.
|
|
45
|
+
_mainThreadId;
|
|
46
|
+
get mainThreadId() {
|
|
47
|
+
return this._mainThreadId;
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
getMainThreadRuntimeCore() {
|
|
50
|
+
const result = this._threadData.get(this._mainThreadId)?.runtime;
|
|
51
|
+
if (!result)
|
|
52
|
+
throw new Error("Main thread not found. This is a bug in assistant-ui.");
|
|
53
|
+
return result;
|
|
51
54
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
getItemById(threadId) {
|
|
56
|
+
return this._threadData.get(threadId);
|
|
57
|
+
}
|
|
58
|
+
async switchToThread(threadId) {
|
|
59
|
+
if (this._mainThreadId === threadId) return;
|
|
55
60
|
const data = this._threadData.get(threadId);
|
|
56
61
|
if (!data) throw new Error("Thread not found");
|
|
57
|
-
if (data.
|
|
58
|
-
this.
|
|
59
|
-
this._mainThread = data.runtime;
|
|
62
|
+
if (data.state === "archived") await this.unarchive(threadId);
|
|
63
|
+
this._mainThreadId = data.threadId;
|
|
60
64
|
this._notifySubscribers();
|
|
61
|
-
data.runtime._notifyEventSubscribers("switched-to");
|
|
62
|
-
return Promise.resolve();
|
|
63
65
|
}
|
|
64
66
|
switchToNewThread() {
|
|
65
|
-
if (this.
|
|
67
|
+
if (this._newThreadId === void 0) {
|
|
66
68
|
let threadId;
|
|
67
69
|
do {
|
|
68
70
|
threadId = (0, import_idUtils.generateId)();
|
|
69
71
|
} while (this._threadData.has(threadId));
|
|
70
|
-
const runtime = this._threadFactory(
|
|
71
|
-
const dispose = runtime.
|
|
72
|
-
this.
|
|
73
|
-
|
|
72
|
+
const runtime = this._threadFactory({ messages: [] });
|
|
73
|
+
const dispose = runtime.unstable_on("initialize", () => {
|
|
74
|
+
const data = this._threadData.get(threadId);
|
|
75
|
+
if (!data) throw new Error("Thread not found");
|
|
76
|
+
this._stateOp(threadId, "regular");
|
|
77
|
+
});
|
|
78
|
+
this._threadData.set(threadId, {
|
|
79
|
+
runtime,
|
|
80
|
+
state: "new",
|
|
81
|
+
threadId,
|
|
82
|
+
dispose
|
|
74
83
|
});
|
|
75
|
-
this.
|
|
76
|
-
this._newThread = threadId;
|
|
84
|
+
this._newThreadId = threadId;
|
|
77
85
|
}
|
|
78
|
-
this.switchToThread(this.
|
|
86
|
+
this.switchToThread(this._newThreadId);
|
|
79
87
|
return Promise.resolve();
|
|
80
88
|
}
|
|
81
|
-
async
|
|
82
|
-
const data = this._threadData.get(
|
|
89
|
+
async _stateOp(threadId, newState) {
|
|
90
|
+
const data = this._threadData.get(threadId);
|
|
83
91
|
if (!data) throw new Error("Thread not found");
|
|
84
|
-
const lastState = data
|
|
85
|
-
if (lastState ===
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
if (lastState === "archived") {
|
|
97
|
-
this._archivedThreads = this._archivedThreads.map(
|
|
98
|
-
(t) => t === lastThreadId ? threadId : t
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (lastState !== state) {
|
|
103
|
-
if (lastState === "new") {
|
|
104
|
-
this._newThread = void 0;
|
|
105
|
-
}
|
|
106
|
-
if (lastState === "regular") {
|
|
107
|
-
this._threads = this._threads.filter((t) => t !== threadId);
|
|
108
|
-
}
|
|
109
|
-
if (lastState === "archived") {
|
|
110
|
-
this._archivedThreads = this._archivedThreads.filter(
|
|
92
|
+
const { state: lastState } = data;
|
|
93
|
+
if (lastState === newState) return;
|
|
94
|
+
switch (lastState) {
|
|
95
|
+
case "new":
|
|
96
|
+
this._newThreadId = void 0;
|
|
97
|
+
break;
|
|
98
|
+
case "regular":
|
|
99
|
+
this._threadIds = this._threadIds.filter((t) => t !== threadId);
|
|
100
|
+
break;
|
|
101
|
+
case "archived":
|
|
102
|
+
this._archivedThreadIds = this._archivedThreadIds.filter(
|
|
111
103
|
(t) => t !== threadId
|
|
112
104
|
);
|
|
105
|
+
break;
|
|
106
|
+
default: {
|
|
107
|
+
const _exhaustiveCheck = lastState;
|
|
108
|
+
throw new Error(`Unsupported state: ${_exhaustiveCheck}`);
|
|
113
109
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
data.runtime.metadata.threadId
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
if (state === "regular") {
|
|
127
|
-
this._threads = [...this._threads, data.runtime.metadata.threadId];
|
|
128
|
-
}
|
|
129
|
-
if (state === "deleted") {
|
|
130
|
-
data.dispose();
|
|
110
|
+
}
|
|
111
|
+
switch (newState) {
|
|
112
|
+
case "regular":
|
|
113
|
+
this._threadIds = [...this._threadIds, data.threadId];
|
|
114
|
+
break;
|
|
115
|
+
case "archived":
|
|
116
|
+
this._archivedThreadIds = [...this._archivedThreadIds, data.threadId];
|
|
117
|
+
break;
|
|
118
|
+
case "deleted":
|
|
131
119
|
this._threadData.delete(threadId);
|
|
120
|
+
data.dispose();
|
|
121
|
+
break;
|
|
122
|
+
default: {
|
|
123
|
+
const _exhaustiveCheck = newState;
|
|
124
|
+
throw new Error(`Unsupported state: ${_exhaustiveCheck}`);
|
|
132
125
|
}
|
|
133
|
-
data.lastState = state;
|
|
134
126
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
if (newState !== "deleted") {
|
|
128
|
+
this._threadData.set(threadId, {
|
|
129
|
+
...data,
|
|
130
|
+
state: newState
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (threadId === this._mainThreadId && (newState === "archived" || newState === "deleted")) {
|
|
134
|
+
const lastThreadId = this._threadIds[0];
|
|
135
|
+
if (lastThreadId) {
|
|
136
|
+
await this.switchToThread(lastThreadId);
|
|
140
137
|
} else {
|
|
141
138
|
await this.switchToNewThread();
|
|
142
139
|
}
|
|
140
|
+
} else {
|
|
141
|
+
this._notifySubscribers();
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
rename(threadId, newTitle) {
|
|
146
145
|
const data = this._threadData.get(threadId);
|
|
147
146
|
if (!data) throw new Error("Thread not found");
|
|
148
|
-
|
|
147
|
+
this._threadData.set(threadId, {
|
|
148
|
+
...data,
|
|
149
|
+
title: newTitle
|
|
150
|
+
});
|
|
151
|
+
this._notifySubscribers();
|
|
149
152
|
return Promise.resolve();
|
|
150
153
|
}
|
|
151
154
|
archive(threadId) {
|
|
152
155
|
const data = this._threadData.get(threadId);
|
|
153
156
|
if (!data) throw new Error("Thread not found");
|
|
154
|
-
if (data.
|
|
155
|
-
throw new Error("Thread is not yet
|
|
156
|
-
|
|
157
|
+
if (data.state !== "regular")
|
|
158
|
+
throw new Error("Thread is not yet initialized or already archived");
|
|
159
|
+
this._stateOp(threadId, "archived");
|
|
157
160
|
return Promise.resolve();
|
|
158
161
|
}
|
|
159
162
|
unarchive(threadId) {
|
|
160
163
|
const data = this._threadData.get(threadId);
|
|
161
164
|
if (!data) throw new Error("Thread not found");
|
|
162
|
-
if (data.
|
|
163
|
-
|
|
164
|
-
data.runtime.metadata.unarchive();
|
|
165
|
+
if (data.state !== "archived") throw new Error("Thread is not archived");
|
|
166
|
+
this._stateOp(threadId, "regular");
|
|
165
167
|
return Promise.resolve();
|
|
166
168
|
}
|
|
167
169
|
delete(threadId) {
|
|
168
170
|
const data = this._threadData.get(threadId);
|
|
169
171
|
if (!data) throw new Error("Thread not found");
|
|
170
|
-
if (data.
|
|
171
|
-
throw new Error("Thread is not yet
|
|
172
|
-
|
|
172
|
+
if (data.state !== "regular" && data.state !== "archived")
|
|
173
|
+
throw new Error("Thread is not yet initalized");
|
|
174
|
+
this._stateOp(threadId, "deleted");
|
|
173
175
|
return Promise.resolve();
|
|
174
176
|
}
|
|
175
177
|
_subscriptions = /* @__PURE__ */ new Set();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"sourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { ExportedMessageRepository } from \"../utils/MessageRepository\";\nimport { generateId } from \"../../utils/idUtils\";\nimport { LocalThreadRuntimeCore } from \"./LocalThreadRuntimeCore\";\nimport { ThreadMetadata } from \"../core/ThreadRuntimeCore\";\n\nexport type ThreadListAdapter = {\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport type LocalThreadData = {\n runtime: LocalThreadRuntimeCore;\n lastState: ThreadMetadata[\"state\"];\n dispose: Unsubscribe;\n};\n\nexport type LocalThreadFactory = (\n threadId: string,\n data: ExportedMessageRepository,\n) => LocalThreadRuntimeCore;\n\nexport class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {\n private _threadData = new Map<string, LocalThreadData>();\n private _threads: readonly string[] = [];\n private _archivedThreads: readonly string[] = [];\n private _newThread: string | undefined;\n\n public get newThread() {\n return this._newThread;\n }\n\n public get threads() {\n return this._threads;\n }\n\n public get archivedThreads() {\n return this._archivedThreads;\n }\n\n private _mainThread!: LocalThreadRuntimeCore;\n\n public get mainThread(): LocalThreadRuntimeCore {\n return this._mainThread;\n }\n\n constructor(private _threadFactory: LocalThreadFactory) {\n this.switchToNewThread();\n }\n\n public getThreadMetadataById(threadId: string) {\n return this._threadData.get(threadId)?.runtime.metadata;\n }\n\n public switchToThread(threadId: string): Promise<void> {\n if (this._mainThread?.metadata.threadId === threadId)\n return Promise.resolve();\n\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (data.runtime.metadata.state === \"archived\") this.unarchive(threadId);\n\n this._mainThread?._notifyEventSubscribers(\"switched-away\");\n this._mainThread = data.runtime;\n this._notifySubscribers();\n\n data.runtime._notifyEventSubscribers(\"switched-to\");\n return Promise.resolve();\n }\n\n public switchToNewThread(): Promise<void> {\n if (this._newThread === undefined) {\n let threadId: string;\n do {\n threadId = generateId();\n } while (this._threadData.has(threadId));\n\n const runtime = this._threadFactory(threadId, { messages: [] });\n const dispose = runtime.metadata.subscribe(() => {\n this._syncState(threadId, runtime.metadata);\n threadId = runtime.metadata.threadId;\n });\n this._threadData.set(threadId, { runtime, lastState: \"new\", dispose });\n this._newThread = threadId;\n }\n\n this.switchToThread(this._newThread);\n return Promise.resolve();\n }\n\n private async _syncState(\n lastThreadId: string,\n { state, threadId }: ThreadMetadata,\n ) {\n const data = this._threadData.get(lastThreadId);\n if (!data) throw new Error(\"Thread not found\");\n const lastState = data.lastState;\n if (lastState === state && lastThreadId === threadId) return;\n\n if (lastThreadId !== threadId) {\n this._threadData.delete(lastThreadId);\n if (lastState === \"new\") {\n this._newThread = threadId;\n }\n if (lastState === \"regular\") {\n this._threads = this._threads.map((t) =>\n t === lastThreadId ? threadId : t,\n );\n }\n if (lastState === \"archived\") {\n this._archivedThreads = this._archivedThreads.map((t) =>\n t === lastThreadId ? threadId : t,\n );\n }\n }\n\n if (lastState !== state) {\n if (lastState === \"new\") {\n this._newThread = undefined;\n }\n\n if (lastState === \"regular\") {\n this._threads = this._threads.filter((t) => t !== threadId);\n }\n\n if (lastState === \"archived\") {\n this._archivedThreads = this._archivedThreads.filter(\n (t) => t !== threadId,\n );\n }\n\n if (state === \"new\") {\n if (this._newThread) {\n this.delete(this._newThread);\n }\n this._newThread = threadId;\n }\n if (state === \"archived\") {\n this._archivedThreads = [\n ...this._archivedThreads,\n data.runtime.metadata.threadId,\n ];\n }\n if (state === \"regular\") {\n this._threads = [...this._threads, data.runtime.metadata.threadId];\n }\n if (state === \"deleted\") {\n data.dispose();\n this._threadData.delete(threadId);\n }\n\n data.lastState = state;\n }\n\n this._notifySubscribers();\n\n if (\n threadId === this._mainThread.metadata.threadId &&\n (state === \"archived\" || state === \"deleted\")\n ) {\n const lastThread = this._threads[0];\n if (lastThread) {\n await this.switchToThread(lastThread);\n } else {\n await this.switchToNewThread();\n }\n }\n }\n\n public rename(threadId: string, newTitle: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n data.runtime.metadata.rename(newTitle);\n\n return Promise.resolve();\n }\n\n public archive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.lastState !== \"regular\")\n throw new Error(\"Thread is not yet created or archived\");\n data.runtime.metadata.archive();\n\n return Promise.resolve();\n }\n\n public unarchive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.lastState !== \"archived\")\n throw new Error(\"Thread is not archived\");\n data.runtime.metadata.unarchive();\n\n return Promise.resolve();\n }\n\n public delete(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.lastState !== \"regular\" && data.lastState !== \"archived\")\n throw new Error(\"Thread is not yet created or already deleted\");\n data.runtime.metadata.delete();\n\n return Promise.resolve();\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private _notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA2B;AAmBpB,IAAM,6BAAN,MAAkE;AAAA,EAwBvE,YAAoB,gBAAoC;AAApC;AAClB,SAAK,kBAAkB;AAAA,EACzB;AAAA,EAzBQ,cAAc,oBAAI,IAA6B;AAAA,EAC/C,WAA8B,CAAC;AAAA,EAC/B,mBAAsC,CAAC;AAAA,EACvC;AAAA,EAER,IAAW,YAAY;AACrB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,UAAU;AACnB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,kBAAkB;AAC3B,WAAO,KAAK;AAAA,EACd;AAAA,EAEQ;AAAA,EAER,IAAW,aAAqC;AAC9C,WAAO,KAAK;AAAA,EACd;AAAA,E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qBAAqB;AAC3B,eAAW,YAAY,KAAK,eAAgB,UAAS;AAAA,EACvD;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"sourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { ExportedMessageRepository } from \"../utils/MessageRepository\";\nimport { generateId } from \"../../utils/idUtils\";\nimport { LocalThreadRuntimeCore } from \"./LocalThreadRuntimeCore\";\n\nexport type ThreadListAdapter = {\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport type LocalThreadData = {\n readonly runtime: LocalThreadRuntimeCore;\n readonly state: \"new\" | \"regular\" | \"archived\";\n readonly threadId: string;\n readonly title?: string | undefined;\n\n dispose(): void;\n};\n\nexport type LocalThreadFactory = (\n data: ExportedMessageRepository,\n) => LocalThreadRuntimeCore;\n\nexport class LocalThreadListRuntimeCore implements ThreadListRuntimeCore {\n private _threadData = new Map<string, LocalThreadData>();\n private _threadIds: readonly string[] = [];\n private _archivedThreadIds: readonly string[] = [];\n private _newThreadId: string | undefined;\n\n public get newThreadId() {\n return this._newThreadId;\n }\n\n public get threadIds() {\n return this._threadIds;\n }\n\n public get archivedThreadIds() {\n return this._archivedThreadIds;\n }\n\n private _mainThreadId!: string;\n\n public get mainThreadId(): string {\n return this._mainThreadId;\n }\n\n constructor(private _threadFactory: LocalThreadFactory) {\n this.switchToNewThread();\n }\n\n public getMainThreadRuntimeCore() {\n const result = this._threadData.get(this._mainThreadId)?.runtime;\n if (!result)\n throw new Error(\"Main thread not found. This is a bug in assistant-ui.\");\n return result;\n }\n\n public getItemById(threadId: string) {\n return this._threadData.get(threadId);\n }\n\n public async switchToThread(threadId: string): Promise<void> {\n if (this._mainThreadId === threadId) return;\n\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n if (data.state === \"archived\") await this.unarchive(threadId);\n\n this._mainThreadId = data.threadId;\n this._notifySubscribers();\n }\n\n public switchToNewThread(): Promise<void> {\n if (this._newThreadId === undefined) {\n let threadId: string;\n do {\n threadId = generateId();\n } while (this._threadData.has(threadId));\n\n const runtime = this._threadFactory({ messages: [] });\n const dispose = runtime.unstable_on(\"initialize\", () => {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n this._stateOp(threadId, \"regular\");\n });\n this._threadData.set(threadId, {\n runtime,\n state: \"new\",\n threadId,\n dispose,\n });\n this._newThreadId = threadId;\n }\n\n this.switchToThread(this._newThreadId);\n return Promise.resolve();\n }\n\n private async _stateOp(\n threadId: string,\n newState: \"regular\" | \"archived\" | \"deleted\",\n ) {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n const { state: lastState } = data;\n if (lastState === newState) return;\n\n // lastState\n switch (lastState) {\n case \"new\":\n this._newThreadId = undefined;\n break;\n case \"regular\":\n this._threadIds = this._threadIds.filter((t) => t !== threadId);\n break;\n case \"archived\":\n this._archivedThreadIds = this._archivedThreadIds.filter(\n (t) => t !== threadId,\n );\n break;\n\n default: {\n const _exhaustiveCheck: never = lastState;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n // newState\n switch (newState) {\n case \"regular\":\n this._threadIds = [...this._threadIds, data.threadId];\n break;\n\n case \"archived\":\n this._archivedThreadIds = [...this._archivedThreadIds, data.threadId];\n break;\n\n case \"deleted\":\n this._threadData.delete(threadId);\n data.dispose();\n break;\n\n default: {\n const _exhaustiveCheck: never = newState;\n throw new Error(`Unsupported state: ${_exhaustiveCheck}`);\n }\n }\n\n if (newState !== \"deleted\") {\n this._threadData.set(threadId, {\n ...data,\n state: newState,\n });\n }\n\n if (\n threadId === this._mainThreadId &&\n (newState === \"archived\" || newState === \"deleted\")\n ) {\n const lastThreadId = this._threadIds[0];\n if (lastThreadId) {\n await this.switchToThread(lastThreadId);\n } else {\n await this.switchToNewThread();\n }\n } else {\n this._notifySubscribers();\n }\n }\n\n public rename(threadId: string, newTitle: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n\n this._threadData.set(threadId, {\n ...data,\n title: newTitle,\n });\n this._notifySubscribers();\n return Promise.resolve();\n }\n\n public archive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.state !== \"regular\")\n throw new Error(\"Thread is not yet initialized or already archived\");\n\n this._stateOp(threadId, \"archived\");\n return Promise.resolve();\n }\n\n public unarchive(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.state !== \"archived\") throw new Error(\"Thread is not archived\");\n\n this._stateOp(threadId, \"regular\");\n return Promise.resolve();\n }\n\n public delete(threadId: string): Promise<void> {\n const data = this._threadData.get(threadId);\n if (!data) throw new Error(\"Thread not found\");\n if (data.state !== \"regular\" && data.state !== \"archived\")\n throw new Error(\"Thread is not yet initalized\");\n\n this._stateOp(threadId, \"deleted\");\n return Promise.resolve();\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private _notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA2B;AAoBpB,IAAM,6BAAN,MAAkE;AAAA,EAwBvE,YAAoB,gBAAoC;AAApC;AAClB,SAAK,kBAAkB;AAAA,EACzB;AAAA,EAzBQ,cAAc,oBAAI,IAA6B;AAAA,EAC/C,aAAgC,CAAC;AAAA,EACjC,qBAAwC,CAAC;AAAA,EACzC;AAAA,EAER,IAAW,cAAc;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,YAAY;AACrB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,oBAAoB;AAC7B,WAAO,KAAK;AAAA,EACd;AAA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@@ -6,146 +6,148 @@ var LocalThreadListRuntimeCore = class {
|
|
|
6
6
|
this.switchToNewThread();
|
|
7
7
|
}
|
|
8
8
|
_threadData = /* @__PURE__ */ new Map();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
get
|
|
13
|
-
return this.
|
|
9
|
+
_threadIds = [];
|
|
10
|
+
_archivedThreadIds = [];
|
|
11
|
+
_newThreadId;
|
|
12
|
+
get newThreadId() {
|
|
13
|
+
return this._newThreadId;
|
|
14
14
|
}
|
|
15
|
-
get
|
|
16
|
-
return this.
|
|
15
|
+
get threadIds() {
|
|
16
|
+
return this._threadIds;
|
|
17
17
|
}
|
|
18
|
-
get
|
|
19
|
-
return this.
|
|
18
|
+
get archivedThreadIds() {
|
|
19
|
+
return this._archivedThreadIds;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
get
|
|
23
|
-
return this.
|
|
21
|
+
_mainThreadId;
|
|
22
|
+
get mainThreadId() {
|
|
23
|
+
return this._mainThreadId;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
getMainThreadRuntimeCore() {
|
|
26
|
+
const result = this._threadData.get(this._mainThreadId)?.runtime;
|
|
27
|
+
if (!result)
|
|
28
|
+
throw new Error("Main thread not found. This is a bug in assistant-ui.");
|
|
29
|
+
return result;
|
|
27
30
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
getItemById(threadId) {
|
|
32
|
+
return this._threadData.get(threadId);
|
|
33
|
+
}
|
|
34
|
+
async switchToThread(threadId) {
|
|
35
|
+
if (this._mainThreadId === threadId) return;
|
|
31
36
|
const data = this._threadData.get(threadId);
|
|
32
37
|
if (!data) throw new Error("Thread not found");
|
|
33
|
-
if (data.
|
|
34
|
-
this.
|
|
35
|
-
this._mainThread = data.runtime;
|
|
38
|
+
if (data.state === "archived") await this.unarchive(threadId);
|
|
39
|
+
this._mainThreadId = data.threadId;
|
|
36
40
|
this._notifySubscribers();
|
|
37
|
-
data.runtime._notifyEventSubscribers("switched-to");
|
|
38
|
-
return Promise.resolve();
|
|
39
41
|
}
|
|
40
42
|
switchToNewThread() {
|
|
41
|
-
if (this.
|
|
43
|
+
if (this._newThreadId === void 0) {
|
|
42
44
|
let threadId;
|
|
43
45
|
do {
|
|
44
46
|
threadId = generateId();
|
|
45
47
|
} while (this._threadData.has(threadId));
|
|
46
|
-
const runtime = this._threadFactory(
|
|
47
|
-
const dispose = runtime.
|
|
48
|
-
this.
|
|
49
|
-
|
|
48
|
+
const runtime = this._threadFactory({ messages: [] });
|
|
49
|
+
const dispose = runtime.unstable_on("initialize", () => {
|
|
50
|
+
const data = this._threadData.get(threadId);
|
|
51
|
+
if (!data) throw new Error("Thread not found");
|
|
52
|
+
this._stateOp(threadId, "regular");
|
|
53
|
+
});
|
|
54
|
+
this._threadData.set(threadId, {
|
|
55
|
+
runtime,
|
|
56
|
+
state: "new",
|
|
57
|
+
threadId,
|
|
58
|
+
dispose
|
|
50
59
|
});
|
|
51
|
-
this.
|
|
52
|
-
this._newThread = threadId;
|
|
60
|
+
this._newThreadId = threadId;
|
|
53
61
|
}
|
|
54
|
-
this.switchToThread(this.
|
|
62
|
+
this.switchToThread(this._newThreadId);
|
|
55
63
|
return Promise.resolve();
|
|
56
64
|
}
|
|
57
|
-
async
|
|
58
|
-
const data = this._threadData.get(
|
|
65
|
+
async _stateOp(threadId, newState) {
|
|
66
|
+
const data = this._threadData.get(threadId);
|
|
59
67
|
if (!data) throw new Error("Thread not found");
|
|
60
|
-
const lastState = data
|
|
61
|
-
if (lastState ===
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
if (lastState === "archived") {
|
|
73
|
-
this._archivedThreads = this._archivedThreads.map(
|
|
74
|
-
(t) => t === lastThreadId ? threadId : t
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (lastState !== state) {
|
|
79
|
-
if (lastState === "new") {
|
|
80
|
-
this._newThread = void 0;
|
|
81
|
-
}
|
|
82
|
-
if (lastState === "regular") {
|
|
83
|
-
this._threads = this._threads.filter((t) => t !== threadId);
|
|
84
|
-
}
|
|
85
|
-
if (lastState === "archived") {
|
|
86
|
-
this._archivedThreads = this._archivedThreads.filter(
|
|
68
|
+
const { state: lastState } = data;
|
|
69
|
+
if (lastState === newState) return;
|
|
70
|
+
switch (lastState) {
|
|
71
|
+
case "new":
|
|
72
|
+
this._newThreadId = void 0;
|
|
73
|
+
break;
|
|
74
|
+
case "regular":
|
|
75
|
+
this._threadIds = this._threadIds.filter((t) => t !== threadId);
|
|
76
|
+
break;
|
|
77
|
+
case "archived":
|
|
78
|
+
this._archivedThreadIds = this._archivedThreadIds.filter(
|
|
87
79
|
(t) => t !== threadId
|
|
88
80
|
);
|
|
81
|
+
break;
|
|
82
|
+
default: {
|
|
83
|
+
const _exhaustiveCheck = lastState;
|
|
84
|
+
throw new Error(`Unsupported state: ${_exhaustiveCheck}`);
|
|
89
85
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
data.runtime.metadata.threadId
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
if (state === "regular") {
|
|
103
|
-
this._threads = [...this._threads, data.runtime.metadata.threadId];
|
|
104
|
-
}
|
|
105
|
-
if (state === "deleted") {
|
|
106
|
-
data.dispose();
|
|
86
|
+
}
|
|
87
|
+
switch (newState) {
|
|
88
|
+
case "regular":
|
|
89
|
+
this._threadIds = [...this._threadIds, data.threadId];
|
|
90
|
+
break;
|
|
91
|
+
case "archived":
|
|
92
|
+
this._archivedThreadIds = [...this._archivedThreadIds, data.threadId];
|
|
93
|
+
break;
|
|
94
|
+
case "deleted":
|
|
107
95
|
this._threadData.delete(threadId);
|
|
96
|
+
data.dispose();
|
|
97
|
+
break;
|
|
98
|
+
default: {
|
|
99
|
+
const _exhaustiveCheck = newState;
|
|
100
|
+
throw new Error(`Unsupported state: ${_exhaustiveCheck}`);
|
|
108
101
|
}
|
|
109
|
-
data.lastState = state;
|
|
110
102
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
103
|
+
if (newState !== "deleted") {
|
|
104
|
+
this._threadData.set(threadId, {
|
|
105
|
+
...data,
|
|
106
|
+
state: newState
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (threadId === this._mainThreadId && (newState === "archived" || newState === "deleted")) {
|
|
110
|
+
const lastThreadId = this._threadIds[0];
|
|
111
|
+
if (lastThreadId) {
|
|
112
|
+
await this.switchToThread(lastThreadId);
|
|
116
113
|
} else {
|
|
117
114
|
await this.switchToNewThread();
|
|
118
115
|
}
|
|
116
|
+
} else {
|
|
117
|
+
this._notifySubscribers();
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
rename(threadId, newTitle) {
|
|
122
121
|
const data = this._threadData.get(threadId);
|
|
123
122
|
if (!data) throw new Error("Thread not found");
|
|
124
|
-
|
|
123
|
+
this._threadData.set(threadId, {
|
|
124
|
+
...data,
|
|
125
|
+
title: newTitle
|
|
126
|
+
});
|
|
127
|
+
this._notifySubscribers();
|
|
125
128
|
return Promise.resolve();
|
|
126
129
|
}
|
|
127
130
|
archive(threadId) {
|
|
128
131
|
const data = this._threadData.get(threadId);
|
|
129
132
|
if (!data) throw new Error("Thread not found");
|
|
130
|
-
if (data.
|
|
131
|
-
throw new Error("Thread is not yet
|
|
132
|
-
|
|
133
|
+
if (data.state !== "regular")
|
|
134
|
+
throw new Error("Thread is not yet initialized or already archived");
|
|
135
|
+
this._stateOp(threadId, "archived");
|
|
133
136
|
return Promise.resolve();
|
|
134
137
|
}
|
|
135
138
|
unarchive(threadId) {
|
|
136
139
|
const data = this._threadData.get(threadId);
|
|
137
140
|
if (!data) throw new Error("Thread not found");
|
|
138
|
-
if (data.
|
|
139
|
-
|
|
140
|
-
data.runtime.metadata.unarchive();
|
|
141
|
+
if (data.state !== "archived") throw new Error("Thread is not archived");
|
|
142
|
+
this._stateOp(threadId, "regular");
|
|
141
143
|
return Promise.resolve();
|
|
142
144
|
}
|
|
143
145
|
delete(threadId) {
|
|
144
146
|
const data = this._threadData.get(threadId);
|
|
145
147
|
if (!data) throw new Error("Thread not found");
|
|
146
|
-
if (data.
|
|
147
|
-
throw new Error("Thread is not yet
|
|
148
|
-
|
|
148
|
+
if (data.state !== "regular" && data.state !== "archived")
|
|
149
|
+
throw new Error("Thread is not yet initalized");
|
|
150
|
+
this._stateOp(threadId, "deleted");
|
|
149
151
|
return Promise.resolve();
|
|
150
152
|
}
|
|
151
153
|
_subscriptions = /* @__PURE__ */ new Set();
|