@scout9/app 1.0.0-alpha.0.1.9 → 1.0.0-alpha.0.1.91

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 (70) hide show
  1. package/README.md +33 -0
  2. package/dist/{index-92deaa5f.cjs → exports-212ef6be.cjs} +46636 -4591
  3. package/dist/index.cjs +58 -15
  4. package/dist/{multipart-parser-090f08a9.cjs → multipart-parser-54a3ab5f.cjs} +13 -7
  5. package/dist/spirits-3b603262.cjs +1218 -0
  6. package/dist/spirits.cjs +9 -0
  7. package/dist/testing-tools.cjs +48 -0
  8. package/package.json +37 -8
  9. package/src/cli.js +162 -69
  10. package/src/core/config/agents.js +300 -7
  11. package/src/core/config/entities.js +58 -28
  12. package/src/core/config/index.js +37 -15
  13. package/src/core/config/project.js +160 -6
  14. package/src/core/config/workflow.js +13 -12
  15. package/src/core/data.js +27 -0
  16. package/src/core/index.js +386 -137
  17. package/src/core/sync.js +71 -0
  18. package/src/core/templates/Dockerfile +22 -0
  19. package/src/core/templates/app.js +453 -0
  20. package/src/core/templates/project-files.js +36 -0
  21. package/src/core/templates/template-package.json +13 -0
  22. package/src/exports.js +21 -17
  23. package/src/platform.js +189 -33
  24. package/src/public.d.ts.text +330 -0
  25. package/src/report.js +117 -0
  26. package/src/runtime/client/api.js +56 -159
  27. package/src/runtime/client/config.js +60 -11
  28. package/src/runtime/client/entity.js +19 -6
  29. package/src/runtime/client/index.js +5 -3
  30. package/src/runtime/client/message.js +13 -3
  31. package/src/runtime/client/platform.js +86 -0
  32. package/src/runtime/client/{agent.js → users.js} +35 -3
  33. package/src/runtime/client/utils.js +10 -9
  34. package/src/runtime/client/workflow.js +132 -9
  35. package/src/runtime/entry.js +2 -2
  36. package/src/testing-tools/dev.js +373 -0
  37. package/src/testing-tools/index.js +1 -0
  38. package/src/testing-tools/mocks.js +37 -5
  39. package/src/testing-tools/spirits.js +530 -0
  40. package/src/utils/audio-buffer.js +16 -0
  41. package/src/utils/audio-type.js +27 -0
  42. package/src/utils/configs/agents.js +68 -0
  43. package/src/utils/configs/entities.js +145 -0
  44. package/src/utils/configs/project.js +23 -0
  45. package/src/utils/configs/workflow.js +47 -0
  46. package/src/utils/file-type.js +569 -0
  47. package/src/utils/file.js +164 -0
  48. package/src/utils/glob.js +30 -0
  49. package/src/utils/image-buffer.js +23 -0
  50. package/src/utils/image-type.js +39 -0
  51. package/src/utils/index.js +1 -0
  52. package/src/utils/is-svg.js +37 -0
  53. package/src/utils/logger.js +111 -0
  54. package/src/utils/module.js +14 -25
  55. package/src/utils/project-templates.js +191 -0
  56. package/src/utils/project.js +387 -0
  57. package/src/utils/video-type.js +29 -0
  58. package/types/index.d.ts +7588 -206
  59. package/types/index.d.ts.map +97 -22
  60. package/dist/index-1b8d7dd2.cjs +0 -49555
  61. package/dist/index-2ccb115e.cjs +0 -49514
  62. package/dist/index-66b06a30.cjs +0 -49549
  63. package/dist/index-bc029a1d.cjs +0 -49528
  64. package/dist/index-d9a93523.cjs +0 -49527
  65. package/dist/multipart-parser-1508046a.cjs +0 -413
  66. package/dist/multipart-parser-7007403a.cjs +0 -413
  67. package/dist/multipart-parser-70c32c1d.cjs +0 -413
  68. package/dist/multipart-parser-71dec101.cjs +0 -413
  69. package/dist/multipart-parser-f15bf2e0.cjs +0 -414
  70. package/src/public.d.ts +0 -209
@@ -1,414 +0,0 @@
1
- 'use strict';
2
-
3
- require('node:fs');
4
- require('node:path');
5
- var index = require("./index-92deaa5f.cjs");
6
- require('fs');
7
- require('events');
8
- require('path');
9
- require('constants');
10
- require('stream');
11
- require('util');
12
- require('assert');
13
- require('buffer');
14
- require('zlib');
15
- require('url');
16
- require('fs/promises');
17
- require('string_decoder');
18
- require('node:child_process');
19
- require('node:fs/promises');
20
- require('node:http');
21
- require('node:https');
22
- require('node:zlib');
23
- require('node:stream');
24
- require('node:buffer');
25
- require('node:util');
26
- require('node:url');
27
- require('node:net');
28
- require('node:vm');
29
- require('os');
30
- require('crypto');
31
- require("glob/dist/esm/index.cjs");
32
-
33
- let s = 0;
34
- const S = {
35
- START_BOUNDARY: s++,
36
- HEADER_FIELD_START: s++,
37
- HEADER_FIELD: s++,
38
- HEADER_VALUE_START: s++,
39
- HEADER_VALUE: s++,
40
- HEADER_VALUE_ALMOST_DONE: s++,
41
- HEADERS_ALMOST_DONE: s++,
42
- PART_DATA_START: s++,
43
- PART_DATA: s++,
44
- END: s++
45
- };
46
- let f = 1;
47
- const F = {
48
- PART_BOUNDARY: f,
49
- LAST_BOUNDARY: f *= 2
50
- };
51
- const LF = 10;
52
- const CR = 13;
53
- const SPACE = 32;
54
- const HYPHEN = 45;
55
- const COLON = 58;
56
- const A = 97;
57
- const Z = 122;
58
- const lower = c => c | 0x20;
59
- const noop = () => {};
60
- class MultipartParser {
61
- /**
62
- * @param {string} boundary
63
- */
64
- constructor(boundary) {
65
- this.index = 0;
66
- this.flags = 0;
67
- this.onHeaderEnd = noop;
68
- this.onHeaderField = noop;
69
- this.onHeadersEnd = noop;
70
- this.onHeaderValue = noop;
71
- this.onPartBegin = noop;
72
- this.onPartData = noop;
73
- this.onPartEnd = noop;
74
- this.boundaryChars = {};
75
- boundary = '\r\n--' + boundary;
76
- const ui8a = new Uint8Array(boundary.length);
77
- for (let i = 0; i < boundary.length; i++) {
78
- ui8a[i] = boundary.charCodeAt(i);
79
- this.boundaryChars[ui8a[i]] = true;
80
- }
81
- this.boundary = ui8a;
82
- this.lookbehind = new Uint8Array(this.boundary.length + 8);
83
- this.state = S.START_BOUNDARY;
84
- }
85
-
86
- /**
87
- * @param {Uint8Array} data
88
- */
89
- write(data) {
90
- let i = 0;
91
- const length_ = data.length;
92
- let previousIndex = this.index;
93
- let {
94
- lookbehind,
95
- boundary,
96
- boundaryChars,
97
- index,
98
- state,
99
- flags
100
- } = this;
101
- const boundaryLength = this.boundary.length;
102
- const boundaryEnd = boundaryLength - 1;
103
- const bufferLength = data.length;
104
- let c;
105
- let cl;
106
- const mark = name => {
107
- this[name + 'Mark'] = i;
108
- };
109
- const clear = name => {
110
- delete this[name + 'Mark'];
111
- };
112
- const callback = (callbackSymbol, start, end, ui8a) => {
113
- if (start === undefined || start !== end) {
114
- this[callbackSymbol](ui8a && ui8a.subarray(start, end));
115
- }
116
- };
117
- const dataCallback = (name, clear) => {
118
- const markSymbol = name + 'Mark';
119
- if (!(markSymbol in this)) {
120
- return;
121
- }
122
- if (clear) {
123
- callback(name, this[markSymbol], i, data);
124
- delete this[markSymbol];
125
- } else {
126
- callback(name, this[markSymbol], data.length, data);
127
- this[markSymbol] = 0;
128
- }
129
- };
130
- for (i = 0; i < length_; i++) {
131
- c = data[i];
132
- switch (state) {
133
- case S.START_BOUNDARY:
134
- if (index === boundary.length - 2) {
135
- if (c === HYPHEN) {
136
- flags |= F.LAST_BOUNDARY;
137
- } else if (c !== CR) {
138
- return;
139
- }
140
- index++;
141
- break;
142
- } else if (index - 1 === boundary.length - 2) {
143
- if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
144
- state = S.END;
145
- flags = 0;
146
- } else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
147
- index = 0;
148
- callback('onPartBegin');
149
- state = S.HEADER_FIELD_START;
150
- } else {
151
- return;
152
- }
153
- break;
154
- }
155
- if (c !== boundary[index + 2]) {
156
- index = -2;
157
- }
158
- if (c === boundary[index + 2]) {
159
- index++;
160
- }
161
- break;
162
- case S.HEADER_FIELD_START:
163
- state = S.HEADER_FIELD;
164
- mark('onHeaderField');
165
- index = 0;
166
- // falls through
167
- case S.HEADER_FIELD:
168
- if (c === CR) {
169
- clear('onHeaderField');
170
- state = S.HEADERS_ALMOST_DONE;
171
- break;
172
- }
173
- index++;
174
- if (c === HYPHEN) {
175
- break;
176
- }
177
- if (c === COLON) {
178
- if (index === 1) {
179
- // empty header field
180
- return;
181
- }
182
- dataCallback('onHeaderField', true);
183
- state = S.HEADER_VALUE_START;
184
- break;
185
- }
186
- cl = lower(c);
187
- if (cl < A || cl > Z) {
188
- return;
189
- }
190
- break;
191
- case S.HEADER_VALUE_START:
192
- if (c === SPACE) {
193
- break;
194
- }
195
- mark('onHeaderValue');
196
- state = S.HEADER_VALUE;
197
- // falls through
198
- case S.HEADER_VALUE:
199
- if (c === CR) {
200
- dataCallback('onHeaderValue', true);
201
- callback('onHeaderEnd');
202
- state = S.HEADER_VALUE_ALMOST_DONE;
203
- }
204
- break;
205
- case S.HEADER_VALUE_ALMOST_DONE:
206
- if (c !== LF) {
207
- return;
208
- }
209
- state = S.HEADER_FIELD_START;
210
- break;
211
- case S.HEADERS_ALMOST_DONE:
212
- if (c !== LF) {
213
- return;
214
- }
215
- callback('onHeadersEnd');
216
- state = S.PART_DATA_START;
217
- break;
218
- case S.PART_DATA_START:
219
- state = S.PART_DATA;
220
- mark('onPartData');
221
- // falls through
222
- case S.PART_DATA:
223
- previousIndex = index;
224
- if (index === 0) {
225
- // boyer-moore derrived algorithm to safely skip non-boundary data
226
- i += boundaryEnd;
227
- while (i < bufferLength && !(data[i] in boundaryChars)) {
228
- i += boundaryLength;
229
- }
230
- i -= boundaryEnd;
231
- c = data[i];
232
- }
233
- if (index < boundary.length) {
234
- if (boundary[index] === c) {
235
- if (index === 0) {
236
- dataCallback('onPartData', true);
237
- }
238
- index++;
239
- } else {
240
- index = 0;
241
- }
242
- } else if (index === boundary.length) {
243
- index++;
244
- if (c === CR) {
245
- // CR = part boundary
246
- flags |= F.PART_BOUNDARY;
247
- } else if (c === HYPHEN) {
248
- // HYPHEN = end boundary
249
- flags |= F.LAST_BOUNDARY;
250
- } else {
251
- index = 0;
252
- }
253
- } else if (index - 1 === boundary.length) {
254
- if (flags & F.PART_BOUNDARY) {
255
- index = 0;
256
- if (c === LF) {
257
- // unset the PART_BOUNDARY flag
258
- flags &= ~F.PART_BOUNDARY;
259
- callback('onPartEnd');
260
- callback('onPartBegin');
261
- state = S.HEADER_FIELD_START;
262
- break;
263
- }
264
- } else if (flags & F.LAST_BOUNDARY) {
265
- if (c === HYPHEN) {
266
- callback('onPartEnd');
267
- state = S.END;
268
- flags = 0;
269
- } else {
270
- index = 0;
271
- }
272
- } else {
273
- index = 0;
274
- }
275
- }
276
- if (index > 0) {
277
- // when matching a possible boundary, keep a lookbehind reference
278
- // in case it turns out to be a false lead
279
- lookbehind[index - 1] = c;
280
- } else if (previousIndex > 0) {
281
- // if our boundary turned out to be rubbish, the captured lookbehind
282
- // belongs to partData
283
- const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
284
- callback('onPartData', 0, previousIndex, _lookbehind);
285
- previousIndex = 0;
286
- mark('onPartData');
287
-
288
- // reconsider the current character even so it interrupted the sequence
289
- // it could be the beginning of a new sequence
290
- i--;
291
- }
292
- break;
293
- case S.END:
294
- break;
295
- default:
296
- throw new Error(`Unexpected state entered: ${state}`);
297
- }
298
- }
299
- dataCallback('onHeaderField');
300
- dataCallback('onHeaderValue');
301
- dataCallback('onPartData');
302
-
303
- // Update properties for the next call
304
- this.index = index;
305
- this.state = state;
306
- this.flags = flags;
307
- }
308
- end() {
309
- if (this.state === S.HEADER_FIELD_START && this.index === 0 || this.state === S.PART_DATA && this.index === this.boundary.length) {
310
- this.onPartEnd();
311
- } else if (this.state !== S.END) {
312
- throw new Error('MultipartParser.end(): stream ended unexpectedly');
313
- }
314
- }
315
- }
316
- function _fileName(headerValue) {
317
- // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
318
- const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
319
- if (!m) {
320
- return;
321
- }
322
- const match = m[2] || m[3] || '';
323
- let filename = match.slice(match.lastIndexOf('\\') + 1);
324
- filename = filename.replace(/%22/g, '"');
325
- filename = filename.replace(/&#(\d{4});/g, (m, code) => {
326
- return String.fromCharCode(code);
327
- });
328
- return filename;
329
- }
330
- async function toFormData(Body, ct) {
331
- if (!/multipart/i.test(ct)) {
332
- throw new TypeError('Failed to fetch');
333
- }
334
- const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
335
- if (!m) {
336
- throw new TypeError('no or bad content-type header, no multipart boundary');
337
- }
338
- const parser = new MultipartParser(m[1] || m[2]);
339
- let headerField;
340
- let headerValue;
341
- let entryValue;
342
- let entryName;
343
- let contentType;
344
- let filename;
345
- const entryChunks = [];
346
- const formData = new index.FormData();
347
- const onPartData = ui8a => {
348
- entryValue += decoder.decode(ui8a, {
349
- stream: true
350
- });
351
- };
352
- const appendToFile = ui8a => {
353
- entryChunks.push(ui8a);
354
- };
355
- const appendFileToFormData = () => {
356
- const file = new index.File(entryChunks, filename, {
357
- type: contentType
358
- });
359
- formData.append(entryName, file);
360
- };
361
- const appendEntryToFormData = () => {
362
- formData.append(entryName, entryValue);
363
- };
364
- const decoder = new TextDecoder('utf-8');
365
- decoder.decode();
366
- parser.onPartBegin = function () {
367
- parser.onPartData = onPartData;
368
- parser.onPartEnd = appendEntryToFormData;
369
- headerField = '';
370
- headerValue = '';
371
- entryValue = '';
372
- entryName = '';
373
- contentType = '';
374
- filename = null;
375
- entryChunks.length = 0;
376
- };
377
- parser.onHeaderField = function (ui8a) {
378
- headerField += decoder.decode(ui8a, {
379
- stream: true
380
- });
381
- };
382
- parser.onHeaderValue = function (ui8a) {
383
- headerValue += decoder.decode(ui8a, {
384
- stream: true
385
- });
386
- };
387
- parser.onHeaderEnd = function () {
388
- headerValue += decoder.decode();
389
- headerField = headerField.toLowerCase();
390
- if (headerField === 'content-disposition') {
391
- // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
392
- const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
393
- if (m) {
394
- entryName = m[2] || m[3] || '';
395
- }
396
- filename = _fileName(headerValue);
397
- if (filename) {
398
- parser.onPartData = appendToFile;
399
- parser.onPartEnd = appendFileToFormData;
400
- }
401
- } else if (headerField === 'content-type') {
402
- contentType = headerValue;
403
- }
404
- headerValue = '';
405
- headerField = '';
406
- };
407
- for await (const chunk of Body) {
408
- parser.write(chunk);
409
- }
410
- parser.end();
411
- return formData;
412
- }
413
-
414
- exports.toFormData = toFormData;
package/src/public.d.ts DELETED
@@ -1,209 +0,0 @@
1
- /**
2
- * Represents the configuration provided in src/index.{js | ts} in a project
3
- */
4
- export interface Scout9ProjectConfig {
5
- llm: {
6
- engine: 'openai',
7
- model: (string & {})
8
- | 'gpt-4-1106-preview'
9
- | 'gpt-4-vision-preview'
10
- | 'gpt-4'
11
- | 'gpt-4-0314'
12
- | 'gpt-4-0613'
13
- | 'gpt-4-32k'
14
- | 'gpt-4-32k-0314'
15
- | 'gpt-4-32k-0613'
16
- | 'gpt-3.5-turbo'
17
- | 'gpt-3.5-turbo-16k'
18
- | 'gpt-3.5-turbo-0301'
19
- | 'gpt-3.5-turbo-0613'
20
- | 'gpt-3.5-turbo-16k-0613';
21
- } | {
22
- engine: 'llama',
23
- model: string;
24
- } | {
25
- engine: 'bard',
26
- model: string;
27
- },
28
- /**
29
- * Configure personal model transformer (PMT) settings to align auto replies the agent's tone
30
- */
31
- pmt: {
32
- engine: 'scout9',
33
- model: 'orin-1.0' | 'orin-2.0-preview'
34
- }
35
- }
36
-
37
- export interface IEntityBuildConfig {
38
- definitions?: {
39
- utterance?: string;
40
- value: string;
41
- text: string[];
42
- }[],
43
- training?: {
44
- text: string, intent: string;
45
- }[];
46
- tests?: {
47
- text: string;
48
- expected: {
49
- intent: string;
50
- context: any;
51
- }
52
- }[];
53
- }
54
-
55
- /**
56
- * Including the provided project config, this is the manifest for all entities and workflows to be managed in build
57
- */
58
- export interface Scout9ProjectBuildConfig extends Scout9ProjectConfig {
59
- agents: Agent[];
60
- entities: ({
61
- entities: string[];
62
- entity: string;
63
- id: string;} & IEntityBuildConfig)[];
64
- workflows: {
65
- entities: string[];
66
- entity: string;
67
- }
68
- }
69
-
70
-
71
- export interface DeployOptions {
72
- cwd?: string;
73
- }
74
-
75
- export interface BuildOptions {
76
- cwd?: string;
77
- mode?: 'development' | 'production';
78
- }
79
-
80
- export interface RunOptions {
81
- cwd?: string;
82
- mode?: 'remote' | 'local';
83
- }
84
-
85
- export interface Conversation {
86
- $agent: string;
87
- $customer: string;
88
- initialContexts?: string[];
89
- environment: 'phone' | 'email' | 'web';
90
- environmentProps?: {
91
- subject?: string;
92
- platformEmailThreadId?: string;
93
- };
94
- }
95
-
96
- export interface Message {
97
- role: 'customer' | 'agent' | 'system';
98
- content: string;
99
- name?: string;
100
- time: string;
101
- }
102
-
103
- export interface Customer {
104
- id: string;
105
- name: string;
106
- firstName?: string;
107
- lastName?: string;
108
- email?: string;
109
- phone?: string;
110
- img?: string;
111
- neighborhood?: string;
112
- city?: string;
113
- country?: string;
114
- line1?: string;
115
- line2?: string;
116
- postal_code?: string;
117
- state?: string;
118
- town?: string;
119
- [key: string]: any;
120
- }
121
-
122
- export interface Agent {
123
- id: string;
124
- firstName?: string;
125
- lastName?: string;
126
- inactive?: boolean;
127
- programmablePhoneNumber?: string;
128
- programmablePhoneNumberSid?: string;
129
- programmableEmail?: string;
130
- forwardEmail?: string;
131
- forwardPhone?: string;
132
- title?: string;
133
- context?: string;
134
- includedLocations?: string[];
135
- excludedLocations?: string[];
136
- model?: 'Scout9' | 'bard' | 'openai';
137
- transcripts?: Message[][];
138
- audioRef?: any[];
139
- }
140
-
141
- export interface WorkflowEvent {
142
- messages: Message[];
143
- conversation: Conversation;
144
- context: any;
145
- message: Message;
146
- agent: Omit<Agent, 'transcripts' | 'audioRef' | 'includedLocations' | 'excludedLocations' | 'model' | 'context'>;
147
- customer: Customer;
148
- intent: string;
149
- stagnationCount: number;
150
- }
151
-
152
- export interface Instruction {
153
- id: string;
154
- content: string;
155
- }
156
-
157
- export interface WorkflowResponseSlot<Type = any> {
158
- forward?: string | boolean | {
159
- to?: string;
160
- mode?: 'after-reply' | 'immediately';
161
- };
162
- instructions?: string | string[] | Instruction | Instruction[];
163
- removeInstructions?: string[];
164
- message?: string;
165
- secondsDelay?: number;
166
- scheduled?: number;
167
- contextUpsert?: Partial<Type>;
168
- resetIntent?: boolean;
169
- }
170
-
171
- export type WorkflowResponse<Type> = WorkflowResponseSlot<Type> | WorkflowResponseSlot<Type>[];
172
-
173
- export declare function json<Type = any>(data: Type, init?: ResponseInit): Promise<EventResponse<Type>>;
174
- export declare function run<Type = any>(event: WorkflowEvent, options?: RunOptions): Promise<WorkflowResponse<Type>>;
175
- export declare function sendEvent<Type = any>(event: WorkflowEvent, options?: RunOptions): Promise<WorkflowResponse<Type>>;
176
- export declare function build(options?: BuildOptions): Promise<Scout9ProjectBuildConfig>;
177
- export declare function deploy(options?: DeployOptions): Promise<Scout9ProjectBuildConfig>;
178
-
179
- export class EventResponse<Type = any> {
180
- /**
181
- * Static method to create an EventResponse object.
182
- * @param body The body of the response, expected to be an object.
183
- * @param options Additional options for the response.
184
- */
185
- static json<Type = any>(body: object, options?: ResponseInit): EventResponse<Type>;
186
-
187
- /**
188
- * The body of the response.
189
- */
190
- body: object;
191
-
192
- /**
193
- * Initialization options for the response.
194
- */
195
- init?: ResponseInit;
196
-
197
- /**
198
- * Creates an instance of EventResponse.
199
- * @param body The body of the response, expected to be an object.
200
- * @param init Initialization options for the response.
201
- */
202
- constructor(body: Type, init?: ResponseInit);
203
-
204
- /**
205
- * Returns a Response object with JSON body.
206
- */
207
- readonly response: Response;
208
- }
209
-