@qvac/core 0.2.2 → 0.3.1
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/dist-lib/lib/api/agents.js +2 -3
- package/dist-lib/lib/api/chat.d.ts +3 -1
- package/dist-lib/lib/api/chat.js +9 -5
- 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.d.ts +2 -0
- package/dist-lib/lib/api/index.js +4 -2
- package/dist-lib/lib/api/inference-calls.d.ts +18 -0
- package/dist-lib/lib/api/inference-calls.js +15 -0
- package/dist-lib/lib/api/knowledge.js +11 -7
- package/dist-lib/lib/api/members.js +2 -3
- package/dist-lib/lib/api/rag.js +10 -2
- 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/harness.d.ts +1 -0
- package/dist-lib/lib/assistant/history.d.ts +1 -2
- package/dist-lib/lib/assistant/history.js +0 -6
- package/dist-lib/lib/assistant-tree.d.ts +2 -0
- package/dist-lib/lib/assistant-tree.js +11 -2
- package/dist-lib/lib/assistant.d.ts +17 -8
- package/dist-lib/lib/assistant.js +172 -125
- package/dist-lib/lib/core/chunk.d.ts +1 -0
- package/dist-lib/lib/core/chunk.js +32 -0
- package/dist-lib/lib/core/contract/devices.js +3 -2
- package/dist-lib/lib/core/files/rag/build.d.ts +1 -2
- package/dist-lib/lib/core/files/rag/build.js +1 -2
- package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/index.d.ts +4 -24
- package/dist-lib/lib/core/files/rag/index.js +3 -17
- package/dist-lib/lib/core/files/rag/load.d.ts +1 -2
- package/dist-lib/lib/core/files/rag/load.js +1 -2
- package/dist-lib/lib/core/files/rag/produce.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/produce.js +1 -3
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +1 -4
- package/dist-lib/lib/core/files/rag/similarity.d.ts +5 -0
- package/dist-lib/lib/core/files/rag/similarity.js +6 -0
- package/dist-lib/lib/core/files/upload.d.ts +1 -1
- package/dist-lib/lib/core/harness-loan.js +1 -1
- package/dist-lib/lib/core/inference-calls-handoff.d.ts +20 -0
- package/dist-lib/lib/core/inference-calls-handoff.js +37 -0
- package/dist-lib/lib/core/inference-calls-receiver.d.ts +14 -0
- package/dist-lib/lib/core/inference-calls-receiver.js +39 -0
- package/dist-lib/lib/core/local/index.js +6 -0
- package/dist-lib/lib/core/notification.js +5 -4
- package/dist-lib/lib/core.d.ts +9 -1
- package/dist-lib/lib/core.js +98 -16
- package/dist-lib/lib/fs-drive-bridge.js +1 -1
- package/dist-lib/lib/inference-calls.d.ts +40 -0
- package/dist-lib/lib/inference-calls.js +266 -0
- 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/content.js +5 -1
- package/dist-lib/schema/engine.js +42 -1
- package/dist-lib/schema/qvac.d.ts +3 -0
- package/dist-lib/schema/qvac.js +11 -2
- 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 +172 -49
- package/dist-lib/spec/hyperschema/index.js +172 -49
- package/dist-lib/spec/hyperschema/schema.json +127 -1
- package/dist-lib/spec/hyperschema/types.d.ts +34 -1
- package/dist-lib/spec/local/hyperdb/messages.js +64 -128
- package/dist-lib/spec/local/hyperschema/index.js +32 -64
- package/dist-lib/spec/local/hyperschema/schema.json +16 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +176 -311
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +132 -236
- package/dist-lib/spec/mesh/hyperschema/index.js +132 -236
- package/dist-lib/spec/mesh/hyperschema/schema.json +70 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +3 -1
- package/package.json +14 -17
- package/tui/app.mjs +327 -46
- package/tui/lib/knowledge-import.mjs +1 -1
- package/tui/lib/render.mjs +17 -1
- package/tui/lib/selection.mjs +16 -0
- package/tui/lib/usage.mjs +54 -0
- package/.claude/skills/asana/SKILL.md +0 -86
- package/.claude/skills/compaction/SKILL.md +0 -132
- package/.claude/skills/device-mesh-debug/SKILL.md +0 -328
- package/.claude/skills/gh-stack/SKILL.md +0 -181
- package/.claude/skills/gh-stack/references/commands.md +0 -177
- package/.claude/skills/gh-stack/references/stack-design.md +0 -97
- package/.claude/skills/gh-stack/references/troubleshooting.md +0 -159
- package/.claude/skills/js-house-style/SKILL.md +0 -670
- package/.claude/skills/pr-create/SKILL.md +0 -201
- package/.claude/skills/pr-review/SKILL.md +0 -424
- package/CLAUDE.md +0 -43
- package/dist-lib/lib/core/files/rag/artifact/codec.d.ts +0 -3
- package/dist-lib/lib/core/files/rag/artifact/codec.js +0 -172
- package/dist-lib/lib/core/files/rag/artifact/id.d.ts +0 -10
- package/dist-lib/lib/core/files/rag/artifact/id.js +0 -39
- package/dist-lib/lib/core/files/rag/artifact/types.d.ts +0 -24
- package/dist-lib/lib/core/files/rag/artifact/types.js +0 -41
- package/dist-lib/lib/core/files/rag/chunk/chunking.d.ts +0 -12
- package/dist-lib/lib/core/files/rag/chunk/chunking.js +0 -117
- package/dist-lib/lib/core/files/rag/chunk/metadata.d.ts +0 -30
- package/dist-lib/lib/core/files/rag/chunk/metadata.js +0 -89
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.d.ts +0 -7
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.js +0 -18
- package/dist-lib/lib/core/files/rag/extract/csv-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/csv-text.js +0 -117
- package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +0 -22
- package/dist-lib/lib/core/files/rag/extract/document-types.js +0 -152
- package/dist-lib/lib/core/files/rag/extract/extract.d.ts +0 -17
- package/dist-lib/lib/core/files/rag/extract/extract.js +0 -81
- package/dist-lib/lib/core/files/rag/extract/html-table-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/html-table-text.js +0 -125
- package/dist-lib/lib/core/files/rag/extract/html-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/html-text.js +0 -132
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.d.ts +0 -17
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +0 -141
- package/dist-lib/lib/core/files/rag/extract/pdf-text.d.ts +0 -12
- package/dist-lib/lib/core/files/rag/extract/pdf-text.js +0 -43
- package/dist-lib/lib/core/files/rag/extract/rtf-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/rtf-text.js +0 -15
- package/dist-lib/lib/core/files/rag/extract/text-decoding.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/text-decoding.js +0 -91
- package/dist-lib/lib/core/files/rag/extract/types.d.ts +0 -36
- package/dist-lib/lib/core/files/rag/extract/types.js +0 -12
- package/dist-lib/lib/core/files/rag/extract/utf.d.ts +0 -2
- package/dist-lib/lib/core/files/rag/extract/utf.js +0 -18
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.d.ts +0 -2
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.js +0 -16
- package/dist-lib/lib/core/files/rag/retrieval/coverage.d.ts +0 -4
- package/dist-lib/lib/core/files/rag/retrieval/coverage.js +0 -48
- package/dist-lib/lib/core/files/rag/retrieval/diversity.d.ts +0 -10
- package/dist-lib/lib/core/files/rag/retrieval/diversity.js +0 -37
- package/dist-lib/lib/core/files/rag/retrieval/floor.d.ts +0 -5
- package/dist-lib/lib/core/files/rag/retrieval/floor.js +0 -21
- package/dist-lib/lib/core/files/rag/retrieval/format.d.ts +0 -6
- package/dist-lib/lib/core/files/rag/retrieval/format.js +0 -21
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.d.ts +0 -2
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +0 -54
- package/dist-lib/lib/core/files/rag/retrieval/notices.d.ts +0 -16
- package/dist-lib/lib/core/files/rag/retrieval/notices.js +0 -27
- package/dist-lib/lib/core/files/rag/retrieval/scoring.d.ts +0 -8
- package/dist-lib/lib/core/files/rag/retrieval/scoring.js +0 -82
- package/dist-lib/lib/core/files/rag/retrieval/search.d.ts +0 -3
- package/dist-lib/lib/core/files/rag/retrieval/search.js +0 -49
- package/dist-lib/lib/core/files/rag/retrieval/selection.d.ts +0 -11
- package/dist-lib/lib/core/files/rag/retrieval/selection.js +0 -93
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.d.ts +0 -6
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.js +0 -79
- package/dist-lib/lib/core/files/rag/retrieval/sources.d.ts +0 -13
- package/dist-lib/lib/core/files/rag/retrieval/sources.js +0 -20
- package/dist-lib/lib/core/files/rag/retrieval/target.d.ts +0 -13
- package/dist-lib/lib/core/files/rag/retrieval/target.js +0 -89
- package/dist-lib/lib/core/files/rag/retrieval/terms.d.ts +0 -8
- package/dist-lib/lib/core/files/rag/retrieval/terms.js +0 -70
- package/dist-lib/lib/core/files/rag/retrieval/types.d.ts +0 -29
- package/dist-lib/lib/core/files/rag/retrieval/types.js +0 -1
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.d.ts +0 -8
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +0 -41
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.js +0 -96
- package/dist-lib/lib/core/files/rag/vector/memory.d.ts +0 -15
- package/dist-lib/lib/core/files/rag/vector/memory.js +0 -135
- package/dist-lib/lib/core/files/rag/vector/types.d.ts +0 -28
- package/dist-lib/lib/core/files/rag/vector/types.js +0 -1
|
@@ -11,6 +11,7 @@ import { loanFailureNotice } from './core/harness-loan.js';
|
|
|
11
11
|
import { SKILL_STATE } from '@qvac/harness/lib/tools/skills/skill-state.ts';
|
|
12
12
|
import { toolsetEnabled } from '@qvac/harness/lib/tools/toolsets.ts';
|
|
13
13
|
import { RAG_CITATION_LINE } from '@qvac/harness/lib/prompt.ts';
|
|
14
|
+
import { MAX_RAG_SOURCE_URL_CHARS, MAX_RAG_SOURCES_PER_CHUNK, RAG_SOURCE_EXCERPT_CHARS } from '../schema/qvac.js';
|
|
14
15
|
import { acceptedRepairCount, historyBranches, isPromptChunk } from './core/prompt-history.js';
|
|
15
16
|
import ReadyGuard from 'ready-guard';
|
|
16
17
|
import ReadyResource from 'ready-resource';
|
|
@@ -26,6 +27,7 @@ import { imageCacheName, sweepImageCache } from './core/image/cache-sweep.js';
|
|
|
26
27
|
import { IMAGE_MIMES, normalizeImageForModel } from './core/image/normalize.js';
|
|
27
28
|
import { summarizeRuns } from './diagnostics.js';
|
|
28
29
|
import { resolveFsGrants } from './fs-drive-bridge.js';
|
|
30
|
+
import { InferenceCallStore } from './inference-calls.js';
|
|
29
31
|
import { fsGrantKey, fsWriteGrantKey } from './fs-grant-keys.js';
|
|
30
32
|
import { fsGrantsFrom, grantedDirsFrom } from './fs-grants.js';
|
|
31
33
|
import { defaultImageCacheDir } from './image-cache-dir.js';
|
|
@@ -42,7 +44,7 @@ import { encodeAgentSkillReadiness } from './skill-readiness.js';
|
|
|
42
44
|
import { harnessClearKvCache, harnessDeathReason, harnessDeleteModel, harnessDied, harnessListModels, harnessSkillCatalog, harnessSkillManagement, harnessSpeak, harnessSpeakStream, harnessTools, harnessTranscribe, imageDownloadProgress, modelCatalogChanged, toolReportEntry } from './assistant/harness.js';
|
|
43
45
|
import { annotateUnreadableImages, audioTranscriptBlock, backfillDocumentOnlyTurn, backfillImageOnlyTurns, silentAudioNotice, unheardAudioNotice } from './assistant/message.js';
|
|
44
46
|
import { drainBody, raceInactivity } from './assistant/fetch-body.js';
|
|
45
|
-
import { GENERIC_ACKNOWLEDGEMENTS, HISTORY_TYPES, SKILL_TOOL, TERMINAL_STATES, historyFromChunks, inputAvailableToRun, listHistoryChunks, staleToolRunIds
|
|
47
|
+
import { GENERIC_ACKNOWLEDGEMENTS, HISTORY_TYPES, SKILL_TOOL, TERMINAL_STATES, historyFromChunks, inputAvailableToRun, listHistoryChunks, staleToolRunIds } from './assistant/history.js';
|
|
46
48
|
export { harnessClearKvCache, harnessDeleteModel, harnessListModels, harnessSkillCatalog, harnessSkillManagement, harnessSpeak, harnessSpeakStream, harnessTools, harnessTranscribe } from './assistant/harness.js';
|
|
47
49
|
export {} from './assistant/skill-encode.js';
|
|
48
50
|
export { annotateUnreadableImages, unheardAudioNotice, unreadableImagesNotice, DOCUMENT_ONLY_USER_PROMPT, IMAGE_AND_DOCUMENT_USER_PROMPT, IMAGE_ONLY_USER_PROMPT } from './assistant/message.js';
|
|
@@ -63,12 +65,11 @@ function isDeniedResult(result) {
|
|
|
63
65
|
return false;
|
|
64
66
|
return result.denied === true;
|
|
65
67
|
}
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
+
const TITLE_RUN_ID = 'chat-title';
|
|
69
|
+
export const CAPTURE_INFERENCE_CALLS_KEY = 'inspector.captureInferenceCalls';
|
|
70
|
+
export const CAPTURE_ON = 'on';
|
|
71
|
+
export const CAPTURE_OFF = 'off';
|
|
68
72
|
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
73
|
const SUSPENDED = RUN_ABORT_REASONS.suspended;
|
|
73
74
|
const OWNERSHIP_LOST = RUN_ABORT_REASONS.ownershipLost;
|
|
74
75
|
const RUN_SETTLED = RUN_ABORT_REASONS.runSettled;
|
|
@@ -85,6 +86,11 @@ function withConfigDefaults(agent, config) {
|
|
|
85
86
|
return agent;
|
|
86
87
|
return { ...agent, ctxSize: config.ctxSize };
|
|
87
88
|
}
|
|
89
|
+
const RAG_SOURCE_BOUNDS = {
|
|
90
|
+
maxSources: MAX_RAG_SOURCES_PER_CHUNK,
|
|
91
|
+
excerptChars: RAG_SOURCE_EXCERPT_CHARS
|
|
92
|
+
};
|
|
93
|
+
const WEB_RAG_SOURCE_BOUNDS = { ...RAG_SOURCE_BOUNDS, maxUrlChars: MAX_RAG_SOURCE_URL_CHARS };
|
|
88
94
|
export class QvacAssistant extends ReadyResource {
|
|
89
95
|
_engine;
|
|
90
96
|
_harness;
|
|
@@ -118,10 +124,8 @@ export class QvacAssistant extends ReadyResource {
|
|
|
118
124
|
_harnessDiagnostics;
|
|
119
125
|
_harnessDeath;
|
|
120
126
|
_refreshingDiagnostics;
|
|
121
|
-
_requests;
|
|
122
127
|
_meshList;
|
|
123
|
-
|
|
124
|
-
_retryMs = CONSUME_RETRY_MS;
|
|
128
|
+
_advertisedOn;
|
|
125
129
|
_chatList;
|
|
126
130
|
_agentList;
|
|
127
131
|
_chatListWatch;
|
|
@@ -130,6 +134,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
130
134
|
_runConsumers;
|
|
131
135
|
_runs;
|
|
132
136
|
_seen;
|
|
137
|
+
_inferenceCalls;
|
|
133
138
|
_lifecycle;
|
|
134
139
|
_audioTranscripts;
|
|
135
140
|
_chats;
|
|
@@ -138,7 +143,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
138
143
|
_modelCatalog = new ModelCatalogRevisionHub();
|
|
139
144
|
_onHarnessStatus;
|
|
140
145
|
_onModelCatalogEvent;
|
|
141
|
-
constructor(engine, harness, { logger = null, imageCacheDir, imageCacheMaxBytes, imageCacheMaxAgeMs, downloadRetryMs, platform = os.platform(), preloadCurrentAgentModel = true, drives, borrowHarness, blobReadTimeoutMs = BLOB_READ_TIMEOUT_MS } = {}) {
|
|
146
|
+
constructor(engine, harness, { logger = null, imageCacheDir, inferenceCallsDir, imageCacheMaxBytes, imageCacheMaxAgeMs, downloadRetryMs, platform = os.platform(), preloadCurrentAgentModel = true, drives, borrowHarness, blobReadTimeoutMs = BLOB_READ_TIMEOUT_MS } = {}) {
|
|
142
147
|
super();
|
|
143
148
|
this._engine = engine;
|
|
144
149
|
this._harness = harness;
|
|
@@ -164,17 +169,17 @@ export class QvacAssistant extends ReadyResource {
|
|
|
164
169
|
this._harnessDiagnostics = null;
|
|
165
170
|
this._harnessDeath = null;
|
|
166
171
|
this._refreshingDiagnostics = false;
|
|
167
|
-
this._requests = null;
|
|
168
172
|
this._meshList = null;
|
|
169
|
-
this.
|
|
173
|
+
this._advertisedOn = null;
|
|
170
174
|
this._chatList = null;
|
|
171
175
|
this._agentList = null;
|
|
172
|
-
this._chatListWatch = this.
|
|
173
|
-
this._agentWatch = this.
|
|
174
|
-
this._meshListWatch = this.
|
|
176
|
+
this._chatListWatch = this._supervisedWatch('chat-list', () => this._watchChatList());
|
|
177
|
+
this._agentWatch = this._supervisedWatch('agent', () => this._watchAgents());
|
|
178
|
+
this._meshListWatch = this._supervisedWatch('mesh-list', () => this._watchMeshList());
|
|
175
179
|
this._runConsumers = new Map();
|
|
176
180
|
this._runs = new Map();
|
|
177
181
|
this._seen = new Map();
|
|
182
|
+
this._inferenceCalls = new InferenceCallStore(inferenceCallsDir);
|
|
178
183
|
this._lifecycle = new AbortController();
|
|
179
184
|
this._audioTranscripts = new Map();
|
|
180
185
|
this._chats = new Map();
|
|
@@ -226,7 +231,6 @@ export class QvacAssistant extends ReadyResource {
|
|
|
226
231
|
mobileClass: this._mobileClass
|
|
227
232
|
});
|
|
228
233
|
this._downloads.start();
|
|
229
|
-
this._startConsume();
|
|
230
234
|
this._chatListWatch.start();
|
|
231
235
|
this._agentWatch.start();
|
|
232
236
|
this._meshListWatch.start();
|
|
@@ -243,12 +247,12 @@ export class QvacAssistant extends ReadyResource {
|
|
|
243
247
|
if (this._warmedModel)
|
|
244
248
|
return;
|
|
245
249
|
const deviceId = this._deviceId;
|
|
246
|
-
const config = await this._engine.getConfig({}).catch(
|
|
250
|
+
const config = await this._engine.getConfig({}).catch(noop);
|
|
247
251
|
const agent = await this._currentAgent(config?.activeAgentId ?? null, deviceId);
|
|
248
252
|
if (!agent?.modelName || !agent.providerDeviceId?.equals(deviceId) || this.suspended)
|
|
249
253
|
return;
|
|
250
254
|
const model = runnableModelName(agent.modelName, await this._ensureCapability(), this._mobileClass);
|
|
251
|
-
const rows = await this._harness.list?.({ cachedOnly: true }).catch(
|
|
255
|
+
const rows = await this._harness.list?.({ cachedOnly: true }).catch(noop);
|
|
252
256
|
if (!rows?.some((row) => row.name === model && row.isCached)) {
|
|
253
257
|
this._log?.info('models', 'model warm skipped', { model, reason: 'not cached' });
|
|
254
258
|
return;
|
|
@@ -268,7 +272,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
268
272
|
}
|
|
269
273
|
async _currentAgent(activeAgentId, deviceId) {
|
|
270
274
|
if (activeAgentId) {
|
|
271
|
-
const agent = await this._engine.getAgent({ id: activeAgentId }).catch(
|
|
275
|
+
const agent = await this._engine.getAgent({ id: activeAgentId }).catch(noop);
|
|
272
276
|
if (agent && !agent.deletedAt)
|
|
273
277
|
return agent;
|
|
274
278
|
}
|
|
@@ -284,6 +288,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
284
288
|
try {
|
|
285
289
|
await Promise.allSettled([
|
|
286
290
|
this._sweepImageCache(),
|
|
291
|
+
this._sweepInferenceCalls(),
|
|
287
292
|
this._reportCapabilities(),
|
|
288
293
|
this._reconcileDeviceProfile()
|
|
289
294
|
]);
|
|
@@ -344,6 +349,16 @@ export class QvacAssistant extends ReadyResource {
|
|
|
344
349
|
this._log?.warn('assistant', 'image cache sweep failed', err);
|
|
345
350
|
}
|
|
346
351
|
}
|
|
352
|
+
async _sweepInferenceCalls() {
|
|
353
|
+
try {
|
|
354
|
+
const { removed } = await this._inferenceCalls.sweep();
|
|
355
|
+
if (removed > 0)
|
|
356
|
+
this._log?.info('assistant', 'inspector records swept', { removed });
|
|
357
|
+
}
|
|
358
|
+
catch (err) {
|
|
359
|
+
this._log?.warn('assistant', 'inspector record sweep failed', err);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
347
362
|
_imageCacheInUse(name) {
|
|
348
363
|
for (const names of this._runImageCacheNames.values())
|
|
349
364
|
if (names.has(name))
|
|
@@ -378,6 +393,22 @@ export class QvacAssistant extends ReadyResource {
|
|
|
378
393
|
supportsImages: this._harness.supportsImages ?? false
|
|
379
394
|
});
|
|
380
395
|
}
|
|
396
|
+
async _capturingInferenceCalls() {
|
|
397
|
+
try {
|
|
398
|
+
const { value } = await this._engine.configGet({ key: CAPTURE_INFERENCE_CALLS_KEY });
|
|
399
|
+
return value === CAPTURE_ON;
|
|
400
|
+
}
|
|
401
|
+
catch (err) {
|
|
402
|
+
this._log?.warn('assistant', 'inspector capture flag unreadable', { err });
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
inferenceCalls(chatId) {
|
|
407
|
+
return this._inferenceCalls.list(chatId);
|
|
408
|
+
}
|
|
409
|
+
forgetInferenceCalls(chatId) {
|
|
410
|
+
return this._inferenceCalls.forget(chatId);
|
|
411
|
+
}
|
|
381
412
|
diagnosticsSlice() {
|
|
382
413
|
const harness = this._harness.diagnostics?.() ?? this._harnessDiagnostics;
|
|
383
414
|
void this._refreshHarnessDiagnostics();
|
|
@@ -515,8 +546,6 @@ export class QvacAssistant extends ReadyResource {
|
|
|
515
546
|
}
|
|
516
547
|
}
|
|
517
548
|
async _close() {
|
|
518
|
-
if (this._retry)
|
|
519
|
-
clearTimeout(this._retry);
|
|
520
549
|
this._chatListWatch.stop();
|
|
521
550
|
this._agentWatch.stop();
|
|
522
551
|
this._stopMeshIntake();
|
|
@@ -528,7 +557,6 @@ export class QvacAssistant extends ReadyResource {
|
|
|
528
557
|
run.controller.abort(RUNNER_CLOSED);
|
|
529
558
|
await this._downloads?.close();
|
|
530
559
|
this._modelCatalog.close();
|
|
531
|
-
await this._requests?.return?.();
|
|
532
560
|
await this._meshList?.return?.();
|
|
533
561
|
await this._chatList?.return?.();
|
|
534
562
|
await this._agentList?.return?.();
|
|
@@ -552,13 +580,10 @@ export class QvacAssistant extends ReadyResource {
|
|
|
552
580
|
return;
|
|
553
581
|
this._state = QvacState.SUSPEND;
|
|
554
582
|
this._log?.info('assistant', 'suspending', { runs: this._runs.size });
|
|
555
|
-
if (this._retry)
|
|
556
|
-
clearTimeout(this._retry);
|
|
557
583
|
this._chatListWatch.stop();
|
|
558
584
|
this._agentWatch.stop();
|
|
559
585
|
this._stopMeshIntake();
|
|
560
586
|
await this._downloads?.suspend();
|
|
561
|
-
await this._requests?.return?.();
|
|
562
587
|
await this._meshList?.return?.();
|
|
563
588
|
await this._chatList?.return?.();
|
|
564
589
|
await this._agentList?.return?.();
|
|
@@ -591,7 +616,6 @@ export class QvacAssistant extends ReadyResource {
|
|
|
591
616
|
await Promise.allSettled([...this._runs.values()].map((run) => run.done));
|
|
592
617
|
this._downloads?.resume();
|
|
593
618
|
if (this.opened) {
|
|
594
|
-
this._startConsume();
|
|
595
619
|
this._chatListWatch.start();
|
|
596
620
|
this._agentWatch.start();
|
|
597
621
|
this._meshListWatch.start();
|
|
@@ -615,7 +639,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
615
639
|
if (!this.opened)
|
|
616
640
|
await this.ready();
|
|
617
641
|
if (agentId) {
|
|
618
|
-
const agent = await this._engine.getAgent({ id: agentId }).catch(
|
|
642
|
+
const agent = await this._engine.getAgent({ id: agentId }).catch(noop);
|
|
619
643
|
const deviceId = this._deviceId;
|
|
620
644
|
if (agent && deviceId && !agent.providerDeviceId?.equals(deviceId)) {
|
|
621
645
|
agentId = null;
|
|
@@ -663,35 +687,29 @@ export class QvacAssistant extends ReadyResource {
|
|
|
663
687
|
async tools() {
|
|
664
688
|
return (await this._harness.tools?.()) ?? [];
|
|
665
689
|
}
|
|
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;
|
|
690
|
+
_supervisedWatch(label, run) {
|
|
691
|
+
let running = false;
|
|
692
|
+
let again = false;
|
|
693
|
+
const settle = (err) => {
|
|
694
|
+
running = false;
|
|
676
695
|
if (err !== null && !isMeshTransition(err)) {
|
|
677
|
-
this._log?.error('assistant', `${label} watch failed
|
|
696
|
+
this._log?.error('assistant', `${label} watch failed`, err);
|
|
678
697
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
timer = setTimeout(start, delay);
|
|
698
|
+
if (again)
|
|
699
|
+
start();
|
|
682
700
|
};
|
|
683
701
|
const start = () => {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
stopped = true;
|
|
691
|
-
if (timer)
|
|
692
|
-
clearTimeout(timer);
|
|
702
|
+
again = false;
|
|
703
|
+
if (this.closing || this.suspended)
|
|
704
|
+
return;
|
|
705
|
+
if (running) {
|
|
706
|
+
again = true;
|
|
707
|
+
return;
|
|
693
708
|
}
|
|
709
|
+
running = true;
|
|
710
|
+
run().then(() => settle(null), (err) => settle(err));
|
|
694
711
|
};
|
|
712
|
+
return { start, stop: () => void (again = false) };
|
|
695
713
|
}
|
|
696
714
|
async _watchChatList() {
|
|
697
715
|
const stream = this._engine.chatsWatch({});
|
|
@@ -706,10 +724,14 @@ export class QvacAssistant extends ReadyResource {
|
|
|
706
724
|
for (const chatId of disappearedChatIds(known, ids)) {
|
|
707
725
|
this._reconciledCompactions.delete(chatId);
|
|
708
726
|
void this._deleteChatKvCache(chatId, 'chat deleted');
|
|
727
|
+
void this._inferenceCalls
|
|
728
|
+
.forget(chatId)
|
|
729
|
+
.catch((err) => this._log?.warn('assistant', 'inspector records not dropped', { err }));
|
|
709
730
|
}
|
|
710
731
|
}
|
|
711
732
|
known = new Set(ids);
|
|
712
733
|
await this._sweepImageCache();
|
|
734
|
+
await this._sweepInferenceCalls();
|
|
713
735
|
}
|
|
714
736
|
}
|
|
715
737
|
async _watchAgents() {
|
|
@@ -786,37 +808,6 @@ export class QvacAssistant extends ReadyResource {
|
|
|
786
808
|
return false;
|
|
787
809
|
}
|
|
788
810
|
}
|
|
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
811
|
async _watchMeshList() {
|
|
821
812
|
const stream = this._engine.meshesWatch({});
|
|
822
813
|
this._meshList = stream[Symbol.asyncIterator]();
|
|
@@ -824,28 +815,46 @@ export class QvacAssistant extends ReadyResource {
|
|
|
824
815
|
const { value, done } = await this._meshList.next();
|
|
825
816
|
if (done || this.closing || this.suspended)
|
|
826
817
|
return;
|
|
827
|
-
|
|
818
|
+
const meshes = value.meshes ?? [];
|
|
819
|
+
this._syncRunConsumers(meshes);
|
|
820
|
+
this._followSelectedMesh(meshes);
|
|
828
821
|
}
|
|
829
822
|
}
|
|
830
823
|
_syncRunConsumers(meshes) {
|
|
831
|
-
const
|
|
824
|
+
const open = new Set(meshes.filter((mesh) => mesh.open).map((mesh) => mesh.meshId));
|
|
832
825
|
for (const [meshId, consumer] of this._runConsumers) {
|
|
833
|
-
if (
|
|
826
|
+
if (open.has(meshId))
|
|
834
827
|
continue;
|
|
835
828
|
consumer.stop();
|
|
836
829
|
this._runConsumers.delete(meshId);
|
|
830
|
+
this._pruneSeen(meshId, new Set());
|
|
837
831
|
}
|
|
838
|
-
for (const meshId of
|
|
839
|
-
|
|
840
|
-
continue;
|
|
841
|
-
const consumer = this._meshRunConsumer(meshId);
|
|
832
|
+
for (const meshId of open) {
|
|
833
|
+
const consumer = this._runConsumers.get(meshId) ?? this._meshRunConsumer(meshId);
|
|
842
834
|
this._runConsumers.set(meshId, consumer);
|
|
843
835
|
consumer.start();
|
|
844
836
|
}
|
|
845
837
|
}
|
|
838
|
+
_followSelectedMesh(meshes) {
|
|
839
|
+
const selected = meshes.find((mesh) => mesh.active);
|
|
840
|
+
const on = selected ? `${selected.meshId}:${selected.writable}` : null;
|
|
841
|
+
if (on === null) {
|
|
842
|
+
this._advertisedOn = null;
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
if (on === this._advertisedOn)
|
|
846
|
+
return;
|
|
847
|
+
this._advertisedOn = on;
|
|
848
|
+
this._chatListWatch.start();
|
|
849
|
+
this._agentWatch.start();
|
|
850
|
+
this._downloads?.meshSelected();
|
|
851
|
+
this._lastCapabilities = null;
|
|
852
|
+
this._reportCapabilities().catch(noop);
|
|
853
|
+
this._reconcileDeviceProfile().catch(noop);
|
|
854
|
+
}
|
|
846
855
|
_meshRunConsumer(meshId) {
|
|
847
856
|
let requests = null;
|
|
848
|
-
const watch = this.
|
|
857
|
+
const watch = this._supervisedWatch(`run-requests:${meshId}`, async () => {
|
|
849
858
|
const stream = this._engine.runRequestsWatch({ meshId });
|
|
850
859
|
requests = stream[Symbol.asyncIterator]();
|
|
851
860
|
while (true) {
|
|
@@ -871,6 +880,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
871
880
|
for (const consumer of this._runConsumers.values())
|
|
872
881
|
consumer.stop();
|
|
873
882
|
this._runConsumers.clear();
|
|
883
|
+
this._advertisedOn = null;
|
|
874
884
|
}
|
|
875
885
|
_pruneSeen(meshId, live) {
|
|
876
886
|
for (const [runId, from] of this._seen) {
|
|
@@ -907,11 +917,11 @@ export class QvacAssistant extends ReadyResource {
|
|
|
907
917
|
const runId = request.runId;
|
|
908
918
|
if (!runId || this._runs.has(runId) || this._seen.has(runId))
|
|
909
919
|
return;
|
|
910
|
-
this._seen.set(runId, meshId
|
|
920
|
+
this._seen.set(runId, meshId);
|
|
911
921
|
const engine = meshScoped(this._engine, meshId);
|
|
912
922
|
const settle = (async () => {
|
|
913
923
|
const agentId = request.runRequest?.agentId;
|
|
914
|
-
const agent = await engine.getAgent({ id: agentId }).catch(
|
|
924
|
+
const agent = await engine.getAgent({ id: agentId }).catch(noop);
|
|
915
925
|
if (!agent) {
|
|
916
926
|
this._seen.delete(runId);
|
|
917
927
|
return;
|
|
@@ -948,7 +958,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
948
958
|
settle.catch((err) => this._log?.error('assistant', `run ${runId} failed`, err));
|
|
949
959
|
}
|
|
950
960
|
async _citeWebSources(transcript, runId, result) {
|
|
951
|
-
const records = webSourcesFromToolResult(result);
|
|
961
|
+
const records = webSourcesFromToolResult(result, WEB_RAG_SOURCE_BOUNDS);
|
|
952
962
|
if (records.length === 0)
|
|
953
963
|
return;
|
|
954
964
|
try {
|
|
@@ -1006,7 +1016,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1006
1016
|
}
|
|
1007
1017
|
if (await this._isHandled(engine, request))
|
|
1008
1018
|
return;
|
|
1009
|
-
const fresh = await engine.getAgent({ id: agent.id }).catch(
|
|
1019
|
+
const fresh = await engine.getAgent({ id: agent.id }).catch(noop);
|
|
1010
1020
|
if (!fresh || fresh.deletedAt || !fresh.providerDeviceId?.equals(deviceId))
|
|
1011
1021
|
return;
|
|
1012
1022
|
agent = fresh;
|
|
@@ -1167,6 +1177,8 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1167
1177
|
await transcript.flush();
|
|
1168
1178
|
};
|
|
1169
1179
|
let titleOutcome = null;
|
|
1180
|
+
let runFailure = null;
|
|
1181
|
+
let runVerdict = 'completed';
|
|
1170
1182
|
try {
|
|
1171
1183
|
const attachTurnIds = attachTurnDocumentIds(history);
|
|
1172
1184
|
if (attachTurnIds.length > 0)
|
|
@@ -1178,11 +1190,15 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1178
1190
|
if (controller.signal.aborted) {
|
|
1179
1191
|
const outcome = this._abortOutcome(runId, controller.signal.reason);
|
|
1180
1192
|
if (outcome.kind === 'replay') {
|
|
1193
|
+
runVerdict = 'replay';
|
|
1181
1194
|
this._seen.delete(runId);
|
|
1182
1195
|
return;
|
|
1183
1196
|
}
|
|
1184
|
-
if (outcome.kind === 'handoff')
|
|
1197
|
+
if (outcome.kind === 'handoff') {
|
|
1198
|
+
runVerdict = 'handoff';
|
|
1185
1199
|
return;
|
|
1200
|
+
}
|
|
1201
|
+
runFailure = outcome.reason;
|
|
1186
1202
|
await transcript.status({ state: 'failed', reason: outcome.reason, metrics });
|
|
1187
1203
|
return;
|
|
1188
1204
|
}
|
|
@@ -1208,7 +1224,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1208
1224
|
}
|
|
1209
1225
|
}
|
|
1210
1226
|
else {
|
|
1211
|
-
const records = sourcesFromHits(knowledge.hits);
|
|
1227
|
+
const records = sourcesFromHits(knowledge.hits, RAG_SOURCE_BOUNDS);
|
|
1212
1228
|
const notice = chooseRagNotice({
|
|
1213
1229
|
errorMessage: knowledge.search.errorMessage,
|
|
1214
1230
|
hitCount: records.length,
|
|
@@ -1317,7 +1333,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1317
1333
|
limit: input.limit
|
|
1318
1334
|
}), controller.signal);
|
|
1319
1335
|
const hits = found.hits ?? [];
|
|
1320
|
-
const records = sourcesFromHits(hits);
|
|
1336
|
+
const records = sourcesFromHits(hits, RAG_SOURCE_BOUNDS);
|
|
1321
1337
|
if (records.length > 0) {
|
|
1322
1338
|
try {
|
|
1323
1339
|
sourceTagFilter.add(records.map((record) => record.title));
|
|
@@ -1345,6 +1361,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1345
1361
|
},
|
|
1346
1362
|
progress: (update) => modelWatch.image(update),
|
|
1347
1363
|
generationParams: diagramRepair ? { reasoning_budget: 0 } : undefined,
|
|
1364
|
+
captureInferenceCalls: await this._capturingInferenceCalls(),
|
|
1348
1365
|
signal: controller.signal
|
|
1349
1366
|
});
|
|
1350
1367
|
let harnessEvents = 0;
|
|
@@ -1368,6 +1385,25 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1368
1385
|
this._log?.info('runs', 'run metrics', { runId, ...runMetricsSummary(rest) });
|
|
1369
1386
|
continue;
|
|
1370
1387
|
}
|
|
1388
|
+
if (event.type === 'inference-sent') {
|
|
1389
|
+
void this._inferenceCalls
|
|
1390
|
+
.recordSent(chatId, {
|
|
1391
|
+
runId,
|
|
1392
|
+
round: Number(event.round ?? 0),
|
|
1393
|
+
messages: event.messages,
|
|
1394
|
+
tokens: event.tokens,
|
|
1395
|
+
outcome: event.outcome,
|
|
1396
|
+
reason: event.reason
|
|
1397
|
+
})
|
|
1398
|
+
.catch((err) => this._log?.warn('assistant', 'sent slice not recorded', { err }));
|
|
1399
|
+
continue;
|
|
1400
|
+
}
|
|
1401
|
+
if (event.type === 'inference-call') {
|
|
1402
|
+
void this._inferenceCalls
|
|
1403
|
+
.record(chatId, { runId, at: Date.now(), call: asRecord(event.call) })
|
|
1404
|
+
.catch((err) => this._log?.warn('assistant', 'inference call not recorded', { err }));
|
|
1405
|
+
continue;
|
|
1406
|
+
}
|
|
1371
1407
|
await flushTranscript();
|
|
1372
1408
|
if (event.type === 'error') {
|
|
1373
1409
|
const folded = isContextOverflowFailure(event.message) &&
|
|
@@ -1378,11 +1414,8 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1378
1414
|
signal: controller.signal,
|
|
1379
1415
|
meshId
|
|
1380
1416
|
}));
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
reason: runFailureNotice(event.message),
|
|
1384
|
-
metrics
|
|
1385
|
-
});
|
|
1417
|
+
runFailure = runFailureNotice(event.message);
|
|
1418
|
+
await transcript.status({ state: 'failed', reason: runFailure, metrics });
|
|
1386
1419
|
if (folded) {
|
|
1387
1420
|
await this._engine
|
|
1388
1421
|
.runAgent({ chatId, agentId: agent.id, parentRunId: runId })
|
|
@@ -1394,11 +1427,15 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1394
1427
|
if (event.type === 'aborted') {
|
|
1395
1428
|
const outcome = this._abortOutcome(runId, controller.signal.reason);
|
|
1396
1429
|
if (outcome.kind === 'replay') {
|
|
1430
|
+
runVerdict = 'replay';
|
|
1397
1431
|
this._seen.delete(runId);
|
|
1398
1432
|
return;
|
|
1399
1433
|
}
|
|
1400
|
-
if (outcome.kind === 'handoff')
|
|
1434
|
+
if (outcome.kind === 'handoff') {
|
|
1435
|
+
runVerdict = 'handoff';
|
|
1401
1436
|
return;
|
|
1437
|
+
}
|
|
1438
|
+
runFailure = outcome.reason;
|
|
1402
1439
|
await transcript.status({ state: 'failed', reason: outcome.reason, metrics });
|
|
1403
1440
|
titleOutcome = 'ended';
|
|
1404
1441
|
return;
|
|
@@ -1461,20 +1498,9 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1461
1498
|
});
|
|
1462
1499
|
}
|
|
1463
1500
|
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
1501
|
await transcript.status({
|
|
1476
1502
|
state: 'completed',
|
|
1477
|
-
metrics: citedTitles ? { ...
|
|
1503
|
+
metrics: citedTitles ? { ...metrics, citedTitles } : metrics
|
|
1478
1504
|
});
|
|
1479
1505
|
titleOutcome = 'completed';
|
|
1480
1506
|
}
|
|
@@ -1483,17 +1509,28 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1483
1509
|
? this._abortOutcome(runId, controller.signal.reason)
|
|
1484
1510
|
: null;
|
|
1485
1511
|
if (outcome?.kind === 'replay') {
|
|
1512
|
+
runVerdict = 'replay';
|
|
1486
1513
|
this._seen.delete(runId);
|
|
1487
1514
|
return;
|
|
1488
1515
|
}
|
|
1489
|
-
if (outcome?.kind === 'handoff')
|
|
1516
|
+
if (outcome?.kind === 'handoff') {
|
|
1517
|
+
runVerdict = 'handoff';
|
|
1490
1518
|
return;
|
|
1519
|
+
}
|
|
1491
1520
|
await flushTranscript();
|
|
1492
|
-
|
|
1493
|
-
|
|
1521
|
+
runFailure =
|
|
1522
|
+
(this._lenderFor(runAgent) ? loanFailureNotice(err) : null) ?? runFailureNotice(err);
|
|
1523
|
+
await transcript.status({ state: 'failed', reason: runFailure, metrics });
|
|
1494
1524
|
titleOutcome = 'ended';
|
|
1495
1525
|
}
|
|
1496
1526
|
finally {
|
|
1527
|
+
void this._inferenceCalls
|
|
1528
|
+
.recordOutcome(chatId, {
|
|
1529
|
+
runId,
|
|
1530
|
+
outcome: runFailure ? 'failed' : runVerdict,
|
|
1531
|
+
reason: runFailure
|
|
1532
|
+
})
|
|
1533
|
+
.catch((err) => this._log?.warn('assistant', 'run outcome not recorded', { err }));
|
|
1497
1534
|
transcript.close();
|
|
1498
1535
|
modelWatch.stop();
|
|
1499
1536
|
ownershipWatch.stop();
|
|
@@ -1583,7 +1620,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1583
1620
|
async _readBlob(url, signal) {
|
|
1584
1621
|
if (!url || signal?.aborted)
|
|
1585
1622
|
return null;
|
|
1586
|
-
const pending = defaultFetch(url).catch(
|
|
1623
|
+
const pending = defaultFetch(url).catch(noop);
|
|
1587
1624
|
try {
|
|
1588
1625
|
const response = await raceInactivity(pending, signal, this._blobReadTimeoutMs);
|
|
1589
1626
|
const bytes = response?.ok
|
|
@@ -1692,7 +1729,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1692
1729
|
}
|
|
1693
1730
|
async _hydrateImage(dir, image, signal) {
|
|
1694
1731
|
const file = path.join(dir, imageCacheName(image));
|
|
1695
|
-
const cached = await fs.promises.stat(file).catch(
|
|
1732
|
+
const cached = await fs.promises.stat(file).catch(noop);
|
|
1696
1733
|
if (!cached?.size) {
|
|
1697
1734
|
const raw = await this._readBlob(image.url, signal);
|
|
1698
1735
|
if (signal.aborted)
|
|
@@ -1706,13 +1743,13 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1706
1743
|
}
|
|
1707
1744
|
else {
|
|
1708
1745
|
const now = new Date();
|
|
1709
|
-
await fs.promises.utimes(file, now, now).catch(
|
|
1746
|
+
await fs.promises.utimes(file, now, now).catch(noop);
|
|
1710
1747
|
}
|
|
1711
1748
|
return file;
|
|
1712
1749
|
}
|
|
1713
1750
|
async _compactIfNearFull(params) {
|
|
1714
1751
|
const { chatId, transcript, trigger, signal, meshId } = params;
|
|
1715
|
-
const metrics =
|
|
1752
|
+
const metrics = await this._lastRunMetrics(chatId, meshId);
|
|
1716
1753
|
if (!nearContextLimit(metrics.cacheTokens, metrics.ctxSize))
|
|
1717
1754
|
return false;
|
|
1718
1755
|
if (!canCompact(metrics.ctxSize)) {
|
|
@@ -1793,15 +1830,15 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1793
1830
|
await this.ready();
|
|
1794
1831
|
const engine = meshScoped(this._engine, options.meshId);
|
|
1795
1832
|
const deviceId = this._deviceId;
|
|
1796
|
-
const chat = await engine.getChat({ id: chatId }).catch(
|
|
1833
|
+
const chat = await engine.getChat({ id: chatId }).catch(noop);
|
|
1797
1834
|
if (!chat)
|
|
1798
1835
|
return { compacted: false, reason: 'unknown chat' };
|
|
1799
|
-
const agent = await engine.getAgent({ id: chat.agentId }).catch(
|
|
1836
|
+
const agent = await engine.getAgent({ id: chat.agentId }).catch(noop);
|
|
1800
1837
|
if (!agent || !agent.providerDeviceId?.equals(deviceId)) {
|
|
1801
1838
|
return { compacted: false, reason: 'not the provider device' };
|
|
1802
1839
|
}
|
|
1803
1840
|
const model = runnableModelName(agent.modelName, await this._ensureCapability(), this._mobileClass);
|
|
1804
|
-
const config = await engine.getConfig({}).catch(
|
|
1841
|
+
const config = await engine.getConfig({}).catch(noop);
|
|
1805
1842
|
const ctxSize = agent.ctxSize || config?.ctxSize || undefined;
|
|
1806
1843
|
if (ctxSize !== undefined && !canCompact(ctxSize)) {
|
|
1807
1844
|
return { compacted: false, reason: 'below-floor' };
|
|
@@ -1926,6 +1963,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1926
1963
|
if (probe && !this.closing) {
|
|
1927
1964
|
try {
|
|
1928
1965
|
generated = await this._titleFromCompletion({
|
|
1966
|
+
chatId,
|
|
1929
1967
|
input: prompt,
|
|
1930
1968
|
model,
|
|
1931
1969
|
agent,
|
|
@@ -1948,7 +1986,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1948
1986
|
return title;
|
|
1949
1987
|
}
|
|
1950
1988
|
async _titleFromCompletion(params) {
|
|
1951
|
-
const { input, model, agent, signal } = params;
|
|
1989
|
+
const { chatId, input, model, agent, signal } = params;
|
|
1952
1990
|
const events = this._harnessFor(agent).completion({
|
|
1953
1991
|
model,
|
|
1954
1992
|
agent: {
|
|
@@ -1960,6 +1998,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1960
1998
|
},
|
|
1961
1999
|
messages: [{ role: 'user', content: buildTitlePrompt(input) }],
|
|
1962
2000
|
generationParams: { reasoning_budget: 0 },
|
|
2001
|
+
captureInferenceCalls: await this._capturingInferenceCalls(),
|
|
1963
2002
|
responseFormat: {
|
|
1964
2003
|
type: 'json_schema',
|
|
1965
2004
|
json_schema: {
|
|
@@ -1978,6 +2017,11 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1978
2017
|
for await (const event of events) {
|
|
1979
2018
|
if (event.type === 'content' && typeof event.text === 'string')
|
|
1980
2019
|
text += event.text;
|
|
2020
|
+
else if (event.type === 'inference-call') {
|
|
2021
|
+
void this._inferenceCalls
|
|
2022
|
+
.record(chatId, { runId: TITLE_RUN_ID, at: Date.now(), call: asRecord(event.call) })
|
|
2023
|
+
.catch((err) => this._log?.warn('assistant', 'title call not recorded', { err }));
|
|
2024
|
+
}
|
|
1981
2025
|
else if (event.type === 'error' || event.type === 'aborted' || event.type === 'done')
|
|
1982
2026
|
break;
|
|
1983
2027
|
}
|
|
@@ -2315,6 +2359,9 @@ function runMetricsSummary(metrics) {
|
|
|
2315
2359
|
stopReason
|
|
2316
2360
|
};
|
|
2317
2361
|
}
|
|
2362
|
+
function asRecord(value) {
|
|
2363
|
+
return typeof value === 'object' && value !== null ? { ...value } : {};
|
|
2364
|
+
}
|
|
2318
2365
|
function isStreamDestroyed(err) {
|
|
2319
2366
|
return typeof err === 'object' && err !== null && 'code' in err && err.code === 'STREAM_DESTROYED';
|
|
2320
2367
|
}
|