@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,190 @@
1
+ /**
2
+ * Recent work this process ran, so an event-loop block report can say what
3
+ * was running while the loop was blocked.
4
+ *
5
+ * The section trail (`persistence/slow-sync-log.ts`) names instrumented
6
+ * synchronous sections, which cover a small share of blocks. This trail
7
+ * records coarse units of work instead: every agent turn, labelled by
8
+ * conversation type, call site, and interface, plus the non-turn background
9
+ * jobs that run on the daemon (the scheduler tick, bundle export and import,
10
+ * the channel retry sweep, git history compaction). A block report groups
11
+ * the entries that overlap its window, which
12
+ * answers whether background work shared the loop with a user-facing turn.
13
+ *
14
+ * Labels are closed sets (no free-form strings), so the grouped result is
15
+ * safe to send as telemetry. The trail is per process; only the daemon
16
+ * reports it.
17
+ */
18
+
19
+ import type { InterfaceId } from "../channels/types.js";
20
+ import type { LLMCallSite } from "../config/schemas/llm.js";
21
+ import type { Conversation } from "./conversation.js";
22
+ import { resolveTurnCallSite } from "./turn-call-site.js";
23
+
24
+ export type DaemonActivityKind =
25
+ | "turn"
26
+ | "schedule_tick"
27
+ | "vbundle_export"
28
+ | "vbundle_import"
29
+ | "channel_retry_sweep"
30
+ | "git_compaction";
31
+
32
+ /** Conversation types a turn label carries; anything else is "other". */
33
+ const TURN_CONVERSATION_TYPES = new Set([
34
+ "standard",
35
+ "background",
36
+ "scheduled",
37
+ ]);
38
+
39
+ export interface DaemonActivityLabel {
40
+ kind: DaemonActivityKind;
41
+ /** Turns only: the conversation's type. */
42
+ conversationType?: "standard" | "background" | "scheduled" | "other";
43
+ /** Turns only: the LLM call site the turn runs under. */
44
+ callSite?: LLMCallSite;
45
+ /**
46
+ * Turns only: the interface of the message that started the turn, else
47
+ * the interface the conversation came from.
48
+ */
49
+ turnInterface?: InterfaceId;
50
+ /** Turns only: whether a client is attached and waiting on the reply. */
51
+ interactive?: boolean;
52
+ }
53
+
54
+ export interface DaemonActivityGroup extends DaemonActivityLabel {
55
+ /** Entries with this label that overlapped the window. */
56
+ count: number;
57
+ /** Of those, how many were still running at report time. */
58
+ running: number;
59
+ /** Longest single entry, clamped to the report time for running ones. */
60
+ longestMs: number;
61
+ }
62
+
63
+ interface ActivityMark {
64
+ label: DaemonActivityLabel;
65
+ startedAt: number;
66
+ endedAt?: number;
67
+ }
68
+
69
+ /**
70
+ * Ended entries are kept for this long, so a block of up to this length can
71
+ * still see the work that overlapped it, however much ended meanwhile.
72
+ */
73
+ const ENDED_MARK_RETENTION_MS = 30 * 60_000;
74
+ /** Hard cap on ended entries, bounding memory under a pathological burst. */
75
+ const MAX_ENDED_MARKS = 2_000;
76
+ /** Cap on groups in one report, keeping it inside the telemetry byte budget. */
77
+ const MAX_GROUPS = 10;
78
+
79
+ const runningMarks = new Set<ActivityMark>();
80
+ const endedMarks: ActivityMark[] = [];
81
+
82
+ /** Narrow a conversation's stored type to the closed label set. */
83
+ export function turnConversationType(
84
+ value: string | undefined,
85
+ ): DaemonActivityLabel["conversationType"] {
86
+ if (value === undefined) {
87
+ return "standard";
88
+ }
89
+ return TURN_CONVERSATION_TYPES.has(value)
90
+ ? (value as "standard" | "background" | "scheduled")
91
+ : "other";
92
+ }
93
+
94
+ /**
95
+ * The label for a turn about to run on `conversation`. Uses the same
96
+ * call-site default and interface precedence as the agent loop: the
97
+ * interface of the message that started the turn, else the conversation's
98
+ * origin interface.
99
+ */
100
+ export function turnActivityLabel(
101
+ conversation: Pick<
102
+ Conversation,
103
+ "conversationType" | "isSubagent" | "originInterface"
104
+ > & {
105
+ getTurnInterfaceContext(): { userMessageInterface?: InterfaceId } | null;
106
+ },
107
+ explicitCallSite: LLMCallSite | undefined,
108
+ isInteractive: boolean | undefined,
109
+ ): DaemonActivityLabel {
110
+ const turnInterface =
111
+ conversation.getTurnInterfaceContext()?.userMessageInterface ??
112
+ conversation.originInterface;
113
+ return {
114
+ kind: "turn",
115
+ conversationType: turnConversationType(conversation.conversationType),
116
+ callSite: resolveTurnCallSite(explicitCallSite, conversation),
117
+ ...(turnInterface ? { turnInterface } : {}),
118
+ interactive: isInteractive ?? false,
119
+ };
120
+ }
121
+
122
+ /** Run `fn` as a unit of tracked work. The mark closes however `fn` settles. */
123
+ export async function trackDaemonActivity<T>(
124
+ label: DaemonActivityLabel,
125
+ fn: () => Promise<T>,
126
+ ): Promise<T> {
127
+ const mark: ActivityMark = { label, startedAt: performance.now() };
128
+ runningMarks.add(mark);
129
+ try {
130
+ return await fn();
131
+ } finally {
132
+ mark.endedAt = performance.now();
133
+ runningMarks.delete(mark);
134
+ endedMarks.push(mark);
135
+ // Marks end in order, so the oldest are at the front.
136
+ const cutoff = mark.endedAt - ENDED_MARK_RETENTION_MS;
137
+ let expired = 0;
138
+ while (
139
+ expired < endedMarks.length &&
140
+ (endedMarks[expired]!.endedAt! < cutoff ||
141
+ endedMarks.length - expired > MAX_ENDED_MARKS)
142
+ ) {
143
+ expired++;
144
+ }
145
+ endedMarks.splice(0, expired);
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Work that overlapped the last `windowMs`, grouped by label, longest first.
151
+ * A mark overlaps when it started before `now` and had not ended before the
152
+ * window began.
153
+ */
154
+ export function getActivityOverlapping(
155
+ windowMs: number,
156
+ now: number = performance.now(),
157
+ ): DaemonActivityGroup[] {
158
+ const windowStart = now - windowMs;
159
+ const groups = new Map<string, DaemonActivityGroup>();
160
+ for (const mark of [...runningMarks, ...endedMarks]) {
161
+ const end = mark.endedAt ?? now;
162
+ if (mark.startedAt > now || end < windowStart) {
163
+ continue;
164
+ }
165
+ const key = JSON.stringify(mark.label);
166
+ const durationMs = Math.round(end - mark.startedAt);
167
+ const group = groups.get(key);
168
+ if (group) {
169
+ group.count++;
170
+ group.running += mark.endedAt === undefined ? 1 : 0;
171
+ group.longestMs = Math.max(group.longestMs, durationMs);
172
+ } else {
173
+ groups.set(key, {
174
+ ...mark.label,
175
+ count: 1,
176
+ running: mark.endedAt === undefined ? 1 : 0,
177
+ longestMs: durationMs,
178
+ });
179
+ }
180
+ }
181
+ return [...groups.values()]
182
+ .sort((a, b) => b.longestMs - a.longestMs)
183
+ .slice(0, MAX_GROUPS);
184
+ }
185
+
186
+ /** Test isolation only: the trail is process-global module state. */
187
+ export function resetActivityTrailForTests(): void {
188
+ runningMarks.clear();
189
+ endedMarks.length = 0;
190
+ }
@@ -0,0 +1,431 @@
1
+ /**
2
+ * Picks which default profile answers a turn that runs on the Auto profile.
3
+ *
4
+ * The agent loop asks TypeSafe's System One model (Jev) one choice question
5
+ * over the user's latest message, with the recent conversation for context,
6
+ * and pins the turn to the answer. Every other outcome (no managed Jev route,
7
+ * provider error, timeout, an answer naming no candidate) pins the turn to
8
+ * Balanced, which is also the Auto profile's own body, so a turn the router
9
+ * cannot judge runs exactly as a Balanced turn would.
10
+ */
11
+
12
+ import { getConversationProfilesForProvider } from "../config/default-profile-catalog.js";
13
+ import {
14
+ AUTO_PROFILE_KEY,
15
+ AUTO_PROFILE_ROUTER_CALL_SITE,
16
+ DEFAULT_PROFILE_KEYS,
17
+ type DefaultProfileKey,
18
+ isDefaultProfileKey,
19
+ } from "../config/default-profile-names.js";
20
+ import { getConfig } from "../config/loader.js";
21
+ import type { ProfileEntry } from "../config/schemas/llm.js";
22
+ import { getMessagesPaginated } from "../persistence/conversation-crud.js";
23
+ import { resolveConversationId } from "../persistence/conversation-key-store.js";
24
+ import { askTypesafe } from "../providers/jev/ask.js";
25
+ import type { ContentBlock, Message, Provider } from "../providers/types.js";
26
+ import { getLogger } from "../util/logger.js";
27
+ import { safeStringSlice } from "../util/unicode.js";
28
+
29
+ const log = getLogger("auto-profile-router");
30
+
31
+ export const AUTO_PROFILE_FALLBACK: DefaultProfileKey = "balanced";
32
+
33
+ /**
34
+ * The profile a turn runs on when the router cannot judge it: Balanced while
35
+ * it is a candidate, else the first candidate the user left enabled, else
36
+ * Balanced (the Auto body itself) when nothing is enabled.
37
+ */
38
+ export function autoProfileFallback(
39
+ candidates: readonly DefaultProfileKey[],
40
+ ): DefaultProfileKey {
41
+ if (candidates.includes(AUTO_PROFILE_FALLBACK)) {
42
+ return AUTO_PROFILE_FALLBACK;
43
+ }
44
+ return candidates[0] ?? AUTO_PROFILE_FALLBACK;
45
+ }
46
+
47
+ /**
48
+ * Budget before the turn proceeds on Balanced. The router runs before the
49
+ * turn's first provider call, so a Jev outage costs at most this much
50
+ * time-to-first-token per Auto turn and never blocks the reply. Jev's
51
+ * measured round trip sits well under it (the voice judge runs on 800ms).
52
+ */
53
+ export const AUTO_PROFILE_ROUTER_TIMEOUT_MS = 1_000;
54
+
55
+ const HISTORY_TURNS = 6;
56
+ const HISTORY_TURN_MAX_CHARS = 600;
57
+ const MESSAGE_MAX_CHARS = 4_000;
58
+
59
+ /**
60
+ * What each default profile is for, phrased so the options exclude each
61
+ * other. The picker copy on the profiles describes a tier to a person;
62
+ * these describe the kind of message that belongs on it.
63
+ */
64
+ const ROUTING_CRITERIA: Record<DefaultProfileKey, string> = {
65
+ balanced:
66
+ "Everyday requests: questions, drafting, summaries, ordinary coding, tasks that use tools. The choice when nothing else clearly applies.",
67
+ "quality-optimized":
68
+ "Hard problems: multi-step reasoning, subtle debugging, large or delicate code changes, careful analysis, writing where quality matters most.",
69
+ "cost-optimized":
70
+ "Simple, mechanical work: short factual answers, reformatting, extraction, small edits where a modest model is plenty.",
71
+ "latency-optimized":
72
+ "Quick conversational replies: greetings, acknowledgements, one-line answers where speed matters more than depth.",
73
+ };
74
+
75
+ const ROUTING_INSTRUCTIONS =
76
+ "Which model profile should answer the user's latest message? Judge the work the reply needs, using the recent conversation to interpret short follow-ups. Pick the cheapest profile that will still produce a good answer.";
77
+
78
+ export type AutoProfileRouteOutcome =
79
+ | "routed"
80
+ | "unavailable"
81
+ | "timeout"
82
+ | "error"
83
+ | "fallback";
84
+
85
+ export interface AutoProfileRoute {
86
+ profile: DefaultProfileKey;
87
+ outcome: AutoProfileRouteOutcome;
88
+ /** Jev's confidence in the pick, when it answered. */
89
+ confidence?: number;
90
+ latencyMs: number;
91
+ }
92
+
93
+ /** A message's spoken text: its text blocks minus injected `<...>` blocks. */
94
+ export function plainTextOf(content: readonly ContentBlock[]): string {
95
+ return content
96
+ .map((block) => (block.type === "text" ? block.text : ""))
97
+ .filter(
98
+ (text) => text.trim().length > 0 && !text.trimStart().startsWith("<"),
99
+ )
100
+ .join(" ")
101
+ .replace(/\s+/g, " ")
102
+ .trim();
103
+ }
104
+
105
+ /**
106
+ * The router's view of the conversation: the last few turns as plain text,
107
+ * without injected context blocks, tool traffic, or the current message
108
+ * (which the router receives on its own).
109
+ */
110
+ export function recentConversationForRouter(
111
+ history: readonly Message[],
112
+ userMessage: string,
113
+ ): string {
114
+ const lines: string[] = [];
115
+ for (const message of history) {
116
+ const text = plainTextOf(message.content);
117
+ if (text.length === 0) {
118
+ continue;
119
+ }
120
+ lines.push(
121
+ `${message.role}: ${safeStringSlice(text, 0, HISTORY_TURN_MAX_CHARS)}`,
122
+ );
123
+ }
124
+ const current = `user: ${userMessage.replace(/\s+/g, " ").trim()}`;
125
+ if (lines.length > 0 && lines[lines.length - 1] === current) {
126
+ lines.pop();
127
+ }
128
+ return lines.slice(-HISTORY_TURNS).join("\n");
129
+ }
130
+
131
+ /**
132
+ * The default profiles the router may pick from: the ones the conversation
133
+ * view offers and the user has not disabled.
134
+ */
135
+ export function autoProfileCandidates(
136
+ profiles: Readonly<Record<string, ProfileEntry>>,
137
+ ): DefaultProfileKey[] {
138
+ return DEFAULT_PROFILE_KEYS.filter((key) => {
139
+ const entry = profiles[key];
140
+ return entry != null && entry.status !== "disabled";
141
+ });
142
+ }
143
+
144
+ /**
145
+ * Route one turn. Never rejects: every failure returns the fallback profile.
146
+ */
147
+ export async function routeAutoProfile(args: {
148
+ conversationId: string;
149
+ history: readonly Message[];
150
+ userMessage: string;
151
+ profiles: Readonly<Record<string, ProfileEntry>>;
152
+ signal?: AbortSignal;
153
+ timeoutMs?: number;
154
+ /** Provider resolver, injectable for tests. */
155
+ resolveProvider?: () => Promise<Provider | null>;
156
+ }): Promise<AutoProfileRoute> {
157
+ const userMessage = args.userMessage.trim();
158
+ const candidates = autoProfileCandidates(args.profiles);
159
+ const fallback = autoProfileFallback(candidates);
160
+ // A choice needs two options; with fewer there is nothing to route.
161
+ if (userMessage.length === 0 || candidates.length < 2) {
162
+ return { profile: fallback, outcome: "fallback", latencyMs: 0 };
163
+ }
164
+ const criteria = Object.fromEntries(
165
+ candidates.map((key) => [
166
+ key,
167
+ `${args.profiles[key]?.label ?? key}: ${ROUTING_CRITERIA[key]}`,
168
+ ]),
169
+ );
170
+ const result = await askTypesafe({
171
+ callSite: AUTO_PROFILE_ROUTER_CALL_SITE,
172
+ conversationId: args.conversationId,
173
+ state: {
174
+ recent_conversation:
175
+ recentConversationForRouter(args.history, userMessage) ||
176
+ "(start of conversation)",
177
+ latest_user_message: safeStringSlice(userMessage, 0, MESSAGE_MAX_CHARS),
178
+ },
179
+ questions: {
180
+ profile: {
181
+ type: "choice",
182
+ instructions: ROUTING_INSTRUCTIONS,
183
+ criteria,
184
+ },
185
+ },
186
+ timeoutMs: args.timeoutMs ?? AUTO_PROFILE_ROUTER_TIMEOUT_MS,
187
+ ...(args.signal ? { signal: args.signal } : {}),
188
+ ...(args.resolveProvider ? { resolveProvider: args.resolveProvider } : {}),
189
+ });
190
+ if (result.outcome !== "answered") {
191
+ return {
192
+ profile: fallback,
193
+ outcome: result.outcome,
194
+ latencyMs: result.latencyMs,
195
+ };
196
+ }
197
+ const answer = result.answers?.profile;
198
+ const choice =
199
+ typeof answer === "object" && answer !== null && "choice" in answer
200
+ ? (answer as { choice?: unknown }).choice
201
+ : undefined;
202
+ const confidence =
203
+ typeof answer === "object" && answer !== null && "confidence" in answer
204
+ ? (answer as { confidence?: unknown }).confidence
205
+ : undefined;
206
+ if (
207
+ typeof choice !== "string" ||
208
+ !isDefaultProfileKey(choice) ||
209
+ !candidates.includes(choice)
210
+ ) {
211
+ log.warn(
212
+ { conversationId: args.conversationId, choice },
213
+ "Auto profile router answered with no candidate profile",
214
+ );
215
+ return { profile: fallback, outcome: "error", latencyMs: result.latencyMs };
216
+ }
217
+ // Argmax with no confidence floor. A floor belongs here if flat
218
+ // distributions turn out to send trivial messages to Quality.
219
+ return {
220
+ profile: choice,
221
+ outcome: "routed",
222
+ ...(typeof confidence === "number" ? { confidence } : {}),
223
+ latencyMs: result.latencyMs,
224
+ };
225
+ }
226
+
227
+ // ---------------------------------------------------------------------------
228
+ // Draft preview and send-time reuse
229
+ // ---------------------------------------------------------------------------
230
+
231
+ /**
232
+ * How long a draft preview stays reusable by the turn that sends the same
233
+ * text. Long enough to cover the pause between the preview and the send,
234
+ * short enough that a stale pick never outlives the draft it was made for.
235
+ */
236
+ export const AUTO_PROFILE_PREVIEW_REUSE_MS = 60_000;
237
+
238
+ /** Recent history rows the preview shows the router, matching the turn's window. */
239
+ const PREVIEW_HISTORY_ROWS = 12;
240
+
241
+ /** Cache key for a preview made before the conversation has a server id. */
242
+ const NO_CONVERSATION_KEY = "*";
243
+
244
+ interface RememberedPreview {
245
+ text: string;
246
+ /** What the router saw besides the text: the candidate set and the last
247
+ * line of recent history. A send whose context differs re-routes. */
248
+ context: string;
249
+ route: AutoProfileRoute;
250
+ at: number;
251
+ }
252
+
253
+ /**
254
+ * Bound on remembered previews. Abandoned drafts never get taken, so
255
+ * expiry alone would let the map grow with every conversation ever
256
+ * previewed; oldest entries go first once the bound is reached.
257
+ */
258
+ const MAX_REMEMBERED_PREVIEWS = 200;
259
+
260
+ const rememberedPreviews = new Map<string, RememberedPreview>();
261
+
262
+ function normalizeDraft(text: string): string {
263
+ return text.replace(/\s+/g, " ").trim();
264
+ }
265
+
266
+ /**
267
+ * The routing inputs other than the draft, reduced to a comparable string:
268
+ * which profiles were candidates, and the last line of history the router
269
+ * saw. Both sides (preview from persisted rows, turn from the live history)
270
+ * render history through `recentConversationForRouter`, so the last line
271
+ * agrees whenever the conversation has not moved.
272
+ */
273
+ export function autoProfilePreviewContext(
274
+ history: readonly Message[],
275
+ userMessage: string,
276
+ candidates: readonly DefaultProfileKey[],
277
+ ): string {
278
+ const rendered = recentConversationForRouter(history, userMessage);
279
+ const lastLine = rendered.slice(rendered.lastIndexOf("\n") + 1);
280
+ return `${candidates.join(",")}\u0000${lastLine}`;
281
+ }
282
+
283
+ function pruneRememberedPreviews(now: number): void {
284
+ for (const [key, entry] of rememberedPreviews) {
285
+ if (now - entry.at > AUTO_PROFILE_PREVIEW_REUSE_MS) {
286
+ rememberedPreviews.delete(key);
287
+ }
288
+ }
289
+ while (rememberedPreviews.size >= MAX_REMEMBERED_PREVIEWS) {
290
+ const oldest = rememberedPreviews.keys().next().value;
291
+ if (oldest === undefined) {
292
+ break;
293
+ }
294
+ rememberedPreviews.delete(oldest);
295
+ }
296
+ }
297
+
298
+ /**
299
+ * Keep a routed preview so the turn that sends the same text reuses it: one
300
+ * Jev call per message instead of two, and the reply's badge matches what
301
+ * the composer showed. Only a routed pick is kept; a fallback is worth
302
+ * retrying at send time.
303
+ */
304
+ export function rememberAutoProfilePreview(
305
+ conversationId: string | undefined,
306
+ text: string,
307
+ route: AutoProfileRoute,
308
+ context: string,
309
+ now: number = Date.now(),
310
+ ): void {
311
+ if (route.outcome !== "routed") {
312
+ return;
313
+ }
314
+ pruneRememberedPreviews(now);
315
+ rememberedPreviews.set(conversationId ?? NO_CONVERSATION_KEY, {
316
+ text: normalizeDraft(text),
317
+ context,
318
+ route,
319
+ at: now,
320
+ });
321
+ }
322
+
323
+ /**
324
+ * The remembered preview for this turn, consumed on read. It has to match
325
+ * the text and the routing context the turn would otherwise send to Jev.
326
+ * A preview made before the conversation existed saw an empty history, so
327
+ * it fits only a turn whose history is still empty: with no history and the
328
+ * same text and candidates, the two requests are identical.
329
+ */
330
+ export function takeAutoProfilePreview(args: {
331
+ conversationId: string;
332
+ text: string;
333
+ history: readonly Message[];
334
+ profiles: Readonly<Record<string, ProfileEntry>>;
335
+ now?: number;
336
+ }): AutoProfileRoute | undefined {
337
+ const now = args.now ?? Date.now();
338
+ const wanted = normalizeDraft(args.text);
339
+ const candidates = autoProfileCandidates(args.profiles);
340
+ const context = autoProfilePreviewContext(args.history, wanted, candidates);
341
+ const historyIsEmpty =
342
+ recentConversationForRouter(args.history, wanted).length === 0;
343
+ const keys = historyIsEmpty
344
+ ? [args.conversationId, NO_CONVERSATION_KEY]
345
+ : [args.conversationId];
346
+ for (const key of keys) {
347
+ const remembered = rememberedPreviews.get(key);
348
+ if (!remembered) {
349
+ continue;
350
+ }
351
+ if (now - remembered.at > AUTO_PROFILE_PREVIEW_REUSE_MS) {
352
+ rememberedPreviews.delete(key);
353
+ continue;
354
+ }
355
+ if (remembered.text === wanted && remembered.context === context) {
356
+ rememberedPreviews.delete(key);
357
+ return remembered.route;
358
+ }
359
+ }
360
+ return undefined;
361
+ }
362
+
363
+ /** For tests. */
364
+ export function clearAutoProfilePreviewsForTesting(): void {
365
+ rememberedPreviews.clear();
366
+ }
367
+
368
+ /**
369
+ * Recent conversational rows for the preview: the same window the turn sees,
370
+ * counted over rows that carry spoken text so tool traffic cannot crowd a
371
+ * short follow-up's context out of the page.
372
+ */
373
+ function recentHistoryFromDb(conversationId: string | undefined): Message[] {
374
+ const resolved = conversationId
375
+ ? resolveConversationId(conversationId)
376
+ : null;
377
+ if (!resolved) {
378
+ return [];
379
+ }
380
+ return getMessagesPaginated(
381
+ resolved,
382
+ PREVIEW_HISTORY_ROWS,
383
+ undefined,
384
+ (row) =>
385
+ (row.role === "user" || row.role === "assistant") &&
386
+ plainTextOf(row.content).length > 0,
387
+ ).messages.map((row) => ({
388
+ role: row.role as Message["role"],
389
+ content: row.content,
390
+ }));
391
+ }
392
+
393
+ /**
394
+ * Route a draft the user has not sent yet, so the composer can show the pick
395
+ * as they type. Returns null when the Auto profile is not available on this
396
+ * install; otherwise the same route a turn on the draft would get, remembered
397
+ * for that turn to reuse.
398
+ */
399
+ export async function previewAutoProfile(args: {
400
+ conversationId?: string;
401
+ text: string;
402
+ signal?: AbortSignal;
403
+ }): Promise<AutoProfileRoute | null> {
404
+ const { llm } = getConfig();
405
+ const profiles = getConversationProfilesForProvider(
406
+ llm.profiles,
407
+ llm.defaultProvider ?? null,
408
+ );
409
+ if (profiles[AUTO_PROFILE_KEY]?.source !== "managed") {
410
+ return null;
411
+ }
412
+ const history = recentHistoryFromDb(args.conversationId);
413
+ const route = await routeAutoProfile({
414
+ conversationId: args.conversationId ?? NO_CONVERSATION_KEY,
415
+ history,
416
+ userMessage: args.text,
417
+ profiles,
418
+ ...(args.signal ? { signal: args.signal } : {}),
419
+ });
420
+ rememberAutoProfilePreview(
421
+ args.conversationId,
422
+ args.text,
423
+ route,
424
+ autoProfilePreviewContext(
425
+ history,
426
+ normalizeDraft(args.text),
427
+ autoProfileCandidates(profiles),
428
+ ),
429
+ );
430
+ return route;
431
+ }
@@ -0,0 +1,81 @@
1
+ import { describe, expect, test } from "bun:test";
2
+
3
+ import sharp from "sharp";
4
+
5
+ import { parseImageDimensions } from "../context/image-dimensions.js";
6
+ import { prepareComputerUseObservation } from "./computer-use-observation.js";
7
+ import { HostCuProxy } from "./host-cu-proxy.js";
8
+
9
+ async function screenshot(width: number, height: number): Promise<string> {
10
+ const bytes = await sharp({
11
+ create: { width, height, channels: 3, background: "white" },
12
+ })
13
+ .jpeg()
14
+ .toBuffer();
15
+ return bytes.toString("base64");
16
+ }
17
+
18
+ describe("computer-use observation transport", () => {
19
+ test("derives metadata from emitted screenshot bytes", async () => {
20
+ const image = await screenshot(835, 540);
21
+ const observation = await prepareComputerUseObservation({
22
+ screenshot: image,
23
+ screenshotWidthPx: 1728,
24
+ screenshotHeightPx: 1117,
25
+ screenWidthPt: 1728,
26
+ screenHeightPt: 1117,
27
+ });
28
+
29
+ expect(observation.screenshot).toBe(image);
30
+ expect(observation.screenshotWidthPx).toBe(835);
31
+ expect(observation.screenshotHeightPx).toBe(540);
32
+ });
33
+
34
+ test("formats the optimized dimensions on the virtual desktop path", async () => {
35
+ const image = await screenshot(3200, 1800);
36
+ const proxy = new HostCuProxy();
37
+ const result = await proxy.executeLocal(
38
+ "computer_use_observe",
39
+ {},
40
+ async () => ({
41
+ screenshot: image,
42
+ screenshotWidthPx: 3200,
43
+ screenshotHeightPx: 1800,
44
+ screenWidthPt: 1600,
45
+ screenHeightPt: 900,
46
+ }),
47
+ );
48
+
49
+ const block = result.contentBlocks?.[0];
50
+ expect(block?.type).toBe("image");
51
+ if (block?.type !== "image" || block.source.type !== "base64") {
52
+ throw new Error("Expected screenshot bytes");
53
+ }
54
+ const dimensions = parseImageDimensions(block.source);
55
+ expect(dimensions).toEqual({ width: 1568, height: 882 });
56
+ const repeated = await prepareComputerUseObservation({
57
+ screenshot: block.source.data,
58
+ });
59
+ expect(repeated.screenshot).toBe(block.source.data);
60
+ expect(result.content).toContain("1568x882 px");
61
+ expect(result.content).toContain("x = round(image_x * 1.020408)");
62
+ expect(result.content).toContain("y = round(image_y * 1.020408)");
63
+ proxy.dispose();
64
+ });
65
+
66
+ test("does not trust dimension metadata when image bytes cannot be read", async () => {
67
+ const observation = await prepareComputerUseObservation({
68
+ screenshot: "invalid",
69
+ screenshotWidthPx: 800,
70
+ screenshotHeightPx: 600,
71
+ });
72
+
73
+ expect(observation.screenshotWidthPx).toBeUndefined();
74
+ expect(observation.screenshotHeightPx).toBeUndefined();
75
+ });
76
+
77
+ test("leaves observations without a screenshot alone", async () => {
78
+ const observation = { axTree: "[1] AXButton Save" };
79
+ expect(await prepareComputerUseObservation(observation)).toBe(observation);
80
+ });
81
+ });