@qvac/core 1.0.0-rc.2 → 1.0.0-rc.3
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/CHANGELOG.md +158 -2
- package/dist-lib/index.d.ts +1 -0
- package/dist-lib/index.js +1 -0
- package/dist-lib/lib/api/chunk-delta.d.ts +7 -2
- package/dist-lib/lib/api/chunk-delta.js +89 -7
- package/dist-lib/lib/api/chunks.js +14 -8
- package/dist-lib/lib/api/config.d.ts +4 -1
- package/dist-lib/lib/api/config.js +45 -4
- package/dist-lib/lib/api/custom-models.js +3 -5
- package/dist-lib/lib/api/devices.js +3 -1
- package/dist-lib/lib/api/files.d.ts +1 -1
- package/dist-lib/lib/api/files.js +65 -8
- package/dist-lib/lib/api/instrument.js +12 -4
- package/dist-lib/lib/api/members.js +7 -13
- package/dist-lib/lib/api/mesh.d.ts +1 -3
- package/dist-lib/lib/api/mesh.js +2 -2
- package/dist-lib/lib/api/notifications.js +8 -4
- package/dist-lib/lib/api/projects.js +5 -1
- package/dist-lib/lib/api/rag.js +32 -19
- package/dist-lib/lib/api/served.js +2 -1
- package/dist-lib/lib/api/workspace.js +0 -1
- package/dist-lib/lib/assistant/harness.d.ts +8 -2
- package/dist-lib/lib/assistant/harness.js +17 -4
- package/dist-lib/lib/assistant/history.d.ts +1 -1
- package/dist-lib/lib/assistant/history.js +19 -13
- package/dist-lib/lib/assistant/message.d.ts +6 -1
- package/dist-lib/lib/assistant/message.js +22 -2
- package/dist-lib/lib/assistant/model-round.d.ts +5 -0
- package/dist-lib/lib/assistant/model-round.js +46 -18
- package/dist-lib/lib/assistant/pdf-budget.d.ts +10 -2
- package/dist-lib/lib/assistant/pdf-budget.js +10 -11
- package/dist-lib/lib/assistant/pdf-pages.d.ts +25 -0
- package/dist-lib/lib/assistant/pdf-pages.js +75 -0
- package/dist-lib/lib/assistant/round-host.js +5 -3
- package/dist-lib/lib/assistant-client.d.ts +2 -1
- package/dist-lib/lib/assistant-client.js +24 -6
- package/dist-lib/lib/assistant-tree.d.ts +2 -0
- package/dist-lib/lib/assistant-tree.js +8 -5
- package/dist-lib/lib/assistant.d.ts +20 -7
- package/dist-lib/lib/assistant.js +468 -240
- package/dist-lib/lib/client.js +10 -1
- package/dist-lib/lib/compaction.d.ts +3 -1
- package/dist-lib/lib/compaction.js +18 -4
- package/dist-lib/lib/constants.d.ts +3 -0
- package/dist-lib/lib/constants.js +3 -0
- package/dist-lib/lib/core/chat-activity.js +13 -16
- package/dist-lib/lib/core/chat-copy.js +1 -1
- package/dist-lib/lib/core/chat-fork.js +2 -1
- package/dist-lib/lib/core/chat-move.d.ts +4 -0
- package/dist-lib/lib/core/chat-move.js +42 -11
- package/dist-lib/lib/core/chat.d.ts +0 -1
- package/dist-lib/lib/core/chat.js +1 -1
- package/dist-lib/lib/core/chunk.d.ts +14 -3
- package/dist-lib/lib/core/chunk.js +112 -22
- package/dist-lib/lib/core/collections.d.ts +12 -1
- package/dist-lib/lib/core/collections.js +12 -1
- package/dist-lib/lib/core/config-value.d.ts +6 -0
- package/dist-lib/lib/core/config-value.js +14 -0
- package/dist-lib/lib/core/contract/activity.d.ts +3 -2
- package/dist-lib/lib/core/contract/activity.js +39 -21
- package/dist-lib/lib/core/contract/agent-join.js +15 -19
- package/dist-lib/lib/core/contract/agents.js +8 -7
- package/dist-lib/lib/core/contract/chat.d.ts +3 -0
- package/dist-lib/lib/core/contract/chat.js +12 -1
- package/dist-lib/lib/core/contract/chunks.js +16 -6
- package/dist-lib/lib/core/contract/devices.js +6 -4
- package/dist-lib/lib/core/contract/index.js +2 -1
- package/dist-lib/lib/core/contract/invites.js +12 -31
- package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
- package/dist-lib/lib/core/contract/mesh-rules.js +4 -0
- package/dist-lib/lib/core/contract/model-requests.js +7 -6
- package/dist-lib/lib/core/contract/project-device-keys.js +15 -6
- package/dist-lib/lib/core/contract/project-host-keys.js +5 -4
- package/dist-lib/lib/core/contract/projects.js +12 -13
- package/dist-lib/lib/core/contract/public-seeds.js +5 -5
- package/dist-lib/lib/core/contract/roles.js +2 -1
- package/dist-lib/lib/core/contract/run-requests.d.ts +1 -1
- package/dist-lib/lib/core/contract/run-requests.js +19 -13
- package/dist-lib/lib/core/contract/shipped-rows.d.ts +2 -0
- package/dist-lib/lib/core/contract/shipped-rows.js +22 -0
- package/dist-lib/lib/core/contract/workspace.js +4 -10
- package/dist-lib/lib/core/contract/writers.js +20 -6
- package/dist-lib/lib/core/devices.d.ts +2 -1
- package/dist-lib/lib/core/devices.js +4 -2
- package/dist-lib/lib/core/document-attachment.d.ts +6 -3
- package/dist-lib/lib/core/document-attachment.js +10 -5
- package/dist-lib/lib/core/files/attachments.js +3 -3
- package/dist-lib/lib/core/files/index.d.ts +8 -5
- package/dist-lib/lib/core/files/index.js +109 -18
- package/dist-lib/lib/core/files/processing/index.d.ts +1 -1
- package/dist-lib/lib/core/files/processing/index.js +8 -2
- package/dist-lib/lib/core/files/processing/source.d.ts +1 -0
- package/dist-lib/lib/core/files/processing/source.js +3 -0
- package/dist-lib/lib/core/files/processing/state.d.ts +1 -0
- package/dist-lib/lib/core/files/processing/state.js +7 -0
- package/dist-lib/lib/core/files/rag/build.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/build.js +14 -1
- package/dist-lib/lib/core/files/rag/index.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/index.js +1 -1
- package/dist-lib/lib/core/files/rag/produce.js +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +7 -1
- package/dist-lib/lib/core/first-event.d.ts +6 -0
- package/dist-lib/lib/core/first-event.js +13 -0
- package/dist-lib/lib/core/invite.d.ts +2 -2
- package/dist-lib/lib/core/invite.js +5 -4
- package/dist-lib/lib/core/local/index.d.ts +10 -1
- package/dist-lib/lib/core/local/index.js +105 -10
- package/dist-lib/lib/core/mesh.d.ts +15 -4
- package/dist-lib/lib/core/mesh.js +128 -57
- package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
- package/dist-lib/lib/core/migrations/chat-chunks.js +47 -0
- package/dist-lib/lib/core/migrations/file-index.d.ts +1 -1
- package/dist-lib/lib/core/migrations/file-index.js +6 -2
- package/dist-lib/lib/core/migrations/index.d.ts +2 -1
- package/dist-lib/lib/core/migrations/index.js +66 -9
- package/dist-lib/lib/core/notification.js +96 -23
- package/dist-lib/lib/core/pdf/figure.d.ts +22 -0
- package/dist-lib/lib/core/pdf/figure.js +64 -0
- package/dist-lib/lib/core/pdf/rasterize.d.ts +10 -1
- package/dist-lib/lib/core/pdf/rasterize.js +72 -22
- package/dist-lib/lib/core/peer-duplex.js +57 -5
- package/dist-lib/lib/core/public-mesh.js +8 -2
- package/dist-lib/lib/core/run-requests.js +2 -3
- package/dist-lib/lib/core/senders.d.ts +7 -6
- package/dist-lib/lib/core/senders.js +23 -30
- package/dist-lib/lib/core/shared-agents.d.ts +1 -0
- package/dist-lib/lib/core/shared-agents.js +47 -19
- package/dist-lib/lib/core/sync/background.d.ts +3 -15
- package/dist-lib/lib/core/sync/background.js +25 -102
- package/dist-lib/lib/core/sync/devices.js +6 -3
- package/dist-lib/lib/core/sync/index.js +12 -2
- package/dist-lib/lib/core/sync-status.js +3 -3
- package/dist-lib/lib/core.d.ts +59 -10
- package/dist-lib/lib/core.js +706 -174
- package/dist-lib/lib/credential-pusher.d.ts +11 -7
- package/dist-lib/lib/credential-pusher.js +40 -8
- package/dist-lib/lib/device-tree.d.ts +18 -0
- package/dist-lib/lib/device-tree.js +32 -0
- package/dist-lib/lib/doctor/redact.js +1 -1
- package/dist-lib/lib/errors.d.ts +4 -0
- package/dist-lib/lib/errors.js +4 -0
- package/dist-lib/lib/fs-drive-bridge.d.ts +7 -0
- package/dist-lib/lib/fs-drive-bridge.js +308 -30
- package/dist-lib/lib/integrations/setup-routes.js +7 -5
- package/dist-lib/lib/knowledge-search.d.ts +1 -1
- package/dist-lib/lib/knowledge-search.js +5 -46
- package/dist-lib/lib/kv-cache-retention.d.ts +35 -0
- package/dist-lib/lib/kv-cache-retention.js +98 -0
- package/dist-lib/lib/latest-frame.d.ts +10 -0
- package/dist-lib/lib/latest-frame.js +48 -0
- package/dist-lib/lib/model-download.d.ts +6 -1
- package/dist-lib/lib/model-download.js +32 -17
- package/dist-lib/lib/oauth/resolve.js +13 -5
- package/dist-lib/lib/reconnecting-watch.js +19 -11
- package/dist-lib/lib/run-notices.d.ts +2 -0
- package/dist-lib/lib/run-notices.js +5 -0
- package/dist-lib/lib/run-replay.d.ts +13 -1
- package/dist-lib/lib/run-replay.js +58 -21
- package/dist-lib/schema/build.js +66 -57
- package/dist-lib/schema/content.js +2 -1
- package/dist-lib/schema/engine.js +37 -5
- package/dist-lib/schema/field-order.js +7 -1
- package/dist-lib/schema/indexes.d.ts +4 -0
- package/dist-lib/schema/indexes.js +18 -0
- package/dist-lib/schema/local.js +9 -2
- package/dist-lib/schema/qvac.js +112 -4
- package/dist-lib/spec/bind.js +3 -0
- package/dist-lib/spec/calls.js +1 -0
- package/dist-lib/spec/capabilities.d.ts +2 -0
- package/dist-lib/spec/hrpc/hrpc.json +13 -0
- package/dist-lib/spec/hrpc/index.js +15 -3
- package/dist-lib/spec/hrpc/messages.js +1475 -1392
- package/dist-lib/spec/hyperschema/index.js +1475 -1392
- package/dist-lib/spec/hyperschema/schema.json +86 -1
- package/dist-lib/spec/hyperschema/types.d.ts +21 -1
- package/dist-lib/spec/local/hyperdb/messages.js +110 -54
- package/dist-lib/spec/local/hyperschema/index.js +56 -28
- package/dist-lib/spec/local/hyperschema/schema.json +55 -20
- package/dist-lib/spec/local/hyperschema/types.d.ts +8 -1
- package/dist-lib/spec/mesh/hyperdb/db.json +255 -51
- package/dist-lib/spec/mesh/hyperdb/index.js +1063 -404
- package/dist-lib/spec/mesh/hyperdb/messages.js +1647 -1214
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +62 -56
- package/dist-lib/spec/mesh/hyperdispatch/index.js +156 -139
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +787 -629
- package/dist-lib/spec/mesh/hyperschema/index.js +787 -629
- package/dist-lib/spec/mesh/hyperschema/schema.json +283 -174
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +29 -1
- package/package.json +23 -17
- package/worker/assistant-sidecar.mjs +3 -0
- package/dist-lib/lib/core/files/processing/settle.d.ts +0 -13
- package/dist-lib/lib/core/files/processing/settle.js +0 -86
- package/dist-lib/lib/core/migrations/device-indexes.d.ts +0 -2
- package/dist-lib/lib/core/migrations/device-indexes.js +0 -7
package/dist-lib/lib/client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ReadyResource from 'ready-resource';
|
|
2
2
|
import { reconnectingWatch } from './reconnecting-watch.js';
|
|
3
|
+
import { readConfigAnswer, readConfigFrames } from './api/config.js';
|
|
3
4
|
import { openLocalEngineSpec } from './spec-loader.js';
|
|
4
5
|
import { settleOnClose } from '@qvac/harness/rpc';
|
|
5
6
|
export class Client extends ReadyResource {
|
|
@@ -28,7 +29,15 @@ export class Client extends ReadyResource {
|
|
|
28
29
|
const modelDownloadsWatch = this._reconnecting(capabilities.modelDownloadsWatch, 'model-download');
|
|
29
30
|
const modelCatalogWatch = this._reconnecting(capabilities.modelCatalogWatch, 'model-catalog');
|
|
30
31
|
const modelsWatch = this._reconnecting(capabilities.modelsWatch, 'models');
|
|
31
|
-
|
|
32
|
+
const config = {
|
|
33
|
+
configGet: async (input) => readConfigAnswer(await capabilities.configGet(input)),
|
|
34
|
+
configWatch: (input) => readConfigFrames(capabilities.configWatch(input))
|
|
35
|
+
};
|
|
36
|
+
Object.assign(this, capabilities, config, {
|
|
37
|
+
modelCatalogWatch,
|
|
38
|
+
modelDownloadsWatch,
|
|
39
|
+
modelsWatch
|
|
40
|
+
});
|
|
32
41
|
this._log?.info('lifecycle', 'client open');
|
|
33
42
|
}
|
|
34
43
|
_reconnecting(open, scope) {
|
|
@@ -14,7 +14,9 @@ export interface CompactionBoundary {
|
|
|
14
14
|
throughId: string;
|
|
15
15
|
foldedTurns: number;
|
|
16
16
|
}
|
|
17
|
-
export declare function compactionBoundary(chunks: ReadonlyArray<AssistantChunk>, keepTurns?: number): CompactionBoundary | null;
|
|
17
|
+
export declare function compactionBoundary(chunks: ReadonlyArray<AssistantChunk>, keepTurns?: number, beforeSeq?: number): CompactionBoundary | null;
|
|
18
|
+
export declare function foldPosition(chunks: ReadonlyArray<AssistantChunk>): (chunk: AssistantChunk) => number;
|
|
19
|
+
export declare function foldsThrough(chunks: ReadonlyArray<AssistantChunk>, through: AssistantChunk): (chunk: AssistantChunk) => boolean;
|
|
18
20
|
export declare function lastCompactedThroughId(chunks: ReadonlyArray<AssistantChunk>): string | null;
|
|
19
21
|
export interface FoldedChunks {
|
|
20
22
|
chunks: ReadonlyArray<AssistantChunk>;
|
|
@@ -35,10 +35,10 @@ export function parseCompactionSummary(text) {
|
|
|
35
35
|
const summary = text.trim();
|
|
36
36
|
return summary.length > 0 ? summary : null;
|
|
37
37
|
}
|
|
38
|
-
export function compactionBoundary(chunks, keepTurns = COMPACTION_KEEP_TURNS) {
|
|
38
|
+
export function compactionBoundary(chunks, keepTurns = COMPACTION_KEEP_TURNS, beforeSeq = Infinity) {
|
|
39
39
|
const userTurns = [];
|
|
40
40
|
for (let index = 0; index < chunks.length; index++) {
|
|
41
|
-
if (chunks[index].userMessage) {
|
|
41
|
+
if (chunks[index].userMessage && chunks[index].seq < beforeSeq) {
|
|
42
42
|
userTurns.push(index);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -52,12 +52,25 @@ export function compactionBoundary(chunks, keepTurns = COMPACTION_KEEP_TURNS) {
|
|
|
52
52
|
from = index;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
const boundary = chunks[from - 1];
|
|
55
|
+
const boundary = chunks.slice(0, from).findLast((chunk) => chunk.type === 'run-request') ?? chunks[from - 1];
|
|
56
56
|
if (!boundary) {
|
|
57
57
|
return null;
|
|
58
58
|
}
|
|
59
59
|
return { throughId: boundary.id, foldedTurns: userTurns.length - keepTurns };
|
|
60
60
|
}
|
|
61
|
+
export function foldPosition(chunks) {
|
|
62
|
+
const requested = new Map();
|
|
63
|
+
for (const chunk of chunks) {
|
|
64
|
+
if (chunk.type === 'run-request' && chunk.runId && !requested.has(chunk.runId)) {
|
|
65
|
+
requested.set(chunk.runId, chunk.seq);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return (chunk) => (chunk.runId ? (requested.get(chunk.runId) ?? chunk.seq) : chunk.seq);
|
|
69
|
+
}
|
|
70
|
+
export function foldsThrough(chunks, through) {
|
|
71
|
+
const at = foldPosition(chunks);
|
|
72
|
+
return (chunk) => at(chunk) <= through.seq;
|
|
73
|
+
}
|
|
61
74
|
function newestCompaction(chunks) {
|
|
62
75
|
let newest = null;
|
|
63
76
|
for (const chunk of chunks) {
|
|
@@ -79,8 +92,9 @@ export function foldCompactedChunks(chunks) {
|
|
|
79
92
|
if (!through) {
|
|
80
93
|
return { chunks, summary: null };
|
|
81
94
|
}
|
|
95
|
+
const folded = foldsThrough(chunks, through);
|
|
82
96
|
return {
|
|
83
|
-
chunks: chunks.filter((chunk) => chunk
|
|
97
|
+
chunks: chunks.filter((chunk) => !folded(chunk) && !chunk.compaction),
|
|
84
98
|
summary: compaction.summary
|
|
85
99
|
};
|
|
86
100
|
}
|
|
@@ -9,5 +9,8 @@ export declare const MODEL_MEMORY_CAP_KEY = "model.memoryCapPercent";
|
|
|
9
9
|
export declare const MODEL_MEMORY_CAP_DEFAULT = 85;
|
|
10
10
|
export declare const MODEL_MEMORY_CAP_MIN = 10;
|
|
11
11
|
export declare const MODEL_MEMORY_CAP_MAX = 100;
|
|
12
|
+
export declare const KV_CACHE_RETENTION_KEY = "kvCache.retentionDays";
|
|
13
|
+
export declare const KV_CACHE_RETENTION_DAYS_DEFAULT = 14;
|
|
14
|
+
export declare const KV_CACHE_RETENTION_NEVER = 0;
|
|
12
15
|
export declare const FAKE_MODELS_KEY = "debug.fakeModels";
|
|
13
16
|
export declare const QUACK_MODEL = "quack";
|
|
@@ -11,5 +11,8 @@ export const MODEL_MEMORY_CAP_KEY = 'model.memoryCapPercent';
|
|
|
11
11
|
export const MODEL_MEMORY_CAP_DEFAULT = 85;
|
|
12
12
|
export const MODEL_MEMORY_CAP_MIN = 10;
|
|
13
13
|
export const MODEL_MEMORY_CAP_MAX = 100;
|
|
14
|
+
export const KV_CACHE_RETENTION_KEY = 'kvCache.retentionDays';
|
|
15
|
+
export const KV_CACHE_RETENTION_DAYS_DEFAULT = 14;
|
|
16
|
+
export const KV_CACHE_RETENTION_NEVER = 0;
|
|
14
17
|
export const FAKE_MODELS_KEY = 'debug.fakeModels';
|
|
15
18
|
export const QUACK_MODEL = 'quack';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
1
2
|
import ScopeLock from 'scope-lock';
|
|
2
|
-
import {
|
|
3
|
+
import { findChunksOfTypes } from './chunk.js';
|
|
3
4
|
import { ACTIVE_CHATS, CHUNKS } from './collections.js';
|
|
4
|
-
|
|
5
|
+
import { TERMINAL_RUN_STATES } from './contract/run-requests.js';
|
|
5
6
|
const ACTIVITY_CHUNK_TYPES = [
|
|
6
7
|
'run-request',
|
|
7
8
|
'run-status',
|
|
@@ -39,15 +40,16 @@ class ChatActivityCatalog {
|
|
|
39
40
|
try {
|
|
40
41
|
const head = store.view.db.head();
|
|
41
42
|
const forwards = store.autobee.stats.fastForwards;
|
|
42
|
-
|
|
43
|
-
this._head
|
|
44
|
-
|
|
45
|
-
this._forwards = forwards;
|
|
43
|
+
const from = forwards === this._forwards && this._head && head && b4a.equals(this._head.key, head.key)
|
|
44
|
+
? this._head
|
|
45
|
+
: null;
|
|
46
46
|
const snap = store.view.snapshot();
|
|
47
47
|
try {
|
|
48
48
|
const chats = await snap.find(ACTIVE_CHATS).toArray();
|
|
49
49
|
const activeChatIds = new Set(chats.map((chat) => chat.id));
|
|
50
|
-
await this._refresh(snap,
|
|
50
|
+
await this._refresh(snap, from, activeChatIds);
|
|
51
|
+
this._head = head;
|
|
52
|
+
this._forwards = forwards;
|
|
51
53
|
const window = chatIds && chatIds.length > 0 ? new Set(chatIds) : null;
|
|
52
54
|
return [...this._states()]
|
|
53
55
|
.filter(([id]) => !window || window.has(id))
|
|
@@ -62,18 +64,17 @@ class ChatActivityCatalog {
|
|
|
62
64
|
this._lock.unlock();
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
|
-
async _refresh(snap,
|
|
66
|
-
if (!
|
|
67
|
+
async _refresh(snap, from, activeChatIds) {
|
|
68
|
+
if (!from) {
|
|
67
69
|
await this._rebuild(snap, activeChatIds);
|
|
68
70
|
}
|
|
69
71
|
else {
|
|
70
72
|
this._prune(activeChatIds);
|
|
71
73
|
await this._loadMissing(snap, activeChatIds);
|
|
72
|
-
if (!(await this._applyChanges(snap,
|
|
74
|
+
if (!(await this._applyChanges(snap, from, activeChatIds))) {
|
|
73
75
|
await this._rebuild(snap, activeChatIds);
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
|
-
this._head = head;
|
|
77
78
|
}
|
|
78
79
|
async _rebuild(snap, activeChatIds) {
|
|
79
80
|
this._chats.clear();
|
|
@@ -98,7 +99,7 @@ class ChatActivityCatalog {
|
|
|
98
99
|
async _loadChat(snap, chatId) {
|
|
99
100
|
const activity = { runs: new Map() };
|
|
100
101
|
this._chats.set(chatId, activity);
|
|
101
|
-
for (const chunk of await
|
|
102
|
+
for (const chunk of await findChunksOfTypes(snap, { chatId, types: ACTIVITY_CHUNK_TYPES })) {
|
|
102
103
|
applyChunk(activity, chunk);
|
|
103
104
|
}
|
|
104
105
|
}
|
|
@@ -263,10 +264,6 @@ function applyApproval(run, chunk) {
|
|
|
263
264
|
run.pendingApprovals.delete(chunk.id);
|
|
264
265
|
}
|
|
265
266
|
}
|
|
266
|
-
async function activityChunks(snap, chatId) {
|
|
267
|
-
const groups = await Promise.all(ACTIVITY_CHUNK_TYPES.map((type) => findChunksOfType(snap, { chatId, type })));
|
|
268
|
-
return groups.flat().sort((left, right) => left.seq - right.seq);
|
|
269
|
-
}
|
|
270
267
|
function settleTool(tools, name) {
|
|
271
268
|
for (let index = tools.length - 1; index >= 0; index -= 1) {
|
|
272
269
|
if (tools[index]?.name !== name)
|
|
@@ -2,7 +2,7 @@ import b4a from 'b4a';
|
|
|
2
2
|
import { PENDING_BLOB_REFERENCE, isPendingBlobReference, parseBlobReference } from './files/store/index.js';
|
|
3
3
|
import { CoreError } from '../errors.js';
|
|
4
4
|
import { inlineReference } from './files/store/inline.js';
|
|
5
|
-
import { TERMINAL_RUN_STATES } from './
|
|
5
|
+
import { TERMINAL_RUN_STATES } from './contract/run-requests.js';
|
|
6
6
|
import { appendChunk, ownedByUs, updateOp } from './chunk.js';
|
|
7
7
|
import { runRequestOf } from './contract/chunks.js';
|
|
8
8
|
import { ACTIVE_AGENTS, AGENTS, CHATS, CHAT_GROUPS, CHUNKS, CHUNKS_BY_CHAT, DEVICES, KNOWLEDGE, KNOWLEDGE_ARTIFACTS, KNOWLEDGE_BY_CHAT, PURGED_CHATS, TOOL_ACTIVITY } from './collections.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { CoreError } from '../errors.js';
|
|
3
3
|
import { landingAgentId, mustGetActiveAgent } from './agent.js';
|
|
4
|
-
import {
|
|
4
|
+
import { enrichChat, listSidebar } from './chat.js';
|
|
5
|
+
import { TERMINAL_RUN_STATES } from './contract/run-requests.js';
|
|
5
6
|
import { chunksOf, copyBlob, removedReference, sentBy, stripped } from './chat-copy.js';
|
|
6
7
|
import { chatSortKey } from './chat-order.js';
|
|
7
8
|
import { isPendingBlobReference } from './files/index.js';
|
|
@@ -6,6 +6,7 @@ import type { openLocalStore } from './local/index.ts';
|
|
|
6
6
|
export declare const CHAT_MOVED = "chat-moved";
|
|
7
7
|
export declare const SOURCE_GONE = "the chat was deleted before its files arrived";
|
|
8
8
|
export declare const TARGET_GONE = "the moved chat was deleted before its files arrived";
|
|
9
|
+
export declare const TARGET_REVOKED = "you were removed from the target before its files arrived";
|
|
9
10
|
export declare const NOT_CARRIED = "a file could not be carried into the target";
|
|
10
11
|
export declare const OTHERS_RUN = "another member's move left a run in the target that only they can finish";
|
|
11
12
|
type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
|
|
@@ -35,6 +36,7 @@ export declare class ChatMoves {
|
|
|
35
36
|
unwatch(listener: () => void): void;
|
|
36
37
|
move(request: AssistantMoveChatToMeshRequest): Promise<AssistantChatMove>;
|
|
37
38
|
status({ meshId, chatId }: AssistantChatId): Promise<AssistantChatMove>;
|
|
39
|
+
private _pairOf;
|
|
38
40
|
resume(): Promise<void>;
|
|
39
41
|
close(): Promise<void>;
|
|
40
42
|
private _begin;
|
|
@@ -57,6 +59,8 @@ export declare class ChatMoves {
|
|
|
57
59
|
private _fetch;
|
|
58
60
|
private _owns;
|
|
59
61
|
private _gone;
|
|
62
|
+
private _revoked;
|
|
63
|
+
private _sourceDropped;
|
|
60
64
|
private _left;
|
|
61
65
|
private _giveUp;
|
|
62
66
|
private _dropPending;
|
|
@@ -3,18 +3,21 @@ import { AbortController } from 'bare-abort-controller';
|
|
|
3
3
|
import { AbortedError } from '@qvac/harness/race-abort';
|
|
4
4
|
import { getAgent, landingAgentId } from './agent.js';
|
|
5
5
|
import { accountPicks } from './shared-agents.js';
|
|
6
|
-
import {
|
|
6
|
+
import { cancelActiveRuns, deleteChat, getChat, mustGetActiveChat } from './chat.js';
|
|
7
|
+
import { TERMINAL_RUN_STATES } from './contract/run-requests.js';
|
|
7
8
|
import { copyMovedChunks, copyMovedKnowledge, movedBlob, stripped } from './chat-copy.js';
|
|
8
9
|
import { ownReadThrough } from './chat-read.js';
|
|
9
10
|
import { appendChunk, getChunk, listChunks, updateOp } from './chunk.js';
|
|
10
11
|
import { derivedId } from './id.js';
|
|
11
12
|
import { isPendingBlobReference } from './files/index.js';
|
|
12
|
-
import {
|
|
13
|
+
import { isOwnRevokedRow } from './helpers/index.js';
|
|
14
|
+
import { CoreError, isCoreError } from '../errors.js';
|
|
13
15
|
import { errorMessage } from '../guards.js';
|
|
14
16
|
import { CHATS, CHAT_READS, DEVICES, KNOWLEDGE, KNOWLEDGE_BY_CHAT } from './collections.js';
|
|
15
17
|
export const CHAT_MOVED = 'chat-moved';
|
|
16
18
|
export const SOURCE_GONE = 'the chat was deleted before its files arrived';
|
|
17
19
|
export const TARGET_GONE = 'the moved chat was deleted before its files arrived';
|
|
20
|
+
export const TARGET_REVOKED = 'you were removed from the target before its files arrived';
|
|
18
21
|
export const NOT_CARRIED = 'a file could not be carried into the target';
|
|
19
22
|
export const OTHERS_RUN = "another member's move left a run in the target that only they can finish";
|
|
20
23
|
export class ChatMoves {
|
|
@@ -65,13 +68,7 @@ export class ChatMoves {
|
|
|
65
68
|
if (!row) {
|
|
66
69
|
throw new CoreError('CHAT_MOVE_NOT_FOUND');
|
|
67
70
|
}
|
|
68
|
-
const
|
|
69
|
-
const pair = settled
|
|
70
|
-
? null
|
|
71
|
-
: {
|
|
72
|
-
source: await this._open(hex(row.meshKey)),
|
|
73
|
-
target: await this._open(hex(row.targetMeshKey))
|
|
74
|
-
};
|
|
71
|
+
const pair = row.completedAt || row.failure ? null : await this._pairOf(row);
|
|
75
72
|
const waiting = pair ? filesOf(await waitingFiles(pair, row)) : [];
|
|
76
73
|
return {
|
|
77
74
|
meshId,
|
|
@@ -86,6 +83,20 @@ export class ChatMoves {
|
|
|
86
83
|
failure: row.failure ?? undefined
|
|
87
84
|
};
|
|
88
85
|
}
|
|
86
|
+
async _pairOf(row) {
|
|
87
|
+
try {
|
|
88
|
+
return {
|
|
89
|
+
source: await this._open(hex(row.meshKey)),
|
|
90
|
+
target: await this._open(hex(row.targetMeshKey))
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
if (isCoreError(err, 'MESH_NOT_FOUND')) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
89
100
|
async resume() {
|
|
90
101
|
for (const row of await this._local.listChatMoves()) {
|
|
91
102
|
if (!row.completedAt && !row.failure) {
|
|
@@ -359,6 +370,9 @@ export class ChatMoves {
|
|
|
359
370
|
return SOURCE_GONE;
|
|
360
371
|
if (await this._left(target))
|
|
361
372
|
return TARGET_GONE;
|
|
373
|
+
if (await this._revoked(target)) {
|
|
374
|
+
return TARGET_REVOKED;
|
|
375
|
+
}
|
|
362
376
|
const chat = await getChat(source, row.chatId);
|
|
363
377
|
if (!chat || chat.deletedAt) {
|
|
364
378
|
return SOURCE_GONE;
|
|
@@ -366,11 +380,26 @@ export class ChatMoves {
|
|
|
366
380
|
const moved = await getChat(target, row.targetChatId);
|
|
367
381
|
return moved?.deletedAt ? TARGET_GONE : null;
|
|
368
382
|
}
|
|
383
|
+
async _revoked(mesh) {
|
|
384
|
+
const own = await mesh.view.get(DEVICES, { id: this._deviceId });
|
|
385
|
+
return !!own && isOwnRevokedRow(mesh, own);
|
|
386
|
+
}
|
|
387
|
+
async _sourceDropped(row) {
|
|
388
|
+
try {
|
|
389
|
+
return await this._left(await this._open(hex(row.meshKey)));
|
|
390
|
+
}
|
|
391
|
+
catch (err) {
|
|
392
|
+
if (isCoreError(err, 'MESH_NOT_FOUND')) {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
throw err;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
369
398
|
async _left(mesh) {
|
|
370
399
|
return mesh.role !== 'public' && !(await this._local.readMeshSession(mesh.key));
|
|
371
400
|
}
|
|
372
401
|
async _giveUp(pair, row, reason) {
|
|
373
|
-
if (reason === TARGET_GONE) {
|
|
402
|
+
if (reason === TARGET_GONE || reason === TARGET_REVOKED) {
|
|
374
403
|
await this._patch(row, { failure: reason });
|
|
375
404
|
return;
|
|
376
405
|
}
|
|
@@ -430,7 +459,9 @@ export class ChatMoves {
|
|
|
430
459
|
const write = this._patching.then(async () => {
|
|
431
460
|
const stored = (await this._local.readChatMove(row.meshKey, row.chatId)) ?? row;
|
|
432
461
|
const next = { ...stored, ...(typeof patch === 'function' ? patch(stored) : patch) };
|
|
433
|
-
|
|
462
|
+
const settled = !!(next.completedAt || next.failure);
|
|
463
|
+
const dropped = settled && (await this._sourceDropped(next));
|
|
464
|
+
await (dropped ? this._local.dropChatMove(next) : this._local.recordChatMove(next));
|
|
434
465
|
if (!quiet) {
|
|
435
466
|
this._changed();
|
|
436
467
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type HyperDB from 'hyperdb';
|
|
2
2
|
import type { QvacChat, QvacChatSuggestion, QvacChatGroup } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
3
3
|
import type { Mesh } from './mesh.ts';
|
|
4
|
-
export declare const TERMINAL_RUN_STATES: ReadonlySet<string>;
|
|
5
4
|
export interface ChatListing extends QvacChat {
|
|
6
5
|
readonly lastActivityAt: number;
|
|
7
6
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CoreError } from '../errors.js';
|
|
2
|
+
import { TERMINAL_RUN_STATES } from './contract/run-requests.js';
|
|
2
3
|
import { mustGetActiveAgent } from './agent.js';
|
|
3
4
|
import { listChatGroupsIn, mustGetActiveChatGroup } from './chat-group.js';
|
|
4
5
|
import { appendChunk, listChunks, updateOp } from './chunk.js';
|
|
@@ -10,7 +11,6 @@ import { chatSortKey } from './chat-order.js';
|
|
|
10
11
|
import { ownReadThrough, ownReads } from './chat-read.js';
|
|
11
12
|
import b4a from 'b4a';
|
|
12
13
|
import { ACTIVE_CHATS, ACTIVE_CHATS_BY_AGENT, ACTIVE_CHAT_GROUPS, CHATS, CHAT_GROUPS, CHUNK_COUNTERS } from './collections.js';
|
|
13
|
-
export const TERMINAL_RUN_STATES = new Set(['completed', 'failed', 'canceled']);
|
|
14
14
|
function byChatOrder(a, b) {
|
|
15
15
|
return chatSortKey(a) - chatSortKey(b) || (a.id < b.id ? -1 : 1);
|
|
16
16
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type HyperDB from 'hyperdb';
|
|
2
2
|
import type { QvacChunk, QvacUpdateChunkOperation } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
3
|
+
import type { AssistantChunkContentToolResult } from '../../spec/hyperschema/types.d.ts';
|
|
3
4
|
import type { Mesh, MeshDispatcher } from './mesh.ts';
|
|
4
5
|
import { type Bounds } from './range.ts';
|
|
5
6
|
type ChunkPayload = Pick<QvacChunk, 'userMessage' | 'content' | 'thinking' | 'toolCall' | 'toolResult' | 'attachment' | 'approvalRequest' | 'runStatus' | 'runRequest' | 'sources' | 'compaction' | 'context' | 'modelRequest' | 'roundReset' | 'agentSwitch'>;
|
|
@@ -18,13 +19,16 @@ type ListAttachmentsByKindInput = Bounds & {
|
|
|
18
19
|
kind: MediaKind;
|
|
19
20
|
origin?: AttachmentOrigin;
|
|
20
21
|
};
|
|
21
|
-
export type ReadChunk = QvacChunk & {
|
|
22
|
+
export type ReadChunk = Omit<QvacChunk, 'toolResult' | 'attachment'> & {
|
|
23
|
+
readonly toolResult: AssistantChunkContentToolResult | null;
|
|
22
24
|
readonly attachment?: (NonNullable<QvacChunk['attachment']> & {
|
|
23
25
|
readonly url?: string;
|
|
24
26
|
}) | null;
|
|
25
27
|
};
|
|
28
|
+
export declare function readChunk({ toolResult, ...chunk }: QvacChunk): ReadChunk;
|
|
29
|
+
export declare function linkChunks(store: Mesh, chunks: QvacChunk[]): ReadChunk[];
|
|
26
30
|
export declare function recordLinks(store: Mesh, chunks: ReadChunk[]): Promise<ReadChunk[]>;
|
|
27
|
-
type ListChunksInput = Bounds & {
|
|
31
|
+
export type ListChunksInput = Bounds & {
|
|
28
32
|
chatId: string;
|
|
29
33
|
type?: QvacChunk['type'];
|
|
30
34
|
types?: ReadonlyArray<QvacChunk['type']>;
|
|
@@ -34,8 +38,15 @@ export interface FindChunksOfTypeInput extends Bounds {
|
|
|
34
38
|
readonly type: QvacChunk['type'];
|
|
35
39
|
}
|
|
36
40
|
export declare function findChunksOfType(snap: HyperDB, { chatId, type, ...bounds }: FindChunksOfTypeInput): Promise<QvacChunk[]>;
|
|
37
|
-
export
|
|
41
|
+
export interface FindChunksOfTypesInput extends Omit<Bounds, 'limit'> {
|
|
42
|
+
readonly chatId: string;
|
|
43
|
+
readonly types: ReadonlyArray<QvacChunk['type']>;
|
|
44
|
+
}
|
|
45
|
+
export declare function findChunksOfTypes(db: HyperDB, { chatId, types, ...bounds }: FindChunksOfTypesInput): Promise<QvacChunk[]>;
|
|
46
|
+
export declare function listChunks(store: Mesh, input: ListChunksInput): Promise<ReadChunk[]>;
|
|
47
|
+
export declare function readChunks(db: HyperDB, { chatId, type, types, ...bounds }: ListChunksInput): Promise<QvacChunk[]>;
|
|
38
48
|
export declare function listAttachmentsByKind(store: Mesh, { kind, origin, ...bounds }: ListAttachmentsByKindInput): Promise<ReadChunk[]>;
|
|
49
|
+
export declare function selectsChunk({ chatId, type, types, gt, gte, lt, lte }: ListChunksInput, chunk: QvacChunk): boolean;
|
|
39
50
|
export declare function getChunk(store: Mesh, id: string): Promise<QvacChunk | null>;
|
|
40
51
|
export declare function mustGetChunk(store: Mesh, id: string): Promise<QvacChunk>;
|
|
41
52
|
export interface AppendedChunk {
|
|
@@ -13,7 +13,8 @@ import { keyRange } from './range.js';
|
|
|
13
13
|
import { runDefinition } from './shared-agents.js';
|
|
14
14
|
import { drivenBy, handedOff, offeredTo } from './run-driver.js';
|
|
15
15
|
import b4a from 'b4a';
|
|
16
|
-
import { AGENTS, ATTACHMENTS_BY_MEDIA_KIND, ATTACHMENTS_BY_MEDIA_KIND_ORIGIN, CHUNKS, CHUNKS_BY_CHAT, CHUNKS_BY_TYPE, HISTORY_CHUNKS, RUN_REQUESTS } from './collections.js';
|
|
16
|
+
import { AGENTS, ATTACHMENTS_BY_MEDIA_KIND, ATTACHMENTS_BY_MEDIA_KIND_ORIGIN, CHAT_CHUNKS, CHUNKS, CHUNKS_BY_CHAT, CHUNKS_BY_TYPE, CHUNK_COUNTERS, HISTORY_CHUNKS, RUN_REQUESTS } from './collections.js';
|
|
17
|
+
const TERMINAL_RUN_STATES = new Set(['completed', 'failed', 'canceled']);
|
|
17
18
|
export const HISTORY_CHUNK_TYPES = [
|
|
18
19
|
'user-message',
|
|
19
20
|
'run-request',
|
|
@@ -22,12 +23,31 @@ export const HISTORY_CHUNK_TYPES = [
|
|
|
22
23
|
'compaction',
|
|
23
24
|
'round-reset'
|
|
24
25
|
];
|
|
25
|
-
|
|
26
|
+
const FALSY_RESULTS = new Map([
|
|
27
|
+
['false', false],
|
|
28
|
+
['0', 0],
|
|
29
|
+
['""', '']
|
|
30
|
+
]);
|
|
31
|
+
export function readChunk({ toolResult, ...chunk }) {
|
|
32
|
+
if (!toolResult) {
|
|
33
|
+
return { ...chunk, toolResult: null };
|
|
34
|
+
}
|
|
35
|
+
const stored = chunk.falsyResult ?? '';
|
|
36
|
+
const result = FALSY_RESULTS.has(stored) ? FALSY_RESULTS.get(stored) : (toolResult.result ?? null);
|
|
37
|
+
return { ...chunk, toolResult: { ...toolResult, result } };
|
|
38
|
+
}
|
|
39
|
+
export function linkChunks(store, chunks) {
|
|
26
40
|
const mint = store.attachmentUrl;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
return chunks.map((row) => {
|
|
42
|
+
const chunk = readChunk(row);
|
|
43
|
+
return mint && chunk.attachment
|
|
44
|
+
? { ...chunk, attachment: linkAttachment(mint, chunk.attachment) }
|
|
45
|
+
: chunk;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function falsyResultOf(payload) {
|
|
49
|
+
const result = payload.toolResult?.result;
|
|
50
|
+
return result === false || result === 0 || result === '' ? JSON.stringify(result) : undefined;
|
|
31
51
|
}
|
|
32
52
|
export async function recordLinks(store, chunks) {
|
|
33
53
|
await store.fileIndex?.record(chunks.filter((chunk) => chunk.attachment?.url));
|
|
@@ -39,7 +59,24 @@ export function findChunksOfType(snap, { chatId, type, ...bounds }) {
|
|
|
39
59
|
.find(CHUNKS_BY_TYPE, keyRange(prefix, 'seq', bounds))
|
|
40
60
|
.toArray();
|
|
41
61
|
}
|
|
42
|
-
export async function
|
|
62
|
+
export async function findChunksOfTypes(db, { chatId, types, ...bounds }) {
|
|
63
|
+
const ordered = await readChatOrdered(db, chatId, { types, ...bounds });
|
|
64
|
+
if (ordered) {
|
|
65
|
+
return ordered;
|
|
66
|
+
}
|
|
67
|
+
const byType = await Promise.all(types.map((type) => findChunksOfType(db, { chatId, type, ...bounds })));
|
|
68
|
+
return byType.flat().sort((left, right) => left.seq - right.seq);
|
|
69
|
+
}
|
|
70
|
+
export async function listChunks(store, input) {
|
|
71
|
+
const snap = store.view.snapshot();
|
|
72
|
+
try {
|
|
73
|
+
return linkChunks(store, await readChunks(snap, input));
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await snap.close();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export async function readChunks(db, { chatId, type, types, ...bounds }) {
|
|
43
80
|
const selected = selectedChunkTypes(type, types);
|
|
44
81
|
if (selected?.length === 0) {
|
|
45
82
|
return [];
|
|
@@ -47,23 +84,66 @@ export async function listChunks(store, { chatId, type, types, ...bounds }) {
|
|
|
47
84
|
if (selected && selected.length > 1 && !isHistorySelection(selected)) {
|
|
48
85
|
throw new CoreError('CHUNK_TYPES_UNMAPPED');
|
|
49
86
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
87
|
+
if (selected?.length === 1) {
|
|
88
|
+
return findChunksOfType(db, { chatId, type: selected[0], ...bounds });
|
|
89
|
+
}
|
|
90
|
+
const history = selected !== null;
|
|
91
|
+
const ordered = history && bounds.limit
|
|
92
|
+
? null
|
|
93
|
+
: await readChatOrdered(db, chatId, {
|
|
94
|
+
types: history ? HISTORY_CHUNK_TYPES : null,
|
|
95
|
+
...bounds
|
|
96
|
+
});
|
|
97
|
+
if (ordered) {
|
|
98
|
+
return ordered;
|
|
99
|
+
}
|
|
100
|
+
return db
|
|
101
|
+
.find(history ? HISTORY_CHUNKS : CHUNKS_BY_CHAT, keyRange({ chatId }, 'seq', bounds))
|
|
102
|
+
.toArray();
|
|
103
|
+
}
|
|
104
|
+
async function readChatOrdered(db, chatId, { types, ...bounds }) {
|
|
105
|
+
const counter = await db.get(CHUNK_COUNTERS, { chatId });
|
|
106
|
+
if (!counter) {
|
|
107
|
+
return null;
|
|
63
108
|
}
|
|
64
|
-
|
|
65
|
-
|
|
109
|
+
const chunks = await db
|
|
110
|
+
.find(CHAT_CHUNKS, keyRange({ chatId }, 'seq', bounds))
|
|
111
|
+
.toArray();
|
|
112
|
+
const { first, last } = seqSpan(counter.count, bounds);
|
|
113
|
+
if (last < first) {
|
|
114
|
+
return chunks.length === 0 ? chunks : null;
|
|
115
|
+
}
|
|
116
|
+
const [low, high] = bounds.reverse ? [chunks.at(-1), chunks[0]] : [chunks[0], chunks.at(-1)];
|
|
117
|
+
const whole = chunks.length === last - first + 1 && low?.seq === first && high?.seq === last;
|
|
118
|
+
if (!whole) {
|
|
119
|
+
return null;
|
|
66
120
|
}
|
|
121
|
+
const settled = new Set(chunks
|
|
122
|
+
.filter((chunk) => TERMINAL_RUN_STATES.has(chunk.runStatus?.state ?? ''))
|
|
123
|
+
.map((c) => c.runId));
|
|
124
|
+
const selected = types ? chunks.filter((chunk) => types.includes(chunk.type)) : chunks;
|
|
125
|
+
return Promise.all(selected.map((chunk) => (changeable(chunk, settled) ? current(db, chunk) : chunk)));
|
|
126
|
+
}
|
|
127
|
+
function changeable(chunk, settled) {
|
|
128
|
+
return ((chunk.type === 'run-status' && !settled.has(chunk.runId)) ||
|
|
129
|
+
(chunk.type === 'approval-request' && chunk.approvalRequest?.status === 'pending') ||
|
|
130
|
+
(chunk.type === 'attachment' && !chunk.attachment?.deletedAt));
|
|
131
|
+
}
|
|
132
|
+
async function current(db, chunk) {
|
|
133
|
+
return (await db.get(CHUNKS, { id: chunk.id })) ?? chunk;
|
|
134
|
+
}
|
|
135
|
+
function seqSpan(count, { gt, gte, lt, lte, reverse, limit }) {
|
|
136
|
+
let first = Math.max(0, gte ?? 0, gt === undefined ? 0 : gt + 1);
|
|
137
|
+
let last = Math.min(count - 1, lte ?? Infinity, lt === undefined ? Infinity : lt - 1);
|
|
138
|
+
if (limit) {
|
|
139
|
+
if (reverse) {
|
|
140
|
+
first = Math.max(first, last - limit + 1);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
last = Math.min(last, first + limit - 1);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return { first, last };
|
|
67
147
|
}
|
|
68
148
|
export async function listAttachmentsByKind(store, { kind, origin, ...bounds }) {
|
|
69
149
|
const mediaKind = mediaKindOrdinal(kind);
|
|
@@ -94,6 +174,15 @@ function selectedChunkTypes(type, types) {
|
|
|
94
174
|
}
|
|
95
175
|
return [...selected];
|
|
96
176
|
}
|
|
177
|
+
export function selectsChunk({ chatId, type, types, gt, gte, lt, lte }, chunk) {
|
|
178
|
+
const selected = selectedChunkTypes(type, types);
|
|
179
|
+
return (chunk.chatId === chatId &&
|
|
180
|
+
(selected === null || selected.includes(chunk.type)) &&
|
|
181
|
+
(gt === undefined || chunk.seq > gt) &&
|
|
182
|
+
(gte === undefined || chunk.seq >= gte) &&
|
|
183
|
+
(lt === undefined || chunk.seq < lt) &&
|
|
184
|
+
(lte === undefined || chunk.seq <= lte));
|
|
185
|
+
}
|
|
97
186
|
function isHistorySelection(types) {
|
|
98
187
|
return (types.length === HISTORY_CHUNK_TYPES.length &&
|
|
99
188
|
types.every((type) => HISTORY_CHUNK_TYPES.includes(type)));
|
|
@@ -256,6 +345,7 @@ export async function appendChunk(store, { id = randomId(), chatId, runId, type,
|
|
|
256
345
|
capabilityArgs,
|
|
257
346
|
enhance,
|
|
258
347
|
sourceId,
|
|
348
|
+
falsyResult: falsyResultOf(payload),
|
|
259
349
|
round,
|
|
260
350
|
callId,
|
|
261
351
|
resumed,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const CHUNKS = "@qvac/chunks";
|
|
2
|
+
export declare const CHAT_CHUNKS = "@qvac/chat-chunks";
|
|
2
3
|
export declare const CHUNK_COUNTERS = "@qvac/chunk-counters";
|
|
3
4
|
export declare const AGENTS = "@qvac/agents";
|
|
4
5
|
export declare const APPROVAL_RULES = "@qvac/approval-rules";
|
|
@@ -67,8 +68,18 @@ export declare const LOCAL_RUN_LOG_STEPS = "@local/run-log-steps";
|
|
|
67
68
|
export declare const LOCAL_MESH_SESSION = "@local/mesh-session";
|
|
68
69
|
export declare const LOCAL_MESH_HISTORY = "@local/mesh-history";
|
|
69
70
|
export declare const LOCAL_MEMBERSHIP = "@local/membership";
|
|
70
|
-
export declare const INDEX_BACKFILLS = "@qvac/index-backfills";
|
|
71
71
|
export declare const LIVE_DEVICES_BY_WRITER_KEY = "@qvac/live-devices-by-writer-key";
|
|
72
|
+
export declare const LIVE_DEVICES_BY_MEMBER = "@qvac/live-devices-by-member";
|
|
73
|
+
export declare const DEVICES_BY_MEMBER = "@qvac/devices-by-member";
|
|
74
|
+
export declare const AGENT_HOSTS_BY_AGENT = "@qvac/agent-hosts-by-agent";
|
|
75
|
+
export declare const AGENT_HOSTS_BY_DEVICE = "@qvac/agent-hosts-by-device";
|
|
76
|
+
export declare const PUBLIC_SEEDS_BY_DEVICE = "@qvac/public-seeds-by-device";
|
|
77
|
+
export declare const PROJECT_HOST_KEYS_BY_DEVICE = "@qvac/project-host-keys-by-device";
|
|
78
|
+
export declare const PROJECT_DEVICE_KEYS_BY_DEVICE = "@qvac/project-device-keys-by-device";
|
|
79
|
+
export declare const PROJECT_DEVICE_KEYS_BY_MEMBER = "@qvac/project-device-keys-by-member";
|
|
80
|
+
export declare const AGENT_USERS_BY_USER = "@qvac/agent-users-by-user";
|
|
81
|
+
export declare const PROJECT_KEYS_BY_MEMBER = "@qvac/project-keys-by-member";
|
|
82
|
+
export declare const TERMINAL_RUN_STATUSES = "@qvac/terminal-run-statuses";
|
|
72
83
|
export declare const MEMBER_REMOVALS = "@qvac/member-removals";
|
|
73
84
|
export declare const INVITE_SEQUENCES = "@qvac/invite-sequences";
|
|
74
85
|
export declare const MESH_INVITE_SPENDS = "@qvac/mesh-invite-spends";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const CHUNKS = '@qvac/chunks';
|
|
2
|
+
export const CHAT_CHUNKS = '@qvac/chat-chunks';
|
|
2
3
|
export const CHUNK_COUNTERS = '@qvac/chunk-counters';
|
|
3
4
|
export const AGENTS = '@qvac/agents';
|
|
4
5
|
export const APPROVAL_RULES = '@qvac/approval-rules';
|
|
@@ -67,8 +68,18 @@ export const LOCAL_RUN_LOG_STEPS = '@local/run-log-steps';
|
|
|
67
68
|
export const LOCAL_MESH_SESSION = '@local/mesh-session';
|
|
68
69
|
export const LOCAL_MESH_HISTORY = '@local/mesh-history';
|
|
69
70
|
export const LOCAL_MEMBERSHIP = '@local/membership';
|
|
70
|
-
export const INDEX_BACKFILLS = '@qvac/index-backfills';
|
|
71
71
|
export const LIVE_DEVICES_BY_WRITER_KEY = '@qvac/live-devices-by-writer-key';
|
|
72
|
+
export const LIVE_DEVICES_BY_MEMBER = '@qvac/live-devices-by-member';
|
|
73
|
+
export const DEVICES_BY_MEMBER = '@qvac/devices-by-member';
|
|
74
|
+
export const AGENT_HOSTS_BY_AGENT = '@qvac/agent-hosts-by-agent';
|
|
75
|
+
export const AGENT_HOSTS_BY_DEVICE = '@qvac/agent-hosts-by-device';
|
|
76
|
+
export const PUBLIC_SEEDS_BY_DEVICE = '@qvac/public-seeds-by-device';
|
|
77
|
+
export const PROJECT_HOST_KEYS_BY_DEVICE = '@qvac/project-host-keys-by-device';
|
|
78
|
+
export const PROJECT_DEVICE_KEYS_BY_DEVICE = '@qvac/project-device-keys-by-device';
|
|
79
|
+
export const PROJECT_DEVICE_KEYS_BY_MEMBER = '@qvac/project-device-keys-by-member';
|
|
80
|
+
export const AGENT_USERS_BY_USER = '@qvac/agent-users-by-user';
|
|
81
|
+
export const PROJECT_KEYS_BY_MEMBER = '@qvac/project-keys-by-member';
|
|
82
|
+
export const TERMINAL_RUN_STATUSES = '@qvac/terminal-run-statuses';
|
|
72
83
|
export const MEMBER_REMOVALS = '@qvac/member-removals';
|
|
73
84
|
export const INVITE_SEQUENCES = '@qvac/invite-sequences';
|
|
74
85
|
export const MESH_INVITE_SPENDS = '@qvac/mesh-invite-spends';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface StoredConfigValue {
|
|
2
|
+
readonly value?: unknown;
|
|
3
|
+
readonly falsyValue?: string | null;
|
|
4
|
+
}
|
|
5
|
+
export declare function configValue(value: unknown): StoredConfigValue;
|
|
6
|
+
export declare function readConfigValue({ value, falsyValue }: StoredConfigValue): unknown;
|