@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.
- package/README.md +1 -0
- package/bin/cbk.js +7 -0
- package/dist/cjs/command/api/conversation/index.cjs +9 -4
- 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/partner/user/index.cjs +9 -4
- package/dist/cjs/command/api/skillset/index.cjs +9 -4
- package/dist/cjs/command/chat/index.cjs +7 -4
- package/dist/cjs/command/solution/index.cjs +52 -0
- package/dist/cjs/command/solution/index.d.ts +7 -0
- package/dist/cjs/command/solution/resource/index.cjs +44 -0
- package/dist/cjs/command/solution/resource/index.d.ts +5 -0
- package/dist/cjs/index.cjs +4 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/input.cjs +18 -0
- package/dist/cjs/input.d.ts +1 -0
- package/dist/cjs/output.cjs +10 -2
- package/dist/cjs/output.d.ts +2 -0
- package/dist/cjs/proxy.cjs +22 -0
- package/dist/cjs/proxy.d.ts +7 -0
- package/dist/cjs/solution/index.cjs +288 -0
- package/dist/cjs/solution/index.d.ts +815 -0
- package/dist/esm/command/api/conversation/index.js +9 -4
- 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/partner/user/index.js +9 -4
- package/dist/esm/command/api/skillset/index.js +9 -4
- package/dist/esm/command/chat/index.js +7 -4
- package/dist/esm/command/solution/index.d.ts +7 -0
- package/dist/esm/command/solution/index.js +48 -0
- package/dist/esm/command/solution/resource/index.d.ts +5 -0
- package/dist/esm/command/solution/resource/index.js +40 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +4 -2
- package/dist/esm/input.d.ts +1 -0
- package/dist/esm/input.js +13 -0
- package/dist/esm/output.d.ts +2 -0
- package/dist/esm/output.js +8 -1
- package/dist/esm/proxy.d.ts +7 -0
- package/dist/esm/proxy.js +17 -0
- package/dist/esm/solution/index.d.ts +815 -0
- package/dist/esm/solution/index.js +271 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +135 -2
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getArrayBackedObject = exports.ArrayBackedObject = exports.Solution = exports.SitemapIntegrationResource = exports.WidgetIntegrationResource = exports.SkillsetResource = exports.DatasetResource = exports.BotResource = exports.Resource = exports.SolutionConfigSchema = exports.ResourceConfigSchema = exports.SitemapIntegrationResourceConfigSchema = exports.WidgetIntegrationResourceConfigSchema = exports.SkillsetResourceConfigSchema = exports.DatasetResourceConfigSchema = exports.BotResourceConfigSchema = exports.BasicResourceConfigSchema = exports.getSolutionFileNameAndPath = exports.getSolutionFilePath = exports.getSolutionFileName = exports.getSolutionFolderPath = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const env_js_1 = require("../env.cjs");
|
|
6
|
+
const output_js_1 = require("../output.cjs");
|
|
7
|
+
const sdk_1 = tslib_1.__importDefault(require("@chatbotkit/sdk"));
|
|
8
|
+
const promises_1 = tslib_1.__importDefault(require("fs/promises"));
|
|
9
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
|
+
const zod_1 = require("zod");
|
|
11
|
+
function getSolutionFolderPath() {
|
|
12
|
+
const folderPath = path_1.default.join('.chatbotkit', 'solutions');
|
|
13
|
+
return folderPath;
|
|
14
|
+
}
|
|
15
|
+
exports.getSolutionFolderPath = getSolutionFolderPath;
|
|
16
|
+
function getSolutionFileName(name) {
|
|
17
|
+
const fileName = name.toLowerCase().replace(/\W/g, '_').replace(/_+/g, '_') + '.json';
|
|
18
|
+
return fileName;
|
|
19
|
+
}
|
|
20
|
+
exports.getSolutionFileName = getSolutionFileName;
|
|
21
|
+
function getSolutionFilePath(name) {
|
|
22
|
+
const fileName = getSolutionFileName(name);
|
|
23
|
+
const filePath = path_1.default.join(getSolutionFolderPath(), fileName);
|
|
24
|
+
return filePath;
|
|
25
|
+
}
|
|
26
|
+
exports.getSolutionFilePath = getSolutionFilePath;
|
|
27
|
+
function getSolutionFileNameAndPath(name) {
|
|
28
|
+
const fileName = getSolutionFileName(name);
|
|
29
|
+
const filePath = getSolutionFilePath(name);
|
|
30
|
+
return { fileName, filePath };
|
|
31
|
+
}
|
|
32
|
+
exports.getSolutionFileNameAndPath = getSolutionFileNameAndPath;
|
|
33
|
+
exports.BasicResourceConfigSchema = zod_1.z.object({
|
|
34
|
+
type: zod_1.z.string(),
|
|
35
|
+
slug: zod_1.z.string().optional(),
|
|
36
|
+
id: zod_1.z.string(),
|
|
37
|
+
name: zod_1.z.string(),
|
|
38
|
+
description: zod_1.z.string().optional(),
|
|
39
|
+
properties: zod_1.z.record(zod_1.z.unknown()),
|
|
40
|
+
});
|
|
41
|
+
exports.BotResourceConfigSchema = exports.BasicResourceConfigSchema.extend({
|
|
42
|
+
type: zod_1.z.literal('bot'),
|
|
43
|
+
properties: zod_1.z.object({
|
|
44
|
+
model: zod_1.z.string().optional(),
|
|
45
|
+
backstory: zod_1.z.string().optional(),
|
|
46
|
+
datasetId: zod_1.z.string().optional(),
|
|
47
|
+
skillsetId: zod_1.z.string().optional(),
|
|
48
|
+
moderation: zod_1.z.boolean().optional(),
|
|
49
|
+
privacy: zod_1.z.boolean().optional(),
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
exports.DatasetResourceConfigSchema = exports.BasicResourceConfigSchema.extend({
|
|
53
|
+
type: zod_1.z.literal('dataset'),
|
|
54
|
+
properties: zod_1.z.object({}),
|
|
55
|
+
});
|
|
56
|
+
exports.SkillsetResourceConfigSchema = exports.BasicResourceConfigSchema.extend({
|
|
57
|
+
type: zod_1.z.literal('skillset'),
|
|
58
|
+
properties: zod_1.z.object({}),
|
|
59
|
+
});
|
|
60
|
+
exports.WidgetIntegrationResourceConfigSchema = exports.BasicResourceConfigSchema.extend({
|
|
61
|
+
type: zod_1.z.literal('widgetIntegration'),
|
|
62
|
+
properties: zod_1.z.object({}),
|
|
63
|
+
});
|
|
64
|
+
exports.SitemapIntegrationResourceConfigSchema = exports.BasicResourceConfigSchema.extend({
|
|
65
|
+
type: zod_1.z.literal('sitemapIntegration'),
|
|
66
|
+
properties: zod_1.z.object({
|
|
67
|
+
url: zod_1.z.string().url(),
|
|
68
|
+
datasetId: zod_1.z.string(),
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
exports.ResourceConfigSchema = zod_1.z.union([
|
|
72
|
+
exports.BotResourceConfigSchema,
|
|
73
|
+
exports.DatasetResourceConfigSchema,
|
|
74
|
+
exports.SkillsetResourceConfigSchema,
|
|
75
|
+
exports.WidgetIntegrationResourceConfigSchema,
|
|
76
|
+
exports.SitemapIntegrationResourceConfigSchema,
|
|
77
|
+
]);
|
|
78
|
+
exports.SolutionConfigSchema = zod_1.z.object({
|
|
79
|
+
version: zod_1.z.literal(1),
|
|
80
|
+
resources: zod_1.z.array(exports.ResourceConfigSchema),
|
|
81
|
+
});
|
|
82
|
+
class Resource {
|
|
83
|
+
constructor(config) {
|
|
84
|
+
this.config = config;
|
|
85
|
+
}
|
|
86
|
+
get type() {
|
|
87
|
+
return this.config.type;
|
|
88
|
+
}
|
|
89
|
+
get slug() {
|
|
90
|
+
var _a;
|
|
91
|
+
return ((_a = this.config.slug) !== null && _a !== void 0 ? _a : this.config.name.toLowerCase().replace(/\W/g, '_').replace(/_+/g, '_'));
|
|
92
|
+
}
|
|
93
|
+
get id() {
|
|
94
|
+
return this.config.id;
|
|
95
|
+
}
|
|
96
|
+
get name() {
|
|
97
|
+
return this.config.name;
|
|
98
|
+
}
|
|
99
|
+
get description() {
|
|
100
|
+
return this.config.description;
|
|
101
|
+
}
|
|
102
|
+
get baseClient() {
|
|
103
|
+
const client = new sdk_1.default({
|
|
104
|
+
secret: (0, env_js_1.getSECRET)(),
|
|
105
|
+
runAsUserId: (0, env_js_1.getRUNAS_USERID)(),
|
|
106
|
+
});
|
|
107
|
+
return client;
|
|
108
|
+
}
|
|
109
|
+
get client() {
|
|
110
|
+
throw new Error('Not implemented');
|
|
111
|
+
}
|
|
112
|
+
async sync() {
|
|
113
|
+
this.client.update(this.config.id, {
|
|
114
|
+
...this.config.properties,
|
|
115
|
+
name: this.config.name,
|
|
116
|
+
description: this.config.description,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.Resource = Resource;
|
|
121
|
+
class BotResource extends Resource {
|
|
122
|
+
get client() {
|
|
123
|
+
return this.baseClient.bot;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.BotResource = BotResource;
|
|
127
|
+
class DatasetResource extends Resource {
|
|
128
|
+
get client() {
|
|
129
|
+
return this.baseClient.dataset;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.DatasetResource = DatasetResource;
|
|
133
|
+
class SkillsetResource extends Resource {
|
|
134
|
+
get client() {
|
|
135
|
+
return this.baseClient.skillset;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.SkillsetResource = SkillsetResource;
|
|
139
|
+
class WidgetIntegrationResource extends Resource {
|
|
140
|
+
get client() {
|
|
141
|
+
return this.baseClient.integration.widget;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.WidgetIntegrationResource = WidgetIntegrationResource;
|
|
145
|
+
class SitemapIntegrationResource extends Resource {
|
|
146
|
+
get client() {
|
|
147
|
+
return this.baseClient.integration.sitemap;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.SitemapIntegrationResource = SitemapIntegrationResource;
|
|
151
|
+
class Solution {
|
|
152
|
+
constructor(config) {
|
|
153
|
+
this.config = config;
|
|
154
|
+
}
|
|
155
|
+
get baseClient() {
|
|
156
|
+
const client = new sdk_1.default({
|
|
157
|
+
secret: (0, env_js_1.getSECRET)(),
|
|
158
|
+
runAsUserId: (0, env_js_1.getRUNAS_USERID)(),
|
|
159
|
+
});
|
|
160
|
+
return client;
|
|
161
|
+
}
|
|
162
|
+
get resources() {
|
|
163
|
+
return this.config.resources.map((resource) => {
|
|
164
|
+
if (resource.type === 'bot') {
|
|
165
|
+
return new BotResource(resource);
|
|
166
|
+
}
|
|
167
|
+
else if (resource.type === 'dataset') {
|
|
168
|
+
return new DatasetResource(resource);
|
|
169
|
+
}
|
|
170
|
+
else if (resource.type === 'skillset') {
|
|
171
|
+
return new SkillsetResource(resource);
|
|
172
|
+
}
|
|
173
|
+
else if (resource.type === 'widgetIntegration') {
|
|
174
|
+
return new WidgetIntegrationResource(resource);
|
|
175
|
+
}
|
|
176
|
+
else if (resource.type === 'sitemapIntegration') {
|
|
177
|
+
return new SitemapIntegrationResource(resource);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
throw new Error(`Unknown resource type: ${resource.type}`);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
get bots() {
|
|
185
|
+
return (this.resources.filter((resource) => resource instanceof BotResource));
|
|
186
|
+
}
|
|
187
|
+
get bot() {
|
|
188
|
+
return getArrayBackedObject(this.bots);
|
|
189
|
+
}
|
|
190
|
+
get datasets() {
|
|
191
|
+
return (this.resources.filter((resource) => resource instanceof DatasetResource));
|
|
192
|
+
}
|
|
193
|
+
get dataset() {
|
|
194
|
+
return getArrayBackedObject(this.datasets);
|
|
195
|
+
}
|
|
196
|
+
get skillsets() {
|
|
197
|
+
return (this.resources.filter((resource) => resource instanceof SkillsetResource));
|
|
198
|
+
}
|
|
199
|
+
get skillset() {
|
|
200
|
+
return getArrayBackedObject(this.skillsets);
|
|
201
|
+
}
|
|
202
|
+
get widgetIntegrations() {
|
|
203
|
+
return (this.resources.filter((resource) => resource instanceof WidgetIntegrationResource));
|
|
204
|
+
}
|
|
205
|
+
get widgetIntegration() {
|
|
206
|
+
return getArrayBackedObject(this.widgetIntegrations);
|
|
207
|
+
}
|
|
208
|
+
get sitemapIntegrations() {
|
|
209
|
+
return (this.resources.filter((resource) => resource instanceof SitemapIntegrationResource));
|
|
210
|
+
}
|
|
211
|
+
get sitemapIntegration() {
|
|
212
|
+
return getArrayBackedObject(this.sitemapIntegrations);
|
|
213
|
+
}
|
|
214
|
+
async sync() {
|
|
215
|
+
await Promise.all(this.resources.map((resource) => resource.sync()));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.Solution = Solution;
|
|
219
|
+
Solution.list = async function () {
|
|
220
|
+
await promises_1.default.mkdir(getSolutionFolderPath(), { recursive: true });
|
|
221
|
+
const files = await promises_1.default.readdir('.chatbotkit/solutions');
|
|
222
|
+
return files
|
|
223
|
+
.filter((file) => file.endsWith('.json'))
|
|
224
|
+
.map((file) => file.replace(/\.json$/, ''));
|
|
225
|
+
};
|
|
226
|
+
Solution.create = async function (name) {
|
|
227
|
+
await promises_1.default.mkdir('.chatbotkit/solutions', { recursive: true });
|
|
228
|
+
const fileName = getSolutionFileName(name);
|
|
229
|
+
const filePath = getSolutionFilePath(name);
|
|
230
|
+
if (await promises_1.default.stat(filePath).catch(() => null)) {
|
|
231
|
+
throw new output_js_1.CommandError(`Solution ${fileName} already exists`);
|
|
232
|
+
}
|
|
233
|
+
const config = {
|
|
234
|
+
version: 1,
|
|
235
|
+
resources: [],
|
|
236
|
+
};
|
|
237
|
+
await promises_1.default.writeFile(filePath, JSON.stringify(config, null, 2));
|
|
238
|
+
};
|
|
239
|
+
Solution.delete = async function (name) {
|
|
240
|
+
const fileName = getSolutionFileName(name);
|
|
241
|
+
const filePath = getSolutionFilePath(name);
|
|
242
|
+
if (!(await promises_1.default.stat(filePath).catch(() => null))) {
|
|
243
|
+
throw new output_js_1.CommandError(`Solution ${fileName} does not exist`);
|
|
244
|
+
}
|
|
245
|
+
await promises_1.default.unlink(filePath);
|
|
246
|
+
};
|
|
247
|
+
Solution.load = async function (config) {
|
|
248
|
+
let solutionConfig;
|
|
249
|
+
if (typeof config === 'string') {
|
|
250
|
+
const { fileName, filePath } = getSolutionFileNameAndPath(config);
|
|
251
|
+
if (!(await promises_1.default.stat(filePath).catch(() => null))) {
|
|
252
|
+
throw new output_js_1.CommandError(`Solution ${fileName} does not exist`);
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
solutionConfig = JSON.parse(await promises_1.default.readFile(filePath, 'utf8'));
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
throw new output_js_1.CommandError(`Failed to load solution ${fileName}: ${error.message}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
solutionConfig = config;
|
|
263
|
+
}
|
|
264
|
+
const parsedConfig = exports.SolutionConfigSchema.safeParse(solutionConfig);
|
|
265
|
+
if (!parsedConfig.success) {
|
|
266
|
+
throw new output_js_1.CommandError(`Invalid solution configuration`);
|
|
267
|
+
}
|
|
268
|
+
return new Solution(parsedConfig.data);
|
|
269
|
+
};
|
|
270
|
+
class ArrayBackedObject {
|
|
271
|
+
constructor(array) {
|
|
272
|
+
this.array = array;
|
|
273
|
+
return new Proxy(this, {
|
|
274
|
+
get: (target, property) => {
|
|
275
|
+
const item = target.array.find((item) => { var _a; return ((_a = (item)) === null || _a === void 0 ? void 0 : _a.slug) === property; });
|
|
276
|
+
if (item) {
|
|
277
|
+
return item;
|
|
278
|
+
}
|
|
279
|
+
return undefined;
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.ArrayBackedObject = ArrayBackedObject;
|
|
285
|
+
function getArrayBackedObject(array) {
|
|
286
|
+
return new ArrayBackedObject(array);
|
|
287
|
+
}
|
|
288
|
+
exports.getArrayBackedObject = getArrayBackedObject;
|