yaml-flow 5.4.0 → 6.0.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 (200) hide show
  1. package/board-live-cards-cli.js +2 -2
  2. package/board-livecards-server-runtime.js +488 -551
  3. package/browser/asset-integrity.json +10 -0
  4. package/browser/board-livecards-runtime-client.js +0 -6
  5. package/browser/board-livegraph-engine.js +2 -1676
  6. package/browser/board-livegraph-engine.js.map +1 -1
  7. package/browser/live-cards.js +347 -26
  8. package/browser/live-cards.schema.json +418 -132
  9. package/card-store.js +37 -0
  10. package/dist/batch/index.cjs +1 -108
  11. package/dist/batch/index.cjs.map +1 -1
  12. package/dist/batch/index.js +1 -106
  13. package/dist/batch/index.js.map +1 -1
  14. package/dist/board-live-cards-lib-Bg6EvCo5.d.cts +136 -0
  15. package/dist/board-live-cards-lib-jM2uYG1v.d.ts +136 -0
  16. package/dist/board-live-cards-public-CltXYgaY.d.cts +314 -0
  17. package/dist/board-live-cards-public-f-E-FAyp.d.ts +314 -0
  18. package/dist/board-livegraph-runtime/index.cjs +2 -1671
  19. package/dist/board-livegraph-runtime/index.cjs.map +1 -1
  20. package/dist/board-livegraph-runtime/index.d.cts +1 -2
  21. package/dist/board-livegraph-runtime/index.d.ts +1 -2
  22. package/dist/board-livegraph-runtime/index.js +2 -1662
  23. package/dist/board-livegraph-runtime/index.js.map +1 -1
  24. package/dist/board-livegraph-runtime/jsonata-sync.cjs +7587 -0
  25. package/dist/card-compute/index.cjs +9 -7159
  26. package/dist/card-compute/index.cjs.map +1 -1
  27. package/dist/card-compute/index.d.cts +22 -0
  28. package/dist/card-compute/index.d.ts +22 -0
  29. package/dist/card-compute/index.js +9 -7145
  30. package/dist/card-compute/index.js.map +1 -1
  31. package/dist/card-compute/jsonata-sync.cjs +7587 -0
  32. package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs +2 -0
  33. package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs.map +1 -0
  34. package/dist/cli/browser-api/board-live-cards-browser-adapter.d.cts +24 -0
  35. package/dist/cli/browser-api/board-live-cards-browser-adapter.d.ts +24 -0
  36. package/dist/cli/browser-api/board-live-cards-browser-adapter.js +2 -0
  37. package/dist/cli/browser-api/board-live-cards-browser-adapter.js.map +1 -0
  38. package/dist/cli/browser-api/card-store-browser-api.cjs +2 -0
  39. package/dist/cli/browser-api/card-store-browser-api.cjs.map +1 -0
  40. package/dist/cli/browser-api/card-store-browser-api.d.cts +26 -0
  41. package/dist/cli/browser-api/card-store-browser-api.d.ts +26 -0
  42. package/dist/cli/browser-api/card-store-browser-api.js +2 -0
  43. package/dist/cli/browser-api/card-store-browser-api.js.map +1 -0
  44. package/dist/cli/browser-api/jsonata-sync.cjs +7587 -0
  45. package/dist/cli/node/artifacts-store-cli.cjs +11 -0
  46. package/dist/cli/node/artifacts-store-cli.cjs.map +1 -0
  47. package/dist/cli/node/artifacts-store-cli.d.cts +8 -0
  48. package/dist/cli/node/artifacts-store-cli.d.ts +8 -0
  49. package/dist/cli/node/artifacts-store-cli.js +11 -0
  50. package/dist/cli/node/artifacts-store-cli.js.map +1 -0
  51. package/dist/cli/node/board-live-cards-cli.cjs +15 -0
  52. package/dist/cli/node/board-live-cards-cli.cjs.map +1 -0
  53. package/dist/cli/node/board-live-cards-cli.d.cts +20 -0
  54. package/dist/cli/node/board-live-cards-cli.d.ts +20 -0
  55. package/dist/cli/node/board-live-cards-cli.js +15 -0
  56. package/dist/cli/node/board-live-cards-cli.js.map +1 -0
  57. package/dist/cli/node/card-store-cli.cjs +8 -0
  58. package/dist/cli/node/card-store-cli.cjs.map +1 -0
  59. package/dist/cli/node/card-store-cli.d.cts +15 -0
  60. package/dist/cli/node/card-store-cli.d.ts +15 -0
  61. package/dist/cli/node/card-store-cli.js +8 -0
  62. package/dist/cli/node/card-store-cli.js.map +1 -0
  63. package/dist/cli/node/fs-board-adapter.cjs +14 -0
  64. package/dist/cli/node/fs-board-adapter.cjs.map +1 -0
  65. package/dist/cli/node/fs-board-adapter.d.cts +204 -0
  66. package/dist/cli/node/fs-board-adapter.d.ts +204 -0
  67. package/dist/cli/node/fs-board-adapter.js +14 -0
  68. package/dist/cli/node/fs-board-adapter.js.map +1 -0
  69. package/dist/cli/node/jsonata-sync.cjs +7587 -0
  70. package/dist/cli/node/source-cli-task-executor.cjs +11 -0
  71. package/dist/cli/node/source-cli-task-executor.cjs.map +1 -0
  72. package/dist/cli/node/source-cli-task-executor.d.cts +1 -0
  73. package/dist/cli/node/source-cli-task-executor.d.ts +1 -0
  74. package/dist/cli/node/source-cli-task-executor.js +11 -0
  75. package/dist/cli/node/source-cli-task-executor.js.map +1 -0
  76. package/dist/config/index.cjs +1 -79
  77. package/dist/config/index.cjs.map +1 -1
  78. package/dist/config/index.js +1 -76
  79. package/dist/config/index.js.map +1 -1
  80. package/dist/continuous-event-graph/index.cjs +2 -2129
  81. package/dist/continuous-event-graph/index.cjs.map +1 -1
  82. package/dist/continuous-event-graph/index.d.cts +81 -5
  83. package/dist/continuous-event-graph/index.d.ts +81 -5
  84. package/dist/continuous-event-graph/index.js +2 -2088
  85. package/dist/continuous-event-graph/index.js.map +1 -1
  86. package/dist/continuous-event-graph/jsonata-sync.cjs +7587 -0
  87. package/dist/event-graph/index.cjs +22 -8292
  88. package/dist/event-graph/index.cjs.map +1 -1
  89. package/dist/event-graph/index.js +22 -8237
  90. package/dist/event-graph/index.js.map +1 -1
  91. package/dist/execution-refs.cjs +2 -0
  92. package/dist/execution-refs.cjs.map +1 -0
  93. package/dist/execution-refs.d.cts +222 -0
  94. package/dist/execution-refs.d.ts +222 -0
  95. package/dist/execution-refs.js +2 -0
  96. package/dist/execution-refs.js.map +1 -0
  97. package/dist/index.cjs +29 -13221
  98. package/dist/index.cjs.map +1 -1
  99. package/dist/index.d.cts +2 -4
  100. package/dist/index.d.ts +2 -4
  101. package/dist/index.js +29 -13112
  102. package/dist/index.js.map +1 -1
  103. package/dist/inference/index.cjs +5 -617
  104. package/dist/inference/index.cjs.map +1 -1
  105. package/dist/inference/index.js +5 -610
  106. package/dist/inference/index.js.map +1 -1
  107. package/dist/jsonata-sync.cjs +7587 -0
  108. package/dist/{live-cards-bridge-x5XREkXm.d.cts → live-cards-bridge-BXbVTsna.d.cts} +27 -4
  109. package/dist/{live-cards-bridge-EQjytzI_.d.ts → live-cards-bridge-Ds28XR15.d.ts} +27 -4
  110. package/dist/pycli/quickjs-board-runtime.global.js +9 -0
  111. package/dist/pycli/quickjs-board-runtime.global.js.map +1 -0
  112. package/dist/pycli/quickjs-step-machine-runtime.global.js +5 -0
  113. package/dist/pycli/quickjs-step-machine-runtime.global.js.map +1 -0
  114. package/dist/step-machine/index.cjs +11 -7129
  115. package/dist/step-machine/index.cjs.map +1 -1
  116. package/dist/step-machine/index.js +11 -7113
  117. package/dist/step-machine/index.js.map +1 -1
  118. package/dist/storage-refs.cjs +10 -0
  119. package/dist/storage-refs.cjs.map +1 -0
  120. package/dist/storage-refs.d.cts +92 -0
  121. package/dist/storage-refs.d.ts +92 -0
  122. package/dist/storage-refs.js +10 -0
  123. package/dist/storage-refs.js.map +1 -0
  124. package/dist/stores/file.cjs +1 -114
  125. package/dist/stores/file.cjs.map +1 -1
  126. package/dist/stores/file.js +1 -112
  127. package/dist/stores/file.js.map +1 -1
  128. package/dist/stores/index.cjs +1 -231
  129. package/dist/stores/index.cjs.map +1 -1
  130. package/dist/stores/index.js +1 -227
  131. package/dist/stores/index.js.map +1 -1
  132. package/dist/stores/localStorage.cjs +1 -76
  133. package/dist/stores/localStorage.cjs.map +1 -1
  134. package/dist/stores/localStorage.js +1 -74
  135. package/dist/stores/localStorage.js.map +1 -1
  136. package/dist/stores/memory.cjs +1 -47
  137. package/dist/stores/memory.cjs.map +1 -1
  138. package/dist/stores/memory.js +1 -45
  139. package/dist/stores/memory.js.map +1 -1
  140. package/examples/browser/boards/portfolio-tracker/portfolio-t4.js +292 -0
  141. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-fetch-prices.js +218 -0
  142. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-fetch-prices.py +201 -0
  143. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-inference-adapter.js +25 -16
  144. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-public.js +553 -0
  145. package/examples/browser/boards/portfolio-tracker/portfolio-tracker.py +365 -0
  146. package/examples/cli/step-machine-cli/portfolio-tracker/--base-ref/.runtime-out +1 -0
  147. package/examples/cli/step-machine-cli/portfolio-tracker/--base-ref/board-graph.json +32 -0
  148. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +53 -1
  149. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/add-cards-cli.js +15 -6
  150. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/init-board-cli.js +6 -1
  151. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/poll-status-cli.js +57 -0
  152. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/retrigger-cli.js +1 -1
  153. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/status-cli.js +1 -1
  154. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/update-holdings-cli.js +7 -2
  155. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/wait-completed-cli.js +6 -2
  156. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/_board_pycli.py +97 -0
  157. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/add-cards.py +50 -0
  158. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/init-board.py +44 -0
  159. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/poll-status.py +70 -0
  160. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/reset-board-dir.py +36 -0
  161. package/examples/cli/step-machine-cli/portfolio-tracker/inline-python-demo.flow.yaml +26 -0
  162. package/examples/cli/step-machine-cli/portfolio-tracker/inline-python-handlers.py +39 -0
  163. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker-pycli.flow.yaml +80 -0
  164. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +25 -172
  165. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.input.json +40 -34
  166. package/examples/cli/step-machine-cli/portfolio-tracker/run-inline-python-demo-pycli.py +46 -0
  167. package/examples/cli/step-machine-cli/portfolio-tracker/run-portfolio-tracker-pycli.py +77 -0
  168. package/examples/cli/step-machine-cli/portfolio-tracker/run-portfolio-tracker.bat +1 -2
  169. package/examples/example-board/agent-instructions.md +11 -5
  170. package/examples/example-board/demo-chat-handler.js +14 -4
  171. package/examples/example-board/demo-server-config.json +1 -0
  172. package/examples/example-board/demo-server.js +19 -34
  173. package/examples/example-board/demo-shell-browser.html +5 -4
  174. package/examples/example-board/demo-shell-with-server.html +10 -6
  175. package/examples/example-board/demo-task-executor.js +81 -35
  176. package/examples/index.html +0 -14
  177. package/examples/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +0 -1
  178. package/examples/step-machine-cli/portfolio-tracker/run-portfolio-tracker.bat +1 -2
  179. package/package.json +39 -3
  180. package/schema/live-cards.schema.json +418 -132
  181. package/dist/cli/board-live-cards-cli.cjs +0 -10644
  182. package/dist/cli/board-live-cards-cli.cjs.map +0 -1
  183. package/dist/cli/board-live-cards-cli.d.cts +0 -179
  184. package/dist/cli/board-live-cards-cli.d.ts +0 -179
  185. package/dist/cli/board-live-cards-cli.js +0 -10592
  186. package/dist/cli/board-live-cards-cli.js.map +0 -1
  187. package/dist/journal-9HEgs7dU.d.ts +0 -28
  188. package/dist/journal-B-JCfQnh.d.cts +0 -28
  189. package/dist/schedule-Cszq9LYY.d.ts +0 -21
  190. package/dist/schedule-qWNL0RQh.d.cts +0 -21
  191. package/examples/browser/boards/portfolio-tracker/cards/holdings-table.json +0 -22
  192. package/examples/browser/boards/portfolio-tracker/cards/portfolio-form.json +0 -16
  193. package/examples/browser/boards/portfolio-tracker/cards/portfolio-risk-assessment.json +0 -28
  194. package/examples/browser/boards/portfolio-tracker/cards/portfolio-value.json +0 -15
  195. package/examples/browser/boards/portfolio-tracker/cards/price-fetch.json +0 -15
  196. package/examples/browser/boards/portfolio-tracker/cards/rebalancing-strategy.json +0 -28
  197. package/examples/browser/boards/portfolio-tracker/fetch-prices.js +0 -43
  198. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-task-executor.cjs +0 -96
  199. package/examples/browser/boards/portfolio-tracker/portfolio-tracker.bat +0 -7
  200. package/examples/browser/boards/portfolio-tracker/portfolio-tracker.js +0 -351
@@ -1,612 +1,7 @@
1
- import { execFile } from 'child_process';
1
+ import {execFile}from'child_process';function g(t){return t?Array.isArray(t.provides)?t.provides:[]:[]}function l(t){return t?Array.isArray(t.requires)?t.requires:[]:[]}function y(t){return t.tasks??{}}function C(t,e,s){let n=t.tasks[e]??m(),o={};if(s){let i=s.tasks[e],c=l(i);for(let r of c)for(let[u,f]of Object.entries(s.tasks))if(g(f).includes(r)){let p=t.tasks[u];p?.lastDataHash&&(o[r]=p.lastDataHash);break}}let a={...n,status:"running",startedAt:new Date().toISOString(),lastUpdated:new Date().toISOString(),progress:0,error:void 0,startConsumedHashes:o};return {...t,tasks:{...t.tasks,[e]:a},lastUpdated:new Date().toISOString()}}function O(t,e,s,n,o,a){let i=t.tasks[s]??m(),c=e.tasks[s];if(!c)throw new Error(`Task "${s}" not found in graph`);let r;n&&c.on&&c.on[n]?r=c.on[n]:r=g(c);let u=i.startConsumedHashes?{...i.startConsumedHashes}:{...i.lastConsumedHashes};if(!i.startConsumedHashes){let S=c.requires??[];for(let h of S)for(let[k,d]of Object.entries(e.tasks))if(g(d).includes(h)){let T=t.tasks[k];T?.lastDataHash&&(u[h]=T.lastDataHash);break}}let f={...i,status:"completed",completedAt:new Date().toISOString(),lastUpdated:new Date().toISOString(),executionCount:i.executionCount+1,lastEpoch:i.executionCount+1,lastDataHash:o,data:a,lastConsumedHashes:u,error:void 0},p=[...new Set([...t.availableOutputs,...r])];return {...t,tasks:{...t.tasks,[s]:f},availableOutputs:p,lastUpdated:new Date().toISOString()}}function I(t,e,s,n){let o=t.tasks[s]??m(),a=e.tasks[s];if(a?.retry){let r=o.retryCount+1;if(r<=a.retry.max_attempts){let u={...o,status:"not-started",retryCount:r,lastUpdated:new Date().toISOString(),error:n};return {...t,tasks:{...t.tasks,[s]:u},lastUpdated:new Date().toISOString()}}}let i={...o,status:"failed",failedAt:new Date().toISOString(),lastUpdated:new Date().toISOString(),error:n,executionCount:o.executionCount+1},c=t.availableOutputs;if(a?.on_failure&&a.on_failure.length>0&&(c=[...new Set([...t.availableOutputs,...a.on_failure])]),a?.circuit_breaker&&i.executionCount>=a.circuit_breaker.max_executions){let r=a.circuit_breaker.on_break;c=[...new Set([...c,...r])];}return {...t,tasks:{...t.tasks,[s]:i},availableOutputs:c,lastUpdated:new Date().toISOString()}}function A(t,e,s,n){let o=t.tasks[e]??m(),a={...o,progress:typeof n=="number"?n:o.progress,messages:[...o.messages??[],...s?[{message:s,timestamp:new Date().toISOString(),status:o.status}]:[]],lastUpdated:new Date().toISOString()};return {...t,tasks:{...t.tasks,[e]:a},lastUpdated:new Date().toISOString()}}function w(t,e){let s=t.tasks[e];if(!s)return t;let n={...s,status:"not-started",startedAt:void 0,completedAt:void 0,failedAt:void 0,error:void 0,data:void 0,progress:null,lastUpdated:new Date().toISOString()};return {...t,tasks:{...t.tasks,[e]:n},lastUpdated:new Date().toISOString()}}function m(){return {status:"not-started",executionCount:0,retryCount:0,lastEpoch:0,messages:[],progress:null}}function x(t,e){let{config:s,state:n}=t;if("executionId"in e&&e.executionId&&e.executionId!==n.executionId)return t;switch(e.type){case "task-started":return {config:s,state:C(n,e.taskName,s)};case "task-completed":return {config:s,state:O(n,s,e.taskName,e.result,e.dataHash,e.data)};case "task-failed":return {config:s,state:I(n,s,e.taskName,e.error)};case "task-progress":return {config:s,state:A(n,e.taskName,e.message,e.progress)};case "task-restart":return {config:s,state:w(n,e.taskName)};case "inject-tokens":return {config:s,state:{...n,availableOutputs:[...new Set([...n.availableOutputs,...e.tokens])],lastUpdated:new Date().toISOString()}};case "agent-action":return {config:s,state:M(n,e.action)};case "task-upsert":return D(t,e.taskName,e.taskConfig);case "task-removal":return N(t,e.taskName);case "node-requires-add":return v(t,e.nodeName,e.tokens);case "node-requires-remove":return _(t,e.nodeName,e.tokens);case "node-provides-add":return U(t,e.nodeName,e.tokens);case "node-provides-remove":return j(t,e.nodeName,e.tokens);default:return t}}function D(t,e,s){let n=!!t.config.tasks[e];return {config:{...t.config,tasks:{...t.config.tasks,[e]:s}},state:{...t.state,tasks:{...t.state.tasks,[e]:n?t.state.tasks[e]:P()},lastUpdated:new Date().toISOString()}}}function N(t,e){if(!t.config.tasks[e])return t;let{[e]:s,...n}=t.config.tasks,{[e]:o,...a}=t.state.tasks;return {config:{...t.config,tasks:n},state:{...t.state,tasks:a,lastUpdated:new Date().toISOString()}}}function v(t,e,s){let n=t.config.tasks[e];if(!n)return t;let o=l(n),a=s.filter(i=>!o.includes(i));return a.length===0?t:{config:{...t.config,tasks:{...t.config.tasks,[e]:{...n,requires:[...o,...a]}}},state:t.state}}function _(t,e,s){let n=t.config.tasks[e];if(!n)return t;let o=l(n),a=o.filter(i=>!s.includes(i));return a.length===o.length?t:{config:{...t.config,tasks:{...t.config.tasks,[e]:{...n,requires:a}}},state:t.state}}function U(t,e,s){let n=t.config.tasks[e];if(!n)return t;let o=g(n),a=s.filter(i=>!o.includes(i));return a.length===0?t:{config:{...t.config,tasks:{...t.config.tasks,[e]:{...n,provides:[...o,...a]}}},state:t.state}}function j(t,e,s){let n=t.config.tasks[e];if(!n)return t;let o=g(n),a=o.filter(i=>!s.includes(i));return a.length===o.length?t:{config:{...t.config,tasks:{...t.config.tasks,[e]:{...n,provides:a}}},state:t.state}}function P(){return {status:"not-started",executionCount:0,retryCount:0,lastEpoch:0,messages:[],progress:null}}function M(t,e){let s=new Date().toISOString();switch(e){case "stop":return {...t,status:"stopped",lastUpdated:s};case "pause":return {...t,status:"paused",lastUpdated:s};case "resume":return {...t,status:"running",lastUpdated:s};default:return t}}var E=.5,H=`You are a workflow completion analyzer. Given a graph of tasks with their current states, evidence, and inference hints, determine which tasks appear to be completed based on the available evidence.
2
2
 
3
- // src/event-graph/graph-helpers.ts
4
- function getProvides(task) {
5
- if (!task) return [];
6
- if (Array.isArray(task.provides)) return task.provides;
7
- return [];
8
- }
9
- function getRequires(task) {
10
- if (!task) return [];
11
- if (Array.isArray(task.requires)) return task.requires;
12
- return [];
13
- }
14
- function getAllTasks(graph) {
15
- return graph.tasks ?? {};
16
- }
17
-
18
- // src/event-graph/task-transitions.ts
19
- function applyTaskStart(state, taskName, graph) {
20
- const existingTask = state.tasks[taskName] ?? createDefaultGraphEngineStore();
21
- const startConsumedHashes = {};
22
- if (graph) {
23
- const taskConfig = graph.tasks[taskName];
24
- const requires = getRequires(taskConfig);
25
- for (const token of requires) {
26
- for (const [otherName, otherConfig] of Object.entries(graph.tasks)) {
27
- if (getProvides(otherConfig).includes(token)) {
28
- const otherState = state.tasks[otherName];
29
- if (otherState?.lastDataHash) startConsumedHashes[token] = otherState.lastDataHash;
30
- break;
31
- }
32
- }
33
- }
34
- }
35
- const updatedTask = {
36
- ...existingTask,
37
- status: "running",
38
- startedAt: (/* @__PURE__ */ new Date()).toISOString(),
39
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
40
- progress: 0,
41
- error: void 0,
42
- startConsumedHashes
43
- };
44
- return {
45
- ...state,
46
- tasks: { ...state.tasks, [taskName]: updatedTask },
47
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
48
- };
49
- }
50
- function applyTaskCompletion(state, graph, taskName, result, dataHash, data) {
51
- const existingTask = state.tasks[taskName] ?? createDefaultGraphEngineStore();
52
- const taskConfig = graph.tasks[taskName];
53
- if (!taskConfig) {
54
- throw new Error(`Task "${taskName}" not found in graph`);
55
- }
56
- let outputTokens;
57
- if (result && taskConfig.on && taskConfig.on[result]) {
58
- outputTokens = taskConfig.on[result];
59
- } else {
60
- outputTokens = getProvides(taskConfig);
61
- }
62
- const lastConsumedHashes = existingTask.startConsumedHashes ? { ...existingTask.startConsumedHashes } : { ...existingTask.lastConsumedHashes };
63
- if (!existingTask.startConsumedHashes) {
64
- const requires = taskConfig.requires ?? [];
65
- for (const token of requires) {
66
- for (const [otherName, otherConfig] of Object.entries(graph.tasks)) {
67
- if (getProvides(otherConfig).includes(token)) {
68
- const otherState = state.tasks[otherName];
69
- if (otherState?.lastDataHash) {
70
- lastConsumedHashes[token] = otherState.lastDataHash;
71
- }
72
- break;
73
- }
74
- }
75
- }
76
- }
77
- const updatedTask = {
78
- ...existingTask,
79
- status: "completed",
80
- completedAt: (/* @__PURE__ */ new Date()).toISOString(),
81
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
82
- executionCount: existingTask.executionCount + 1,
83
- lastEpoch: existingTask.executionCount + 1,
84
- lastDataHash: dataHash,
85
- data,
86
- lastConsumedHashes,
87
- error: void 0
88
- };
89
- const newOutputs = [.../* @__PURE__ */ new Set([...state.availableOutputs, ...outputTokens])];
90
- return {
91
- ...state,
92
- tasks: { ...state.tasks, [taskName]: updatedTask },
93
- availableOutputs: newOutputs,
94
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
95
- };
96
- }
97
- function applyTaskFailure(state, graph, taskName, error) {
98
- const existingTask = state.tasks[taskName] ?? createDefaultGraphEngineStore();
99
- const taskConfig = graph.tasks[taskName];
100
- if (taskConfig?.retry) {
101
- const retryCount = existingTask.retryCount + 1;
102
- if (retryCount <= taskConfig.retry.max_attempts) {
103
- const updatedTask2 = {
104
- ...existingTask,
105
- status: "not-started",
106
- retryCount,
107
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
108
- error
109
- };
110
- return {
111
- ...state,
112
- tasks: { ...state.tasks, [taskName]: updatedTask2 },
113
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
114
- };
115
- }
116
- }
117
- const updatedTask = {
118
- ...existingTask,
119
- status: "failed",
120
- failedAt: (/* @__PURE__ */ new Date()).toISOString(),
121
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
122
- error,
123
- executionCount: existingTask.executionCount + 1
124
- };
125
- let newOutputs = state.availableOutputs;
126
- if (taskConfig?.on_failure && taskConfig.on_failure.length > 0) {
127
- newOutputs = [.../* @__PURE__ */ new Set([...state.availableOutputs, ...taskConfig.on_failure])];
128
- }
129
- if (taskConfig?.circuit_breaker && updatedTask.executionCount >= taskConfig.circuit_breaker.max_executions) {
130
- const breakTokens = taskConfig.circuit_breaker.on_break;
131
- newOutputs = [.../* @__PURE__ */ new Set([...newOutputs, ...breakTokens])];
132
- }
133
- return {
134
- ...state,
135
- tasks: { ...state.tasks, [taskName]: updatedTask },
136
- availableOutputs: newOutputs,
137
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
138
- };
139
- }
140
- function applyTaskProgress(state, taskName, message, progress) {
141
- const existingTask = state.tasks[taskName] ?? createDefaultGraphEngineStore();
142
- const updatedTask = {
143
- ...existingTask,
144
- progress: typeof progress === "number" ? progress : existingTask.progress,
145
- messages: [
146
- ...existingTask.messages ?? [],
147
- ...message ? [{ message, timestamp: (/* @__PURE__ */ new Date()).toISOString(), status: existingTask.status }] : []
148
- ],
149
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
150
- };
151
- return {
152
- ...state,
153
- tasks: { ...state.tasks, [taskName]: updatedTask },
154
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
155
- };
156
- }
157
- function applyTaskRestart(state, taskName) {
158
- const existingTask = state.tasks[taskName];
159
- if (!existingTask) return state;
160
- const updatedTask = {
161
- ...existingTask,
162
- status: "not-started",
163
- startedAt: void 0,
164
- completedAt: void 0,
165
- failedAt: void 0,
166
- error: void 0,
167
- data: void 0,
168
- progress: null,
169
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
170
- };
171
- return {
172
- ...state,
173
- tasks: { ...state.tasks, [taskName]: updatedTask },
174
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
175
- };
176
- }
177
- function createDefaultGraphEngineStore() {
178
- return {
179
- status: "not-started",
180
- executionCount: 0,
181
- retryCount: 0,
182
- lastEpoch: 0,
183
- messages: [],
184
- progress: null
185
- };
186
- }
187
-
188
- // src/continuous-event-graph/core.ts
189
- function applyEvent(live, event) {
190
- const { config, state } = live;
191
- if ("executionId" in event && event.executionId && event.executionId !== state.executionId) {
192
- return live;
193
- }
194
- switch (event.type) {
195
- // --- Execution state transitions ---
196
- case "task-started":
197
- return { config, state: applyTaskStart(state, event.taskName, config) };
198
- case "task-completed":
199
- return { config, state: applyTaskCompletion(state, config, event.taskName, event.result, event.dataHash, event.data) };
200
- case "task-failed":
201
- return { config, state: applyTaskFailure(state, config, event.taskName, event.error) };
202
- case "task-progress":
203
- return { config, state: applyTaskProgress(state, event.taskName, event.message, event.progress) };
204
- case "task-restart":
205
- return { config, state: applyTaskRestart(state, event.taskName) };
206
- case "inject-tokens":
207
- return {
208
- config,
209
- state: {
210
- ...state,
211
- availableOutputs: [.../* @__PURE__ */ new Set([...state.availableOutputs, ...event.tokens])],
212
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
213
- }
214
- };
215
- case "agent-action":
216
- return { config, state: applyAgentAction(state, event.action) };
217
- // --- Structural mutations ---
218
- case "task-upsert":
219
- return addNode(live, event.taskName, event.taskConfig);
220
- case "task-removal":
221
- return removeNode(live, event.taskName);
222
- case "node-requires-add":
223
- return addRequires(live, event.nodeName, event.tokens);
224
- case "node-requires-remove":
225
- return removeRequires(live, event.nodeName, event.tokens);
226
- case "node-provides-add":
227
- return addProvides(live, event.nodeName, event.tokens);
228
- case "node-provides-remove":
229
- return removeProvides(live, event.nodeName, event.tokens);
230
- default:
231
- return live;
232
- }
233
- }
234
- function addNode(live, name, taskConfig) {
235
- const exists = !!live.config.tasks[name];
236
- return {
237
- config: {
238
- ...live.config,
239
- tasks: { ...live.config.tasks, [name]: taskConfig }
240
- },
241
- state: {
242
- ...live.state,
243
- tasks: {
244
- ...live.state.tasks,
245
- [name]: exists ? live.state.tasks[name] : createDefaultGraphEngineStore2()
246
- },
247
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
248
- }
249
- };
250
- }
251
- function removeNode(live, name) {
252
- if (!live.config.tasks[name]) return live;
253
- const { [name]: _removedConfig, ...remainingTasks } = live.config.tasks;
254
- const { [name]: _removedState, ...remainingStates } = live.state.tasks;
255
- return {
256
- config: {
257
- ...live.config,
258
- tasks: remainingTasks
259
- },
260
- state: {
261
- ...live.state,
262
- tasks: remainingStates,
263
- lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
264
- }
265
- };
266
- }
267
- function addRequires(live, nodeName, tokens) {
268
- const task = live.config.tasks[nodeName];
269
- if (!task) return live;
270
- const current = getRequires(task);
271
- const toAdd = tokens.filter((t) => !current.includes(t));
272
- if (toAdd.length === 0) return live;
273
- return {
274
- config: {
275
- ...live.config,
276
- tasks: {
277
- ...live.config.tasks,
278
- [nodeName]: { ...task, requires: [...current, ...toAdd] }
279
- }
280
- },
281
- state: live.state
282
- };
283
- }
284
- function removeRequires(live, nodeName, tokens) {
285
- const task = live.config.tasks[nodeName];
286
- if (!task) return live;
287
- const current = getRequires(task);
288
- const remaining = current.filter((t) => !tokens.includes(t));
289
- if (remaining.length === current.length) return live;
290
- return {
291
- config: {
292
- ...live.config,
293
- tasks: {
294
- ...live.config.tasks,
295
- [nodeName]: { ...task, requires: remaining }
296
- }
297
- },
298
- state: live.state
299
- };
300
- }
301
- function addProvides(live, nodeName, tokens) {
302
- const task = live.config.tasks[nodeName];
303
- if (!task) return live;
304
- const current = getProvides(task);
305
- const toAdd = tokens.filter((t) => !current.includes(t));
306
- if (toAdd.length === 0) return live;
307
- return {
308
- config: {
309
- ...live.config,
310
- tasks: {
311
- ...live.config.tasks,
312
- [nodeName]: { ...task, provides: [...current, ...toAdd] }
313
- }
314
- },
315
- state: live.state
316
- };
317
- }
318
- function removeProvides(live, nodeName, tokens) {
319
- const task = live.config.tasks[nodeName];
320
- if (!task) return live;
321
- const current = getProvides(task);
322
- const remaining = current.filter((t) => !tokens.includes(t));
323
- if (remaining.length === current.length) return live;
324
- return {
325
- config: {
326
- ...live.config,
327
- tasks: {
328
- ...live.config.tasks,
329
- [nodeName]: { ...task, provides: remaining }
330
- }
331
- },
332
- state: live.state
333
- };
334
- }
335
- function createDefaultGraphEngineStore2() {
336
- return {
337
- status: "not-started",
338
- executionCount: 0,
339
- retryCount: 0,
340
- lastEpoch: 0,
341
- messages: [],
342
- progress: null
343
- };
344
- }
345
- function applyAgentAction(state, action) {
346
- const now = (/* @__PURE__ */ new Date()).toISOString();
347
- switch (action) {
348
- case "stop":
349
- return { ...state, status: "stopped", lastUpdated: now };
350
- case "pause":
351
- return { ...state, status: "paused", lastUpdated: now };
352
- case "resume":
353
- return { ...state, status: "running", lastUpdated: now };
354
- default:
355
- return state;
356
- }
357
- }
358
-
359
- // src/inference/core.ts
360
- var DEFAULT_THRESHOLD = 0.5;
361
- var DEFAULT_SYSTEM_PROMPT = `You are a workflow completion analyzer. Given a graph of tasks with their current states, evidence, and inference hints, determine which tasks appear to be completed based on the available evidence.
362
-
363
- For each task you analyze, provide a JSON response. Be conservative \u2014 only mark tasks as completed when the evidence strongly supports it.`;
364
- function buildInferencePrompt(live, options = {}) {
365
- const { scope, context, systemPrompt } = options;
366
- const graphTasks = getAllTasks(live.config);
367
- const { state } = live;
368
- const candidates = getAnalyzableCandidates(live, scope);
369
- if (candidates.length === 0) {
370
- return "";
371
- }
372
- const lines = [];
373
- lines.push(systemPrompt || DEFAULT_SYSTEM_PROMPT);
374
- lines.push("");
375
- lines.push("## Graph State");
376
- lines.push("");
377
- lines.push(`Available tokens: ${state.availableOutputs.length > 0 ? state.availableOutputs.join(", ") : "(none)"}`);
378
- lines.push("");
379
- const completedTasks = Object.entries(state.tasks).filter(([_, ts]) => ts.status === "completed").map(([name]) => name);
380
- if (completedTasks.length > 0) {
381
- lines.push(`Completed tasks: ${completedTasks.join(", ")}`);
382
- lines.push("");
383
- }
384
- lines.push("## Tasks to Analyze");
385
- lines.push("");
386
- for (const taskName of candidates) {
387
- const taskConfig = graphTasks[taskName];
388
- const taskState = state.tasks[taskName];
389
- lines.push(`### ${taskName}`);
390
- if (taskConfig.description) {
391
- lines.push(`Description: ${taskConfig.description}`);
392
- }
393
- const requires = getRequires(taskConfig);
394
- const provides = getProvides(taskConfig);
395
- if (requires.length > 0) lines.push(`Requires: ${requires.join(", ")}`);
396
- if (provides.length > 0) lines.push(`Provides: ${provides.join(", ")}`);
397
- lines.push(`Current status: ${taskState?.status || "not-started"}`);
398
- const hints = taskConfig.inference;
399
- if (hints) {
400
- if (hints.criteria) lines.push(`Completion criteria: ${hints.criteria}`);
401
- if (hints.keywords?.length) lines.push(`Keywords: ${hints.keywords.join(", ")}`);
402
- if (hints.suggestedChecks?.length) lines.push(`Suggested checks: ${hints.suggestedChecks.join("; ")}`);
403
- }
404
- lines.push("");
405
- }
406
- if (context) {
407
- lines.push("## Additional Context / Evidence");
408
- lines.push("");
409
- lines.push(context);
410
- lines.push("");
411
- }
412
- lines.push("## Response Format");
413
- lines.push("");
414
- lines.push("Respond with a JSON array of objects, one per task you have evidence for:");
415
- lines.push("```json");
416
- lines.push("[");
417
- lines.push(" {");
418
- lines.push(' "taskName": "task-name",');
419
- lines.push(' "confidence": 0.0 to 1.0,');
420
- lines.push(' "reasoning": "explanation of why you believe this task is complete or not"');
421
- lines.push(" }");
422
- lines.push("]");
423
- lines.push("```");
424
- lines.push("");
425
- lines.push("Rules:");
426
- lines.push('- Only include tasks from the "Tasks to Analyze" section');
427
- lines.push("- confidence 0.0 = no evidence of completion, 1.0 = certain it is complete");
428
- lines.push("- If you have no evidence for a task, omit it from the array");
429
- lines.push("- Be conservative \u2014 require clear evidence before high confidence");
430
- lines.push("- Respond ONLY with the JSON array, no additional text");
431
- return lines.join("\n");
432
- }
433
- async function inferCompletions(live, adapter, options = {}) {
434
- options.threshold ?? DEFAULT_THRESHOLD;
435
- const analyzedNodes = getAnalyzableCandidates(live, options.scope);
436
- if (analyzedNodes.length === 0) {
437
- return { suggestions: [], promptUsed: "", rawResponse: "", analyzedNodes: [] };
438
- }
439
- const prompt = buildInferencePrompt(live, options);
440
- const rawResponse = await adapter.analyze(prompt);
441
- const suggestions = parseInferenceResponse(rawResponse, analyzedNodes);
442
- return {
443
- suggestions,
444
- promptUsed: prompt,
445
- rawResponse,
446
- analyzedNodes
447
- };
448
- }
449
- function applyInferences(live, result, threshold = DEFAULT_THRESHOLD) {
450
- let current = live;
451
- for (const suggestion of result.suggestions) {
452
- if (suggestion.confidence < threshold) continue;
453
- const taskState = current.state.tasks[suggestion.taskName];
454
- if (!taskState) continue;
455
- if (taskState.status === "completed" || taskState.status === "running") continue;
456
- const now = (/* @__PURE__ */ new Date()).toISOString();
457
- current = applyEvent(current, {
458
- type: "task-started",
459
- taskName: suggestion.taskName,
460
- timestamp: now
461
- });
462
- current = applyEvent(current, {
463
- type: "task-completed",
464
- taskName: suggestion.taskName,
465
- timestamp: now,
466
- result: "llm-inferred"
467
- });
468
- }
469
- return current;
470
- }
471
- async function inferAndApply(live, adapter, options = {}) {
472
- const threshold = options.threshold ?? DEFAULT_THRESHOLD;
473
- const inference = await inferCompletions(live, adapter, options);
474
- const updated = applyInferences(live, inference, threshold);
475
- const applied = inference.suggestions.filter((s) => s.confidence >= threshold);
476
- const skipped = inference.suggestions.filter((s) => s.confidence < threshold);
477
- return {
478
- live: updated,
479
- inference,
480
- applied,
481
- skipped
482
- };
483
- }
484
- function getAnalyzableCandidates(live, scope) {
485
- const graphTasks = getAllTasks(live.config);
486
- const { state } = live;
487
- const candidates = [];
488
- for (const [name, config] of Object.entries(graphTasks)) {
489
- const taskState = state.tasks[name];
490
- if (taskState?.status === "completed" || taskState?.status === "running") continue;
491
- if (scope) {
492
- if (scope.includes(name)) candidates.push(name);
493
- } else {
494
- if (config.inference?.autoDetectable) candidates.push(name);
495
- }
496
- }
497
- return candidates;
498
- }
499
- function parseInferenceResponse(rawResponse, validNodes, _threshold) {
500
- const validSet = new Set(validNodes);
501
- try {
502
- const jsonStr = extractJson(rawResponse);
503
- if (!jsonStr) return [];
504
- const parsed = JSON.parse(jsonStr);
505
- if (!Array.isArray(parsed)) return [];
506
- const suggestions = [];
507
- for (const item of parsed) {
508
- if (!item || typeof item !== "object") continue;
509
- if (typeof item.taskName !== "string") continue;
510
- if (typeof item.confidence !== "number") continue;
511
- if (!validSet.has(item.taskName)) continue;
512
- const confidence = Math.max(0, Math.min(1, item.confidence));
513
- suggestions.push({
514
- taskName: item.taskName,
515
- confidence,
516
- reasoning: typeof item.reasoning === "string" ? item.reasoning : "",
517
- detectionMethod: "llm-inferred"
518
- });
519
- }
520
- return suggestions;
521
- } catch {
522
- return [];
523
- }
524
- }
525
- function extractJson(text) {
526
- if (!text || typeof text !== "string") return null;
527
- const trimmed = text.trim();
528
- const fenceMatch = trimmed.match(/```(?:json)?\s*\n?([\s\S]*?)\n?\s*```/);
529
- if (fenceMatch) return fenceMatch[1].trim();
530
- const firstBracket = trimmed.indexOf("[");
531
- const lastBracket = trimmed.lastIndexOf("]");
532
- if (firstBracket !== -1 && lastBracket > firstBracket) {
533
- return trimmed.slice(firstBracket, lastBracket + 1);
534
- }
535
- if (trimmed.startsWith("[")) return trimmed;
536
- return null;
537
- }
538
- function createCliAdapter(opts) {
539
- const timeout = opts.timeout ?? 6e4;
540
- return {
541
- analyze: (prompt) => {
542
- return new Promise((resolve, reject) => {
543
- const args = opts.args(prompt);
544
- const child = execFile(
545
- opts.command,
546
- opts.stdin ? opts.args("") : args,
547
- {
548
- timeout,
549
- cwd: opts.cwd,
550
- env: opts.env ? { ...process.env, ...opts.env } : void 0,
551
- maxBuffer: 10 * 1024 * 1024
552
- // 10MB
553
- },
554
- (error, stdout, stderr) => {
555
- if (error) {
556
- reject(new Error(
557
- `CLI adapter failed: ${opts.command} exited with ${error.code ?? "error"}` + (stderr ? `
558
- stderr: ${stderr.slice(0, 500)}` : "") + `
559
- ${error.message}`
560
- ));
561
- } else {
562
- resolve(stdout);
563
- }
564
- }
565
- );
566
- if (opts.stdin && child.stdin) {
567
- child.stdin.write(prompt);
568
- child.stdin.end();
569
- }
570
- });
571
- }
572
- };
573
- }
574
- function createHttpAdapter(opts) {
575
- const timeout = opts.timeout ?? 6e4;
576
- return {
577
- analyze: async (prompt) => {
578
- const body = opts.buildBody ? opts.buildBody(prompt) : { prompt };
579
- const controller = new AbortController();
580
- const timer = setTimeout(() => controller.abort(), timeout);
581
- try {
582
- const response = await fetch(opts.url, {
583
- method: "POST",
584
- headers: {
585
- "Content-Type": "application/json",
586
- ...opts.headers ?? {}
587
- },
588
- body: JSON.stringify(body),
589
- signal: controller.signal
590
- });
591
- if (!response.ok) {
592
- const text = await response.text().catch(() => "");
593
- throw new Error(`HTTP ${response.status}: ${text.slice(0, 500)}`);
594
- }
595
- const json = await response.json();
596
- if (opts.extractResponse) {
597
- return opts.extractResponse(json);
598
- }
599
- if (typeof json.response === "string") return json.response;
600
- if (typeof json.text === "string") return json.text;
601
- if (typeof json.content === "string") return json.content;
602
- return JSON.stringify(json);
603
- } finally {
604
- clearTimeout(timer);
605
- }
606
- }
607
- };
608
- }
609
-
610
- export { applyInferences, buildInferencePrompt, createCliAdapter, createHttpAdapter, inferAndApply, inferCompletions };
611
- //# sourceMappingURL=index.js.map
3
+ For each task you analyze, provide a JSON response. Be conservative \u2014 only mark tasks as completed when the evidence strongly supports it.`;function G(t,e={}){let{scope:s,context:n,systemPrompt:o}=e,a=y(t.config),{state:i}=t,c=L(t,s);if(c.length===0)return "";let r=[];r.push(o||H),r.push(""),r.push("## Graph State"),r.push(""),r.push(`Available tokens: ${i.availableOutputs.length>0?i.availableOutputs.join(", "):"(none)"}`),r.push("");let u=Object.entries(i.tasks).filter(([f,p])=>p.status==="completed").map(([f])=>f);u.length>0&&(r.push(`Completed tasks: ${u.join(", ")}`),r.push("")),r.push("## Tasks to Analyze"),r.push("");for(let f of c){let p=a[f],S=i.tasks[f];r.push(`### ${f}`),p.description&&r.push(`Description: ${p.description}`);let h=l(p),k=g(p);h.length>0&&r.push(`Requires: ${h.join(", ")}`),k.length>0&&r.push(`Provides: ${k.join(", ")}`),r.push(`Current status: ${S?.status||"not-started"}`);let d=p.inference;d&&(d.criteria&&r.push(`Completion criteria: ${d.criteria}`),d.keywords?.length&&r.push(`Keywords: ${d.keywords.join(", ")}`),d.suggestedChecks?.length&&r.push(`Suggested checks: ${d.suggestedChecks.join("; ")}`)),r.push("");}return n&&(r.push("## Additional Context / Evidence"),r.push(""),r.push(n),r.push("")),r.push("## Response Format"),r.push(""),r.push("Respond with a JSON array of objects, one per task you have evidence for:"),r.push("```json"),r.push("["),r.push(" {"),r.push(' "taskName": "task-name",'),r.push(' "confidence": 0.0 to 1.0,'),r.push(' "reasoning": "explanation of why you believe this task is complete or not"'),r.push(" }"),r.push("]"),r.push("```"),r.push(""),r.push("Rules:"),r.push('- Only include tasks from the "Tasks to Analyze" section'),r.push("- confidence 0.0 = no evidence of completion, 1.0 = certain it is complete"),r.push("- If you have no evidence for a task, omit it from the array"),r.push("- Be conservative \u2014 require clear evidence before high confidence"),r.push("- Respond ONLY with the JSON array, no additional text"),r.join(`
4
+ `)}async function b(t,e,s={}){s.threshold??E;let o=L(t,s.scope);if(o.length===0)return {suggestions:[],promptUsed:"",rawResponse:"",analyzedNodes:[]};let a=G(t,s),i=await e.analyze(a);return {suggestions:F(i,o),promptUsed:a,rawResponse:i,analyzedNodes:o}}function R(t,e,s=E){let n=t;for(let o of e.suggestions){if(o.confidence<s)continue;let a=n.state.tasks[o.taskName];if(!a||a.status==="completed"||a.status==="running")continue;let i=new Date().toISOString();n=x(n,{type:"task-started",taskName:o.taskName,timestamp:i}),n=x(n,{type:"task-completed",taskName:o.taskName,timestamp:i,result:"llm-inferred"});}return n}async function q(t,e,s={}){let n=s.threshold??E,o=await b(t,e,s),a=R(t,o,n),i=o.suggestions.filter(r=>r.confidence>=n),c=o.suggestions.filter(r=>r.confidence<n);return {live:a,inference:o,applied:i,skipped:c}}function L(t,e){let s=y(t.config),{state:n}=t,o=[];for(let[a,i]of Object.entries(s)){let c=n.tasks[a];c?.status==="completed"||c?.status==="running"||(e?e.includes(a)&&o.push(a):i.inference?.autoDetectable&&o.push(a));}return o}function F(t,e,s){let n=new Set(e);try{let o=$(t);if(!o)return [];let a=JSON.parse(o);if(!Array.isArray(a))return [];let i=[];for(let c of a){if(!c||typeof c!="object"||typeof c.taskName!="string"||typeof c.confidence!="number"||!n.has(c.taskName))continue;let r=Math.max(0,Math.min(1,c.confidence));i.push({taskName:c.taskName,confidence:r,reasoning:typeof c.reasoning=="string"?c.reasoning:"",detectionMethod:"llm-inferred"});}return i}catch{return []}}function $(t){if(!t||typeof t!="string")return null;let e=t.trim(),s=e.match(/```(?:json)?\s*\n?([\s\S]*?)\n?\s*```/);if(s)return s[1].trim();let n=e.indexOf("["),o=e.lastIndexOf("]");return n!==-1&&o>n?e.slice(n,o+1):e.startsWith("[")?e:null}function z(t){let e=t.timeout??6e4;return {analyze:s=>new Promise((n,o)=>{let a=t.args(s),i=execFile(t.command,t.stdin?t.args(""):a,{timeout:e,cwd:t.cwd,env:t.env?{...process.env,...t.env}:void 0,maxBuffer:10*1024*1024},(c,r,u)=>{c?o(new Error(`CLI adapter failed: ${t.command} exited with ${c.code??"error"}`+(u?`
5
+ stderr: ${u.slice(0,500)}`:"")+`
6
+ ${c.message}`)):n(r);});t.stdin&&i.stdin&&(i.stdin.write(s),i.stdin.end());})}}function K(t){let e=t.timeout??6e4;return {analyze:async s=>{let n=t.buildBody?t.buildBody(s):{prompt:s},o=new AbortController,a=setTimeout(()=>o.abort(),e);try{let i=await fetch(t.url,{method:"POST",headers:{"Content-Type":"application/json",...t.headers??{}},body:JSON.stringify(n),signal:o.signal});if(!i.ok){let r=await i.text().catch(()=>"");throw new Error(`HTTP ${i.status}: ${r.slice(0,500)}`)}let c=await i.json();return t.extractResponse?t.extractResponse(c):typeof c.response=="string"?c.response:typeof c.text=="string"?c.text:typeof c.content=="string"?c.content:JSON.stringify(c)}finally{clearTimeout(a);}}}}export{R as applyInferences,G as buildInferencePrompt,z as createCliAdapter,K as createHttpAdapter,q as inferAndApply,b as inferCompletions};//# sourceMappingURL=index.js.map
612
7
  //# sourceMappingURL=index.js.map