@qvac/core 1.0.0-rc.6 → 1.0.0-rc.8

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.
Files changed (67) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist-lib/lib/api/agents.js +5 -2
  3. package/dist-lib/lib/api/approval-rules.js +8 -5
  4. package/dist-lib/lib/api/chat.d.ts +1 -2
  5. package/dist-lib/lib/api/chat.js +4 -18
  6. package/dist-lib/lib/api/device-routes.d.ts +6 -1
  7. package/dist-lib/lib/api/device-routes.js +20 -1
  8. package/dist-lib/lib/api/index.d.ts +0 -1
  9. package/dist-lib/lib/api/index.js +1 -2
  10. package/dist-lib/lib/api/mesh.d.ts +1 -1
  11. package/dist-lib/lib/api/mesh.js +1 -1
  12. package/dist-lib/lib/api/rag.js +2 -5
  13. package/dist-lib/lib/api/sync.js +12 -2
  14. package/dist-lib/lib/assistant/model-round.d.ts +7 -1
  15. package/dist-lib/lib/assistant/model-round.js +33 -11
  16. package/dist-lib/lib/assistant-tree.js +7 -0
  17. package/dist-lib/lib/assistant.d.ts +3 -2
  18. package/dist-lib/lib/assistant.js +20 -19
  19. package/dist-lib/lib/core/archived-mesh.d.ts +1 -0
  20. package/dist-lib/lib/core/archived-mesh.js +11 -14
  21. package/dist-lib/lib/core/chat-copy.d.ts +0 -1
  22. package/dist-lib/lib/core/chat-copy.js +1 -2
  23. package/dist-lib/lib/core/chat-move.d.ts +3 -1
  24. package/dist-lib/lib/core/chat-move.js +5 -2
  25. package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
  26. package/dist-lib/lib/core/local/index.d.ts +2 -1
  27. package/dist-lib/lib/core/local/index.js +3 -2
  28. package/dist-lib/lib/core/public-mesh.d.ts +6 -8
  29. package/dist-lib/lib/core/public-mesh.js +19 -29
  30. package/dist-lib/lib/core/sync/index.js +1 -1
  31. package/dist-lib/lib/core.d.ts +21 -8
  32. package/dist-lib/lib/core.js +233 -204
  33. package/dist-lib/lib/errors.d.ts +8 -12
  34. package/dist-lib/lib/errors.js +8 -12
  35. package/dist-lib/lib/model-download.d.ts +6 -1
  36. package/dist-lib/lib/model-download.js +16 -3
  37. package/dist-lib/lib/oauth/resolve.js +29 -8
  38. package/dist-lib/lib/oauth/token-exchange-core.js +11 -0
  39. package/dist-lib/schema/engine.js +10 -3
  40. package/dist-lib/schema/local.js +4 -2
  41. package/dist-lib/schema/qvac.js +2 -1
  42. package/dist-lib/spec/capabilities.d.ts +2 -2
  43. package/dist-lib/spec/hrpc/hrpc.json +1 -1
  44. package/dist-lib/spec/hrpc/index.js +1 -1
  45. package/dist-lib/spec/hrpc/messages.js +273 -250
  46. package/dist-lib/spec/hyperschema/index.js +273 -250
  47. package/dist-lib/spec/hyperschema/schema.json +27 -6
  48. package/dist-lib/spec/hyperschema/types.d.ts +7 -1
  49. package/dist-lib/spec/local/hyperdb/messages.js +26 -12
  50. package/dist-lib/spec/local/hyperschema/index.js +13 -6
  51. package/dist-lib/spec/local/hyperschema/schema.json +10 -0
  52. package/dist-lib/spec/local/hyperschema/types.d.ts +2 -0
  53. package/dist-lib/spec/mesh/hyperdb/messages.js +30 -6
  54. package/dist-lib/spec/mesh/hyperdispatch/messages.js +15 -3
  55. package/dist-lib/spec/mesh/hyperschema/index.js +15 -3
  56. package/dist-lib/spec/mesh/hyperschema/schema.json +5 -0
  57. package/dist-lib/spec/mesh/hyperschema/types.d.ts +1 -0
  58. package/package.json +10 -4
  59. package/tui/README.md +51 -0
  60. package/tui/app.mjs +88 -17
  61. package/tui/boot.mjs +23 -6
  62. package/tui/cli.mjs +93 -0
  63. package/tui/index.mjs +2 -87
  64. package/tui/lib/updater.mjs +86 -0
  65. package/tui/main.mjs +26 -15
  66. package/dist-lib/lib/core/chat-project.d.ts +0 -2
  67. package/dist-lib/lib/core/chat-project.js +0 -15
package/CHANGELOG.md CHANGED
@@ -88,11 +88,14 @@ release.
88
88
  unchanged.
89
89
  ([decision](docs/decisions/2026-11-05-a-streaming-reply-lands-once-a-second.md))
90
90
 
91
+ - A private chat linked to a project no longer reads the project's knowledge base: `ragSearch` and
92
+ the runs it feeds rank the knowledge base only for a chat in the project. ([rag.md](docs/api/rag.md))
93
+
91
94
  - The KV cache retention sweep runs every 12 hours instead of every hour, besides when a mesh opens
92
95
  and when `kvCache.retentionDays` changes, so a cache can outlive its retention by up to 12 hours
93
96
  on a host that stays up. ([config.md](docs/api/config.md#kv-cache-retention))
94
97
 
95
- - Core depends on `@qvac/harness` 1.0.0-rc.17 from npm instead of a git commit, so a consumer installs
98
+ - Core depends on `@qvac/harness` 1.0.0-rc.18 from npm instead of a git commit, so a consumer installs
96
99
  the published harness with its named entries.
97
100
 
98
101
  - Wipe a store written by 1.0.0-rc.0 to rc.2 before running this build. The collection, route and
@@ -128,6 +131,10 @@ release.
128
131
 
129
132
  ### Fixed
130
133
 
134
+ - A reply served by another device no longer repeats parts of itself. The run owner skips the text
135
+ the host already wrote when its harness streams it back, but matched that text chunk by chunk,
136
+ and the harness wire joins chunks that arrive together, so a delta frame carrying two of the
137
+ host's chunks was written a second time by the owner. The echo is now matched as text.
131
138
  - A run that restarts mid-reply no longer has its host write the abandoned round's answer a second
132
139
  time beside the new attempt's: the run cancels the model rounds its earlier attempt left open
133
140
  before it starts again.
@@ -67,8 +67,11 @@ export function createAgentsApi(pool, { deviceId, changed = null, modelPicked =
67
67
  };
68
68
  const agentHolder = async (meshId, agentId) => {
69
69
  const mesh = await requireMesh(pool, meshId);
70
- const chats = await requireMesh(pool, meshId, CHAT_ROWS);
71
- return chats !== mesh && !(await getAgent(mesh, agentId)) ? chats : mesh;
70
+ const named = mesh.role === 'account' && b4a.toHex(mesh.key) === meshId;
71
+ if (named || (await getAgent(mesh, agentId))) {
72
+ return mesh;
73
+ }
74
+ return requireMesh(pool, meshId, CHAT_ROWS);
72
75
  };
73
76
  return {
74
77
  createAgent: async ({ meshId, config }) => {
@@ -1,16 +1,19 @@
1
1
  import { listApprovalRules, removeApprovalRule } from '../core/approval-rules.js';
2
2
  import { requireMesh } from './current-mesh.js';
3
+ const RULE_ROWS = { route: 'put-approval-rule' };
3
4
  export function createApprovalRulesApi(pool) {
4
5
  return {
5
6
  listApprovalRules: async (request) => {
6
7
  const mesh = await requireMesh(pool, request.meshId);
7
- return {
8
- rules: await listApprovalRules(mesh),
9
- ourMemberId: mesh.ourMemberId ?? undefined
10
- };
8
+ const account = await requireMesh(pool, request.meshId, RULE_ROWS);
9
+ const rules = await listApprovalRules(mesh);
10
+ if (account !== mesh) {
11
+ rules.push(...(await listApprovalRules(account)));
12
+ }
13
+ return { rules, ourMemberId: mesh.ourMemberId ?? undefined };
11
14
  },
12
15
  removeApprovalRule: async ({ meshId, ruleId }) => {
13
- await removeApprovalRule(await requireMesh(pool, meshId, { route: 'put-approval-rule' }), ruleId);
16
+ await removeApprovalRule(await requireMesh(pool, meshId, RULE_ROWS), ruleId);
14
17
  return { ok: true };
15
18
  }
16
19
  };
@@ -16,9 +16,8 @@ export interface CreateChatApiOptions {
16
16
  } | null;
17
17
  readonly deletedProject?: ProjectGone;
18
18
  readonly projectOf?: ProjectOf | null;
19
- readonly workspaceOf?: ((projectId: string) => Promise<string | null>) | null;
20
19
  readonly log: LoggerInterface | null;
21
20
  }
22
21
  type ProjectGone = ((projectId: string) => Promise<boolean>) | null;
23
- export declare function createChatApi(pool: MeshPool, local: LocalStore, { account, agents, deviceId, inferenceCalls, deletedProject, projectOf, workspaceOf, log }: CreateChatApiOptions): ChatCapabilities;
22
+ export declare function createChatApi(pool: MeshPool, local: LocalStore, { account, agents, deviceId, inferenceCalls, deletedProject, projectOf, log }: CreateChatApiOptions): ChatCapabilities;
24
23
  export {};
@@ -9,7 +9,6 @@ import { forkChat } from '../core/chat-fork.js';
9
9
  import { listChatPage } from '../core/chat-order.js';
10
10
  import { searchChats } from '../core/chat-search.js';
11
11
  import { heldMesh, meshWatchable, requireMesh } from './current-mesh.js';
12
- import { CHATS } from '../core/collections.js';
13
12
  const SEARCH_SUPERSEDED_ABORT = 'superseded by a newer chat search';
14
13
  const WORKSPACE_ROWS = { route: 'put-project' };
15
14
  async function projectLink(pool, chat, { projectId, projectOf }) {
@@ -44,15 +43,8 @@ async function listedIn(pool, chat, { project, projectOf }) {
44
43
  async function liveLink(chat, gone) {
45
44
  return chat.projectId && (await gone?.(chat.projectId)) ? { ...chat, projectId: undefined } : chat;
46
45
  }
47
- export function createChatApi(pool, local, { account = () => null, agents = null, deviceId, inferenceCalls = null, deletedProject = null, projectOf = null, workspaceOf = null, log }) {
46
+ export function createChatApi(pool, local, { account = () => null, agents = null, deviceId, inferenceCalls = null, deletedProject = null, projectOf = null, log }) {
48
47
  const picks = agents ?? accountPicks(account);
49
- const linkScope = async (meshId, projectId) => {
50
- const named = account();
51
- if (!projectId || !named || b4a.toHex(named.key) !== meshId) {
52
- return meshId;
53
- }
54
- return (await workspaceOf?.(projectId)) ?? meshId;
55
- };
56
48
  let searchAbort = null;
57
49
  const chatList = (mesh, { limit, cursor }) => listChatPage(mesh, local, { limit: limit || undefined, cursor: cursor ?? undefined }).then(async (page) => ({
58
50
  ...page,
@@ -64,8 +56,7 @@ export function createChatApi(pool, local, { account = () => null, agents = null
64
56
  if (shared && !projectId) {
65
57
  throw new CoreError('CHAT_SHARED_NEEDS_PROJECT');
66
58
  }
67
- const scope = await linkScope(meshId, projectId);
68
- const mesh = await requireMesh(pool, scope);
59
+ const mesh = await requireMesh(pool, meshId);
69
60
  const link = await projectLink(pool, mesh, { projectId, projectOf });
70
61
  if (shared && link) {
71
62
  const project = await requireMesh(pool, link);
@@ -76,7 +67,7 @@ export function createChatApi(pool, local, { account = () => null, agents = null
76
67
  await picks.pick(mesh, agentId);
77
68
  return {
78
69
  ...(await createChat(mesh, { agentId, title: config.title, projectId: link })),
79
- meshId: scope
70
+ meshId
80
71
  };
81
72
  },
82
73
  listChats: async (request) => chatList(await requireMesh(pool, request.meshId), request),
@@ -98,12 +89,7 @@ export function createChatApi(pool, local, { account = () => null, agents = null
98
89
  return set;
99
90
  },
100
91
  setChatProject: async ({ chatId, meshId, projectId }) => {
101
- const scope = await linkScope(meshId, projectId);
102
- const mesh = await requireMesh(pool, scope);
103
- const elsewhere = scope !== meshId && !(await mesh.view.get(CHATS, { id: chatId }));
104
- if (elsewhere && (await (await requireMesh(pool, meshId)).view.get(CHATS, { id: chatId }))) {
105
- throw new CoreError('CHAT_PROJECT_OTHER_WORKSPACE');
106
- }
92
+ const mesh = await requireMesh(pool, meshId);
107
93
  return setChatProject(mesh, chatId, await projectLink(pool, mesh, { projectId, projectOf }));
108
94
  },
109
95
  forkChat: async ({ meshId, targetMeshId, config, ...cut }) => {
@@ -6,4 +6,9 @@ export interface ForwardingOptions {
6
6
  readonly remote: (deviceId: Buffer) => Capabilities;
7
7
  }
8
8
  export declare function forwardToDevices(local: Partial<CapabilityHandlers>, opts: ForwardingOptions): DeviceRoutes;
9
- export declare function servedToSiblings(local: Partial<CapabilityHandlers>): DeviceRoutes;
9
+ interface SiblingAsks {
10
+ asked(name: string): Promise<void> | undefined;
11
+ resumed(name: string): void;
12
+ }
13
+ export declare function servedToSiblings(local: Partial<CapabilityHandlers>, sibling: SiblingAsks): DeviceRoutes;
14
+ export {};
@@ -64,10 +64,11 @@ export function forwardToDevices(local, opts) {
64
64
  };
65
65
  return modelRoutes(at);
66
66
  }
67
- export function servedToSiblings(local) {
67
+ export function servedToSiblings(local, sibling) {
68
68
  const routes = modelRoutes(() => local);
69
69
  return {
70
70
  ...routes,
71
+ ...siblingDownloads(routes, sibling),
71
72
  previewCustomModel: (input) => {
72
73
  refuseLocalSources(input);
73
74
  return routes.previewCustomModel(input);
@@ -90,6 +91,24 @@ export function servedToSiblings(local) {
90
91
  })
91
92
  };
92
93
  }
94
+ function siblingDownloads(routes, sibling) {
95
+ return {
96
+ retryModelDownload: async (input) => {
97
+ const asked = sibling.asked(input.name);
98
+ if (!asked) {
99
+ return await routes.retryModelDownload(input);
100
+ }
101
+ await asked;
102
+ return { ok: true };
103
+ },
104
+ setModelPaused: async (input) => {
105
+ if (!input.paused) {
106
+ sibling.resumed(input.name);
107
+ }
108
+ return await routes.setModelPaused(input);
109
+ }
110
+ };
111
+ }
93
112
  function here(input) {
94
113
  const local = { ...input };
95
114
  delete local.deviceId;
@@ -76,7 +76,6 @@ interface ApiDeps {
76
76
  deletedProject?: ((projectId: string) => Promise<boolean>) | null;
77
77
  projectOf?: ProjectOf | null;
78
78
  nameOf?: NameOf | null;
79
- workspaceOf?: ((projectId: string) => Promise<string | null>) | null;
80
79
  pushSkillSecret?: ((request: AssistantPushSkillSecretRequest) => Promise<void>) | null;
81
80
  listQuarantinedSkills?: (() => Promise<AssistantQuarantinedSkillKeys>) | null;
82
81
  retryQuarantinedSkills?: (() => Promise<AssistantQuarantinedSkillKeys>) | null;
@@ -79,7 +79,6 @@ export function createApi(deps = {}) {
79
79
  inferenceCalls: deps.inferenceCalls ?? null,
80
80
  deletedProject: deps.deletedProject ?? null,
81
81
  projectOf: deps.projectOf ?? null,
82
- workspaceOf: deps.workspaceOf ?? null,
83
82
  log
84
83
  })
85
84
  : null),
@@ -138,7 +137,7 @@ export function createApi(deps = {}) {
138
137
  ...(mesh && state
139
138
  ? createHostRunLogApi(routed(mesh, 'append-chunk'), state.runLogs, deps.deviceId ?? null)
140
139
  : null),
141
- ...(mesh ? createSyncApi(routed(mesh, 'append-chunk'), log) : null),
140
+ ...(mesh ? createSyncApi(mesh, log) : null),
142
141
  ...(mesh ? createToolConfigsApi(routed(mesh, 'put-tool-configs'), log) : null),
143
142
  ...(mesh
144
143
  ? createToolActivityApi(routed(mesh, 'append-tool-activity'), deps.deviceId ?? null, log)
@@ -37,7 +37,7 @@ export interface MeshStatusSource {
37
37
  }): Promise<string>;
38
38
  listArchived(): Promise<AssistantArchivedMeshList>;
39
39
  archivedContents(meshId: string): Promise<AssistantArchivedMeshContents>;
40
- migrateArchived(meshId: string): Promise<AssistantArchivedMeshMigration>;
40
+ migrateArchived(meshId: string, workspaceId: string): Promise<AssistantArchivedMeshMigration>;
41
41
  recoverable(): Promise<boolean>;
42
42
  publishRecovery(phrase: string): Promise<void>;
43
43
  recover(phrase: string, timeout?: number): Promise<void>;
@@ -49,7 +49,7 @@ export function createMeshApi(status, updateMember, log) {
49
49
  },
50
50
  listArchivedMeshes: () => status.listArchived(),
51
51
  archivedMeshContents: ({ meshId }) => status.archivedContents(meshId),
52
- migrateArchivedMesh: ({ meshId }) => status.migrateArchived(meshId),
52
+ migrateArchivedMesh: ({ meshId, workspaceId }) => status.migrateArchived(meshId, workspaceId),
53
53
  accountRecoverable: async () => ({
54
54
  recoverable: await status.recoverable()
55
55
  }),
@@ -2,9 +2,8 @@ import { toolsetEnabled } from '@qvac/harness/lib/tools/toolsets.ts';
2
2
  import { getAgent } from '../core/agent.js';
3
3
  import { runDefinition } from '../core/shared-agents.js';
4
4
  import { getChat } from '../core/chat.js';
5
- import { chatProject } from '../core/chat-project.js';
6
5
  import { isKnowledgeRoutedAttachment, fullTextBudgetChars, fullTextHits, joinedIndex, retrievalBudgetTokens, retrieveRagKnowledge, searchRagChunks, referencesPendingFile } from '../core/files/index.js';
7
- import { heldMesh, requireMesh } from './current-mesh.js';
6
+ import { requireMesh } from './current-mesh.js';
8
7
  import { errorMessage } from '../guards.js';
9
8
  import b4a from 'b4a';
10
9
  export const MAX_RAG_SEARCH_LIMIT = 20;
@@ -50,9 +49,7 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
50
49
  pendingFiles = pendingFileNames(initialFiles);
51
50
  chatFilesIndexingHere = indexingHere(initialFiles);
52
51
  const scopeRows = chatRows.filter((row) => scopeIds.has(row.id));
53
- const project = off.has('project')
54
- ? null
55
- : await chatProject(mesh, chatId, (id) => heldMesh(pool, id));
52
+ const project = off.has('project') || mesh.role !== 'project' ? null : mesh;
56
53
  const kbEntries = project ? ((await project.files.knowledgeBase()).entries ?? []) : [];
57
54
  const kbRows = kbEntries.filter((entry) => entry.loaded).map((entry) => entry.knowledge);
58
55
  projectFilesNotReady = kbEntries.filter((entry) => !entry.loaded && entry.status !== 'failed').length;
@@ -1,7 +1,17 @@
1
- import { requireMesh } from './current-mesh.js';
1
+ import { isCoreError } from '../errors.js';
2
+ import { requireMesh, routed } from './current-mesh.js';
2
3
  import { watchable } from './watchable.js';
3
4
  export function createSyncApi(pool, log) {
5
+ const chats = routed(pool, 'append-chunk');
4
6
  return {
5
- syncStatusWatch: watchable(async (request) => (await requireMesh(pool, request.meshId, { follow: true })).syncActivity ?? null, (_request, activity) => activity.snapshot(), { name: 'syncStatusWatch', log })
7
+ syncStatusWatch: watchable(async (request) => {
8
+ const mesh = await requireMesh(chats, request.meshId, { follow: true }).catch((err) => {
9
+ if (isCoreError(err, 'ROUTE_NEEDS_WORKSPACE')) {
10
+ return requireMesh(pool, request.meshId, { follow: true });
11
+ }
12
+ throw err;
13
+ });
14
+ return mesh.syncActivity ?? null;
15
+ }, (_request, activity) => activity.snapshot(), { name: 'syncStatusWatch', log })
6
16
  };
7
17
  }
@@ -44,6 +44,11 @@ export interface OutputHooks {
44
44
  forwarded(echo: Echo): void;
45
45
  retook(): void;
46
46
  }
47
+ export declare class Echoes {
48
+ private readonly _pending;
49
+ forwarded({ type, text }: Echo): void;
50
+ own(type: Echo['type'], text: string): string;
51
+ }
47
52
  export declare class OwnerRounds {
48
53
  readonly port: ModelRoundPort;
49
54
  inputLength: number;
@@ -59,7 +64,7 @@ export declare class OwnerRounds {
59
64
  get rounds(): number;
60
65
  ranHere(round: number | undefined): boolean;
61
66
  retook(): boolean;
62
- echoed(type: string, text: string): boolean;
67
+ unechoed(type: Echo['type'], text: string): string;
63
68
  retire(): Promise<void>;
64
69
  private _round;
65
70
  probe({ kind, prompt, modelId, responseFormat, signal }: Probe): Promise<string>;
@@ -90,6 +95,7 @@ export declare class RoundOutput {
90
95
  private _resetAt;
91
96
  constructor(id: string, io: ModelRoundIo, hooks: OutputHooks);
92
97
  apply(frame: AssistantChunkDelta): AssistantChunkContentModelRequest | undefined;
98
+ hold(): void;
93
99
  reask(id: string, emit: ModelRoundIo['emit']): void;
94
100
  round(): AssistantChunkContentModelRequest | undefined;
95
101
  switchedTo(from: number): string | undefined;
@@ -35,12 +35,30 @@ const roundOptions = z.object({
35
35
  media: z.array(z.object({ at: z.number(), refs: z.array(mediaRef) })).optional()
36
36
  });
37
37
  const roundResult = z.custom((value) => isRecord(value) && typeof value.contentText === 'string' && isRecord(value.final));
38
+ export class Echoes {
39
+ _pending = { content: '', thinking: '' };
40
+ forwarded({ type, text }) {
41
+ this._pending[type] += text;
42
+ }
43
+ own(type, text) {
44
+ const pending = this._pending[type];
45
+ if (pending.startsWith(text)) {
46
+ this._pending[type] = pending.slice(text.length);
47
+ return '';
48
+ }
49
+ if (pending && text.startsWith(pending)) {
50
+ this._pending[type] = '';
51
+ return text.slice(pending.length);
52
+ }
53
+ return text;
54
+ }
55
+ }
38
56
  export class OwnerRounds {
39
57
  port;
40
58
  inputLength = 0;
41
59
  share = null;
42
60
  _opts;
43
- _echoes = [];
61
+ _echoes = new Echoes();
44
62
  _known = null;
45
63
  _contextSent = false;
46
64
  _rounds = 0;
@@ -65,13 +83,8 @@ export class OwnerRounds {
65
83
  this._retakes--;
66
84
  return true;
67
85
  }
68
- echoed(type, text) {
69
- const at = this._echoes.findIndex((echo) => echo.type === type && echo.text === text);
70
- if (at === -1) {
71
- return false;
72
- }
73
- this._echoes.splice(at, 1);
74
- return true;
86
+ unechoed(type, text) {
87
+ return this._echoes.own(type, text);
75
88
  }
76
89
  async retire() {
77
90
  const { engine, chatId, runId } = this._opts;
@@ -305,11 +318,12 @@ export class OwnerRounds {
305
318
  io.signal.addEventListener('abort', abort);
306
319
  const at = { asked: first, moving: null, host: null };
307
320
  const output = new RoundOutput(first.id, io, {
308
- forwarded: (echo) => this._echoes.push(echo),
321
+ forwarded: (echo) => this._echoes.forwarded(echo),
309
322
  retook: () => this._retakes++
310
323
  });
311
324
  const move = async (agentId) => {
312
325
  at.moving = { agentId, after: output.newest(), emit: io.retake() };
326
+ output.hold();
313
327
  await engine.cancelModelRequest({ chunkId: at.asked.id }).catch(noop);
314
328
  };
315
329
  void this._followHost(agents, { at, output, move }).catch(noop);
@@ -416,6 +430,9 @@ export class RoundOutput {
416
430
  }
417
431
  return round;
418
432
  }
433
+ hold() {
434
+ this._emit = null;
435
+ }
419
436
  reask(id, emit) {
420
437
  this._id = id;
421
438
  this._emit = emit;
@@ -463,16 +480,21 @@ export class RoundOutput {
463
480
  this._takenAt = now ? at : this._takenAt;
464
481
  }
465
482
  _forward(chunk) {
483
+ const emit = this._emit;
466
484
  const text = chunk.content?.text ?? chunk.thinking?.text;
467
485
  const type = chunk.type;
468
486
  const fresh = chunk.parentId === this._id && !this._emitted.has(chunk.id) && chunk.seq > this._resetAt;
469
487
  const taken = !this._reopened && this._taker && b4a.equals(chunk.originDeviceId, this._taker);
470
- if (!fresh || !taken || text === undefined || (type !== 'content' && type !== 'thinking')) {
488
+ if (!emit ||
489
+ !fresh ||
490
+ !taken ||
491
+ text === undefined ||
492
+ (type !== 'content' && type !== 'thinking')) {
471
493
  return;
472
494
  }
473
495
  this._emitted.add(chunk.id);
474
496
  this._hooks.forwarded({ type, text });
475
- this._emit({ type, text });
497
+ emit({ type, text });
476
498
  }
477
499
  }
478
500
  export async function listRoundChunks(engine, chatId) {
@@ -23,6 +23,7 @@ export function assistantTree(opts) {
23
23
  let offDeleteChatKvCache = null;
24
24
  let offCompactChat = null;
25
25
  let offRetryModelDownload = null;
26
+ let offSiblingDownloads = null;
26
27
  let offModelResidency = null;
27
28
  let offModelUsers = null;
28
29
  let offSkills = null;
@@ -118,6 +119,10 @@ export function assistantTree(opts) {
118
119
  logger
119
120
  });
120
121
  offRetryModelDownload = core.registerRetryModelDownload((name) => assistant.retryModelDownload(name));
122
+ offSiblingDownloads = core.registerSiblingDownloads({
123
+ asked: (name) => assistant.retryModelDownload(name, { sibling: true }),
124
+ resumed: (name) => assistant.siblingResumedDownload(name)
125
+ });
121
126
  offModelResidency = core.registerModelResidency({
122
127
  load: (name) => assistant.loadModel(name),
123
128
  unload: (name) => assistant.unloadModel(name)
@@ -204,6 +209,8 @@ export function assistantTree(opts) {
204
209
  offFakeModels = null;
205
210
  offRetryModelDownload?.();
206
211
  offRetryModelDownload = null;
212
+ offSiblingDownloads?.();
213
+ offSiblingDownloads = null;
207
214
  offModelResidency?.();
208
215
  offModelResidency = null;
209
216
  offModelUsers?.();
@@ -8,6 +8,7 @@ import type { DriveHost } from './core/fs-drives.ts';
8
8
  import { type DiagnosticsSlice } from './diagnostics.ts';
9
9
  import { type InferenceCallPage } from './inference-calls.ts';
10
10
  import type { LoggerInterface } from '@qvac/logging';
11
+ import { type RetryOptions } from './model-download.ts';
11
12
  import { type DeleteModelSummary, type Harness, type ListModelsOptions, type ModelInfo, type ToolCatalogEntry } from './assistant/harness.ts';
12
13
  import type { Skill } from './assistant/skill-encode.ts';
13
14
  import { type CompactOptions, type CompactResult } from './assistant/history.ts';
@@ -67,7 +68,6 @@ export declare class QvacAssistant extends ReadyResource {
67
68
  private _deviceId;
68
69
  private _info;
69
70
  private readonly _lastCapabilities;
70
- private _ownWorkspace;
71
71
  private _listed;
72
72
  private _accountHosted;
73
73
  private _readySkills;
@@ -173,7 +173,8 @@ export declare class QvacAssistant extends ReadyResource {
173
173
  private _runnableHost;
174
174
  notifyModelCatalog(): void;
175
175
  cachedModelsChanged(): void;
176
- retryModelDownload(name: string): Promise<void>;
176
+ retryModelDownload(name: string, options?: RetryOptions): Promise<void>;
177
+ siblingResumedDownload(name: string): void;
177
178
  skills(agentId?: string | null, modelName?: string | null, options?: SkillListOptions): Promise<ReadonlyArray<Skill>>;
178
179
  private _recordSkillReadiness;
179
180
  private _readySkillNames;
@@ -281,7 +281,6 @@ export class QvacAssistant extends ReadyResource {
281
281
  _deviceId;
282
282
  _info;
283
283
  _lastCapabilities = new Map();
284
- _ownWorkspace = null;
285
284
  _listed = [];
286
285
  _accountHosted = [];
287
286
  _readySkills;
@@ -1132,11 +1131,14 @@ export class QvacAssistant extends ReadyResource {
1132
1131
  this._modelCatalog.notify();
1133
1132
  this._reportCapabilities().catch(noop);
1134
1133
  }
1135
- async retryModelDownload(name) {
1134
+ async retryModelDownload(name, options) {
1136
1135
  if (!this._downloads) {
1137
1136
  throw new CoreError('MODEL_DOWNLOAD_UNAVAILABLE');
1138
1137
  }
1139
- await this._downloads.retry(name);
1138
+ await this._downloads.retry(name, options);
1139
+ }
1140
+ siblingResumedDownload(name) {
1141
+ this._downloads?.siblingResumed(name);
1140
1142
  }
1141
1143
  async skills(agentId, modelName, options) {
1142
1144
  if (!this.opened)
@@ -1407,7 +1409,7 @@ export class QvacAssistant extends ReadyResource {
1407
1409
  const read = new Set();
1408
1410
  const closed = new Set();
1409
1411
  for (const mesh of this._listed) {
1410
- if (mesh.meshId === this._ownWorkspace)
1412
+ if (mesh.account)
1411
1413
  continue;
1412
1414
  if (!mesh.open) {
1413
1415
  closed.add(mesh.meshId);
@@ -1552,11 +1554,9 @@ export class QvacAssistant extends ReadyResource {
1552
1554
  }
1553
1555
  _syncMeshConsumers(meshes) {
1554
1556
  this._listed = meshes;
1555
- const consumed = meshes.filter((mesh) => mesh.open && mesh.meshId !== this._ownWorkspace);
1556
- const open = new Set(consumed.map((mesh) => mesh.meshId));
1557
- const served = new Set(consumed.filter((mesh) => mesh.served).map((mesh) => mesh.meshId));
1557
+ const consumed = new Map(meshes.filter((mesh) => mesh.open).map((mesh) => [mesh.meshId, mesh]));
1558
1558
  for (const [meshId, consumer] of this._meshConsumers) {
1559
- if (open.has(meshId))
1559
+ if (consumed.has(meshId))
1560
1560
  continue;
1561
1561
  consumer.stop();
1562
1562
  this._meshConsumers.delete(meshId);
@@ -1566,18 +1566,14 @@ export class QvacAssistant extends ReadyResource {
1566
1566
  }
1567
1567
  this._servedChats.delete(meshId);
1568
1568
  }
1569
- for (const meshId of open) {
1570
- const consumer = this._meshConsumers.get(meshId) ?? this._meshConsumer(meshId, served.has(meshId));
1569
+ for (const [meshId, entry] of consumed) {
1570
+ const consumer = this._meshConsumers.get(meshId) ?? this._meshConsumer(entry);
1571
1571
  this._meshConsumers.set(meshId, consumer);
1572
1572
  consumer.start();
1573
1573
  }
1574
1574
  }
1575
1575
  _followAccount(account) {
1576
1576
  this._accountMeshId = account.meshId ?? null;
1577
- if ((account.ownWorkspace ?? null) !== this._ownWorkspace) {
1578
- this._ownWorkspace = account.ownWorkspace ?? null;
1579
- this._syncMeshConsumers(this._listed);
1580
- }
1581
1577
  const on = account.meshId ? `${account.meshId}:${account.writable}` : null;
1582
1578
  if (on === null) {
1583
1579
  this._advertisedOn = null;
@@ -1593,7 +1589,11 @@ export class QvacAssistant extends ReadyResource {
1593
1589
  void this._reconcileDeviceProfile();
1594
1590
  this._triggerModelWarm();
1595
1591
  }
1596
- _meshConsumer(meshId, served) {
1592
+ _meshConsumer({ meshId, served = false, account }) {
1593
+ if (account) {
1594
+ const agents = this._streamWatch(`agent:${meshId}`, () => this._engine.agentsWatch({ meshId }), (frames) => this._followAgentEdits(meshId, frames));
1595
+ return { start: () => agents.start(), stop: () => agents.stop() };
1596
+ }
1597
1597
  const watches = [
1598
1598
  this._streamWatch(`chat-list:${meshId}`, () => this._engine.chatsWatch({ meshId }), (frames) => this._reclaimDeletedChats(frames, meshId, served)),
1599
1599
  this._streamWatch(`kv-cache-retention:${meshId}`, () => this._engine.configWatch({ key: KV_CACHE_RETENTION_KEY }), (frames) => this._sweepIdleChatCaches(meshId, frames))
@@ -2209,11 +2209,12 @@ export class QvacAssistant extends ReadyResource {
2209
2209
  await transcript.text(type, text, round);
2210
2210
  };
2211
2211
  const writeRoundText = async (type, text) => {
2212
- if (!rounds.echoed(type, text)) {
2213
- await writeText(type, text);
2212
+ const own = rounds.unechoed(type, text);
2213
+ if (type === 'content' && own.length < text.length) {
2214
+ answer(text.slice(0, text.length - own.length));
2214
2215
  }
2215
- else if (type === 'content') {
2216
- answer(text);
2216
+ if (own) {
2217
+ await writeText(type, own);
2217
2218
  }
2218
2219
  };
2219
2220
  const failRun = async (message) => {
@@ -13,6 +13,7 @@ export interface ArchivedMeshContents extends ArchivedMeshCounts {
13
13
  readonly meshId: string;
14
14
  }
15
15
  export interface ArchivedMeshMigration extends ArchivedMeshContents {
16
+ readonly workspaceId: string;
16
17
  readonly migrated: boolean;
17
18
  readonly migratedAt: number;
18
19
  }
@@ -1,7 +1,7 @@
1
1
  import b4a from 'b4a';
2
2
  import crypto from 'hypercore-crypto';
3
3
  import { copyBlob, copyChunks, stripped } from './chat-copy.js';
4
- import { ownWorkspaceSeed, publicMeshKey, publicSeed } from './public-mesh.js';
4
+ import { publicMeshKey, publicSeed } from './public-mesh.js';
5
5
  import { Mesh } from './mesh.js';
6
6
  import { recordedRole } from './local/index.js';
7
7
  import { ACTIVE_AGENTS, ACTIVE_CHATS, ACTIVE_CHAT_GROUPS, ACTIVE_TOOL_CONFIGS_BY_AGENT, AGENTS, KNOWLEDGE, MESH_SEEDS } from './collections.js';
@@ -37,26 +37,23 @@ export async function withArchivedMesh(row, opts, fn) {
37
37
  await mesh.close();
38
38
  }
39
39
  }
40
- async function ownWorkspaceKey(account) {
41
- const seed = ownWorkspaceSeed(account.seed);
42
- const keys = [];
43
- for await (const row of account.view.find(MESH_SEEDS)) {
44
- if (b4a.equals(row.seed, seed)) {
45
- keys.push(row.meshKey);
40
+ async function migratedWorkspace(account, opts) {
41
+ for await (const { meshKey } of account.view.find(MESH_SEEDS)) {
42
+ const record = await opts.publicRecord?.(meshKey);
43
+ if (record?.migrated) {
44
+ return { workspaceKey: meshKey, record };
46
45
  }
47
46
  }
48
- return keys.sort(b4a.compare)[0] ?? null;
47
+ return null;
49
48
  }
50
49
  async function openArchivedPublic(account, opts) {
51
- const workspaceKey = await ownWorkspaceKey(account);
52
- const record = workspaceKey && (await opts.publicRecord?.(workspaceKey));
50
+ const migrated = await migratedWorkspace(account, opts);
51
+ const workspaceKey = migrated?.workspaceKey;
52
+ const record = migrated?.record;
53
53
  const key = record?.key
54
54
  ? b4a.from(record.key, 'hex')
55
55
  : workspaceKey && (await publicMeshKey(account, workspaceKey));
56
- if (!workspaceKey ||
57
- !record?.migrated ||
58
- !key ||
59
- !(await opts.storage.hasCore(crypto.discoveryKey(key)))) {
56
+ if (!workspaceKey || !record || !key || !(await opts.storage.hasCore(crypto.discoveryKey(key)))) {
60
57
  return null;
61
58
  }
62
59
  const mesh = new Mesh(opts.store, {
@@ -35,7 +35,6 @@ export declare function stripped<T extends {
35
35
  export interface ContentCopy extends MeshCopy {
36
36
  readonly deviceId: Buffer;
37
37
  readonly chats?: ReadonlySet<string>;
38
- readonly unlinkProjects?: boolean;
39
38
  readonly endsOpenRuns?: boolean;
40
39
  }
41
40
  export declare function copyContent(copy: ContentCopy): Promise<void>;
@@ -222,9 +222,8 @@ async function copyRows(snap, copy, remap) {
222
222
  }
223
223
  if (await newer(into, CHATS, chat)) {
224
224
  const groupId = copy.chats ? undefined : chat.groupId;
225
- const projectId = copy.unlinkProjects ? undefined : chat.projectId;
226
225
  batch.dispatch('put-chat', {
227
- chat: { ...stripped(chat), agentId: agent?.id ?? chat.agentId, groupId, projectId }
226
+ chat: { ...stripped(chat), agentId: agent?.id ?? chat.agentId, groupId }
228
227
  });
229
228
  }
230
229
  }