feat: connect chat and runs, cancellable chat messages, unified frontend runs module
This commit is contained in:
1 parent
d7e92f38f3
commit
bc71fa4d59
7 files changed
+244
-119
No files matched your search
@@ -9,6 +9,7 @@
|
||||
|
||||
import * as backend from '../backend';
|
||||
import * as ui from '../ui';
|
||||
import * as runs from '../runs';
|
||||
|
||||
const props = defineProps({
|
||||
id: {
|
||||
@@ -33,6 +34,7 @@
|
||||
const expandedThreads = ref({}); // Object<int: bool>, to simulate a Set<int>
|
||||
const editingMessageId = ref(null);
|
||||
const noteMode = ref(false);
|
||||
const messageRunMap = ref({});
|
||||
|
||||
const editInfo = computed(() => {
|
||||
if (editingMessageId.value != null) {
|
||||
@@ -50,6 +52,8 @@
|
||||
|
||||
let _isMounted = false;
|
||||
let unsubscribeChat = null;
|
||||
let unsubscribeRuns = null;
|
||||
let runListener = null;
|
||||
|
||||
// TODO: user sent message is added without id.
|
||||
// User should receive his own message notification, and find its message to assign it an id.
|
||||
@@ -110,6 +114,8 @@
|
||||
});
|
||||
});
|
||||
|
||||
unsubscribeRuns = runs.onChatMessage(chatId, onRunMessage);
|
||||
|
||||
let response = await backend.sendAction("get-chat-messages", {chatId});
|
||||
// Always good to duplicate when assigning to a ref
|
||||
messages.value = response.messages.map(it => ({
|
||||
@@ -147,6 +153,29 @@
|
||||
async function unloadChatState () {
|
||||
if (unsubscribeChat) unsubscribeChat();
|
||||
unsubscribeChat = null;
|
||||
if (unsubscribeRuns) unsubscribeRuns();
|
||||
unsubscribeRuns = null;
|
||||
}
|
||||
|
||||
function onRunMessage (event) {
|
||||
if (!runListener) {
|
||||
runListener = runs.addRunListener(onRunUpdate);
|
||||
}
|
||||
runListener.addRunId(event.runId);
|
||||
messageRunMap.value[event.messageId] = event.runId;
|
||||
ui.alert("Chat Run Message: " + JSON.stringify(event));
|
||||
}
|
||||
|
||||
function onRunUpdate (newRun) {
|
||||
if (newRun.done) {
|
||||
runListener.runIds.delete(newRun.id);
|
||||
let map = messageRunMap.value;
|
||||
for (let messageId in map) {
|
||||
if (map[messageId] == newRun.id) {
|
||||
delete map[messageId];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This won't fire when called, the mounted callback will take care
|
||||
@@ -428,6 +457,9 @@
|
||||
:message="msg"
|
||||
@open-menu="chatEntryContextMenu"
|
||||
@toggle-thread="expandThread"
|
||||
|
||||
:cancellable="messageRunMap[msg.id]"
|
||||
@cancel="runs.cancelRun(messageRunMap[msg.id])"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user