@scout9/app 1.0.0-alpha.0.1.86 → 1.0.0-alpha.0.1.88

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.
@@ -2,11 +2,14 @@
2
2
 
3
3
  import { z } from 'zod';
4
4
  import { zId } from './utils.js';
5
- import { agentConfigurationSchema, customerSchema } from './agent.js';
5
+ import { agentConfigurationSchema, customerSchema } from './users.js';
6
6
  import { MessageSchema } from './message.js';
7
7
 
8
8
 
9
9
 
10
+ /**
11
+ * @typedef {import('zod').infer<typeof WorkflowConfigurationSchema>} IWorkflowConfiguration
12
+ */
10
13
  export const WorkflowConfigurationSchema = z.object({
11
14
  entities: z.array(zId('Workflow Folder', z.string()), {description: 'Workflow id association, used to handle route params'})
12
15
  .min(1, 'Must have at least 1 entity')
@@ -14,8 +17,15 @@ export const WorkflowConfigurationSchema = z.object({
14
17
  entity: zId('Workflow Folder', z.string()),
15
18
  });
16
19
 
20
+ /**
21
+ * @typedef {import('zod').infer<typeof WorkflowsConfigurationSchema>} IWorkflowsConfiguration
22
+ */
17
23
  export const WorkflowsConfigurationSchema = z.array(WorkflowConfigurationSchema);
18
24
 
25
+
26
+ /**
27
+ * @typedef {import('zod').infer<typeof ConversationSchema>} IConversation
28
+ */
19
29
  export const ConversationSchema = z.object({
20
30
  $agent: zId('Conversation Agent ID', z.string({description: 'Default agent assigned to the conversation(s)'})),
21
31
  $customer: zId('Conversation Customer ID', z.string({description: 'Customer this conversation is with'})),
@@ -25,20 +35,41 @@ export const ConversationSchema = z.object({
25
35
  subject: z.string({description: 'HTML Subject of the conversation'}).optional(),
26
36
  platformEmailThreadId: z.string({description: 'Used to sync email messages with the conversation'}).optional(),
27
37
  }).optional(),
38
+ locked: z.boolean({description: 'Whether the conversation is locked or not'}).optional().nullable(),
39
+ lockedReason: z.string({description: 'Why this conversation was locked'}).optional().nullable(),
40
+ lockAttempts: z.number({description: 'Number attempts made until conversation is locked'}).optional().nullable(),
41
+ forwardedTo: z.string({description: 'What personaId/phone/email was forwarded'}).optional().nullable(),
42
+ forwarded: z.string({description: 'Datetime ISO 8601 timestamp when persona was forwarded'}).optional().nullable(),
43
+ forwardNote: z.string().optional().nullable(),
44
+ intent: z.string({description: 'Detected intent of conversation'}).optional().nullable(),
45
+ intentScore: z.number({description: 'Confidence score of the assigned intent'}).optional().nullable(),
28
46
  });
29
47
 
48
+ /**
49
+ * @typedef {import('zod').infer<typeof IntentWorkflowEventSchema>} IIntentWorkflowEvent
50
+ */
30
51
  export const IntentWorkflowEventSchema = z.object({
31
52
  current: z.string().nullable(),
32
53
  flow: z.array(z.string()),
33
54
  initial: z.string().nullable()
34
- })
55
+ });
35
56
 
57
+ /**
58
+ * @typedef {import('zod').infer<typeof WorkflowEventSchema>} IWorkflowEvent
59
+ */
36
60
  export const WorkflowEventSchema = z.object({
37
61
  messages: z.array(MessageSchema),
38
62
  conversation: ConversationSchema,
39
63
  context: z.any(),
40
64
  message: MessageSchema,
41
- agent: agentConfigurationSchema,
65
+ agent: agentConfigurationSchema.omit({
66
+ transcripts: true,
67
+ audios: true,
68
+ includedLocations: true,
69
+ excludedLocations: true,
70
+ model: true,
71
+ context: true
72
+ }),
42
73
  customer: customerSchema,
43
74
  intent: IntentWorkflowEventSchema,
44
75
  stagnationCount: z.number(),
@@ -48,7 +79,10 @@ export const WorkflowEventSchema = z.object({
48
79
  const Primitive = z.union([z.string(), z.number(), z.boolean()]);
49
80
  // Assuming ConversationContext is already defined as a Zod schema
50
81
 
51
- // Lazy is used to handle recursive types.
82
+ /**
83
+ * Lazy is used to handle recursive types.
84
+ * @typedef {import('zod').infer<typeof ConversationContext>} IConversation
85
+ */
52
86
  export const ConversationContext = z.lazy(() =>
53
87
  z.record(
54
88
  Primitive.or(ConversationContext)
@@ -57,15 +91,25 @@ export const ConversationContext = z.lazy(() =>
57
91
 
58
92
  const ContextSchema = z.record(Primitive.or(ConversationContext));
59
93
 
94
+ /**
95
+ * Forward input information of a conversation
96
+ * @typedef {import('zod').infer<typeof ForwardSchema>} IForward
97
+ */
60
98
  export const ForwardSchema = z.union([
61
99
  z.boolean(),
62
100
  z.string(),
63
101
  z.object({
64
102
  to: z.string().optional(),
65
103
  mode: z.enum(['after-reply', 'immediately']).optional(),
104
+ note: z.string({description: 'Note to provide to the agent'}).optional()
66
105
  }),
67
- ]);
106
+ ], {description: 'Forward input information of a conversation'});
107
+
68
108
 
109
+ /**
110
+ * Instruction object schema used to send context to guide conversations
111
+ * @typedef {import('zod').infer<typeof InstructionSchema>} IInstruction
112
+ */
69
113
  export const InstructionSchema = z.object({
70
114
  id: zId('Instruction ID').describe('Unique ID for the instruction, this is used to remove the instruction later'),
71
115
  content: z.string(),
@@ -74,6 +118,7 @@ export const InstructionSchema = z.object({
74
118
  /**
75
119
  * If its a string, it will be sent as a static string.
76
120
  * If it's a object or WorkflowResponseMessageAPI - it will use
121
+ * @typedef {import('zod').infer<typeof WorkflowResponseMessage>} IWorkflowResponseMessage
77
122
  */
78
123
  export const WorkflowResponseMessage = z.union(
79
124
  z.string(),
@@ -84,6 +129,9 @@ export const WorkflowResponseMessage = z.union(
84
129
  WorkflowResponseMessageApiRequest
85
130
  );
86
131
 
132
+ /**
133
+ * @typedef {import('zod').infer<typeof WorkflowResponseMessageApiRequest>} IWorkflowResponseMessageApiRequest
134
+ */
87
135
  export const WorkflowResponseMessageApiRequest = z.object({
88
136
  uri: z.string(),
89
137
  data: z.any().optional(),
@@ -95,6 +143,7 @@ export const WorkflowResponseMessageApiRequest = z.object({
95
143
 
96
144
  /**
97
145
  * The intended response provided by the WorkflowResponseMessageApiRequest
146
+ * @typedef {import('zod').infer<typeof WorkflowResponseMessageApiResponse>} IWorkflowResponseMessageApiResponse
98
147
  */
99
148
  export const WorkflowResponseMessageApiResponse = z.union([
100
149
  z.string(),
@@ -116,8 +165,13 @@ export const WorkflowResponseMessageApiResponse = z.union([
116
165
  })
117
166
  ]);
118
167
 
168
+ /**
169
+ * The workflow response object slot
170
+ * @typedef {import('zod').infer<typeof WorkflowResponseSlotSchema>} IWorkflowResponseSlot
171
+ */
119
172
  export const WorkflowResponseSlotSchema = z.object({
120
173
  forward: ForwardSchema.optional(),
174
+ forwardNote: z.string({description: 'Note to provide to the agent, recommend using forward object api instead'}).optional(),
121
175
  instructions: z.union([z.string(), InstructionSchema, z.array(z.string()), z.array(InstructionSchema)]).optional(),
122
176
  removeInstructions: z.array(z.string()).optional(),
123
177
  message: z.string().optional(),
@@ -128,7 +182,21 @@ export const WorkflowResponseSlotSchema = z.object({
128
182
  resetIntent: z.boolean().optional(),
129
183
  });
130
184
 
185
+ /**
186
+ * The workflow response to send in any given workflow
187
+ * @typedef {import('zod').infer<typeof WorkflowResponseSchema>} IWorkflowResponse
188
+ */
131
189
  export const WorkflowResponseSchema = z.union([
132
190
  WorkflowResponseSlotSchema,
133
191
  z.array(WorkflowResponseSlotSchema)
134
192
  ]);
193
+
194
+ /**
195
+ * @typedef {import('zod').infer<typeof WorkflowFunctionSchema>} IWorkflowFunction
196
+ */
197
+ export const WorkflowFunctionSchema = z.function()
198
+ .args(WorkflowEventSchema)
199
+ .returns(z.union([
200
+ z.promise(WorkflowResponseSchema),
201
+ WorkflowResponseSchema,
202
+ ]));
@@ -15,22 +15,22 @@ import { Spirits } from './spirits.js';
15
15
  export class Scout9Test {
16
16
 
17
17
  /**
18
- * @type {import('@scout9/app').Customer}
18
+ * @type {import('@scout9/app').ICustomer}
19
19
  */
20
20
  customer;
21
21
 
22
22
  /**
23
- * @type {import('@scout9/app').Persona}
23
+ * @type {import('@scout9/app').IPersona}
24
24
  */
25
25
  persona;
26
26
 
27
27
  /**
28
- * @type {import('@scout9/app').Conversation}
28
+ * @type {import('@scout9/app').IConversation}
29
29
  */
30
30
  conversation;
31
31
 
32
32
  /**
33
- * @type {import('@scout9/app').Message[]}
33
+ * @type {import('@scout9/app').IMessage[]}
34
34
  */
35
35
  messages;
36
36
 
@@ -41,13 +41,13 @@ export class Scout9Test {
41
41
 
42
42
  /**
43
43
  * @private
44
- * @type {import('scout9/app').Scout9ProjectBuildConfig | null}
44
+ * @type {import('scout9/app').IScout9ProjectBuildConfig | null}
45
45
  */
46
46
  _project = null;
47
47
 
48
48
  /**
49
49
  * @private
50
- * @type {import('@scout9/app').WorkflowFunction | null}
50
+ * @type {import('@scout9/app').IWorkflowFunction | null}
51
51
  */
52
52
  _app = null;
53
53
 
@@ -86,16 +86,16 @@ export class Scout9Test {
86
86
  /**
87
87
  * Mimics a customer message to your app (useful for testing)
88
88
  * @param props - the Scout9Test properties
89
- * @param {import('@scout9/app').Customer | undefined} [props.customer] - customer to use
89
+ * @param {import('@scout9/app').ICustomer | undefined} [props.customer] - customer to use
90
90
  * @param {any | undefined} [props.context] - prior conversation context
91
91
  * @param {string | undefined} [props.persona] id to use
92
- * @param {import('@scout9/app').Conversation | undefined} [props.conversation] - existing conversation
92
+ * @param {import('@scout9/app').IConversation | undefined} [props.conversation] - existing conversation
93
93
  * @param {string | undefined} [props.cwd]
94
94
  * @param {string | undefined} [props.src]
95
95
  * @param {string | undefined} [props.mode]
96
96
  * @param {import('@scout9/admin').Scout9Api} [props.api]
97
- * @param {import('@scout9/app').WorkflowFunction} [props.app]
98
- * @param {import('scout9/app').Scout9ProjectBuildConfig} [props.project]
97
+ * @param {import('@scout9/app').IWorkflowFunction} [props.app]
98
+ * @param {import('scout9/app').IScout9ProjectBuildConfig} [props.project]
99
99
  */
100
100
  constructor(
101
101
  {
@@ -303,8 +303,8 @@ export class Scout9Test {
303
303
  /**
304
304
  * Runs your local app workflow
305
305
  * @param {string} message - the message to run through the workflow
306
- * @param {Omit<Partial<import('@scout9/app').WorkflowEvent>, 'message'> | undefined} [event] - additional event data
307
- * @returns {Promise<import('@scout9/app').WorkflowResponse>}
306
+ * @param {Omit<Partial<import('@scout9/app').IWorkflowEvent>, 'message'> | undefined} [event] - additional event data
307
+ * @returns {Promise<import('@scout9/app').IWorkflowResponse>}
308
308
  */
309
309
  async workflow(message, event = {}) {
310
310
  if (!this._app) {
@@ -324,7 +324,7 @@ export class Scout9Test {
324
324
  * @param {Object} [input] - Generation input, defaults to test registered data such as existing messages, context, and persona information.
325
325
  * @param {string} [input.personaId] - Persona ID to use, defaults to test registered persona id.
326
326
  * @param {Partial<import('@scout9/admin').ConversationCreateRequest>} [input.conversation] - Conversation overrides, defaults to test registered conversation data.
327
- * @param {import('@scout9/app').Message[]} [input.messages] - Message overrides, defaults to test registered message data.
327
+ * @param {import('@scout9/app').IMessage[]} [input.messages] - Message overrides, defaults to test registered message data.
328
328
  * @param {any} [input.context] - Context overrides, defaults to test registered context data.
329
329
  * @returns {Promise<import('@scout9/admin').GenerateResponse>}
330
330
  */
@@ -1,7 +1,7 @@
1
1
  import moment from 'moment';
2
2
 
3
3
  /**
4
- * @returns {import('@scout9/app').Agent}
4
+ * @returns {import('@scout9/app').IAgent}
5
5
  */
6
6
  export const createMockAgent = (firstName = 'Carmela', lastName = 'Soprano') => {
7
7
  return {
@@ -12,7 +12,7 @@ export const createMockAgent = (firstName = 'Carmela', lastName = 'Soprano') =>
12
12
  }
13
13
 
14
14
  /**
15
- * @returns {import('@scout9/app').Customer}
15
+ * @returns {import('@scout9/app').ICustomer}
16
16
  */
17
17
  export const createMockCustomer = (firstName = 'Tony', lastName = 'Soprano') => {
18
18
  return {
@@ -28,7 +28,7 @@ export const createMockCustomer = (firstName = 'Tony', lastName = 'Soprano') =>
28
28
  * @param content
29
29
  * @param role
30
30
  * @param time
31
- * @returns {import('@scout9/app').Message}
31
+ * @returns {import('@scout9/app').IMessage}
32
32
  */
33
33
  export const createMockMessage = (content, role = 'customer', time = moment().toISOString()) => {
34
34
  return {
@@ -42,7 +42,7 @@ export const createMockMessage = (content, role = 'customer', time = moment().t
42
42
  }
43
43
 
44
44
  /**
45
- * @returns {import('@scout9/app').Conversation}
45
+ * @returns {import('@scout9/app').IConversation}
46
46
  */
47
47
  export const createMockConversation = (environment = 'phone', $agent = 'default', $customer = 'default') => {
48
48
  return {
@@ -54,8 +54,8 @@ export const createMockConversation = (environment = 'phone', $agent = 'default'
54
54
 
55
55
  /**
56
56
  * @param {string} message
57
- * @param {string | import('@scout9/app').WorkflowEvent['intent'] | null} intent
58
- * @returns {import('@scout9/app').WorkflowEvent}
57
+ * @param {string | import('@scout9/app').IWorkflowEvent['intent'] | null} intent
58
+ * @returns {import('@scout9/app').IWorkflowEvent}
59
59
  */
60
60
  export const createMockWorkflowEvent = (
61
61
  message,
@@ -14,35 +14,35 @@
14
14
 
15
15
  /**
16
16
  * @typedef {Object} ConversationData
17
- * @property {import('@scout9/app').Scout9ProjectBuildConfig} config - used to define generation and extract persona metadata
18
- * @property {import('@scout9/app').Conversation} conversation
19
- * @property {Array<import('@scout9/app').Message>} messages
20
- * @property {import('@scout9/app').Message} message - the message sent by the customer (should exist in messages)
21
- * @property {import('@scout9/app').Customer} customer
17
+ * @property {import('@scout9/app').IScout9ProjectBuildConfig} config - used to define generation and extract persona metadata
18
+ * @property {import('@scout9/app').IConversation} conversation
19
+ * @property {Array<import('@scout9/app').IMessage>} messages
20
+ * @property {import('@scout9/app').IMessage} message - the message sent by the customer (should exist in messages)
21
+ * @property {import('@scout9/app').ICustomer} customer
22
22
  * @property {any} context
23
23
  */
24
24
 
25
25
  /**
26
26
  * @typedef {Object} ParseOutput
27
- * @property {Array<import('@scout9/app').Message>} messages
28
- * @property {import('@scout9/app').Conversation} conversation
29
- * @property {import('@scout9/app').Message} message
27
+ * @property {Array<import('@scout9/app').IMessage>} messages
28
+ * @property {import('@scout9/app').IConversation} conversation
29
+ * @property {import('@scout9/app').IMessage} message
30
30
  * @property {any} context
31
31
  */
32
32
 
33
33
  /**
34
34
  * @typedef {Object} WorkflowOutput
35
- * @property {Array<import('@scout9/app').WorkflowResponseSlot>} slots
36
- * @property {Array<import('@scout9/app').Message>} messages
37
- * @property {import('@scout9/app').Conversation} conversation
35
+ * @property {Array<import('@scout9/app').IWorkflowResponseSlot>} slots
36
+ * @property {Array<import('@scout9/app').IMessage>} messages
37
+ * @property {import('@scout9/app').IConversation} conversation
38
38
  * @property {any} context
39
39
  */
40
40
 
41
41
  /**
42
42
  * @typedef {Object} GenerateOutput
43
43
  * @property {import('@scout9/admin').GenerateResponse | undefined} generate
44
- * @property {Array<import('@scout9/app').Message>} messages
45
- * @property {import('@scout9/app').Conversation} conversation
44
+ * @property {Array<import('@scout9/app').IMessage>} messages
45
+ * @property {import('@scout9/app').IConversation} conversation
46
46
  * @property {any} context
47
47
  */
48
48
 
@@ -55,8 +55,8 @@
55
55
 
56
56
  /**
57
57
  * @callback WorkflowFun
58
- * @param {import('@scout9/app').WorkflowEvent} event - conversation data
59
- * @returns {Promise<import('@scout9/app').WorkflowResponse>}
58
+ * @param {import('@scout9/app').IWorkflowEvent} event - conversation data
59
+ * @returns {Promise<import('@scout9/app').IWorkflowResponse>}
60
60
  */
61
61
 
62
62
  /**
@@ -67,7 +67,7 @@
67
67
 
68
68
  /**
69
69
  * @callback IdGeneratorFun
70
- * @param {import('@scout9/app').Message.role} prefix
70
+ * @param {import('@scout9/app').IMessage.role} prefix
71
71
  * @returns {string}
72
72
  */
73
73
  /**
@@ -90,10 +90,10 @@
90
90
 
91
91
  /**
92
92
  * @typedef {Object} ConversationEvent
93
- * @property {Change<import('@scout9/app').Conversation> & {forwardNote?: string; forward?: import('@scout9/app').WorkflowResponseSlot['forward']}} conversation
94
- * @property {Change<Array<import('@scout9/app').Message>>} messages
93
+ * @property {Change<import('@scout9/app').IConversation> & {forwardNote?: string; forward?: import('@scout9/app').WorkflowResponseSlot['forward']}} conversation
94
+ * @property {Change<Array<import('@scout9/app').IMessage>>} messages
95
95
  * @property {Change<Object>} context
96
- * @property {Change<import('@scout9/app').Message>} message
96
+ * @property {Change<import('@scout9/app').IMessage>} message
97
97
  */
98
98
  export const Spirits = {
99
99
 
@@ -7,7 +7,7 @@ function agentsTemplate(agents, exe = 'js') {
7
7
  return `
8
8
  /**
9
9
  * Required core entity type: Agents represents you and your team
10
- * @returns {Array<import('@scout9/app').Agent>}
10
+ * @returns {Array<import('@scout9/app').IAgent>}
11
11
  */
12
12
  export default function Agents() {
13
13
  return ${JSON.stringify(agents, null, 2)};
@@ -19,12 +19,13 @@ export default function Agents() {
19
19
  * @param {Scout9ProjectBuildConfig} config
20
20
  * @param {string} exe - file extension
21
21
  * @returns {string}
22
+ *
22
23
  */
23
24
  function rootTemplate(config, exe = 'js') {
24
25
  return `
25
26
  /**
26
27
  * Configuration for the Scout9 project.
27
- * @type {import('@scout9/app').Scout9ProjectConfig}
28
+ * @type {import('@scout9/app').IScout9ProjectConfig}
28
29
  */
29
30
  export default {
30
31
 
@@ -51,8 +52,8 @@ export default {
51
52
  function appTemplate() {
52
53
  return `
53
54
  /**
54
- * @param {import('@scout9/app').WorkflowEvent} event - every workflow receives an event object
55
- * @returns {Promise<import('@scout9/app').WorkflowResponse>} - every workflow must return a WorkflowResponse
55
+ * @param {import('@scout9/app').IWorkflowEvent} event - every workflow receives an event object
56
+ * @returns {Promise<import('@scout9/app').IWorkflowResponse>} - every workflow must return a WorkflowResponse
56
57
  */
57
58
  export default async function Scout9App(event) {
58
59
  return {