@vellumai/assistant 0.12.4 → 0.12.5-dev.202609251017.e467a6c

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 (281) hide show
  1. package/docs/architecture/memory.md +9 -1
  2. package/docs/architecture/scheduling.md +13 -5
  3. package/docs/desktop-browser-cli.md +3 -2
  4. package/docs/guardian-request-flow.md +1 -1
  5. package/node_modules/@vellumai/avatar-manifest/src/__tests__/notification-avatar.test.ts +48 -4
  6. package/node_modules/@vellumai/avatar-manifest/src/notification-avatar.ts +12 -8
  7. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
  8. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
  9. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
  10. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
  11. package/node_modules/@vellumai/gateway-client/src/outbound-contract.ts +2 -4
  12. package/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
  13. package/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
  14. package/openapi.yaml +152 -3
  15. package/package.json +1 -1
  16. package/src/__tests__/agent-loop.test.ts +76 -0
  17. package/src/__tests__/anthropic-error-formatting.test.ts +9 -0
  18. package/src/__tests__/background-shell-bash.test.ts +34 -0
  19. package/src/__tests__/background-shell-host-bash.test.ts +98 -1
  20. package/src/__tests__/background-tool-registry.test.ts +39 -0
  21. package/src/__tests__/channel-readiness-discord.test.ts +8 -0
  22. package/src/__tests__/channel-readiness-slack-remote.test.ts +8 -0
  23. package/src/__tests__/client-os-metadata-persistence.test.ts +4 -20
  24. package/src/__tests__/conversation-agent-loop.test.ts +529 -1
  25. package/src/__tests__/conversation-error.test.ts +18 -0
  26. package/src/__tests__/conversation-pairing.test.ts +69 -0
  27. package/src/__tests__/conversation-queue.test.ts +257 -4
  28. package/src/__tests__/conversation-runtime-assembly.test.ts +27 -0
  29. package/src/__tests__/emit-signal-routing-intent.test.ts +62 -0
  30. package/src/__tests__/evict-conversations-for-reload.test.ts +21 -0
  31. package/src/__tests__/gemini-provider.test.ts +9 -0
  32. package/src/__tests__/host-cu-proxy.test.ts +79 -0
  33. package/src/__tests__/host-cu-routes-targeted.test.ts +14 -5
  34. package/src/__tests__/introduction-card-resolver.test.ts +53 -8
  35. package/src/__tests__/job-handler-registration-guard.test.ts +1 -0
  36. package/src/__tests__/non-member-access-request.test.ts +48 -0
  37. package/src/__tests__/notification-events-source-context-probe.test.ts +48 -1
  38. package/src/__tests__/notification-platform-adapter.test.ts +97 -0
  39. package/src/__tests__/notification-vellum-adapter.test.ts +103 -3
  40. package/src/__tests__/platform-callback-registration.test.ts +46 -1
  41. package/src/__tests__/plugin-import-boundary-guard.test.ts +3 -0
  42. package/src/__tests__/scaffold-managed-skill-tool.test.ts +116 -66
  43. package/src/__tests__/scheduler-disk-pressure.test.ts +1 -0
  44. package/src/__tests__/scheduler-result-notification.test.ts +521 -7
  45. package/src/__tests__/scheduler-wake.test.ts +1 -0
  46. package/src/__tests__/skill-load-inline-command.test.ts +35 -0
  47. package/src/__tests__/subagent-cron-run-attribution.test.ts +41 -2
  48. package/src/__tests__/subagent-manager-notify.test.ts +48 -0
  49. package/src/__tests__/trusted-contact-inline-approval-integration.test.ts +6 -6
  50. package/src/__tests__/usage-attribution.test.ts +31 -0
  51. package/src/__tests__/wake-schedule-escalation.test.ts +1 -0
  52. package/src/agent/loop.ts +23 -0
  53. package/src/api/ask-question-tool.ts +50 -0
  54. package/src/api/events/generation-handoff.ts +4 -0
  55. package/src/api/events/message-complete.ts +4 -0
  56. package/src/api/events/tool-result.ts +11 -0
  57. package/src/api/index.ts +11 -0
  58. package/src/api/requests/guardian-actions.test.ts +45 -0
  59. package/src/api/requests/guardian-actions.ts +20 -0
  60. package/src/api/responses/conversation-message.ts +4 -0
  61. package/src/api/responses/home.ts +27 -0
  62. package/src/approvals/guardian-decision-primitive.ts +6 -4
  63. package/src/approvals/guardian-request-resolvers.ts +35 -30
  64. package/src/avatar/notification-avatar.test.ts +42 -34
  65. package/src/avatar/notification-avatar.ts +1 -0
  66. package/src/calls/__tests__/call-controller.test.ts +18 -0
  67. package/src/calls/__tests__/voice-control-protocol.test.ts +6 -1
  68. package/src/calls/__tests__/voice-leg-coordinator.test.ts +70 -0
  69. package/src/calls/__tests__/voice-session-bridge.test.ts +116 -4
  70. package/src/calls/__tests__/voice-triage-escalate.test.ts +77 -11
  71. package/src/calls/call-controller.ts +3 -1
  72. package/src/calls/voice-control-protocol.ts +12 -4
  73. package/src/calls/voice-escalation-judge.ts +2 -2
  74. package/src/calls/voice-leg-coordinator.ts +23 -5
  75. package/src/calls/voice-screen-annotation.ts +44 -0
  76. package/src/calls/voice-session-bridge.ts +63 -20
  77. package/src/calls/voice-triage-escalate.ts +82 -27
  78. package/src/cli/commands/__tests__/conversations-clear.test.ts +156 -0
  79. package/src/cli/commands/conversations.help.ts +7 -2
  80. package/src/cli/commands/conversations.ts +36 -30
  81. package/src/cli/commands/oauth/index.help.ts +8 -2
  82. package/src/cli/commands/oauth/request.test.ts +32 -0
  83. package/src/cli/commands/platform/index.help.ts +2 -1
  84. package/src/cli/commands/platform/index.ts +8 -2
  85. package/src/cli/lib/__tests__/plugin-catalog-cache.test.ts +60 -0
  86. package/src/cli/lib/__tests__/plugin-catalog-platform.test.ts +66 -2
  87. package/src/cli/lib/bundled-marketplace.json +35 -0
  88. package/src/cli/lib/bundled-plugin-packages.json +21 -0
  89. package/src/cli/lib/plugin-catalog-cache.ts +17 -2
  90. package/src/cli/lib/plugin-catalog-platform.ts +48 -9
  91. package/src/config/__tests__/default-profile-catalog.test.ts +28 -0
  92. package/src/config/__tests__/platform-identity.test.ts +59 -0
  93. package/src/config/__tests__/profile-order.test.ts +19 -0
  94. package/src/config/__tests__/sync-gated-profiles.test.ts +71 -0
  95. package/src/config/bundled-skills/computer-use/SKILL.md +20 -0
  96. package/src/config/bundled-skills/computer-use/TOOLS.json +11 -11
  97. package/src/config/bundled-skills/screen-annotation/SKILL.md +41 -29
  98. package/src/config/bundled-skills/screen-annotation/TOOLS.json +5 -5
  99. package/src/config/call-site-defaults.ts +6 -0
  100. package/src/config/default-profile-catalog.ts +30 -1
  101. package/src/config/default-profile-names.ts +36 -2
  102. package/src/config/feature-flag-registry.json +9 -1
  103. package/src/config/platform-identity.ts +22 -5
  104. package/src/config/profile-order.ts +7 -1
  105. package/src/config/schemas/call-site-catalog.ts +7 -0
  106. package/src/config/schemas/llm.ts +21 -5
  107. package/src/config/sync-gated-profiles.ts +96 -44
  108. package/src/daemon/__tests__/abort-null-controller.test.ts +135 -1
  109. package/src/daemon/__tests__/auto-profile-router.test.ts +380 -0
  110. package/src/daemon/__tests__/turn-tail-assistant-reply-notify.test.ts +16 -0
  111. package/src/daemon/activity-trail.test.ts +206 -0
  112. package/src/daemon/activity-trail.ts +190 -0
  113. package/src/daemon/auto-profile-router.ts +431 -0
  114. package/src/daemon/computer-use-observation.test.ts +81 -0
  115. package/src/daemon/computer-use-observation.ts +23 -0
  116. package/src/daemon/conversation-agent-loop-handlers.ts +11 -0
  117. package/src/daemon/conversation-agent-loop.ts +157 -32
  118. package/src/daemon/conversation-error.ts +19 -0
  119. package/src/daemon/conversation-lifecycle.ts +70 -7
  120. package/src/daemon/conversation-media-retry.ts +1 -2
  121. package/src/daemon/conversation-messaging.ts +31 -2
  122. package/src/daemon/conversation-process.ts +107 -16
  123. package/src/daemon/conversation-queue-manager.ts +7 -0
  124. package/src/daemon/conversation-runtime-assembly.ts +1 -0
  125. package/src/daemon/conversation-turn-finalize.ts +14 -0
  126. package/src/daemon/conversation.ts +25 -6
  127. package/src/daemon/event-loop-watchdog.test.ts +201 -2
  128. package/src/daemon/event-loop-watchdog.ts +182 -6
  129. package/src/daemon/host-cu-proxy.ts +34 -3
  130. package/src/daemon/pkb-reminder-builder.test.ts +10 -3
  131. package/src/daemon/pkb-reminder-builder.ts +1 -1
  132. package/src/daemon/wake-conversation-ops.ts +4 -2
  133. package/src/desktop/desktop-computer-use.test.ts +14 -4
  134. package/src/home/feed-types.ts +2 -0
  135. package/src/inbound/platform-callback-registration.ts +19 -6
  136. package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +27 -0
  137. package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +83 -0
  138. package/src/live-voice/__tests__/live-voice-triage-escalate.test.ts +48 -1
  139. package/src/live-voice/__tests__/live-voice-vad.test.ts +34 -2
  140. package/src/live-voice/__tests__/protocol.test.ts +22 -0
  141. package/src/live-voice/continuation-judge.ts +1 -1
  142. package/src/live-voice/live-voice-session.ts +25 -19
  143. package/src/live-voice/protocol.ts +16 -5
  144. package/src/messaging/providers/discord/withdraw.ts +4 -5
  145. package/src/messaging/providers/gmail/client.ts +4 -0
  146. package/src/messaging/providers/slack/withdraw.ts +5 -5
  147. package/src/messaging/providers/telegram-bot/withdraw.ts +4 -5
  148. package/src/monitoring/__tests__/proc-fixtures.ts +28 -0
  149. package/src/monitoring/__tests__/proc-wait-state.test.ts +232 -0
  150. package/src/monitoring/__tests__/process-usage.test.ts +243 -0
  151. package/src/monitoring/proc-wait-state.ts +366 -0
  152. package/src/monitoring/process-memory.ts +4 -3
  153. package/src/monitoring/process-usage.ts +215 -0
  154. package/src/monitoring/resource-sample-types.ts +8 -0
  155. package/src/monitoring/resource-sampler.ts +17 -2
  156. package/src/monitoring/stall-capture.ts +12 -0
  157. package/src/notifications/README.md +88 -9
  158. package/src/notifications/__tests__/assistant-reply-producer.test.ts +390 -119
  159. package/src/notifications/__tests__/background-result-producer.test.ts +1272 -0
  160. package/src/notifications/__tests__/broadcaster.test.ts +292 -1
  161. package/src/notifications/__tests__/completion-policy.test.ts +243 -0
  162. package/src/notifications/__tests__/decision-engine.test.ts +51 -4
  163. package/src/notifications/__tests__/has-pending-background-work.test.ts +281 -0
  164. package/src/notifications/__tests__/home-feed-side-effect.test.ts +161 -3
  165. package/src/notifications/__tests__/resolve-visible-in-source.test.ts +110 -1
  166. package/src/notifications/__tests__/schedule-result-producer.test.ts +11 -4
  167. package/src/notifications/adapters/macos.ts +24 -12
  168. package/src/notifications/adapters/platform.ts +16 -5
  169. package/src/notifications/assistant-reply-producer.ts +96 -71
  170. package/src/notifications/background-result-producer.ts +369 -0
  171. package/src/notifications/broadcaster.ts +28 -8
  172. package/src/notifications/completion-policy.ts +115 -0
  173. package/src/notifications/completion-work.ts +46 -0
  174. package/src/notifications/conversation-pairing.ts +32 -13
  175. package/src/notifications/decision-engine.ts +18 -24
  176. package/src/notifications/emit-signal.ts +16 -1
  177. package/src/notifications/events-store.ts +4 -0
  178. package/src/notifications/has-pending-background-work.ts +91 -0
  179. package/src/notifications/home-feed-mirror.ts +44 -0
  180. package/src/notifications/home-feed-side-effect.ts +54 -28
  181. package/src/notifications/resolve-visible-in-source.ts +56 -2
  182. package/src/notifications/result-output.ts +154 -0
  183. package/src/notifications/schedule-result-producer.ts +6 -187
  184. package/src/notifications/types.ts +2 -0
  185. package/src/oauth/AGENTS.md +9 -1
  186. package/src/oauth/byo-connection.test.ts +28 -0
  187. package/src/persistence/__tests__/recent-conversation-messages.test.ts +41 -0
  188. package/src/persistence/conversation-crud.ts +26 -0
  189. package/src/persistence/conversation-types.ts +15 -37
  190. package/src/persistence/embeddings/__tests__/embedding-local-lifecycle.test.ts +85 -14
  191. package/src/persistence/jobs-store.ts +229 -0
  192. package/src/persistence/migrations/383-normalize-opencode-host-connections.ts +44 -0
  193. package/src/persistence/migrations/__tests__/383-normalize-opencode-host-connections.test.ts +102 -0
  194. package/src/persistence/steps.ts +12 -0
  195. package/src/platform/sync-avatar.test.ts +29 -0
  196. package/src/plugins/defaults/memory/AGENTS.md +5 -3
  197. package/src/plugins/defaults/memory/__tests__/skill-update-receipt-boundary-guard.test.ts +45 -0
  198. package/src/plugins/defaults/memory/__tests__/skill-update-receipt-job.test.ts +580 -0
  199. package/src/plugins/defaults/memory/__tests__/turn-retrieval.test.ts +21 -0
  200. package/src/plugins/defaults/memory/graph/tools.ts +9 -5
  201. package/src/plugins/defaults/memory/hooks/conversation-deleted.ts +4 -0
  202. package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +7 -3
  203. package/src/plugins/defaults/memory/job-handlers.ts +8 -2
  204. package/src/plugins/defaults/memory/skill-update-receipt-job.ts +334 -0
  205. package/src/plugins/defaults/memory/tools.test.ts +17 -0
  206. package/src/plugins/defaults/memory/turn-retrieval.ts +8 -0
  207. package/src/plugins/defaults/memory/v3/__tests__/injection.test.ts +24 -0
  208. package/src/plugins/defaults/memory/v3/injector.ts +4 -4
  209. package/src/plugins/types.ts +2 -0
  210. package/src/providers/__tests__/search-provider-catalog.test.ts +8 -0
  211. package/src/providers/anthropic/client.ts +4 -0
  212. package/src/providers/gemini/client.ts +7 -1
  213. package/src/providers/inference/auth.ts +25 -0
  214. package/src/providers/inference/profile-probe.ts +1 -0
  215. package/src/{calls/__tests__/typesafe-noul.test.ts → providers/jev/ask.test.ts} +4 -4
  216. package/src/{calls/typesafe-noul.ts → providers/jev/ask.ts} +67 -34
  217. package/src/providers/openai/__tests__/api-error-normalization.test.ts +12 -0
  218. package/src/providers/openai/api-error-normalization.ts +4 -0
  219. package/src/providers/retry.ts +2 -0
  220. package/src/providers/search-provider-catalog.ts +10 -0
  221. package/src/providers/types.ts +7 -0
  222. package/src/providers/usage-tracking.ts +5 -3
  223. package/src/runtime/__tests__/agent-wake.test.ts +308 -0
  224. package/src/runtime/access-request-helper.ts +16 -9
  225. package/src/runtime/agent-wake-queue.ts +52 -0
  226. package/src/runtime/agent-wake.ts +111 -18
  227. package/src/runtime/channel-approval-types.ts +6 -38
  228. package/src/runtime/channel-approvals.ts +4 -5
  229. package/src/runtime/http-server.ts +4 -1
  230. package/src/runtime/introduction-policy.test.ts +17 -1
  231. package/src/runtime/introduction-policy.ts +25 -7
  232. package/src/runtime/migrations/vbundle-builder.ts +9 -0
  233. package/src/runtime/routes/__tests__/inference-profiles-routes.test.ts +21 -1
  234. package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +60 -0
  235. package/src/runtime/routes/__tests__/oauth-proxy-routes.test.ts +61 -3
  236. package/src/runtime/routes/auto-profile-routes.ts +83 -0
  237. package/src/runtime/routes/conversation-management-routes.ts +1 -3
  238. package/src/runtime/routes/conversation-routes.ts +9 -0
  239. package/src/runtime/routes/guardian-action-routes.ts +8 -23
  240. package/src/runtime/routes/host-cu-routes.ts +3 -1
  241. package/src/runtime/routes/index.ts +2 -0
  242. package/src/runtime/routes/inference-profiles-routes.ts +5 -2
  243. package/src/runtime/routes/inference-provider-connection-routes.ts +25 -8
  244. package/src/runtime/routes/migration-routes.ts +8 -2
  245. package/src/runtime/routes/oauth-proxy-passthrough.test.ts +32 -0
  246. package/src/runtime/routes/platform-routes.ts +6 -1
  247. package/src/runtime/routes/user-route-dispatcher.ts +1 -2
  248. package/src/runtime/web-presence.ts +3 -4
  249. package/src/schedule/schedule-store.ts +10 -0
  250. package/src/schedule/scheduler.ts +92 -24
  251. package/src/subagent/manager.ts +32 -12
  252. package/src/telegram/__tests__/webhook-health.test.ts +8 -0
  253. package/src/telemetry/telemetry-wire-source.json +1 -1
  254. package/src/telemetry/telemetry-wire.generated.ts +1 -0
  255. package/src/tools/background-tool-registry.ts +30 -3
  256. package/src/tools/browser/cdp-client/local-cdp-client.ts +1 -2
  257. package/src/tools/host-terminal/host-shell.ts +7 -0
  258. package/src/tools/network/__tests__/web-fetch-firecrawl.test.ts +28 -1
  259. package/src/tools/network/__tests__/web-fetch-metadata.test.ts +34 -0
  260. package/src/tools/network/__tests__/web-fetch-tinyfish.test.ts +35 -1
  261. package/src/tools/network/__tests__/web-search.test.ts +96 -0
  262. package/src/tools/network/web-fetch.ts +30 -9
  263. package/src/tools/network/web-search.ts +235 -4
  264. package/src/tools/skills/load.ts +13 -17
  265. package/src/tools/skills/scaffold-managed.ts +86 -71
  266. package/src/tools/terminal/shell-launch.test.ts +27 -1
  267. package/src/tools/terminal/shell.ts +4 -0
  268. package/src/tools/workspace-tools/loader.ts +1 -2
  269. package/src/usage/attribution.ts +18 -1
  270. package/src/util/abort-reasons.ts +2 -0
  271. package/src/util/errors.ts +1 -0
  272. package/src/util/oauth-request-body.test.ts +5 -1
  273. package/src/util/provider-error-patterns.ts +11 -0
  274. package/src/util/single-flight.test.ts +6 -0
  275. package/src/util/single-flight.ts +2 -0
  276. package/src/util/worker-pipe.test.ts +56 -10
  277. package/src/util/worker-pipe.ts +9 -4
  278. package/src/workspace/git-service.ts +6 -1
  279. package/src/workspace/migrations/158-repoint-opencode-host-provider-fragments.ts +163 -0
  280. package/src/workspace/migrations/__tests__/158-repoint-opencode-host-provider-fragments.test.ts +188 -0
  281. package/src/workspace/migrations/registry.ts +2 -0
@@ -0,0 +1,52 @@
1
+ import { createKeyedSingleFlight } from "../util/single-flight.js";
2
+
3
+ export const runWakeSingleFlight = createKeyedSingleFlight();
4
+ interface WakeOrigin {
5
+ cronRunId?: string;
6
+ startedAt?: number;
7
+ }
8
+ const pendingWakes = new Map<string, Map<symbol, WakeOrigin>>();
9
+
10
+ /** Tracks ownership while a wake is queued, hydrating, or executing. */
11
+ export function trackAgentWake(
12
+ conversationId: string,
13
+ origin: WakeOrigin,
14
+ ): () => void {
15
+ const wakes =
16
+ pendingWakes.get(conversationId) ?? new Map<symbol, WakeOrigin>();
17
+ const token = Symbol();
18
+ wakes.set(token, origin);
19
+ pendingWakes.set(conversationId, wakes);
20
+ return () => {
21
+ wakes.delete(token);
22
+ if (wakes.size === 0) {
23
+ pendingWakes.delete(conversationId);
24
+ }
25
+ };
26
+ }
27
+
28
+ export function hasPendingAgentWake(
29
+ conversationId: string,
30
+ cronRunId?: string,
31
+ options?: { startedAfter?: number },
32
+ ): boolean {
33
+ if (cronRunId === undefined && options?.startedAfter === undefined) {
34
+ return (
35
+ runWakeSingleFlight.isPending(conversationId) ||
36
+ pendingWakes.has(conversationId)
37
+ );
38
+ }
39
+ return [...(pendingWakes.get(conversationId)?.values() ?? [])].some(
40
+ (origin) =>
41
+ (cronRunId === undefined || origin.cronRunId === cronRunId) &&
42
+ (options?.startedAfter === undefined ||
43
+ (origin.startedAt !== undefined &&
44
+ origin.startedAt >= options.startedAfter)),
45
+ );
46
+ }
47
+
48
+ /** @internal */
49
+ export function resetAgentWakeQueueForTests(): void {
50
+ runWakeSingleFlight.reset();
51
+ pendingWakes.clear();
52
+ }
@@ -109,6 +109,7 @@ import {
109
109
  scopeWakeAllowedTools,
110
110
  } from "../daemon/wake-conversation-ops.js";
111
111
  import { desktopAutomationLease } from "../desktop/desktop-automation-lease.js";
112
+ import { emitBackgroundResultNotification } from "../notifications/background-result-producer.js";
112
113
  import {
113
114
  recordCompactionEndBestEffort,
114
115
  recordCompactionStartBestEffort,
@@ -121,14 +122,22 @@ import {
121
122
  } from "../persistence/llm-request-log-store.js";
122
123
  import type { SystemPromptPersonaOverride } from "../prompts/system-prompt.js";
123
124
  import type { Message, ToolDefinition } from "../providers/types.js";
125
+ import { getScheduleRunStatus } from "../schedule/schedule-store.js";
124
126
  import {
125
127
  type UntrustedContentSource,
126
128
  wrapUntrustedContent,
127
129
  } from "../security/untrusted-content.js";
130
+ import { stampTurnOutcome } from "../telemetry/turn-outcome.js";
128
131
  import type { CompletedBackgroundTool } from "../tools/background-tool-registry.js";
129
132
  import { getLogger } from "../util/logger.js";
130
- import { createKeyedSingleFlight } from "../util/single-flight.js";
131
133
  import { safeStringSlice } from "../util/unicode.js";
134
+ import {
135
+ resetAgentWakeQueueForTests,
136
+ runWakeSingleFlight,
137
+ trackAgentWake,
138
+ } from "./agent-wake-queue.js";
139
+
140
+ export { hasPendingAgentWake } from "./agent-wake-queue.js";
132
141
 
133
142
  const log = getLogger("agent-wake");
134
143
 
@@ -566,10 +575,9 @@ async function defaultResolveTarget(
566
575
  // snapshot reads. Without this, fork-based memory retrospectives see
567
576
  // an empty history because loadFromDb ran with trustClass="unknown"
568
577
  // and filtered out every guardian-provenance message.
569
- const conversation = await getOrCreateConversation(conversationId, {
578
+ return await getOrCreateConversation(conversationId, {
570
579
  trustContext: opts.trustContext,
571
580
  });
572
- return conversation;
573
581
  } catch (err) {
574
582
  log.warn(
575
583
  { err, conversationId },
@@ -620,20 +628,10 @@ async function kickWakeDrainQueue(
620
628
  }
621
629
  }
622
630
 
623
- // ── Per-conversation single-flight lock ───────────────────────────────
624
- //
625
- // When a wake arrives and another run is in flight for the same
626
- // conversation, we chain onto its tail so the wake runs *after* the current
627
- // work completes. `createKeyedSingleFlight` owns the tail-chaining and
628
- // bounded-map bookkeeping; wakes serialize on their own chain, independent of
629
- // any other single-flight consumer.
630
-
631
- const runWakeSingleFlight = createKeyedSingleFlight();
632
-
633
631
  /**
634
632
  * How long a wake waits for an in-flight turn to release the conversation's
635
633
  * processing lock before skipping with reason "timeout". We rely primarily
636
- * on the single-flight chain above to serialize *wakes*; the pre-run
634
+ * on the single-flight chain to serialize *wakes*; the pre-run
637
635
  * `waitForIdle` gate catches the case where a user turn started
638
636
  * independently while our wake was queued.
639
637
  */
@@ -762,8 +760,17 @@ export async function wakeAgentForOpportunity(
762
760
  const resolveTarget = deps?.resolveTarget ?? defaultResolveTarget;
763
761
  const nowFn = deps?.now ?? Date.now;
764
762
  const startedAt = nowFn();
763
+ const scheduledRunFailed = (): boolean =>
764
+ opts.cronRunId !== undefined &&
765
+ getScheduleRunStatus(opts.cronRunId) === "error";
766
+ let wakeTriggerMessageId: string | undefined;
767
+ let completionAssistantMessageId: string | undefined;
765
768
 
766
- return runWakeSingleFlight(conversationId, async () => {
769
+ const finishWake = trackAgentWake(conversationId, {
770
+ cronRunId: opts.cronRunId,
771
+ startedAt: opts.backgroundToolCompletion?.startedAt,
772
+ });
773
+ return runWakeSingleFlight<WakeResult>(conversationId, async () => {
767
774
  // Snapshot the conversation's resting trust before the resolver runs, so
768
775
  // it can be restored after. The resolver leaves the wake's trust on the
769
776
  // conversation, and a following no-trust wake would otherwise pick it up
@@ -860,6 +867,10 @@ export async function wakeAgentForOpportunity(
860
867
  restorePersistentWakeTrust();
861
868
  return { invoked: false, producedToolCalls: false, reason: "timeout" };
862
869
  }
870
+ if (scheduledRunFailed()) {
871
+ restorePersistentWakeTrust();
872
+ return { invoked: false, producedToolCalls: false, reason: "timeout" };
873
+ }
863
874
 
864
875
  // Trust elevation is applied per-turn via `currentTurnTrustContext` right
865
876
  // before the run (see below) — not on the persistent conversation trust.
@@ -928,6 +939,27 @@ export async function wakeAgentForOpportunity(
928
939
  // observed the lock free, and nothing between its final `isProcessing()`
929
940
  // check and this acquisition awaits — keep that stretch await-free so
930
941
  // the lock cannot change hands in between.
942
+ const scheduleAbortController = opts.cronRunId
943
+ ? new AbortController()
944
+ : undefined;
945
+ const priorScheduledRunId = conversation.currentTurnCronRunId;
946
+ const priorWorkOrigins = conversation.currentTurnWorkOrigins;
947
+ const wakeWorkOrigins = opts.backgroundToolCompletion
948
+ ? [
949
+ {
950
+ sentAt: opts.backgroundToolCompletion.startedAt,
951
+ metadata: {
952
+ backgroundEventSource: "background-tool",
953
+ backgroundToolCompletion: opts.backgroundToolCompletion,
954
+ },
955
+ },
956
+ ]
957
+ : [];
958
+ conversation.currentTurnWorkOrigins = wakeWorkOrigins;
959
+ if (scheduleAbortController) {
960
+ conversation.abortController = scheduleAbortController;
961
+ conversation.currentTurnCronRunId = opts.cronRunId;
962
+ }
931
963
  conversation.setProcessing(true);
932
964
 
933
965
  // ── Pre-run auto-compaction gate ──────────────────────────────────
@@ -983,7 +1015,7 @@ export async function wakeAgentForOpportunity(
983
1015
  };
984
1016
  conversation.messages.push(triggerMessage);
985
1017
  try {
986
- await persistWakeTriggerMessage(
1018
+ wakeTriggerMessageId = await persistWakeTriggerMessage(
987
1019
  conversation,
988
1020
  triggerMessage,
989
1021
  source,
@@ -1288,6 +1320,8 @@ export async function wakeAgentForOpportunity(
1288
1320
  const wakeSurfaceId = `wake-${conversationId}-${nowFn()}`;
1289
1321
  let surfaceInjected = false;
1290
1322
  let persistedTailIndex = 0;
1323
+ let lastPersistedAssistantMessageId: string | undefined;
1324
+ let tailPersistenceFailed = false;
1291
1325
 
1292
1326
  // Transition from buffered to live emission. Idempotent — only the
1293
1327
  // first call has an effect. Mutates the first assistant message in
@@ -1371,12 +1405,16 @@ export async function wakeAgentForOpportunity(
1371
1405
  }
1372
1406
  for (const msg of newMessages) {
1373
1407
  try {
1374
- await persistWakeTailMessage(conversation, msg);
1408
+ const persistedId = await persistWakeTailMessage(conversation, msg);
1409
+ if (msg.role === "assistant") {
1410
+ lastPersistedAssistantMessageId = persistedId;
1411
+ }
1375
1412
  } catch (err) {
1376
1413
  log.warn(
1377
1414
  { conversationId, source, err, role: msg.role },
1378
1415
  "agent-wake: failed to persist wake-tail message",
1379
1416
  );
1417
+ tailPersistenceFailed = true;
1380
1418
  }
1381
1419
  }
1382
1420
  persistedTailIndex += newMessages.length;
@@ -1439,6 +1477,16 @@ export async function wakeAgentForOpportunity(
1439
1477
  * is one function rather than a rebuild bolted onto either half.
1440
1478
  */
1441
1479
  const restoreWakeTurnScope = (): void => {
1480
+ if (conversation.currentTurnWorkOrigins === wakeWorkOrigins) {
1481
+ conversation.currentTurnWorkOrigins = priorWorkOrigins;
1482
+ }
1483
+ if (
1484
+ scheduleAbortController &&
1485
+ conversation.abortController === scheduleAbortController
1486
+ ) {
1487
+ conversation.abortController = null;
1488
+ conversation.currentTurnCronRunId = priorScheduledRunId;
1489
+ }
1442
1490
  desktopAutomationLease.releaseForConversation(conversationId);
1443
1491
  restoreWakeAllowedTools();
1444
1492
  clearWakePersonaOverride();
@@ -1523,7 +1571,12 @@ export async function wakeAgentForOpportunity(
1523
1571
  reason: "context_overflow" as const,
1524
1572
  };
1525
1573
  };
1574
+ let cancelledBeforeRun = false;
1526
1575
  try {
1576
+ if (scheduleAbortController?.signal.aborted || scheduledRunFailed()) {
1577
+ cancelledBeforeRun = true;
1578
+ return { invoked: false, producedToolCalls: false, reason: "timeout" };
1579
+ }
1527
1580
  // ── Over-window policy under suppressed auto-compaction ─────────
1528
1581
  // The pre-run gate above is the wake's only compaction path (the
1529
1582
  // loop's in-loop budget gate stays disabled), so when the caller
@@ -1620,6 +1673,7 @@ export async function wakeAgentForOpportunity(
1620
1673
  try {
1621
1674
  ({ history: updatedHistory } = await conversation.agentLoop.run({
1622
1675
  messages: runInput,
1676
+ signal: scheduleAbortController?.signal,
1623
1677
  onEvent,
1624
1678
  requestId: `wake:${source}`,
1625
1679
  onCheckpoint,
@@ -1827,6 +1881,15 @@ export async function wakeAgentForOpportunity(
1827
1881
  "agent-wake: setProcessing(false) threw; continuing",
1828
1882
  );
1829
1883
  }
1884
+ if (
1885
+ !tailPersistenceFailed &&
1886
+ lastPersistedAssistantMessageId &&
1887
+ opts.backgroundToolCompletion &&
1888
+ (terminalExitReason === "no_tool_calls" ||
1889
+ terminalExitReason === "yield_to_user")
1890
+ ) {
1891
+ completionAssistantMessageId = lastPersistedAssistantMessageId;
1892
+ }
1830
1893
  await kickWakeDrainQueue(conversation, "agent_wake_tail", {
1831
1894
  conversationId,
1832
1895
  source,
@@ -1835,6 +1898,24 @@ export async function wakeAgentForOpportunity(
1835
1898
 
1836
1899
  return { invoked: true, producedToolCalls, ...exitReasonField() };
1837
1900
  } finally {
1901
+ if (
1902
+ opts.backgroundToolCompletion &&
1903
+ wakeTriggerMessageId &&
1904
+ (cancelledBeforeRun ||
1905
+ runError ||
1906
+ (terminalExitReason !== null &&
1907
+ terminalExitReason !== "no_tool_calls" &&
1908
+ terminalExitReason !== "yield_to_user"))
1909
+ ) {
1910
+ stampTurnOutcome(
1911
+ wakeTriggerMessageId,
1912
+ cancelledBeforeRun ||
1913
+ String(terminalExitReason).startsWith("aborted_") ||
1914
+ terminalExitReason === "checkpoint_handoff"
1915
+ ? "cancelled"
1916
+ : "failed",
1917
+ );
1918
+ }
1838
1919
  // Put the conversation's resting trust back on every exit path.
1839
1920
  restorePersistentWakeTrust();
1840
1921
  // The success path (above) already called setProcessing(false) and
@@ -1910,6 +1991,18 @@ export async function wakeAgentForOpportunity(
1910
1991
  );
1911
1992
  }
1912
1993
  }
1994
+ }).finally(() => {
1995
+ finishWake();
1996
+ if (opts.backgroundToolCompletion && wakeTriggerMessageId) {
1997
+ void emitBackgroundResultNotification({
1998
+ conversationId,
1999
+ assistantMessageId: completionAssistantMessageId,
2000
+ recoverOnly: completionAssistantMessageId === undefined,
2001
+ userMessageId: wakeTriggerMessageId,
2002
+ cronRunId: opts.cronRunId,
2003
+ rlog: log,
2004
+ });
2005
+ }
1913
2006
  });
1914
2007
  }
1915
2008
 
@@ -1923,5 +2016,5 @@ export async function wakeAgentForOpportunity(
1923
2016
  * @internal
1924
2017
  */
1925
2018
  export function __resetWakeChainForTests(): void {
1926
- runWakeSingleFlight.reset();
2019
+ resetAgentWakeQueueForTests();
1927
2020
  }
@@ -9,6 +9,10 @@
9
9
  */
10
10
 
11
11
  import type { ApprovalActionOption } from "@vellumai/gateway-client";
12
+ import {
13
+ GUARDIAN_DECISION_ACTION_IDS,
14
+ isParkGuardianAction,
15
+ } from "@vellumai/service-contracts/guardian-requests";
12
16
 
13
17
  import type { GuardianDecisionAction } from "./guardian-decision-types.js";
14
18
 
@@ -35,14 +39,7 @@ export {
35
39
  * introduction-card actions, valid only for `access_request` requests — the
36
40
  * guardian decision primitive rejects them for any other kind.
37
41
  */
38
- export const APPROVAL_ACTION_IDS = [
39
- "approve_once",
40
- "reject",
41
- "trust",
42
- "verify_code",
43
- "leave_unverified",
44
- "block",
45
- ] as const;
42
+ export const APPROVAL_ACTION_IDS = GUARDIAN_DECISION_ACTION_IDS;
46
43
 
47
44
  export type ApprovalAction = (typeof APPROVAL_ACTION_IDS)[number];
48
45
 
@@ -70,38 +67,9 @@ export const INTRODUCTION_ACTION_SET: ReadonlySet<string> = new Set([
70
67
  "block",
71
68
  ]);
72
69
 
73
- /**
74
- * Actions that resolve a request to the `denied` terminal status. Everything
75
- * else resolves to `approved`.
76
- */
77
- export const DENYING_ACTION_SET: ReadonlySet<string> = new Set([
78
- "reject",
79
- "leave_unverified",
80
- "block",
81
- ]);
82
-
83
- /**
84
- * The denying actions that *park* the sender at `unverified` — a neutral hold,
85
- * not an active rejection. A parked contact is still admitted under the
86
- * permissive admission floors (`any_contact`, `strangers`) and can be trusted
87
- * or verified later; contrast `block` (→ revoked, a hard keep-out) and `reject`
88
- * (an explicit decline). Both resolve the request to `denied`, so the terminal
89
- * status alone can't tell a park from a rejection — surfaces that present the
90
- * resolved card consult this to render a park neutrally (see
91
- * {@link PARK_STATUS_LABEL}) instead of as a denial.
92
- */
93
- export const PARK_ACTION_SET: ReadonlySet<string> = new Set([
94
- "leave_unverified",
95
- ]);
96
-
97
70
  /** Completed-card label shown for a parked (leave-unverified) decision. */
98
71
  export const PARK_STATUS_LABEL = "Left unverified";
99
72
 
100
- /** True when `action` parks the sender at `unverified` (a neutral hold). */
101
- export function isParkAction(action: string | undefined): boolean {
102
- return action !== undefined && PARK_ACTION_SET.has(action);
103
- }
104
-
105
73
  /** Outcome word per terminal guardian-request status on a resolved card. */
106
74
  const DECISION_STATUS_WORDS: Record<string, string> = {
107
75
  approved: "Approved",
@@ -121,7 +89,7 @@ export function resolveDecisionStatusWord(
121
89
  status: string,
122
90
  decidedAction?: string,
123
91
  ): string {
124
- if (status === "denied" && isParkAction(decidedAction)) {
92
+ if (status === "denied" && isParkGuardianAction(decidedAction)) {
125
93
  return PARK_STATUS_LABEL;
126
94
  }
127
95
  return DECISION_STATUS_WORDS[status] ?? "Resolved";
@@ -9,6 +9,8 @@
9
9
  * 3. Consume user decisions and apply them to the underlying session
10
10
  */
11
11
 
12
+ import { isDenyingGuardianAction } from "@vellumai/service-contracts/guardian-requests";
13
+
12
14
  import { findConversation } from "../daemon/conversation-registry.js";
13
15
  import type { UserDecision } from "../permissions/types.js";
14
16
  import { composeApprovalMessage } from "./approval-message-composer.js";
@@ -18,10 +20,7 @@ import type {
18
20
  ApprovalUIMetadata,
19
21
  ChannelApprovalPrompt,
20
22
  } from "./channel-approval-types.js";
21
- import {
22
- DENYING_ACTION_SET,
23
- toApprovalActionOptions,
24
- } from "./channel-approval-types.js";
23
+ import { toApprovalActionOptions } from "./channel-approval-types.js";
25
24
  import {
26
25
  buildOneTimeDecisionActions,
27
26
  buildPlainTextFallback,
@@ -136,7 +135,7 @@ export function buildApprovalUIMetadata(
136
135
  * pending tool confirmation as an approval.
137
136
  */
138
137
  function mapApprovalActionToUserDecision(action: ApprovalAction): UserDecision {
139
- return DENYING_ACTION_SET.has(action) ? "deny" : "allow";
138
+ return isDenyingGuardianAction(action) ? "deny" : "allow";
140
139
  }
141
140
 
142
141
  // ---------------------------------------------------------------------------
@@ -114,6 +114,7 @@ import {
114
114
  // Re-export for consumers
115
115
  export { isPrivateAddress } from "./middleware/auth.js";
116
116
 
117
+ import { trackDaemonActivity } from "../daemon/activity-trail.js";
117
118
  import type { RuntimeHttpServerOptions } from "./http-types.js";
118
119
 
119
120
  const log = getLogger("runtime-http");
@@ -697,7 +698,9 @@ export class RuntimeHttpServer {
697
698
  return;
698
699
  }
699
700
  this.sweepInProgress = true;
700
- void sweepFailedEvents(processMessage)
701
+ void trackDaemonActivity({ kind: "channel_retry_sweep" }, () =>
702
+ sweepFailedEvents(processMessage),
703
+ )
701
704
  .catch((err) => {
702
705
  log.error({ err }, "Failed channel event retry sweep failed");
703
706
  })
@@ -6,6 +6,7 @@ import {
6
6
  isHandshakeOffered,
7
7
  isWorkspaceVouchedIdentity,
8
8
  parseRequesterSignals,
9
+ requesterCanCompleteHandshake,
9
10
  resolveTrustBinding,
10
11
  serializeRequesterSignals,
11
12
  VERIFIED_VIA_CHANNEL_CLAIM,
@@ -117,13 +118,18 @@ describe("handshake policy", () => {
117
118
  expect(isHandshakeOffered("phone", {})).toBe(false);
118
119
  });
119
120
 
121
+ test("not offered on email: the code has no route to the sender", () => {
122
+ expect(requesterCanCompleteHandshake("email", {})).toBe(false);
123
+ expect(isHandshakeOffered("email", {})).toBe(false);
124
+ expect(isHandshakeOffered("email", { isStranger: true })).toBe(false);
125
+ });
126
+
120
127
  test("leads for externals, strangers, and identity-less channels", () => {
121
128
  expect(isHandshakeOffered("slack", { isStranger: true })).toBe(true);
122
129
  expect(isHandshakeOffered("slack", { isRestricted: true })).toBe(true);
123
130
  // Unknown signals (users.info failure) fail toward the handshake.
124
131
  expect(isHandshakeOffered("slack", {})).toBe(true);
125
132
  expect(isHandshakeOffered("telegram", {})).toBe(true);
126
- expect(isHandshakeOffered("email", {})).toBe(true);
127
133
  });
128
134
  });
129
135
 
@@ -145,6 +151,16 @@ describe("introduction action lists", () => {
145
151
  }
146
152
  });
147
153
 
154
+ test("email sender: direct trust leads, no code option", () => {
155
+ const actions = buildIntroductionActions("email", {});
156
+ expect(actions.map((a) => a.id)).toEqual([
157
+ "trust",
158
+ "leave_unverified",
159
+ "block",
160
+ ]);
161
+ expect(actions[0].label).toBe("Trust");
162
+ });
163
+
148
164
  test("external: handshake leads, trust is 'Trust anyway'", () => {
149
165
  const actions = buildIntroductionActions("slack", { isStranger: true });
150
166
  expect(actions.map((a) => a.id)).toEqual([
@@ -31,6 +31,7 @@ import {
31
31
  VERIFIED_VIA_CHANNEL_CLAIM,
32
32
  VERIFIED_VIA_MANUAL,
33
33
  } from "@vellumai/gateway-client";
34
+ import type { GuardianActionEmphasis } from "@vellumai/service-contracts/guardian-requests";
34
35
 
35
36
  import type { ApprovalAction } from "./channel-approval-types.js";
36
37
 
@@ -194,14 +195,30 @@ export interface IntroductionActionOption {
194
195
  "trust" | "verify_code" | "leave_unverified" | "block"
195
196
  >;
196
197
  label: string;
197
- emphasis: "primary" | "secondary" | "destructive";
198
+ emphasis: GuardianActionEmphasis;
199
+ }
200
+
201
+ /**
202
+ * Whether this requester could ever complete the code handshake.
203
+ *
204
+ * A bot cannot return a code. An email sender cannot be sent one: approval
205
+ * has no delivery route for email, so the guardian would have to pass the
206
+ * code on outside the product, and the address the code would prove is
207
+ * already checked on every message (a `From:` that fails DMARC/DKIM reaches
208
+ * the runtime as a stranger).
209
+ */
210
+ export function requesterCanCompleteHandshake(
211
+ sourceChannel: string | undefined,
212
+ signals: RequesterIdentitySignals,
213
+ ): boolean {
214
+ return signals.isBot !== true && sourceChannel !== "email";
198
215
  }
199
216
 
200
217
  /**
201
218
  * Whether the verification handshake is offered for this requester.
202
219
  *
203
220
  * The handshake is the exception, not the default:
204
- * - never for bots/integrations — a bot cannot return a code;
221
+ * - never where it cannot complete (see {@link requesterCanCompleteHandshake});
205
222
  * - not for workspace-vouched identities — the platform already
206
223
  * authenticated them;
207
224
  * - not on voice — a phone call has no text handshake path;
@@ -211,7 +228,7 @@ export function isHandshakeOffered(
211
228
  sourceChannel: string | undefined,
212
229
  signals: RequesterIdentitySignals,
213
230
  ): boolean {
214
- if (signals.isBot === true) {
231
+ if (!requesterCanCompleteHandshake(sourceChannel, signals)) {
215
232
  return false;
216
233
  }
217
234
  if (sourceChannel === "phone") {
@@ -224,15 +241,16 @@ export function isHandshakeOffered(
224
241
  * Build the ordered introduction-card action list for a requester. The first
225
242
  * action is the emphasized default:
226
243
  *
227
- * workspace member / bot / voice: [ Trust ] [ Leave unverified ] [ Block ]
228
- * external / stranger / guest: [ Verify with a code ] [ Trust anyway ]
229
- * [ Leave unverified ] [ Block ]
244
+ * workspace member / bot / voice / email: [ Trust ] [ Leave unverified ] [ Block ]
245
+ * external / stranger / guest: [ Verify with a code ] [ Trust anyway ]
246
+ * [ Leave unverified ] [ Block ]
230
247
  *
231
248
  * `leave_unverified` is the silent "park" outcome: it leaves the sender an
232
249
  * `unverified` contact and never notifies the requester. It is NOT a guaranteed
233
250
  * keep-out — an `unverified` contact is still admitted under the permissive
234
251
  * admission floors (`any_contact`, `strangers`); the hard keep-out is `block`
235
- * (→ revoked). The code option is NEVER rendered for a bot.
252
+ * (→ revoked). The code option is never rendered where the handshake cannot
253
+ * complete (a bot, an email sender; see {@link requesterCanCompleteHandshake}).
236
254
  */
237
255
  export function buildIntroductionActions(
238
256
  sourceChannel: string | undefined,
@@ -28,6 +28,7 @@ import { pipeline } from "node:stream/promises";
28
28
  import { createGzip, gzipSync } from "node:zlib";
29
29
 
30
30
  import { sanitizeConfigForTransfer } from "../../config/sanitize-for-transfer.js";
31
+ import { trackDaemonActivity } from "../../daemon/activity-trail.js";
31
32
  import { getLogger } from "../../util/logger.js";
32
33
  import type { VBundleOriginMode } from "./origin-mode.js";
33
34
  import type {
@@ -1181,6 +1182,14 @@ export interface StreamExportVBundleResult {
1181
1182
  */
1182
1183
  export async function streamExportVBundle(
1183
1184
  options: BuildExportVBundleOptions,
1185
+ ): Promise<StreamExportVBundleResult> {
1186
+ return trackDaemonActivity({ kind: "vbundle_export" }, () =>
1187
+ streamExport(options),
1188
+ );
1189
+ }
1190
+
1191
+ async function streamExport(
1192
+ options: BuildExportVBundleOptions,
1184
1193
  ): Promise<StreamExportVBundleResult> {
1185
1194
  const {
1186
1195
  assistant,
@@ -123,7 +123,8 @@ function seedVellumConnection(): void {
123
123
 
124
124
  function persistedProfiles(): Record<string, unknown> {
125
125
  const llm = loadRawConfig().llm as
126
- { profiles?: Record<string, unknown> } | undefined;
126
+ | { profiles?: Record<string, unknown> }
127
+ | undefined;
127
128
  return llm?.profiles ?? {};
128
129
  }
129
130
 
@@ -742,6 +743,25 @@ describe("GET inference/profiles honors llm.defaultProvider", () => {
742
743
  expect(names.has("balanced")).toBe(true);
743
744
  });
744
745
 
746
+ test("lists profiles in profileOrder, then the rest alphabetically", async () => {
747
+ setConfig("llm", {
748
+ profiles: {
749
+ "zed-custom": { source: "user", provider: "anthropic" },
750
+ auto: { source: "managed" },
751
+ "alpha-custom": { source: "user", provider: "anthropic" },
752
+ },
753
+ profileOrder: ["auto", "balanced", "zed-custom"],
754
+ });
755
+ const listed = (await call("inference_profiles_list", {})) as {
756
+ profiles: Array<{ name: string }>;
757
+ };
758
+ const names = listed.profiles.map((profile) => profile.name);
759
+ expect(names.slice(0, 3)).toEqual(["auto", "balanced", "zed-custom"]);
760
+ const tail = names.slice(3);
761
+ expect(tail).toEqual([...tail].sort());
762
+ expect(tail).toContain("alpha-custom");
763
+ });
764
+
745
765
  test("expands balanced through a BYOK default provider, not the vellum column", async () => {
746
766
  setConfig("llm", {
747
767
  defaultProvider: { provider: "anthropic" },
@@ -405,6 +405,66 @@ describe("POST inference/provider-connections (create)", () => {
405
405
  expect(result.auth).toEqual({ type: "platform" });
406
406
  });
407
407
 
408
+ test("stores an openai-compatible row pointed at opencode.ai as provider opencode", async () => {
409
+ const created = (await call(
410
+ findHandler("inference_provider_connections_create"),
411
+ {
412
+ body: {
413
+ name: "opencode-go",
414
+ provider: "openai-compatible",
415
+ credential: "vault/opencode/key",
416
+ base_url: "https://opencode.ai/zen/go/v1",
417
+ models: [{ id: "mimo-v2.6-flash" }],
418
+ },
419
+ },
420
+ )) as { provider: string; baseUrl: string | null };
421
+ expect(created.provider).toBe("opencode");
422
+ expect(created.baseUrl).toBe("https://opencode.ai/zen/go/v1");
423
+
424
+ const lookalike = (await call(
425
+ findHandler("inference_provider_connections_create"),
426
+ {
427
+ body: {
428
+ name: "lookalike",
429
+ provider: "openai-compatible",
430
+ base_url: "https://opencode.ai.evil.example/v1",
431
+ models: [{ id: "m" }],
432
+ },
433
+ },
434
+ )) as { provider: string };
435
+ expect(lookalike.provider).toBe("openai-compatible");
436
+ });
437
+
438
+ test("rejects a keyless openai-compatible row pointed at opencode.ai", async () => {
439
+ await expect(
440
+ call(findHandler("inference_provider_connections_create"), {
441
+ body: {
442
+ name: "opencode-keyless",
443
+ provider: "openai-compatible",
444
+ base_url: "https://opencode.ai/zen/v1",
445
+ models: [{ id: "m" }],
446
+ },
447
+ }),
448
+ ).rejects.toThrow(/Provider "opencode" requires an API key/);
449
+ });
450
+
451
+ test("rejects repointing an existing openai-compatible row at opencode.ai", async () => {
452
+ await call(findHandler("inference_provider_connections_create"), {
453
+ body: {
454
+ name: "my-proxy",
455
+ provider: "openai-compatible",
456
+ base_url: "http://localhost:8080/v1",
457
+ models: [{ id: "m" }],
458
+ },
459
+ });
460
+ await expect(
461
+ call(findHandler("inference_provider_connections_update"), {
462
+ pathParams: { name: "my-proxy" },
463
+ body: { base_url: "https://opencode.ai/zen/v1" },
464
+ }),
465
+ ).rejects.toThrow(/needs an "opencode" connection/);
466
+ });
467
+
408
468
  test("rejects a whitespace-only label", async () => {
409
469
  await expect(
410
470
  call(findHandler("inference_provider_connections_create"), {