@xyne/workflow-sdk 3.2.47 → 3.2.49

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 (178) hide show
  1. package/dist/agents/host-agent-step.d.ts +2 -2
  2. package/dist/client/index.d.ts +1 -1
  3. package/dist/client/index.d.ts.map +1 -1
  4. package/dist/client/types.d.ts +46 -34
  5. package/dist/client/types.d.ts.map +1 -1
  6. package/dist/client/workflow-client.d.ts +1 -1
  7. package/dist/client/workflow-client.d.ts.map +1 -1
  8. package/dist/client/workflow-client.js +34 -30
  9. package/dist/client/workflow-client.js.map +1 -1
  10. package/dist/connectors/builtin/steps/classifier-agent.step.d.ts +2 -2
  11. package/dist/connectors/builtin/steps/parallel.step.d.ts +4 -4
  12. package/dist/connectors/builtin/steps/wait.step.d.ts +28 -0
  13. package/dist/connectors/builtin/steps/wait.step.d.ts.map +1 -1
  14. package/dist/connectors/builtin/steps/wait.step.js +26 -1
  15. package/dist/connectors/builtin/steps/wait.step.js.map +1 -1
  16. package/dist/conversational-flow/calls.d.ts +20 -0
  17. package/dist/conversational-flow/calls.d.ts.map +1 -0
  18. package/dist/conversational-flow/calls.js +59 -0
  19. package/dist/conversational-flow/calls.js.map +1 -0
  20. package/dist/conversational-flow/conditions.d.ts +24 -0
  21. package/dist/conversational-flow/conditions.d.ts.map +1 -0
  22. package/dist/conversational-flow/conditions.js +69 -0
  23. package/dist/conversational-flow/conditions.js.map +1 -0
  24. package/dist/conversational-flow/create.d.ts +23 -18
  25. package/dist/conversational-flow/create.d.ts.map +1 -1
  26. package/dist/conversational-flow/create.js +73 -96
  27. package/dist/conversational-flow/create.js.map +1 -1
  28. package/dist/conversational-flow/edit/build.d.ts +112 -0
  29. package/dist/conversational-flow/edit/build.d.ts.map +1 -0
  30. package/dist/conversational-flow/edit/build.js +249 -0
  31. package/dist/conversational-flow/edit/build.js.map +1 -0
  32. package/dist/conversational-flow/edit/calls.d.ts +61 -0
  33. package/dist/conversational-flow/edit/calls.d.ts.map +1 -0
  34. package/dist/conversational-flow/edit/calls.js +296 -0
  35. package/dist/conversational-flow/edit/calls.js.map +1 -0
  36. package/dist/conversational-flow/edit/cases.d.ts +29 -0
  37. package/dist/conversational-flow/edit/cases.d.ts.map +1 -0
  38. package/dist/conversational-flow/edit/cases.js +83 -0
  39. package/dist/conversational-flow/edit/cases.js.map +1 -0
  40. package/dist/conversational-flow/edit/endings.d.ts +16 -0
  41. package/dist/conversational-flow/edit/endings.d.ts.map +1 -0
  42. package/dist/conversational-flow/edit/endings.js +53 -0
  43. package/dist/conversational-flow/edit/endings.js.map +1 -0
  44. package/dist/conversational-flow/edit/followups.d.ts +28 -0
  45. package/dist/conversational-flow/edit/followups.d.ts.map +1 -0
  46. package/dist/conversational-flow/edit/followups.js +103 -0
  47. package/dist/conversational-flow/edit/followups.js.map +1 -0
  48. package/dist/conversational-flow/edit/inputs.d.ts +24 -0
  49. package/dist/conversational-flow/edit/inputs.d.ts.map +1 -0
  50. package/dist/conversational-flow/edit/inputs.js +53 -0
  51. package/dist/conversational-flow/edit/inputs.js.map +1 -0
  52. package/dist/conversational-flow/edit/kinds.d.ts +29 -0
  53. package/dist/conversational-flow/edit/kinds.d.ts.map +1 -0
  54. package/dist/conversational-flow/edit/kinds.js +142 -0
  55. package/dist/conversational-flow/edit/kinds.js.map +1 -0
  56. package/dist/conversational-flow/edit/options.d.ts +68 -0
  57. package/dist/conversational-flow/edit/options.d.ts.map +1 -0
  58. package/dist/conversational-flow/edit/options.js +209 -0
  59. package/dist/conversational-flow/edit/options.js.map +1 -0
  60. package/dist/conversational-flow/edit/picklist.d.ts +28 -0
  61. package/dist/conversational-flow/edit/picklist.d.ts.map +1 -0
  62. package/dist/conversational-flow/edit/picklist.js +58 -0
  63. package/dist/conversational-flow/edit/picklist.js.map +1 -0
  64. package/dist/conversational-flow/edit/prompts.d.ts +24 -0
  65. package/dist/conversational-flow/edit/prompts.d.ts.map +1 -0
  66. package/dist/conversational-flow/edit/prompts.js +180 -0
  67. package/dist/conversational-flow/edit/prompts.js.map +1 -0
  68. package/dist/conversational-flow/edit/routers.d.ts +65 -0
  69. package/dist/conversational-flow/edit/routers.d.ts.map +1 -0
  70. package/dist/conversational-flow/edit/routers.js +208 -0
  71. package/dist/conversational-flow/edit/routers.js.map +1 -0
  72. package/dist/conversational-flow/edit/screens.d.ts +44 -0
  73. package/dist/conversational-flow/edit/screens.d.ts.map +1 -0
  74. package/dist/conversational-flow/edit/screens.js +137 -0
  75. package/dist/conversational-flow/edit/screens.js.map +1 -0
  76. package/dist/conversational-flow/edit/versions.d.ts +43 -0
  77. package/dist/conversational-flow/edit/versions.d.ts.map +1 -0
  78. package/dist/conversational-flow/edit/versions.js +189 -0
  79. package/dist/conversational-flow/edit/versions.js.map +1 -0
  80. package/dist/conversational-flow/index.d.ts +33 -16
  81. package/dist/conversational-flow/index.d.ts.map +1 -1
  82. package/dist/conversational-flow/index.js +42 -9
  83. package/dist/conversational-flow/index.js.map +1 -1
  84. package/dist/conversational-flow/json.d.ts +15 -0
  85. package/dist/conversational-flow/json.d.ts.map +1 -0
  86. package/dist/conversational-flow/json.js +14 -0
  87. package/dist/conversational-flow/json.js.map +1 -0
  88. package/dist/conversational-flow/jumps.d.ts +22 -0
  89. package/dist/conversational-flow/jumps.d.ts.map +1 -0
  90. package/dist/conversational-flow/jumps.js +160 -0
  91. package/dist/conversational-flow/jumps.js.map +1 -0
  92. package/dist/conversational-flow/locate.d.ts +30 -0
  93. package/dist/conversational-flow/locate.d.ts.map +1 -0
  94. package/dist/conversational-flow/locate.js +73 -0
  95. package/dist/conversational-flow/locate.js.map +1 -0
  96. package/dist/conversational-flow/paths.d.ts +31 -0
  97. package/dist/conversational-flow/paths.d.ts.map +1 -0
  98. package/dist/conversational-flow/paths.js +50 -0
  99. package/dist/conversational-flow/paths.js.map +1 -0
  100. package/dist/conversational-flow/prompt.d.ts +48 -0
  101. package/dist/conversational-flow/prompt.d.ts.map +1 -0
  102. package/dist/conversational-flow/prompt.js +161 -0
  103. package/dist/conversational-flow/prompt.js.map +1 -0
  104. package/dist/conversational-flow/read.d.ts +9 -17
  105. package/dist/conversational-flow/read.d.ts.map +1 -1
  106. package/dist/conversational-flow/read.js +217 -384
  107. package/dist/conversational-flow/read.js.map +1 -1
  108. package/dist/conversational-flow/rounds.d.ts +29 -0
  109. package/dist/conversational-flow/rounds.d.ts.map +1 -0
  110. package/dist/conversational-flow/rounds.js +41 -0
  111. package/dist/conversational-flow/rounds.js.map +1 -0
  112. package/dist/conversational-flow/routers.d.ts +24 -80
  113. package/dist/conversational-flow/routers.d.ts.map +1 -1
  114. package/dist/conversational-flow/routers.js +76 -262
  115. package/dist/conversational-flow/routers.js.map +1 -1
  116. package/dist/conversational-flow/server/conversation-service.d.ts +46 -18
  117. package/dist/conversational-flow/server/conversation-service.d.ts.map +1 -1
  118. package/dist/conversational-flow/server/conversation-service.js +56 -18
  119. package/dist/conversational-flow/server/conversation-service.js.map +1 -1
  120. package/dist/conversational-flow/server/routes.d.ts +15 -6
  121. package/dist/conversational-flow/server/routes.d.ts.map +1 -1
  122. package/dist/conversational-flow/server/routes.js +71 -74
  123. package/dist/conversational-flow/server/routes.js.map +1 -1
  124. package/dist/conversational-flow/settle.d.ts +21 -15
  125. package/dist/conversational-flow/settle.d.ts.map +1 -1
  126. package/dist/conversational-flow/settle.js +240 -38
  127. package/dist/conversational-flow/settle.js.map +1 -1
  128. package/dist/conversational-flow/shape.d.ts +114 -0
  129. package/dist/conversational-flow/shape.d.ts.map +1 -0
  130. package/dist/conversational-flow/shape.js +209 -0
  131. package/dist/conversational-flow/shape.js.map +1 -0
  132. package/dist/conversational-flow/testing.d.ts +54 -0
  133. package/dist/conversational-flow/testing.d.ts.map +1 -0
  134. package/dist/conversational-flow/testing.js +119 -0
  135. package/dist/conversational-flow/testing.js.map +1 -0
  136. package/dist/conversational-flow/tree.d.ts +28 -17
  137. package/dist/conversational-flow/tree.d.ts.map +1 -1
  138. package/dist/conversational-flow/tree.js +60 -47
  139. package/dist/conversational-flow/tree.js.map +1 -1
  140. package/dist/conversational-flow/turn.d.ts +30 -22
  141. package/dist/conversational-flow/turn.d.ts.map +1 -1
  142. package/dist/conversational-flow/turn.js +69 -48
  143. package/dist/conversational-flow/turn.js.map +1 -1
  144. package/dist/conversational-flow/types.d.ts +154 -118
  145. package/dist/conversational-flow/types.d.ts.map +1 -1
  146. package/dist/conversational-flow/types.js +27 -51
  147. package/dist/conversational-flow/types.js.map +1 -1
  148. package/dist/conversational-flow/typing.d.ts +31 -0
  149. package/dist/conversational-flow/typing.d.ts.map +1 -0
  150. package/dist/conversational-flow/typing.js +53 -0
  151. package/dist/conversational-flow/typing.js.map +1 -0
  152. package/dist/engine/variable-resolver.d.ts +16 -0
  153. package/dist/engine/variable-resolver.d.ts.map +1 -1
  154. package/dist/engine/variable-resolver.js +45 -1
  155. package/dist/engine/variable-resolver.js.map +1 -1
  156. package/dist/types/pause-state.d.ts +9 -0
  157. package/dist/types/pause-state.d.ts.map +1 -1
  158. package/package.json +1 -1
  159. package/dist/conversational-flow/edit.d.ts +0 -101
  160. package/dist/conversational-flow/edit.d.ts.map +0 -1
  161. package/dist/conversational-flow/edit.js +0 -785
  162. package/dist/conversational-flow/edit.js.map +0 -1
  163. package/dist/conversational-flow/internals.d.ts +0 -51
  164. package/dist/conversational-flow/internals.d.ts.map +0 -1
  165. package/dist/conversational-flow/internals.js +0 -163
  166. package/dist/conversational-flow/internals.js.map +0 -1
  167. package/dist/conversational-flow/lookup-edit.d.ts +0 -96
  168. package/dist/conversational-flow/lookup-edit.d.ts.map +0 -1
  169. package/dist/conversational-flow/lookup-edit.js +0 -266
  170. package/dist/conversational-flow/lookup-edit.js.map +0 -1
  171. package/dist/conversational-flow/lookups.d.ts +0 -46
  172. package/dist/conversational-flow/lookups.d.ts.map +0 -1
  173. package/dist/conversational-flow/lookups.js +0 -145
  174. package/dist/conversational-flow/lookups.js.map +0 -1
  175. package/dist/conversational-flow/router-edit.d.ts +0 -53
  176. package/dist/conversational-flow/router-edit.d.ts.map +0 -1
  177. package/dist/conversational-flow/router-edit.js +0 -191
  178. package/dist/conversational-flow/router-edit.js.map +0 -1
@@ -1,67 +1,80 @@
1
+ /**
2
+ * The tree, now that the config is one: walking it is walking the screens'
3
+ * `parent` and `children`, which the reader took from where their cases sit.
4
+ */
1
5
  import { optionsOf } from './types.js';
2
- /** Children of each screen, in the order the router lists them. */
6
+ /** A screen's ancestors, nearest first. */
7
+ export function ancestorsOf(flow, id) {
8
+ const parent = new Map(flow.screens.map((s) => [s.id, s.parent]));
9
+ const out = [];
10
+ for (let at = parent.get(id); at !== undefined; at = parent.get(at))
11
+ out.push(at);
12
+ return out;
13
+ }
14
+ /** A screen and everything under it, in the order the switches list them. */
15
+ /**
16
+ * Outside the menu: a router, an ending, a hand off.
17
+ *
18
+ * Every screen can lead to one, so where they sit in the config says nothing
19
+ * about where they belong in the menu — which is why the map draws them apart
20
+ * rather than as children of whichever frame happens to hold them.
21
+ */
22
+ export function outsideMenu(screen) {
23
+ return screen.kind === 'router' || screen.kind === 'end' || screen.kind === 'handoff';
24
+ }
25
+ /**
26
+ * The screens inside each screen, in the order its switch lists them — the same
27
+ * `children` every screen already carries, gathered once for drawing the tree.
28
+ */
3
29
  export function childrenOf(flow) {
30
+ const byId = new Map(flow.screens.map((s) => [s.id, s]));
4
31
  const out = new Map();
5
- for (const s of flow.screens) {
6
- if (s.parent === undefined)
7
- continue;
8
- const list = out.get(s.parent) ?? [];
9
- list.push(s);
10
- out.set(s.parent, list);
32
+ for (const screen of flow.screens) {
33
+ const kids = screen.children.map((id) => byId.get(id)).filter((s) => s !== undefined);
34
+ if (kids.length > 0)
35
+ out.set(screen.id, kids);
11
36
  }
12
37
  return out;
13
38
  }
14
- /** Menu screens depth-first from the root, the way an outline reads. */
15
- export function treeOrder(flow) {
16
- const children = childrenOf(flow);
17
- const root = flow.screens.find((s) => s.id === flow.rootScreen);
39
+ export function subtreeOf(flow, id) {
40
+ const byId = new Map(flow.screens.map((s) => [s.id, s]));
18
41
  const out = [];
19
- const visit = (s) => {
20
- out.push(s);
21
- for (const c of children.get(s.id) ?? [])
22
- visit(c);
42
+ const visit = (at) => {
43
+ out.push(at);
44
+ for (const child of byId.get(at)?.children ?? [])
45
+ visit(child);
23
46
  };
24
- if (root && root.depth === 0)
25
- visit(root);
47
+ visit(id);
26
48
  return out;
27
49
  }
28
- /** Screens outside the menu tree: routers, ends, and anything no option reaches. */
29
- export function outsideTree(flow) {
30
- return flow.screens.filter((s) => s.depth === -1);
31
- }
32
- /** Ids of a screen's ancestors, nearest first. */
33
- export function ancestorsOf(flow, id) {
34
- const parent = new Map(flow.screens.map((s) => [s.id, s.parent]));
35
- const out = [];
36
- for (let at = parent.get(id); at !== undefined; at = parent.get(at))
37
- out.push(at);
38
- return out;
50
+ /** Screens depth-first from the first one, the way an outline reads. */
51
+ export function treeOrder(flow) {
52
+ const byId = new Map(flow.screens.map((s) => [s.id, s]));
53
+ return subtreeOf(flow, flow.rootScreen)
54
+ .map((id) => byId.get(id))
55
+ .filter((s) => s !== undefined);
39
56
  }
40
- /** "Payments › Charges › Charged twice" — ancestors below the root, then the screen. */
57
+ /**
58
+ * "Payments › Charges › Charged twice" — how the flow words where someone is.
59
+ *
60
+ * The first screen is left out: it is the conversation, not a place inside it.
61
+ */
41
62
  export function breadcrumb(flow, screen) {
42
63
  const byId = new Map(flow.screens.map((s) => [s.id, s]));
43
- const chain = [];
44
- for (let at = screen; at; at = at.parent ? byId.get(at.parent) : undefined)
45
- chain.unshift(at);
46
- const titles = chain.filter((s) => s.id !== flow.rootScreen).map((s) => s.title);
64
+ const chain = [...[...ancestorsOf(flow, screen.id)].reverse(), screen.id];
65
+ const titles = chain.filter((id) => id !== flow.rootScreen).map((id) => byId.get(id)?.title ?? id);
47
66
  return titles.length > 0 ? titles.join(' › ') : screen.title;
48
67
  }
49
- /** How this flow words the way back to its first screen ("Main menu"), if it has one. */
68
+ /**
69
+ * How this flow words going back to the first screen — "Main menu", usually —
70
+ * taken from wherever it already says it, so nothing invents a second wording.
71
+ */
50
72
  export function mainMenuLabel(flow) {
51
- for (const s of flow.screens) {
52
- const o = optionsOf(s).find((x) => x.back && x.to.kind === 'screen' && x.to.screen === flow.rootScreen);
53
- if (o)
54
- return o.label;
73
+ for (const screen of flow.screens) {
74
+ const option = optionsOf(screen).find((o) => o.back && o.to.kind === 'screen' && o.to.screen === flow.rootScreen);
75
+ if (option)
76
+ return option.label;
55
77
  }
56
78
  return undefined;
57
79
  }
58
- /**
59
- * The screen that leads to this one, for screens the tree leaves out — a Finish
60
- * or a hand off, which every screen may link to and so has no parent of its
61
- * own. The first to link it, as the menu reads: the same rule `placeInTree`
62
- * uses for screens that are in the tree.
63
- */
64
- export function linkerOf(flow, id) {
65
- return treeOrder(flow).find((s) => optionsOf(s).some((o) => o.to.kind === 'screen' && o.to.screen === id));
66
- }
67
80
  //# sourceMappingURL=tree.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/conversational-flow/tree.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,mEAAmE;AACnE,MAAM,UAAU,UAAU,CAAC,IAAwB;IACjD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAoB,CAAC;IACxC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS;YAAE,SAAS;QACrC,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACb,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,S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nG,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAwB;IACpD,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC;QAClH,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC,KAAK,CAAC;IAClC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -2,19 +2,19 @@
2
2
  * A run seen as a conversation, one turn at a time: what the person is asked
3
3
  * now, how they can answer, and what happened since their last answer.
4
4
  *
5
- * Pure, and read entirely from the run's own step records — the paused step's
5
+ * Pure, and read entirely from the run's own records — the paused step's
6
6
  * `pauseState` (its prompt and form), a pending `resumePayload` (a reply given
7
- * but not yet applied), a WAIT's recorded `resumeData`, the router's response,
8
- * the CYCLE's result. A turn is identified by the paused step's node path, so
9
- * answering it is an ordinary resume of that step.
7
+ * but not yet applied), a WAIT's recorded `resumeData`, a router's response, the
8
+ * conversation's own result. A turn is identified by the paused step's node
9
+ * path, so answering it is an ordinary resume of that step.
10
10
  *
11
11
  * Works for any workflow that pauses with a form. A conversational flow also
12
- * gets its screens: where the person is, which options lead back or finish, and
13
- * how typed text was routed.
12
+ * gets its screens — and because the config is the tree, a record's path says
13
+ * which screen it belongs to (`paths.ts`), however many frames deep it ran.
14
14
  */
15
15
  import type { WorkflowConfig } from '../types/workflow-config.js';
16
16
  import type { BusEvent } from '../events/types.js';
17
- import type { ConversationalFlow, ScreenKind } from './types.js';
17
+ import { type ConversationalFlow, type ScreenKind } from './types.js';
18
18
  /**
19
19
  * `handed_off`: a person has the conversation, in the integrator's own system.
20
20
  * The turn stays open until they are done: answering it with a Finish closes
@@ -23,10 +23,10 @@ import type { ConversationalFlow, ScreenKind } from './types.js';
23
23
  export type TurnStatus = 'awaiting_reply' | 'working' | 'finished' | 'handed_off' | 'failed' | 'ended';
24
24
  export interface TurnMessage {
25
25
  role: 'assistant';
26
- /** `agent` when an agent wrote it (Ask AI); `flow` when the author did. */
26
+ /** `agent` when an agent wrote it; `flow` when the author did. */
27
27
  source: 'flow' | 'agent';
28
28
  text: string;
29
- /** The heading the flow shows above it, e.g. "Payments › Charges". */
29
+ /** The heading shown above it, e.g. "Payments › Charges". */
30
30
  header?: string;
31
31
  }
32
32
  export interface TurnOption {
@@ -63,6 +63,14 @@ export type TurnEvent = {
63
63
  confidence?: number;
64
64
  by?: string;
65
65
  }
66
+ /** Something was fetched on the way in. */
67
+ | {
68
+ type: 'looked_up';
69
+ name: string;
70
+ ok: boolean;
71
+ status?: number;
72
+ ms?: number;
73
+ }
66
74
  /** The person who had it was done: sent back to a screen, or closed at a Finish. */
67
75
  | {
68
76
  type: 'handed_back';
@@ -78,7 +86,6 @@ export interface TurnScreen {
78
86
  }
79
87
  /** A conversation passed to a person: what happened until then, for whoever takes it. */
80
88
  export interface TurnHandoff {
81
- /** Everything asked and answered — the same entries as the transcript. */
82
89
  context: TranscriptEntry[];
83
90
  }
84
91
  export interface Turn {
@@ -126,13 +133,9 @@ export interface TurnAnswer {
126
133
  values?: Record<string, unknown>;
127
134
  }
128
135
  /**
129
- * What `GET /conversations/:id/stream` sends. A `turn` when you connect and each
130
- * time the conversation moves on; in between, what is happening now.
131
- *
132
- * `text`, `thinking` and `tool` come from agents that report as they work, and
133
- * are a preview only: the next `turn` always carries the finished message, so a
134
- * client that ignores them loses nothing. The AI router's own output is never
135
- * streamed — it is the flow's decision, not something to show the person.
136
+ * What the conversation's stream sends: a `turn` on connecting and each time it
137
+ * moves on, and in between what is happening now. The previews are a preview
138
+ * only — the next `turn` always carries the finished message.
136
139
  */
137
140
  export type ConversationStreamEvent = {
138
141
  type: 'turn';
@@ -151,6 +154,16 @@ export type ConversationStreamEvent = {
151
154
  type: 'tool';
152
155
  tool: string;
153
156
  phase: 'start' | 'end';
157
+ }
158
+ /**
159
+ * Something went wrong after the stream had already answered 200. A status
160
+ * code is no longer available, so a failure says so in the stream itself —
161
+ * and a client that handles every event handles this one too.
162
+ */
163
+ | {
164
+ type: 'error';
165
+ code: string;
166
+ message: string;
154
167
  };
155
168
  /** The answer doesn't fit what the turn asks for. */
156
169
  export declare class TurnAnswerError extends Error {
@@ -184,11 +197,6 @@ export declare function streamEventOf(event: BusEvent, flow: ConversationalFlow
184
197
  /**
185
198
  * How to answer the open turn `turnId`: which step to resume, and with what.
186
199
  *
187
- * - A paused step with a form: the option goes into its select field, text into
188
- * its text field, values by name — an `approve` carrying the form.
189
- * - An agent waiting for a reply (`waitForReply`): text is the reply — the agent
190
- * continues its conversation with it; a choice ends the conversation there.
191
- *
192
200
  * Throws `TurnAnswerError` when the answer doesn't fit what is asked.
193
201
  */
194
202
  export declare function answerFor(run: RunView, turnId: string, answer: TurnAnswer): {
@@ -1 +1 @@
1
- {"version":3,"file":"turn.d.ts","sourceRoot":"","sources":["../../src/conversational-flow/turn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAKnD,OAAO,KAAK,EAAE,kBAAkB,EAAkB,UAAU,EAAE,MAAM,YAAY,CAAC;AAIjF;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEvG,M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4BAA4B;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,qGAAqG;IACrG,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;IAC9B,MAAM,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;CACrC;AAED,eAAO,MAAM,cAAc,OAAO,CAAC;AAUnC,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAoBnC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAwD3C;AAED,sDAAsD;AACtD,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAUvD;AAqBD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI,GAAG,uBAAuB,GAAG,IAAI,CAkC9G;AAID;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CA+B9G;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,GAAG,SAAS,CAuBlG"}
@@ -1,7 +1,7 @@
1
1
  import { readConversationalFlow } from './read.js';
2
- import { END_MESSAGE_KEY } from './types.js';
2
+ import { roundsIn, screenAtPath } from './paths.js';
3
3
  import { ancestorsOf } from './tree.js';
4
- import { routerName } from './types.js';
4
+ import { END_MESSAGE_KEY } from './types.js';
5
5
  /** The answer doesn't fit what the turn asks for. */
6
6
  export class TurnAnswerError extends Error {
7
7
  name = 'TurnAnswerError';
@@ -12,8 +12,6 @@ const WAITING = new Set(['EXTERNAL_WAIT', 'REVIEW_WAIT']);
12
12
  /** `<node path>#t<turn>` — one turn of an agent step's conversation (`waitForReply`). */
13
13
  const CONVERSATION_TURN = /^(.*)#t(\d+)$/;
14
14
  const TERMINAL = { COMPLETED: 'finished', FAILED: 'failed', CANCELLED: 'ended' };
15
- /** `<cycle>:body#<round>/<switch>:case_<n>/…/<step>` — a step inside one screen's case. */
16
- const IN_SCREEN = /^([^:/]+):body#\d+\/[^:/]+:case_(\d+)(?:#\d+)?\/(.+)$/;
17
15
  // ─── Reading ───
18
16
  export function readTurn(run) {
19
17
  const flow = run.config ? readConversationalFlow(run.config) : null;
@@ -109,18 +107,23 @@ const QUIET_STEPS = new Set(['CYCLE', 'SWITCH', 'CONDITIONAL', 'GO_TO', 'FINISH'
109
107
  export function streamEventOf(event, flow) {
110
108
  const routers = new Map((flow?.screens ?? []).filter((s) => s.router).map((s) => [s.router.stepId, s]));
111
109
  const askAi = (stepId) => flow?.screens.find((s) => s.askAi?.stepId === stepId);
110
+ const fetching = (stepId) => flow?.screens.flatMap((s) => s.calls).find((c) => c.id === stepId);
112
111
  if (event.event === 'step_started') {
113
112
  const { stepName, stepType } = event.data;
114
- const routing = routers.get(stepName);
113
+ const step = lastSegment(stepName);
114
+ const routing = routers.get(step);
115
115
  if (routing)
116
- return { type: 'working', kind: 'router', step: stepName, title: routerName(routing.router) };
117
- const screen = askAi(stepName);
116
+ return { type: 'working', kind: 'router', step, title: routing.title };
117
+ const screen = askAi(step);
118
118
  if (screen)
119
- return { type: 'working', kind: 'agent', step: stepName, title: screen.title };
120
- return QUIET_STEPS.has(stepType) ? null : { type: 'working', kind: 'step', step: stepName };
119
+ return { type: 'working', kind: 'agent', step, title: screen.title };
120
+ const call = fetching(step);
121
+ if (call)
122
+ return { type: 'working', kind: 'step', step, title: call.title };
123
+ return QUIET_STEPS.has(stepType) ? null : { type: 'working', kind: 'step', step };
121
124
  }
122
125
  if (event.event === 'step_progress') {
123
- if (routers.has(event.data.stepName))
126
+ if (routers.has(lastSegment(event.data.stepName)))
124
127
  return null;
125
128
  const payload = rec(event.data['payload']);
126
129
  switch (event.data['type']) {
@@ -142,11 +145,6 @@ export function streamEventOf(event, flow) {
142
145
  /**
143
146
  * How to answer the open turn `turnId`: which step to resume, and with what.
144
147
  *
145
- * - A paused step with a form: the option goes into its select field, text into
146
- * its text field, values by name — an `approve` carrying the form.
147
- * - An agent waiting for a reply (`waitForReply`): text is the reply — the agent
148
- * continues its conversation with it; a choice ends the conversation there.
149
- *
150
148
  * Throws `TurnAnswerError` when the answer doesn't fit what is asked.
151
149
  */
152
150
  export function answerFor(run, turnId, answer) {
@@ -204,10 +202,8 @@ export function answeredWith(run, turnId, answer) {
204
202
  if (state['turn'] === turn && pending) {
205
203
  return answer.choice !== undefined ? rec(pending['data'])['choice'] === answer.choice : pending['feedback'] === answer.text;
206
204
  }
207
- // The reply that opened the next turn was this answer.
208
205
  if (state['turn'] === turn + 1)
209
206
  return answer.choice === undefined && state['reply'] === answer.text;
210
- // The conversation ended on this choice.
211
207
  if (step.status === 'COMPLETED')
212
208
  return rec(data['output'])['choice'] === answer.choice;
213
209
  return undefined;
@@ -222,29 +218,34 @@ export function answeredWith(run, turnId, answer) {
222
218
  function turnIdOf(row) {
223
219
  return row.conversation ? `${row.step.stepName}#t${String(row.conversation.turn)}` : row.step.stepName;
224
220
  }
225
- /** What a step answered, as text: an agent's `response`, when it is text. */
226
221
  function answerText(data) {
227
222
  return str(rec(data['output'])['response']);
228
223
  }
229
224
  // ─── Rows ───
230
225
  /**
231
- * `…body#<round>/…` — which round of a CYCLE a record belongs to. Hosts don't
232
- * promise to return records in the order they were written, so the order of the
233
- * conversation is rebuilt from the paths themselves: by round, then shallower
234
- * before deeper (a follow-up question sits inside the question it follows).
226
+ * The run in the order it happened.
227
+ *
228
+ * Hosts don't promise to return records in the order they were written, so the
229
+ * order is rebuilt from the paths: by the rounds they ran in, outermost first —
230
+ * round 2 of the conversation is after round 1 whatever happened inside either —
231
+ * and then shallower before deeper, so a question comes before what it opened.
235
232
  */
236
- const ROUND = /:body#(\d+)\//;
237
233
  function chronological(steps) {
238
- const key = (s) => {
239
- const round = ROUND.exec(s.stepName);
240
- return { round: round ? Number(round[1]) : -1, depth: s.stepName.split('/').length };
241
- };
242
234
  return steps
243
- .map((step, i) => ({ step, i, ...key(step) }))
244
- .sort((a, b) => a.round - b.round || a.depth - b.depth || a.i - b.i)
235
+ .map((step, i) => ({ step, i, rounds: roundsIn(step.stepName), depth: step.stepName.split('/').length }))
236
+ .sort((a, b) => compare(a.rounds, b.rounds) || a.depth - b.depth || a.i - b.i)
245
237
  .map((x) => x.step);
246
238
  }
239
+ function compare(a, b) {
240
+ for (let at = 0; at < Math.max(a.length, b.length); at += 1) {
241
+ const difference = (a[at] ?? -1) - (b[at] ?? -1);
242
+ if (difference !== 0)
243
+ return difference;
244
+ }
245
+ return 0;
246
+ }
247
247
  function readRows(run, flow) {
248
+ const config = run.config;
248
249
  return chronological(run.steps).map((step, index) => {
249
250
  const data = parse(step.data);
250
251
  const pause = rec(data['pauseState']);
@@ -257,22 +258,26 @@ function readRows(run, flow) {
257
258
  ...(typeof conversation['reply'] === 'string' ? { reply: conversation['reply'] } : {}),
258
259
  };
259
260
  }
260
- const m = flow ? IN_SCREEN.exec(step.stepName) : null;
261
- if (flow && m && m[1] === flow.cycleId) {
262
- const screen = flow.screens[Number(m[2])];
263
- if (screen) {
264
- const stepId = m[3].split('/').pop().replace(/#\d+$/, '').replace(/^.*:/, '');
265
- row.screen = screen;
266
- row.stepId = stepId;
267
- const prompt = screen.prompts.find((p) => p.id === stepId);
268
- if (prompt)
269
- row.prompt = prompt;
270
- row.askAi = screen.askAi?.stepId === stepId;
271
- }
261
+ const screen = flow && config ? screenAtPath(config, flow, step.stepName) : undefined;
262
+ if (screen) {
263
+ const stepId = lastSegment(step.stepName);
264
+ row.screen = screen;
265
+ row.stepId = stepId;
266
+ const prompt = screen.prompts.find((p) => p.id === stepId);
267
+ if (prompt)
268
+ row.prompt = prompt;
269
+ const call = screen.calls.find((c) => c.id === stepId);
270
+ if (call)
271
+ row.call = call;
272
+ row.askAi = screen.askAi?.stepId === stepId;
272
273
  }
273
274
  return row;
274
275
  });
275
276
  }
277
+ /** The step's own id, out of the path that says where it ran. */
278
+ function lastSegment(nodePath) {
279
+ return nodePath.split('/').pop().replace(/#\d+$/, '').replace(/^.*:/, '');
280
+ }
276
281
  /** A step that can itself be answered — not a control step marking the way to one. */
277
282
  function isGate(row) {
278
283
  return row.step.executorType !== 'conditional';
@@ -319,6 +324,19 @@ function rowEvents(row, flow) {
319
324
  out.push({ type: 'tapped', optionId: picked, label: row.prompt.options.find((o) => o.value === picked)?.label ?? picked });
320
325
  }
321
326
  }
327
+ if (row.call && row.step.status !== 'RUNNING') {
328
+ // A call that never came back has no output at all; that is what `ok` says.
329
+ const output = rec(row.data['output']);
330
+ const status = typeof output['status'] === 'number' ? output['status'] : undefined;
331
+ const ms = typeof output['duration'] === 'number' ? output['duration'] : undefined;
332
+ out.push({
333
+ type: 'looked_up',
334
+ name: row.call.title,
335
+ ok: output['ok'] === true,
336
+ ...(status !== undefined ? { status } : {}),
337
+ ...(ms !== undefined ? { ms } : {}),
338
+ });
339
+ }
322
340
  if (row.screen.router?.stepId === row.stepId && row.step.status === 'COMPLETED') {
323
341
  // An agent answers `{ screen, reason }`; a classifier answers a class and how sure it was.
324
342
  const output = rec(row.data['output']);
@@ -327,15 +345,14 @@ function rowEvents(row, flow) {
327
345
  const reason = str(response['reason']);
328
346
  const confidence = typeof output['confidence'] === 'number' ? output['confidence'] : undefined;
329
347
  const title = to ? flow.screens.find((s) => s.id === to)?.title : undefined;
330
- // Which router chose, since a flow may have one per section.
331
- const by = row.screen.title;
332
348
  out.push({
333
349
  type: 'routed',
334
350
  ...(to ? { to } : {}),
335
351
  ...(title ? { title } : {}),
336
352
  ...(reason ? { reason } : {}),
337
353
  ...(confidence !== undefined ? { confidence } : {}),
338
- ...(by ? { by } : {}),
354
+ // Which router chose, since a flow may have one per section.
355
+ by: row.screen.title,
339
356
  });
340
357
  }
341
358
  return out;
@@ -353,14 +370,16 @@ function conversationEvents(row) {
353
370
  /** The answer a step holds: given and waiting to be applied, or applied and recorded. */
354
371
  function recordedAnswer(data) {
355
372
  const pending = data['resumePayload'];
356
- if (pending !== undefined)
373
+ if (pending !== undefined) {
357
374
  return { ...rec(rec(pending)['data']), ...(typeof rec(pending)['feedback'] === 'string' ? { feedback: rec(pending)['feedback'] } : {}) };
375
+ }
358
376
  const output = rec(data['output']);
359
377
  if (typeof output['choice'] === 'string')
360
378
  return { choice: output['choice'] };
361
379
  const applied = output['resumeData'];
362
380
  return applied === undefined ? undefined : rec(rec(applied)['data']);
363
381
  }
382
+ const ASK_AGAIN = 'Ask something else';
364
383
  function replyOf(row, flow) {
365
384
  if (row.conversation && row.askAi && row.screen?.askAi) {
366
385
  // After an answer: leave by one of the screen's ways out, or ask again.
@@ -383,7 +402,6 @@ function replyOf(row, flow) {
383
402
  reply.fields = rest.map((f) => ({ ...f, name: String(f['name']), type: String(f['type']) }));
384
403
  return reply;
385
404
  }
386
- const ASK_AGAIN = 'Ask something else';
387
405
  function ends(flow) {
388
406
  return new Set(flow?.screens.filter((s) => s.kind === 'end').map((s) => s.id) ?? []);
389
407
  }
@@ -392,9 +410,12 @@ function screenOf(screen, flow) {
392
410
  const path = [...ancestorsOf(flow, screen.id)].reverse().map((id) => titles.get(id) ?? id);
393
411
  return { id: screen.id, title: screen.title, kind: screen.kind, path: [...path, screen.title] };
394
412
  }
395
- /** The value the flow's Finish carried — the CYCLE's recorded result. */
413
+ /**
414
+ * What the conversation concluded: the value its Finish carried, recorded as the
415
+ * result of the cycle the conversation itself is.
416
+ */
396
417
  function outcomeOf(rows, flow) {
397
- const cycle = rows.find((r) => r.step.stepName === flow.cycleId);
418
+ const cycle = rows.find((r) => r.step.stepName === flow.rootScreen);
398
419
  const output = rec(cycle?.data['output']);
399
420
  return output['exit'] === 'finish' ? rec(output['result']) : undefined;
400
421
  }