nova-personal-agent-server 0.4.0 → 1.0.2

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 (327) hide show
  1. package/LICENSE +674 -201
  2. package/README.md +12 -2
  3. package/bin/nova-space-host.mjs +4 -0
  4. package/node_modules/@nova-personal-agent/relay/dist/src/cli.js +71 -0
  5. package/node_modules/@nova-personal-agent/relay/dist/src/client.js +340 -0
  6. package/node_modules/@nova-personal-agent/relay/dist/src/crypto.js +167 -0
  7. package/node_modules/@nova-personal-agent/relay/dist/src/live.js +169 -0
  8. package/node_modules/@nova-personal-agent/relay/dist/src/mailbox.js +217 -0
  9. package/node_modules/@nova-personal-agent/relay/dist/src/media.js +320 -0
  10. package/node_modules/@nova-personal-agent/relay/dist/src/pairing.js +13 -0
  11. package/node_modules/@nova-personal-agent/relay/dist/src/protocol.js +50 -0
  12. package/node_modules/@nova-personal-agent/relay/dist/src/security.js +305 -0
  13. package/node_modules/@nova-personal-agent/relay/dist/src/server.js +477 -0
  14. package/node_modules/@nova-personal-agent/relay/dist/src/source-address.js +58 -0
  15. package/node_modules/@nova-personal-agent/relay/package.json +1 -0
  16. package/package.json +13 -6
  17. package/runtime/dist/src/cascaded-text-provider.js +8 -3
  18. package/runtime/dist/src/composition/assembly.js +133 -35
  19. package/runtime/dist/src/composition/cascaded-realtime-assembly.js +114 -59
  20. package/runtime/dist/src/composition/production-composition.js +57 -21
  21. package/runtime/dist/src/composition/realtime-assembly.js +160 -52
  22. package/runtime/dist/src/composition/soul-context.js +22 -0
  23. package/runtime/dist/src/config/capability-registry.js +48 -3
  24. package/runtime/dist/src/config/cascaded-realtime-config.js +23 -10
  25. package/runtime/dist/src/config/config.js +541 -128
  26. package/runtime/dist/src/config/credential-rotation.js +26 -0
  27. package/runtime/dist/src/config/data-root.js +764 -0
  28. package/runtime/dist/src/config/diagnostics.js +3 -1
  29. package/runtime/dist/src/config/environment-contract.js +190 -188
  30. package/runtime/dist/src/config/model-routes.js +140 -0
  31. package/runtime/dist/src/config/voice-credentials.js +55 -0
  32. package/runtime/dist/src/connectors/composio/index.js +9 -0
  33. package/runtime/dist/src/connectors/feishu/index.js +258 -44
  34. package/runtime/dist/src/connectors/macos/mail.js +7 -3
  35. package/runtime/dist/src/connectors/macos/reader.js +3 -1
  36. package/runtime/dist/src/conversation-voice-provider.js +5 -2
  37. package/runtime/dist/src/core/causal-runtime.js +38 -3
  38. package/runtime/dist/src/core/context-view.js +7 -0
  39. package/runtime/dist/src/core/guards.js +32 -0
  40. package/runtime/dist/src/core/runtime.js +3 -0
  41. package/runtime/dist/src/core/schedule-tools.js +2 -2
  42. package/runtime/dist/src/core/source-processing-instructions.js +2 -2
  43. package/runtime/dist/src/core/source-processing-tools.js +3 -1
  44. package/runtime/dist/src/core/tool-schema.js +42 -7
  45. package/runtime/dist/src/desktop/desktop-camera.js +3 -5
  46. package/runtime/dist/src/desktop/desktop-control.js +41 -8
  47. package/runtime/dist/src/desktop/desktop-session.js +90 -19
  48. package/runtime/dist/src/desktop/desktop-wire.js +5 -7
  49. package/runtime/dist/src/desktop/startup-error.js +18 -16
  50. package/runtime/dist/src/desktop/workbench-acceptance.js +52 -14
  51. package/runtime/dist/src/desktop-entry.js +6 -2
  52. package/runtime/dist/src/desktop.js +5 -1
  53. package/runtime/dist/src/device/attempt.js +65 -0
  54. package/runtime/dist/src/device/authority.js +159 -0
  55. package/runtime/dist/src/device/gateway.js +87 -0
  56. package/runtime/dist/src/device/ledger.js +91 -0
  57. package/runtime/dist/src/device/ownership.js +92 -0
  58. package/runtime/dist/src/device/port.js +2 -0
  59. package/runtime/dist/src/device/schedule-ownership.js +103 -0
  60. package/runtime/dist/src/executors/acp/transport.js +2 -0
  61. package/runtime/dist/src/executors/browser.js +4 -3
  62. package/runtime/dist/src/executors/codex/adapter-project.js +58 -12
  63. package/runtime/dist/src/executors/codex/app-server-schema.js +12 -21
  64. package/runtime/dist/src/executors/codex/app-server-transport.js +32 -18
  65. package/runtime/dist/src/executors/codex/common.js +1 -1
  66. package/runtime/dist/src/executors/codex/contract.js +12 -16
  67. package/runtime/dist/src/executors/codex/credential-snapshot.js +1 -9
  68. package/runtime/dist/src/executors/codex/factory.js +54 -32
  69. package/runtime/dist/src/executors/codex/host-config.js +69 -20
  70. package/runtime/dist/src/executors/codex/launch-profile.js +3 -2
  71. package/runtime/dist/src/executors/codex/local-provider-credential.js +39 -0
  72. package/runtime/dist/src/executors/codex/process-owner.js +4 -6
  73. package/runtime/dist/src/executors/codex/production-host.js +33 -34
  74. package/runtime/dist/src/executors/codex/protocol.js +9 -14
  75. package/runtime/dist/src/executors/codex/session-title.js +6 -8
  76. package/runtime/dist/src/executors/codex/spawn-env.js +27 -6
  77. package/runtime/dist/src/executors/codex/turn-projection.js +12 -17
  78. package/runtime/dist/src/executors/codex/windows-guardian.js +4 -6
  79. package/runtime/dist/src/executors/coding/intake.js +12 -7
  80. package/runtime/dist/src/executors/computer-backend.js +18 -10
  81. package/runtime/dist/src/executors/computer-config.js +32 -0
  82. package/runtime/dist/src/executors/computer-device.js +68 -16
  83. package/runtime/dist/src/executors/computer-worker.js +18 -6
  84. package/runtime/dist/src/executors/computer.js +29 -56
  85. package/runtime/dist/src/executors/device-lock.js +14 -5
  86. package/runtime/dist/src/executors/gui-execution.js +2 -0
  87. package/runtime/dist/src/executors/index.js +0 -1
  88. package/runtime/dist/src/executors/mobile.js +9 -8
  89. package/runtime/dist/src/executors/native-process.js +4 -0
  90. package/runtime/dist/src/executors/search.js +3 -5
  91. package/runtime/dist/src/executors/task-resources.js +21 -0
  92. package/runtime/dist/src/executors/watcher.js +2 -4
  93. package/runtime/dist/src/experience/host.js +179 -0
  94. package/runtime/dist/src/index.js +2 -0
  95. package/runtime/dist/src/knowledge/assembly.js +3 -4
  96. package/runtime/dist/src/knowledge/embeddings.js +50 -34
  97. package/runtime/dist/src/knowledge/service.js +1 -0
  98. package/runtime/dist/src/knowledge/store-client.js +1 -6
  99. package/runtime/dist/src/knowledge/store-worker.js +1 -3
  100. package/runtime/dist/src/mem0/resource.js +25 -0
  101. package/runtime/dist/src/mem0/store-worker.js +234 -21
  102. package/runtime/dist/src/memory/consumer.js +31 -0
  103. package/runtime/dist/src/memory/engine-worker.js +210 -0
  104. package/runtime/dist/src/memory/entry.js +8 -1
  105. package/runtime/dist/src/memory/explicit-memory.js +20 -0
  106. package/runtime/dist/src/memory/factory.js +30 -15
  107. package/runtime/dist/src/memory/grounded-voicemem.js +10 -0
  108. package/runtime/dist/src/memory/ledger-recall-engine.js +86 -0
  109. package/runtime/dist/src/memory/prerecall-port.js +27 -0
  110. package/runtime/dist/src/memory/prerecall.js +1 -1
  111. package/runtime/dist/src/memory/production-engine.js +151 -0
  112. package/runtime/dist/src/memory/provenance.js +1 -0
  113. package/runtime/dist/src/memory/remote-personal-memory.js +3 -1
  114. package/runtime/dist/src/memory/retrieval.js +107 -22
  115. package/runtime/dist/src/memory/sensitivity.js +6 -2
  116. package/runtime/dist/src/memory/source-retrieval.js +11 -0
  117. package/runtime/dist/src/memory/tool-capabilities.js +46 -0
  118. package/runtime/dist/src/memory/voicemem-sdk/LICENSE +202 -0
  119. package/runtime/dist/src/memory/voicemem-sdk/NOTICE.md +97 -0
  120. package/runtime/dist/src/memory/voicemem-sdk/PATCH-NOTICE.md +23 -0
  121. package/runtime/dist/src/memory/voicemem-sdk/archive.js +12 -0
  122. package/runtime/dist/src/memory/voicemem-sdk/audio.js +111 -0
  123. package/runtime/dist/src/memory/voicemem-sdk/barge-in.js +59 -0
  124. package/runtime/dist/src/memory/voicemem-sdk/checkpoint.js +56 -0
  125. package/runtime/dist/src/memory/voicemem-sdk/cleanup.js +139 -0
  126. package/runtime/dist/src/memory/voicemem-sdk/dashscope-asr.js +254 -0
  127. package/runtime/dist/src/memory/voicemem-sdk/dashscope-tts.js +247 -0
  128. package/runtime/dist/src/memory/voicemem-sdk/evaluation.js +330 -0
  129. package/runtime/dist/src/memory/voicemem-sdk/extraction.js +220 -0
  130. package/runtime/dist/src/memory/voicemem-sdk/finetune-data.js +115 -0
  131. package/runtime/dist/src/memory/voicemem-sdk/finetune.js +170 -0
  132. package/runtime/dist/src/memory/voicemem-sdk/grounded-reply-preferences.js +81 -0
  133. package/runtime/dist/src/memory/voicemem-sdk/index.js +22 -0
  134. package/runtime/dist/src/memory/voicemem-sdk/local-embedding.js +164 -0
  135. package/runtime/dist/src/memory/voicemem-sdk/local-runtime.js +53 -0
  136. package/runtime/dist/src/memory/voicemem-sdk/local-speaker.js +240 -0
  137. package/runtime/dist/src/memory/voicemem-sdk/memory.js +767 -0
  138. package/runtime/dist/src/memory/voicemem-sdk/model-json.js +14 -0
  139. package/runtime/dist/src/memory/voicemem-sdk/personamem.js +209 -0
  140. package/runtime/dist/src/memory/voicemem-sdk/prompts/addenda.js +215 -0
  141. package/runtime/dist/src/memory/voicemem-sdk/prompts/additive-extraction.js +478 -0
  142. package/runtime/dist/src/memory/voicemem-sdk/prompts/index.js +32 -0
  143. package/runtime/dist/src/memory/voicemem-sdk/prompts/update-memory.js +152 -0
  144. package/runtime/dist/src/memory/voicemem-sdk/providers.js +325 -0
  145. package/runtime/dist/src/memory/voicemem-sdk/ranking.js +65 -0
  146. package/runtime/dist/src/memory/voicemem-sdk/reaction.js +33 -0
  147. package/runtime/dist/src/memory/voicemem-sdk/realtime.js +215 -0
  148. package/runtime/dist/src/memory/voicemem-sdk/reply.js +68 -0
  149. package/runtime/dist/src/memory/voicemem-sdk/routing.js +209 -0
  150. package/runtime/dist/src/memory/voicemem-sdk/slots.js +61 -0
  151. package/runtime/dist/src/memory/voicemem-sdk/speaker-bindings.js +120 -0
  152. package/runtime/dist/src/memory/voicemem-sdk/speaker-profiles.js +327 -0
  153. package/runtime/dist/src/memory/voicemem-sdk/store.js +577 -0
  154. package/runtime/dist/src/memory/voicemem-sdk/stream.js +317 -0
  155. package/runtime/dist/src/memory/voicemem-sdk/subgraph.js +113 -0
  156. package/runtime/dist/src/memory/voicemem-sdk/summaries.js +56 -0
  157. package/runtime/dist/src/memory/voicemem-sdk/time.js +157 -0
  158. package/runtime/dist/src/memory/voicemem-sdk/types.js +2 -0
  159. package/runtime/dist/src/memory-ledger/store-client.js +235 -37
  160. package/runtime/dist/src/memory-ledger/store-worker.js +8 -5
  161. package/runtime/dist/src/memory-ledger/store.js +91 -1
  162. package/runtime/dist/src/memory-substrate/consolidation.js +23 -7
  163. package/runtime/dist/src/memory-substrate/diary.js +27 -0
  164. package/runtime/dist/src/memory-substrate/engine-outbox.js +107 -0
  165. package/runtime/dist/src/memory-substrate/explicit-memory.js +112 -0
  166. package/runtime/dist/src/memory-substrate/fact-fidelity.js +68 -0
  167. package/runtime/dist/src/memory-substrate/feishu-consent.js +41 -0
  168. package/runtime/dist/src/memory-substrate/file-authority.js +29 -6
  169. package/runtime/dist/src/memory-substrate/life-operations.js +35 -9
  170. package/runtime/dist/src/memory-substrate/markdown-repository.js +271 -65
  171. package/runtime/dist/src/memory-substrate/memory-documents.js +96 -0
  172. package/runtime/dist/src/memory-substrate/migration.js +2 -0
  173. package/runtime/dist/src/memory-substrate/purge.js +12 -2
  174. package/runtime/dist/src/memory-substrate/resource.js +514 -129
  175. package/runtime/dist/src/memory-substrate/retrieval.js +8 -5
  176. package/runtime/dist/src/memory-substrate/source-operations.js +9 -1
  177. package/runtime/dist/src/memory-substrate/source-processing.js +436 -40
  178. package/runtime/dist/src/memory-substrate/source-retrieval.js +28 -0
  179. package/runtime/dist/src/memory-substrate/source-state.js +8 -0
  180. package/runtime/dist/src/memory-substrate/space-source-input.js +90 -0
  181. package/runtime/dist/src/memory-substrate/store.js +125 -23
  182. package/runtime/dist/src/model/goal-checkin-writer.js +72 -0
  183. package/runtime/dist/src/model/goal-writer.js +80 -0
  184. package/runtime/dist/src/model/jev-client.js +24 -13
  185. package/runtime/dist/src/model/model-adapters.js +2 -3
  186. package/runtime/dist/src/model/model-catalog.js +80 -0
  187. package/runtime/dist/src/model/model-gateway.js +47 -18
  188. package/runtime/dist/src/model/model-purpose.js +3 -4
  189. package/runtime/dist/src/model/personal-writer.js +536 -44
  190. package/runtime/dist/src/model/proactivity.js +50 -6
  191. package/runtime/dist/src/model/responses-model-gateway.js +59 -0
  192. package/runtime/dist/src/model/task-verifier.js +3 -3
  193. package/runtime/dist/src/model/timeline-anchors.js +77 -0
  194. package/runtime/dist/src/model/timeline-perspective.js +13 -0
  195. package/runtime/dist/src/model/timeline-selection.js +182 -0
  196. package/runtime/dist/src/model/understanding-writer.js +27 -0
  197. package/runtime/dist/src/model/vision-capability.js +3 -1
  198. package/runtime/dist/src/model/workbench-writer.js +96 -0
  199. package/runtime/dist/src/news/feeds.js +6 -10
  200. package/runtime/dist/src/news/interests.js +23 -0
  201. package/runtime/dist/src/news/service.js +87 -31
  202. package/runtime/dist/src/news/sources.json +116 -0
  203. package/runtime/dist/src/notifications/adapters/space-relay.js +4 -0
  204. package/runtime/dist/src/notifications/content.js +41 -0
  205. package/runtime/dist/src/notifications/contracts.js +4 -2
  206. package/runtime/dist/src/notifications/feed.js +6 -2
  207. package/runtime/dist/src/notifications/service.js +27 -14
  208. package/runtime/dist/src/notifications/store.js +3 -1
  209. package/runtime/dist/src/personal-agent/app-context.js +39 -4
  210. package/runtime/dist/src/personal-agent/chat-failure.js +37 -0
  211. package/runtime/dist/src/personal-agent/computer-use/contract.js +42 -0
  212. package/runtime/dist/src/personal-agent/computer-use/session.js +280 -0
  213. package/runtime/dist/src/personal-agent/computer-use/skill.js +18 -0
  214. package/runtime/dist/src/personal-agent/computer-use/tools.js +15 -0
  215. package/runtime/dist/src/personal-agent/context-candidates.js +9 -13
  216. package/runtime/dist/src/personal-agent/context-dependencies.js +28 -0
  217. package/runtime/dist/src/personal-agent/contracts.js +24 -4
  218. package/runtime/dist/src/personal-agent/conversation-runtime.js +440 -42
  219. package/runtime/dist/src/personal-agent/conversation-tool-bridge.js +97 -0
  220. package/runtime/dist/src/personal-agent/conversation-tool-policy.js +22 -0
  221. package/runtime/dist/src/personal-agent/conversations.js +71 -15
  222. package/runtime/dist/src/personal-agent/daily-brief.js +5 -0
  223. package/runtime/dist/src/personal-agent/daily-workbench.js +558 -0
  224. package/runtime/dist/src/personal-agent/discovery-window.js +36 -0
  225. package/runtime/dist/src/personal-agent/goal-checkin.js +53 -0
  226. package/runtime/dist/src/personal-agent/host.js +2379 -223
  227. package/runtime/dist/src/personal-agent/identity-context.js +33 -0
  228. package/runtime/dist/src/personal-agent/life.js +129 -11
  229. package/runtime/dist/src/personal-agent/local-shell.js +181 -0
  230. package/runtime/dist/src/personal-agent/local-tools.js +234 -0
  231. package/runtime/dist/src/personal-agent/preferred-name-sync.js +35 -0
  232. package/runtime/dist/src/personal-agent/profile-warmup.js +100 -39
  233. package/runtime/dist/src/personal-agent/project-digests.js +7 -3
  234. package/runtime/dist/src/personal-agent/project-history.js +36 -0
  235. package/runtime/dist/src/personal-agent/reading-copies.js +183 -0
  236. package/runtime/dist/src/personal-agent/scheduled-tasks.js +50 -13
  237. package/runtime/dist/src/personal-agent/scheduled-tool-runtime.js +26 -10
  238. package/runtime/dist/src/personal-agent/source-processing-agent.js +239 -17
  239. package/runtime/dist/src/personal-agent/sources.js +9 -1
  240. package/runtime/dist/src/personal-agent/store.js +124 -14
  241. package/runtime/dist/src/personal-agent/task-loop.js +3 -0
  242. package/runtime/dist/src/personal-agent/tasks.js +16 -4
  243. package/runtime/dist/src/personal-agent/timeline-brief.js +462 -0
  244. package/runtime/dist/src/personal-agent/timeline-cache.js +191 -0
  245. package/runtime/dist/src/personal-agent/timeline-cluster.js +30 -0
  246. package/runtime/dist/src/personal-agent/timeline-inputs.js +47 -0
  247. package/runtime/dist/src/personal-agent/timeline-time.js +60 -0
  248. package/runtime/dist/src/personal-agent/understanding-products.js +49 -0
  249. package/runtime/dist/src/personal-agent/understanding.js +7 -22
  250. package/runtime/dist/src/personal-agent/workbench-context.js +17 -21
  251. package/runtime/dist/src/personal-agent/workbench-copy.js +124 -0
  252. package/runtime/dist/src/personal-agent/workbench-evidence.js +77 -0
  253. package/runtime/dist/src/personal-agent/workbench-instructions.js +21 -0
  254. package/runtime/dist/src/personal-agent/workbench-runtime.js +1006 -0
  255. package/runtime/dist/src/personal-agent/workbench-shell-class.js +304 -0
  256. package/runtime/dist/src/personal-agent/workbench-store.js +292 -0
  257. package/runtime/dist/src/personal-agent/workbench-temporal.js +66 -0
  258. package/runtime/dist/src/projects/project-native-resource.js +10 -8
  259. package/runtime/dist/src/projects/project-store.js +36 -4
  260. package/runtime/dist/src/realtime/bridge.js +77 -8
  261. package/runtime/dist/src/realtime/capabilities.js +19 -0
  262. package/runtime/dist/src/realtime/cascaded/adapter.js +180 -40
  263. package/runtime/dist/src/realtime/cascaded/ark-llm.js +150 -24
  264. package/runtime/dist/src/realtime/cascaded/chat-completions-llm.js +243 -83
  265. package/runtime/dist/src/realtime/cascaded/llm-stream-limits.js +18 -0
  266. package/runtime/dist/src/realtime/cascaded/llm.js +96 -0
  267. package/runtime/dist/src/realtime/cascaded/openai-compatible-speech.js +251 -0
  268. package/runtime/dist/src/realtime/cascaded/provider.js +8 -0
  269. package/runtime/dist/src/realtime/evidence.js +1 -1
  270. package/runtime/dist/src/realtime/frontend-instructions.js +76 -55
  271. package/runtime/dist/src/realtime/gemini.js +14 -3
  272. package/runtime/dist/src/realtime/host-delivery.js +37 -4
  273. package/runtime/dist/src/realtime/protocol.js +18 -3
  274. package/runtime/dist/src/realtime/provider-projection.js +4 -1
  275. package/runtime/dist/src/realtime/provider-session.js +73 -16
  276. package/runtime/dist/src/realtime/qwen-transport.js +35 -4
  277. package/runtime/dist/src/realtime/qwen.js +144 -9
  278. package/runtime/dist/src/realtime/service-state.js +0 -1
  279. package/runtime/dist/src/realtime/service.js +93 -7
  280. package/runtime/dist/src/realtime/session.js +39 -32
  281. package/runtime/dist/src/realtime/sglang-native.js +214 -0
  282. package/runtime/dist/src/realtime/system-prompts.en.js +14 -2
  283. package/runtime/dist/src/realtime/telemetry.js +6 -3
  284. package/runtime/dist/src/realtime/tool-continuations.js +84 -7
  285. package/runtime/dist/src/realtime/transport.js +17 -0
  286. package/runtime/dist/src/realtime/usage.js +33 -17
  287. package/runtime/dist/src/realtime/volcengine/ark.js +40 -15
  288. package/runtime/dist/src/realtime/volcengine/asr.js +2 -1
  289. package/runtime/dist/src/realtime/volcengine/silence-endpointing.js +1 -7
  290. package/runtime/dist/src/realtime/volcengine/tts.js +2 -1
  291. package/runtime/dist/src/server/aoq-chat-server.js +1 -1
  292. package/runtime/dist/src/server/client-server.js +21 -0
  293. package/runtime/dist/src/server-entry.js +3 -0
  294. package/runtime/dist/src/space-host/admin-socket.js +115 -0
  295. package/runtime/dist/src/space-host/audio-owner.js +44 -0
  296. package/runtime/dist/src/space-host/cli.js +195 -0
  297. package/runtime/dist/src/space-host/config.js +247 -0
  298. package/runtime/dist/src/space-host/context-input.js +12 -0
  299. package/runtime/dist/src/space-host/contracts.js +10 -0
  300. package/runtime/dist/src/space-host/host-admin.js +114 -0
  301. package/runtime/dist/src/space-host/key-delivery.js +28 -0
  302. package/runtime/dist/src/space-host/mobile-tools.js +9 -0
  303. package/runtime/dist/src/space-host/model-settings.js +213 -0
  304. package/runtime/dist/src/space-host/projection.js +37 -0
  305. package/runtime/dist/src/space-host/push.js +137 -0
  306. package/runtime/dist/src/space-host/relay-transport.js +55 -0
  307. package/runtime/dist/src/space-host/service.js +841 -0
  308. package/runtime/dist/src/space-host/voice-crypto.js +240 -0
  309. package/runtime/dist/src/space-host/voice.js +600 -0
  310. package/runtime/dist/src/space-host/windows-secret-key.js +82 -0
  311. package/runtime/dist/src/storage/private-database.js +7 -10
  312. package/runtime/dist/src/text/unicode-normalize.js +5 -1
  313. package/runtime/dist/src/understanding/candidates.js +8 -10
  314. package/runtime/dist/src/understanding/fixture.js +1 -1
  315. package/runtime/dist/src/understanding/pipeline.js +4 -4
  316. package/runtime/dist/src/usage/context.js +23 -0
  317. package/runtime/dist/src/usage/index.js +4 -0
  318. package/runtime/dist/src/usage/ledger-worker.js +90 -0
  319. package/runtime/dist/src/usage/ledger.js +74 -0
  320. package/runtime/dist/src/usage/model-call.js +63 -0
  321. package/runtime/dist/src/usage/pricing.js +68 -0
  322. package/runtime/dist/src/usage/summary.js +69 -0
  323. package/runtime/dist/src/voicemem/store-client.js +104 -21
  324. package/runtime/dist/src/voicemem/store-worker.js +5 -8
  325. package/runtime/dist/src/voicemem/versioned-memory.js +1 -1
  326. package/src/command.mjs +8 -1
  327. package/runtime/dist/src/executors/autoglm.js +0 -376
@@ -8,6 +8,7 @@ import { codePointLengthLikePython, stripLikePython } from '../../text/python-te
8
8
  import { MAX_REALTIME_PCM_BYTES, MAX_REALTIME_TEXT, hostContextItemSchema, hostResponseIntentSchema, realtimeIdentifierSchema, realtimeProviderEventSchema, responseAdaptationContextSchema, workspaceContextInjectionSchema, } from '../protocol.js';
9
9
  import { NullTelemetry } from '../telemetry.js';
10
10
  import { StreamingSpeech } from '../streaming-speech.js';
11
+ import { throwIfAborted } from '../../core/guards.js';
11
12
  export const MAX_CASCADED_EVENT_QUEUE = 4_096;
12
13
  export const MAX_CASCADED_QUEUED_AUDIO_BYTES = 16 * 1_024 * 1_024;
13
14
  export const MAX_CASCADED_PENDING_HOST_ITEMS = 256;
@@ -28,6 +29,11 @@ export class CascadedRealtimeError extends Error {
28
29
  }
29
30
  }
30
31
  class MixedResponseFailure extends Error {
32
+ constructor(message = 'LLM mixed text and tool output') {
33
+ super(message);
34
+ this.name = 'MixedResponseFailure';
35
+ this.code = 'protocol';
36
+ }
31
37
  }
32
38
  class TtsResponseFailure extends Error {
33
39
  }
@@ -168,6 +174,8 @@ export class CascadedRealtimeAdapter {
168
174
  #llm;
169
175
  #llmFactory;
170
176
  #prerecall;
177
+ #prerecallPolicy;
178
+ #prerecallMeta;
171
179
  #captureFrame;
172
180
  #telemetry;
173
181
  #idFactory;
@@ -197,6 +205,8 @@ export class CascadedRealtimeAdapter {
197
205
  this.#llm = options.llm;
198
206
  this.#llmFactory = options.llmFactory;
199
207
  this.#prerecall = options.prerecall;
208
+ this.#prerecallPolicy = { minChars: 6, partialIntervalMs: 300, speculativeBudgetMs: 1500, finalWaitMs: 250, ...options.prerecallPolicy };
209
+ this.#prerecallMeta = Object.fromEntries(Object.entries(options.prerecallMeta ?? {}).filter(([, value]) => ['remote', 'local', 'none'].includes(value)));
200
210
  this.#captureFrame = options.captureFrame;
201
211
  this.#telemetry = options.telemetry ?? new NullTelemetry();
202
212
  this.#idFactory = options.idFactory ?? randomUUID;
@@ -240,6 +250,8 @@ export class CascadedRealtimeAdapter {
240
250
  abandonedCalls: new Map(),
241
251
  workspaceContext: null,
242
252
  prerecall: null,
253
+ prerecallLastStartAt: 0,
254
+ prerecallPendingPartial: null,
243
255
  responseAdaptation: null,
244
256
  consumptionGeneration: 0,
245
257
  responseSequence: 0,
@@ -252,6 +264,10 @@ export class CascadedRealtimeAdapter {
252
264
  revoked: false,
253
265
  };
254
266
  this.#owner = owner;
267
+ if (this.#prerecall) {
268
+ const current = owner;
269
+ owner.controller.signal.addEventListener('abort', () => this.#clearPartialPrerecall(current), { once: true });
270
+ }
255
271
  if (this.#initialHistory !== undefined) {
256
272
  if (!llm.restoreHistory)
257
273
  throw new CascadedRealtimeError('configuration');
@@ -680,6 +696,12 @@ export class CascadedRealtimeAdapter {
680
696
  session, controller, speechId, itemId,
681
697
  task: Promise.resolve(), speechEnded: false, failed: false,
682
698
  };
699
+ if (this.#prerecall) {
700
+ this.#clearPartialPrerecall(owner);
701
+ owner.prerecall?.controller.abort();
702
+ owner.prerecall = null;
703
+ owner.prerecallLastStartAt = 0;
704
+ }
683
705
  owner.asr = active;
684
706
  active.task = this.#consumeAsr(owner, active);
685
707
  void active.task.catch(() => undefined);
@@ -729,6 +751,8 @@ export class CascadedRealtimeAdapter {
729
751
  await active.session.finish(combineSignals(signal, active.controller.signal));
730
752
  }
731
753
  catch {
754
+ active.failed = true;
755
+ this.#clearPartialPrerecall(owner);
732
756
  await this.#emit(owner, {
733
757
  kind: 'provider_error', session_epoch: owner.epoch,
734
758
  code: 'cascaded_asr_finish', recoverable: true,
@@ -752,6 +776,8 @@ export class CascadedRealtimeAdapter {
752
776
  throw new Error('ASR transcript is too large');
753
777
  }
754
778
  if (transcript.final) {
779
+ if (this.#prerecall)
780
+ this.#clearPartialPrerecall(owner);
755
781
  finalSeen = true;
756
782
  this.#record('cascaded.asr.final', { epoch: owner.epoch });
757
783
  if (stripLikePython(transcript.text) === '') {
@@ -770,8 +796,7 @@ export class CascadedRealtimeAdapter {
770
796
  }
771
797
  else {
772
798
  this.#record('cascaded.asr.partial', { epoch: owner.epoch });
773
- if (transcript.text.length >= 6)
774
- void this.#prepareRecall(owner, active.itemId, transcript.text);
799
+ this.#schedulePartialPrerecall(owner, active.itemId, transcript.text);
775
800
  await this.#emit(owner, {
776
801
  kind: 'user_transcript_delta', session_epoch: owner.epoch,
777
802
  item_id: active.itemId, text: transcript.text,
@@ -787,6 +812,7 @@ export class CascadedRealtimeAdapter {
787
812
  if (this.#isCurrent(owner) && owner.asr === active
788
813
  && !active.controller.signal.aborted && !owner.controller.signal.aborted) {
789
814
  active.failed = true;
815
+ this.#clearPartialPrerecall(owner);
790
816
  await this.#emit(owner, {
791
817
  kind: 'provider_error', session_epoch: owner.epoch,
792
818
  code: 'cascaded_asr_receive', recoverable: true,
@@ -807,6 +833,8 @@ export class CascadedRealtimeAdapter {
807
833
  const active = owner.asr;
808
834
  if (active === null)
809
835
  return;
836
+ active.failed = true;
837
+ this.#clearPartialPrerecall(owner);
810
838
  if (!active.speechEnded) {
811
839
  active.speechEnded = true;
812
840
  await this.#emit(owner, {
@@ -823,6 +851,7 @@ export class CascadedRealtimeAdapter {
823
851
  await this.#discardAsr(owner);
824
852
  }
825
853
  async #discardAsr(owner) {
854
+ this.#clearPartialPrerecall(owner);
826
855
  const active = owner.asr;
827
856
  if (active === null)
828
857
  return;
@@ -893,20 +922,65 @@ export class CascadedRealtimeAdapter {
893
922
  });
894
923
  void active.task.catch(() => undefined);
895
924
  }
896
- #prepareRecall(owner, itemId, query) {
925
+ #clearPartialPrerecall(owner) {
926
+ if (owner.prerecallPendingPartial)
927
+ clearTimeout(owner.prerecallPendingPartial.timer);
928
+ owner.prerecallPendingPartial = null;
929
+ }
930
+ #schedulePartialPrerecall(owner, itemId, text) {
931
+ const active = owner.asr;
932
+ if (!this.#prerecall || active?.itemId !== itemId || active.failed || active.controller.signal.aborted)
933
+ return;
934
+ if (owner.prerecall?.itemId !== itemId) {
935
+ this.#clearPartialPrerecall(owner);
936
+ owner.prerecall?.controller.abort();
937
+ owner.prerecall = null;
938
+ owner.prerecallLastStartAt = 0;
939
+ }
940
+ if (text.length < this.#prerecallPolicy.minChars) {
941
+ this.#clearPartialPrerecall(owner);
942
+ return;
943
+ }
944
+ const now = performance.now();
945
+ const remaining = this.#prerecallPolicy.partialIntervalMs - (now - owner.prerecallLastStartAt);
946
+ if (!owner.prerecall || remaining <= 0) {
947
+ this.#clearPartialPrerecall(owner);
948
+ owner.prerecallLastStartAt = now;
949
+ void this.#prepareRecall(owner, itemId, text, 'speculative');
950
+ }
951
+ else if (owner.prerecallPendingPartial) {
952
+ owner.prerecallPendingPartial.text = text;
953
+ }
954
+ else {
955
+ const timer = setTimeout(() => {
956
+ const pending = owner.prerecallPendingPartial;
957
+ owner.prerecallPendingPartial = null;
958
+ if (!pending || !this.#isCurrent(owner) || owner.asr !== active || active.failed
959
+ || active.controller.signal.aborted || active.itemId !== pending.itemId || owner.userInput?.itemId === pending.itemId)
960
+ return;
961
+ owner.prerecallLastStartAt = performance.now();
962
+ void this.#prepareRecall(owner, pending.itemId, pending.text, 'speculative');
963
+ }, remaining);
964
+ owner.prerecallPendingPartial = { itemId, text, timer };
965
+ }
966
+ }
967
+ #prepareRecall(owner, itemId, query, source) {
897
968
  if (!this.#prerecall)
898
969
  return Promise.resolve(null);
899
970
  if (owner.prerecall?.query === query && owner.prerecall.itemId === itemId)
900
971
  return owner.prerecall.result;
901
972
  owner.prerecall?.controller.abort();
902
973
  const controller = new AbortController();
903
- const signal = AbortSignal.any([owner.controller.signal, controller.signal, AbortSignal.timeout(250)]);
904
- const started = performance.now();
905
- const result = abortable(this.#prerecall(query, signal), signal).catch(() => null).then(content => {
906
- this.#record('memory.prerecall.completed', { duration_ms: performance.now() - started, injected: false });
974
+ const timeout = AbortSignal.timeout(this.#prerecallPolicy.speculativeBudgetMs);
975
+ const signal = AbortSignal.any([owner.controller.signal, controller.signal, timeout]);
976
+ const startedAt = performance.now();
977
+ const result = Promise.resolve().then(() => abortable(this.#prerecall(query, signal), signal)).then(content => ({ content, failed: false }), () => ({ content: null, failed: true })).then(({ content, failed }) => {
978
+ const outcome = owner.controller.signal.aborted || controller.signal.aborted ? 'aborted'
979
+ : timeout.aborted ? 'timeout' : failed ? 'error' : content !== null ? 'ok' : 'empty';
980
+ this.#record('memory.prerecall.completed', { ...this.#prerecallMeta, duration_ms: performance.now() - startedAt, source, query_length: [...query].length, outcome });
907
981
  return signal.aborted ? null : content;
908
982
  });
909
- owner.prerecall = { query, itemId, controller, result };
983
+ owner.prerecall = { query, itemId, controller, result, source };
910
984
  return result;
911
985
  }
912
986
  async #runResponse(owner, active, inputs, allowTools, taskContinuation) {
@@ -914,6 +988,8 @@ export class CascadedRealtimeAdapter {
914
988
  let llmResponseId = null;
915
989
  let llmFailureCode = null;
916
990
  let textSeen = false;
991
+ let captionSent = false;
992
+ let preview = '', previewLength = 0;
917
993
  let toolSeen = false;
918
994
  let pendingTool = null;
919
995
  const transcript = [];
@@ -949,20 +1025,33 @@ export class CascadedRealtimeAdapter {
949
1025
  const userText = inputs.find(item => item.kind === 'user_text');
950
1026
  let memoryContext = null;
951
1027
  if (userText?.kind === 'user_text' && this.#prerecall) {
952
- const consumeSignal = AbortSignal.any([signal, AbortSignal.timeout(250)]);
953
- const prepared = await abortable(this.#prepareRecall(owner, owner.userInput?.itemId ?? active.id, userText.text), consumeSignal).catch(() => null);
954
- if (prepared) {
1028
+ this.#clearPartialPrerecall(owner);
1029
+ const startedAt = performance.now();
1030
+ const timeout = AbortSignal.timeout(this.#prerecallPolicy.finalWaitMs);
1031
+ const consumeSignal = AbortSignal.any([signal, timeout]);
1032
+ const itemId = owner.userInput?.itemId ?? active.id;
1033
+ const reused = owner.prerecall?.query === userText.text && owner.prerecall.itemId === itemId;
1034
+ const result = this.#prepareRecall(owner, itemId, userText.text, 'final');
1035
+ const run = owner.prerecall;
1036
+ const prepared = await abortable(result, consumeSignal).catch(() => null);
1037
+ if (prepared)
955
1038
  memoryContext = await abortable(prepared(consumeSignal), consumeSignal).catch(() => null);
1039
+ if (timeout.aborted || signal.aborted) {
1040
+ memoryContext = null;
1041
+ if (run.query === userText.text && run.itemId === itemId)
1042
+ run.controller.abort();
956
1043
  }
957
1044
  throwIfAborted(signal);
958
1045
  if (!this.#isCurrent(owner) || owner.response !== active)
959
1046
  return;
960
- this.#record('memory.prerecall.injected', { injected: memoryContext !== null });
1047
+ // Host-only responses omit adaptation; report injection only when the LLM receives it.
1048
+ this.#record('memory.prerecall.injected', { ...this.#prerecallMeta, injected: allowTools && memoryContext !== null, source: run.source, reused, wait_ms: performance.now() - startedAt, query_length: [...userText.text].length });
961
1049
  }
962
1050
  this.#record('cascaded.llm.requested', { epoch: owner.epoch, response_id: active.id });
963
1051
  this.#warmStandbyTts(owner);
964
1052
  for await (const event of owner.llm.stream({
965
1053
  language,
1054
+ previewText: this.#textOnly,
966
1055
  inputs: visualInputs.map(item => structuredClone(item)),
967
1056
  tools: allowTools ? owner.tools.map(tool => structuredClone(tool)) : [],
968
1057
  workspaceContext: allowTools ? owner.workspaceContext?.item.content ?? null : null,
@@ -983,6 +1072,22 @@ export class CascadedRealtimeAdapter {
983
1072
  llmResponseId = event.response_id;
984
1073
  this.#record('cascaded.llm.started', { epoch: owner.epoch, response_id: active.id });
985
1074
  }
1075
+ else if (event.kind === 'text_preview') {
1076
+ if (!this.#textOnly)
1077
+ continue;
1078
+ if (llmResponseId === null || textSeen || toolSeen)
1079
+ throw new Error('LLM preview out of order');
1080
+ previewLength += [...event.text].length;
1081
+ if (previewLength > MAX_REALTIME_TEXT)
1082
+ throw new Error('LLM preview text overflow');
1083
+ preview += event.text;
1084
+ captionSent = true;
1085
+ await this.#emit(owner, { kind: 'response_transcript_delta', session_epoch: owner.epoch, response_id: active.id, text: event.text, full_text: preview });
1086
+ }
1087
+ else if (event.kind === 'reasoning_delta') {
1088
+ // Thinking tokens are display-only for the workbench; realtime speech never consumes them.
1089
+ continue;
1090
+ }
986
1091
  else if (event.kind === 'text_delta') {
987
1092
  if (toolSeen)
988
1093
  throw new MixedResponseFailure();
@@ -1013,20 +1118,44 @@ export class CascadedRealtimeAdapter {
1013
1118
  if (transcriptLength === [...event.text].length) {
1014
1119
  this.#record('cascaded.llm.first_text', { epoch: owner.epoch, response_id: active.id });
1015
1120
  }
1016
- await this.#emit(owner, {
1017
- kind: 'response_transcript_delta', session_epoch: owner.epoch,
1018
- response_id: active.id, text: event.text,
1019
- });
1121
+ const fullText = transcript.join('');
1122
+ const delta = preview ? fullText.startsWith(preview) ? fullText.slice(Math.max(preview.length, fullText.length - event.text.length)) : '' : event.text;
1123
+ if (delta) {
1124
+ captionSent = true;
1125
+ await this.#emit(owner, {
1126
+ kind: 'response_transcript_delta', session_epoch: owner.epoch,
1127
+ response_id: active.id, text: delta, ...(this.#textOnly ? { full_text: fullText } : {}),
1128
+ });
1129
+ }
1020
1130
  if (active.tts !== null)
1021
1131
  for (const chunk of chunker.push(speech.push(event.text))) {
1022
1132
  await this.#sendTtsText(owner, active.tts, chunk);
1023
1133
  }
1024
1134
  }
1025
1135
  else if (event.kind === 'tool_call') {
1026
- if (textSeen || toolSeen)
1136
+ if (toolSeen)
1027
1137
  throw new MixedResponseFailure();
1028
1138
  if (llmResponseId === null)
1029
1139
  throw new Error('LLM tool before identity');
1140
+ // A provider may narrate before calling a tool in the same response. In text mode that
1141
+ // narration is the opening paragraph of the user-visible turn: keep it on screen instead
1142
+ // of emitting a turn-level empty final, so the continuation can extend the same answer.
1143
+ // Speech keeps the historical withdrawal: narration must not reach TTS before the tool
1144
+ // decision is final.
1145
+ if (!this.#textOnly && (textSeen || preview || captionSent)) {
1146
+ await this.#cancelTts(owner, active);
1147
+ await this.#emit(owner, { kind: 'response_transcript_final', session_epoch: owner.epoch, response_id: active.id, text: '' });
1148
+ textSeen = false;
1149
+ captionSent = false;
1150
+ preview = '';
1151
+ previewLength = 0;
1152
+ transcript.length = 0;
1153
+ transcriptLength = 0;
1154
+ }
1155
+ if (this.#textOnly) {
1156
+ preview = '';
1157
+ previewLength = 0;
1158
+ }
1030
1159
  toolSeen = true;
1031
1160
  pendingTool = event;
1032
1161
  owner.pendingToolCallId = event.call_id;
@@ -1054,22 +1183,26 @@ export class CascadedRealtimeAdapter {
1054
1183
  }
1055
1184
  await this.#finishTts(owner, active);
1056
1185
  }
1057
- await this.#emit(owner, {
1058
- kind: 'response_transcript_final', session_epoch: owner.epoch,
1059
- response_id: active.id, text: transcript.join(''),
1060
- });
1061
- }
1062
- else {
1063
- await this.#cancelTts(owner, active);
1064
- if (pendingTool !== null) {
1186
+ // Text-mode narration before a pending tool call is not a final: the turn continues
1187
+ // after the tool result and the consumer merges both responses into one answer.
1188
+ if (!(this.#textOnly && pendingTool !== null)) {
1065
1189
  await this.#emit(owner, {
1066
- kind: 'tool_call_ready', session_epoch: owner.epoch,
1067
- call_id: pendingTool.call_id, item_id: pendingTool.item_id,
1068
- name: pendingTool.name, arguments: structuredClone(pendingTool.arguments),
1069
- response_id: active.id,
1190
+ kind: 'response_transcript_final', session_epoch: owner.epoch,
1191
+ response_id: active.id, text: transcript.join(''),
1070
1192
  });
1071
1193
  }
1072
1194
  }
1195
+ else {
1196
+ await this.#cancelTts(owner, active);
1197
+ }
1198
+ if (pendingTool !== null && (!textSeen || this.#textOnly)) {
1199
+ await this.#emit(owner, {
1200
+ kind: 'tool_call_ready', session_epoch: owner.epoch,
1201
+ call_id: pendingTool.call_id, item_id: pendingTool.item_id,
1202
+ name: pendingTool.name, arguments: structuredClone(pendingTool.arguments),
1203
+ response_id: active.id,
1204
+ });
1205
+ }
1073
1206
  if (active.origin.kind === 'user_item' && owner.userInput?.itemId === active.origin.item_id) {
1074
1207
  owner.userInput.submitted = true;
1075
1208
  }
@@ -1080,6 +1213,12 @@ export class CascadedRealtimeAdapter {
1080
1213
  throw new Error('LLM stream ended without terminal');
1081
1214
  }
1082
1215
  catch (error) {
1216
+ // A failed or cancelled turn must not leave its display-only text on screen. Withdraw with an
1217
+ // empty final even when the abort signal is already set; nothing is persisted for this turn.
1218
+ if (captionSent && active.id !== null && this.#isCurrent(owner) && owner.response === active) {
1219
+ captionSent = false;
1220
+ await this.#emit(owner, { kind: 'response_transcript_final', session_epoch: owner.epoch, response_id: active.id, text: '' });
1221
+ }
1083
1222
  if (owner.pendingToolCallId !== null) {
1084
1223
  continuationResetFailed = !(await this.#abandonPendingToolCall(owner));
1085
1224
  }
@@ -1090,12 +1229,14 @@ export class CascadedRealtimeAdapter {
1090
1229
  }
1091
1230
  }
1092
1231
  else if (error instanceof MixedResponseFailure) {
1232
+ // Text after a tool is still malformed: report it before the terminal frame so consumers
1233
+ // see the reason, then fail the round without exposing the tool.
1093
1234
  await this.#cancelTts(owner, active);
1094
1235
  await this.#emit(owner, {
1095
1236
  kind: 'provider_error', session_epoch: owner.epoch,
1096
1237
  code: 'cascaded_mixed_text_tool', recoverable: false,
1097
1238
  });
1098
- if (active.id !== null)
1239
+ if (active.id !== null && !active.terminal)
1099
1240
  await this.#emitTerminal(owner, active, 'failed', 'mixed_output');
1100
1241
  }
1101
1242
  else {
@@ -1103,16 +1244,22 @@ export class CascadedRealtimeAdapter {
1103
1244
  const ttsFailure = error instanceof TtsResponseFailure;
1104
1245
  const rawCode = llmFailureCode ?? (error instanceof Error && 'code' in error ? error.code : null);
1105
1246
  const code = typeof rawCode === 'string'
1106
- && ['configuration', 'aborted', 'timeout', 'protocol', 'overflow', 'closed', 'network', 'http'].includes(rawCode)
1247
+ && ['configuration', 'aborted', 'timeout', 'protocol', 'overflow', 'closed', 'network', 'http', 'output_limit'].includes(rawCode)
1107
1248
  ? rawCode : 'unknown';
1108
1249
  this.#record('cascaded.response.failed', { component: ttsFailure ? 'tts' : 'llm', code });
1250
+ active.id ??= this.#freshId();
1251
+ // Causes the user can act on (account, key, rate limit, connectivity) survive to the conversation.
1252
+ const detail = error instanceof Error && 'detail' in error ? error.detail : null;
1253
+ const reason = ttsFailure ? 'tts_failure'
1254
+ : code === 'http' && (detail === 'auth' || detail === 'quota' || detail === 'rate_limited') ? `provider_http_${detail}`
1255
+ : code === 'network' || code === 'timeout' || code === 'output_limit' ? `provider_${code}` : 'provider_failure';
1256
+ await this.#emitTerminal(owner, active, 'failed', reason);
1257
+ // Reconnect advances the epoch; settle the owned response before emitting its recoverable error.
1109
1258
  await this.#emit(owner, {
1110
1259
  kind: 'provider_error', session_epoch: owner.epoch,
1111
1260
  code: ttsFailure ? 'cascaded_tts_receive' : 'cascaded_response_failed',
1112
1261
  recoverable: true,
1113
1262
  });
1114
- active.id ??= this.#freshId();
1115
- await this.#emitTerminal(owner, active, 'failed', ttsFailure ? 'tts_failure' : 'provider_failure');
1116
1263
  }
1117
1264
  }
1118
1265
  finally {
@@ -1626,13 +1773,6 @@ function cloneEvent(event) {
1626
1773
  function combineSignals(first, second) {
1627
1774
  return first === second ? first : AbortSignal.any([first, second]);
1628
1775
  }
1629
- function throwIfAborted(signal) {
1630
- if (!signal.aborted)
1631
- return;
1632
- if (signal.reason instanceof Error)
1633
- throw signal.reason;
1634
- throw new DOMException('This operation was aborted', 'AbortError');
1635
- }
1636
1776
  async function settleWithin(task, timeoutMs) {
1637
1777
  let timer;
1638
1778
  try {