@chatbotkit/cli 1.19.0 → 1.21.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 +62 -20
- package/bin/cbk.js +3 -0
- package/dist/cjs/command/agent/index.cjs +100 -0
- package/dist/cjs/command/agent/index.d.ts +3 -0
- package/dist/cjs/command/api/conversation/index.cjs +13 -8
- package/dist/cjs/command/api/conversation/index.d.ts +0 -2
- package/dist/cjs/command/api/conversation/message/index.cjs +9 -4
- package/dist/cjs/command/api/dataset/index.cjs +9 -4
- package/dist/cjs/command/api/index.cjs +10 -5
- package/dist/cjs/command/api/index.d.ts +1 -0
- package/dist/cjs/command/api/partner/index.cjs +7 -2
- package/dist/cjs/command/api/partner/user/index.cjs +9 -4
- package/dist/cjs/command/api/skillset/index.cjs +9 -4
- package/dist/cjs/command/chat/index.cjs +34 -9
- package/dist/cjs/index.cjs +6 -4
- package/dist/cjs/output.cjs +4 -0
- package/dist/cjs/solution/index.cjs +3 -3
- package/dist/cjs/spinner.cjs +56 -0
- package/dist/cjs/spinner.d.ts +15 -0
- package/dist/cjs/tools.cjs +197 -0
- package/dist/cjs/tools.d.ts +9 -0
- package/dist/esm/command/agent/index.d.ts +3 -0
- package/dist/esm/command/agent/index.js +97 -0
- package/dist/esm/command/api/conversation/index.d.ts +0 -2
- package/dist/esm/command/api/conversation/index.js +12 -7
- package/dist/esm/command/api/conversation/message/index.js +9 -4
- package/dist/esm/command/api/dataset/index.js +9 -4
- package/dist/esm/command/api/index.d.ts +1 -0
- package/dist/esm/command/api/index.js +10 -5
- package/dist/esm/command/api/partner/index.js +7 -2
- package/dist/esm/command/api/partner/user/index.js +9 -4
- package/dist/esm/command/api/skillset/index.js +9 -4
- package/dist/esm/command/chat/index.js +34 -9
- package/dist/esm/index.js +2 -0
- package/dist/esm/output.js +4 -0
- package/dist/esm/solution/index.d.ts +16 -16
- package/dist/esm/spinner.d.ts +15 -0
- package/dist/esm/spinner.js +52 -0
- package/dist/esm/tools.d.ts +9 -0
- package/dist/esm/tools.js +192 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +76 -5
|
@@ -50,15 +50,15 @@ export const BotResourceConfigSchema: z.ZodObject<{
|
|
|
50
50
|
backstory?: string | undefined;
|
|
51
51
|
datasetId?: string | undefined;
|
|
52
52
|
skillsetId?: string | undefined;
|
|
53
|
-
moderation?: boolean | undefined;
|
|
54
53
|
privacy?: boolean | undefined;
|
|
54
|
+
moderation?: boolean | undefined;
|
|
55
55
|
}, {
|
|
56
56
|
model?: string | undefined;
|
|
57
57
|
backstory?: string | undefined;
|
|
58
58
|
datasetId?: string | undefined;
|
|
59
59
|
skillsetId?: string | undefined;
|
|
60
|
-
moderation?: boolean | undefined;
|
|
61
60
|
privacy?: boolean | undefined;
|
|
61
|
+
moderation?: boolean | undefined;
|
|
62
62
|
}>;
|
|
63
63
|
}, "strip", z.ZodTypeAny, {
|
|
64
64
|
type: "bot";
|
|
@@ -68,8 +68,8 @@ export const BotResourceConfigSchema: z.ZodObject<{
|
|
|
68
68
|
backstory?: string | undefined;
|
|
69
69
|
datasetId?: string | undefined;
|
|
70
70
|
skillsetId?: string | undefined;
|
|
71
|
-
moderation?: boolean | undefined;
|
|
72
71
|
privacy?: boolean | undefined;
|
|
72
|
+
moderation?: boolean | undefined;
|
|
73
73
|
};
|
|
74
74
|
slug?: string | undefined;
|
|
75
75
|
id?: string | undefined;
|
|
@@ -82,8 +82,8 @@ export const BotResourceConfigSchema: z.ZodObject<{
|
|
|
82
82
|
backstory?: string | undefined;
|
|
83
83
|
datasetId?: string | undefined;
|
|
84
84
|
skillsetId?: string | undefined;
|
|
85
|
-
moderation?: boolean | undefined;
|
|
86
85
|
privacy?: boolean | undefined;
|
|
86
|
+
moderation?: boolean | undefined;
|
|
87
87
|
};
|
|
88
88
|
slug?: string | undefined;
|
|
89
89
|
id?: string | undefined;
|
|
@@ -215,15 +215,15 @@ export const ResourceConfigSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
215
215
|
backstory?: string | undefined;
|
|
216
216
|
datasetId?: string | undefined;
|
|
217
217
|
skillsetId?: string | undefined;
|
|
218
|
-
moderation?: boolean | undefined;
|
|
219
218
|
privacy?: boolean | undefined;
|
|
219
|
+
moderation?: boolean | undefined;
|
|
220
220
|
}, {
|
|
221
221
|
model?: string | undefined;
|
|
222
222
|
backstory?: string | undefined;
|
|
223
223
|
datasetId?: string | undefined;
|
|
224
224
|
skillsetId?: string | undefined;
|
|
225
|
-
moderation?: boolean | undefined;
|
|
226
225
|
privacy?: boolean | undefined;
|
|
226
|
+
moderation?: boolean | undefined;
|
|
227
227
|
}>;
|
|
228
228
|
}, "strip", z.ZodTypeAny, {
|
|
229
229
|
type: "bot";
|
|
@@ -233,8 +233,8 @@ export const ResourceConfigSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
233
233
|
backstory?: string | undefined;
|
|
234
234
|
datasetId?: string | undefined;
|
|
235
235
|
skillsetId?: string | undefined;
|
|
236
|
-
moderation?: boolean | undefined;
|
|
237
236
|
privacy?: boolean | undefined;
|
|
237
|
+
moderation?: boolean | undefined;
|
|
238
238
|
};
|
|
239
239
|
slug?: string | undefined;
|
|
240
240
|
id?: string | undefined;
|
|
@@ -247,8 +247,8 @@ export const ResourceConfigSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
247
247
|
backstory?: string | undefined;
|
|
248
248
|
datasetId?: string | undefined;
|
|
249
249
|
skillsetId?: string | undefined;
|
|
250
|
-
moderation?: boolean | undefined;
|
|
251
250
|
privacy?: boolean | undefined;
|
|
251
|
+
moderation?: boolean | undefined;
|
|
252
252
|
};
|
|
253
253
|
slug?: string | undefined;
|
|
254
254
|
id?: string | undefined;
|
|
@@ -378,15 +378,15 @@ export const SolutionConfigSchema: z.ZodObject<{
|
|
|
378
378
|
backstory?: string | undefined;
|
|
379
379
|
datasetId?: string | undefined;
|
|
380
380
|
skillsetId?: string | undefined;
|
|
381
|
-
moderation?: boolean | undefined;
|
|
382
381
|
privacy?: boolean | undefined;
|
|
382
|
+
moderation?: boolean | undefined;
|
|
383
383
|
}, {
|
|
384
384
|
model?: string | undefined;
|
|
385
385
|
backstory?: string | undefined;
|
|
386
386
|
datasetId?: string | undefined;
|
|
387
387
|
skillsetId?: string | undefined;
|
|
388
|
-
moderation?: boolean | undefined;
|
|
389
388
|
privacy?: boolean | undefined;
|
|
389
|
+
moderation?: boolean | undefined;
|
|
390
390
|
}>;
|
|
391
391
|
}, "strip", z.ZodTypeAny, {
|
|
392
392
|
type: "bot";
|
|
@@ -396,8 +396,8 @@ export const SolutionConfigSchema: z.ZodObject<{
|
|
|
396
396
|
backstory?: string | undefined;
|
|
397
397
|
datasetId?: string | undefined;
|
|
398
398
|
skillsetId?: string | undefined;
|
|
399
|
-
moderation?: boolean | undefined;
|
|
400
399
|
privacy?: boolean | undefined;
|
|
400
|
+
moderation?: boolean | undefined;
|
|
401
401
|
};
|
|
402
402
|
slug?: string | undefined;
|
|
403
403
|
id?: string | undefined;
|
|
@@ -410,8 +410,8 @@ export const SolutionConfigSchema: z.ZodObject<{
|
|
|
410
410
|
backstory?: string | undefined;
|
|
411
411
|
datasetId?: string | undefined;
|
|
412
412
|
skillsetId?: string | undefined;
|
|
413
|
-
moderation?: boolean | undefined;
|
|
414
413
|
privacy?: boolean | undefined;
|
|
414
|
+
moderation?: boolean | undefined;
|
|
415
415
|
};
|
|
416
416
|
slug?: string | undefined;
|
|
417
417
|
id?: string | undefined;
|
|
@@ -530,8 +530,8 @@ export const SolutionConfigSchema: z.ZodObject<{
|
|
|
530
530
|
backstory?: string | undefined;
|
|
531
531
|
datasetId?: string | undefined;
|
|
532
532
|
skillsetId?: string | undefined;
|
|
533
|
-
moderation?: boolean | undefined;
|
|
534
533
|
privacy?: boolean | undefined;
|
|
534
|
+
moderation?: boolean | undefined;
|
|
535
535
|
};
|
|
536
536
|
slug?: string | undefined;
|
|
537
537
|
id?: string | undefined;
|
|
@@ -578,8 +578,8 @@ export const SolutionConfigSchema: z.ZodObject<{
|
|
|
578
578
|
backstory?: string | undefined;
|
|
579
579
|
datasetId?: string | undefined;
|
|
580
580
|
skillsetId?: string | undefined;
|
|
581
|
-
moderation?: boolean | undefined;
|
|
582
581
|
privacy?: boolean | undefined;
|
|
582
|
+
moderation?: boolean | undefined;
|
|
583
583
|
};
|
|
584
584
|
slug?: string | undefined;
|
|
585
585
|
id?: string | undefined;
|
|
@@ -627,8 +627,8 @@ export class Resource {
|
|
|
627
627
|
backstory?: string | undefined;
|
|
628
628
|
datasetId?: string | undefined;
|
|
629
629
|
skillsetId?: string | undefined;
|
|
630
|
-
moderation?: boolean | undefined;
|
|
631
630
|
privacy?: boolean | undefined;
|
|
631
|
+
moderation?: boolean | undefined;
|
|
632
632
|
};
|
|
633
633
|
slug?: string | undefined;
|
|
634
634
|
id?: string | undefined;
|
|
@@ -708,8 +708,8 @@ export class Solution {
|
|
|
708
708
|
backstory?: string | undefined;
|
|
709
709
|
datasetId?: string | undefined;
|
|
710
710
|
skillsetId?: string | undefined;
|
|
711
|
-
moderation?: boolean | undefined;
|
|
712
711
|
privacy?: boolean | undefined;
|
|
712
|
+
moderation?: boolean | undefined;
|
|
713
713
|
};
|
|
714
714
|
slug?: string | undefined;
|
|
715
715
|
id?: string | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class Spinner {
|
|
2
|
+
constructor(text?: string, options?: {
|
|
3
|
+
frames?: string[] | undefined;
|
|
4
|
+
interval?: number | undefined;
|
|
5
|
+
});
|
|
6
|
+
text: string;
|
|
7
|
+
frames: string[];
|
|
8
|
+
interval: number;
|
|
9
|
+
frameIndex: number;
|
|
10
|
+
intervalId: NodeJS.Timeout | null;
|
|
11
|
+
isSpinning: boolean;
|
|
12
|
+
start(): void;
|
|
13
|
+
stop(keepText?: boolean): void;
|
|
14
|
+
setText(text: string): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export class Spinner {
|
|
2
|
+
constructor(text = '', options = {}) {
|
|
3
|
+
this.text = text;
|
|
4
|
+
this.frames = options.frames || [
|
|
5
|
+
'⠋',
|
|
6
|
+
'⠙',
|
|
7
|
+
'⠹',
|
|
8
|
+
'⠸',
|
|
9
|
+
'⠼',
|
|
10
|
+
'⠴',
|
|
11
|
+
'⠦',
|
|
12
|
+
'⠧',
|
|
13
|
+
'⠇',
|
|
14
|
+
'⠏',
|
|
15
|
+
];
|
|
16
|
+
this.interval = options.interval || 80;
|
|
17
|
+
this.frameIndex = 0;
|
|
18
|
+
this.intervalId = null;
|
|
19
|
+
this.isSpinning = false;
|
|
20
|
+
}
|
|
21
|
+
start() {
|
|
22
|
+
if (this.isSpinning) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.isSpinning = true;
|
|
26
|
+
this.frameIndex = 0;
|
|
27
|
+
this.intervalId = setInterval(() => {
|
|
28
|
+
const frame = this.frames[this.frameIndex];
|
|
29
|
+
process.stdout.write(`\r${this.text}${frame} `);
|
|
30
|
+
this.frameIndex = (this.frameIndex + 1) % this.frames.length;
|
|
31
|
+
}, this.interval);
|
|
32
|
+
}
|
|
33
|
+
stop(keepText = true) {
|
|
34
|
+
if (!this.isSpinning) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.isSpinning = false;
|
|
38
|
+
if (this.intervalId) {
|
|
39
|
+
clearInterval(this.intervalId);
|
|
40
|
+
this.intervalId = null;
|
|
41
|
+
}
|
|
42
|
+
if (keepText) {
|
|
43
|
+
process.stdout.write(`\r${this.text}`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
process.stdout.write('\r' + ' '.repeat(this.text.length + 2) + '\r');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
setText(text) {
|
|
50
|
+
this.text = text;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function getTools(selectedTools?: Array<keyof typeof tools>): typeof tools;
|
|
2
|
+
export function getToolNames(): Array<keyof typeof tools>;
|
|
3
|
+
export const tools: Record<string, {
|
|
4
|
+
description: string;
|
|
5
|
+
input: z.ZodObject<any>;
|
|
6
|
+
handler: (input: any) => Promise<any>;
|
|
7
|
+
default?: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
import { z } from 'zod';
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { exec, spawn } from 'child_process';
|
|
2
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
const execAsync = promisify(exec);
|
|
6
|
+
export const tools = {
|
|
7
|
+
read: {
|
|
8
|
+
description: 'Read the contents of a file',
|
|
9
|
+
default: true,
|
|
10
|
+
input: z.object({
|
|
11
|
+
path: z.string().describe('The file path to read'),
|
|
12
|
+
}),
|
|
13
|
+
handler: async (input) => {
|
|
14
|
+
try {
|
|
15
|
+
const content = await readFile(input.path, 'utf-8');
|
|
16
|
+
return { success: true, content };
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
return {
|
|
20
|
+
success: false,
|
|
21
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
write: {
|
|
27
|
+
description: 'Write content to a file',
|
|
28
|
+
default: true,
|
|
29
|
+
input: z.object({
|
|
30
|
+
path: z.string().describe('The file path to write to'),
|
|
31
|
+
content: z.string().describe('The content to write'),
|
|
32
|
+
}),
|
|
33
|
+
handler: async (input) => {
|
|
34
|
+
try {
|
|
35
|
+
await writeFile(input.path, input.content, 'utf-8');
|
|
36
|
+
return { success: true };
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
edit: {
|
|
47
|
+
description: 'Edit a file by replacing an exact string occurrence with a new string. Only one occurrence must exist.',
|
|
48
|
+
default: true,
|
|
49
|
+
input: z.object({
|
|
50
|
+
path: z.string().describe('The file path to edit'),
|
|
51
|
+
oldString: z
|
|
52
|
+
.string()
|
|
53
|
+
.describe('The exact string to find and replace (must match exactly)'),
|
|
54
|
+
newString: z.string().describe('The new string to replace with'),
|
|
55
|
+
}),
|
|
56
|
+
handler: async (input) => {
|
|
57
|
+
try {
|
|
58
|
+
const content = await readFile(input.path, 'utf-8');
|
|
59
|
+
const occurrences = content.split(input.oldString).length - 1;
|
|
60
|
+
if (occurrences === 0) {
|
|
61
|
+
return {
|
|
62
|
+
success: false,
|
|
63
|
+
error: 'String not found in file',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (occurrences > 1) {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
error: `Multiple occurrences found (${occurrences}). The old string must match exactly one location.`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const newContent = content.replace(input.oldString, input.newString);
|
|
73
|
+
await writeFile(input.path, newContent, 'utf-8');
|
|
74
|
+
const oldPreview = input.oldString.length > 100
|
|
75
|
+
? input.oldString.substring(0, 100) + '...'
|
|
76
|
+
: input.oldString;
|
|
77
|
+
const newPreview = input.newString.length > 100
|
|
78
|
+
? input.newString.substring(0, 100) + '...'
|
|
79
|
+
: input.newString;
|
|
80
|
+
return {
|
|
81
|
+
success: true,
|
|
82
|
+
message: `Successfully replaced:\n OLD: ${oldPreview}\n NEW: ${newPreview}`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
find: {
|
|
94
|
+
description: 'Search for files matching a pattern',
|
|
95
|
+
default: true,
|
|
96
|
+
input: z.object({
|
|
97
|
+
pattern: z.string().describe('The glob pattern to search for'),
|
|
98
|
+
directory: z
|
|
99
|
+
.string()
|
|
100
|
+
.optional()
|
|
101
|
+
.describe('The directory to search in (defaults to current)'),
|
|
102
|
+
}),
|
|
103
|
+
handler: async (input) => {
|
|
104
|
+
try {
|
|
105
|
+
const dir = input.directory || '.';
|
|
106
|
+
const { stdout } = await execAsync(`find ${dir} -name "${input.pattern}"`);
|
|
107
|
+
const files = stdout.trim().split('\n').filter(Boolean);
|
|
108
|
+
return { success: true, files };
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return {
|
|
112
|
+
success: false,
|
|
113
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
exec: {
|
|
119
|
+
description: 'Execute a shell command (non-interactive only). Commands timeout after the specified duration (default 30 seconds). Use only for commands that run and exit automatically.',
|
|
120
|
+
default: true,
|
|
121
|
+
input: z.object({
|
|
122
|
+
command: z.string().describe('The command to execute'),
|
|
123
|
+
timeout: z
|
|
124
|
+
.number()
|
|
125
|
+
.default(30)
|
|
126
|
+
.describe('Timeout in seconds. The command will be killed if it runs longer than this.'),
|
|
127
|
+
}),
|
|
128
|
+
handler: async (input) => {
|
|
129
|
+
const timeoutMs = input.timeout * 1000;
|
|
130
|
+
return new Promise((resolve) => {
|
|
131
|
+
const childProcess = spawn('sh', ['-c', input.command], {
|
|
132
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
133
|
+
timeout: timeoutMs,
|
|
134
|
+
});
|
|
135
|
+
let stdout = '';
|
|
136
|
+
let stderr = '';
|
|
137
|
+
let timedOut = false;
|
|
138
|
+
childProcess.stdout.on('data', (data) => {
|
|
139
|
+
stdout += data.toString();
|
|
140
|
+
});
|
|
141
|
+
childProcess.stderr.on('data', (data) => {
|
|
142
|
+
stderr += data.toString();
|
|
143
|
+
});
|
|
144
|
+
childProcess.on('close', (code) => {
|
|
145
|
+
if (timedOut) {
|
|
146
|
+
resolve({
|
|
147
|
+
success: false,
|
|
148
|
+
error: `Command timed out after ${timeoutMs / 1000} seconds. This may indicate an interactive command.`,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
else if (code === 0) {
|
|
152
|
+
resolve({ success: true, stdout, stderr });
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
resolve({
|
|
156
|
+
success: false,
|
|
157
|
+
error: `Command exited with code ${code}`,
|
|
158
|
+
stdout,
|
|
159
|
+
stderr,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
childProcess.on('error', (error) => {
|
|
164
|
+
resolve({
|
|
165
|
+
success: false,
|
|
166
|
+
error: error.message,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
setTimeout(() => {
|
|
170
|
+
if (!childProcess.killed) {
|
|
171
|
+
timedOut = true;
|
|
172
|
+
childProcess.kill('SIGTERM');
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
if (!childProcess.killed) {
|
|
175
|
+
childProcess.kill('SIGKILL');
|
|
176
|
+
}
|
|
177
|
+
}, 2000);
|
|
178
|
+
}
|
|
179
|
+
}, timeoutMs);
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
export function getTools(selectedTools) {
|
|
185
|
+
if (!selectedTools || selectedTools.length === 0) {
|
|
186
|
+
return Object.fromEntries(Object.entries(tools).filter(([, tool]) => tool.default));
|
|
187
|
+
}
|
|
188
|
+
return Object.fromEntries(Object.entries(tools).filter(([name]) => selectedTools.includes(name)));
|
|
189
|
+
}
|
|
190
|
+
export function getToolNames() {
|
|
191
|
+
return Object.keys(tools);
|
|
192
|
+
}
|