@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
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Putting a case somewhere, and taking one out.
3
+ *
4
+ * A screen is a case; where that case sits is where the screen is. So the only
5
+ * structural move in the whole layer is lifting a case out of one switch and
6
+ * putting it in another — and the one thing that takes care is that a screen with
7
+ * nothing inside it and a screen with screens inside it are written differently:
8
+ *
9
+ * a leaf case eq(screen) [its calls…, its question]
10
+ * a section case any(subtree) [its calls…, CYCLE [ its own case, its children ]]
11
+ *
12
+ * So giving a leaf its first child promotes it — its steps move inside the new
13
+ * loop unchanged, and its calls with them, which is why promotion changes nothing
14
+ * about what it fetches or when. Taking the last child away demotes it back.
15
+ *
16
+ * Everything that adds, moves or removes anything goes through here, screens and
17
+ * routers alike, so the shape is maintained in one place.
18
+ */
19
+ import type { WorkflowConfig } from '../../types/workflow-config.js';
20
+ import { type Rec } from '../json.js';
21
+ import type { ConversationalFlow } from '../types.js';
22
+ /**
23
+ * The switch a screen's children live in — making one if this is the first
24
+ * child, which is what turns a screen into a section.
25
+ */
26
+ export declare function frameFor(draft: WorkflowConfig, flow: ConversationalFlow, screenId: string): Rec[];
27
+ /** Take a screen's case out of the switch it sits in, demoting its parent if it was the last. */
28
+ export declare function lift(draft: WorkflowConfig, flow: ConversationalFlow, screenId: string): Rec;
29
+ //# sourceMappingURL=cases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cases.d.ts","sourceRoot":"","sources":["../../../src/conversational-flow/edit/cases.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAoB,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAKxD,OAAO,KAAK,EAAE,kBAAkB,EAAU,MAAM,aAAa,CAAC;AAE9D;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,GAAG,GAAG,EAAE,CAmBjG;AAED,iGAAiG;AACjG,wBAAgB,IAAI,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,GAAG,GAAG,CAY3F"}
@@ -0,0 +1,83 @@
1
+ import { asArray, asSteps } from '../json.js';
2
+ import { caseFor, cycleAt, sectionCaseFor } from '../locate.js';
3
+ import { carriedTo, inheritedInput } from '../rounds.js';
4
+ import { ConversationalFlowEditError } from '../settle.js';
5
+ import { caseListIn, caseKind, cycleStep, isCycle, jumpStep, partsOf, screenCase, sectionCase, switchIn, switchStep } from '../shape.js';
6
+ /**
7
+ * The switch a screen's children live in — making one if this is the first
8
+ * child, which is what turns a screen into a section.
9
+ */
10
+ export function frameFor(draft, flow, screenId) {
11
+ const screen = requireScreen(flow, screenId);
12
+ if (screen.children.length > 0 || screen.id === flow.rootScreen) {
13
+ const cycle = cycleAt(draft, [...screen.frames], flow.routeKey);
14
+ const routing = cycle ? switchIn(cycle) : undefined;
15
+ if (!routing)
16
+ throw new ConversationalFlowEditError(`“${screen.title}” has nowhere to hold a screen.`);
17
+ return caseListIn(routing);
18
+ }
19
+ // Promotion: the leaf's own case, steps and all, moves inside a new loop.
20
+ const own = caseFor(draft, flow, screen);
21
+ const holder = holderOf(draft, flow, screen);
22
+ if (!own || !holder)
23
+ throw new ConversationalFlowEditError(`“${screen.title}” is not somewhere a screen can go.`);
24
+ const at = holder.findIndex((entry) => entry === own);
25
+ const routing = switchStep(`${screen.id}_route`, [screenCase(screen.id, screen.title, asArray(own['steps']), flow.routeKey)], [
26
+ jumpStep(`${screen.id}_unknown`, flow.rootScreen, carriedTo(draft, flow, flow.rootScreen)),
27
+ ]);
28
+ holder.splice(at, 1, sectionCase([screen.id], screen.title, [cycleStep(screen.id, inheritedInput(draft, flow), [routing])], flow.routeKey));
29
+ return caseListIn(routing);
30
+ }
31
+ /** Take a screen's case out of the switch it sits in, demoting its parent if it was the last. */
32
+ export function lift(draft, flow, screenId) {
33
+ const screen = requireScreen(flow, screenId);
34
+ const holder = holderOf(draft, flow, screen);
35
+ if (!holder)
36
+ throw new ConversationalFlowEditError(`“${screen.title}” is not in a switch.`);
37
+ const own = screen.children.length > 0 ? sectionCaseFor(draft, flow, screen) : caseFor(draft, flow, screen);
38
+ const at = holder.findIndex((entry) => entry === own);
39
+ if (at < 0)
40
+ throw new ConversationalFlowEditError(`“${screen.title}” is not where it says it is.`);
41
+ const [lifted] = holder.splice(at, 1);
42
+ const parent = screen.parent ? flow.screens.find((s) => s.id === screen.parent) : undefined;
43
+ if (parent && parent.id !== flow.rootScreen && parent.children.length === 1)
44
+ demote(draft, flow, parent);
45
+ return lifted;
46
+ }
47
+ /** A section with nothing left inside it is a screen again: its loop comes off. */
48
+ function demote(draft, flow, screen) {
49
+ const section = sectionCaseFor(draft, flow, screen);
50
+ const holder = holderOf(draft, flow, screen);
51
+ if (!section || !holder)
52
+ return;
53
+ const cycle = partsOf(section, flow.routeKey).rest.find(isCycle);
54
+ const routing = cycle ? switchIn(cycle) : undefined;
55
+ if (!routing)
56
+ return;
57
+ const own = caseListIn(routing).find((entry) => {
58
+ const kind = caseKind(entry, flow.routeKey);
59
+ return kind?.kind === 'screen' && kind.screen === screen.id;
60
+ });
61
+ if (!own)
62
+ return;
63
+ // Whatever the section itself fetched now belongs to the screen it was.
64
+ const calls = partsOf(section, flow.routeKey).calls.map((c) => c.step);
65
+ const at = holder.findIndex((entry) => entry === section);
66
+ holder.splice(at, 1, screenCase(screen.id, screen.title, [...calls, ...asSteps(own['steps'])], flow.routeKey));
67
+ }
68
+ /** The list of cases a screen's own case sits in. */
69
+ function holderOf(draft, flow, screen) {
70
+ const frames = screen.children.length > 0 ? screen.frames.slice(0, -1) : screen.frames;
71
+ if (frames.length === 0)
72
+ return undefined;
73
+ const cycle = cycleAt(draft, frames, flow.routeKey);
74
+ const routing = cycle ? switchIn(cycle) : undefined;
75
+ return routing ? caseListIn(routing) : undefined;
76
+ }
77
+ function requireScreen(flow, id) {
78
+ const screen = flow.screens.find((s) => s.id === id);
79
+ if (!screen)
80
+ throw new ConversationalFlowEditError(`There is no screen “${id}”.`);
81
+ return screen;
82
+ }
83
+ //# sourceMappingURL=cases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cases.js","sourceRoot":"","sources":["../../../src/conversational-flow/edit/cases.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAY,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzI;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAqB,EAAE,IAAwB,EAAE,QAAgB;IACxF,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC7C,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,EAAE,K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AAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,2BAA2B,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;IAClF,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A Finish: what the conversation says as it closes, and what it reports.
3
+ *
4
+ * Both ride in what the FINISH carries — the value the conversation's own cycle
5
+ * returns. `message` is reserved for the farewell, because a person reads it;
6
+ * everything else is for whoever runs the flow.
7
+ */
8
+ import type { WorkflowConfig } from '../../types/workflow-config.js';
9
+ /** What it says as it closes. Empty for a silent ending. */
10
+ export declare function setEndMessage(config: WorkflowConfig, screenId: string, message: string): WorkflowConfig;
11
+ /**
12
+ * What the run reports when it ends here — a category, a team, a reference.
13
+ * The farewell rides in the same object and is kept.
14
+ */
15
+ export declare function setEndResult(config: WorkflowConfig, screenId: string, value: Record<string, unknown>): WorkflowConfig;
16
+ //# sourceMappingURL=endings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endings.d.ts","sourceRoot":"","sources":["../../../src/conversational-flow/edit/endings.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAOrE,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CAQvG;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,cAAc,CASrH"}
@@ -0,0 +1,53 @@
1
+ import { asRec } from '../json.js';
2
+ import { caseFor } from '../locate.js';
3
+ import { ConversationalFlowEditError, requireFlow, settle } from '../settle.js';
4
+ import { partsOf } from '../shape.js';
5
+ import { END_MESSAGE_KEY } from '../types.js';
6
+ /** What it says as it closes. Empty for a silent ending. */
7
+ export function setEndMessage(config, screenId, message) {
8
+ requireEnding(requireFlow(config), screenId);
9
+ const text = message.trim();
10
+ return settle(config, (draft) => {
11
+ const carried = carriedBy(draft, requireFlow(draft), screenId);
12
+ if (text)
13
+ carried[END_MESSAGE_KEY] = text;
14
+ else
15
+ delete carried[END_MESSAGE_KEY];
16
+ });
17
+ }
18
+ /**
19
+ * What the run reports when it ends here — a category, a team, a reference.
20
+ * The farewell rides in the same object and is kept.
21
+ */
22
+ export function setEndResult(config, screenId, value) {
23
+ requireEnding(requireFlow(config), screenId);
24
+ return settle(config, (draft) => {
25
+ const carried = carriedBy(draft, requireFlow(draft), screenId);
26
+ const farewell = carried[END_MESSAGE_KEY];
27
+ for (const key of Object.keys(carried))
28
+ delete carried[key];
29
+ Object.assign(carried, value);
30
+ if (typeof farewell === 'string' && farewell)
31
+ carried[END_MESSAGE_KEY] = farewell;
32
+ });
33
+ }
34
+ /** The object the Finish carries, live, so a caller can change it in place. */
35
+ function carriedBy(config, flow, screenId) {
36
+ const screen = requireEnding(flow, screenId);
37
+ const entry = caseFor(config, flow, screen);
38
+ const finish = entry ? partsOf(entry, flow.routeKey).rest.find((step) => step.type === 'FINISH') : undefined;
39
+ if (!finish)
40
+ throw new ConversationalFlowEditError(`“${screen.title}” doesn’t end the conversation.`);
41
+ if (!finish.config['with'])
42
+ finish.config['with'] = {};
43
+ return asRec(finish.config['with']);
44
+ }
45
+ function requireEnding(flow, id) {
46
+ const screen = flow.screens.find((s) => s.id === id);
47
+ if (!screen)
48
+ throw new ConversationalFlowEditError(`There is no screen “${id}”.`);
49
+ if (screen.kind !== 'end')
50
+ throw new ConversationalFlowEditError(`“${screen.title}” isn’t a Finish screen.`);
51
+ return screen;
52
+ }
53
+ //# sourceMappingURL=endings.js.map
@@ -0,0 +1 @@
1
+ {"version":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MAAM,IAAI,2BAA2B,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;IAClF,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK;QAAE,MAAM,IAAI,2BAA2B,CAAC,IAAI,MAAM,CAAC,KAAK,0BAA0B,CAAC,CAAC;IAC7G,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Follow-up questions: an answer that asks something more before moving on.
3
+ *
4
+ * A screen with follow-ups carries a SWITCH after its question, and each answer
5
+ * that leads to one is a case in it. So the follow-up is asked in the same round
6
+ * of the conversation, inside the screen that asked first — it is not a screen of
7
+ * its own, has no place in the tree, and nothing else can link to it.
8
+ *
9
+ * Which is exactly why removing one is safe, and why turning such a screen into
10
+ * another kind is refused while it still has any.
11
+ */
12
+ import type { WorkflowConfig } from '../../types/workflow-config.js';
13
+ /**
14
+ * Add an answer that asks something more.
15
+ *
16
+ * The follow-up offers the same ways back as the question above it, so someone
17
+ * who has changed their mind is never stuck inside an answer.
18
+ */
19
+ export declare function addFollowUp(config: WorkflowConfig, promptId: string, args: {
20
+ label: string;
21
+ question: string;
22
+ }): {
23
+ config: WorkflowConfig;
24
+ promptId: string;
25
+ };
26
+ /** Take an answer's follow-up away, and the answer with it. */
27
+ export declare function removeFollowUp(config: WorkflowConfig, promptId: string, value: string): WorkflowConfig;
28
+ //# sourceMappingURL=followups.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"followups.d.ts","sourceRoot":"","sources":["../../../src/conversational-flow/edit/followups.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAUrE;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,MAAM,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAoC9C;AAED,+DAA+D;AAC/D,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,cAAc,CAkBtG"}
@@ -0,0 +1,103 @@
1
+ import { asArray, asRec } from '../json.js';
2
+ import { caseFor } from '../locate.js';
3
+ import { ConversationalFlowEditError, requireFlow, settle } from '../settle.js';
4
+ import { routersFor } from '../routers.js';
5
+ import { partsOf, stepIn } from '../shape.js';
6
+ import { questionSteps } from './build.js';
7
+ import { optionList, promptIn } from './options.js';
8
+ /**
9
+ * Add an answer that asks something more.
10
+ *
11
+ * The follow-up offers the same ways back as the question above it, so someone
12
+ * who has changed their mind is never stuck inside an answer.
13
+ */
14
+ export function addFollowUp(config, promptId, args) {
15
+ const flow = requireFlow(config);
16
+ const { screen, prompt } = requireBranching(flow, promptId);
17
+ const label = args.label.trim();
18
+ if (!label)
19
+ throw new ConversationalFlowEditError('An answer needs a label.');
20
+ const value = unique(slug(label), new Set(prompt.options.map((o) => o.value)));
21
+ let added = '';
22
+ const next = settle(config, (draft) => {
23
+ const live = requireFlow(draft);
24
+ const at = requireScreen(live, screen.id);
25
+ const options = optionList(draft, live, at, promptId);
26
+ const firstBack = prompt.options.findIndex((o) => o.back);
27
+ options.splice(firstBack === -1 ? options.length : firstBack, 0, { label, value });
28
+ const built = questionSteps(draft, live, {
29
+ screenId: `${screen.id}__${value}`,
30
+ title: label,
31
+ prompt: args.question,
32
+ options: prompt.options.filter((o) => o.back).map((o) => ({ label: o.label, value: o.value })),
33
+ // A follow-up is asked where the question above it is: the same heading,
34
+ // and typing goes to the same router.
35
+ ...(prompt.header !== undefined ? { header: prompt.header } : {}),
36
+ ...(routersFor(live, screen.id)[0] ? { router: routersFor(live, screen.id)[0].id } : {}),
37
+ branches: true,
38
+ });
39
+ added = String(asRec(built[0])['id']);
40
+ const choice = `{{steps.${promptId}.output.resumeData.data.${prompt.choiceField ?? 'choice'}}}`;
41
+ casesOfPick(draft, live, at, prompt).push({
42
+ label: value,
43
+ condition: { variable: choice, operator: 'eq', value },
44
+ steps: built,
45
+ });
46
+ });
47
+ return { config: next, promptId: added };
48
+ }
49
+ /** Take an answer's follow-up away, and the answer with it. */
50
+ export function removeFollowUp(config, promptId, value) {
51
+ const flow = requireFlow(config);
52
+ const { screen, prompt } = requireBranching(flow, promptId);
53
+ if (!prompt.options.some((o) => o.value === value)) {
54
+ throw new ConversationalFlowEditError(`“${screen.title}” has no answer “${value}”.`);
55
+ }
56
+ return settle(config, (draft) => {
57
+ const live = requireFlow(draft);
58
+ const at = requireScreen(live, screen.id);
59
+ const options = optionList(draft, live, at, promptId);
60
+ for (let index = options.length - 1; index >= 0; index -= 1) {
61
+ if (asRec(options[index])['value'] === value)
62
+ options.splice(index, 1);
63
+ }
64
+ const cases = casesOfPick(draft, live, at, prompt);
65
+ for (let index = cases.length - 1; index >= 0; index -= 1) {
66
+ if (asRec(cases[index])['label'] === value)
67
+ cases.splice(index, 1);
68
+ }
69
+ });
70
+ }
71
+ /** The live list of cases the question's answers branch into. */
72
+ function casesOfPick(draft, flow, screen, prompt) {
73
+ const entry = caseFor(draft, flow, screen);
74
+ const pick = entry ? stepIn(partsOf(entry, flow.routeKey).rest, prompt.pickSwitchId ?? '') : undefined;
75
+ if (!pick)
76
+ throw new ConversationalFlowEditError(`“${screen.title}” no longer branches on its answers.`);
77
+ if (!Array.isArray(pick.config['cases']))
78
+ pick.config['cases'] = [];
79
+ return asArray(pick.config['cases']);
80
+ }
81
+ function requireBranching(flow, promptId) {
82
+ const found = promptIn(flow, promptId);
83
+ if (!found.prompt.pickSwitchId) {
84
+ throw new ConversationalFlowEditError(`“${found.screen.title}” answers every option by moving on. Give it follow-up questions first.`);
85
+ }
86
+ return found;
87
+ }
88
+ function requireScreen(flow, id) {
89
+ const screen = flow.screens.find((s) => s.id === id);
90
+ if (!screen)
91
+ throw new ConversationalFlowEditError(`There is no screen “${id}”.`);
92
+ return screen;
93
+ }
94
+ function unique(base, taken) {
95
+ let name = base;
96
+ for (let n = 2; taken.has(name); n += 1)
97
+ name = `${base}_${n}`;
98
+ return name;
99
+ }
100
+ function slug(label) {
101
+ return label.toLowerCase().normalize('NFKD').replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '') || 'answer';
102
+ }
103
+ //# sourceMappingURL=followups.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"followups.js","sourceRoot":"","sources":["../../../src/conversational-flow/edit/followups.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAY,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,MAAsB,EACtB,QAAgB,EAChB,IAAyC;IAEzC,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC5D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAChC,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,2BAA2B,CAAC,0BAA0B,CAAC,CAAC;IAC9E,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI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B;IAC9C,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;QAAE,IAAI,GAAG,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;IAC/D,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,IAAI,CAAC,KAAa;IACzB,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC;AAC/G,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * What the conversation is started with.
3
+ *
4
+ * A flow that quotes `{{trigger.context.orderId}}` is making a promise about
5
+ * what whoever starts it will pass in. Declaring that promise is what lets the
6
+ * validator check the references, the editor offer them, and the Test tab ask
7
+ * for them — undeclared, all three are guessing.
8
+ *
9
+ * It is written on the trigger's own `inputSchema`, which is the mechanism the
10
+ * manual trigger already has for exactly this; nothing new is stored.
11
+ */
12
+ import type { WorkflowConfig } from '../../types/workflow-config.js';
13
+ /** One thing the conversation is started with. */
14
+ export interface ConversationInput {
15
+ /** A dotted name, as it will be quoted: `orderId`, `customer.tier`. */
16
+ path: string;
17
+ type?: 'string' | 'number' | 'boolean';
18
+ }
19
+ /**
20
+ * Declare them, replacing whatever was declared before. The list is the whole
21
+ * promise, so removing a name is how you stop promising it.
22
+ */
23
+ export declare function setConversationInputs(config: WorkflowConfig, inputs: readonly ConversationInput[]): WorkflowConfig;
24
+ //# sourceMappingURL=inputs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../../src/conversational-flow/edit/inputs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAIrE,kDAAkD;AAClD,MAAM,WAAW,iBAAiB;IAChC,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;CACxC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,SAAS,iBAAiB,EAAE,GAAG,cAAc,CA0BlH"}
@@ -0,0 +1,53 @@
1
+ import { asRec } from '../json.js';
2
+ import { ConversationalFlowEditError, requireFlow, settle } from '../settle.js';
3
+ /**
4
+ * Declare them, replacing whatever was declared before. The list is the whole
5
+ * promise, so removing a name is how you stop promising it.
6
+ */
7
+ export function setConversationInputs(config, inputs) {
8
+ requireFlow(config);
9
+ const named = inputs.filter((input) => input.path.trim() !== '');
10
+ for (const input of named) {
11
+ if (/[^A-Za-z0-9_.]/.test(input.path)) {
12
+ throw new ConversationalFlowEditError(`“${input.path}” can only use letters, numbers, underscores and dots.`);
13
+ }
14
+ }
15
+ return settle(config, (draft) => {
16
+ const trigger = asRec(draft.trigger);
17
+ const triggerConfig = asRec(trigger['config']);
18
+ trigger['config'] = triggerConfig;
19
+ draft.trigger = trigger;
20
+ if (named.length === 0) {
21
+ delete triggerConfig['inputSchema'];
22
+ return;
23
+ }
24
+ // The Conversation API puts what the caller passed under `context`, so that
25
+ // is where the promise has to be made.
26
+ triggerConfig['inputSchema'] = {
27
+ type: 'object',
28
+ properties: { context: shapeOf(named) },
29
+ };
30
+ });
31
+ }
32
+ /** Dotted names → the JSON Schema the trigger declares them with. */
33
+ function shapeOf(inputs) {
34
+ const root = { type: 'object', properties: {} };
35
+ for (const input of inputs) {
36
+ let node = root;
37
+ const parts = input.path.split('.').map((p) => p.trim()).filter(Boolean);
38
+ parts.forEach((part, at) => {
39
+ const properties = asRec(node['properties']);
40
+ node['properties'] = properties;
41
+ if (at === parts.length - 1)
42
+ properties[part] = { type: input.type ?? 'string' };
43
+ else {
44
+ const next = asRec(properties[part]);
45
+ next['type'] = 'object';
46
+ properties[part] = next;
47
+ node = next;
48
+ }
49
+ });
50
+ }
51
+ return root;
52
+ }
53
+ //# sourceMappingURL=inputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputs.js","sourceRoot":"","sources":["../../../src/conversational-flow/edit/inputs.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,EAAY,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAShF;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAsB,EAAE,MAAoC;IAChG,WAAW,CAAC,MAAM,CAAC,CAAC;IACpB,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACjE,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,2BAA2B,CAAC,IAAI,KAAK,CAAC,IAAI,wDAAwD,CAAC,CAAC;QAChH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;QAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrC,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC/C,OAAO,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC;QAClC,KAAK,CAAC,OAAO,GAAG,OAAoC,CAAC;QAErD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,aAAa,CAAC,aAAa,CAAC,CAAC;YACpC,OAAO;QACT,CAAC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C;AACd,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Changing what kind of screen a screen is.
3
+ *
4
+ * The screen keeps its place in the tree, its name, its wording, what the router
5
+ * is told about it, and anything it fetches on the way in — only the steps that
6
+ * make it *that kind of screen* are rebuilt. So this is one write: the case's
7
+ * steps, after the calls, replaced by what `build.ts` says this kind is made of.
8
+ *
9
+ * Menu and Message are one kind here. Which one a screen reads as follows from
10
+ * whether anything is inside it, so asking for the other is not a change.
11
+ */
12
+ import type { WorkflowConfig } from '../../types/workflow-config.js';
13
+ /** The kinds an author can ask for. A router is made by adding one, not by conversion. */
14
+ export type NewScreenType = 'menu' | 'message' | 'questions' | 'ask-ai' | 'end' | 'handoff';
15
+ export declare function setScreenType(config: WorkflowConfig, screenId: string, type: NewScreenType, options?: {
16
+ agentSlug?: string;
17
+ }): WorkflowConfig;
18
+ /**
19
+ * What an Ask AI screen's agent is and how it is briefed.
20
+ *
21
+ * The question the person typed stays appended to the instructions, because that
22
+ * is how the agent is given it — changing the brief never takes it away.
23
+ */
24
+ export declare function setAskAi(config: WorkflowConfig, screenId: string, patch: {
25
+ agent?: string;
26
+ task?: string;
27
+ intro?: string;
28
+ }): WorkflowConfig;
29
+ //# sourceMappingURL=kinds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../../../src/conversational-flow/edit/kinds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAUrE,0FAA0F;AAC1F,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC;AAE5F,wBAAgB,aAAa,CAC3B,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,aAAa,EACnB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACnC,cAAc,CAiDhB;AAoBD;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACvD,cAAc,CAwBhB"}
@@ -0,0 +1,142 @@
1
+ import { asArray, asRec, asSteps } from '../json.js';
2
+ import { caseFor } from '../locate.js';
3
+ import { ConversationalFlowEditError, requireFlow, settle } from '../settle.js';
4
+ import { routersFor } from '../routers.js';
5
+ import { partsOf, stepIn } from '../shape.js';
6
+ import { QUESTION_SEPARATOR } from '../types.js';
7
+ import { AskAiUnsupported, stepsForKind } from './build.js';
8
+ import { optionList, waysBack } from './options.js';
9
+ export function setScreenType(config, screenId, type, options = {}) {
10
+ const flow = requireFlow(config);
11
+ const screen = requireScreen(flow, screenId);
12
+ if (screen.kind === 'router') {
13
+ throw new ConversationalFlowEditError('A router decides where typed messages go; it isn’t a screen people see.');
14
+ }
15
+ if (sameKind(screen.kind, type))
16
+ return config;
17
+ const keepsOptions = asksSomething(type);
18
+ if (screen.id === flow.rootScreen && !keepsOptions) {
19
+ throw new ConversationalFlowEditError('The first screen opens the conversation, so it has to be one people can answer.');
20
+ }
21
+ if (!keepsOptions && screen.children.length > 0) {
22
+ const inside = flow.screens.filter((s) => s.parent === screenId).map((s) => s.title);
23
+ throw new ConversationalFlowEditError(`Move ${list(inside)} somewhere else first — ${inside.length === 1 ? 'it is' : 'they are'} inside “${screen.title}”.`);
24
+ }
25
+ if (screen.kind === 'questions' && type !== 'questions' && screen.prompts.length > 1) {
26
+ throw new ConversationalFlowEditError('Remove the follow-up questions first — they only exist inside this screen.');
27
+ }
28
+ // Whatever it said carries over: a Message turned into a Finish says it last.
29
+ const wording = screen.prompts[0]?.text ?? screen.askAi?.intro ?? screen.endMessage ?? '';
30
+ const hadOptions = asksSomething(screen.kind);
31
+ try {
32
+ return settle(config, (draft) => {
33
+ const live = requireFlow(draft);
34
+ const at = requireScreen(live, screenId);
35
+ const entry = caseFor(draft, live, at);
36
+ if (!entry)
37
+ return;
38
+ const kept = keepsOptions && hadOptions && at.prompts[0] ? clone(optionList(draft, live, at, at.prompts[0].id)) : undefined;
39
+ const built = buildFor(draft, live, at, type, { wording, agentSlug: options.agentSlug });
40
+ // Converting between the kinds that ask something keeps every option the
41
+ // author made; converting from one that asks nothing starts from the ways back.
42
+ if (kept)
43
+ selectOptions(built[0]).splice(0, Infinity, ...kept);
44
+ if (at.about)
45
+ asRec(built[0])['description'] = at.about;
46
+ // The calls it makes on the way in are the author's and stay where they are.
47
+ const steps = asSteps(entry['steps']);
48
+ const lead = steps.slice(0, steps.length - partsOf(entry, live.routeKey).rest.length);
49
+ entry['steps'] = [...lead, ...built];
50
+ });
51
+ }
52
+ catch (error) {
53
+ if (error instanceof AskAiUnsupported)
54
+ throw new ConversationalFlowEditError(error.message);
55
+ throw error;
56
+ }
57
+ }
58
+ function buildFor(draft, flow, screen, type, args) {
59
+ const nearest = routersFor(flow, screen.id)[0];
60
+ return stepsForKind(draft, flow, type, {
61
+ screenId: screen.id,
62
+ title: screen.title,
63
+ prompt: args.wording,
64
+ options: waysBack(flow, screen),
65
+ ...(nearest ? { router: nearest.id } : {}),
66
+ ...(args.agentSlug ? { agentSlug: args.agentSlug } : {}),
67
+ });
68
+ }
69
+ /**
70
+ * What an Ask AI screen's agent is and how it is briefed.
71
+ *
72
+ * The question the person typed stays appended to the instructions, because that
73
+ * is how the agent is given it — changing the brief never takes it away.
74
+ */
75
+ export function setAskAi(config, screenId, patch) {
76
+ const flow = requireFlow(config);
77
+ const screen = requireScreen(flow, screenId);
78
+ if (!screen.askAi)
79
+ throw new ConversationalFlowEditError(`“${screen.title}” doesn’t answer with an agent.`);
80
+ return settle(config, (draft) => {
81
+ const live = requireFlow(draft);
82
+ const at = requireScreen(live, screenId);
83
+ const entry = caseFor(draft, live, at);
84
+ const steps = entry ? partsOf(entry, live.routeKey).rest : [];
85
+ const agent = stepIn(steps, at.askAi?.stepId ?? '');
86
+ if (!agent)
87
+ return;
88
+ if (patch.agent !== undefined)
89
+ agent.config['agentSlug'] = patch.agent.trim();
90
+ if (patch.task !== undefined) {
91
+ const task = typeof agent.config['task'] === 'string' ? agent.config['task'] : '';
92
+ const question = task.lastIndexOf(QUESTION_SEPARATOR);
93
+ agent.config['task'] = patch.task + (question === -1 ? '' : task.slice(question));
94
+ }
95
+ if (patch.intro !== undefined) {
96
+ const wait = stepIn(steps, at.prompts[0]?.id ?? '');
97
+ if (wait)
98
+ wait.config['prompt'] = patch.intro;
99
+ }
100
+ });
101
+ }
102
+ // ─── Plumbing ───
103
+ /** The kinds that ask something, and so have options to keep. */
104
+ function asksSomething(kind) {
105
+ return kind === 'menu' || kind === 'message' || kind === 'questions';
106
+ }
107
+ /**
108
+ * Menu and Message are the same steps; a screen reads as a Menu once something
109
+ * is inside it. So asking a leaf to become a Menu changes nothing until it has
110
+ * a child, and saying so here keeps the edit from rebuilding it for no reason.
111
+ */
112
+ function sameKind(kind, wanted) {
113
+ if (kind === wanted)
114
+ return true;
115
+ return (kind === 'menu' || kind === 'message') && (wanted === 'menu' || wanted === 'message');
116
+ }
117
+ /** The options of whatever a kind's first step is, live. */
118
+ function selectOptions(step) {
119
+ const fields = asArray(asRec(asRec(asRec(step)['config'])['form'])['fields']).map(asRec);
120
+ const select = fields.find((f) => f['type'] === 'select');
121
+ if (!select)
122
+ return [];
123
+ if (!Array.isArray(select['options']))
124
+ select['options'] = [];
125
+ return select['options'];
126
+ }
127
+ function requireScreen(flow, id) {
128
+ const screen = flow.screens.find((s) => s.id === id);
129
+ if (!screen)
130
+ throw new ConversationalFlowEditError(`There is no screen “${id}”.`);
131
+ return screen;
132
+ }
133
+ function list(titles) {
134
+ if (titles.length <= 1)
135
+ return titles.map((t) => `“${t}”`).join('');
136
+ const quoted = titles.map((t) => `“${t}”`);
137
+ return `${quoted.slice(0, -1).join(', ')} and ${quoted[quoted.length - 1]}`;
138
+ }
139
+ function clone(value) {
140
+ return JSON.parse(JSON.stringify(value));
141
+ }
142
+ //# sourceMappingURL=kinds.js.map