@scout9/app 1.0.0-alpha.0.6.4 → 1.0.0-alpha.0.6.6
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-fee40f1c.cjs → dev-df88036b.cjs} +3 -3
- package/dist/{index-b59a82b2.cjs → index-33d77bc4.cjs} +7 -7
- package/dist/index.cjs +4 -4
- package/dist/{macros-a37c4a77.cjs → macros-1a4fd407.cjs} +7 -1
- package/dist/{multipart-parser-06b501ee.cjs → multipart-parser-17ab0a54.cjs} +4 -4
- package/dist/schemas.cjs +1 -1
- package/dist/{spirits-e626085b.cjs → spirits-9719ae4f.cjs} +135 -113
- package/dist/spirits.cjs +1 -1
- package/dist/testing-tools.cjs +3 -3
- package/package.json +1 -1
- package/src/public.d.ts +67 -2
- package/src/runtime/schemas/message.js +3 -1
- package/src/testing-tools/spirits.js +25 -7
- package/types/index.d.ts +218 -7
- package/types/index.d.ts.map +3 -1
package/dist/testing-tools.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var dev = require("./dev-
|
|
6
|
-
require("./spirits-
|
|
5
|
+
var dev = require("./dev-df88036b.cjs");
|
|
6
|
+
require("./spirits-9719ae4f.cjs");
|
|
7
7
|
require('util');
|
|
8
8
|
require('stream');
|
|
9
9
|
require('path');
|
|
@@ -24,7 +24,7 @@ require('node:url');
|
|
|
24
24
|
require('node:events');
|
|
25
25
|
require('node:stream');
|
|
26
26
|
require('node:string_decoder');
|
|
27
|
-
require("./macros-
|
|
27
|
+
require("./macros-1a4fd407.cjs");
|
|
28
28
|
require('node:readline');
|
|
29
29
|
require('node:process');
|
|
30
30
|
require('node:os');
|
package/package.json
CHANGED
package/src/public.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Application platform for managing auto reply workflows from personal communication methods
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* @param {WorkflowEvent} event - every workflow receives an event object
|
|
9
11
|
* @param {Object} options
|
|
@@ -530,6 +532,21 @@ export type FollowupWithInstructions = FollowupBase & { instructions: Instructio
|
|
|
530
532
|
|
|
531
533
|
export type Followup = FollowupWithMessage | FollowupWithInstructions;
|
|
532
534
|
|
|
535
|
+
/**
|
|
536
|
+
* Metadata to provide a atomic transaction on a entity context record
|
|
537
|
+
* @ingress auto/manual only
|
|
538
|
+
*/
|
|
539
|
+
export type EntityContextUpsert = {
|
|
540
|
+
entityType: string;
|
|
541
|
+
entityRecordId: string;
|
|
542
|
+
method: 'mutate' | 'delete'
|
|
543
|
+
} & ({
|
|
544
|
+
method: 'delete'
|
|
545
|
+
} | {
|
|
546
|
+
method: 'mutate';
|
|
547
|
+
fields: Record<string, string | number | boolean | null | '#remove' | '#delete'>;
|
|
548
|
+
});
|
|
549
|
+
|
|
533
550
|
export type Forward = boolean | string | {
|
|
534
551
|
to?: string | undefined;
|
|
535
552
|
mode?: ("after-reply" | "immediately") | undefined;
|
|
@@ -554,6 +571,9 @@ export type EntityToken = {
|
|
|
554
571
|
export type Message = {
|
|
555
572
|
/** Unique ID for the message */
|
|
556
573
|
id: string;
|
|
574
|
+
/**
|
|
575
|
+
* @TODO role:agent is inaccurate it should be "persona"
|
|
576
|
+
*/
|
|
557
577
|
role: "agent" | "customer" | "system";
|
|
558
578
|
content: string;
|
|
559
579
|
/** Datetime ISO 8601 timestamp */
|
|
@@ -569,8 +589,12 @@ export type Message = {
|
|
|
569
589
|
intentScore?: (number | null) | undefined;
|
|
570
590
|
/** How long to delay the message manually in seconds */
|
|
571
591
|
delayInSeconds?: (number | null) | undefined;
|
|
572
|
-
/** Entities related to the message */
|
|
592
|
+
/** Entities related to the message (gets set after the PMT transform) */
|
|
573
593
|
entities?: EntityToken[] | null;
|
|
594
|
+
/** If set to true, the PMT will not transform, message will be sent as is */
|
|
595
|
+
ignoreTransform?: boolean;
|
|
596
|
+
/** Media urls to attach to the transported message */
|
|
597
|
+
mediaUrls?: string[];
|
|
574
598
|
};
|
|
575
599
|
|
|
576
600
|
export type PersonaConfiguration = AgentConfiguration;
|
|
@@ -666,27 +690,68 @@ export type AnticipateKeywords = WorkflowResponseSlotBase & {
|
|
|
666
690
|
|
|
667
691
|
export type Anticipate = AnticipateDid | AnticipateKeywords[];
|
|
668
692
|
|
|
693
|
+
export type DirectMessage = Partial<Omit<Message, 'id' | 'entities' | 'time' | 'role'>>;
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Workflow Response Slot, can use for both PMT workflow event and event macro runtimes
|
|
697
|
+
*/
|
|
669
698
|
export type WorkflowResponseSlotBase = {
|
|
670
699
|
/** Forward input information of a conversation */
|
|
671
700
|
forward?: Forward | undefined;
|
|
701
|
+
|
|
672
702
|
/** Note to provide to the agent, recommend using forward object api instead */
|
|
673
703
|
forwardNote?: string | undefined;
|
|
704
|
+
|
|
705
|
+
/** Instructions to send to the PMT on how to steer the conversation */
|
|
674
706
|
instructions?: Instruction[] | undefined;
|
|
707
|
+
|
|
708
|
+
/** Remove instructions from memory (requires set instructions to have ids) */
|
|
675
709
|
removeInstructions?: string[] | undefined;
|
|
676
|
-
|
|
710
|
+
|
|
711
|
+
/** If provided, sends a direct message to the user */
|
|
712
|
+
message?: string | DirectMessage | undefined;
|
|
713
|
+
|
|
714
|
+
/** Delays in seconds of instructions (if provided) to PMT and direct message (if provided) to user */
|
|
677
715
|
secondsDelay?: number | undefined;
|
|
716
|
+
|
|
717
|
+
/** unix time of when to send instructions or message */
|
|
678
718
|
scheduled?: number | undefined;
|
|
719
|
+
|
|
720
|
+
/** Context to upsert to the conversation */
|
|
679
721
|
contextUpsert?: {
|
|
680
722
|
[x: string]: any;
|
|
681
723
|
} | undefined;
|
|
724
|
+
|
|
725
|
+
/** If true, resets the conversations intent value to undefined or to its initial value */
|
|
682
726
|
resetIntent?: boolean | undefined;
|
|
727
|
+
|
|
728
|
+
/** Information to follow up to the client */
|
|
683
729
|
followup?: Followup | undefined;
|
|
684
730
|
};
|
|
685
731
|
|
|
732
|
+
/**
|
|
733
|
+
* Workflow Response Slot, only PMT workflow events
|
|
734
|
+
*/
|
|
686
735
|
export type WorkflowResponseSlot = WorkflowResponseSlotBase & {
|
|
736
|
+
/**
|
|
737
|
+
* The Anticipate API acts as a preflight to the users next response, for example:
|
|
738
|
+
* - did the user agree to accept the concert tickets? Then proceed with asking for their email
|
|
739
|
+
* - Did the user say any of these words: "cancel", "drop", or "remove"? Then cancel tickets
|
|
740
|
+
*/
|
|
687
741
|
anticipate?: Anticipate | undefined;
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* If provided, it will propagate entity context to your Scout9 entity context store
|
|
746
|
+
* @ingress auto/manual only
|
|
747
|
+
*/
|
|
748
|
+
entityContextUpsert?: Array<EntityContextUpsert> | undefined;
|
|
688
749
|
};
|
|
689
750
|
|
|
751
|
+
/**
|
|
752
|
+
* The JSON anticipated response for a given workflow to drive the PMT runtime
|
|
753
|
+
* Can either be an EventMacro or WorkflowResponseSlot
|
|
754
|
+
*/
|
|
690
755
|
export type WorkflowResponse = EventMacros | WorkflowResponseSlot | (WorkflowResponseSlot | EventMacros)[];
|
|
691
756
|
|
|
692
757
|
export type WorkflowFunction = (event: WorkflowEvent) => WorkflowResponse | Promise<WorkflowResponse>;
|
|
@@ -20,5 +20,7 @@ export const MessageSchema = z.object({
|
|
|
20
20
|
intent: z.string({description: 'Detected intent'}).optional().nullable(),
|
|
21
21
|
intentScore: z.number({description: 'Confidence score of the assigned intent'}).nullable().optional(),
|
|
22
22
|
delayInSeconds: z.number({description: 'How long to delay the message manually in seconds'}).nullable().optional(),
|
|
23
|
-
entities: z.array(MessageEntitySchema).optional().nullable()
|
|
23
|
+
entities: z.array(MessageEntitySchema).optional().nullable(),
|
|
24
|
+
ignoreTransform: z.boolean({description: 'If set to true, the PMT will not transform, message will be sent as is'}).optional(),
|
|
25
|
+
mediaUrls: z.array(z.string(), {description: 'Media urls to attach to the transported message'}).optional().nullable()
|
|
24
26
|
});
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* @property {string} id
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Represents a change with before and after states of a given type.
|
|
9
8
|
* @template Type The type of the before and after properties.
|
|
@@ -112,6 +111,7 @@
|
|
|
112
111
|
* @property {Change<any>} context
|
|
113
112
|
* @property {Change<import('@scout9/app').Message>} message
|
|
114
113
|
* @property {Array<import('@scout9/app').Followup>} followup
|
|
114
|
+
* @property {Array<import('@scout9/app').EntityContextUpsert>} entityContextUpsert
|
|
115
115
|
*/
|
|
116
116
|
export const Spirits = {
|
|
117
117
|
|
|
@@ -137,7 +137,10 @@ export const Spirits = {
|
|
|
137
137
|
conversation: conversationBefore
|
|
138
138
|
} = input;
|
|
139
139
|
let {conversation, messages, context, message} = input;
|
|
140
|
+
|
|
141
|
+
// Storing post process events here
|
|
140
142
|
const followup = [];
|
|
143
|
+
const entityContextUpsert = [];
|
|
141
144
|
|
|
142
145
|
// 0. Setup Helpers
|
|
143
146
|
const updateConversation = (previousConversation, conversationUpdates) => {
|
|
@@ -398,6 +401,7 @@ export const Spirits = {
|
|
|
398
401
|
contextUpsert,
|
|
399
402
|
anticipate,
|
|
400
403
|
followup: slotFollowup,
|
|
404
|
+
entityContextUpsert: slotEntityContextUpsert
|
|
401
405
|
} of slots) {
|
|
402
406
|
|
|
403
407
|
// Anticipate customer response
|
|
@@ -439,6 +443,10 @@ export const Spirits = {
|
|
|
439
443
|
followup.push(slotFollowup);
|
|
440
444
|
}
|
|
441
445
|
|
|
446
|
+
if (slotEntityContextUpsert && slotEntityContextUpsert.length) {
|
|
447
|
+
entityContextUpsert.push(...slotEntityContextUpsert);
|
|
448
|
+
}
|
|
449
|
+
|
|
442
450
|
// Forward to agent or other agent
|
|
443
451
|
if (forward) {
|
|
444
452
|
conversation = lockConversation(conversation, 'App instructed forward');
|
|
@@ -514,15 +522,24 @@ export const Spirits = {
|
|
|
514
522
|
}
|
|
515
523
|
|
|
516
524
|
if (manualMessage) {
|
|
525
|
+
|
|
526
|
+
/** @type {import('@scout9/app').Message} */
|
|
517
527
|
let manualMessageObj = {
|
|
518
|
-
id: idGenerator('
|
|
519
|
-
role: 'agent',
|
|
520
|
-
content:
|
|
528
|
+
id: idGenerator('persona'),
|
|
529
|
+
role: 'agent', // @TODO switch role to persona
|
|
530
|
+
content: '',
|
|
521
531
|
time: new Date().toISOString()
|
|
522
532
|
};
|
|
523
|
-
if (typeof manualMessage
|
|
524
|
-
|
|
533
|
+
if (typeof manualMessage === 'object') {
|
|
534
|
+
Object.assign(manualMessageObj, manualMessage);
|
|
535
|
+
manualMessageObj.role = 'agent';
|
|
536
|
+
manualMessageObj.time = new Date().toISOString();
|
|
537
|
+
} else if (typeof manualMessage === 'string') {
|
|
538
|
+
manualMessageObj.content = manualMessage;
|
|
539
|
+
} else {
|
|
540
|
+
throw new Error('Manual message must be of type "string" or "DirectMessage"');
|
|
525
541
|
}
|
|
542
|
+
|
|
526
543
|
if (scheduled) {
|
|
527
544
|
manualMessageObj.time = new Date(scheduled * 1000).toISOString();
|
|
528
545
|
manualMessageObj.scheduled = manualMessageObj.time;
|
|
@@ -680,7 +697,8 @@ export const Spirits = {
|
|
|
680
697
|
before: contextBefore,
|
|
681
698
|
after: context
|
|
682
699
|
},
|
|
683
|
-
followup
|
|
700
|
+
followup,
|
|
701
|
+
entityContextUpsert
|
|
684
702
|
};
|
|
685
703
|
}
|
|
686
704
|
};
|