@qvac/core 0.1.6 → 0.1.7
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/README.md +10 -5
- package/dist-lib/lib/api/chat-groups.d.ts +1 -1
- package/dist-lib/lib/api/chat-groups.js +6 -3
- package/dist-lib/lib/core/chat-group.d.ts +5 -0
- package/dist-lib/lib/core/chat-group.js +63 -1
- package/dist-lib/lib/core/chat.d.ts +10 -0
- package/dist-lib/lib/core/chat.js +75 -9
- package/dist-lib/lib/core/rank.d.ts +14 -0
- package/dist-lib/lib/core/rank.js +23 -0
- package/dist-lib/schema/engine.js +30 -0
- package/dist-lib/schema/field-order.js +3 -1
- package/dist-lib/schema/qvac.js +5 -2
- package/dist-lib/spec/bind.js +9 -0
- package/dist-lib/spec/calls.js +31 -28
- package/dist-lib/spec/capabilities.d.ts +6 -0
- package/dist-lib/spec/hrpc/hrpc.json +39 -0
- package/dist-lib/spec/hrpc/index.js +39 -3
- package/dist-lib/spec/hrpc/messages.js +63 -2
- package/dist-lib/spec/hyperschema/index.js +63 -2
- package/dist-lib/spec/hyperschema/schema.json +44 -1
- package/dist-lib/spec/hyperschema/types.d.ts +14 -1
- package/dist-lib/spec/mesh/hyperdb/messages.js +36 -14
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +19 -8
- package/dist-lib/spec/mesh/hyperschema/index.js +19 -8
- package/dist-lib/spec/mesh/hyperschema/schema.json +16 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +4 -1
- package/package.json +1 -1
- package/tui/app.mjs +95 -23
- package/tui/lib/sidebar.mjs +3 -2
package/README.md
CHANGED
|
@@ -245,11 +245,16 @@ The engine exposes a snapshot chat catalog:
|
|
|
245
245
|
const { chats } = await engine.listChats()
|
|
246
246
|
```
|
|
247
247
|
|
|
248
|
-
It returns complete, active mesh chat rows
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
248
|
+
It returns complete, active mesh chat rows in sidebar order, bottom first
|
|
249
|
+
(clients reverse to render): a chat sits where the user last dragged it
|
|
250
|
+
(`moveChat`) until a chunk lands in it, then most-recently-active wins; `id`
|
|
251
|
+
breaks ties. Groups ride the same frame, top first (`moveChatGroup` orders
|
|
252
|
+
them). Recency is derived from the chunk counter and costs no write, but it is
|
|
253
|
+
part of the row, so `chatsWatch` re-emits on any change to the rendered list:
|
|
254
|
+
create, rename, delete, flag, placement, or a chunk landing. The existing
|
|
255
|
+
replicated chat encoding uses zero as the default for an absent optional
|
|
256
|
+
`deletedAt`, so `deletedAt: 0` is not a representable tombstone and is treated
|
|
257
|
+
as active. Positive tombstone timestamps are excluded.
|
|
253
258
|
`listChats()` itself is a snapshot query. Chat create, update, delete, and watch
|
|
254
259
|
capabilities are available through the typed chat API.
|
|
255
260
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
2
2
|
import { type CurrentMesh } from './current-mesh.ts';
|
|
3
|
-
type ChatGroupCapabilities = Pick<CapabilityHandlers, 'createChatGroup' | 'listChatGroups' | 'renameChatGroup' | 'deleteChatGroup' | 'setChatGroup'>;
|
|
3
|
+
type ChatGroupCapabilities = Pick<CapabilityHandlers, 'createChatGroup' | 'listChatGroups' | 'renameChatGroup' | 'deleteChatGroup' | 'setChatGroup' | 'moveChat' | 'moveChatGroup' | 'sortChatGroupsByName'>;
|
|
4
4
|
export declare function createChatGroupsApi(current: CurrentMesh): ChatGroupCapabilities;
|
|
5
5
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createChatGroup, deleteChatGroup, listChatGroups, renameChatGroup } from "../core/chat-group.js";
|
|
2
|
-
import { setChatGroup } from "../core/chat.js";
|
|
1
|
+
import { createChatGroup, deleteChatGroup, listChatGroups, moveChatGroup, renameChatGroup, sortChatGroupsByName } from "../core/chat-group.js";
|
|
2
|
+
import { moveChat, setChatGroup } from "../core/chat.js";
|
|
3
3
|
import { requireMesh } from "./current-mesh.js";
|
|
4
4
|
export function createChatGroupsApi(current) {
|
|
5
5
|
return {
|
|
@@ -7,6 +7,9 @@ export function createChatGroupsApi(current) {
|
|
|
7
7
|
listChatGroups: async () => listChatGroups(await requireMesh(current)).then((groups) => ({ groups })),
|
|
8
8
|
renameChatGroup: async ({ id, name }) => renameChatGroup(await requireMesh(current), id, name),
|
|
9
9
|
deleteChatGroup: async ({ id }) => deleteChatGroup(await requireMesh(current), id),
|
|
10
|
-
setChatGroup: async ({ id, groupId }) => setChatGroup(await requireMesh(current), id, groupId)
|
|
10
|
+
setChatGroup: async ({ id, groupId }) => setChatGroup(await requireMesh(current), id, groupId),
|
|
11
|
+
moveChat: async ({ id, groupId, afterId }) => moveChat(await requireMesh(current), id, { groupId, afterId }),
|
|
12
|
+
moveChatGroup: async ({ id, afterId }) => moveChatGroup(await requireMesh(current), id, { afterId }),
|
|
13
|
+
sortChatGroupsByName: async () => sortChatGroupsByName(await requireMesh(current)).then((groups) => ({ groups }))
|
|
11
14
|
};
|
|
12
15
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type HyperDB from 'hyperdb';
|
|
2
2
|
import type { QvacChatGroup } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
3
3
|
import type { Mesh } from './mesh.ts';
|
|
4
|
+
export declare function groupSortKey(group: QvacChatGroup): number;
|
|
4
5
|
export declare function byGroupOrder(a: QvacChatGroup, b: QvacChatGroup): number;
|
|
5
6
|
export declare function listChatGroupsIn(snap: HyperDB): Promise<QvacChatGroup[]>;
|
|
6
7
|
export declare function listChatGroups(store: Mesh): Promise<QvacChatGroup[]>;
|
|
@@ -11,4 +12,8 @@ export declare function createChatGroup(store: Mesh, input: {
|
|
|
11
12
|
name: string;
|
|
12
13
|
}): Promise<QvacChatGroup>;
|
|
13
14
|
export declare function renameChatGroup(store: Mesh, id: string, name: string): Promise<QvacChatGroup>;
|
|
15
|
+
export declare function moveChatGroup(store: Mesh, id: string, { afterId }: {
|
|
16
|
+
afterId?: string | null;
|
|
17
|
+
}): Promise<QvacChatGroup>;
|
|
18
|
+
export declare function sortChatGroupsByName(store: Mesh): Promise<QvacChatGroup[]>;
|
|
14
19
|
export declare function deleteChatGroup(store: Mesh, id: string): Promise<QvacChatGroup>;
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { randomId } from "./id.js";
|
|
2
|
+
import { place } from "./rank.js";
|
|
2
3
|
const CHAT_GROUPS = '@qvac/chat-groups';
|
|
3
4
|
const ACTIVE_CHAT_GROUPS = '@qvac/active-chat-groups';
|
|
4
5
|
const NAME_MAX_LENGTH = 100;
|
|
6
|
+
export function groupSortKey(group) {
|
|
7
|
+
return group.rank || 0;
|
|
8
|
+
}
|
|
5
9
|
export function byGroupOrder(a, b) {
|
|
6
|
-
|
|
10
|
+
const ranked = groupSortKey(b) - groupSortKey(a);
|
|
11
|
+
if (ranked)
|
|
12
|
+
return ranked;
|
|
13
|
+
const an = a.name.toLowerCase();
|
|
14
|
+
const bn = b.name.toLowerCase();
|
|
15
|
+
if (an !== bn)
|
|
16
|
+
return an < bn ? -1 : 1;
|
|
17
|
+
return a.id < b.id ? -1 : 1;
|
|
7
18
|
}
|
|
8
19
|
export async function listChatGroupsIn(snap) {
|
|
9
20
|
const groups = await snap.find(ACTIVE_CHAT_GROUPS).toArray();
|
|
@@ -70,6 +81,57 @@ async function patchChatGroup(store, id, patch) {
|
|
|
70
81
|
export async function renameChatGroup(store, id, name) {
|
|
71
82
|
return patchChatGroup(store, id, { name: assertGroupName(name) });
|
|
72
83
|
}
|
|
84
|
+
export async function moveChatGroup(store, id, { afterId }) {
|
|
85
|
+
const anchor = afterId || undefined;
|
|
86
|
+
if (anchor === id)
|
|
87
|
+
throw new Error(`a chat group cannot be placed after itself: ${id}`);
|
|
88
|
+
const now = Date.now();
|
|
89
|
+
const snap = store.view.snapshot();
|
|
90
|
+
let current;
|
|
91
|
+
let placement;
|
|
92
|
+
try {
|
|
93
|
+
const group = await snap.get(CHAT_GROUPS, { id });
|
|
94
|
+
if (!group || group.deletedAt)
|
|
95
|
+
throw new Error(`chat group not found: ${id}`);
|
|
96
|
+
current = group;
|
|
97
|
+
const siblings = (await listChatGroupsIn(snap)).filter((sibling) => sibling.id !== id);
|
|
98
|
+
let at = -1;
|
|
99
|
+
if (anchor) {
|
|
100
|
+
at = siblings.findIndex((sibling) => sibling.id === anchor);
|
|
101
|
+
if (at === -1)
|
|
102
|
+
throw new Error(`chat group not found: ${anchor}`);
|
|
103
|
+
}
|
|
104
|
+
placement = place(siblings, groupSortKey, { at, now });
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
await snap.close();
|
|
108
|
+
}
|
|
109
|
+
const stamp = (row, rank) => ({
|
|
110
|
+
...row,
|
|
111
|
+
rank,
|
|
112
|
+
updatedAt: Math.max(now, row.updatedAt)
|
|
113
|
+
});
|
|
114
|
+
const batch = store.batch();
|
|
115
|
+
for (const { row, rank } of placement.respaced) {
|
|
116
|
+
batch.dispatch('put-chat-group', { group: stamp(row, rank) });
|
|
117
|
+
}
|
|
118
|
+
batch.dispatch('put-chat-group', { group: stamp(current, placement.rank) });
|
|
119
|
+
await batch.flush();
|
|
120
|
+
return mustGetActiveChatGroup(store, id);
|
|
121
|
+
}
|
|
122
|
+
export async function sortChatGroupsByName(store) {
|
|
123
|
+
const now = Date.now();
|
|
124
|
+
const batch = store.batch();
|
|
125
|
+
for (const group of await listChatGroups(store)) {
|
|
126
|
+
if (!group.rank)
|
|
127
|
+
continue;
|
|
128
|
+
batch.dispatch('put-chat-group', {
|
|
129
|
+
group: { ...group, rank: 0, updatedAt: Math.max(now, group.updatedAt) }
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
await batch.flush();
|
|
133
|
+
return listChatGroups(store);
|
|
134
|
+
}
|
|
73
135
|
export async function deleteChatGroup(store, id) {
|
|
74
136
|
const current = await mustGetChatGroup(store, id);
|
|
75
137
|
const now = Date.now();
|
|
@@ -8,12 +8,18 @@ export interface Sidebar {
|
|
|
8
8
|
readonly chats: ChatListing[];
|
|
9
9
|
readonly groups: QvacChatGroup[];
|
|
10
10
|
}
|
|
11
|
+
export declare function chatSortKey(chat: {
|
|
12
|
+
rank?: number;
|
|
13
|
+
rankedAt?: number;
|
|
14
|
+
lastActivityAt: number;
|
|
15
|
+
}): number;
|
|
11
16
|
export declare function liveGroupIds(snap: HyperDB): Promise<Set<string>>;
|
|
12
17
|
export declare function lastActivity(snap: HyperDB): Promise<Map<string, number>>;
|
|
13
18
|
export declare function enrichChat(store: Mesh, chat: QvacChat): Promise<ChatListing>;
|
|
14
19
|
export declare function enrichIn(snap: HyperDB, chat: QvacChat): Promise<ChatListing>;
|
|
15
20
|
export declare function enrichAll(chats: ReadonlyArray<QvacChat>, activity: Map<string, number>, liveGroups: Set<string>): ChatListing[];
|
|
16
21
|
export declare function listSidebar(store: Mesh): Promise<Sidebar>;
|
|
22
|
+
export declare function listSidebarIn(snap: HyperDB): Promise<Sidebar>;
|
|
17
23
|
export declare function listChats(store: Mesh): Promise<ChatListing[]>;
|
|
18
24
|
export declare function getChat(store: Mesh, id: string): Promise<QvacChat | null>;
|
|
19
25
|
export declare function mustGetChat(store: Mesh, id: string): Promise<QvacChat>;
|
|
@@ -30,6 +36,10 @@ export declare function createChat(store: Mesh, input: {
|
|
|
30
36
|
export declare function renameChat(store: Mesh, id: string, title: string): Promise<ChatListing>;
|
|
31
37
|
export declare function setChatRagEnabled(store: Mesh, id: string, ragEnabled: boolean): Promise<ChatListing>;
|
|
32
38
|
export declare function setChatGroup(store: Mesh, id: string, groupId: string | null | undefined): Promise<ChatListing>;
|
|
39
|
+
export declare function moveChat(store: Mesh, id: string, { groupId, afterId }: {
|
|
40
|
+
groupId?: string | null;
|
|
41
|
+
afterId?: string | null;
|
|
42
|
+
}): Promise<ChatListing>;
|
|
33
43
|
export declare function setChatWebSearchEnabled(store: Mesh, id: string, webSearchEnabled: boolean): Promise<ChatListing>;
|
|
34
44
|
export declare function removeChatKnowledge(store: Mesh, chatId: string, at: number): Promise<void>;
|
|
35
45
|
export declare function removeChatAttachments(store: Mesh, deviceId: Buffer, chatId: string, at: number): Promise<void>;
|
|
@@ -2,6 +2,7 @@ import { listChatGroupsIn, mustGetActiveChatGroup } from "./chat-group.js";
|
|
|
2
2
|
import { appendChunk, listChunks, updateOp } from "./chunk.js";
|
|
3
3
|
import { randomId } from "./id.js";
|
|
4
4
|
import { assertRemovableAt } from "./files/index.js";
|
|
5
|
+
import { place } from "./rank.js";
|
|
5
6
|
const CHATS = '@qvac/chats';
|
|
6
7
|
const CHAT_GROUPS = '@qvac/chat-groups';
|
|
7
8
|
const ACTIVE_CHATS = '@qvac/active-chats';
|
|
@@ -9,8 +10,11 @@ const ACTIVE_CHATS_BY_AGENT = '@qvac/active-chats-by-agent';
|
|
|
9
10
|
const ACTIVE_CHAT_GROUPS = '@qvac/active-chat-groups';
|
|
10
11
|
const CHUNK_COUNTERS = '@qvac/chunk-counters';
|
|
11
12
|
const TERMINAL_RUN_STATES = new Set(['completed', 'failed', 'canceled']);
|
|
13
|
+
export function chatSortKey(chat) {
|
|
14
|
+
return chat.rank && (chat.rankedAt ?? 0) >= chat.lastActivityAt ? chat.rank : chat.lastActivityAt;
|
|
15
|
+
}
|
|
12
16
|
function byChatOrder(a, b) {
|
|
13
|
-
return a
|
|
17
|
+
return chatSortKey(a) - chatSortKey(b) || (a.id < b.id ? -1 : 1);
|
|
14
18
|
}
|
|
15
19
|
export async function liveGroupIds(snap) {
|
|
16
20
|
const groups = await snap.find(ACTIVE_CHAT_GROUPS).toArray();
|
|
@@ -51,15 +55,18 @@ export function enrichAll(chats, activity, liveGroups) {
|
|
|
51
55
|
export async function listSidebar(store) {
|
|
52
56
|
const snap = store.view.snapshot();
|
|
53
57
|
try {
|
|
54
|
-
|
|
55
|
-
const [activity, groups] = await Promise.all([lastActivity(snap), listChatGroupsIn(snap)]);
|
|
56
|
-
const live = new Set(groups.map((group) => group.id));
|
|
57
|
-
return { chats: enrichAll(chats, activity, live).sort(byChatOrder), groups };
|
|
58
|
+
return await listSidebarIn(snap);
|
|
58
59
|
}
|
|
59
60
|
finally {
|
|
60
61
|
await snap.close();
|
|
61
62
|
}
|
|
62
63
|
}
|
|
64
|
+
export async function listSidebarIn(snap) {
|
|
65
|
+
const chats = await snap.find(ACTIVE_CHATS).toArray();
|
|
66
|
+
const [activity, groups] = await Promise.all([lastActivity(snap), listChatGroupsIn(snap)]);
|
|
67
|
+
const live = new Set(groups.map((group) => group.id));
|
|
68
|
+
return { chats: enrichAll(chats, activity, live).sort(byChatOrder), groups };
|
|
69
|
+
}
|
|
63
70
|
export async function listChats(store) {
|
|
64
71
|
return (await listSidebar(store)).chats;
|
|
65
72
|
}
|
|
@@ -107,7 +114,9 @@ export async function createChat(store, input) {
|
|
|
107
114
|
return listingOf(chat, false, undefined);
|
|
108
115
|
}
|
|
109
116
|
async function patchChat(store, id, patch) {
|
|
110
|
-
|
|
117
|
+
return patchChatRow(store, await mustGetActiveChat(store, id), patch);
|
|
118
|
+
}
|
|
119
|
+
async function patchChatRow(store, current, patch) {
|
|
111
120
|
const updated = { ...current, ...patch, updatedAt: Date.now() };
|
|
112
121
|
await store.dispatch('put-chat', { chat: updated });
|
|
113
122
|
return enrichChat(store, updated);
|
|
@@ -119,9 +128,66 @@ export function setChatRagEnabled(store, id, ragEnabled) {
|
|
|
119
128
|
return patchChat(store, id, { ragEnabled });
|
|
120
129
|
}
|
|
121
130
|
export async function setChatGroup(store, id, groupId) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
const target = groupId || undefined;
|
|
132
|
+
if (target)
|
|
133
|
+
await mustGetActiveChatGroup(store, target);
|
|
134
|
+
const current = await mustGetActiveChat(store, id);
|
|
135
|
+
const kept = (current.groupId || undefined) === target;
|
|
136
|
+
return patchChatRow(store, current, kept ? { groupId: target } : { groupId: target, rank: undefined, rankedAt: undefined });
|
|
137
|
+
}
|
|
138
|
+
export async function moveChat(store, id, { groupId, afterId }) {
|
|
139
|
+
const target = groupId || undefined;
|
|
140
|
+
const anchor = afterId || undefined;
|
|
141
|
+
if (anchor === id)
|
|
142
|
+
throw new Error(`a chat cannot be placed after itself: ${id}`);
|
|
143
|
+
const now = Date.now();
|
|
144
|
+
const snap = store.view.snapshot();
|
|
145
|
+
let moved;
|
|
146
|
+
let placement;
|
|
147
|
+
let stored;
|
|
148
|
+
try {
|
|
149
|
+
if (target) {
|
|
150
|
+
const group = await snap.get(CHAT_GROUPS, { id: target });
|
|
151
|
+
if (!group || group.deletedAt)
|
|
152
|
+
throw new Error(`chat group not found: ${target}`);
|
|
153
|
+
}
|
|
154
|
+
const { chats } = await listSidebarIn(snap);
|
|
155
|
+
const me = chats.find((chat) => chat.id === id);
|
|
156
|
+
if (!me)
|
|
157
|
+
throw new Error(`chat not found: ${id}`);
|
|
158
|
+
moved = me;
|
|
159
|
+
const siblings = chats
|
|
160
|
+
.filter((sibling) => sibling.id !== id && (sibling.groupId || undefined) === target)
|
|
161
|
+
.reverse();
|
|
162
|
+
let at = -1;
|
|
163
|
+
if (anchor) {
|
|
164
|
+
at = siblings.findIndex((sibling) => sibling.id === anchor);
|
|
165
|
+
if (at === -1) {
|
|
166
|
+
throw new Error(`chat ${anchor} is not in the ${target ? `group ${target}` : 'ungrouped list'}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
placement = place(siblings, chatSortKey, { at, now });
|
|
170
|
+
stored = new Map(await Promise.all(placement.respaced.map(async ({ row }) => [row.id, (await snap.get(CHATS, { id: row.id })) ?? row])));
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
await snap.close();
|
|
174
|
+
}
|
|
175
|
+
const stamp = (chat, lastActivityAt, rank) => ({
|
|
176
|
+
...chat,
|
|
177
|
+
rank,
|
|
178
|
+
rankedAt: Math.max(now, lastActivityAt),
|
|
179
|
+
updatedAt: Math.max(now, chat.updatedAt ?? 0)
|
|
180
|
+
});
|
|
181
|
+
const batch = store.batch();
|
|
182
|
+
for (const { row, rank } of placement.respaced) {
|
|
183
|
+
batch.dispatch('put-chat', { chat: stamp(stored.get(row.id), row.lastActivityAt, rank) });
|
|
184
|
+
}
|
|
185
|
+
const { lastActivityAt, ...chat } = moved;
|
|
186
|
+
batch.dispatch('put-chat', {
|
|
187
|
+
chat: { ...stamp(chat, lastActivityAt, placement.rank), groupId: target }
|
|
188
|
+
});
|
|
189
|
+
await batch.flush();
|
|
190
|
+
return enrichChat(store, await mustGetActiveChat(store, id));
|
|
125
191
|
}
|
|
126
192
|
export function setChatWebSearchEnabled(store, id, webSearchEnabled) {
|
|
127
193
|
return patchChat(store, id, { webSearchEnabled });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const STEP = 1000;
|
|
2
|
+
export interface Placement<T> {
|
|
3
|
+
rank: number;
|
|
4
|
+
respaced: Array<{
|
|
5
|
+
row: T;
|
|
6
|
+
rank: number;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
export declare function rankBetween(anchor: number, next: number | undefined): number;
|
|
10
|
+
export declare function rankOnTop(top: number | undefined, now: number): number;
|
|
11
|
+
export declare function place<T>(siblings: readonly T[], keyOf: (row: T) => number, { at, now }: {
|
|
12
|
+
at: number;
|
|
13
|
+
now: number;
|
|
14
|
+
}): Placement<T>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const FLOOR = 1;
|
|
2
|
+
export const STEP = 1_000;
|
|
3
|
+
const TOP_STEP = 1;
|
|
4
|
+
export function rankBetween(anchor, next) {
|
|
5
|
+
if (next === undefined)
|
|
6
|
+
return Math.max(anchor - STEP, FLOOR);
|
|
7
|
+
return anchor + (next - anchor) / 2;
|
|
8
|
+
}
|
|
9
|
+
export function rankOnTop(top, now) {
|
|
10
|
+
return top === undefined ? now : Math.max(top + TOP_STEP, now);
|
|
11
|
+
}
|
|
12
|
+
export function place(siblings, keyOf, { at, now }) {
|
|
13
|
+
const upper = at >= 0 ? keyOf(siblings[at]) : undefined;
|
|
14
|
+
const below = siblings[at + 1];
|
|
15
|
+
const lower = below === undefined ? undefined : keyOf(below);
|
|
16
|
+
const rank = upper === undefined ? rankOnTop(lower, now) : rankBetween(upper, lower);
|
|
17
|
+
if ((upper === undefined || rank < upper) && (lower === undefined || rank > lower)) {
|
|
18
|
+
return { rank, respaced: [] };
|
|
19
|
+
}
|
|
20
|
+
const top = Math.max(now, keyOf(siblings[0]));
|
|
21
|
+
const respaced = siblings.map((row, i) => ({ row, rank: top - (i > at ? i + 1 : i) * STEP }));
|
|
22
|
+
return { rank: top - (at + 1) * STEP, respaced };
|
|
23
|
+
}
|
|
@@ -260,6 +260,21 @@ export function registerEngineTypes(ns) {
|
|
|
260
260
|
{ name: 'groupId', type: 'string' }
|
|
261
261
|
]
|
|
262
262
|
});
|
|
263
|
+
ns.register({
|
|
264
|
+
name: 'move-chat-request',
|
|
265
|
+
fields: [
|
|
266
|
+
{ name: 'id', type: 'string', required: true },
|
|
267
|
+
{ name: 'groupId', type: 'string' },
|
|
268
|
+
{ name: 'afterId', type: 'string' }
|
|
269
|
+
]
|
|
270
|
+
});
|
|
271
|
+
ns.register({
|
|
272
|
+
name: 'move-chat-group-request',
|
|
273
|
+
fields: [
|
|
274
|
+
{ name: 'id', type: 'string', required: true },
|
|
275
|
+
{ name: 'afterId', type: 'string' }
|
|
276
|
+
]
|
|
277
|
+
});
|
|
263
278
|
ns.register({
|
|
264
279
|
name: 'tool-report-entry',
|
|
265
280
|
fields: [
|
|
@@ -2010,4 +2025,19 @@ export function registerEngineApi(api) {
|
|
|
2010
2025
|
request: { name: '@assistant/file-retry-request', stream: false },
|
|
2011
2026
|
response: { name: '@assistant/ok-response', stream: false }
|
|
2012
2027
|
});
|
|
2028
|
+
api.register({
|
|
2029
|
+
name: 'move-chat',
|
|
2030
|
+
request: { name: '@assistant/move-chat-request', stream: false },
|
|
2031
|
+
response: { name: '@assistant/chat', stream: false }
|
|
2032
|
+
});
|
|
2033
|
+
api.register({
|
|
2034
|
+
name: 'move-chat-group',
|
|
2035
|
+
request: { name: '@assistant/move-chat-group-request', stream: false },
|
|
2036
|
+
response: { name: '@assistant/chat-group', stream: false }
|
|
2037
|
+
});
|
|
2038
|
+
api.register({
|
|
2039
|
+
name: 'sort-chat-groups-by-name',
|
|
2040
|
+
request: { name: '@assistant/empty', stream: false },
|
|
2041
|
+
response: { name: '@assistant/chat-group-list', stream: false }
|
|
2042
|
+
});
|
|
2013
2043
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fs from 'bare-fs';
|
|
2
2
|
import { spawnSync } from 'bare-subprocess';
|
|
3
|
-
const EXEMPT = {
|
|
3
|
+
const EXEMPT = {
|
|
4
|
+
'@qvac/seed-defaults-operation-v1.chat': 'seedableChat allowlists the seed chat and leaves rank and rankedAt off it'
|
|
5
|
+
};
|
|
4
6
|
export function assertFieldOrder(root, schemaFile, tags) {
|
|
5
7
|
const current = index(JSON.parse(fs.readFileSync(schemaFile, 'utf8')).schema);
|
|
6
8
|
const seen = new Set();
|
package/dist-lib/schema/qvac.js
CHANGED
|
@@ -169,7 +169,9 @@ export function registerQvacTypes(ns) {
|
|
|
169
169
|
{ name: 'ragEnabled', type: 'bool' },
|
|
170
170
|
{ name: 'webSearchEnabled', type: 'bool' },
|
|
171
171
|
{ name: 'updatedAt', type: 'uint' },
|
|
172
|
-
{ name: 'groupId', type: 'string' }
|
|
172
|
+
{ name: 'groupId', type: 'string' },
|
|
173
|
+
{ name: 'rank', type: 'float64' },
|
|
174
|
+
{ name: 'rankedAt', type: 'uint' }
|
|
173
175
|
]);
|
|
174
176
|
ns.register({
|
|
175
177
|
name: 'tool-report-entry',
|
|
@@ -407,7 +409,8 @@ export function registerQvacTypes(ns) {
|
|
|
407
409
|
{ name: 'name', type: 'string', required: true },
|
|
408
410
|
{ name: 'createdAt', type: 'uint', required: true },
|
|
409
411
|
{ name: 'updatedAt', type: 'uint', required: true },
|
|
410
|
-
{ name: 'deletedAt', type: 'uint' }
|
|
412
|
+
{ name: 'deletedAt', type: 'uint' },
|
|
413
|
+
{ name: 'rank', type: 'float64' }
|
|
411
414
|
]);
|
|
412
415
|
versioned('put-chat-group-operation', [
|
|
413
416
|
{ name: 'group', type: '@qvac/chat-group', required: true }
|
package/dist-lib/spec/bind.js
CHANGED
|
@@ -517,4 +517,13 @@ export function bindApi(rpc, api) {
|
|
|
517
517
|
if (api.fileRetry) {
|
|
518
518
|
rpc.onFileRetry((req) => api.fileRetry(req));
|
|
519
519
|
}
|
|
520
|
+
if (api.moveChat) {
|
|
521
|
+
rpc.onMoveChat((req) => api.moveChat(req));
|
|
522
|
+
}
|
|
523
|
+
if (api.moveChatGroup) {
|
|
524
|
+
rpc.onMoveChatGroup((req) => api.moveChatGroup(req));
|
|
525
|
+
}
|
|
526
|
+
if (api.sortChatGroupsByName) {
|
|
527
|
+
rpc.onSortChatGroupsByName((req) => api.sortChatGroupsByName(req));
|
|
528
|
+
}
|
|
520
529
|
}
|
package/dist-lib/spec/calls.js
CHANGED
|
@@ -14,33 +14,33 @@ export function engineClient(rpc) {
|
|
|
14
14
|
configSet: (input) => rpc.configSet(input),
|
|
15
15
|
configWatch: (input) => armed(rpc.configWatch(input)),
|
|
16
16
|
createAgent: (input) => rpc.createAgent(input),
|
|
17
|
-
listAgents: (input) => rpc.listAgents(input),
|
|
17
|
+
listAgents: (input) => rpc.listAgents(input ?? {}),
|
|
18
18
|
getAgent: (input) => rpc.getAgent(input),
|
|
19
19
|
updateAgent: (input) => rpc.updateAgent(input),
|
|
20
20
|
deleteAgent: (input) => rpc.deleteAgent(input),
|
|
21
|
-
agentsWatch: (input) => armed(rpc.agentsWatch(input)),
|
|
21
|
+
agentsWatch: (input) => armed(rpc.agentsWatch(input ?? {})),
|
|
22
22
|
createChat: (input) => rpc.createChat(input),
|
|
23
|
-
listChats: (input) => rpc.listChats(input),
|
|
23
|
+
listChats: (input) => rpc.listChats(input ?? {}),
|
|
24
24
|
getChat: (input) => rpc.getChat(input),
|
|
25
25
|
renameChat: (input) => rpc.renameChat(input),
|
|
26
26
|
setChatRagEnabled: (input) => rpc.setChatRagEnabled(input),
|
|
27
27
|
setChatWebSearchEnabled: (input) => rpc.setChatWebSearchEnabled(input),
|
|
28
28
|
deleteChat: (input) => rpc.deleteChat(input),
|
|
29
|
-
chatsWatch: (input) => armed(rpc.chatsWatch(input)),
|
|
29
|
+
chatsWatch: (input) => armed(rpc.chatsWatch(input ?? {})),
|
|
30
30
|
createChatGroup: (input) => rpc.createChatGroup(input),
|
|
31
|
-
listChatGroups: (input) => rpc.listChatGroups(input),
|
|
31
|
+
listChatGroups: (input) => rpc.listChatGroups(input ?? {}),
|
|
32
32
|
renameChatGroup: (input) => rpc.renameChatGroup(input),
|
|
33
33
|
deleteChatGroup: (input) => rpc.deleteChatGroup(input),
|
|
34
34
|
setChatGroup: (input) => rpc.setChatGroup(input),
|
|
35
35
|
listChatActivity: (input) => rpc.listChatActivity(input),
|
|
36
36
|
chatActivityWatch: (input) => armed(rpc.chatActivityWatch(input)),
|
|
37
|
-
listDevices: (input) => rpc.listDevices(input),
|
|
38
|
-
devicesWatch: (input) => armed(rpc.devicesWatch(input)),
|
|
37
|
+
listDevices: (input) => rpc.listDevices(input ?? {}),
|
|
38
|
+
devicesWatch: (input) => armed(rpc.devicesWatch(input ?? {})),
|
|
39
39
|
saveDeviceCapabilities: (input) => rpc.saveDeviceCapabilities(input),
|
|
40
|
-
modelDownloadsWatch: (input) => armed(rpc.modelDownloadsWatch(input)),
|
|
40
|
+
modelDownloadsWatch: (input) => armed(rpc.modelDownloadsWatch(input ?? {})),
|
|
41
41
|
setModelDownloadStatus: (input) => rpc.setModelDownloadStatus(input),
|
|
42
42
|
clearModelDownload: (input) => rpc.clearModelDownload(input),
|
|
43
|
-
customModelsWatch: (input) => armed(rpc.customModelsWatch(input)),
|
|
43
|
+
customModelsWatch: (input) => armed(rpc.customModelsWatch(input ?? {})),
|
|
44
44
|
addCustomModel: (input) => rpc.addCustomModel(input),
|
|
45
45
|
removeCustomModel: (input) => rpc.removeCustomModel(input),
|
|
46
46
|
removeDevice: (input) => rpc.removeDevice(input),
|
|
@@ -62,43 +62,43 @@ export function engineClient(rpc) {
|
|
|
62
62
|
runAgent: (input) => rpc.runAgent(input),
|
|
63
63
|
sendMessage: (input) => rpc.sendMessage(input),
|
|
64
64
|
stopRun: (input) => rpc.stopRun(input),
|
|
65
|
-
meshStatusWatch: (input) => armed(rpc.meshStatusWatch(input)),
|
|
66
|
-
networkWatch: (input) => armed(rpc.networkWatch(input)),
|
|
67
|
-
deviceInfo: (input) => rpc.deviceInfo(input),
|
|
65
|
+
meshStatusWatch: (input) => armed(rpc.meshStatusWatch(input ?? {})),
|
|
66
|
+
networkWatch: (input) => armed(rpc.networkWatch(input ?? {})),
|
|
67
|
+
deviceInfo: (input) => rpc.deviceInfo(input ?? {}),
|
|
68
68
|
storeIdentityPhrase: (input) => rpc.storeIdentityPhrase(input),
|
|
69
|
-
leaveMesh: (input) => rpc.leaveMesh(input),
|
|
70
|
-
acknowledgeKicked: (input) => rpc.acknowledgeKicked(input),
|
|
69
|
+
leaveMesh: (input) => rpc.leaveMesh(input ?? {}),
|
|
70
|
+
acknowledgeKicked: (input) => rpc.acknowledgeKicked(input ?? {}),
|
|
71
71
|
joinMesh: (input) => rpc.joinMesh(input),
|
|
72
|
-
cancelMeshJoin: (input) => rpc.cancelMeshJoin(input),
|
|
73
|
-
suspend: (input) => rpc.suspend(input),
|
|
74
|
-
resume: (input) => rpc.resume(input),
|
|
75
|
-
meshInvite: (input) => rpc.meshInvite(input),
|
|
76
|
-
listApprovalRules: (input) => rpc.listApprovalRules(input),
|
|
77
|
-
diagnostics: (input) => rpc.diagnostics(input),
|
|
78
|
-
diagnosticsWatch: (input) => armed(rpc.diagnosticsWatch(input)),
|
|
79
|
-
runRequestsWatch: (input) => armed(rpc.runRequestsWatch(input)),
|
|
72
|
+
cancelMeshJoin: (input) => rpc.cancelMeshJoin(input ?? {}),
|
|
73
|
+
suspend: (input) => rpc.suspend(input ?? {}),
|
|
74
|
+
resume: (input) => rpc.resume(input ?? {}),
|
|
75
|
+
meshInvite: (input) => rpc.meshInvite(input ?? {}),
|
|
76
|
+
listApprovalRules: (input) => rpc.listApprovalRules(input ?? {}),
|
|
77
|
+
diagnostics: (input) => rpc.diagnostics(input ?? {}),
|
|
78
|
+
diagnosticsWatch: (input) => armed(rpc.diagnosticsWatch(input ?? {})),
|
|
79
|
+
runRequestsWatch: (input) => armed(rpc.runRequestsWatch(input ?? {})),
|
|
80
80
|
listModels: (input) => rpc.listModels(input),
|
|
81
81
|
deleteModel: (input) => rpc.deleteModel(input),
|
|
82
|
-
modelCatalogWatch: (input) => armed(rpc.modelCatalogWatch(input)),
|
|
82
|
+
modelCatalogWatch: (input) => armed(rpc.modelCatalogWatch(input ?? {})),
|
|
83
83
|
skills: (input) => rpc.skills(input),
|
|
84
84
|
downloadKnowledge: (input) => armed(rpc.downloadKnowledge(input)),
|
|
85
|
-
getConfig: (input) => rpc.getConfig(input),
|
|
85
|
+
getConfig: (input) => rpc.getConfig(input ?? {}),
|
|
86
86
|
setConfig: (input) => rpc.setConfig(input),
|
|
87
87
|
setModelPaused: (input) => rpc.setModelPaused(input),
|
|
88
88
|
retryModelDownload: (input) => rpc.retryModelDownload(input),
|
|
89
|
-
configWatchTyped: (input) => armed(rpc.configWatchTyped(input)),
|
|
89
|
+
configWatchTyped: (input) => armed(rpc.configWatchTyped(input ?? {})),
|
|
90
90
|
logsWatch: (input) => armed(rpc.logsWatch(input)),
|
|
91
91
|
writeLog: (input) => rpc.writeLog(input),
|
|
92
92
|
listIndexing: (input) => rpc.listIndexing(input),
|
|
93
93
|
transcribe: (input) => rpc.transcribe(input),
|
|
94
94
|
speak: (input) => rpc.speak(input),
|
|
95
95
|
skillCatalog: (input) => rpc.skillCatalog(input),
|
|
96
|
-
tools: (input) => rpc.tools(input),
|
|
96
|
+
tools: (input) => rpc.tools(input ?? {}),
|
|
97
97
|
speakStream: () => armed(rpc.speakStream()),
|
|
98
98
|
indexingProgressWatch: (input) => armed(rpc.indexingProgressWatch(input)),
|
|
99
99
|
indexingWatch: (input) => armed(rpc.indexingWatch(input)),
|
|
100
100
|
transcodeImage: (input) => rpc.transcodeImage(input),
|
|
101
|
-
syncStatusWatch: (input) => armed(rpc.syncStatusWatch(input)),
|
|
101
|
+
syncStatusWatch: (input) => armed(rpc.syncStatusWatch(input ?? {})),
|
|
102
102
|
setToolConfigs: (input) => rpc.setToolConfigs(input),
|
|
103
103
|
deleteToolConfigs: (input) => rpc.deleteToolConfigs(input),
|
|
104
104
|
listToolConfigs: (input) => rpc.listToolConfigs(input),
|
|
@@ -108,7 +108,7 @@ export function engineClient(rpc) {
|
|
|
108
108
|
listToolActivity: (input) => rpc.listToolActivity(input),
|
|
109
109
|
toolActivityWatch: (input) => armed(rpc.toolActivityWatch(input)),
|
|
110
110
|
recordToolActivity: (input) => rpc.recordToolActivity(input),
|
|
111
|
-
clearKvCache: (input) => rpc.clearKvCache(input),
|
|
111
|
+
clearKvCache: (input) => rpc.clearKvCache(input ?? {}),
|
|
112
112
|
listManagedSkills: (input) => rpc.listManagedSkills(input),
|
|
113
113
|
readSkillFile: (input) => rpc.readSkillFile(input),
|
|
114
114
|
writeSkillFile: (input) => rpc.writeSkillFile(input),
|
|
@@ -125,5 +125,8 @@ export function engineClient(rpc) {
|
|
|
125
125
|
fileRead: (input) => armed(rpc.fileRead(input)),
|
|
126
126
|
filePreview: (input) => rpc.filePreview(input),
|
|
127
127
|
fileRetry: (input) => rpc.fileRetry(input),
|
|
128
|
+
moveChat: (input) => rpc.moveChat(input),
|
|
129
|
+
moveChatGroup: (input) => rpc.moveChatGroup(input),
|
|
130
|
+
sortChatGroupsByName: (input) => rpc.sortChatGroupsByName(input ?? {}),
|
|
128
131
|
};
|
|
129
132
|
}
|
|
@@ -143,6 +143,9 @@ export interface Capabilities {
|
|
|
143
143
|
fileRead(input: T.AssistantFileReadRequest): WatchStream<T.AssistantFileReadFrame>
|
|
144
144
|
filePreview(input: T.AssistantFileRequest): Promise<T.AssistantFilePreviewResponse>
|
|
145
145
|
fileRetry(input: T.AssistantFileRetryRequest): Promise<T.AssistantOkResponse>
|
|
146
|
+
moveChat(input: T.AssistantMoveChatRequest): Promise<T.AssistantChat>
|
|
147
|
+
moveChatGroup(input: T.AssistantMoveChatGroupRequest): Promise<T.AssistantChatGroup>
|
|
148
|
+
sortChatGroupsByName(input?: T.AssistantEmpty): Promise<T.AssistantChatGroupList>
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
export interface CapabilityHandlers {
|
|
@@ -261,4 +264,7 @@ export interface CapabilityHandlers {
|
|
|
261
264
|
fileRead(input: T.AssistantFileReadRequest): AsyncIterable<T.AssistantFileReadFrame>
|
|
262
265
|
filePreview(input: T.AssistantFileRequest): T.AssistantFilePreviewResponse | Promise<T.AssistantFilePreviewResponse>
|
|
263
266
|
fileRetry(input: T.AssistantFileRetryRequest): T.AssistantOkResponse | Promise<T.AssistantOkResponse>
|
|
267
|
+
moveChat(input: T.AssistantMoveChatRequest): T.AssistantChat | Promise<T.AssistantChat>
|
|
268
|
+
moveChatGroup(input: T.AssistantMoveChatGroupRequest): T.AssistantChatGroup | Promise<T.AssistantChatGroup>
|
|
269
|
+
sortChatGroupsByName(input?: T.AssistantEmpty): T.AssistantChatGroupList | Promise<T.AssistantChatGroupList>
|
|
264
270
|
}
|
|
@@ -1495,6 +1495,45 @@
|
|
|
1495
1495
|
"stream": false
|
|
1496
1496
|
},
|
|
1497
1497
|
"version": 1
|
|
1498
|
+
},
|
|
1499
|
+
{
|
|
1500
|
+
"id": 115,
|
|
1501
|
+
"name": "@assistant/move-chat",
|
|
1502
|
+
"request": {
|
|
1503
|
+
"name": "@assistant/move-chat-request",
|
|
1504
|
+
"stream": false
|
|
1505
|
+
},
|
|
1506
|
+
"response": {
|
|
1507
|
+
"name": "@assistant/chat",
|
|
1508
|
+
"stream": false
|
|
1509
|
+
},
|
|
1510
|
+
"version": 1
|
|
1511
|
+
},
|
|
1512
|
+
{
|
|
1513
|
+
"id": 116,
|
|
1514
|
+
"name": "@assistant/move-chat-group",
|
|
1515
|
+
"request": {
|
|
1516
|
+
"name": "@assistant/move-chat-group-request",
|
|
1517
|
+
"stream": false
|
|
1518
|
+
},
|
|
1519
|
+
"response": {
|
|
1520
|
+
"name": "@assistant/chat-group",
|
|
1521
|
+
"stream": false
|
|
1522
|
+
},
|
|
1523
|
+
"version": 1
|
|
1524
|
+
},
|
|
1525
|
+
{
|
|
1526
|
+
"id": 117,
|
|
1527
|
+
"name": "@assistant/sort-chat-groups-by-name",
|
|
1528
|
+
"request": {
|
|
1529
|
+
"name": "@assistant/empty",
|
|
1530
|
+
"stream": false
|
|
1531
|
+
},
|
|
1532
|
+
"response": {
|
|
1533
|
+
"name": "@assistant/chat-group-list",
|
|
1534
|
+
"stream": false
|
|
1535
|
+
},
|
|
1536
|
+
"version": 1
|
|
1498
1537
|
}
|
|
1499
1538
|
]
|
|
1500
1539
|
}
|