@chatbotkit/cli 1.7.0 → 1.9.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.
Files changed (45) hide show
  1. package/README.md +1 -0
  2. package/bin/cbk.js +7 -0
  3. package/dist/cjs/command/api/conversation/index.cjs +9 -4
  4. package/dist/cjs/command/api/conversation/message/index.cjs +9 -4
  5. package/dist/cjs/command/api/dataset/index.cjs +9 -4
  6. package/dist/cjs/command/api/partner/user/index.cjs +9 -4
  7. package/dist/cjs/command/api/skillset/index.cjs +9 -4
  8. package/dist/cjs/command/chat/index.cjs +7 -4
  9. package/dist/cjs/command/solution/index.cjs +52 -0
  10. package/dist/cjs/command/solution/index.d.ts +7 -0
  11. package/dist/cjs/command/solution/resource/index.cjs +44 -0
  12. package/dist/cjs/command/solution/resource/index.d.ts +5 -0
  13. package/dist/cjs/index.cjs +4 -2
  14. package/dist/cjs/index.d.ts +1 -1
  15. package/dist/cjs/input.cjs +18 -0
  16. package/dist/cjs/input.d.ts +1 -0
  17. package/dist/cjs/output.cjs +10 -2
  18. package/dist/cjs/output.d.ts +2 -0
  19. package/dist/cjs/proxy.cjs +22 -0
  20. package/dist/cjs/proxy.d.ts +7 -0
  21. package/dist/cjs/solution/index.cjs +288 -0
  22. package/dist/cjs/solution/index.d.ts +815 -0
  23. package/dist/esm/command/api/conversation/index.js +9 -4
  24. package/dist/esm/command/api/conversation/message/index.js +9 -4
  25. package/dist/esm/command/api/dataset/index.js +9 -4
  26. package/dist/esm/command/api/partner/user/index.js +9 -4
  27. package/dist/esm/command/api/skillset/index.js +9 -4
  28. package/dist/esm/command/chat/index.js +7 -4
  29. package/dist/esm/command/solution/index.d.ts +7 -0
  30. package/dist/esm/command/solution/index.js +48 -0
  31. package/dist/esm/command/solution/resource/index.d.ts +5 -0
  32. package/dist/esm/command/solution/resource/index.js +40 -0
  33. package/dist/esm/index.d.ts +1 -1
  34. package/dist/esm/index.js +4 -2
  35. package/dist/esm/input.d.ts +1 -0
  36. package/dist/esm/input.js +13 -0
  37. package/dist/esm/output.d.ts +2 -0
  38. package/dist/esm/output.js +8 -1
  39. package/dist/esm/proxy.d.ts +7 -0
  40. package/dist/esm/proxy.js +17 -0
  41. package/dist/esm/solution/index.d.ts +815 -0
  42. package/dist/esm/solution/index.js +271 -0
  43. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  44. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  45. package/package.json +135 -2
@@ -3,16 +3,19 @@ import { print } from '../../../output.js';
3
3
  import message from './message/index.js';
4
4
  import { ConversationClient } from '@chatbotkit/sdk/conversation/index.js';
5
5
  import { Command } from 'commander';
6
- const client = new ConversationClient({
7
- secret: getSECRET(),
8
- runAsUserId: getRUNAS_USERID(),
9
- });
6
+ function getClient() {
7
+ return new ConversationClient({
8
+ secret: getSECRET(),
9
+ runAsUserId: getRUNAS_USERID(),
10
+ });
11
+ }
10
12
  export const conversationList = new Command()
11
13
  .name('list')
12
14
  .description('List conversations')
13
15
  .option('-s, --stream', 'Stream conversations')
14
16
  .action(async (str, options) => {
15
17
  const { stream } = options;
18
+ const client = getClient();
16
19
  if (stream) {
17
20
  for await (const conversation of client.list().stream()) {
18
21
  print(conversation);
@@ -30,6 +33,7 @@ export const conversationFetch = new Command()
30
33
  .description('Fetch conversation')
31
34
  .argument('<conversationId>', 'Conversation ID')
32
35
  .action(async (conversationId) => {
36
+ const client = getClient();
33
37
  const conversation = await client.fetch(conversationId);
34
38
  print(conversation);
35
39
  });
@@ -38,6 +42,7 @@ export const conversationDelete = new Command()
38
42
  .description('Delete conversation')
39
43
  .argument('<conversationId>', 'Conversation ID')
40
44
  .action(async (conversationId) => {
45
+ const client = getClient();
41
46
  await client.delete(conversationId);
42
47
  });
43
48
  export const command = new Command()
@@ -2,10 +2,12 @@ import { getRUNAS_USERID, getSECRET } from '../../../../env.js';
2
2
  import { print } from '../../../../output.js';
3
3
  import { ConversationMessageClient } from '@chatbotkit/sdk/conversation/message/index.js';
4
4
  import { Command } from 'commander';
5
- const client = new ConversationMessageClient({
6
- secret: getSECRET(),
7
- runAsUserId: getRUNAS_USERID(),
8
- });
5
+ function getClient() {
6
+ return new ConversationMessageClient({
7
+ secret: getSECRET(),
8
+ runAsUserId: getRUNAS_USERID(),
9
+ });
10
+ }
9
11
  export const messageList = new Command()
10
12
  .name('list')
11
13
  .description('List messages')
@@ -13,6 +15,7 @@ export const messageList = new Command()
13
15
  .argument('<conversationId>', 'Conversation ID')
14
16
  .action(async (conversationId, options) => {
15
17
  const { stream } = options;
18
+ const client = getClient();
16
19
  if (stream) {
17
20
  for await (const message of client.list(conversationId).stream()) {
18
21
  print(message);
@@ -31,6 +34,7 @@ export const messageFetch = new Command()
31
34
  .argument('<conversationId>', 'Conversation ID')
32
35
  .argument('<messageId>', 'Message ID')
33
36
  .action(async (conversationId, messageId) => {
37
+ const client = getClient();
34
38
  const message = await client.fetch(conversationId, messageId);
35
39
  print(message);
36
40
  });
@@ -40,6 +44,7 @@ export const messageDelete = new Command()
40
44
  .argument('<conversationId>', 'Conversation ID')
41
45
  .argument('<messageId>', 'Message ID')
42
46
  .action(async (conversationId, messageId) => {
47
+ const client = getClient();
43
48
  await client.delete(conversationId, messageId);
44
49
  });
45
50
  export const command = new Command()
@@ -2,16 +2,19 @@ import { getRUNAS_USERID, getSECRET } from '../../../env.js';
2
2
  import { print } from '../../../output.js';
3
3
  import { DatasetClient } from '@chatbotkit/sdk/dataset/index.js';
4
4
  import { Command } from 'commander';
5
- const client = new DatasetClient({
6
- secret: getSECRET(),
7
- runAsUserId: getRUNAS_USERID(),
8
- });
5
+ function getClient() {
6
+ return new DatasetClient({
7
+ secret: getSECRET(),
8
+ runAsUserId: getRUNAS_USERID(),
9
+ });
10
+ }
9
11
  export const datasetList = new Command()
10
12
  .name('list')
11
13
  .description('List datasets')
12
14
  .option('-s, --stream', 'Stream datasets')
13
15
  .action(async (str, options) => {
14
16
  const { stream } = options;
17
+ const client = getClient();
15
18
  if (stream) {
16
19
  for await (const dataset of client.list().stream()) {
17
20
  print(dataset);
@@ -29,6 +32,7 @@ export const datasetFetch = new Command()
29
32
  .description('Fetch dataset')
30
33
  .argument('<datasetId>', 'Dataset ID')
31
34
  .action(async (datasetId) => {
35
+ const client = getClient();
32
36
  const dataset = await client.fetch(datasetId);
33
37
  print(dataset);
34
38
  });
@@ -37,6 +41,7 @@ export const datasetDelete = new Command()
37
41
  .description('Delete dataset')
38
42
  .argument('<datasetId>', 'Dataset ID')
39
43
  .action(async (datasetId) => {
44
+ const client = getClient();
40
45
  await client.delete(datasetId);
41
46
  });
42
47
  export const command = new Command()
@@ -2,16 +2,19 @@ import { getRUNAS_USERID, getSECRET } from '../../../../env.js';
2
2
  import { print } from '../../../../output.js';
3
3
  import { PartnerUserClient } from '@chatbotkit/sdk/partner/user/index.js';
4
4
  import { Command } from 'commander';
5
- const client = new PartnerUserClient({
6
- secret: getSECRET(),
7
- runAsUserId: getRUNAS_USERID(),
8
- });
5
+ function getClient() {
6
+ return new PartnerUserClient({
7
+ secret: getSECRET(),
8
+ runAsUserId: getRUNAS_USERID(),
9
+ });
10
+ }
9
11
  export const userList = new Command()
10
12
  .name('list')
11
13
  .description('List users')
12
14
  .option('-s, --stream', 'Stream users')
13
15
  .action(async (_arg, options) => {
14
16
  const { stream } = options;
17
+ const client = getClient();
15
18
  if (stream) {
16
19
  for await (const user of client.list().stream()) {
17
20
  print(user);
@@ -29,6 +32,7 @@ export const userFetch = new Command()
29
32
  .description('Fetch user')
30
33
  .argument('User ID')
31
34
  .action(async (userId) => {
35
+ const client = getClient();
32
36
  const user = await client.fetch(userId);
33
37
  print(user);
34
38
  });
@@ -37,6 +41,7 @@ export const userDelete = new Command()
37
41
  .description('Delete user')
38
42
  .argument('<userId>', 'User ID')
39
43
  .action(async (userId) => {
44
+ const client = getClient();
40
45
  await client.delete(userId);
41
46
  });
42
47
  export const command = new Command()
@@ -2,16 +2,19 @@ import { getRUNAS_USERID, getSECRET } from '../../../env.js';
2
2
  import { print } from '../../../output.js';
3
3
  import { SkillsetClient } from '@chatbotkit/sdk/skillset/index.js';
4
4
  import { Command } from 'commander';
5
- const client = new SkillsetClient({
6
- secret: getSECRET(),
7
- runAsUserId: getRUNAS_USERID(),
8
- });
5
+ function getClient() {
6
+ return new SkillsetClient({
7
+ secret: getSECRET(),
8
+ runAsUserId: getRUNAS_USERID(),
9
+ });
10
+ }
9
11
  export const skillsetList = new Command()
10
12
  .name('list')
11
13
  .description('List skillsets')
12
14
  .option('-s, --stream', 'Stream skillsets')
13
15
  .action(async (str, options) => {
14
16
  const { stream } = options;
17
+ const client = getClient();
15
18
  if (stream) {
16
19
  for await (const skillset of client.list().stream()) {
17
20
  print(skillset);
@@ -29,6 +32,7 @@ export const skillsetFetch = new Command()
29
32
  .description('Fetch skillset')
30
33
  .argument('<skillsetId>', 'Skillset ID')
31
34
  .action(async (skillsetId) => {
35
+ const client = getClient();
32
36
  const skillset = await client.fetch(skillsetId);
33
37
  print(skillset);
34
38
  });
@@ -37,6 +41,7 @@ export const skillsetDelete = new Command()
37
41
  .description('Delete skillset')
38
42
  .argument('<skillsetId>', 'Skillset ID')
39
43
  .action(async (skillsetId) => {
44
+ const client = getClient();
40
45
  await client.delete(skillsetId);
41
46
  });
42
47
  export const command = new Command()
@@ -2,15 +2,18 @@ import { getRUNAS_USERID, getSECRET } from '../../env.js';
2
2
  import { ConversationClient } from '@chatbotkit/sdk/conversation/index.js';
3
3
  import { Command, Option } from 'commander';
4
4
  import readline from 'readline/promises';
5
- const client = new ConversationClient({
6
- secret: getSECRET(),
7
- runAsUserId: getRUNAS_USERID(),
8
- });
5
+ function getClient() {
6
+ return new ConversationClient({
7
+ secret: getSECRET(),
8
+ runAsUserId: getRUNAS_USERID(),
9
+ });
10
+ }
9
11
  export const command = new Command()
10
12
  .name('chat')
11
13
  .description('Start a chat session')
12
14
  .addOption(new Option('-m, --model <model>', 'Model name').default('gpt-4'))
13
15
  .action(async (_arg, options) => {
16
+ const client = getClient();
14
17
  const rl = readline.createInterface({
15
18
  input: process.stdin,
16
19
  output: process.stdout,
@@ -0,0 +1,7 @@
1
+ export const solutionList: Command;
2
+ export const solutionCreate: Command;
3
+ export const solutionDelete: Command;
4
+ export const solutionSync: Command;
5
+ export const command: Command;
6
+ export default command;
7
+ import { Command } from 'commander';
@@ -0,0 +1,48 @@
1
+ import { confirm } from '../../input.js';
2
+ import { print } from '../../output.js';
3
+ import { Solution, getSolutionFileName } from '../../solution/index.js';
4
+ import resource from './resource/index.js';
5
+ import { Command } from 'commander';
6
+ export const solutionList = new Command()
7
+ .name('list')
8
+ .description('List solutions')
9
+ .action(async () => {
10
+ for (const name of await Solution.list()) {
11
+ print({ name });
12
+ }
13
+ });
14
+ export const solutionCreate = new Command()
15
+ .name('create')
16
+ .description('Create a new solution')
17
+ .argument('<name>', 'The name of the solution')
18
+ .action(async (name) => {
19
+ await Solution.create(name);
20
+ });
21
+ export const solutionDelete = new Command()
22
+ .name('delete')
23
+ .description('Delete a solution')
24
+ .argument('<name>', 'The name of the solution')
25
+ .action(async (name) => {
26
+ const fileName = getSolutionFileName(name);
27
+ if (!(await confirm(`Are you sure you want to delete solution ${fileName}?`))) {
28
+ return;
29
+ }
30
+ await Solution.delete(name);
31
+ });
32
+ export const solutionSync = new Command()
33
+ .name('sync')
34
+ .description('Sync a solution')
35
+ .argument('<name>', 'The name of the solution')
36
+ .action(async (name) => {
37
+ const solution = await Solution.load(name);
38
+ await solution.sync();
39
+ });
40
+ export const command = new Command()
41
+ .name('solution')
42
+ .description('Manage ChatBotKit solutions')
43
+ .addCommand(solutionList)
44
+ .addCommand(solutionCreate)
45
+ .addCommand(solutionDelete)
46
+ .addCommand(solutionSync)
47
+ .addCommand(resource);
48
+ export default command;
@@ -0,0 +1,5 @@
1
+ export const resourceCreate: Command;
2
+ export const resourceDelete: Command;
3
+ export const command: Command;
4
+ export default command;
5
+ import { Command } from 'commander';
@@ -0,0 +1,40 @@
1
+ import { confirm } from '../../../input.js';
2
+ import { CommandError } from '../../../output.js';
3
+ import { getSolutionFileName } from '../../../solution/index.js';
4
+ import { Command } from 'commander';
5
+ import fs from 'fs/promises';
6
+ import path from 'path';
7
+ export const resourceCreate = new Command()
8
+ .name('create')
9
+ .description('Create a new resource')
10
+ .argument('<name>', 'The name of the resource')
11
+ .action(async (name) => {
12
+ await fs.mkdir('.chatbotkit/resources', { recursive: true });
13
+ const fileName = getSolutionFileName(name);
14
+ const filePath = path.join('.chatbotkit', 'resources', fileName);
15
+ if (await fs.stat(filePath).catch(() => null)) {
16
+ throw new CommandError(`Resource ${fileName} already exists`);
17
+ }
18
+ await fs.writeFile(filePath, JSON.stringify({}));
19
+ });
20
+ export const resourceDelete = new Command()
21
+ .name('delete')
22
+ .description('Delete a resource')
23
+ .argument('<name>', 'The name of the resource')
24
+ .action(async (name) => {
25
+ const fileName = getSolutionFileName(name);
26
+ const filePath = path.join('.chatbotkit', 'resources', fileName);
27
+ if (!(await fs.stat(filePath).catch(() => null))) {
28
+ throw new CommandError(`Resource ${fileName} does not exist`);
29
+ }
30
+ if (!(await confirm(`Are you sure you want to delete resource ${fileName}?`))) {
31
+ return;
32
+ }
33
+ await fs.unlink(filePath);
34
+ });
35
+ export const command = new Command()
36
+ .name('resource')
37
+ .description('Manage ChatBotKit solution resources')
38
+ .addCommand(resourceCreate)
39
+ .addCommand(resourceDelete);
40
+ export default command;
@@ -1 +1 @@
1
- export default function cbk(): Promise<void>;
1
+ export default function cbk(argv?: string[] | undefined): Promise<void>;
package/dist/esm/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import command from './command/api/index.js';
2
2
  import chat from './command/chat/index.js';
3
+ import solution from './command/solution/index.js';
3
4
  import { Command } from 'commander';
4
- export default async function cbk() {
5
+ export default async function cbk(argv = process.argv) {
5
6
  const program = new Command();
6
7
  program.name('cbk').description('Command line tools for ChatBotKit');
7
8
  program.addCommand(command);
8
9
  program.addCommand(chat);
9
- program.parse();
10
+ program.addCommand(solution);
11
+ program.parse(argv);
10
12
  }
@@ -0,0 +1 @@
1
+ export function confirm(question: string): Promise<boolean>;
@@ -0,0 +1,13 @@
1
+ import readline from 'readline';
2
+ export async function confirm(question) {
3
+ const rl = readline.createInterface({
4
+ input: process.stdin,
5
+ output: process.stdout,
6
+ });
7
+ return new Promise((resolve) => {
8
+ rl.question(question + ' [y/N]', (answer) => {
9
+ rl.close();
10
+ resolve(answer.toLowerCase().startsWith('y'));
11
+ });
12
+ });
13
+ }
@@ -3,3 +3,5 @@ export function printError(error: any): void;
3
3
  export namespace config {
4
4
  let output: 'yaml' | 'json' | 'jsonl';
5
5
  }
6
+ export class CommandError extends Error {
7
+ }
@@ -3,6 +3,8 @@ import util from 'util';
3
3
  export const config = {
4
4
  output: 'yaml',
5
5
  };
6
+ export class CommandError extends Error {
7
+ }
6
8
  export function print(input) {
7
9
  switch (true) {
8
10
  case config.output === 'yaml': {
@@ -24,5 +26,10 @@ export function print(input) {
24
26
  }
25
27
  }
26
28
  export function printError(error) {
27
- console.error(error);
29
+ if (error instanceof CommandError) {
30
+ console.error(error.message);
31
+ }
32
+ else {
33
+ console.error(error);
34
+ }
28
35
  }
@@ -0,0 +1,7 @@
1
+ export function getArrayBackedObject<T>(array: T[]): {
2
+ [key: string]: T | undefined;
3
+ };
4
+ export class ArrayBackedObject<T> {
5
+ constructor(array: T[]);
6
+ array: T[];
7
+ }
@@ -0,0 +1,17 @@
1
+ export class ArrayBackedObject {
2
+ constructor(array) {
3
+ this.array = array;
4
+ return new Proxy(this, {
5
+ get: (target, property) => {
6
+ const item = target.array.find((item) => (item)?.name === property);
7
+ if (item) {
8
+ return item;
9
+ }
10
+ return undefined;
11
+ },
12
+ });
13
+ }
14
+ }
15
+ export function getArrayBackedObject(array) {
16
+ return new ArrayBackedObject(array);
17
+ }