@inflexa-ai/harness 0.1.1

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 (823) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +58 -0
  4. package/dist/agents/conversation-agent.d.ts +105 -0
  5. package/dist/agents/conversation-agent.js +140 -0
  6. package/dist/agents/report-builder.d.ts +32 -0
  7. package/dist/agents/report-builder.js +31 -0
  8. package/dist/agents/sandbox/__fixtures__/deps.d.ts +23 -0
  9. package/dist/agents/sandbox/__fixtures__/deps.js +96 -0
  10. package/dist/agents/sandbox/bulk-transcriptomics-agent.d.ts +8 -0
  11. package/dist/agents/sandbox/bulk-transcriptomics-agent.js +22 -0
  12. package/dist/agents/sandbox/cheminformatics-agent.d.ts +9 -0
  13. package/dist/agents/sandbox/cheminformatics-agent.js +62 -0
  14. package/dist/agents/sandbox/chromatin-agent.d.ts +8 -0
  15. package/dist/agents/sandbox/chromatin-agent.js +24 -0
  16. package/dist/agents/sandbox/data-profiler.d.ts +10 -0
  17. package/dist/agents/sandbox/data-profiler.js +24 -0
  18. package/dist/agents/sandbox/dna-methylation-agent.d.ts +8 -0
  19. package/dist/agents/sandbox/dna-methylation-agent.js +24 -0
  20. package/dist/agents/sandbox/drug-repurposing-agent.d.ts +8 -0
  21. package/dist/agents/sandbox/drug-repurposing-agent.js +54 -0
  22. package/dist/agents/sandbox/enrichment-agent.d.ts +8 -0
  23. package/dist/agents/sandbox/enrichment-agent.js +24 -0
  24. package/dist/agents/sandbox/ephemeral-executor.d.ts +9 -0
  25. package/dist/agents/sandbox/ephemeral-executor.js +29 -0
  26. package/dist/agents/sandbox/genomic-variant-agent.d.ts +8 -0
  27. package/dist/agents/sandbox/genomic-variant-agent.js +27 -0
  28. package/dist/agents/sandbox/immune-profiling-agent.d.ts +8 -0
  29. package/dist/agents/sandbox/immune-profiling-agent.js +43 -0
  30. package/dist/agents/sandbox/index.d.ts +31 -0
  31. package/dist/agents/sandbox/index.js +96 -0
  32. package/dist/agents/sandbox/metabolomics-agent.d.ts +8 -0
  33. package/dist/agents/sandbox/metabolomics-agent.js +15 -0
  34. package/dist/agents/sandbox/microbiome-agent.d.ts +8 -0
  35. package/dist/agents/sandbox/microbiome-agent.js +15 -0
  36. package/dist/agents/sandbox/multi-omics-integration-agent.d.ts +8 -0
  37. package/dist/agents/sandbox/multi-omics-integration-agent.js +33 -0
  38. package/dist/agents/sandbox/multimodal-sc-agent.d.ts +8 -0
  39. package/dist/agents/sandbox/multimodal-sc-agent.js +15 -0
  40. package/dist/agents/sandbox/network-agent.d.ts +8 -0
  41. package/dist/agents/sandbox/network-agent.js +25 -0
  42. package/dist/agents/sandbox/pkpd-clinical-response-agent.d.ts +8 -0
  43. package/dist/agents/sandbox/pkpd-clinical-response-agent.js +59 -0
  44. package/dist/agents/sandbox/proteomics-agent.d.ts +8 -0
  45. package/dist/agents/sandbox/proteomics-agent.js +15 -0
  46. package/dist/agents/sandbox/scientific-executor.d.ts +9 -0
  47. package/dist/agents/sandbox/scientific-executor.js +56 -0
  48. package/dist/agents/sandbox/shared.d.ts +100 -0
  49. package/dist/agents/sandbox/shared.js +195 -0
  50. package/dist/agents/sandbox/single-cell-agent.d.ts +8 -0
  51. package/dist/agents/sandbox/single-cell-agent.js +25 -0
  52. package/dist/agents/sandbox/spatial-omics-agent.d.ts +8 -0
  53. package/dist/agents/sandbox/spatial-omics-agent.js +15 -0
  54. package/dist/agents/sandbox/statistical-modeling-agent.d.ts +8 -0
  55. package/dist/agents/sandbox/statistical-modeling-agent.js +37 -0
  56. package/dist/agents/sandbox/translational-safety-agent.d.ts +8 -0
  57. package/dist/agents/sandbox/translational-safety-agent.js +59 -0
  58. package/dist/agents/sandbox/types.d.ts +34 -0
  59. package/dist/agents/sandbox/types.js +15 -0
  60. package/dist/agents/sandbox/validate-skills.d.ts +18 -0
  61. package/dist/agents/sandbox/validate-skills.js +40 -0
  62. package/dist/agents/sandbox-catalog.d.ts +33 -0
  63. package/dist/agents/sandbox-catalog.js +44 -0
  64. package/dist/agents/system-prompt.d.ts +25 -0
  65. package/dist/agents/system-prompt.js +23 -0
  66. package/dist/app/chat-turn.d.ts +35 -0
  67. package/dist/app/chat-turn.js +64 -0
  68. package/dist/app/data-profile-policy.d.ts +36 -0
  69. package/dist/app/data-profile-policy.js +37 -0
  70. package/dist/app/message-assembly.d.ts +65 -0
  71. package/dist/app/message-assembly.js +61 -0
  72. package/dist/app/synthesize-run.d.ts +57 -0
  73. package/dist/app/synthesize-run.js +103 -0
  74. package/dist/auth/local-auth-context.d.ts +19 -0
  75. package/dist/auth/local-auth-context.js +20 -0
  76. package/dist/auth/local-run-authorizer.d.ts +10 -0
  77. package/dist/auth/local-run-authorizer.js +23 -0
  78. package/dist/auth/types.d.ts +166 -0
  79. package/dist/auth/types.js +61 -0
  80. package/dist/billing/cached-resolver.d.ts +23 -0
  81. package/dist/billing/cached-resolver.js +61 -0
  82. package/dist/billing/noop-resolver.d.ts +6 -0
  83. package/dist/billing/noop-resolver.js +7 -0
  84. package/dist/billing/noop-run-charge.d.ts +6 -0
  85. package/dist/billing/noop-run-charge.js +10 -0
  86. package/dist/billing/resolver.d.ts +64 -0
  87. package/dist/billing/resolver.js +24 -0
  88. package/dist/billing/run-charge.d.ts +24 -0
  89. package/dist/billing/run-charge.js +9 -0
  90. package/dist/config/resource-limits.d.ts +76 -0
  91. package/dist/config/resource-limits.js +116 -0
  92. package/dist/contracts/analogy-report.d.ts +120 -0
  93. package/dist/contracts/analogy-report.js +50 -0
  94. package/dist/contracts/chat-events.d.ts +61 -0
  95. package/dist/contracts/chat-events.js +13 -0
  96. package/dist/contracts/chat-parts.d.ts +308 -0
  97. package/dist/contracts/chat-parts.js +13 -0
  98. package/dist/contracts/content-url.d.ts +49 -0
  99. package/dist/contracts/content-url.js +56 -0
  100. package/dist/contracts/index.d.ts +12 -0
  101. package/dist/contracts/index.js +5 -0
  102. package/dist/contracts/message.d.ts +36 -0
  103. package/dist/contracts/message.js +9 -0
  104. package/dist/contracts/part-registry.d.ts +18 -0
  105. package/dist/contracts/part-registry.js +28 -0
  106. package/dist/contracts/schemas/chat-events.d.ts +90 -0
  107. package/dist/contracts/schemas/chat-events.js +43 -0
  108. package/dist/contracts/schemas/chat-parts.d.ts +683 -0
  109. package/dist/contracts/schemas/chat-parts.js +295 -0
  110. package/dist/contracts/schemas/index.d.ts +2 -0
  111. package/dist/contracts/schemas/index.js +2 -0
  112. package/dist/contracts/target-assessment-row.d.ts +85 -0
  113. package/dist/contracts/target-assessment-row.js +37 -0
  114. package/dist/contracts/target-dossier.d.ts +16720 -0
  115. package/dist/contracts/target-dossier.js +1339 -0
  116. package/dist/data/clinical-benchmarks.json +108 -0
  117. package/dist/data/protein-family-modality.json +101 -0
  118. package/dist/data/safety-panel-schema.d.ts +64 -0
  119. package/dist/data/safety-panel-schema.js +34 -0
  120. package/dist/data/safety-panel.json +436 -0
  121. package/dist/execution/artifact-metadata.d.ts +74 -0
  122. package/dist/execution/artifact-metadata.js +203 -0
  123. package/dist/execution/artifact-record.d.ts +19 -0
  124. package/dist/execution/artifact-record.js +7 -0
  125. package/dist/execution/artifact-registration.d.ts +36 -0
  126. package/dist/execution/artifact-registration.js +61 -0
  127. package/dist/execution/artifact-registry.d.ts +82 -0
  128. package/dist/execution/artifact-registry.js +17 -0
  129. package/dist/execution/dbos-run-launcher.d.ts +7 -0
  130. package/dist/execution/dbos-run-launcher.js +38 -0
  131. package/dist/execution/ephemeral-runner.d.ts +81 -0
  132. package/dist/execution/ephemeral-runner.js +161 -0
  133. package/dist/execution/filesystem-artifact-registry.d.ts +57 -0
  134. package/dist/execution/filesystem-artifact-registry.js +92 -0
  135. package/dist/execution/noop-artifact-registry.d.ts +11 -0
  136. package/dist/execution/noop-artifact-registry.js +17 -0
  137. package/dist/execution/post-step-pipeline.d.ts +70 -0
  138. package/dist/execution/post-step-pipeline.js +207 -0
  139. package/dist/execution/post-step.d.ts +20 -0
  140. package/dist/execution/post-step.js +65 -0
  141. package/dist/execution/reconcile-manifest.d.ts +25 -0
  142. package/dist/execution/reconcile-manifest.js +132 -0
  143. package/dist/execution/report-render.d.ts +39 -0
  144. package/dist/execution/report-render.js +98 -0
  145. package/dist/execution/report-runner.d.ts +87 -0
  146. package/dist/execution/report-runner.js +227 -0
  147. package/dist/execution/run-authorizer.d.ts +43 -0
  148. package/dist/execution/run-authorizer.js +17 -0
  149. package/dist/execution/run-launcher.d.ts +36 -0
  150. package/dist/execution/run-launcher.js +15 -0
  151. package/dist/execution/run-synthesis.d.ts +107 -0
  152. package/dist/execution/run-synthesis.js +329 -0
  153. package/dist/execution/staged-input.d.ts +41 -0
  154. package/dist/execution/staged-input.js +15 -0
  155. package/dist/execution/step-summary-metrics.d.ts +10 -0
  156. package/dist/execution/step-summary-metrics.js +22 -0
  157. package/dist/execution/step-summary.d.ts +55 -0
  158. package/dist/execution/step-summary.js +106 -0
  159. package/dist/execution/topo-sort.d.ts +33 -0
  160. package/dist/execution/topo-sort.js +99 -0
  161. package/dist/index.d.ts +112 -0
  162. package/dist/index.js +157 -0
  163. package/dist/input-sanitization.d.ts +22 -0
  164. package/dist/input-sanitization.js +64 -0
  165. package/dist/lib/async-utils.d.ts +10 -0
  166. package/dist/lib/async-utils.js +24 -0
  167. package/dist/lib/chrome.d.ts +15 -0
  168. package/dist/lib/chrome.js +95 -0
  169. package/dist/lib/db-result.d.ts +93 -0
  170. package/dist/lib/db-result.js +197 -0
  171. package/dist/lib/fs-helpers.d.ts +74 -0
  172. package/dist/lib/fs-helpers.js +119 -0
  173. package/dist/lib/fs-result.d.ts +98 -0
  174. package/dist/lib/fs-result.js +137 -0
  175. package/dist/lib/host-concurrency.d.ts +16 -0
  176. package/dist/lib/host-concurrency.js +60 -0
  177. package/dist/lib/identifiers.d.ts +8 -0
  178. package/dist/lib/identifiers.js +10 -0
  179. package/dist/lib/metrics.d.ts +7 -0
  180. package/dist/lib/metrics.js +12 -0
  181. package/dist/lib/mime-detect.d.ts +17 -0
  182. package/dist/lib/mime-detect.js +29 -0
  183. package/dist/lib/otel.d.ts +30 -0
  184. package/dist/lib/otel.js +102 -0
  185. package/dist/lib/regulatory-corpus/fetch-fda-guidance.d.ts +35 -0
  186. package/dist/lib/regulatory-corpus/fetch-fda-guidance.js +107 -0
  187. package/dist/lib/regulatory-corpus/fetch-ich.d.ts +46 -0
  188. package/dist/lib/regulatory-corpus/fetch-ich.js +173 -0
  189. package/dist/lib/regulatory-corpus.d.ts +88 -0
  190. package/dist/lib/regulatory-corpus.js +141 -0
  191. package/dist/lib/result.d.ts +87 -0
  192. package/dist/lib/result.js +103 -0
  193. package/dist/lib/storage.d.ts +29 -0
  194. package/dist/lib/storage.js +37 -0
  195. package/dist/lib/streamed-download.d.ts +28 -0
  196. package/dist/lib/streamed-download.js +111 -0
  197. package/dist/lib/trace-context.d.ts +11 -0
  198. package/dist/lib/trace-context.js +49 -0
  199. package/dist/loop/__fixtures__/scripted-provider.d.ts +31 -0
  200. package/dist/loop/__fixtures__/scripted-provider.js +57 -0
  201. package/dist/loop/budget-exceeded.d.ts +22 -0
  202. package/dist/loop/budget-exceeded.js +41 -0
  203. package/dist/loop/metrics.d.ts +25 -0
  204. package/dist/loop/metrics.js +46 -0
  205. package/dist/loop/run-agent.d.ts +28 -0
  206. package/dist/loop/run-agent.js +204 -0
  207. package/dist/loop/run-step.d.ts +29 -0
  208. package/dist/loop/run-step.js +34 -0
  209. package/dist/loop/run-to-terminal.d.ts +46 -0
  210. package/dist/loop/run-to-terminal.js +51 -0
  211. package/dist/loop/types.d.ts +95 -0
  212. package/dist/loop/types.js +10 -0
  213. package/dist/memory/ai-sdk-message-storage.d.ts +20 -0
  214. package/dist/memory/ai-sdk-message-storage.js +114 -0
  215. package/dist/memory/card-builders.d.ts +114 -0
  216. package/dist/memory/card-builders.js +231 -0
  217. package/dist/memory/content-to-cortex.d.ts +42 -0
  218. package/dist/memory/content-to-cortex.js +85 -0
  219. package/dist/memory/count-tokens.d.ts +18 -0
  220. package/dist/memory/count-tokens.js +64 -0
  221. package/dist/memory/derive-thread-title.d.ts +14 -0
  222. package/dist/memory/derive-thread-title.js +26 -0
  223. package/dist/memory/message-backfill.d.ts +2 -0
  224. package/dist/memory/message-backfill.js +38 -0
  225. package/dist/memory/reconstruct-cards.d.ts +23 -0
  226. package/dist/memory/reconstruct-cards.js +64 -0
  227. package/dist/memory/thread-history.d.ts +80 -0
  228. package/dist/memory/thread-history.js +187 -0
  229. package/dist/memory/thread-store.d.ts +66 -0
  230. package/dist/memory/thread-store.js +88 -0
  231. package/dist/memory/working-memory.d.ts +135 -0
  232. package/dist/memory/working-memory.js +185 -0
  233. package/dist/prompts/SOUL.d.ts +17 -0
  234. package/dist/prompts/SOUL.js +173 -0
  235. package/dist/prompts/analogical-reasoner.d.ts +1 -0
  236. package/dist/prompts/analogical-reasoner.js +170 -0
  237. package/dist/prompts/conversation.d.ts +1 -0
  238. package/dist/prompts/conversation.js +697 -0
  239. package/dist/prompts/execute-analysis/step-summary.d.ts +1 -0
  240. package/dist/prompts/execute-analysis/step-summary.js +38 -0
  241. package/dist/prompts/literature-reviewer.d.ts +1 -0
  242. package/dist/prompts/literature-reviewer.js +107 -0
  243. package/dist/prompts/planner.d.ts +2 -0
  244. package/dist/prompts/planner.js +259 -0
  245. package/dist/prompts/report-builder.d.ts +1 -0
  246. package/dist/prompts/report-builder.js +127 -0
  247. package/dist/prompts/sandbox/bulk-transcriptomics-agent.d.ts +1 -0
  248. package/dist/prompts/sandbox/bulk-transcriptomics-agent.js +78 -0
  249. package/dist/prompts/sandbox/cheminformatics-agent.d.ts +1 -0
  250. package/dist/prompts/sandbox/cheminformatics-agent.js +224 -0
  251. package/dist/prompts/sandbox/chromatin-agent.d.ts +1 -0
  252. package/dist/prompts/sandbox/chromatin-agent.js +100 -0
  253. package/dist/prompts/sandbox/data-profiler.d.ts +1 -0
  254. package/dist/prompts/sandbox/data-profiler.js +291 -0
  255. package/dist/prompts/sandbox/dna-methylation-agent.d.ts +1 -0
  256. package/dist/prompts/sandbox/dna-methylation-agent.js +96 -0
  257. package/dist/prompts/sandbox/drug-repurposing-agent.d.ts +1 -0
  258. package/dist/prompts/sandbox/drug-repurposing-agent.js +144 -0
  259. package/dist/prompts/sandbox/enrichment-agent.d.ts +1 -0
  260. package/dist/prompts/sandbox/enrichment-agent.js +89 -0
  261. package/dist/prompts/sandbox/ephemeral-executor.d.ts +1 -0
  262. package/dist/prompts/sandbox/ephemeral-executor.js +66 -0
  263. package/dist/prompts/sandbox/genomic-variant-agent.d.ts +1 -0
  264. package/dist/prompts/sandbox/genomic-variant-agent.js +83 -0
  265. package/dist/prompts/sandbox/immune-profiling-agent.d.ts +1 -0
  266. package/dist/prompts/sandbox/immune-profiling-agent.js +101 -0
  267. package/dist/prompts/sandbox/metabolomics-agent.d.ts +1 -0
  268. package/dist/prompts/sandbox/metabolomics-agent.js +89 -0
  269. package/dist/prompts/sandbox/microbiome-agent.d.ts +1 -0
  270. package/dist/prompts/sandbox/microbiome-agent.js +109 -0
  271. package/dist/prompts/sandbox/multi-omics-integration-agent.d.ts +1 -0
  272. package/dist/prompts/sandbox/multi-omics-integration-agent.js +122 -0
  273. package/dist/prompts/sandbox/multimodal-sc-agent.d.ts +1 -0
  274. package/dist/prompts/sandbox/multimodal-sc-agent.js +90 -0
  275. package/dist/prompts/sandbox/network-agent.d.ts +1 -0
  276. package/dist/prompts/sandbox/network-agent.js +95 -0
  277. package/dist/prompts/sandbox/pkpd-clinical-response-agent.d.ts +1 -0
  278. package/dist/prompts/sandbox/pkpd-clinical-response-agent.js +71 -0
  279. package/dist/prompts/sandbox/proteomics-agent.d.ts +1 -0
  280. package/dist/prompts/sandbox/proteomics-agent.js +93 -0
  281. package/dist/prompts/sandbox/scientific-executor.d.ts +1 -0
  282. package/dist/prompts/sandbox/scientific-executor.js +68 -0
  283. package/dist/prompts/sandbox/single-cell-agent.d.ts +1 -0
  284. package/dist/prompts/sandbox/single-cell-agent.js +129 -0
  285. package/dist/prompts/sandbox/spatial-omics-agent.d.ts +1 -0
  286. package/dist/prompts/sandbox/spatial-omics-agent.js +94 -0
  287. package/dist/prompts/sandbox/statistical-modeling-agent.d.ts +1 -0
  288. package/dist/prompts/sandbox/statistical-modeling-agent.js +112 -0
  289. package/dist/prompts/sandbox/translational-safety-agent.d.ts +1 -0
  290. package/dist/prompts/sandbox/translational-safety-agent.js +105 -0
  291. package/dist/prompts/sandbox-standards.d.ts +18 -0
  292. package/dist/prompts/sandbox-standards.js +358 -0
  293. package/dist/prompts/synthesis-agent.d.ts +1 -0
  294. package/dist/prompts/synthesis-agent.js +289 -0
  295. package/dist/prompts/target-assessment/briefs/executive-recommendation.d.ts +1 -0
  296. package/dist/prompts/target-assessment/briefs/executive-recommendation.js +85 -0
  297. package/dist/prompts/target-assessment/briefs/index.d.ts +4 -0
  298. package/dist/prompts/target-assessment/briefs/index.js +4 -0
  299. package/dist/prompts/target-assessment/briefs/liability-bullets.d.ts +1 -0
  300. package/dist/prompts/target-assessment/briefs/liability-bullets.js +114 -0
  301. package/dist/prompts/target-assessment/briefs/target-organ-liabilities.d.ts +1 -0
  302. package/dist/prompts/target-assessment/briefs/target-organ-liabilities.js +29 -0
  303. package/dist/prompts/target-assessment/briefs/translational-commentary.d.ts +1 -0
  304. package/dist/prompts/target-assessment/briefs/translational-commentary.js +23 -0
  305. package/dist/prompts/target-assessment/drugs-in-class.d.ts +1 -0
  306. package/dist/prompts/target-assessment/drugs-in-class.js +29 -0
  307. package/dist/prompts/target-assessment/modulator-triage.d.ts +1 -0
  308. package/dist/prompts/target-assessment/modulator-triage.js +31 -0
  309. package/dist/prompts/target-assessment/off-target-annotator.d.ts +1 -0
  310. package/dist/prompts/target-assessment/off-target-annotator.js +28 -0
  311. package/dist/prompts/target-assessment/tox-voice/core.d.ts +1 -0
  312. package/dist/prompts/target-assessment/tox-voice/core.js +74 -0
  313. package/dist/prompts/target-assessment/tox-voice/critique.d.ts +7 -0
  314. package/dist/prompts/target-assessment/tox-voice/critique.js +109 -0
  315. package/dist/prompts/target-assessment/tox-voice/exemplars.d.ts +8 -0
  316. package/dist/prompts/target-assessment/tox-voice/exemplars.js +24 -0
  317. package/dist/prompts/target-assessment/tox-voice/index.d.ts +4 -0
  318. package/dist/prompts/target-assessment/tox-voice/index.js +4 -0
  319. package/dist/prompts/target-assessment/tox-voice/vocabulary.d.ts +15 -0
  320. package/dist/prompts/target-assessment/tox-voice/vocabulary.js +72 -0
  321. package/dist/provenance/collector.d.ts +148 -0
  322. package/dist/provenance/collector.js +296 -0
  323. package/dist/provenance/exec-frame.d.ts +36 -0
  324. package/dist/provenance/exec-frame.js +49 -0
  325. package/dist/provenance/types.d.ts +95 -0
  326. package/dist/provenance/types.js +64 -0
  327. package/dist/providers/__fixtures__/session.d.ts +16 -0
  328. package/dist/providers/__fixtures__/session.js +20 -0
  329. package/dist/providers/ai-sdk.d.ts +47 -0
  330. package/dist/providers/ai-sdk.js +142 -0
  331. package/dist/providers/anthropic.d.ts +22 -0
  332. package/dist/providers/anthropic.js +26 -0
  333. package/dist/providers/embedding.d.ts +32 -0
  334. package/dist/providers/embedding.js +42 -0
  335. package/dist/providers/errors.d.ts +80 -0
  336. package/dist/providers/errors.js +137 -0
  337. package/dist/providers/llm-capabilities.d.ts +33 -0
  338. package/dist/providers/llm-capabilities.js +58 -0
  339. package/dist/providers/streaming-chat.d.ts +23 -0
  340. package/dist/providers/streaming-chat.js +61 -0
  341. package/dist/providers/types.d.ts +59 -0
  342. package/dist/providers/types.js +8 -0
  343. package/dist/runtime/assemble.d.ts +68 -0
  344. package/dist/runtime/assemble.js +46 -0
  345. package/dist/runtime/boot.d.ts +73 -0
  346. package/dist/runtime/boot.js +65 -0
  347. package/dist/runtime/connection-budget.d.ts +48 -0
  348. package/dist/runtime/connection-budget.js +57 -0
  349. package/dist/runtime/dbos.d.ts +94 -0
  350. package/dist/runtime/dbos.js +160 -0
  351. package/dist/runtime/lifecycle.d.ts +12 -0
  352. package/dist/runtime/lifecycle.js +19 -0
  353. package/dist/runtime/pools.d.ts +25 -0
  354. package/dist/runtime/pools.js +30 -0
  355. package/dist/runtime/shutdown.d.ts +33 -0
  356. package/dist/runtime/shutdown.js +39 -0
  357. package/dist/sandbox/await-exec.d.ts +143 -0
  358. package/dist/sandbox/await-exec.js +406 -0
  359. package/dist/sandbox/client.d.ts +82 -0
  360. package/dist/sandbox/client.js +23 -0
  361. package/dist/sandbox/create-sandbox.d.ts +105 -0
  362. package/dist/sandbox/create-sandbox.js +132 -0
  363. package/dist/sandbox/deliver-exec-event.d.ts +25 -0
  364. package/dist/sandbox/deliver-exec-event.js +29 -0
  365. package/dist/sandbox/docker-client.d.ts +75 -0
  366. package/dist/sandbox/docker-client.js +315 -0
  367. package/dist/sandbox/estimate-data-profile-resources.d.ts +5 -0
  368. package/dist/sandbox/estimate-data-profile-resources.js +73 -0
  369. package/dist/sandbox/exec-id.d.ts +12 -0
  370. package/dist/sandbox/exec-id.js +20 -0
  371. package/dist/sandbox/execution-id.d.ts +30 -0
  372. package/dist/sandbox/execution-id.js +47 -0
  373. package/dist/sandbox/hmac.d.ts +54 -0
  374. package/dist/sandbox/hmac.js +67 -0
  375. package/dist/sandbox/identity.d.ts +15 -0
  376. package/dist/sandbox/identity.js +22 -0
  377. package/dist/sandbox/ignored-dirs.d.ts +7 -0
  378. package/dist/sandbox/ignored-dirs.js +7 -0
  379. package/dist/sandbox/k8s-client.d.ts +71 -0
  380. package/dist/sandbox/k8s-client.js +488 -0
  381. package/dist/sandbox/liveness.d.ts +60 -0
  382. package/dist/sandbox/liveness.js +82 -0
  383. package/dist/sandbox/mount-plan.d.ts +77 -0
  384. package/dist/sandbox/mount-plan.js +84 -0
  385. package/dist/sandbox/notification-sweep.d.ts +42 -0
  386. package/dist/sandbox/notification-sweep.js +74 -0
  387. package/dist/sandbox/reaper.d.ts +70 -0
  388. package/dist/sandbox/reaper.js +124 -0
  389. package/dist/sandbox/sandbox-error.d.ts +105 -0
  390. package/dist/sandbox/sandbox-error.js +92 -0
  391. package/dist/sandbox/sandbox-step-translate.d.ts +35 -0
  392. package/dist/sandbox/sandbox-step-translate.js +76 -0
  393. package/dist/sandbox/submit-exec.d.ts +33 -0
  394. package/dist/sandbox/submit-exec.js +68 -0
  395. package/dist/sandbox/types.d.ts +277 -0
  396. package/dist/sandbox/types.js +147 -0
  397. package/dist/sandbox/watchdog.d.ts +71 -0
  398. package/dist/sandbox/watchdog.js +150 -0
  399. package/dist/schemas/artifact-manifest.d.ts +34 -0
  400. package/dist/schemas/artifact-manifest.js +36 -0
  401. package/dist/schemas/data-profile-schemas.d.ts +92 -0
  402. package/dist/schemas/data-profile-schemas.js +89 -0
  403. package/dist/schemas/file-metadata.d.ts +51 -0
  404. package/dist/schemas/file-metadata.js +39 -0
  405. package/dist/schemas/plan-schemas.d.ts +110 -0
  406. package/dist/schemas/plan-schemas.js +50 -0
  407. package/dist/schemas/render-step-prompt.d.ts +32 -0
  408. package/dist/schemas/render-step-prompt.js +76 -0
  409. package/dist/schemas/run-synthesis.d.ts +148 -0
  410. package/dist/schemas/run-synthesis.js +87 -0
  411. package/dist/schemas/step-summary.d.ts +18 -0
  412. package/dist/schemas/step-summary.js +20 -0
  413. package/dist/schemas/validate-plan.d.ts +39 -0
  414. package/dist/schemas/validate-plan.js +120 -0
  415. package/dist/schemas/workflow-state.d.ts +314 -0
  416. package/dist/schemas/workflow-state.js +139 -0
  417. package/dist/state/active-sandboxes.d.ts +58 -0
  418. package/dist/state/active-sandboxes.js +100 -0
  419. package/dist/state/analyses-metrics.d.ts +21 -0
  420. package/dist/state/analyses-metrics.js +59 -0
  421. package/dist/state/analyses.d.ts +58 -0
  422. package/dist/state/analyses.js +132 -0
  423. package/dist/state/artifacts.d.ts +53 -0
  424. package/dist/state/artifacts.js +175 -0
  425. package/dist/state/data-profile.d.ts +176 -0
  426. package/dist/state/data-profile.js +284 -0
  427. package/dist/state/db.d.ts +10 -0
  428. package/dist/state/db.js +9 -0
  429. package/dist/state/index.d.ts +29 -0
  430. package/dist/state/index.js +20 -0
  431. package/dist/state/init.d.ts +14 -0
  432. package/dist/state/init.js +406 -0
  433. package/dist/state/plans.d.ts +56 -0
  434. package/dist/state/plans.js +117 -0
  435. package/dist/state/runs.d.ts +69 -0
  436. package/dist/state/runs.js +206 -0
  437. package/dist/state/schema.d.ts +150 -0
  438. package/dist/state/schema.js +100 -0
  439. package/dist/state/step-executions.d.ts +77 -0
  440. package/dist/state/step-executions.js +175 -0
  441. package/dist/state/target-assessments.d.ts +68 -0
  442. package/dist/state/target-assessments.js +222 -0
  443. package/dist/state/vector-store.d.ts +53 -0
  444. package/dist/state/vector-store.js +89 -0
  445. package/dist/tasks/data-profile.d.ts +171 -0
  446. package/dist/tasks/data-profile.js +461 -0
  447. package/dist/tasks/refresh-regulatory-corpus.d.ts +59 -0
  448. package/dist/tasks/refresh-regulatory-corpus.js +146 -0
  449. package/dist/tasks/regulatory-corpus-boot-refresh.d.ts +55 -0
  450. package/dist/tasks/regulatory-corpus-boot-refresh.js +149 -0
  451. package/dist/tools/__fixtures__/tool-context.d.ts +13 -0
  452. package/dist/tools/__fixtures__/tool-context.js +18 -0
  453. package/dist/tools/bio/check-safety-panel.d.ts +35 -0
  454. package/dist/tools/bio/check-safety-panel.js +76 -0
  455. package/dist/tools/bio/find-approval-precedent.d.ts +32 -0
  456. package/dist/tools/bio/find-approval-precedent.js +72 -0
  457. package/dist/tools/bio/get-article-details.d.ts +11 -0
  458. package/dist/tools/bio/get-article-details.js +20 -0
  459. package/dist/tools/bio/get-article-full-text.d.ts +19 -0
  460. package/dist/tools/bio/get-article-full-text.js +32 -0
  461. package/dist/tools/bio/get-bioactivity.d.ts +11 -0
  462. package/dist/tools/bio/get-bioactivity.js +23 -0
  463. package/dist/tools/bio/get-drug-info.d.ts +9 -0
  464. package/dist/tools/bio/get-drug-info.js +22 -0
  465. package/dist/tools/bio/get-impc-ko-profile.d.ts +9 -0
  466. package/dist/tools/bio/get-impc-ko-profile.js +20 -0
  467. package/dist/tools/bio/get-mechanism.d.ts +8 -0
  468. package/dist/tools/bio/get-mechanism.js +18 -0
  469. package/dist/tools/bio/get-pubchem-assays.d.ts +22 -0
  470. package/dist/tools/bio/get-pubchem-assays.js +107 -0
  471. package/dist/tools/bio/get-pubchem-cross-refs.d.ts +15 -0
  472. package/dist/tools/bio/get-pubchem-cross-refs.js +68 -0
  473. package/dist/tools/bio/get-target-safety.d.ts +18 -0
  474. package/dist/tools/bio/get-target-safety.js +26 -0
  475. package/dist/tools/bio/index.d.ts +41 -0
  476. package/dist/tools/bio/index.js +48 -0
  477. package/dist/tools/bio/keys.d.ts +31 -0
  478. package/dist/tools/bio/keys.js +30 -0
  479. package/dist/tools/bio/lookup-go-term.d.ts +31 -0
  480. package/dist/tools/bio/lookup-go-term.js +116 -0
  481. package/dist/tools/bio/search-bgee-expression.d.ts +10 -0
  482. package/dist/tools/bio/search-bgee-expression.js +24 -0
  483. package/dist/tools/bio/search-clinical-trials.d.ts +12 -0
  484. package/dist/tools/bio/search-clinical-trials.js +21 -0
  485. package/dist/tools/bio/search-clinvar.d.ts +13 -0
  486. package/dist/tools/bio/search-clinvar.js +28 -0
  487. package/dist/tools/bio/search-compounds.d.ts +22 -0
  488. package/dist/tools/bio/search-compounds.js +160 -0
  489. package/dist/tools/bio/search-ctx-chemical.d.ts +50 -0
  490. package/dist/tools/bio/search-ctx-chemical.js +130 -0
  491. package/dist/tools/bio/search-ctx-exposure.d.ts +55 -0
  492. package/dist/tools/bio/search-ctx-exposure.js +176 -0
  493. package/dist/tools/bio/search-ctx-hazard.d.ts +111 -0
  494. package/dist/tools/bio/search-ctx-hazard.js +178 -0
  495. package/dist/tools/bio/search-dgidb.d.ts +43 -0
  496. package/dist/tools/bio/search-dgidb.js +199 -0
  497. package/dist/tools/bio/search-disgenet.d.ts +30 -0
  498. package/dist/tools/bio/search-disgenet.js +84 -0
  499. package/dist/tools/bio/search-drugbank.d.ts +38 -0
  500. package/dist/tools/bio/search-drugbank.js +109 -0
  501. package/dist/tools/bio/search-faers.d.ts +11 -0
  502. package/dist/tools/bio/search-faers.js +23 -0
  503. package/dist/tools/bio/search-gene.d.ts +11 -0
  504. package/dist/tools/bio/search-gene.js +19 -0
  505. package/dist/tools/bio/search-geo-datasets.d.ts +20 -0
  506. package/dist/tools/bio/search-geo-datasets.js +86 -0
  507. package/dist/tools/bio/search-gwas-catalog.d.ts +33 -0
  508. package/dist/tools/bio/search-gwas-catalog.js +172 -0
  509. package/dist/tools/bio/search-interactions.d.ts +17 -0
  510. package/dist/tools/bio/search-interactions.js +31 -0
  511. package/dist/tools/bio/search-opentargets.d.ts +11 -0
  512. package/dist/tools/bio/search-opentargets.js +25 -0
  513. package/dist/tools/bio/search-pathway.d.ts +12 -0
  514. package/dist/tools/bio/search-pathway.js +32 -0
  515. package/dist/tools/bio/search-pharmgkb.d.ts +17 -0
  516. package/dist/tools/bio/search-pharmgkb.js +46 -0
  517. package/dist/tools/bio/search-pubchem-compound.d.ts +26 -0
  518. package/dist/tools/bio/search-pubchem-compound.js +110 -0
  519. package/dist/tools/bio/search-pubmed.d.ts +17 -0
  520. package/dist/tools/bio/search-pubmed.js +31 -0
  521. package/dist/tools/bio/search-targets.d.ts +9 -0
  522. package/dist/tools/bio/search-targets.js +20 -0
  523. package/dist/tools/bio/search-toxcast.d.ts +36 -0
  524. package/dist/tools/bio/search-toxcast.js +141 -0
  525. package/dist/tools/define-tool.d.ts +80 -0
  526. package/dist/tools/define-tool.js +48 -0
  527. package/dist/tools/display/index.d.ts +4 -0
  528. package/dist/tools/display/index.js +4 -0
  529. package/dist/tools/display/show-user.d.ts +33 -0
  530. package/dist/tools/display/show-user.js +67 -0
  531. package/dist/tools/execute-plan.d.ts +64 -0
  532. package/dist/tools/execute-plan.js +208 -0
  533. package/dist/tools/iterate-report.d.ts +172 -0
  534. package/dist/tools/iterate-report.js +521 -0
  535. package/dist/tools/lib/api-utils.d.ts +80 -0
  536. package/dist/tools/lib/api-utils.js +128 -0
  537. package/dist/tools/lib/bgee-client.d.ts +36 -0
  538. package/dist/tools/lib/bgee-client.js +150 -0
  539. package/dist/tools/lib/cbioportal-client.d.ts +34 -0
  540. package/dist/tools/lib/cbioportal-client.js +159 -0
  541. package/dist/tools/lib/chembl-client.d.ts +123 -0
  542. package/dist/tools/lib/chembl-client.js +458 -0
  543. package/dist/tools/lib/chembl-config.d.ts +5 -0
  544. package/dist/tools/lib/chembl-config.js +3 -0
  545. package/dist/tools/lib/clinical-benchmarks-client.d.ts +33 -0
  546. package/dist/tools/lib/clinical-benchmarks-client.js +54 -0
  547. package/dist/tools/lib/clinical-trials-client.d.ts +216 -0
  548. package/dist/tools/lib/clinical-trials-client.js +339 -0
  549. package/dist/tools/lib/clinicaltrials-config.d.ts +4 -0
  550. package/dist/tools/lib/clinicaltrials-config.js +2 -0
  551. package/dist/tools/lib/clinvar-client.d.ts +25 -0
  552. package/dist/tools/lib/clinvar-client.js +126 -0
  553. package/dist/tools/lib/disgenet-config.d.ts +2 -0
  554. package/dist/tools/lib/disgenet-config.js +11 -0
  555. package/dist/tools/lib/drugbank-config.d.ts +2 -0
  556. package/dist/tools/lib/drugbank-config.js +12 -0
  557. package/dist/tools/lib/ema-client.d.ts +45 -0
  558. package/dist/tools/lib/ema-client.js +127 -0
  559. package/dist/tools/lib/ema-config.d.ts +7 -0
  560. package/dist/tools/lib/ema-config.js +7 -0
  561. package/dist/tools/lib/ensembl-client.d.ts +27 -0
  562. package/dist/tools/lib/ensembl-client.js +82 -0
  563. package/dist/tools/lib/gwas-catalog-config.d.ts +4 -0
  564. package/dist/tools/lib/gwas-catalog-config.js +2 -0
  565. package/dist/tools/lib/identifier-resolver.d.ts +85 -0
  566. package/dist/tools/lib/identifier-resolver.js +333 -0
  567. package/dist/tools/lib/impc-client.d.ts +44 -0
  568. package/dist/tools/lib/impc-client.js +239 -0
  569. package/dist/tools/lib/iuphar-client.d.ts +75 -0
  570. package/dist/tools/lib/iuphar-client.js +230 -0
  571. package/dist/tools/lib/iuphar-config.d.ts +5 -0
  572. package/dist/tools/lib/iuphar-config.js +3 -0
  573. package/dist/tools/lib/ncbi-utils.d.ts +58 -0
  574. package/dist/tools/lib/ncbi-utils.js +286 -0
  575. package/dist/tools/lib/openfda-client.d.ts +53 -0
  576. package/dist/tools/lib/openfda-client.js +192 -0
  577. package/dist/tools/lib/openfda-config.d.ts +2 -0
  578. package/dist/tools/lib/openfda-config.js +2 -0
  579. package/dist/tools/lib/opentargets-client.d.ts +64 -0
  580. package/dist/tools/lib/opentargets-client.js +290 -0
  581. package/dist/tools/lib/opentargets-config.d.ts +5 -0
  582. package/dist/tools/lib/opentargets-config.js +5 -0
  583. package/dist/tools/lib/path-validation.d.ts +14 -0
  584. package/dist/tools/lib/path-validation.js +26 -0
  585. package/dist/tools/lib/pathway-client.d.ts +27 -0
  586. package/dist/tools/lib/pathway-client.js +149 -0
  587. package/dist/tools/lib/pharmgkb-config.d.ts +4 -0
  588. package/dist/tools/lib/pharmgkb-config.js +2 -0
  589. package/dist/tools/lib/preview-lock.d.ts +20 -0
  590. package/dist/tools/lib/preview-lock.js +35 -0
  591. package/dist/tools/lib/protein-family-modality.d.ts +16 -0
  592. package/dist/tools/lib/protein-family-modality.js +42 -0
  593. package/dist/tools/lib/protein-family-normalize.d.ts +12 -0
  594. package/dist/tools/lib/protein-family-normalize.js +46 -0
  595. package/dist/tools/lib/pubchem-client.d.ts +40 -0
  596. package/dist/tools/lib/pubchem-client.js +128 -0
  597. package/dist/tools/lib/pubchem-config.d.ts +5 -0
  598. package/dist/tools/lib/pubchem-config.js +3 -0
  599. package/dist/tools/lib/pubmed-client.d.ts +28 -0
  600. package/dist/tools/lib/pubmed-client.js +91 -0
  601. package/dist/tools/lib/report-preflight.d.ts +39 -0
  602. package/dist/tools/lib/report-preflight.js +283 -0
  603. package/dist/tools/lib/string-client.d.ts +33 -0
  604. package/dist/tools/lib/string-client.js +93 -0
  605. package/dist/tools/lib/toxcast-config.d.ts +2 -0
  606. package/dist/tools/lib/toxcast-config.js +11 -0
  607. package/dist/tools/lib/uniprot-client.d.ts +28 -0
  608. package/dist/tools/lib/uniprot-client.js +103 -0
  609. package/dist/tools/lib/uniprot-config.d.ts +5 -0
  610. package/dist/tools/lib/uniprot-config.js +3 -0
  611. package/dist/tools/memory/index.d.ts +4 -0
  612. package/dist/tools/memory/index.js +4 -0
  613. package/dist/tools/memory/update-working-memory.d.ts +25 -0
  614. package/dist/tools/memory/update-working-memory.js +112 -0
  615. package/dist/tools/registry.d.ts +15 -0
  616. package/dist/tools/registry.js +26 -0
  617. package/dist/tools/report/build-report.d.ts +13 -0
  618. package/dist/tools/report/build-report.js +26 -0
  619. package/dist/tools/report/index.d.ts +14 -0
  620. package/dist/tools/report/index.js +14 -0
  621. package/dist/tools/report/mint-preview-url.d.ts +26 -0
  622. package/dist/tools/report/mint-preview-url.js +44 -0
  623. package/dist/tools/report/preview-publisher.d.ts +37 -0
  624. package/dist/tools/report/preview-publisher.js +25 -0
  625. package/dist/tools/report/preview-snapshot.d.ts +26 -0
  626. package/dist/tools/report/preview-snapshot.js +121 -0
  627. package/dist/tools/report/submit-report.d.ts +25 -0
  628. package/dist/tools/report/submit-report.js +126 -0
  629. package/dist/tools/report/version-fs.d.ts +15 -0
  630. package/dist/tools/report/version-fs.js +154 -0
  631. package/dist/tools/research/context7-docs.d.ts +31 -0
  632. package/dist/tools/research/context7-docs.js +61 -0
  633. package/dist/tools/research/generate-analogy-report.d.ts +60 -0
  634. package/dist/tools/research/generate-analogy-report.js +288 -0
  635. package/dist/tools/research/generate-plan.d.ts +39 -0
  636. package/dist/tools/research/generate-plan.js +393 -0
  637. package/dist/tools/research/index.d.ts +15 -0
  638. package/dist/tools/research/index.js +15 -0
  639. package/dist/tools/research/inspect-run.d.ts +54 -0
  640. package/dist/tools/research/inspect-run.js +85 -0
  641. package/dist/tools/research/literature-reviewer.d.ts +29 -0
  642. package/dist/tools/research/literature-reviewer.js +84 -0
  643. package/dist/tools/research/search-arxiv.d.ts +32 -0
  644. package/dist/tools/research/search-arxiv.js +123 -0
  645. package/dist/tools/research/search-github-repos.d.ts +32 -0
  646. package/dist/tools/research/search-github-repos.js +86 -0
  647. package/dist/tools/research/search-semantic-scholar.d.ts +33 -0
  648. package/dist/tools/research/search-semantic-scholar.js +93 -0
  649. package/dist/tools/run-ephemeral.d.ts +33 -0
  650. package/dist/tools/run-ephemeral.js +65 -0
  651. package/dist/tools/sandbox/index.d.ts +7 -0
  652. package/dist/tools/sandbox/index.js +7 -0
  653. package/dist/tools/sandbox/list-available-packages.d.ts +7 -0
  654. package/dist/tools/sandbox/list-available-packages.js +27 -0
  655. package/dist/tools/sandbox/list-available-refs.d.ts +7 -0
  656. package/dist/tools/sandbox/list-available-refs.js +147 -0
  657. package/dist/tools/sandbox/report-blocker.d.ts +23 -0
  658. package/dist/tools/sandbox/report-blocker.js +39 -0
  659. package/dist/tools/sandbox/skills.d.ts +72 -0
  660. package/dist/tools/sandbox/skills.js +144 -0
  661. package/dist/tools/workspace/edit-file.d.ts +46 -0
  662. package/dist/tools/workspace/edit-file.js +100 -0
  663. package/dist/tools/workspace/execute-command.d.ts +80 -0
  664. package/dist/tools/workspace/execute-command.js +95 -0
  665. package/dist/tools/workspace/file-stat.d.ts +24 -0
  666. package/dist/tools/workspace/file-stat.js +37 -0
  667. package/dist/tools/workspace/grep.d.ts +57 -0
  668. package/dist/tools/workspace/grep.js +154 -0
  669. package/dist/tools/workspace/index.d.ts +26 -0
  670. package/dist/tools/workspace/index.js +27 -0
  671. package/dist/tools/workspace/list-files.d.ts +24 -0
  672. package/dist/tools/workspace/list-files.js +38 -0
  673. package/dist/tools/workspace/mutator.d.ts +83 -0
  674. package/dist/tools/workspace/mutator.js +81 -0
  675. package/dist/tools/workspace/read-file.d.ts +39 -0
  676. package/dist/tools/workspace/read-file.js +93 -0
  677. package/dist/tools/workspace/result-bounds.d.ts +42 -0
  678. package/dist/tools/workspace/result-bounds.js +50 -0
  679. package/dist/tools/workspace/run-exec.d.ts +32 -0
  680. package/dist/tools/workspace/run-exec.js +34 -0
  681. package/dist/tools/workspace/show-file.d.ts +37 -0
  682. package/dist/tools/workspace/show-file.js +54 -0
  683. package/dist/tools/workspace/show-plan.d.ts +23 -0
  684. package/dist/tools/workspace/show-plan.js +44 -0
  685. package/dist/tools/workspace/workspace-search.d.ts +25 -0
  686. package/dist/tools/workspace/workspace-search.js +78 -0
  687. package/dist/tools/workspace/write-file.d.ts +16 -0
  688. package/dist/tools/workspace/write-file.js +33 -0
  689. package/dist/workflows/execute-analysis-scheduler.d.ts +94 -0
  690. package/dist/workflows/execute-analysis-scheduler.js +186 -0
  691. package/dist/workflows/execute-analysis.d.ts +271 -0
  692. package/dist/workflows/execute-analysis.js +746 -0
  693. package/dist/workflows/execute-target-assessment.d.ts +101 -0
  694. package/dist/workflows/execute-target-assessment.js +528 -0
  695. package/dist/workflows/metrics.d.ts +37 -0
  696. package/dist/workflows/metrics.js +55 -0
  697. package/dist/workflows/plan/level.d.ts +12 -0
  698. package/dist/workflows/plan/level.js +12 -0
  699. package/dist/workflows/register-workflows.d.ts +51 -0
  700. package/dist/workflows/register-workflows.js +48 -0
  701. package/dist/workflows/resume-execute-analysis.d.ts +70 -0
  702. package/dist/workflows/resume-execute-analysis.js +80 -0
  703. package/dist/workflows/sandbox-step.d.ts +243 -0
  704. package/dist/workflows/sandbox-step.js +573 -0
  705. package/dist/workflows/target-assessment/assemblers/index.d.ts +5 -0
  706. package/dist/workflows/target-assessment/assemblers/index.js +4 -0
  707. package/dist/workflows/target-assessment/assemblers/literature.d.ts +299 -0
  708. package/dist/workflows/target-assessment/assemblers/literature.js +987 -0
  709. package/dist/workflows/target-assessment/assemblers/orchestrator.d.ts +109 -0
  710. package/dist/workflows/target-assessment/assemblers/orchestrator.js +835 -0
  711. package/dist/workflows/target-assessment/assemblers/safety.d.ts +352 -0
  712. package/dist/workflows/target-assessment/assemblers/safety.js +985 -0
  713. package/dist/workflows/target-assessment/assemblers/trials.d.ts +30 -0
  714. package/dist/workflows/target-assessment/assemblers/trials.js +75 -0
  715. package/dist/workflows/target-assessment/collectors/index.d.ts +105 -0
  716. package/dist/workflows/target-assessment/collectors/index.js +468 -0
  717. package/dist/workflows/target-assessment/correction-loop.d.ts +45 -0
  718. package/dist/workflows/target-assessment/correction-loop.js +62 -0
  719. package/dist/workflows/target-assessment/coverage.d.ts +81 -0
  720. package/dist/workflows/target-assessment/coverage.js +82 -0
  721. package/dist/workflows/target-assessment/decisions/index.d.ts +86 -0
  722. package/dist/workflows/target-assessment/decisions/index.js +127 -0
  723. package/dist/workflows/target-assessment/fanout/index.d.ts +31 -0
  724. package/dist/workflows/target-assessment/fanout/index.js +155 -0
  725. package/dist/workflows/target-assessment/lib/approval-precedents.d.ts +52 -0
  726. package/dist/workflows/target-assessment/lib/approval-precedents.js +119 -0
  727. package/dist/workflows/target-assessment/lib/citation-validator.d.ts +46 -0
  728. package/dist/workflows/target-assessment/lib/citation-validator.js +316 -0
  729. package/dist/workflows/target-assessment/lib/clinical-consequence-annotator.d.ts +62 -0
  730. package/dist/workflows/target-assessment/lib/clinical-consequence-annotator.js +172 -0
  731. package/dist/workflows/target-assessment/lib/clinical-evidence-attribution.d.ts +45 -0
  732. package/dist/workflows/target-assessment/lib/clinical-evidence-attribution.js +156 -0
  733. package/dist/workflows/target-assessment/lib/compute-derived.d.ts +19 -0
  734. package/dist/workflows/target-assessment/lib/compute-derived.js +252 -0
  735. package/dist/workflows/target-assessment/lib/compute-selectivity.d.ts +15 -0
  736. package/dist/workflows/target-assessment/lib/compute-selectivity.js +18 -0
  737. package/dist/workflows/target-assessment/lib/dedup-modulators.d.ts +37 -0
  738. package/dist/workflows/target-assessment/lib/dedup-modulators.js +157 -0
  739. package/dist/workflows/target-assessment/lib/evidence-conflict-detector.d.ts +17 -0
  740. package/dist/workflows/target-assessment/lib/evidence-conflict-detector.js +100 -0
  741. package/dist/workflows/target-assessment/lib/expression-constants.d.ts +21 -0
  742. package/dist/workflows/target-assessment/lib/expression-constants.js +21 -0
  743. package/dist/workflows/target-assessment/lib/family-complex-supplement.d.ts +21 -0
  744. package/dist/workflows/target-assessment/lib/family-complex-supplement.js +37 -0
  745. package/dist/workflows/target-assessment/lib/heterodimer-filter.d.ts +39 -0
  746. package/dist/workflows/target-assessment/lib/heterodimer-filter.js +54 -0
  747. package/dist/workflows/target-assessment/lib/intended-polypharm-filter.d.ts +4 -0
  748. package/dist/workflows/target-assessment/lib/intended-polypharm-filter.js +24 -0
  749. package/dist/workflows/target-assessment/lib/llm-step.d.ts +77 -0
  750. package/dist/workflows/target-assessment/lib/llm-step.js +99 -0
  751. package/dist/workflows/target-assessment/lib/meddra-organ-map.d.ts +30 -0
  752. package/dist/workflows/target-assessment/lib/meddra-organ-map.js +126 -0
  753. package/dist/workflows/target-assessment/lib/recommendation-quality-gates.d.ts +17 -0
  754. package/dist/workflows/target-assessment/lib/recommendation-quality-gates.js +99 -0
  755. package/dist/workflows/target-assessment/lib/recommendation-sanitizer.d.ts +2 -0
  756. package/dist/workflows/target-assessment/lib/recommendation-sanitizer.js +51 -0
  757. package/dist/workflows/target-assessment/lib/regulatory-actions.d.ts +26 -0
  758. package/dist/workflows/target-assessment/lib/regulatory-actions.js +147 -0
  759. package/dist/workflows/target-assessment/lib/structured-llm.d.ts +58 -0
  760. package/dist/workflows/target-assessment/lib/structured-llm.js +101 -0
  761. package/dist/workflows/target-assessment/lib/target-identity-filter.d.ts +60 -0
  762. package/dist/workflows/target-assessment/lib/target-identity-filter.js +86 -0
  763. package/dist/workflows/target-assessment/lib/therapeutic-programs.d.ts +20 -0
  764. package/dist/workflows/target-assessment/lib/therapeutic-programs.js +68 -0
  765. package/dist/workflows/target-assessment/metrics.d.ts +21 -0
  766. package/dist/workflows/target-assessment/metrics.js +42 -0
  767. package/dist/workflows/target-assessment/phase4-assemble.d.ts +1841 -0
  768. package/dist/workflows/target-assessment/phase4-assemble.js +39 -0
  769. package/dist/workflows/target-assessment/phase5-persist.d.ts +57 -0
  770. package/dist/workflows/target-assessment/phase5-persist.js +461 -0
  771. package/dist/workflows/target-assessment/progress.d.ts +38 -0
  772. package/dist/workflows/target-assessment/progress.js +76 -0
  773. package/dist/workflows/target-assessment/schemas.d.ts +931 -0
  774. package/dist/workflows/target-assessment/schemas.js +293 -0
  775. package/dist/workflows/target-assessment/steps/collectors/pathways.d.ts +15 -0
  776. package/dist/workflows/target-assessment/steps/collectors/pathways.js +58 -0
  777. package/dist/workflows/target-assessment/steps/fanout/aes-for-one-class-drug-step.d.ts +34 -0
  778. package/dist/workflows/target-assessment/steps/fanout/aes-for-one-class-drug-step.js +31 -0
  779. package/dist/workflows/target-assessment/steps/fanout/aes-for-one-trial-step.d.ts +57 -0
  780. package/dist/workflows/target-assessment/steps/fanout/aes-for-one-trial-step.js +54 -0
  781. package/dist/workflows/target-assessment/steps/fanout/faers-for-one-modulator-step.d.ts +35 -0
  782. package/dist/workflows/target-assessment/steps/fanout/faers-for-one-modulator-step.js +32 -0
  783. package/dist/workflows/target-assessment/steps/fanout/index.d.ts +14 -0
  784. package/dist/workflows/target-assessment/steps/fanout/index.js +10 -0
  785. package/dist/workflows/target-assessment/steps/fanout/polypharm-for-one-modulator-step.d.ts +28 -0
  786. package/dist/workflows/target-assessment/steps/fanout/polypharm-for-one-modulator-step.js +27 -0
  787. package/dist/workflows/target-assessment/steps/phase0-resolve.d.ts +71 -0
  788. package/dist/workflows/target-assessment/steps/phase0-resolve.js +21 -0
  789. package/dist/workflows/target-assessment/steps/phase1-aggregate.d.ts +1018 -0
  790. package/dist/workflows/target-assessment/steps/phase1-aggregate.js +25 -0
  791. package/dist/workflows/target-assessment/steps/phase2-aggregate.d.ts +696 -0
  792. package/dist/workflows/target-assessment/steps/phase2-aggregate.js +38 -0
  793. package/dist/workflows/target-assessment/steps/phase3-aggregate.d.ts +936 -0
  794. package/dist/workflows/target-assessment/steps/phase3-aggregate.js +22 -0
  795. package/dist/workflows/target-assessment/steps/synthesis/diagnostics.d.ts +34 -0
  796. package/dist/workflows/target-assessment/steps/synthesis/diagnostics.js +45 -0
  797. package/dist/workflows/target-assessment/sub-workflows/index.d.ts +15 -0
  798. package/dist/workflows/target-assessment/sub-workflows/index.js +11 -0
  799. package/dist/workflows/target-assessment/sub-workflows/per-class-drug-aes.d.ts +41 -0
  800. package/dist/workflows/target-assessment/sub-workflows/per-class-drug-aes.js +12 -0
  801. package/dist/workflows/target-assessment/sub-workflows/per-modulator-faers.d.ts +41 -0
  802. package/dist/workflows/target-assessment/sub-workflows/per-modulator-faers.js +12 -0
  803. package/dist/workflows/target-assessment/sub-workflows/per-modulator-polypharm.d.ts +36 -0
  804. package/dist/workflows/target-assessment/sub-workflows/per-modulator-polypharm.js +12 -0
  805. package/dist/workflows/target-assessment/sub-workflows/per-trial-aes.d.ts +66 -0
  806. package/dist/workflows/target-assessment/sub-workflows/per-trial-aes.js +12 -0
  807. package/dist/workflows/target-assessment/synthesis/index.d.ts +560 -0
  808. package/dist/workflows/target-assessment/synthesis/index.js +351 -0
  809. package/dist/workflows/target-assessment/synthesis-probes.d.ts +56 -0
  810. package/dist/workflows/target-assessment/synthesis-probes.js +320 -0
  811. package/dist/workspace/filesystem.d.ts +117 -0
  812. package/dist/workspace/filesystem.js +304 -0
  813. package/dist/workspace/mount-strategy.d.ts +50 -0
  814. package/dist/workspace/mount-strategy.js +67 -0
  815. package/dist/workspace/paths.d.ts +185 -0
  816. package/dist/workspace/paths.js +219 -0
  817. package/dist/workspace/provenance-collector.d.ts +34 -0
  818. package/dist/workspace/provenance-collector.js +16 -0
  819. package/dist/workspace/search-config.d.ts +23 -0
  820. package/dist/workspace/search-config.js +43 -0
  821. package/dist/workspace/workspace-paths.d.ts +26 -0
  822. package/dist/workspace/workspace-paths.js +31 -0
  823. package/package.json +101 -0
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Shared builders for the display-card data parts (`data-plan`,
3
+ * `data-presentation`, `data-run-card`, `data-file-reference`).
4
+ *
5
+ * Display tools (`show_plan`, `show_user`, `show_file`) emit these cards live
6
+ * over the chat SSE stream, but the persisted turn keeps only the Anthropic
7
+ * transcript (text / tool_use / tool_result) — the cards are not stored. To
8
+ * re-render a card on reload, `content-to-cortex` reconstructs it from the
9
+ * tool_use block via these same builders, so the live and replayed cards are
10
+ * byte-identical (the deterministic `id` matches, enabling downstream
11
+ * reconciliation).
12
+ *
13
+ * The builders return the FLAT wire `data` payload (no `type` wrapper, no
14
+ * `source`): the tool emits `{ type, source, data }` (the emit pipeline
15
+ * flattens `data` onto the wire), while the read path spreads the payload
16
+ * under the part `type` directly.
17
+ */
18
+ import { type ResultAsync } from "neverthrow";
19
+ import type { Pool } from "pg";
20
+ import { type DbError } from "../lib/db-result.js";
21
+ export interface PlanCardData {
22
+ id: string;
23
+ planId: string;
24
+ title?: string;
25
+ steps: unknown;
26
+ analytical_narrative: unknown;
27
+ omicsType: unknown;
28
+ omicsSubtype: unknown;
29
+ }
30
+ export interface PresentationCardData {
31
+ id: string;
32
+ title?: string;
33
+ content: Record<string, unknown>;
34
+ }
35
+ export interface RunCardData {
36
+ id: string;
37
+ runId: string;
38
+ planId: string;
39
+ title: string;
40
+ stepCount: number;
41
+ }
42
+ export interface PreviewCardData {
43
+ id: string;
44
+ previewId: string;
45
+ version: number;
46
+ title: string;
47
+ previewPath: string;
48
+ format: "html" | "pdf";
49
+ }
50
+ /** Build the `data-plan` payload by loading the stored plan. `ok(null)` when
51
+ * the plan is missing or no longer parses (absence is NOT an error) — the
52
+ * caller falls back to a chip. */
53
+ export declare function buildPlanCardData(pool: Pool, planId: string, analysisId: string, title?: string): ResultAsync<PlanCardData | null, DbError>;
54
+ /** Build the `data-run-card` payload for a started analysis run. Loads the
55
+ * plan (for `title` + `stepCount`) the same way `buildPlanCardData` does. The
56
+ * live emit path passes the freshly-minted `runId`; the reconstruct-on-read
57
+ * path omits it and the most recent run for `(analysisId, planId)` is looked
58
+ * up from `cortex_runs`. Null when the plan or run cannot be resolved — the
59
+ * caller falls back to a chip. */
60
+ export declare function buildRunCardData(pool: Pool, opts: {
61
+ planId: string;
62
+ analysisId: string;
63
+ runId?: string;
64
+ }): ResultAsync<RunCardData | null, DbError>;
65
+ /** Build the `data-presentation` payload from the `show_user` tool input.
66
+ * Self-contained — the card lives entirely in the input. */
67
+ export declare function buildPresentationCardData(input: Record<string, unknown>): PresentationCardData | null;
68
+ /** Max files a `show_file` group may reference; multiple render as a gallery. */
69
+ export declare const MAX_FILES = 10;
70
+ /** One referenced file in a `data-file-reference` card. */
71
+ export interface FileReferenceEntryData {
72
+ path: string;
73
+ runId?: string;
74
+ caption?: string;
75
+ }
76
+ /** The `data-file-reference` payload: a group of referenced analysis artifacts. */
77
+ export interface FileReferenceCardData {
78
+ id: string;
79
+ title?: string;
80
+ files: FileReferenceEntryData[];
81
+ }
82
+ /** Extracts `runId` from paths shaped `runs/{runId}/...`; undefined otherwise. */
83
+ export declare function deriveRunId(path: string): string | undefined;
84
+ /** Stable dedup key over sorted paths + optional title. */
85
+ export declare function fileGroupHash(paths: string[], title: string | undefined): string;
86
+ /**
87
+ * Build the `data-file-reference` payload from the `show_file` tool input. Shared by the live emit
88
+ * and the reconstruct-on-read path so both cards are byte-identical (same group-hash id, per-entry
89
+ * `runId` derivation, captions). `null` when no valid group can be built — no files, too many, or ANY
90
+ * path failing the shared shape rules (leading slash / `..` traversal). The live tool maps `null` to
91
+ * its `invalid_path` variant and emits nothing; the read path falls back to a generic tool chip.
92
+ * Validating here is load-bearing: the transcript persists the raw tool_use, so without it a traversal
93
+ * path the live tool rejected would be resurrected into a card on reload.
94
+ */
95
+ export declare function buildFileReferenceCardData(input: Record<string, unknown>): FileReferenceCardData | null;
96
+ /**
97
+ * Build the `data-report-preview` payload for an `iterate_report` tool_use. The
98
+ * preview's source of truth is the filesystem under
99
+ * `previews/{previewId}/`: directory layout yields `version`
100
+ * (latest `vN`) + `previewPath`, and `preview-meta.json` yields title/format.
101
+ * Mirrors `buildRunCardData` — the live emit knows the server-generated
102
+ * `previewId`, while the reconstruct-on-read path resolves it (from the
103
+ * iteration's `previewId` input, or else the analysis's latest preview). The
104
+ * card is keyed by `previewId` only, so every iteration's tool_use rebuilds
105
+ * the same card and the frontend groups them into one with all versions selectable.
106
+ * Null when nothing renders — the caller falls back to a chip.
107
+ */
108
+ export declare function buildPreviewCardData(
109
+ /** Absolute host root of the analysis's workspace tree (previews live inside it). */
110
+ workspaceRoot: string, opts: {
111
+ previewId?: string;
112
+ title?: string;
113
+ format?: "html" | "pdf";
114
+ }): Promise<PreviewCardData | null>;
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Shared builders for the display-card data parts (`data-plan`,
3
+ * `data-presentation`, `data-run-card`, `data-file-reference`).
4
+ *
5
+ * Display tools (`show_plan`, `show_user`, `show_file`) emit these cards live
6
+ * over the chat SSE stream, but the persisted turn keeps only the Anthropic
7
+ * transcript (text / tool_use / tool_result) — the cards are not stored. To
8
+ * re-render a card on reload, `content-to-cortex` reconstructs it from the
9
+ * tool_use block via these same builders, so the live and replayed cards are
10
+ * byte-identical (the deterministic `id` matches, enabling downstream
11
+ * reconciliation).
12
+ *
13
+ * The builders return the FLAT wire `data` payload (no `type` wrapper, no
14
+ * `source`): the tool emits `{ type, source, data }` (the emit pipeline
15
+ * flattens `data` onto the wire), while the read path spreads the payload
16
+ * under the part `type` directly.
17
+ */
18
+ import { createHash } from "node:crypto";
19
+ import { readdir, readFile, stat } from "node:fs/promises";
20
+ import { join } from "node:path";
21
+ import { okAsync } from "neverthrow";
22
+ import { tryQuery } from "../lib/db-result.js";
23
+ import { tryFs } from "../lib/fs-result.js";
24
+ import { AnalysisPlanSchema } from "../schemas/workflow-state.js";
25
+ import { loadPlan } from "../state/index.js";
26
+ import { validatePath } from "../tools/lib/path-validation.js";
27
+ import { latestPreviewVersion, previewDir, PREVIEWS_ROOT } from "../workspace/paths.js";
28
+ const PREVIEW_META_FILE = "preview-meta.json";
29
+ /** Deterministic presentation id — must match `show_user`'s. */
30
+ function presentationId(input) {
31
+ const hash = createHash("sha256")
32
+ .update(JSON.stringify(input, Object.keys(input).sort()))
33
+ .digest("hex")
34
+ .slice(0, 16);
35
+ return `pres-${hash}`;
36
+ }
37
+ /** Build the `data-plan` payload by loading the stored plan. `ok(null)` when
38
+ * the plan is missing or no longer parses (absence is NOT an error) — the
39
+ * caller falls back to a chip. */
40
+ export function buildPlanCardData(pool, planId, analysisId, title) {
41
+ return loadPlan(pool, planId, { analysisId }).map((plan) => {
42
+ if (!plan)
43
+ return null;
44
+ const parsed = AnalysisPlanSchema.safeParse(plan);
45
+ if (!parsed.success)
46
+ return null;
47
+ const id = `pres-${createHash("sha256").update(planId).digest("hex").slice(0, 16)}`;
48
+ // Explicit `show_plan({ title })` overrides; otherwise default to the
49
+ // planner-set plan title so both cards share one source.
50
+ const heading = title ?? parsed.data.title;
51
+ return {
52
+ id,
53
+ planId,
54
+ ...(heading !== undefined ? { title: heading } : {}),
55
+ steps: parsed.data.steps,
56
+ analytical_narrative: parsed.data.analytical_narrative,
57
+ omicsType: parsed.data.omicsType,
58
+ omicsSubtype: parsed.data.omicsSubtype,
59
+ };
60
+ });
61
+ }
62
+ /** Build the `data-run-card` payload for a started analysis run. Loads the
63
+ * plan (for `title` + `stepCount`) the same way `buildPlanCardData` does. The
64
+ * live emit path passes the freshly-minted `runId`; the reconstruct-on-read
65
+ * path omits it and the most recent run for `(analysisId, planId)` is looked
66
+ * up from `cortex_runs`. Null when the plan or run cannot be resolved — the
67
+ * caller falls back to a chip. */
68
+ export function buildRunCardData(pool, opts) {
69
+ const { planId, analysisId } = opts;
70
+ return loadPlan(pool, planId, { analysisId }).andThen((plan) => {
71
+ if (!plan)
72
+ return okAsync(null);
73
+ const parsed = AnalysisPlanSchema.safeParse(plan);
74
+ if (!parsed.success)
75
+ return okAsync(null);
76
+ const finalize = (runId) => {
77
+ if (!runId)
78
+ return null;
79
+ const omicsType = parsed.data.omicsType;
80
+ const title = parsed.data.title?.trim() || (omicsType ? `${omicsType} analysis` : "Analysis run");
81
+ const id = `pres-${createHash("sha256").update(runId).digest("hex").slice(0, 16)}`;
82
+ return {
83
+ id,
84
+ runId,
85
+ planId,
86
+ title,
87
+ stepCount: parsed.data.steps.length,
88
+ };
89
+ };
90
+ if (opts.runId)
91
+ return okAsync(finalize(opts.runId));
92
+ return tryQuery("cardBuilders.buildRunCardData.latestRun", async () => {
93
+ const result = await pool.query({
94
+ text: `SELECT run_id FROM cortex_runs
95
+ WHERE analysis_id = $1 AND plan_id = $2
96
+ ORDER BY started_at DESC LIMIT 1`,
97
+ values: [analysisId, planId],
98
+ });
99
+ return result.rows[0]?.run_id;
100
+ }).map(finalize);
101
+ });
102
+ }
103
+ /** Build the `data-presentation` payload from the `show_user` tool input.
104
+ * Self-contained — the card lives entirely in the input. */
105
+ export function buildPresentationCardData(input) {
106
+ const { kind, title, ...rest } = input;
107
+ if (typeof kind !== "string")
108
+ return null;
109
+ return {
110
+ id: presentationId(input),
111
+ ...(typeof title === "string" ? { title } : {}),
112
+ content: { kind, ...rest },
113
+ };
114
+ }
115
+ /** Max files a `show_file` group may reference; multiple render as a gallery. */
116
+ export const MAX_FILES = 10;
117
+ /** Extracts `runId` from paths shaped `runs/{runId}/...`; undefined otherwise. */
118
+ export function deriveRunId(path) {
119
+ const segments = path.split("/");
120
+ if (segments.length >= 2 && segments[0] === "runs" && segments[1].length > 0) {
121
+ return segments[1];
122
+ }
123
+ return undefined;
124
+ }
125
+ /** Stable dedup key over sorted paths + optional title. */
126
+ export function fileGroupHash(paths, title) {
127
+ const sorted = [...paths].sort();
128
+ const material = JSON.stringify({ title: title ?? null, paths: sorted });
129
+ return createHash("sha256").update(material).digest("hex").slice(0, 16);
130
+ }
131
+ /**
132
+ * Build the `data-file-reference` payload from the `show_file` tool input. Shared by the live emit
133
+ * and the reconstruct-on-read path so both cards are byte-identical (same group-hash id, per-entry
134
+ * `runId` derivation, captions). `null` when no valid group can be built — no files, too many, or ANY
135
+ * path failing the shared shape rules (leading slash / `..` traversal). The live tool maps `null` to
136
+ * its `invalid_path` variant and emits nothing; the read path falls back to a generic tool chip.
137
+ * Validating here is load-bearing: the transcript persists the raw tool_use, so without it a traversal
138
+ * path the live tool rejected would be resurrected into a card on reload.
139
+ */
140
+ export function buildFileReferenceCardData(input) {
141
+ const title = typeof input.title === "string" ? input.title : undefined;
142
+ const rawFiles = Array.isArray(input.files) ? input.files : [];
143
+ if (rawFiles.length === 0 || rawFiles.length > MAX_FILES)
144
+ return null;
145
+ const files = [];
146
+ for (const raw of rawFiles) {
147
+ const file = (raw ?? {});
148
+ const path = typeof file.path === "string" ? file.path : "";
149
+ if (validatePath(path) !== null)
150
+ return null;
151
+ const runId = deriveRunId(path);
152
+ const caption = typeof file.caption === "string" ? file.caption : undefined;
153
+ files.push({
154
+ path,
155
+ ...(runId !== undefined ? { runId } : {}),
156
+ ...(caption !== undefined ? { caption } : {}),
157
+ });
158
+ }
159
+ const id = `pres-${fileGroupHash(files.map((f) => f.path), title)}`;
160
+ return { id, ...(title !== undefined ? { title } : {}), files };
161
+ }
162
+ /** The stored preview metadata, or `null` when the file is absent — a malformed
163
+ * file is a genuine read failure (`err`), folded to `null` at the call site. */
164
+ function readPreviewMeta(previewRootAbs) {
165
+ const path = join(previewRootAbs, PREVIEW_META_FILE);
166
+ return tryFs("cardBuilders.readPreviewMeta", async () => JSON.parse(await readFile(path, "utf8")), { path, onAbsent: () => null });
167
+ }
168
+ /** Directory names (not files) directly under `dir`, or `[]` when absent. */
169
+ function subdirs(dir) {
170
+ return tryFs("cardBuilders.subdirs", async () => (await readdir(dir, { withFileTypes: true })).filter((e) => e.isDirectory()).map((e) => e.name), {
171
+ path: dir,
172
+ onAbsent: () => [],
173
+ });
174
+ }
175
+ /** The most-recently-modified previewId under an analysis, or null when none. */
176
+ function latestPreviewId(previewsRootAbs) {
177
+ return subdirs(previewsRootAbs).map(async (dirs) => {
178
+ if (dirs.length <= 1)
179
+ return dirs[0] ?? null;
180
+ let best = null;
181
+ for (const name of dirs) {
182
+ const path = join(previewsRootAbs, name);
183
+ const mtimeMs = await tryFs("cardBuilders.latestPreviewId.stat", async () => (await stat(path)).mtimeMs, { path }).unwrapOr(null); // skip an unreadable/absent entry
184
+ if (mtimeMs !== null && (!best || mtimeMs > best.mtimeMs)) {
185
+ best = { name, mtimeMs };
186
+ }
187
+ }
188
+ return best?.name ?? dirs[0];
189
+ });
190
+ }
191
+ /**
192
+ * Build the `data-report-preview` payload for an `iterate_report` tool_use. The
193
+ * preview's source of truth is the filesystem under
194
+ * `previews/{previewId}/`: directory layout yields `version`
195
+ * (latest `vN`) + `previewPath`, and `preview-meta.json` yields title/format.
196
+ * Mirrors `buildRunCardData` — the live emit knows the server-generated
197
+ * `previewId`, while the reconstruct-on-read path resolves it (from the
198
+ * iteration's `previewId` input, or else the analysis's latest preview). The
199
+ * card is keyed by `previewId` only, so every iteration's tool_use rebuilds
200
+ * the same card and the frontend groups them into one with all versions selectable.
201
+ * Null when nothing renders — the caller falls back to a chip.
202
+ */
203
+ export async function buildPreviewCardData(
204
+ /** Absolute host root of the analysis's workspace tree (previews live inside it). */
205
+ workspaceRoot, opts) {
206
+ const previewsRootAbs = join(workspaceRoot, PREVIEWS_ROOT);
207
+ const resolveId = opts.previewId ? okAsync(opts.previewId) : latestPreviewId(previewsRootAbs);
208
+ return resolveId
209
+ .andThen((previewId) => {
210
+ if (!previewId)
211
+ return okAsync(null);
212
+ const previewRootAbs = join(workspaceRoot, previewDir(previewId));
213
+ return subdirs(previewRootAbs).andThen((versionDirs) => {
214
+ const version = latestPreviewVersion(versionDirs);
215
+ if (version === 0)
216
+ return okAsync(null);
217
+ return readPreviewMeta(previewRootAbs).map((meta) => {
218
+ const id = `prev-${createHash("sha256").update(previewId).digest("hex").slice(0, 16)}`;
219
+ return {
220
+ id,
221
+ previewId,
222
+ version,
223
+ title: opts.title ?? meta?.title ?? "Report",
224
+ previewPath: `v${version}/index.html`,
225
+ format: opts.format ?? (meta?.format === "pdf" ? "pdf" : "html"),
226
+ };
227
+ });
228
+ });
229
+ })
230
+ .unwrapOr(null);
231
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Converter: stored AI SDK model messages → wire `CortexMessage[]`.
3
+ *
4
+ * The display read (`ThreadHistory.loadPage`) returns rows whose `content`
5
+ * is the AI SDK `ModelMessage` that `appendTurn` persisted. This maps each
6
+ * row to a `CortexMessage` for the chat wire:
7
+ *
8
+ * - text part → text part
9
+ * - tool-call part → a reconstructed display card (`data-plan`,
10
+ * `data-presentation`) when `resolveCard` recognises
11
+ * the tool, else a generic tool-call part
12
+ * - everything else → dropped (reasoning, tool-result, etc.) — the UI
13
+ * does not render them
14
+ *
15
+ * Display cards are emitted live over the chat SSE stream but never persisted
16
+ * (storage holds only the AI SDK model-message transcript). `resolveCard`
17
+ * rebuilds them from the persisted tool-call part so they reappear on reload.
18
+ *
19
+ * A row that yields no renderable parts (e.g. a `tool`-role message carrying
20
+ * only tool-result continuation parts) is omitted entirely, so the rendered
21
+ * conversation has no empty bubbles. Storage is never mutated.
22
+ */
23
+ import type { CortexMessage } from "@inflexa-ai/harness/contracts/message.js";
24
+ import type { ToolCardResolver } from "./reconstruct-cards.js";
25
+ import type { StoredMessage } from "./thread-history.js";
26
+ /**
27
+ * Map stored messages (oldest-first) to `CortexMessage[]`. Rows that produce
28
+ * no renderable parts are dropped, and consecutive same-role rows are coalesced
29
+ * into one message. The first row's `seq` becomes the stable message id.
30
+ * `resolveCard` (optional) reconstructs display cards from `tool_use` blocks.
31
+ *
32
+ * Coalescing mirrors the live SSE shape. The agent loop persists each assistant
33
+ * step (typically a single `tool_use`) as its own row, and the `tool_result`
34
+ * `user` rows between them drop to zero renderable parts above — so one assistant
35
+ * turn is stored as a run of adjacent assistant rows. The live chat stream
36
+ * accumulates that whole turn into a single assistant message whose `parts` hold
37
+ * every step; reconstructing it row-by-row instead would emit one message per
38
+ * tool call, which the UI renders as a stack of single-tool boxes. Merging the
39
+ * run restores the one-bubble-per-turn shape (and lets the UI collapse the tool
40
+ * calls into one group) regardless of how the loop split the turn into rows.
41
+ */
42
+ export declare function contentToCortexMessages(messages: readonly StoredMessage[], resolveCard?: ToolCardResolver): Promise<CortexMessage[]>;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Converter: stored AI SDK model messages → wire `CortexMessage[]`.
3
+ *
4
+ * The display read (`ThreadHistory.loadPage`) returns rows whose `content`
5
+ * is the AI SDK `ModelMessage` that `appendTurn` persisted. This maps each
6
+ * row to a `CortexMessage` for the chat wire:
7
+ *
8
+ * - text part → text part
9
+ * - tool-call part → a reconstructed display card (`data-plan`,
10
+ * `data-presentation`) when `resolveCard` recognises
11
+ * the tool, else a generic tool-call part
12
+ * - everything else → dropped (reasoning, tool-result, etc.) — the UI
13
+ * does not render them
14
+ *
15
+ * Display cards are emitted live over the chat SSE stream but never persisted
16
+ * (storage holds only the AI SDK model-message transcript). `resolveCard`
17
+ * rebuilds them from the persisted tool-call part so they reappear on reload.
18
+ *
19
+ * A row that yields no renderable parts (e.g. a `tool`-role message carrying
20
+ * only tool-result continuation parts) is omitted entirely, so the rendered
21
+ * conversation has no empty bubbles. Storage is never mutated.
22
+ */
23
+ function genericToolCall(block) {
24
+ return {
25
+ type: "tool-call",
26
+ toolCallId: block.toolCallId,
27
+ toolName: block.toolName,
28
+ status: "finished",
29
+ };
30
+ }
31
+ async function blockToPart(block, resolveCard) {
32
+ if (block.type === "text")
33
+ return { type: "text", text: block.text };
34
+ if (block.type === "tool-call") {
35
+ const card = resolveCard ? await resolveCard({ type: "tool_use", id: block.toolCallId, name: block.toolName, input: block.input }) : null;
36
+ return card ?? genericToolCall(block);
37
+ }
38
+ // reasoning, tool_result, file, and any other block — not rendered.
39
+ return null;
40
+ }
41
+ async function rowToParts(message, resolveCard) {
42
+ const content = message.content;
43
+ if (typeof content === "string") {
44
+ return content.length > 0 ? [{ type: "text", text: content }] : [];
45
+ }
46
+ const parts = [];
47
+ for (const block of content) {
48
+ const part = await blockToPart(block, resolveCard);
49
+ if (part)
50
+ parts.push(part);
51
+ }
52
+ return parts;
53
+ }
54
+ /**
55
+ * Map stored messages (oldest-first) to `CortexMessage[]`. Rows that produce
56
+ * no renderable parts are dropped, and consecutive same-role rows are coalesced
57
+ * into one message. The first row's `seq` becomes the stable message id.
58
+ * `resolveCard` (optional) reconstructs display cards from `tool_use` blocks.
59
+ *
60
+ * Coalescing mirrors the live SSE shape. The agent loop persists each assistant
61
+ * step (typically a single `tool_use`) as its own row, and the `tool_result`
62
+ * `user` rows between them drop to zero renderable parts above — so one assistant
63
+ * turn is stored as a run of adjacent assistant rows. The live chat stream
64
+ * accumulates that whole turn into a single assistant message whose `parts` hold
65
+ * every step; reconstructing it row-by-row instead would emit one message per
66
+ * tool call, which the UI renders as a stack of single-tool boxes. Merging the
67
+ * run restores the one-bubble-per-turn shape (and lets the UI collapse the tool
68
+ * calls into one group) regardless of how the loop split the turn into rows.
69
+ */
70
+ export async function contentToCortexMessages(messages, resolveCard) {
71
+ const out = [];
72
+ for (const message of messages) {
73
+ const parts = await rowToParts(message.message, resolveCard);
74
+ if (parts.length === 0)
75
+ continue;
76
+ const role = message.message.role === "tool" ? "assistant" : message.message.role;
77
+ const prev = out[out.length - 1];
78
+ if (prev && prev.role === role) {
79
+ prev.parts.push(...parts);
80
+ continue;
81
+ }
82
+ out.push({ id: String(message.seq), role, parts });
83
+ }
84
+ return out;
85
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Write-time token counting for the conversation message store.
3
+ *
4
+ * `appendTurn` stamps a `tokens` count on every message row so `loadRecent`
5
+ * windows by token budget without tokenizing on the read path. Counted once
6
+ * at write, applied at load.
7
+ *
8
+ * Providers do not publish one shared offline tokenizer,
9
+ * so this uses `js-tiktoken`'s `cl100k_base` BPE. It is an approximation:
10
+ * callers treat the budget as a soft target with a safety margin below the
11
+ * true context limit.
12
+ */
13
+ import type { ModelMessage } from "ai";
14
+ /**
15
+ * Token count of a message's content. Used only at write time. Empty
16
+ * content (an empty array or empty string) counts as `0`.
17
+ */
18
+ export declare function countTokens(content: ModelMessage["content"]): number;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Write-time token counting for the conversation message store.
3
+ *
4
+ * `appendTurn` stamps a `tokens` count on every message row so `loadRecent`
5
+ * windows by token budget without tokenizing on the read path. Counted once
6
+ * at write, applied at load.
7
+ *
8
+ * Providers do not publish one shared offline tokenizer,
9
+ * so this uses `js-tiktoken`'s `cl100k_base` BPE. It is an approximation:
10
+ * callers treat the budget as a soft target with a safety margin below the
11
+ * true context limit.
12
+ */
13
+ import { getEncoding } from "js-tiktoken";
14
+ let encoder;
15
+ function enc() {
16
+ encoder ??= getEncoding("cl100k_base");
17
+ return encoder;
18
+ }
19
+ /**
20
+ * The token-bearing text of one content block. Text-carrying fields are
21
+ * extracted directly; structural blocks (`tool_use` input, `tool_result`
22
+ * payload) are JSON-stringified. A signed `thinking` block counts only its
23
+ * reasoning text — the opaque `signature` is metadata, not prompt tokens.
24
+ */
25
+ function tokenizableText(block) {
26
+ if (typeof block === "string")
27
+ return block;
28
+ if (typeof block !== "object" || block === null)
29
+ return JSON.stringify(block);
30
+ const part = block;
31
+ switch (part.type) {
32
+ case "text":
33
+ return typeof part.text === "string" ? part.text : "";
34
+ case "reasoning":
35
+ return typeof part.text === "string" ? part.text : "";
36
+ case "reasoning-file":
37
+ case "custom":
38
+ case "file":
39
+ return "";
40
+ case "tool-call":
41
+ return `${String(part.toolName ?? "")} ${JSON.stringify(part.input ?? {})}`;
42
+ case "tool-result": {
43
+ return `${String(part.toolName ?? "")} ${JSON.stringify(part.output ?? {})}`;
44
+ }
45
+ default:
46
+ return JSON.stringify(part);
47
+ }
48
+ }
49
+ /**
50
+ * Token count of a message's content. Used only at write time. Empty
51
+ * content (an empty array or empty string) counts as `0`.
52
+ */
53
+ export function countTokens(content) {
54
+ if (typeof content === "string") {
55
+ return content.length === 0 ? 0 : enc().encode(content).length;
56
+ }
57
+ let total = 0;
58
+ for (const block of content) {
59
+ const text = tokenizableText(block);
60
+ if (text.length > 0)
61
+ total += enc().encode(text).length;
62
+ }
63
+ return total;
64
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Derive a deterministic thread title from the user's first message.
3
+ * Pure function — no I/O, no global state.
4
+ *
5
+ * Rules:
6
+ * 1. Collapse runs of whitespace to a single space.
7
+ * 2. Trim.
8
+ * 3. Empty / whitespace-only input → `"Untitled"`.
9
+ * 4. If length ≤ `max`, return unchanged.
10
+ * 5. Else slice to `max`, walk back to the last space (word boundary),
11
+ * append the real ellipsis `…` (U+2026). If no space exists inside
12
+ * the window, hard-slice at `max` and append `…`.
13
+ */
14
+ export declare function deriveThreadTitle(text: string, max?: number): string;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Derive a deterministic thread title from the user's first message.
3
+ * Pure function — no I/O, no global state.
4
+ *
5
+ * Rules:
6
+ * 1. Collapse runs of whitespace to a single space.
7
+ * 2. Trim.
8
+ * 3. Empty / whitespace-only input → `"Untitled"`.
9
+ * 4. If length ≤ `max`, return unchanged.
10
+ * 5. Else slice to `max`, walk back to the last space (word boundary),
11
+ * append the real ellipsis `…` (U+2026). If no space exists inside
12
+ * the window, hard-slice at `max` and append `…`.
13
+ */
14
+ export function deriveThreadTitle(text, max = 40) {
15
+ const normalized = text.replace(/\s+/g, " ").trim();
16
+ if (normalized.length === 0)
17
+ return "Untitled";
18
+ if (normalized.length <= max)
19
+ return normalized;
20
+ const slice = normalized.slice(0, max);
21
+ const lastSpace = slice.lastIndexOf(" ");
22
+ if (lastSpace > 0) {
23
+ return slice.slice(0, lastSpace) + "…";
24
+ }
25
+ return slice + "…";
26
+ }
@@ -0,0 +1,2 @@
1
+ import type { PoolClient } from "pg";
2
+ export declare function backfillAiSdkMessageEnvelopes(client: PoolClient): Promise<void>;
@@ -0,0 +1,38 @@
1
+ import { envelopeMessage, legacyAnthropicToModelMessage } from "./ai-sdk-message-storage.js";
2
+ export async function backfillAiSdkMessageEnvelopes(client) {
3
+ // Legacy Anthropic columns (`role`, `content_jsonb`) are temporary and
4
+ // should be removed after the AI SDK message-envelope migration window.
5
+ const { rows } = await client.query(`SELECT thread_id, seq::text AS seq, role, content_jsonb
6
+ FROM messages
7
+ WHERE message_envelope IS NULL
8
+ ORDER BY thread_id, seq`);
9
+ for (const row of rows) {
10
+ const identity = `${row.thread_id}/${row.seq}`;
11
+ try {
12
+ const message = legacyAnthropicToModelMessage({
13
+ threadId: row.thread_id,
14
+ seq: Number(row.seq),
15
+ role: row.role,
16
+ content: row.content_jsonb,
17
+ });
18
+ await client.query("UPDATE messages SET message_envelope = $1::jsonb WHERE thread_id = $2 AND seq = $3::bigint", [
19
+ JSON.stringify(envelopeMessage(message)),
20
+ row.thread_id,
21
+ row.seq,
22
+ ]);
23
+ }
24
+ catch (err) {
25
+ const message = err instanceof Error ? err.message : String(err);
26
+ throw new Error(`Failed to backfill AI SDK message envelope for ${identity}: ${message}`, { cause: err });
27
+ }
28
+ }
29
+ const remaining = await client.query(`SELECT thread_id, seq::text AS seq
30
+ FROM messages
31
+ WHERE message_envelope IS NULL
32
+ ORDER BY thread_id, seq
33
+ LIMIT 1`);
34
+ if (remaining.rows.length > 0) {
35
+ const row = remaining.rows[0];
36
+ throw new Error(`AI SDK message backfill left an unmigrated row at ${row.thread_id}/${row.seq}`);
37
+ }
38
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Read-path reconstruction of display cards from a persisted turn.
3
+ *
4
+ * `show_plan` / `show_user` / `show_file` / `execute_plan` / `iterate_report` emit
5
+ * `data-plan` / `data-presentation` / `data-file-reference` / `data-run-card` /
6
+ * `data-report-preview` cards
7
+ * live over the chat SSE stream. On reload, `content-to-cortex` calls this
8
+ * resolver for each AI SDK tool-call part: a recognised display tool yields its card (rebuilt via the
9
+ * shared `card-builders`); anything else yields `null` and falls back to a
10
+ * generic `tool-call` chip. Keyed by the analysis `Pool` + id (plan / run) or
11
+ * the analysis's workspace root (preview, filesystem-backed) so the card can
12
+ * be re-loaded.
13
+ */
14
+ import type { CortexPart } from "@inflexa-ai/harness/contracts/message.js";
15
+ import type { Pool } from "pg";
16
+ export interface StoredToolCallForCard {
17
+ readonly type: "tool_use";
18
+ readonly id: string;
19
+ readonly name: string;
20
+ readonly input: unknown;
21
+ }
22
+ export type ToolCardResolver = (block: StoredToolCallForCard) => Promise<CortexPart | null>;
23
+ export declare function createCardResolver(pool: Pool, analysisId: string, workspaceRoot: string): ToolCardResolver;