@yaebal/conversation 0.0.1 → 0.0.2
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/lib/index.d.ts +20 -17
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +20 -0
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +21 -19
package/lib/index.d.ts
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
import type { Context, Plugin } from "@yaebal/core";
|
|
2
|
-
/**
|
|
3
|
-
* @yaebal/conversation — write multi-step dialogs as a straight line:
|
|
4
|
-
*
|
|
5
|
-
* const greet = createConversation("greet", async (cv, ctx) => {
|
|
6
|
-
* await ctx.send("what's your name?");
|
|
7
|
-
*
|
|
8
|
-
* const answer = await cv.wait();
|
|
9
|
-
* await answer.send(`hi ${answer.text}`);
|
|
10
|
-
* });
|
|
11
|
-
* bot.install(conversation([greet]));
|
|
12
|
-
* bot.command("greet", (ctx) => ctx.conversation.enter("greet"));
|
|
13
|
-
*
|
|
14
|
-
* it's a COROUTINE, not a replay engine (grammY-style): the builder runs once,
|
|
15
|
-
* detached, and `cv.wait()` resolves with the next update for that chat. while a
|
|
16
|
-
* conversation is active it OWNS the chat's updates (they don't reach other
|
|
17
|
-
* handlers). state is in-memory, lost on restart — like `prompt`/`scenes`.
|
|
18
|
-
*/
|
|
19
2
|
export interface Conversation {
|
|
20
3
|
/** resolve with the next update's context for this chat. */
|
|
21
4
|
wait(): Promise<Context>;
|
|
@@ -42,6 +25,26 @@ export interface ConversationOptions {
|
|
|
42
25
|
/** called if a conversation builder throws. */
|
|
43
26
|
onError?: (error: unknown, ctx: Context) => void;
|
|
44
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* yaebal/conversation — write multi-step dialogs as a straight line:
|
|
30
|
+
*
|
|
31
|
+
* ```
|
|
32
|
+
* const greet = createConversation("greet", async (cv, ctx) => {
|
|
33
|
+
* await ctx.send("what's your name?");
|
|
34
|
+
*
|
|
35
|
+
* const answer = await cv.wait();
|
|
36
|
+
* await answer.send(`hi ${answer.text}`);
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* bot.install(conversation([greet]));
|
|
40
|
+
* bot.command("greet", (ctx) => ctx.conversation.enter("greet"));
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* it's a COROUTINE, not a replay engine: the builder runs once, detached,
|
|
44
|
+
* and `cv.wait()` resolves with the next update for that chat. while a
|
|
45
|
+
* conversation is active it OWNS the chat's updates (they don't reach other
|
|
46
|
+
* handlers). state is in-memory, lost on restart — like `prompt`/`scenes`.
|
|
47
|
+
*/
|
|
45
48
|
export declare function conversation(defs: ConversationDef[], options?: ConversationOptions): Plugin<Context, {
|
|
46
49
|
conversation: ConversationControl;
|
|
47
50
|
}>;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEpD
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,WAAW,YAAY;IAC5B,4DAA4D;IAC5D,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3F,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,mBAAmB,CAAC;CAC7B;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,eAAe,CAE9F;AAED,MAAM,WAAW,mBAAmB;IACnC,qDAAqD;IACrD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,iEAAiE;IACjE,MAAM,IAAI,OAAO,CAAC;IAClB,sEAAsE;IACtE,KAAK,IAAI,IAAI,CAAC;CACd;AAED,MAAM,WAAW,mBAAmB;IACnC,yEAAyE;IACzE,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC;IAC9C,+CAA+C;IAC/C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;CACjD;AAQD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAC3B,IAAI,EAAE,eAAe,EAAE,EACvB,OAAO,GAAE,mBAAwB,GAC/B,MAAM,CAAC,OAAO,EAAE;IAAE,YAAY,EAAE,mBAAmB,CAAA;CAAE,CAAC,CA+ExD"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
export function createConversation(name, builder) {
|
|
2
2
|
return { name, builder };
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* yaebal/conversation — write multi-step dialogs as a straight line:
|
|
6
|
+
*
|
|
7
|
+
* ```
|
|
8
|
+
* const greet = createConversation("greet", async (cv, ctx) => {
|
|
9
|
+
* await ctx.send("what's your name?");
|
|
10
|
+
*
|
|
11
|
+
* const answer = await cv.wait();
|
|
12
|
+
* await answer.send(`hi ${answer.text}`);
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* bot.install(conversation([greet]));
|
|
16
|
+
* bot.command("greet", (ctx) => ctx.conversation.enter("greet"));
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* it's a COROUTINE, not a replay engine: the builder runs once, detached,
|
|
20
|
+
* and `cv.wait()` resolves with the next update for that chat. while a
|
|
21
|
+
* conversation is active it OWNS the chat's updates (they don't reach other
|
|
22
|
+
* handlers). state is in-memory, lost on restart — like `prompt`/`scenes`.
|
|
23
|
+
*/
|
|
4
24
|
export function conversation(defs, options = {}) {
|
|
5
25
|
const registry = new Map(defs.map((d) => [d.name, d]));
|
|
6
26
|
const sessions = new Map();
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,OAA4B;IAC5E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC1B,CAAC;AAwBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,YAAY,CAC3B,IAAuB,EACvB,UAA+B,EAAE;IAEjC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAgB,CAAC;IACzC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,GAAY,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IAE9E,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,GAAoB,EAAE,QAAiB,EAAE,EAAE;QACtE,MAAM,IAAI,GAAS,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;QACpD,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAExB,MAAM,EAAE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0.0.2",
|
|
4
4
|
"description": "yaebal conversation — await-style multi-step dialogs (coroutine, no replay).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@yaebal/core": "0.0.
|
|
19
|
+
"@yaebal/core": "0.0.5"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "latest"
|
package/src/index.ts
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
import type { Context, Plugin } from "@yaebal/core";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* @yaebal/conversation — write multi-step dialogs as a straight line:
|
|
5
|
-
*
|
|
6
|
-
* const greet = createConversation("greet", async (cv, ctx) => {
|
|
7
|
-
* await ctx.send("what's your name?");
|
|
8
|
-
*
|
|
9
|
-
* const answer = await cv.wait();
|
|
10
|
-
* await answer.send(`hi ${answer.text}`);
|
|
11
|
-
* });
|
|
12
|
-
* bot.install(conversation([greet]));
|
|
13
|
-
* bot.command("greet", (ctx) => ctx.conversation.enter("greet"));
|
|
14
|
-
*
|
|
15
|
-
* it's a COROUTINE, not a replay engine (grammY-style): the builder runs once,
|
|
16
|
-
* detached, and `cv.wait()` resolves with the next update for that chat. while a
|
|
17
|
-
* conversation is active it OWNS the chat's updates (they don't reach other
|
|
18
|
-
* handlers). state is in-memory, lost on restart — like `prompt`/`scenes`.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
3
|
export interface Conversation {
|
|
22
4
|
/** resolve with the next update's context for this chat. */
|
|
23
5
|
wait(): Promise<Context>;
|
|
@@ -58,6 +40,26 @@ interface Live {
|
|
|
58
40
|
current: Context;
|
|
59
41
|
}
|
|
60
42
|
|
|
43
|
+
/**
|
|
44
|
+
* yaebal/conversation — write multi-step dialogs as a straight line:
|
|
45
|
+
*
|
|
46
|
+
* ```
|
|
47
|
+
* const greet = createConversation("greet", async (cv, ctx) => {
|
|
48
|
+
* await ctx.send("what's your name?");
|
|
49
|
+
*
|
|
50
|
+
* const answer = await cv.wait();
|
|
51
|
+
* await answer.send(`hi ${answer.text}`);
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* bot.install(conversation([greet]));
|
|
55
|
+
* bot.command("greet", (ctx) => ctx.conversation.enter("greet"));
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* it's a COROUTINE, not a replay engine: the builder runs once, detached,
|
|
59
|
+
* and `cv.wait()` resolves with the next update for that chat. while a
|
|
60
|
+
* conversation is active it OWNS the chat's updates (they don't reach other
|
|
61
|
+
* handlers). state is in-memory, lost on restart — like `prompt`/`scenes`.
|
|
62
|
+
*/
|
|
61
63
|
export function conversation(
|
|
62
64
|
defs: ConversationDef[],
|
|
63
65
|
options: ConversationOptions = {},
|
|
@@ -138,6 +140,6 @@ export function conversation(
|
|
|
138
140
|
}
|
|
139
141
|
await next();
|
|
140
142
|
});
|
|
141
|
-
|
|
143
|
+
|
|
142
144
|
return plugin;
|
|
143
145
|
}
|