@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
@@ -0,0 +1,112 @@
1
+ /**
2
+ * What each kind of screen is made of.
3
+ *
4
+ * One place, because two edits need it: adding a screen, and changing what kind
5
+ * an existing one is. Every builder models itself on a question the flow already
6
+ * has — the same field names, the same way of telling typing from tapping — so a
7
+ * screen added to a flow looks like the rest of it rather than like this file.
8
+ *
9
+ * Nothing here is derived: the headings, the subtrees, where the jumps are
10
+ * aimed and what a hand off offers are all written by `settle` afterwards.
11
+ */
12
+ import type { WorkflowConfig } from '../../types/workflow-config.js';
13
+ import { type Rec } from '../json.js';
14
+ import { type ConversationalFlow, type Screen } from '../types.js';
15
+ /** Everything the builders share: who is being built, and what it says. */
16
+ export interface Building {
17
+ screenId: string;
18
+ title: string;
19
+ /** What the screen says. */
20
+ prompt: string;
21
+ /** The options it offers — its ways back, and whatever its kind adds. */
22
+ options: Rec[];
23
+ /** The router its typed text goes to. Without one, the flow's own. */
24
+ router?: string;
25
+ /**
26
+ * The heading above it. Left out for a screen, whose heading is where it sits
27
+ * and so is written by `settle`; given for a follow-up, which is asked inside
28
+ * another question rather than anywhere of its own.
29
+ */
30
+ header?: string;
31
+ }
32
+ /**
33
+ * What a screen of this kind is made of — the one place that decides, so a screen
34
+ * created as a Finish and a screen turned into one are the same screen.
35
+ */
36
+ export declare function stepsForKind(draft: WorkflowConfig, flow: ConversationalFlow, kind: 'menu' | 'message' | 'questions' | 'ask-ai' | 'end' | 'handoff' | undefined, args: Building & {
37
+ agentSlug?: string;
38
+ }): unknown[];
39
+ /**
40
+ * A screen that asks: the question, and where each answer goes.
41
+ *
42
+ * `branches` makes it a screen with follow-ups — the jump moves into a SWITCH
43
+ * whose cases are the answers that ask something more before moving on.
44
+ */
45
+ export declare function questionSteps(draft: WorkflowConfig, flow: ConversationalFlow, args: Building & {
46
+ branches?: boolean;
47
+ }): unknown[];
48
+ /**
49
+ * The end of the conversation. Whatever the screen said becomes its last word,
50
+ * so turning a Message into a Finish keeps its wording instead of dropping it.
51
+ */
52
+ export declare function endingSteps(flow: ConversationalFlow, args: Pick<Building, 'screenId' | 'prompt'>): unknown[];
53
+ /**
54
+ * A person has it from here.
55
+ *
56
+ * The run pauses on a WAIT only they answer — no text box, since the customer is
57
+ * talking to them now — and a jump carries their answer on: an ending closes the
58
+ * conversation, a screen sends it back into the flow. What they may choose is
59
+ * written by `settle`.
60
+ */
61
+ export declare function handoffSteps(draft: WorkflowConfig, flow: ConversationalFlow, args: Pick<Building, 'screenId'>): unknown[];
62
+ /**
63
+ * An agent that answers until they leave.
64
+ *
65
+ * It opens like any screen — the intro, the ways out, a text box — and a typed
66
+ * question goes to an agent that answers and then waits for a reply: another
67
+ * question is answered in place, and tapping one of the ways out carries them
68
+ * there. So the whole exchange is one round of the conversation.
69
+ */
70
+ export declare function askAiSteps(draft: WorkflowConfig, flow: ConversationalFlow, args: Building & {
71
+ agentSlug?: string;
72
+ }): unknown[];
73
+ export declare class AskAiUnsupported extends Error {
74
+ readonly name = "AskAiUnsupported";
75
+ }
76
+ /** What decides where typed text goes: a classifier model, or one of the agents. */
77
+ export type RouterMode = {
78
+ mode: 'classifier';
79
+ model?: string;
80
+ credentialName?: string;
81
+ minConfidence?: number;
82
+ } | {
83
+ mode: 'agent';
84
+ agentSlug: string;
85
+ };
86
+ /**
87
+ * A router: the step that reads a typed message and names a screen, and the jump
88
+ * that carries its answer on.
89
+ *
90
+ * What it is told, the screens it may choose and where an unsure message goes are
91
+ * all written by `settle`, from the frame the router ends up in.
92
+ */
93
+ export declare function routerSteps(draft: WorkflowConfig, flow: ConversationalFlow, args: {
94
+ screenId: string;
95
+ wanted: RouterMode;
96
+ stepId?: string;
97
+ }): unknown[];
98
+ /** The deciding step itself, keeping anything the author wrote on the old one. */
99
+ export declare function decidingStep(stepId: string, wanted: RouterMode, description?: string): Rec;
100
+ /** How the jump after a router names what it chose. */
101
+ export declare function routerAnswer(stepId: string, wanted: RouterMode, routeKey: string): string;
102
+ /**
103
+ * The ending a new Message screen offers as "That's all": a way out of the
104
+ * conversation that belongs to no branch in particular.
105
+ *
106
+ * A Finish that says something ("Your driver is 3 minutes away") is that
107
+ * branch's own ending, and offering it from an unrelated screen would put words
108
+ * in its mouth. So: a silent Finish first, then whichever ending the most
109
+ * screens already lead to, and none at all when every ending belongs somewhere.
110
+ */
111
+ export declare function sharedExit(flow: ConversationalFlow, exclude: string): Screen | undefined;
112
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/conversational-flow/edit/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAuB,KAAK,GAAG,EAAa,MAAM,YAAY,CAAC;AAItE,OAAO,EAOL,KAAK,kBAAkB,EACvB,KAAK,MAAM,EACZ,MAAM,aAAa,CAAC;AAErB,2EAA2E;AAC3E,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,kBAAkB,EACxB,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,EACjF,IAAI,EAAE,QAAQ,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACtC,OAAO,E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E,MAAM,CAAA;CAAE,GAC9D,OAAO,EAAE,CAUX;AAED,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,GAAG,CAkB1F;AAED,uDAAuD;AACvD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzF;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOxF"}
@@ -0,0 +1,249 @@
1
+ import { asArray, asRec, str } from '../json.js';
2
+ import { caseFor } from '../locate.js';
3
+ import { carriedTo, textKeyOf } from '../rounds.js';
4
+ import { finishStep, jumpStep, partsOf } from '../shape.js';
5
+ import { AGENT_STEP_TYPE, CLASSIFIER_STEP_TYPE, END_MESSAGE_KEY, HANDOFF_SECTION, optionsOf, QUESTION_SEPARATOR, } from '../types.js';
6
+ /**
7
+ * What a screen of this kind is made of — the one place that decides, so a screen
8
+ * created as a Finish and a screen turned into one are the same screen.
9
+ */
10
+ export function stepsForKind(draft, flow, kind, args) {
11
+ if (kind === 'end')
12
+ return endingSteps(flow, args);
13
+ if (kind === 'handoff')
14
+ return handoffSteps(draft, flow, args);
15
+ if (kind === 'ask-ai') {
16
+ return askAiSteps(draft, flow, { ...args, prompt: args.prompt || `Ask me anything about ${args.title.toLowerCase()}.` });
17
+ }
18
+ if (kind === 'message') {
19
+ // Somewhere to go when it is done, if the flow has an ending that belongs to
20
+ // no branch in particular.
21
+ const exit = sharedExit(flow, args.screenId);
22
+ if (exit)
23
+ args.options.push({ label: 'That’s all', value: exit.id });
24
+ }
25
+ return questionSteps(draft, flow, { ...args, branches: kind === 'questions' });
26
+ }
27
+ /**
28
+ * A screen that asks: the question, and where each answer goes.
29
+ *
30
+ * `branches` makes it a screen with follow-ups — the jump moves into a SWITCH
31
+ * whose cases are the answers that ask something more before moving on.
32
+ */
33
+ export function questionSteps(draft, flow, args) {
34
+ const waitId = `ask_${args.screenId}`;
35
+ const fields = fieldsFor(draft, flow, modelPrompt(flow));
36
+ const select = fields.find((f) => f['type'] === 'select');
37
+ if (select)
38
+ select['options'] = args.options;
39
+ // Without a heading, `settle` writes where the screen sits once it knows.
40
+ const wait = {
41
+ id: waitId,
42
+ type: 'WAIT',
43
+ config: { mode: 'approval', ...(args.header !== undefined ? { reason: args.header } : {}), prompt: args.prompt, form: { fields } },
44
+ };
45
+ const pick = jumpStep(args.branches ? `leave_${args.screenId}` : `go_${args.screenId}`, flow.rootScreen, {
46
+ ...carriedTo(draft, flow, flow.rootScreen),
47
+ [flow.routeKey]: `{{steps.${waitId}.output.resumeData.data.${str(select?.['name']) ?? 'choice'}}}`,
48
+ });
49
+ // With follow-ups, what they tapped is answered here before it is carried on.
50
+ const tapped = args.branches
51
+ ? [{ id: `pick_${args.screenId}`, type: 'SWITCH', config: { cases: [], default: [pick] } }]
52
+ : [pick];
53
+ const textField = str(fields.find((f) => f['type'] === 'text')?.['name']);
54
+ const router = args.router ?? flow.screens.find((s) => s.kind === 'router')?.id;
55
+ if (!router || !textField)
56
+ return [wait, ...tapped];
57
+ return [wait, typedGate(draft, flow, args.screenId, waitId, textField, router, tapped)];
58
+ }
59
+ /**
60
+ * The end of the conversation. Whatever the screen said becomes its last word,
61
+ * so turning a Message into a Finish keeps its wording instead of dropping it.
62
+ */
63
+ export function endingSteps(flow, args) {
64
+ return [
65
+ finishStep(`finish_${args.screenId}`, flow.rootScreen, {
66
+ ...(args.prompt ? { [END_MESSAGE_KEY]: args.prompt } : {}),
67
+ outcome: args.screenId,
68
+ }),
69
+ ];
70
+ }
71
+ /**
72
+ * A person has it from here.
73
+ *
74
+ * The run pauses on a WAIT only they answer — no text box, since the customer is
75
+ * talking to them now — and a jump carries their answer on: an ending closes the
76
+ * conversation, a screen sends it back into the flow. What they may choose is
77
+ * written by `settle`.
78
+ */
79
+ export function handoffSteps(draft, flow, args) {
80
+ const waitId = `handoff_${args.screenId}`;
81
+ const fields = fieldsFor(draft, flow, modelPrompt(flow)).filter((f) => f['type'] === 'select');
82
+ for (const field of fields)
83
+ field['options'] = [];
84
+ const select = fields[0];
85
+ return [
86
+ {
87
+ id: waitId,
88
+ type: 'WAIT',
89
+ config: {
90
+ mode: 'approval',
91
+ prompt: '',
92
+ display: [{ id: HANDOFF_SECTION, label: 'Handed off to a person', value: '' }],
93
+ form: { fields },
94
+ },
95
+ },
96
+ jumpStep(`go_${args.screenId}`, flow.rootScreen, {
97
+ ...carriedTo(draft, flow, flow.rootScreen),
98
+ [flow.routeKey]: `{{steps.${waitId}.output.resumeData.data.${str(select?.['name']) ?? 'choice'}}}`,
99
+ }),
100
+ ];
101
+ }
102
+ /**
103
+ * An agent that answers until they leave.
104
+ *
105
+ * It opens like any screen — the intro, the ways out, a text box — and a typed
106
+ * question goes to an agent that answers and then waits for a reply: another
107
+ * question is answered in place, and tapping one of the ways out carries them
108
+ * there. So the whole exchange is one round of the conversation.
109
+ */
110
+ export function askAiSteps(draft, flow, args) {
111
+ const built = questionSteps(draft, flow, args);
112
+ const gate = built[1];
113
+ if (gate?.type !== 'CONDITIONAL') {
114
+ throw new AskAiUnsupported('Ask AI needs a flow whose screens take typed messages.');
115
+ }
116
+ const waitId = `ask_${args.screenId}`;
117
+ const agentId = `ai_${args.screenId}`;
118
+ const textField = str(asArray(asRec(asRec(built[0]['config'])['form'])['fields']).map(asRec).find((f) => f['type'] === 'text')?.['name']);
119
+ const agent = {
120
+ id: agentId,
121
+ type: AGENT_STEP_TYPE,
122
+ config: {
123
+ agentSlug: args.agentSlug ?? flow.screens.find((s) => s.router?.mode === 'agent')?.router?.agent ?? '',
124
+ task: `Answer their questions about ${args.title}. Use your connected systems and sources, and say so plainly when you are not sure.` +
125
+ QUESTION_SEPARATOR +
126
+ `{{steps.${waitId}.output.resumeData.data.${textField ?? 'message'}}}`,
127
+ outputType: 'string',
128
+ waitForReply: true,
129
+ },
130
+ };
131
+ // The agent is told to name one of the ways out; that is what ends the exchange.
132
+ gate.config['if_true'] = [
133
+ agent,
134
+ jumpStep(`leave_${args.screenId}`, flow.rootScreen, {
135
+ ...carriedTo(draft, flow, flow.rootScreen),
136
+ [flow.routeKey]: `{{steps.${agentId}.output.choice}}`,
137
+ }),
138
+ ];
139
+ return built;
140
+ }
141
+ export class AskAiUnsupported extends Error {
142
+ name = 'AskAiUnsupported';
143
+ }
144
+ /**
145
+ * A router: the step that reads a typed message and names a screen, and the jump
146
+ * that carries its answer on.
147
+ *
148
+ * What it is told, the screens it may choose and where an unsure message goes are
149
+ * all written by `settle`, from the frame the router ends up in.
150
+ */
151
+ export function routerSteps(draft, flow, args) {
152
+ const stepId = args.stepId ?? `decide_${args.screenId}`;
153
+ const step = decidingStep(stepId, args.wanted);
154
+ return [
155
+ step,
156
+ jumpStep(`go_${args.screenId}`, flow.rootScreen, {
157
+ ...carriedTo(draft, flow, flow.rootScreen),
158
+ [flow.routeKey]: routerAnswer(stepId, args.wanted, flow.routeKey),
159
+ }),
160
+ ];
161
+ }
162
+ /** The deciding step itself, keeping anything the author wrote on the old one. */
163
+ export function decidingStep(stepId, wanted, description) {
164
+ const kept = { id: stepId, ...(description ? { description } : {}) };
165
+ if (wanted.mode === 'agent') {
166
+ // Its brief and the shape of its answer are written by `settle`.
167
+ return { ...kept, type: AGENT_STEP_TYPE, config: { agentSlug: wanted.agentSlug.trim(), task: '', outputType: 'json' } };
168
+ }
169
+ return {
170
+ ...kept,
171
+ type: CLASSIFIER_STEP_TYPE,
172
+ config: {
173
+ input: '',
174
+ instructions: '',
175
+ classes: {},
176
+ ...(wanted.model ? { model: wanted.model } : {}),
177
+ ...(wanted.credentialName ? { credentialName: wanted.credentialName } : {}),
178
+ ...(wanted.minConfidence !== undefined ? { minConfidence: wanted.minConfidence } : {}),
179
+ },
180
+ };
181
+ }
182
+ /** How the jump after a router names what it chose. */
183
+ export function routerAnswer(stepId, wanted, routeKey) {
184
+ return wanted.mode === 'classifier' ? `{{steps.${stepId}.output.class}}` : `{{steps.${stepId}.output.response.${routeKey}}}`;
185
+ }
186
+ /**
187
+ * The ending a new Message screen offers as "That's all": a way out of the
188
+ * conversation that belongs to no branch in particular.
189
+ *
190
+ * A Finish that says something ("Your driver is 3 minutes away") is that
191
+ * branch's own ending, and offering it from an unrelated screen would put words
192
+ * in its mouth. So: a silent Finish first, then whichever ending the most
193
+ * screens already lead to, and none at all when every ending belongs somewhere.
194
+ */
195
+ export function sharedExit(flow, exclude) {
196
+ const ends = flow.screens.filter((s) => s.kind === 'end' && s.id !== exclude);
197
+ const silent = ends.filter((s) => s.endMessage === undefined);
198
+ if (silent.length > 0)
199
+ return silent[0];
200
+ const leads = (id) => flow.screens.filter((s) => optionsOf(s).some((o) => o.to.kind === 'screen' && o.to.screen === id)).length;
201
+ return ends.filter((s) => leads(s.id) > 1).sort((a, b) => leads(b.id) - leads(a.id))[0];
202
+ }
203
+ // ─── What every question shares ───
204
+ /** Typing goes to the router; tapping goes wherever the tap says. */
205
+ function typedGate(draft, flow, screenId, waitId, textField, routerId, tapped) {
206
+ const typed = `{{steps.${waitId}.output.resumeData.data.${textField}}}`;
207
+ return {
208
+ id: `typed_${screenId}`,
209
+ type: 'CONDITIONAL',
210
+ config: {
211
+ condition: {
212
+ all: [
213
+ { variable: typed, operator: 'exists' },
214
+ { variable: typed, operator: 'neq', value: '' },
215
+ ],
216
+ },
217
+ if_true: [jumpStep(`typed_go_${screenId}`, flow.rootScreen, { ...carriedTo(draft, flow, routerId), [textKeyOf(draft, flow)]: typed })],
218
+ if_false: tapped,
219
+ },
220
+ };
221
+ }
222
+ /** A question this flow already has, to model a new one on. */
223
+ function modelPrompt(flow) {
224
+ return flow.screens.find((s) => (s.kind === 'menu' || s.kind === 'message') && s.prompts[0])?.prompts[0]?.id;
225
+ }
226
+ /** The form fields this flow uses, with the options emptied for a new screen. */
227
+ function fieldsFor(draft, flow, promptId) {
228
+ const fallback = [
229
+ { type: 'select', name: 'choice', label: 'Choose one', options: [] },
230
+ { type: 'text', name: 'message', label: 'Or type your question' },
231
+ ];
232
+ if (!promptId)
233
+ return fallback;
234
+ for (const screen of flow.screens) {
235
+ if (!screen.prompts.some((p) => p.id === promptId))
236
+ continue;
237
+ const entry = caseFor(draft, flow, screen);
238
+ const wait = entry ? partsOf(entry, flow.routeKey).rest.find((s) => s.id === promptId) : undefined;
239
+ const fields = asArray(asRec(wait?.config['form'])['fields']).map(asRec);
240
+ if (fields.length === 0)
241
+ break;
242
+ return fields.map((field) => ({ ...clone(field), ...(field['type'] === 'select' ? { options: [] } : {}) }));
243
+ }
244
+ return fallback;
245
+ }
246
+ function clone(value) {
247
+ return JSON.parse(JSON.stringify(value));
248
+ }
249
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/conversational-flow/edit/build.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAuB,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,SAAS,EACT,kBAAkB,GAGnB,MAAM,aAAa,CAAC;AAoBrB;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAqB,EACrB,IAAwB,EACxB,IAAiF,EACjF,IAAuC;IAEvC,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnD,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,YAAY,C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AAE,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9G,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,KAAK,CAAI,KAAQ;IACxB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAM,CAAC;AAChD,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Calls: what a frame fetches on the way in.
3
+ *
4
+ * Where the step sits is the whole meaning, so that is the only thing these
5
+ * edits decide:
6
+ *
7
+ * before the first screen's cycle once per conversation, in scope everywhere
8
+ * before a section's cycle once per entry to it, in scope inside it
9
+ * before a question every visit, in scope on that screen
10
+ *
11
+ * However someone arrives — tapped down, typed and routed straight in, came
12
+ * back — they pass through the frames above them, so what those frames fetched
13
+ * has been fetched. That is the property the whole shape exists for, and it is
14
+ * not maintained anywhere: it is where the step is.
15
+ */
16
+ import type { WorkflowConfig } from '../../types/workflow-config.js';
17
+ import type { CallScope, ConversationalFlow } from '../types.js';
18
+ export interface CallDraft {
19
+ /** What to call it — shown in the editor and in the run's trace. */
20
+ title: string;
21
+ /** The HTTP step's own config: `url`, `method`, `headers`, `body`, `response`, … */
22
+ request: Record<string, unknown>;
23
+ }
24
+ /** How a call's answer is quoted, from anywhere inside its frame. */
25
+ export declare function callRef(callId: string, path?: string): string;
26
+ /**
27
+ * Fetch something on the way into `screenId`.
28
+ *
29
+ * The scope follows the screen unless it is asked for: a section fetches for
30
+ * everything inside it, a leaf for itself, and the first screen for the whole
31
+ * conversation — which is what an id passed in at the start is usually for.
32
+ */
33
+ export declare function addCall(config: WorkflowConfig, screenId: string, draft: CallDraft, scope?: CallScope): {
34
+ config: WorkflowConfig;
35
+ callId: string;
36
+ };
37
+ /**
38
+ * Move a lookup so it runs in front of a different screen.
39
+ *
40
+ * Where it sits *is* its scope, so this is the only way to change one — and it
41
+ * is the honest way to say it: not "pick a scope" but "pick what it runs before".
42
+ * Its guard moves with it; where a failed one goes is unchanged unless the new
43
+ * place cannot have one.
44
+ */
45
+ export declare function moveCall(config: WorkflowConfig, callId: string, screenId: string, scope?: CallScope): WorkflowConfig;
46
+ /**
47
+ * Rewrite a call. The request replaces what was there — the editor holds the
48
+ * whole request, so merging halves of two would be guesswork — and where a
49
+ * failed one goes is `setCallFallback`'s, so it is left alone.
50
+ */
51
+ export declare function setCall(config: WorkflowConfig, callId: string, draft: CallDraft): WorkflowConfig;
52
+ /** Stop fetching it, and take the guard that said where a failed one goes. */
53
+ export declare function removeCall(config: WorkflowConfig, callId: string): WorkflowConfig;
54
+ /**
55
+ * Where to go when it cannot be reached — or `null` to drop that, after which
56
+ * an unanswered call fails the conversation.
57
+ */
58
+ export declare function setCallFallback(config: WorkflowConfig, callId: string, to: string | null): WorkflowConfig;
59
+ /** Where a call's answer is quoted, in the author's terms. */
60
+ export declare function quotedIn(flow: ConversationalFlow, callId: string): string[];
61
+ //# sourceMappingURL=calls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../../../src/conversational-flow/edit/calls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAKrE,OAAO,KAAK,EAAQ,SAAS,EAAE,kBAAkB,EAAU,MAAM,aAAa,CAAC;AAK/E,MAAM,WAAW,SAAS;IACxB,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC;IACd,oFAAoF;IACpF,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,qEAAqE;AACrE,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI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