@qvac/core 0.3.1 → 0.3.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/README.md +4 -4
- package/dist-lib/lib/assistant/history.d.ts +10 -1
- package/dist-lib/lib/assistant/history.js +36 -1
- package/dist-lib/lib/assistant/message.d.ts +2 -0
- package/dist-lib/lib/assistant/message.js +11 -0
- package/dist-lib/lib/assistant/skill-encode.js +27 -1
- package/dist-lib/lib/assistant.d.ts +5 -2
- package/dist-lib/lib/assistant.js +41 -8
- package/dist-lib/lib/core/chat-activity.js +2 -8
- package/dist-lib/lib/core/skill-secrets.js +3 -6
- package/dist-lib/lib/core.d.ts +1 -0
- package/dist-lib/lib/core.js +51 -9
- package/dist-lib/lib/credential-pusher.d.ts +2 -3
- package/dist-lib/lib/credential-pusher.js +67 -39
- package/dist-lib/lib/integrations/index.d.ts +1 -2
- package/dist-lib/lib/integrations/index.js +0 -1
- package/dist-lib/lib/integrations/setup-routes.js +0 -15
- package/dist-lib/lib/oauth/flow-core.js +1 -1
- package/dist-lib/lib/oauth/flow.d.ts +4 -2
- package/dist-lib/lib/oauth/flow.js +3 -4
- package/dist-lib/lib/oauth/host.d.ts +3 -1
- package/dist-lib/lib/oauth/host.js +3 -1
- package/dist-lib/lib/oauth/keys.d.ts +21 -20
- package/dist-lib/lib/oauth/keys.js +59 -85
- package/dist-lib/lib/oauth/loopback.d.ts +2 -2
- package/dist-lib/lib/oauth/loopback.js +32 -19
- package/dist-lib/lib/oauth/loopback.stub.d.ts +2 -2
- package/dist-lib/lib/oauth/loopback.stub.js +2 -2
- package/dist-lib/lib/oauth/providers.d.ts +3 -5
- package/dist-lib/lib/oauth/providers.js +20 -67
- package/dist-lib/lib/oauth/redirect-types.d.ts +1 -0
- package/dist-lib/lib/oauth/registry.d.ts +10 -0
- package/dist-lib/lib/oauth/registry.js +25 -0
- package/dist-lib/lib/oauth/resolve.js +1 -1
- package/dist-lib/lib/oauth/token-exchange-core.js +2 -1
- package/dist-lib/lib/oauth/types.d.ts +1 -1
- package/dist-lib/lib/oauth.client.d.ts +3 -1
- package/dist-lib/lib/oauth.client.js +3 -1
- package/dist-lib/lib/oauth.d.ts +4 -7
- package/dist-lib/lib/oauth.js +4 -7
- package/dist-lib/lib/skill-types.d.ts +12 -0
- package/dist-lib/schema/engine.js +21 -1
- package/dist-lib/spec/hrpc/messages.js +114 -5
- package/dist-lib/spec/hyperschema/index.js +114 -5
- package/dist-lib/spec/hyperschema/schema.json +84 -1
- package/dist-lib/spec/hyperschema/types.d.ts +18 -1
- package/package.json +4 -4
- package/tui/app.mjs +98 -155
- package/tui/lib/save-file.mjs +1 -1
- package/dist-lib/lib/integrations/oauth-providers.d.ts +0 -14
- package/dist-lib/lib/integrations/oauth-providers.js +0 -116
- package/dist-lib/lib/oauth/asana.d.ts +0 -35
- package/dist-lib/lib/oauth/asana.js +0 -71
- package/dist-lib/lib/oauth/google.d.ts +0 -37
- package/dist-lib/lib/oauth/google.js +0 -77
- package/dist-lib/lib/oauth/notion.d.ts +0 -34
- package/dist-lib/lib/oauth/notion.js +0 -82
- package/dist-lib/lib/oauth/spotify.d.ts +0 -32
- package/dist-lib/lib/oauth/spotify.js +0 -74
- package/dist-lib/lib/oauth/verify.d.ts +0 -8
- package/dist-lib/lib/oauth/verify.js +0 -58
package/README.md
CHANGED
|
@@ -291,10 +291,10 @@ empty or absent `chatIds` returns the whole active set.
|
|
|
291
291
|
|
|
292
292
|
The media states are the only phase detail on this stream, and they belong here
|
|
293
293
|
because they are coarse and boundary-driven — image generation is one long phase,
|
|
294
|
-
not a per-token flip. Core derives them from the run's `progress.phase`
|
|
295
|
-
(`generating`
|
|
296
|
-
`
|
|
297
|
-
|
|
294
|
+
not a per-token flip. Core derives them from the run's `progress.phase` alone
|
|
295
|
+
(`generating` → image, or audio while the run's unsettled media tool is
|
|
296
|
+
`generate_music`; `transcribing` → transcription). A media tool whose model is
|
|
297
|
+
still downloading or loading reads as `running`, like every other model wait.
|
|
298
298
|
Everything finer stays off the list: the moment-to-moment phase
|
|
299
299
|
(thinking/responding, which non-media tool, the live percentage) is on the
|
|
300
300
|
per-chat chunk stream the open chat subscribes to, and model download/load
|
|
@@ -23,7 +23,16 @@ export interface CompactResult {
|
|
|
23
23
|
readonly foldedTurns?: number;
|
|
24
24
|
readonly reason?: string;
|
|
25
25
|
}
|
|
26
|
-
export declare function
|
|
26
|
+
export declare function couldNameSenders(chunks: ReadonlyArray<AssistantChunk>): boolean;
|
|
27
|
+
export declare function senderNamesFrom(chunks: ReadonlyArray<AssistantChunk>, members: ReadonlyArray<{
|
|
28
|
+
id: Buffer;
|
|
29
|
+
name: string;
|
|
30
|
+
}>, devices: ReadonlyArray<{
|
|
31
|
+
id: Buffer;
|
|
32
|
+
memberId?: Buffer | null;
|
|
33
|
+
}>): ReadonlyMap<string, string>;
|
|
34
|
+
export declare function senderAttribution(names: ReadonlyMap<string, string>): string;
|
|
35
|
+
export declare function historyFromChunks(chunks: ReadonlyArray<AssistantChunk>, stale?: Partial<StaleToolRuns>, senderNames?: ReadonlyMap<string, string>): ChatMessage[];
|
|
27
36
|
export declare function inputAvailableToRun(chunk: AssistantChunk, requestSeq: number): boolean;
|
|
28
37
|
export declare function normalizeQuestion(text: string): string;
|
|
29
38
|
export declare const GENERIC_ACKNOWLEDGEMENTS: Set<string>;
|
|
@@ -39,8 +39,40 @@ export function beforeLatestAttempt(chunk, starts) {
|
|
|
39
39
|
const start = starts.get(chunk.runId);
|
|
40
40
|
return start !== undefined && chunk.seq < start;
|
|
41
41
|
}
|
|
42
|
-
export function
|
|
42
|
+
export function couldNameSenders(chunks) {
|
|
43
|
+
const seen = new Set();
|
|
44
|
+
for (const chunk of chunks) {
|
|
45
|
+
if (chunk.type !== 'user-message')
|
|
46
|
+
continue;
|
|
47
|
+
seen.add((chunk.senderMemberId ?? chunk.originDeviceId).toString('hex'));
|
|
48
|
+
if (seen.size > 1)
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
export function senderNamesFrom(chunks, members, devices) {
|
|
54
|
+
if (members.length < 2)
|
|
55
|
+
return new Map();
|
|
56
|
+
const byMember = new Map(members.map((member) => [member.id.toString('hex'), member.name]));
|
|
57
|
+
const deviceMember = new Map(devices.map((device) => [device.id.toString('hex'), device.memberId]));
|
|
58
|
+
const names = new Map();
|
|
59
|
+
for (const chunk of chunks) {
|
|
60
|
+
if (chunk.type !== 'user-message')
|
|
61
|
+
continue;
|
|
62
|
+
const memberId = chunk.senderMemberId ?? deviceMember.get(chunk.originDeviceId.toString('hex'));
|
|
63
|
+
const name = memberId ? byMember.get(memberId.toString('hex')) : undefined;
|
|
64
|
+
if (name)
|
|
65
|
+
names.set(chunk.id, name);
|
|
66
|
+
}
|
|
67
|
+
return names;
|
|
68
|
+
}
|
|
69
|
+
export function senderAttribution(names) {
|
|
70
|
+
const distinct = [...new Set(names.values())].sort();
|
|
71
|
+
return distinct.length > 1 ? distinct.join('\u0000') : '';
|
|
72
|
+
}
|
|
73
|
+
export function historyFromChunks(chunks, stale = {}, senderNames = new Map()) {
|
|
43
74
|
const attemptStarts = latestAttemptStarts(chunks);
|
|
75
|
+
const shared = new Set(senderNames.values()).size > 1;
|
|
44
76
|
const staleRunIds = stale.runIds ?? new Set();
|
|
45
77
|
const staleQuestionChunkIds = stale.questionChunkIds ?? new Set();
|
|
46
78
|
const folded = foldCompactedChunks(chunks);
|
|
@@ -72,7 +104,10 @@ export function historyFromChunks(chunks, stale = {}) {
|
|
|
72
104
|
if (chunk.userMessage) {
|
|
73
105
|
if (staleQuestionChunkIds.has(chunk.id))
|
|
74
106
|
continue;
|
|
107
|
+
const sender = shared ? senderNames.get(chunk.id) : undefined;
|
|
75
108
|
const turn = { role: 'user', content: chunk.userMessage.text };
|
|
109
|
+
if (sender)
|
|
110
|
+
turn.sender = sender;
|
|
76
111
|
const refs = (byMessage.get(chunk.id) ?? [])
|
|
77
112
|
.map((attachmentChunk) => attachmentChunk.attachment)
|
|
78
113
|
.filter((ref) => !ref.deletedAt);
|
|
@@ -2,6 +2,7 @@ import type { DocumentAttachment } from '../core/document-attachment.ts';
|
|
|
2
2
|
export interface ChatMessage {
|
|
3
3
|
role: 'user' | 'assistant' | 'tool';
|
|
4
4
|
content: string;
|
|
5
|
+
sender?: string;
|
|
5
6
|
attachments?: {
|
|
6
7
|
path: string;
|
|
7
8
|
}[];
|
|
@@ -43,3 +44,4 @@ export interface AttachmentMeta {
|
|
|
43
44
|
export interface FetchedAttachment extends AttachmentMeta {
|
|
44
45
|
bytes: Uint8Array;
|
|
45
46
|
}
|
|
47
|
+
export declare function nameSenders(messages: ReadonlyArray<ChatMessage>): ChatMessage[];
|
|
@@ -45,3 +45,14 @@ export function audioTranscriptBlock(fileName, transcript) {
|
|
|
45
45
|
transcript
|
|
46
46
|
].join('\n');
|
|
47
47
|
}
|
|
48
|
+
const MAX_SENDER_NAME_CHARS = 64;
|
|
49
|
+
function displayableSender(name) {
|
|
50
|
+
const flat = name?.replace(/\s+/g, ' ').trim();
|
|
51
|
+
return flat ? Array.from(flat).slice(0, MAX_SENDER_NAME_CHARS).join('') : undefined;
|
|
52
|
+
}
|
|
53
|
+
export function nameSenders(messages) {
|
|
54
|
+
return messages.map(({ sender, ...turn }) => {
|
|
55
|
+
const name = displayableSender(sender);
|
|
56
|
+
return name ? { ...turn, content: `${name}: ${turn.content}` } : turn;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readSetup as normalizeSkillSetup } from '@qvac/harness/lib/tools/skills/manifest-parse.ts';
|
|
2
|
+
const TOKEN_AUTH = ['pkce-only', 'secret-in-body', 'secret-in-basic'];
|
|
2
3
|
export function toEngineSkill(skill) {
|
|
3
4
|
const setup = normalizeSkillSetup(skill.setup);
|
|
4
5
|
return {
|
|
@@ -63,7 +64,32 @@ export function toEngineSkillSetup(setup) {
|
|
|
63
64
|
}))
|
|
64
65
|
}
|
|
65
66
|
: {}),
|
|
66
|
-
...(route.satisfied !== undefined ? { satisfied: route.satisfied } : {})
|
|
67
|
+
...(route.satisfied !== undefined ? { satisfied: route.satisfied } : {}),
|
|
68
|
+
...(route.oauth &&
|
|
69
|
+
route.oauth.stateKey &&
|
|
70
|
+
route.oauth.authUrl &&
|
|
71
|
+
route.oauth.tokenUrl &&
|
|
72
|
+
TOKEN_AUTH.includes(route.oauth.tokenAuth)
|
|
73
|
+
? {
|
|
74
|
+
oauth: {
|
|
75
|
+
stateKey: route.oauth.stateKey,
|
|
76
|
+
authUrl: route.oauth.authUrl,
|
|
77
|
+
tokenUrl: route.oauth.tokenUrl,
|
|
78
|
+
tokenAuth: route.oauth.tokenAuth,
|
|
79
|
+
scopes: [...(route.oauth.scopes ?? [])],
|
|
80
|
+
...(route.oauth.extraAuthParams
|
|
81
|
+
? { extraAuthParams: route.oauth.extraAuthParams }
|
|
82
|
+
: {}),
|
|
83
|
+
...(route.oauth.registrationEndpoint
|
|
84
|
+
? { registrationEndpoint: route.oauth.registrationEndpoint }
|
|
85
|
+
: {}),
|
|
86
|
+
...(route.oauth.port !== undefined ? { port: route.oauth.port } : {}),
|
|
87
|
+
...(route.oauth.sharedIosSession !== undefined
|
|
88
|
+
? { sharedIosSession: route.oauth.sharedIosSession }
|
|
89
|
+
: {})
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
: {})
|
|
67
93
|
}))
|
|
68
94
|
}
|
|
69
95
|
: {})
|
|
@@ -12,8 +12,8 @@ import type { Skill } from './assistant/skill-encode.ts';
|
|
|
12
12
|
import { type CompactOptions, type CompactResult } from './assistant/history.ts';
|
|
13
13
|
export { harnessClearKvCache, harnessDeleteModel, harnessListModels, harnessSkillCatalog, harnessSkillManagement, harnessSpeak, harnessSpeakStream, harnessTools, harnessTranscribe, type DeleteModelSummary, type Harness, type HarnessInfo, type ListModelsOptions, type ModelInfo, type ModelType, type ToolCatalogEntry } from './assistant/harness.ts';
|
|
14
14
|
export { type Skill } from './assistant/skill-encode.ts';
|
|
15
|
-
export { annotateUnreadableImages, unheardAudioNotice, unreadableImagesNotice, DOCUMENT_ONLY_USER_PROMPT, IMAGE_AND_DOCUMENT_USER_PROMPT, IMAGE_ONLY_USER_PROMPT } from './assistant/message.ts';
|
|
16
|
-
export { historyFromChunks, listHistoryChunks, staleToolRunIds, type CompactOptions, type CompactResult, type CompactionTrigger, type StaleToolRuns } from './assistant/history.ts';
|
|
15
|
+
export { annotateUnreadableImages, unheardAudioNotice, unreadableImagesNotice, DOCUMENT_ONLY_USER_PROMPT, IMAGE_AND_DOCUMENT_USER_PROMPT, IMAGE_ONLY_USER_PROMPT, nameSenders } from './assistant/message.ts';
|
|
16
|
+
export { couldNameSenders, historyFromChunks, listHistoryChunks, senderAttribution, senderNamesFrom, staleToolRunIds, type CompactOptions, type CompactResult, type CompactionTrigger, type StaleToolRuns } from './assistant/history.ts';
|
|
17
17
|
export declare const CAPTURE_INFERENCE_CALLS_KEY = "inspector.captureInferenceCalls";
|
|
18
18
|
export declare const CAPTURE_ON = "on";
|
|
19
19
|
export declare const CAPTURE_OFF = "off";
|
|
@@ -79,6 +79,7 @@ export declare class QvacAssistant extends ReadyResource {
|
|
|
79
79
|
private readonly _chats;
|
|
80
80
|
private readonly _runImageCacheNames;
|
|
81
81
|
private readonly _reconciledCompactions;
|
|
82
|
+
private readonly _chatAttribution;
|
|
82
83
|
private readonly _modelCatalog;
|
|
83
84
|
private readonly _onHarnessStatus;
|
|
84
85
|
private readonly _onModelCatalogEvent;
|
|
@@ -129,6 +130,8 @@ export declare class QvacAssistant extends ReadyResource {
|
|
|
129
130
|
private _watchAgents;
|
|
130
131
|
private _reclaimAgentChatCaches;
|
|
131
132
|
private _reconcileCompaction;
|
|
133
|
+
private _senderNames;
|
|
134
|
+
private _reconcileAttribution;
|
|
132
135
|
deleteChatKvCache(chatId: string): Promise<AssistantKvCacheDeletionResponse>;
|
|
133
136
|
private _deleteChatKvCache;
|
|
134
137
|
private _watchMeshList;
|
|
@@ -42,13 +42,14 @@ import { searchKnowledge } from './knowledge-search.js';
|
|
|
42
42
|
import { isLifecycleTeardown, knownAbortOutcome, RUN_ABORT_REASONS, RUN_FAILURE_REASONS, runFailureNotice } from './run-notices.js';
|
|
43
43
|
import { encodeAgentSkillReadiness } from './skill-readiness.js';
|
|
44
44
|
import { harnessClearKvCache, harnessDeathReason, harnessDeleteModel, harnessDied, harnessListModels, harnessSkillCatalog, harnessSkillManagement, harnessSpeak, harnessSpeakStream, harnessTools, harnessTranscribe, imageDownloadProgress, modelCatalogChanged, toolReportEntry } from './assistant/harness.js';
|
|
45
|
-
import { annotateUnreadableImages, audioTranscriptBlock, backfillDocumentOnlyTurn, backfillImageOnlyTurns, silentAudioNotice, unheardAudioNotice } from './assistant/message.js';
|
|
45
|
+
import { annotateUnreadableImages, audioTranscriptBlock, backfillDocumentOnlyTurn, backfillImageOnlyTurns, silentAudioNotice, unheardAudioNotice, nameSenders } from './assistant/message.js';
|
|
46
46
|
import { drainBody, raceInactivity } from './assistant/fetch-body.js';
|
|
47
|
-
import { GENERIC_ACKNOWLEDGEMENTS, HISTORY_TYPES, SKILL_TOOL, TERMINAL_STATES, historyFromChunks, inputAvailableToRun, listHistoryChunks, staleToolRunIds } from './assistant/history.js';
|
|
47
|
+
import { GENERIC_ACKNOWLEDGEMENTS, HISTORY_TYPES, SKILL_TOOL, TERMINAL_STATES, couldNameSenders, historyFromChunks, inputAvailableToRun, listHistoryChunks, senderAttribution, senderNamesFrom, staleToolRunIds } from './assistant/history.js';
|
|
48
48
|
export { harnessClearKvCache, harnessDeleteModel, harnessListModels, harnessSkillCatalog, harnessSkillManagement, harnessSpeak, harnessSpeakStream, harnessTools, harnessTranscribe } from './assistant/harness.js';
|
|
49
49
|
export {} from './assistant/skill-encode.js';
|
|
50
|
-
export { annotateUnreadableImages, unheardAudioNotice, unreadableImagesNotice, DOCUMENT_ONLY_USER_PROMPT, IMAGE_AND_DOCUMENT_USER_PROMPT, IMAGE_ONLY_USER_PROMPT } from './assistant/message.js';
|
|
51
|
-
export { historyFromChunks, listHistoryChunks, staleToolRunIds } from './assistant/history.js';
|
|
50
|
+
export { annotateUnreadableImages, unheardAudioNotice, unreadableImagesNotice, DOCUMENT_ONLY_USER_PROMPT, IMAGE_AND_DOCUMENT_USER_PROMPT, IMAGE_ONLY_USER_PROMPT, nameSenders } from './assistant/message.js';
|
|
51
|
+
export { couldNameSenders, historyFromChunks, listHistoryChunks, senderAttribution, senderNamesFrom, staleToolRunIds } from './assistant/history.js';
|
|
52
|
+
const NO_SENDERS = new Map();
|
|
52
53
|
const QvacState = local.getEnum('@local/qvac-state');
|
|
53
54
|
const FINAL_FLUSH_MS = 10_000;
|
|
54
55
|
const UPLOAD_FRAME_BYTES = 64 * 1024;
|
|
@@ -140,6 +141,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
140
141
|
_chats;
|
|
141
142
|
_runImageCacheNames;
|
|
142
143
|
_reconciledCompactions;
|
|
144
|
+
_chatAttribution;
|
|
143
145
|
_modelCatalog = new ModelCatalogRevisionHub();
|
|
144
146
|
_onHarnessStatus;
|
|
145
147
|
_onModelCatalogEvent;
|
|
@@ -185,6 +187,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
185
187
|
this._chats = new Map();
|
|
186
188
|
this._runImageCacheNames = new Map();
|
|
187
189
|
this._reconciledCompactions = new Map();
|
|
190
|
+
this._chatAttribution = new Map();
|
|
188
191
|
this._onHarnessStatus = (status) => {
|
|
189
192
|
this._log?.warn('assistant', 'harness status', status);
|
|
190
193
|
if (harnessDied(status)) {
|
|
@@ -723,6 +726,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
723
726
|
if (known !== null) {
|
|
724
727
|
for (const chatId of disappearedChatIds(known, ids)) {
|
|
725
728
|
this._reconciledCompactions.delete(chatId);
|
|
729
|
+
this._chatAttribution.delete(chatId);
|
|
726
730
|
void this._deleteChatKvCache(chatId, 'chat deleted');
|
|
727
731
|
void this._inferenceCalls
|
|
728
732
|
.forget(chatId)
|
|
@@ -784,6 +788,29 @@ export class QvacAssistant extends ReadyResource {
|
|
|
784
788
|
if (gone)
|
|
785
789
|
this._reconciledCompactions.set(chatId, newest.id);
|
|
786
790
|
}
|
|
791
|
+
async _senderNames(engine, chunks) {
|
|
792
|
+
if (!couldNameSenders(chunks))
|
|
793
|
+
return new Map();
|
|
794
|
+
const stamped = chunks.every((chunk) => chunk.type !== 'user-message' || chunk.senderMemberId);
|
|
795
|
+
const [{ members }, { devices }] = await Promise.all([
|
|
796
|
+
engine.listMembers({}).catch(() => ({ members: [] })),
|
|
797
|
+
stamped ? { devices: [] } : engine.listDevices({}).catch(() => ({ devices: [] }))
|
|
798
|
+
]);
|
|
799
|
+
return senderNamesFrom(chunks, members ?? [], devices ?? []);
|
|
800
|
+
}
|
|
801
|
+
async _reconcileAttribution(chatId, senders) {
|
|
802
|
+
const attribution = senderAttribution(senders);
|
|
803
|
+
const seen = this._chatAttribution.get(chatId);
|
|
804
|
+
if (seen === attribution)
|
|
805
|
+
return;
|
|
806
|
+
if (seen === undefined && !attribution) {
|
|
807
|
+
this._chatAttribution.set(chatId, attribution);
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
const gone = await this._deleteChatKvCache(chatId, 'sender attribution changed');
|
|
811
|
+
if (gone)
|
|
812
|
+
this._chatAttribution.set(chatId, attribution);
|
|
813
|
+
}
|
|
787
814
|
async deleteChatKvCache(chatId) {
|
|
788
815
|
return ((await this._harness.deleteKvCache?.(chatKvCacheKey(chatId))) ?? {
|
|
789
816
|
status: 'unsupported',
|
|
@@ -1082,7 +1109,12 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1082
1109
|
let ran = (priorResults ?? []).some((chunk) => chunk.runId === runId &&
|
|
1083
1110
|
chunk.toolResult?.name !== SKILL_TOOL &&
|
|
1084
1111
|
!isDeniedResult(chunk.toolResult?.result));
|
|
1085
|
-
const
|
|
1112
|
+
const named = couldNameSenders(history);
|
|
1113
|
+
const senders = named ? await this._senderNames(engine, history) : NO_SENDERS;
|
|
1114
|
+
if (named || this._chatAttribution.get(chatId)) {
|
|
1115
|
+
await this._reconcileAttribution(chatId, senders);
|
|
1116
|
+
}
|
|
1117
|
+
const messages = historyFromChunks(history, staleToolRunIds(history, priorAsks ?? [], runId), senders);
|
|
1086
1118
|
if (currentRepair)
|
|
1087
1119
|
messages.push({ role: 'user', content: currentRepair.promptText });
|
|
1088
1120
|
const diagramRepair = currentRepair !== undefined;
|
|
@@ -1314,7 +1346,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1314
1346
|
const events = this._harnessFor(runAgent).completion({
|
|
1315
1347
|
model,
|
|
1316
1348
|
agent: runAgent,
|
|
1317
|
-
messages,
|
|
1349
|
+
messages: nameSenders(messages),
|
|
1318
1350
|
cacheKey,
|
|
1319
1351
|
thinkingDefault: config ? (config.thinkingEnabled ? 'enabled' : 'disabled') : undefined,
|
|
1320
1352
|
toolConfigs,
|
|
@@ -1854,6 +1886,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1854
1886
|
const userTurns = chunks.filter((chunk) => chunk.userMessage).length;
|
|
1855
1887
|
let announced = false;
|
|
1856
1888
|
let keepTurns = COMPACTION_KEEP_TURNS;
|
|
1889
|
+
const senders = await this._senderNames(engine, chunks);
|
|
1857
1890
|
for (;;) {
|
|
1858
1891
|
const boundary = compactionBoundary(chunks, keepTurns);
|
|
1859
1892
|
if (!boundary)
|
|
@@ -1864,7 +1897,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1864
1897
|
if (through.seq <= lastThroughSeq)
|
|
1865
1898
|
return { compacted: false, reason: 'already-compacted' };
|
|
1866
1899
|
const inRange = chunks.filter((chunk) => chunk.seq <= through.seq);
|
|
1867
|
-
const folded = historyFromChunks(inRange, staleToolRunIds(inRange, priorAsks ?? [], ''));
|
|
1900
|
+
const folded = historyFromChunks(inRange, staleToolRunIds(inRange, priorAsks ?? [], ''), senders);
|
|
1868
1901
|
if (!announced) {
|
|
1869
1902
|
await options.onFold?.();
|
|
1870
1903
|
announced = true;
|
|
@@ -1912,7 +1945,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1912
1945
|
messages: [
|
|
1913
1946
|
{
|
|
1914
1947
|
role: 'user',
|
|
1915
|
-
content: buildCompactionPrompt(turns.map((turn) => ({ role: turn.role, content: turn.content })), hasPriorSummary)
|
|
1948
|
+
content: buildCompactionPrompt(nameSenders(turns).map((turn) => ({ role: turn.role, content: turn.content })), hasPriorSummary)
|
|
1916
1949
|
}
|
|
1917
1950
|
],
|
|
1918
1951
|
generationParams: { reasoning_budget: 0 },
|
|
@@ -133,18 +133,12 @@ function activityState(runs) {
|
|
|
133
133
|
return mediaState(latestRun(started)) ?? 'running';
|
|
134
134
|
}
|
|
135
135
|
function mediaState(run) {
|
|
136
|
-
const tool = latestTool(run.tools);
|
|
137
136
|
if (run.progress === 'generating') {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return 'generating-image';
|
|
137
|
+
const tool = latestTool(run.tools);
|
|
138
|
+
return tool && AUDIO_TOOLS.has(tool.name) ? 'generating-audio' : 'generating-image';
|
|
141
139
|
}
|
|
142
140
|
if (run.progress === 'transcribing')
|
|
143
141
|
return 'transcribing-audio';
|
|
144
|
-
if (tool && IMAGE_TOOLS.has(tool.name))
|
|
145
|
-
return 'generating-image';
|
|
146
|
-
if (tool && AUDIO_TOOLS.has(tool.name))
|
|
147
|
-
return 'generating-audio';
|
|
148
142
|
return null;
|
|
149
143
|
}
|
|
150
144
|
function applyChunk(activity, chunk) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { credentialSlots } from '@qvac/harness/lib/tools/skills/credential-slots.ts';
|
|
3
3
|
import { isDeviceSharedCredentialKey } from '@qvac/harness/lib/tools/skills/scope-key.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { settingConfigKey } from '../credential-pusher.js';
|
|
5
5
|
import { scopedKey } from '../oauth/common.js';
|
|
6
6
|
import { getAgent } from './agent.js';
|
|
7
7
|
const DEVICES = '@qvac/devices';
|
|
@@ -65,15 +65,12 @@ function credentialKeys(skill) {
|
|
|
65
65
|
for (const route of skill.setup?.routes ?? []) {
|
|
66
66
|
if (route.credentialKey)
|
|
67
67
|
keys.add(route.credentialKey);
|
|
68
|
+
if (route.oauth?.stateKey)
|
|
69
|
+
keys.add(route.oauth.stateKey);
|
|
68
70
|
for (const field of route.fields ?? []) {
|
|
69
71
|
if (field.secret === true)
|
|
70
72
|
keys.add(field.key);
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
|
-
for (const key of [...keys]) {
|
|
74
|
-
const state = oauthStateKey(key);
|
|
75
|
-
if (state)
|
|
76
|
-
keys.add(state);
|
|
77
|
-
}
|
|
78
75
|
return [...keys];
|
|
79
76
|
}
|
package/dist-lib/lib/core.d.ts
CHANGED
package/dist-lib/lib/core.js
CHANGED
|
@@ -45,7 +45,6 @@ import { buildDefaultSeed } from './core/helpers/index.js';
|
|
|
45
45
|
import { Mesh } from './core/mesh.js';
|
|
46
46
|
import { raceResource } from './race-resource.js';
|
|
47
47
|
import { createSystemInfoSampler } from './core/system-info.js';
|
|
48
|
-
import { oauthStateKeyFor } from './credential-pusher.js';
|
|
49
48
|
import { setLogger } from './logger.js';
|
|
50
49
|
import { settleOnClose } from '@qvac/harness/rpc';
|
|
51
50
|
import { openLocalSpec } from './spec-loader.js';
|
|
@@ -491,7 +490,12 @@ export class Core extends ReadyResource {
|
|
|
491
490
|
if (this._blockedByMinVersion() || this._currentMesh() || this._minting)
|
|
492
491
|
return;
|
|
493
492
|
try {
|
|
494
|
-
await this._switchToMesh({
|
|
493
|
+
const mesh = await this._switchToMesh({
|
|
494
|
+
seed: this._meshSeed,
|
|
495
|
+
baseKey: this._meshKey,
|
|
496
|
+
account: true
|
|
497
|
+
});
|
|
498
|
+
void this._openAccountBeside(mesh).catch(noop);
|
|
495
499
|
}
|
|
496
500
|
catch (err) {
|
|
497
501
|
if (this.closing)
|
|
@@ -503,6 +507,23 @@ export class Core extends ReadyResource {
|
|
|
503
507
|
this._log?.error(['p2p', 'mesh'], 'mesh open failed', err);
|
|
504
508
|
}
|
|
505
509
|
}
|
|
510
|
+
async _openAccountBeside(active) {
|
|
511
|
+
const home = await this._homeMeshKey();
|
|
512
|
+
if (!home || home.equals(active.key))
|
|
513
|
+
return;
|
|
514
|
+
await this._meshTransitionLock.lock();
|
|
515
|
+
try {
|
|
516
|
+
if (this.closing || this._blockedByMinVersion())
|
|
517
|
+
return;
|
|
518
|
+
const mesh = await this._openPooledMesh(home.toString('hex')).catch(() => null);
|
|
519
|
+
if (mesh && !mesh.ourMemberId)
|
|
520
|
+
await mesh.refreshOurMember();
|
|
521
|
+
}
|
|
522
|
+
finally {
|
|
523
|
+
this._meshTransitionLock.unlock();
|
|
524
|
+
}
|
|
525
|
+
this._notifyStatus();
|
|
526
|
+
}
|
|
506
527
|
async _runBootOnline() {
|
|
507
528
|
void this.onlineBoot.ready().catch(noop);
|
|
508
529
|
try {
|
|
@@ -530,7 +551,12 @@ export class Core extends ReadyResource {
|
|
|
530
551
|
try {
|
|
531
552
|
if (this.closing || this._currentMesh() || this._minting)
|
|
532
553
|
return;
|
|
533
|
-
await this._startMesh({
|
|
554
|
+
const mesh = await this._startMesh({
|
|
555
|
+
seed: this._meshSeed,
|
|
556
|
+
baseKey: this._meshKey,
|
|
557
|
+
account: true
|
|
558
|
+
});
|
|
559
|
+
void this._openAccountBeside(mesh).catch(noop);
|
|
534
560
|
}
|
|
535
561
|
catch (err) {
|
|
536
562
|
if (this.closing)
|
|
@@ -2370,7 +2396,7 @@ export class Core extends ReadyResource {
|
|
|
2370
2396
|
try {
|
|
2371
2397
|
if (meshId === this._activeMeshKey)
|
|
2372
2398
|
throw new Error('The active mesh cannot be closed');
|
|
2373
|
-
const mesh = this._currentMesh(meshId);
|
|
2399
|
+
const mesh = this._currentMesh(meshId) ?? (await this._opening.get(meshId)?.catch(noop));
|
|
2374
2400
|
if (!mesh)
|
|
2375
2401
|
return;
|
|
2376
2402
|
await this._retirePooledMesh(mesh);
|
|
@@ -2934,16 +2960,16 @@ export class Core extends ReadyResource {
|
|
|
2934
2960
|
return new Map();
|
|
2935
2961
|
const fields = new Map();
|
|
2936
2962
|
for (const slot of skill.credentials ?? []) {
|
|
2937
|
-
for (const key of slot.split('|'))
|
|
2963
|
+
for (const key of slot.split('|'))
|
|
2938
2964
|
fields.set(key, true);
|
|
2939
|
-
const stateKey = oauthStateKeyFor(key);
|
|
2940
|
-
if (stateKey)
|
|
2941
|
-
fields.set(stateKey, true);
|
|
2942
|
-
}
|
|
2943
2965
|
}
|
|
2966
|
+
const foreign = credentialKeysOwnedElsewhere(skills, skillName);
|
|
2944
2967
|
for (const route of skill.setup?.routes ?? []) {
|
|
2945
2968
|
if (route.credentialKey)
|
|
2946
2969
|
fields.set(route.credentialKey, true);
|
|
2970
|
+
const stateKey = route.oauth?.stateKey;
|
|
2971
|
+
if (stateKey && !foreign.has(stateKey))
|
|
2972
|
+
fields.set(stateKey, true);
|
|
2947
2973
|
for (const field of route.fields ?? [])
|
|
2948
2974
|
fields.set(field.key, field.secret === true);
|
|
2949
2975
|
}
|
|
@@ -3485,3 +3511,19 @@ function statusErrorMessage(context, err) {
|
|
|
3485
3511
|
const detail = err instanceof Error ? err.message : err ? String(err) : '';
|
|
3486
3512
|
return detail ? `${context}: ${detail}` : context;
|
|
3487
3513
|
}
|
|
3514
|
+
function credentialKeysOwnedElsewhere(skills, skillName) {
|
|
3515
|
+
const keys = new Set();
|
|
3516
|
+
for (const entry of skills) {
|
|
3517
|
+
if (entry.name === skillName)
|
|
3518
|
+
continue;
|
|
3519
|
+
for (const slot of entry.credentials ?? []) {
|
|
3520
|
+
for (const key of slot.split('|'))
|
|
3521
|
+
keys.add(key);
|
|
3522
|
+
}
|
|
3523
|
+
for (const route of entry.setup?.routes ?? []) {
|
|
3524
|
+
if (route.credentialKey)
|
|
3525
|
+
keys.add(route.credentialKey);
|
|
3526
|
+
}
|
|
3527
|
+
}
|
|
3528
|
+
return keys;
|
|
3529
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Harness } from './assistant.ts';
|
|
2
2
|
import { type ConfigEngine } from './oauth.ts';
|
|
3
|
+
import type { OAuthRouteLike } from './oauth/keys.ts';
|
|
3
4
|
export type CredentialEntry = {
|
|
4
5
|
key: string;
|
|
5
6
|
token?: string | null;
|
|
@@ -20,7 +21,7 @@ export type PusherSkill = {
|
|
|
20
21
|
credentials?: readonly string[];
|
|
21
22
|
};
|
|
22
23
|
setup?: {
|
|
23
|
-
routes?: ReadonlyArray<{
|
|
24
|
+
routes?: ReadonlyArray<OAuthRouteLike & {
|
|
24
25
|
fields?: ReadonlyArray<{
|
|
25
26
|
key: string;
|
|
26
27
|
secret?: boolean;
|
|
@@ -53,7 +54,6 @@ export type CredentialPusherLogger = {
|
|
|
53
54
|
export type CredentialPusherHandle = (() => Promise<void>) & {
|
|
54
55
|
sync(): Promise<void>;
|
|
55
56
|
};
|
|
56
|
-
export declare function oauthStateKeyFor(credentialKey: string): string | null;
|
|
57
57
|
export declare function nextRefreshDelay(entries: ReadonlyArray<{
|
|
58
58
|
expiresAt?: number | null;
|
|
59
59
|
}>, now?: number): number;
|
|
@@ -63,5 +63,4 @@ export declare function settingFields(catalog: ReadonlyArray<PusherSkill>): Read
|
|
|
63
63
|
key: string;
|
|
64
64
|
}>;
|
|
65
65
|
export declare function settingConfigKey(agentId: string | undefined, skill: string, key: string): string;
|
|
66
|
-
export declare function oauthStateKey(credentialKey: string): string | undefined;
|
|
67
66
|
export declare function startCredentialPusher(harness: CredentialTarget, engine: CredentialEngine, logger?: CredentialPusherLogger | null): CredentialPusherHandle;
|