@scout9/app 1.0.0-alpha.0.6.7 → 1.0.0-alpha.0.6.9
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/dist/{dev-197a7adb.cjs → dev-d74b94c8.cjs} +4 -4
- package/dist/{index-1010a60c.cjs → index-ddb54eed.cjs} +7 -7
- package/dist/index.cjs +4 -4
- package/dist/{macros-85a033b9.cjs → macros-22b2e0b8.cjs} +9 -6
- package/dist/{multipart-parser-0d83aaf8.cjs → multipart-parser-8ce4a465.cjs} +4 -4
- package/dist/schemas.cjs +1 -1
- package/dist/{spirits-9719ae4f.cjs → spirits-59475def.cjs} +102 -97
- package/dist/spirits.cjs +1 -1
- package/dist/testing-tools.cjs +3 -3
- package/package.json +1 -1
- package/src/public.d.ts +55 -12
- package/src/runtime/schemas/workflow.js +14 -10
- package/src/testing-tools/spirits.js +23 -13
- package/types/index.d.ts +2299 -2235
- package/types/index.d.ts.map +2 -1
package/src/public.d.ts
CHANGED
|
@@ -560,6 +560,10 @@ export type IntentWorkflowEvent = {
|
|
|
560
560
|
initial: string | null;
|
|
561
561
|
};
|
|
562
562
|
|
|
563
|
+
/**
|
|
564
|
+
* metadata relationship for the <entity-context>/<entity> element in transcripts and instructions
|
|
565
|
+
* @ingress auto/manual
|
|
566
|
+
*/
|
|
563
567
|
export type EntityToken = {
|
|
564
568
|
start: number;
|
|
565
569
|
end: number;
|
|
@@ -568,6 +572,38 @@ export type EntityToken = {
|
|
|
568
572
|
text?: string | null;
|
|
569
573
|
}
|
|
570
574
|
|
|
575
|
+
/**
|
|
576
|
+
* metadata relationship for the <entity-api> element in transcripts and instructions
|
|
577
|
+
* @ingress auto/manual
|
|
578
|
+
*/
|
|
579
|
+
export type EntityApi = {
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* REST URI to hit
|
|
583
|
+
*/
|
|
584
|
+
uri: string;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Method to use to call the api, defaults to "POST"
|
|
588
|
+
*/
|
|
589
|
+
method?: string;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Additional payload to include to the api
|
|
593
|
+
*/
|
|
594
|
+
body?: ConversationContext;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Headers to apply to the call
|
|
598
|
+
*/
|
|
599
|
+
headers?: Record<string, string>;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Separate URI to establish OAuth 2.0/JWT tokens
|
|
603
|
+
*/
|
|
604
|
+
auth?: Omit<EntityApi, 'auth'>;
|
|
605
|
+
}
|
|
606
|
+
|
|
571
607
|
export type Message = {
|
|
572
608
|
/** Unique ID for the message */
|
|
573
609
|
id: string;
|
|
@@ -696,6 +732,14 @@ export type DirectMessage = Partial<Omit<Message, 'id' | 'entities' | 'time' | '
|
|
|
696
732
|
* Workflow Response Slot, can use for both PMT workflow event and event macro runtimes
|
|
697
733
|
*/
|
|
698
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
|
+
|
|
699
743
|
/** Forward input information of a conversation */
|
|
700
744
|
forward?: Forward | undefined;
|
|
701
745
|
|
|
@@ -705,11 +749,14 @@ export type WorkflowResponseSlotBase = {
|
|
|
705
749
|
/** Instructions to send to the PMT on how to steer the conversation */
|
|
706
750
|
instructions?: Instruction[] | undefined;
|
|
707
751
|
|
|
752
|
+
/** If provided, sends a direct message to the user */
|
|
753
|
+
message?: string | DirectMessage | undefined;
|
|
754
|
+
|
|
708
755
|
/** Remove instructions from memory (requires set instructions to have ids) */
|
|
709
756
|
removeInstructions?: string[] | undefined;
|
|
710
757
|
|
|
711
|
-
/** If
|
|
712
|
-
|
|
758
|
+
/** If true, resets the conversations intent value to undefined or to its initial value */
|
|
759
|
+
resetIntent?: boolean | undefined;
|
|
713
760
|
|
|
714
761
|
/** Delays in seconds of instructions (if provided) to PMT and direct message (if provided) to user */
|
|
715
762
|
secondsDelay?: number | undefined;
|
|
@@ -717,16 +764,6 @@ export type WorkflowResponseSlotBase = {
|
|
|
717
764
|
/** unix time of when to send instructions or message */
|
|
718
765
|
scheduled?: number | undefined;
|
|
719
766
|
|
|
720
|
-
/** Context to upsert to the conversation */
|
|
721
|
-
contextUpsert?: {
|
|
722
|
-
[x: string]: any;
|
|
723
|
-
} | undefined;
|
|
724
|
-
|
|
725
|
-
/** If true, resets the conversations intent value to undefined or to its initial value */
|
|
726
|
-
resetIntent?: boolean | undefined;
|
|
727
|
-
|
|
728
|
-
/** Information to follow up to the client */
|
|
729
|
-
followup?: Followup | undefined;
|
|
730
767
|
};
|
|
731
768
|
|
|
732
769
|
/**
|
|
@@ -745,6 +782,12 @@ export type WorkflowResponseSlot = WorkflowResponseSlotBase & {
|
|
|
745
782
|
* @ingress auto/manual only
|
|
746
783
|
*/
|
|
747
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;
|
|
748
791
|
};
|
|
749
792
|
|
|
750
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 {
|
|
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'})
|
|
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
|
-
|
|
159
|
-
scheduled: z.number().optional(),
|
|
160
|
-
contextUpsert: ConversationContext.optional(),
|
|
160
|
+
removeInstructions: z.array(z.string()).optional(),
|
|
161
161
|
resetIntent: z.boolean().optional(),
|
|
162
|
-
|
|
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').
|
|
64
|
+
* @param {import('@scout9/admin').GenerateRequestOneOf1} data - data to generate from
|
|
73
65
|
* @returns {Promise<import('@scout9/admin').GenerateResponse>}
|
|
74
66
|
*/
|
|
75
67
|
|
|
@@ -104,9 +96,13 @@
|
|
|
104
96
|
* @property {StatusCallback | undefined} [progress]
|
|
105
97
|
*/
|
|
106
98
|
|
|
99
|
+
|
|
107
100
|
/**
|
|
108
101
|
* @typedef {Object} ConversationEvent
|
|
109
|
-
* @property {Change<import('@scout9/app').Conversation> & {
|
|
102
|
+
* @property {(Change<import('@scout9/app').Conversation> & {
|
|
103
|
+
* forwardNote?: string;
|
|
104
|
+
* forward?: import('@scout9/app').WorkflowResponseSlot['forward'];
|
|
105
|
+
* })} conversation
|
|
110
106
|
* @property {Change<Array<import('@scout9/app').Message>>} messages
|
|
111
107
|
* @property {Change<any>} context
|
|
112
108
|
* @property {Change<import('@scout9/app').Message>} message
|
|
@@ -389,6 +385,9 @@ export const Spirits = {
|
|
|
389
385
|
let _forward;
|
|
390
386
|
let _forwardNote;
|
|
391
387
|
|
|
388
|
+
/** @type {Array<string> | undefined} */
|
|
389
|
+
let _tasks;
|
|
390
|
+
|
|
392
391
|
for (const {
|
|
393
392
|
forward,
|
|
394
393
|
forwardNote,
|
|
@@ -401,7 +400,8 @@ export const Spirits = {
|
|
|
401
400
|
contextUpsert,
|
|
402
401
|
anticipate,
|
|
403
402
|
followup: slotFollowup,
|
|
404
|
-
entityContextUpsert: slotEntityContextUpsert
|
|
403
|
+
entityContextUpsert: slotEntityContextUpsert,
|
|
404
|
+
tasks
|
|
405
405
|
} of slots) {
|
|
406
406
|
|
|
407
407
|
// Anticipate customer response
|
|
@@ -439,6 +439,12 @@ export const Spirits = {
|
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
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
|
+
|
|
442
448
|
if (slotFollowup) {
|
|
443
449
|
followup.push(slotFollowup);
|
|
444
450
|
}
|
|
@@ -585,13 +591,17 @@ export const Spirits = {
|
|
|
585
591
|
if ((!conversation.locked || !hasNoInstructions) && !!hasNoCustomMessage) {
|
|
586
592
|
try {
|
|
587
593
|
progress('Generating message', 'info', 'SET_PROCESSING', 'system');
|
|
588
|
-
const
|
|
594
|
+
const generatorInput = {
|
|
589
595
|
messages,
|
|
590
596
|
persona,
|
|
591
597
|
context,
|
|
592
598
|
llm: config.llm,
|
|
593
599
|
pmt: config.pmt
|
|
594
|
-
}
|
|
600
|
+
}
|
|
601
|
+
if (!!_tasks && Array.isArray(_tasks) && !!_tasks.length) {
|
|
602
|
+
generatorInput.tasks = _tasks;
|
|
603
|
+
}
|
|
604
|
+
const generatorPayload = await generator(generatorInput);
|
|
595
605
|
if (!generatorPayload.send) {
|
|
596
606
|
progress('Generated response', 'failed', undefined, {error: generatorPayload.error || 'Unknown Reason'});
|
|
597
607
|
console.error(
|