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

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 +32 -0
  2. package/dist/{index-92deaa5f.cjs → exports-e7d51b70.cjs} +46618 -4591
  3. package/dist/index.cjs +58 -15
  4. package/dist/{multipart-parser-090f08a9.cjs → multipart-parser-e09a67c9.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 +30 -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 +131 -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 +158 -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
package/src/report.js ADDED
@@ -0,0 +1,117 @@
1
+ import { red, cyan, green, dim, white, grey, bold, italic, magenta, yellow } from 'kleur/colors';
2
+ import { ProgressLogger } from './utils/index.js';
3
+
4
+ /**
5
+ *
6
+ * @param {import('zod').ZodError} zodError
7
+ * @param {string} source
8
+ */
9
+ export function logUserValidationError(
10
+ zodError,
11
+ source,
12
+ ) {
13
+ const issues = zodError.issues || [];
14
+
15
+ console.log(red(`Scout9 Schema Validation Error at ${bold(source)}, fix these issues and rerun`));
16
+ for (const {code, expected, received, path, message} of issues) {
17
+ const pathStr = path.join('.');
18
+ let text = '';
19
+ const objectPath = red(`${italic('.' + pathStr)}`) + grey(':');
20
+ switch (code) {
21
+ case 'invalid_type':
22
+ text = `Expected type ${cyan(expected)} but received ${yellow(received)}.`;
23
+ break;
24
+ case 'invalid_enum':
25
+ text = `Expected one of ${expected.map(e => cyan(e)).join(', ')} but received ${yellow(received)}.`;
26
+ break;
27
+ default:
28
+ text = yellow(`(${code}) ${message} .${pathStr}`);
29
+ }
30
+ console.log('\t', objectPath, grey(`${text}`));
31
+ }
32
+ }
33
+
34
+
35
+ /**
36
+ * @param {Scout9ProjectBuildConfig} config
37
+ * @param {ProgressLogger} logger
38
+ */
39
+ export function report(config, logger) {
40
+ logger.primary(`${white('Scout9 App For:')} ${cyan(config.organization.name)} ${magenta(config.tag)}`);
41
+ if (config.organization?.dashboard) {
42
+ logger.info(`Dashboard: ${cyan(config.organization.dashboard)}`);
43
+ }
44
+ logger.info(`LLM Engine: ${cyan(config.llm.engine)} ${magenta(config.llm.model)}`);
45
+ logger.info(`PMT Engine: ${cyan(config.pmt.engine)} ${magenta(config.pmt.model)}`);
46
+ logger.info(`Max Lock Attempts: ${cyan(config?.maxLockAttempts || 3)}`);
47
+ logger.info(`Initial Context:\n\t\t${(config?.initialContext || []).map(i => `${white('-')} ${magenta('"')}${italic(i)}${magenta('"')}`).join('\n\t\t')}`);
48
+ // logger.primary(`${config.agents.length} Persona${config.agents.length > 1 ? 's' : ''}\n\n`);
49
+ for (const agent of config.agents) {
50
+ logger.primary(`${grey('Persona: ')}${agent.firstName}${agent.lastName ? ' ' + agent.lastName : ''}`);
51
+ logger.info(`Context: ${magenta('"')}${italic(agent.context)}${magenta('"')}`);
52
+ let phone = agent.deployed?.phone || agent?.programmablePhoneNumber || '';
53
+ phone = phone ? cyan(phone) : '';
54
+ const phoneForward = agent.forwardPhone ? magenta(agent.forwardPhone) : red('Not Configured');
55
+
56
+ const web = agent?.deployed?.web ? cyan(agent.deployed.web) : red('Not Configured');
57
+ let email = agent.deployed?.email || agent?.programmableEmail || '';
58
+ email = email ? cyan(email) : red('None Configured');
59
+ const emailForward = agent.forwardEmail ? magenta(agent.forwardEmail) : red('Not Configured');
60
+ logger.info(`Web: ${web}`);
61
+ if (phone) {
62
+ logger.info(`Phone: ${phone} --> ${italic('forwards to')} ${dim(phoneForward)}`);
63
+ }
64
+ if (email) {
65
+ logger.info(`Email: ${email} --> ${italic('forwards to')} ${emailForward}`);
66
+ }
67
+ }
68
+ // logger.primary(`\n\n${config.entities.length} ${config.entities.length > 1 ? 'Entities' : 'Entity'}\n\n`);
69
+
70
+ for (const entityConfig of config.entities) {
71
+ const {entity, api, entities, training, tests, definitions} = entityConfig;
72
+ const parents = entities.slice(0, -1).join('/')
73
+ logger.primary(`${grey('Entity: ')}${parents}/${magenta(entity)}`);
74
+ if (definitions && definitions.length > 0) {
75
+ logger.info(`${cyan(definitions.length)} definition${definitions.length > 1 ? 's' : ''}`);
76
+ }
77
+ if (training && training.length > 0) {
78
+ logger.info(`${cyan(training.length)} training phrase${training.length > 1 ? 's' : ''}`);
79
+ }
80
+ if (tests && tests.length > 0) {
81
+ logger.info(`${cyan(tests.length)} test${tests.length > 1 ? 's' : ''}`);
82
+ }
83
+ if (!api) {
84
+ logger.info(`${cyan('0')} api's exported`);
85
+ }
86
+ if (api?.QUERY) {
87
+ logger.info(`${cyan('QUERY')}: ${api.QUERY ? green('on') : red('off')}`);
88
+ }
89
+ if (api?.GET) {
90
+ logger.info(`${cyan('GET')}: ${api.GET ? green('on') : red('off')}`);
91
+ }
92
+ if (api?.POST) {
93
+ logger.info(`${cyan('POST')}: ${api.POST ? green('on') : red('off')}`);
94
+ }
95
+ if (api?.PUT) {
96
+ logger.info(`${cyan('PUT')}: ${api.PUT ? green('on') : red('off')}`);
97
+ }
98
+ if (api?.PATCH) {
99
+ logger.info(`${cyan('PATCH')}: ${api.PATCH ? green('on') : red('off')}`);
100
+ }
101
+ if (api?.DELETE) {
102
+ logger.info(`${cyan('DELETE')}: ${api.DELETE ? green('on') : red('off')}`);
103
+ }
104
+ }
105
+
106
+ for (const workflowConfig of config.workflows) {
107
+ const {entity, api, entities } = workflowConfig;
108
+ const parents = entities.slice(0, -1).join('/')
109
+ logger.primary(`${grey('Workflow: ')}${parents}/${magenta(entity)}`);
110
+ if (!api) {
111
+ logger.info(`${cyan('0')} api's exported`);
112
+ }
113
+ }
114
+
115
+ logger.primary(`Run ${cyan('scout9 dev')} to test your project locally`);
116
+
117
+ }
@@ -1,183 +1,80 @@
1
-
2
- // export type Scout9Response =
3
- // export type RequestHandler<
4
- // RequestBody = unknown,
5
- // ResponseBody = Record<string | number, any> | Record<string | number, any>[],
6
- // Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
7
- // RouteId extends string | null = string | null,
8
- // SearchParams extends Partial<Record<string, string | string[]>> = Partial<Record<string, string>>
9
- // > = (event: EventRequest<RequestBody, Params, RouteId, SearchParams>) => MaybePromise<EventResponse<ResponseBody>>;
10
- //
11
- // /**
12
- // * For QUERY entity api calls, this is used for getting multiple entities
13
- // */
14
- // export type QueryRequestHandler<
15
- // ResponseBody = Record<string | number, any>,
16
- // Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
17
- // RouteId extends string | null = string | null,
18
- // > = RequestHandler<unknown, ResponseBody[], Params, RouteId, {q?: string, page?: string, limit?: string, orderBy?: string, endAt?: string, startAt?: string}>;
19
- //
20
- // /**
21
- // * For GET entity api calls, this is used for getting one entity
22
- // */
23
- // export type GetRequestHandler<
24
- // ResponseBody = Record<string | number, any>,
25
- // Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
26
- // RouteId extends string | null = string | null,
27
- // > = RequestHandler<unknown, ResponseBody, Params, RouteId>;
28
- //
29
- // /**
30
- // * For POST entity api calls, this is used for creating an entity
31
- // */
32
- // export type PostRequestHandler<
33
- // RequestBody = Record<string | number, any>,
34
- // Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
35
- // RouteId extends string | null = string | null
36
- // > = RequestHandler<RequestBody, {success: boolean, id: string, error?: string | object, [key: string]: any}, Params, RouteId>;
37
- //
38
- // export type CreatedRequestHandler<
39
- // RequestBody = Record<string | number, any>,
40
- // Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
41
- // RouteId extends string | null = string | null
42
- // > = PostRequestHandler<RequestBody, Params, RouteId>;
43
- //
44
- //
45
- // /**
46
- // * For PUT entity api calls, this is used for creating an entity
47
- // */
48
- // export type PutRequestHandler<
49
- // RequestBody = Record<string | number, any>,
50
- // Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
51
- // RouteId extends string | null = string | null
52
- // > = RequestHandler<Partial<RequestBody>, {success: boolean, error?: string | object, [key: string]: any}, Params, RouteId>;
53
- //
54
- //
55
- // /**
56
- // * For PUT entity api calls, this is used for creating an entity
57
- // */
58
- // export type PatchRequestHandler<
59
- // RequestBody = Record<string | number, any>,
60
- // Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
61
- // RouteId extends string | null = string | null
62
- // > = PutRequestHandler<RequestBody, Params, RouteId>;
63
- //
64
- // /**
65
- // * For PUT entity api calls, this is used for creating an entity
66
- // */
67
- // export type UpdateRequestHandler<
68
- // RequestBody = Record<string | number, any>,
69
- // Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
70
- // RouteId extends string | null = string | null
71
- // > = PutRequestHandler<RequestBody, Params, RouteId>;
72
- //
73
- // /**
74
- // * For PUT entity api calls, this is used for creating an entity
75
- // */
76
- // export type DeleteRequestHandler<
77
- // Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
78
- // RouteId extends string | null = string | null
79
- // > = RequestHandler<unknown, {success: boolean, error?: string | object, [key: string]: any}, Params, RouteId>;
80
- //
81
- //
82
- // export interface EventRequest<
83
- // Body = unknown,
84
- // Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
85
- // RouteId extends string | null = string | null,
86
- // SearchParams extends Partial<Record<string, string | string[]>> = Partial<Record<string, string>>,
87
- // > {
88
- //
89
- // /**
90
- // * `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
91
- // *
92
- // * - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
93
- // * - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
94
- // * - Internal requests (e.g. for `+server.js` routes) go directly to the handler function when running on the server, without the overhead of an HTTP call.
95
- // * - During server-side rendering, the response will be captured and inlined into the rendered HTML by hooking into the `text` and `json` methods of the `Response` object. Note that headers will _not_ be serialized, unless explicitly included
96
- // * - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
97
- // *
98
- // */
99
- // fetch: typeof fetch;
100
- //
101
- // /**
102
- // * The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
103
- // */
104
- // params: Params;
105
- //
106
- // /**
107
- // * The requested URL.
108
- // */
109
- // url: URL;
110
- //
111
- // /**
112
- // * The anticipated searchParams inside `const { searchParams } = new URL(req.url)`
113
- // */
114
- // searchParams: SearchParams;
115
- //
116
- // /**
117
- // * The anticipated parsed body inside `request.body`
118
- // */
119
- // body: Body;
120
- //
121
- // /**
122
- // * The original request object
123
- // */
124
- // request: Request;
125
- //
126
- // /**
127
- // * If you need to set headers for the response, you can do so using the this method. This is useful if you want the page to be cached, for example:
128
- // *
129
- // * ```js
130
- // * /// file: src/routes/blog/+page.js
131
- // * export async function load({ fetch, setHeaders }) {
132
- // * const url = `https://cms.example.com/articles.json`;
133
- // * const response = await fetch(url);
134
- // *
135
- // * setHeaders({
136
- // * age: response.headers.get('age'),
137
- // * 'cache-control': response.headers.get('cache-control')
138
- // * });
139
- // *
140
- // * return response.json();
141
- // * }
142
- // * ```
143
- // *
144
- // * Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
145
- // *
146
- // * You cannot add a `set-cookie` header with `setHeaders` API instead.
147
- // */
148
- // setHeaders(headers: Record<string, string>): void;
149
- //
150
- // /**
151
- // * Info about the current route
152
- // */
153
- // route: {
154
- // /**
155
- // * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
156
- // */
157
- // id: RouteId;
158
- // };
159
- // }
1
+ import { z } from 'zod';
160
2
 
161
3
  /**
162
4
  * Utility runtime class used to guide event output
5
+ * @template T
163
6
  */
164
7
  export class EventResponse {
165
8
 
9
+ /**
10
+ * Create a new EventResponse instance with a JSON body.
11
+ * @template T
12
+ * @param {T} body - The body of the response.
13
+ * @param {ResponseInit} [options] - Additional options for the response.
14
+ * @returns {EventResponse<T>} A new EventResponse instance.
15
+ */
166
16
  static json(body, options) {
167
17
  return new EventResponse(body, options);
168
18
  }
169
19
 
20
+ /**
21
+ * Create an EventResponse.
22
+ * @param {T} body - The body of the response.
23
+ * @param {ResponseInit} [init] - Additional options for the response.
24
+ * @throws {Error} If the body is not a valid object.
25
+ */
170
26
  constructor(body, init) {
27
+ /**
28
+ * @type {T}
29
+ * @private
30
+ */
171
31
  this.body = body;
32
+
33
+ /**
34
+ * @type {ResponseInit}
35
+ * @private
36
+ */
172
37
  this.init = init;
173
38
  if (typeof this.body !== 'object') {
174
39
  throw new Error(`EventResponse body in not a valid object:\n"${JSON.stringify(body, null, 2)}"`);
175
40
  }
176
41
  }
177
42
 
43
+ /**
44
+ * Get the response object.
45
+ * @returns {Response} The response object.
46
+ */
178
47
  get response() {
179
48
  return Response.json(this.body, this.init);
180
49
  }
50
+
51
+ /**
52
+ * Get the data of the response.
53
+ * @returns {T} The body of the response.
54
+ */
55
+ get data() {
56
+ return this.body;
57
+ }
58
+
181
59
  }
182
60
 
183
61
 
62
+
63
+ const responseInitSchema = z.object({
64
+ status: z.number().optional(),
65
+ statusText: z.string().optional(),
66
+ headers: z.any().optional() // Headers can be complex; adjust as needed
67
+ });
68
+
69
+ /**
70
+ * @template T
71
+ * @typedef {object} IEventResponse
72
+ * @property {T} body - The body of the response.
73
+ * @property {ResponseInit} [init] - Additional options for the response.
74
+ * @property {Response} response - The response object.
75
+ * @property {T} data - The body of the response.
76
+ */
77
+ export const eventResponseSchema = z.object({
78
+ body: z.any(), // Adjust as per your actual body structure
79
+ init: responseInitSchema.optional()
80
+ });
@@ -1,9 +1,7 @@
1
- import { Agent } from '@scout9/app';
2
1
  import { z } from 'zod';
3
- import { zId } from './utils.js';
4
- import { agentsConfigurationSchema } from './agent.js';
5
- import { entitiesRootConfigurationSchema, entitiesRootProjectConfigurationSchema } from './entity.js';
6
- import { WorkflowConfigurationSchema } from './workflow.js';
2
+ import { agentsBaseConfigurationSchema } from './users.js';
3
+ import { entitiesRootProjectConfigurationSchema } from './entity.js';
4
+ import { WorkflowsConfigurationSchema } from './workflow.js';
7
5
 
8
6
  const llmModelOptions = z.union([
9
7
  z.literal('gpt-4-1106-preview'),
@@ -42,15 +40,66 @@ const bardSchema = z.object({
42
40
  model: z.string()
43
41
  });
44
42
 
43
+ /**
44
+ * Configure personal model transformer (PMT) settings to align auto replies the agent's tone
45
+ */
45
46
  const pmtSchema = z.object({
46
47
  engine: z.literal('scout9'),
47
- model: pmtModelOptions
48
+ // model: pmtModelOptions
49
+ model: z.string()
50
+ }, {
51
+ description: 'Configure personal model transformer (PMT) settings to align auto replies the agent\'s tone'
48
52
  });
49
53
 
50
- export const Scout9ProjectBuildConfigSchema = z.object({
51
- agents: agentsConfigurationSchema,
52
- entities: entitiesRootProjectConfigurationSchema,
53
- workflows: WorkflowConfigurationSchema,
54
+ /**
55
+ * Represents the configuration provided in src/index.{js | ts} in a project
56
+ * @typedef {import('zod').infer<typeof Scout9ProjectConfigSchema>} IScout9ProjectConfig
57
+ */
58
+ export const Scout9ProjectConfigSchema = z.object({
59
+ /**
60
+ * Tag to reference this application
61
+ * @defaut your local package.json name + version, or scout9-app-v1.0.0
62
+ */
63
+ tag: z.string().optional(), // Defaults to scout9-app-v1.0.0
54
64
  llm: z.union([llmSchema, llamaSchema, bardSchema]),
55
- pmt: pmtSchema
65
+ /**
66
+ * Configure personal model transformer (PMT) settings to align auto replies the agent's tone
67
+ */
68
+ pmt: pmtSchema,
69
+
70
+ /**
71
+ * Determines the max auto replies without further conversation progression (defined by new context data gathered)
72
+ * before the conversation is locked and requires manual intervention
73
+ * @default 3
74
+ */
75
+ maxLockAttempts: z.number({
76
+ description: 'Determines the max auto replies without further conversation progression (defined by new context data gathered), before the conversation is locked and requires manual intervention'
77
+ }).min(0).max(20).default(3).optional(),
78
+
79
+ initialContext: z.array(z.string(), {
80
+ description: 'Configure the initial contexts for every conversation'
81
+ }),
82
+
83
+ organization: z.object({
84
+ name: z.string(),
85
+ description: z.string(),
86
+ dashboard: z.string().optional(),
87
+ logo: z.string().optional(),
88
+ icon: z.string().optional(),
89
+ logos: z.string().optional(),
90
+ website: z.string().optional(),
91
+ email: z.string().email().optional(),
92
+ phone: z.string().optional(),
93
+ }).optional()
94
+ })
95
+
96
+ /**
97
+ * @typedef {import('zod').infer<typeof Scout9ProjectBuildConfigSchema>} IScout9ProjectBuildConfig
98
+ */
99
+ export const Scout9ProjectBuildConfigSchema = Scout9ProjectConfigSchema.extend({
100
+ agents: agentsBaseConfigurationSchema,
101
+ entities: entitiesRootProjectConfigurationSchema,
102
+ workflows: WorkflowsConfigurationSchema
56
103
  });
104
+
105
+
@@ -1,9 +1,11 @@
1
1
  import { z } from 'zod';
2
2
  import { zId } from './utils.js';
3
- import { ConversationContext } from './workflow.js';
4
3
 
5
4
 
6
- export const _entityApiConfigurationSchema = z.object({
5
+ /**
6
+ * @typedef {import('zod').infer<typeof entityApiConfigurationSchema>} IEntityApiConfiguration
7
+ */
8
+ export const entityApiConfigurationSchema = z.object({
7
9
  // path: z.string(),
8
10
  GET: z.boolean().optional(),
9
11
  UPDATE: z.boolean().optional(),
@@ -11,9 +13,7 @@ export const _entityApiConfigurationSchema = z.object({
11
13
  PUT: z.boolean().optional(),
12
14
  PATCH: z.boolean().optional(),
13
15
  DELETE: z.boolean().optional()
14
- })
15
-
16
- export const entityApiConfigurationSchema = _entityApiConfigurationSchema.nullable();
16
+ }).nullable();
17
17
 
18
18
  const entityConfigurationDefinitionSchema = z.object({
19
19
  utterance: zId('Utterance', z.string({description: 'What entity utterance this represents, if not provided, it will default to the entity id'}))
@@ -40,6 +40,9 @@ const _entityConfigurationSchema = z.object({
40
40
  tests: z.array(entityConfigurationTestSchema).optional()
41
41
  }).strict();
42
42
 
43
+ /**
44
+ * @typedef {import('zod').infer<typeof entityConfigurationSchema>} IEntityConfiguration
45
+ */
43
46
  export const entityConfigurationSchema = _entityConfigurationSchema.refine((data) => {
44
47
  // If 'definitions' is provided, then 'training' must also be provided
45
48
  if (data.definitions !== undefined) {
@@ -52,6 +55,9 @@ export const entityConfigurationSchema = _entityConfigurationSchema.refine((data
52
55
  message: "If 'definitions' is provided, then 'training' must also be provided",
53
56
  });
54
57
 
58
+ /**
59
+ * @typedef {import('zod').infer<typeof entitiesRootConfigurationSchema>} IEntitiesRootConfiguration
60
+ */
55
61
  export const entitiesRootConfigurationSchema = z.array(entityConfigurationSchema);
56
62
 
57
63
 
@@ -66,7 +72,10 @@ const entityExtendedProjectConfigurationSchema = z.object({
66
72
  const _entityRootProjectConfigurationSchema = _entityConfigurationSchema.extend(entityExtendedProjectConfigurationSchema.shape);
67
73
  const _entitiesRootProjectConfigurationSchema = z.array(_entityRootProjectConfigurationSchema);
68
74
 
69
- // @TODO why type extend not valid?
75
+ /**
76
+ * @TODO why type extend not valid?
77
+ * @typedef {import('zod').infer<typeof entityRootProjectConfigurationSchema>} IEntityRootProjectConfiguration
78
+ */
70
79
  export const entityRootProjectConfigurationSchema = _entityConfigurationSchema.extend(entityExtendedProjectConfigurationSchema.shape).refine((data) => {
71
80
  // If 'definitions' is provided, then 'training' must also be provided
72
81
  if (data.definitions !== undefined) {
@@ -78,4 +87,8 @@ export const entityRootProjectConfigurationSchema = _entityConfigurationSchema.e
78
87
  // Custom error message
79
88
  message: "If 'definitions' is provided, then 'training' must also be provided",
80
89
  });
90
+
91
+ /**
92
+ * @typedef {import('zod').infer<typeof entitiesRootProjectConfigurationSchema>} IEntitiesRootProjectConfiguration
93
+ */
81
94
  export const entitiesRootProjectConfigurationSchema = z.array(entityRootProjectConfigurationSchema);
@@ -1,6 +1,8 @@
1
+ export * from './users.js';
1
2
  export * from './api.js';
2
- export * from './workflow.js';
3
- export * from './agent.js';
4
- export * from './entity.js';
5
3
  export * from './config.js';
4
+ export * from './entity.js';
5
+ export * from './message.js';
6
+ export * from './workflow.js';
7
+ export * from './platform.js';
6
8
 
@@ -1,8 +1,18 @@
1
1
  import { z } from 'zod';
2
+ import { zId } from './utils.js';
2
3
 
4
+ /**
5
+ * @typedef {import('zod').infer<typeof MessageSchema>} IMessage
6
+ */
3
7
  export const MessageSchema = z.object({
4
- content: z.string(),
8
+ id: zId('Message ID', {description: 'Unique ID for the message'}),
5
9
  role: z.enum(['agent', 'customer', 'system']),
6
- time: z.string(),
7
- name: z.string().optional()
10
+ content: z.string(),
11
+ time: z.string({description: 'Datetime ISO 8601 timestamp'}),
12
+ name: z.string().optional(),
13
+ scheduled: z.string({description: 'Datetime ISO 8601 timestamp'}).optional(),
14
+ context: z.any({description: 'The context generated from the message'}).optional(),
15
+ intent: z.string({description: 'Detected intent'}).optional().nullable(),
16
+ intentScore: z.number({description: 'Confidence score of the assigned intent'}).nullable().optional(),
17
+ delayInSeconds: z.number({description: 'How long to delay the message manually in seconds'}).nullable().optional()
8
18
  });
@@ -0,0 +1,86 @@
1
+ import { z } from 'zod';
2
+ import { eventResponseSchema, EventResponse } from './api.js';
3
+
4
+
5
+ /**
6
+ * @typedef {object} IApiFunctionParams
7
+ * @property {Object.<string, string|string[]>} searchParams
8
+ * @property {Record<string, string>} params
9
+ */
10
+ const apiFunctionParamsSchema = z.object({
11
+ searchParams: z.record(z.union([z.string(), z.array(z.string())])),
12
+ params: z.record(z.string())
13
+ });
14
+
15
+ /**
16
+ * @typedef {IApiFunctionParams & { id: string }} IApiEntityFunctionParams
17
+ */
18
+ const apiEntityFunctionParamsSchema = apiFunctionParamsSchema.extend({
19
+ id: z.string()
20
+ });
21
+
22
+ /**
23
+ * @template Params
24
+ * @template Response
25
+ * @typedef {function(IApiFunctionParams): Promise<EventResponse>} IApiFunction
26
+ */
27
+ export const apiFunctionSchema = z.function()
28
+ .args(apiFunctionParamsSchema)
29
+ .returns(z.promise(eventResponseSchema));
30
+
31
+ /**
32
+ * @template Params
33
+ * @template Response
34
+ * @typedef {IApiFunction<Params, Response>} IQueryApiFunction
35
+ */
36
+ export const queryApiFunctionSchema = apiFunctionSchema;
37
+
38
+ /**
39
+ * @template Params
40
+ * @template Response
41
+ * @typedef {IApiFunction<Params, Response>} GetApiFunction
42
+ */
43
+ export const getApiFunctionSchema = apiFunctionSchema;
44
+
45
+ /**
46
+ * @template Params
47
+ * @template RequestBody
48
+ * @template Response
49
+ * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPostApiFunction
50
+ */
51
+ export const postApiFunctionSchema = (requestBodySchema) => z.function()
52
+ .args(apiFunctionParamsSchema.extend({
53
+ body: requestBodySchema.partial()
54
+ }))
55
+ .returns(z.promise(eventResponseSchema));
56
+
57
+ /**
58
+ * @template Params
59
+ * @template RequestBody
60
+ * @template Response
61
+ * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPutApiFunction
62
+ */
63
+ export const putApiFunctionSchema = (requestBodySchema) => z.function()
64
+ .args(apiFunctionParamsSchema.extend({
65
+ body: requestBodySchema.partial()
66
+ }))
67
+ .returns(z.promise(eventResponseSchema));
68
+
69
+ /**
70
+ * @template Params
71
+ * @template RequestBody
72
+ * @template Response
73
+ * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPatchApiFunction
74
+ */
75
+ export const patchApiFunctionSchema = (requestBodySchema) => z.function()
76
+ .args(apiFunctionParamsSchema.extend({
77
+ body: requestBodySchema.partial()
78
+ }))
79
+ .returns(z.promise(eventResponseSchema));
80
+
81
+ /**
82
+ * @template Params
83
+ * @template Response
84
+ * @typedef {IApiFunction<Params, Response>} IDeleteApiFunction
85
+ */
86
+ export const deleteApiFunctionSchema = apiFunctionSchema;