@qvac/core 0.2.2 → 0.3.0
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/.claude/skills/compaction/SKILL.md +15 -11
- package/.claude/skills/js-house-style/SKILL.md +1 -0
- package/.claude/skills/pr-create/SKILL.md +42 -0
- package/.claude/skills/pr-review/SKILL.md +4 -0
- package/.claude/skills/release/SKILL.md +122 -0
- package/CLAUDE.md +7 -2
- package/dist-lib/lib/api/agents.js +2 -3
- package/dist-lib/lib/api/chat.js +3 -3
- package/dist-lib/lib/api/chunks.d.ts +1 -1
- package/dist-lib/lib/api/chunks.js +5 -15
- package/dist-lib/lib/api/current-mesh.d.ts +16 -1
- package/dist-lib/lib/api/current-mesh.js +18 -0
- package/dist-lib/lib/api/devices.js +6 -3
- package/dist-lib/lib/api/index.js +1 -1
- package/dist-lib/lib/api/knowledge.js +11 -7
- package/dist-lib/lib/api/members.js +2 -3
- package/dist-lib/lib/api/sync.d.ts +1 -1
- package/dist-lib/lib/api/sync.js +2 -1
- package/dist-lib/lib/api/tool-activity.js +2 -2
- package/dist-lib/lib/api/tool-configs.js +2 -2
- package/dist-lib/lib/api/watchable.d.ts +6 -1
- package/dist-lib/lib/api/watchable.js +13 -2
- package/dist-lib/lib/assistant/history.d.ts +1 -2
- package/dist-lib/lib/assistant/history.js +0 -6
- package/dist-lib/lib/assistant.d.ts +3 -7
- package/dist-lib/lib/assistant.js +65 -110
- package/dist-lib/lib/core/chunk.d.ts +1 -0
- package/dist-lib/lib/core/chunk.js +27 -0
- package/dist-lib/lib/core/contract/devices.js +3 -2
- package/dist-lib/lib/core/harness-loan.js +1 -1
- package/dist-lib/lib/core/local/index.js +6 -0
- package/dist-lib/lib/core.d.ts +1 -0
- package/dist-lib/lib/core.js +20 -12
- package/dist-lib/lib/fs-drive-bridge.js +1 -1
- package/dist-lib/lib/mesh-scoped-engine.js +5 -0
- package/dist-lib/lib/model-download.d.ts +2 -0
- package/dist-lib/lib/model-download.js +20 -5
- package/dist-lib/lib/oauth/keys.js +1 -0
- package/dist-lib/lib/oauth/spotify.js +1 -0
- package/dist-lib/lib/oauth/verify.d.ts +8 -0
- package/dist-lib/lib/oauth/verify.js +58 -0
- package/dist-lib/lib/oauth.d.ts +1 -0
- package/dist-lib/lib/oauth.js +1 -0
- package/dist-lib/schema/qvac.d.ts +3 -0
- package/dist-lib/schema/qvac.js +7 -0
- package/package.json +4 -4
- package/tui/app.mjs +327 -46
- package/tui/lib/render.mjs +17 -1
- package/tui/lib/selection.mjs +16 -0
- package/tui/lib/usage.mjs +54 -0
|
@@ -58,10 +58,8 @@ export declare class QvacAssistant extends ReadyResource {
|
|
|
58
58
|
private _harnessDiagnostics;
|
|
59
59
|
private _harnessDeath;
|
|
60
60
|
private _refreshingDiagnostics;
|
|
61
|
-
private _requests;
|
|
62
61
|
private _meshList;
|
|
63
|
-
private
|
|
64
|
-
private _retryMs;
|
|
62
|
+
private _advertisedOn;
|
|
65
63
|
private _chatList;
|
|
66
64
|
private _agentList;
|
|
67
65
|
private readonly _chatListWatch;
|
|
@@ -113,18 +111,16 @@ export declare class QvacAssistant extends ReadyResource {
|
|
|
113
111
|
}): Promise<ReadonlyArray<Skill>>;
|
|
114
112
|
private _recordSkillReadiness;
|
|
115
113
|
tools(): Promise<ReadonlyArray<ToolCatalogEntry>>;
|
|
116
|
-
private
|
|
117
|
-
private _rearmingWatch;
|
|
114
|
+
private _supervisedWatch;
|
|
118
115
|
private _watchChatList;
|
|
119
116
|
private _watchAgents;
|
|
120
117
|
private _reclaimAgentChatCaches;
|
|
121
118
|
private _reconcileCompaction;
|
|
122
119
|
deleteChatKvCache(chatId: string): Promise<AssistantKvCacheDeletionResponse>;
|
|
123
120
|
private _deleteChatKvCache;
|
|
124
|
-
private _rearmConsume;
|
|
125
|
-
private _consume;
|
|
126
121
|
private _watchMeshList;
|
|
127
122
|
private _syncRunConsumers;
|
|
123
|
+
private _followSelectedMesh;
|
|
128
124
|
private _meshRunConsumer;
|
|
129
125
|
private _stopMeshIntake;
|
|
130
126
|
private _pruneSeen;
|
|
@@ -42,7 +42,7 @@ import { encodeAgentSkillReadiness } from './skill-readiness.js';
|
|
|
42
42
|
import { harnessClearKvCache, harnessDeathReason, harnessDeleteModel, harnessDied, harnessListModels, harnessSkillCatalog, harnessSkillManagement, harnessSpeak, harnessSpeakStream, harnessTools, harnessTranscribe, imageDownloadProgress, modelCatalogChanged, toolReportEntry } from './assistant/harness.js';
|
|
43
43
|
import { annotateUnreadableImages, audioTranscriptBlock, backfillDocumentOnlyTurn, backfillImageOnlyTurns, silentAudioNotice, unheardAudioNotice } from './assistant/message.js';
|
|
44
44
|
import { drainBody, raceInactivity } from './assistant/fetch-body.js';
|
|
45
|
-
import { GENERIC_ACKNOWLEDGEMENTS, HISTORY_TYPES, SKILL_TOOL, TERMINAL_STATES, historyFromChunks, inputAvailableToRun, listHistoryChunks, staleToolRunIds
|
|
45
|
+
import { GENERIC_ACKNOWLEDGEMENTS, HISTORY_TYPES, SKILL_TOOL, TERMINAL_STATES, historyFromChunks, inputAvailableToRun, listHistoryChunks, staleToolRunIds } from './assistant/history.js';
|
|
46
46
|
export { harnessClearKvCache, harnessDeleteModel, harnessListModels, harnessSkillCatalog, harnessSkillManagement, harnessSpeak, harnessSpeakStream, harnessTools, harnessTranscribe } from './assistant/harness.js';
|
|
47
47
|
export {} from './assistant/skill-encode.js';
|
|
48
48
|
export { annotateUnreadableImages, unheardAudioNotice, unreadableImagesNotice, DOCUMENT_ONLY_USER_PROMPT, IMAGE_AND_DOCUMENT_USER_PROMPT, IMAGE_ONLY_USER_PROMPT } from './assistant/message.js';
|
|
@@ -63,12 +63,7 @@ function isDeniedResult(result) {
|
|
|
63
63
|
return false;
|
|
64
64
|
return result.denied === true;
|
|
65
65
|
}
|
|
66
|
-
const CONSUME_RETRY_MS = 1000;
|
|
67
|
-
const CONSUME_RETRY_MAX_MS = 30000;
|
|
68
66
|
const BLOB_READ_TIMEOUT_MS = 15_000;
|
|
69
|
-
function nextRetryDelay(err, current) {
|
|
70
|
-
return isMeshTransition(err) ? Math.min(current * 2, CONSUME_RETRY_MAX_MS) : CONSUME_RETRY_MS;
|
|
71
|
-
}
|
|
72
67
|
const SUSPENDED = RUN_ABORT_REASONS.suspended;
|
|
73
68
|
const OWNERSHIP_LOST = RUN_ABORT_REASONS.ownershipLost;
|
|
74
69
|
const RUN_SETTLED = RUN_ABORT_REASONS.runSettled;
|
|
@@ -118,10 +113,8 @@ export class QvacAssistant extends ReadyResource {
|
|
|
118
113
|
_harnessDiagnostics;
|
|
119
114
|
_harnessDeath;
|
|
120
115
|
_refreshingDiagnostics;
|
|
121
|
-
_requests;
|
|
122
116
|
_meshList;
|
|
123
|
-
|
|
124
|
-
_retryMs = CONSUME_RETRY_MS;
|
|
117
|
+
_advertisedOn;
|
|
125
118
|
_chatList;
|
|
126
119
|
_agentList;
|
|
127
120
|
_chatListWatch;
|
|
@@ -164,14 +157,13 @@ export class QvacAssistant extends ReadyResource {
|
|
|
164
157
|
this._harnessDiagnostics = null;
|
|
165
158
|
this._harnessDeath = null;
|
|
166
159
|
this._refreshingDiagnostics = false;
|
|
167
|
-
this._requests = null;
|
|
168
160
|
this._meshList = null;
|
|
169
|
-
this.
|
|
161
|
+
this._advertisedOn = null;
|
|
170
162
|
this._chatList = null;
|
|
171
163
|
this._agentList = null;
|
|
172
|
-
this._chatListWatch = this.
|
|
173
|
-
this._agentWatch = this.
|
|
174
|
-
this._meshListWatch = this.
|
|
164
|
+
this._chatListWatch = this._supervisedWatch('chat-list', () => this._watchChatList());
|
|
165
|
+
this._agentWatch = this._supervisedWatch('agent', () => this._watchAgents());
|
|
166
|
+
this._meshListWatch = this._supervisedWatch('mesh-list', () => this._watchMeshList());
|
|
175
167
|
this._runConsumers = new Map();
|
|
176
168
|
this._runs = new Map();
|
|
177
169
|
this._seen = new Map();
|
|
@@ -226,7 +218,6 @@ export class QvacAssistant extends ReadyResource {
|
|
|
226
218
|
mobileClass: this._mobileClass
|
|
227
219
|
});
|
|
228
220
|
this._downloads.start();
|
|
229
|
-
this._startConsume();
|
|
230
221
|
this._chatListWatch.start();
|
|
231
222
|
this._agentWatch.start();
|
|
232
223
|
this._meshListWatch.start();
|
|
@@ -243,12 +234,12 @@ export class QvacAssistant extends ReadyResource {
|
|
|
243
234
|
if (this._warmedModel)
|
|
244
235
|
return;
|
|
245
236
|
const deviceId = this._deviceId;
|
|
246
|
-
const config = await this._engine.getConfig({}).catch(
|
|
237
|
+
const config = await this._engine.getConfig({}).catch(noop);
|
|
247
238
|
const agent = await this._currentAgent(config?.activeAgentId ?? null, deviceId);
|
|
248
239
|
if (!agent?.modelName || !agent.providerDeviceId?.equals(deviceId) || this.suspended)
|
|
249
240
|
return;
|
|
250
241
|
const model = runnableModelName(agent.modelName, await this._ensureCapability(), this._mobileClass);
|
|
251
|
-
const rows = await this._harness.list?.({ cachedOnly: true }).catch(
|
|
242
|
+
const rows = await this._harness.list?.({ cachedOnly: true }).catch(noop);
|
|
252
243
|
if (!rows?.some((row) => row.name === model && row.isCached)) {
|
|
253
244
|
this._log?.info('models', 'model warm skipped', { model, reason: 'not cached' });
|
|
254
245
|
return;
|
|
@@ -268,7 +259,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
268
259
|
}
|
|
269
260
|
async _currentAgent(activeAgentId, deviceId) {
|
|
270
261
|
if (activeAgentId) {
|
|
271
|
-
const agent = await this._engine.getAgent({ id: activeAgentId }).catch(
|
|
262
|
+
const agent = await this._engine.getAgent({ id: activeAgentId }).catch(noop);
|
|
272
263
|
if (agent && !agent.deletedAt)
|
|
273
264
|
return agent;
|
|
274
265
|
}
|
|
@@ -515,8 +506,6 @@ export class QvacAssistant extends ReadyResource {
|
|
|
515
506
|
}
|
|
516
507
|
}
|
|
517
508
|
async _close() {
|
|
518
|
-
if (this._retry)
|
|
519
|
-
clearTimeout(this._retry);
|
|
520
509
|
this._chatListWatch.stop();
|
|
521
510
|
this._agentWatch.stop();
|
|
522
511
|
this._stopMeshIntake();
|
|
@@ -528,7 +517,6 @@ export class QvacAssistant extends ReadyResource {
|
|
|
528
517
|
run.controller.abort(RUNNER_CLOSED);
|
|
529
518
|
await this._downloads?.close();
|
|
530
519
|
this._modelCatalog.close();
|
|
531
|
-
await this._requests?.return?.();
|
|
532
520
|
await this._meshList?.return?.();
|
|
533
521
|
await this._chatList?.return?.();
|
|
534
522
|
await this._agentList?.return?.();
|
|
@@ -552,13 +540,10 @@ export class QvacAssistant extends ReadyResource {
|
|
|
552
540
|
return;
|
|
553
541
|
this._state = QvacState.SUSPEND;
|
|
554
542
|
this._log?.info('assistant', 'suspending', { runs: this._runs.size });
|
|
555
|
-
if (this._retry)
|
|
556
|
-
clearTimeout(this._retry);
|
|
557
543
|
this._chatListWatch.stop();
|
|
558
544
|
this._agentWatch.stop();
|
|
559
545
|
this._stopMeshIntake();
|
|
560
546
|
await this._downloads?.suspend();
|
|
561
|
-
await this._requests?.return?.();
|
|
562
547
|
await this._meshList?.return?.();
|
|
563
548
|
await this._chatList?.return?.();
|
|
564
549
|
await this._agentList?.return?.();
|
|
@@ -591,7 +576,6 @@ export class QvacAssistant extends ReadyResource {
|
|
|
591
576
|
await Promise.allSettled([...this._runs.values()].map((run) => run.done));
|
|
592
577
|
this._downloads?.resume();
|
|
593
578
|
if (this.opened) {
|
|
594
|
-
this._startConsume();
|
|
595
579
|
this._chatListWatch.start();
|
|
596
580
|
this._agentWatch.start();
|
|
597
581
|
this._meshListWatch.start();
|
|
@@ -615,7 +599,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
615
599
|
if (!this.opened)
|
|
616
600
|
await this.ready();
|
|
617
601
|
if (agentId) {
|
|
618
|
-
const agent = await this._engine.getAgent({ id: agentId }).catch(
|
|
602
|
+
const agent = await this._engine.getAgent({ id: agentId }).catch(noop);
|
|
619
603
|
const deviceId = this._deviceId;
|
|
620
604
|
if (agent && deviceId && !agent.providerDeviceId?.equals(deviceId)) {
|
|
621
605
|
agentId = null;
|
|
@@ -663,35 +647,29 @@ export class QvacAssistant extends ReadyResource {
|
|
|
663
647
|
async tools() {
|
|
664
648
|
return (await this._harness.tools?.()) ?? [];
|
|
665
649
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
let timer = null;
|
|
672
|
-
let stopped = false;
|
|
673
|
-
const rearm = (err) => {
|
|
674
|
-
if (stopped || this.closing || this.suspended)
|
|
675
|
-
return;
|
|
650
|
+
_supervisedWatch(label, run) {
|
|
651
|
+
let running = false;
|
|
652
|
+
let again = false;
|
|
653
|
+
const settle = (err) => {
|
|
654
|
+
running = false;
|
|
676
655
|
if (err !== null && !isMeshTransition(err)) {
|
|
677
|
-
this._log?.error('assistant', `${label} watch failed
|
|
656
|
+
this._log?.error('assistant', `${label} watch failed`, err);
|
|
678
657
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
timer = setTimeout(start, delay);
|
|
658
|
+
if (again)
|
|
659
|
+
start();
|
|
682
660
|
};
|
|
683
661
|
const start = () => {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
stopped = true;
|
|
691
|
-
if (timer)
|
|
692
|
-
clearTimeout(timer);
|
|
662
|
+
again = false;
|
|
663
|
+
if (this.closing || this.suspended)
|
|
664
|
+
return;
|
|
665
|
+
if (running) {
|
|
666
|
+
again = true;
|
|
667
|
+
return;
|
|
693
668
|
}
|
|
669
|
+
running = true;
|
|
670
|
+
run().then(() => settle(null), (err) => settle(err));
|
|
694
671
|
};
|
|
672
|
+
return { start, stop: () => void (again = false) };
|
|
695
673
|
}
|
|
696
674
|
async _watchChatList() {
|
|
697
675
|
const stream = this._engine.chatsWatch({});
|
|
@@ -786,37 +764,6 @@ export class QvacAssistant extends ReadyResource {
|
|
|
786
764
|
return false;
|
|
787
765
|
}
|
|
788
766
|
}
|
|
789
|
-
_rearmConsume(err) {
|
|
790
|
-
if (this.closing || this.suspended)
|
|
791
|
-
return;
|
|
792
|
-
if (err !== null && !isMeshTransition(err)) {
|
|
793
|
-
this._log?.error('assistant', 'run-request watch failed — restarting', err);
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
this._log?.debug('assistant', 'rearming consume', {
|
|
797
|
-
cause: err === null ? 'stream end' : 'mesh transition'
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
this._lastCapabilities = null;
|
|
801
|
-
const delay = isMeshTransition(err) ? this._retryMs : CONSUME_RETRY_MS;
|
|
802
|
-
this._retryMs = nextRetryDelay(err, delay);
|
|
803
|
-
this._retry = setTimeout(() => this._startConsume(), delay);
|
|
804
|
-
}
|
|
805
|
-
async _consume() {
|
|
806
|
-
const stream = this._engine.runRequestsWatch({});
|
|
807
|
-
this._requests = stream[Symbol.asyncIterator]();
|
|
808
|
-
this._reportCapabilities().catch(noop);
|
|
809
|
-
this._reconcileDeviceProfile().catch(noop);
|
|
810
|
-
while (true) {
|
|
811
|
-
const { value, done } = await this._requests.next();
|
|
812
|
-
if (done || this.closing || this.suspended)
|
|
813
|
-
return;
|
|
814
|
-
const requests = value.chunks ?? [];
|
|
815
|
-
for (const chunk of requests)
|
|
816
|
-
this._dispatch(chunk);
|
|
817
|
-
this._pruneSeen(null, new Set(requests.map((c) => c.runId)));
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
767
|
async _watchMeshList() {
|
|
821
768
|
const stream = this._engine.meshesWatch({});
|
|
822
769
|
this._meshList = stream[Symbol.asyncIterator]();
|
|
@@ -824,28 +771,46 @@ export class QvacAssistant extends ReadyResource {
|
|
|
824
771
|
const { value, done } = await this._meshList.next();
|
|
825
772
|
if (done || this.closing || this.suspended)
|
|
826
773
|
return;
|
|
827
|
-
|
|
774
|
+
const meshes = value.meshes ?? [];
|
|
775
|
+
this._syncRunConsumers(meshes);
|
|
776
|
+
this._followSelectedMesh(meshes);
|
|
828
777
|
}
|
|
829
778
|
}
|
|
830
779
|
_syncRunConsumers(meshes) {
|
|
831
|
-
const
|
|
780
|
+
const open = new Set(meshes.filter((mesh) => mesh.open).map((mesh) => mesh.meshId));
|
|
832
781
|
for (const [meshId, consumer] of this._runConsumers) {
|
|
833
|
-
if (
|
|
782
|
+
if (open.has(meshId))
|
|
834
783
|
continue;
|
|
835
784
|
consumer.stop();
|
|
836
785
|
this._runConsumers.delete(meshId);
|
|
786
|
+
this._pruneSeen(meshId, new Set());
|
|
837
787
|
}
|
|
838
|
-
for (const meshId of
|
|
839
|
-
|
|
840
|
-
continue;
|
|
841
|
-
const consumer = this._meshRunConsumer(meshId);
|
|
788
|
+
for (const meshId of open) {
|
|
789
|
+
const consumer = this._runConsumers.get(meshId) ?? this._meshRunConsumer(meshId);
|
|
842
790
|
this._runConsumers.set(meshId, consumer);
|
|
843
791
|
consumer.start();
|
|
844
792
|
}
|
|
845
793
|
}
|
|
794
|
+
_followSelectedMesh(meshes) {
|
|
795
|
+
const selected = meshes.find((mesh) => mesh.active);
|
|
796
|
+
const on = selected ? `${selected.meshId}:${selected.writable}` : null;
|
|
797
|
+
if (on === null) {
|
|
798
|
+
this._advertisedOn = null;
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
if (on === this._advertisedOn)
|
|
802
|
+
return;
|
|
803
|
+
this._advertisedOn = on;
|
|
804
|
+
this._chatListWatch.start();
|
|
805
|
+
this._agentWatch.start();
|
|
806
|
+
this._downloads?.meshSelected();
|
|
807
|
+
this._lastCapabilities = null;
|
|
808
|
+
this._reportCapabilities().catch(noop);
|
|
809
|
+
this._reconcileDeviceProfile().catch(noop);
|
|
810
|
+
}
|
|
846
811
|
_meshRunConsumer(meshId) {
|
|
847
812
|
let requests = null;
|
|
848
|
-
const watch = this.
|
|
813
|
+
const watch = this._supervisedWatch(`run-requests:${meshId}`, async () => {
|
|
849
814
|
const stream = this._engine.runRequestsWatch({ meshId });
|
|
850
815
|
requests = stream[Symbol.asyncIterator]();
|
|
851
816
|
while (true) {
|
|
@@ -871,6 +836,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
871
836
|
for (const consumer of this._runConsumers.values())
|
|
872
837
|
consumer.stop();
|
|
873
838
|
this._runConsumers.clear();
|
|
839
|
+
this._advertisedOn = null;
|
|
874
840
|
}
|
|
875
841
|
_pruneSeen(meshId, live) {
|
|
876
842
|
for (const [runId, from] of this._seen) {
|
|
@@ -907,11 +873,11 @@ export class QvacAssistant extends ReadyResource {
|
|
|
907
873
|
const runId = request.runId;
|
|
908
874
|
if (!runId || this._runs.has(runId) || this._seen.has(runId))
|
|
909
875
|
return;
|
|
910
|
-
this._seen.set(runId, meshId
|
|
876
|
+
this._seen.set(runId, meshId);
|
|
911
877
|
const engine = meshScoped(this._engine, meshId);
|
|
912
878
|
const settle = (async () => {
|
|
913
879
|
const agentId = request.runRequest?.agentId;
|
|
914
|
-
const agent = await engine.getAgent({ id: agentId }).catch(
|
|
880
|
+
const agent = await engine.getAgent({ id: agentId }).catch(noop);
|
|
915
881
|
if (!agent) {
|
|
916
882
|
this._seen.delete(runId);
|
|
917
883
|
return;
|
|
@@ -1006,7 +972,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1006
972
|
}
|
|
1007
973
|
if (await this._isHandled(engine, request))
|
|
1008
974
|
return;
|
|
1009
|
-
const fresh = await engine.getAgent({ id: agent.id }).catch(
|
|
975
|
+
const fresh = await engine.getAgent({ id: agent.id }).catch(noop);
|
|
1010
976
|
if (!fresh || fresh.deletedAt || !fresh.providerDeviceId?.equals(deviceId))
|
|
1011
977
|
return;
|
|
1012
978
|
agent = fresh;
|
|
@@ -1461,20 +1427,9 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1461
1427
|
});
|
|
1462
1428
|
}
|
|
1463
1429
|
const citedTitles = ragInjected ? citedByPhraseOverlap(answerText, retrievedRecords) : null;
|
|
1464
|
-
const foldedNow = metrics
|
|
1465
|
-
? await this._compactIfNearFull({
|
|
1466
|
-
chatId,
|
|
1467
|
-
transcript,
|
|
1468
|
-
trigger: 'turn-filled-window',
|
|
1469
|
-
metrics: metrics,
|
|
1470
|
-
signal: controller.signal,
|
|
1471
|
-
meshId
|
|
1472
|
-
})
|
|
1473
|
-
: false;
|
|
1474
|
-
const settled = foldedNow ? withoutOccupancy(metrics) : metrics;
|
|
1475
1430
|
await transcript.status({
|
|
1476
1431
|
state: 'completed',
|
|
1477
|
-
metrics: citedTitles ? { ...
|
|
1432
|
+
metrics: citedTitles ? { ...metrics, citedTitles } : metrics
|
|
1478
1433
|
});
|
|
1479
1434
|
titleOutcome = 'completed';
|
|
1480
1435
|
}
|
|
@@ -1583,7 +1538,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1583
1538
|
async _readBlob(url, signal) {
|
|
1584
1539
|
if (!url || signal?.aborted)
|
|
1585
1540
|
return null;
|
|
1586
|
-
const pending = defaultFetch(url).catch(
|
|
1541
|
+
const pending = defaultFetch(url).catch(noop);
|
|
1587
1542
|
try {
|
|
1588
1543
|
const response = await raceInactivity(pending, signal, this._blobReadTimeoutMs);
|
|
1589
1544
|
const bytes = response?.ok
|
|
@@ -1692,7 +1647,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1692
1647
|
}
|
|
1693
1648
|
async _hydrateImage(dir, image, signal) {
|
|
1694
1649
|
const file = path.join(dir, imageCacheName(image));
|
|
1695
|
-
const cached = await fs.promises.stat(file).catch(
|
|
1650
|
+
const cached = await fs.promises.stat(file).catch(noop);
|
|
1696
1651
|
if (!cached?.size) {
|
|
1697
1652
|
const raw = await this._readBlob(image.url, signal);
|
|
1698
1653
|
if (signal.aborted)
|
|
@@ -1706,13 +1661,13 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1706
1661
|
}
|
|
1707
1662
|
else {
|
|
1708
1663
|
const now = new Date();
|
|
1709
|
-
await fs.promises.utimes(file, now, now).catch(
|
|
1664
|
+
await fs.promises.utimes(file, now, now).catch(noop);
|
|
1710
1665
|
}
|
|
1711
1666
|
return file;
|
|
1712
1667
|
}
|
|
1713
1668
|
async _compactIfNearFull(params) {
|
|
1714
1669
|
const { chatId, transcript, trigger, signal, meshId } = params;
|
|
1715
|
-
const metrics =
|
|
1670
|
+
const metrics = await this._lastRunMetrics(chatId, meshId);
|
|
1716
1671
|
if (!nearContextLimit(metrics.cacheTokens, metrics.ctxSize))
|
|
1717
1672
|
return false;
|
|
1718
1673
|
if (!canCompact(metrics.ctxSize)) {
|
|
@@ -1793,15 +1748,15 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1793
1748
|
await this.ready();
|
|
1794
1749
|
const engine = meshScoped(this._engine, options.meshId);
|
|
1795
1750
|
const deviceId = this._deviceId;
|
|
1796
|
-
const chat = await engine.getChat({ id: chatId }).catch(
|
|
1751
|
+
const chat = await engine.getChat({ id: chatId }).catch(noop);
|
|
1797
1752
|
if (!chat)
|
|
1798
1753
|
return { compacted: false, reason: 'unknown chat' };
|
|
1799
|
-
const agent = await engine.getAgent({ id: chat.agentId }).catch(
|
|
1754
|
+
const agent = await engine.getAgent({ id: chat.agentId }).catch(noop);
|
|
1800
1755
|
if (!agent || !agent.providerDeviceId?.equals(deviceId)) {
|
|
1801
1756
|
return { compacted: false, reason: 'not the provider device' };
|
|
1802
1757
|
}
|
|
1803
1758
|
const model = runnableModelName(agent.modelName, await this._ensureCapability(), this._mobileClass);
|
|
1804
|
-
const config = await engine.getConfig({}).catch(
|
|
1759
|
+
const config = await engine.getConfig({}).catch(noop);
|
|
1805
1760
|
const ctxSize = agent.ctxSize || config?.ctxSize || undefined;
|
|
1806
1761
|
if (ctxSize !== undefined && !canCompact(ctxSize)) {
|
|
1807
1762
|
return { compacted: false, reason: 'below-floor' };
|
|
@@ -58,4 +58,5 @@ export declare function resolveApproval(store: Mesh, { id, approved, scope, expi
|
|
|
58
58
|
expiresAt?: number;
|
|
59
59
|
agentId?: string;
|
|
60
60
|
}): Promise<QvacChunk>;
|
|
61
|
+
export declare function listRunRequests(store: Mesh, deviceId: Buffer | null): Promise<QvacChunk[]>;
|
|
61
62
|
export {};
|
|
@@ -210,3 +210,30 @@ export async function resolveApproval(store, { id, approved, scope, expiresAt, a
|
|
|
210
210
|
}
|
|
211
211
|
return resolved;
|
|
212
212
|
}
|
|
213
|
+
export async function listRunRequests(store, deviceId) {
|
|
214
|
+
if (!deviceId)
|
|
215
|
+
return [];
|
|
216
|
+
const snap = store.view.snapshot();
|
|
217
|
+
try {
|
|
218
|
+
const requests = await snap.find('@qvac/run-requests').toArray();
|
|
219
|
+
const providers = new Map();
|
|
220
|
+
const mine = [];
|
|
221
|
+
for (const request of requests) {
|
|
222
|
+
if (store.closing)
|
|
223
|
+
return mine;
|
|
224
|
+
const agentId = request.runRequest?.agentId;
|
|
225
|
+
if (!agentId)
|
|
226
|
+
continue;
|
|
227
|
+
if (!providers.has(agentId)) {
|
|
228
|
+
const agent = await snap.get('@qvac/agents', { id: agentId });
|
|
229
|
+
providers.set(agentId, agent?.providerDeviceId);
|
|
230
|
+
}
|
|
231
|
+
if (providers.get(agentId)?.equals(deviceId))
|
|
232
|
+
mine.push(request);
|
|
233
|
+
}
|
|
234
|
+
return mine;
|
|
235
|
+
}
|
|
236
|
+
finally {
|
|
237
|
+
await snap.close();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { capDeviceName } from '../../../schema/qvac.js';
|
|
1
2
|
import { trackActivity } from './activity.js';
|
|
2
3
|
import { sealed } from './seal.js';
|
|
3
4
|
import { verifyWriterClaim } from '../device-attestation.js';
|
|
@@ -21,7 +22,7 @@ export function registerDeviceRoutes(router) {
|
|
|
21
22
|
}
|
|
22
23
|
const registered = {
|
|
23
24
|
id: device.id,
|
|
24
|
-
name: device.name,
|
|
25
|
+
name: capDeviceName(device.name),
|
|
25
26
|
joinedAt: device.joinedAt,
|
|
26
27
|
capabilityProfile: device.capabilityProfile,
|
|
27
28
|
recommendedModelName: device.recommendedModelName,
|
|
@@ -55,7 +56,7 @@ export function registerDeviceRoutes(router) {
|
|
|
55
56
|
});
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
|
-
const next = { ...existing, name: device.name };
|
|
59
|
+
const next = { ...existing, name: capDeviceName(device.name) };
|
|
59
60
|
await tx.insert(DEVICES, next);
|
|
60
61
|
return next;
|
|
61
62
|
}));
|
|
@@ -145,7 +145,7 @@ export class HarnessLoan {
|
|
|
145
145
|
if (!peer || peer.served.has(id))
|
|
146
146
|
return;
|
|
147
147
|
const stream = this._attach(peer, id, false);
|
|
148
|
-
const served = await this._opts.onborrow(peer.remoteKey).catch(
|
|
148
|
+
const served = await this._opts.onborrow(peer.remoteKey).catch(noop);
|
|
149
149
|
if (!served) {
|
|
150
150
|
stream.destroy();
|
|
151
151
|
return;
|
|
@@ -2,6 +2,7 @@ import CorestoreStorage from 'hypercore-storage';
|
|
|
2
2
|
import HyperDB from 'hyperdb';
|
|
3
3
|
import crypto from 'hypercore-crypto';
|
|
4
4
|
import ScopeLock from 'scope-lock';
|
|
5
|
+
import { MAX_DEVICE_NAME_CHARS, deviceNameWithinBounds } from '../../../schema/qvac.js';
|
|
5
6
|
import { generateMnemonic, mintIdentity } from '../identity.js';
|
|
6
7
|
import LocalDatabaseSpec from '../../../spec/local/hyperdb/index.js';
|
|
7
8
|
const CONFIG = '@local/config';
|
|
@@ -238,6 +239,11 @@ class LocalStore {
|
|
|
238
239
|
}
|
|
239
240
|
if (!seed)
|
|
240
241
|
return null;
|
|
242
|
+
const name = seed.name.trim();
|
|
243
|
+
if (!deviceNameWithinBounds(name)) {
|
|
244
|
+
throw new Error(`device name must be at most ${MAX_DEVICE_NAME_CHARS} characters`);
|
|
245
|
+
}
|
|
246
|
+
seed = { ...seed, name };
|
|
241
247
|
const tx = this._db.transaction();
|
|
242
248
|
await tx.insert(DEVICE, { publicKey, ...seed });
|
|
243
249
|
await tx.flush();
|
package/dist-lib/lib/core.d.ts
CHANGED
|
@@ -359,6 +359,7 @@ export declare class Core extends ReadyResource {
|
|
|
359
359
|
private _onConnection;
|
|
360
360
|
private _trackPeerConnection;
|
|
361
361
|
private _onPeerChange;
|
|
362
|
+
private _currentMeshAccessor;
|
|
362
363
|
private _meshStatusSource;
|
|
363
364
|
private _networkStatusSource;
|
|
364
365
|
private _networkSnapshot;
|
package/dist-lib/lib/core.js
CHANGED
|
@@ -328,11 +328,12 @@ export class Core extends ReadyResource {
|
|
|
328
328
|
await this._openOtaConfig();
|
|
329
329
|
await this._openBootMesh();
|
|
330
330
|
this._systemInfo = createSystemInfoSampler();
|
|
331
|
+
const meshStatus = this._meshStatusSource();
|
|
331
332
|
this._api = createApi({
|
|
332
333
|
state: this.local,
|
|
333
334
|
notificationLifetime: this,
|
|
334
|
-
mesh:
|
|
335
|
-
meshStatus
|
|
335
|
+
mesh: this._currentMeshAccessor(meshStatus),
|
|
336
|
+
meshStatus,
|
|
336
337
|
network: this._networkStatusSource(),
|
|
337
338
|
diagnostics: this._diagnosticsSource(),
|
|
338
339
|
logs: this._logSource(),
|
|
@@ -1242,12 +1243,12 @@ export class Core extends ReadyResource {
|
|
|
1242
1243
|
continue;
|
|
1243
1244
|
const own = await entry.mesh.view
|
|
1244
1245
|
.get('@qvac/devices', { id: deviceId })
|
|
1245
|
-
.catch(
|
|
1246
|
+
.catch(noop);
|
|
1246
1247
|
if (!own?.memberId || !own.memberProof)
|
|
1247
1248
|
continue;
|
|
1248
1249
|
const member = await entry.mesh.view
|
|
1249
1250
|
.get('@qvac/members', { id: own.memberId })
|
|
1250
|
-
.catch(
|
|
1251
|
+
.catch(noop);
|
|
1251
1252
|
if (member)
|
|
1252
1253
|
return { id: member.id, name: member.name, proof: own.memberProof };
|
|
1253
1254
|
}
|
|
@@ -1662,7 +1663,7 @@ export class Core extends ReadyResource {
|
|
|
1662
1663
|
return null;
|
|
1663
1664
|
const home = await this._homeMeshKey();
|
|
1664
1665
|
const held = home ? this._currentMesh(home.toString('hex')) : null;
|
|
1665
|
-
const mesh = home ? await this._openPooledMesh(home.toString('hex')).catch(
|
|
1666
|
+
const mesh = home ? await this._openPooledMesh(home.toString('hex')).catch(noop) : null;
|
|
1666
1667
|
if (mesh && !mesh.writable) {
|
|
1667
1668
|
await Promise.race([mesh.waitForWritable(), this._closeSignal, after(ACCOUNT_WRITABLE_MS)]);
|
|
1668
1669
|
}
|
|
@@ -2099,7 +2100,7 @@ export class Core extends ReadyResource {
|
|
|
2099
2100
|
for (const row of [...rows].sort((a, b) => preferred(b) - preferred(a))) {
|
|
2100
2101
|
const meshId = row.key.toString('hex');
|
|
2101
2102
|
const held = this._currentMesh(meshId);
|
|
2102
|
-
const mesh = await this._openPooledMesh(meshId).catch(
|
|
2103
|
+
const mesh = await this._openPooledMesh(meshId).catch(noop);
|
|
2103
2104
|
if (mesh?.writable)
|
|
2104
2105
|
return mesh;
|
|
2105
2106
|
if (mesh && !held)
|
|
@@ -2692,7 +2693,7 @@ export class Core extends ReadyResource {
|
|
|
2692
2693
|
continue;
|
|
2693
2694
|
if (self && device.id.equals(self))
|
|
2694
2695
|
continue;
|
|
2695
|
-
const seed = await this._meshSeedHandoff.request(device.id, meshKey).catch(
|
|
2696
|
+
const seed = await this._meshSeedHandoff.request(device.id, meshKey).catch(noop);
|
|
2696
2697
|
if (seed)
|
|
2697
2698
|
return seed;
|
|
2698
2699
|
}
|
|
@@ -2746,7 +2747,7 @@ export class Core extends ReadyResource {
|
|
|
2746
2747
|
continue;
|
|
2747
2748
|
const device = await entry.mesh.view
|
|
2748
2749
|
.get('@qvac/devices', { id: deviceId })
|
|
2749
|
-
.catch(
|
|
2750
|
+
.catch(noop);
|
|
2750
2751
|
if (device && !device.revoked)
|
|
2751
2752
|
return true;
|
|
2752
2753
|
}
|
|
@@ -2770,9 +2771,7 @@ export class Core extends ReadyResource {
|
|
|
2770
2771
|
const ours = entry.mesh.ourMemberId;
|
|
2771
2772
|
if (!ours)
|
|
2772
2773
|
continue;
|
|
2773
|
-
const row = await entry.mesh.view
|
|
2774
|
-
.get(JOINED_MESHES, { meshKey })
|
|
2775
|
-
.catch(() => null);
|
|
2774
|
+
const row = await entry.mesh.view.get(JOINED_MESHES, { meshKey }).catch(noop);
|
|
2776
2775
|
if (row?.memberId.equals(ours) && !row.leftAt)
|
|
2777
2776
|
return true;
|
|
2778
2777
|
}
|
|
@@ -2786,7 +2785,7 @@ export class Core extends ReadyResource {
|
|
|
2786
2785
|
continue;
|
|
2787
2786
|
const device = await entry.mesh.view
|
|
2788
2787
|
.get('@qvac/devices', { id: deviceId })
|
|
2789
|
-
.catch(
|
|
2788
|
+
.catch(noop);
|
|
2790
2789
|
if (!device)
|
|
2791
2790
|
continue;
|
|
2792
2791
|
if (device.revoked)
|
|
@@ -2944,6 +2943,15 @@ export class Core extends ReadyResource {
|
|
|
2944
2943
|
});
|
|
2945
2944
|
this._notifyStatus();
|
|
2946
2945
|
}
|
|
2946
|
+
_currentMeshAccessor(status) {
|
|
2947
|
+
return Object.assign((meshId) => this._meshFor(meshId), {
|
|
2948
|
+
selection: {
|
|
2949
|
+
key: () => this._activeMeshKey,
|
|
2950
|
+
watch: (listener) => status.watch(listener),
|
|
2951
|
+
unwatch: (listener) => status.unwatch(listener)
|
|
2952
|
+
}
|
|
2953
|
+
});
|
|
2954
|
+
}
|
|
2947
2955
|
_meshStatusSource() {
|
|
2948
2956
|
return {
|
|
2949
2957
|
watch: (listener) => void this._statusListeners.add(listener),
|
|
@@ -13,7 +13,7 @@ export async function sweepDriveStaging(now = Date.now()) {
|
|
|
13
13
|
const names = await fs.promises.readdir(STAGING_DIR).catch(() => []);
|
|
14
14
|
await Promise.all(names.map(async (name) => {
|
|
15
15
|
const file = path.join(STAGING_DIR, name);
|
|
16
|
-
const stat = await fs.promises.stat(file).catch(
|
|
16
|
+
const stat = await fs.promises.stat(file).catch(noop);
|
|
17
17
|
if (stat && now - stat.mtimeMs > STAGING_MAX_AGE_MS) {
|
|
18
18
|
await fs.promises.unlink(file).catch(noop);
|
|
19
19
|
}
|
|
@@ -13,6 +13,11 @@ export const MESH_SCOPED = new Set([
|
|
|
13
13
|
'listToolConfigs',
|
|
14
14
|
'ragSearch',
|
|
15
15
|
'fileStatusWatch',
|
|
16
|
+
'listKnowledge',
|
|
17
|
+
'knowledgeWatch',
|
|
18
|
+
'listIndexing',
|
|
19
|
+
'indexingWatch',
|
|
20
|
+
'indexingProgressWatch',
|
|
16
21
|
'fileRead',
|
|
17
22
|
'listDevices',
|
|
18
23
|
'devicesWatch',
|
|
@@ -152,6 +152,7 @@ export declare class ModelDownloadReconciler {
|
|
|
152
152
|
private _reset;
|
|
153
153
|
suspend(): Promise<void>;
|
|
154
154
|
resume(): void;
|
|
155
|
+
meshSelected(): void;
|
|
155
156
|
yieldToRuns(models: ReadonlyArray<string>): void;
|
|
156
157
|
observeImageProgress(observation: ImageDownloadObservation): void;
|
|
157
158
|
private _transfer;
|
|
@@ -161,6 +162,7 @@ export declare class ModelDownloadReconciler {
|
|
|
161
162
|
close(): Promise<void>;
|
|
162
163
|
private _watchConfig;
|
|
163
164
|
private _syncToolConfigsWatch;
|
|
165
|
+
private _swapToolConfigsWatch;
|
|
164
166
|
private _watchToolConfigs;
|
|
165
167
|
private _watchAgents;
|
|
166
168
|
private _restartWatch;
|