@dudko.dev/agent-web-ui 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +316 -5
  3. package/dist/canvas.cjs +266 -0
  4. package/dist/canvas.cjs.map +1 -0
  5. package/dist/canvas.d.cts +105 -0
  6. package/dist/canvas.d.ts +105 -0
  7. package/dist/canvas.js +200 -0
  8. package/dist/canvas.js.map +1 -0
  9. package/dist/chunk-7O64ZI6Z.js +125 -0
  10. package/dist/chunk-7O64ZI6Z.js.map +1 -0
  11. package/dist/chunk-EL2YCROY.js +127 -0
  12. package/dist/chunk-EL2YCROY.js.map +1 -0
  13. package/dist/chunk-GB7RZJMG.js +98 -0
  14. package/dist/chunk-GB7RZJMG.js.map +1 -0
  15. package/dist/chunk-KZQB35LS.js +22 -0
  16. package/dist/chunk-KZQB35LS.js.map +1 -0
  17. package/dist/chunk-SVYHDLAZ.js +348 -0
  18. package/dist/chunk-SVYHDLAZ.js.map +1 -0
  19. package/dist/chunk-VCR7LU7J.js +348 -0
  20. package/dist/chunk-VCR7LU7J.js.map +1 -0
  21. package/dist/chunk-WFM6B7CL.js +406 -0
  22. package/dist/chunk-WFM6B7CL.js.map +1 -0
  23. package/dist/chunk-WZ7K7JIP.js +348 -0
  24. package/dist/chunk-WZ7K7JIP.js.map +1 -0
  25. package/dist/chunk-ZBHESK6V.js +1440 -0
  26. package/dist/chunk-ZBHESK6V.js.map +1 -0
  27. package/dist/controller.cjs +1891 -0
  28. package/dist/controller.cjs.map +1 -0
  29. package/dist/controller.d.cts +253 -0
  30. package/dist/controller.d.ts +253 -0
  31. package/dist/controller.js +482 -0
  32. package/dist/controller.js.map +1 -0
  33. package/dist/en-Dg2MtzcJ.d.cts +348 -0
  34. package/dist/en-Dg2MtzcJ.d.ts +348 -0
  35. package/dist/index.cjs +4276 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +997 -0
  38. package/dist/index.d.ts +997 -0
  39. package/dist/index.js +2494 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/labels-B5xpIGf_.d.cts +25 -0
  42. package/dist/labels-B5xpIGf_.d.ts +25 -0
  43. package/dist/labels-CmiTBLWD.d.cts +1176 -0
  44. package/dist/labels-DH1ESUtm.d.ts +1176 -0
  45. package/dist/locales/be.cjs +806 -0
  46. package/dist/locales/be.cjs.map +1 -0
  47. package/dist/locales/be.d.cts +16 -0
  48. package/dist/locales/be.d.ts +16 -0
  49. package/dist/locales/be.js +380 -0
  50. package/dist/locales/be.js.map +1 -0
  51. package/dist/locales/bg.cjs +759 -0
  52. package/dist/locales/bg.cjs.map +1 -0
  53. package/dist/locales/bg.d.cts +16 -0
  54. package/dist/locales/bg.d.ts +16 -0
  55. package/dist/locales/bg.js +333 -0
  56. package/dist/locales/bg.js.map +1 -0
  57. package/dist/locales/ca.cjs +785 -0
  58. package/dist/locales/ca.cjs.map +1 -0
  59. package/dist/locales/ca.d.cts +16 -0
  60. package/dist/locales/ca.d.ts +16 -0
  61. package/dist/locales/ca.js +359 -0
  62. package/dist/locales/ca.js.map +1 -0
  63. package/dist/locales/cs.cjs +806 -0
  64. package/dist/locales/cs.cjs.map +1 -0
  65. package/dist/locales/cs.d.cts +16 -0
  66. package/dist/locales/cs.d.ts +16 -0
  67. package/dist/locales/cs.js +380 -0
  68. package/dist/locales/cs.js.map +1 -0
  69. package/dist/locales/da.cjs +759 -0
  70. package/dist/locales/da.cjs.map +1 -0
  71. package/dist/locales/da.d.cts +16 -0
  72. package/dist/locales/da.d.ts +16 -0
  73. package/dist/locales/da.js +333 -0
  74. package/dist/locales/da.js.map +1 -0
  75. package/dist/locales/de.cjs +768 -0
  76. package/dist/locales/de.cjs.map +1 -0
  77. package/dist/locales/de.d.cts +16 -0
  78. package/dist/locales/de.d.ts +16 -0
  79. package/dist/locales/de.js +342 -0
  80. package/dist/locales/de.js.map +1 -0
  81. package/dist/locales/el.cjs +768 -0
  82. package/dist/locales/el.cjs.map +1 -0
  83. package/dist/locales/el.d.cts +16 -0
  84. package/dist/locales/el.d.ts +16 -0
  85. package/dist/locales/el.js +342 -0
  86. package/dist/locales/el.js.map +1 -0
  87. package/dist/locales/en.cjs +765 -0
  88. package/dist/locales/en.cjs.map +1 -0
  89. package/dist/locales/en.d.cts +12 -0
  90. package/dist/locales/en.d.ts +12 -0
  91. package/dist/locales/en.js +339 -0
  92. package/dist/locales/en.js.map +1 -0
  93. package/dist/locales/es-419.cjs +793 -0
  94. package/dist/locales/es-419.cjs.map +1 -0
  95. package/dist/locales/es-419.d.cts +18 -0
  96. package/dist/locales/es-419.d.ts +18 -0
  97. package/dist/locales/es-419.js +26 -0
  98. package/dist/locales/es-419.js.map +1 -0
  99. package/dist/locales/es.cjs +781 -0
  100. package/dist/locales/es.cjs.map +1 -0
  101. package/dist/locales/es.d.cts +16 -0
  102. package/dist/locales/es.d.ts +16 -0
  103. package/dist/locales/es.js +14 -0
  104. package/dist/locales/es.js.map +1 -0
  105. package/dist/locales/fi.cjs +765 -0
  106. package/dist/locales/fi.cjs.map +1 -0
  107. package/dist/locales/fi.d.cts +16 -0
  108. package/dist/locales/fi.d.ts +16 -0
  109. package/dist/locales/fi.js +339 -0
  110. package/dist/locales/fi.js.map +1 -0
  111. package/dist/locales/fr-CA.cjs +789 -0
  112. package/dist/locales/fr-CA.cjs.map +1 -0
  113. package/dist/locales/fr-CA.d.cts +19 -0
  114. package/dist/locales/fr-CA.d.ts +19 -0
  115. package/dist/locales/fr-CA.js +22 -0
  116. package/dist/locales/fr-CA.js.map +1 -0
  117. package/dist/locales/fr.cjs +781 -0
  118. package/dist/locales/fr.cjs.map +1 -0
  119. package/dist/locales/fr.d.cts +16 -0
  120. package/dist/locales/fr.d.ts +16 -0
  121. package/dist/locales/fr.js +14 -0
  122. package/dist/locales/fr.js.map +1 -0
  123. package/dist/locales/gn.cjs +762 -0
  124. package/dist/locales/gn.cjs.map +1 -0
  125. package/dist/locales/gn.d.cts +18 -0
  126. package/dist/locales/gn.d.ts +18 -0
  127. package/dist/locales/gn.js +336 -0
  128. package/dist/locales/gn.js.map +1 -0
  129. package/dist/locales/hr.cjs +781 -0
  130. package/dist/locales/hr.cjs.map +1 -0
  131. package/dist/locales/hr.d.cts +16 -0
  132. package/dist/locales/hr.d.ts +16 -0
  133. package/dist/locales/hr.js +355 -0
  134. package/dist/locales/hr.js.map +1 -0
  135. package/dist/locales/ht.cjs +762 -0
  136. package/dist/locales/ht.cjs.map +1 -0
  137. package/dist/locales/ht.d.cts +18 -0
  138. package/dist/locales/ht.d.ts +18 -0
  139. package/dist/locales/ht.js +336 -0
  140. package/dist/locales/ht.js.map +1 -0
  141. package/dist/locales/hu.cjs +765 -0
  142. package/dist/locales/hu.cjs.map +1 -0
  143. package/dist/locales/hu.d.cts +16 -0
  144. package/dist/locales/hu.d.ts +16 -0
  145. package/dist/locales/hu.js +339 -0
  146. package/dist/locales/hu.js.map +1 -0
  147. package/dist/locales/index.cjs +543 -0
  148. package/dist/locales/index.cjs.map +1 -0
  149. package/dist/locales/index.d.cts +40 -0
  150. package/dist/locales/index.d.ts +40 -0
  151. package/dist/locales/index.js +105 -0
  152. package/dist/locales/index.js.map +1 -0
  153. package/dist/locales/it.cjs +789 -0
  154. package/dist/locales/it.cjs.map +1 -0
  155. package/dist/locales/it.d.cts +16 -0
  156. package/dist/locales/it.d.ts +16 -0
  157. package/dist/locales/it.js +363 -0
  158. package/dist/locales/it.js.map +1 -0
  159. package/dist/locales/nb.cjs +759 -0
  160. package/dist/locales/nb.cjs.map +1 -0
  161. package/dist/locales/nb.d.cts +16 -0
  162. package/dist/locales/nb.d.ts +16 -0
  163. package/dist/locales/nb.js +333 -0
  164. package/dist/locales/nb.js.map +1 -0
  165. package/dist/locales/nl.cjs +765 -0
  166. package/dist/locales/nl.cjs.map +1 -0
  167. package/dist/locales/nl.d.cts +16 -0
  168. package/dist/locales/nl.d.ts +16 -0
  169. package/dist/locales/nl.js +339 -0
  170. package/dist/locales/nl.js.map +1 -0
  171. package/dist/locales/pl.cjs +806 -0
  172. package/dist/locales/pl.cjs.map +1 -0
  173. package/dist/locales/pl.d.cts +16 -0
  174. package/dist/locales/pl.d.ts +16 -0
  175. package/dist/locales/pl.js +380 -0
  176. package/dist/locales/pl.js.map +1 -0
  177. package/dist/locales/pt-BR.cjs +785 -0
  178. package/dist/locales/pt-BR.cjs.map +1 -0
  179. package/dist/locales/pt-BR.d.cts +16 -0
  180. package/dist/locales/pt-BR.d.ts +16 -0
  181. package/dist/locales/pt-BR.js +359 -0
  182. package/dist/locales/pt-BR.js.map +1 -0
  183. package/dist/locales/pt.cjs +789 -0
  184. package/dist/locales/pt.cjs.map +1 -0
  185. package/dist/locales/pt.d.cts +16 -0
  186. package/dist/locales/pt.d.ts +16 -0
  187. package/dist/locales/pt.js +363 -0
  188. package/dist/locales/pt.js.map +1 -0
  189. package/dist/locales/qu.cjs +768 -0
  190. package/dist/locales/qu.cjs.map +1 -0
  191. package/dist/locales/qu.d.cts +18 -0
  192. package/dist/locales/qu.d.ts +18 -0
  193. package/dist/locales/qu.js +342 -0
  194. package/dist/locales/qu.js.map +1 -0
  195. package/dist/locales/ro.cjs +781 -0
  196. package/dist/locales/ro.cjs.map +1 -0
  197. package/dist/locales/ro.d.cts +16 -0
  198. package/dist/locales/ro.d.ts +16 -0
  199. package/dist/locales/ro.js +355 -0
  200. package/dist/locales/ro.js.map +1 -0
  201. package/dist/locales/ru.cjs +801 -0
  202. package/dist/locales/ru.cjs.map +1 -0
  203. package/dist/locales/ru.d.cts +16 -0
  204. package/dist/locales/ru.d.ts +16 -0
  205. package/dist/locales/ru.js +375 -0
  206. package/dist/locales/ru.js.map +1 -0
  207. package/dist/locales/sk.cjs +806 -0
  208. package/dist/locales/sk.cjs.map +1 -0
  209. package/dist/locales/sk.d.cts +16 -0
  210. package/dist/locales/sk.d.ts +16 -0
  211. package/dist/locales/sk.js +380 -0
  212. package/dist/locales/sk.js.map +1 -0
  213. package/dist/locales/sq.cjs +765 -0
  214. package/dist/locales/sq.cjs.map +1 -0
  215. package/dist/locales/sq.d.cts +16 -0
  216. package/dist/locales/sq.d.ts +16 -0
  217. package/dist/locales/sq.js +339 -0
  218. package/dist/locales/sq.js.map +1 -0
  219. package/dist/locales/sr-Latn.cjs +853 -0
  220. package/dist/locales/sr-Latn.cjs.map +1 -0
  221. package/dist/locales/sr-Latn.d.cts +19 -0
  222. package/dist/locales/sr-Latn.d.ts +19 -0
  223. package/dist/locales/sr-Latn.js +86 -0
  224. package/dist/locales/sr-Latn.js.map +1 -0
  225. package/dist/locales/sr.cjs +781 -0
  226. package/dist/locales/sr.cjs.map +1 -0
  227. package/dist/locales/sr.d.cts +16 -0
  228. package/dist/locales/sr.d.ts +16 -0
  229. package/dist/locales/sr.js +14 -0
  230. package/dist/locales/sr.js.map +1 -0
  231. package/dist/locales/sv.cjs +765 -0
  232. package/dist/locales/sv.cjs.map +1 -0
  233. package/dist/locales/sv.d.cts +16 -0
  234. package/dist/locales/sv.d.ts +16 -0
  235. package/dist/locales/sv.js +339 -0
  236. package/dist/locales/sv.js.map +1 -0
  237. package/dist/locales/tr.cjs +762 -0
  238. package/dist/locales/tr.cjs.map +1 -0
  239. package/dist/locales/tr.d.cts +16 -0
  240. package/dist/locales/tr.d.ts +16 -0
  241. package/dist/locales/tr.js +336 -0
  242. package/dist/locales/tr.js.map +1 -0
  243. package/dist/locales/uk.cjs +806 -0
  244. package/dist/locales/uk.cjs.map +1 -0
  245. package/dist/locales/uk.d.cts +16 -0
  246. package/dist/locales/uk.d.ts +16 -0
  247. package/dist/locales/uk.js +380 -0
  248. package/dist/locales/uk.js.map +1 -0
  249. package/dist/markdown.cjs +620 -0
  250. package/dist/markdown.cjs.map +1 -0
  251. package/dist/markdown.d.cts +153 -0
  252. package/dist/markdown.d.ts +153 -0
  253. package/dist/markdown.js +573 -0
  254. package/dist/markdown.js.map +1 -0
  255. package/dist/mcp-app-policy-DXKQ2jjM.d.cts +73 -0
  256. package/dist/mcp-app-policy-DXKQ2jjM.d.ts +73 -0
  257. package/dist/mcp-app-sandbox.cjs +323 -0
  258. package/dist/mcp-app-sandbox.cjs.map +1 -0
  259. package/dist/mcp-app-sandbox.d.cts +70 -0
  260. package/dist/mcp-app-sandbox.d.ts +70 -0
  261. package/dist/mcp-app-sandbox.js +209 -0
  262. package/dist/mcp-app-sandbox.js.map +1 -0
  263. package/dist/mcp-app.cjs +980 -0
  264. package/dist/mcp-app.cjs.map +1 -0
  265. package/dist/mcp-app.d.cts +491 -0
  266. package/dist/mcp-app.d.ts +491 -0
  267. package/dist/mcp-app.js +816 -0
  268. package/dist/mcp-app.js.map +1 -0
  269. package/dist/pipeline.cjs +845 -0
  270. package/dist/pipeline.cjs.map +1 -0
  271. package/dist/pipeline.css +1407 -0
  272. package/dist/pipeline.d.cts +348 -0
  273. package/dist/pipeline.d.ts +348 -0
  274. package/dist/pipeline.js +778 -0
  275. package/dist/pipeline.js.map +1 -0
  276. package/dist/questions-Dw--IEjT.d.cts +100 -0
  277. package/dist/questions-Dw--IEjT.d.ts +100 -0
  278. package/dist/styles.css +4109 -0
  279. package/dist/types-CQquuZpl.d.cts +19 -0
  280. package/dist/types-CXZfZVP5.d.ts +19 -0
  281. package/dist/types-DnBCok3z.d.cts +994 -0
  282. package/dist/types-DnBCok3z.d.ts +994 -0
  283. package/package.json +165 -8
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/pipeline/state.ts","../src/pipeline/edit.ts","../src/pipeline/codegen.ts","../src/pipeline/labels.ts"],"sourcesContent":["import type { AgentEvent, IUsage, PipelineResult, PipelineStop } from '@dudko.dev/agent-web'\n\n// The pipeline's event → UI mapping: a pure reducer, like `agentStateReducer` for one agent. No\n// React, no clock, no randomness - the same events always give the same state, so it is tested\n// against recorded event sequences and a host can build its own UI on it.\n\nexport type PipelineRunStatus = 'idle' | 'running' | 'done' | 'failed' | 'stopped'\n\n/**\n * `waiting`: an edge fired towards the node and it has not started yet (it waits for its wave,\n * or for the other branch of a fan-in). `skipped`: a cap refused the visit.\n */\nexport type PipelineNodeStatus = 'idle' | 'waiting' | 'running' | 'done' | 'failed' | 'skipped'\n\n/** What the node's own agent is doing right now, in one line's worth. */\nexport interface PipelineNodeActivity {\n phase?: 'plan' | 'execute' | 'replan' | 'synthesize'\n /** The plan step in progress, with its place in the plan (1-based, as the core counts). */\n step?: string\n stepIndex?: number\n stepTotal?: number\n /** The tool being called, while it runs. */\n tool?: string\n /** Tool calls made in this visit so far. */\n toolCalls: number\n}\n\nexport interface PipelineOutputView {\n visit: number\n text: string\n route?: string\n}\n\nexport interface PipelineNodeView {\n status: PipelineNodeStatus\n /** Visits started. */\n visits: number\n /** The nodes whose outputs the current (or last) visit received. */\n from: string[]\n /** One entry per finished visit, in order. */\n outputs: PipelineOutputView[]\n activity?: PipelineNodeActivity\n error?: string\n /** Why the last activation was refused. */\n skipped?: 'maxRuns' | 'maxNodeVisits'\n /** Tokens of all its finished visits. */\n usage?: IUsage\n}\n\nexport interface PipelineEdgeView {\n from: string\n to: string\n /** The last decision. */\n fired: boolean\n /** The visit of the source node that decided it. */\n visit: number\n /** How many times it fired in this run. */\n count: number\n /** It fired and what it carries has not been consumed yet: the target waits or runs. */\n live: boolean\n}\n\n/** One node visit, in the order visits started: the run as a timeline. */\nexport interface PipelineVisitView {\n nodeId: string\n visit: number\n from: string[]\n status: 'running' | 'done' | 'failed' | 'stopped'\n text?: string\n route?: string\n error?: string\n usage?: IUsage\n}\n\nexport interface PipelineUiState {\n status: PipelineRunStatus\n /** The request of the current (or last) run. */\n input?: string\n /** The definition's name, as the run reported it. */\n name?: string\n /** By node id. A node the run has not touched is absent: read it with `pipelineNodeView`. */\n nodes: Record<string, PipelineNodeView>\n /** By edge id: the last decision on each edge that was decided. */\n edges: Record<string, PipelineEdgeView>\n /** The edges the node that finished last fired. */\n lastFired: string[]\n visits: PipelineVisitView[]\n /** The final text (set when the run ends). */\n text: string\n usage: IUsage\n /** Node visits started. */\n runs: number\n stoppedBy?: PipelineStop\n error?: string\n /** The node whose failure ended the run. */\n failedNode?: string\n}\n\nexport type PipelineAction =\n | { type: 'run.start'; input: string }\n | { type: 'event'; event: AgentEvent }\n /** `run` resolved. */\n | { type: 'run.result'; result: PipelineResult }\n /** `run` rejected, or could not start. */\n | { type: 'run.error'; error: string; nodeId?: string }\n | { type: 'reset' }\n\nconst ZERO: IUsage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 }\n\nconst IDLE_NODE: PipelineNodeView = { status: 'idle', visits: 0, from: [], outputs: [] }\n\nexport const createInitialPipelineState = (): PipelineUiState => ({\n status: 'idle',\n nodes: {},\n edges: {},\n lastFired: [],\n visits: [],\n text: '',\n usage: ZERO,\n runs: 0,\n})\n\n/** A node's view; an idle one for a node the run has not touched. */\nexport const pipelineNodeView = (state: PipelineUiState, nodeId: string): PipelineNodeView =>\n state.nodes[nodeId] ?? IDLE_NODE\n\nconst sum = (a: IUsage | undefined, b: IUsage | undefined): IUsage => {\n const out: Record<string, number> = { ...(a ?? ZERO) }\n for (const [key, value] of Object.entries(b ?? {})) {\n if (typeof value === 'number' && Number.isFinite(value)) out[key] = (out[key] ?? 0) + value\n }\n return out as unknown as IUsage\n}\n\nconst withNode = (\n state: PipelineUiState,\n nodeId: string,\n patch: (node: PipelineNodeView) => PipelineNodeView,\n): PipelineUiState => ({\n ...state,\n nodes: { ...state.nodes, [nodeId]: patch(pipelineNodeView(state, nodeId)) },\n})\n\n// The run is over: nothing waits or runs any more, and no edge carries anything.\nconst settle = (state: PipelineUiState, visitStatus: 'stopped' | 'done'): PipelineUiState => {\n const nodes: PipelineUiState['nodes'] = {}\n for (const [id, node] of Object.entries(state.nodes)) {\n if (node.status === 'running' || node.status === 'waiting') {\n const { activity, ...rest } = node\n void activity\n nodes[id] = { ...rest, status: node.outputs.length > 0 ? 'done' : 'idle' }\n } else {\n nodes[id] = node\n }\n }\n const edges: PipelineUiState['edges'] = {}\n for (const [id, edge] of Object.entries(state.edges)) {\n edges[id] = edge.live ? { ...edge, live: false } : edge\n }\n return {\n ...state,\n nodes,\n edges,\n visits: state.visits.map((v) => (v.status === 'running' ? { ...v, status: visitStatus } : v)),\n }\n}\n\nconst quiet = (state: PipelineUiState, to: string): PipelineUiState['edges'] => {\n let edges = state.edges\n for (const [id, edge] of Object.entries(state.edges)) {\n if (edge.live && edge.to === to) {\n if (edges === state.edges) edges = { ...state.edges }\n edges[id] = { ...edge, live: false }\n }\n }\n return edges\n}\n\nconst patchVisit = (\n visits: PipelineVisitView[],\n nodeId: string,\n visit: number,\n patch: Partial<PipelineVisitView>,\n): PipelineVisitView[] =>\n visits.map((v) => (v.nodeId === nodeId && v.visit === visit ? { ...v, ...patch } : v))\n\n// An event of a node's own agent: keep one line of it.\nconst activityOf = (\n current: PipelineNodeActivity | undefined,\n event: AgentEvent,\n): PipelineNodeActivity | undefined => {\n const base = current ?? { toolCalls: 0 }\n switch (event.type) {\n case 'run.start':\n return { phase: 'plan', toolCalls: 0 }\n case 'step.start':\n return {\n phase: 'execute',\n step: event.step.description,\n stepIndex: event.index,\n stepTotal: event.total,\n toolCalls: base.toolCalls,\n }\n case 'step.tool-call':\n return { ...base, phase: 'execute', tool: event.name, toolCalls: base.toolCalls + 1 }\n case 'step.tool-result':\n case 'step.complete': {\n if (base.tool === undefined) return current\n const { tool, ...rest } = base\n void tool\n return rest\n }\n case 'replan.decision':\n return base.phase === 'replan' && base.tool === undefined\n ? current\n : { toolCalls: base.toolCalls, phase: 'replan' }\n case 'final.text-delta':\n case 'final.reasoning-delta':\n return base.phase === 'synthesize'\n ? current\n : { toolCalls: base.toolCalls, phase: 'synthesize' }\n default:\n return current\n }\n}\n\nconst reduceEvent = (state: PipelineUiState, event: AgentEvent): PipelineUiState => {\n switch (event.type) {\n case 'pipeline.started':\n return event.pipeline === state.name ? state : { ...state, name: event.pipeline }\n\n case 'pipeline.node.started': {\n const next = withNode(state, event.nodeId, (node) => {\n const { error, skipped, activity, ...rest } = node\n void [error, skipped, activity]\n return { ...rest, status: 'running', visits: event.visit, from: event.from }\n })\n return {\n ...next,\n runs: state.runs + 1,\n visits: [\n ...state.visits,\n { nodeId: event.nodeId, visit: event.visit, from: event.from, status: 'running' },\n ],\n }\n }\n\n case 'pipeline.node.finished': {\n const output: PipelineOutputView = {\n visit: event.visit,\n text: event.text,\n ...(event.route !== undefined ? { route: event.route } : {}),\n }\n const next = withNode(state, event.nodeId, (node) => {\n const { activity, ...rest } = node\n void activity\n return {\n ...rest,\n status: 'done',\n outputs: [...node.outputs, output],\n ...(event.usage ? { usage: sum(node.usage, event.usage as IUsage) } : {}),\n }\n })\n return {\n ...next,\n edges: quiet(state, event.nodeId),\n lastFired: [],\n usage: sum(state.usage, event.usage as IUsage | undefined),\n visits: patchVisit(state.visits, event.nodeId, event.visit, {\n status: 'done',\n text: event.text,\n ...(event.route !== undefined ? { route: event.route } : {}),\n ...(event.usage ? { usage: event.usage as IUsage } : {}),\n }),\n }\n }\n\n case 'pipeline.node.failed': {\n const settled = settle(\n {\n ...state,\n visits: patchVisit(state.visits, event.nodeId, event.visit, {\n status: 'failed',\n error: event.error,\n }),\n },\n 'stopped',\n )\n const next = withNode(settled, event.nodeId, (node) => {\n const { activity, ...rest } = node\n void activity\n return { ...rest, status: 'failed', error: event.error }\n })\n return { ...next, status: 'failed', error: event.error, failedNode: event.nodeId }\n }\n\n case 'pipeline.node.skipped': {\n const next = withNode(state, event.nodeId, (node) => ({\n ...node,\n status: 'skipped',\n skipped: event.reason,\n from: event.from,\n }))\n return { ...next, edges: quiet(state, event.nodeId) }\n }\n\n case 'pipeline.edge': {\n const before = state.edges[event.edgeId]\n const edge: PipelineEdgeView = {\n from: event.from,\n to: event.to,\n fired: event.fired,\n visit: event.visit,\n count: (before?.count ?? 0) + (event.fired ? 1 : 0),\n live: event.fired,\n }\n const next: PipelineUiState = {\n ...state,\n edges: { ...state.edges, [event.edgeId]: edge },\n lastFired: event.fired ? [...state.lastFired, event.edgeId] : state.lastFired,\n }\n if (!event.fired) return next\n const target = pipelineNodeView(next, event.to)\n // A node that is running takes this output in a later visit; its status stays.\n if (target.status === 'running' || target.status === 'waiting') return next\n return withNode(next, event.to, (node) => ({ ...node, status: 'waiting' }))\n }\n\n case 'pipeline.finished': {\n const settled = settle(state, event.stoppedBy === 'aborted' ? 'stopped' : 'done')\n const { stoppedBy, ...rest } = settled\n void stoppedBy\n return {\n ...rest,\n status: event.stoppedBy === 'aborted' ? 'stopped' : 'done',\n runs: event.runs,\n ...(event.stoppedBy ? { stoppedBy: event.stoppedBy } : {}),\n }\n }\n\n default: {\n // Everything else is an event of one node's own agent.\n if (event.nodeId === undefined) return state\n const node = state.nodes[event.nodeId]\n if (!node || node.status !== 'running') return state\n const activity = activityOf(node.activity, event)\n if (activity === node.activity) return state\n return withNode(state, event.nodeId, (n) => ({ ...n, activity }))\n }\n }\n}\n\n/** Fold one action into the state. Returns the same object when nothing changed. */\nexport const pipelineStateReducer = (\n state: PipelineUiState,\n action: PipelineAction,\n): PipelineUiState => {\n switch (action.type) {\n case 'reset':\n return createInitialPipelineState()\n case 'run.start':\n return { ...createInitialPipelineState(), status: 'running', input: action.input }\n case 'event':\n return reduceEvent(state, action.event)\n case 'run.result': {\n const { result } = action\n const settled = state.status === 'running' ? settle(state, 'done') : state\n const { stoppedBy, ...rest } = settled\n void stoppedBy\n return {\n ...rest,\n status:\n state.status === 'running'\n ? result.stoppedBy === 'aborted'\n ? 'stopped'\n : 'done'\n : state.status,\n text: result.text,\n usage: result.usage as IUsage,\n runs: result.runs,\n ...(result.stoppedBy ? { stoppedBy: result.stoppedBy } : {}),\n }\n }\n case 'run.error': {\n const settled = settle(state, 'stopped')\n return {\n ...settled,\n status: 'failed',\n // The node's own words (from `pipeline.node.failed`) say more than the wrapper's.\n error: state.error ?? action.error,\n ...(action.nodeId && !state.failedNode ? { failedNode: action.nodeId } : {}),\n }\n }\n }\n}\n","import { normalizePipeline } from '@dudko.dev/agent-web'\nimport type {\n PipelineCondition,\n PipelineDefinition,\n PipelineEdge,\n PipelineIssue,\n PipelineNode,\n} from '@dudko.dev/agent-web'\n\n// Editing a pipeline definition: pure functions from a definition to a new one. They keep the\n// graph consistent (an edge never points at a node that is gone, the entry always names a node\n// while there is one) and return the SAME object when there is nothing to change, so a caller\n// can tell by identity.\n\nexport type PipelineSelection = { kind: 'node' | 'edge'; id: string } | null\n\n/** A definition to start from: one node, which is the entry. */\nexport const emptyPipeline = (): PipelineDefinition => ({\n version: 1,\n entry: 'agent',\n nodes: [{ id: 'agent', name: 'Agent', position: { x: 0, y: 0 } }],\n edges: [],\n})\n\n/**\n * The definition with an id on every edge. The runner hands ids out by position (`e0`, `e1`, …),\n * which shift when an edge is removed - an editor needs them fixed, so it writes them down.\n */\nexport const ensureEdgeIds = (definition: PipelineDefinition): PipelineDefinition =>\n definition.edges.every((e) => typeof e.id === 'string' && e.id.length > 0)\n ? definition\n : normalizePipeline(definition)\n\nconst unique = (taken: Set<string>, base: string): string => {\n if (!taken.has(base)) return base\n for (let n = 2; ; n++) {\n if (!taken.has(`${base}-${n}`)) return `${base}-${n}`\n }\n}\n\n/** \"Fact checker!\" → \"fact-checker\". */\nexport const slugifyId = (text: string): string =>\n text\n .trim()\n .toLowerCase()\n .replace(/[^\\p{L}\\p{N}]+/gu, '-')\n .replace(/^-+|-+$/g, '')\n\n/** An id no node has: `base`, or `base-2`, `base-3`, … */\nexport const uniqueNodeId = (definition: PipelineDefinition, base = 'node'): string =>\n unique(new Set(definition.nodes.map((n) => n.id)), slugifyId(base) || 'node')\n\n/** An id no edge has (`e0`, `e1`, …; the positional ids of unnamed edges count as taken). */\nexport const uniqueEdgeId = (definition: PipelineDefinition): string => {\n const taken = new Set(definition.edges.map((e, i) => e.id ?? `e${i}`))\n for (let n = definition.edges.length; ; n++) {\n if (!taken.has(`e${n}`)) return `e${n}`\n }\n}\n\nconst isEmpty = (value: unknown): boolean =>\n value === undefined ||\n value === '' ||\n (Array.isArray(value) && value.length === 0) ||\n (typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n Object.keys(value).length === 0)\n\n// `patch` over `target`; a key set to nothing (undefined, '', [], {}) is removed, so a definition\n// never collects empty fields.\nconst applyPatch = <T extends object>(target: T, patch: Partial<T>, keep: (keyof T)[]): T => {\n const out = { ...target } as Record<string, unknown>\n let changed = false\n for (const [key, value] of Object.entries(patch)) {\n if (isEmpty(value) && !keep.includes(key as keyof T)) {\n if (key in out) {\n delete out[key]\n changed = true\n }\n } else if (JSON.stringify(out[key]) !== JSON.stringify(value)) {\n out[key] = value\n changed = true\n }\n }\n return changed ? (out as T) : target\n}\n\n/**\n * Add a node. Without an id it gets a free one (from its name, or `node`); an id that is taken\n * is made unique. The first node of a pipeline becomes its entry.\n */\nexport const addNode = (\n definition: PipelineDefinition,\n node: Partial<PipelineNode> = {},\n): PipelineDefinition => {\n const id = uniqueNodeId(definition, node.id || node.name || 'node')\n const nodes = [...definition.nodes, { ...node, id }]\n const hasEntry = definition.nodes.some((n) => n.id === definition.entry)\n return { ...definition, nodes, ...(hasEntry ? {} : { entry: id }) }\n}\n\n/** Change a node's fields (not its id: `renameNode`). An emptied field is removed. */\nexport const updateNode = (\n definition: PipelineDefinition,\n id: string,\n patch: Partial<Omit<PipelineNode, 'id'>>,\n): PipelineDefinition => {\n const index = definition.nodes.findIndex((n) => n.id === id)\n if (index < 0) return definition\n const next = applyPatch(definition.nodes[index], patch as Partial<PipelineNode>, ['id'])\n if (next === definition.nodes[index]) return definition\n const nodes = [...definition.nodes]\n nodes[index] = next\n return { ...definition, nodes }\n}\n\nexport const moveNode = (\n definition: PipelineDefinition,\n id: string,\n position: { x: number; y: number },\n): PipelineDefinition =>\n updateNode(definition, id, { position: { x: Math.round(position.x), y: Math.round(position.y) } })\n\n/** Remove a node and every edge that touches it. The entry moves to the first node left. */\nexport const removeNode = (definition: PipelineDefinition, id: string): PipelineDefinition => {\n if (!definition.nodes.some((n) => n.id === id)) return definition\n const nodes = definition.nodes.filter((n) => n.id !== id)\n return {\n ...definition,\n nodes,\n edges: definition.edges.filter((e) => e.from !== id && e.to !== id),\n entry: definition.entry === id ? (nodes[0]?.id ?? '') : definition.entry,\n }\n}\n\n/** Give a node another id; its edges and the entry follow. Refused when the id is empty or taken. */\nexport const renameNode = (\n definition: PipelineDefinition,\n id: string,\n nextId: string,\n): PipelineDefinition => {\n const to = nextId.trim()\n if (!to || to === id) return definition\n if (!definition.nodes.some((n) => n.id === id)) return definition\n if (definition.nodes.some((n) => n.id === to)) return definition\n return {\n ...definition,\n nodes: definition.nodes.map((n) => (n.id === id ? { ...n, id: to } : n)),\n edges: definition.edges.map((e) =>\n e.from === id || e.to === id\n ? { ...e, from: e.from === id ? to : e.from, to: e.to === id ? to : e.to }\n : e,\n ),\n entry: definition.entry === id ? to : definition.entry,\n }\n}\n\nexport const setEntry = (definition: PipelineDefinition, id: string): PipelineDefinition =>\n definition.entry === id || !definition.nodes.some((n) => n.id === id)\n ? definition\n : { ...definition, entry: id }\n\n// `always` is what an edge without a condition means: keep the definition short.\nconst cleanCondition = (when: PipelineCondition | undefined): PipelineCondition | undefined =>\n !when || when.kind === 'always' ? undefined : when\n\nconst sameCondition = (a: PipelineCondition | undefined, b: PipelineCondition | undefined) =>\n JSON.stringify(cleanCondition(a) ?? null) === JSON.stringify(cleanCondition(b) ?? null)\n\n/**\n * Connect two nodes. Refused when either does not exist, or when the same edge (the same ends\n * and the same condition) is already there. The edge gets a free id unless it brings one.\n */\nexport const addEdge = (\n definition: PipelineDefinition,\n edge: { from: string; to: string; when?: PipelineCondition; id?: string },\n): PipelineDefinition => {\n const has = (id: string) => definition.nodes.some((n) => n.id === id)\n if (!has(edge.from) || !has(edge.to)) return definition\n const base = ensureEdgeIds(definition)\n if (\n base.edges.some(\n (e) => e.from === edge.from && e.to === edge.to && sameCondition(e.when, edge.when),\n )\n ) {\n return definition\n }\n const id = edge.id && !base.edges.some((e) => e.id === edge.id) ? edge.id : uniqueEdgeId(base)\n const when = cleanCondition(edge.when)\n const added: PipelineEdge = { id, from: edge.from, to: edge.to, ...(when ? { when } : {}) }\n return { ...base, edges: [...base.edges, added] }\n}\n\nconst edgeIndex = (definition: PipelineDefinition, id: string): number =>\n definition.edges.findIndex((e, i) => (e.id ?? `e${i}`) === id)\n\n/** Change an edge's condition or ends. An end that names no node is refused. */\nexport const updateEdge = (\n definition: PipelineDefinition,\n id: string,\n patch: { from?: string; to?: string; when?: PipelineCondition },\n): PipelineDefinition => {\n const base = ensureEdgeIds(definition)\n const index = edgeIndex(base, id)\n if (index < 0) return definition\n const has = (nodeId: string) => base.nodes.some((n) => n.id === nodeId)\n if (\n (patch.from !== undefined && !has(patch.from)) ||\n (patch.to !== undefined && !has(patch.to))\n ) {\n return definition\n }\n const before = base.edges[index]\n const { when: was, ...ends } = before\n const when = cleanCondition('when' in patch ? patch.when : was)\n const next: PipelineEdge = {\n ...ends,\n ...(patch.from !== undefined ? { from: patch.from } : {}),\n ...(patch.to !== undefined ? { to: patch.to } : {}),\n ...(when ? { when } : {}),\n }\n if (JSON.stringify(next) === JSON.stringify(before)) return definition\n const edges = [...base.edges]\n edges[index] = next\n return { ...base, edges }\n}\n\nexport const removeEdge = (definition: PipelineDefinition, id: string): PipelineDefinition => {\n const base = ensureEdgeIds(definition)\n const index = edgeIndex(base, id)\n if (index < 0) return definition\n return { ...base, edges: base.edges.filter((_, i) => i !== index) }\n}\n\n/** Rename one of a node's routes; the edges that take that route follow. */\nexport const renameRoute = (\n definition: PipelineDefinition,\n nodeId: string,\n label: string,\n nextLabel: string,\n): PipelineDefinition => {\n const node = definition.nodes.find((n) => n.id === nodeId)\n if (!node?.routes?.some((r) => r.label === label) || label === nextLabel) return definition\n if (node.routes.some((r) => r.label === nextLabel)) return definition\n return {\n ...definition,\n nodes: definition.nodes.map((n) =>\n n.id === nodeId\n ? {\n ...n,\n routes: (n.routes ?? []).map((r) =>\n r.label === label ? { ...r, label: nextLabel } : r,\n ),\n }\n : n,\n ),\n edges: definition.edges.map((e) =>\n e.from === nodeId && e.when?.kind === 'route' && e.when.label === label\n ? { ...e, when: { kind: 'route', label: nextLabel } }\n : e,\n ),\n }\n}\n\n/** Set (a number) or clear (undefined) the limits; a definition with none has no `limits`. */\nexport const setLimits = (\n definition: PipelineDefinition,\n patch: { maxNodeVisits?: number; maxRuns?: number },\n): PipelineDefinition => {\n const before = definition.limits ?? {}\n const limits = applyPatch(before, patch, [])\n if (limits === before) return definition\n const { limits: was, ...rest } = definition\n void was\n return Object.keys(limits).length > 0 ? { ...rest, limits } : rest\n}\n\nexport const setPipelineName = (\n definition: PipelineDefinition,\n name: string,\n): PipelineDefinition => {\n if ((definition.name ?? '') === name) return definition\n const { name: was, ...rest } = definition\n void was\n return name ? { ...rest, name } : rest\n}\n\nexport interface AutoLayoutOptions {\n /** Distance between the left sides of two columns (default 320). */\n columnGap?: number\n /** Distance between the tops of two nodes of a column (default 170). */\n rowGap?: number\n /** Place every node, not only the ones without a position. */\n all?: boolean\n}\n\n/**\n * Give a position to the nodes that have none (a definition written by hand, or by a model):\n * columns by distance from the entry, left to right. Nodes the entry does not reach go last.\n */\nexport const autoLayout = (\n definition: PipelineDefinition,\n options: AutoLayoutOptions = {},\n): PipelineDefinition => {\n const { columnGap = 320, rowGap = 170, all = false } = options\n const placed = (n: PipelineNode) =>\n !all && typeof n.position?.x === 'number' && typeof n.position?.y === 'number'\n if (definition.nodes.every(placed)) return definition\n const depth = new Map<string, number>()\n const ids = new Set(definition.nodes.map((n) => n.id))\n const walk = (start: string, from: number) => {\n const queue: string[] = [start]\n depth.set(start, from)\n while (queue.length) {\n const id = queue.shift() as string\n for (const edge of definition.edges) {\n if (edge.from === id && ids.has(edge.to) && !depth.has(edge.to)) {\n depth.set(edge.to, (depth.get(id) as number) + 1)\n queue.push(edge.to)\n }\n }\n }\n }\n if (ids.has(definition.entry)) walk(definition.entry, 0)\n for (const node of definition.nodes) {\n if (!depth.has(node.id)) walk(node.id, Math.max(-1, ...depth.values()) + 1)\n }\n const rows = new Map<number, number>()\n const columns = new Map<number, number>()\n for (const node of definition.nodes) {\n const d = depth.get(node.id) as number\n columns.set(d, (columns.get(d) ?? 0) + 1)\n }\n const tallest = Math.max(...columns.values())\n return {\n ...definition,\n nodes: definition.nodes.map((node) => {\n const d = depth.get(node.id) as number\n const row = rows.get(d) ?? 0\n rows.set(d, row + 1)\n if (placed(node)) return node\n // Each column is centred on the tallest one.\n const offset = ((tallest - (columns.get(d) as number)) * rowGap) / 2\n return { ...node, position: { x: d * columnGap, y: Math.round(offset + row * rowGap) } }\n }),\n }\n}\n\n/** A free spot for a new node: to the right of the lowest node of the last column. */\nexport const nextNodePosition = (definition: PipelineDefinition): { x: number; y: number } => {\n const positions = definition.nodes.map((n) => n.position).filter(Boolean) as {\n x: number\n y: number\n }[]\n if (positions.length === 0) return { x: 0, y: 0 }\n const right = Math.max(...positions.map((p) => p.x))\n const bottom = Math.max(...positions.filter((p) => p.x === right).map((p) => p.y))\n return { x: right, y: bottom + 170 }\n}\n\n/** What a validation issue is about, as something to select. */\nexport const issueTarget = (\n issue: PipelineIssue,\n definition: PipelineDefinition,\n): PipelineSelection => {\n if (issue.edgeId !== undefined || issue.edgeIndex !== undefined) {\n const index =\n issue.edgeIndex ?? definition.edges.findIndex((e, i) => (e.id ?? `e${i}`) === issue.edgeId)\n const edge = definition.edges[index]\n if (edge) return { kind: 'edge', id: edge.id ?? `e${index}` }\n }\n if (issue.nodeId !== undefined && definition.nodes.some((n) => n.id === issue.nodeId)) {\n return { kind: 'node', id: issue.nodeId }\n }\n return null\n}\n\n/**\n * Read a definition from text (an imported file, a paste). Throws with a plain message when the\n * text is not JSON or not the shape of a pipeline; a definition that parses but does not\n * validate is returned as it is, for the editor to show what is wrong with it.\n */\nexport const parsePipelineJson = (text: string): PipelineDefinition => {\n let value: unknown\n try {\n value = JSON.parse(text)\n } catch (err) {\n throw new Error(`not JSON: ${(err as Error).message}`)\n }\n const def = value as Partial<PipelineDefinition> | null\n if (typeof def !== 'object' || def === null || Array.isArray(def)) {\n throw new Error('a pipeline definition must be an object')\n }\n if (!Array.isArray(def.nodes) || !Array.isArray(def.edges)) {\n throw new Error('a pipeline definition needs `nodes` and `edges` arrays')\n }\n if (def.nodes.some((n) => typeof n !== 'object' || n === null || typeof n.id !== 'string')) {\n throw new Error('every node needs an `id`')\n }\n if (\n def.edges.some(\n (e) =>\n typeof e !== 'object' ||\n e === null ||\n typeof e.from !== 'string' ||\n typeof e.to !== 'string',\n )\n ) {\n throw new Error('every edge needs `from` and `to`')\n }\n return autoLayout(\n ensureEdgeIds({\n ...(def as PipelineDefinition),\n entry: typeof def.entry === 'string' ? def.entry : '',\n }),\n )\n}\n","import type { PipelineDefinition } from '@dudko.dev/agent-web'\n\n// \"Copy as code\": a definition as a program that runs it. Pure text in, text out.\n\nexport type PipelineCodeTarget = 'browser' | 'node'\n\nexport interface PipelineCodeOptions {\n /** `browser`: @dudko.dev/agent-web. `node`: @dudko.dev/agent. */\n target?: PipelineCodeTarget\n /** Keep the nodes' `position` (an editor's business; the runner ignores it). Default false. */\n positions?: boolean\n /** The request in the example call. */\n input?: string\n}\n\nconst IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/\n\n// \"fact-checker\" + \"Tools\" → factCheckerTools: a name for the value the host supplies.\nconst identifier = (name: string, suffix: string, taken: Set<string>): string => {\n const words = name.split(/[^A-Za-z0-9]+/).filter(Boolean)\n let base = words\n .map((w, i) => (i === 0 ? w.charAt(0).toLowerCase() : w.charAt(0).toUpperCase()) + w.slice(1))\n .join('')\n if (!base || /^[0-9]/.test(base)) base = `x${base}`\n base += suffix\n let out = base\n for (let n = 2; taken.has(out); n++) out = `${base}${n}`\n taken.add(out)\n return out\n}\n\nconst namesOf = (\n definition: PipelineDefinition,\n field: 'skills' | 'tools' | 'mcpServers',\n): string[] => [...new Set(definition.nodes.flatMap((n) => n[field] ?? []))]\n\nconst quote = (text: string): string =>\n `'${text\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/'/g, \"\\\\'\")\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029')}'`\n\nconst key = (name: string): string => (IDENTIFIER.test(name) ? name : quote(name))\n\n// JSON, written the way the code around it is: unquoted keys, single quotes.\nconst literal = (value: unknown, indent = ''): string => {\n const inner = `${indent} `\n if (typeof value === 'string') return quote(value)\n if (value === null || typeof value !== 'object') return String(value)\n if (Array.isArray(value)) {\n if (value.length === 0) return '[]'\n const flat = `[${value.map((v) => literal(v, inner)).join(', ')}]`\n if (flat.length + indent.length <= 80 && !flat.includes('\\n')) return flat\n return `[\\n${value.map((v) => `${inner}${literal(v, inner)},`).join('\\n')}\\n${indent}]`\n }\n const entries = Object.entries(value).filter(([, v]) => v !== undefined)\n if (entries.length === 0) return '{}'\n const flat = `{ ${entries.map(([k, v]) => `${key(k)}: ${literal(v, inner)}`).join(', ')} }`\n if (flat.length + indent.length <= 80 && !flat.includes('\\n')) return flat\n return `{\\n${entries.map(([k, v]) => `${inner}${key(k)}: ${literal(v, inner)},`).join('\\n')}\\n${indent}}`\n}\n\nconst registry = (\n field: string,\n names: string[],\n suffix: string,\n taken: Set<string>,\n note: string,\n): string | undefined =>\n names.length === 0\n ? undefined\n : ` ${field}: { ${names.map((n) => `${key(n)}: ${identifier(n, suffix, taken)}`).join(', ')} }, // ${note}`\n\n/**\n * A snippet that runs the definition with the browser package or with the Node one. The names\n * the definition uses (models, skills, tool groups, MCP servers) appear as variables for the\n * host to supply: a definition never carries a model or a key.\n */\nexport const pipelineToCode = (\n definition: PipelineDefinition,\n options: PipelineCodeOptions = {},\n): string => {\n const { target = 'browser', positions = false, input = 'Your request' } = options\n const browser = target === 'browser'\n const pkg = browser ? '@dudko.dev/agent-web' : '@dudko.dev/agent'\n const def: PipelineDefinition = positions\n ? definition\n : {\n ...definition,\n nodes: definition.nodes.map((n) => {\n const { position, ...rest } = n\n void position\n return rest\n }),\n }\n const taken = new Set(['definition', 'pipeline', 'result', 'config', 'model', 'credentials'])\n const models = [...new Set(definition.nodes.flatMap((n) => (n.model ? [n.model] : [])))]\n const registries = [\n registry(\n 'models',\n models,\n 'Model',\n taken,\n browser ? 'a LanguageModel or a ProviderModelSpec each' : 'a model spec each',\n ),\n registry('skills', namesOf(definition, 'skills'), 'Skill', taken, 'a Skill each'),\n registry('tools', namesOf(definition, 'tools'), 'Tools', taken, 'a named group of tools each'),\n registry(\n 'mcpServers',\n namesOf(definition, 'mcpServers'),\n 'Mcp',\n taken,\n browser ? 'a connectMcpHttp result each' : 'an MCP server config each',\n ),\n ].filter(Boolean)\n\n const lines = [\n `import { createPipeline, nodeResolver } from '${pkg}'`,\n `import type { PipelineDefinition } from '${pkg}'`,\n '',\n `const definition: PipelineDefinition = ${literal(def)}`,\n '',\n 'const pipeline = createPipeline(definition, {',\n ' // What the names in the definition stand for. A name that is not here fails its node.',\n ' resolveNode: nodeResolver({',\n browser\n ? ' base: { model, credentials }, // a BrowserAgentConfig: every node starts from it'\n : ' base: config, // an IAgentConfig: every node starts from it',\n ...registries,\n ' }),',\n '})',\n '',\n 'const result = await pipeline.run({',\n ` input: ${literal(input)},`,\n ' onEvent: (e) => {',\n \" if (e.type === 'pipeline.node.started') console.log('→', e.nodeId, `#${e.visit}`)\",\n ' },',\n '})',\n 'console.log(result.text)',\n ...(browser\n ? []\n : ['await pipeline.close() // closes the node agents (their MCP connections)']),\n '',\n ]\n return lines.join('\\n')\n}\n","import type { PipelineCondition, PipelineStop } from '@dudko.dev/agent-web'\nimport { defaultCanvasLabels, type CanvasLabels } from '../canvas/labels.js'\nimport type { PipelineNodeStatus, PipelineRunStatus } from './state.js'\n\ntype ConditionKind = PipelineCondition['kind']\n\n/**\n * Every string the pipeline editor renders or says - override any of them for another language\n * or wording, per component (`labels` prop) or for a whole tree (`<PipelineLabelsProvider>`).\n * Counted phrases are functions. The reference with the defaults is in docs/pipeline.md.\n */\nexport interface PipelineLabels {\n // ── toolbar ────────────────────────────────────────────────────────────────\n toolbar: string\n addNode: string\n deleteSelected: string\n fit: string\n zoomIn: string\n zoomOut: string\n importJson: string\n exportJson: string\n copyCode: string\n /** The name a new node gets (\"Agent 3\"). */\n newNodeName: (n: number) => string\n importFailed: (reason: string) => string\n\n // ── validation ─────────────────────────────────────────────────────────────\n issues: string\n noIssues: string\n errors: (n: number) => string\n warnings: (n: number) => string\n issueError: string\n issueWarning: string\n\n // ── canvas ─────────────────────────────────────────────────────────────────\n /** The canvas's own strings (its name, its keyboard help, what a port and an edge are called). */\n canvas: CanvasLabels\n emptyCanvas: string\n /** The node's state for a screen reader: \"running, visit 2\". */\n nodeDescription: (status: string, visits: number) => string\n\n // ── node card ──────────────────────────────────────────────────────────────\n nodeStatus: Record<PipelineNodeStatus, string>\n entry: string\n defaultModel: string\n skillsBadge: (n: number) => string\n toolsBadge: (n: number) => string\n mcpBadge: (n: number) => string\n visits: (n: number) => string\n /** The output port of a node with routes that takes no route: every other kind of edge. */\n anyOutput: string\n activityPlanning: string\n activityReplanning: string\n activityAnswering: string\n activityStep: (index: number, total: number, step: string) => string\n activityTool: (name: string) => string\n skippedBy: Record<'maxRuns' | 'maxNodeVisits', string>\n\n // ── inspector ──────────────────────────────────────────────────────────────\n inspector: string\n inspectorNode: string\n inspectorEdge: string\n inspectorPipeline: string\n close: string\n expand: string\n collapse: string\n fieldId: string\n fieldIdHint: string\n idTaken: string\n idEmpty: string\n fieldName: string\n fieldInstructions: string\n instructionsPlaceholder: string\n fieldModel: string\n /** An option that is in the definition but not in the host's list. */\n unknownOption: (name: string) => string\n fieldSkills: string\n fieldTools: string\n fieldMcp: string\n noOptions: string\n fieldRoutes: string\n routesHint: string\n routeLabel: string\n routeDescription: string\n addRoute: string\n removeRoute: (label: string) => string\n fieldJoin: string\n joinAll: string\n joinAny: string\n isEntry: string\n makeEntry: string\n deleteNode: string\n edgeEnds: (from: string, to: string) => string\n fieldCondition: string\n conditionKinds: Record<ConditionKind, string>\n conditionHints: Record<ConditionKind, string>\n fieldText: string\n caseSensitive: string\n fieldPattern: string\n fieldFlags: string\n fieldRoute: string\n noRoutes: string\n deleteEdge: string\n pipelineName: string\n pipelineNamePlaceholder: string\n fieldEntry: string\n fieldMaxNodeVisits: string\n fieldMaxRuns: string\n limitDefault: (n: number) => string\n counts: (nodes: number, edges: number) => string\n\n // ── run ────────────────────────────────────────────────────────────────────\n runPlaceholder: string\n runInput: string\n run: string\n stop: string\n fixErrorsFirst: string\n runStatus: Record<PipelineRunStatus, string>\n stoppedBy: Record<PipelineStop, string>\n /** Announced to a screen reader as nodes start, finish, fail. */\n announceNode: (name: string, status: string) => string\n\n // ── results ────────────────────────────────────────────────────────────────\n results: string\n showResults: string\n hideResults: string\n finalAnswer: string\n nodeOutputs: string\n noOutputYet: string\n visitTitle: (name: string, visit: number) => string\n routeTaken: (label: string) => string\n receivedFrom: (names: string) => string\n usage: (input: string, output: string) => string\n runsCount: (n: number) => string\n\n // ── copy as code ───────────────────────────────────────────────────────────\n codeTitle: string\n codeBrowser: string\n codeNode: string\n copy: string\n copied: string\n}\n\nexport const defaultPipelineLabels: PipelineLabels = {\n toolbar: 'Pipeline tools',\n addNode: 'Add node',\n deleteSelected: 'Delete',\n fit: 'Fit',\n zoomIn: 'Zoom in',\n zoomOut: 'Zoom out',\n importJson: 'Import JSON',\n exportJson: 'Export JSON',\n copyCode: 'Copy as code',\n newNodeName: (n) => `Agent ${n}`,\n importFailed: (reason) => `Could not import: ${reason}`,\n\n issues: 'Issues',\n noIssues: 'No issues',\n errors: (n) => `${n} error${n === 1 ? '' : 's'}`,\n warnings: (n) => `${n} warning${n === 1 ? '' : 's'}`,\n issueError: 'Error',\n issueWarning: 'Warning',\n\n canvas: { ...defaultCanvasLabels, canvas: 'Pipeline canvas' },\n emptyCanvas: 'No nodes yet. Add one to start.',\n nodeDescription: (status, visits) => (visits > 1 ? `${status}, visit ${visits}.` : `${status}.`),\n\n nodeStatus: {\n idle: 'idle',\n waiting: 'waiting',\n running: 'running',\n done: 'done',\n failed: 'failed',\n skipped: 'skipped',\n },\n entry: 'entry',\n defaultModel: 'default model',\n skillsBadge: (n) => `${n} skill${n === 1 ? '' : 's'}`,\n toolsBadge: (n) => `${n} tool group${n === 1 ? '' : 's'}`,\n mcpBadge: (n) => `${n} MCP server${n === 1 ? '' : 's'}`,\n visits: (n) => `×${n}`,\n anyOutput: 'any',\n activityPlanning: 'planning…',\n activityReplanning: 'checking the plan…',\n activityAnswering: 'writing the answer…',\n activityStep: (index, total, step) => `${index}/${total} ${step}`,\n activityTool: (name) => `tool: ${name}`,\n skippedBy: {\n maxNodeVisits: 'visit limit reached',\n maxRuns: 'run limit reached',\n },\n\n inspector: 'Inspector',\n inspectorNode: 'Node',\n inspectorEdge: 'Connection',\n inspectorPipeline: 'Pipeline',\n close: 'Close',\n expand: 'Show details',\n collapse: 'Hide details',\n fieldId: 'Id',\n fieldIdHint: 'Unique; edges and events name the node by it.',\n idTaken: 'Another node has this id.',\n idEmpty: 'A node needs an id.',\n fieldName: 'Name',\n fieldInstructions: 'Instructions',\n instructionsPlaceholder: 'The role of this node: what it does with what it receives.',\n fieldModel: 'Model',\n unknownOption: (name) => `${name} (not available)`,\n fieldSkills: 'Skills',\n fieldTools: 'Tools',\n fieldMcp: 'MCP servers',\n noOptions: 'None available.',\n fieldRoutes: 'Routes',\n routesHint: 'After it answers, the node picks one. Each becomes an output port.',\n routeLabel: 'Label',\n routeDescription: 'When to pick it',\n addRoute: 'Add route',\n removeRoute: (label) => `Remove route ${label}`,\n fieldJoin: 'When several nodes lead here',\n joinAll: 'Wait for all of them',\n joinAny: 'Run on any of them',\n isEntry: 'This node receives the request.',\n makeEntry: 'Make it the entry',\n deleteNode: 'Delete node',\n edgeEnds: (from, to) => `${from} → ${to}`,\n fieldCondition: 'Fires',\n conditionKinds: {\n always: 'always',\n contains: 'contains',\n matches: 'matches',\n route: 'route',\n otherwise: 'otherwise',\n },\n conditionHints: {\n always: 'Every time the source node answers.',\n contains: 'When the answer contains this text.',\n matches: 'When this pattern occurs in the answer. No backreferences or lookaround.',\n route: 'When the source node picks this route.',\n otherwise: 'When no other connection of the source node fired.',\n },\n fieldText: 'Text',\n caseSensitive: 'Match case',\n fieldPattern: 'Pattern',\n fieldFlags: 'Flags',\n fieldRoute: 'Route',\n noRoutes: 'The source node has no routes. Add one to it first.',\n deleteEdge: 'Delete connection',\n pipelineName: 'Name',\n pipelineNamePlaceholder: 'Untitled pipeline',\n fieldEntry: 'Entry node',\n fieldMaxNodeVisits: 'Visits per node',\n fieldMaxRuns: 'Node runs in total',\n limitDefault: (n) => `default ${n}`,\n counts: (nodes, edges) =>\n `${nodes} node${nodes === 1 ? '' : 's'}, ${edges} connection${edges === 1 ? '' : 's'}`,\n\n runPlaceholder: 'What should the pipeline work on?',\n runInput: 'Request',\n run: 'Run',\n stop: 'Stop',\n fixErrorsFirst: 'Fix the errors before running.',\n runStatus: {\n idle: 'Not run yet',\n running: 'Running…',\n done: 'Finished',\n failed: 'Failed',\n stopped: 'Stopped',\n },\n stoppedBy: {\n maxNodeVisits: 'A node reached its visit limit, so a loop was cut short.',\n maxRuns: 'The pipeline reached its limit of node runs.',\n aborted: 'Stopped before it finished.',\n },\n announceNode: (name, status) => `${name}: ${status}`,\n\n results: 'Result',\n showResults: 'Show the result',\n hideResults: 'Hide the result',\n finalAnswer: 'Final answer',\n nodeOutputs: 'Node outputs',\n noOutputYet: 'Nothing yet.',\n visitTitle: (name, visit) => (visit > 1 ? `${name} · visit ${visit}` : name),\n routeTaken: (label) => `route: ${label}`,\n receivedFrom: (names) => `from ${names}`,\n usage: (input, output) => `in ${input} · out ${output}`,\n runsCount: (n) => `${n} node run${n === 1 ? '' : 's'}`,\n\n codeTitle: 'Copy as code',\n codeBrowser: 'Browser',\n codeNode: 'Node',\n copy: 'Copy',\n copied: 'Copied',\n}\n\nconst NESTED = [\n 'canvas',\n 'nodeStatus',\n 'skippedBy',\n 'conditionKinds',\n 'conditionHints',\n 'runStatus',\n 'stoppedBy',\n] as const\ntype Nested = (typeof NESTED)[number]\n\n/** Overrides: any label, with the nested groups merged key by key. */\nexport type PipelineLabelsOverride = Partial<Omit<PipelineLabels, Nested>> & {\n [K in Nested]?: Partial<PipelineLabels[K]>\n}\n\n/** `base` with `over` applied (nested groups merged, not replaced). */\nexport const mergePipelineLabels = (\n base: PipelineLabels,\n over?: PipelineLabelsOverride,\n): PipelineLabels => {\n if (!over) return base\n const out = { ...base, ...over } as PipelineLabels\n for (const key of NESTED) {\n if (over[key]) (out as unknown as Record<string, unknown>)[key] = { ...base[key], ...over[key] }\n }\n return out\n}\n"],"mappings":";;;;;AA2GA,IAAM,OAAe,EAAE,aAAa,GAAG,cAAc,GAAG,aAAa,EAAE;AAEvE,IAAM,YAA8B,EAAE,QAAQ,QAAQ,QAAQ,GAAG,MAAM,CAAC,GAAG,SAAS,CAAC,EAAE;AAEhF,IAAM,6BAA6B,OAAwB;AAAA,EAChE,QAAQ;AAAA,EACR,OAAO,CAAC;AAAA,EACR,OAAO,CAAC;AAAA,EACR,WAAW,CAAC;AAAA,EACZ,QAAQ,CAAC;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AACR;AAGO,IAAM,mBAAmB,CAAC,OAAwB,WACvD,MAAM,MAAM,MAAM,KAAK;AAEzB,IAAM,MAAM,CAAC,GAAuB,MAAkC;AACpE,QAAM,MAA8B,EAAE,GAAI,KAAK,KAAM;AACrD,aAAW,CAACA,MAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,CAAC,CAAC,GAAG;AAClD,QAAI,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,EAAG,KAAIA,IAAG,KAAK,IAAIA,IAAG,KAAK,KAAK;AAAA,EACxF;AACA,SAAO;AACT;AAEA,IAAM,WAAW,CACf,OACA,QACA,WACqB;AAAA,EACrB,GAAG;AAAA,EACH,OAAO,EAAE,GAAG,MAAM,OAAO,CAAC,MAAM,GAAG,MAAM,iBAAiB,O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GAAG;AAAA,EAEpD,WAAW;AAAA,EACX,aAAa;AAAA,EACb,UAAU;AAAA,EACV,MAAM;AAAA,EACN,QAAQ;AACV;AAEA,IAAM,SAAS;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AASO,IAAM,sBAAsB,CACjC,MACA,SACmB;AACnB,MAAI,CAAC,KAAM,QAAO;AAClB,QAAM,MAAM,EAAE,GAAG,MAAM,GAAG,KAAK;AAC/B,aAAWC,QAAO,QAAQ;AACxB,QAAI,KAAKA,IAAG,EAAG,CAAC,IAA2CA,IAAG,IAAI,EAAE,GAAG,KAAKA,IAAG,GAAG,GAAG,KAAKA,IAAG,EAAE;AAAA,EACjG;AACA,SAAO;AACT;","names":["key","key","id","flat","key"]}
@@ -0,0 +1,100 @@
1
+ import { AskUserRequest, AskUserContext, AskUserAnswer, AskUserConfig, AskUserHandler, AgentEvent } from '@dudko.dev/agent-web';
2
+
3
+ /**
4
+ * The model asks the person ONE closed question (the core's `ask_user`, `config.askUser`): the
5
+ * part of it that is not React - the queue the hook hands the core as `askUser.onQuestion`, the
6
+ * answer a prompt builds, and what of a question's tool result may be kept.
7
+ *
8
+ * Pure: no React, no clock of its own (the queue takes `now`), no import of the core at run time
9
+ * (types only), so the main entry still loads next to an older core.
10
+ *
11
+ * Nothing here keeps, logs or returns what the person typed (`{ other }`) except to the one caller
12
+ * that hands it to the core: the queue passes an answer straight to the core's resolver, and
13
+ * {@link withoutOwnWords} takes the person's words out of the events before a view keeps them.
14
+ */
15
+ /** The core's tool name (`ASK_USER_TOOL`). */
16
+ declare const ASK_USER_TOOL_NAME = "ask_user";
17
+ /** The core's default for `askUser.timeoutMs` (`ASK_USER_TIMEOUT_MS`). */
18
+ declare const QUESTION_TIMEOUT_MS = 300000;
19
+ /**
20
+ * A question waiting for the person: the core's request (the question and every option are the
21
+ * MODEL's text, cleaned - show them as plain text), and when the core stops waiting for it.
22
+ */
23
+ interface PendingQuestion extends AskUserRequest {
24
+ /** Epoch ms after which the core answers it by itself ("did not answer in time"); absent: no limit. */
25
+ expiresAt?: number;
26
+ }
27
+ /**
28
+ * How long the core waits for an answer with this `askUser`; `undefined` = no limit of its own
29
+ * (`0`, `Infinity`, more than a timer holds - the core's own rules).
30
+ */
31
+ declare const questionTimeoutOf: (askUser: boolean | AskUserConfig | undefined) => number | undefined;
32
+ /**
33
+ * `config.askUser` as `useAgent` builds the agent with it: on without a handler of its own
34
+ * (`true`, `{ timeoutMs, maxPerRun }`) it gets `handler`; a host's own `onQuestion` wins, and off
35
+ * (absent, `false`) stays off - nothing is added, so the core mounts no tool.
36
+ */
37
+ declare const askUserWith: (askUser: boolean | AskUserConfig | undefined, handler: AskUserHandler) => boolean | AskUserConfig | undefined;
38
+ interface QuestionQueueOptions {
39
+ /**
40
+ * How long the core waits (ms), for `expiresAt`; `undefined` = no limit. A function is read when
41
+ * a question arrives (the settings of the agent that asks).
42
+ */
43
+ timeoutMs?: number | (() => number | undefined);
44
+ /** Called whenever the list of waiting questions changed. */
45
+ onChange?: (pending: PendingQuestion[]) => void;
46
+ /** The clock (tests). */
47
+ now?: () => number;
48
+ }
49
+ interface QuestionQueue {
50
+ /** The core's `askUser.onQuestion`: resolves when the person answers, or as `{ declined: true }`. */
51
+ handler: (request: AskUserRequest, ctx?: AskUserContext) => Promise<AskUserAnswer>;
52
+ /** The questions waiting, oldest first. */
53
+ pending: () => PendingQuestion[];
54
+ /** Answer one. False when no such question is waiting (answered, expired, cancelled). */
55
+ answer: (id: string, answer: AskUserAnswer) => boolean;
56
+ /**
57
+ * Take the waiting questions down - all of them, or those `match` picks - as declined (the run
58
+ * ended, it was stopped). The core has usually stopped waiting already; this only makes sure no
59
+ * resolver is left.
60
+ */
61
+ cancel: (match?: (question: PendingQuestion) => boolean) => void;
62
+ /** Cancel everything and stop reporting: the owner is gone. A later question is declined at once. */
63
+ dispose: () => void;
64
+ }
65
+ /**
66
+ * The questions the model is waiting on: `request.id → resolver`. A question leaves the queue
67
+ * exactly once - answered by the person, dropped because the core no longer wants the answer
68
+ * (`ctx.signal`: its time ran out, the run stopped), or cancelled by its owner (the run ended, an
69
+ * unmount) - and the queue never holds an answer: `answer` passes it straight to the resolver.
70
+ */
71
+ declare const createQuestionQueue: (options?: QuestionQueueOptions) => QuestionQueue;
72
+ /**
73
+ * Why a question ended without the person deciding: the core's `AskUserReason`
74
+ * (`handler-error`, `invalid-answer`, `cannot-park`), or its action (`timeout`, `stopped`).
75
+ */
76
+ type QuestionOutcomeReason = 'timeout' | 'stopped' | 'handler-error' | 'invalid-answer' | 'cannot-park';
77
+ /**
78
+ * The person's picks as the core's answer: the labels that were offered, in the order they were
79
+ * offered, each once - and one only unless the question allows several. `undefined` when nothing
80
+ * that was offered is picked (Send stays off).
81
+ */
82
+ declare const questionChoiceOf: (question: Pick<AskUserRequest, "options" | "multiple">, picked: readonly string[]) => AskUserAnswer | undefined;
83
+ /**
84
+ * The person's own words as the core's answer, when the question allows them and there is
85
+ * anything but spaces; `undefined` otherwise (Send stays off). The text goes to the caller only.
86
+ */
87
+ declare const questionOtherOf: (question: Pick<AskUserRequest, "allowOther">, text: string) => AskUserAnswer | undefined;
88
+ /** Whether an `ask_user` result may be kept by a view: it holds no word the person typed. */
89
+ declare const askUserOutputKept: (output: unknown, ok: boolean) => boolean;
90
+ /**
91
+ * The event with the person's own words taken out: the result of an `ask_user` call that is not
92
+ * known to hold labels only (an answer in their own words) loses its `output` - in
93
+ * `step.tool-result`, in `step.complete`'s tool calls, and in a subagent's events at any depth.
94
+ * Everything else comes back as it was (the same object). The model was given the words; the
95
+ * view, the saved chat and the event log are not.
96
+ */
97
+ declare const withoutOwnWords: (event: AgentEvent) => AgentEvent;
98
+
99
+ export { ASK_USER_TOOL_NAME as A, QUESTION_TIMEOUT_MS as a, askUserOutputKept as d, askUserWith as e, createQuestionQueue as f, questionOtherOf as g, questionTimeoutOf as h, questionChoiceOf as q, withoutOwnWords as w };
100
+ export type { PendingQuestion as P, QuestionOutcomeReason as Q, QuestionQueue as b, QuestionQueueOptions as c };
@@ -0,0 +1,100 @@
1
+ import { AskUserRequest, AskUserContext, AskUserAnswer, AskUserConfig, AskUserHandler, AgentEvent } from '@dudko.dev/agent-web';
2
+
3
+ /**
4
+ * The model asks the person ONE closed question (the core's `ask_user`, `config.askUser`): the
5
+ * part of it that is not React - the queue the hook hands the core as `askUser.onQuestion`, the
6
+ * answer a prompt builds, and what of a question's tool result may be kept.
7
+ *
8
+ * Pure: no React, no clock of its own (the queue takes `now`), no import of the core at run time
9
+ * (types only), so the main entry still loads next to an older core.
10
+ *
11
+ * Nothing here keeps, logs or returns what the person typed (`{ other }`) except to the one caller
12
+ * that hands it to the core: the queue passes an answer straight to the core's resolver, and
13
+ * {@link withoutOwnWords} takes the person's words out of the events before a view keeps them.
14
+ */
15
+ /** The core's tool name (`ASK_USER_TOOL`). */
16
+ declare const ASK_USER_TOOL_NAME = "ask_user";
17
+ /** The core's default for `askUser.timeoutMs` (`ASK_USER_TIMEOUT_MS`). */
18
+ declare const QUESTION_TIMEOUT_MS = 300000;
19
+ /**
20
+ * A question waiting for the person: the core's request (the question and every option are the
21
+ * MODEL's text, cleaned - show them as plain text), and when the core stops waiting for it.
22
+ */
23
+ interface PendingQuestion extends AskUserRequest {
24
+ /** Epoch ms after which the core answers it by itself ("did not answer in time"); absent: no limit. */
25
+ expiresAt?: number;
26
+ }
27
+ /**
28
+ * How long the core waits for an answer with this `askUser`; `undefined` = no limit of its own
29
+ * (`0`, `Infinity`, more than a timer holds - the core's own rules).
30
+ */
31
+ declare const questionTimeoutOf: (askUser: boolean | AskUserConfig | undefined) => number | undefined;
32
+ /**
33
+ * `config.askUser` as `useAgent` builds the agent with it: on without a handler of its own
34
+ * (`true`, `{ timeoutMs, maxPerRun }`) it gets `handler`; a host's own `onQuestion` wins, and off
35
+ * (absent, `false`) stays off - nothing is added, so the core mounts no tool.
36
+ */
37
+ declare const askUserWith: (askUser: boolean | AskUserConfig | undefined, handler: AskUserHandler) => boolean | AskUserConfig | undefined;
38
+ interface QuestionQueueOptions {
39
+ /**
40
+ * How long the core waits (ms), for `expiresAt`; `undefined` = no limit. A function is read when
41
+ * a question arrives (the settings of the agent that asks).
42
+ */
43
+ timeoutMs?: number | (() => number | undefined);
44
+ /** Called whenever the list of waiting questions changed. */
45
+ onChange?: (pending: PendingQuestion[]) => void;
46
+ /** The clock (tests). */
47
+ now?: () => number;
48
+ }
49
+ interface QuestionQueue {
50
+ /** The core's `askUser.onQuestion`: resolves when the person answers, or as `{ declined: true }`. */
51
+ handler: (request: AskUserRequest, ctx?: AskUserContext) => Promise<AskUserAnswer>;
52
+ /** The questions waiting, oldest first. */
53
+ pending: () => PendingQuestion[];
54
+ /** Answer one. False when no such question is waiting (answered, expired, cancelled). */
55
+ answer: (id: string, answer: AskUserAnswer) => boolean;
56
+ /**
57
+ * Take the waiting questions down - all of them, or those `match` picks - as declined (the run
58
+ * ended, it was stopped). The core has usually stopped waiting already; this only makes sure no
59
+ * resolver is left.
60
+ */
61
+ cancel: (match?: (question: PendingQuestion) => boolean) => void;
62
+ /** Cancel everything and stop reporting: the owner is gone. A later question is declined at once. */
63
+ dispose: () => void;
64
+ }
65
+ /**
66
+ * The questions the model is waiting on: `request.id → resolver`. A question leaves the queue
67
+ * exactly once - answered by the person, dropped because the core no longer wants the answer
68
+ * (`ctx.signal`: its time ran out, the run stopped), or cancelled by its owner (the run ended, an
69
+ * unmount) - and the queue never holds an answer: `answer` passes it straight to the resolver.
70
+ */
71
+ declare const createQuestionQueue: (options?: QuestionQueueOptions) => QuestionQueue;
72
+ /**
73
+ * Why a question ended without the person deciding: the core's `AskUserReason`
74
+ * (`handler-error`, `invalid-answer`, `cannot-park`), or its action (`timeout`, `stopped`).
75
+ */
76
+ type QuestionOutcomeReason = 'timeout' | 'stopped' | 'handler-error' | 'invalid-answer' | 'cannot-park';
77
+ /**
78
+ * The person's picks as the core's answer: the labels that were offered, in the order they were
79
+ * offered, each once - and one only unless the question allows several. `undefined` when nothing
80
+ * that was offered is picked (Send stays off).
81
+ */
82
+ declare const questionChoiceOf: (question: Pick<AskUserRequest, "options" | "multiple">, picked: readonly string[]) => AskUserAnswer | undefined;
83
+ /**
84
+ * The person's own words as the core's answer, when the question allows them and there is
85
+ * anything but spaces; `undefined` otherwise (Send stays off). The text goes to the caller only.
86
+ */
87
+ declare const questionOtherOf: (question: Pick<AskUserRequest, "allowOther">, text: string) => AskUserAnswer | undefined;
88
+ /** Whether an `ask_user` result may be kept by a view: it holds no word the person typed. */
89
+ declare const askUserOutputKept: (output: unknown, ok: boolean) => boolean;
90
+ /**
91
+ * The event with the person's own words taken out: the result of an `ask_user` call that is not
92
+ * known to hold labels only (an answer in their own words) loses its `output` - in
93
+ * `step.tool-result`, in `step.complete`'s tool calls, and in a subagent's events at any depth.
94
+ * Everything else comes back as it was (the same object). The model was given the words; the
95
+ * view, the saved chat and the event log are not.
96
+ */
97
+ declare const withoutOwnWords: (event: AgentEvent) => AgentEvent;
98
+
99
+ export { ASK_USER_TOOL_NAME as A, QUESTION_TIMEOUT_MS as a, askUserOutputKept as d, askUserWith as e, createQuestionQueue as f, questionOtherOf as g, questionTimeoutOf as h, questionChoiceOf as q, withoutOwnWords as w };
100
+ export type { PendingQuestion as P, QuestionOutcomeReason as Q, QuestionQueue as b, QuestionQueueOptions as c };