@scout9/app 1.0.0-alpha.0.5.8 → 1.0.0-alpha.0.5.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-ccf05f24.cjs → dev-8ed1e379.cjs} +155 -9
- package/dist/{index-b329d3e5.cjs → index-4f698e67.cjs} +7 -7
- package/dist/index.cjs +4 -4
- package/dist/{macros-f855de63.cjs → macros-4bff92c7.cjs} +12 -3
- package/dist/{multipart-parser-5819fcfd.cjs → multipart-parser-8f894f70.cjs} +4 -4
- package/dist/schemas.cjs +1 -1
- package/dist/{spirits-2ab4d673.cjs → spirits-82575cd5.cjs} +160 -78
- package/dist/spirits.cjs +1 -1
- package/dist/testing-tools.cjs +3 -3
- package/package.json +2 -1
- package/src/core/templates/app.js +277 -178
- package/src/public.d.ts +8 -2
- package/src/runtime/schemas/users.js +6 -1
- package/src/runtime/schemas/workflow.js +6 -2
- package/src/testing-tools/spirits.js +46 -0
- package/types/index.d.ts +1057 -161
- package/types/index.d.ts.map +1 -1
package/src/public.d.ts
CHANGED
|
@@ -359,6 +359,12 @@ export type Agent = {
|
|
|
359
359
|
model?: ("Scout9" | "bard" | "openai");
|
|
360
360
|
transcripts?: Message[][] | undefined;
|
|
361
361
|
audios?: any[] | undefined;
|
|
362
|
+
pmt?: {
|
|
363
|
+
tag?: string;
|
|
364
|
+
ingress: "auto" | "manual" | "app" | "webhook";
|
|
365
|
+
llm?: string;
|
|
366
|
+
scout9?: string;
|
|
367
|
+
}
|
|
362
368
|
};
|
|
363
369
|
|
|
364
370
|
export type AgentConfiguration = Agent & {id: string};
|
|
@@ -630,7 +636,7 @@ export type WorkflowEvent = {
|
|
|
630
636
|
conversation: Conversation;
|
|
631
637
|
context?: any;
|
|
632
638
|
message: Message;
|
|
633
|
-
agent: Omit<AgentConfiguration, 'transcripts' | 'audios' | 'includedLocations' | 'excludedLocations' | 'model' | 'context'>;
|
|
639
|
+
agent: Omit<AgentConfiguration, 'transcripts' | 'audios' | 'includedLocations' | 'excludedLocations' | 'model' | 'context' | 'pmt'>;
|
|
634
640
|
customer: Customer;
|
|
635
641
|
intent: IntentWorkflowEvent;
|
|
636
642
|
stagnationCount: number;
|
|
@@ -657,7 +663,7 @@ export type WorkflowResponseSlotBase = {
|
|
|
657
663
|
forwardNote?: string | undefined;
|
|
658
664
|
instructions?: Instruction[] | undefined;
|
|
659
665
|
removeInstructions?: string[] | undefined;
|
|
660
|
-
message?: string | undefined;
|
|
666
|
+
message?: string | {content: string; transform?: boolean} | undefined;
|
|
661
667
|
secondsDelay?: number | undefined;
|
|
662
668
|
scheduled?: number | undefined;
|
|
663
669
|
contextUpsert?: {
|
|
@@ -45,7 +45,12 @@ export const AgentSchema = z.object({
|
|
|
45
45
|
excludedLocations: z.array(z.string({description: 'Locations the agent is excluded from'})).optional(),
|
|
46
46
|
model: z.enum(['Scout9', 'bard', 'openai']).optional().default('openai'),
|
|
47
47
|
transcripts: z.array(z.array(MessageSchema)).optional(),
|
|
48
|
-
audios: z.array(z.any()).optional()
|
|
48
|
+
audios: z.array(z.any()).optional(),
|
|
49
|
+
pmt: z.object({
|
|
50
|
+
tag: z.string().optional(),
|
|
51
|
+
ingress: z.enum(["auto", "manual", "app", "workflow"]),
|
|
52
|
+
llm: z.string().optional(),
|
|
53
|
+
}).optional()
|
|
49
54
|
});
|
|
50
55
|
|
|
51
56
|
export const PersonaSchema = AgentSchema;
|
|
@@ -134,7 +134,8 @@ export const WorkflowEventSchema = z.object({
|
|
|
134
134
|
includedLocations: true,
|
|
135
135
|
excludedLocations: true,
|
|
136
136
|
model: true,
|
|
137
|
-
context: true
|
|
137
|
+
context: true,
|
|
138
|
+
pmt: true
|
|
138
139
|
}),
|
|
139
140
|
customer: CustomerSchema,
|
|
140
141
|
intent: IntentWorkflowEventSchema,
|
|
@@ -151,7 +152,10 @@ export const WorkflowResponseSlotBaseSchema = z.object({
|
|
|
151
152
|
.optional(),
|
|
152
153
|
instructions: InstructionSchema.optional(),
|
|
153
154
|
removeInstructions: z.array(z.string()).optional(),
|
|
154
|
-
message: z.string().
|
|
155
|
+
message: z.union([z.string(), z.object({
|
|
156
|
+
content: z.string(),
|
|
157
|
+
transform: z.boolean().optional()
|
|
158
|
+
})]).optional(),
|
|
155
159
|
secondsDelay: z.number().optional(),
|
|
156
160
|
scheduled: z.number().optional(),
|
|
157
161
|
contextUpsert: ConversationContext.optional(),
|
|
@@ -65,6 +65,12 @@
|
|
|
65
65
|
* @returns {Promise<import('@scout9/admin').GenerateResponse>}
|
|
66
66
|
*/
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @callback TransformerFun
|
|
70
|
+
* @param {import('@scout9/admin').PmtTransformRequest} data - data to generate from
|
|
71
|
+
* @returns {Promise<import('@scout9/admin').PmtTransformResponse>}
|
|
72
|
+
*/
|
|
73
|
+
|
|
68
74
|
/**
|
|
69
75
|
* @callback IdGeneratorFun
|
|
70
76
|
* @param {import('@scout9/app').Message['role']} prefix
|
|
@@ -84,6 +90,7 @@
|
|
|
84
90
|
* @property {ParseFun} parser
|
|
85
91
|
* @property {WorkflowFun} workflow
|
|
86
92
|
* @property {GenerateFun} generator
|
|
93
|
+
* @property {TransformerFun} transformer
|
|
87
94
|
* @property {IdGeneratorFun} idGenerator
|
|
88
95
|
* @property {StatusCallback | undefined} [progress]
|
|
89
96
|
*/
|
|
@@ -110,6 +117,7 @@ export const Spirits = {
|
|
|
110
117
|
parser,
|
|
111
118
|
workflow,
|
|
112
119
|
generator,
|
|
120
|
+
transformer,
|
|
113
121
|
idGenerator,
|
|
114
122
|
progress = (message, level, type, payload) => {
|
|
115
123
|
},
|
|
@@ -349,6 +357,7 @@ export const Spirits = {
|
|
|
349
357
|
}, []));
|
|
350
358
|
const hasNoInstructions = slots.every(s => !s.instructions || (Array.isArray(s.instructions) && s.instructions.length === 0));
|
|
351
359
|
const hasNoCustomMessage = slots.every(s => !s.message);
|
|
360
|
+
const messagesToTransform = slots.filter(s => !!s.message && typeof s.message === 'object' && !!s.message.transform);
|
|
352
361
|
const previousLockAttempt = conversation.lockAttempts || 0; // Used to track
|
|
353
362
|
|
|
354
363
|
if (hasNoInstructions && noNewContext) {
|
|
@@ -596,6 +605,43 @@ export const Spirits = {
|
|
|
596
605
|
conversation = lockConversation(conversation, 'API: ' + e.message);
|
|
597
606
|
}
|
|
598
607
|
}
|
|
608
|
+
|
|
609
|
+
if (messagesToTransform.length && transformer) {
|
|
610
|
+
try {
|
|
611
|
+
for (const messageToTransform of messagesToTransform) {
|
|
612
|
+
const transformResponse = await transformer({
|
|
613
|
+
message: messagesToTransform,
|
|
614
|
+
persona,
|
|
615
|
+
customer: customer.id,
|
|
616
|
+
messages,
|
|
617
|
+
context: context
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
progress('Generated response', 'success', undefined, undefined);
|
|
621
|
+
// Check if already had message
|
|
622
|
+
const agentMessages = messages.filter(m => m.role === 'agent');
|
|
623
|
+
const lastAgentMessage = agentMessages[agentMessages.length - 1];
|
|
624
|
+
if (lastAgentMessage && lastAgentMessage.content === transformResponse.message) {
|
|
625
|
+
// Error should not have happened
|
|
626
|
+
conversation = lockConversation(conversation, 'Duplicate message');
|
|
627
|
+
} else {
|
|
628
|
+
messages.push({
|
|
629
|
+
id: idGenerator('agent'),
|
|
630
|
+
role: 'agent',
|
|
631
|
+
content: transformResponse.message,
|
|
632
|
+
time: new Date().toISOString()
|
|
633
|
+
});
|
|
634
|
+
progress('Added agent message', 'info', 'ADD_MESSAGE', messages[messages.length - 1]);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
}
|
|
638
|
+
} catch (e) {
|
|
639
|
+
console.error(`Locking conversation, error transforming response: ${e.message}`);
|
|
640
|
+
conversation = lockConversation(conversation, 'API: ' + e.message);
|
|
641
|
+
}
|
|
642
|
+
} else if (messagesToTransform.length) {
|
|
643
|
+
console.warn(`No transformer provided`)
|
|
644
|
+
}
|
|
599
645
|
}
|
|
600
646
|
|
|
601
647
|
progress('Parsing message', 'info', 'SET_PROCESSING', null);
|