@xyne/workflow-sdk 3.2.46 → 3.2.48

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 (186) hide show
  1. package/dist/agents/host-agent-step.d.ts +2 -2
  2. package/dist/connectors/builtin/steps/classifier-agent.step.d.ts +2 -2
  3. package/dist/connectors/builtin/steps/map.step.d.ts +15 -4
  4. package/dist/connectors/builtin/steps/map.step.d.ts.map +1 -1
  5. package/dist/connectors/builtin/steps/map.step.js +51 -18
  6. package/dist/connectors/builtin/steps/map.step.js.map +1 -1
  7. package/dist/connectors/builtin/steps/parallel.step.d.ts +4 -4
  8. package/dist/connectors/builtin/steps/wait.step.d.ts +28 -0
  9. package/dist/connectors/builtin/steps/wait.step.d.ts.map +1 -1
  10. package/dist/connectors/builtin/steps/wait.step.js +26 -1
  11. package/dist/connectors/builtin/steps/wait.step.js.map +1 -1
  12. package/dist/conversational-flow/calls.d.ts +20 -0
  13. package/dist/conversational-flow/calls.d.ts.map +1 -0
  14. package/dist/conversational-flow/calls.js +59 -0
  15. package/dist/conversational-flow/calls.js.map +1 -0
  16. package/dist/conversational-flow/conditions.d.ts +24 -0
  17. package/dist/conversational-flow/conditions.d.ts.map +1 -0
  18. package/dist/conversational-flow/conditions.js +69 -0
  19. package/dist/conversational-flow/conditions.js.map +1 -0
  20. package/dist/conversational-flow/create.d.ts +23 -18
  21. package/dist/conversational-flow/create.d.ts.map +1 -1
  22. package/dist/conversational-flow/create.js +73 -96
  23. package/dist/conversational-flow/create.js.map +1 -1
  24. package/dist/conversational-flow/edit/build.d.ts +112 -0
  25. package/dist/conversational-flow/edit/build.d.ts.map +1 -0
  26. package/dist/conversational-flow/edit/build.js +249 -0
  27. package/dist/conversational-flow/edit/build.js.map +1 -0
  28. package/dist/conversational-flow/edit/calls.d.ts +61 -0
  29. package/dist/conversational-flow/edit/calls.d.ts.map +1 -0
  30. package/dist/conversational-flow/edit/calls.js +296 -0
  31. package/dist/conversational-flow/edit/calls.js.map +1 -0
  32. package/dist/conversational-flow/edit/cases.d.ts +29 -0
  33. package/dist/conversational-flow/edit/cases.d.ts.map +1 -0
  34. package/dist/conversational-flow/edit/cases.js +83 -0
  35. package/dist/conversational-flow/edit/cases.js.map +1 -0
  36. package/dist/conversational-flow/edit/endings.d.ts +16 -0
  37. package/dist/conversational-flow/edit/endings.d.ts.map +1 -0
  38. package/dist/conversational-flow/edit/endings.js +53 -0
  39. package/dist/conversational-flow/edit/endings.js.map +1 -0
  40. package/dist/conversational-flow/edit/followups.d.ts +28 -0
  41. package/dist/conversational-flow/edit/followups.d.ts.map +1 -0
  42. package/dist/conversational-flow/edit/followups.js +103 -0
  43. package/dist/conversational-flow/edit/followups.js.map +1 -0
  44. package/dist/conversational-flow/edit/inputs.d.ts +24 -0
  45. package/dist/conversational-flow/edit/inputs.d.ts.map +1 -0
  46. package/dist/conversational-flow/edit/inputs.js +53 -0
  47. package/dist/conversational-flow/edit/inputs.js.map +1 -0
  48. package/dist/conversational-flow/edit/kinds.d.ts +29 -0
  49. package/dist/conversational-flow/edit/kinds.d.ts.map +1 -0
  50. package/dist/conversational-flow/edit/kinds.js +142 -0
  51. package/dist/conversational-flow/edit/kinds.js.map +1 -0
  52. package/dist/conversational-flow/edit/options.d.ts +68 -0
  53. package/dist/conversational-flow/edit/options.d.ts.map +1 -0
  54. package/dist/conversational-flow/edit/options.js +209 -0
  55. package/dist/conversational-flow/edit/options.js.map +1 -0
  56. package/dist/conversational-flow/edit/picklist.d.ts +28 -0
  57. package/dist/conversational-flow/edit/picklist.d.ts.map +1 -0
  58. package/dist/conversational-flow/edit/picklist.js +58 -0
  59. package/dist/conversational-flow/edit/picklist.js.map +1 -0
  60. package/dist/conversational-flow/edit/prompts.d.ts +24 -0
  61. package/dist/conversational-flow/edit/prompts.d.ts.map +1 -0
  62. package/dist/conversational-flow/edit/prompts.js +180 -0
  63. package/dist/conversational-flow/edit/prompts.js.map +1 -0
  64. package/dist/conversational-flow/edit/routers.d.ts +65 -0
  65. package/dist/conversational-flow/edit/routers.d.ts.map +1 -0
  66. package/dist/conversational-flow/edit/routers.js +208 -0
  67. package/dist/conversational-flow/edit/routers.js.map +1 -0
  68. package/dist/conversational-flow/edit/screens.d.ts +44 -0
  69. package/dist/conversational-flow/edit/screens.d.ts.map +1 -0
  70. package/dist/conversational-flow/edit/screens.js +137 -0
  71. package/dist/conversational-flow/edit/screens.js.map +1 -0
  72. package/dist/conversational-flow/edit/versions.d.ts +43 -0
  73. package/dist/conversational-flow/edit/versions.d.ts.map +1 -0
  74. package/dist/conversational-flow/edit/versions.js +189 -0
  75. package/dist/conversational-flow/edit/versions.js.map +1 -0
  76. package/dist/conversational-flow/index.d.ts +33 -16
  77. package/dist/conversational-flow/index.d.ts.map +1 -1
  78. package/dist/conversational-flow/index.js +42 -9
  79. package/dist/conversational-flow/index.js.map +1 -1
  80. package/dist/conversational-flow/json.d.ts +15 -0
  81. package/dist/conversational-flow/json.d.ts.map +1 -0
  82. package/dist/conversational-flow/json.js +14 -0
  83. package/dist/conversational-flow/json.js.map +1 -0
  84. package/dist/conversational-flow/jumps.d.ts +22 -0
  85. package/dist/conversational-flow/jumps.d.ts.map +1 -0
  86. package/dist/conversational-flow/jumps.js +160 -0
  87. package/dist/conversational-flow/jumps.js.map +1 -0
  88. package/dist/conversational-flow/locate.d.ts +30 -0
  89. package/dist/conversational-flow/locate.d.ts.map +1 -0
  90. package/dist/conversational-flow/locate.js +73 -0
  91. package/dist/conversational-flow/locate.js.map +1 -0
  92. package/dist/conversational-flow/paths.d.ts +31 -0
  93. package/dist/conversational-flow/paths.d.ts.map +1 -0
  94. package/dist/conversational-flow/paths.js +50 -0
  95. package/dist/conversational-flow/paths.js.map +1 -0
  96. package/dist/conversational-flow/prompt.d.ts +48 -0
  97. package/dist/conversational-flow/prompt.d.ts.map +1 -0
  98. package/dist/conversational-flow/prompt.js +161 -0
  99. package/dist/conversational-flow/prompt.js.map +1 -0
  100. package/dist/conversational-flow/read.d.ts +9 -17
  101. package/dist/conversational-flow/read.d.ts.map +1 -1
  102. package/dist/conversational-flow/read.js +217 -384
  103. package/dist/conversational-flow/read.js.map +1 -1
  104. package/dist/conversational-flow/rounds.d.ts +29 -0
  105. package/dist/conversational-flow/rounds.d.ts.map +1 -0
  106. package/dist/conversational-flow/rounds.js +41 -0
  107. package/dist/conversational-flow/rounds.js.map +1 -0
  108. package/dist/conversational-flow/routers.d.ts +24 -80
  109. package/dist/conversational-flow/routers.d.ts.map +1 -1
  110. package/dist/conversational-flow/routers.js +76 -262
  111. package/dist/conversational-flow/routers.js.map +1 -1
  112. package/dist/conversational-flow/settle.d.ts +21 -15
  113. package/dist/conversational-flow/settle.d.ts.map +1 -1
  114. package/dist/conversational-flow/settle.js +240 -38
  115. package/dist/conversational-flow/settle.js.map +1 -1
  116. package/dist/conversational-flow/shape.d.ts +114 -0
  117. package/dist/conversational-flow/shape.d.ts.map +1 -0
  118. package/dist/conversational-flow/shape.js +209 -0
  119. package/dist/conversational-flow/shape.js.map +1 -0
  120. package/dist/conversational-flow/testing.d.ts +54 -0
  121. package/dist/conversational-flow/testing.d.ts.map +1 -0
  122. package/dist/conversational-flow/testing.js +119 -0
  123. package/dist/conversational-flow/testing.js.map +1 -0
  124. package/dist/conversational-flow/tree.d.ts +28 -17
  125. package/dist/conversational-flow/tree.d.ts.map +1 -1
  126. package/dist/conversational-flow/tree.js +60 -47
  127. package/dist/conversational-flow/tree.js.map +1 -1
  128. package/dist/conversational-flow/turn.d.ts +20 -22
  129. package/dist/conversational-flow/turn.d.ts.map +1 -1
  130. package/dist/conversational-flow/turn.js +69 -48
  131. package/dist/conversational-flow/turn.js.map +1 -1
  132. package/dist/conversational-flow/types.d.ts +154 -118
  133. package/dist/conversational-flow/types.d.ts.map +1 -1
  134. package/dist/conversational-flow/types.js +27 -51
  135. package/dist/conversational-flow/types.js.map +1 -1
  136. package/dist/conversational-flow/typing.d.ts +31 -0
  137. package/dist/conversational-flow/typing.d.ts.map +1 -0
  138. package/dist/conversational-flow/typing.js +53 -0
  139. package/dist/conversational-flow/typing.js.map +1 -0
  140. package/dist/engine/config-validator.js +2 -2
  141. package/dist/engine/config-validator.js.map +1 -1
  142. package/dist/engine/variable-resolver.d.ts +16 -0
  143. package/dist/engine/variable-resolver.d.ts.map +1 -1
  144. package/dist/engine/variable-resolver.js +46 -2
  145. package/dist/engine/variable-resolver.js.map +1 -1
  146. package/dist/engine/workflow-executor.d.ts.map +1 -1
  147. package/dist/engine/workflow-executor.js +10 -0
  148. package/dist/engine/workflow-executor.js.map +1 -1
  149. package/dist/runtime/workflow-runtime.d.ts.map +1 -1
  150. package/dist/runtime/workflow-runtime.js +3 -0
  151. package/dist/runtime/workflow-runtime.js.map +1 -1
  152. package/dist/steps/base-step.d.ts.map +1 -1
  153. package/dist/steps/base-step.js +1 -0
  154. package/dist/steps/base-step.js.map +1 -1
  155. package/dist/testing/mock-context.d.ts.map +1 -1
  156. package/dist/testing/mock-context.js +1 -0
  157. package/dist/testing/mock-context.js.map +1 -1
  158. package/dist/types/context.d.ts +15 -0
  159. package/dist/types/context.d.ts.map +1 -1
  160. package/dist/types/pause-state.d.ts +9 -0
  161. package/dist/types/pause-state.d.ts.map +1 -1
  162. package/dist/util/variable-ref.d.ts +1 -1
  163. package/dist/util/variable-ref.d.ts.map +1 -1
  164. package/dist/util/variable-ref.js +1 -1
  165. package/dist/util/variable-ref.js.map +1 -1
  166. package/package.json +1 -1
  167. package/dist/conversational-flow/edit.d.ts +0 -101
  168. package/dist/conversational-flow/edit.d.ts.map +0 -1
  169. package/dist/conversational-flow/edit.js +0 -785
  170. package/dist/conversational-flow/edit.js.map +0 -1
  171. package/dist/conversational-flow/internals.d.ts +0 -51
  172. package/dist/conversational-flow/internals.d.ts.map +0 -1
  173. package/dist/conversational-flow/internals.js +0 -163
  174. package/dist/conversational-flow/internals.js.map +0 -1
  175. package/dist/conversational-flow/lookup-edit.d.ts +0 -96
  176. package/dist/conversational-flow/lookup-edit.d.ts.map +0 -1
  177. package/dist/conversational-flow/lookup-edit.js +0 -266
  178. package/dist/conversational-flow/lookup-edit.js.map +0 -1
  179. package/dist/conversational-flow/lookups.d.ts +0 -46
  180. package/dist/conversational-flow/lookups.d.ts.map +0 -1
  181. package/dist/conversational-flow/lookups.js +0 -145
  182. package/dist/conversational-flow/lookups.js.map +0 -1
  183. package/dist/conversational-flow/router-edit.d.ts +0 -53
  184. package/dist/conversational-flow/router-edit.d.ts.map +0 -1
  185. package/dist/conversational-flow/router-edit.js +0 -191
  186. package/dist/conversational-flow/router-edit.js.map +0 -1
@@ -1,286 +1,100 @@
1
- import { breadcrumb, treeOrder } from './tree.js';
2
- import { AGENT_STEP_TYPE, CLASSIFIER_STEP_TYPE, optionsOf } from './types.js';
3
- import { asRec, asSteps, containerOf, findStep, walk } from './internals.js';
4
- /** Screens a router may send people to: everything they can be shown. */
5
- export function routableScreens(flow) {
6
- return flow.screens.filter((s) => s.kind !== 'router' && s.kind !== 'end');
7
- }
8
1
  /**
9
- * Finish screens a router may choose — the ones whose author said when to send
10
- * people there.
2
+ * Asking the flow about its routers.
11
3
  *
12
- * Every other screen can be described to the model by where it sits in the
13
- * menu; a Finish sits nowhere, so without that line there is nothing to
14
- * describe it by, and nothing to stop the model ending a conversation it merely
15
- * found hard to place. Writing the line is the author saying "typing may end it
16
- * here".
4
+ * A router is a screen like any other, so which screens it serves is not stored
5
+ * anywhere: it is the frame the router sits in. A router in the conversation's
6
+ * own frame reaches everything; one inside a section reaches that section and
7
+ * what is below it. Scoping is therefore a question about position, which is
8
+ * what every query here answers.
17
9
  */
18
- export function endsByTyping(flow) {
19
- return flow.screens.filter((s) => s.kind === 'end' && s.about !== undefined);
20
- }
21
- /** Every router in the flow, the one serving everything first. */
10
+ import { ancestorsOf, breadcrumb, subtreeOf } from './tree.js';
11
+ /** Every router in the flow, as the tree reads them. */
22
12
  export function routersOf(flow) {
23
- return flow.screens.filter((s) => s.router !== undefined).sort((a, b) => Number(a.router.scope !== undefined) - Number(b.router.scope !== undefined));
24
- }
25
- /**
26
- * Where a screen's typed text should go: the nearest scoped router at or above
27
- * it, else the one serving the flow.
28
- *
29
- * "At or above" is why a section's own screen uses its own router, and why a
30
- * screen beneath two scoped sections uses the nearer one.
31
- */
32
- export function routerFor(flow, screenId) {
33
- const byId = new Map(flow.screens.map((s) => [s.id, s]));
34
- const scoped = new Map(routersOf(flow).filter((r) => r.router.scope).map((r) => [r.router.scope, r]));
35
- for (let at = byId.get(screenId); at; at = at.parent ? byId.get(at.parent) : undefined) {
36
- const router = scoped.get(at.id);
37
- if (router)
38
- return router;
39
- }
40
- return flowRouter(flow);
13
+ return flow.screens.filter((s) => s.kind === 'router');
41
14
  }
42
- /**
43
- * What a router may choose. Scoped: its section and everything beneath it, plus
44
- * the first screen — "when the message isn't about this section" — every hand
45
- * off, so asking for a person works wherever they are, and the endings its own
46
- * screens lead to. Unscoped: every screen they can be shown, and every ending.
47
- *
48
- * An ending is not automatically global: a Finish that says something ("Your
49
- * driver is 3 minutes away") belongs to the part of the flow that links to it,
50
- * and a router serving Payments has no business closing the conversation on a
51
- * Rides screen. A shared "End of chat", linked from inside the section, stays
52
- * available because the link is what puts it in reach.
53
- *
54
- * Not the same set as the screens that route *to* it: the flow's router must
55
- * still reach a leaf inside a scoped section, or typing at the main menu could
56
- * only ever reach the section itself.
57
- */
58
- export function candidatesOf(flow, router) {
59
- const scope = router.router?.scope;
60
- // Ending is not part of a section: a conversation ends wherever it ends.
61
- const ends = endsByTyping(flow);
62
- if (!scope)
63
- return [...routableScreens(flow), ...ends];
64
- const section = flow.screens.find((s) => s.id === scope);
65
- if (!section)
66
- return [...routableScreens(flow), ...ends];
67
- const inside = new Set([section.id]);
68
- for (const s of treeOrder(flow))
69
- if (s.parent !== undefined && inside.has(s.parent))
70
- inside.add(s.id);
71
- const linkedFromInside = (end) => flow.screens.some((s) => inside.has(s.id) && optionsOf(s).some((o) => o.to.kind === 'screen' && o.to.screen === end.id));
72
- return [
73
- ...routableScreens(flow).filter((s) => inside.has(s.id) || s.id === flow.rootScreen || s.kind === 'handoff'),
74
- ...ends.filter(linkedFromInside),
75
- ];
15
+ /** The router in the conversation's own frame — the one that reaches everything. */
16
+ export function flowRouter(flow) {
17
+ return routersOf(flow).find((s) => frameOf(flow, s) === flow.rootScreen);
76
18
  }
77
- /**
78
- * Whether a screen's typed text may keep going where it goes. Anything else is
79
- * repaired by `settle` — a router that was removed, or a scoped one whose
80
- * section is no longer above this screen.
81
- *
82
- * A screen pointed at the flow's router is always valid: that is how an author
83
- * says "from here, typing may open anything", and it survives every move.
84
- */
85
- export function routingIsValid(flow, screenId, targetId) {
86
- const target = flow.screens.find((s) => s.id === targetId);
87
- if (!target?.router)
88
- return false;
89
- const scope = target.router.scope;
90
- if (!scope)
91
- return true;
92
- const byId = new Map(flow.screens.map((s) => [s.id, s]));
93
- for (let at = byId.get(screenId); at; at = at.parent ? byId.get(at.parent) : undefined) {
94
- if (at.id === scope)
95
- return true;
96
- }
97
- return false;
19
+ /** The screen whose frame something sits in: the conversation, or a section. */
20
+ export function frameOf(flow, screen) {
21
+ return screen.frames[screen.frames.length - 1] ?? flow.rootScreen;
98
22
  }
99
23
  /**
100
- * Point every screen's typed text at a router that can serve it. Only links
101
- * that have become invalid are touched, so an author's own choice — "from this
102
- * screen, typing may open anything" — is left standing.
24
+ * The section a router serves — undefined for the one that serves the whole
25
+ * flow, and for anything that is not a router: only a router has a scope.
103
26
  */
104
- export function repairTypedRouting(draft, flow) {
105
- for (const screen of flow.screens) {
106
- for (const prompt of screen.prompts) {
107
- if (prompt.freeText?.kind !== 'screen')
108
- continue;
109
- if (routingIsValid(flow, screen.id, prompt.freeText.screen))
110
- continue;
111
- const target = routerFor(flow, screen.id);
112
- if (!target)
113
- continue;
114
- const jump = typedJumpOf(draft, prompt.id);
115
- if (jump)
116
- asRec(jump.config['with'])[flow.routeKey] = target.id;
117
- }
118
- }
119
- }
120
- /** The GO_TO a prompt's typed branch carries — the one naming a router. */
121
- export function typedJumpOf(draft, promptId) {
122
- const around = asSteps(containerOf(draft, promptId));
123
- const at = around.findIndex((s) => s.id === promptId);
124
- const gate = around[at + 1];
125
- if (gate?.type !== 'CONDITIONAL')
27
+ export function scopeOf(flow, router) {
28
+ if (!router.router)
126
29
  return undefined;
127
- return asSteps(asRec(gate.config)['if_true']).find((s) => s.type === 'GO_TO');
30
+ const frame = frameOf(flow, router);
31
+ return frame === flow.rootScreen ? undefined : flow.screens.find((s) => s.id === frame);
128
32
  }
129
33
  /**
130
- * The AI router's instructions and output contract, generated from the screens.
131
- * The author's own guidance (the router step's description) goes first; the
132
- * `enum` is what stops the agent naming a screen that doesn't exist.
34
+ * Where typed text goes from a screen: the router its question names.
35
+ *
36
+ * It is authored — one screen inside Payments may keep its typing in Payments
37
+ * while its neighbour sends everything to the top — so it is read, not derived.
133
38
  */
134
- export function writeRouters(draft, flow) {
135
- const textKey = typedTextKey(draft, flow);
136
- const service = serviceOf(flow);
137
- for (const screen of routersOf(flow)) {
138
- const router = screen.router;
139
- if (router.mode === 'keywords')
39
+ export function routerFor(flow, screenId) {
40
+ const screen = flow.screens.find((s) => s.id === screenId);
41
+ for (const prompt of screen?.prompts ?? []) {
42
+ const to = prompt.freeText;
43
+ if (to?.kind !== 'screen')
140
44
  continue;
141
- if (router.mode === 'classifier')
142
- writeClassifier(draft, flow, screen, candidatesOf(flow, screen), textKey, service);
143
- else
144
- writeAgentRouter(draft, flow, router, candidatesOf(flow, screen), textKey);
45
+ const router = flow.screens.find((s) => s.id === to.screen && s.kind === 'router');
46
+ if (router)
47
+ return router;
145
48
  }
49
+ return undefined;
146
50
  }
147
51
  /**
148
- * The service every router uses: the flow router's model, credential and how
149
- * sure it must be. Configured once, so scoping a section asks the author for
150
- * nothing.
151
- */
152
- function serviceOf(flow) {
153
- const main = flowRouter(flow)?.router;
154
- if (main?.mode !== 'classifier')
155
- return {};
156
- return {
157
- ...(main.model !== undefined ? { model: main.model } : {}),
158
- ...(main.credentialName !== undefined ? { credentialName: main.credentialName } : {}),
159
- ...(main.minConfidence !== undefined ? { minConfidence: main.minConfidence } : {}),
160
- };
161
- }
162
- /** An agent asked for JSON: its instructions and the screens it may name. */
163
- function writeAgentRouter(draft, flow, router, screens, textKey) {
164
- const step = findStep(draft, router.stepId, AGENT_STEP_TYPE);
165
- const lines = screens.map((s) => describeScreen(flow, s));
166
- step.config['task'] = [
167
- ...(router.guidance ? [router.guidance, ''] : []),
168
- textKey
169
- ? `Someone in this conversation typed: "{{steps.__loop.output.input.${textKey}}}"`
170
- : 'Someone in this conversation typed a message.',
171
- '',
172
- 'Send them to the screen that best answers it. The screens, with where each sits:',
173
- ...lines,
174
- '',
175
- 'Prefer the most specific screen. Only choose a [section] when the message is too vague for any of its screens.',
176
- `If nothing fits, choose "${flow.rootScreen}".`,
177
- `Answer with JSON only: {"${flow.routeKey}": "<id from the list>", "reason": "<one short sentence>"}.`,
178
- ].join('\n');
179
- step.config['outputType'] = 'json';
180
- step.config['outputSchema'] = {
181
- type: 'object',
182
- properties: {
183
- [flow.routeKey]: { type: 'string', enum: screens.map((s) => s.id) },
184
- reason: { type: 'string' },
185
- },
186
- required: [flow.routeKey, 'reason'],
187
- };
188
- }
189
- /**
190
- * A classifier router: the screens become its classes, each described the way
191
- * the agent router's list describes them, and the question it is asked carries
192
- * the author's guidance. Its endpoint, model and credential are the author's
193
- * and are never touched here.
52
+ * The routers a screen may send typing to: the ones whose frame encloses it.
53
+ *
54
+ * Innermost first, so "keep this in Payments" reads before "look anywhere".
194
55
  */
195
- function writeClassifier(draft, flow, screen, screens, textKey, service) {
196
- const router = screen.router;
197
- const step = findStep(draft, router.stepId, CLASSIFIER_STEP_TYPE);
198
- const section = router.scope ? flow.screens.find((s) => s.id === router.scope) : undefined;
199
- step.config['input'] = textKey ? `{{steps.__loop.output.input.${textKey}}}` : '';
200
- step.config['instructions'] = [
201
- ...(router.guidance ? [router.guidance, ''] : []),
202
- section
203
- ? `Which screen best answers what they typed? They are in ${breadcrumb(flow, section)}; prefer the most specific screen there, a [section] only when the message is too vague for any screen beneath it, and the first screen only when the message isn't about ${section.title} at all.`
204
- : 'Which screen best answers what they typed? Prefer the most specific one; a [section] only when the message is too vague for any screen beneath it.',
205
- ].join('\n');
206
- step.config['classes'] = Object.fromEntries(screens.map((s) => [s.id, describeClass(flow, s)]));
207
- // Every router asks the same service; only the flow's router is configured.
208
- for (const key of ['model', 'credentialName', 'minConfidence']) {
209
- if (service[key] !== undefined)
210
- step.config[key] = service[key];
211
- else
212
- delete step.config[key];
213
- }
214
- // Somewhere to send a message it can't place: a scoped router keeps them in
215
- // its own section, the flow's sends them back to the start.
216
- if (typeof step.config['minConfidence'] === 'number')
217
- step.config['fallbackClass'] = section?.id ?? flow.rootScreen;
218
- else
219
- delete step.config['fallbackClass'];
220
- }
221
- /** "payments_double_charge (Payments › Charges › Charged twice) [section] — the same trip was charged twice" */
222
- function describeScreen(flow, s) {
223
- if (s.kind === 'end')
224
- return `${s.id} — ends the conversation: ${s.about ?? 'they are done'}`;
225
- const section = flow.screens.some((c) => c.parent === s.id) ? ' [section]' : '';
226
- const about = s.about ?? `the ${breadcrumb(flow, s)} screen`;
227
- return `${s.id} (${breadcrumb(flow, s)})${section} — ${about}`;
228
- }
229
- /** The same description, without repeating the id the class key already carries. */
230
- function describeClass(flow, s) {
231
- if (s.kind === 'end')
232
- return `Ends the conversation — ${s.about ?? 'they are done'}`;
233
- const section = flow.screens.some((c) => c.parent === s.id) ? ' [section]' : '';
234
- const about = s.about ?? `the ${breadcrumb(flow, s)} screen`;
235
- return `${breadcrumb(flow, s)}${section} — ${about}`;
56
+ export function routersFor(flow, screenId) {
57
+ const enclosing = [screenId, ...ancestorsOf(flow, screenId)];
58
+ return routersOf(flow)
59
+ .filter((router) => enclosing.includes(frameOf(flow, router)))
60
+ .sort((a, b) => enclosing.indexOf(frameOf(flow, a)) - enclosing.indexOf(frameOf(flow, b)));
236
61
  }
237
- /** The cycle input that carries what they typed — read from a typed-text GO_TO. */
238
- function typedTextKey(draft, flow) {
239
- for (const s of flow.screens) {
240
- for (const p of s.prompts) {
241
- if (p.freeText?.kind !== 'screen' || !p.textField)
242
- continue;
243
- const jump = walk(asSteps(draft.steps)).find((x) => x.type === 'GO_TO' && Object.values(asRec(x.config['with'])).some((v) => typeof v === 'string' && v.includes(`steps.${p.id}.output.resumeData.data.${p.textField}`)));
244
- const carried = asRec(jump?.config['with']);
245
- const key = Object.keys(carried).find((k) => k !== flow.routeKey && typeof carried[k] === 'string' && carried[k].includes('{{'));
246
- if (key)
247
- return key;
248
- }
249
- }
250
- return undefined;
62
+ /** Whether typing on `screenId` could reach `routerId` at all. */
63
+ export function routingIsValid(flow, screenId, routerId) {
64
+ return routersFor(flow, screenId).some((router) => router.id === routerId);
251
65
  }
252
- export function agentRouter(flow) {
253
- return flow.screens.find((s) => s.router?.mode === 'agent');
254
- }
255
- /** The router that reads typed text, however it decides — classifier or agent. */
256
- export function aiRouter(flow) {
257
- return flow.screens.find((s) => s.router?.mode === 'classifier' || s.router?.mode === 'agent');
66
+ /** The screens a router may open: its own frame's subtree, as `settle` wrote it. */
67
+ export function candidatesOf(flow, router) {
68
+ const byId = new Map(flow.screens.map((s) => [s.id, s]));
69
+ return router.router?.candidates.map((id) => byId.get(id)).filter((s) => s !== undefined) ?? [];
258
70
  }
259
- /** The router that serves the flow as a whole — the one with no scope. */
260
- export function flowRouter(flow) {
261
- return flow.screens.find((s) => s.router !== undefined && s.router.scope === undefined);
71
+ /** The screens a router anywhere in the flow could open. */
72
+ export function routableScreens(flow) {
73
+ const byId = new Map(flow.screens.map((s) => [s.id, s]));
74
+ return subtreeOf(flow, flow.rootScreen)
75
+ .map((id) => byId.get(id))
76
+ .filter((s) => s !== undefined)
77
+ .filter((s) => s.kind !== 'router')
78
+ .filter((s) => s.kind !== 'end' || (s.about ?? '') !== '');
262
79
  }
263
- /**
264
- * Point a section and everything beneath it at one router. A bulk action —
265
- * scoping a section, un-scoping it, moving a branch into another section —
266
- * rather than something `settle` does, so a per-screen choice survives edits
267
- * elsewhere.
268
- */
269
- export function pointSubtreeAt(draft, flow, sectionId, routerId) {
270
- const inside = new Set([sectionId]);
271
- for (const s of treeOrder(flow))
272
- if (s.parent !== undefined && inside.has(s.parent))
273
- inside.add(s.id);
274
- for (const screen of flow.screens) {
275
- if (!inside.has(screen.id))
276
- continue;
277
- for (const prompt of screen.prompts) {
278
- if (prompt.freeText?.kind !== 'screen')
279
- continue;
280
- const jump = typedJumpOf(draft, prompt.id);
281
- if (jump)
282
- asRec(jump.config['with'])[flow.routeKey] = routerId;
283
- }
284
- }
80
+ /** The endings a router may choose — the ones whose author said when they apply. */
81
+ export function endsByTyping(flow) {
82
+ return flow.screens.filter((s) => s.kind === 'end' && (s.about ?? '') !== '');
83
+ }
84
+ /** How to name a router in the editor: what it asks, and what it reaches. */
85
+ export function routerName(flow, router) {
86
+ const section = scopeOf(flow, router);
87
+ const reach = section ? `${breadcrumb(flow, section)} and below` : 'anywhere';
88
+ return `${serviceName(router)} · ${reach}`;
89
+ }
90
+ function serviceName(router) {
91
+ const info = router.router;
92
+ if (!info)
93
+ return 'Router';
94
+ if (info.mode === 'classifier')
95
+ return info.credentialName ?? info.model ?? 'Classifier';
96
+ if (info.mode === 'agent')
97
+ return info.agent ?? 'AI agent';
98
+ return 'Keywords';
285
99
  }
286
100
  //# sourceMappingURL=routers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"routers.js","sourceRoot":"","sources":["../../src/conversational-flow/routers.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAuB,MAAM,gBAAgB,CAAC;AAElG,yEAAyE;AACzE,MAAM,UAAU,eAAe,CAAC,IAAwB;IAC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CAAC,CAAC;AAC/D,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,YAAY,CAAC,IAAwB;IACnD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;AAChF,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,UAAU,CAAC,IAAwB,EAAE,MAAc;IACjE,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC;IAC9E,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,KAAK,EAAE,CAAC;AAC7C,CAAC;AAED,SAAS,WAAW,CAAC,MAAc;IACjC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3B,IAAI,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAC;IAC3B,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,KAAK,IAAI,YAAY,CAAC;IACzF,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC;IAC3D,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -1,26 +1,32 @@
1
1
  /**
2
- * What is refreshed after every structural edit, so the author never maintains
3
- * it by hand:
2
+ * What is true of the config once an edit is done, rather than something an
3
+ * author maintains:
4
4
  *
5
- * - prompt headers that were the generated breadcrumb ("Payments › Charges");
6
- * - typed text pointed at a router that can still serve the screen it comes
7
- * from — repaired only where it has become invalid, so an author's own choice
8
- * of router stands;
9
- * - each router's instructions and the screens it may choose;
10
- * - where each hand off can be sent once the person is done.
5
+ * - a section's case names its whole subtree, so a descent finds anything inside it;
6
+ * - every frame starts a round with the same keys, so a jump may name any of them;
7
+ * - every jump names the innermost frame holding both its ends;
8
+ * - a question's heading is the breadcrumb, where it was the generated one;
9
+ * - a router is told about the screens its own frame can open;
10
+ * - typing that named a router no longer above it is sent to the nearest one.
11
11
  *
12
- * An edit calls `settle` instead of `mutate` when its change can move any of
13
- * those — a screen added, moved, renamed, retyped or removed.
12
+ * An edit calls `settle` rather than `mutate` when it can move any of those —
13
+ * which, once the config is the tree, is most structural edits.
14
14
  */
15
15
  import type { WorkflowConfig } from '../types/workflow-config.js';
16
- /** Recompute what is derived from the screens (headers, the router) without any other change. */
16
+ import type { ConversationalFlow } from './types.js';
17
+ export declare class ConversationalFlowEditError extends Error {
18
+ readonly name = "ConversationalFlowEditError";
19
+ }
20
+ /** Recompute everything derived, without any other change. */
17
21
  export declare function refreshDerived(config: WorkflowConfig): WorkflowConfig;
18
22
  /**
19
- * Apply `edit`, then refresh what is derived from the screens: breadcrumb
20
- * headers (only those that were the generated breadcrumb — a header the author
21
- * wrote is left alone) and the AI router's list of screens.
23
+ * Apply `edit`, then make the config true again.
24
+ *
25
+ * A heading the author wrote is left alone: only the ones that still read as
26
+ * the breadcrumb they were given are rewritten.
22
27
  */
23
28
  export declare function settle(config: WorkflowConfig, edit: (draft: WorkflowConfig) => void,
24
- /** The config as the author last saw it, when `config` is already part-way through a multi-step edit. */
29
+ /** The config as the author last saw it, when this is part-way through a larger edit. */
25
30
  baseline?: WorkflowConfig): WorkflowConfig;
31
+ export declare function requireFlow(config: WorkflowConfig): ConversationalFlow;
26
32
  //# sourceMappingURL=settle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"settle.d.ts","sourceRoot":"","sources":["../../src/conversational-flow/settle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAMlE,iGAAiG;AACjG,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAErE;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CACpB,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI;AACrC,yGAAyG;AACzG,QAAQ,GAAE,cAAuB,GAChC,cAAc,CAqBhB"}
1
+ {"version":3,"file":"settle.d.ts","sourceRoot":"","sources":["../../src/conversational-flow/settle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AASlE,OAAO,KAAK,EAAE,kBAAkB,EAAU,MAAM,YAAY,CAAC;AAE7D,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,SAAkB,IAAI,iCAAiC;CACxD;AAED,8DAA8D;AAC9D,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAErE;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI;AACrC,yFAAyF;AACzF,QAAQ,GAAE,cAAuB,GAChC,cAAc,CAoBhB;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,kBAAkB,CAItE"}