@inflexa-ai/harness 0.1.1 → 0.2.0

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 (268) hide show
  1. package/dist/agents/conversation-agent.d.ts +12 -11
  2. package/dist/agents/conversation-agent.js +30 -33
  3. package/dist/agents/report-builder.js +2 -1
  4. package/dist/agents/sandbox/bulk-transcriptomics-agent.js +1 -1
  5. package/dist/agents/sandbox/cheminformatics-agent.js +1 -19
  6. package/dist/agents/sandbox/chromatin-agent.js +1 -10
  7. package/dist/agents/sandbox/dna-methylation-agent.js +1 -10
  8. package/dist/agents/sandbox/drug-repurposing-agent.js +4 -14
  9. package/dist/agents/sandbox/enrichment-agent.js +1 -10
  10. package/dist/agents/sandbox/ephemeral-executor.js +1 -10
  11. package/dist/agents/sandbox/genomic-variant-agent.js +1 -3
  12. package/dist/agents/sandbox/immune-profiling-agent.js +1 -13
  13. package/dist/agents/sandbox/metabolomics-agent.js +1 -1
  14. package/dist/agents/sandbox/microbiome-agent.js +1 -1
  15. package/dist/agents/sandbox/multi-omics-integration-agent.js +1 -12
  16. package/dist/agents/sandbox/multimodal-sc-agent.js +1 -1
  17. package/dist/agents/sandbox/network-agent.js +1 -10
  18. package/dist/agents/sandbox/pkpd-clinical-response-agent.js +2 -8
  19. package/dist/agents/sandbox/proteomics-agent.js +1 -1
  20. package/dist/agents/sandbox/scientific-executor.js +1 -10
  21. package/dist/agents/sandbox/shared.d.ts +17 -6
  22. package/dist/agents/sandbox/shared.js +49 -38
  23. package/dist/agents/sandbox/single-cell-agent.js +1 -1
  24. package/dist/agents/sandbox/spatial-omics-agent.js +1 -1
  25. package/dist/agents/sandbox/statistical-modeling-agent.js +1 -1
  26. package/dist/agents/sandbox/translational-safety-agent.js +3 -9
  27. package/dist/agents/sandbox/types.d.ts +1 -1
  28. package/dist/agents/system-prompt.d.ts +37 -11
  29. package/dist/agents/system-prompt.js +35 -12
  30. package/dist/app/data-profile-orientation.d.ts +34 -0
  31. package/dist/app/data-profile-orientation.js +117 -0
  32. package/dist/contracts/schemas/chat-parts.d.ts +9 -9
  33. package/dist/execution/artifact-metadata.js +2 -1
  34. package/dist/execution/ephemeral-runner.d.ts +13 -0
  35. package/dist/execution/ephemeral-runner.js +23 -1
  36. package/dist/execution/run-synthesis.js +20 -19
  37. package/dist/execution/step-summary.js +2 -1
  38. package/dist/index.d.ts +6 -2
  39. package/dist/index.js +19 -5
  40. package/dist/loop/__fixtures__/scripted-provider.d.ts +2 -2
  41. package/dist/loop/__fixtures__/scripted-provider.js +2 -1
  42. package/dist/loop/metrics.d.ts +33 -1
  43. package/dist/loop/metrics.js +56 -2
  44. package/dist/loop/run-agent.d.ts +13 -1
  45. package/dist/loop/run-agent.js +19 -4
  46. package/dist/memory/card-builders.d.ts +8 -1
  47. package/dist/memory/card-builders.js +20 -3
  48. package/dist/memory/reconstruct-cards.js +4 -3
  49. package/dist/memory/thread-history.d.ts +27 -2
  50. package/dist/memory/thread-history.js +45 -5
  51. package/dist/memory/working-memory.d.ts +93 -10
  52. package/dist/memory/working-memory.js +220 -84
  53. package/dist/prompts/SOUL.d.ts +22 -9
  54. package/dist/prompts/SOUL.js +56 -37
  55. package/dist/prompts/analogical-reasoner.d.ts +1 -1
  56. package/dist/prompts/analogical-reasoner.js +2 -2
  57. package/dist/prompts/briefing.d.ts +100 -0
  58. package/dist/prompts/briefing.js +166 -0
  59. package/dist/prompts/conversation.d.ts +1 -1
  60. package/dist/prompts/conversation.js +94 -440
  61. package/dist/prompts/literature-reviewer.d.ts +1 -1
  62. package/dist/prompts/literature-reviewer.js +10 -10
  63. package/dist/prompts/planner.js +28 -59
  64. package/dist/prompts/report-builder.d.ts +1 -1
  65. package/dist/prompts/report-builder.js +71 -24
  66. package/dist/prompts/sandbox/bulk-transcriptomics-agent.d.ts +1 -1
  67. package/dist/prompts/sandbox/bulk-transcriptomics-agent.js +2 -7
  68. package/dist/prompts/sandbox/cheminformatics-agent.d.ts +1 -1
  69. package/dist/prompts/sandbox/cheminformatics-agent.js +11 -15
  70. package/dist/prompts/sandbox/chromatin-agent.d.ts +1 -1
  71. package/dist/prompts/sandbox/chromatin-agent.js +3 -7
  72. package/dist/prompts/sandbox/data-profiler.d.ts +1 -1
  73. package/dist/prompts/sandbox/data-profiler.js +13 -8
  74. package/dist/prompts/sandbox/dna-methylation-agent.d.ts +1 -1
  75. package/dist/prompts/sandbox/dna-methylation-agent.js +2 -7
  76. package/dist/prompts/sandbox/drug-repurposing-agent.d.ts +1 -1
  77. package/dist/prompts/sandbox/drug-repurposing-agent.js +15 -16
  78. package/dist/prompts/sandbox/enrichment-agent.d.ts +1 -1
  79. package/dist/prompts/sandbox/enrichment-agent.js +2 -9
  80. package/dist/prompts/sandbox/genomic-variant-agent.d.ts +1 -1
  81. package/dist/prompts/sandbox/genomic-variant-agent.js +2 -6
  82. package/dist/prompts/sandbox/immune-profiling-agent.d.ts +1 -1
  83. package/dist/prompts/sandbox/immune-profiling-agent.js +3 -8
  84. package/dist/prompts/sandbox/metabolomics-agent.d.ts +1 -1
  85. package/dist/prompts/sandbox/metabolomics-agent.js +1 -7
  86. package/dist/prompts/sandbox/microbiome-agent.d.ts +1 -1
  87. package/dist/prompts/sandbox/microbiome-agent.js +2 -7
  88. package/dist/prompts/sandbox/multi-omics-integration-agent.d.ts +1 -1
  89. package/dist/prompts/sandbox/multi-omics-integration-agent.js +2 -8
  90. package/dist/prompts/sandbox/multimodal-sc-agent.d.ts +1 -1
  91. package/dist/prompts/sandbox/multimodal-sc-agent.js +2 -7
  92. package/dist/prompts/sandbox/network-agent.d.ts +1 -1
  93. package/dist/prompts/sandbox/network-agent.js +2 -7
  94. package/dist/prompts/sandbox/proteomics-agent.d.ts +1 -1
  95. package/dist/prompts/sandbox/proteomics-agent.js +2 -9
  96. package/dist/prompts/sandbox/single-cell-agent.d.ts +1 -1
  97. package/dist/prompts/sandbox/single-cell-agent.js +2 -9
  98. package/dist/prompts/sandbox/spatial-omics-agent.d.ts +1 -1
  99. package/dist/prompts/sandbox/spatial-omics-agent.js +3 -6
  100. package/dist/prompts/sandbox/statistical-modeling-agent.d.ts +1 -1
  101. package/dist/prompts/sandbox/statistical-modeling-agent.js +2 -7
  102. package/dist/prompts/sandbox/translational-safety-agent.d.ts +1 -1
  103. package/dist/prompts/sandbox/translational-safety-agent.js +13 -14
  104. package/dist/prompts/sandbox-standards.d.ts +22 -14
  105. package/dist/prompts/sandbox-standards.js +91 -71
  106. package/dist/prompts/synthesis-agent.d.ts +1 -1
  107. package/dist/prompts/synthesis-agent.js +33 -131
  108. package/dist/provenance/collector.js +1 -1
  109. package/dist/providers/ai-sdk.js +31 -4
  110. package/dist/providers/prompt-cache.d.ts +74 -0
  111. package/dist/providers/prompt-cache.js +77 -0
  112. package/dist/providers/types.d.ts +33 -0
  113. package/dist/reference-data/catalog.d.ts +131 -0
  114. package/dist/reference-data/catalog.js +348 -0
  115. package/dist/reference-data/receipt.d.ts +41 -0
  116. package/dist/reference-data/receipt.js +40 -0
  117. package/dist/schemas/data-profile-schemas.js +5 -3
  118. package/dist/schemas/plan-schemas.d.ts +21 -21
  119. package/dist/schemas/plan-schemas.js +9 -3
  120. package/dist/schemas/run-synthesis.d.ts +8 -4
  121. package/dist/schemas/run-synthesis.js +92 -56
  122. package/dist/schemas/validate-plan.js +1 -1
  123. package/dist/schemas/workflow-state.d.ts +7 -1
  124. package/dist/schemas/workflow-state.js +33 -19
  125. package/dist/state/artifacts.d.ts +13 -0
  126. package/dist/state/artifacts.js +27 -0
  127. package/dist/state/data-profile.d.ts +64 -5
  128. package/dist/state/index.d.ts +3 -3
  129. package/dist/state/index.js +1 -1
  130. package/dist/tasks/data-profile.d.ts +20 -2
  131. package/dist/tasks/data-profile.js +71 -22
  132. package/dist/tools/bio/chembl.d.ts +38 -0
  133. package/dist/tools/bio/chembl.js +138 -0
  134. package/dist/tools/bio/comptox.d.ts +50 -0
  135. package/dist/tools/bio/comptox.js +149 -0
  136. package/dist/tools/bio/get-impc-ko-profile.js +9 -6
  137. package/dist/tools/bio/index.d.ts +5 -17
  138. package/dist/tools/bio/index.js +5 -17
  139. package/dist/tools/bio/keys.d.ts +14 -9
  140. package/dist/tools/bio/keys.js +16 -16
  141. package/dist/tools/bio/opentargets.d.ts +38 -0
  142. package/dist/tools/bio/opentargets.js +89 -0
  143. package/dist/tools/bio/pubchem.d.ts +29 -0
  144. package/dist/tools/bio/pubchem.js +92 -0
  145. package/dist/tools/bio/pubmed.d.ts +51 -0
  146. package/dist/tools/bio/pubmed.js +100 -0
  147. package/dist/tools/bio/search-bgee-expression.js +12 -6
  148. package/dist/tools/bio/search-clinical-trials.js +16 -5
  149. package/dist/tools/bio/search-faers.js +8 -4
  150. package/dist/tools/bio/search-geo-datasets.js +20 -6
  151. package/dist/tools/bio/search-gwas-catalog.d.ts +1 -1
  152. package/dist/tools/bio/search-pharmgkb.js +10 -4
  153. package/dist/tools/display/index.d.ts +1 -0
  154. package/dist/tools/display/index.js +1 -0
  155. package/dist/tools/display/normalize-echart-spec.d.ts +61 -0
  156. package/dist/tools/display/normalize-echart-spec.js +211 -0
  157. package/dist/tools/display/show-user.d.ts +6 -1
  158. package/dist/tools/display/show-user.js +25 -12
  159. package/dist/tools/execute-plan.js +5 -2
  160. package/dist/tools/iterate-report.d.ts +168 -118
  161. package/dist/tools/iterate-report.js +334 -96
  162. package/dist/tools/lib/chembl-client.d.ts +12 -0
  163. package/dist/tools/lib/chembl-client.js +127 -0
  164. package/dist/tools/lib/ctx-ops.d.ts +224 -0
  165. package/dist/tools/lib/ctx-ops.js +450 -0
  166. package/dist/tools/lib/iuphar-client.js +10 -1
  167. package/dist/tools/lib/openfda-client.js +11 -3
  168. package/dist/tools/lib/pathway-client.js +10 -4
  169. package/dist/tools/lib/pubchem-ops.d.ts +74 -0
  170. package/dist/tools/lib/pubchem-ops.js +224 -0
  171. package/dist/tools/memory/update-working-memory.d.ts +45 -7
  172. package/dist/tools/memory/update-working-memory.js +111 -41
  173. package/dist/tools/report/index.d.ts +3 -2
  174. package/dist/tools/report/index.js +3 -2
  175. package/dist/tools/research/generate-analogy-report.js +25 -12
  176. package/dist/tools/research/generate-plan.d.ts +12 -5
  177. package/dist/tools/research/generate-plan.js +168 -37
  178. package/dist/tools/research/index.d.ts +1 -0
  179. package/dist/tools/research/index.js +1 -0
  180. package/dist/tools/research/inspect-data-profile.d.ts +85 -0
  181. package/dist/tools/research/inspect-data-profile.js +161 -0
  182. package/dist/tools/research/literature-reviewer.js +3 -4
  183. package/dist/tools/sandbox/list-available-packages.d.ts +79 -5
  184. package/dist/tools/sandbox/list-available-packages.js +152 -10
  185. package/dist/tools/sandbox/list-available-refs.d.ts +141 -5
  186. package/dist/tools/sandbox/list-available-refs.js +647 -134
  187. package/dist/tools/sandbox/report-blocker.d.ts +39 -9
  188. package/dist/tools/sandbox/report-blocker.js +43 -20
  189. package/dist/tools/workspace/read-file.js +4 -5
  190. package/dist/tools/workspace/run-exec.d.ts +4 -4
  191. package/dist/tools/workspace/run-exec.js +4 -4
  192. package/dist/tools/workspace/show-file.js +10 -6
  193. package/dist/tools/workspace/show-plan.js +12 -6
  194. package/dist/tools/workspace/workspace-search.d.ts +1 -1
  195. package/dist/tools/workspace/workspace-search.js +11 -5
  196. package/dist/workflows/execute-analysis.d.ts +43 -4
  197. package/dist/workflows/execute-analysis.js +107 -6
  198. package/dist/workflows/target-assessment/lib/citation-validator.js +2 -2
  199. package/dist/workflows/target-assessment/lib/clinical-consequence-annotator.js +2 -1
  200. package/dist/workspace/paths.d.ts +2 -2
  201. package/dist/workspace/paths.js +2 -2
  202. package/package.json +33 -33
  203. package/dist/execution/filesystem-artifact-registry.d.ts +0 -57
  204. package/dist/execution/filesystem-artifact-registry.js +0 -92
  205. package/dist/lib/identifiers.d.ts +0 -8
  206. package/dist/lib/identifiers.js +0 -10
  207. package/dist/lib/mime-detect.d.ts +0 -17
  208. package/dist/lib/mime-detect.js +0 -29
  209. package/dist/lib/streamed-download.d.ts +0 -28
  210. package/dist/lib/streamed-download.js +0 -111
  211. package/dist/lib/trace-context.d.ts +0 -11
  212. package/dist/lib/trace-context.js +0 -49
  213. package/dist/providers/llm-capabilities.d.ts +0 -33
  214. package/dist/providers/llm-capabilities.js +0 -58
  215. package/dist/schemas/render-step-prompt.d.ts +0 -32
  216. package/dist/schemas/render-step-prompt.js +0 -76
  217. package/dist/tools/bio/find-approval-precedent.d.ts +0 -32
  218. package/dist/tools/bio/find-approval-precedent.js +0 -72
  219. package/dist/tools/bio/get-article-details.d.ts +0 -11
  220. package/dist/tools/bio/get-article-details.js +0 -20
  221. package/dist/tools/bio/get-article-full-text.d.ts +0 -19
  222. package/dist/tools/bio/get-article-full-text.js +0 -32
  223. package/dist/tools/bio/get-bioactivity.d.ts +0 -11
  224. package/dist/tools/bio/get-bioactivity.js +0 -23
  225. package/dist/tools/bio/get-drug-info.d.ts +0 -9
  226. package/dist/tools/bio/get-drug-info.js +0 -22
  227. package/dist/tools/bio/get-mechanism.d.ts +0 -8
  228. package/dist/tools/bio/get-mechanism.js +0 -18
  229. package/dist/tools/bio/get-pubchem-assays.d.ts +0 -22
  230. package/dist/tools/bio/get-pubchem-assays.js +0 -107
  231. package/dist/tools/bio/get-pubchem-cross-refs.d.ts +0 -15
  232. package/dist/tools/bio/get-pubchem-cross-refs.js +0 -68
  233. package/dist/tools/bio/get-target-safety.d.ts +0 -18
  234. package/dist/tools/bio/get-target-safety.js +0 -26
  235. package/dist/tools/bio/search-compounds.d.ts +0 -22
  236. package/dist/tools/bio/search-compounds.js +0 -160
  237. package/dist/tools/bio/search-ctx-chemical.d.ts +0 -50
  238. package/dist/tools/bio/search-ctx-chemical.js +0 -130
  239. package/dist/tools/bio/search-ctx-exposure.d.ts +0 -55
  240. package/dist/tools/bio/search-ctx-exposure.js +0 -176
  241. package/dist/tools/bio/search-ctx-hazard.d.ts +0 -111
  242. package/dist/tools/bio/search-ctx-hazard.js +0 -178
  243. package/dist/tools/bio/search-opentargets.d.ts +0 -11
  244. package/dist/tools/bio/search-opentargets.js +0 -25
  245. package/dist/tools/bio/search-pubchem-compound.d.ts +0 -26
  246. package/dist/tools/bio/search-pubchem-compound.js +0 -110
  247. package/dist/tools/bio/search-pubmed.d.ts +0 -17
  248. package/dist/tools/bio/search-pubmed.js +0 -31
  249. package/dist/tools/bio/search-targets.d.ts +0 -9
  250. package/dist/tools/bio/search-targets.js +0 -20
  251. package/dist/tools/bio/search-toxcast.d.ts +0 -36
  252. package/dist/tools/bio/search-toxcast.js +0 -141
  253. package/dist/workflows/register-workflows.d.ts +0 -51
  254. package/dist/workflows/register-workflows.js +0 -48
  255. package/dist/workflows/resume-execute-analysis.d.ts +0 -70
  256. package/dist/workflows/resume-execute-analysis.js +0 -80
  257. package/dist/workflows/target-assessment/correction-loop.d.ts +0 -45
  258. package/dist/workflows/target-assessment/correction-loop.js +0 -62
  259. package/dist/workflows/target-assessment/steps/phase0-resolve.d.ts +0 -71
  260. package/dist/workflows/target-assessment/steps/phase0-resolve.js +0 -21
  261. package/dist/workflows/target-assessment/steps/phase1-aggregate.d.ts +0 -1018
  262. package/dist/workflows/target-assessment/steps/phase1-aggregate.js +0 -25
  263. package/dist/workspace/mount-strategy.d.ts +0 -50
  264. package/dist/workspace/mount-strategy.js +0 -67
  265. package/dist/workspace/provenance-collector.d.ts +0 -34
  266. package/dist/workspace/provenance-collector.js +0 -16
  267. package/dist/workspace/workspace-paths.d.ts +0 -26
  268. package/dist/workspace/workspace-paths.js +0 -31
@@ -1,48 +0,0 @@
1
- /**
2
- * Single registration call site for the analysis-side DBOS workflows.
3
- *
4
- * This module is the **one place** that calls `registerExecuteAnalysis` and
5
- * `registerSandboxStep`, binding the parent + child workflow bodies to the
6
- * running DBOS engine. Keeping both registrations in one file holds a single
7
- * invariant: both workflows land under the same `applicationVersion` stamp
8
- * that `launchDbos` writes onto the engine (`harness/runtime/dbos.ts`).
9
- * Blue/green drains gate on `dbos.application_versions`, so registering the
10
- * parent and child together under one stamp guarantees a drain treats them
11
- * as one cohort.
12
- *
13
- * Deps are supplied by the composition root: `registerAnalysisWorkflows`
14
- * takes a fully-formed deps bundle and passes each half straight through to
15
- * the per-workflow register functions. This module constructs nothing —
16
- * it only wires.
17
- */
18
- import { registerExecuteAnalysis } from "./execute-analysis.js";
19
- import { registerSandboxStep } from "./sandbox-step.js";
20
- /**
21
- * Register the parent + child workflows with the running DBOS engine.
22
- *
23
- * Call this BEFORE `launchDbos`: `DBOS.launch()` runs recovery synchronously and
24
- * resolves in-flight workflows by their registered name, so a workflow that is
25
- * not registered at launch cannot be reclaimed. `runtime/assemble.ts` — the
26
- * declared source of truth for wiring order — registers every workflow before
27
- * launch for exactly this reason, and the embedded runtime does the same.
28
- * Idempotency is owned by the SDK — calling twice with the same name is a
29
- * `DBOS.registerWorkflow` invariant violation, not something this module
30
- * guards against.
31
- *
32
- * Scope: this helper takes a fully-formed `AnalysisWorkflowDeps`, so it fits
33
- * only a caller that already holds a registered sandbox-step callable —
34
- * `ExecuteAnalysisDeps.sandboxStepCallable` (inside `deps.executeAnalysis`)
35
- * exists only after `registerSandboxStep` has run. A caller that still needs
36
- * that child callable must instead register the two workflows directly in
37
- * assemble-order — register the child first, then feed its callable into the
38
- * parent's deps — the way `runtime/assemble.ts` does; registering the child
39
- * here as well would make its `registerSandboxStep` a second registration under
40
- * the same name, which the SDK rejects. No in-tree caller holds a
41
- * pre-registered child callable, so this helper is currently uncalled.
42
- */
43
- export function registerAnalysisWorkflows(deps) {
44
- return {
45
- executeAnalysis: registerExecuteAnalysis(deps.executeAnalysis),
46
- sandboxStep: registerSandboxStep(deps.sandboxStep),
47
- };
48
- }
@@ -1,70 +0,0 @@
1
- /**
2
- * Resume helper for the `executeAnalysis` parent workflow.
3
- *
4
- * The actual resume *entry-point* (the HTTP route, the operator CLI hook,
5
- * the analytics-tier replay) is owned by change 9 — that change exposes
6
- * resume to the world. This module owns the **internal contract** every
7
- * resume call site MUST satisfy so the parent body re-opens the running
8
- * charge correctly after a 402 pause.
9
- *
10
- * Contract:
11
- *
12
- * 1. Call `prepareExecuteAnalysisResume(pool, parentWorkflowId)` BEFORE
13
- * `DBOS.resumeWorkflow(parentWorkflowId)`.
14
- * 2. The helper finds the cortex_runs row by `workflow_id`, atomically
15
- * bumps `attempt_count`, and returns the new attempt + the runId.
16
- * Children that are still CANCELLED need an explicit
17
- * `DBOS.resumeWorkflow(childWorkflowId)` from the caller; completed
18
- * children's `getResult` returns from the DBOS cache.
19
- * 3. On resume the parent body reads the bumped attempt_count and uses
20
- * it in `open-running-charge:${attempt}` / `close-running-charge:${attempt}`
21
- * / `revoke-run-auth:${attempt}` so each step name has never been
22
- * cached. A fresh managed-root charge is opened to replace the one that
23
- * closed with `budget_exceeded` on the pause.
24
- * 4. The same attempt is passed through to children via
25
- * `SandboxStepInput.attempt`, where it drives
26
- * `attemptStepNameFormatter` and so the resumed LLM calls miss the
27
- * prior cached 402 and fire fresh (NOTES #3).
28
- * 5. The workflow id and run id MUST NOT change across resume:
29
- * `cortex_runs.workflow_id` is rewritten by nothing in this code
30
- * path. The whole point of the bumped attempt counter is that the
31
- * same workflow id can survive multiple resumes without cache
32
- * collisions.
33
- *
34
- * Failure modes:
35
- *
36
- * - The row does not exist → `MissingRunError`. Caller MUST surface a 404
37
- * to the originating operator; do NOT call `DBOS.resumeWorkflow` on a
38
- * missing run.
39
- * - The row's status is terminal (`completed`/`partial`/`failed`/`canceled`
40
- * without `suspended_insufficient_funds` on the analysis): the helper
41
- * still bumps the counter so a defensive retry is harmless, but the
42
- * caller SHOULD skip the resume — the workflow already ran to
43
- * completion. Change 9's entry point owns this guard.
44
- */
45
- import type { Pool } from "pg";
46
- import type { CortexRunRow } from "../state/schema.js";
47
- export declare class MissingRunError extends Error {
48
- readonly workflowId: string;
49
- constructor(workflowId: string);
50
- }
51
- export interface PrepareResumeResult {
52
- readonly runId: string;
53
- readonly workflowId: string;
54
- readonly attempt: number;
55
- readonly previousStatus: CortexRunRow["status"];
56
- }
57
- /**
58
- * Bump the parent-workflow resume attempt counter and return the new
59
- * value. The caller invokes `DBOS.resumeWorkflow(workflowId)` immediately
60
- * after; the resumed parent body reads the bumped counter and re-opens
61
- * the running charge with a step name that has never been cached.
62
- *
63
- * `workflowId` and `runId` are the same bare UUID — `cortex_runs.run_id`
64
- * IS the DBOS workflowID.
65
- *
66
- * Idempotency: each call bumps once. A double-call before
67
- * `DBOS.resumeWorkflow` is harmless — both step names are misses and the
68
- * close on the just-opened charge will still cleanly land.
69
- */
70
- export declare function prepareExecuteAnalysisResume(pool: Pool, workflowId: string): Promise<PrepareResumeResult>;
@@ -1,80 +0,0 @@
1
- /**
2
- * Resume helper for the `executeAnalysis` parent workflow.
3
- *
4
- * The actual resume *entry-point* (the HTTP route, the operator CLI hook,
5
- * the analytics-tier replay) is owned by change 9 — that change exposes
6
- * resume to the world. This module owns the **internal contract** every
7
- * resume call site MUST satisfy so the parent body re-opens the running
8
- * charge correctly after a 402 pause.
9
- *
10
- * Contract:
11
- *
12
- * 1. Call `prepareExecuteAnalysisResume(pool, parentWorkflowId)` BEFORE
13
- * `DBOS.resumeWorkflow(parentWorkflowId)`.
14
- * 2. The helper finds the cortex_runs row by `workflow_id`, atomically
15
- * bumps `attempt_count`, and returns the new attempt + the runId.
16
- * Children that are still CANCELLED need an explicit
17
- * `DBOS.resumeWorkflow(childWorkflowId)` from the caller; completed
18
- * children's `getResult` returns from the DBOS cache.
19
- * 3. On resume the parent body reads the bumped attempt_count and uses
20
- * it in `open-running-charge:${attempt}` / `close-running-charge:${attempt}`
21
- * / `revoke-run-auth:${attempt}` so each step name has never been
22
- * cached. A fresh managed-root charge is opened to replace the one that
23
- * closed with `budget_exceeded` on the pause.
24
- * 4. The same attempt is passed through to children via
25
- * `SandboxStepInput.attempt`, where it drives
26
- * `attemptStepNameFormatter` and so the resumed LLM calls miss the
27
- * prior cached 402 and fire fresh (NOTES #3).
28
- * 5. The workflow id and run id MUST NOT change across resume:
29
- * `cortex_runs.workflow_id` is rewritten by nothing in this code
30
- * path. The whole point of the bumped attempt counter is that the
31
- * same workflow id can survive multiple resumes without cache
32
- * collisions.
33
- *
34
- * Failure modes:
35
- *
36
- * - The row does not exist → `MissingRunError`. Caller MUST surface a 404
37
- * to the originating operator; do NOT call `DBOS.resumeWorkflow` on a
38
- * missing run.
39
- * - The row's status is terminal (`completed`/`partial`/`failed`/`canceled`
40
- * without `suspended_insufficient_funds` on the analysis): the helper
41
- * still bumps the counter so a defensive retry is harmless, but the
42
- * caller SHOULD skip the resume — the workflow already ran to
43
- * completion. Change 9's entry point owns this guard.
44
- */
45
- import { unwrapOrThrow } from "../lib/result.js";
46
- import { bumpRunAttemptCount, queryRun } from "../state/index.js";
47
- export class MissingRunError extends Error {
48
- workflowId;
49
- constructor(workflowId) {
50
- super(`No cortex_runs row found for run_id=${workflowId}`);
51
- this.workflowId = workflowId;
52
- this.name = "MissingRunError";
53
- }
54
- }
55
- /**
56
- * Bump the parent-workflow resume attempt counter and return the new
57
- * value. The caller invokes `DBOS.resumeWorkflow(workflowId)` immediately
58
- * after; the resumed parent body reads the bumped counter and re-opens
59
- * the running charge with a step name that has never been cached.
60
- *
61
- * `workflowId` and `runId` are the same bare UUID — `cortex_runs.run_id`
62
- * IS the DBOS workflowID.
63
- *
64
- * Idempotency: each call bumps once. A double-call before
65
- * `DBOS.resumeWorkflow` is harmless — both step names are misses and the
66
- * close on the just-opened charge will still cleanly land.
67
- */
68
- export async function prepareExecuteAnalysisResume(pool, workflowId) {
69
- const row = unwrapOrThrow(await queryRun(pool, workflowId));
70
- if (!row) {
71
- throw new MissingRunError(workflowId);
72
- }
73
- const attempt = unwrapOrThrow(await bumpRunAttemptCount(pool, row.runId));
74
- return {
75
- runId: row.runId,
76
- workflowId,
77
- attempt,
78
- previousStatus: row.status,
79
- };
80
- }
@@ -1,45 +0,0 @@
1
- /**
2
- * Correction loop for Phase-3 fan-out branches that returned empty
3
- * without an error.
4
- *
5
- * Contract:
6
- * 1. If `coverage` is `available` (non-empty data), pass through.
7
- * 2. If `coverage` is `queried_no_data` and we have a deterministic
8
- * alt-name retry available, run ONE retry. If it succeeds, return
9
- * the new payload tagged `available`.
10
- * 3. If still empty after the alt-name retry, escalate ONCE to the
11
- * responsible Phase-2 agent (via the supplied `escalate` callback)
12
- * with the failure bundle. If the agent returns a usable payload,
13
- * return it. Otherwise return `coverage: "queried_no_data"`.
14
- *
15
- * The escalation callback is optional — callers without an agent fall
16
- * back to a final coverage tag without escalation.
17
- */
18
- import type { Coverage, SerializedError } from "./coverage.js";
19
- type CoverageEnvelope<T> = {
20
- coverage: "available";
21
- data: T;
22
- } | {
23
- coverage: "queried_no_data";
24
- error?: SerializedError;
25
- } | {
26
- coverage: "not_loaded";
27
- reason?: string;
28
- };
29
- export interface CorrectionInput<T> {
30
- initial: CoverageEnvelope<T>;
31
- altRetry?: () => Promise<CoverageEnvelope<T>>;
32
- escalate?: () => Promise<CoverageEnvelope<T>>;
33
- }
34
- export interface CorrectionTrace {
35
- altRetryAttempted: boolean;
36
- altRetrySucceeded: boolean;
37
- escalationAttempted: boolean;
38
- escalationSucceeded: boolean;
39
- finalCoverage: Coverage;
40
- }
41
- export declare function runCorrectionLoop<T>(input: CorrectionInput<T>): Promise<{
42
- result: CoverageEnvelope<T>;
43
- trace: CorrectionTrace;
44
- }>;
45
- export {};
@@ -1,62 +0,0 @@
1
- /**
2
- * Correction loop for Phase-3 fan-out branches that returned empty
3
- * without an error.
4
- *
5
- * Contract:
6
- * 1. If `coverage` is `available` (non-empty data), pass through.
7
- * 2. If `coverage` is `queried_no_data` and we have a deterministic
8
- * alt-name retry available, run ONE retry. If it succeeds, return
9
- * the new payload tagged `available`.
10
- * 3. If still empty after the alt-name retry, escalate ONCE to the
11
- * responsible Phase-2 agent (via the supplied `escalate` callback)
12
- * with the failure bundle. If the agent returns a usable payload,
13
- * return it. Otherwise return `coverage: "queried_no_data"`.
14
- *
15
- * The escalation callback is optional — callers without an agent fall
16
- * back to a final coverage tag without escalation.
17
- */
18
- export async function runCorrectionLoop(input) {
19
- const trace = {
20
- altRetryAttempted: false,
21
- altRetrySucceeded: false,
22
- escalationAttempted: false,
23
- escalationSucceeded: false,
24
- finalCoverage: input.initial.coverage,
25
- };
26
- if (input.initial.coverage === "available") {
27
- return { result: input.initial, trace };
28
- }
29
- if (input.initial.coverage === "not_loaded") {
30
- return { result: input.initial, trace };
31
- }
32
- if (input.altRetry) {
33
- trace.altRetryAttempted = true;
34
- try {
35
- const retried = await input.altRetry();
36
- if (retried.coverage === "available") {
37
- trace.altRetrySucceeded = true;
38
- trace.finalCoverage = "available";
39
- return { result: retried, trace };
40
- }
41
- }
42
- catch {
43
- // alt retry failed; proceed to escalation
44
- }
45
- }
46
- if (input.escalate) {
47
- trace.escalationAttempted = true;
48
- try {
49
- const esc = await input.escalate();
50
- if (esc.coverage === "available") {
51
- trace.escalationSucceeded = true;
52
- trace.finalCoverage = "available";
53
- return { result: esc, trace };
54
- }
55
- }
56
- catch {
57
- // escalation failed; fall through
58
- }
59
- }
60
- trace.finalCoverage = "queried_no_data";
61
- return { result: input.initial, trace };
62
- }
@@ -1,71 +0,0 @@
1
- /**
2
- * Phase 0 — target resolution.
3
- *
4
- * The single step in the workflow allowed to throw. A hard resolution
5
- * failure aborts the assessment with `error.kind: "target-unresolved"`.
6
- *
7
- * The DBOS workflow body re-implements Phase 0 inline; this module is kept
8
- * for its schemas (input/output) so dependent modules continue to compile.
9
- */
10
- export declare const phase0InputSchema: import("zod").ZodObject<{
11
- assessmentId: import("zod").ZodString;
12
- target: import("zod").ZodString;
13
- goal: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
14
- organizationId: import("zod").ZodString;
15
- requestedBy: import("zod").ZodString;
16
- }, import("zod/v4/core").$strip>;
17
- export declare const phase0OutputSchema: import("zod").ZodObject<{
18
- assessmentId: import("zod").ZodString;
19
- goal: import("zod").ZodNullable<import("zod").ZodString>;
20
- canonicalId: import("zod").ZodString;
21
- canonicalOntology: import("zod").ZodEnum<{
22
- ensembl: "ensembl";
23
- hgnc: "hgnc";
24
- }>;
25
- geneSymbol: import("zod").ZodString;
26
- approvedName: import("zod").ZodString;
27
- ids: import("zod").ZodObject<{
28
- hgnc: import("zod").ZodNullable<import("zod").ZodString>;
29
- ensembl: import("zod").ZodNullable<import("zod").ZodString>;
30
- uniprot: import("zod").ZodNullable<import("zod").ZodString>;
31
- chembl: import("zod").ZodNullable<import("zod").ZodString>;
32
- entrez: import("zod").ZodNullable<import("zod").ZodString>;
33
- }, import("zod/v4/core").$strip>;
34
- synonyms: import("zod").ZodArray<import("zod").ZodString>;
35
- proteinSynonyms: import("zod").ZodArray<import("zod").ZodString>;
36
- proteinFamily: import("zod").ZodNullable<import("zod").ZodString>;
37
- resolutionCoverage: import("zod").ZodObject<{
38
- hgnc: import("zod").ZodBoolean;
39
- uniprot: import("zod").ZodBoolean;
40
- ensembl: import("zod").ZodBoolean;
41
- chembl: import("zod").ZodBoolean;
42
- }, import("zod/v4/core").$strip>;
43
- }, import("zod/v4/core").$strip>;
44
- export declare function phase0Execute(inputData: {
45
- assessmentId: string;
46
- goal?: string | null;
47
- target: string;
48
- }): Promise<{
49
- canonicalId: string;
50
- canonicalOntology: "hgnc" | "ensembl";
51
- geneSymbol: string;
52
- approvedName: string;
53
- ids: {
54
- hgnc: string | null;
55
- ensembl: string | null;
56
- uniprot: string | null;
57
- chembl: string | null;
58
- entrez: string | null;
59
- };
60
- synonyms: string[];
61
- proteinSynonyms: string[];
62
- proteinFamily: string | null;
63
- resolutionCoverage: {
64
- hgnc: boolean;
65
- uniprot: boolean;
66
- ensembl: boolean;
67
- chembl: boolean;
68
- };
69
- assessmentId: string;
70
- goal: string | null;
71
- }>;
@@ -1,21 +0,0 @@
1
- /**
2
- * Phase 0 — target resolution.
3
- *
4
- * The single step in the workflow allowed to throw. A hard resolution
5
- * failure aborts the assessment with `error.kind: "target-unresolved"`.
6
- *
7
- * The DBOS workflow body re-implements Phase 0 inline; this module is kept
8
- * for its schemas (input/output) so dependent modules continue to compile.
9
- */
10
- import { TargetAssessmentInputSchema, ResolvedTargetSchema } from "../schemas.js";
11
- import { resolveTarget } from "../../../tools/lib/identifier-resolver.js";
12
- export const phase0InputSchema = TargetAssessmentInputSchema;
13
- export const phase0OutputSchema = ResolvedTargetSchema;
14
- export async function phase0Execute(inputData) {
15
- const resolved = await resolveTarget(inputData.target);
16
- return {
17
- assessmentId: inputData.assessmentId,
18
- goal: inputData.goal ?? null,
19
- ...resolved,
20
- };
21
- }