@chatbotkit/cli 1.5.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 +31 -0
- package/bin/cbk.js +4 -0
- package/dist/cjs/command/api/conversation/index.cjs +54 -0
- package/dist/cjs/command/api/conversation/index.d.ts +6 -0
- package/dist/cjs/command/api/conversation/message/index.cjs +54 -0
- package/dist/cjs/command/api/conversation/message/index.d.ts +6 -0
- package/dist/cjs/command/api/dataset/index.cjs +51 -0
- package/dist/cjs/command/api/dataset/index.d.ts +6 -0
- package/dist/cjs/command/api/index.cjs +27 -0
- package/dist/cjs/command/api/index.d.ts +3 -0
- package/dist/cjs/command/api/partner/index.cjs +11 -0
- package/dist/cjs/command/api/partner/index.d.ts +3 -0
- package/dist/cjs/command/api/partner/user/index.cjs +51 -0
- package/dist/cjs/command/api/partner/user/index.d.ts +6 -0
- package/dist/cjs/command/api/skillset/index.cjs +51 -0
- package/dist/cjs/command/api/skillset/index.d.ts +6 -0
- package/dist/cjs/command/chat/index.cjs +40 -0
- package/dist/cjs/command/chat/index.d.ts +3 -0
- package/dist/cjs/env.cjs +14 -0
- package/dist/cjs/env.d.ts +2 -0
- package/dist/cjs/index.cjs +14 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/output.cjs +34 -0
- package/dist/cjs/output.d.ts +5 -0
- package/dist/esm/command/api/conversation/index.d.ts +6 -0
- package/dist/esm/command/api/conversation/index.js +50 -0
- package/dist/esm/command/api/conversation/message/index.d.ts +6 -0
- package/dist/esm/command/api/conversation/message/index.js +51 -0
- package/dist/esm/command/api/dataset/index.d.ts +6 -0
- package/dist/esm/command/api/dataset/index.js +48 -0
- package/dist/esm/command/api/index.d.ts +3 -0
- package/dist/esm/command/api/index.js +23 -0
- package/dist/esm/command/api/partner/index.d.ts +3 -0
- package/dist/esm/command/api/partner/index.js +7 -0
- package/dist/esm/command/api/partner/user/index.d.ts +6 -0
- package/dist/esm/command/api/partner/user/index.js +48 -0
- package/dist/esm/command/api/skillset/index.d.ts +6 -0
- package/dist/esm/command/api/skillset/index.js +48 -0
- package/dist/esm/command/chat/index.d.ts +3 -0
- package/dist/esm/command/chat/index.js +36 -0
- package/dist/esm/env.d.ts +2 -0
- package/dist/esm/env.js +9 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/output.d.ts +5 -0
- package/dist/esm/output.js +28 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +373 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[](https://twitter.com/chatbotkit)
|
|
2
|
+
[](https://chatbotkit.com)
|
|
3
|
+
[](https://www.npmjs.com/package/@chatbotkit/cli)
|
|
4
|
+
|
|
5
|
+
# ChatBotKit CLI
|
|
6
|
+
|
|
7
|
+
The ChatBotKit CLI is a command-line interface for the ChatBotKit SDK. It provides a set of commands to help you manage your ChatBotKit projects.
|
|
8
|
+
|
|
9
|
+
## Getting Started
|
|
10
|
+
|
|
11
|
+
To begin using the ChatBotKit CLI, follow these steps:
|
|
12
|
+
|
|
13
|
+
1. **Installation**: Add the SDK to your project using npm:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install --global @chatbotkit/cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
2. **Usage**: Get help on the available commands:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
cbk --help
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Documentation
|
|
26
|
+
|
|
27
|
+
For comprehensive information about the ChatBotKit CLI SDK, including detailed documentation on its functionalities, helper methods, and configuration options, please visit our [type documentation page](https://chatbotkit.github.io/node-sdk/modules/_chatbotkit_cli.html).
|
|
28
|
+
|
|
29
|
+
## Contributing
|
|
30
|
+
|
|
31
|
+
If you find a bug or would like to contribute to the ChatBotKit SDK, please open an issue or submit a pull request on the [official GitHub repository](https://github.com/chatbotkit/node-sdk).
|
package/bin/cbk.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = exports.conversationDelete = exports.conversationFetch = exports.conversationList = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const commander_1 = require("commander");
|
|
6
|
+
const index_js_1 = require("@chatbotkit/sdk/conversation/index.js");
|
|
7
|
+
const index_js_2 = tslib_1.__importDefault(require("./message/index.cjs"));
|
|
8
|
+
const output_js_1 = require("../../../output.cjs");
|
|
9
|
+
const env_js_1 = require("../../../env.cjs");
|
|
10
|
+
const client = new index_js_1.ConversationClient({
|
|
11
|
+
secret: (0, env_js_1.getSECRET)(),
|
|
12
|
+
runAsUserId: (0, env_js_1.getRUNAS_USERID)(),
|
|
13
|
+
});
|
|
14
|
+
exports.conversationList = new commander_1.Command()
|
|
15
|
+
.name('list')
|
|
16
|
+
.description('List conversations')
|
|
17
|
+
.option('-s, --stream', 'Stream conversations')
|
|
18
|
+
.action(async (str, options) => {
|
|
19
|
+
const { stream } = options;
|
|
20
|
+
if (stream) {
|
|
21
|
+
for await (const conversation of client.list().stream()) {
|
|
22
|
+
(0, output_js_1.print)(conversation);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const { items } = await client.list();
|
|
27
|
+
for (const conversation of items) {
|
|
28
|
+
(0, output_js_1.print)(conversation);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
exports.conversationFetch = new commander_1.Command()
|
|
33
|
+
.name('fetch')
|
|
34
|
+
.description('Fetch conversation')
|
|
35
|
+
.argument('<conversationId>', 'Conversation ID')
|
|
36
|
+
.action(async (conversationId) => {
|
|
37
|
+
const conversation = await client.fetch(conversationId);
|
|
38
|
+
(0, output_js_1.print)(conversation);
|
|
39
|
+
});
|
|
40
|
+
exports.conversationDelete = new commander_1.Command()
|
|
41
|
+
.name('delete')
|
|
42
|
+
.description('Delete conversation')
|
|
43
|
+
.argument('<conversationId>', 'Conversation ID')
|
|
44
|
+
.action(async (conversationId) => {
|
|
45
|
+
await client.delete(conversationId);
|
|
46
|
+
});
|
|
47
|
+
exports.command = new commander_1.Command()
|
|
48
|
+
.name('conversation')
|
|
49
|
+
.description('Conversation tools for ChatBotKit')
|
|
50
|
+
.addCommand(exports.conversationList)
|
|
51
|
+
.addCommand(exports.conversationFetch)
|
|
52
|
+
.addCommand(exports.conversationDelete)
|
|
53
|
+
.addCommand(index_js_2.default);
|
|
54
|
+
exports.default = exports.command;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = exports.messageDelete = exports.messageFetch = exports.messageList = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const index_js_1 = require("@chatbotkit/sdk/conversation/message/index.js");
|
|
6
|
+
const output_js_1 = require("../../../../output.cjs");
|
|
7
|
+
const env_js_1 = require("../../../../env.cjs");
|
|
8
|
+
const client = new index_js_1.ConversationMessageClient({
|
|
9
|
+
secret: (0, env_js_1.getSECRET)(),
|
|
10
|
+
runAsUserId: (0, env_js_1.getRUNAS_USERID)(),
|
|
11
|
+
});
|
|
12
|
+
exports.messageList = new commander_1.Command()
|
|
13
|
+
.name('list')
|
|
14
|
+
.description('List messages')
|
|
15
|
+
.option('-s, --stream', 'Stream messages')
|
|
16
|
+
.argument('<conversationId>', 'Conversation ID')
|
|
17
|
+
.action(async (conversationId, options) => {
|
|
18
|
+
const { stream } = options;
|
|
19
|
+
if (stream) {
|
|
20
|
+
for await (const message of client.list(conversationId).stream()) {
|
|
21
|
+
(0, output_js_1.print)(message);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const { items } = await client.list(conversationId);
|
|
26
|
+
for (const message of items) {
|
|
27
|
+
(0, output_js_1.print)(message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
exports.messageFetch = new commander_1.Command()
|
|
32
|
+
.name('fetch')
|
|
33
|
+
.description('Fetch message')
|
|
34
|
+
.argument('<conversationId>', 'Conversation ID')
|
|
35
|
+
.argument('<messageId>', 'Message ID')
|
|
36
|
+
.action(async (conversationId, messageId) => {
|
|
37
|
+
const message = await client.fetch(conversationId, messageId);
|
|
38
|
+
(0, output_js_1.print)(message);
|
|
39
|
+
});
|
|
40
|
+
exports.messageDelete = new commander_1.Command()
|
|
41
|
+
.name('delete')
|
|
42
|
+
.description('Delete message')
|
|
43
|
+
.argument('<conversationId>', 'Conversation ID')
|
|
44
|
+
.argument('<messageId>', 'Message ID')
|
|
45
|
+
.action(async (conversationId, messageId) => {
|
|
46
|
+
await client.delete(conversationId, messageId);
|
|
47
|
+
});
|
|
48
|
+
exports.command = new commander_1.Command()
|
|
49
|
+
.name('message')
|
|
50
|
+
.description('Message tools for ChatBotKit')
|
|
51
|
+
.addCommand(exports.messageList)
|
|
52
|
+
.addCommand(exports.messageFetch)
|
|
53
|
+
.addCommand(exports.messageDelete);
|
|
54
|
+
exports.default = exports.command;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = exports.datasetDelete = exports.datasetFetch = exports.datasetList = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const index_js_1 = require("@chatbotkit/sdk/dataset/index.js");
|
|
6
|
+
const output_js_1 = require("../../../output.cjs");
|
|
7
|
+
const env_js_1 = require("../../../env.cjs");
|
|
8
|
+
const client = new index_js_1.DatasetClient({
|
|
9
|
+
secret: (0, env_js_1.getSECRET)(),
|
|
10
|
+
runAsUserId: (0, env_js_1.getRUNAS_USERID)(),
|
|
11
|
+
});
|
|
12
|
+
exports.datasetList = new commander_1.Command()
|
|
13
|
+
.name('list')
|
|
14
|
+
.description('List datasets')
|
|
15
|
+
.option('-s, --stream', 'Stream datasets')
|
|
16
|
+
.action(async (str, options) => {
|
|
17
|
+
const { stream } = options;
|
|
18
|
+
if (stream) {
|
|
19
|
+
for await (const dataset of client.list().stream()) {
|
|
20
|
+
(0, output_js_1.print)(dataset);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const { items } = await client.list();
|
|
25
|
+
for (const dataset of items) {
|
|
26
|
+
(0, output_js_1.print)(dataset);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
exports.datasetFetch = new commander_1.Command()
|
|
31
|
+
.name('fetch')
|
|
32
|
+
.description('Fetch dataset')
|
|
33
|
+
.argument('<datasetId>', 'Dataset ID')
|
|
34
|
+
.action(async (datasetId) => {
|
|
35
|
+
const dataset = await client.fetch(datasetId);
|
|
36
|
+
(0, output_js_1.print)(dataset);
|
|
37
|
+
});
|
|
38
|
+
exports.datasetDelete = new commander_1.Command()
|
|
39
|
+
.name('delete')
|
|
40
|
+
.description('Delete dataset')
|
|
41
|
+
.argument('<datasetId>', 'Dataset ID')
|
|
42
|
+
.action(async (datasetId) => {
|
|
43
|
+
await client.delete(datasetId);
|
|
44
|
+
});
|
|
45
|
+
exports.command = new commander_1.Command()
|
|
46
|
+
.name('dataset')
|
|
47
|
+
.description('Dataset tools for ChatBotKit')
|
|
48
|
+
.addCommand(exports.datasetList)
|
|
49
|
+
.addCommand(exports.datasetFetch)
|
|
50
|
+
.addCommand(exports.datasetDelete);
|
|
51
|
+
exports.default = exports.command;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const commander_1 = require("commander");
|
|
6
|
+
const index_js_1 = tslib_1.__importDefault(require("./partner/index.cjs"));
|
|
7
|
+
const index_js_2 = tslib_1.__importDefault(require("./dataset/index.cjs"));
|
|
8
|
+
const index_js_3 = tslib_1.__importDefault(require("./skillset/index.cjs"));
|
|
9
|
+
const index_js_4 = tslib_1.__importDefault(require("./conversation/index.cjs"));
|
|
10
|
+
const output_js_1 = require("../../output.cjs");
|
|
11
|
+
exports.command = new commander_1.Command()
|
|
12
|
+
.name('api')
|
|
13
|
+
.description('API tools for ChatBotKit')
|
|
14
|
+
.addCommand(index_js_2.default)
|
|
15
|
+
.addCommand(index_js_3.default)
|
|
16
|
+
.addCommand(index_js_4.default)
|
|
17
|
+
.addCommand(index_js_1.default);
|
|
18
|
+
exports.command
|
|
19
|
+
.addOption(new commander_1.Option('-o, --output <format>', 'Output format').choices([
|
|
20
|
+
'yaml',
|
|
21
|
+
'json',
|
|
22
|
+
'jsonl',
|
|
23
|
+
]))
|
|
24
|
+
.on('option:output', (value) => {
|
|
25
|
+
output_js_1.config.output = value;
|
|
26
|
+
});
|
|
27
|
+
exports.default = exports.command;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const commander_1 = require("commander");
|
|
6
|
+
const index_js_1 = tslib_1.__importDefault(require("./user/index.cjs"));
|
|
7
|
+
exports.command = new commander_1.Command()
|
|
8
|
+
.name('partner')
|
|
9
|
+
.description('Partner tools for ChatBotKit')
|
|
10
|
+
.addCommand(index_js_1.default);
|
|
11
|
+
exports.default = exports.command;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = exports.userDelete = exports.userFetch = exports.userList = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const index_js_1 = require("@chatbotkit/sdk/partner/user/index.js");
|
|
6
|
+
const output_js_1 = require("../../../../output.cjs");
|
|
7
|
+
const env_js_1 = require("../../../../env.cjs");
|
|
8
|
+
const client = new index_js_1.PartnerUserClient({
|
|
9
|
+
secret: (0, env_js_1.getSECRET)(),
|
|
10
|
+
runAsUserId: (0, env_js_1.getRUNAS_USERID)(),
|
|
11
|
+
});
|
|
12
|
+
exports.userList = new commander_1.Command()
|
|
13
|
+
.name('list')
|
|
14
|
+
.description('List users')
|
|
15
|
+
.option('-s, --stream', 'Stream users')
|
|
16
|
+
.action(async (_arg, options) => {
|
|
17
|
+
const { stream } = options;
|
|
18
|
+
if (stream) {
|
|
19
|
+
for await (const user of client.list().stream()) {
|
|
20
|
+
(0, output_js_1.print)(user);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const { items } = await client.list();
|
|
25
|
+
for (const user of items) {
|
|
26
|
+
(0, output_js_1.print)(user);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
exports.userFetch = new commander_1.Command()
|
|
31
|
+
.name('fetch')
|
|
32
|
+
.description('Fetch user')
|
|
33
|
+
.argument('User ID')
|
|
34
|
+
.action(async (userId) => {
|
|
35
|
+
const user = await client.fetch(userId);
|
|
36
|
+
(0, output_js_1.print)(user);
|
|
37
|
+
});
|
|
38
|
+
exports.userDelete = new commander_1.Command()
|
|
39
|
+
.name('delete')
|
|
40
|
+
.description('Delete user')
|
|
41
|
+
.argument('<userId>', 'User ID')
|
|
42
|
+
.action(async (userId) => {
|
|
43
|
+
await client.delete(userId);
|
|
44
|
+
});
|
|
45
|
+
exports.command = new commander_1.Command()
|
|
46
|
+
.name('user')
|
|
47
|
+
.description('User tools for ChatBotKit')
|
|
48
|
+
.addCommand(exports.userList)
|
|
49
|
+
.addCommand(exports.userFetch)
|
|
50
|
+
.addCommand(exports.userDelete);
|
|
51
|
+
exports.default = exports.command;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = exports.skillsetDelete = exports.skillsetFetch = exports.skillsetList = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const index_js_1 = require("@chatbotkit/sdk/skillset/index.js");
|
|
6
|
+
const output_js_1 = require("../../../output.cjs");
|
|
7
|
+
const env_js_1 = require("../../../env.cjs");
|
|
8
|
+
const client = new index_js_1.SkillsetClient({
|
|
9
|
+
secret: (0, env_js_1.getSECRET)(),
|
|
10
|
+
runAsUserId: (0, env_js_1.getRUNAS_USERID)(),
|
|
11
|
+
});
|
|
12
|
+
exports.skillsetList = new commander_1.Command()
|
|
13
|
+
.name('list')
|
|
14
|
+
.description('List skillsets')
|
|
15
|
+
.option('-s, --stream', 'Stream skillsets')
|
|
16
|
+
.action(async (str, options) => {
|
|
17
|
+
const { stream } = options;
|
|
18
|
+
if (stream) {
|
|
19
|
+
for await (const skillset of client.list().stream()) {
|
|
20
|
+
(0, output_js_1.print)(skillset);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const { items } = await client.list();
|
|
25
|
+
for (const skillset of items) {
|
|
26
|
+
(0, output_js_1.print)(skillset);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
exports.skillsetFetch = new commander_1.Command()
|
|
31
|
+
.name('fetch')
|
|
32
|
+
.description('Fetch skillset')
|
|
33
|
+
.argument('<skillsetId>', 'Skillset ID')
|
|
34
|
+
.action(async (skillsetId) => {
|
|
35
|
+
const skillset = await client.fetch(skillsetId);
|
|
36
|
+
(0, output_js_1.print)(skillset);
|
|
37
|
+
});
|
|
38
|
+
exports.skillsetDelete = new commander_1.Command()
|
|
39
|
+
.name('delete')
|
|
40
|
+
.description('Delete skillset')
|
|
41
|
+
.argument('<skillsetId>', 'Skillset ID')
|
|
42
|
+
.action(async (skillsetId) => {
|
|
43
|
+
await client.delete(skillsetId);
|
|
44
|
+
});
|
|
45
|
+
exports.command = new commander_1.Command()
|
|
46
|
+
.name('skillset')
|
|
47
|
+
.description('Skillset tools for ChatBotKit')
|
|
48
|
+
.addCommand(exports.skillsetList)
|
|
49
|
+
.addCommand(exports.skillsetFetch)
|
|
50
|
+
.addCommand(exports.skillsetDelete);
|
|
51
|
+
exports.default = exports.command;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const promises_1 = tslib_1.__importDefault(require("readline/promises"));
|
|
6
|
+
const commander_1 = require("commander");
|
|
7
|
+
const index_js_1 = require("@chatbotkit/sdk/conversation/index.js");
|
|
8
|
+
const env_js_1 = require("../../env.cjs");
|
|
9
|
+
const client = new index_js_1.ConversationClient({
|
|
10
|
+
secret: (0, env_js_1.getSECRET)(),
|
|
11
|
+
runAsUserId: (0, env_js_1.getRUNAS_USERID)(),
|
|
12
|
+
});
|
|
13
|
+
exports.command = new commander_1.Command()
|
|
14
|
+
.name('chat')
|
|
15
|
+
.description('Start a chat session')
|
|
16
|
+
.addOption(new commander_1.Option('-m, --model <model>', 'Model name').default('gpt-4'))
|
|
17
|
+
.action(async (_arg, options) => {
|
|
18
|
+
const rl = promises_1.default.createInterface({
|
|
19
|
+
input: process.stdin,
|
|
20
|
+
output: process.stdout,
|
|
21
|
+
});
|
|
22
|
+
const messages = [];
|
|
23
|
+
for (;;) {
|
|
24
|
+
const user = await rl.question('user: ');
|
|
25
|
+
messages.push({ type: 'user', text: user });
|
|
26
|
+
process.stdout.write('bot: ');
|
|
27
|
+
for await (const { type, data } of client
|
|
28
|
+
.complete(null, { model: options.model, messages })
|
|
29
|
+
.stream()) {
|
|
30
|
+
if (type === 'token') {
|
|
31
|
+
process.stdout.write(data.token);
|
|
32
|
+
}
|
|
33
|
+
else if (type === 'result') {
|
|
34
|
+
messages.push({ type: 'bot', text: data.text });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
process.stdout.write('\n');
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
exports.default = exports.command;
|
package/dist/cjs/env.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRUNAS_USERID = exports.getSECRET = void 0;
|
|
4
|
+
function getSECRET() {
|
|
5
|
+
if (!process.env.CHATBOTKIT_API_SECRET) {
|
|
6
|
+
throw new Error('CHATBOTKIT_API_SECRET is not set');
|
|
7
|
+
}
|
|
8
|
+
return process.env.CHATBOTKIT_API_SECRET;
|
|
9
|
+
}
|
|
10
|
+
exports.getSECRET = getSECRET;
|
|
11
|
+
function getRUNAS_USERID() {
|
|
12
|
+
return process.env.CHATBOTKIT_API_RUNAS_USERID;
|
|
13
|
+
}
|
|
14
|
+
exports.getRUNAS_USERID = getRUNAS_USERID;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const index_js_1 = tslib_1.__importDefault(require("./command/api/index.cjs"));
|
|
6
|
+
const index_js_2 = tslib_1.__importDefault(require("./command/chat/index.cjs"));
|
|
7
|
+
async function cbk() {
|
|
8
|
+
const program = new commander_1.Command();
|
|
9
|
+
program.name('cbk').description('Command line tools for ChatBotKit');
|
|
10
|
+
program.addCommand(index_js_1.default);
|
|
11
|
+
program.addCommand(index_js_2.default);
|
|
12
|
+
program.parse();
|
|
13
|
+
}
|
|
14
|
+
exports.default = cbk;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function cbk(): Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printError = exports.print = exports.config = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const util_1 = tslib_1.__importDefault(require("util"));
|
|
6
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
7
|
+
exports.config = {
|
|
8
|
+
output: 'yaml',
|
|
9
|
+
};
|
|
10
|
+
function print(input) {
|
|
11
|
+
switch (true) {
|
|
12
|
+
case exports.config.output === 'yaml': {
|
|
13
|
+
console.log(js_yaml_1.default.dump(input, { noRefs: true }));
|
|
14
|
+
console.log('# ---');
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
case exports.config.output === 'json': {
|
|
18
|
+
console.log(util_1.default.inspect(input, { depth: Infinity, colors: true }));
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case exports.config.output === 'jsonl': {
|
|
22
|
+
console.log(JSON.stringify(input));
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
default: {
|
|
26
|
+
throw new Error(`Unknown output format: ${exports.config.output}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.print = print;
|
|
31
|
+
function printError(error) {
|
|
32
|
+
console.error(error);
|
|
33
|
+
}
|
|
34
|
+
exports.printError = printError;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { ConversationClient } from '@chatbotkit/sdk/conversation/index.js';
|
|
3
|
+
import message from './message/index.js';
|
|
4
|
+
import { print } from '../../../output.js';
|
|
5
|
+
import { getSECRET, getRUNAS_USERID } from '../../../env.js';
|
|
6
|
+
const client = new ConversationClient({
|
|
7
|
+
secret: getSECRET(),
|
|
8
|
+
runAsUserId: getRUNAS_USERID(),
|
|
9
|
+
});
|
|
10
|
+
export const conversationList = new Command()
|
|
11
|
+
.name('list')
|
|
12
|
+
.description('List conversations')
|
|
13
|
+
.option('-s, --stream', 'Stream conversations')
|
|
14
|
+
.action(async (str, options) => {
|
|
15
|
+
const { stream } = options;
|
|
16
|
+
if (stream) {
|
|
17
|
+
for await (const conversation of client.list().stream()) {
|
|
18
|
+
print(conversation);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const { items } = await client.list();
|
|
23
|
+
for (const conversation of items) {
|
|
24
|
+
print(conversation);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
export const conversationFetch = new Command()
|
|
29
|
+
.name('fetch')
|
|
30
|
+
.description('Fetch conversation')
|
|
31
|
+
.argument('<conversationId>', 'Conversation ID')
|
|
32
|
+
.action(async (conversationId) => {
|
|
33
|
+
const conversation = await client.fetch(conversationId);
|
|
34
|
+
print(conversation);
|
|
35
|
+
});
|
|
36
|
+
export const conversationDelete = new Command()
|
|
37
|
+
.name('delete')
|
|
38
|
+
.description('Delete conversation')
|
|
39
|
+
.argument('<conversationId>', 'Conversation ID')
|
|
40
|
+
.action(async (conversationId) => {
|
|
41
|
+
await client.delete(conversationId);
|
|
42
|
+
});
|
|
43
|
+
export const command = new Command()
|
|
44
|
+
.name('conversation')
|
|
45
|
+
.description('Conversation tools for ChatBotKit')
|
|
46
|
+
.addCommand(conversationList)
|
|
47
|
+
.addCommand(conversationFetch)
|
|
48
|
+
.addCommand(conversationDelete)
|
|
49
|
+
.addCommand(message);
|
|
50
|
+
export default command;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { ConversationMessageClient } from '@chatbotkit/sdk/conversation/message/index.js';
|
|
3
|
+
import { print } from '../../../../output.js';
|
|
4
|
+
import { getSECRET, getRUNAS_USERID } from '../../../../env.js';
|
|
5
|
+
const client = new ConversationMessageClient({
|
|
6
|
+
secret: getSECRET(),
|
|
7
|
+
runAsUserId: getRUNAS_USERID(),
|
|
8
|
+
});
|
|
9
|
+
export const messageList = new Command()
|
|
10
|
+
.name('list')
|
|
11
|
+
.description('List messages')
|
|
12
|
+
.option('-s, --stream', 'Stream messages')
|
|
13
|
+
.argument('<conversationId>', 'Conversation ID')
|
|
14
|
+
.action(async (conversationId, options) => {
|
|
15
|
+
const { stream } = options;
|
|
16
|
+
if (stream) {
|
|
17
|
+
for await (const message of client.list(conversationId).stream()) {
|
|
18
|
+
print(message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const { items } = await client.list(conversationId);
|
|
23
|
+
for (const message of items) {
|
|
24
|
+
print(message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
export const messageFetch = new Command()
|
|
29
|
+
.name('fetch')
|
|
30
|
+
.description('Fetch message')
|
|
31
|
+
.argument('<conversationId>', 'Conversation ID')
|
|
32
|
+
.argument('<messageId>', 'Message ID')
|
|
33
|
+
.action(async (conversationId, messageId) => {
|
|
34
|
+
const message = await client.fetch(conversationId, messageId);
|
|
35
|
+
print(message);
|
|
36
|
+
});
|
|
37
|
+
export const messageDelete = new Command()
|
|
38
|
+
.name('delete')
|
|
39
|
+
.description('Delete message')
|
|
40
|
+
.argument('<conversationId>', 'Conversation ID')
|
|
41
|
+
.argument('<messageId>', 'Message ID')
|
|
42
|
+
.action(async (conversationId, messageId) => {
|
|
43
|
+
await client.delete(conversationId, messageId);
|
|
44
|
+
});
|
|
45
|
+
export const command = new Command()
|
|
46
|
+
.name('message')
|
|
47
|
+
.description('Message tools for ChatBotKit')
|
|
48
|
+
.addCommand(messageList)
|
|
49
|
+
.addCommand(messageFetch)
|
|
50
|
+
.addCommand(messageDelete);
|
|
51
|
+
export default command;
|