@falai/agent 0.2.0 → 0.3.0
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/README.md +4 -4
- package/dist/cjs/core/State.d.ts +1 -1
- package/dist/cjs/core/State.d.ts.map +1 -1
- package/dist/cjs/core/State.js +4 -10
- package/dist/cjs/core/State.js.map +1 -1
- package/dist/cjs/types/route.d.ts +4 -6
- package/dist/cjs/types/route.d.ts.map +1 -1
- package/dist/core/State.d.ts +1 -1
- package/dist/core/State.d.ts.map +1 -1
- package/dist/core/State.js +4 -10
- package/dist/core/State.js.map +1 -1
- package/dist/types/route.d.ts +4 -6
- package/dist/types/route.d.ts.map +1 -1
- package/docs/API_REFERENCE.md +25 -1
- package/docs/GETTING_STARTED.md +3 -3
- package/examples/healthcare-agent.ts +15 -15
- package/examples/openai-agent.ts +2 -2
- package/examples/persistent-onboarding.ts +7 -7
- package/examples/travel-agent.ts +17 -17
- package/package.json +1 -1
- package/src/core/State.ts +6 -25
- package/src/types/route.ts +7 -9
package/README.md
CHANGED
|
@@ -292,12 +292,12 @@ const askName = onboardingRoute.initialState.transitionTo({
|
|
|
292
292
|
chatState: "Ask for user's full name",
|
|
293
293
|
});
|
|
294
294
|
|
|
295
|
-
const askEmail = askName.
|
|
295
|
+
const askEmail = askName.transitionTo({
|
|
296
296
|
chatState: "Request email address",
|
|
297
297
|
condition: "User provided their name",
|
|
298
298
|
});
|
|
299
299
|
|
|
300
|
-
const confirmDetails = askEmail.
|
|
300
|
+
const confirmDetails = askEmail.transitionTo({
|
|
301
301
|
chatState: "Confirm all details before proceeding",
|
|
302
302
|
});
|
|
303
303
|
|
|
@@ -310,13 +310,13 @@ onboardingRoute.createGuideline({
|
|
|
310
310
|
});
|
|
311
311
|
|
|
312
312
|
// Happy path completion
|
|
313
|
-
confirmDetails.
|
|
313
|
+
confirmDetails.transitionTo({
|
|
314
314
|
chatState: "Welcome message and next steps",
|
|
315
315
|
condition: "User confirms details",
|
|
316
316
|
});
|
|
317
317
|
|
|
318
318
|
// End the route
|
|
319
|
-
confirmDetails.
|
|
319
|
+
confirmDetails.transitionTo({ state: END_ROUTE });
|
|
320
320
|
```
|
|
321
321
|
|
|
322
322
|
### 🔀 Disambiguation with Observations
|
package/dist/cjs/core/State.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class State<TContext = unknown> {
|
|
|
19
19
|
*
|
|
20
20
|
* @param spec - Transition specification (chatState, toolState, or direct state)
|
|
21
21
|
* @param condition - Optional condition for this transition
|
|
22
|
-
* @returns
|
|
22
|
+
* @returns TransitionResult that supports chaining
|
|
23
23
|
*/
|
|
24
24
|
transitionTo(spec: TransitionSpec<TContext>, condition?: string): TransitionResult<TContext>;
|
|
25
25
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../src/core/State.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;GAEG;AACH,qBAAa,KAAK,CAAC,QAAQ,GAAG,OAAO;aAMjB,OAAO,EAAE,MAAM;aACf,WAAW,CAAC,EAAE,MAAM;IANtC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,UAAU,CAAmB;gBAGnB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,YAAA,EACpC,QAAQ,CAAC,EAAE,MAAM;IAMnB;;;;;;OAMG;IACH,YAAY,CACV,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC9B,SAAS,CAAC,EAAE,MAAM,GACjB,gBAAgB,CAAC,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../src/core/State.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;GAEG;AACH,qBAAa,KAAK,CAAC,QAAQ,GAAG,OAAO;aAMjB,OAAO,EAAE,MAAM;aACf,WAAW,CAAC,EAAE,MAAM;IANtC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,UAAU,CAAmB;gBAGnB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,YAAA,EACpC,QAAQ,CAAC,EAAE,MAAM;IAMnB;;;;;;OAMG;IACH,YAAY,CACV,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC9B,SAAS,CAAC,EAAE,MAAM,GACjB,gBAAgB,CAAC,QAAQ,CAAC;IAwC7B;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAIxC;;OAEG;IACH,aAAa,IAAI,SAAS,EAAE;IAI5B;;OAEG;IACH,cAAc,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE;IAIxC;;OAEG;IACH,MAAM,IAAI,QAAQ;IAOlB;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAapC;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAa1B"}
|
package/dist/cjs/core/State.js
CHANGED
|
@@ -24,7 +24,7 @@ class State {
|
|
|
24
24
|
*
|
|
25
25
|
* @param spec - Transition specification (chatState, toolState, or direct state)
|
|
26
26
|
* @param condition - Optional condition for this transition
|
|
27
|
-
* @returns
|
|
27
|
+
* @returns TransitionResult that supports chaining
|
|
28
28
|
*/
|
|
29
29
|
transitionTo(spec, condition) {
|
|
30
30
|
// Handle END_ROUTE
|
|
@@ -34,26 +34,20 @@ class State {
|
|
|
34
34
|
const endTransition = new Transition_1.Transition(this.getRef(), { state: constants_1.END_ROUTE }, condition);
|
|
35
35
|
this.transitions.push(endTransition);
|
|
36
36
|
// Return a terminal state reference
|
|
37
|
-
return
|
|
38
|
-
target: this.createTerminalRef(),
|
|
39
|
-
};
|
|
37
|
+
return this.createTerminalRef();
|
|
40
38
|
}
|
|
41
39
|
// Handle direct state reference
|
|
42
40
|
if (spec.state && typeof spec.state !== "symbol") {
|
|
43
41
|
const transition = new Transition_1.Transition(this.getRef(), spec, condition);
|
|
44
42
|
this.transitions.push(transition);
|
|
45
|
-
return
|
|
46
|
-
target: this.createStateRefWithTransition(spec.state),
|
|
47
|
-
};
|
|
43
|
+
return this.createStateRefWithTransition(spec.state);
|
|
48
44
|
}
|
|
49
45
|
// Create new target state for chatState or toolState
|
|
50
46
|
const targetState = new State(this.routeId, spec.chatState);
|
|
51
47
|
const transition = new Transition_1.Transition(this.getRef(), spec, condition);
|
|
52
48
|
transition.setTarget(targetState);
|
|
53
49
|
this.transitions.push(transition);
|
|
54
|
-
return
|
|
55
|
-
target: this.createStateRefWithTransition(targetState.getRef(), targetState),
|
|
56
|
-
};
|
|
50
|
+
return this.createStateRefWithTransition(targetState.getRef(), targetState);
|
|
57
51
|
}
|
|
58
52
|
/**
|
|
59
53
|
* Add a guideline specific to this state
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.js","sourceRoot":"","sources":["../../../src/core/State.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AASH,4CAAyC;AACzC,6CAA0C;AAC1C,oCAA8C;AAE9C;;GAEG;AACH,MAAa,KAAK;IAKhB,YACkB,OAAe,EACf,WAAoB,EACpC,QAAiB;QAFD,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAS;QAL9B,gBAAW,GAA2B,EAAE,CAAC;QACzC,eAAU,GAAgB,E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C,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,4BAA4B,CAClC,GAAa,EACb,KAAuB;QAEvB,MAAM,aAAa,GAAG,KAAK,IAAI,IAAI,CAAC;QAEpC,OAAO;YACL,GAAG,GAAG;YACN,YAAY,EAAE,CAAC,IAA8B,EAAE,SAAkB,EAAE,EAAE,CACnE,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC;SAC9C,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,iBAAiB;QACvB,MAAM,WAAW,GAAa;YAC5B,EAAE,EAAE,KAAK;YACT,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;QAEF,OAAO;YACL,GAAG,WAAW;YACd,YAAY,EAAE,GAAG,EAAE;gBACjB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;YAC5D,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AA/HD,sBA+HC"}
|
|
@@ -50,12 +50,10 @@ export interface TransitionSpec<TContext = unknown> {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Result of a transition operation
|
|
53
|
+
* Combines state reference with the ability to chain transitions
|
|
53
54
|
*/
|
|
54
|
-
export interface TransitionResult<TContext = unknown> {
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
/** Allow chaining transitions */
|
|
58
|
-
transitionTo: (spec: TransitionSpec<TContext>, condition?: string) => TransitionResult<TContext>;
|
|
59
|
-
};
|
|
55
|
+
export interface TransitionResult<TContext = unknown> extends StateRef {
|
|
56
|
+
/** Allow chaining transitions */
|
|
57
|
+
transitionTo: (spec: TransitionSpec<TContext>, condition?: string) => TransitionResult<TContext>;
|
|
60
58
|
}
|
|
61
59
|
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/types/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,uBAAuB;IACvB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,uBAAuB;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,qGAAqG;IACrG,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,wCAAwC;IACxC,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,QAAQ,GAAG,OAAO;IAChD,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mCAAmC;IAEnC,SAAS,CAAC,EAAE,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;IAC1C,mDAAmD;IACnD,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC3B;AAED
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/types/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,uBAAuB;IACvB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,uBAAuB;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,qGAAqG;IACrG,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,wCAAwC;IACxC,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,QAAQ,GAAG,OAAO;IAChD,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mCAAmC;IAEnC,SAAS,CAAC,EAAE,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;IAC1C,mDAAmD;IACnD,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,QAAQ,GAAG,OAAO,CAAE,SAAQ,QAAQ;IACpE,iCAAiC;IACjC,YAAY,EAAE,CACZ,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC9B,SAAS,CAAC,EAAE,MAAM,KACf,gBAAgB,CAAC,QAAQ,CAAC,CAAC;CACjC"}
|
package/dist/core/State.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class State<TContext = unknown> {
|
|
|
19
19
|
*
|
|
20
20
|
* @param spec - Transition specification (chatState, toolState, or direct state)
|
|
21
21
|
* @param condition - Optional condition for this transition
|
|
22
|
-
* @returns
|
|
22
|
+
* @returns TransitionResult that supports chaining
|
|
23
23
|
*/
|
|
24
24
|
transitionTo(spec: TransitionSpec<TContext>, condition?: string): TransitionResult<TContext>;
|
|
25
25
|
/**
|
package/dist/core/State.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../src/core/State.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;GAEG;AACH,qBAAa,KAAK,CAAC,QAAQ,GAAG,OAAO;aAMjB,OAAO,EAAE,MAAM;aACf,WAAW,CAAC,EAAE,MAAM;IANtC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,UAAU,CAAmB;gBAGnB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,YAAA,EACpC,QAAQ,CAAC,EAAE,MAAM;IAMnB;;;;;;OAMG;IACH,YAAY,CACV,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC9B,SAAS,CAAC,EAAE,MAAM,GACjB,gBAAgB,CAAC,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../src/core/State.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;GAEG;AACH,qBAAa,KAAK,CAAC,QAAQ,GAAG,OAAO;aAMjB,OAAO,EAAE,MAAM;aACf,WAAW,CAAC,EAAE,MAAM;IANtC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,UAAU,CAAmB;gBAGnB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,YAAA,EACpC,QAAQ,CAAC,EAAE,MAAM;IAMnB;;;;;;OAMG;IACH,YAAY,CACV,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC9B,SAAS,CAAC,EAAE,MAAM,GACjB,gBAAgB,CAAC,QAAQ,CAAC;IAwC7B;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAIxC;;OAEG;IACH,aAAa,IAAI,SAAS,EAAE;IAI5B;;OAEG;IACH,cAAc,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE;IAIxC;;OAEG;IACH,MAAM,IAAI,QAAQ;IAOlB;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAapC;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAa1B"}
|
package/dist/core/State.js
CHANGED
|
@@ -21,7 +21,7 @@ export class State {
|
|
|
21
21
|
*
|
|
22
22
|
* @param spec - Transition specification (chatState, toolState, or direct state)
|
|
23
23
|
* @param condition - Optional condition for this transition
|
|
24
|
-
* @returns
|
|
24
|
+
* @returns TransitionResult that supports chaining
|
|
25
25
|
*/
|
|
26
26
|
transitionTo(spec, condition) {
|
|
27
27
|
// Handle END_ROUTE
|
|
@@ -31,26 +31,20 @@ export class State {
|
|
|
31
31
|
const endTransition = new Transition(this.getRef(), { state: END_ROUTE }, condition);
|
|
32
32
|
this.transitions.push(endTransition);
|
|
33
33
|
// Return a terminal state reference
|
|
34
|
-
return
|
|
35
|
-
target: this.createTerminalRef(),
|
|
36
|
-
};
|
|
34
|
+
return this.createTerminalRef();
|
|
37
35
|
}
|
|
38
36
|
// Handle direct state reference
|
|
39
37
|
if (spec.state && typeof spec.state !== "symbol") {
|
|
40
38
|
const transition = new Transition(this.getRef(), spec, condition);
|
|
41
39
|
this.transitions.push(transition);
|
|
42
|
-
return
|
|
43
|
-
target: this.createStateRefWithTransition(spec.state),
|
|
44
|
-
};
|
|
40
|
+
return this.createStateRefWithTransition(spec.state);
|
|
45
41
|
}
|
|
46
42
|
// Create new target state for chatState or toolState
|
|
47
43
|
const targetState = new State(this.routeId, spec.chatState);
|
|
48
44
|
const transition = new Transition(this.getRef(), spec, condition);
|
|
49
45
|
transition.setTarget(targetState);
|
|
50
46
|
this.transitions.push(transition);
|
|
51
|
-
return
|
|
52
|
-
target: this.createStateRefWithTransition(targetState.getRef(), targetState),
|
|
53
|
-
};
|
|
47
|
+
return this.createStateRefWithTransition(targetState.getRef(), targetState);
|
|
54
48
|
}
|
|
55
49
|
/**
|
|
56
50
|
* Add a guideline specific to this state
|
package/dist/core/State.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.js","sourceRoot":"","sources":["../../src/core/State.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,KAAK;IAKhB,YACkB,OAAe,EACf,WAAoB,EACpC,QAAiB;QAFD,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAS;QAL9B,gBAAW,GAA2B,EAAE,CAAC;QACzC,eAAU,GAAgB,EAAE,CAAC;QAOnC,kDAAkD;QAClD,IAAI,CAAC,EAAE,GAAG,QAAQ,IAAI,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;;OAMG;IACH,YAAY,CACV,IAA8B,EAC9B,SAAkB;QAElB,mBAAmB;QACnB,IACE,IAAI,CAAC,KAAK;YACV,OAAO,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;;OAEG;IACK,4BAA4B,CAClC,GAAa,EACb,KAAuB;QAEvB,MAAM,aAAa,GAAG,KAAK,IAAI,IAAI,CAAC;QAEpC,OAAO;YACL,GAAG,GAAG;YACN,YAAY,EAAE,CAAC,IAA8B,EAAE,SAAkB,EAAE,EAAE,CACnE,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC;SAC9C,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,iBAAiB;QACvB,MAAM,WAAW,GAAa;YAC5B,EAAE,EAAE,KAAK;YACT,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;QAEF,OAAO;YACL,GAAG,WAAW;YACd,YAAY,EAAE,GAAG,EAAE;gBACjB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;YAC5D,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
package/dist/types/route.d.ts
CHANGED
|
@@ -50,12 +50,10 @@ export interface TransitionSpec<TContext = unknown> {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Result of a transition operation
|
|
53
|
+
* Combines state reference with the ability to chain transitions
|
|
53
54
|
*/
|
|
54
|
-
export interface TransitionResult<TContext = unknown> {
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
/** Allow chaining transitions */
|
|
58
|
-
transitionTo: (spec: TransitionSpec<TContext>, condition?: string) => TransitionResult<TContext>;
|
|
59
|
-
};
|
|
55
|
+
export interface TransitionResult<TContext = unknown> extends StateRef {
|
|
56
|
+
/** Allow chaining transitions */
|
|
57
|
+
transitionTo: (spec: TransitionSpec<TContext>, condition?: string) => TransitionResult<TContext>;
|
|
60
58
|
}
|
|
61
59
|
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/types/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAA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AAC;CACjB;AAED;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,qGAAqG;IACrG,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,wCAAwC;IACxC,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,QAAQ,GAAG,OAAO;IAChD,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mCAAmC;IAEnC,SAAS,CAAC,EAAE,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;IAC1C,mDAAmD;IACnD,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,QAAQ,GAAG,OAAO,CAAE,SAAQ,QAAQ;IACpE,iCAAiC;IACjC,YAAY,EAAE,CACZ,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC9B,SAAS,CAAC,EAAE,MAAM,KACf,gBAAgB,CAAC,QAAQ,CAAC,CAAC;CACjC"}
|
package/docs/API_REFERENCE.md
CHANGED
|
@@ -195,7 +195,7 @@ Represents a state within a conversation route.
|
|
|
195
195
|
|
|
196
196
|
##### `transitionTo(spec: TransitionSpec, condition?: string): TransitionResult`
|
|
197
197
|
|
|
198
|
-
Creates a transition from this state.
|
|
198
|
+
Creates a transition from this state and returns a chainable result.
|
|
199
199
|
|
|
200
200
|
```typescript
|
|
201
201
|
interface TransitionSpec {
|
|
@@ -203,6 +203,30 @@ interface TransitionSpec {
|
|
|
203
203
|
toolState?: ToolRef; // Transition to execute a tool
|
|
204
204
|
state?: StateRef | symbol; // Transition to specific state or END_ROUTE
|
|
205
205
|
}
|
|
206
|
+
|
|
207
|
+
interface TransitionResult {
|
|
208
|
+
id: string; // State identifier
|
|
209
|
+
routeId: string; // Route identifier
|
|
210
|
+
transitionTo: (spec: TransitionSpec, condition?: string) => TransitionResult;
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Returns:** A `TransitionResult` that includes the target state's reference (`id`, `routeId`) and a `transitionTo` method for chaining additional transitions.
|
|
215
|
+
|
|
216
|
+
**Example:**
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
const t0 = route.initialState.transitionTo({
|
|
220
|
+
chatState: "Ask for user name",
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const t1 = t0.transitionTo({
|
|
224
|
+
chatState: "Ask for email",
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// Access state properties
|
|
228
|
+
console.log(t1.id); // State ID
|
|
229
|
+
console.log(t1.routeId); // Route ID
|
|
206
230
|
```
|
|
207
231
|
|
|
208
232
|
##### `addGuideline(guideline: Guideline): void`
|
package/docs/GETTING_STARTED.md
CHANGED
|
@@ -159,16 +159,16 @@ const step1 = onboardingRoute.initialState.transitionTo({
|
|
|
159
159
|
chatState: "Ask for user's name",
|
|
160
160
|
});
|
|
161
161
|
|
|
162
|
-
const step2 = step1.
|
|
162
|
+
const step2 = step1.transitionTo({
|
|
163
163
|
chatState: "Ask for user's email",
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
-
const step3 = step2.
|
|
166
|
+
const step3 = step2.transitionTo({
|
|
167
167
|
chatState: "Confirm details and welcome user",
|
|
168
168
|
});
|
|
169
169
|
|
|
170
170
|
// End the route
|
|
171
|
-
step3.
|
|
171
|
+
step3.transitionTo({ state: END_ROUTE });
|
|
172
172
|
```
|
|
173
173
|
|
|
174
174
|
### Handle Context Dynamically
|
|
@@ -107,54 +107,54 @@ async function createHealthcareAgent() {
|
|
|
107
107
|
chatState: "Determine the reason for the visit",
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
const t1 = t0.
|
|
110
|
+
const t1 = t0.transitionTo({
|
|
111
111
|
toolState: getUpcomingSlots,
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
-
const t2 = t1.
|
|
114
|
+
const t2 = t1.transitionTo({
|
|
115
115
|
chatState: "List available times and ask which ones works for them",
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
const t3 = t2.
|
|
118
|
+
const t3 = t2.transitionTo(
|
|
119
119
|
{
|
|
120
120
|
chatState: "Confirm the details with the patient before scheduling",
|
|
121
121
|
},
|
|
122
122
|
"The patient picks a time"
|
|
123
123
|
);
|
|
124
124
|
|
|
125
|
-
const t4 = t3.
|
|
125
|
+
const t4 = t3.transitionTo(
|
|
126
126
|
{
|
|
127
127
|
toolState: scheduleAppointment,
|
|
128
128
|
},
|
|
129
129
|
"The patient confirms the details"
|
|
130
130
|
);
|
|
131
131
|
|
|
132
|
-
const t5 = t4.
|
|
132
|
+
const t5 = t4.transitionTo({
|
|
133
133
|
chatState: "Confirm the appointment has been scheduled",
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
-
t5.
|
|
136
|
+
t5.transitionTo({ state: END_ROUTE });
|
|
137
137
|
|
|
138
138
|
// Alternative path: no times work
|
|
139
|
-
const t6 = t2.
|
|
139
|
+
const t6 = t2.transitionTo(
|
|
140
140
|
{
|
|
141
141
|
toolState: getLaterSlots,
|
|
142
142
|
},
|
|
143
143
|
"None of those times work for the patient"
|
|
144
144
|
);
|
|
145
145
|
|
|
146
|
-
const t7 = t6.
|
|
146
|
+
const t7 = t6.transitionTo({
|
|
147
147
|
chatState: "List later times and ask if any of them works",
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
-
t7.
|
|
150
|
+
t7.transitionTo(
|
|
151
151
|
{
|
|
152
|
-
state: t3
|
|
152
|
+
state: t3,
|
|
153
153
|
},
|
|
154
154
|
"The patient picks a time"
|
|
155
155
|
);
|
|
156
156
|
|
|
157
|
-
const t8 = t7.
|
|
157
|
+
const t8 = t7.transitionTo(
|
|
158
158
|
{
|
|
159
159
|
chatState:
|
|
160
160
|
"Ask the patient to call the office to schedule an appointment",
|
|
@@ -162,7 +162,7 @@ async function createHealthcareAgent() {
|
|
|
162
162
|
"None of those times work for the patient either"
|
|
163
163
|
);
|
|
164
164
|
|
|
165
|
-
t8.
|
|
165
|
+
t8.transitionTo({ state: END_ROUTE });
|
|
166
166
|
|
|
167
167
|
schedulingRoute.createGuideline({
|
|
168
168
|
condition: "The patient says their visit is urgent",
|
|
@@ -180,7 +180,7 @@ async function createHealthcareAgent() {
|
|
|
180
180
|
toolState: getLabResults,
|
|
181
181
|
});
|
|
182
182
|
|
|
183
|
-
l0.
|
|
183
|
+
l0.transitionTo(
|
|
184
184
|
{
|
|
185
185
|
chatState:
|
|
186
186
|
"Tell the patient that the results are not available yet, and to try again later",
|
|
@@ -188,7 +188,7 @@ async function createHealthcareAgent() {
|
|
|
188
188
|
"The lab results could not be found"
|
|
189
189
|
);
|
|
190
190
|
|
|
191
|
-
l0.
|
|
191
|
+
l0.transitionTo(
|
|
192
192
|
{
|
|
193
193
|
chatState:
|
|
194
194
|
"Explain the lab results to the patient - that they are normal",
|
|
@@ -196,7 +196,7 @@ async function createHealthcareAgent() {
|
|
|
196
196
|
"The lab results are good - i.e., nothing to worry about"
|
|
197
197
|
);
|
|
198
198
|
|
|
199
|
-
l0.
|
|
199
|
+
l0.transitionTo(
|
|
200
200
|
{
|
|
201
201
|
chatState:
|
|
202
202
|
"Present the results and ask them to call the office for clarifications on the results as you are not a doctor",
|
package/examples/openai-agent.ts
CHANGED
|
@@ -108,12 +108,12 @@ async function main() {
|
|
|
108
108
|
chatState: "Ask which city they want weather for",
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
-
const fetchWeather = askLocation.
|
|
111
|
+
const fetchWeather = askLocation.transitionTo({
|
|
112
112
|
toolState: getWeather,
|
|
113
113
|
condition: "User provides a city name",
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
const showWeather = fetchWeather.
|
|
116
|
+
const showWeather = fetchWeather.transitionTo({
|
|
117
117
|
chatState:
|
|
118
118
|
"Present the weather information in a friendly way with temperature and condition",
|
|
119
119
|
});
|
|
@@ -243,34 +243,34 @@ async function createPersistentOnboardingAgent(sessionId: string) {
|
|
|
243
243
|
chatState: "Ask for business name and a brief description",
|
|
244
244
|
});
|
|
245
245
|
|
|
246
|
-
const saveBusinessStep = askBusinessInfo.
|
|
246
|
+
const saveBusinessStep = askBusinessInfo.transitionTo({
|
|
247
247
|
toolState: saveBusinessInfo,
|
|
248
248
|
});
|
|
249
249
|
|
|
250
250
|
// Step 2: Collect industry
|
|
251
|
-
const askIndustry = saveBusinessStep.
|
|
251
|
+
const askIndustry = saveBusinessStep.transitionTo({
|
|
252
252
|
chatState: "Ask what industry the business operates in",
|
|
253
253
|
});
|
|
254
254
|
|
|
255
|
-
const saveIndustryStep = askIndustry.
|
|
255
|
+
const saveIndustryStep = askIndustry.transitionTo({
|
|
256
256
|
toolState: saveIndustry,
|
|
257
257
|
});
|
|
258
258
|
|
|
259
259
|
// Step 3: Collect contact
|
|
260
|
-
const askContact = saveIndustryStep.
|
|
260
|
+
const askContact = saveIndustryStep.transitionTo({
|
|
261
261
|
chatState: "Ask for their contact email",
|
|
262
262
|
});
|
|
263
263
|
|
|
264
|
-
const saveContactStep = askContact.
|
|
264
|
+
const saveContactStep = askContact.transitionTo({
|
|
265
265
|
toolState: saveContactEmail,
|
|
266
266
|
});
|
|
267
267
|
|
|
268
268
|
// Step 4: Confirmation
|
|
269
|
-
const confirm = saveContactStep.
|
|
269
|
+
const confirm = saveContactStep.transitionTo({
|
|
270
270
|
chatState: "Summarize all collected information and ask for confirmation",
|
|
271
271
|
});
|
|
272
272
|
|
|
273
|
-
confirm.
|
|
273
|
+
confirm.transitionTo({ state: END_ROUTE });
|
|
274
274
|
|
|
275
275
|
// Guidelines
|
|
276
276
|
onboardingRoute.createGuideline({
|
package/examples/travel-agent.ts
CHANGED
|
@@ -162,20 +162,20 @@ async function createTravelAgent() {
|
|
|
162
162
|
chatState: "Ask about the destination",
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
-
const t1 = t0.
|
|
165
|
+
const t1 = t0.transitionTo({
|
|
166
166
|
chatState: "Ask about preferred travel dates",
|
|
167
167
|
});
|
|
168
168
|
|
|
169
|
-
const t2 = t1.
|
|
169
|
+
const t2 = t1.transitionTo({
|
|
170
170
|
toolState: getAvailableFlights,
|
|
171
171
|
});
|
|
172
172
|
|
|
173
|
-
const t3 = t2.
|
|
173
|
+
const t3 = t2.transitionTo({
|
|
174
174
|
chatState: "Present available flights and ask which one works for them",
|
|
175
175
|
});
|
|
176
176
|
|
|
177
177
|
// Happy path: customer selects a flight
|
|
178
|
-
const t4 = t3.
|
|
178
|
+
const t4 = t3.transitionTo(
|
|
179
179
|
{
|
|
180
180
|
chatState:
|
|
181
181
|
"Collect passenger information and confirm booking details before proceeding",
|
|
@@ -183,41 +183,41 @@ async function createTravelAgent() {
|
|
|
183
183
|
"The customer selects a flight"
|
|
184
184
|
);
|
|
185
185
|
|
|
186
|
-
const t5 = t4.
|
|
186
|
+
const t5 = t4.transitionTo(
|
|
187
187
|
{
|
|
188
188
|
toolState: bookFlight,
|
|
189
189
|
},
|
|
190
190
|
"The customer confirms the booking details"
|
|
191
191
|
);
|
|
192
192
|
|
|
193
|
-
const t6 = t5.
|
|
193
|
+
const t6 = t5.transitionTo({
|
|
194
194
|
chatState: "Provide confirmation number and booking summary",
|
|
195
195
|
});
|
|
196
196
|
|
|
197
|
-
t6.
|
|
197
|
+
t6.transitionTo({ state: END_ROUTE });
|
|
198
198
|
|
|
199
199
|
// Alternative path: no flights work
|
|
200
|
-
const t7 = t3.
|
|
200
|
+
const t7 = t3.transitionTo(
|
|
201
201
|
{
|
|
202
202
|
toolState: getAlternativeFlights,
|
|
203
203
|
},
|
|
204
204
|
"None of the flights work for the customer"
|
|
205
205
|
);
|
|
206
206
|
|
|
207
|
-
const t8 = t7.
|
|
207
|
+
const t8 = t7.transitionTo({
|
|
208
208
|
chatState: "Present alternative flights and ask if any work",
|
|
209
209
|
});
|
|
210
210
|
|
|
211
211
|
// Link back to happy path
|
|
212
|
-
t8.
|
|
212
|
+
t8.transitionTo(
|
|
213
213
|
{
|
|
214
|
-
state: t4
|
|
214
|
+
state: t4,
|
|
215
215
|
},
|
|
216
216
|
"The customer selects a flight"
|
|
217
217
|
);
|
|
218
218
|
|
|
219
219
|
// No alternative flights work either
|
|
220
|
-
const t9 = t8.
|
|
220
|
+
const t9 = t8.transitionTo(
|
|
221
221
|
{
|
|
222
222
|
chatState:
|
|
223
223
|
"Suggest calling our office or visiting our website for more options",
|
|
@@ -225,7 +225,7 @@ async function createTravelAgent() {
|
|
|
225
225
|
"None of the alternative flights work either"
|
|
226
226
|
);
|
|
227
227
|
|
|
228
|
-
t9.
|
|
228
|
+
t9.transitionTo({ state: END_ROUTE });
|
|
229
229
|
|
|
230
230
|
// Add route-specific guidelines
|
|
231
231
|
flightBookingRoute.createGuideline({
|
|
@@ -253,11 +253,11 @@ async function createTravelAgent() {
|
|
|
253
253
|
chatState: "Ask for the confirmation number or booking reference",
|
|
254
254
|
});
|
|
255
255
|
|
|
256
|
-
const s1 = s0.
|
|
256
|
+
const s1 = s0.transitionTo({
|
|
257
257
|
toolState: getBookingStatus,
|
|
258
258
|
});
|
|
259
259
|
|
|
260
|
-
s1.
|
|
260
|
+
s1.transitionTo(
|
|
261
261
|
{
|
|
262
262
|
chatState:
|
|
263
263
|
"Tell the customer that the booking could not be found and ask them to verify the confirmation number or call the office",
|
|
@@ -265,7 +265,7 @@ async function createTravelAgent() {
|
|
|
265
265
|
"The booking could not be found"
|
|
266
266
|
);
|
|
267
267
|
|
|
268
|
-
s1.
|
|
268
|
+
s1.transitionTo(
|
|
269
269
|
{
|
|
270
270
|
chatState:
|
|
271
271
|
"Provide the booking details and confirm everything is in order",
|
|
@@ -273,7 +273,7 @@ async function createTravelAgent() {
|
|
|
273
273
|
"The booking is confirmed and all details are correct"
|
|
274
274
|
);
|
|
275
275
|
|
|
276
|
-
s1.
|
|
276
|
+
s1.transitionTo(
|
|
277
277
|
{
|
|
278
278
|
chatState:
|
|
279
279
|
"Present the booking information and mention any issues or pending actions required",
|
package/package.json
CHANGED
package/src/core/State.ts
CHANGED
|
@@ -35,7 +35,7 @@ export class State<TContext = unknown> {
|
|
|
35
35
|
*
|
|
36
36
|
* @param spec - Transition specification (chatState, toolState, or direct state)
|
|
37
37
|
* @param condition - Optional condition for this transition
|
|
38
|
-
* @returns
|
|
38
|
+
* @returns TransitionResult that supports chaining
|
|
39
39
|
*/
|
|
40
40
|
transitionTo(
|
|
41
41
|
spec: TransitionSpec<TContext>,
|
|
@@ -55,9 +55,7 @@ export class State<TContext = unknown> {
|
|
|
55
55
|
this.transitions.push(endTransition);
|
|
56
56
|
|
|
57
57
|
// Return a terminal state reference
|
|
58
|
-
return
|
|
59
|
-
target: this.createTerminalRef(),
|
|
60
|
-
};
|
|
58
|
+
return this.createTerminalRef();
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
// Handle direct state reference
|
|
@@ -69,9 +67,7 @@ export class State<TContext = unknown> {
|
|
|
69
67
|
);
|
|
70
68
|
this.transitions.push(transition);
|
|
71
69
|
|
|
72
|
-
return
|
|
73
|
-
target: this.createStateRefWithTransition(spec.state),
|
|
74
|
-
};
|
|
70
|
+
return this.createStateRefWithTransition(spec.state);
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
// Create new target state for chatState or toolState
|
|
@@ -81,12 +77,7 @@ export class State<TContext = unknown> {
|
|
|
81
77
|
|
|
82
78
|
this.transitions.push(transition);
|
|
83
79
|
|
|
84
|
-
return
|
|
85
|
-
target: this.createStateRefWithTransition(
|
|
86
|
-
targetState.getRef(),
|
|
87
|
-
targetState
|
|
88
|
-
),
|
|
89
|
-
};
|
|
80
|
+
return this.createStateRefWithTransition(targetState.getRef(), targetState);
|
|
90
81
|
}
|
|
91
82
|
|
|
92
83
|
/**
|
|
@@ -126,12 +117,7 @@ export class State<TContext = unknown> {
|
|
|
126
117
|
private createStateRefWithTransition(
|
|
127
118
|
ref: StateRef,
|
|
128
119
|
state?: State<TContext>
|
|
129
|
-
):
|
|
130
|
-
transitionTo: (
|
|
131
|
-
spec: TransitionSpec<TContext>,
|
|
132
|
-
condition?: string
|
|
133
|
-
) => TransitionResult<TContext>;
|
|
134
|
-
} {
|
|
120
|
+
): TransitionResult<TContext> {
|
|
135
121
|
const stateInstance = state || this;
|
|
136
122
|
|
|
137
123
|
return {
|
|
@@ -144,12 +130,7 @@ export class State<TContext = unknown> {
|
|
|
144
130
|
/**
|
|
145
131
|
* Create a terminal state reference (for END_ROUTE)
|
|
146
132
|
*/
|
|
147
|
-
private createTerminalRef():
|
|
148
|
-
transitionTo: (
|
|
149
|
-
spec: TransitionSpec<TContext>,
|
|
150
|
-
condition?: string
|
|
151
|
-
) => TransitionResult<TContext>;
|
|
152
|
-
} {
|
|
133
|
+
private createTerminalRef(): TransitionResult<TContext> {
|
|
153
134
|
const terminalRef: StateRef = {
|
|
154
135
|
id: "END",
|
|
155
136
|
routeId: this.routeId,
|
package/src/types/route.ts
CHANGED
|
@@ -58,14 +58,12 @@ export interface TransitionSpec<TContext = unknown> {
|
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Result of a transition operation
|
|
61
|
+
* Combines state reference with the ability to chain transitions
|
|
61
62
|
*/
|
|
62
|
-
export interface TransitionResult<TContext = unknown> {
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
condition?: string
|
|
69
|
-
) => TransitionResult<TContext>;
|
|
70
|
-
};
|
|
63
|
+
export interface TransitionResult<TContext = unknown> extends StateRef {
|
|
64
|
+
/** Allow chaining transitions */
|
|
65
|
+
transitionTo: (
|
|
66
|
+
spec: TransitionSpec<TContext>,
|
|
67
|
+
condition?: string
|
|
68
|
+
) => TransitionResult<TContext>;
|
|
71
69
|
}
|