@qvac/core 1.0.0-rc.5 → 1.0.0-rc.7

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 (131) hide show
  1. package/CHANGELOG.md +43 -2
  2. package/README.md +55 -4
  3. package/dist-lib/lib/api/agents.d.ts +2 -1
  4. package/dist-lib/lib/api/agents.js +10 -3
  5. package/dist-lib/lib/api/app-config.d.ts +3 -0
  6. package/dist-lib/lib/api/app-config.js +20 -0
  7. package/dist-lib/lib/api/approval-rules.js +8 -5
  8. package/dist-lib/lib/api/chat.d.ts +1 -2
  9. package/dist-lib/lib/api/chat.js +4 -18
  10. package/dist-lib/lib/api/device-routes.d.ts +1 -1
  11. package/dist-lib/lib/api/device-routes.js +3 -1
  12. package/dist-lib/lib/api/index.d.ts +0 -1
  13. package/dist-lib/lib/api/index.js +3 -3
  14. package/dist-lib/lib/api/mesh.d.ts +1 -1
  15. package/dist-lib/lib/api/mesh.js +1 -1
  16. package/dist-lib/lib/api/projects.js +3 -4
  17. package/dist-lib/lib/api/served.d.ts +2 -2
  18. package/dist-lib/lib/api/served.js +24 -1
  19. package/dist-lib/lib/api/sync.js +12 -2
  20. package/dist-lib/lib/assistant/harness.d.ts +3 -0
  21. package/dist-lib/lib/assistant/history.js +14 -2
  22. package/dist-lib/lib/assistant/message.d.ts +1 -0
  23. package/dist-lib/lib/assistant/model-round.d.ts +3 -0
  24. package/dist-lib/lib/assistant/model-round.js +16 -2
  25. package/dist-lib/lib/assistant/round-host.d.ts +2 -0
  26. package/dist-lib/lib/assistant/round-host.js +8 -0
  27. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  28. package/dist-lib/lib/assistant-tree.js +4 -2
  29. package/dist-lib/lib/assistant.d.ts +11 -2
  30. package/dist-lib/lib/assistant.js +124 -20
  31. package/dist-lib/lib/client.js +4 -1
  32. package/dist-lib/lib/core/agent-copies.js +2 -1
  33. package/dist-lib/lib/core/agent-hosting.js +9 -4
  34. package/dist-lib/lib/core/agent.js +2 -1
  35. package/dist-lib/lib/core/archived-mesh.d.ts +1 -0
  36. package/dist-lib/lib/core/archived-mesh.js +11 -14
  37. package/dist-lib/lib/core/chat-copy.d.ts +1 -1
  38. package/dist-lib/lib/core/chat-copy.js +14 -4
  39. package/dist-lib/lib/core/chat-move.d.ts +3 -1
  40. package/dist-lib/lib/core/chat-move.js +5 -2
  41. package/dist-lib/lib/core/chat.d.ts +0 -1
  42. package/dist-lib/lib/core/chat.js +0 -3
  43. package/dist-lib/lib/core/collections.d.ts +7 -7
  44. package/dist-lib/lib/core/collections.js +7 -7
  45. package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
  46. package/dist-lib/lib/core/contract/project-device-keys.d.ts +4 -2
  47. package/dist-lib/lib/core/contract/project-device-keys.js +12 -12
  48. package/dist-lib/lib/core/contract/project-host-keys.d.ts +5 -3
  49. package/dist-lib/lib/core/contract/project-host-keys.js +22 -11
  50. package/dist-lib/lib/core/contract/projects.d.ts +4 -2
  51. package/dist-lib/lib/core/contract/projects.js +29 -17
  52. package/dist-lib/lib/core/deleted-agent-runs.d.ts +1 -0
  53. package/dist-lib/lib/core/deleted-agent-runs.js +22 -11
  54. package/dist-lib/lib/core/helpers/index.d.ts +1 -1
  55. package/dist-lib/lib/core/helpers/index.js +2 -2
  56. package/dist-lib/lib/core/local/index.d.ts +2 -1
  57. package/dist-lib/lib/core/local/index.js +3 -2
  58. package/dist-lib/lib/core/mesh.d.ts +1 -0
  59. package/dist-lib/lib/core/mesh.js +4 -4
  60. package/dist-lib/lib/core/project-keys.d.ts +5 -2
  61. package/dist-lib/lib/core/project-keys.js +15 -6
  62. package/dist-lib/lib/core/public-mesh.d.ts +6 -8
  63. package/dist-lib/lib/core/public-mesh.js +19 -29
  64. package/dist-lib/lib/core/sync/index.js +6 -6
  65. package/dist-lib/lib/core.d.ts +17 -8
  66. package/dist-lib/lib/core.js +317 -224
  67. package/dist-lib/lib/errors.d.ts +4 -12
  68. package/dist-lib/lib/errors.js +4 -12
  69. package/dist-lib/lib/kv-cache-ledger.d.ts +22 -0
  70. package/dist-lib/lib/kv-cache-ledger.js +72 -0
  71. package/dist-lib/lib/kv-cache-retention.d.ts +1 -0
  72. package/dist-lib/lib/kv-cache-retention.js +5 -2
  73. package/dist-lib/lib/model-memory-cap.d.ts +3 -0
  74. package/dist-lib/lib/model-memory-cap.js +15 -6
  75. package/dist-lib/lib/run-replay.d.ts +3 -2
  76. package/dist-lib/lib/run-replay.js +16 -5
  77. package/dist-lib/lib/run-transcript.js +1 -1
  78. package/dist-lib/schema/engine.js +64 -4
  79. package/dist-lib/schema/local.js +4 -2
  80. package/dist-lib/schema/qvac.js +64 -2
  81. package/dist-lib/spec/bind.js +3 -0
  82. package/dist-lib/spec/calls.js +1 -0
  83. package/dist-lib/spec/capabilities.d.ts +4 -2
  84. package/dist-lib/spec/hrpc/hrpc.json +14 -1
  85. package/dist-lib/spec/hrpc/index.js +16 -4
  86. package/dist-lib/spec/hrpc/messages.js +508 -235
  87. package/dist-lib/spec/hyperschema/index.js +508 -235
  88. package/dist-lib/spec/hyperschema/schema.json +214 -6
  89. package/dist-lib/spec/hyperschema/types.d.ts +40 -1
  90. package/dist-lib/spec/local/hyperdb/messages.js +26 -12
  91. package/dist-lib/spec/local/hyperschema/index.js +13 -6
  92. package/dist-lib/spec/local/hyperschema/schema.json +10 -0
  93. package/dist-lib/spec/local/hyperschema/types.d.ts +2 -0
  94. package/dist-lib/spec/mesh/hyperdb/db.json +110 -0
  95. package/dist-lib/spec/mesh/hyperdb/index.js +498 -2
  96. package/dist-lib/spec/mesh/hyperdb/messages.js +895 -416
  97. package/dist-lib/spec/mesh/hyperdispatch/messages.js +259 -6
  98. package/dist-lib/spec/mesh/hyperschema/index.js +259 -6
  99. package/dist-lib/spec/mesh/hyperschema/schema.json +160 -0
  100. package/dist-lib/spec/mesh/hyperschema/types.d.ts +38 -0
  101. package/package.json +27 -11
  102. package/tui/README.md +190 -0
  103. package/tui/app.mjs +8282 -0
  104. package/tui/boot.mjs +159 -0
  105. package/tui/index.mjs +89 -0
  106. package/tui/lib/boot-timing.mjs +41 -0
  107. package/tui/lib/busy-words.mjs +116 -0
  108. package/tui/lib/connect-sheet.mjs +350 -0
  109. package/tui/lib/device-target.mjs +64 -0
  110. package/tui/lib/export.mjs +194 -0
  111. package/tui/lib/folders-command.mjs +84 -0
  112. package/tui/lib/fork-command.mjs +43 -0
  113. package/tui/lib/knowledge-command.mjs +190 -0
  114. package/tui/lib/knowledge-import.mjs +153 -0
  115. package/tui/lib/local-path.mjs +21 -0
  116. package/tui/lib/move-command.mjs +17 -0
  117. package/tui/lib/render.mjs +225 -0
  118. package/tui/lib/save-file.mjs +88 -0
  119. package/tui/lib/select.mjs +81 -0
  120. package/tui/lib/selection.mjs +18 -0
  121. package/tui/lib/setup.mjs +135 -0
  122. package/tui/lib/sidebar.mjs +63 -0
  123. package/tui/lib/skill-connect.mjs +145 -0
  124. package/tui/lib/splash-art.mjs +107 -0
  125. package/tui/lib/splash.mjs +18 -0
  126. package/tui/lib/upload-frames.mjs +9 -0
  127. package/tui/lib/usage.mjs +59 -0
  128. package/tui/lib/wrap.mjs +143 -0
  129. package/tui/main.mjs +279 -0
  130. package/tui/plugins.mjs +158 -0
  131. package/worker/assistant-sidecar.mjs +1 -0
package/CHANGELOG.md CHANGED
@@ -15,6 +15,11 @@ release.
15
15
 
16
16
  ### Added
17
17
 
18
+ - A vision model sees an image a tool attaches during a run, such as a PNG `http_request` downloads
19
+ from Google Drive. The assistant gives the harness the image from its own image cache, as it does
20
+ a user's image, and the harness shows it on the turn that closes the tool round. Later runs show
21
+ it again on the same turn. Video stays an attachment for now. Needs a harness with `showImage`.
22
+
18
23
  - A completed run that primed the chat cache after Core deleted it says so on its
19
24
  `run-status.metrics`: `cacheRebuild` carries Core's deletion reason and the prompt tokens of the
20
25
  run's first round on the key, as its `metrics.rounds` counts them, null when that round has no
@@ -66,14 +71,28 @@ release.
66
71
  passes it to `Core`. Unset keeps today's behaviour; `false` starts a host
67
72
  without fetching the default models. A sidecar that fails to start also writes
68
73
  the reason to stderr, since the host may not be listening yet.
74
+ - `duck plugins list|install|enable|disable` manages the userland harness
75
+ plugins in `~/.config/qv-ac` without booting an engine. Install clones a git
76
+ URL or copies a `hyper://` drive, and does not enable what it installs.
77
+ - `npm i -g bare @qvac/core` runs `duck`: the model addons the harness's stock entry loads are
78
+ optional dependencies of the package, so an install brings them, and `bare-thread` is pinned to
79
+ `~1.2.7` in `dependencies`, since 1.4 fails to load the stowed harness worker.
69
80
 
70
81
  ### Changed
71
82
 
83
+ - A streaming reply lands in its chat about once a second instead of every 250 ms: `RunTranscript`
84
+ flushes buffered text on a 1 s tick (and still at 8,192 chars, on a type or round change and at the
85
+ end). A client watching the chat gets a quarter of the frames, so it should pace its own text
86
+ animation by how often text arrives rather than assume a fixed cadence. On a Pixel 8 this cut
87
+ app CPU per generated token by about 30% and skin heating per token by 20–40%, with decode speed
88
+ unchanged.
89
+ ([decision](docs/decisions/2026-11-05-a-streaming-reply-lands-once-a-second.md))
90
+
72
91
  - The KV cache retention sweep runs every 12 hours instead of every hour, besides when a mesh opens
73
92
  and when `kvCache.retentionDays` changes, so a cache can outlive its retention by up to 12 hours
74
93
  on a host that stays up. ([config.md](docs/api/config.md#kv-cache-retention))
75
94
 
76
- - Core depends on `@qvac/harness` 1.0.0-rc.16 from npm instead of a git commit, so a consumer installs
95
+ - Core depends on `@qvac/harness` 1.0.0-rc.17 from npm instead of a git commit, so a consumer installs
77
96
  the published harness with its named entries.
78
97
 
79
98
  - Wipe a store written by 1.0.0-rc.0 to rc.2 before running this build. The collection, route and
@@ -104,12 +123,34 @@ release.
104
123
 
105
124
  ### Removed
106
125
 
107
- - The `duck` terminal UI and its bin; the terminal app lives in its own repo.
126
+ - `duck`'s `/agent borrow` and `/mesh new compute`, now that Core 1.0 retires
127
+ model loans and compute meshes.
108
128
 
109
129
  ### Fixed
110
130
 
131
+ - A run that restarts mid-reply no longer has its host write the abandoned round's answer a second
132
+ time beside the new attempt's: the run cancels the model rounds its earlier attempt left open
133
+ before it starts again.
111
134
  - A resume whose announce reached no DHT node retries that topic within
112
135
  seconds, instead of leaving the device unfindable for ten minutes.
136
+ - A chat cache whose workspace this device no longer sees is deleted: left while the device was
137
+ closed, before it heard of the leave, or a member's chats it served. The assistant records which
138
+ chats it built a cache for and, at boot and whenever a mesh leaves the list, deletes those no open
139
+ mesh lists. A host keeps that record beside the run replays, through the new `kvCacheChatsDir`
140
+ option, so a data reset takes both; retention Never turns the sweep off too.
141
+
142
+ ```js
143
+ assistantTree({ runReplayDir: `${root}/run-replay`, kvCacheChatsDir: `${root}/kv-cache-chats` })
144
+ ```
145
+
146
+ - A device that hosts another member's agent sweeps its chat caches too: KV cache retention and the
147
+ orphaned cache sweep read a hosted mesh through `listChats`, which the assistant's connection now
148
+ answers there with the chats it serves, instead of failing the whole sweep. A host restart keeps
149
+ the caches it serves until hosting resumes, instead of deleting them at boot.
150
+ - Upgrading from app 0.21 no longer reruns a send that was still unanswered in a private chat. The
151
+ private chats copied into your own workspace now end an open run as failed, as the chats copied
152
+ into a project already did, instead of leaving a request for the assistant to take. An approval
153
+ that run was holding is denied in the copy in both places, so none stays pending on a failed run.
113
154
 
114
155
  ## [0.11.4] - 2026-10-30
115
156
 
package/README.md CHANGED
@@ -21,7 +21,8 @@
21
21
  <a href="#one-shot-tasks">Tasks</a> &middot;
22
22
  <a href="#rendering-the-chunk-stream-any-ui">Chunk stream</a> &middot;
23
23
  <a href="#harness-event-reference">Events</a> &middot;
24
- <a href="#development">Development</a>
24
+ <a href="#development">Development</a> &middot;
25
+ <a href="#the-duck-tui">duck TUI</a>
25
26
  </p>
26
27
 
27
28
  A P2P, multi-device AI workbench core. Three pieces, one duplex stream:
@@ -43,12 +44,22 @@ A P2P, multi-device AI workbench core. Three pieces, one duplex stream:
43
44
 
44
45
  ## Install
45
46
 
47
+ `@qvac/core` is two things: a **library** you embed, and **`duck`**, a terminal
48
+ app that runs the whole stack on top of it.
49
+
46
50
  ```sh
47
- npm i @qvac/core
51
+ npm i @qvac/core # the library
52
+ npm i -g bare @qvac/core # duck, on your PATH, with the Bare it runs on
53
+ ```
54
+
55
+ ```sh
56
+ duck # the TUI
57
+ duck --help
48
58
  ```
49
59
 
50
60
  The library is the three pieces above — start at
51
- [Integrating a harness](#integrating-a-harness). Runnable examples live in
61
+ [Integrating a harness](#integrating-a-harness). `duck` is the fastest way to
62
+ watch them work; it has its own section at [The duck TUI](#the-duck-tui). Runnable examples live in
52
63
  [`examples/`](./examples/README.md); `bun run mesh-two-people` is the shortest
53
64
  one, and shows what a device invite does that a member invite does not.
54
65
 
@@ -655,6 +666,10 @@ MCP-type app registered at app.asana.com), Spotify a client id; Notion needs
655
666
  nothing — its MCP server self-provisions a public client via dynamic
656
667
  registration (RFC 7591) + PKCE.
657
668
 
669
+ In duck, `/skill <name>` opens a skill's setup sheet: what it needs, its fields,
670
+ and the browser sign-in for an OAuth skill. `/skill on <name>` opens it first
671
+ when the skill needs setup, and `/connect <name>` signs in straight away.
672
+
658
673
  ### Notion
659
674
 
660
675
  Notion runs over its official MCP server (`https://mcp.notion.com/mcp`) via
@@ -668,8 +683,11 @@ in a tool result means the token expired — connect Notion again.
668
683
  ```sh
669
684
  npm test # node + bare suites
670
685
  npm run build:schema # regenerate spec/ from schema/ (bare)
686
+ bun run duck # run the TUI (no build step)
671
687
  ```
672
688
 
689
+ The TUI lives in [`tui/`](tui/README.md) and installs as the `duck` command.
690
+
673
691
  Schema changes go in `schema/*.ts` (builders) — `spec/` is generated. The
674
692
  mesh schema (`spec/mesh/*`) is the replicated protocol: every device in a
675
693
  mesh must run the same generated spec. See `MIGRATION.md` for the audited
@@ -679,7 +697,40 @@ feature checklist vs core v1.
679
697
 
680
698
  Core ships no office decoder. Office documents (`.docx`, `.xlsx`, `.pptx`,
681
699
  `.odt`, …) index only when the host passes one through the `extractors.office`
682
- option — the desktop app injects `extractOfficeText` from
700
+ option — the desktop app and `duck` inject `extractOfficeText` from
683
701
  `@qvac/harness/office`. A host without one, such as mobile, fails those files
684
702
  as `extractor unavailable on this device`. Everything else — `.pdf`, `.txt`,
685
703
  `.md`, `.rtf`, `.html`, `.csv`, `.json` and the rest — works from any install.
704
+
705
+ ## The duck TUI
706
+
707
+ `duck` brings the whole stack up — Core, the assistant, your harness — behind a
708
+ terminal UI. It is on your PATH after `npm i -g @qvac/core`, or `bun run duck`
709
+ in this repo. `duck --help` lists the flags, and
710
+ [`docs/tui-commands.md`](docs/tui-commands.md) every slash command.
711
+
712
+ The TUI copies its mesh invite to the clipboard on ctrl+y. On a second machine
713
+ (or a second terminal), start `duck` and join from inside it:
714
+
715
+ ```
716
+ /join qvac://device/…
717
+ ```
718
+
719
+ The preview says who you would join as. A device invite (`/invite`) retires the
720
+ mesh this device is on and pairs it into the inviter's account; a member invite
721
+ (`/invite member`) adds a workspace beside yours. Headless, `duck --join <invite>`
722
+ takes a member invite and `duck --device-join <invite>` a device invite.
723
+
724
+ `--headless` brings the same stack up with no TUI: it prints the invite and then
725
+ streams logs (including the sidecar child's own output, which the TUI drops) to
726
+ stdout until ctrl+C. That is the shape to run as a background mesh peer, and the
727
+ only way to read the engine's logs live — `QVAC_LOG_LEVEL` picks the level:
728
+
729
+ ```sh
730
+ duck --headless
731
+ ```
732
+
733
+ The joiner brings no models — it finds the mesh's agent and asks. The device
734
+ that sends drives the run, the agent's model host serves each model round, and
735
+ both sides watch the same replicated stream: load progress, thinking, tokens,
736
+ tool approvals (either side can answer), and final stats.
@@ -8,6 +8,7 @@ type AgentCapabilities = Pick<CapabilityHandlers, 'createAgent' | 'listAgents' |
8
8
  export interface CreateAgentsApiOptions {
9
9
  readonly deviceId: Buffer | null;
10
10
  readonly changed?: ((agentId: string) => Promise<void>) | null;
11
+ readonly modelPicked?: ((modelName: string) => Promise<void>) | null;
11
12
  readonly keepCopies?: ((agent: QvacAgent) => Promise<void>) | null;
12
13
  readonly peers?: Pick<MeshStatusSource, 'watch' | 'unwatch' | 'snapshot'> | null;
13
14
  readonly accountChanges?: AccountChanges | null;
@@ -18,5 +19,5 @@ interface AccountChanges {
18
19
  watch(listener: () => void): void;
19
20
  unwatch(listener: () => void): void;
20
21
  }
21
- export declare function createAgentsApi(pool: MeshPool, { deviceId, changed, keepCopies, peers, accountChanges, folders, log }: CreateAgentsApiOptions): AgentCapabilities;
22
+ export declare function createAgentsApi(pool: MeshPool, { deviceId, changed, modelPicked, keepCopies, peers, accountChanges, folders, log }: CreateAgentsApiOptions): AgentCapabilities;
22
23
  export {};
@@ -17,11 +17,12 @@ async function definitions(mesh, rows) {
17
17
  const resolved = await Promise.all(rows.map((row) => runDefinition(mesh, row)));
18
18
  return resolved.filter((row) => row !== null);
19
19
  }
20
- export function createAgentsApi(pool, { deviceId, changed = null, keepCopies = null, peers = null, accountChanges = null, folders, log }) {
20
+ export function createAgentsApi(pool, { deviceId, changed = null, modelPicked = null, keepCopies = null, peers = null, accountChanges = null, folders, log }) {
21
21
  const reachable = () => new Set([
22
22
  ...(peers?.snapshot().peerDeviceIds ?? []),
23
23
  ...(deviceId ? [b4a.toHex(deviceId)] : [])
24
24
  ]);
25
+ const isOwnDefault = (agent) => agent.isDefault === true && !!deviceId && b4a.equals(agent.providerDeviceId, deviceId);
25
26
  const withDerived = async (mesh, agent) => ({
26
27
  ...agent,
27
28
  lenderDeviceId: undefined,
@@ -66,8 +67,11 @@ export function createAgentsApi(pool, { deviceId, changed = null, keepCopies = n
66
67
  };
67
68
  const agentHolder = async (meshId, agentId) => {
68
69
  const mesh = await requireMesh(pool, meshId);
69
- const chats = await requireMesh(pool, meshId, CHAT_ROWS);
70
- 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);
71
75
  };
72
76
  return {
73
77
  createAgent: async ({ meshId, config }) => {
@@ -99,6 +103,9 @@ export function createAgentsApi(pool, { deviceId, changed = null, keepCopies = n
99
103
  const mesh = await requireMesh(pool, meshId);
100
104
  await notPicked(mesh, agentId);
101
105
  const updated = await updateAgent(mesh, agentId, config);
106
+ if (config.modelName && isOwnDefault(updated)) {
107
+ await modelPicked?.(config.modelName);
108
+ }
102
109
  await changed?.(agentId);
103
110
  return withDerived(mesh, updated);
104
111
  },
@@ -4,5 +4,8 @@ import type { openLocalStore } from '../core/local/index.ts';
4
4
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
5
5
  type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
6
6
  export declare function writeAutoDownloadModels(state: LocalStore, enabled: boolean): Promise<AssistantAppConfig>;
7
+ export declare function readLastModelName(state: LocalStore): Promise<string | null>;
8
+ export declare function writeLastModelName(state: LocalStore, name: string): Promise<void>;
9
+ export declare function backfillLastModelName(state: LocalStore, pick: () => Promise<string | null>): Promise<void>;
7
10
  export declare function createAppConfigApi(state: LocalStore, log: LoggerInterface | null): Pick<CapabilityHandlers, 'getConfig' | 'setConfig' | 'setModelPaused' | 'setModelReleased' | 'setAutoDownloadModels' | 'configWatchTyped'>;
8
11
  export {};
@@ -121,6 +121,26 @@ export async function writeAutoDownloadModels(state, enabled) {
121
121
  const row = await state.updateAppConfigRow((current) => toRow({ ...toConfig(current), autoDownloadModels: enabled }));
122
122
  return toConfig(row);
123
123
  }
124
+ export async function readLastModelName(state) {
125
+ return (await readConfig(state)).lastModelName ?? null;
126
+ }
127
+ export async function writeLastModelName(state, name) {
128
+ await state.updateAppConfigRow((current) => toRow({ ...toConfig(current), lastModelName: name }));
129
+ }
130
+ export async function backfillLastModelName(state, pick) {
131
+ const config = await readConfig(state);
132
+ if (!config.onboardingCompleted || config.lastModelName) {
133
+ return;
134
+ }
135
+ const name = await pick();
136
+ if (!name) {
137
+ return;
138
+ }
139
+ await state.updateAppConfigRow((current) => {
140
+ const latest = toConfig(current);
141
+ return toRow({ ...latest, lastModelName: latest.lastModelName ?? name });
142
+ });
143
+ }
124
144
  export function createAppConfigApi(state, log) {
125
145
  return {
126
146
  getConfig(_) {
@@ -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 }) => {
@@ -1,5 +1,5 @@
1
1
  import type { Capabilities, CapabilityHandlers } from '../../spec/capabilities.d.ts';
2
- export declare const DEVICE_ROUTES: readonly ["listModels", "deleteModel", "loadModel", "unloadModel", "retryModelDownload", "clearModelDownload", "modelCatalogWatch", "modelDownloadsWatch", "customModelsWatch", "previewCustomModel", "addCustomModel", "removeCustomModel", "modelUsers", "modelsWatch", "configGet", "configSet", "configWatch", "setModelPaused"];
2
+ export declare const DEVICE_ROUTES: readonly ["listModels", "deleteModel", "loadModel", "unloadModel", "retryModelDownload", "clearModelDownload", "modelCatalogWatch", "modelDownloadsWatch", "customModelsWatch", "previewCustomModel", "addCustomModel", "removeCustomModel", "modelUsers", "modelsWatch", "configGet", "configSet", "configWatch", "setModelPaused", "skillOauth"];
3
3
  export type DeviceRoutes = Pick<CapabilityHandlers, (typeof DEVICE_ROUTES)[number]>;
4
4
  export interface ForwardingOptions {
5
5
  readonly deviceId: Buffer;
@@ -26,7 +26,8 @@ export const DEVICE_ROUTES = [
26
26
  'configGet',
27
27
  'configSet',
28
28
  'configWatch',
29
- 'setModelPaused'
29
+ 'setModelPaused',
30
+ 'skillOauth'
30
31
  ];
31
32
  function modelRoutes(at) {
32
33
  return {
@@ -47,6 +48,7 @@ function modelRoutes(at) {
47
48
  configGet: (input) => answer(at(input).configGet, 'configGet', here(input)),
48
49
  configSet: (input) => answer(at(input).configSet, 'configSet', here(input)),
49
50
  configWatch: (input) => watched(() => required(at(input).configWatch, 'configWatch')(here(input))),
51
+ skillOauth: (input) => answer(at(input).skillOauth, 'skillOauth', here(input)),
50
52
  setModelPaused: (input) => answer(at(input).setModelPaused, 'setModelPaused', here(input))
51
53
  };
52
54
  }
@@ -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;
@@ -10,7 +10,7 @@ import { createChatApi } from './chat.js';
10
10
  import { createChatMoveApi } from './chat-move.js';
11
11
  import { createChatGroupsApi } from './chat-groups.js';
12
12
  import { createChunksApi } from './chunks.js';
13
- import { createAppConfigApi } from './app-config.js';
13
+ import { createAppConfigApi, writeLastModelName } from './app-config.js';
14
14
  import { createConfigApi } from './config.js';
15
15
  import { createDevicesApi } from './devices.js';
16
16
  import { createDiagnosticsApi } from './diagnostics.js';
@@ -63,6 +63,7 @@ export function createApi(deps = {}) {
63
63
  ? createAgentsApi(routed(mesh, 'put-agent'), {
64
64
  deviceId: deps.deviceId ?? null,
65
65
  changed: deps.agentChanged ?? null,
66
+ modelPicked: state ? (name) => writeLastModelName(state, name) : null,
66
67
  keepCopies: deps.agentCopiesKept ?? null,
67
68
  peers: deps.meshStatus ?? null,
68
69
  accountChanges: deps.accountAgents ?? null,
@@ -78,7 +79,6 @@ export function createApi(deps = {}) {
78
79
  inferenceCalls: deps.inferenceCalls ?? null,
79
80
  deletedProject: deps.deletedProject ?? null,
80
81
  projectOf: deps.projectOf ?? null,
81
- workspaceOf: deps.workspaceOf ?? null,
82
82
  log
83
83
  })
84
84
  : null),
@@ -137,7 +137,7 @@ export function createApi(deps = {}) {
137
137
  ...(mesh && state
138
138
  ? createHostRunLogApi(routed(mesh, 'append-chunk'), state.runLogs, deps.deviceId ?? null)
139
139
  : null),
140
- ...(mesh ? createSyncApi(routed(mesh, 'append-chunk'), log) : null),
140
+ ...(mesh ? createSyncApi(mesh, log) : null),
141
141
  ...(mesh ? createToolConfigsApi(routed(mesh, 'put-tool-configs'), log) : null),
142
142
  ...(mesh
143
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
  }),
@@ -103,10 +103,9 @@ async function addMember(pool, { projectOf, nameOf }, { meshId, projectId, membe
103
103
  const { workspace, row } = scope;
104
104
  const batch = workspace.batch();
105
105
  batch.dispatch('set-project-listing', { projectId: row.id, memberId });
106
- const key = await dueProjectKey(workspace.view, memberId, {
107
- projectId: row.id,
108
- seed: project.seed
109
- });
106
+ const sealedBy = workspace.ourMemberId;
107
+ const sealing = sealedBy && { projectId: row.id, seed: project.seed, sealedBy };
108
+ const key = sealing && (await dueProjectKey(workspace.view, memberId, sealing));
110
109
  if (key) {
111
110
  batch.dispatch('put-project-key', key);
112
111
  }
@@ -3,11 +3,11 @@ import type { AssistantMeshList } from '../../spec/hyperschema/types.d.ts';
3
3
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
4
4
  import { type MeshPool } from './current-mesh.ts';
5
5
  import type { MeshStatusSource } from './mesh.ts';
6
- export declare const SERVED_ROUTES: readonly ["listMeshes", "meshesWatch", "chatsWatch", "listChunks", "chunksWatch", "appendChunk", "modelRequestsWatch", "takeModelRequest", "settleModelRequest"];
6
+ export declare const SERVED_ROUTES: readonly ["listMeshes", "meshesWatch", "listChats", "chatsWatch", "listChunks", "chunksWatch", "appendChunk", "modelRequestsWatch", "takeModelRequest", "settleModelRequest"];
7
7
  export type ServedRoutes = Pick<CapabilityHandlers, (typeof SERVED_ROUTES)[number]>;
8
8
  export interface ServedOptions {
9
9
  readonly pool: MeshPool;
10
- readonly local: Partial<Pick<CapabilityHandlers, 'chatsWatch' | 'appendChunk'>>;
10
+ readonly local: Partial<Pick<CapabilityHandlers, 'listChats' | 'chatsWatch' | 'appendChunk'>>;
11
11
  readonly foreign: (meshId: string) => boolean;
12
12
  readonly status: Pick<MeshStatusSource, 'watch' | 'unwatch'>;
13
13
  readonly list: () => Promise<AssistantMeshList>;
@@ -1,3 +1,4 @@
1
+ import { lastActivity } from '../core/chat.js';
1
2
  import { readChunk } from '../core/chunk.js';
2
3
  import { listModelRequests } from '../core/model-requests.js';
3
4
  import { servedChats } from '../core/public-mesh.js';
@@ -7,6 +8,7 @@ import { watchable } from './watchable.js';
7
8
  export const SERVED_ROUTES = [
8
9
  'listMeshes',
9
10
  'meshesWatch',
11
+ 'listChats',
10
12
  'chatsWatch',
11
13
  'listChunks',
12
14
  'chunksWatch',
@@ -30,13 +32,18 @@ export function createServedApi({ pool, local, foreign, status, list, deviceId,
30
32
  const live = await listModelRequests(mesh);
31
33
  return { chunks: live.filter((round) => chats.has(round.chatId)).map(readChunk) };
32
34
  }, { name: 'modelRequestsWatch', log });
33
- const { chatsWatch: ownChats = chatsWatch, appendChunk: ownAppend = chunks.appendChunk } = local;
35
+ const listChats = async ({ meshId }) => {
36
+ const mesh = await requireMesh(pool, meshId, { wide: true });
37
+ return { chats: deviceId ? await servedListing(mesh, deviceId) : [] };
38
+ };
39
+ const { listChats: ownList = listChats, chatsWatch: ownChats = chatsWatch, appendChunk: ownAppend = chunks.appendChunk } = local;
34
40
  return {
35
41
  listMeshes: list,
36
42
  meshesWatch: watchable(() => status, list, {
37
43
  name: 'meshesWatch',
38
44
  log
39
45
  }),
46
+ listChats: (request) => (foreign(request.meshId) ? listChats(request) : ownList(request)),
40
47
  chatsWatch: (request) => (foreign(request.meshId) ? chatsWatch(request) : ownChats(request)),
41
48
  listChunks: chunks.listChunks,
42
49
  chunksWatch: chunks.chunksWatch,
@@ -46,3 +53,19 @@ export function createServedApi({ pool, local, foreign, status, list, deviceId,
46
53
  settleModelRequest: chunks.settleModelRequest
47
54
  };
48
55
  }
56
+ async function servedListing(mesh, deviceId) {
57
+ const snap = mesh.view.snapshot();
58
+ try {
59
+ const activity = await lastActivity(snap);
60
+ return (await servedChats(mesh, deviceId)).map(({ id, agentId, title, createdAt }) => ({
61
+ id,
62
+ agentId,
63
+ title,
64
+ createdAt,
65
+ lastActivityAt: activity.get(id) || createdAt
66
+ }));
67
+ }
68
+ finally {
69
+ await snap.close();
70
+ }
71
+ }
@@ -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
  }
@@ -128,6 +128,9 @@ export interface Harness {
128
128
  approve?: (call: ApprovalCall) => Promise<boolean>;
129
129
  attach?: (input: AttachInput) => Promise<AssistantChunkContentAttachment>;
130
130
  fetchAttachment?: (query: FetchAttachmentOptions) => Promise<FetchedAttachment | AttachmentMeta | null>;
131
+ showImage?: (query: {
132
+ attachmentId: string;
133
+ }) => Promise<string | null>;
131
134
  progress?: (update: ImageProgress | null) => void;
132
135
  input?: AsyncIterable<RunInput>;
133
136
  signal?: AbortSignal;
@@ -77,6 +77,12 @@ export function historyFromChunks(chunks, stale = {}, { sentRuns = new Map(), as
77
77
  }
78
78
  }
79
79
  const byMessage = groupAttachmentsByMessage(attachments, userMessages);
80
+ const byId = new Map();
81
+ for (const { attachment } of attachments) {
82
+ if (attachment && !attachment.deletedAt) {
83
+ byId.set(attachment.id, attachment);
84
+ }
85
+ }
80
86
  const digests = derivedAttachments(chunks);
81
87
  const steered = steeredQuestions(source, sentRuns);
82
88
  const history = [];
@@ -104,7 +110,7 @@ export function historyFromChunks(chunks, stale = {}, { sentRuns = new Map(), as
104
110
  }
105
111
  const sent = live ? sentRuns.get(live) : undefined;
106
112
  if (sent) {
107
- const replayed = sent.map((message) => ({ ...message }));
113
+ const replayed = sent.map((message) => shownAgain(message, byId));
108
114
  history.push(...replayed);
109
115
  for (const message of [...replayed, turn]) {
110
116
  kept.add(message);
@@ -213,6 +219,10 @@ export function historyFromChunks(chunks, stale = {}, { sentRuns = new Map(), as
213
219
  }
214
220
  return history.filter((turn) => turn.role === 'user' || turn.content.length > 0 || kept.has(turn));
215
221
  }
222
+ function shownAgain({ imageIds, ...turn }, byId) {
223
+ const images = (imageIds ?? []).flatMap((id) => byId.get(id) ?? []);
224
+ return images.length ? { ...turn, images } : turn;
225
+ }
216
226
  function steeredQuestions(chunks, sentRuns) {
217
227
  const into = new Map();
218
228
  for (const chunk of chunks) {
@@ -262,7 +272,9 @@ export function replayFromChunks(rounds) {
262
272
  }
263
273
  const turns = chunk.modelRequest?.state === 'done' ? chunk.modelRequest.toolTurns : undefined;
264
274
  if (Array.isArray(turns)) {
265
- sentRuns.set(chunk.runId, turns.filter(isChatMessage).map(({ role, content }) => ({ role, content })));
275
+ sentRuns.set(chunk.runId, turns
276
+ .filter(isChatMessage)
277
+ .map(({ role, content, imageIds }) => imageIds ? { role, content, imageIds } : { role, content }));
266
278
  }
267
279
  }
268
280
  return { sentRuns, readRuns };
@@ -9,6 +9,7 @@ export interface ChatMessage {
9
9
  attachments?: {
10
10
  path: string;
11
11
  }[];
12
+ imageIds?: string[];
12
13
  images?: AttachmentRef[];
13
14
  audioAttachments?: AttachmentRef[];
14
15
  videos?: VideoRef[];