@murphai/hosted-execution 0.1.15 → 0.1.18

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 (656) hide show
  1. package/LICENSE +201 -674
  2. package/README.md +15 -14
  3. package/dist/auth.d.ts +11 -25
  4. package/dist/auth.d.ts.map +1 -1
  5. package/dist/auth.js +32 -76
  6. package/dist/auth.js.map +1 -1
  7. package/dist/builders.d.ts +3 -4
  8. package/dist/builders.d.ts.map +1 -1
  9. package/dist/builders.js +24 -24
  10. package/dist/builders.js.map +1 -1
  11. package/dist/bundles.d.ts +3 -13
  12. package/dist/bundles.d.ts.map +1 -1
  13. package/dist/bundles.js +1 -16
  14. package/dist/bundles.js.map +1 -1
  15. package/dist/client.d.ts +2 -26
  16. package/dist/client.d.ts.map +1 -1
  17. package/dist/client.js +38 -212
  18. package/dist/client.js.map +1 -1
  19. package/dist/contracts.d.ts +49 -118
  20. package/dist/contracts.d.ts.map +1 -1
  21. package/dist/contracts.js +15 -58
  22. package/dist/contracts.js.map +1 -1
  23. package/dist/dispatch-ref.d.ts +1 -2
  24. package/dist/dispatch-ref.d.ts.map +1 -1
  25. package/dist/dispatch-ref.js +16 -30
  26. package/dist/dispatch-ref.js.map +1 -1
  27. package/dist/env.d.ts +0 -38
  28. package/dist/env.d.ts.map +1 -1
  29. package/dist/env.js +1 -87
  30. package/dist/env.js.map +1 -1
  31. package/dist/index.d.ts +0 -2
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +0 -2
  34. package/dist/index.js.map +1 -1
  35. package/dist/observability.d.ts +3 -1
  36. package/dist/observability.d.ts.map +1 -1
  37. package/dist/observability.js +76 -53
  38. package/dist/observability.js.map +1 -1
  39. package/dist/outbox-payload.d.ts +7 -5
  40. package/dist/outbox-payload.d.ts.map +1 -1
  41. package/dist/outbox-payload.js +75 -38
  42. package/dist/outbox-payload.js.map +1 -1
  43. package/dist/parsers.d.ts +10 -10
  44. package/dist/parsers.d.ts.map +1 -1
  45. package/dist/parsers.js +192 -139
  46. package/dist/parsers.js.map +1 -1
  47. package/dist/routes.d.ts +4 -9
  48. package/dist/routes.d.ts.map +1 -1
  49. package/dist/routes.js +7 -18
  50. package/dist/routes.js.map +1 -1
  51. package/node_modules/@murphai/core/README.md +3 -0
  52. package/node_modules/@murphai/core/dist/assessment/index.d.ts +5 -0
  53. package/node_modules/@murphai/core/dist/assessment/index.d.ts.map +1 -0
  54. package/node_modules/@murphai/core/dist/assessment/index.js +4 -0
  55. package/node_modules/@murphai/core/dist/assessment/index.js.map +1 -0
  56. package/node_modules/@murphai/core/dist/assessment/project.d.ts +9 -0
  57. package/node_modules/@murphai/core/dist/assessment/project.d.ts.map +1 -0
  58. package/node_modules/@murphai/core/dist/assessment/project.js +353 -0
  59. package/node_modules/@murphai/core/dist/assessment/project.js.map +1 -0
  60. package/node_modules/@murphai/core/dist/assessment/storage.d.ts +13 -0
  61. package/node_modules/@murphai/core/dist/assessment/storage.d.ts.map +1 -0
  62. package/node_modules/@murphai/core/dist/assessment/storage.js +202 -0
  63. package/node_modules/@murphai/core/dist/assessment/storage.js.map +1 -0
  64. package/node_modules/@murphai/core/dist/assessment/types.d.ts +112 -0
  65. package/node_modules/@murphai/core/dist/assessment/types.d.ts.map +1 -0
  66. package/node_modules/@murphai/core/dist/assessment/types.js +5 -0
  67. package/node_modules/@murphai/core/dist/assessment/types.js.map +1 -0
  68. package/node_modules/@murphai/core/dist/atomic-write.d.ts +5 -0
  69. package/node_modules/@murphai/core/dist/atomic-write.d.ts.map +1 -0
  70. package/node_modules/@murphai/core/dist/atomic-write.js +120 -0
  71. package/node_modules/@murphai/core/dist/atomic-write.js.map +1 -0
  72. package/node_modules/@murphai/core/dist/audit.d.ts +27 -0
  73. package/node_modules/@murphai/core/dist/audit.d.ts.map +1 -0
  74. package/node_modules/@murphai/core/dist/audit.js +94 -0
  75. package/node_modules/@murphai/core/dist/audit.js.map +1 -0
  76. package/node_modules/@murphai/core/dist/automation.d.ts +55 -0
  77. package/node_modules/@murphai/core/dist/automation.d.ts.map +1 -0
  78. package/node_modules/@murphai/core/dist/automation.js +411 -0
  79. package/node_modules/@murphai/core/dist/automation.js.map +1 -0
  80. package/node_modules/@murphai/core/dist/bank/allergies.d.ts +5 -0
  81. package/node_modules/@murphai/core/dist/bank/allergies.d.ts.map +1 -0
  82. package/node_modules/@murphai/core/dist/bank/allergies.js +209 -0
  83. package/node_modules/@murphai/core/dist/bank/allergies.js.map +1 -0
  84. package/node_modules/@murphai/core/dist/bank/conditions.d.ts +5 -0
  85. package/node_modules/@murphai/core/dist/bank/conditions.d.ts.map +1 -0
  86. package/node_modules/@murphai/core/dist/bank/conditions.js +249 -0
  87. package/node_modules/@murphai/core/dist/bank/conditions.js.map +1 -0
  88. package/node_modules/@murphai/core/dist/bank/foods.d.ts +8 -0
  89. package/node_modules/@murphai/core/dist/bank/foods.d.ts.map +1 -0
  90. package/node_modules/@murphai/core/dist/bank/foods.js +255 -0
  91. package/node_modules/@murphai/core/dist/bank/foods.js.map +1 -0
  92. package/node_modules/@murphai/core/dist/bank/goals.d.ts +5 -0
  93. package/node_modules/@murphai/core/dist/bank/goals.d.ts.map +1 -0
  94. package/node_modules/@murphai/core/dist/bank/goals.js +289 -0
  95. package/node_modules/@murphai/core/dist/bank/goals.js.map +1 -0
  96. package/node_modules/@murphai/core/dist/bank/index.d.ts +10 -0
  97. package/node_modules/@murphai/core/dist/bank/index.d.ts.map +1 -0
  98. package/node_modules/@murphai/core/dist/bank/index.js +10 -0
  99. package/node_modules/@murphai/core/dist/bank/index.js.map +1 -0
  100. package/node_modules/@murphai/core/dist/bank/protocols.d.ts +8 -0
  101. package/node_modules/@murphai/core/dist/bank/protocols.d.ts.map +1 -0
  102. package/node_modules/@murphai/core/dist/bank/protocols.js +466 -0
  103. package/node_modules/@murphai/core/dist/bank/protocols.js.map +1 -0
  104. package/node_modules/@murphai/core/dist/bank/providers.d.ts +46 -0
  105. package/node_modules/@murphai/core/dist/bank/providers.d.ts.map +1 -0
  106. package/node_modules/@murphai/core/dist/bank/providers.js +160 -0
  107. package/node_modules/@murphai/core/dist/bank/providers.js.map +1 -0
  108. package/node_modules/@murphai/core/dist/bank/recipes.d.ts +8 -0
  109. package/node_modules/@murphai/core/dist/bank/recipes.d.ts.map +1 -0
  110. package/node_modules/@murphai/core/dist/bank/recipes.js +287 -0
  111. package/node_modules/@murphai/core/dist/bank/recipes.js.map +1 -0
  112. package/node_modules/@murphai/core/dist/bank/shared.d.ts +39 -0
  113. package/node_modules/@murphai/core/dist/bank/shared.d.ts.map +1 -0
  114. package/node_modules/@murphai/core/dist/bank/shared.js +150 -0
  115. package/node_modules/@murphai/core/dist/bank/shared.js.map +1 -0
  116. package/node_modules/@murphai/core/dist/bank/types.d.ts +469 -0
  117. package/node_modules/@murphai/core/dist/bank/types.d.ts.map +1 -0
  118. package/node_modules/@murphai/core/dist/bank/types.js +35 -0
  119. package/node_modules/@murphai/core/dist/bank/types.js.map +1 -0
  120. package/node_modules/@murphai/core/dist/bank/workout-formats.d.ts +5 -0
  121. package/node_modules/@murphai/core/dist/bank/workout-formats.d.ts.map +1 -0
  122. package/node_modules/@murphai/core/dist/bank/workout-formats.js +204 -0
  123. package/node_modules/@murphai/core/dist/bank/workout-formats.js.map +1 -0
  124. package/node_modules/@murphai/core/dist/canonical-mutations.d.ts +54 -0
  125. package/node_modules/@murphai/core/dist/canonical-mutations.d.ts.map +1 -0
  126. package/node_modules/@murphai/core/dist/canonical-mutations.js +196 -0
  127. package/node_modules/@murphai/core/dist/canonical-mutations.js.map +1 -0
  128. package/node_modules/@murphai/core/dist/constants.d.ts +125 -0
  129. package/node_modules/@murphai/core/dist/constants.d.ts.map +1 -0
  130. package/node_modules/@murphai/core/dist/constants.js +132 -0
  131. package/node_modules/@murphai/core/dist/constants.js.map +1 -0
  132. package/node_modules/@murphai/core/dist/domains/events.d.ts +100 -0
  133. package/node_modules/@murphai/core/dist/domains/events.d.ts.map +1 -0
  134. package/node_modules/@murphai/core/dist/domains/events.js +593 -0
  135. package/node_modules/@murphai/core/dist/domains/events.js.map +1 -0
  136. package/node_modules/@murphai/core/dist/domains/experiments.d.ts +71 -0
  137. package/node_modules/@murphai/core/dist/domains/experiments.d.ts.map +1 -0
  138. package/node_modules/@murphai/core/dist/domains/experiments.js +275 -0
  139. package/node_modules/@murphai/core/dist/domains/experiments.js.map +1 -0
  140. package/node_modules/@murphai/core/dist/domains/journal.d.ts +52 -0
  141. package/node_modules/@murphai/core/dist/domains/journal.d.ts.map +1 -0
  142. package/node_modules/@murphai/core/dist/domains/journal.js +173 -0
  143. package/node_modules/@murphai/core/dist/domains/journal.js.map +1 -0
  144. package/node_modules/@murphai/core/dist/domains/shared.d.ts +37 -0
  145. package/node_modules/@murphai/core/dist/domains/shared.d.ts.map +1 -0
  146. package/node_modules/@murphai/core/dist/domains/shared.js +101 -0
  147. package/node_modules/@murphai/core/dist/domains/shared.js.map +1 -0
  148. package/node_modules/@murphai/core/dist/domains/vault-summary.d.ts +15 -0
  149. package/node_modules/@murphai/core/dist/domains/vault-summary.d.ts.map +1 -0
  150. package/node_modules/@murphai/core/dist/domains/vault-summary.js +58 -0
  151. package/node_modules/@murphai/core/dist/domains/vault-summary.js.map +1 -0
  152. package/node_modules/@murphai/core/dist/errors.d.ts +8 -0
  153. package/node_modules/@murphai/core/dist/errors.d.ts.map +1 -0
  154. package/node_modules/@murphai/core/dist/errors.js +14 -0
  155. package/node_modules/@murphai/core/dist/errors.js.map +1 -0
  156. package/node_modules/@murphai/core/dist/event-attachments.d.ts +69 -0
  157. package/node_modules/@murphai/core/dist/event-attachments.d.ts.map +1 -0
  158. package/node_modules/@murphai/core/dist/event-attachments.js +202 -0
  159. package/node_modules/@murphai/core/dist/event-attachments.js.map +1 -0
  160. package/node_modules/@murphai/core/dist/event-links.d.ts +15 -0
  161. package/node_modules/@murphai/core/dist/event-links.d.ts.map +1 -0
  162. package/node_modules/@murphai/core/dist/event-links.js +54 -0
  163. package/node_modules/@murphai/core/dist/event-links.js.map +1 -0
  164. package/node_modules/@murphai/core/dist/family/api.d.ts +5 -0
  165. package/node_modules/@murphai/core/dist/family/api.d.ts.map +1 -0
  166. package/node_modules/@murphai/core/dist/family/api.js +221 -0
  167. package/node_modules/@murphai/core/dist/family/api.js.map +1 -0
  168. package/node_modules/@murphai/core/dist/family/index.d.ts +3 -0
  169. package/node_modules/@murphai/core/dist/family/index.d.ts.map +1 -0
  170. package/node_modules/@murphai/core/dist/family/index.js +3 -0
  171. package/node_modules/@murphai/core/dist/family/index.js.map +1 -0
  172. package/node_modules/@murphai/core/dist/family/types.d.ts +34 -0
  173. package/node_modules/@murphai/core/dist/family/types.d.ts.map +1 -0
  174. package/node_modules/@murphai/core/dist/family/types.js +2 -0
  175. package/node_modules/@murphai/core/dist/family/types.js.map +1 -0
  176. package/node_modules/@murphai/core/dist/frontmatter.d.ts +4 -0
  177. package/node_modules/@murphai/core/dist/frontmatter.d.ts.map +1 -0
  178. package/node_modules/@murphai/core/dist/frontmatter.js +99 -0
  179. package/node_modules/@murphai/core/dist/frontmatter.js.map +1 -0
  180. package/node_modules/@murphai/core/dist/fs.d.ts +22 -0
  181. package/node_modules/@murphai/core/dist/fs.d.ts.map +1 -0
  182. package/node_modules/@murphai/core/dist/fs.js +172 -0
  183. package/node_modules/@murphai/core/dist/fs.js.map +1 -0
  184. package/node_modules/@murphai/core/dist/genetics/api.d.ts +5 -0
  185. package/node_modules/@murphai/core/dist/genetics/api.d.ts.map +1 -0
  186. package/node_modules/@murphai/core/dist/genetics/api.js +226 -0
  187. package/node_modules/@murphai/core/dist/genetics/api.js.map +1 -0
  188. package/node_modules/@murphai/core/dist/genetics/index.d.ts +3 -0
  189. package/node_modules/@murphai/core/dist/genetics/index.d.ts.map +1 -0
  190. package/node_modules/@murphai/core/dist/genetics/index.js +3 -0
  191. package/node_modules/@murphai/core/dist/genetics/index.js.map +1 -0
  192. package/node_modules/@murphai/core/dist/genetics/types.d.ts +40 -0
  193. package/node_modules/@murphai/core/dist/genetics/types.d.ts.map +1 -0
  194. package/node_modules/@murphai/core/dist/genetics/types.js +4 -0
  195. package/node_modules/@murphai/core/dist/genetics/types.js.map +1 -0
  196. package/node_modules/@murphai/core/dist/history/api.d.ts +7 -0
  197. package/node_modules/@murphai/core/dist/history/api.d.ts.map +1 -0
  198. package/node_modules/@murphai/core/dist/history/api.js +473 -0
  199. package/node_modules/@murphai/core/dist/history/api.js.map +1 -0
  200. package/node_modules/@murphai/core/dist/history/event-spine.d.ts +41 -0
  201. package/node_modules/@murphai/core/dist/history/event-spine.d.ts.map +1 -0
  202. package/node_modules/@murphai/core/dist/history/event-spine.js +111 -0
  203. package/node_modules/@murphai/core/dist/history/event-spine.js.map +1 -0
  204. package/node_modules/@murphai/core/dist/history/index.d.ts +3 -0
  205. package/node_modules/@murphai/core/dist/history/index.d.ts.map +1 -0
  206. package/node_modules/@murphai/core/dist/history/index.js +3 -0
  207. package/node_modules/@murphai/core/dist/history/index.js.map +1 -0
  208. package/node_modules/@murphai/core/dist/history/shared.d.ts +25 -0
  209. package/node_modules/@murphai/core/dist/history/shared.d.ts.map +1 -0
  210. package/node_modules/@murphai/core/dist/history/shared.js +144 -0
  211. package/node_modules/@murphai/core/dist/history/shared.js.map +1 -0
  212. package/node_modules/@murphai/core/dist/history/types.d.ts +127 -0
  213. package/node_modules/@murphai/core/dist/history/types.d.ts.map +1 -0
  214. package/node_modules/@murphai/core/dist/history/types.js +8 -0
  215. package/node_modules/@murphai/core/dist/history/types.js.map +1 -0
  216. package/node_modules/@murphai/core/dist/ids.d.ts +3 -0
  217. package/node_modules/@murphai/core/dist/ids.d.ts.map +1 -0
  218. package/node_modules/@murphai/core/dist/ids.js +20 -0
  219. package/node_modules/@murphai/core/dist/ids.js.map +1 -0
  220. package/node_modules/@murphai/core/dist/index.d.ts +30 -0
  221. package/node_modules/@murphai/core/dist/index.d.ts.map +1 -0
  222. package/node_modules/@murphai/core/dist/index.js +23 -0
  223. package/node_modules/@murphai/core/dist/index.js.map +1 -0
  224. package/node_modules/@murphai/core/dist/jsonl.d.ts +12 -0
  225. package/node_modules/@murphai/core/dist/jsonl.d.ts.map +1 -0
  226. package/node_modules/@murphai/core/dist/jsonl.js +40 -0
  227. package/node_modules/@murphai/core/dist/jsonl.js.map +1 -0
  228. package/node_modules/@murphai/core/dist/memory.d.ts +17 -0
  229. package/node_modules/@murphai/core/dist/memory.d.ts.map +1 -0
  230. package/node_modules/@murphai/core/dist/memory.js +72 -0
  231. package/node_modules/@murphai/core/dist/memory.js.map +1 -0
  232. package/node_modules/@murphai/core/dist/mutations.d.ts +150 -0
  233. package/node_modules/@murphai/core/dist/mutations.d.ts.map +1 -0
  234. package/node_modules/@murphai/core/dist/mutations.js +1109 -0
  235. package/node_modules/@murphai/core/dist/mutations.js.map +1 -0
  236. package/node_modules/@murphai/core/dist/operations/canonical-write-lock.d.ts +29 -0
  237. package/node_modules/@murphai/core/dist/operations/canonical-write-lock.d.ts.map +1 -0
  238. package/node_modules/@murphai/core/dist/operations/canonical-write-lock.js +164 -0
  239. package/node_modules/@murphai/core/dist/operations/canonical-write-lock.js.map +1 -0
  240. package/node_modules/@murphai/core/dist/operations/index.d.ts +5 -0
  241. package/node_modules/@murphai/core/dist/operations/index.d.ts.map +1 -0
  242. package/node_modules/@murphai/core/dist/operations/index.js +3 -0
  243. package/node_modules/@murphai/core/dist/operations/index.js.map +1 -0
  244. package/node_modules/@murphai/core/dist/operations/raw-manifests.d.ts +33 -0
  245. package/node_modules/@murphai/core/dist/operations/raw-manifests.d.ts.map +1 -0
  246. package/node_modules/@murphai/core/dist/operations/raw-manifests.js +105 -0
  247. package/node_modules/@murphai/core/dist/operations/raw-manifests.js.map +1 -0
  248. package/node_modules/@murphai/core/dist/operations/write-batch.d.ts +166 -0
  249. package/node_modules/@murphai/core/dist/operations/write-batch.d.ts.map +1 -0
  250. package/node_modules/@murphai/core/dist/operations/write-batch.js +886 -0
  251. package/node_modules/@murphai/core/dist/operations/write-batch.js.map +1 -0
  252. package/node_modules/@murphai/core/dist/path-safety.d.ts +19 -0
  253. package/node_modules/@murphai/core/dist/path-safety.d.ts.map +1 -0
  254. package/node_modules/@murphai/core/dist/path-safety.js +193 -0
  255. package/node_modules/@murphai/core/dist/path-safety.js.map +1 -0
  256. package/node_modules/@murphai/core/dist/profile/index.d.ts +4 -0
  257. package/node_modules/@murphai/core/dist/profile/index.d.ts.map +1 -0
  258. package/node_modules/@murphai/core/dist/profile/index.js +3 -0
  259. package/node_modules/@murphai/core/dist/profile/index.js.map +1 -0
  260. package/node_modules/@murphai/core/dist/profile/storage.d.ts +41 -0
  261. package/node_modules/@murphai/core/dist/profile/storage.d.ts.map +1 -0
  262. package/node_modules/@murphai/core/dist/profile/storage.js +225 -0
  263. package/node_modules/@murphai/core/dist/profile/storage.js.map +1 -0
  264. package/node_modules/@murphai/core/dist/profile/types.d.ts +29 -0
  265. package/node_modules/@murphai/core/dist/profile/types.d.ts.map +1 -0
  266. package/node_modules/@murphai/core/dist/profile/types.js +8 -0
  267. package/node_modules/@murphai/core/dist/profile/types.js.map +1 -0
  268. package/node_modules/@murphai/core/dist/public-mutations.d.ts +120 -0
  269. package/node_modules/@murphai/core/dist/public-mutations.d.ts.map +1 -0
  270. package/node_modules/@murphai/core/dist/public-mutations.js +275 -0
  271. package/node_modules/@murphai/core/dist/public-mutations.js.map +1 -0
  272. package/node_modules/@murphai/core/dist/raw.d.ts +28 -0
  273. package/node_modules/@murphai/core/dist/raw.d.ts.map +1 -0
  274. package/node_modules/@murphai/core/dist/raw.js +107 -0
  275. package/node_modules/@murphai/core/dist/raw.js.map +1 -0
  276. package/node_modules/@murphai/core/dist/registry/api.d.ts +80 -0
  277. package/node_modules/@murphai/core/dist/registry/api.d.ts.map +1 -0
  278. package/node_modules/@murphai/core/dist/registry/api.js +113 -0
  279. package/node_modules/@murphai/core/dist/registry/api.js.map +1 -0
  280. package/node_modules/@murphai/core/dist/registry/id-or-slug.d.ts +15 -0
  281. package/node_modules/@murphai/core/dist/registry/id-or-slug.d.ts.map +1 -0
  282. package/node_modules/@murphai/core/dist/registry/id-or-slug.js +9 -0
  283. package/node_modules/@murphai/core/dist/registry/id-or-slug.js.map +1 -0
  284. package/node_modules/@murphai/core/dist/registry/markdown.d.ts +101 -0
  285. package/node_modules/@murphai/core/dist/registry/markdown.d.ts.map +1 -0
  286. package/node_modules/@murphai/core/dist/registry/markdown.js +136 -0
  287. package/node_modules/@murphai/core/dist/registry/markdown.js.map +1 -0
  288. package/node_modules/@murphai/core/dist/shares.d.ts +36 -0
  289. package/node_modules/@murphai/core/dist/shares.d.ts.map +1 -0
  290. package/node_modules/@murphai/core/dist/shares.js +333 -0
  291. package/node_modules/@murphai/core/dist/shares.js.map +1 -0
  292. package/node_modules/@murphai/core/dist/storage-spine.d.ts +3 -0
  293. package/node_modules/@murphai/core/dist/storage-spine.d.ts.map +1 -0
  294. package/node_modules/@murphai/core/dist/storage-spine.js +3 -0
  295. package/node_modules/@murphai/core/dist/storage-spine.js.map +1 -0
  296. package/node_modules/@murphai/core/dist/time.d.ts +11 -0
  297. package/node_modules/@murphai/core/dist/time.d.ts.map +1 -0
  298. package/node_modules/@murphai/core/dist/time.js +72 -0
  299. package/node_modules/@murphai/core/dist/time.js.map +1 -0
  300. package/node_modules/@murphai/core/dist/types.d.ts +18 -0
  301. package/node_modules/@murphai/core/dist/types.d.ts.map +1 -0
  302. package/node_modules/@murphai/core/dist/types.js +7 -0
  303. package/node_modules/@murphai/core/dist/types.js.map +1 -0
  304. package/node_modules/@murphai/core/dist/vault-core-document.d.ts +8 -0
  305. package/node_modules/@murphai/core/dist/vault-core-document.d.ts.map +1 -0
  306. package/node_modules/@murphai/core/dist/vault-core-document.js +16 -0
  307. package/node_modules/@murphai/core/dist/vault-core-document.js.map +1 -0
  308. package/node_modules/@murphai/core/dist/vault-metadata.d.ts +17 -0
  309. package/node_modules/@murphai/core/dist/vault-metadata.d.ts.map +1 -0
  310. package/node_modules/@murphai/core/dist/vault-metadata.js +44 -0
  311. package/node_modules/@murphai/core/dist/vault-metadata.js.map +1 -0
  312. package/node_modules/@murphai/core/dist/vault-upgrade.d.ts +24 -0
  313. package/node_modules/@murphai/core/dist/vault-upgrade.d.ts.map +1 -0
  314. package/node_modules/@murphai/core/dist/vault-upgrade.js +44 -0
  315. package/node_modules/@murphai/core/dist/vault-upgrade.js.map +1 -0
  316. package/node_modules/@murphai/core/dist/vault.d.ts +40 -0
  317. package/node_modules/@murphai/core/dist/vault.d.ts.map +1 -0
  318. package/node_modules/@murphai/core/dist/vault.js +649 -0
  319. package/node_modules/@murphai/core/dist/vault.js.map +1 -0
  320. package/node_modules/@murphai/core/dist/write-policy.d.ts +63 -0
  321. package/node_modules/@murphai/core/dist/write-policy.d.ts.map +1 -0
  322. package/node_modules/@murphai/core/dist/write-policy.js +146 -0
  323. package/node_modules/@murphai/core/dist/write-policy.js.map +1 -0
  324. package/node_modules/@murphai/core/package.json +27 -0
  325. package/node_modules/@murphai/device-syncd/README.md +123 -0
  326. package/node_modules/@murphai/device-syncd/dist/bin.d.ts +2 -0
  327. package/node_modules/@murphai/device-syncd/dist/bin.d.ts.map +1 -0
  328. package/node_modules/@murphai/device-syncd/dist/bin.js +29 -0
  329. package/node_modules/@murphai/device-syncd/dist/bin.js.map +1 -0
  330. package/node_modules/@murphai/device-syncd/dist/client.d.ts +124 -0
  331. package/node_modules/@murphai/device-syncd/dist/client.d.ts.map +1 -0
  332. package/node_modules/@murphai/device-syncd/dist/client.js +199 -0
  333. package/node_modules/@murphai/device-syncd/dist/client.js.map +1 -0
  334. package/node_modules/@murphai/device-syncd/dist/config.d.ts +18 -0
  335. package/node_modules/@murphai/device-syncd/dist/config.d.ts.map +1 -0
  336. package/node_modules/@murphai/device-syncd/dist/config.js +279 -0
  337. package/node_modules/@murphai/device-syncd/dist/config.js.map +1 -0
  338. package/node_modules/@murphai/device-syncd/dist/crypto.d.ts +6 -0
  339. package/node_modules/@murphai/device-syncd/dist/crypto.d.ts.map +1 -0
  340. package/node_modules/@murphai/device-syncd/dist/crypto.js +27 -0
  341. package/node_modules/@murphai/device-syncd/dist/crypto.js.map +1 -0
  342. package/node_modules/@murphai/device-syncd/dist/errors.d.ts +21 -0
  343. package/node_modules/@murphai/device-syncd/dist/errors.d.ts.map +1 -0
  344. package/node_modules/@murphai/device-syncd/dist/errors.js +32 -0
  345. package/node_modules/@murphai/device-syncd/dist/errors.js.map +1 -0
  346. package/node_modules/@murphai/device-syncd/dist/hosted-hints.d.ts +3 -0
  347. package/node_modules/@murphai/device-syncd/dist/hosted-hints.d.ts.map +1 -0
  348. package/node_modules/@murphai/device-syncd/dist/hosted-hints.js +110 -0
  349. package/node_modules/@murphai/device-syncd/dist/hosted-hints.js.map +1 -0
  350. package/node_modules/@murphai/device-syncd/dist/hosted-runtime.d.ts +139 -0
  351. package/node_modules/@murphai/device-syncd/dist/hosted-runtime.d.ts.map +1 -0
  352. package/node_modules/@murphai/device-syncd/dist/hosted-runtime.js +336 -0
  353. package/node_modules/@murphai/device-syncd/dist/hosted-runtime.js.map +1 -0
  354. package/node_modules/@murphai/device-syncd/dist/http.d.ts +34 -0
  355. package/node_modules/@murphai/device-syncd/dist/http.d.ts.map +1 -0
  356. package/node_modules/@murphai/device-syncd/dist/http.js +644 -0
  357. package/node_modules/@murphai/device-syncd/dist/http.js.map +1 -0
  358. package/node_modules/@murphai/device-syncd/dist/index.d.ts +23 -0
  359. package/node_modules/@murphai/device-syncd/dist/index.d.ts.map +1 -0
  360. package/node_modules/@murphai/device-syncd/dist/index.js +15 -0
  361. package/node_modules/@murphai/device-syncd/dist/index.js.map +1 -0
  362. package/node_modules/@murphai/device-syncd/dist/providers/garmin.d.ts +15 -0
  363. package/node_modules/@murphai/device-syncd/dist/providers/garmin.d.ts.map +1 -0
  364. package/node_modules/@murphai/device-syncd/dist/providers/garmin.js +485 -0
  365. package/node_modules/@murphai/device-syncd/dist/providers/garmin.js.map +1 -0
  366. package/node_modules/@murphai/device-syncd/dist/providers/oura-webhooks.d.ts +49 -0
  367. package/node_modules/@murphai/device-syncd/dist/providers/oura-webhooks.d.ts.map +1 -0
  368. package/node_modules/@murphai/device-syncd/dist/providers/oura-webhooks.js +401 -0
  369. package/node_modules/@murphai/device-syncd/dist/providers/oura-webhooks.js.map +1 -0
  370. package/node_modules/@murphai/device-syncd/dist/providers/oura.d.ts +20 -0
  371. package/node_modules/@murphai/device-syncd/dist/providers/oura.d.ts.map +1 -0
  372. package/node_modules/@murphai/device-syncd/dist/providers/oura.js +804 -0
  373. package/node_modules/@murphai/device-syncd/dist/providers/oura.js.map +1 -0
  374. package/node_modules/@murphai/device-syncd/dist/providers/shared-oauth.d.ts +104 -0
  375. package/node_modules/@murphai/device-syncd/dist/providers/shared-oauth.d.ts.map +1 -0
  376. package/node_modules/@murphai/device-syncd/dist/providers/shared-oauth.js +214 -0
  377. package/node_modules/@murphai/device-syncd/dist/providers/shared-oauth.js.map +1 -0
  378. package/node_modules/@murphai/device-syncd/dist/providers/whoop.d.ts +15 -0
  379. package/node_modules/@murphai/device-syncd/dist/providers/whoop.d.ts.map +1 -0
  380. package/node_modules/@murphai/device-syncd/dist/providers/whoop.js +551 -0
  381. package/node_modules/@murphai/device-syncd/dist/providers/whoop.js.map +1 -0
  382. package/node_modules/@murphai/device-syncd/dist/public-account.d.ts +4 -0
  383. package/node_modules/@murphai/device-syncd/dist/public-account.d.ts.map +1 -0
  384. package/node_modules/@murphai/device-syncd/dist/public-account.js +13 -0
  385. package/node_modules/@murphai/device-syncd/dist/public-account.js.map +1 -0
  386. package/node_modules/@murphai/device-syncd/dist/public-ingress.d.ts +43 -0
  387. package/node_modules/@murphai/device-syncd/dist/public-ingress.d.ts.map +1 -0
  388. package/node_modules/@murphai/device-syncd/dist/public-ingress.js +353 -0
  389. package/node_modules/@murphai/device-syncd/dist/public-ingress.js.map +1 -0
  390. package/node_modules/@murphai/device-syncd/dist/registry.d.ts +3 -0
  391. package/node_modules/@murphai/device-syncd/dist/registry.d.ts.map +1 -0
  392. package/node_modules/@murphai/device-syncd/dist/registry.js +5 -0
  393. package/node_modules/@murphai/device-syncd/dist/registry.js.map +1 -0
  394. package/node_modules/@murphai/device-syncd/dist/service.d.ts +61 -0
  395. package/node_modules/@murphai/device-syncd/dist/service.d.ts.map +1 -0
  396. package/node_modules/@murphai/device-syncd/dist/service.js +496 -0
  397. package/node_modules/@murphai/device-syncd/dist/service.js.map +1 -0
  398. package/node_modules/@murphai/device-syncd/dist/shared.d.ts +26 -0
  399. package/node_modules/@murphai/device-syncd/dist/shared.d.ts.map +1 -0
  400. package/node_modules/@murphai/device-syncd/dist/shared.js +182 -0
  401. package/node_modules/@murphai/device-syncd/dist/shared.js.map +1 -0
  402. package/node_modules/@murphai/device-syncd/dist/store.d.ts +105 -0
  403. package/node_modules/@murphai/device-syncd/dist/store.d.ts.map +1 -0
  404. package/node_modules/@murphai/device-syncd/dist/store.js +965 -0
  405. package/node_modules/@murphai/device-syncd/dist/store.js.map +1 -0
  406. package/node_modules/@murphai/device-syncd/dist/types.d.ts +287 -0
  407. package/node_modules/@murphai/device-syncd/dist/types.d.ts.map +1 -0
  408. package/node_modules/@murphai/device-syncd/dist/types.js +2 -0
  409. package/node_modules/@murphai/device-syncd/dist/types.js.map +1 -0
  410. package/node_modules/@murphai/device-syncd/dist/webhook-verification.d.ts +14 -0
  411. package/node_modules/@murphai/device-syncd/dist/webhook-verification.d.ts.map +1 -0
  412. package/node_modules/@murphai/device-syncd/dist/webhook-verification.js +16 -0
  413. package/node_modules/@murphai/device-syncd/dist/webhook-verification.js.map +1 -0
  414. package/node_modules/@murphai/device-syncd/package.json +85 -0
  415. package/node_modules/@murphai/importers/README.md +34 -0
  416. package/node_modules/@murphai/importers/dist/assessment/core-port.d.ts +13 -0
  417. package/node_modules/@murphai/importers/dist/assessment/core-port.d.ts.map +1 -0
  418. package/node_modules/@murphai/importers/dist/assessment/core-port.js +13 -0
  419. package/node_modules/@murphai/importers/dist/assessment/core-port.js.map +1 -0
  420. package/node_modules/@murphai/importers/dist/assessment/import-assessment-response.d.ts +15 -0
  421. package/node_modules/@murphai/importers/dist/assessment/import-assessment-response.d.ts.map +1 -0
  422. package/node_modules/@murphai/importers/dist/assessment/import-assessment-response.js +32 -0
  423. package/node_modules/@murphai/importers/dist/assessment/import-assessment-response.js.map +1 -0
  424. package/node_modules/@murphai/importers/dist/assessment/index.d.ts +4 -0
  425. package/node_modules/@murphai/importers/dist/assessment/index.d.ts.map +1 -0
  426. package/node_modules/@murphai/importers/dist/assessment/index.js +2 -0
  427. package/node_modules/@murphai/importers/dist/assessment/index.js.map +1 -0
  428. package/node_modules/@murphai/importers/dist/core-port.d.ts +119 -0
  429. package/node_modules/@murphai/importers/dist/core-port.d.ts.map +1 -0
  430. package/node_modules/@murphai/importers/dist/core-port.js +22 -0
  431. package/node_modules/@murphai/importers/dist/core-port.js.map +1 -0
  432. package/node_modules/@murphai/importers/dist/create-importers.d.ts +17 -0
  433. package/node_modules/@murphai/importers/dist/create-importers.d.ts.map +1 -0
  434. package/node_modules/@murphai/importers/dist/create-importers.js +68 -0
  435. package/node_modules/@murphai/importers/dist/create-importers.js.map +1 -0
  436. package/node_modules/@murphai/importers/dist/csv-sample-importer.d.ts +22 -0
  437. package/node_modules/@murphai/importers/dist/csv-sample-importer.d.ts.map +1 -0
  438. package/node_modules/@murphai/importers/dist/csv-sample-importer.js +153 -0
  439. package/node_modules/@murphai/importers/dist/csv-sample-importer.js.map +1 -0
  440. package/node_modules/@murphai/importers/dist/device-providers/defaults.d.ts +5 -0
  441. package/node_modules/@murphai/importers/dist/device-providers/defaults.d.ts.map +1 -0
  442. package/node_modules/@murphai/importers/dist/device-providers/defaults.js +11 -0
  443. package/node_modules/@murphai/importers/dist/device-providers/defaults.js.map +1 -0
  444. package/node_modules/@murphai/importers/dist/device-providers/garmin-activity-normalizers.d.ts +9 -0
  445. package/node_modules/@murphai/importers/dist/device-providers/garmin-activity-normalizers.d.ts.map +1 -0
  446. package/node_modules/@murphai/importers/dist/device-providers/garmin-activity-normalizers.js +172 -0
  447. package/node_modules/@murphai/importers/dist/device-providers/garmin-activity-normalizers.js.map +1 -0
  448. package/node_modules/@murphai/importers/dist/device-providers/garmin-health-normalizers.d.ts +12 -0
  449. package/node_modules/@murphai/importers/dist/device-providers/garmin-health-normalizers.d.ts.map +1 -0
  450. package/node_modules/@murphai/importers/dist/device-providers/garmin-health-normalizers.js +619 -0
  451. package/node_modules/@murphai/importers/dist/device-providers/garmin-health-normalizers.js.map +1 -0
  452. package/node_modules/@murphai/importers/dist/device-providers/garmin-helpers.d.ts +40 -0
  453. package/node_modules/@murphai/importers/dist/device-providers/garmin-helpers.d.ts.map +1 -0
  454. package/node_modules/@murphai/importers/dist/device-providers/garmin-helpers.js +295 -0
  455. package/node_modules/@murphai/importers/dist/device-providers/garmin-helpers.js.map +1 -0
  456. package/node_modules/@murphai/importers/dist/device-providers/garmin.d.ts +19 -0
  457. package/node_modules/@murphai/importers/dist/device-providers/garmin.d.ts.map +1 -0
  458. package/node_modules/@murphai/importers/dist/device-providers/garmin.js +150 -0
  459. package/node_modules/@murphai/importers/dist/device-providers/garmin.js.map +1 -0
  460. package/node_modules/@murphai/importers/dist/device-providers/import-device-provider-snapshot.d.ts +14 -0
  461. package/node_modules/@murphai/importers/dist/device-providers/import-device-provider-snapshot.d.ts.map +1 -0
  462. package/node_modules/@murphai/importers/dist/device-providers/import-device-provider-snapshot.js +37 -0
  463. package/node_modules/@murphai/importers/dist/device-providers/import-device-provider-snapshot.js.map +1 -0
  464. package/node_modules/@murphai/importers/dist/device-providers/index.d.ts +10 -0
  465. package/node_modules/@murphai/importers/dist/device-providers/index.d.ts.map +1 -0
  466. package/node_modules/@murphai/importers/dist/device-providers/index.js +8 -0
  467. package/node_modules/@murphai/importers/dist/device-providers/index.js.map +1 -0
  468. package/node_modules/@murphai/importers/dist/device-providers/oura.d.ts +20 -0
  469. package/node_modules/@murphai/importers/dist/device-providers/oura.d.ts.map +1 -0
  470. package/node_modules/@murphai/importers/dist/device-providers/oura.js +602 -0
  471. package/node_modules/@murphai/importers/dist/device-providers/oura.js.map +1 -0
  472. package/node_modules/@murphai/importers/dist/device-providers/provider-descriptors.d.ts +491 -0
  473. package/node_modules/@murphai/importers/dist/device-providers/provider-descriptors.d.ts.map +1 -0
  474. package/node_modules/@murphai/importers/dist/device-providers/provider-descriptors.js +326 -0
  475. package/node_modules/@murphai/importers/dist/device-providers/provider-descriptors.js.map +1 -0
  476. package/node_modules/@murphai/importers/dist/device-providers/registry.d.ts +9 -0
  477. package/node_modules/@murphai/importers/dist/device-providers/registry.d.ts.map +1 -0
  478. package/node_modules/@murphai/importers/dist/device-providers/registry.js +5 -0
  479. package/node_modules/@murphai/importers/dist/device-providers/registry.js.map +1 -0
  480. package/node_modules/@murphai/importers/dist/device-providers/shared-normalization.d.ts +81 -0
  481. package/node_modules/@murphai/importers/dist/device-providers/shared-normalization.d.ts.map +1 -0
  482. package/node_modules/@murphai/importers/dist/device-providers/shared-normalization.js +215 -0
  483. package/node_modules/@murphai/importers/dist/device-providers/shared-normalization.js.map +1 -0
  484. package/node_modules/@murphai/importers/dist/device-providers/types.d.ts +12 -0
  485. package/node_modules/@murphai/importers/dist/device-providers/types.d.ts.map +1 -0
  486. package/node_modules/@murphai/importers/dist/device-providers/types.js +2 -0
  487. package/node_modules/@murphai/importers/dist/device-providers/types.js.map +1 -0
  488. package/node_modules/@murphai/importers/dist/device-providers/whoop.d.ts +16 -0
  489. package/node_modules/@murphai/importers/dist/device-providers/whoop.d.ts.map +1 -0
  490. package/node_modules/@murphai/importers/dist/device-providers/whoop.js +410 -0
  491. package/node_modules/@murphai/importers/dist/device-providers/whoop.js.map +1 -0
  492. package/node_modules/@murphai/importers/dist/document-importer.d.ts +15 -0
  493. package/node_modules/@murphai/importers/dist/document-importer.d.ts.map +1 -0
  494. package/node_modules/@murphai/importers/dist/document-importer.js +31 -0
  495. package/node_modules/@murphai/importers/dist/document-importer.js.map +1 -0
  496. package/node_modules/@murphai/importers/dist/index.d.ts +10 -0
  497. package/node_modules/@murphai/importers/dist/index.d.ts.map +1 -0
  498. package/node_modules/@murphai/importers/dist/index.js +9 -0
  499. package/node_modules/@murphai/importers/dist/index.js.map +1 -0
  500. package/node_modules/@murphai/importers/dist/meal-importer.d.ts +15 -0
  501. package/node_modules/@murphai/importers/dist/meal-importer.d.ts.map +1 -0
  502. package/node_modules/@murphai/importers/dist/meal-importer.js +39 -0
  503. package/node_modules/@murphai/importers/dist/meal-importer.js.map +1 -0
  504. package/node_modules/@murphai/importers/dist/preset-registry.d.ts +31 -0
  505. package/node_modules/@murphai/importers/dist/preset-registry.d.ts.map +1 -0
  506. package/node_modules/@murphai/importers/dist/preset-registry.js +96 -0
  507. package/node_modules/@murphai/importers/dist/preset-registry.js.map +1 -0
  508. package/node_modules/@murphai/importers/dist/shared.d.ts +31 -0
  509. package/node_modules/@murphai/importers/dist/shared.d.ts.map +1 -0
  510. package/node_modules/@murphai/importers/dist/shared.js +154 -0
  511. package/node_modules/@murphai/importers/dist/shared.js.map +1 -0
  512. package/node_modules/@murphai/importers/package.json +36 -0
  513. package/node_modules/@murphai/runtime-state/README.md +37 -0
  514. package/node_modules/@murphai/runtime-state/dist/assistant-local-state-descriptors.d.ts +3 -0
  515. package/node_modules/@murphai/runtime-state/dist/assistant-local-state-descriptors.d.ts.map +1 -0
  516. package/node_modules/@murphai/runtime-state/dist/assistant-local-state-descriptors.js +80 -0
  517. package/node_modules/@murphai/runtime-state/dist/assistant-local-state-descriptors.js.map +1 -0
  518. package/node_modules/@murphai/runtime-state/dist/assistant-state-security.d.ts +29 -0
  519. package/node_modules/@murphai/runtime-state/dist/assistant-state-security.d.ts.map +1 -0
  520. package/node_modules/@murphai/runtime-state/dist/assistant-state-security.js +159 -0
  521. package/node_modules/@murphai/runtime-state/dist/assistant-state-security.js.map +1 -0
  522. package/node_modules/@murphai/runtime-state/dist/assistant-state.d.ts +33 -0
  523. package/node_modules/@murphai/runtime-state/dist/assistant-state.d.ts.map +1 -0
  524. package/node_modules/@murphai/runtime-state/dist/assistant-state.js +47 -0
  525. package/node_modules/@murphai/runtime-state/dist/assistant-state.js.map +1 -0
  526. package/node_modules/@murphai/runtime-state/dist/assistant-usage.d.ts +56 -0
  527. package/node_modules/@murphai/runtime-state/dist/assistant-usage.d.ts.map +1 -0
  528. package/node_modules/@murphai/runtime-state/dist/assistant-usage.js +189 -0
  529. package/node_modules/@murphai/runtime-state/dist/assistant-usage.js.map +1 -0
  530. package/node_modules/@murphai/runtime-state/dist/atomic-write.d.ts +7 -0
  531. package/node_modules/@murphai/runtime-state/dist/atomic-write.d.ts.map +1 -0
  532. package/node_modules/@murphai/runtime-state/dist/atomic-write.js +27 -0
  533. package/node_modules/@murphai/runtime-state/dist/atomic-write.js.map +1 -0
  534. package/node_modules/@murphai/runtime-state/dist/device-sync-local-state-descriptors.d.ts +3 -0
  535. package/node_modules/@murphai/runtime-state/dist/device-sync-local-state-descriptors.d.ts.map +1 -0
  536. package/node_modules/@murphai/runtime-state/dist/device-sync-local-state-descriptors.js +12 -0
  537. package/node_modules/@murphai/runtime-state/dist/device-sync-local-state-descriptors.js.map +1 -0
  538. package/node_modules/@murphai/runtime-state/dist/gateway-local-state-descriptors.d.ts +3 -0
  539. package/node_modules/@murphai/runtime-state/dist/gateway-local-state-descriptors.d.ts.map +1 -0
  540. package/node_modules/@murphai/runtime-state/dist/gateway-local-state-descriptors.js +13 -0
  541. package/node_modules/@murphai/runtime-state/dist/gateway-local-state-descriptors.js.map +1 -0
  542. package/node_modules/@murphai/runtime-state/dist/hosted-bundle-node.d.ts +43 -0
  543. package/node_modules/@murphai/runtime-state/dist/hosted-bundle-node.d.ts.map +1 -0
  544. package/node_modules/@murphai/runtime-state/dist/hosted-bundle-node.js +203 -0
  545. package/node_modules/@murphai/runtime-state/dist/hosted-bundle-node.js.map +1 -0
  546. package/node_modules/@murphai/runtime-state/dist/hosted-bundle-ref.d.ts +13 -0
  547. package/node_modules/@murphai/runtime-state/dist/hosted-bundle-ref.d.ts.map +1 -0
  548. package/node_modules/@murphai/runtime-state/dist/hosted-bundle-ref.js +46 -0
  549. package/node_modules/@murphai/runtime-state/dist/hosted-bundle-ref.js.map +1 -0
  550. package/node_modules/@murphai/runtime-state/dist/hosted-bundle.d.ts +67 -0
  551. package/node_modules/@murphai/runtime-state/dist/hosted-bundle.d.ts.map +1 -0
  552. package/node_modules/@murphai/runtime-state/dist/hosted-bundle.js +261 -0
  553. package/node_modules/@murphai/runtime-state/dist/hosted-bundle.js.map +1 -0
  554. package/node_modules/@murphai/runtime-state/dist/hosted-bundles.d.ts +31 -0
  555. package/node_modules/@murphai/runtime-state/dist/hosted-bundles.d.ts.map +1 -0
  556. package/node_modules/@murphai/runtime-state/dist/hosted-bundles.js +211 -0
  557. package/node_modules/@murphai/runtime-state/dist/hosted-bundles.js.map +1 -0
  558. package/node_modules/@murphai/runtime-state/dist/hosted-email.d.ts +50 -0
  559. package/node_modules/@murphai/runtime-state/dist/hosted-email.d.ts.map +1 -0
  560. package/node_modules/@murphai/runtime-state/dist/hosted-email.js +191 -0
  561. package/node_modules/@murphai/runtime-state/dist/hosted-email.js.map +1 -0
  562. package/node_modules/@murphai/runtime-state/dist/hosted-user-env.d.ts +14 -0
  563. package/node_modules/@murphai/runtime-state/dist/hosted-user-env.d.ts.map +1 -0
  564. package/node_modules/@murphai/runtime-state/dist/hosted-user-env.js +59 -0
  565. package/node_modules/@murphai/runtime-state/dist/hosted-user-env.js.map +1 -0
  566. package/node_modules/@murphai/runtime-state/dist/hosted-user-keys.d.ts +83 -0
  567. package/node_modules/@murphai/runtime-state/dist/hosted-user-keys.d.ts.map +1 -0
  568. package/node_modules/@murphai/runtime-state/dist/hosted-user-keys.js +308 -0
  569. package/node_modules/@murphai/runtime-state/dist/hosted-user-keys.js.map +1 -0
  570. package/node_modules/@murphai/runtime-state/dist/inbox-local-state-descriptors.d.ts +3 -0
  571. package/node_modules/@murphai/runtime-state/dist/inbox-local-state-descriptors.d.ts.map +1 -0
  572. package/node_modules/@murphai/runtime-state/dist/inbox-local-state-descriptors.js +18 -0
  573. package/node_modules/@murphai/runtime-state/dist/inbox-local-state-descriptors.js.map +1 -0
  574. package/node_modules/@murphai/runtime-state/dist/index.d.ts +7 -0
  575. package/node_modules/@murphai/runtime-state/dist/index.d.ts.map +1 -0
  576. package/node_modules/@murphai/runtime-state/dist/index.js +7 -0
  577. package/node_modules/@murphai/runtime-state/dist/index.js.map +1 -0
  578. package/node_modules/@murphai/runtime-state/dist/local-state-descriptor-helpers.d.ts +31 -0
  579. package/node_modules/@murphai/runtime-state/dist/local-state-descriptor-helpers.d.ts.map +1 -0
  580. package/node_modules/@murphai/runtime-state/dist/local-state-descriptor-helpers.js +120 -0
  581. package/node_modules/@murphai/runtime-state/dist/local-state-descriptor-helpers.js.map +1 -0
  582. package/node_modules/@murphai/runtime-state/dist/local-state-descriptor-manifests.d.ts +3 -0
  583. package/node_modules/@murphai/runtime-state/dist/local-state-descriptor-manifests.d.ts.map +1 -0
  584. package/node_modules/@murphai/runtime-state/dist/local-state-descriptor-manifests.js +17 -0
  585. package/node_modules/@murphai/runtime-state/dist/local-state-descriptor-manifests.js.map +1 -0
  586. package/node_modules/@murphai/runtime-state/dist/local-state-files.d.ts +10 -0
  587. package/node_modules/@murphai/runtime-state/dist/local-state-files.d.ts.map +1 -0
  588. package/node_modules/@murphai/runtime-state/dist/local-state-files.js +27 -0
  589. package/node_modules/@murphai/runtime-state/dist/local-state-files.js.map +1 -0
  590. package/node_modules/@murphai/runtime-state/dist/local-state-taxonomy.d.ts +29 -0
  591. package/node_modules/@murphai/runtime-state/dist/local-state-taxonomy.d.ts.map +1 -0
  592. package/node_modules/@murphai/runtime-state/dist/local-state-taxonomy.js +82 -0
  593. package/node_modules/@murphai/runtime-state/dist/local-state-taxonomy.js.map +1 -0
  594. package/node_modules/@murphai/runtime-state/dist/locks.d.ts +46 -0
  595. package/node_modules/@murphai/runtime-state/dist/locks.d.ts.map +1 -0
  596. package/node_modules/@murphai/runtime-state/dist/locks.js +187 -0
  597. package/node_modules/@murphai/runtime-state/dist/locks.js.map +1 -0
  598. package/node_modules/@murphai/runtime-state/dist/loopback-control-plane.d.ts +4 -0
  599. package/node_modules/@murphai/runtime-state/dist/loopback-control-plane.d.ts.map +1 -0
  600. package/node_modules/@murphai/runtime-state/dist/loopback-control-plane.js +35 -0
  601. package/node_modules/@murphai/runtime-state/dist/loopback-control-plane.js.map +1 -0
  602. package/node_modules/@murphai/runtime-state/dist/node/index.d.ts +22 -0
  603. package/node_modules/@murphai/runtime-state/dist/node/index.d.ts.map +1 -0
  604. package/node_modules/@murphai/runtime-state/dist/node/index.js +22 -0
  605. package/node_modules/@murphai/runtime-state/dist/node/index.js.map +1 -0
  606. package/node_modules/@murphai/runtime-state/dist/parser-local-state-descriptors.d.ts +3 -0
  607. package/node_modules/@murphai/runtime-state/dist/parser-local-state-descriptors.d.ts.map +1 -0
  608. package/node_modules/@murphai/runtime-state/dist/parser-local-state-descriptors.js +12 -0
  609. package/node_modules/@murphai/runtime-state/dist/parser-local-state-descriptors.js.map +1 -0
  610. package/node_modules/@murphai/runtime-state/dist/process-env.d.ts +4 -0
  611. package/node_modules/@murphai/runtime-state/dist/process-env.d.ts.map +1 -0
  612. package/node_modules/@murphai/runtime-state/dist/process-env.js +124 -0
  613. package/node_modules/@murphai/runtime-state/dist/process-env.js.map +1 -0
  614. package/node_modules/@murphai/runtime-state/dist/query-local-state-descriptors.d.ts +3 -0
  615. package/node_modules/@murphai/runtime-state/dist/query-local-state-descriptors.d.ts.map +1 -0
  616. package/node_modules/@murphai/runtime-state/dist/query-local-state-descriptors.js +13 -0
  617. package/node_modules/@murphai/runtime-state/dist/query-local-state-descriptors.js.map +1 -0
  618. package/node_modules/@murphai/runtime-state/dist/runtime-paths.d.ts +48 -0
  619. package/node_modules/@murphai/runtime-state/dist/runtime-paths.d.ts.map +1 -0
  620. package/node_modules/@murphai/runtime-state/dist/runtime-paths.js +93 -0
  621. package/node_modules/@murphai/runtime-state/dist/runtime-paths.js.map +1 -0
  622. package/node_modules/@murphai/runtime-state/dist/shared.d.ts +14 -0
  623. package/node_modules/@murphai/runtime-state/dist/shared.d.ts.map +1 -0
  624. package/node_modules/@murphai/runtime-state/dist/shared.js +46 -0
  625. package/node_modules/@murphai/runtime-state/dist/shared.js.map +1 -0
  626. package/node_modules/@murphai/runtime-state/dist/sqlite.d.ts +26 -0
  627. package/node_modules/@murphai/runtime-state/dist/sqlite.d.ts.map +1 -0
  628. package/node_modules/@murphai/runtime-state/dist/sqlite.js +110 -0
  629. package/node_modules/@murphai/runtime-state/dist/sqlite.js.map +1 -0
  630. package/node_modules/@murphai/runtime-state/dist/ulid.d.ts +5 -0
  631. package/node_modules/@murphai/runtime-state/dist/ulid.d.ts.map +1 -0
  632. package/node_modules/@murphai/runtime-state/dist/ulid.js +31 -0
  633. package/node_modules/@murphai/runtime-state/dist/ulid.js.map +1 -0
  634. package/node_modules/@murphai/runtime-state/dist/versioned-json-files.d.ts +24 -0
  635. package/node_modules/@murphai/runtime-state/dist/versioned-json-files.d.ts.map +1 -0
  636. package/node_modules/@murphai/runtime-state/dist/versioned-json-files.js +30 -0
  637. package/node_modules/@murphai/runtime-state/dist/versioned-json-files.js.map +1 -0
  638. package/node_modules/@murphai/runtime-state/dist/versioned-json-state.d.ts +18 -0
  639. package/node_modules/@murphai/runtime-state/dist/versioned-json-state.d.ts.map +1 -0
  640. package/node_modules/@murphai/runtime-state/dist/versioned-json-state.js +25 -0
  641. package/node_modules/@murphai/runtime-state/dist/versioned-json-state.js.map +1 -0
  642. package/node_modules/@murphai/runtime-state/dist/write-operation-local-state-descriptors.d.ts +3 -0
  643. package/node_modules/@murphai/runtime-state/dist/write-operation-local-state-descriptors.d.ts.map +1 -0
  644. package/node_modules/@murphai/runtime-state/dist/write-operation-local-state-descriptors.js +12 -0
  645. package/node_modules/@murphai/runtime-state/dist/write-operation-local-state-descriptors.js.map +1 -0
  646. package/node_modules/@murphai/runtime-state/package.json +30 -0
  647. package/package.json +45 -11
  648. package/dist/.tsbuildinfo +0 -1
  649. package/dist/callback-hosts.d.ts +0 -19
  650. package/dist/callback-hosts.d.ts.map +0 -1
  651. package/dist/callback-hosts.js +0 -19
  652. package/dist/callback-hosts.js.map +0 -1
  653. package/dist/web-control-plane.d.ts +0 -105
  654. package/dist/web-control-plane.d.ts.map +0 -1
  655. package/dist/web-control-plane.js +0 -358
  656. package/dist/web-control-plane.js.map +0 -1
@@ -0,0 +1,1109 @@
1
+ import { createHash } from "node:crypto";
2
+ import { experimentFrontmatterSchema, journalDayFrontmatterSchema, eventRecordSchema, safeParseContract, sampleRecordSchema, } from "@murphai/contracts";
3
+ import { BASELINE_EVENT_KINDS, BASELINE_SAMPLE_STREAMS, EVENT_SCHEMA_VERSION, EVENT_SOURCES, FRONTMATTER_SCHEMA_VERSIONS, ID_PREFIXES, SAMPLE_QUALITIES, SAMPLE_SCHEMA_VERSION, SAMPLE_SOURCES, VAULT_LAYOUT, } from "./constants.js";
4
+ import { emitAuditRecord } from "./audit.js";
5
+ import { buildAttachmentCompatibilityProjections, buildAttachmentPathCompatibilityProjections, prepareEventAttachments, stagePreparedEventAttachmentsInBatch, } from "./event-attachments.js";
6
+ import { canonicalizeEventRelations } from "./event-links.js";
7
+ import { VaultError } from "./errors.js";
8
+ import { pathExists, readUtf8File, writeVaultTextFile } from "./fs.js";
9
+ import { parseFrontmatterDocument, stringifyFrontmatterDocument } from "./frontmatter.js";
10
+ import { generateRecordId } from "./ids.js";
11
+ import { readJsonlRecords, toMonthlyShardRelativePath } from "./jsonl.js";
12
+ import { stageRawImportManifest } from "./operations/raw-manifests.js";
13
+ import { runCanonicalWrite } from "./operations/write-batch.js";
14
+ import { resolveVaultPath } from "./path-safety.js";
15
+ import { sanitizePathSegment } from "./path-safety.js";
16
+ import { prepareInlineRawArtifact, prepareRawArtifact } from "./raw.js";
17
+ import { defaultTimeZone, normalizeTimeZone, toIsoTimestamp, toLocalDayKey, } from "./time.js";
18
+ import { loadVault } from "./vault.js";
19
+ const EVENT_KIND_SET = new Set(BASELINE_EVENT_KINDS);
20
+ const EVENT_SOURCE_SET = new Set(EVENT_SOURCES);
21
+ const SAMPLE_STREAM_SET = new Set(BASELINE_SAMPLE_STREAMS);
22
+ const SAMPLE_SOURCE_SET = new Set(SAMPLE_SOURCES);
23
+ const SAMPLE_QUALITY_SET = new Set(SAMPLE_QUALITIES);
24
+ function compactRecord(record) {
25
+ return Object.fromEntries(Object.entries(record).filter(([, value]) => {
26
+ if (value === undefined || value === null) {
27
+ return false;
28
+ }
29
+ if (Array.isArray(value)) {
30
+ return true;
31
+ }
32
+ if (typeof value === "object") {
33
+ return Object.keys(value).length > 0;
34
+ }
35
+ return true;
36
+ }));
37
+ }
38
+ function stableSortValue(value) {
39
+ if (Array.isArray(value)) {
40
+ return value.map((entry) => stableSortValue(entry));
41
+ }
42
+ if (value && typeof value === "object") {
43
+ const entries = Object.entries(value)
44
+ .filter(([, entry]) => entry !== undefined)
45
+ .sort(([left], [right]) => left.localeCompare(right))
46
+ .map(([key, entry]) => [key, stableSortValue(entry)]);
47
+ return Object.fromEntries(entries);
48
+ }
49
+ return value;
50
+ }
51
+ function stableStringify(value) {
52
+ return JSON.stringify(stableSortValue(value));
53
+ }
54
+ function normalizeExternalRef(value) {
55
+ if (value === undefined || value === null) {
56
+ return undefined;
57
+ }
58
+ const candidate = assertPlainObject(value, "VAULT_INVALID_EXTERNAL_REF", "externalRef must be a plain object.");
59
+ return compactRecord({
60
+ system: typeof candidate.system === "string" ? candidate.system.trim() : undefined,
61
+ resourceType: typeof candidate.resourceType === "string" ? candidate.resourceType.trim() : undefined,
62
+ resourceId: typeof candidate.resourceId === "string" ? candidate.resourceId.trim() : undefined,
63
+ version: typeof candidate.version === "string" && candidate.version.trim()
64
+ ? candidate.version.trim()
65
+ : undefined,
66
+ facet: typeof candidate.facet === "string" && candidate.facet.trim()
67
+ ? candidate.facet.trim()
68
+ : undefined,
69
+ });
70
+ }
71
+ function normalizeLooseRecord(value, code, message) {
72
+ if (value === undefined || value === null) {
73
+ return undefined;
74
+ }
75
+ return assertPlainObject(value, code, message);
76
+ }
77
+ function normalizeDayKeyInput(value) {
78
+ return typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value.trim())
79
+ ? value.trim()
80
+ : undefined;
81
+ }
82
+ function normalizeRequiredRole(value, label) {
83
+ const candidate = String(value ?? "").trim();
84
+ if (!candidate) {
85
+ throw new VaultError("VAULT_INVALID_RAW_ROLE", `${label} must be a non-empty string.`);
86
+ }
87
+ return candidate;
88
+ }
89
+ function normalizeInlineRawContent(content) {
90
+ if (typeof content === "string") {
91
+ return content;
92
+ }
93
+ if (content === undefined) {
94
+ throw new VaultError("VAULT_INVALID_RAW_CONTENT", "raw artifact content is required.");
95
+ }
96
+ return `${JSON.stringify(stableSortValue(content), null, 2)}\n`;
97
+ }
98
+ function earliestTimestamp(timestamps, fallback = new Date()) {
99
+ if (timestamps.length === 0) {
100
+ return toIsoTimestamp(fallback, "occurredAt");
101
+ }
102
+ return [...timestamps].sort()[0];
103
+ }
104
+ function assertPlainObject(value, code, message) {
105
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
106
+ throw new VaultError(code, message);
107
+ }
108
+ return value;
109
+ }
110
+ function assertContractShape(schema, value, code, message) {
111
+ const result = safeParseContract(schema, value);
112
+ if (!result.success) {
113
+ throw new VaultError(code, `${message} ${JSON.stringify(result.errors)}`, { errors: result.errors });
114
+ }
115
+ }
116
+ function normalizeSource(value, allowed, fallback) {
117
+ return typeof value === "string" && allowed.has(value) ? value : fallback;
118
+ }
119
+ function normalizeSampleInputRecord(value, code, message) {
120
+ return assertPlainObject(value, code, message);
121
+ }
122
+ function trimStringList(value) {
123
+ if (!Array.isArray(value)) {
124
+ return undefined;
125
+ }
126
+ const entries = value
127
+ .filter((entry) => typeof entry === "string")
128
+ .map((entry) => entry.trim())
129
+ .filter(Boolean);
130
+ return entries.length > 0 ? entries : undefined;
131
+ }
132
+ function uniqueTrimmedStringList(value) {
133
+ const entries = trimStringList(value);
134
+ return entries ? [...new Set(entries)] : undefined;
135
+ }
136
+ const NUMERIC_UNIT_ALIASES = {
137
+ glucose: {
138
+ "mg/dl": "mg_dL",
139
+ "mg_dl": "mg_dL",
140
+ mg_dL: "mg_dL",
141
+ },
142
+ heart_rate: {
143
+ bpm: "bpm",
144
+ },
145
+ hrv: {
146
+ ms: "ms",
147
+ },
148
+ steps: {
149
+ count: "count",
150
+ },
151
+ respiratory_rate: {
152
+ breaths_per_minute: "breaths_per_minute",
153
+ "breaths/minute": "breaths_per_minute",
154
+ },
155
+ temperature: {
156
+ celsius: "celsius",
157
+ c: "celsius",
158
+ },
159
+ sleep_stage: {
160
+ stage: "stage",
161
+ },
162
+ };
163
+ const CROCKFORD_BASE32_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
164
+ const EVENT_VALIDATION_PLACEHOLDER_ID = `${ID_PREFIXES.event}_00000000000000000000000000`;
165
+ const SAMPLE_VALIDATION_PLACEHOLDER_ID = `${ID_PREFIXES.sample}_00000000000000000000000000`;
166
+ function normalizeNumericUnit(stream, unit) {
167
+ const normalized = String(unit ?? "").trim();
168
+ const aliases = NUMERIC_UNIT_ALIASES[stream];
169
+ const candidate = aliases[normalized] ??
170
+ aliases[normalized.toLowerCase()];
171
+ if (!candidate) {
172
+ throw new VaultError("VAULT_INVALID_SAMPLE_UNIT", `Unsupported unit "${normalized}" for stream "${stream}".`, {
173
+ stream,
174
+ unit: normalized,
175
+ });
176
+ }
177
+ return candidate;
178
+ }
179
+ function encodeBase32(bytes, length) {
180
+ let output = "";
181
+ let buffer = 0;
182
+ let bits = 0;
183
+ for (const byte of bytes) {
184
+ buffer = (buffer << 8) | byte;
185
+ bits += 8;
186
+ while (bits >= 5 && output.length < length) {
187
+ bits -= 5;
188
+ output += CROCKFORD_BASE32_ALPHABET[(buffer >> bits) & 31];
189
+ }
190
+ }
191
+ if (bits > 0 && output.length < length) {
192
+ output += CROCKFORD_BASE32_ALPHABET[(buffer << (5 - bits)) & 31];
193
+ }
194
+ return output.padEnd(length, "0").slice(0, length);
195
+ }
196
+ function deterministicContractId(prefix, seed) {
197
+ const hash = createHash("sha256").update(seed).digest();
198
+ return `${prefix}_${encodeBase32(hash, 26)}`;
199
+ }
200
+ function buildPreparedAttachmentState(preparedAttachments) {
201
+ const projections = buildAttachmentPathCompatibilityProjections(preparedAttachments.map((attachment) => ({
202
+ role: attachment.role,
203
+ kind: attachment.kind ?? "other",
204
+ relativePath: attachment.raw.relativePath,
205
+ })));
206
+ return {
207
+ projections: {
208
+ audioPaths: projections.audioPaths,
209
+ documentPath: projections.documentPath,
210
+ photoPaths: projections.photoPaths,
211
+ rawRefs: projections.rawRefs,
212
+ },
213
+ };
214
+ }
215
+ function buildNormalizedEventSeed({ kind, occurredAt, recordedAt = new Date(), dayKey, timeZone, defaultTimeZone: fallbackTimeZone, source, title, note, tags, links, relatedIds, rawRefs, externalRef, fields = {}, }) {
216
+ if (!EVENT_KIND_SET.has(kind)) {
217
+ throw new VaultError("VAULT_UNSUPPORTED_EVENT_KIND", `Unsupported baseline event kind "${kind}".`, {
218
+ kind,
219
+ });
220
+ }
221
+ const normalizedFields = assertPlainObject(fields, "VAULT_INVALID_EVENT_FIELDS", "Event fields must be a plain object.");
222
+ const occurredTimestamp = toIsoTimestamp(occurredAt, "occurredAt");
223
+ const recordedTimestamp = toIsoTimestamp(recordedAt, "recordedAt");
224
+ const resolvedTimeZone = normalizeTimeZone(timeZone ?? fallbackTimeZone);
225
+ const resolvedDayKey = normalizeDayKeyInput(dayKey) ??
226
+ toLocalDayKey(occurredTimestamp, resolvedTimeZone ?? defaultTimeZone(), "occurredAt");
227
+ const canonicalRelations = canonicalizeEventRelations({
228
+ links,
229
+ relatedIds,
230
+ normalizeStringList: uniqueTrimmedStringList,
231
+ errorCode: "VAULT_INVALID_INPUT",
232
+ errorMessage: "links entries must be objects with non-empty type and targetId fields.",
233
+ });
234
+ const seed = {
235
+ kind,
236
+ occurredAt: occurredTimestamp,
237
+ recordedAt: recordedTimestamp,
238
+ dayKey: resolvedDayKey,
239
+ timeZone: resolvedTimeZone,
240
+ source: normalizeSource(source, EVENT_SOURCE_SET, "manual"),
241
+ title: typeof title === "string" && title.trim() ? title.trim() : kind,
242
+ note: typeof note === "string" && note.trim() ? note.trim() : undefined,
243
+ tags: trimStringList(tags),
244
+ links: canonicalRelations.links,
245
+ relatedIds: canonicalRelations.relatedIds,
246
+ rawRefs: trimStringList(rawRefs),
247
+ externalRef: normalizeExternalRef(externalRef),
248
+ fields: normalizedFields,
249
+ };
250
+ validateEventSeed(seed);
251
+ return seed;
252
+ }
253
+ function buildEventContractInput(seed, recordId) {
254
+ return compactRecord({
255
+ schemaVersion: EVENT_SCHEMA_VERSION,
256
+ id: recordId,
257
+ kind: seed.kind,
258
+ occurredAt: seed.occurredAt,
259
+ recordedAt: seed.recordedAt,
260
+ dayKey: seed.dayKey,
261
+ timeZone: seed.timeZone,
262
+ source: seed.source,
263
+ title: seed.title,
264
+ note: seed.note,
265
+ tags: seed.tags,
266
+ links: seed.links?.length ? seed.links : undefined,
267
+ relatedIds: seed.relatedIds,
268
+ rawRefs: seed.rawRefs,
269
+ externalRef: seed.externalRef,
270
+ ...seed.fields,
271
+ });
272
+ }
273
+ function validateEventSeed(seed) {
274
+ assertContractShape(eventRecordSchema, buildEventContractInput(seed, EVENT_VALIDATION_PLACEHOLDER_ID), "EVENT_INVALID", "Event record failed contract validation before write.");
275
+ }
276
+ function buildStoredEventRecord(seed, recordId) {
277
+ const record = buildEventContractInput(seed, recordId);
278
+ assertContractShape(eventRecordSchema, record, "EVENT_INVALID", "Event record failed contract validation before write.");
279
+ return record;
280
+ }
281
+ function prepareStoredEventLedgerEntry(seed, recordId) {
282
+ const record = buildStoredEventRecord(seed, recordId);
283
+ return {
284
+ relativePath: toMonthlyShardRelativePath(VAULT_LAYOUT.eventLedgerDirectory, record.occurredAt, "occurredAt"),
285
+ record,
286
+ };
287
+ }
288
+ function prepareEventLedgerEntry({ recordId, ...input }) {
289
+ return prepareStoredEventLedgerEntry(buildNormalizedEventSeed(input), recordId ?? generateRecordId(ID_PREFIXES.event));
290
+ }
291
+ async function stageJsonlRecord(batch, relativePath, record) {
292
+ return batch.stageJsonlAppend(relativePath, `${JSON.stringify(record)}\n`);
293
+ }
294
+ function buildNormalizedSampleSeed({ stream, recordedAt, dayKey, timeZone, defaultTimeZone: fallbackTimeZone, source, quality, sample, unit, externalRef, }) {
295
+ const recordedTimestamp = toIsoTimestamp(sample.recordedAt ?? recordedAt, "recordedAt");
296
+ const normalizedUnit = normalizeNumericUnit(stream, unit);
297
+ const resolvedTimeZone = normalizeTimeZone(timeZone ?? fallbackTimeZone);
298
+ const resolvedDayKey = normalizeDayKeyInput(dayKey) ??
299
+ toLocalDayKey(recordedTimestamp, resolvedTimeZone ?? defaultTimeZone(), "recordedAt");
300
+ const baseSeed = {
301
+ stream,
302
+ recordedAt: recordedTimestamp,
303
+ dayKey: resolvedDayKey,
304
+ timeZone: resolvedTimeZone,
305
+ source: normalizeSource(source, SAMPLE_SOURCE_SET, "import"),
306
+ quality: normalizeSource(quality, SAMPLE_QUALITY_SET, "raw"),
307
+ externalRef: normalizeExternalRef(externalRef),
308
+ };
309
+ const seed = stream === "sleep_stage"
310
+ ? {
311
+ ...baseSeed,
312
+ unit: normalizedUnit,
313
+ measurement: {
314
+ kind: "sleep_stage",
315
+ stage: String(sample.stage ?? "").trim(),
316
+ startAt: toIsoTimestamp(sample.startAt, "startAt"),
317
+ endAt: toIsoTimestamp(sample.endAt, "endAt"),
318
+ durationMinutes: Number(sample.durationMinutes),
319
+ },
320
+ }
321
+ : (() => {
322
+ if (typeof sample.value !== "number" || !Number.isFinite(sample.value)) {
323
+ throw new VaultError("VAULT_INVALID_SAMPLE", "Sample value must be a finite number.", {
324
+ stream,
325
+ sampleSummary: JSON.stringify(sample),
326
+ });
327
+ }
328
+ return {
329
+ ...baseSeed,
330
+ unit: normalizedUnit,
331
+ measurement: {
332
+ kind: "numeric",
333
+ value: sample.value,
334
+ },
335
+ };
336
+ })();
337
+ assertContractShape(sampleRecordSchema, materializeSampleRecord({ seed, recordId: SAMPLE_VALIDATION_PLACEHOLDER_ID }), "SAMPLE_INVALID", "Sample record failed contract validation before write.");
338
+ return seed;
339
+ }
340
+ function materializeSampleRecord({ seed, recordId, }) {
341
+ const measurementFields = seed.measurement.kind === "sleep_stage"
342
+ ? {
343
+ stage: seed.measurement.stage,
344
+ startAt: seed.measurement.startAt,
345
+ endAt: seed.measurement.endAt,
346
+ durationMinutes: seed.measurement.durationMinutes,
347
+ unit: seed.unit,
348
+ }
349
+ : {
350
+ value: seed.measurement.value,
351
+ unit: seed.unit,
352
+ };
353
+ return compactRecord({
354
+ schemaVersion: SAMPLE_SCHEMA_VERSION,
355
+ id: recordId,
356
+ dayKey: seed.dayKey,
357
+ timeZone: seed.timeZone,
358
+ stream: seed.stream,
359
+ recordedAt: seed.recordedAt,
360
+ source: seed.source,
361
+ quality: seed.quality,
362
+ externalRef: seed.externalRef,
363
+ ...measurementFields,
364
+ });
365
+ }
366
+ function finalizeSampleRecord({ seed, recordId, }) {
367
+ const record = materializeSampleRecord({ seed, recordId });
368
+ assertContractShape(sampleRecordSchema, record, "SAMPLE_INVALID", "Sample record failed contract validation before write.");
369
+ return record;
370
+ }
371
+ function buildSampleRecord({ recordId, ...input }) {
372
+ return finalizeSampleRecord({
373
+ seed: buildNormalizedSampleSeed(input),
374
+ recordId: recordId ?? generateRecordId(ID_PREFIXES.sample),
375
+ });
376
+ }
377
+ async function readExistingRecordIds(vaultRoot, relativePath) {
378
+ const resolved = resolveVaultPath(vaultRoot, relativePath);
379
+ if (!(await pathExists(resolved.absolutePath))) {
380
+ return new Set();
381
+ }
382
+ const records = await readJsonlRecords({
383
+ vaultRoot,
384
+ relativePath,
385
+ });
386
+ return new Set(records
387
+ .map((record) => (typeof record.id === "string" ? record.id : null))
388
+ .filter((id) => id !== null));
389
+ }
390
+ async function buildJsonlAppendPlan(vaultRoot, entries, options = {}) {
391
+ const payloads = new Map();
392
+ const existingIdsByShard = new Map();
393
+ const targetShardPaths = [...new Set(entries.map((entry) => entry.relativePath))].sort();
394
+ for (const entry of entries) {
395
+ const existingIds = existingIdsByShard.get(entry.relativePath) ??
396
+ (await readExistingRecordIds(vaultRoot, entry.relativePath));
397
+ existingIdsByShard.set(entry.relativePath, existingIds);
398
+ if (existingIds.has(entry.record.id)) {
399
+ continue;
400
+ }
401
+ if (options.dedupeWithinPlan) {
402
+ existingIds.add(entry.record.id);
403
+ }
404
+ const existingPayload = payloads.get(entry.relativePath) ?? "";
405
+ payloads.set(entry.relativePath, `${existingPayload}${JSON.stringify(entry.record)}\n`);
406
+ }
407
+ return {
408
+ targetShardPaths,
409
+ appendedShardPaths: [...payloads.keys()].sort(),
410
+ payloads,
411
+ };
412
+ }
413
+ async function stageJsonlAppendPlan(batch, appendPlan) {
414
+ for (const relativePath of appendPlan.appendedShardPaths) {
415
+ const payload = appendPlan.payloads.get(relativePath);
416
+ if (!payload) {
417
+ continue;
418
+ }
419
+ await batch.stageJsonlAppend(relativePath, payload);
420
+ }
421
+ }
422
+ function normalizeDeviceEventInputs(eventInputs, context) {
423
+ return eventInputs.map((eventInput, index) => {
424
+ const kind = String(eventInput.kind ?? "").trim();
425
+ if (!EVENT_KIND_SET.has(kind)) {
426
+ throw new VaultError("VAULT_UNSUPPORTED_EVENT_KIND", `Unsupported baseline event kind "${String(eventInput.kind ?? "")}".`, { index });
427
+ }
428
+ const fields = normalizeLooseRecord(eventInput.fields, "VAULT_INVALID_EVENT_FIELDS", `Device event ${index + 1} fields must be a plain object.`) ?? {};
429
+ const rawArtifactRoles = trimStringList(eventInput.rawArtifactRoles) ?? [];
430
+ const seed = buildNormalizedEventSeed({
431
+ kind,
432
+ occurredAt: eventInput.occurredAt ?? eventInput.recordedAt ?? context.importedAt,
433
+ recordedAt: eventInput.recordedAt ?? eventInput.occurredAt,
434
+ dayKey: typeof eventInput.dayKey === "string" ? eventInput.dayKey : undefined,
435
+ timeZone: typeof eventInput.timeZone === "string" ? eventInput.timeZone : undefined,
436
+ defaultTimeZone: context.defaultTimeZone,
437
+ source: eventInput.source ?? context.source,
438
+ title: typeof eventInput.title === "string" ? eventInput.title : undefined,
439
+ note: eventInput.note,
440
+ tags: eventInput.tags,
441
+ relatedIds: eventInput.relatedIds,
442
+ externalRef: eventInput.externalRef,
443
+ fields,
444
+ });
445
+ const { rawRefs: _rawRefs, ...seedRecord } = buildEventContractInput(seed);
446
+ return {
447
+ seed,
448
+ rawArtifactRoles,
449
+ recordId: deterministicContractId(ID_PREFIXES.event, stableStringify({
450
+ provider: context.provider,
451
+ accountId: context.accountId ?? null,
452
+ rawArtifactRoles,
453
+ record: seedRecord,
454
+ })),
455
+ };
456
+ });
457
+ }
458
+ function normalizeDeviceSampleInputs(sampleInputs, context) {
459
+ return sampleInputs.map((sampleInput, index) => {
460
+ const stream = String(sampleInput.stream ?? "").trim();
461
+ if (!SAMPLE_STREAM_SET.has(stream)) {
462
+ throw new VaultError("VAULT_UNSUPPORTED_SAMPLE_STREAM", `Unsupported baseline sample stream "${String(sampleInput.stream ?? "")}".`, { index });
463
+ }
464
+ const sample = normalizeSampleInputRecord(sampleInput.sample, "VAULT_INVALID_SAMPLE", `Device sample ${index + 1} must include a sample object.`);
465
+ const seed = buildNormalizedSampleSeed({
466
+ stream,
467
+ recordedAt: sampleInput.recordedAt ?? sample.recordedAt ?? sample.occurredAt,
468
+ dayKey: typeof sampleInput.dayKey === "string" ? sampleInput.dayKey : undefined,
469
+ timeZone: typeof sampleInput.timeZone === "string" ? sampleInput.timeZone : undefined,
470
+ defaultTimeZone: context.defaultTimeZone,
471
+ source: sampleInput.source ?? context.source,
472
+ quality: sampleInput.quality ?? "normalized",
473
+ sample,
474
+ unit: String(sampleInput.unit ?? ""),
475
+ externalRef: sampleInput.externalRef,
476
+ });
477
+ const record = materializeSampleRecord({ seed });
478
+ return {
479
+ seed,
480
+ recordId: deterministicContractId(ID_PREFIXES.sample, stableStringify({
481
+ provider: context.provider,
482
+ accountId: context.accountId ?? null,
483
+ record,
484
+ })),
485
+ };
486
+ });
487
+ }
488
+ function normalizeDeviceRawArtifactInputs(rawArtifactInputs, provider) {
489
+ const seenRawRoles = new Set();
490
+ return rawArtifactInputs.map((artifactInput, index) => {
491
+ const role = normalizeRequiredRole(artifactInput.role ?? `artifact-${index + 1}`, `raw artifact ${index + 1} role`);
492
+ if (seenRawRoles.has(role)) {
493
+ throw new VaultError("VAULT_DUPLICATE_RAW_ROLE", `Device raw artifact role "${role}" may only appear once per batch.`);
494
+ }
495
+ seenRawRoles.add(role);
496
+ const content = normalizeInlineRawContent(artifactInput.content);
497
+ return {
498
+ role,
499
+ fileName: typeof artifactInput.fileName === "string" && artifactInput.fileName.trim()
500
+ ? artifactInput.fileName.trim()
501
+ : `${provider}-${String(index + 1).padStart(2, "0")}.json`,
502
+ mediaType: typeof artifactInput.mediaType === "string" && artifactInput.mediaType.trim()
503
+ ? artifactInput.mediaType.trim()
504
+ : undefined,
505
+ content,
506
+ metadata: normalizeLooseRecord(artifactInput.metadata, "VAULT_INVALID_RAW_ARTIFACT", `Device raw artifact ${index + 1} metadata must be a plain object.`),
507
+ sha256: createHash("sha256").update(content).digest("hex"),
508
+ index,
509
+ };
510
+ });
511
+ }
512
+ function normalizeDeviceBatchInputs({ provider, accountId, importedAt = new Date(), defaultTimeZone: fallbackTimeZone, source = "device", events = [], samples = [], rawArtifacts = [], provenance, }) {
513
+ const normalizedProvider = sanitizePathSegment(provider, "provider");
514
+ const normalizedAccountId = typeof accountId === "string" && accountId.trim() ? accountId.trim() : undefined;
515
+ const normalizedImportedAt = toIsoTimestamp(importedAt, "importedAt");
516
+ const defaultTimeZone = normalizeTimeZone(fallbackTimeZone);
517
+ const normalizedProvenance = normalizeLooseRecord(provenance, "VAULT_INVALID_DEVICE_PROVENANCE", "Device import provenance must be a plain object.") ?? {};
518
+ const eventInputs = Array.isArray(events)
519
+ ? events.map((event, index) => assertPlainObject(event, "VAULT_INVALID_EVENT", `Device event ${index + 1} must be a plain object.`))
520
+ : [];
521
+ const sampleInputs = Array.isArray(samples)
522
+ ? samples.map((sample, index) => assertPlainObject(sample, "VAULT_INVALID_SAMPLE", `Device sample ${index + 1} must be a plain object.`))
523
+ : [];
524
+ const rawArtifactInputs = Array.isArray(rawArtifacts)
525
+ ? rawArtifacts.map((artifact, index) => assertPlainObject(artifact, "VAULT_INVALID_RAW_ARTIFACT", `Device raw artifact ${index + 1} must be a plain object.`))
526
+ : [];
527
+ if (eventInputs.length === 0 && sampleInputs.length === 0 && rawArtifactInputs.length === 0) {
528
+ throw new VaultError("VAULT_INVALID_DEVICE_BATCH", "importDeviceBatch requires at least one event, sample, or raw artifact.");
529
+ }
530
+ return {
531
+ provider: normalizedProvider,
532
+ accountId: normalizedAccountId,
533
+ importedAt: normalizedImportedAt,
534
+ source,
535
+ defaultTimeZone,
536
+ provenance: normalizedProvenance,
537
+ events: normalizeDeviceEventInputs(eventInputs, {
538
+ provider: normalizedProvider,
539
+ accountId: normalizedAccountId,
540
+ importedAt: normalizedImportedAt,
541
+ source,
542
+ defaultTimeZone,
543
+ }),
544
+ samples: normalizeDeviceSampleInputs(sampleInputs, {
545
+ provider: normalizedProvider,
546
+ accountId: normalizedAccountId,
547
+ source,
548
+ defaultTimeZone,
549
+ }),
550
+ rawArtifacts: normalizeDeviceRawArtifactInputs(rawArtifactInputs, normalizedProvider),
551
+ };
552
+ }
553
+ function prepareDeviceRawArtifacts(rawArtifacts, options) {
554
+ return rawArtifacts.map((artifact) => ({
555
+ role: artifact.role,
556
+ content: artifact.content,
557
+ raw: prepareInlineRawArtifact({
558
+ fileName: artifact.fileName,
559
+ targetName: `${String(artifact.index + 1).padStart(2, "0")}-${artifact.fileName}`,
560
+ mediaType: artifact.mediaType,
561
+ category: "integrations",
562
+ provider: options.provider,
563
+ occurredAt: options.effectiveOccurredAt,
564
+ recordId: options.importId,
565
+ }),
566
+ metadata: artifact.metadata,
567
+ sha256: artifact.sha256,
568
+ }));
569
+ }
570
+ function prepareDeviceEventEntries(events, preparedRawArtifacts) {
571
+ const rawArtifactPathByRole = new Map(preparedRawArtifacts.map((artifact) => [artifact.role, artifact.raw.relativePath]));
572
+ const soleRawArtifactPath = preparedRawArtifacts.length === 1 ? preparedRawArtifacts[0]?.raw.relativePath : undefined;
573
+ return events.map((event) => {
574
+ const rawRefs = event.rawArtifactRoles.length > 0
575
+ ? event.rawArtifactRoles.map((role) => {
576
+ const rawPath = rawArtifactPathByRole.get(role);
577
+ if (!rawPath) {
578
+ throw new VaultError("VAULT_RAW_ROLE_MISSING", `No staged raw artifact matched role "${role}" for device event ${event.recordId}.`);
579
+ }
580
+ return rawPath;
581
+ })
582
+ : soleRawArtifactPath
583
+ ? [soleRawArtifactPath]
584
+ : undefined;
585
+ return prepareStoredEventLedgerEntry({
586
+ ...event.seed,
587
+ rawRefs,
588
+ }, event.recordId);
589
+ });
590
+ }
591
+ function prepareDeviceSampleEntries(samples) {
592
+ return samples.map((sample) => {
593
+ const record = finalizeSampleRecord({
594
+ seed: sample.seed,
595
+ recordId: sample.recordId,
596
+ });
597
+ return {
598
+ record,
599
+ relativePath: toMonthlyShardRelativePath(`${VAULT_LAYOUT.sampleLedgerDirectory}/${sample.seed.stream}`, record.recordedAt, "recordedAt"),
600
+ };
601
+ });
602
+ }
603
+ function prepareDeviceBatchPlan({ provider, accountId, importedAt = new Date(), defaultTimeZone: fallbackTimeZone, source = "device", events = [], samples = [], rawArtifacts = [], provenance, }) {
604
+ const normalizedInputs = normalizeDeviceBatchInputs({
605
+ provider,
606
+ accountId,
607
+ importedAt,
608
+ defaultTimeZone: fallbackTimeZone,
609
+ source,
610
+ events,
611
+ samples,
612
+ rawArtifacts,
613
+ provenance,
614
+ });
615
+ const effectiveOccurredAt = earliestTimestamp([
616
+ ...normalizedInputs.events.map(({ seed }) => seed.occurredAt),
617
+ ...normalizedInputs.samples.map(({ seed }) => seed.recordedAt),
618
+ ], normalizedInputs.importedAt);
619
+ const importId = deterministicContractId(ID_PREFIXES.transform, stableStringify({
620
+ provider: normalizedInputs.provider,
621
+ accountId: normalizedInputs.accountId ?? null,
622
+ eventIds: normalizedInputs.events.map(({ recordId }) => recordId),
623
+ sampleIds: normalizedInputs.samples.map(({ recordId }) => recordId),
624
+ rawArtifacts: normalizedInputs.rawArtifacts.map((artifact) => ({
625
+ role: artifact.role,
626
+ fileName: artifact.fileName,
627
+ mediaType: artifact.mediaType ?? null,
628
+ sha256: artifact.sha256,
629
+ })),
630
+ }));
631
+ const preparedRawArtifacts = prepareDeviceRawArtifacts(normalizedInputs.rawArtifacts, {
632
+ importId,
633
+ provider: normalizedInputs.provider,
634
+ effectiveOccurredAt,
635
+ });
636
+ const preparedEvents = prepareDeviceEventEntries(normalizedInputs.events, preparedRawArtifacts);
637
+ const preparedSamples = prepareDeviceSampleEntries(normalizedInputs.samples);
638
+ return {
639
+ importId,
640
+ provider: normalizedInputs.provider,
641
+ accountId: normalizedInputs.accountId,
642
+ importedAt: normalizedInputs.importedAt,
643
+ source: normalizedInputs.source,
644
+ provenance: normalizedInputs.provenance,
645
+ effectiveOccurredAt,
646
+ preparedEvents,
647
+ preparedSamples,
648
+ preparedRawArtifacts,
649
+ };
650
+ }
651
+ export async function importDocument({ vaultRoot, sourcePath, occurredAt = new Date(), title, note, source = "import", }) {
652
+ const vault = await loadVault({ vaultRoot });
653
+ const documentId = generateRecordId(ID_PREFIXES.document);
654
+ const eventId = generateRecordId(ID_PREFIXES.event);
655
+ const preparedAttachments = prepareEventAttachments({
656
+ ownerKind: "document",
657
+ ownerId: documentId,
658
+ occurredAt,
659
+ attachments: [
660
+ {
661
+ role: "source_document",
662
+ kind: "document",
663
+ sourcePath,
664
+ },
665
+ ],
666
+ });
667
+ const raw = preparedAttachments[0].raw;
668
+ const pendingAttachmentState = buildPreparedAttachmentState(preparedAttachments);
669
+ const eventSeed = buildNormalizedEventSeed({
670
+ kind: "document",
671
+ occurredAt,
672
+ recordedAt: new Date(),
673
+ timeZone: vault.metadata.timezone,
674
+ source,
675
+ title: String(title ?? raw.originalFileName).trim(),
676
+ note,
677
+ relatedIds: [documentId],
678
+ rawRefs: pendingAttachmentState.projections.rawRefs,
679
+ fields: {
680
+ documentId,
681
+ documentPath: pendingAttachmentState.projections.documentPath,
682
+ mimeType: raw.mediaType,
683
+ },
684
+ });
685
+ return runCanonicalWrite({
686
+ vaultRoot,
687
+ operationType: "document_import",
688
+ summary: `Import document ${documentId}`,
689
+ occurredAt,
690
+ mutate: async ({ batch }) => {
691
+ const stagedAttachments = await stagePreparedEventAttachmentsInBatch({
692
+ batch,
693
+ importId: documentId,
694
+ importKind: "document",
695
+ importedAt: eventSeed.recordedAt,
696
+ source: eventSeed.source ?? source ?? null,
697
+ attachments: preparedAttachments,
698
+ provenance: {
699
+ eventId,
700
+ lookupId: documentId,
701
+ occurredAt: eventSeed.occurredAt,
702
+ title: eventSeed.title ?? null,
703
+ note: eventSeed.note ?? null,
704
+ },
705
+ });
706
+ if (!stagedAttachments) {
707
+ throw new VaultError("EVENT_ATTACHMENTS_MISSING", "Document import expected one staged attachment.");
708
+ }
709
+ const projections = buildAttachmentCompatibilityProjections(stagedAttachments.attachments);
710
+ const event = prepareStoredEventLedgerEntry({
711
+ ...eventSeed,
712
+ rawRefs: stagedAttachments.rawRefs,
713
+ fields: {
714
+ ...eventSeed.fields,
715
+ attachments: stagedAttachments.attachments,
716
+ documentPath: projections.documentPath ?? raw.relativePath,
717
+ },
718
+ }, eventId);
719
+ const manifestPath = stagedAttachments.manifestPath;
720
+ await stageJsonlRecord(batch, event.relativePath, event.record);
721
+ const audit = await emitAuditRecord({
722
+ vaultRoot,
723
+ batch,
724
+ action: "document_import",
725
+ commandName: "core.importDocument",
726
+ summary: `Imported document ${raw.originalFileName}.`,
727
+ occurredAt,
728
+ files: [raw.relativePath, manifestPath, event.relativePath],
729
+ targetIds: [documentId, event.record.id],
730
+ });
731
+ return {
732
+ documentId,
733
+ raw,
734
+ event: event.record,
735
+ eventPath: event.relativePath,
736
+ auditPath: audit.relativePath,
737
+ manifestPath,
738
+ };
739
+ },
740
+ });
741
+ }
742
+ export async function addMeal({ vaultRoot, occurredAt = new Date(), note, photoPath, audioPath, source = "manual", }) {
743
+ const vault = await loadVault({ vaultRoot });
744
+ if (!photoPath && !audioPath && !note) {
745
+ throw new VaultError("VAULT_MEAL_CONTENT_REQUIRED", "Meal imports require at least one of photoPath, audioPath, or note.");
746
+ }
747
+ const mealId = generateRecordId(ID_PREFIXES.meal);
748
+ const eventId = generateRecordId(ID_PREFIXES.event);
749
+ const preparedAttachments = prepareEventAttachments({
750
+ ownerKind: "meal",
751
+ ownerId: mealId,
752
+ occurredAt,
753
+ attachments: [
754
+ ...(photoPath
755
+ ? [
756
+ {
757
+ role: "photo",
758
+ kind: "photo",
759
+ sourcePath: photoPath,
760
+ },
761
+ ]
762
+ : []),
763
+ ...(audioPath
764
+ ? [
765
+ {
766
+ role: "audio",
767
+ kind: "audio",
768
+ sourcePath: audioPath,
769
+ },
770
+ ]
771
+ : []),
772
+ ],
773
+ });
774
+ const photo = preparedAttachments.find((attachment) => attachment.role === "photo")?.raw ?? null;
775
+ const audio = preparedAttachments.find((attachment) => attachment.role === "audio")?.raw ?? null;
776
+ const rawDirectory = resolveRawMealDirectory(occurredAt, mealId);
777
+ const pendingAttachmentState = buildPreparedAttachmentState(preparedAttachments);
778
+ const eventSeed = buildNormalizedEventSeed({
779
+ kind: "meal",
780
+ occurredAt,
781
+ recordedAt: new Date(),
782
+ timeZone: vault.metadata.timezone,
783
+ source,
784
+ title: "Meal",
785
+ note,
786
+ relatedIds: [mealId],
787
+ rawRefs: pendingAttachmentState.projections.rawRefs,
788
+ fields: {
789
+ mealId,
790
+ photoPaths: pendingAttachmentState.projections.photoPaths,
791
+ audioPaths: pendingAttachmentState.projections.audioPaths,
792
+ },
793
+ });
794
+ return runCanonicalWrite({
795
+ vaultRoot,
796
+ operationType: "meal_import",
797
+ summary: `Import meal ${mealId}`,
798
+ occurredAt,
799
+ mutate: async ({ batch }) => {
800
+ const stagedAttachments = await stagePreparedEventAttachmentsInBatch({
801
+ batch,
802
+ importId: mealId,
803
+ importKind: "meal",
804
+ importedAt: eventSeed.recordedAt,
805
+ rawDirectory,
806
+ source: eventSeed.source ?? source ?? null,
807
+ attachments: preparedAttachments,
808
+ provenance: {
809
+ eventId,
810
+ lookupId: mealId,
811
+ occurredAt: eventSeed.occurredAt,
812
+ note: eventSeed.note ?? null,
813
+ },
814
+ });
815
+ let rawRefs = eventSeed.rawRefs;
816
+ let attachments;
817
+ let photoPaths = eventSeed.fields.photoPaths;
818
+ let audioPaths = eventSeed.fields.audioPaths;
819
+ if (stagedAttachments) {
820
+ const projections = buildAttachmentCompatibilityProjections(stagedAttachments.attachments);
821
+ rawRefs = projections.rawRefs;
822
+ attachments = stagedAttachments.attachments;
823
+ photoPaths = projections.photoPaths;
824
+ audioPaths = projections.audioPaths;
825
+ }
826
+ const manifestPath = stagedAttachments
827
+ ? stagedAttachments.manifestPath
828
+ : await stageRawImportManifest({
829
+ batch,
830
+ importId: mealId,
831
+ importKind: "meal",
832
+ importedAt: eventSeed.recordedAt,
833
+ rawDirectory,
834
+ source: eventSeed.source ?? source ?? null,
835
+ artifacts: [],
836
+ canonicalProvenance: {
837
+ eventId,
838
+ lookupId: mealId,
839
+ occurredAt: eventSeed.occurredAt,
840
+ note: eventSeed.note ?? null,
841
+ },
842
+ });
843
+ if (!stagedAttachments) {
844
+ rawRefs = [manifestPath];
845
+ }
846
+ const event = prepareStoredEventLedgerEntry({
847
+ ...eventSeed,
848
+ rawRefs,
849
+ fields: {
850
+ ...eventSeed.fields,
851
+ attachments,
852
+ photoPaths,
853
+ audioPaths,
854
+ },
855
+ }, eventId);
856
+ await stageJsonlRecord(batch, event.relativePath, event.record);
857
+ const touchedFiles = [photo?.relativePath, audio?.relativePath, manifestPath, event.relativePath].filter((value) => typeof value === "string");
858
+ const audit = await emitAuditRecord({
859
+ vaultRoot,
860
+ batch,
861
+ action: "meal_add",
862
+ commandName: "core.addMeal",
863
+ summary: `Added meal ${mealId}.`,
864
+ occurredAt,
865
+ files: touchedFiles,
866
+ targetIds: [mealId, event.record.id],
867
+ });
868
+ return {
869
+ mealId,
870
+ event: event.record,
871
+ eventPath: event.relativePath,
872
+ photo,
873
+ audio,
874
+ auditPath: audit.relativePath,
875
+ manifestPath,
876
+ };
877
+ },
878
+ });
879
+ }
880
+ function resolveRawMealDirectory(occurredAt, mealId) {
881
+ const timestamp = toIsoTimestamp(occurredAt, "occurredAt");
882
+ return `${VAULT_LAYOUT.rawMealsDirectory}/${timestamp.slice(0, 4)}/${timestamp.slice(5, 7)}/${mealId}`;
883
+ }
884
+ export async function importSamples({ vaultRoot, stream, unit, samples, sourcePath, source = "import", quality = "raw", batchProvenance, }) {
885
+ const vault = await loadVault({ vaultRoot });
886
+ if (!SAMPLE_STREAM_SET.has(stream)) {
887
+ throw new VaultError("VAULT_UNSUPPORTED_SAMPLE_STREAM", `Unsupported baseline sample stream "${stream}".`, {
888
+ stream,
889
+ });
890
+ }
891
+ if (!Array.isArray(samples) || samples.length === 0) {
892
+ throw new VaultError("VAULT_INVALID_SAMPLES", "importSamples requires a non-empty samples array.");
893
+ }
894
+ const normalizedStream = stream;
895
+ const normalizedSamples = samples.map((sample) => normalizeSampleInputRecord(sample, "VAULT_INVALID_SAMPLE", "Each sample must be a plain object."));
896
+ const transformFingerprint = normalizedSamples.map((sample) => buildSampleRecord({
897
+ stream: normalizedStream,
898
+ recordedAt: sample.recordedAt ?? sample.occurredAt,
899
+ timeZone: vault.metadata.timezone,
900
+ source,
901
+ quality,
902
+ sample,
903
+ unit,
904
+ recordId: `${ID_PREFIXES.sample}_00000000000000000000000000`,
905
+ }));
906
+ const transformId = deterministicContractId(ID_PREFIXES.transform, JSON.stringify({
907
+ stream: normalizedStream,
908
+ unit,
909
+ source,
910
+ quality,
911
+ sourcePath: sourcePath ?? null,
912
+ rows: transformFingerprint.map(({ id, ...record }) => record),
913
+ }));
914
+ const preparedRecords = [];
915
+ for (const [index, normalizedSample] of normalizedSamples.entries()) {
916
+ const record = buildSampleRecord({
917
+ stream: normalizedStream,
918
+ recordedAt: normalizedSample.recordedAt ?? normalizedSample.occurredAt,
919
+ timeZone: vault.metadata.timezone,
920
+ source,
921
+ quality,
922
+ sample: normalizedSample,
923
+ unit,
924
+ recordId: deterministicContractId(ID_PREFIXES.sample, `${transformId}:${index}`),
925
+ });
926
+ const relativePath = toMonthlyShardRelativePath(`${VAULT_LAYOUT.sampleLedgerDirectory}/${normalizedStream}`, record.recordedAt, "recordedAt");
927
+ preparedRecords.push({ record, relativePath });
928
+ }
929
+ const raw = sourcePath
930
+ ? prepareRawArtifact({
931
+ sourcePath,
932
+ category: "samples",
933
+ occurredAt: preparedRecords[0]?.record.recordedAt ?? new Date(),
934
+ recordId: transformId,
935
+ stream: normalizedStream,
936
+ allowExistingMatch: true,
937
+ })
938
+ : null;
939
+ const touchedFiles = raw ? [raw.relativePath] : [];
940
+ const records = preparedRecords.map((entry) => entry.record);
941
+ const appendPlan = await buildJsonlAppendPlan(vaultRoot, preparedRecords);
942
+ const rowProvenance = batchProvenance?.rows ?? [];
943
+ return runCanonicalWrite({
944
+ vaultRoot,
945
+ operationType: "sample_batch_import",
946
+ summary: `Import ${normalizedStream} sample batch ${transformId}`,
947
+ occurredAt: preparedRecords[0]?.record.recordedAt ?? new Date(),
948
+ mutate: async ({ batch }) => {
949
+ const stagedRaw = raw && sourcePath
950
+ ? await batch.stageRawCopy({
951
+ sourcePath,
952
+ targetRelativePath: raw.relativePath,
953
+ originalFileName: raw.originalFileName,
954
+ mediaType: raw.mediaType,
955
+ allowExistingMatch: true,
956
+ })
957
+ : null;
958
+ const manifestPath = stagedRaw
959
+ ? await stageRawImportManifest({
960
+ batch,
961
+ importId: transformId,
962
+ importKind: "sample_batch",
963
+ importedAt: records[0]?.recordedAt ?? new Date().toISOString(),
964
+ source: source ?? null,
965
+ artifacts: [
966
+ {
967
+ role: "source_csv",
968
+ raw: stagedRaw,
969
+ },
970
+ ],
971
+ canonicalProvenance: {
972
+ stream: normalizedStream,
973
+ unit,
974
+ importedCount: records.length,
975
+ sampleIds: records.map((record) => record.id),
976
+ ledgerFiles: appendPlan.targetShardPaths,
977
+ sourceFileName: batchProvenance?.sourceFileName ?? raw?.originalFileName ?? null,
978
+ importConfig: batchProvenance?.importConfig ?? null,
979
+ rowCount: rowProvenance.length,
980
+ rows: rowProvenance,
981
+ },
982
+ })
983
+ : "";
984
+ await stageJsonlAppendPlan(batch, appendPlan);
985
+ const touchedPaths = [...touchedFiles];
986
+ touchedPaths.push(...(manifestPath ? [manifestPath] : []), ...appendPlan.appendedShardPaths);
987
+ const audit = await emitAuditRecord({
988
+ vaultRoot,
989
+ batch,
990
+ action: "samples_import_csv",
991
+ commandName: "core.importSamples",
992
+ summary: `Imported ${records.length} ${normalizedStream} sample record(s).`,
993
+ occurredAt: records[0]?.recordedAt ?? new Date(),
994
+ files: touchedPaths,
995
+ targetIds: records.map((record) => record.id),
996
+ });
997
+ return {
998
+ count: records.length,
999
+ records,
1000
+ shardPaths: appendPlan.targetShardPaths,
1001
+ raw,
1002
+ transformId,
1003
+ auditPath: audit.relativePath,
1004
+ manifestPath,
1005
+ };
1006
+ },
1007
+ });
1008
+ }
1009
+ export async function importDeviceBatch({ vaultRoot, provider, accountId, importedAt = new Date(), source = "device", events = [], samples = [], rawArtifacts = [], provenance, }) {
1010
+ const vault = await loadVault({ vaultRoot });
1011
+ const deviceBatchPlan = prepareDeviceBatchPlan({
1012
+ provider,
1013
+ accountId,
1014
+ importedAt,
1015
+ defaultTimeZone: vault.metadata.timezone,
1016
+ source,
1017
+ events,
1018
+ samples,
1019
+ rawArtifacts,
1020
+ provenance,
1021
+ });
1022
+ const eventAppendPlan = await buildJsonlAppendPlan(vaultRoot, deviceBatchPlan.preparedEvents, {
1023
+ dedupeWithinPlan: true,
1024
+ });
1025
+ const sampleAppendPlan = await buildJsonlAppendPlan(vaultRoot, deviceBatchPlan.preparedSamples, {
1026
+ dedupeWithinPlan: true,
1027
+ });
1028
+ const eventRecords = deviceBatchPlan.preparedEvents.map((entry) => entry.record);
1029
+ const sampleRecords = deviceBatchPlan.preparedSamples.map((entry) => entry.record);
1030
+ return runCanonicalWrite({
1031
+ vaultRoot,
1032
+ operationType: "device_batch_import",
1033
+ summary: `Import ${deviceBatchPlan.provider} device batch ${deviceBatchPlan.importId}`,
1034
+ occurredAt: deviceBatchPlan.effectiveOccurredAt,
1035
+ mutate: async ({ batch }) => {
1036
+ const stagedRawArtifacts = [];
1037
+ for (const artifact of deviceBatchPlan.preparedRawArtifacts) {
1038
+ stagedRawArtifacts.push({
1039
+ role: artifact.role,
1040
+ raw: await batch.stageRawText({
1041
+ targetRelativePath: artifact.raw.relativePath,
1042
+ originalFileName: artifact.raw.originalFileName,
1043
+ mediaType: artifact.raw.mediaType,
1044
+ content: artifact.content,
1045
+ allowExistingMatch: true,
1046
+ }),
1047
+ });
1048
+ }
1049
+ const manifestPath = stagedRawArtifacts.length > 0
1050
+ ? await stageRawImportManifest({
1051
+ batch,
1052
+ importId: deviceBatchPlan.importId,
1053
+ importKind: "device_batch",
1054
+ importedAt: deviceBatchPlan.importedAt,
1055
+ source: deviceBatchPlan.source ?? null,
1056
+ artifacts: stagedRawArtifacts,
1057
+ canonicalProvenance: {
1058
+ provider: deviceBatchPlan.provider,
1059
+ accountId: deviceBatchPlan.accountId ?? null,
1060
+ importedAt: deviceBatchPlan.importedAt,
1061
+ eventCount: eventRecords.length,
1062
+ sampleCount: sampleRecords.length,
1063
+ eventIds: eventRecords.map((record) => record.id),
1064
+ sampleIds: sampleRecords.map((record) => record.id),
1065
+ rawArtifacts: deviceBatchPlan.preparedRawArtifacts.map((artifact) => ({
1066
+ role: artifact.role,
1067
+ relativePath: artifact.raw.relativePath,
1068
+ sha256: artifact.sha256,
1069
+ metadata: artifact.metadata ?? null,
1070
+ })),
1071
+ },
1072
+ operatorMetadata: deviceBatchPlan.provenance,
1073
+ })
1074
+ : "";
1075
+ await stageJsonlAppendPlan(batch, eventAppendPlan);
1076
+ await stageJsonlAppendPlan(batch, sampleAppendPlan);
1077
+ const touchedPaths = [
1078
+ ...deviceBatchPlan.preparedRawArtifacts.map((artifact) => artifact.raw.relativePath),
1079
+ ...(manifestPath ? [manifestPath] : []),
1080
+ ...eventAppendPlan.appendedShardPaths,
1081
+ ...sampleAppendPlan.appendedShardPaths,
1082
+ ];
1083
+ const audit = await emitAuditRecord({
1084
+ vaultRoot,
1085
+ batch,
1086
+ action: "device_import",
1087
+ commandName: "core.importDeviceBatch",
1088
+ summary: `Imported ${deviceBatchPlan.provider} device batch with ${eventRecords.length} event(s) and ${sampleRecords.length} sample(s).`,
1089
+ occurredAt: deviceBatchPlan.importedAt,
1090
+ files: touchedPaths,
1091
+ targetIds: [...eventRecords.map((record) => record.id), ...sampleRecords.map((record) => record.id)],
1092
+ });
1093
+ return {
1094
+ importId: deviceBatchPlan.importId,
1095
+ provider: deviceBatchPlan.provider,
1096
+ accountId: deviceBatchPlan.accountId,
1097
+ importedAt: deviceBatchPlan.importedAt,
1098
+ events: eventRecords,
1099
+ samples: sampleRecords,
1100
+ eventShardPaths: eventAppendPlan.targetShardPaths,
1101
+ sampleShardPaths: sampleAppendPlan.targetShardPaths,
1102
+ rawArtifacts: deviceBatchPlan.preparedRawArtifacts.map((artifact) => artifact.raw),
1103
+ auditPath: audit.relativePath,
1104
+ manifestPath,
1105
+ };
1106
+ },
1107
+ });
1108
+ }
1109
+ //# sourceMappingURL=mutations.js.map