@vellumai/assistant 0.12.5 → 0.12.6-dev.202609292019.a6f6d85

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 (264) hide show
  1. package/.env.example +2 -0
  2. package/ARCHITECTURE.md +23 -0
  3. package/docs/automatic-done.md +32 -0
  4. package/docs/desktop-browser-cli.md +3 -2
  5. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +2 -1
  6. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/mcp-oauth.test.ts +53 -0
  7. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
  8. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/mcp-oauth.ts +60 -0
  9. package/node_modules/@vellumai/environments/src/shell.test.ts +13 -1
  10. package/node_modules/@vellumai/environments/src/shell.ts +22 -1
  11. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +2 -1
  12. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/mcp-oauth.test.ts +53 -0
  13. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
  14. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/mcp-oauth.ts +60 -0
  15. package/node_modules/@vellumai/gateway-client/src/__tests__/status-contracts.test.ts +39 -0
  16. package/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +25 -0
  17. package/node_modules/@vellumai/service-contracts/package.json +2 -1
  18. package/node_modules/@vellumai/service-contracts/src/__tests__/mcp-oauth.test.ts +53 -0
  19. package/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
  20. package/node_modules/@vellumai/service-contracts/src/mcp-oauth.ts +60 -0
  21. package/openapi.yaml +270 -10
  22. package/package.json +1 -1
  23. package/src/__tests__/agent-loop.test.ts +76 -0
  24. package/src/__tests__/anthropic-provider.test.ts +2 -0
  25. package/src/__tests__/byok-default-profile-ensure.test.ts +7 -0
  26. package/src/__tests__/config-get-vision-flag.test.ts +1 -1
  27. package/src/__tests__/config-loader-validation-reset-notice.test.ts +2 -2
  28. package/src/__tests__/conversation-agent-loop-overflow.test.ts +160 -154
  29. package/src/__tests__/conversation-evictor.test.ts +54 -0
  30. package/src/__tests__/conversation-pairing.test.ts +112 -0
  31. package/src/__tests__/document-append-idempotency.test.ts +13 -0
  32. package/src/__tests__/document-create-dedupe.test.ts +13 -0
  33. package/src/__tests__/document-find-replace.test.ts +13 -0
  34. package/src/__tests__/document-revision-history.test.ts +390 -0
  35. package/src/__tests__/document-revision.test.ts +425 -0
  36. package/src/__tests__/document-tool-security.test.ts +13 -0
  37. package/src/__tests__/document-update-default-surface.test.ts +13 -0
  38. package/src/__tests__/emit-signal-routing-intent.test.ts +270 -0
  39. package/src/__tests__/gateway-flag-listener.test.ts +59 -6
  40. package/src/__tests__/headless-browser-navigate.test.ts +20 -30
  41. package/src/__tests__/host-cu-proxy.test.ts +79 -0
  42. package/src/__tests__/host-cu-routes-targeted.test.ts +14 -5
  43. package/src/__tests__/host-shell-tool.test.ts +6 -2
  44. package/src/__tests__/identity-routes.test.ts +4 -3
  45. package/src/__tests__/llm-catalog-parity.test.ts +4 -4
  46. package/src/__tests__/llm-schema.test.ts +1 -1
  47. package/src/__tests__/notification-platform-adapter.test.ts +83 -1
  48. package/src/__tests__/oauth2-gateway-transport.test.ts +2 -0
  49. package/src/__tests__/openai-provider.test.ts +11 -11
  50. package/src/__tests__/pricing.test.ts +11 -0
  51. package/src/__tests__/public-ingress-urls.test.ts +26 -0
  52. package/src/__tests__/retry-thinking-tool-choice.test.ts +47 -0
  53. package/src/__tests__/usage-attribution.test.ts +31 -0
  54. package/src/__tests__/workspace-migration-133-collapse-provider-connections.test.ts +3 -3
  55. package/src/__tests__/workspace-migration-160-repair-retired-fireworks-model-ids.test.ts +262 -0
  56. package/src/__tests__/workspace-migration-161-repair-retired-fireworks-glm-5p2-model-id.test.ts +233 -0
  57. package/src/acp/agent-process.ts +6 -1
  58. package/src/acp/client-handler.ts +6 -1
  59. package/src/agent/loop.ts +29 -6
  60. package/src/api/events/document-editor-show.ts +5 -0
  61. package/src/api/events/document-editor-update.ts +10 -0
  62. package/src/api/events/tool-result.ts +1 -0
  63. package/src/calls/__tests__/voice-session-bridge.test.ts +54 -0
  64. package/src/calls/channel-admission-reader.ts +15 -9
  65. package/src/calls/twilio-provider.ts +14 -31
  66. package/src/calls/voice-session-bridge.ts +18 -1
  67. package/src/cli/commands/browser.ts +1 -2
  68. package/src/cli/lib/__tests__/plugin-artifact.test.ts +23 -0
  69. package/src/cli/lib/__tests__/plugin-catalog-visibility.test.ts +2 -0
  70. package/src/cli/lib/__tests__/plugin-details.test.ts +16 -0
  71. package/src/cli/lib/bundled-marketplace.json +41 -2
  72. package/src/cli/lib/inspect-plugin.ts +15 -15
  73. package/src/cli/lib/list-installed-plugins.ts +29 -28
  74. package/src/cli/lib/plugin-artifact.ts +74 -63
  75. package/src/cli/lib/plugin-catalog-visibility.ts +1 -0
  76. package/src/cli/lib/plugin-details.ts +27 -42
  77. package/src/cli/lib/plugin-marketplace.ts +6 -8
  78. package/src/cli/lib/plugin-surfaces.ts +8 -7
  79. package/src/cli.ts +1 -3
  80. package/src/config/__tests__/chat-settings.test.ts +121 -0
  81. package/src/config/assistant-feature-flags.ts +28 -23
  82. package/src/config/bundled-skills/computer-use/SKILL.md +20 -0
  83. package/src/config/bundled-skills/computer-use/TOOLS.json +11 -11
  84. package/src/config/chat-settings.ts +100 -0
  85. package/src/config/default-profile-catalog.ts +1 -1
  86. package/src/config/feature-flag-cache.ts +7 -25
  87. package/src/config/feature-flag-registry.json +1 -9
  88. package/src/config/loader.ts +5 -1
  89. package/src/config/profile-text-generation.ts +25 -21
  90. package/src/config/schemas/conversations.ts +14 -0
  91. package/src/config/schemas/llm.ts +1 -0
  92. package/src/config/schemas/notifications.ts +8 -1
  93. package/src/contacts/gateway-channel-read.ts +1 -1
  94. package/src/conversations/__tests__/auto-archive-activity.test.ts +136 -0
  95. package/src/conversations/__tests__/auto-archive.test.ts +304 -0
  96. package/src/conversations/auto-archive-activity.ts +61 -0
  97. package/src/conversations/auto-archive.ts +201 -0
  98. package/src/daemon/computer-use-observation.test.ts +81 -0
  99. package/src/daemon/computer-use-observation.ts +23 -0
  100. package/src/daemon/conversation-agent-loop.ts +11 -6
  101. package/src/daemon/conversation-evictor.ts +50 -16
  102. package/src/daemon/doordash-steps.ts +1 -3
  103. package/src/daemon/handlers/__tests__/config-a2a-accept.test.ts +43 -1
  104. package/src/daemon/handlers/__tests__/config-channels.test.ts +1 -1
  105. package/src/daemon/handlers/config-a2a.ts +75 -2
  106. package/src/daemon/host-cu-proxy.ts +34 -3
  107. package/src/daemon/lifecycle.ts +15 -2
  108. package/src/daemon/shutdown-handlers.ts +3 -0
  109. package/src/daemon/turn-finalization.ts +4 -0
  110. package/src/desktop/desktop-browser-endpoint.ts +11 -2
  111. package/src/desktop/desktop-chrome-policy.test.ts +1 -0
  112. package/src/desktop/desktop-chrome-policy.ts +7 -1
  113. package/src/desktop/desktop-computer-use.test.ts +14 -4
  114. package/src/desktop/desktop-session-manager.ts +5 -3
  115. package/src/documents/document-revisions-store.ts +153 -0
  116. package/src/documents/document-store.ts +471 -133
  117. package/src/followups/followup-store.ts +0 -4
  118. package/src/inbound/__tests__/oauth-callback-url.test.ts +25 -2
  119. package/src/inbound/oauth-callback-url.ts +30 -1
  120. package/src/inbound/public-ingress-urls.ts +12 -2
  121. package/src/ipc/gateway-client.test.ts +40 -0
  122. package/src/ipc/gateway-client.ts +12 -29
  123. package/src/ipc/gateway-flag-listener.ts +7 -10
  124. package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +71 -0
  125. package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +83 -0
  126. package/src/live-voice/__tests__/protocol.test.ts +77 -0
  127. package/src/live-voice/__tests__/share-targets.test.ts +163 -0
  128. package/src/live-voice/live-voice-session.ts +23 -6
  129. package/src/live-voice/protocol.ts +22 -0
  130. package/src/live-voice/share-targets.ts +225 -0
  131. package/src/mcp/__tests__/mcp-oauth-client-registration.test.ts +144 -3
  132. package/src/mcp/__tests__/mcp-oauth-provider.test.ts +2 -0
  133. package/src/mcp/client.ts +1 -19
  134. package/src/mcp/mcp-oauth-provider.ts +66 -49
  135. package/src/media/openrouter-image-service.ts +39 -22
  136. package/src/monitoring/__tests__/oom-inheritance-sweep.test.ts +86 -0
  137. package/src/monitoring/__tests__/oom-kill-reporter.test.ts +374 -0
  138. package/src/monitoring/control.ts +2 -1
  139. package/src/monitoring/oom-inheritance-sweep.ts +96 -0
  140. package/src/monitoring/oom-kill-reporter.ts +469 -0
  141. package/src/monitoring/resource-sampler.ts +30 -0
  142. package/src/notifications/README.md +53 -4
  143. package/src/notifications/__tests__/assistant-initiated-thread.test.ts +254 -0
  144. package/src/notifications/__tests__/broadcaster.test.ts +558 -6
  145. package/src/notifications/__tests__/completion-policy.test.ts +37 -0
  146. package/src/notifications/__tests__/from-me-alert-integration.test.ts +192 -0
  147. package/src/notifications/adapters/platform.ts +14 -0
  148. package/src/notifications/assistant-initiated-thread.ts +101 -0
  149. package/src/notifications/broadcaster.ts +94 -16
  150. package/src/notifications/chat-reply-policy.ts +11 -0
  151. package/src/notifications/completion-policy.ts +12 -2
  152. package/src/notifications/conversation-pairing.ts +15 -70
  153. package/src/notifications/emit-signal.ts +34 -3
  154. package/src/notifications/types.ts +2 -0
  155. package/src/oauth/connect-orchestrator.ts +1 -2
  156. package/src/persistence/__tests__/conversation-auto-archive.test.ts +330 -0
  157. package/src/persistence/conversation-auto-archive.ts +170 -0
  158. package/src/persistence/conversation-crud.ts +2 -1
  159. package/src/persistence/conversation-queries.ts +15 -8
  160. package/src/persistence/embeddings/embed.test.ts +96 -0
  161. package/src/persistence/embeddings/embed.ts +20 -2
  162. package/src/persistence/embeddings/embedding-gemini.test.ts +39 -3
  163. package/src/persistence/embeddings/embedding-gemini.ts +39 -1
  164. package/src/persistence/embeddings/embedding-local.ts +6 -0
  165. package/src/persistence/embeddings/qdrant-manager.ts +5 -0
  166. package/src/persistence/job-utils.ts +10 -0
  167. package/src/persistence/migrations/384-add-document-revision.test.ts +83 -0
  168. package/src/persistence/migrations/384-add-document-revision.ts +21 -0
  169. package/src/persistence/migrations/385-create-document-revisions.test.ts +67 -0
  170. package/src/persistence/migrations/385-create-document-revisions.ts +28 -0
  171. package/src/persistence/migrations/386-conversations-last-reopened-at.ts +10 -0
  172. package/src/persistence/migrations/__tests__/386-conversations-last-reopened-at.test.ts +32 -0
  173. package/src/persistence/schema/conversations.ts +1 -0
  174. package/src/persistence/schema/documents.ts +20 -0
  175. package/src/persistence/steps.ts +6 -0
  176. package/src/platform/managed-speech.ts +42 -46
  177. package/src/plugin-api/vision-support.test.ts +21 -21
  178. package/src/plugins/defaults/empty-response/hooks/post-model-call.ts +11 -6
  179. package/src/providers/__tests__/dispatch-connection-routing.test.ts +1 -1
  180. package/src/providers/__tests__/search-provider-catalog.test.ts +8 -0
  181. package/src/providers/anthropic/client.ts +1 -1
  182. package/src/providers/fireworks/client.test.ts +168 -0
  183. package/src/providers/fireworks/client.ts +24 -0
  184. package/src/providers/inference/adapter-factory.ts +6 -0
  185. package/src/providers/ionet/client.test.ts +143 -0
  186. package/src/providers/ionet/client.ts +37 -0
  187. package/src/providers/model-catalog.ts +141 -84
  188. package/src/providers/model-intents.ts +4 -4
  189. package/src/providers/openai/chat-completions-provider.ts +23 -1
  190. package/src/providers/retry.ts +56 -4
  191. package/src/providers/search-provider-catalog.ts +10 -0
  192. package/src/providers/types.ts +10 -2
  193. package/src/providers/usage-tracking.ts +5 -3
  194. package/src/runtime/assistant-event-hub.ts +23 -0
  195. package/src/runtime/auth/__tests__/guard-tests.test.ts +0 -7
  196. package/src/runtime/auth/__tests__/route-policy.test.ts +1 -1
  197. package/src/runtime/channel-retry-sweep.ts +1 -2
  198. package/src/runtime/migrations/__tests__/vbundle-streaming-validator.test.ts +35 -10
  199. package/src/runtime/migrations/__tests__/vbundle-validator-v1-schema.test.ts +48 -0
  200. package/src/runtime/migrations/vbundle-builder.ts +19 -3
  201. package/src/runtime/migrations/vbundle-streaming-importer.ts +14 -19
  202. package/src/runtime/migrations/vbundle-streaming-validator.ts +14 -7
  203. package/src/runtime/migrations/vbundle-validator.ts +54 -1
  204. package/src/runtime/pending-interactions.ts +20 -2
  205. package/src/runtime/routes/__tests__/contact-routes.test.ts +5 -3
  206. package/src/runtime/routes/__tests__/conversation-list-routes.test.ts +36 -0
  207. package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +375 -2
  208. package/src/runtime/routes/__tests__/inference-send-routes.test.ts +1 -1
  209. package/src/runtime/routes/__tests__/user-route-dispatcher.test.ts +12 -0
  210. package/src/runtime/routes/contact-routes.ts +2 -2
  211. package/src/runtime/routes/conversation-list-routes.ts +10 -2
  212. package/src/runtime/routes/conversation-query-routes.ts +48 -10
  213. package/src/runtime/routes/documents-routes.ts +185 -47
  214. package/src/runtime/routes/events-routes.ts +1 -3
  215. package/src/runtime/routes/host-app-control-routes.ts +1 -0
  216. package/src/runtime/routes/host-bash-routes.ts +1 -0
  217. package/src/runtime/routes/host-browser-routes.ts +15 -0
  218. package/src/runtime/routes/host-cu-routes.ts +4 -1
  219. package/src/runtime/routes/host-file-routes.ts +1 -0
  220. package/src/runtime/routes/host-proxy-result-binding.test.ts +83 -0
  221. package/src/runtime/routes/host-proxy-result-binding.ts +25 -0
  222. package/src/runtime/routes/host-transfer-routes.ts +1 -0
  223. package/src/runtime/routes/identity-routes.ts +3 -3
  224. package/src/runtime/routes/integrations/a2a.ts +4 -1
  225. package/src/runtime/routes/migration-routes.ts +3 -1
  226. package/src/runtime/routes/notification-routes.ts +1 -2
  227. package/src/runtime/routes/ui-snapshot-routes.test.ts +1 -0
  228. package/src/runtime/routes/user-route-dispatcher.ts +5 -1
  229. package/src/runtime/verification-templates.ts +1 -2
  230. package/src/sequence/analytics.ts +0 -4
  231. package/src/sequence/engine.ts +1 -11
  232. package/src/sequence/guardrails.ts +1 -6
  233. package/src/sequence/importer.ts +0 -8
  234. package/src/sequence/store.ts +0 -10
  235. package/src/signals/user-message.ts +0 -6
  236. package/src/skills/catalog-install.ts +52 -23
  237. package/src/tools/browser/browser-execution.ts +20 -23
  238. package/src/tools/browser/cdp-client/cdp-inspect/ws-transport.ts +1 -3
  239. package/src/tools/document/document-tool.ts +13 -11
  240. package/src/tools/executor.ts +1 -2
  241. package/src/tools/host-terminal/host-shell.ts +4 -2
  242. package/src/tools/network/__tests__/web-search.test.ts +105 -0
  243. package/src/tools/network/web-fetch.ts +2 -4
  244. package/src/tools/network/web-search.ts +239 -12
  245. package/src/tools/shared/filesystem/format-diff.ts +1 -2
  246. package/src/tools/shared/shell-output.test.ts +42 -0
  247. package/src/tools/shared/shell-output.ts +27 -4
  248. package/src/tools/terminal/shell.ts +3 -3
  249. package/src/tools/ui-surface/visual-validation.ts +1 -2
  250. package/src/usage/attribution.ts +18 -1
  251. package/src/util/__tests__/oom-priority.test.ts +55 -0
  252. package/src/util/__tests__/worker-memory.test.ts +16 -0
  253. package/src/util/debounce.ts +0 -4
  254. package/src/util/oom-priority.ts +79 -0
  255. package/src/util/platform.ts +0 -2
  256. package/src/util/plugin-manifest.ts +5 -7
  257. package/src/util/pricing.ts +25 -0
  258. package/src/util/worker-memory.ts +9 -3
  259. package/src/util/worker-process.ts +8 -0
  260. package/src/workspace/byok-default-profile-ensure.ts +11 -0
  261. package/src/workspace/hatched-date.ts +11 -4
  262. package/src/workspace/migrations/160-repair-retired-fireworks-model-ids.ts +209 -0
  263. package/src/workspace/migrations/161-repair-retired-fireworks-glm-5p2-model-id.ts +197 -0
  264. package/src/workspace/migrations/registry.ts +4 -0
@@ -381,6 +381,33 @@ export function computeManifestChecksum(manifest: unknown): string {
381
381
  // Core validation
382
382
  // ---------------------------------------------------------------------------
383
383
 
384
+ /**
385
+ * Hard caps on `manifest.json`, shared by the buffered and streaming
386
+ * validators so preflight and import agree on what is acceptable. The two
387
+ * are sized together: the manifest carries one `contents` entry (path,
388
+ * sha256, size) per bundled file at roughly 150 bytes each, so 200,000
389
+ * entries serialize to about 32 MiB.
390
+ *
391
+ * That absorbs a workspace with a stray dependency install or checked-out
392
+ * repo while still bounding the transient memory a hostile "manifest" can
393
+ * force the importer to hold (buffer, decoded string, parsed object,
394
+ * canonical re-serialization for the self-checksum) and the per-entry work
395
+ * it commits to, on a memory-constrained pod.
396
+ */
397
+ export const MANIFEST_MAX_BYTES = 32 * 1024 * 1024;
398
+ export const MANIFEST_MAX_ENTRIES = 200_000;
399
+
400
+ export interface ValidateVBundleOptions {
401
+ /**
402
+ * Reject manifests over `MANIFEST_MAX_BYTES` or `MANIFEST_MAX_ENTRIES`.
403
+ * Preflights that precede a streaming import set this so they never
404
+ * approve a bundle the import will refuse. The buffered import path
405
+ * (`commitImport`) has no such ceilings, so it stays off there to keep
406
+ * existing large backups restorable.
407
+ */
408
+ enforceStreamingLimits?: boolean;
409
+ }
410
+
384
411
  // Only manifest.json is structurally required. The DB and config live under
385
412
  // workspace/ (new format) or data/db/ + config/ (old format) — both are valid.
386
413
  const REQUIRED_ENTRIES = ["manifest.json"];
@@ -397,7 +424,10 @@ const MAX_DECOMPRESSED_SIZE = 2 * 1024 * 1024 * 1024;
397
424
  * 3. Manifest checksum (SHA-256 of canonicalized JSON with the `checksum` field set to empty string)
398
425
  * 4. Per-file content integrity (SHA-256 of each file vs manifest declaration)
399
426
  */
400
- export function validateVBundle(data: Uint8Array): VBundleValidationResult {
427
+ export function validateVBundle(
428
+ data: Uint8Array,
429
+ { enforceStreamingLimits = false }: ValidateVBundleOptions = {},
430
+ ): VBundleValidationResult {
401
431
  const errors: ValidationError[] = [];
402
432
 
403
433
  // Step 1: Decompress gzip with size cap to prevent zip-bomb DoS
@@ -455,6 +485,17 @@ export function validateVBundle(data: Uint8Array): VBundleValidationResult {
455
485
  }
456
486
 
457
487
  // Step 4: Parse and validate manifest schema
488
+ if (
489
+ enforceStreamingLimits &&
490
+ manifestEntry.data.length > MANIFEST_MAX_BYTES
491
+ ) {
492
+ errors.push({
493
+ code: "MANIFEST_TOO_LARGE",
494
+ message: `manifest.json exceeds ${MANIFEST_MAX_BYTES} byte limit (${manifestEntry.data.length} bytes)`,
495
+ path: "manifest.json",
496
+ });
497
+ return { is_valid: false, errors };
498
+ }
458
499
  let manifestRaw: unknown;
459
500
  try {
460
501
  manifestRaw = JSON.parse(new TextDecoder().decode(manifestEntry.data));
@@ -523,6 +564,18 @@ export function validateVBundle(data: Uint8Array): VBundleValidationResult {
523
564
  manifest = translateLegacyManifest(legacy);
524
565
  }
525
566
 
567
+ if (
568
+ enforceStreamingLimits &&
569
+ manifest.contents.length > MANIFEST_MAX_ENTRIES
570
+ ) {
571
+ errors.push({
572
+ code: "MANIFEST_TOO_MANY_ENTRIES",
573
+ message: `manifest.json declares more than ${MANIFEST_MAX_ENTRIES} entries (${manifest.contents.length})`,
574
+ path: "manifest.json",
575
+ });
576
+ return { is_valid: false, errors };
577
+ }
578
+
526
579
  // Step 6: Verify per-file content integrity
527
580
  const manifestFilePaths = new Set(manifest.contents.map((f) => f.path));
528
581
 
@@ -23,7 +23,10 @@ import type { QuestionEntry } from "../api/events/question-request.js";
23
23
  import { findConversationOrSubagent } from "../daemon/conversation-registry.js";
24
24
  import type { UserDecision } from "../permissions/types.js";
25
25
  import { getLogger } from "../util/logger.js";
26
- import { broadcastMessage } from "./assistant-event-hub.js";
26
+ import {
27
+ assistantEventHub,
28
+ broadcastMessage,
29
+ } from "./assistant-event-hub.js";
27
30
 
28
31
  const log = getLogger("pending-interactions");
29
32
 
@@ -110,6 +113,12 @@ export interface PendingInteraction {
110
113
  directResolve?: (decision: UserDecision) => void;
111
114
  /** When set, the host_bash request should be routed to this specific client. */
112
115
  targetClientId?: string;
116
+ /**
117
+ * Hub connection that was active for `targetClientId` at dispatch. Results
118
+ * must arrive while this connection is still subscribed so a reconnect
119
+ * cannot submit under the same client id.
120
+ */
121
+ targetConnectionId?: string;
113
122
  /**
114
123
  * Actor principal captured at registration. Targeted requests snapshot the
115
124
  * target client's actor so a brief SSE reconnect does not 403 a legitimate
@@ -167,7 +176,16 @@ export function register(
167
176
  requestId: string,
168
177
  interaction: PendingInteraction,
169
178
  ): void {
170
- pending.set(requestId, interaction);
179
+ const targetConnectionId =
180
+ interaction.targetConnectionId ??
181
+ (interaction.targetClientId
182
+ ? assistantEventHub.getClientById?.(interaction.targetClientId)
183
+ ?.connectionId
184
+ : undefined);
185
+ pending.set(requestId, {
186
+ ...interaction,
187
+ ...(targetConnectionId != null ? { targetConnectionId } : {}),
188
+ });
171
189
  }
172
190
 
173
191
  /**
@@ -275,7 +275,7 @@ describe("contacts read API relays from the gateway", () => {
275
275
  });
276
276
 
277
277
  test("get surfaces a clean gateway not-found as a 404", async () => {
278
- ipcResult = { ok: true };
278
+ ipcResult = null;
279
279
 
280
280
  await expect(handleGetContact("missing")).rejects.toMatchObject({
281
281
  statusCode: 404,
@@ -391,7 +391,8 @@ describe("filtered/native contact reads: daemon filters, gateway hydrates teleme
391
391
  expect(contact.interactionCount).toBe(11);
392
392
  expect(contact.lastInteraction).toBe(9200);
393
393
  expect(
394
- (contact as { autoApproveThreshold?: string | null }).autoApproveThreshold,
394
+ (contact as { autoApproveThreshold?: string | null })
395
+ .autoApproveThreshold,
395
396
  ).toBe("high");
396
397
  const channel = contact.channels[0] as Record<string, unknown>;
397
398
  expect(channel.interactionCount).toBe(11);
@@ -422,7 +423,8 @@ describe("filtered/native contact reads: daemon filters, gateway hydrates teleme
422
423
  expect(contact.interactionCount).toBe(0);
423
424
  expect(contact.lastInteraction).toBeNull();
424
425
  expect(
425
- (contact as { autoApproveThreshold?: string | null }).autoApproveThreshold,
426
+ (contact as { autoApproveThreshold?: string | null })
427
+ .autoApproveThreshold,
426
428
  ).toBeNull();
427
429
  const channel = contact.channels[0] as Record<string, unknown>;
428
430
  expect(channel.interactionCount).toBe(0);
@@ -71,6 +71,7 @@ interface ListResponse {
71
71
  nextOffset: number;
72
72
  hasMore: boolean;
73
73
  groups?: unknown[];
74
+ orderedBy: string;
74
75
  }
75
76
 
76
77
  function findHandler(routes: RouteDefinition[], operationId: string) {
@@ -1380,6 +1381,41 @@ describe("GET /v1/conversations, conversationType=all", () => {
1380
1381
  ]);
1381
1382
  });
1382
1383
 
1384
+ test("files a done row by when it was marked done when that is later than its last message", async () => {
1385
+ const recent = createConversation("recent-foreground");
1386
+ const doneLater = createConversation("old-chat-marked-done-later");
1387
+ const doneEarlier = createConversation("old-chat-done-before-a-reply");
1388
+ setLastMessageAt(recent.id, 2000);
1389
+ setLastMessageAt(doneLater.id, 1000);
1390
+ setLastMessageAt(doneEarlier.id, 1500);
1391
+ rawRun(
1392
+ "test:markDone",
1393
+ "UPDATE conversations SET archived_at = ? WHERE id = ?",
1394
+ 3000,
1395
+ doneLater.id,
1396
+ );
1397
+ rawRun(
1398
+ "test:markDone",
1399
+ "UPDATE conversations SET archived_at = ? WHERE id = ?",
1400
+ 500,
1401
+ doneEarlier.id,
1402
+ );
1403
+
1404
+ const result = (await invoke({
1405
+ conversationType: "all",
1406
+ archiveStatus: "all",
1407
+ })) as ListResponse;
1408
+
1409
+ expect(result.conversations.map((c) => c.title)).toEqual([
1410
+ "old-chat-marked-done-later",
1411
+ "recent-foreground",
1412
+ "old-chat-done-before-a-reply",
1413
+ ]);
1414
+ // A client paging done rows relies on this to know the order is not
1415
+ // message recency.
1416
+ expect(result.orderedBy).toBe("lastActivity");
1417
+ });
1418
+
1383
1419
  test("excludes legacy private rows and subagent runs", async () => {
1384
1420
  createConversation("foreground-1");
1385
1421
  const legacyPrivate = createConversation("legacy-private");
@@ -1,7 +1,8 @@
1
- import { utimesSync, writeFileSync } from "node:fs";
1
+ import { readFileSync, utimesSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
4
4
 
5
+ import { waitFor } from "../../../__tests__/helpers/wait-for.js";
5
6
  import {
6
7
  sampleConcepts as sharedSampleConcepts,
7
8
  sampleConfig,
@@ -50,11 +51,14 @@ mock.module("../../../persistence/embeddings/embedding-backend.js", () => ({
50
51
  },
51
52
  }));
52
53
 
54
+ import type { AssistantEventEnvelope } from "../../../api/index.js";
53
55
  import { BACKUP_PROFILE_KEYS } from "../../../config/default-profile-names.js";
54
56
  import {
55
57
  getConfig,
58
+ invalidateConfigCache,
56
59
  loadConfig,
57
60
  loadRawConfig,
61
+ setNestedValue,
58
62
  } from "../../../config/loader.js";
59
63
  import { AssistantConfigSchema } from "../../../config/schema.js";
60
64
  import { LLMConfigBase } from "../../../config/schemas/llm.js";
@@ -82,7 +86,8 @@ import {
82
86
  createConnection,
83
87
  getConnection,
84
88
  } from "../../../providers/inference/connections.js";
85
- import { ROUTES } from "../conversation-query-routes.js";
89
+ import { assistantEventHub } from "../../assistant-event-hub.js";
90
+ import { commitConfigWrite, ROUTES } from "../conversation-query-routes.js";
86
91
 
87
92
  // Local subset: this test only exercises a single concept row.
88
93
  const sampleConcepts: MemoryV2ConceptRowRecord[] = sharedSampleConcepts.slice(
@@ -2047,3 +2052,371 @@ describe("config writes to a per-agent acp entry", () => {
2047
2052
  expect(loadConfig().acp.agents.claude?.model).toBe("sonnet");
2048
2053
  });
2049
2054
  });
2055
+
2056
+ describe("persisted chat settings", () => {
2057
+ const getRoute = ROUTES.find((r) => r.operationId === "config_get")!;
2058
+ const patchRoute = ROUTES.find((r) => r.operationId === "config_patch")!;
2059
+ const setRoute = ROUTES.find((r) => r.operationId === "config_set")!;
2060
+
2061
+ beforeEach(() => {
2062
+ initializeProvidersCalls = 0;
2063
+ clearEmbeddingBackendCacheCalls = 0;
2064
+ rawConfigFixture = {
2065
+ conversations: {
2066
+ skipAutoRetitling: true,
2067
+ autoArchive: { enabled: true, afterDays: 14, futureOption: "keep" },
2068
+ },
2069
+ notifications: { newMessageEnabled: false, futureOption: "keep" },
2070
+ maxStepsPerSession: 75,
2071
+ };
2072
+ seedRawConfig();
2073
+ invalidateConfigCache();
2074
+ });
2075
+
2076
+ const writers = ["PATCH", "SET", "canonical"] as const;
2077
+ async function writeSetting(
2078
+ writer: (typeof writers)[number],
2079
+ path: string,
2080
+ value: unknown,
2081
+ ): Promise<unknown> {
2082
+ if (writer === "SET") {
2083
+ return setRoute.handler({ body: { path, value } });
2084
+ }
2085
+ const raw = writer === "canonical" ? loadRawConfig() : {};
2086
+ setNestedValue(raw, path, value);
2087
+ return writer === "PATCH"
2088
+ ? patchRoute.handler({ body: raw })
2089
+ : commitConfigWrite(raw, "test");
2090
+ }
2091
+
2092
+ for (const writer of writers) {
2093
+ test.each([
2094
+ { conversations: false },
2095
+ { conversations: [] },
2096
+ { conversations: null },
2097
+ { conversations: { autoArchive: "legacy" } },
2098
+ { conversations: { autoArchive: [] } },
2099
+ { conversations: { autoArchive: null } },
2100
+ { conversations: { autoArchive: { enabled: "true", afterDays: 2 } } },
2101
+ { conversations: { autoArchive: { enabled: null, afterDays: null } } },
2102
+ { notifications: "legacy" },
2103
+ { notifications: [] },
2104
+ { notifications: null },
2105
+ { notifications: { newMessageEnabled: "false" } },
2106
+ { notifications: { newMessageEnabled: null } },
2107
+ ])(
2108
+ `${writer} unrelated writes preserve untouched legacy values: %j`,
2109
+ async (legacy) => {
2110
+ rawConfigFixture = { ...legacy, maxStepsPerSession: 75 };
2111
+ seedRawConfig();
2112
+ invalidateConfigCache();
2113
+
2114
+ await writeSetting(writer, "maxStepsPerSession", 100);
2115
+
2116
+ expect(loadRawConfig()).toEqual({
2117
+ ...rawConfigFixture,
2118
+ maxStepsPerSession: 100,
2119
+ });
2120
+ expect(initializeProvidersCalls).toBe(1);
2121
+ expect(clearEmbeddingBackendCacheCalls).toBe(1);
2122
+ },
2123
+ );
2124
+
2125
+ test(`${writer} can repair one leaf without changing other legacy values`, async () => {
2126
+ rawConfigFixture = {
2127
+ conversations: { autoArchive: { enabled: "true", afterDays: 2 } },
2128
+ notifications: null,
2129
+ };
2130
+ seedRawConfig();
2131
+ invalidateConfigCache();
2132
+
2133
+ await writeSetting(writer, "conversations.autoArchive.enabled", true);
2134
+
2135
+ expect(loadRawConfig()).toEqual({
2136
+ conversations: { autoArchive: { enabled: true, afterDays: 2 } },
2137
+ notifications: null,
2138
+ });
2139
+ });
2140
+
2141
+ test(`${writer} rejects an invalid leaf change beside an unchanged invalid sibling`, async () => {
2142
+ rawConfigFixture = {
2143
+ conversations: { autoArchive: { enabled: "true", afterDays: 2 } },
2144
+ };
2145
+ seedRawConfig();
2146
+ invalidateConfigCache();
2147
+ const configPath = join(process.env.VELLUM_WORKSPACE_DIR!, "config.json");
2148
+ const originalBytes = readFileSync(configPath, "utf-8");
2149
+
2150
+ await expect(
2151
+ writeSetting(writer, "conversations.autoArchive.afterDays", 3),
2152
+ ).rejects.toMatchObject({ statusCode: 400 });
2153
+
2154
+ expect(readFileSync(configPath, "utf-8")).toBe(originalBytes);
2155
+ expect(initializeProvidersCalls).toBe(0);
2156
+ });
2157
+
2158
+ test.each([
2159
+ ["conversations", []],
2160
+ ["conversations.autoArchive", { enabled: "true" }],
2161
+ ["conversations.autoArchive", { afterDays: 2 }],
2162
+ ["notifications.newMessageEnabled", "true"],
2163
+ ["notifications.newMessageEnabled", 1],
2164
+ ])(
2165
+ `${writer} rejects changed invalid settings at %s over legacy config`,
2166
+ async (path, value) => {
2167
+ rawConfigFixture = {
2168
+ conversations: false,
2169
+ notifications: { newMessageEnabled: "false" },
2170
+ maxStepsPerSession: 75,
2171
+ };
2172
+ seedRawConfig();
2173
+ invalidateConfigCache();
2174
+ const configPath = join(
2175
+ process.env.VELLUM_WORKSPACE_DIR!,
2176
+ "config.json",
2177
+ );
2178
+ const originalBytes = readFileSync(configPath, "utf-8");
2179
+
2180
+ await expect(
2181
+ writeSetting(writer, path as string, value),
2182
+ ).rejects.toMatchObject({
2183
+ statusCode: 400,
2184
+ });
2185
+
2186
+ expect(readFileSync(configPath, "utf-8")).toBe(originalBytes);
2187
+ expect(initializeProvidersCalls).toBe(0);
2188
+ expect(clearEmbeddingBackendCacheCalls).toBe(0);
2189
+ },
2190
+ );
2191
+ }
2192
+
2193
+ test("PATCH resets only the explicitly nulled legacy leaf", async () => {
2194
+ rawConfigFixture = {
2195
+ conversations: { autoArchive: { enabled: null, afterDays: null } },
2196
+ notifications: { newMessageEnabled: null },
2197
+ };
2198
+ seedRawConfig();
2199
+ invalidateConfigCache();
2200
+
2201
+ await patchRoute.handler({
2202
+ body: { conversations: { autoArchive: { enabled: null } } },
2203
+ });
2204
+
2205
+ expect(loadRawConfig()).toEqual({
2206
+ conversations: { autoArchive: { afterDays: null } },
2207
+ notifications: { newMessageEnabled: null },
2208
+ });
2209
+ });
2210
+
2211
+ test("sparse GET exposes effective defaults without materializing unrelated fields", async () => {
2212
+ rawConfigFixture = {};
2213
+ seedRawConfig();
2214
+ invalidateConfigCache();
2215
+ const result = await getRoute.handler({});
2216
+ expect(result).toMatchObject({
2217
+ conversations: { autoArchive: { enabled: false, afterDays: 7 } },
2218
+ notifications: { newMessageEnabled: true },
2219
+ });
2220
+ expect(result).not.toHaveProperty("conversations.skipAutoRetitling");
2221
+ expect(loadRawConfig()).not.toHaveProperty("conversations");
2222
+ expect(loadRawConfig()).not.toHaveProperty("notifications");
2223
+ });
2224
+
2225
+ test("partial PATCH persists, reloads, and publishes config invalidation", async () => {
2226
+ const received: AssistantEventEnvelope[] = [];
2227
+ const subscription = assistantEventHub.subscribe({
2228
+ type: "process",
2229
+ callback: (event) => {
2230
+ received.push(event);
2231
+ },
2232
+ });
2233
+ try {
2234
+ const result = await patchRoute.handler({
2235
+ body: { conversations: { autoArchive: { afterDays: 30 } } },
2236
+ });
2237
+ expect(result).toMatchObject({
2238
+ conversations: {
2239
+ skipAutoRetitling: true,
2240
+ autoArchive: { enabled: true, afterDays: 30, futureOption: "keep" },
2241
+ },
2242
+ notifications: { newMessageEnabled: false, futureOption: "keep" },
2243
+ maxStepsPerSession: 75,
2244
+ });
2245
+ expect(loadRawConfig()).toEqual({
2246
+ ...rawConfigFixture,
2247
+ conversations: {
2248
+ skipAutoRetitling: true,
2249
+ autoArchive: { enabled: true, afterDays: 30, futureOption: "keep" },
2250
+ },
2251
+ });
2252
+ invalidateConfigCache();
2253
+ expect(loadConfig().conversations.autoArchive).toEqual({
2254
+ enabled: true,
2255
+ afterDays: 30,
2256
+ });
2257
+ expect(loadConfig().notifications.newMessageEnabled).toBe(false);
2258
+ expect(await getRoute.handler({})).toEqual(result);
2259
+ expect(initializeProvidersCalls).toBe(1);
2260
+ expect(clearEmbeddingBackendCacheCalls).toBe(1);
2261
+ await waitFor(() =>
2262
+ received.some((event) => event.message.type === "sync_changed"),
2263
+ );
2264
+ expect(received.map((event) => event.message)).toContainEqual({
2265
+ type: "sync_changed",
2266
+ tags: ["assistant:self:config"],
2267
+ });
2268
+ } finally {
2269
+ subscription.dispose();
2270
+ }
2271
+ });
2272
+
2273
+ test("PATCH null leaves restore defaults and preserve sibling values", async () => {
2274
+ const result = await patchRoute.handler({
2275
+ body: {
2276
+ conversations: { autoArchive: { enabled: null, afterDays: null } },
2277
+ notifications: { newMessageEnabled: null },
2278
+ },
2279
+ });
2280
+ expect(result).toMatchObject({
2281
+ conversations: {
2282
+ skipAutoRetitling: true,
2283
+ autoArchive: { enabled: false, afterDays: 7, futureOption: "keep" },
2284
+ },
2285
+ notifications: { newMessageEnabled: true, futureOption: "keep" },
2286
+ });
2287
+ expect(loadRawConfig()).toMatchObject({
2288
+ conversations: { autoArchive: { futureOption: "keep" } },
2289
+ notifications: { futureOption: "keep" },
2290
+ });
2291
+ expect(loadRawConfig()).not.toHaveProperty(
2292
+ "conversations.autoArchive.enabled",
2293
+ );
2294
+ expect(loadRawConfig()).not.toHaveProperty(
2295
+ "notifications.newMessageEnabled",
2296
+ );
2297
+ });
2298
+
2299
+ test.each([
2300
+ { conversations: { autoArchive: null }, notifications: null },
2301
+ { conversations: null, notifications: null },
2302
+ ])("PATCH null subtrees restore defaults: %j", async (body) => {
2303
+ const result = await patchRoute.handler({ body });
2304
+ expect(result).toMatchObject({
2305
+ conversations: { autoArchive: { enabled: false, afterDays: 7 } },
2306
+ notifications: { newMessageEnabled: true },
2307
+ });
2308
+ expect(loadRawConfig()).not.toHaveProperty("conversations.autoArchive");
2309
+ expect(loadRawConfig()).not.toHaveProperty("notifications");
2310
+ });
2311
+
2312
+ test.each([
2313
+ { conversations: false },
2314
+ { conversations: { autoArchive: [] } },
2315
+ { conversations: { autoArchive: { enabled: "true" } } },
2316
+ { conversations: { autoArchive: { afterDays: 5 } } },
2317
+ { notifications: "off" },
2318
+ { notifications: { newMessageEnabled: 0 } },
2319
+ ])(
2320
+ "invalid PATCH leaves saved config and runtime unchanged: %j",
2321
+ async (body) => {
2322
+ const original = loadRawConfig();
2323
+ await expect(patchRoute.handler({ body })).rejects.toMatchObject({
2324
+ statusCode: 400,
2325
+ });
2326
+ expect(loadRawConfig()).toEqual(original);
2327
+ expect(initializeProvidersCalls).toBe(0);
2328
+ expect(clearEmbeddingBackendCacheCalls).toBe(0);
2329
+ },
2330
+ );
2331
+
2332
+ test.each([false, "legacy", [], null])(
2333
+ "PATCH null resets a malformed stored autoArchive subtree: %j",
2334
+ async (autoArchive) => {
2335
+ rawConfigFixture = {
2336
+ conversations: { skipAutoRetitling: true, autoArchive },
2337
+ notifications: { newMessageEnabled: false },
2338
+ maxStepsPerSession: 75,
2339
+ };
2340
+ seedRawConfig();
2341
+ invalidateConfigCache();
2342
+
2343
+ const result = await patchRoute.handler({
2344
+ body: { conversations: { autoArchive: null } },
2345
+ });
2346
+
2347
+ expect(result).toMatchObject({
2348
+ conversations: {
2349
+ skipAutoRetitling: true,
2350
+ autoArchive: { enabled: false, afterDays: 7 },
2351
+ },
2352
+ notifications: { newMessageEnabled: false },
2353
+ });
2354
+ expect(loadRawConfig()).toEqual({
2355
+ conversations: { skipAutoRetitling: true },
2356
+ notifications: { newMessageEnabled: false },
2357
+ maxStepsPerSession: 75,
2358
+ });
2359
+ },
2360
+ );
2361
+
2362
+ test.each([false, "legacy", [], null])(
2363
+ "PATCH null resets malformed stored settings sections: %j",
2364
+ async (value) => {
2365
+ rawConfigFixture = {
2366
+ conversations: value,
2367
+ notifications: value,
2368
+ maxStepsPerSession: 75,
2369
+ };
2370
+ seedRawConfig();
2371
+ invalidateConfigCache();
2372
+
2373
+ const result = await patchRoute.handler({
2374
+ body: { conversations: null, notifications: null },
2375
+ });
2376
+
2377
+ expect(result).toMatchObject({
2378
+ conversations: { autoArchive: { enabled: false, afterDays: 7 } },
2379
+ notifications: { newMessageEnabled: true },
2380
+ });
2381
+ expect(loadRawConfig()).toEqual({ maxStepsPerSession: 75 });
2382
+ },
2383
+ );
2384
+
2385
+ test("SET persists valid preferences through the same writer", async () => {
2386
+ await setRoute.handler({
2387
+ body: { path: "notifications.newMessageEnabled", value: true },
2388
+ });
2389
+ expect(loadConfig().notifications.newMessageEnabled).toBe(true);
2390
+ expect(loadRawConfig()).toHaveProperty(
2391
+ "notifications.futureOption",
2392
+ "keep",
2393
+ );
2394
+ });
2395
+
2396
+ test.each([
2397
+ ["conversations.autoArchive.afterDays", 2],
2398
+ ["conversations.autoArchive.enabled", null],
2399
+ ["conversations.autoArchive", []],
2400
+ ["notifications.newMessageEnabled", "false"],
2401
+ ["notifications", null],
2402
+ ])("invalid SET %s is rejected before saving", async (path, value) => {
2403
+ const original = loadRawConfig();
2404
+ await expect(
2405
+ setRoute.handler({ body: { path, value } }),
2406
+ ).rejects.toMatchObject({ statusCode: 400 });
2407
+ expect(loadRawConfig()).toEqual(original);
2408
+ expect(initializeProvidersCalls).toBe(0);
2409
+ });
2410
+
2411
+ test("canonical config writes reject invalid settings", async () => {
2412
+ const original = loadRawConfig();
2413
+ await expect(
2414
+ commitConfigWrite(
2415
+ { ...original, notifications: { newMessageEnabled: null } },
2416
+ "test",
2417
+ ),
2418
+ ).rejects.toMatchObject({ statusCode: 400 });
2419
+ expect(loadRawConfig()).toEqual(original);
2420
+ expect(initializeProvidersCalls).toBe(0);
2421
+ });
2422
+ });
@@ -252,7 +252,7 @@ describe("inference_send profile usability", () => {
252
252
  const err = await rejection({ ...hermes, status: "disabled" });
253
253
  expect(err).toBeInstanceOf(BadRequestError);
254
254
  expect(err.message).toContain("disabled");
255
- expect(err.message).toContain("deepseek-v4-flash");
255
+ expect(err.message).toContain("deepseek-v4p1-flash");
256
256
  });
257
257
 
258
258
  test("rejects a profile that lost its provider", async () => {
@@ -106,6 +106,18 @@ describe("path traversal", () => {
106
106
  );
107
107
  expect(res.status).toBe(400);
108
108
  });
109
+
110
+ test("rejects backslashes in the route path", async () => {
111
+ // Some URL normalizers treat a backslash as a separator, so a
112
+ // backslash-carrying routePath is refused outright regardless of dots.
113
+ const dispatcher = makeDispatcher();
114
+ for (const routePath of ["..\\config", "foo\\bar", "x\\..\\config"]) {
115
+ const res = await dispatcher.dispatch(routePath, makeRequest("GET"));
116
+ expect(res.status).toBe(400);
117
+ const body = await readErrorBody(res);
118
+ expect(body.error.message).toContain("Path traversal");
119
+ }
120
+ });
109
121
  });
110
122
 
111
123
  // ---------------------------------------------------------------------------
@@ -393,8 +393,8 @@ export async function handleListContacts(queryParams: Record<string, string>) {
393
393
  export async function handleGetContact(contactId: string) {
394
394
  try {
395
395
  const result = await ipcCallPersistent("contacts_get_rich", { contactId });
396
- // The gateway returns null (no `contact`) on a clean not-found.
397
- if (!result || (result as { contact?: unknown }).contact === undefined) {
396
+ // The gateway returns null on a clean not-found.
397
+ if (result == null) {
398
398
  throw new NotFoundError(`Contact "${contactId}" not found`);
399
399
  }
400
400
  const { contact, assistantMetadata } =