@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
@@ -0,0 +1,192 @@
1
+ import { beforeAll, expect, mock, test } from "bun:test";
2
+
3
+ import type { NotificationSignal } from "../signal.js";
4
+ import type {
5
+ ChannelAdapter,
6
+ ChannelDeliveryPayload,
7
+ NotificationChannel,
8
+ NotificationDecision,
9
+ } from "../types.js";
10
+
11
+ mock.module("../../config/assistant-initiated-threads-gate.js", () => ({
12
+ isAssistantInitiatedThreadsEnabled: () => true,
13
+ }));
14
+ const guardianReader =
15
+ await import("../../contacts/guardian-delivery-reader.js");
16
+ mock.module("../../contacts/guardian-delivery-reader.js", () => ({
17
+ ...guardianReader,
18
+ getGuardianDelivery: async () => null,
19
+ }));
20
+ mock.module("../destination-resolver.js", () => ({
21
+ resolveDestinations: (channels: NotificationChannel[]) =>
22
+ new Map(channels.map((channel) => [channel, { channel }])),
23
+ }));
24
+
25
+ const { createConversation, getConversation, getMessageById, getMessages } =
26
+ await import("../../persistence/conversation-crud.js");
27
+ const { initializeDb } = await import("../../persistence/db-init.js");
28
+ const { resolveAssistantInitiatedThread } =
29
+ await import("../assistant-initiated-thread.js");
30
+ const { NotificationBroadcaster } = await import("../broadcaster.js");
31
+ const { createDecision } = await import("../decisions-store.js");
32
+ const { findDeliveryByDecisionAndChannel } =
33
+ await import("../deliveries-store.js");
34
+ const { createEvent } = await import("../events-store.js");
35
+
36
+ beforeAll(async () => {
37
+ await initializeDb();
38
+ });
39
+
40
+ function persistedShare() {
41
+ const producer = createConversation({ conversationType: "background" });
42
+ const signal: NotificationSignal = {
43
+ signalId: crypto.randomUUID(),
44
+ createdAt: Date.now(),
45
+ sourceChannel: "assistant_tool",
46
+ sourceContextId: producer.id,
47
+ sourceEventName: "assistant.share",
48
+ contextPayload: {},
49
+ attentionHints: {
50
+ requiresAction: false,
51
+ urgency: "low",
52
+ isAsyncBackground: true,
53
+ visibleInSourceNow: false,
54
+ },
55
+ };
56
+ createEvent({
57
+ id: signal.signalId,
58
+ sourceEventName: signal.sourceEventName,
59
+ sourceChannel: signal.sourceChannel,
60
+ sourceContextId: signal.sourceContextId,
61
+ attentionHints: signal.attentionHints,
62
+ payload: signal.contextPayload,
63
+ });
64
+ const decision: NotificationDecision & { persistedDecisionId: string } = {
65
+ persistedDecisionId: crypto.randomUUID(),
66
+ shouldNotify: true,
67
+ selectedChannels: ["vellum", "platform"],
68
+ reasoningSummary: "Share a useful update",
69
+ renderedCopy: {
70
+ vellum: { title: "A useful update", body: "The report is ready." },
71
+ },
72
+ dedupeKey: signal.signalId,
73
+ confidence: 1,
74
+ fallbackUsed: false,
75
+ };
76
+ createDecision({
77
+ ...decision,
78
+ id: decision.persistedDecisionId,
79
+ notificationEventId: signal.signalId,
80
+ });
81
+ return {
82
+ signal,
83
+ decision,
84
+ options: {
85
+ assistantInitiatedThread: {
86
+ resolution: resolveAssistantInitiatedThread(signal),
87
+ platformAdded: true,
88
+ },
89
+ },
90
+ };
91
+ }
92
+
93
+ function recordingAdapter(channel: "vellum" | "platform") {
94
+ const sent: ChannelDeliveryPayload[] = [];
95
+ const readableAtSend: boolean[] = [];
96
+ const adapter: ChannelAdapter = {
97
+ channel,
98
+ async send(payload) {
99
+ const conversationId = payload.deepLinkTarget?.conversationId;
100
+ const messageId = payload.deepLinkTarget?.messageId;
101
+ readableAtSend.push(
102
+ typeof conversationId === "string" &&
103
+ typeof messageId === "string" &&
104
+ getConversation(conversationId)?.source === "assistant_initiated" &&
105
+ getMessageById(messageId, conversationId) != null,
106
+ );
107
+ sent.push(payload);
108
+ return {
109
+ success: true,
110
+ ...(channel === "platform"
111
+ ? { remotePushAccepted: true, remotePushPlatforms: ["ios" as const] }
112
+ : {}),
113
+ };
114
+ },
115
+ };
116
+ return { adapter, sent, readableAtSend };
117
+ }
118
+
119
+ test("new From me alerts address the saved chat and seed before either adapter sends", async () => {
120
+ const { signal, decision, options } = persistedShare();
121
+ const local = recordingAdapter("vellum");
122
+ const push = recordingAdapter("platform");
123
+ const broadcaster = new NotificationBroadcaster([
124
+ local.adapter,
125
+ push.adapter,
126
+ ]);
127
+ const created: Array<{
128
+ source?: string;
129
+ silent: boolean;
130
+ seedCount: number;
131
+ }> = [];
132
+ broadcaster.setOnConversationCreated((info) => {
133
+ created.push({
134
+ source: info.source,
135
+ silent: info.silent,
136
+ seedCount: getMessages(info.conversationId).length,
137
+ });
138
+ });
139
+
140
+ await broadcaster.broadcastDecision(signal, decision, options);
141
+
142
+ expect(created).toEqual([
143
+ { source: "assistant_initiated", silent: false, seedCount: 1 },
144
+ ]);
145
+ expect(local.readableAtSend).toEqual([true]);
146
+ expect(push.readableAtSend).toEqual([true]);
147
+ expect(local.sent[0]).toMatchObject({
148
+ silent: false,
149
+ urgency: "low",
150
+ correlationId: signal.signalId,
151
+ remotePushDispatched: true,
152
+ remotePushPlatforms: ["ios"],
153
+ });
154
+ expect(push.sent[0].deepLinkTarget).toEqual(local.sent[0].deepLinkTarget);
155
+ const conversationId = local.sent[0].deepLinkTarget?.conversationId as string;
156
+ expect(conversationId).not.toBe(signal.sourceContextId);
157
+ expect(getMessages(conversationId)).toHaveLength(1);
158
+ expect(getMessages(signal.sourceContextId)).toHaveLength(0);
159
+ });
160
+
161
+ test("a missing platform delivery reuses the saved initial-creation audit without reseeding", async () => {
162
+ const { signal, decision, options } = persistedShare();
163
+ const local = recordingAdapter("vellum");
164
+ await new NotificationBroadcaster([local.adapter]).broadcastDecision(
165
+ signal,
166
+ decision,
167
+ options,
168
+ );
169
+ const initial = findDeliveryByDecisionAndChannel(
170
+ decision.persistedDecisionId,
171
+ "vellum",
172
+ );
173
+ expect(initial).toMatchObject({
174
+ conversationStrategy: "start_new_conversation",
175
+ conversationAction: "start_new",
176
+ status: "sent",
177
+ });
178
+
179
+ const push = recordingAdapter("platform");
180
+ const retry = new NotificationBroadcaster([local.adapter, push.adapter]);
181
+ await retry.broadcastDecision(signal, decision, options);
182
+ await retry.broadcastDecision(signal, decision, options);
183
+
184
+ expect(local.sent).toHaveLength(1);
185
+ expect(push.sent).toHaveLength(1);
186
+ expect(push.readableAtSend).toEqual([true]);
187
+ expect(push.sent[0].deepLinkTarget).toMatchObject({
188
+ conversationId: initial?.conversationId,
189
+ messageId: initial?.messageId,
190
+ });
191
+ expect(getMessages(initial!.conversationId!)).toHaveLength(1);
192
+ });
@@ -20,6 +20,10 @@ import {
20
20
  isRetryableStatus,
21
21
  sleep,
22
22
  } from "../../util/retry.js";
23
+ import {
24
+ areChatReplyAlertsDisabled,
25
+ CHAT_REPLY_ALERTS_DISABLED,
26
+ } from "../chat-reply-policy.js";
23
27
  import {
24
28
  isCompletionNotification,
25
29
  isCompletionRecipientUnavailable,
@@ -162,6 +166,16 @@ export class PlatformPushAdapter implements ChannelAdapter {
162
166
  platformsReported ? [...accumulatedPlatforms] : undefined;
163
167
 
164
168
  for (let attempt = 0; attempt <= RETRY_DELAYS_MS.length; attempt++) {
169
+ if (areChatReplyAlertsDisabled(payload.sourceEventName)) {
170
+ const remotePushAccepted = accumulatedPlatforms.size > 0;
171
+ return {
172
+ success: remotePushAccepted,
173
+ skipped: !remotePushAccepted,
174
+ error: CHAT_REPLY_ALERTS_DISABLED,
175
+ remotePushAccepted,
176
+ remotePushPlatforms: remotePushPlatforms(),
177
+ };
178
+ }
165
179
  let response: Response;
166
180
  try {
167
181
  response = await client.fetch(path, {
@@ -0,0 +1,101 @@
1
+ import { isAssistantInitiatedThreadsEnabled } from "../config/assistant-initiated-threads-gate.js";
2
+ import {
3
+ getConversation,
4
+ getDisplayMetaForConversations,
5
+ getMessageById,
6
+ } from "../persistence/conversation-crud.js";
7
+ import {
8
+ ASSISTANT_INITIATED_SOURCE,
9
+ UNGROUPED_GROUP_ID,
10
+ } from "../persistence/conversation-types.js";
11
+ import { getLogger } from "../util/logger.js";
12
+ import type { NotificationSignal } from "./signal.js";
13
+
14
+ const log = getLogger("assistant-initiated-thread");
15
+
16
+ export interface AssistantInitiatedThreadResolution {
17
+ /** Eligible for automatic promotion; creation and sidebar membership are not guaranteed. */
18
+ isCandidate: boolean;
19
+ /** Prepared for vellum pairing only. Other channels retain the producer's signal. */
20
+ vellumSignal: NotificationSignal;
21
+ }
22
+
23
+ /** Background shares need a visible thread because their producer is hidden from the sidebar. */
24
+ export function resolveAssistantInitiatedThread(
25
+ signal: NotificationSignal,
26
+ ): AssistantInitiatedThreadResolution {
27
+ if (
28
+ signal.sourceEventName !== "assistant.share" ||
29
+ signal.requiresConversation === true ||
30
+ signal.conversationMetadata?.source !== undefined ||
31
+ !isAssistantInitiatedThreadsEnabled()
32
+ ) {
33
+ return { isCandidate: false, vellumSignal: signal };
34
+ }
35
+
36
+ try {
37
+ const producing = getConversation(signal.sourceContextId);
38
+ if (
39
+ producing &&
40
+ producing.conversationType !== "background" &&
41
+ producing.conversationType !== "scheduled"
42
+ ) {
43
+ return { isCandidate: false, vellumSignal: signal };
44
+ }
45
+ } catch (err) {
46
+ log.warn(
47
+ { err, sourceContextId: signal.sourceContextId },
48
+ "Unable to resolve the assistant-initiated thread candidate",
49
+ );
50
+ return { isCandidate: false, vellumSignal: signal };
51
+ }
52
+
53
+ return {
54
+ isCandidate: true,
55
+ vellumSignal: {
56
+ ...signal,
57
+ requiresConversation: true,
58
+ conversationMetadata: {
59
+ ...signal.conversationMetadata,
60
+ source: ASSISTANT_INITIATED_SOURCE,
61
+ },
62
+ },
63
+ };
64
+ }
65
+
66
+ /** A new thread can alert only after its visible destination and seed are durable. */
67
+ export function isPersistedAssistantInitiatedThread(
68
+ conversationId: string | null,
69
+ messageId: string | null,
70
+ ): boolean {
71
+ if (!conversationId || !messageId) {
72
+ return false;
73
+ }
74
+ try {
75
+ const conversation = getConversation(conversationId);
76
+ if (
77
+ !conversation ||
78
+ conversation.source !== ASSISTANT_INITIATED_SOURCE ||
79
+ conversation.conversationType !== "standard" ||
80
+ conversation.archivedAt !== null
81
+ ) {
82
+ return false;
83
+ }
84
+ const placement = getDisplayMetaForConversations([conversationId]).get(
85
+ conversationId,
86
+ );
87
+ return (
88
+ placement !== undefined &&
89
+ !placement.isPinned &&
90
+ (placement.groupId === null ||
91
+ placement.groupId === UNGROUPED_GROUP_ID) &&
92
+ getMessageById(messageId, conversationId) !== null
93
+ );
94
+ } catch (err) {
95
+ log.warn(
96
+ { err, conversationId },
97
+ "Unable to verify the notification thread and seed",
98
+ );
99
+ return false;
100
+ }
101
+ }
@@ -23,11 +23,21 @@ import {
23
23
  } from "./access-request-copy.js";
24
24
  import { isGuardianSensitiveEvent } from "./adapters/macos.js";
25
25
  import { resolveMessageText } from "./adapters/shared.js";
26
+ import {
27
+ type AssistantInitiatedThreadResolution,
28
+ isPersistedAssistantInitiatedThread,
29
+ resolveAssistantInitiatedThread,
30
+ } from "./assistant-initiated-thread.js";
31
+ import {
32
+ areChatReplyAlertsDisabled,
33
+ CHAT_REPLY_ALERTS_DISABLED,
34
+ } from "./chat-reply-policy.js";
26
35
  import {
27
36
  isCompletionNotification,
28
37
  isCompletionRecipientUnavailable,
29
38
  isLocalNotificationSilent,
30
39
  notificationConversationId,
40
+ type NotificationPresentationContext,
31
41
  resolveCompletionRecipient,
32
42
  } from "./completion-policy.js";
33
43
  import {
@@ -247,10 +257,7 @@ export interface ConversationCreatedInfo {
247
257
  groupId?: string;
248
258
  /** Semantic source from the signal producer (e.g. "schedule", "reminder"). */
249
259
  source?: string;
250
- /**
251
- * Mirrors the vellum adapter's `silent` flag (true for low- and
252
- * medium-urgency signals).
253
- */
260
+ /** Mirrors the vellum adapter's resolved local presentation policy. */
254
261
  silent: boolean;
255
262
  }
256
263
  /**
@@ -263,6 +270,10 @@ export type OnConversationCreatedFn = (
263
270
  ) => void | Promise<void>;
264
271
  export interface BroadcastDecisionOptions {
265
272
  onConversationCreated?: OnConversationCreatedFn;
273
+ assistantInitiatedThread?: {
274
+ resolution: AssistantInitiatedThreadResolution;
275
+ platformAdded: boolean;
276
+ };
266
277
  /** Deadline override for tests; defaults to PLATFORM_OUTCOME_DEADLINE_MS. */
267
278
  platformOutcomeDeadlineMs?: number;
268
279
  /**
@@ -293,6 +304,7 @@ interface PendingChannelDispatch {
293
304
  destinationLabel: string;
294
305
  pairing: PairingResult;
295
306
  hasPersistedDecision: boolean;
307
+ presentation: NotificationPresentationContext;
296
308
  }
297
309
 
298
310
  /**
@@ -358,10 +370,15 @@ export class NotificationBroadcaster {
358
370
  decision.selectedChannels,
359
371
  guardians,
360
372
  );
361
- const silent = isLocalNotificationSilent({
362
- ...signal,
363
- urgency: signal.attentionHints.urgency,
364
- });
373
+ const assistantInitiatedThread =
374
+ options?.assistantInitiatedThread?.resolution ??
375
+ resolveAssistantInitiatedThread(signal);
376
+ const presentation: NotificationPresentationContext = {};
377
+ const resolveSilent = () =>
378
+ isLocalNotificationSilent(
379
+ { ...signal, urgency: signal.attentionHints.urgency },
380
+ presentation,
381
+ );
365
382
 
366
383
  // Ensure vellum is processed first so the notification_conversation_created
367
384
  // event fires immediately, before slower channel sends (e.g. Telegram 30s
@@ -438,6 +455,21 @@ export class NotificationBroadcaster {
438
455
  await flushDeferredVellumSend();
439
456
  }
440
457
 
458
+ if (
459
+ channel === "platform" &&
460
+ options?.assistantInitiatedThread?.platformAdded &&
461
+ (!presentation.assistantInitiatedThreadCreated ||
462
+ signal.contextPayload.quiet === true)
463
+ ) {
464
+ results.push({
465
+ channel,
466
+ destination: destinations.get(channel)?.endpoint ?? channel,
467
+ status: "skipped",
468
+ errorMessage: "No newly persisted From me conversation for push",
469
+ });
470
+ continue;
471
+ }
472
+
441
473
  const adapter = this.adapters.get(channel);
442
474
  if (!adapter) {
443
475
  log.warn(
@@ -567,6 +599,17 @@ export class NotificationBroadcaster {
567
599
  conversationId: existingDelivery.conversationId,
568
600
  messageId: existingDelivery.messageId,
569
601
  };
602
+ presentation.assistantInitiatedThreadCreated =
603
+ assistantInitiatedThread.isCandidate &&
604
+ existingDelivery.conversationStrategy ===
605
+ "start_new_conversation" &&
606
+ (existingDelivery.conversationAction === "start_new" ||
607
+ (existingDelivery.conversationAction === "reuse_existing" &&
608
+ existingDelivery.conversationFallbackUsed === 1)) &&
609
+ isPersistedAssistantInitiatedThread(
610
+ existingDelivery.conversationId,
611
+ existingDelivery.messageId,
612
+ );
570
613
  }
571
614
  log.info(
572
615
  {
@@ -596,7 +639,12 @@ export class NotificationBroadcaster {
596
639
  signal,
597
640
  channel,
598
641
  copy,
599
- { conversationAction, bindingContext: destination.bindingContext },
642
+ {
643
+ conversationAction,
644
+ bindingContext: destination.bindingContext,
645
+ assistantInitiatedThread:
646
+ channel === "vellum" ? assistantInitiatedThread : undefined,
647
+ },
600
648
  );
601
649
 
602
650
  if (channel === "vellum" && pairing.conversationId) {
@@ -604,6 +652,14 @@ export class NotificationBroadcaster {
604
652
  conversationId: pairing.conversationId,
605
653
  messageId: pairing.messageId,
606
654
  };
655
+ presentation.assistantInitiatedThreadCreated =
656
+ assistantInitiatedThread.isCandidate &&
657
+ pairing.createdNewConversation &&
658
+ pairing.strategy === "start_new_conversation" &&
659
+ isPersistedAssistantInitiatedThread(
660
+ pairing.conversationId,
661
+ pairing.messageId,
662
+ );
607
663
  }
608
664
 
609
665
  // For the vellum and platform channels, merge the conversationId into
@@ -660,9 +716,13 @@ export class NotificationBroadcaster {
660
716
  title: conversationTitle,
661
717
  sourceEventName: signal.sourceEventName,
662
718
  targetGuardianPrincipalId,
663
- groupId: signal.conversationMetadata?.groupId,
664
- source: signal.conversationMetadata?.source,
665
- silent,
719
+ groupId:
720
+ assistantInitiatedThread.vellumSignal.conversationMetadata
721
+ ?.groupId,
722
+ source:
723
+ assistantInitiatedThread.vellumSignal.conversationMetadata
724
+ ?.source,
725
+ silent: resolveSilent(),
666
726
  };
667
727
 
668
728
  // The per-dispatch onConversationCreated callback fires whenever a vellum
@@ -692,6 +752,7 @@ export class NotificationBroadcaster {
692
752
  ) {
693
753
  if (this.onConversationCreated) {
694
754
  try {
755
+ info.silent = resolveSilent();
695
756
  await this.onConversationCreated(info);
696
757
  } catch (err) {
697
758
  log.error(
@@ -714,7 +775,7 @@ export class NotificationBroadcaster {
714
775
  deepLinkTarget,
715
776
  contextPayload: signal.contextPayload,
716
777
  urgency: signal.attentionHints.urgency,
717
- silent,
778
+ silent: resolveSilent(),
718
779
  approvalContext,
719
780
  accessRequestContext,
720
781
  toolApprovalSource,
@@ -729,6 +790,7 @@ export class NotificationBroadcaster {
729
790
  destinationLabel,
730
791
  pairing,
731
792
  hasPersistedDecision,
793
+ presentation,
732
794
  };
733
795
 
734
796
  // Compute conversation decision audit fields for the delivery record
@@ -915,7 +977,22 @@ export class NotificationBroadcaster {
915
977
  hasPersistedDecision,
916
978
  } = dispatch;
917
979
  try {
918
- const adapterResult = await adapter.send(payload, destination, observer);
980
+ if (channel === "vellum") {
981
+ payload.silent = isLocalNotificationSilent(
982
+ payload,
983
+ dispatch.presentation,
984
+ );
985
+ }
986
+ const adapterResult: DeliveryResult =
987
+ channel === "platform" &&
988
+ areChatReplyAlertsDisabled(signal.sourceEventName)
989
+ ? {
990
+ success: false,
991
+ skipped: true,
992
+ error: CHAT_REPLY_ALERTS_DISABLED,
993
+ remotePushAccepted: false,
994
+ }
995
+ : await adapter.send(payload, destination, observer);
919
996
 
920
997
  if (adapterResult.success) {
921
998
  // Prefer the channel-native id the adapter just captured (e.g.
@@ -966,13 +1043,14 @@ export class NotificationBroadcaster {
966
1043
  }),
967
1044
  );
968
1045
  } else {
1046
+ const status = adapterResult.skipped ? "skipped" : "failed";
969
1047
  if (hasPersistedDecision) {
970
- updateDeliveryStatus(deliveryId, "failed", {
1048
+ updateDeliveryStatus(deliveryId, status, {
971
1049
  message: adapterResult.error,
972
1050
  });
973
1051
  }
974
1052
  results.push(
975
- buildDeliveryResult(dispatch, "failed", {
1053
+ buildDeliveryResult(dispatch, status, {
976
1054
  errorMessage: adapterResult.error,
977
1055
  }),
978
1056
  );
@@ -0,0 +1,11 @@
1
+ import { getConfig } from "../config/loader.js";
2
+
3
+ export const CHAT_REPLY_ALERTS_DISABLED =
4
+ "Chat reply notifications are disabled";
5
+
6
+ export function areChatReplyAlertsDisabled(sourceEventName: string): boolean {
7
+ return (
8
+ sourceEventName === "chat.assistant_reply" &&
9
+ !getConfig().notifications.newMessageEnabled
10
+ );
11
+ }
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
 
3
+ import { areChatReplyAlertsDisabled } from "./chat-reply-policy.js";
3
4
  import type { ChannelDestination } from "./types.js";
4
5
  import type { Urgency } from "./urgency.js";
5
6
 
@@ -61,14 +62,23 @@ export function notificationConversationId(
61
62
  return readCompletionContext(event)?.conversationId ?? event.sourceContextId;
62
63
  }
63
64
 
64
- /** Completion presentation is independent of urgency and channel routing. */
65
+ export interface NotificationPresentationContext {
66
+ assistantInitiatedThreadCreated?: boolean;
67
+ }
68
+
69
+ /** Presentation is independent of urgency and channel routing. */
65
70
  export function isLocalNotificationSilent(
66
71
  event: CompletionEvent & { urgency: Urgency },
72
+ presentation?: NotificationPresentationContext,
67
73
  ): boolean {
68
- if (event.contextPayload?.quiet === true) {
74
+ if (
75
+ event.contextPayload?.quiet === true ||
76
+ areChatReplyAlertsDisabled(event.sourceEventName)
77
+ ) {
69
78
  return true;
70
79
  }
71
80
  return (
81
+ !presentation?.assistantInitiatedThreadCreated &&
72
82
  !isCompletionNotification(event) &&
73
83
  event.urgency !== "high" &&
74
84
  event.urgency !== "critical"