@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.
- package/dist/agents/host-agent-step.d.ts +2 -2
- package/dist/connectors/builtin/steps/classifier-agent.step.d.ts +2 -2
- package/dist/connectors/builtin/steps/map.step.d.ts +15 -4
- package/dist/connectors/builtin/steps/map.step.d.ts.map +1 -1
- package/dist/connectors/builtin/steps/map.step.js +51 -18
- package/dist/connectors/builtin/steps/map.step.js.map +1 -1
- package/dist/connectors/builtin/steps/parallel.step.d.ts +4 -4
- package/dist/connectors/builtin/steps/wait.step.d.ts +28 -0
- package/dist/connectors/builtin/steps/wait.step.d.ts.map +1 -1
- package/dist/connectors/builtin/steps/wait.step.js +26 -1
- package/dist/connectors/builtin/steps/wait.step.js.map +1 -1
- package/dist/conversational-flow/calls.d.ts +20 -0
- package/dist/conversational-flow/calls.d.ts.map +1 -0
- package/dist/conversational-flow/calls.js +59 -0
- package/dist/conversational-flow/calls.js.map +1 -0
- package/dist/conversational-flow/conditions.d.ts +24 -0
- package/dist/conversational-flow/conditions.d.ts.map +1 -0
- package/dist/conversational-flow/conditions.js +69 -0
- package/dist/conversational-flow/conditions.js.map +1 -0
- package/dist/conversational-flow/create.d.ts +23 -18
- package/dist/conversational-flow/create.d.ts.map +1 -1
- package/dist/conversational-flow/create.js +73 -96
- package/dist/conversational-flow/create.js.map +1 -1
- package/dist/conversational-flow/edit/build.d.ts +112 -0
- package/dist/conversational-flow/edit/build.d.ts.map +1 -0
- package/dist/conversational-flow/edit/build.js +249 -0
- package/dist/conversational-flow/edit/build.js.map +1 -0
- package/dist/conversational-flow/edit/calls.d.ts +61 -0
- package/dist/conversational-flow/edit/calls.d.ts.map +1 -0
- package/dist/conversational-flow/edit/calls.js +296 -0
- package/dist/conversational-flow/edit/calls.js.map +1 -0
- package/dist/conversational-flow/edit/cases.d.ts +29 -0
- package/dist/conversational-flow/edit/cases.d.ts.map +1 -0
- package/dist/conversational-flow/edit/cases.js +83 -0
- package/dist/conversational-flow/edit/cases.js.map +1 -0
- package/dist/conversational-flow/edit/endings.d.ts +16 -0
- package/dist/conversational-flow/edit/endings.d.ts.map +1 -0
- package/dist/conversational-flow/edit/endings.js +53 -0
- package/dist/conversational-flow/edit/endings.js.map +1 -0
- package/dist/conversational-flow/edit/followups.d.ts +28 -0
- package/dist/conversational-flow/edit/followups.d.ts.map +1 -0
- package/dist/conversational-flow/edit/followups.js +103 -0
- package/dist/conversational-flow/edit/followups.js.map +1 -0
- package/dist/conversational-flow/edit/inputs.d.ts +24 -0
- package/dist/conversational-flow/edit/inputs.d.ts.map +1 -0
- package/dist/conversational-flow/edit/inputs.js +53 -0
- package/dist/conversational-flow/edit/inputs.js.map +1 -0
- package/dist/conversational-flow/edit/kinds.d.ts +29 -0
- package/dist/conversational-flow/edit/kinds.d.ts.map +1 -0
- package/dist/conversational-flow/edit/kinds.js +142 -0
- package/dist/conversational-flow/edit/kinds.js.map +1 -0
- package/dist/conversational-flow/edit/options.d.ts +68 -0
- package/dist/conversational-flow/edit/options.d.ts.map +1 -0
- package/dist/conversational-flow/edit/options.js +209 -0
- package/dist/conversational-flow/edit/options.js.map +1 -0
- package/dist/conversational-flow/edit/picklist.d.ts +28 -0
- package/dist/conversational-flow/edit/picklist.d.ts.map +1 -0
- package/dist/conversational-flow/edit/picklist.js +58 -0
- package/dist/conversational-flow/edit/picklist.js.map +1 -0
- package/dist/conversational-flow/edit/prompts.d.ts +24 -0
- package/dist/conversational-flow/edit/prompts.d.ts.map +1 -0
- package/dist/conversational-flow/edit/prompts.js +180 -0
- package/dist/conversational-flow/edit/prompts.js.map +1 -0
- package/dist/conversational-flow/edit/routers.d.ts +65 -0
- package/dist/conversational-flow/edit/routers.d.ts.map +1 -0
- package/dist/conversational-flow/edit/routers.js +208 -0
- package/dist/conversational-flow/edit/routers.js.map +1 -0
- package/dist/conversational-flow/edit/screens.d.ts +44 -0
- package/dist/conversational-flow/edit/screens.d.ts.map +1 -0
- package/dist/conversational-flow/edit/screens.js +137 -0
- package/dist/conversational-flow/edit/screens.js.map +1 -0
- package/dist/conversational-flow/edit/versions.d.ts +43 -0
- package/dist/conversational-flow/edit/versions.d.ts.map +1 -0
- package/dist/conversational-flow/edit/versions.js +189 -0
- package/dist/conversational-flow/edit/versions.js.map +1 -0
- package/dist/conversational-flow/index.d.ts +33 -16
- package/dist/conversational-flow/index.d.ts.map +1 -1
- package/dist/conversational-flow/index.js +42 -9
- package/dist/conversational-flow/index.js.map +1 -1
- package/dist/conversational-flow/json.d.ts +15 -0
- package/dist/conversational-flow/json.d.ts.map +1 -0
- package/dist/conversational-flow/json.js +14 -0
- package/dist/conversational-flow/json.js.map +1 -0
- package/dist/conversational-flow/jumps.d.ts +22 -0
- package/dist/conversational-flow/jumps.d.ts.map +1 -0
- package/dist/conversational-flow/jumps.js +160 -0
- package/dist/conversational-flow/jumps.js.map +1 -0
- package/dist/conversational-flow/locate.d.ts +30 -0
- package/dist/conversational-flow/locate.d.ts.map +1 -0
- package/dist/conversational-flow/locate.js +73 -0
- package/dist/conversational-flow/locate.js.map +1 -0
- package/dist/conversational-flow/paths.d.ts +31 -0
- package/dist/conversational-flow/paths.d.ts.map +1 -0
- package/dist/conversational-flow/paths.js +50 -0
- package/dist/conversational-flow/paths.js.map +1 -0
- package/dist/conversational-flow/prompt.d.ts +48 -0
- package/dist/conversational-flow/prompt.d.ts.map +1 -0
- package/dist/conversational-flow/prompt.js +161 -0
- package/dist/conversational-flow/prompt.js.map +1 -0
- package/dist/conversational-flow/read.d.ts +9 -17
- package/dist/conversational-flow/read.d.ts.map +1 -1
- package/dist/conversational-flow/read.js +217 -384
- package/dist/conversational-flow/read.js.map +1 -1
- package/dist/conversational-flow/rounds.d.ts +29 -0
- package/dist/conversational-flow/rounds.d.ts.map +1 -0
- package/dist/conversational-flow/rounds.js +41 -0
- package/dist/conversational-flow/rounds.js.map +1 -0
- package/dist/conversational-flow/routers.d.ts +24 -80
- package/dist/conversational-flow/routers.d.ts.map +1 -1
- package/dist/conversational-flow/routers.js +76 -262
- package/dist/conversational-flow/routers.js.map +1 -1
- package/dist/conversational-flow/settle.d.ts +21 -15
- package/dist/conversational-flow/settle.d.ts.map +1 -1
- package/dist/conversational-flow/settle.js +240 -38
- package/dist/conversational-flow/settle.js.map +1 -1
- package/dist/conversational-flow/shape.d.ts +114 -0
- package/dist/conversational-flow/shape.d.ts.map +1 -0
- package/dist/conversational-flow/shape.js +209 -0
- package/dist/conversational-flow/shape.js.map +1 -0
- package/dist/conversational-flow/testing.d.ts +54 -0
- package/dist/conversational-flow/testing.d.ts.map +1 -0
- package/dist/conversational-flow/testing.js +119 -0
- package/dist/conversational-flow/testing.js.map +1 -0
- package/dist/conversational-flow/tree.d.ts +28 -17
- package/dist/conversational-flow/tree.d.ts.map +1 -1
- package/dist/conversational-flow/tree.js +60 -47
- package/dist/conversational-flow/tree.js.map +1 -1
- package/dist/conversational-flow/turn.d.ts +20 -22
- package/dist/conversational-flow/turn.d.ts.map +1 -1
- package/dist/conversational-flow/turn.js +69 -48
- package/dist/conversational-flow/turn.js.map +1 -1
- package/dist/conversational-flow/types.d.ts +154 -118
- package/dist/conversational-flow/types.d.ts.map +1 -1
- package/dist/conversational-flow/types.js +27 -51
- package/dist/conversational-flow/types.js.map +1 -1
- package/dist/conversational-flow/typing.d.ts +31 -0
- package/dist/conversational-flow/typing.d.ts.map +1 -0
- package/dist/conversational-flow/typing.js +53 -0
- package/dist/conversational-flow/typing.js.map +1 -0
- package/dist/engine/config-validator.js +2 -2
- package/dist/engine/config-validator.js.map +1 -1
- package/dist/engine/variable-resolver.d.ts +16 -0
- package/dist/engine/variable-resolver.d.ts.map +1 -1
- package/dist/engine/variable-resolver.js +46 -2
- package/dist/engine/variable-resolver.js.map +1 -1
- package/dist/engine/workflow-executor.d.ts.map +1 -1
- package/dist/engine/workflow-executor.js +10 -0
- package/dist/engine/workflow-executor.js.map +1 -1
- package/dist/runtime/workflow-runtime.d.ts.map +1 -1
- package/dist/runtime/workflow-runtime.js +3 -0
- package/dist/runtime/workflow-runtime.js.map +1 -1
- package/dist/steps/base-step.d.ts.map +1 -1
- package/dist/steps/base-step.js +1 -0
- package/dist/steps/base-step.js.map +1 -1
- package/dist/testing/mock-context.d.ts.map +1 -1
- package/dist/testing/mock-context.js +1 -0
- package/dist/testing/mock-context.js.map +1 -1
- package/dist/types/context.d.ts +15 -0
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/pause-state.d.ts +9 -0
- package/dist/types/pause-state.d.ts.map +1 -1
- package/dist/util/variable-ref.d.ts +1 -1
- package/dist/util/variable-ref.d.ts.map +1 -1
- package/dist/util/variable-ref.js +1 -1
- package/dist/util/variable-ref.js.map +1 -1
- package/package.json +1 -1
- package/dist/conversational-flow/edit.d.ts +0 -101
- package/dist/conversational-flow/edit.d.ts.map +0 -1
- package/dist/conversational-flow/edit.js +0 -785
- package/dist/conversational-flow/edit.js.map +0 -1
- package/dist/conversational-flow/internals.d.ts +0 -51
- package/dist/conversational-flow/internals.d.ts.map +0 -1
- package/dist/conversational-flow/internals.js +0 -163
- package/dist/conversational-flow/internals.js.map +0 -1
- package/dist/conversational-flow/lookup-edit.d.ts +0 -96
- package/dist/conversational-flow/lookup-edit.d.ts.map +0 -1
- package/dist/conversational-flow/lookup-edit.js +0 -266
- package/dist/conversational-flow/lookup-edit.js.map +0 -1
- package/dist/conversational-flow/lookups.d.ts +0 -46
- package/dist/conversational-flow/lookups.d.ts.map +0 -1
- package/dist/conversational-flow/lookups.js +0 -145
- package/dist/conversational-flow/lookups.js.map +0 -1
- package/dist/conversational-flow/router-edit.d.ts +0 -53
- package/dist/conversational-flow/router-edit.d.ts.map +0 -1
- package/dist/conversational-flow/router-edit.js +0 -191
- package/dist/conversational-flow/router-edit.js.map +0 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The router: what reads a typed message and opens the screen that fits.
|
|
3
|
+
*
|
|
4
|
+
* Two things here are the author's, and nothing else is. Which service answers,
|
|
5
|
+
* and what they want it told — and, per screen or per section, which router the
|
|
6
|
+
* typing goes to.
|
|
7
|
+
*
|
|
8
|
+
* What a router may *choose* is never edited: it is the screens its own frame
|
|
9
|
+
* holds, which `settle` writes after every change. So a router in the
|
|
10
|
+
* conversation's frame reaches the whole flow and one inside a section reaches
|
|
11
|
+
* that section, without anything having to say so.
|
|
12
|
+
*/
|
|
13
|
+
import type { WorkflowConfig } from '../../types/workflow-config.js';
|
|
14
|
+
import { type RouterMode } from './build.js';
|
|
15
|
+
export interface RouterService {
|
|
16
|
+
/** The model id the classifier asks for. */
|
|
17
|
+
model?: string;
|
|
18
|
+
/** The credential holding where that service lives and the key it takes. */
|
|
19
|
+
credentialName?: string | null;
|
|
20
|
+
/** Below this it opens the first screen instead of guessing; `null` to stop. */
|
|
21
|
+
minConfidence?: number | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Which service decides, for every router in the flow.
|
|
25
|
+
*
|
|
26
|
+
* One flow, one service: a router in a section asks the same model as the one
|
|
27
|
+
* at the top, because the choice is about the deployment and not about the
|
|
28
|
+
* screens being chosen between.
|
|
29
|
+
*/
|
|
30
|
+
export declare function setRouterService(config: WorkflowConfig, service: RouterService): WorkflowConfig;
|
|
31
|
+
/**
|
|
32
|
+
* What the author wants this router told, on top of the screens themselves.
|
|
33
|
+
* Kept on the step's description, and put first in what it is asked.
|
|
34
|
+
*/
|
|
35
|
+
export declare function setRouterGuidance(config: WorkflowConfig, screenId: string, guidance: string): WorkflowConfig;
|
|
36
|
+
export type { RouterMode } from './build.js';
|
|
37
|
+
/**
|
|
38
|
+
* Change what answers this router, keeping everything about it that is the
|
|
39
|
+
* author's: its guidance, and the screens it may open — which are its frame's,
|
|
40
|
+
* not its own.
|
|
41
|
+
*
|
|
42
|
+
* The step keeps its id, so the jump that carries its answer only has to name
|
|
43
|
+
* the answer differently: a class, or a field of what the agent replied.
|
|
44
|
+
*/
|
|
45
|
+
export declare function setRouterMode(config: WorkflowConfig, screenId: string, wanted: RouterMode): WorkflowConfig;
|
|
46
|
+
/**
|
|
47
|
+
* Send what is typed on one screen to a particular router.
|
|
48
|
+
*
|
|
49
|
+
* This is the exception, made screen by screen: a screen inside Payments may keep
|
|
50
|
+
* its typing in Payments while its neighbour asks the router at the top. Only a
|
|
51
|
+
* router whose frame encloses the screen can be reached from it.
|
|
52
|
+
*/
|
|
53
|
+
export declare function setTypedRouter(config: WorkflowConfig, screenId: string, routerId: string): WorkflowConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Keep typed messages inside a section — or stop keeping them there.
|
|
56
|
+
*
|
|
57
|
+
* On: the section gets a router of its own, in its own frame, asking the same
|
|
58
|
+
* service as the flow's, and every screen inside it sends its typing there. Off:
|
|
59
|
+
* that router goes, and those screens fall back to the nearest one outside.
|
|
60
|
+
*
|
|
61
|
+
* It is a bulk action rather than a rule, which is what makes an exception
|
|
62
|
+
* possible at all: a total derivation would erase one on the next edit.
|
|
63
|
+
*/
|
|
64
|
+
export declare function scopeRouter(config: WorkflowConfig, sectionId: string, on: boolean): WorkflowConfig;
|
|
65
|
+
//# sourceMappingURL=routers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routers.d.ts","sourceRoot":"","sources":["../../../src/conversational-flow/edit/routers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AASrE,OAAO,EAA2C,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAGtF,MAAM,WAAW,aAAa;IAC5B,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,gFAAgF;IAChF,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,GAAG,cAAc,CA2B/F;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAU5G;AAeD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,cAAc,CAuB1G;AAID;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAgBzG;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,GAAG,cAAc,CA6ClG"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { asArray, asRec } from '../json.js';
|
|
2
|
+
import { caseFor } from '../locate.js';
|
|
3
|
+
import { frameOf, routerFor, routersFor, routersOf, scopeOf } from '../routers.js';
|
|
4
|
+
import { ConversationalFlowEditError, requireFlow, settle } from '../settle.js';
|
|
5
|
+
import { jumpsIn, partsOf, screenCase } from '../shape.js';
|
|
6
|
+
import { subtreeOf } from '../tree.js';
|
|
7
|
+
import { pointTypingAt } from '../typing.js';
|
|
8
|
+
import { decidingStep, routerAnswer, routerSteps } from './build.js';
|
|
9
|
+
import { frameFor, lift } from './cases.js';
|
|
10
|
+
/**
|
|
11
|
+
* Which service decides, for every router in the flow.
|
|
12
|
+
*
|
|
13
|
+
* One flow, one service: a router in a section asks the same model as the one
|
|
14
|
+
* at the top, because the choice is about the deployment and not about the
|
|
15
|
+
* screens being chosen between.
|
|
16
|
+
*/
|
|
17
|
+
export function setRouterService(config, service) {
|
|
18
|
+
const flow = requireFlow(config);
|
|
19
|
+
if (typeof service.minConfidence === 'number' && (service.minConfidence < 0 || service.minConfidence > 1)) {
|
|
20
|
+
throw new ConversationalFlowEditError('How sure it must be is a fraction between 0 and 1.');
|
|
21
|
+
}
|
|
22
|
+
if (!flow.screens.some((s) => s.router?.mode === 'classifier')) {
|
|
23
|
+
throw new ConversationalFlowEditError('This flow has no classifier to configure.');
|
|
24
|
+
}
|
|
25
|
+
return settle(config, (draft) => {
|
|
26
|
+
const live = requireFlow(draft);
|
|
27
|
+
for (const screen of live.screens) {
|
|
28
|
+
if (screen.router?.mode !== 'classifier')
|
|
29
|
+
continue;
|
|
30
|
+
const step = decidingStep_(draft, live, screen);
|
|
31
|
+
if (!step)
|
|
32
|
+
continue;
|
|
33
|
+
if (service.model !== undefined)
|
|
34
|
+
step.config['model'] = service.model;
|
|
35
|
+
if (service.credentialName !== undefined) {
|
|
36
|
+
if (service.credentialName)
|
|
37
|
+
step.config['credentialName'] = service.credentialName;
|
|
38
|
+
else
|
|
39
|
+
delete step.config['credentialName'];
|
|
40
|
+
}
|
|
41
|
+
if (service.minConfidence !== undefined) {
|
|
42
|
+
// Where an unsure message goes follows from where the router sits, so
|
|
43
|
+
// `settle` places it; this only says whether there is a bar at all.
|
|
44
|
+
if (service.minConfidence === null)
|
|
45
|
+
delete step.config['minConfidence'];
|
|
46
|
+
else
|
|
47
|
+
step.config['minConfidence'] = service.minConfidence;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* What the author wants this router told, on top of the screens themselves.
|
|
54
|
+
* Kept on the step's description, and put first in what it is asked.
|
|
55
|
+
*/
|
|
56
|
+
export function setRouterGuidance(config, screenId, guidance) {
|
|
57
|
+
requireRouter(requireFlow(config), screenId);
|
|
58
|
+
const text = guidance.trim();
|
|
59
|
+
return settle(config, (draft) => {
|
|
60
|
+
const live = requireFlow(draft);
|
|
61
|
+
const step = decidingStep_(draft, live, requireRouter(live, screenId));
|
|
62
|
+
if (!step)
|
|
63
|
+
return;
|
|
64
|
+
if (text)
|
|
65
|
+
step.description = text;
|
|
66
|
+
else
|
|
67
|
+
delete step.description;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function decidingStep_(config, flow, screen) {
|
|
71
|
+
const entry = caseFor(config, flow, screen);
|
|
72
|
+
if (!entry)
|
|
73
|
+
return undefined;
|
|
74
|
+
return partsOf(entry, flow.routeKey).rest.find((step) => step.id === screen.router?.stepId);
|
|
75
|
+
}
|
|
76
|
+
function requireRouter(flow, id) {
|
|
77
|
+
const screen = flow.screens.find((s) => s.id === id);
|
|
78
|
+
if (!screen)
|
|
79
|
+
throw new ConversationalFlowEditError(`There is no screen “${id}”.`);
|
|
80
|
+
if (!screen.router)
|
|
81
|
+
throw new ConversationalFlowEditError(`“${screen.title}” doesn’t read typed messages.`);
|
|
82
|
+
return screen;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Change what answers this router, keeping everything about it that is the
|
|
86
|
+
* author's: its guidance, and the screens it may open — which are its frame's,
|
|
87
|
+
* not its own.
|
|
88
|
+
*
|
|
89
|
+
* The step keeps its id, so the jump that carries its answer only has to name
|
|
90
|
+
* the answer differently: a class, or a field of what the agent replied.
|
|
91
|
+
*/
|
|
92
|
+
export function setRouterMode(config, screenId, wanted) {
|
|
93
|
+
requireRouter(requireFlow(config), screenId);
|
|
94
|
+
if (wanted.mode === 'agent' && !wanted.agentSlug.trim()) {
|
|
95
|
+
throw new ConversationalFlowEditError('Say which agent should read what they type.');
|
|
96
|
+
}
|
|
97
|
+
return settle(config, (draft) => {
|
|
98
|
+
const flow = requireFlow(draft);
|
|
99
|
+
const screen = requireRouter(flow, screenId);
|
|
100
|
+
const entry = caseFor(draft, flow, screen);
|
|
101
|
+
const old = decidingStep_(draft, flow, screen);
|
|
102
|
+
if (!entry || !old)
|
|
103
|
+
return;
|
|
104
|
+
const steps = asArray(entry['steps']);
|
|
105
|
+
const at = steps.indexOf(old);
|
|
106
|
+
if (at === -1)
|
|
107
|
+
return;
|
|
108
|
+
steps[at] = decidingStep(old.id, wanted, old.description);
|
|
109
|
+
const answer = routerAnswer(old.id, wanted, flow.routeKey);
|
|
110
|
+
for (const jump of jumpsIn(steps)) {
|
|
111
|
+
const carried = asRec(jump.config['with']);
|
|
112
|
+
if (String(carried[flow.routeKey] ?? '').includes(`steps.${old.id}.output`))
|
|
113
|
+
carried[flow.routeKey] = answer;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// ─── Which router a screen's typing goes to ───
|
|
118
|
+
/**
|
|
119
|
+
* Send what is typed on one screen to a particular router.
|
|
120
|
+
*
|
|
121
|
+
* This is the exception, made screen by screen: a screen inside Payments may keep
|
|
122
|
+
* its typing in Payments while its neighbour asks the router at the top. Only a
|
|
123
|
+
* router whose frame encloses the screen can be reached from it.
|
|
124
|
+
*/
|
|
125
|
+
export function setTypedRouter(config, screenId, routerId) {
|
|
126
|
+
const flow = requireFlow(config);
|
|
127
|
+
const screen = requireScreen(flow, screenId);
|
|
128
|
+
const router = requireRouter(flow, routerId);
|
|
129
|
+
if (!routersFor(flow, screenId).some((r) => r.id === routerId)) {
|
|
130
|
+
const where = scopeOf(flow, router);
|
|
131
|
+
throw new ConversationalFlowEditError(`“${router.title}” only serves ${where ? `“${where.title}” and the screens inside it` : 'the conversation'}, so “${screen.title}” cannot reach it.`);
|
|
132
|
+
}
|
|
133
|
+
if (!screen.prompts.some((p) => p.freeText)) {
|
|
134
|
+
throw new ConversationalFlowEditError(`“${screen.title}” doesn’t take typing. Turn it on first.`);
|
|
135
|
+
}
|
|
136
|
+
return settle(config, (draft) => {
|
|
137
|
+
pointTypingAt(draft, requireFlow(draft), screenId, routerId);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Keep typed messages inside a section — or stop keeping them there.
|
|
142
|
+
*
|
|
143
|
+
* On: the section gets a router of its own, in its own frame, asking the same
|
|
144
|
+
* service as the flow's, and every screen inside it sends its typing there. Off:
|
|
145
|
+
* that router goes, and those screens fall back to the nearest one outside.
|
|
146
|
+
*
|
|
147
|
+
* It is a bulk action rather than a rule, which is what makes an exception
|
|
148
|
+
* possible at all: a total derivation would erase one on the next edit.
|
|
149
|
+
*/
|
|
150
|
+
export function scopeRouter(config, sectionId, on) {
|
|
151
|
+
const flow = requireFlow(config);
|
|
152
|
+
const section = requireScreen(flow, sectionId);
|
|
153
|
+
if (sectionId === flow.rootScreen) {
|
|
154
|
+
throw new ConversationalFlowEditError('The conversation’s own router already serves everything.');
|
|
155
|
+
}
|
|
156
|
+
const existing = routersOf(flow).find((r) => frameOf(flow, r) === sectionId);
|
|
157
|
+
if (on === Boolean(existing))
|
|
158
|
+
return config;
|
|
159
|
+
if (on) {
|
|
160
|
+
if (section.children.length === 0) {
|
|
161
|
+
throw new ConversationalFlowEditError(`Nothing is inside “${section.title}”, so there is nothing to keep typing in.`);
|
|
162
|
+
}
|
|
163
|
+
const outer = routersFor(flow, sectionId)[0]?.router;
|
|
164
|
+
const wanted = outer?.mode === 'agent'
|
|
165
|
+
? { mode: 'agent', agentSlug: outer.agent ?? '' }
|
|
166
|
+
: {
|
|
167
|
+
mode: 'classifier',
|
|
168
|
+
...(outer?.model ? { model: outer.model } : {}),
|
|
169
|
+
...(outer?.credentialName ? { credentialName: outer.credentialName } : {}),
|
|
170
|
+
...(outer?.minConfidence !== undefined ? { minConfidence: outer.minConfidence } : {}),
|
|
171
|
+
};
|
|
172
|
+
const routerId = unique(`route_${sectionId}`, new Set(flow.screens.map((s) => s.id)));
|
|
173
|
+
return settle(config, (draft) => {
|
|
174
|
+
const live = requireFlow(draft);
|
|
175
|
+
const built = routerSteps(draft, live, { screenId: routerId, wanted });
|
|
176
|
+
frameFor(draft, live, sectionId).push(screenCase(routerId, `${section.title} — typed messages`, built, live.routeKey));
|
|
177
|
+
const settled = requireFlow(draft);
|
|
178
|
+
for (const id of subtreeOf(settled, sectionId))
|
|
179
|
+
pointTypingAt(draft, settled, id, routerId);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const router = existing;
|
|
183
|
+
const fallback = routersFor(flow, sectionId).find((r) => r.id !== router.id);
|
|
184
|
+
if (!fallback) {
|
|
185
|
+
throw new ConversationalFlowEditError('There is no other router to send typed messages to.');
|
|
186
|
+
}
|
|
187
|
+
return settle(config, (draft) => {
|
|
188
|
+
const live = requireFlow(draft);
|
|
189
|
+
for (const id of subtreeOf(live, sectionId)) {
|
|
190
|
+
if (routerFor(live, id)?.id === router.id)
|
|
191
|
+
pointTypingAt(draft, live, id, fallback.id);
|
|
192
|
+
}
|
|
193
|
+
lift(draft, requireFlow(draft), router.id);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function requireScreen(flow, id) {
|
|
197
|
+
const screen = flow.screens.find((s) => s.id === id);
|
|
198
|
+
if (!screen)
|
|
199
|
+
throw new ConversationalFlowEditError(`There is no screen “${id}”.`);
|
|
200
|
+
return screen;
|
|
201
|
+
}
|
|
202
|
+
function unique(base, taken) {
|
|
203
|
+
let name = base;
|
|
204
|
+
for (let n = 2; taken.has(name); n += 1)
|
|
205
|
+
name = `${base}_${n}`;
|
|
206
|
+
return name;
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=routers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routers.js","sourceRoot":"","sources":["../../../src/conversational-flow/edit/routers.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAa,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,2BAA2B,EAAE,WAAW,EAAE,MAAM,EAAE,MA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MAAM,EAAE,IAAI,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC;YAC5C,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,KAAK,MAAM,CAAC,EAAE;gBAAE,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;QACzF,CAAC;QACD,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,IAAwB,EAAE,EAAU;IACzD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,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;AAED,SAAS,MAAM,CAAC,IAAY,EAAE,KAAkB;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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adding, naming, moving and removing screens.
|
|
3
|
+
*
|
|
4
|
+
* A screen is a case; where that case sits is where the screen is, and putting a
|
|
5
|
+
* case somewhere is `cases.ts`'s job. What is left here is what an author means
|
|
6
|
+
* by adding, naming, moving or removing a screen: which options follow it, and
|
|
7
|
+
* what a new one asks.
|
|
8
|
+
*
|
|
9
|
+
* Everything derived — the subtrees each section claims, where each jump is
|
|
10
|
+
* aimed, the headings — is `settle`'s, and runs after every one of these.
|
|
11
|
+
*/
|
|
12
|
+
import type { WorkflowConfig } from '../../types/workflow-config.js';
|
|
13
|
+
import type { NewScreenType } from './kinds.js';
|
|
14
|
+
export interface NewScreen {
|
|
15
|
+
title: string;
|
|
16
|
+
/** The screen it goes inside. */
|
|
17
|
+
parent: string;
|
|
18
|
+
/** What kind of screen it is. A plain one that asks, unless another is named. */
|
|
19
|
+
type?: NewScreenType;
|
|
20
|
+
/** Its id, when the caller wants to choose one; otherwise made from the title. */
|
|
21
|
+
id?: string;
|
|
22
|
+
/** The agent an Ask AI screen asks. */
|
|
23
|
+
agentSlug?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Put a new screen inside `parent`, and give the parent an option that opens it.
|
|
27
|
+
*
|
|
28
|
+
* Its question is modelled on one the flow already has, so the field names and
|
|
29
|
+
* the way typed text is handled stay whatever this flow uses.
|
|
30
|
+
*/
|
|
31
|
+
export declare function addScreen(config: WorkflowConfig, args: NewScreen): {
|
|
32
|
+
config: WorkflowConfig;
|
|
33
|
+
screenId: string;
|
|
34
|
+
};
|
|
35
|
+
/** What the screen is called. Its id is what other things name it by, and stays. */
|
|
36
|
+
export declare function renameScreen(config: WorkflowConfig, screenId: string, title: string): WorkflowConfig;
|
|
37
|
+
/** Move a screen, and everything inside it, into another screen. */
|
|
38
|
+
export declare function moveScreen(config: WorkflowConfig, screenId: string, parentId: string): WorkflowConfig;
|
|
39
|
+
/**
|
|
40
|
+
* Remove a screen, and the options that opened it. A screen with screens inside
|
|
41
|
+
* it is refused: they would go with it, and that is a different decision.
|
|
42
|
+
*/
|
|
43
|
+
export declare function removeScreen(config: WorkflowConfig, screenId: string): WorkflowConfig;
|
|
44
|
+
//# sourceMappingURL=screens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screens.d.ts","sourceRoot":"","sources":["../../../src/conversational-flow/edit/screens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAQrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAKhD,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,kFAAkF;IAClF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,GAAG;IAAE,MAAM,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAsB/G;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,cAAc,CAcpG;AAED,oEAAoE;AACpE,wBAAgB,UAAU,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAerG;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAcrF"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { caseFor, sectionCaseFor } from '../locate.js';
|
|
2
|
+
import { routersFor } from '../routers.js';
|
|
3
|
+
import { ConversationalFlowEditError, requireFlow, settle } from '../settle.js';
|
|
4
|
+
import { screenCase } from '../shape.js';
|
|
5
|
+
import { subtreeOf } from '../tree.js';
|
|
6
|
+
import { stepsForKind } from './build.js';
|
|
7
|
+
import { frameFor, lift } from './cases.js';
|
|
8
|
+
import { dropOptionsTo, optionList, relabelOptionsTo, waysBackTo } from './options.js';
|
|
9
|
+
/**
|
|
10
|
+
* Put a new screen inside `parent`, and give the parent an option that opens it.
|
|
11
|
+
*
|
|
12
|
+
* Its question is modelled on one the flow already has, so the field names and
|
|
13
|
+
* the way typed text is handled stay whatever this flow uses.
|
|
14
|
+
*/
|
|
15
|
+
export function addScreen(config, args) {
|
|
16
|
+
const flow = requireFlow(config);
|
|
17
|
+
const parent = requireScreen(flow, args.parent);
|
|
18
|
+
if (parent.kind === 'router')
|
|
19
|
+
throw new ConversationalFlowEditError('A router decides where typed messages go; nothing sits inside it.');
|
|
20
|
+
if (parent.kind === 'end')
|
|
21
|
+
throw new ConversationalFlowEditError(`“${parent.title}” ends the conversation, so nothing follows it.`);
|
|
22
|
+
const title = args.title.trim();
|
|
23
|
+
if (!title)
|
|
24
|
+
throw new ConversationalFlowEditError('A screen needs a name.');
|
|
25
|
+
const screenId = unique(args.id ?? slug(title), new Set(flow.screens.map((s) => s.id)));
|
|
26
|
+
const next = settle(config, (draft) => {
|
|
27
|
+
const at = requireFlow(draft);
|
|
28
|
+
const holder = frameFor(draft, at, args.parent);
|
|
29
|
+
const parent = requireScreen(at, args.parent);
|
|
30
|
+
const built = newScreenSteps(draft, at, screenId, title, parent, args);
|
|
31
|
+
holder.push(screenCase(screenId, title, built, at.routeKey));
|
|
32
|
+
// Giving a leaf its first child moved the parent's own case inside a new
|
|
33
|
+
// loop, so where its question lives is read again before it is changed.
|
|
34
|
+
const settled = requireFlow(draft);
|
|
35
|
+
offerOn(draft, settled, args.parent, { label: title, value: screenId });
|
|
36
|
+
});
|
|
37
|
+
return { config: next, screenId };
|
|
38
|
+
}
|
|
39
|
+
/** What the screen is called. Its id is what other things name it by, and stays. */
|
|
40
|
+
export function renameScreen(config, screenId, title) {
|
|
41
|
+
const trimmed = title.trim();
|
|
42
|
+
if (!trimmed)
|
|
43
|
+
throw new ConversationalFlowEditError('A screen needs a name.');
|
|
44
|
+
const flow = requireFlow(config);
|
|
45
|
+
requireScreen(flow, screenId);
|
|
46
|
+
return settle(config, (draft) => {
|
|
47
|
+
const at = requireFlow(draft);
|
|
48
|
+
const screen = requireScreen(at, screenId);
|
|
49
|
+
const own = caseFor(draft, at, screen);
|
|
50
|
+
if (own)
|
|
51
|
+
own['label'] = trimmed;
|
|
52
|
+
const section = screen.children.length > 0 ? sectionCaseFor(draft, at, screen) : undefined;
|
|
53
|
+
if (section)
|
|
54
|
+
section['label'] = trimmed;
|
|
55
|
+
relabelOptionsTo(draft, at, screenId, trimmed);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/** Move a screen, and everything inside it, into another screen. */
|
|
59
|
+
export function moveScreen(config, screenId, parentId) {
|
|
60
|
+
const flow = requireFlow(config);
|
|
61
|
+
const screen = requireScreen(flow, screenId);
|
|
62
|
+
const parent = requireScreen(flow, parentId);
|
|
63
|
+
if (screen.id === flow.rootScreen)
|
|
64
|
+
throw new ConversationalFlowEditError('The first screen is the conversation; it cannot move.');
|
|
65
|
+
if (screen.parent === parentId)
|
|
66
|
+
return config;
|
|
67
|
+
if (subtreeOf(flow, screenId).includes(parentId)) {
|
|
68
|
+
throw new ConversationalFlowEditError(`“${parent.title}” is inside “${screen.title}”, so it cannot also hold it.`);
|
|
69
|
+
}
|
|
70
|
+
return settle(config, (draft) => {
|
|
71
|
+
const at = requireFlow(draft);
|
|
72
|
+
const lifted = lift(draft, at, screenId);
|
|
73
|
+
frameFor(draft, requireFlow(draft), parentId).push(lifted);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Remove a screen, and the options that opened it. A screen with screens inside
|
|
78
|
+
* it is refused: they would go with it, and that is a different decision.
|
|
79
|
+
*/
|
|
80
|
+
export function removeScreen(config, screenId) {
|
|
81
|
+
const flow = requireFlow(config);
|
|
82
|
+
const screen = requireScreen(flow, screenId);
|
|
83
|
+
if (screen.id === flow.rootScreen)
|
|
84
|
+
throw new ConversationalFlowEditError('The first screen can’t be removed.');
|
|
85
|
+
if (screen.children.length > 0) {
|
|
86
|
+
throw new ConversationalFlowEditError(`Move what is inside “${screen.title}” somewhere else first — ${screen.children.length === 1 ? 'it would go' : 'they would go'} with it.`);
|
|
87
|
+
}
|
|
88
|
+
return settle(config, (draft) => {
|
|
89
|
+
const at = requireFlow(draft);
|
|
90
|
+
lift(draft, at, screenId);
|
|
91
|
+
dropOptionsTo(draft, requireFlow(draft), screenId);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* What a new screen is made of. A screen that asks is the common case; every
|
|
96
|
+
* other kind is built the same way `setScreenType` builds it, so a screen
|
|
97
|
+
* created as a Finish and a screen turned into one are the same screen.
|
|
98
|
+
*/
|
|
99
|
+
function newScreenSteps(draft, flow, screenId, title, parent, args) {
|
|
100
|
+
const nearest = routersFor(flow, parent.id)[0];
|
|
101
|
+
return stepsForKind(draft, flow, args.type, {
|
|
102
|
+
screenId,
|
|
103
|
+
title,
|
|
104
|
+
prompt: '',
|
|
105
|
+
options: waysBackTo(flow, parent.id),
|
|
106
|
+
// Typing goes wherever typing goes from the screen it sits in.
|
|
107
|
+
...(nearest ? { router: nearest.id } : {}),
|
|
108
|
+
...(args.agentSlug ? { agentSlug: args.agentSlug } : {}),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Give the parent an option that opens the new screen, above its ways back. */
|
|
112
|
+
function offerOn(draft, flow, screenId, option) {
|
|
113
|
+
const screen = requireScreen(flow, screenId);
|
|
114
|
+
const prompt = screen.prompts[0];
|
|
115
|
+
if (!prompt)
|
|
116
|
+
return;
|
|
117
|
+
const options = optionList(draft, flow, screen, prompt.id);
|
|
118
|
+
const firstBack = prompt.options.findIndex((o) => o.back);
|
|
119
|
+
options.splice(firstBack === -1 ? options.length : firstBack, 0, option);
|
|
120
|
+
}
|
|
121
|
+
// ─── Plumbing ───
|
|
122
|
+
function requireScreen(flow, id) {
|
|
123
|
+
const screen = flow.screens.find((s) => s.id === id);
|
|
124
|
+
if (!screen)
|
|
125
|
+
throw new ConversationalFlowEditError(`There is no screen “${id}”.`);
|
|
126
|
+
return screen;
|
|
127
|
+
}
|
|
128
|
+
function unique(base, taken) {
|
|
129
|
+
let name = base;
|
|
130
|
+
for (let n = 2; taken.has(name); n += 1)
|
|
131
|
+
name = `${base}_${n}`;
|
|
132
|
+
return name;
|
|
133
|
+
}
|
|
134
|
+
function slug(title) {
|
|
135
|
+
return title.toLowerCase().normalize('NFKD').replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '') || 'screen';
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=screens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screens.js","sourceRoot":"","sources":["../../../src/conversational-flow/edit/screens.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAevF;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,MAAsB,EAAE,IAAe;IAC/D,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ;QA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,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,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A screen that asks differently depending on the data.
|
|
3
|
+
*
|
|
4
|
+
* The construct is the one a Questions screen already uses — a SWITCH inside the
|
|
5
|
+
* case, picking what to ask — with the condition on data instead of on what they
|
|
6
|
+
* tapped. Position tells them apart: a versions switch comes *before* any
|
|
7
|
+
* question, a follow-up switch after one.
|
|
8
|
+
*
|
|
9
|
+
* case eq(screen,'my_details')
|
|
10
|
+
* SWITCH versions_my_details
|
|
11
|
+
* ├ when {{…body.plan}} eq "priority" → [ WAIT …__priority, its gate, its jumps ]
|
|
12
|
+
* └ default → [ WAIT …, its gate, its jumps ]
|
|
13
|
+
*
|
|
14
|
+
* Each branch carries its whole tail rather than sharing one: the gate has to
|
|
15
|
+
* name the question it reads, and no template can say "whichever ran". So a
|
|
16
|
+
* version is a complete way of asking — its wording, its options, both — which
|
|
17
|
+
* is also how the editor presents it.
|
|
18
|
+
*
|
|
19
|
+
* Adding the first version wraps what is already there, untouched, as `default`;
|
|
20
|
+
* removing the last unwraps it again, leaving exactly what was there before.
|
|
21
|
+
*/
|
|
22
|
+
import type { WorkflowConfig } from '../../types/workflow-config.js';
|
|
23
|
+
import type { Condition } from '../types.js';
|
|
24
|
+
/**
|
|
25
|
+
* Ask this screen a second way when `when` holds.
|
|
26
|
+
*
|
|
27
|
+
* The new version starts as a copy of the one asked otherwise — same wording,
|
|
28
|
+
* same options — because an author changes what differs, and everything that
|
|
29
|
+
* doesn't should already be right.
|
|
30
|
+
*/
|
|
31
|
+
export declare function addVersion(config: WorkflowConfig, screenId: string, when: Condition): {
|
|
32
|
+
config: WorkflowConfig;
|
|
33
|
+
promptId: string;
|
|
34
|
+
};
|
|
35
|
+
/** Change when a version is asked. */
|
|
36
|
+
export declare function setVersionWhen(config: WorkflowConfig, promptId: string, when: Condition): WorkflowConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Take a version away. The one asked when nothing else holds cannot go — it is
|
|
39
|
+
* what the screen does — and removing the last conditional one unwraps the
|
|
40
|
+
* switch, leaving the case as it was before any version was added.
|
|
41
|
+
*/
|
|
42
|
+
export declare function removeVersion(config: WorkflowConfig, promptId: string): WorkflowConfig;
|
|
43
|
+
//# sourceMappingURL=versions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versions.d.ts","sourceRoot":"","sources":["../../../src/conversational-flow/edit/versions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAMrE,OAAO,KAAK,EAAE,SAAS,EAAsC,MAAM,aAAa,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,SAAS,GACd;IAAE,MAAM,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAiC9C;AAED,sCAAsC;AACtC,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,cAAc,CAYxG;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAmBtF"}
|