@nago730/chatbot-library 1.1.1 → 1.1.4
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/LICENSE +21 -21
- package/README.md +392 -392
- package/package.json +50 -36
- package/src/engine.ts +24 -24
- package/src/examples/firebaseAdapter.example.ts +421 -421
- package/src/index.ts +2 -2
- package/src/types.ts +39 -39
- package/src/useChat.ts +338 -338
package/package.json
CHANGED
|
@@ -1,36 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@nago730/chatbot-library",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "React용 Headless 챗봇 엔진: JSON 시나리오, 멀티 세션, Firebase 등 유연한 상태 관리 지원",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"module": "./dist/index.mjs",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"react
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@nago730/chatbot-library",
|
|
3
|
+
"version": "1.1.4",
|
|
4
|
+
"description": "React용 Headless 챗봇 엔진: JSON 시나리오, 멀티 세션, Firebase 등 유연한 상태 관리 지원",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/Nago730/chatbot-library.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/Nago730/chatbot-library/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/Nago730/chatbot-library#readme",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --minify",
|
|
25
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch --clean",
|
|
26
|
+
"lint": "tsc",
|
|
27
|
+
"prepublishOnly": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"chatbot",
|
|
31
|
+
"headless",
|
|
32
|
+
"react",
|
|
33
|
+
"react-chatbot",
|
|
34
|
+
"engine"
|
|
35
|
+
],
|
|
36
|
+
"author": "Nago730",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"react": ">=16.8.0",
|
|
40
|
+
"react-dom": ">=16.8.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/react": "^19.0.0",
|
|
44
|
+
"@types/react-dom": "^19.0.0",
|
|
45
|
+
"react": "^19.0.0",
|
|
46
|
+
"react-dom": "^19.0.0",
|
|
47
|
+
"tsup": "^8.5.1",
|
|
48
|
+
"typescript": "^5.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/engine.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { ChatNode } from './types';
|
|
2
|
-
|
|
3
|
-
export class ChatEngine {
|
|
4
|
-
constructor(private flow: Record<string, ChatNode>) {}
|
|
5
|
-
|
|
6
|
-
getCurrentNode(stepId: string): ChatNode {
|
|
7
|
-
const node = this.flow[stepId];
|
|
8
|
-
if (!node) {
|
|
9
|
-
throw new Error(`ChatEngineError: Node with id "${stepId}" not found in flow.`);
|
|
10
|
-
}
|
|
11
|
-
return node;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
getNextStep(currentStepId: string, answer: any): string {
|
|
15
|
-
const node = this.flow[currentStepId];
|
|
16
|
-
if (!node) {
|
|
17
|
-
throw new Error(`ChatEngineError: Cannot calculate next step from missing node "${currentStepId}".`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (typeof node.next === 'function') {
|
|
21
|
-
return node.next(answer);
|
|
22
|
-
}
|
|
23
|
-
return node.next;
|
|
24
|
-
}
|
|
1
|
+
import { ChatNode } from './types';
|
|
2
|
+
|
|
3
|
+
export class ChatEngine {
|
|
4
|
+
constructor(private flow: Record<string, ChatNode>) {}
|
|
5
|
+
|
|
6
|
+
getCurrentNode(stepId: string): ChatNode {
|
|
7
|
+
const node = this.flow[stepId];
|
|
8
|
+
if (!node) {
|
|
9
|
+
throw new Error(`ChatEngineError: Node with id "${stepId}" not found in flow.`);
|
|
10
|
+
}
|
|
11
|
+
return node;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getNextStep(currentStepId: string, answer: any): string {
|
|
15
|
+
const node = this.flow[currentStepId];
|
|
16
|
+
if (!node) {
|
|
17
|
+
throw new Error(`ChatEngineError: Cannot calculate next step from missing node "${currentStepId}".`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof node.next === 'function') {
|
|
21
|
+
return node.next(answer);
|
|
22
|
+
}
|
|
23
|
+
return node.next;
|
|
24
|
+
}
|
|
25
25
|
}
|