nova-personal-agent-server 0.4.1 → 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 +10 -0
  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 +11 -4
  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
@@ -1,4 +1,7 @@
1
+ import { responseStyleContext, validateResponseStyleHits } from './ledger-recall-engine.js';
2
+ import { withUsageContext } from '../usage/context.js';
1
3
  import { abortable } from '../core/camera-session.js';
4
+ import { sourceFilterSchema } from './source-retrieval.js';
2
5
  import { SensitiveContentPolicy } from '../memory/sensitivity.js';
3
6
  const safeId = (id) => typeof id === 'string' && id.length > 0 && id.length <= 600 && !id.includes('\0');
4
7
  const policy = new SensitiveContentPolicy();
@@ -12,6 +15,11 @@ const deadline = (signal) => AbortSignal.any([...(signal ? [signal] : []), Abort
12
15
  /** C projection: entries and raw-index candidates resolve against the same A/B authority. */
13
16
  export class UnifiedRetrieval {
14
17
  options;
18
+ // Serialized snippet labels are not proof of host knowledge-index provenance.
19
+ knowledgeReferences = new WeakMap();
20
+ userOnly = new WeakSet();
21
+ // Styles depend on the entire source inventory, not just their supporting sources.
22
+ styleProjections = new WeakMap();
15
23
  owners = new WeakMap();
16
24
  consumers = new WeakMap();
17
25
  constructor(options) {
@@ -22,6 +30,11 @@ export class UnifiedRetrieval {
22
30
  throw Error('knowledge_purge_unavailable');
23
31
  await this.options.rawPurgeEvidence(ids);
24
32
  }
33
+ /** A synchronous fence for all async work consuming this projection. */
34
+ recallAuthorityUnchanged(result) {
35
+ const resource = this.owners.get(result), revision = resource?.recallAuthorityRevision?.();
36
+ return () => this.options.memory() === resource && revision === resource?.recallAuthorityRevision?.();
37
+ }
25
38
  /** Consume a prefetched projection using current A/B rows, without another embedding request. */
26
39
  async revalidate(result, signal) {
27
40
  signal.throwIfAborted();
@@ -29,13 +42,19 @@ export class UnifiedRetrieval {
29
42
  const empty = { state: 'unavailable', scope: result.scope, entries: [], snippets: [], degraded: true };
30
43
  if (!resource || this.options.memory() !== resource)
31
44
  return empty;
45
+ const userOnly = this.userOnly.has(result), knowledge = this.knowledgeReferences.get(result) ?? new Set();
32
46
  const entries = await Promise.all(result.entries.map(async (item) => {
33
47
  const row = await abortable(resource.get?.(item.entry_id) ?? Promise.resolve(null), signal);
34
- return row?.status === 'active' && row.version === item.revision && excerpt(row.content, 1000) === item.text ? item : null;
48
+ return row?.status === 'active' && row.version === item.revision && excerpt(row.content, 1000) === item.text
49
+ && (row.memory_scope ?? null) === (item.memory_scope ?? null) && (!userOnly || row.memory_scope === 'user') ? item : null;
35
50
  }));
51
+ const allowedRefs = new Set(entries.flatMap(item => item?.evidence_refs ?? []));
36
52
  const snippets = await Promise.all(result.snippets.map(async (item) => {
53
+ if (userOnly && !allowedRefs.has(item.evidence_id) && !knowledge.has(item.evidence_id))
54
+ return null;
37
55
  const row = await abortable(resource.readEvidence?.(item.evidence_id) ?? Promise.resolve(null), signal);
38
- return row?.evidence_id === item.evidence_id ? this.snippet(row, 1000) : null;
56
+ const snippet = row?.evidence_id === item.evidence_id ? this.snippet(row, 1000, knowledge.has(item.evidence_id)) : null;
57
+ return snippet && (!knowledge.has(item.evidence_id) || (snippet.text === item.text && snippet.locator === item.locator && snippet.source_kind === item.source_kind && snippet.observed_at === item.observed_at)) ? snippet : null;
39
58
  }));
40
59
  signal.throwIfAborted();
41
60
  if (this.options.memory() !== resource)
@@ -43,30 +62,59 @@ export class UnifiedRetrieval {
43
62
  const current = { ...result, entries: entries.filter((item) => item !== null), snippets: snippets.filter((item) => item !== null) };
44
63
  current.state = current.entries.length || current.snippets.length ? 'ok' : 'empty';
45
64
  this.owners.set(current, resource);
65
+ if (userOnly)
66
+ this.userOnly.add(current);
67
+ this.knowledgeReferences.set(current, knowledge);
68
+ const styleProjection = this.styleProjections.get(result);
69
+ if (styleProjection)
70
+ this.styleProjections.set(current, styleProjection);
46
71
  const consumer = this.consumers.get(result);
47
72
  if (consumer !== undefined)
48
73
  this.consumers.set(current, consumer);
49
74
  return this.authorize(current, resource, consumer, signal);
50
75
  }
76
+ /** Response adaptation only: never include style records in factual entries or tool results. */
77
+ async prepareResponseStyle(result, signal) {
78
+ signal.throwIfAborted();
79
+ const resource = this.owners.get(result), consumer = this.consumers.get(result), projection = this.styleProjections.get(result);
80
+ const unchanged = () => this.options.memory() === resource && projection !== undefined && resource?.recallAuthorityRevision?.() === projection.authorityRevision;
81
+ if (resource?.supportsResponseStyle !== true || !consumer || !projection || !unchanged())
82
+ return () => null;
83
+ // Authorization reads also discover committed changes made by other ledger clients.
84
+ const hits = await validateResponseStyleHits(resource, projection.hits, consumer, signal);
85
+ signal.throwIfAborted();
86
+ if (!unchanged())
87
+ return () => null;
88
+ return () => !signal.aborted && unchanged() ? responseStyleContext(hits) : null;
89
+ }
51
90
  async authorize(result, resource, consumer, signal) {
52
- if (consumer === undefined || !resource.canReadConversationEvidence)
91
+ const knowledge = this.knowledgeReferences.get(result);
92
+ if (knowledge?.size && (!consumer || !resource.canReadConversationEvidence)) {
93
+ result.snippets = result.snippets.filter(snippet => !knowledge.has(snippet.evidence_id));
94
+ result.degraded = true;
95
+ result.state = result.entries.length || result.snippets.length ? 'ok' : 'unavailable';
96
+ }
97
+ if ((consumer === undefined && !resource.requiresConversationConsumer) || !resource.canReadConversationEvidence)
53
98
  return result;
54
- const allowed = async (ids) => ids.length > 0 && (await Promise.all(ids.map(id => abortable(resource.canReadConversationEvidence(id, consumer), signal)))).every(Boolean);
99
+ const allowed = async (ids) => ids.length > 0 && (await Promise.all(ids.map(id => abortable(resource.canReadConversationEvidence(id, consumer ?? ''), signal)))).every(Boolean);
55
100
  const entries = await Promise.all(result.entries.map(async (entry) => await allowed(entry.evidence_refs) ? entry : null));
56
101
  const snippets = await Promise.all(result.snippets.map(async (snippet) => await allowed([snippet.evidence_id]) ? snippet : null));
57
102
  signal.throwIfAborted();
58
103
  if (this.options.memory() !== resource)
59
104
  return { state: 'unavailable', scope: result.scope, entries: [], snippets: [], degraded: true };
60
105
  result.entries = entries.filter((entry) => entry !== null);
61
- result.snippets = snippets.filter((snippet) => snippet !== null);
106
+ const allowedRefs = new Set(result.entries.flatMap(entry => entry.evidence_refs));
107
+ result.snippets = snippets.filter((snippet) => snippet !== null && (!this.userOnly.has(result) || allowedRefs.has(snippet.evidence_id) || this.knowledgeReferences.get(result)?.has(snippet.evidence_id) === true));
62
108
  result.state = result.entries.length || result.snippets.length ? 'ok' : result.degraded ? 'unavailable' : 'empty';
63
109
  return result;
64
110
  }
65
- snippet(row, bytes) {
111
+ snippet(row, bytes, knowledge = false) {
112
+ if (knowledge && row.source_kind !== 'file')
113
+ return null;
66
114
  const text = excerpt(row.text, bytes);
67
115
  if (!safeId(row.evidence_id) || !text)
68
116
  return null;
69
- return { evidence_id: row.evidence_id, source_kind: row.source_kind, locator: row.locator, text, observed_at: row.observed_at, trust: 'untrusted_external' };
117
+ return { evidence_id: row.evidence_id, source_kind: row.source_kind, locator: row.locator, text, observed_at: row.observed_at, trust: 'untrusted_external', ...(knowledge ? { context_kind: 'knowledge_reference' } : {}) };
70
118
  }
71
119
  async evidence(id, options = {}) {
72
120
  if (!safeId(id))
@@ -81,7 +129,7 @@ export class UnifiedRetrieval {
81
129
  options.signal?.throwIfAborted();
82
130
  if (this.options.memory() !== resource)
83
131
  return { state: 'unavailable', evidence: null };
84
- const allowed = options.consumer === undefined || !resource.canReadConversationEvidence || await abortable(resource.canReadConversationEvidence(id, options.consumer), signal);
132
+ const allowed = (options.consumer === undefined && !resource.requiresConversationConsumer) || !resource.canReadConversationEvidence || await abortable(resource.canReadConversationEvidence(id, options.consumer ?? ''), signal);
85
133
  options.signal?.throwIfAborted();
86
134
  if (this.options.memory() !== resource)
87
135
  return { state: 'unavailable', evidence: null };
@@ -94,6 +142,8 @@ export class UnifiedRetrieval {
94
142
  }
95
143
  }
96
144
  async recall(query, options = {}) {
145
+ const userOnly = options.userOnly === true;
146
+ const filter = options.sourceFilter === undefined ? undefined : sourceFilterSchema.parse(options.sourceFilter);
97
147
  const scope = options.scope ?? 'any', requested = options.limit ?? 8;
98
148
  if (typeof query !== 'string' || !query.trim() || query.length > 512 || query.includes('\0')
99
149
  || !['recent', 'any'].includes(scope) || !Number.isSafeInteger(requested) || requested < 1)
@@ -103,26 +153,41 @@ export class UnifiedRetrieval {
103
153
  const resource = this.options.memory();
104
154
  if (!resource)
105
155
  return { state: 'unavailable', scope, entries: [], snippets: [], degraded: true };
156
+ const styleAuthorityRevision = resource.recallAuthorityRevision?.();
106
157
  const call = (work) => {
107
158
  const abort = AbortSignal.any([signal, AbortSignal.timeout(5000)]);
108
- return abortable(Promise.resolve().then(() => work(abort)), abort);
159
+ return withUsageContext({ ...this.options.usageContext, feature: 'recall', operation: 'retrieve' }, () => abortable(Promise.resolve().then(() => work(abort)), abort));
109
160
  };
110
- const [recalled, raw] = await Promise.allSettled([
111
- call(abort => resource.recall(query.trim(), { scope, limit: 8, signal: abort })),
161
+ const [recalled, raw, sources] = await Promise.allSettled([
162
+ filter ? Promise.resolve({ hits: [], degraded: false }) : call(abort => resource.recall(query.trim(), { scope, userOnly, limit: Math.min(8, resource.maxRecallLimit ?? 8), signal: abort })),
112
163
  // Recent is the memory provider's bounded candidate window and those entries' originals.
113
164
  // The current raw index has no recent-window ranking contract, so search it only for any.
114
- this.options.rawRecall && scope === 'any' ? call(abort => this.options.rawRecall(query.trim(), 8, abort)) : Promise.resolve([]),
165
+ (!userOnly || this.options.rawRecallKind === 'knowledge') && !filter && this.options.rawRecall && scope === 'any' ? call(abort => {
166
+ if (this.options.rawRecallKind === 'knowledge' && (!options.consumer || !resource.readEvidence || !resource.canReadConversationEvidence))
167
+ return Promise.reject(Error('knowledge_reference_authority_unavailable'));
168
+ return this.options.rawRecall(query.trim(), 8, abort);
169
+ }) : Promise.resolve([]),
170
+ !userOnly && resource.recallSources && options.consumer ? call(abort => resource.recallSources(query.trim(), { scope, limit: 8, consumer: options.consumer, signal: abort, ...(filter ? { filter } : {}) })) : Promise.resolve({ hits: [], truncated: filter !== undefined }),
115
171
  ]);
116
172
  options.signal?.throwIfAborted();
117
- let degraded = recalled.status === 'rejected' || raw.status === 'rejected';
173
+ if (recalled.status === 'rejected') {
174
+ // Never forward provider messages, arbitrary error codes, queries or endpoint identities.
175
+ const error = recalled.reason;
176
+ const code = error instanceof Error && error.name === 'TimeoutError' ? 'timeout'
177
+ : error instanceof Error && error.name === 'AbortError' ? 'aborted' : 'error';
178
+ this.options.telemetry?.record('memory.recall.engine_failed', { engine: resource.recallEngine ?? 'unknown', code });
179
+ }
180
+ let degraded = recalled.status === 'rejected' || raw.status === 'rejected' || sources.status === 'rejected';
181
+ if (sources.status === 'fulfilled')
182
+ degraded ||= sources.value.truncated;
118
183
  if (recalled.status === 'fulfilled')
119
184
  degraded ||= recalled.value.degraded;
120
185
  const entries = new Map();
121
- const evidenceRanks = new Map();
186
+ const evidenceRanks = new Map(), knowledge = new Set();
122
187
  if (recalled.status === 'fulfilled') {
123
- if (!resource.get)
188
+ if (!resource.get && recalled.value.hits.length)
124
189
  degraded = true;
125
- else
190
+ else if (resource.get)
126
191
  for (const [index, hit] of recalled.value.hits.slice(0, 8).entries()) {
127
192
  if (!safeId(hit.memoryId) || entries.has(hit.memoryId))
128
193
  continue;
@@ -132,12 +197,17 @@ export class UnifiedRetrieval {
132
197
  || (hit.revision !== undefined && current.version !== hit.revision)
133
198
  || current.content !== hit.text.slice(0, 500))
134
199
  continue;
200
+ if (userOnly && current.memory_scope !== 'user') {
201
+ if (current.memory_scope !== 'general')
202
+ degraded = true;
203
+ continue;
204
+ }
135
205
  const text = excerpt(current.content, 1000);
136
206
  if (!text)
137
207
  continue;
138
208
  const refs = [...new Set(hit.evidenceIds.filter(safeId))].slice(0, 16);
139
209
  const rank = 1 / (60 + index + 1);
140
- entries.set(current.id, { rank, entry: { entry_id: current.id, revision: current.version, reference: `${current.id}@${current.version}`, origin: current.origin, text, evidence_refs: refs, kind: current.kind, life: current.life ? { ...current.life, due_precision: current.life.due === null ? null : 'date', due_time: null } : null } });
210
+ entries.set(current.id, { rank, entry: { entry_id: current.id, revision: current.version, reference: `${current.id}@${current.version}`, origin: current.origin, text, evidence_refs: refs, kind: current.kind, memory_scope: current.memory_scope ?? null, life: current.life ? { ...current.life, due_precision: current.life.due === null ? null : 'date', due_time: null } : null } });
141
211
  // The same evidence appearing in several memories counts once in this ranked channel.
142
212
  for (const id of refs)
143
213
  if (!evidenceRanks.has(id))
@@ -158,10 +228,17 @@ export class UnifiedRetrieval {
158
228
  if (seen.has(hit.evidence_id))
159
229
  continue;
160
230
  seen.add(hit.evidence_id);
231
+ if (this.options.rawRecallKind === 'knowledge')
232
+ knowledge.add(hit.evidence_id);
161
233
  // Reciprocal rank fusion; index-specific similarity scores carry no cross-channel meaning.
162
234
  evidenceRanks.set(hit.evidence_id, (evidenceRanks.get(hit.evidence_id) ?? 0) + 1 / (60 + index + 1));
163
235
  }
164
236
  }
237
+ if (sources.status === 'fulfilled')
238
+ for (const [index, hit] of sources.value.hits.entries()) {
239
+ if (safeId(hit.evidence_id))
240
+ evidenceRanks.set(hit.evidence_id, (evidenceRanks.get(hit.evidence_id) ?? 0) + 1 / (60 + index + 1));
241
+ }
165
242
  const candidates = [
166
243
  ...[...entries.values()].map(({ rank, entry }) => ({ rank, key: `entry:${entry.entry_id}`, entry })),
167
244
  ...[...evidenceRanks].map(([evidenceId, rank]) => ({ rank, key: `snippet:${evidenceId}`, evidenceId })),
@@ -181,7 +258,8 @@ export class UnifiedRetrieval {
181
258
  try {
182
259
  if (candidate.entry) {
183
260
  const current = await abortable(resource.get(candidate.entry.entry_id), signal);
184
- if (current?.status !== 'active' || current.version !== candidate.entry.revision || excerpt(current.content, 1000) !== candidate.entry.text)
261
+ if (current?.status !== 'active' || current.version !== candidate.entry.revision || excerpt(current.content, 1000) !== candidate.entry.text
262
+ || (current.memory_scope ?? null) !== (candidate.entry.memory_scope ?? null) || (userOnly && current.memory_scope !== 'user'))
185
263
  continue;
186
264
  }
187
265
  else {
@@ -190,7 +268,7 @@ export class UnifiedRetrieval {
190
268
  continue;
191
269
  }
192
270
  const row = await abortable(resource.readEvidence(candidate.evidenceId), signal);
193
- const snippet = row !== null && row.evidence_id === candidate.evidenceId ? this.snippet(row, 1000) : null;
271
+ const snippet = row !== null && row.evidence_id === candidate.evidenceId ? this.snippet(row, 1000, knowledge.has(candidate.evidenceId)) : null;
194
272
  if (!snippet)
195
273
  continue;
196
274
  snippets.set(snippet.evidence_id, snippet);
@@ -206,10 +284,11 @@ export class UnifiedRetrieval {
206
284
  try {
207
285
  if (candidate.entry) {
208
286
  const current = await abortable(resource.get(candidate.entry.entry_id), signal);
209
- return current?.status === 'active' && current.version === candidate.entry.revision && excerpt(current.content, 1000) === candidate.entry.text ? candidate : null;
287
+ return current?.status === 'active' && current.version === candidate.entry.revision && excerpt(current.content, 1000) === candidate.entry.text
288
+ && (current.memory_scope ?? null) === (candidate.entry.memory_scope ?? null) && (!userOnly || current.memory_scope === 'user') ? candidate : null;
210
289
  }
211
290
  const row = await abortable(resource.readEvidence(candidate.evidenceId), signal);
212
- const snippet = row !== null && row.evidence_id === candidate.evidenceId ? this.snippet(row, 1000) : null;
291
+ const snippet = row !== null && row.evidence_id === candidate.evidenceId ? this.snippet(row, 1000, knowledge.has(candidate.evidenceId)) : null;
213
292
  if (!snippet || snippet.text !== snippets.get(snippet.evidence_id)?.text)
214
293
  return null;
215
294
  snippets.set(snippet.evidence_id, snippet);
@@ -224,9 +303,15 @@ export class UnifiedRetrieval {
224
303
  if (this.options.memory() !== resource)
225
304
  return { state: 'unavailable', scope, entries: [], snippets: [], degraded: true };
226
305
  const resultEntries = checked.flatMap(candidate => candidate?.entry ? [candidate.entry] : []);
227
- const resultSnippets = checked.flatMap(candidate => candidate?.evidenceId ? [snippets.get(candidate.evidenceId)] : []);
306
+ const allowedRefs = new Set(resultEntries.flatMap(entry => entry.evidence_refs));
307
+ const resultSnippets = checked.flatMap(candidate => candidate?.evidenceId && (!userOnly || allowedRefs.has(candidate.evidenceId) || knowledge.has(candidate.evidenceId)) ? [snippets.get(candidate.evidenceId)] : []);
228
308
  const result = { state: resultEntries.length || resultSnippets.length ? 'ok' : degraded ? 'unavailable' : 'empty', scope, entries: resultEntries, snippets: resultSnippets, degraded };
229
309
  this.owners.set(result, resource);
310
+ if (userOnly)
311
+ this.userOnly.add(result);
312
+ this.knowledgeReferences.set(result, new Set(resultSnippets.filter(snippet => snippet.context_kind === 'knowledge_reference').map(snippet => snippet.evidence_id)));
313
+ if (resource.supportsResponseStyle === true && styleAuthorityRevision !== undefined && recalled.status === 'fulfilled' && 'contextHits' in recalled.value)
314
+ this.styleProjections.set(result, { hits: recalled.value.contextHits ?? [], authorityRevision: styleAuthorityRevision });
230
315
  if (options.consumer !== undefined)
231
316
  this.consumers.set(result, options.consumer);
232
317
  return this.authorize(result, resource, options.consumer, signal);
@@ -126,12 +126,16 @@ function* boundedAbsolutePathCandidates(line) {
126
126
  }
127
127
  /** Removes credential-bearing spans while retaining the non-sensitive field context. */
128
128
  export class SensitiveContentPolicy {
129
- scrub(_field, value) {
129
+ scrub(field, value) {
130
130
  let matches = 0;
131
131
  let scrubbed = value;
132
132
  const lines = value.split('\n'), credentialLines = new Set();
133
133
  for (let index = 0; index < lines.length; index++) {
134
134
  const token = lines[index].trim();
135
+ // Free-form message bodies may contain bare credentials without a password label.
136
+ // These standalone tokens have no useful role in a personal portrait.
137
+ if (field === 'source_processing' && (/^(?:[A-Za-z_-]+-)?[a-fA-F0-9]{32,}$/u.test(token) || /^(?=.*[A-Za-z])(?=.*\d)(?=.*[!@#$%^&*+=])[A-Za-z\d!@#$%^&*_.+=-]{8,128}$/u.test(token)))
138
+ credentialLines.add(index);
135
139
  if (/^["']?(?:密码|口令|密钥|私钥|访问令牌)["']?\s*[::=]?\s*$/u.test(token) && /^[A-Za-z0-9!@#$%^&*_.+=\/-]{3,}$/u.test(lines[index + 1]?.trim() ?? ''))
136
140
  credentialLines.add(index + 1);
137
141
  }
@@ -164,7 +168,7 @@ export class SensitiveContentPolicy {
164
168
  return '[redacted]';
165
169
  });
166
170
  scrubbed = replaceAll(scrubbed, /(?:密码|口令|密钥|私钥|访问令牌|CVC|CVV|安全码)[ \t]+[`"']?[A-Za-z0-9!@#$%^&*_.+=\/-]{3,}[`"']?/giu, () => { matches++; return '[redacted]'; });
167
- scrubbed = replaceAll(scrubbed, /\b(?:sk|rk|pk|ak|xox[baprs]|ghp|github_pat)[_-][A-Za-z0-9][A-Za-z0-9_-]{11,}\b/giu, () => {
171
+ scrubbed = replaceAll(scrubbed, /\b(?:sk|rk|pk|ak|tskey|xox[baprs]|ghp|github_pat)[_-][A-Za-z0-9][A-Za-z0-9_-]{11,}\b/giu, () => {
168
172
  matches += 1;
169
173
  return '[redacted]';
170
174
  });
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+ /** Constraints on originals, not inferred memories or current conversation history. */
3
+ export const sourceFilterSchema = z.object({
4
+ kind: z.enum(['im', 'mail', 'calendar', 'file']).optional(),
5
+ provider: z.string().trim().min(1).max(80).optional(),
6
+ since: z.iso.datetime({ offset: true }).optional(),
7
+ before: z.iso.datetime({ offset: true }).optional(),
8
+ last_days: z.number().int().min(1).max(365).optional(),
9
+ }).strict().refine(value => value.last_days === undefined || (!value.since && !value.before), 'last_days cannot be combined with explicit dates')
10
+ .refine(value => !value.since || !value.before || Date.parse(value.since) < Date.parse(value.before), 'invalid source time range');
11
+ //# sourceMappingURL=source-retrieval.js.map
@@ -0,0 +1,46 @@
1
+ import { legacyMemoryComposition } from './factory.js';
2
+ export const FULL_MEMORY_TOOLS = Object.freeze({ recall: true, evidence: true, sourceFilter: true, lookup: true, remember: true, engine: 'ledger' });
3
+ export const NO_MEMORY_TOOLS = Object.freeze({ recall: false, evidence: false, sourceFilter: false, lookup: false, remember: false, engine: 'none' });
4
+ export function deriveMemoryToolCapabilities(resource, engine = 'none') {
5
+ // Session recall remains available even without a personal resource.
6
+ return { recall: true, evidence: !!resource?.readEvidence, sourceFilter: !!resource?.recallSources,
7
+ lookup: !!resource?.lookupExplicit && !!resource.get, remember: !!resource?.beginExplicitTurn && !!resource.writeExplicit, engine };
8
+ }
9
+ /** The same branch predicate owns both static tool planning and resource composition. */
10
+ export function useLocalLedger(input) {
11
+ return (input.spaceConfig !== undefined && input.spaceConfig.data_mode !== 'existing')
12
+ || (input.memoryComposition ?? legacyMemoryComposition(input.createPersonalMemory))?.kind === 'ledger'
13
+ || (input.knowledge && input.createPersonalMemory === undefined && (!input.memoryComposition || input.memoryComposition.kind === 'disabled'));
14
+ }
15
+ export function planMemoryToolCapabilities(input) {
16
+ if (useLocalLedger(input)) {
17
+ const isolated = input.spaceConfig !== undefined && input.spaceConfig.data_mode !== 'existing';
18
+ const composition = input.memoryComposition ?? legacyMemoryComposition(input.createPersonalMemory);
19
+ const local = composition?.kind === 'ledger';
20
+ return isolated || local ? { ...FULL_MEMORY_TOOLS, engine: local ? composition.engine : 'ledger' } : { ...NO_MEMORY_TOOLS, recall: true, evidence: true, engine: 'knowledge' };
21
+ }
22
+ if (input.memoryComposition?.kind === 'remote')
23
+ return { ...NO_MEMORY_TOOLS, recall: true, engine: 'remote' };
24
+ if (input.memoryComposition?.kind === 'standalone-mem0')
25
+ return { ...NO_MEMORY_TOOLS, recall: true, evidence: true, engine: 'mem0' };
26
+ if (input.createPersonalMemory === undefined)
27
+ return { ...NO_MEMORY_TOOLS, recall: true };
28
+ const backend = input.createPersonalMemory.memoryBackend;
29
+ if (input.settings.memory_connection === 'remote' || backend === 'remote')
30
+ return { ...NO_MEMORY_TOOLS, recall: true, engine: 'remote' };
31
+ if (backend === 'mem0')
32
+ return { ...NO_MEMORY_TOOLS, recall: true, evidence: true, engine: 'mem0' };
33
+ // Untagged injected factories retain legacy tools; live resources refine this plan.
34
+ return FULL_MEMORY_TOOLS;
35
+ }
36
+ export function memoryToolsFor(caps, mode) {
37
+ return mode.scheduled || mode.sourceProcessing ? { ...caps, remember: false, lookup: false } : caps;
38
+ }
39
+ /** Shared conversations may compile before the owning graph has created its resource. */
40
+ export function resolveMemoryToolCapabilities(resource, planned) {
41
+ if (!resource)
42
+ return planned;
43
+ const engine = resource.writeExplicit ? resource.recallEngine ?? 'ledger' : planned.engine === 'mem0' ? 'mem0' : resource.readEvidence ? 'knowledge' : planned.engine;
44
+ return deriveMemoryToolCapabilities(resource, engine);
45
+ }
46
+ //# sourceMappingURL=tool-capabilities.js.map
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.