@scout9/app 1.0.0-alpha.0.6.8 → 1.0.0-alpha.0.7.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/src/public.d.ts CHANGED
@@ -732,6 +732,14 @@ export type DirectMessage = Partial<Omit<Message, 'id' | 'entities' | 'time' | '
732
732
  * Workflow Response Slot, can use for both PMT workflow event and event macro runtimes
733
733
  */
734
734
  export type WorkflowResponseSlotBase = {
735
+ /** Context to upsert to the conversation */
736
+ contextUpsert?: {
737
+ [x: string]: any;
738
+ } | undefined;
739
+
740
+ /** Information to follow up to the client */
741
+ followup?: Followup | undefined;
742
+
735
743
  /** Forward input information of a conversation */
736
744
  forward?: Forward | undefined;
737
745
 
@@ -741,11 +749,14 @@ export type WorkflowResponseSlotBase = {
741
749
  /** Instructions to send to the PMT on how to steer the conversation */
742
750
  instructions?: Instruction[] | undefined;
743
751
 
752
+ /** If provided, sends a direct message to the user */
753
+ message?: string | DirectMessage | undefined;
754
+
744
755
  /** Remove instructions from memory (requires set instructions to have ids) */
745
756
  removeInstructions?: string[] | undefined;
746
757
 
747
- /** If provided, sends a direct message to the user */
748
- message?: string | DirectMessage | undefined;
758
+ /** If true, resets the conversations intent value to undefined or to its initial value */
759
+ resetIntent?: boolean | undefined;
749
760
 
750
761
  /** Delays in seconds of instructions (if provided) to PMT and direct message (if provided) to user */
751
762
  secondsDelay?: number | undefined;
@@ -753,16 +764,6 @@ export type WorkflowResponseSlotBase = {
753
764
  /** unix time of when to send instructions or message */
754
765
  scheduled?: number | undefined;
755
766
 
756
- /** Context to upsert to the conversation */
757
- contextUpsert?: {
758
- [x: string]: any;
759
- } | undefined;
760
-
761
- /** If true, resets the conversations intent value to undefined or to its initial value */
762
- resetIntent?: boolean | undefined;
763
-
764
- /** Information to follow up to the client */
765
- followup?: Followup | undefined;
766
767
  };
767
768
 
768
769
  /**
@@ -781,6 +782,12 @@ export type WorkflowResponseSlot = WorkflowResponseSlotBase & {
781
782
  * @ingress auto/manual only
782
783
  */
783
784
  entityContextUpsert?: Array<EntityContextUpsert> | undefined;
785
+
786
+ /**
787
+ * If provided, it will send the user's workflow tasks to the PMT to execute custom business logic
788
+ * @ingress auto/manual only
789
+ */
790
+ tasks?: string[] | undefined;
784
791
  };
785
792
 
786
793
  /**
@@ -4,7 +4,7 @@ import { z } from 'zod';
4
4
  import { zId } from './utils.js';
5
5
  import { AgentConfigurationSchema, CustomerSchema } from './users.js';
6
6
  import { MessageSchema } from './message.js';
7
- import { ConversationSchema, ConversationContext } from './conversation.js';
7
+ import { ConversationContext, ConversationSchema } from './conversation.js';
8
8
 
9
9
 
10
10
  export const ForwardSchema = z.union([
@@ -89,7 +89,8 @@ export const InstructionSchema = z.union([
89
89
  export const FollowupBaseSchema = z.object({
90
90
  scheduled: z.number(),
91
91
  cancelIf: ConversationContext.optional(),
92
- overrideLock: z.boolean({description: 'This will still run even if the conversation is locked, defaults to false'}).optional()
92
+ overrideLock: z.boolean({description: 'This will still run even if the conversation is locked, defaults to false'})
93
+ .optional()
93
94
  });
94
95
 
95
96
  /**
@@ -97,7 +98,7 @@ export const FollowupBaseSchema = z.object({
97
98
  */
98
99
  export const FollowupSchema = z.union([
99
100
  FollowupBaseSchema.extend({
100
- message: z.string({description: 'Manual message sent to client'}),
101
+ message: z.string({description: 'Manual message sent to client'})
101
102
  }),
102
103
  FollowupBaseSchema.extend({
103
104
  instructions: InstructionSchema
@@ -143,23 +144,23 @@ export const WorkflowEventSchema = z.object({
143
144
  note: z.string({description: 'Any developer notes to provide'}).optional()
144
145
  });
145
146
 
146
- export const DirectMessageSchema = MessageSchema.partial().omit({id: true, entities: true, time: true, role: true})
147
+ export const DirectMessageSchema = MessageSchema.partial().omit({id: true, entities: true, time: true, role: true});
147
148
 
148
149
  /**
149
150
  * The workflow response object slot
150
151
  */
151
152
  export const WorkflowResponseSlotBaseSchema = z.object({
153
+ contextUpsert: ConversationContext.optional(),
154
+ followup: FollowupSchema.optional(),
152
155
  forward: ForwardSchema.optional(),
153
156
  forwardNote: z.string({description: 'Note to provide to the agent, recommend using forward object api instead'})
154
157
  .optional(),
155
158
  instructions: InstructionSchema.optional(),
156
- removeInstructions: z.array(z.string()).optional(),
157
159
  message: z.union([z.string(), DirectMessageSchema]).optional(),
158
- secondsDelay: z.number().optional(),
159
- scheduled: z.number().optional(),
160
- contextUpsert: ConversationContext.optional(),
160
+ removeInstructions: z.array(z.string()).optional(),
161
161
  resetIntent: z.boolean().optional(),
162
- followup: FollowupSchema.optional()
162
+ secondsDelay: z.number().optional(),
163
+ scheduled: z.number().optional()
163
164
  });
164
165
 
165
166
 
@@ -205,7 +206,10 @@ export const WorkflowResponseSlotSchema = WorkflowResponseSlotBaseSchema.extend(
205
206
  }))
206
207
  ]).optional(),
207
208
 
208
- entityContextUpsert: z.array(EntityContextUpsertSchema).optional()
209
+ entityContextUpsert: z.array(EntityContextUpsertSchema).optional(),
210
+
211
+ tasks: z.array(z.string({description: '@ingress=auto/manual only, If provided, it will send the user\'s workflow tasks to the PMT to execute custom business logic'}))
212
+ .optional()
209
213
  });
210
214
 
211
215
  /**
@@ -46,14 +46,6 @@
46
46
  * @property {any} context
47
47
  */
48
48
 
49
- /**
50
- * @typedef {Object} GenerateOutput
51
- * @property {import('@scout9/admin').GenerateResponse | undefined} generate
52
- * @property {Array<import('@scout9/app').Message>} messages
53
- * @property {import('@scout9/app').Conversation} conversation
54
- * @property {any} context
55
- */
56
-
57
49
  /**
58
50
  * @callback ParseFun
59
51
  * @param {string} message - message to send
@@ -69,7 +61,7 @@
69
61
 
70
62
  /**
71
63
  * @callback GenerateFun
72
- * @param {import('@scout9/admin').GenerateRequestOneOf} data - data to generate from
64
+ * @param {import('@scout9/admin').GenerateRequestOneOf1} data - data to generate from
73
65
  * @returns {Promise<import('@scout9/admin').GenerateResponse>}
74
66
  */
75
67
 
@@ -393,6 +385,9 @@ export const Spirits = {
393
385
  let _forward;
394
386
  let _forwardNote;
395
387
 
388
+ /** @type {Array<string> | undefined} */
389
+ let _tasks;
390
+
396
391
  for (const {
397
392
  forward,
398
393
  forwardNote,
@@ -405,7 +400,8 @@ export const Spirits = {
405
400
  contextUpsert,
406
401
  anticipate,
407
402
  followup: slotFollowup,
408
- entityContextUpsert: slotEntityContextUpsert
403
+ entityContextUpsert: slotEntityContextUpsert,
404
+ tasks
409
405
  } of slots) {
410
406
 
411
407
  // Anticipate customer response
@@ -443,6 +439,12 @@ export const Spirits = {
443
439
  }
444
440
  }
445
441
 
442
+ // tasks from auto/manual ingress to execute
443
+ if (!!tasks && Array.isArray(tasks) && !!tasks.length) {
444
+ if (!_tasks) _tasks = [];
445
+ _tasks.push(...tasks);
446
+ }
447
+
446
448
  if (slotFollowup) {
447
449
  followup.push(slotFollowup);
448
450
  }
@@ -589,13 +591,17 @@ export const Spirits = {
589
591
  if ((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage) {
590
592
  try {
591
593
  progress('Generating message', 'info', 'SET_PROCESSING', 'system');
592
- const generatorPayload = await generator({
594
+ const generatorInput = {
593
595
  messages,
594
596
  persona,
595
597
  context,
596
598
  llm: config.llm,
597
599
  pmt: config.pmt
598
- });
600
+ }
601
+ if (!!_tasks && Array.isArray(_tasks) && !!_tasks.length) {
602
+ generatorInput.tasks = _tasks;
603
+ }
604
+ const generatorPayload = await generator(generatorInput);
599
605
  if (!generatorPayload.send) {
600
606
  progress('Generated response', 'failed', undefined, {error: generatorPayload.error || 'Unknown Reason'});
601
607
  console.error(