feat(chat): support chat resources, implement chat-based remote discovery via resource messages
This commit is contained in:
1 parent
da1420d04b
commit
30afcf2803
10 files changed
+142
-85
No files matched your search
@@ -84,6 +84,7 @@
|
||||
for (let entry of messages.value) {
|
||||
if (entry.id == it.id) {
|
||||
entry.type = it.kind;
|
||||
entry.subkind = it.subkind;
|
||||
entry.format = it.format;
|
||||
entry.content = it.content;
|
||||
entry.threadId = it.threadId;
|
||||
@@ -109,6 +110,7 @@
|
||||
addMessage({
|
||||
id: it.id,
|
||||
type: it.kind,
|
||||
subkind: it.subkind,
|
||||
format: it.format,
|
||||
sender: it.sender,
|
||||
content: it.content,
|
||||
@@ -124,6 +126,7 @@
|
||||
//id: it.id,
|
||||
id: _messageNonce++,
|
||||
type: it.kind,
|
||||
subkind: it.subkind,
|
||||
sender: it.sender,
|
||||
content: it.content,
|
||||
threadId: it.threadId,
|
||||
@@ -296,8 +299,8 @@
|
||||
// New message object with updated name
|
||||
const message = Object.assign({}, _msg, {sender: senderName(_msg.sender)});
|
||||
|
||||
// Non-threaded messages and notes go directly to the entry list
|
||||
if (message.threadId == null || message.type == 'note') {
|
||||
// Non-threaded messages, notes, and resources go directly to the entry list
|
||||
if (message.threadId == null) {
|
||||
entries.push(message);
|
||||
|
||||
} else {
|
||||
@@ -343,6 +346,40 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function addRemoteResource () {
|
||||
const res = await backend.sendAction('remote-list');
|
||||
const remotes = res.remotes || [];
|
||||
if (remotes.length == 0) {
|
||||
ui.alert("No remotes connected");
|
||||
return;
|
||||
}
|
||||
|
||||
const selected = await ui.contextMenu(remotes.map(r => ({
|
||||
value: r.name,
|
||||
title: r.name + (r.description ? ` — ${r.description}` : ''),
|
||||
})));
|
||||
if (!selected) return;
|
||||
|
||||
const threadId = currentThreadId.value;
|
||||
backend.sendAction("send-chat-message", {
|
||||
chatId, content: selected, threadId,
|
||||
kind: 'resource', subkind: 'remote',
|
||||
}).then((response) => {
|
||||
if (response['error']) {
|
||||
ui.alert("Error adding remote: " + response['error']);
|
||||
}
|
||||
});
|
||||
|
||||
// Optimistic entry, matched against the server broadcast by content
|
||||
addMessage({
|
||||
type: 'resource',
|
||||
subkind: 'remote',
|
||||
sender: 'user',
|
||||
content: selected,
|
||||
threadId,
|
||||
}, {unsent: true});
|
||||
}
|
||||
|
||||
function editMessage (message) {
|
||||
let elem = inputFieldElem.value;
|
||||
if (message) {
|
||||
@@ -475,6 +512,9 @@
|
||||
<button @click="startNewThread()">
|
||||
New Thread
|
||||
</button>
|
||||
<button @click="addRemoteResource()">
|
||||
Add Remote
|
||||
</button>
|
||||
<button @click="noteMode=!noteMode">
|
||||
{{noteMode ? 'Cancel Note' : 'Make Note'}}
|
||||
</button>
|
||||
|
||||
Reference in new issue
Block a user