@assistant-ui/react 0.7.65 → 0.7.66
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/ThreadListItemRuntime.d.ts +2 -0
- package/dist/api/ThreadListItemRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListItemRuntime.js +5 -0
- package/dist/api/ThreadListItemRuntime.js.map +1 -1
- package/dist/api/ThreadListItemRuntime.mjs +5 -0
- package/dist/api/ThreadListItemRuntime.mjs.map +1 -1
- package/dist/cloud/AssistantCloudThreads.d.ts +1 -1
- package/dist/cloud/AssistantCloudThreads.d.ts.map +1 -1
- package/dist/cloud/AssistantCloudThreads.js.map +1 -1
- package/dist/cloud/AssistantCloudThreads.mjs.map +1 -1
- package/dist/cloud/useCloudThreadListRuntime.d.ts +1 -1
- package/dist/cloud/useCloudThreadListRuntime.d.ts.map +1 -1
- package/dist/cloud/useCloudThreadListRuntime.js +8 -83
- package/dist/cloud/useCloudThreadListRuntime.js.map +1 -1
- package/dist/cloud/useCloudThreadListRuntime.mjs +8 -89
- package/dist/cloud/useCloudThreadListRuntime.mjs.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts +1 -0
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.d.ts +1 -1
- package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.d.ts.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.d.ts +22 -3
- package/dist/runtimes/edge/EdgeChatAdapter.d.ts.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.js +44 -13
- package/dist/runtimes/edge/EdgeChatAdapter.js.map +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.mjs +34 -13
- package/dist/runtimes/edge/EdgeChatAdapter.mjs.map +1 -1
- package/dist/runtimes/edge/useEdgeRuntime.d.ts +1 -1
- package/dist/runtimes/edge/useEdgeRuntime.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts +1 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js +3 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs +3 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/ChatModelAdapter.d.ts +1 -0
- package/dist/runtimes/local/ChatModelAdapter.d.ts.map +1 -1
- package/dist/runtimes/local/ChatModelAdapter.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.d.ts +4 -1
- package/dist/runtimes/local/LocalRuntimeOptions.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.js +2 -0
- package/dist/runtimes/local/LocalRuntimeOptions.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.mjs +2 -0
- package/dist/runtimes/local/LocalRuntimeOptions.mjs.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts +21 -31
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js +43 -147
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs +43 -147
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.js +4 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +4 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.d.ts +1 -1
- package/dist/runtimes/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.js +10 -1
- package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.mjs +10 -1
- package/dist/runtimes/local/useLocalRuntime.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js +4 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.mjs +4 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +6 -6
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +25 -23
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs +25 -23
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.d.ts +13 -0
- package/dist/runtimes/remote-thread-list/adapter/cloud.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/adapter/cloud.js +96 -0
- package/dist/runtimes/remote-thread-list/adapter/cloud.js.map +1 -0
- package/dist/runtimes/remote-thread-list/adapter/cloud.mjs +76 -0
- package/dist/runtimes/remote-thread-list/adapter/cloud.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts +12 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.js +58 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.js.map +1 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.mjs +35 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.mjs.map +1 -0
- package/dist/runtimes/remote-thread-list/index.d.ts +2 -1
- package/dist/runtimes/remote-thread-list/index.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/index.js +3 -0
- package/dist/runtimes/remote-thread-list/index.js.map +1 -1
- package/dist/runtimes/remote-thread-list/index.mjs +2 -0
- package/dist/runtimes/remote-thread-list/index.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +6 -6
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/types.js.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.d.ts +2 -2
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js +7 -7
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs +7 -7
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/ThreadListItemRuntime.ts +8 -0
- package/src/cloud/AssistantCloudThreads.tsx +1 -1
- package/src/cloud/useCloudThreadListRuntime.tsx +8 -110
- package/src/runtimes/core/ThreadListRuntimeCore.tsx +1 -0
- package/src/runtimes/edge/EdgeChatAdapter.ts +90 -19
- package/src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx +4 -0
- package/src/runtimes/local/ChatModelAdapter.tsx +1 -0
- package/src/runtimes/local/LocalRuntimeOptions.tsx +4 -0
- package/src/runtimes/local/LocalThreadListRuntimeCore.tsx +47 -190
- package/src/runtimes/local/LocalThreadRuntimeCore.tsx +3 -0
- package/src/runtimes/local/useLocalRuntime.tsx +15 -2
- package/src/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.tsx +7 -0
- package/src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +27 -28
- package/src/runtimes/remote-thread-list/adapter/cloud.tsx +99 -0
- package/src/runtimes/remote-thread-list/adapter/in-memory.tsx +43 -0
- package/src/runtimes/remote-thread-list/index.ts +3 -4
- package/src/runtimes/remote-thread-list/types.tsx +10 -12
- package/src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalThreadListRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"LocalThreadListRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,MAAM,kBAAkB,GAAG,MAAM,sBAAsB,CAAC;AAG9D,qBAAa,0BACX,SAAQ,gBACR,YAAW,qBAAqB;IAEhC,OAAO,CAAC,WAAW,CAAyB;gBAChC,cAAc,EAAE,kBAAkB;IAMvC,wBAAwB;IAI/B,IAAW,WAAW,IAAI,MAAM,CAE/B;IAED,IAAW,SAAS,IAAI,SAAS,MAAM,EAAE,CAExC;IAED,IAAW,iBAAiB,IAAI,SAAS,MAAM,EAAE,CAEhD;IAED,IAAW,YAAY,IAAI,MAAM,CAEhC;IAEM,oBAAoB,IAAI,KAAK;IAI7B,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAItC,WAAW,CAAC,QAAQ,EAAE,MAAM;;;;;;;;IActB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrC,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1B,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,UAAU,IAAI,KAAK;IAInB,aAAa,IAAI,KAAK;CAG9B"}
|
|
@@ -23,175 +23,71 @@ __export(LocalThreadListRuntimeCore_exports, {
|
|
|
23
23
|
LocalThreadListRuntimeCore: () => LocalThreadListRuntimeCore
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(LocalThreadListRuntimeCore_exports);
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var LocalThreadListRuntimeCore = class {
|
|
26
|
+
var import_BaseSubscribable = require("../remote-thread-list/BaseSubscribable.js");
|
|
27
|
+
var EMPTY_ARRAY = Object.freeze([]);
|
|
28
|
+
var LocalThreadListRuntimeCore = class extends import_BaseSubscribable.BaseSubscribable {
|
|
29
|
+
_mainThread;
|
|
29
30
|
constructor(_threadFactory) {
|
|
30
|
-
|
|
31
|
-
this.
|
|
31
|
+
super();
|
|
32
|
+
this._mainThread = _threadFactory();
|
|
33
|
+
}
|
|
34
|
+
getMainThreadRuntimeCore() {
|
|
35
|
+
return this._mainThread;
|
|
32
36
|
}
|
|
33
|
-
_threadData = /* @__PURE__ */ new Map();
|
|
34
|
-
_threadIds = [];
|
|
35
|
-
_archivedThreadIds = [];
|
|
36
|
-
_newThreadId;
|
|
37
37
|
get newThreadId() {
|
|
38
|
-
|
|
38
|
+
throw new Error("Method not implemented.");
|
|
39
39
|
}
|
|
40
40
|
get threadIds() {
|
|
41
|
-
|
|
41
|
+
throw EMPTY_ARRAY;
|
|
42
42
|
}
|
|
43
43
|
get archivedThreadIds() {
|
|
44
|
-
|
|
44
|
+
throw EMPTY_ARRAY;
|
|
45
45
|
}
|
|
46
|
-
_mainThreadId;
|
|
47
46
|
get mainThreadId() {
|
|
48
|
-
return
|
|
47
|
+
return "__DEFAULT_ID__";
|
|
49
48
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (!result)
|
|
53
|
-
throw new Error("Main thread not found. This is a bug in assistant-ui.");
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
getThreadRuntimeCore(threadId) {
|
|
57
|
-
const result = this._threadData.get(threadId)?.runtime;
|
|
58
|
-
if (!result) throw new Error("Thread not found.");
|
|
59
|
-
return result;
|
|
49
|
+
getThreadRuntimeCore() {
|
|
50
|
+
throw new Error("Method not implemented.");
|
|
60
51
|
}
|
|
61
52
|
getLoadThreadsPromise() {
|
|
62
|
-
|
|
53
|
+
throw new Error("Method not implemented.");
|
|
63
54
|
}
|
|
64
55
|
getItemById(threadId) {
|
|
65
|
-
|
|
56
|
+
if (threadId === this.mainThreadId) {
|
|
57
|
+
return {
|
|
58
|
+
status: "regular",
|
|
59
|
+
threadId: this.mainThreadId,
|
|
60
|
+
remoteId: this.mainThreadId,
|
|
61
|
+
externalId: void 0,
|
|
62
|
+
title: void 0,
|
|
63
|
+
isMain: true
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
throw new Error("Method not implemented");
|
|
66
67
|
}
|
|
67
|
-
async switchToThread(
|
|
68
|
-
|
|
69
|
-
const data = this._threadData.get(threadId);
|
|
70
|
-
if (!data) throw new Error("Thread not found");
|
|
71
|
-
if (data.status === "archived") await this.unarchive(threadId);
|
|
72
|
-
this._mainThreadId = data.threadId;
|
|
73
|
-
this._notifySubscribers();
|
|
68
|
+
async switchToThread() {
|
|
69
|
+
throw new Error("Method not implemented.");
|
|
74
70
|
}
|
|
75
71
|
switchToNewThread() {
|
|
76
|
-
|
|
77
|
-
let threadId;
|
|
78
|
-
do {
|
|
79
|
-
threadId = (0, import_idUtils.generateId)();
|
|
80
|
-
} while (this._threadData.has(threadId));
|
|
81
|
-
const runtime = this._threadFactory();
|
|
82
|
-
const dispose = runtime.unstable_on("initialize", () => {
|
|
83
|
-
dispose();
|
|
84
|
-
const data = this._threadData.get(threadId);
|
|
85
|
-
if (!data) throw new Error("Thread not found");
|
|
86
|
-
this._stateOp(threadId, "regular");
|
|
87
|
-
});
|
|
88
|
-
this._threadData.set(threadId, {
|
|
89
|
-
runtime,
|
|
90
|
-
status: "new",
|
|
91
|
-
threadId
|
|
92
|
-
});
|
|
93
|
-
this._newThreadId = threadId;
|
|
94
|
-
}
|
|
95
|
-
this.switchToThread(this._newThreadId);
|
|
96
|
-
return Promise.resolve();
|
|
97
|
-
}
|
|
98
|
-
async _stateOp(threadId, newState) {
|
|
99
|
-
const data = this._threadData.get(threadId);
|
|
100
|
-
if (!data) throw new Error("Thread not found");
|
|
101
|
-
const { status: lastState } = data;
|
|
102
|
-
if (lastState === newState) return;
|
|
103
|
-
switch (lastState) {
|
|
104
|
-
case "new":
|
|
105
|
-
this._newThreadId = void 0;
|
|
106
|
-
break;
|
|
107
|
-
case "regular":
|
|
108
|
-
this._threadIds = this._threadIds.filter((t) => t !== threadId);
|
|
109
|
-
break;
|
|
110
|
-
case "archived":
|
|
111
|
-
this._archivedThreadIds = this._archivedThreadIds.filter(
|
|
112
|
-
(t) => t !== threadId
|
|
113
|
-
);
|
|
114
|
-
break;
|
|
115
|
-
default: {
|
|
116
|
-
const _exhaustiveCheck = lastState;
|
|
117
|
-
throw new Error(`Unsupported state: ${_exhaustiveCheck}`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
switch (newState) {
|
|
121
|
-
case "regular":
|
|
122
|
-
this._threadIds = [data.threadId, ...this._threadIds];
|
|
123
|
-
break;
|
|
124
|
-
case "archived":
|
|
125
|
-
this._archivedThreadIds = [data.threadId, ...this._archivedThreadIds];
|
|
126
|
-
break;
|
|
127
|
-
case "deleted":
|
|
128
|
-
this._threadData.delete(threadId);
|
|
129
|
-
break;
|
|
130
|
-
default: {
|
|
131
|
-
const _exhaustiveCheck = newState;
|
|
132
|
-
throw new Error(`Unsupported state: ${_exhaustiveCheck}`);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (newState !== "deleted") {
|
|
136
|
-
this._threadData.set(threadId, {
|
|
137
|
-
...data,
|
|
138
|
-
status: newState
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
if (threadId === this._mainThreadId && (newState === "archived" || newState === "deleted")) {
|
|
142
|
-
const lastThreadId = this._threadIds[0];
|
|
143
|
-
if (lastThreadId) {
|
|
144
|
-
await this.switchToThread(lastThreadId);
|
|
145
|
-
} else {
|
|
146
|
-
await this.switchToNewThread();
|
|
147
|
-
}
|
|
148
|
-
} else {
|
|
149
|
-
this._notifySubscribers();
|
|
150
|
-
}
|
|
72
|
+
throw new Error("Method not implemented.");
|
|
151
73
|
}
|
|
152
|
-
rename(
|
|
153
|
-
|
|
154
|
-
if (!data) throw new Error("Thread not found");
|
|
155
|
-
this._threadData.set(threadId, {
|
|
156
|
-
...data,
|
|
157
|
-
title: newTitle
|
|
158
|
-
});
|
|
159
|
-
this._notifySubscribers();
|
|
160
|
-
return Promise.resolve();
|
|
161
|
-
}
|
|
162
|
-
archive(threadId) {
|
|
163
|
-
const data = this._threadData.get(threadId);
|
|
164
|
-
if (!data) throw new Error("Thread not found");
|
|
165
|
-
if (data.status !== "regular")
|
|
166
|
-
throw new Error("Thread is not yet initialized or already archived");
|
|
167
|
-
this._stateOp(threadId, "archived");
|
|
168
|
-
return Promise.resolve();
|
|
169
|
-
}
|
|
170
|
-
unarchive(threadId) {
|
|
171
|
-
const data = this._threadData.get(threadId);
|
|
172
|
-
if (!data) throw new Error("Thread not found");
|
|
173
|
-
if (data.status !== "archived") throw new Error("Thread is not archived");
|
|
174
|
-
this._stateOp(threadId, "regular");
|
|
175
|
-
return Promise.resolve();
|
|
176
|
-
}
|
|
177
|
-
delete(threadId) {
|
|
178
|
-
const data = this._threadData.get(threadId);
|
|
179
|
-
if (!data) throw new Error("Thread not found");
|
|
180
|
-
if (data.status !== "regular" && data.status !== "archived")
|
|
181
|
-
throw new Error("Thread is not yet initialized");
|
|
182
|
-
this._stateOp(threadId, "deleted");
|
|
183
|
-
return Promise.resolve();
|
|
74
|
+
rename() {
|
|
75
|
+
throw new Error("Method not implemented.");
|
|
184
76
|
}
|
|
185
|
-
|
|
77
|
+
archive() {
|
|
78
|
+
throw new Error("Method not implemented.");
|
|
79
|
+
}
|
|
80
|
+
unarchive() {
|
|
81
|
+
throw new Error("Method not implemented.");
|
|
82
|
+
}
|
|
83
|
+
delete() {
|
|
186
84
|
throw new Error("Method not implemented.");
|
|
187
85
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
this._subscriptions.add(callback);
|
|
191
|
-
return () => this._subscriptions.delete(callback);
|
|
86
|
+
initialize() {
|
|
87
|
+
throw new Error("Method not implemented.");
|
|
192
88
|
}
|
|
193
|
-
|
|
194
|
-
|
|
89
|
+
generateTitle() {
|
|
90
|
+
throw new Error("Method not implemented.");
|
|
195
91
|
}
|
|
196
92
|
};
|
|
197
93
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"sourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\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 status: \"new\" | \"regular\" | \"archived\";\n readonly threadId: string;\n readonly title?: string | undefined;\n};\n\nexport type LocalThreadFactory = () => LocalThreadRuntimeCore;\n\nconst RESOLVED_PROMISE = Promise.resolve();\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 getThreadRuntimeCore(threadId: string) {\n const result = this._threadData.get(threadId)?.runtime;\n if (!result) throw new Error(\"Thread not found.\");\n return result;\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return RESOLVED_PROMISE;\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.status === \"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();\n const dispose = runtime.unstable_on(\"initialize\", () => {\n dispose();\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 status: \"new\",\n threadId,\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 { status: 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 = [data.threadId, ...this._threadIds];\n break;\n\n case \"archived\":\n this._archivedThreadIds = [data.threadId, ...this._archivedThreadIds];\n break;\n\n case \"deleted\":\n this._threadData.delete(threadId);\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 status: 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.status !== \"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.status !== \"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.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n this._stateOp(threadId, \"deleted\");\n return Promise.resolve();\n }\n\n public initialize(): never {\n throw new Error(\"Method not implemented.\");\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;AAEA,qBAA2B;AAgB3B,IAAM,mBAAmB,QAAQ,QAAQ;AAClC,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;AAAA,EAEQ;AAAA,EAER,IAAW,eAAuB;AAChC,WAAO,KAAK;AAAA,EACd;AAAA,EAMO,2BAA2B;AAChC,UAAM,SAAS,KAAK,YAAY,IAAI,KAAK,aAAa,GAAG;AACzD,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,uDAAuD;AACzE,WAAO;AAAA,EACT;AAAA,EAEO,qBAAqB,UAAkB;AAC5C,UAAM,SAAS,KAAK,YAAY,IAAI,QAAQ,GAAG;AAC/C,QAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,mBAAmB;AAChD,WAAO;AAAA,EACT;AAAA,EAEO,wBAAuC;AAC5C,WAAO;AAAA,EACT;AAAA,EAEO,YAAY,UAAkB;AACnC,WAAO,KAAK,YAAY,IAAI,Q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,CAAC,KAAM,OAAM,IAAI,MAAM,kBAAkB;AAC7C,QAAI,KAAK,WAAW;AAClB,YAAM,IAAI,MAAM,mDAAmD;AAErE,SAAK,SAAS,UAAU,UAAU;AAClC,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEO,UAAU,UAAiC;AAChD,UAAM,OAAO,KAAK,YAAY,IAAI,QAAQ;AAC1C,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,kBAAkB;AAC7C,QAAI,KAAK,WAAW,WAAY,OAAM,IAAI,MAAM,wBAAwB;AAExE,SAAK,SAAS,UAAU,SAAS;AACjC,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEO,OAAO,UAAiC;AAC7C,UAAM,OAAO,KAAK,YAAY,IAAI,QAAQ;AAC1C,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,kBAAkB;AAC7C,QAAI,KAAK,WAAW,aAAa,KAAK,WAAW;AAC/C,YAAM,IAAI,MAAM,+BAA+B;AAEjD,SAAK,SAAS,UAAU,SAAS;AACjC,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEO,aAAoB;AACzB,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AAAA,EAEQ,iBAAiB,oBAAI,IAAgB;AAAA,EAEtC,UAAU,UAAmC;AAClD,SAAK,eAAe,IAAI,QAAQ;AAChC,WAAO,MAAM,KAAK,eAAe,OAAO,QAAQ;AAAA,EAClD;AAAA,EAEQ,qBAAqB;AAC3B,eAAW,YAAY,KAAK,eAAgB,UAAS;AAAA,EACvD;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"sourcesContent":["import { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { BaseSubscribable } from \"../remote-thread-list/BaseSubscribable\";\nimport { LocalThreadRuntimeCore } from \"./LocalThreadRuntimeCore\";\n\nexport type LocalThreadFactory = () => LocalThreadRuntimeCore;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nexport class LocalThreadListRuntimeCore\n extends BaseSubscribable\n implements ThreadListRuntimeCore\n{\n private _mainThread: LocalThreadRuntimeCore;\n constructor(_threadFactory: LocalThreadFactory) {\n super();\n\n this._mainThread = _threadFactory();\n }\n\n public getMainThreadRuntimeCore() {\n return this._mainThread;\n }\n\n public get newThreadId(): string {\n throw new Error(\"Method not implemented.\");\n }\n\n public get threadIds(): readonly string[] {\n throw EMPTY_ARRAY;\n }\n\n public get archivedThreadIds(): readonly string[] {\n throw EMPTY_ARRAY;\n }\n\n public get mainThreadId(): string {\n return \"__DEFAULT_ID__\";\n }\n\n public getThreadRuntimeCore(): never {\n throw new Error(\"Method not implemented.\");\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public getItemById(threadId: string) {\n if (threadId === this.mainThreadId) {\n return {\n status: \"regular\" as const,\n threadId: this.mainThreadId,\n remoteId: this.mainThreadId,\n externalId: undefined,\n title: undefined,\n isMain: true,\n };\n }\n throw new Error(\"Method not implemented\");\n }\n\n public async switchToThread(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public switchToNewThread(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public rename(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public archive(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public unarchive(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public delete(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public initialize(): never {\n throw new Error(\"Method not implemented.\");\n }\n\n public generateTitle(): never {\n throw new Error(\"Method not implemented.\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAAiC;AAKjC,IAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AAC7B,IAAM,6BAAN,cACG,yCAEV;AAAA,EACU;AAAA,EACR,YAAY,gBAAo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AC3C;AACF;","names":[]}
|
|
@@ -1,173 +1,69 @@
|
|
|
1
1
|
// src/runtimes/local/LocalThreadListRuntimeCore.tsx
|
|
2
|
-
import {
|
|
3
|
-
var
|
|
4
|
-
var LocalThreadListRuntimeCore = class {
|
|
2
|
+
import { BaseSubscribable } from "../remote-thread-list/BaseSubscribable.mjs";
|
|
3
|
+
var EMPTY_ARRAY = Object.freeze([]);
|
|
4
|
+
var LocalThreadListRuntimeCore = class extends BaseSubscribable {
|
|
5
|
+
_mainThread;
|
|
5
6
|
constructor(_threadFactory) {
|
|
6
|
-
|
|
7
|
-
this.
|
|
7
|
+
super();
|
|
8
|
+
this._mainThread = _threadFactory();
|
|
9
|
+
}
|
|
10
|
+
getMainThreadRuntimeCore() {
|
|
11
|
+
return this._mainThread;
|
|
8
12
|
}
|
|
9
|
-
_threadData = /* @__PURE__ */ new Map();
|
|
10
|
-
_threadIds = [];
|
|
11
|
-
_archivedThreadIds = [];
|
|
12
|
-
_newThreadId;
|
|
13
13
|
get newThreadId() {
|
|
14
|
-
|
|
14
|
+
throw new Error("Method not implemented.");
|
|
15
15
|
}
|
|
16
16
|
get threadIds() {
|
|
17
|
-
|
|
17
|
+
throw EMPTY_ARRAY;
|
|
18
18
|
}
|
|
19
19
|
get archivedThreadIds() {
|
|
20
|
-
|
|
20
|
+
throw EMPTY_ARRAY;
|
|
21
21
|
}
|
|
22
|
-
_mainThreadId;
|
|
23
22
|
get mainThreadId() {
|
|
24
|
-
return
|
|
23
|
+
return "__DEFAULT_ID__";
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!result)
|
|
29
|
-
throw new Error("Main thread not found. This is a bug in assistant-ui.");
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
getThreadRuntimeCore(threadId) {
|
|
33
|
-
const result = this._threadData.get(threadId)?.runtime;
|
|
34
|
-
if (!result) throw new Error("Thread not found.");
|
|
35
|
-
return result;
|
|
25
|
+
getThreadRuntimeCore() {
|
|
26
|
+
throw new Error("Method not implemented.");
|
|
36
27
|
}
|
|
37
28
|
getLoadThreadsPromise() {
|
|
38
|
-
|
|
29
|
+
throw new Error("Method not implemented.");
|
|
39
30
|
}
|
|
40
31
|
getItemById(threadId) {
|
|
41
|
-
|
|
32
|
+
if (threadId === this.mainThreadId) {
|
|
33
|
+
return {
|
|
34
|
+
status: "regular",
|
|
35
|
+
threadId: this.mainThreadId,
|
|
36
|
+
remoteId: this.mainThreadId,
|
|
37
|
+
externalId: void 0,
|
|
38
|
+
title: void 0,
|
|
39
|
+
isMain: true
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
throw new Error("Method not implemented");
|
|
42
43
|
}
|
|
43
|
-
async switchToThread(
|
|
44
|
-
|
|
45
|
-
const data = this._threadData.get(threadId);
|
|
46
|
-
if (!data) throw new Error("Thread not found");
|
|
47
|
-
if (data.status === "archived") await this.unarchive(threadId);
|
|
48
|
-
this._mainThreadId = data.threadId;
|
|
49
|
-
this._notifySubscribers();
|
|
44
|
+
async switchToThread() {
|
|
45
|
+
throw new Error("Method not implemented.");
|
|
50
46
|
}
|
|
51
47
|
switchToNewThread() {
|
|
52
|
-
|
|
53
|
-
let threadId;
|
|
54
|
-
do {
|
|
55
|
-
threadId = generateId();
|
|
56
|
-
} while (this._threadData.has(threadId));
|
|
57
|
-
const runtime = this._threadFactory();
|
|
58
|
-
const dispose = runtime.unstable_on("initialize", () => {
|
|
59
|
-
dispose();
|
|
60
|
-
const data = this._threadData.get(threadId);
|
|
61
|
-
if (!data) throw new Error("Thread not found");
|
|
62
|
-
this._stateOp(threadId, "regular");
|
|
63
|
-
});
|
|
64
|
-
this._threadData.set(threadId, {
|
|
65
|
-
runtime,
|
|
66
|
-
status: "new",
|
|
67
|
-
threadId
|
|
68
|
-
});
|
|
69
|
-
this._newThreadId = threadId;
|
|
70
|
-
}
|
|
71
|
-
this.switchToThread(this._newThreadId);
|
|
72
|
-
return Promise.resolve();
|
|
73
|
-
}
|
|
74
|
-
async _stateOp(threadId, newState) {
|
|
75
|
-
const data = this._threadData.get(threadId);
|
|
76
|
-
if (!data) throw new Error("Thread not found");
|
|
77
|
-
const { status: lastState } = data;
|
|
78
|
-
if (lastState === newState) return;
|
|
79
|
-
switch (lastState) {
|
|
80
|
-
case "new":
|
|
81
|
-
this._newThreadId = void 0;
|
|
82
|
-
break;
|
|
83
|
-
case "regular":
|
|
84
|
-
this._threadIds = this._threadIds.filter((t) => t !== threadId);
|
|
85
|
-
break;
|
|
86
|
-
case "archived":
|
|
87
|
-
this._archivedThreadIds = this._archivedThreadIds.filter(
|
|
88
|
-
(t) => t !== threadId
|
|
89
|
-
);
|
|
90
|
-
break;
|
|
91
|
-
default: {
|
|
92
|
-
const _exhaustiveCheck = lastState;
|
|
93
|
-
throw new Error(`Unsupported state: ${_exhaustiveCheck}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
switch (newState) {
|
|
97
|
-
case "regular":
|
|
98
|
-
this._threadIds = [data.threadId, ...this._threadIds];
|
|
99
|
-
break;
|
|
100
|
-
case "archived":
|
|
101
|
-
this._archivedThreadIds = [data.threadId, ...this._archivedThreadIds];
|
|
102
|
-
break;
|
|
103
|
-
case "deleted":
|
|
104
|
-
this._threadData.delete(threadId);
|
|
105
|
-
break;
|
|
106
|
-
default: {
|
|
107
|
-
const _exhaustiveCheck = newState;
|
|
108
|
-
throw new Error(`Unsupported state: ${_exhaustiveCheck}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (newState !== "deleted") {
|
|
112
|
-
this._threadData.set(threadId, {
|
|
113
|
-
...data,
|
|
114
|
-
status: newState
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (threadId === this._mainThreadId && (newState === "archived" || newState === "deleted")) {
|
|
118
|
-
const lastThreadId = this._threadIds[0];
|
|
119
|
-
if (lastThreadId) {
|
|
120
|
-
await this.switchToThread(lastThreadId);
|
|
121
|
-
} else {
|
|
122
|
-
await this.switchToNewThread();
|
|
123
|
-
}
|
|
124
|
-
} else {
|
|
125
|
-
this._notifySubscribers();
|
|
126
|
-
}
|
|
48
|
+
throw new Error("Method not implemented.");
|
|
127
49
|
}
|
|
128
|
-
rename(
|
|
129
|
-
|
|
130
|
-
if (!data) throw new Error("Thread not found");
|
|
131
|
-
this._threadData.set(threadId, {
|
|
132
|
-
...data,
|
|
133
|
-
title: newTitle
|
|
134
|
-
});
|
|
135
|
-
this._notifySubscribers();
|
|
136
|
-
return Promise.resolve();
|
|
137
|
-
}
|
|
138
|
-
archive(threadId) {
|
|
139
|
-
const data = this._threadData.get(threadId);
|
|
140
|
-
if (!data) throw new Error("Thread not found");
|
|
141
|
-
if (data.status !== "regular")
|
|
142
|
-
throw new Error("Thread is not yet initialized or already archived");
|
|
143
|
-
this._stateOp(threadId, "archived");
|
|
144
|
-
return Promise.resolve();
|
|
145
|
-
}
|
|
146
|
-
unarchive(threadId) {
|
|
147
|
-
const data = this._threadData.get(threadId);
|
|
148
|
-
if (!data) throw new Error("Thread not found");
|
|
149
|
-
if (data.status !== "archived") throw new Error("Thread is not archived");
|
|
150
|
-
this._stateOp(threadId, "regular");
|
|
151
|
-
return Promise.resolve();
|
|
152
|
-
}
|
|
153
|
-
delete(threadId) {
|
|
154
|
-
const data = this._threadData.get(threadId);
|
|
155
|
-
if (!data) throw new Error("Thread not found");
|
|
156
|
-
if (data.status !== "regular" && data.status !== "archived")
|
|
157
|
-
throw new Error("Thread is not yet initialized");
|
|
158
|
-
this._stateOp(threadId, "deleted");
|
|
159
|
-
return Promise.resolve();
|
|
50
|
+
rename() {
|
|
51
|
+
throw new Error("Method not implemented.");
|
|
160
52
|
}
|
|
161
|
-
|
|
53
|
+
archive() {
|
|
54
|
+
throw new Error("Method not implemented.");
|
|
55
|
+
}
|
|
56
|
+
unarchive() {
|
|
57
|
+
throw new Error("Method not implemented.");
|
|
58
|
+
}
|
|
59
|
+
delete() {
|
|
162
60
|
throw new Error("Method not implemented.");
|
|
163
61
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this._subscriptions.add(callback);
|
|
167
|
-
return () => this._subscriptions.delete(callback);
|
|
62
|
+
initialize() {
|
|
63
|
+
throw new Error("Method not implemented.");
|
|
168
64
|
}
|
|
169
|
-
|
|
170
|
-
|
|
65
|
+
generateTitle() {
|
|
66
|
+
throw new Error("Method not implemented.");
|
|
171
67
|
}
|
|
172
68
|
};
|
|
173
69
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"sourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\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 status: \"new\" | \"regular\" | \"archived\";\n readonly threadId: string;\n readonly title?: string | undefined;\n};\n\nexport type LocalThreadFactory = () => LocalThreadRuntimeCore;\n\nconst RESOLVED_PROMISE = Promise.resolve();\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 getThreadRuntimeCore(threadId: string) {\n const result = this._threadData.get(threadId)?.runtime;\n if (!result) throw new Error(\"Thread not found.\");\n return result;\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return RESOLVED_PROMISE;\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.status === \"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();\n const dispose = runtime.unstable_on(\"initialize\", () => {\n dispose();\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 status: \"new\",\n threadId,\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 { status: 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 = [data.threadId, ...this._threadIds];\n break;\n\n case \"archived\":\n this._archivedThreadIds = [data.threadId, ...this._archivedThreadIds];\n break;\n\n case \"deleted\":\n this._threadData.delete(threadId);\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 status: 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.status !== \"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.status !== \"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.status !== \"regular\" && data.status !== \"archived\")\n throw new Error(\"Thread is not yet initialized\");\n\n this._stateOp(threadId, \"deleted\");\n return Promise.resolve();\n }\n\n public initialize(): never {\n throw new Error(\"Method not implemented.\");\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":";AAEA,SAAS,kBAAkB;AAgB3B,IAAM,mBAAmB,QAAQ,QAAQ;AAClC,IAAM,6BAAN,MA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UAAiC;AAC7C,UAAM,OAAO,KAAK,YAAY,IAAI,QAAQ;AAC1C,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,kBAAkB;AAC7C,QAAI,KAAK,WAAW,aAAa,KAAK,WAAW;AAC/C,YAAM,IAAI,MAAM,+BAA+B;AAEjD,SAAK,SAAS,UAAU,SAAS;AACjC,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEO,aAAoB;AACzB,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AAAA,EAEQ,iBAAiB,oBAAI,IAAgB;AAAA,EAEtC,UAAU,UAAmC;AAClD,SAAK,eAAe,IAAI,QAAQ;AAChC,WAAO,MAAM,KAAK,eAAe,OAAO,QAAQ;AAAA,EAClD;AAAA,EAEQ,qBAAqB;AAC3B,eAAW,YAAY,KAAK,eAAgB,UAAS;AAAA,EACvD;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadListRuntimeCore.tsx"],"sourcesContent":["import { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { BaseSubscribable } from \"../remote-thread-list/BaseSubscribable\";\nimport { LocalThreadRuntimeCore } from \"./LocalThreadRuntimeCore\";\n\nexport type LocalThreadFactory = () => LocalThreadRuntimeCore;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nexport class LocalThreadListRuntimeCore\n extends BaseSubscribable\n implements ThreadListRuntimeCore\n{\n private _mainThread: LocalThreadRuntimeCore;\n constructor(_threadFactory: LocalThreadFactory) {\n super();\n\n this._mainThread = _threadFactory();\n }\n\n public getMainThreadRuntimeCore() {\n return this._mainThread;\n }\n\n public get newThreadId(): string {\n throw new Error(\"Method not implemented.\");\n }\n\n public get threadIds(): readonly string[] {\n throw EMPTY_ARRAY;\n }\n\n public get archivedThreadIds(): readonly string[] {\n throw EMPTY_ARRAY;\n }\n\n public get mainThreadId(): string {\n return \"__DEFAULT_ID__\";\n }\n\n public getThreadRuntimeCore(): never {\n throw new Error(\"Method not implemented.\");\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public getItemById(threadId: string) {\n if (threadId === this.mainThreadId) {\n return {\n status: \"regular\" as const,\n threadId: this.mainThreadId,\n remoteId: this.mainThreadId,\n externalId: undefined,\n title: undefined,\n isMain: true,\n };\n }\n throw new Error(\"Method not implemented\");\n }\n\n public async switchToThread(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public switchToNewThread(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public rename(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public archive(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public unarchive(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public delete(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public initialize(): never {\n throw new Error(\"Method not implemented.\");\n }\n\n public generateTitle(): never {\n throw new Error(\"Method not implemented.\");\n }\n}\n"],"mappings":";AACA,SAAS,wBAAwB;AAKjC,IAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AAC7B,IAAM,6BAAN,cACG,iBAEV;AAAA,EACU;AAAA,EACR,YAAY,gBAAoC;AAC9C,UAAM;AAEN,SAAK,cAAc,eAAe;AAAA,EACpC;AAAA,EAEO,2BAA2B;AAChC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,cAAsB;AAC/B,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AAAA,EAEA,IAAW,YAA+B;AACxC,UAAM;AAAA,EACR;AAAA,EAEA,IAAW,oBAAuC;AAChD,UAAM;AAAA,EACR;AAAA,EAEA,IAAW,eAAuB;AAChC,WAAO;AAAA,EACT;AAAA,EAEO,uBAA8B;AACnC,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AAAA,EAEO,wBAAuC;AAC5C,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AAAA,EAEO,YAAY,UAAkB;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AM;IAE9D,IAAW,QAAQ;;;;;;MAElB;gBAGC,eAAe,EAAE,oBAAoB,EACrC,OAAO,EAAE,uBAAuB;IAMlC,OAAO,CAAC,QAAQ,CAA2B;IAE3C,OAAO,CAAC,cAAc,CAAiB;IAEvC,IAAW,MAAM,cAEhB;IAEM,qBAAqB,CAAC,OAAO,EAAE,uBAAuB;IA4B7D,OAAO,CAAC,YAAY,CAA4B;IACzC,eAAe;IAcT,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB7C,QAAQ,CAAC,EACpB,QAAQ,EACR,SAAS,GACV,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;YAqCnB,gBAAgB;IAgJvB,SAAS;IAKT,aAAa,CAAC,EACnB,SAAS,EACT,UAAU,EACV,MAAM,GACP,EAAE,oBAAoB;CAwCxB"}
|
|
@@ -200,7 +200,10 @@ var LocalThreadRuntimeCore = class extends import_BaseThreadRuntimeCore.BaseThre
|
|
|
200
200
|
abortSignal: this.abortController.signal,
|
|
201
201
|
context,
|
|
202
202
|
config: context,
|
|
203
|
-
unstable_assistantMessageId: message.id
|
|
203
|
+
unstable_assistantMessageId: message.id,
|
|
204
|
+
unstable_getMessage() {
|
|
205
|
+
return message;
|
|
206
|
+
}
|
|
204
207
|
});
|
|
205
208
|
if (Symbol.asyncIterator in promiseOrGenerator) {
|
|
206
209
|
for await (const r of promiseOrGenerator) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type { AppendMessage, ThreadAssistantMessage } from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { RunConfig } from \"../../types/AssistantTypes\";\nimport { ModelContextProvider } from \"../../model-context\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n contextProvider: ModelContextProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(contextProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n private _loadPromise: Promise<void> | undefined;\n public __internal_load() {\n if (this._loadPromise) return this._loadPromise;\n\n const promise = this.adapters.history?.load() ?? Promise.resolve(null);\n\n this._loadPromise = promise.then((repo) => {\n if (!repo) return;\n this.repository.import(repo);\n this._notifySubscribers();\n });\n\n return this._loadPromise;\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n this._options.adapters.history?.append({\n parentId: message.parentId,\n message: newMessage,\n });\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun({\n parentId: newMessage.id,\n sourceId: message.sourceId,\n runConfig: message.runConfig ?? {},\n });\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun({\n parentId,\n runConfig,\n }: StartRunConfig): Promise<void> {\n this.ensureInitialized();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: {\n unstable_annotations: [],\n unstable_data: [],\n steps: [],\n custom: {},\n },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n try {\n do {\n message = await this.performRoundtrip(parentId, message, runConfig);\n } while (\n shouldContinue(\n message,\n this._options.unstable_shouldContinueIgnoreToolNames ?? [],\n )\n );\n } finally {\n this._notifyEventSubscribers(\"run-end\");\n }\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialAnnotations = message.metadata?.unstable_annotations;\n const initialData = message.metadata?.unstable_data;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n const newAnnotations = m.metadata?.unstable_annotations;\n const newData = m.metadata?.unstable_data;\n const annotations = newAnnotations\n ? [...(initialAnnotations ?? []), ...newAnnotations]\n : undefined;\n const data = newData ? [...(initialData ?? []), ...newData] : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(annotations\n ? { unstable_annotations: annotations }\n : undefined),\n ...(data ? { unstable_data: data } : undefined),\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const context = this.getModelContext();\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal: this.abortController.signal,\n context,\n config: context,\n unstable_assistantMessageId: message.id,\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"error\",\n error:\n e instanceof Error\n ? e.message\n : `[${typeof e}] ${new String(e).toString()}`,\n },\n });\n\n throw e;\n }\n } finally {\n if (\n message.status.type === \"complete\" ||\n message.status.type === \"incomplete\"\n ) {\n await this._options.adapters.history?.append({\n parentId,\n message: message,\n });\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (\n added &&\n shouldContinue(\n message,\n this._options.unstable_shouldContinueIgnoreToolNames ?? [],\n )\n ) {\n this.performRoundtrip(parentId, message, this._lastRunConfig);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA2B;AAE3B,kBAAgC;AAEhC,4BAA+B;AAQ/B,mCAAsC;AAI/B,IAAM,yBAAN,cACG,mDAEV;AAAA,EACkB,eAAe;AAAA,IAC7B,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEQ,kBAA0C;AAAA,EAElC,aAAa;AAAA,EACb,cAA2C,CAAC;AAAA,EAE5D,IAAW,WAAW;AACpB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YACE,iBACA,SACA;AACA,UAAM,eAAe;AACrB,SAAK,sBAAsB,OAAO;AAAA,EACpC;AAAA,EAEQ;AAAA,EAEA,iBAA4B,CAAC;AAAA,EAErC,IAAW,SAAS;AAClB,WAAO;AAAA,EACT;AAAA,EAEO,s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AAA,EACF,GAAyB;AACvB,UAAM,cAAc,KAAK,WAAW,WAAW,SAAS;AACxD,UAAM,EAAE,SAAS,IAAI;AACrB,QAAI,EAAE,QAAQ,IAAI;AAElB,QAAI,QAAQ,SAAS;AACnB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,QAAQ;AACZ,QAAI,QAAQ;AACZ,UAAM,aAAa,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAC5C,UAAI,EAAE,SAAS,YAAa,QAAO;AACnC,UAAI,EAAE,eAAe,WAAY,QAAO;AACxC,cAAQ;AACR,UAAI,CAAC,EAAE,OAAQ,SAAQ;AACvB,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,oDAAoD;AAEtE,cAAU;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AACA,SAAK,WAAW,mBAAmB,UAAU,OAAO;AAEpD,QACE,aACA;AAAA,MACE;AAAA,MACA,KAAK,SAAS,0CAA0C,CAAC;AAAA,IAC3D,GACA;AACA,WAAK,iBAAiB,UAAU,SAAS,KAAK,cAAc;AAAA,IAC9D;AAAA,EACF;AACF;","names":["steps"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/LocalThreadRuntimeCore.tsx"],"sourcesContent":["import { generateId } from \"../../internal\";\nimport type { AppendMessage, ThreadAssistantMessage } from \"../../types\";\nimport { fromCoreMessage } from \"../edge\";\nimport type { ChatModelRunResult } from \"./ChatModelAdapter\";\nimport { shouldContinue } from \"./shouldContinue\";\nimport { LocalRuntimeOptionsBase } from \"./LocalRuntimeOptions\";\nimport {\n AddToolResultOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\nimport { RunConfig } from \"../../types/AssistantTypes\";\nimport { ModelContextProvider } from \"../../model-context\";\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n private abortController: AbortController | null = null;\n\n public readonly isDisabled = false;\n public readonly suggestions: readonly ThreadSuggestion[] = [];\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n contextProvider: ModelContextProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(contextProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n private _loadPromise: Promise<void> | undefined;\n public __internal_load() {\n if (this._loadPromise) return this._loadPromise;\n\n const promise = this.adapters.history?.load() ?? Promise.resolve(null);\n\n this._loadPromise = promise.then((repo) => {\n if (!repo) return;\n this.repository.import(repo);\n this._notifySubscribers();\n });\n\n return this._loadPromise;\n }\n\n public async append(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const newMessage = fromCoreMessage(message, {\n attachments: message.attachments,\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n this._options.adapters.history?.append({\n parentId: message.parentId,\n message: newMessage,\n });\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun({\n parentId: newMessage.id,\n sourceId: message.sourceId,\n runConfig: message.runConfig ?? {},\n });\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async startRun({\n parentId,\n runConfig,\n }: StartRunConfig): Promise<void> {\n this.ensureInitialized();\n\n this.repository.resetHead(parentId);\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: {\n unstable_annotations: [],\n unstable_data: [],\n steps: [],\n custom: {},\n },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"run-start\");\n\n try {\n do {\n message = await this.performRoundtrip(parentId, message, runConfig);\n } while (\n shouldContinue(\n message,\n this._options.unstable_shouldContinueIgnoreToolNames ?? [],\n )\n );\n } finally {\n this._notifyEventSubscribers(\"run-end\");\n }\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n ) {\n const messages = this.repository.getMessages();\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialAnnotations = message.metadata?.unstable_annotations;\n const initialData = message.metadata?.unstable_data;\n const initialSteps = message.metadata?.steps;\n const initalCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n const newAnnotations = m.metadata?.unstable_annotations;\n const newData = m.metadata?.unstable_data;\n const annotations = newAnnotations\n ? [...(initialAnnotations ?? []), ...newAnnotations]\n : undefined;\n const data = newData ? [...(initialData ?? []), ...newData] : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(annotations\n ? { unstable_annotations: annotations }\n : undefined),\n ...(data ? { unstable_data: data } : undefined),\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.custom\n ? {\n custom: { ...(initalCustom ?? {}), ...m.metadata.custom },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const context = this.getModelContext();\n const promiseOrGenerator = this.adapters.chatModel.run({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal: this.abortController.signal,\n context,\n config: context,\n unstable_assistantMessageId: message.id,\n unstable_getMessage() {\n return message;\n },\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n this.abortController = null;\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n this.abortController = null;\n\n // TODO this should be handled by the run result stream\n if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"error\",\n error:\n e instanceof Error\n ? e.message\n : `[${typeof e}] ${new String(e).toString()}`,\n },\n });\n\n throw e;\n }\n } finally {\n if (\n message.status.type === \"complete\" ||\n message.status.type === \"incomplete\"\n ) {\n await this._options.adapters.history?.append({\n parentId,\n message: message,\n });\n }\n }\n return message;\n }\n\n public cancelRun() {\n this.abortController?.abort();\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (\n added &&\n shouldContinue(\n message,\n this._options.unstable_shouldContinueIgnoreToolNames ?? [],\n )\n ) {\n this.performRoundtrip(parentId, message, this._lastRunConfig);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA2B;AAE3B,kBAAgC;AAEhC,4BAA+B;AAQ/B,mCAAsC;AAI/B,IAAM,yBAAN,cACG,mDAEV;AAAA,EACkB,eAAe;AAAA,IAC7B,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEQ,kBAA0C;AAAA,EAElC,aAAa;AAAA,EACb,cAA2C,CAAC;AAAA,EAE5D,IAAW,WAAW;AACpB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YACE,iBACA,SACA;AACA,UAAM,eAAe;AACrB,SAAK,sBAAsB,OAAO;AAAA,EACpC;AAAA,EAEQ;AAAA,EAEA,iBAA4B,CAAC;AAAA,EAErC,IAAW,SAAS;AAClB,WAAO;AAAA,EACT;AAAA,EAEO,sBAAsB,SAAkC;AAC7D,QAAI,KAAK,aAAa,QAAS;AAE/B,SAAK,WAAW;AAEhB,QAAI,aAAa;AAEjB,UAAM,WAAW,QAAQ,UAAU,WAAW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AAS,IAAI;AACrB,QAAI,EAAE,QAAQ,IAAI;AAElB,QAAI,QAAQ,SAAS;AACnB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,QAAQ;AACZ,QAAI,QAAQ;AACZ,UAAM,aAAa,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAC5C,UAAI,EAAE,SAAS,YAAa,QAAO;AACnC,UAAI,EAAE,eAAe,WAAY,QAAO;AACxC,cAAQ;AACR,UAAI,CAAC,EAAE,OAAQ,SAAQ;AACvB,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,oDAAoD;AAEtE,cAAU;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,IACX;AACA,SAAK,WAAW,mBAAmB,UAAU,OAAO;AAEpD,QACE,aACA;AAAA,MACE;AAAA,MACA,KAAK,SAAS,0CAA0C,CAAC;AAAA,IAC3D,GACA;AACA,WAAK,iBAAiB,UAAU,SAAS,KAAK,cAAc;AAAA,IAC9D;AAAA,EACF;AACF;","names":["steps"]}
|
|
@@ -176,7 +176,10 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
176
176
|
abortSignal: this.abortController.signal,
|
|
177
177
|
context,
|
|
178
178
|
config: context,
|
|
179
|
-
unstable_assistantMessageId: message.id
|
|
179
|
+
unstable_assistantMessageId: message.id,
|
|
180
|
+
unstable_getMessage() {
|
|
181
|
+
return message;
|
|
182
|
+
}
|
|
180
183
|
});
|
|
181
184
|
if (Symbol.asyncIterator in promiseOrGenerator) {
|
|
182
185
|
for await (const r of promiseOrGenerator) {
|