@scout9/app 1.0.0-alpha.0.1.92 → 1.0.0-alpha.0.1.94
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/{exports-dfabefaf.cjs → exports-1f0580dd.cjs} +528 -24
- package/dist/index.cjs +111 -2
- package/dist/{multipart-parser-52e1536f.cjs → multipart-parser-bbe3e14d.cjs} +2 -2
- package/dist/{spirits-6a709255.cjs → spirits-32395ac4.cjs} +23 -1
- package/dist/spirits.cjs +1 -1
- package/dist/testing-tools.cjs +2 -2
- package/package.json +1 -1
- package/src/core/config/agents.js +1 -1
- package/src/exports.js +1 -0
- package/src/runtime/client/utils.js +1 -0
- package/src/runtime/client/workflow.js +82 -24
- package/src/runtime/index.js +1 -0
- package/src/runtime/macros/builder.js +43 -0
- package/src/runtime/macros/event.js +234 -0
- package/src/runtime/macros/globals.js +14 -0
- package/src/runtime/macros/index.js +3 -0
- package/src/runtime/macros/schemas.js +12 -0
- package/src/runtime/macros/utils.js +31 -0
- package/src/testing-tools/spirits.js +1 -1
- package/src/utils/configs/agents.js +1 -1
- package/types/index.d.ts +18426 -332
- package/types/index.d.ts.map +9 -2
package/dist/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var exports$1 = require("./exports-
|
|
6
|
-
var spirits = require("./spirits-
|
|
5
|
+
var exports$1 = require("./exports-1f0580dd.cjs");
|
|
6
|
+
var spirits = require("./spirits-32395ac4.cjs");
|
|
7
7
|
require('node:readline');
|
|
8
8
|
require('fs');
|
|
9
9
|
require('events');
|
|
@@ -37,12 +37,115 @@ require('node:util');
|
|
|
37
37
|
require('node:net');
|
|
38
38
|
require('node:vm');
|
|
39
39
|
|
|
40
|
+
var MacroGlobals = /*#__PURE__*/function () {
|
|
41
|
+
function MacroGlobals() {
|
|
42
|
+
spirits._classCallCheck(this, MacroGlobals);
|
|
43
|
+
}
|
|
44
|
+
spirits._createClass(MacroGlobals, null, [{
|
|
45
|
+
key: "$convo",
|
|
46
|
+
value: function $convo() {
|
|
47
|
+
var _globalThis$SCOUT;
|
|
48
|
+
var $convo = globalThis === null || globalThis === void 0 || (_globalThis$SCOUT = globalThis.SCOUT9) === null || _globalThis$SCOUT === void 0 ? void 0 : _globalThis$SCOUT.$convo;
|
|
49
|
+
if (!$convo) {
|
|
50
|
+
throw new Error("$convo not found in runtime context, ".concat(spirits._classStaticPrivateFieldSpecGet(MacroGlobals, MacroGlobals, _hint)));
|
|
51
|
+
}
|
|
52
|
+
return $convo;
|
|
53
|
+
}
|
|
54
|
+
}]);
|
|
55
|
+
return MacroGlobals;
|
|
56
|
+
}();
|
|
57
|
+
var _hint = {
|
|
58
|
+
writable: true,
|
|
59
|
+
value: "make sure the context is properly instantiated before running workflow."
|
|
60
|
+
};
|
|
40
61
|
|
|
62
|
+
function handleAxiosResponse(res) {
|
|
63
|
+
if (res.status === 200) {
|
|
64
|
+
return res.data;
|
|
65
|
+
} else {
|
|
66
|
+
throw new Error("".concat(res.status, " ").concat(res.statusText));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
41
69
|
|
|
70
|
+
/**
|
|
71
|
+
* The `did` macro takes a given prompt and infers a binary `true` or `false` result in relation to the prompt's subject actor and the prompt's inquiry.
|
|
72
|
+
* @param {string} prompt
|
|
73
|
+
* @return {Promise<boolean>}
|
|
74
|
+
*/
|
|
75
|
+
function did(_x) {
|
|
76
|
+
return _did.apply(this, arguments);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The `context` macro, similar to the `did` macro, takes a natural statement and checks the entire conversation state and extracts or infers a metadata composition result.
|
|
81
|
+
* @param {string} prompt
|
|
82
|
+
* @param {import('@scout9/admin').CaptureContextRequestExamples} [examples]
|
|
83
|
+
* @return {Promise<import('@scout9/admin').CaptureContext200Response>}
|
|
84
|
+
*/
|
|
85
|
+
function _did() {
|
|
86
|
+
_did = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee(prompt) {
|
|
87
|
+
var convoId, _yield$Scout9Api$did$, value;
|
|
88
|
+
return spirits._regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
89
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
90
|
+
case 0:
|
|
91
|
+
convoId = MacroGlobals.$convo();
|
|
92
|
+
_context2.next = 3;
|
|
93
|
+
return new exports$1.build.Scout9Api(new exports$1.build.Configuration({
|
|
94
|
+
apiKey: process.env.SCOUT9_API_KEY
|
|
95
|
+
})).did({
|
|
96
|
+
prompt: prompt,
|
|
97
|
+
convoId: convoId
|
|
98
|
+
}).then(handleAxiosResponse);
|
|
99
|
+
case 3:
|
|
100
|
+
_yield$Scout9Api$did$ = _context2.sent;
|
|
101
|
+
value = _yield$Scout9Api$did$.value;
|
|
102
|
+
return _context2.abrupt("return", value);
|
|
103
|
+
case 6:
|
|
104
|
+
case "end":
|
|
105
|
+
return _context2.stop();
|
|
106
|
+
}
|
|
107
|
+
}, _callee);
|
|
108
|
+
}));
|
|
109
|
+
return _did.apply(this, arguments);
|
|
110
|
+
}
|
|
111
|
+
function context(_x2, _x3) {
|
|
112
|
+
return _context.apply(this, arguments);
|
|
113
|
+
}
|
|
114
|
+
function _context() {
|
|
115
|
+
_context = spirits._asyncToGenerator( /*#__PURE__*/spirits._regeneratorRuntime().mark(function _callee2(prompt, examples) {
|
|
116
|
+
var convoId;
|
|
117
|
+
return spirits._regeneratorRuntime().wrap(function _callee2$(_context3) {
|
|
118
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
119
|
+
case 0:
|
|
120
|
+
convoId = MacroGlobals.$convo();
|
|
121
|
+
_context3.next = 3;
|
|
122
|
+
return new exports$1.build.Scout9Api(new exports$1.build.Configuration({
|
|
123
|
+
apiKey: process.env.SCOUT9_API_KEY
|
|
124
|
+
})).captureContext({
|
|
125
|
+
prompt: prompt,
|
|
126
|
+
examples: examples,
|
|
127
|
+
convoId: convoId
|
|
128
|
+
}).then(handleAxiosResponse);
|
|
129
|
+
case 3:
|
|
130
|
+
return _context3.abrupt("return", _context3.sent);
|
|
131
|
+
case 4:
|
|
132
|
+
case "end":
|
|
133
|
+
return _context3.stop();
|
|
134
|
+
}
|
|
135
|
+
}, _callee2);
|
|
136
|
+
}));
|
|
137
|
+
return _context.apply(this, arguments);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
exports.ContextExampleSchema = exports$1.ContextExampleSchema;
|
|
141
|
+
exports.ContextExampleWithTrainingDataSchema = exports$1.ContextExampleWithTrainingDataSchema;
|
|
42
142
|
exports.ConversationContext = exports$1.ConversationContext;
|
|
43
143
|
exports.ConversationSchema = exports$1.ConversationSchema;
|
|
44
144
|
exports.EventResponse = exports$1.EventResponse;
|
|
145
|
+
exports.FollowupBaseSchema = exports$1.FollowupBaseSchema;
|
|
146
|
+
exports.FollowupSchema = exports$1.FollowupSchema;
|
|
45
147
|
exports.ForwardSchema = exports$1.ForwardSchema;
|
|
148
|
+
exports.InstructionObjectSchema = exports$1.InstructionObjectSchema;
|
|
46
149
|
exports.InstructionSchema = exports$1.InstructionSchema;
|
|
47
150
|
exports.IntentWorkflowEventSchema = exports$1.IntentWorkflowEventSchema;
|
|
48
151
|
exports.MessageSchema = exports$1.MessageSchema;
|
|
@@ -56,6 +159,7 @@ exports.WorkflowResponseMessage = exports$1.WorkflowResponseMessage;
|
|
|
56
159
|
exports.WorkflowResponseMessageApiRequest = exports$1.WorkflowResponseMessageApiRequest;
|
|
57
160
|
exports.WorkflowResponseMessageApiResponse = exports$1.WorkflowResponseMessageApiResponse;
|
|
58
161
|
exports.WorkflowResponseSchema = exports$1.WorkflowResponseSchema;
|
|
162
|
+
exports.WorkflowResponseSlotBaseSchema = exports$1.WorkflowResponseSlotBaseSchema;
|
|
59
163
|
exports.WorkflowResponseSlotSchema = exports$1.WorkflowResponseSlotSchema;
|
|
60
164
|
exports.WorkflowsConfigurationSchema = exports$1.WorkflowsConfigurationSchema;
|
|
61
165
|
exports.agentBaseConfigurationSchema = exports$1.agentBaseConfigurationSchema;
|
|
@@ -77,12 +181,17 @@ exports.entityApiConfigurationSchema = exports$1.entityApiConfigurationSchema;
|
|
|
77
181
|
exports.entityConfigurationSchema = exports$1.entityConfigurationSchema;
|
|
78
182
|
exports.entityRootProjectConfigurationSchema = exports$1.entityRootProjectConfigurationSchema;
|
|
79
183
|
exports.eventResponseSchema = exports$1.eventResponseSchema;
|
|
184
|
+
exports.forward = exports$1.forward;
|
|
80
185
|
exports.getApiFunctionSchema = exports$1.getApiFunctionSchema;
|
|
186
|
+
exports.instruct = exports$1.instruct;
|
|
81
187
|
exports.json = exports$1.json;
|
|
82
188
|
exports.patchApiFunctionSchema = exports$1.patchApiFunctionSchema;
|
|
83
189
|
exports.postApiFunctionSchema = exports$1.postApiFunctionSchema;
|
|
84
190
|
exports.putApiFunctionSchema = exports$1.putApiFunctionSchema;
|
|
85
191
|
exports.queryApiFunctionSchema = exports$1.queryApiFunctionSchema;
|
|
192
|
+
exports.reply = exports$1.reply;
|
|
86
193
|
exports.run = exports$1.run;
|
|
87
194
|
exports.sendEvent = exports$1.sendEvent;
|
|
88
195
|
exports.Spirits = spirits.Spirits;
|
|
196
|
+
exports.context = context;
|
|
197
|
+
exports.did = did;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require('node:fs');
|
|
4
4
|
require('node:path');
|
|
5
|
-
var exports$1 = require("./exports-
|
|
6
|
-
require("./spirits-
|
|
5
|
+
var exports$1 = require("./exports-1f0580dd.cjs");
|
|
6
|
+
require("./spirits-32395ac4.cjs");
|
|
7
7
|
require('node:readline');
|
|
8
8
|
require('fs');
|
|
9
9
|
require('events');
|
|
@@ -550,6 +550,27 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
|
550
550
|
}
|
|
551
551
|
};
|
|
552
552
|
}
|
|
553
|
+
function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) {
|
|
554
|
+
_classCheckPrivateStaticAccess(receiver, classConstructor);
|
|
555
|
+
_classCheckPrivateStaticFieldDescriptor(descriptor, "get");
|
|
556
|
+
return _classApplyDescriptorGet(receiver, descriptor);
|
|
557
|
+
}
|
|
558
|
+
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
559
|
+
if (descriptor.get) {
|
|
560
|
+
return descriptor.get.call(receiver);
|
|
561
|
+
}
|
|
562
|
+
return descriptor.value;
|
|
563
|
+
}
|
|
564
|
+
function _classCheckPrivateStaticAccess(receiver, classConstructor) {
|
|
565
|
+
if (receiver !== classConstructor) {
|
|
566
|
+
throw new TypeError("Private static access of wrong provenance");
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function _classCheckPrivateStaticFieldDescriptor(descriptor, action) {
|
|
570
|
+
if (descriptor === undefined) {
|
|
571
|
+
throw new TypeError("attempted to " + action + " private static field before its declaration");
|
|
572
|
+
}
|
|
573
|
+
}
|
|
553
574
|
|
|
554
575
|
/**
|
|
555
576
|
* @typedef {Object} Document
|
|
@@ -644,7 +665,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
|
644
665
|
* @typedef {Object} ConversationEvent
|
|
645
666
|
* @property {Change<import('../runtime/client/workflow.js').IConversation> & {forwardNote?: string; forward?: import('../runtime/client/message.js').IWorkflowResponseSlot['forward']}} conversation
|
|
646
667
|
* @property {Change<Array<import('../runtime/client/message.js').IMessage>>} messages
|
|
647
|
-
* @property {Change<
|
|
668
|
+
* @property {Change<any>} context
|
|
648
669
|
* @property {Change<import('../runtime/client/message.js').IMessage>} message
|
|
649
670
|
*/
|
|
650
671
|
var Spirits = {
|
|
@@ -1224,6 +1245,7 @@ var Spirits = {
|
|
|
1224
1245
|
exports.Spirits = Spirits;
|
|
1225
1246
|
exports._asyncToGenerator = _asyncToGenerator;
|
|
1226
1247
|
exports._classCallCheck = _classCallCheck;
|
|
1248
|
+
exports._classStaticPrivateFieldSpecGet = _classStaticPrivateFieldSpecGet;
|
|
1227
1249
|
exports._createClass = _createClass;
|
|
1228
1250
|
exports._createForOfIteratorHelper = _createForOfIteratorHelper;
|
|
1229
1251
|
exports._defineProperty = _defineProperty;
|
package/dist/spirits.cjs
CHANGED
package/dist/testing-tools.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var exports$1 = require("./exports-
|
|
6
|
-
var spirits = require("./spirits-
|
|
5
|
+
var exports$1 = require("./exports-1f0580dd.cjs");
|
|
6
|
+
var spirits = require("./spirits-32395ac4.cjs");
|
|
7
7
|
require('node:readline');
|
|
8
8
|
require('fs');
|
|
9
9
|
require('events');
|
package/package.json
CHANGED
|
@@ -135,7 +135,7 @@ export default async function loadAgentConfig({
|
|
|
135
135
|
}
|
|
136
136
|
if (!agent.programmablePhoneNumber) {
|
|
137
137
|
const userName = agent.firstName ? `${agent.firstName}${agent.lastName ? ' ' + agent.lastName : ''}` : agent.forwardPhone;
|
|
138
|
-
cb(`⚠️${colors.yellow('Warning')}: ${userName} does not have a masked phone number to do auto replies
|
|
138
|
+
cb(`⚠️${colors.yellow('Warning')}: ${userName} does not have a masked phone number to do auto replies.\nYou can register one at ${colors.cyan(
|
|
139
139
|
'https://scout9.com/b')} under ${colors.green('users')} > ${colors.green(userName)}. Then run ${colors.cyan(
|
|
140
140
|
'scout9 sync')} to update.`);
|
|
141
141
|
}
|
package/src/exports.js
CHANGED
|
@@ -5,6 +5,7 @@ export { EventResponse } from './runtime/index.js';
|
|
|
5
5
|
|
|
6
6
|
export * from './testing-tools/index.js';
|
|
7
7
|
export * from './runtime/client/index.js';
|
|
8
|
+
export * from './runtime/macros/index.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @param {import('./runtime/client/workflow.js').IWorkflowEvent} event - every workflow receives an event object
|
|
@@ -6,15 +6,17 @@ import { agentConfigurationSchema, customerSchema } from './users.js';
|
|
|
6
6
|
import { MessageSchema } from './message.js';
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
/**
|
|
11
10
|
* @typedef {import('zod').infer<typeof WorkflowConfigurationSchema>} IWorkflowConfiguration
|
|
12
11
|
*/
|
|
13
12
|
export const WorkflowConfigurationSchema = z.object({
|
|
14
|
-
entities: z.array(
|
|
13
|
+
entities: z.array(
|
|
14
|
+
zId('Workflow Folder', z.string()),
|
|
15
|
+
{description: 'Workflow id association, used to handle route params'}
|
|
16
|
+
)
|
|
15
17
|
.min(1, 'Must have at least 1 entity')
|
|
16
18
|
.max(15, 'Cannot have more than 15 entity paths'),
|
|
17
|
-
entity: zId('Workflow Folder', z.string())
|
|
19
|
+
entity: zId('Workflow Folder', z.string())
|
|
18
20
|
});
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -29,11 +31,12 @@ export const WorkflowsConfigurationSchema = z.array(WorkflowConfigurationSchema)
|
|
|
29
31
|
export const ConversationSchema = z.object({
|
|
30
32
|
$agent: zId('Conversation Agent ID', z.string({description: 'Default agent assigned to the conversation(s)'})),
|
|
31
33
|
$customer: zId('Conversation Customer ID', z.string({description: 'Customer this conversation is with'})),
|
|
32
|
-
initialContexts: z.array(z.string(), {description: 'Initial contexts to load when starting the conversation'})
|
|
34
|
+
initialContexts: z.array(z.string(), {description: 'Initial contexts to load when starting the conversation'})
|
|
35
|
+
.optional(),
|
|
33
36
|
environment: z.enum(['phone', 'email', 'web']),
|
|
34
37
|
environmentProps: z.object({
|
|
35
38
|
subject: z.string({description: 'HTML Subject of the conversation'}).optional(),
|
|
36
|
-
platformEmailThreadId: z.string({description: 'Used to sync email messages with the conversation'}).optional()
|
|
39
|
+
platformEmailThreadId: z.string({description: 'Used to sync email messages with the conversation'}).optional()
|
|
37
40
|
}).optional(),
|
|
38
41
|
locked: z.boolean({description: 'Whether the conversation is locked or not'}).optional().nullable(),
|
|
39
42
|
lockedReason: z.string({description: 'Why this conversation was locked'}).optional().nullable(),
|
|
@@ -42,16 +45,16 @@ export const ConversationSchema = z.object({
|
|
|
42
45
|
forwarded: z.string({description: 'Datetime ISO 8601 timestamp when persona was forwarded'}).optional().nullable(),
|
|
43
46
|
forwardNote: z.string().optional().nullable(),
|
|
44
47
|
intent: z.string({description: 'Detected intent of conversation'}).optional().nullable(),
|
|
45
|
-
intentScore: z.number({description: 'Confidence score of the assigned intent'}).optional().nullable()
|
|
48
|
+
intentScore: z.number({description: 'Confidence score of the assigned intent'}).optional().nullable()
|
|
46
49
|
});
|
|
47
50
|
|
|
48
51
|
/**
|
|
49
52
|
* @typedef {import('zod').infer<typeof IntentWorkflowEventSchema>} IIntentWorkflowEvent
|
|
50
53
|
*/
|
|
51
54
|
export const IntentWorkflowEventSchema = z.object({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
current: z.string().nullable(),
|
|
56
|
+
flow: z.array(z.string()),
|
|
57
|
+
initial: z.string().nullable()
|
|
55
58
|
});
|
|
56
59
|
|
|
57
60
|
/**
|
|
@@ -74,7 +77,7 @@ export const WorkflowEventSchema = z.object({
|
|
|
74
77
|
intent: IntentWorkflowEventSchema,
|
|
75
78
|
stagnationCount: z.number(),
|
|
76
79
|
note: z.string({description: 'Any developer notes to provide'}).optional()
|
|
77
|
-
})
|
|
80
|
+
});
|
|
78
81
|
|
|
79
82
|
const Primitive = z.union([z.string(), z.number(), z.boolean()]);
|
|
80
83
|
// Assuming ConversationContext is already defined as a Zod schema
|
|
@@ -102,29 +105,36 @@ export const ForwardSchema = z.union([
|
|
|
102
105
|
to: z.string().optional(),
|
|
103
106
|
mode: z.enum(['after-reply', 'immediately']).optional(),
|
|
104
107
|
note: z.string({description: 'Note to provide to the agent'}).optional()
|
|
105
|
-
})
|
|
108
|
+
})
|
|
106
109
|
], {description: 'Forward input information of a conversation'});
|
|
107
110
|
|
|
108
111
|
|
|
109
112
|
/**
|
|
110
113
|
* Instruction object schema used to send context to guide conversations
|
|
111
|
-
* @typedef {import('zod').infer<typeof
|
|
114
|
+
* @typedef {import('zod').infer<typeof InstructionObjectSchema>} IInstruction
|
|
112
115
|
*/
|
|
113
|
-
export const
|
|
114
|
-
id: zId('Instruction ID')
|
|
115
|
-
|
|
116
|
+
export const InstructionObjectSchema = z.object({
|
|
117
|
+
id: zId('Instruction ID')
|
|
118
|
+
.describe('Unique ID for the instruction, this is used to remove the instruction later')
|
|
119
|
+
.optional(),
|
|
120
|
+
persist: z.boolean()
|
|
121
|
+
.describe(
|
|
122
|
+
'if true, the instruction persists the conversation, if false the instruction will only last for 1 auto reply')
|
|
123
|
+
.default(true)
|
|
124
|
+
.optional(),
|
|
125
|
+
content: z.string()
|
|
116
126
|
});
|
|
117
127
|
|
|
118
128
|
/**
|
|
119
129
|
* @typedef {import('zod').infer<typeof WorkflowResponseMessageApiRequest>} IWorkflowResponseMessageApiRequest
|
|
120
130
|
*/
|
|
121
|
-
export const WorkflowResponseMessageApiRequest =
|
|
131
|
+
export const WorkflowResponseMessageApiRequest = z.object({
|
|
122
132
|
uri: z.string(),
|
|
123
133
|
data: z.any().optional(),
|
|
124
134
|
headers: z.object({
|
|
125
|
-
[z.string()]: z.string()
|
|
135
|
+
[z.string()]: z.string()
|
|
126
136
|
}).optional(),
|
|
127
|
-
method: z.enum([
|
|
137
|
+
method: z.enum(['GET', 'POST', 'PUT']).optional()
|
|
128
138
|
});
|
|
129
139
|
|
|
130
140
|
/**
|
|
@@ -168,19 +178,67 @@ export const WorkflowResponseMessageApiResponse = z.union([
|
|
|
168
178
|
|
|
169
179
|
/**
|
|
170
180
|
* The workflow response object slot
|
|
171
|
-
* @typedef {import('zod').infer<typeof
|
|
181
|
+
* @typedef {import('zod').infer<typeof InstructionSchema>} IInstruction
|
|
182
|
+
*/
|
|
183
|
+
export const InstructionSchema = z.union([z.string(), InstructionObjectSchema, z.array(z.string()), z.array(
|
|
184
|
+
InstructionObjectSchema)]);
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Base follow up schema to follow up with the client
|
|
188
|
+
* @typedef {import('zod').infer<typeof FollowupBaseSchema>} IFollowupBase
|
|
189
|
+
*/
|
|
190
|
+
export const FollowupBaseSchema = z.object({
|
|
191
|
+
scheduled: z.number(),
|
|
192
|
+
cancelIf: ConversationContext.optional(),
|
|
193
|
+
overrideLock: z.boolean({description: 'This will still run even if the conversation is locked, defaults to false'}).optional()
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Data used to automatically follow up with the client in the future
|
|
198
|
+
* @typedef {import('zod').infer<typeof FollowupSchema>} IFollowup
|
|
199
|
+
*/
|
|
200
|
+
export const FollowupSchema = z.union([
|
|
201
|
+
FollowupBaseSchema.extend({
|
|
202
|
+
message: z.string({description: 'Manual message sent to client'}),
|
|
203
|
+
}),
|
|
204
|
+
FollowupBaseSchema.extend({
|
|
205
|
+
instructions: InstructionSchema
|
|
206
|
+
})
|
|
207
|
+
]);
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The workflow response object slot
|
|
211
|
+
* @typedef {import('zod').infer<typeof WorkflowResponseSlotBaseSchema>} IWorkflowResponseSlotBase
|
|
172
212
|
*/
|
|
173
|
-
export const
|
|
213
|
+
export const WorkflowResponseSlotBaseSchema = z.object({
|
|
174
214
|
forward: ForwardSchema.optional(),
|
|
175
|
-
forwardNote: z.string({description: 'Note to provide to the agent, recommend using forward object api instead'})
|
|
176
|
-
|
|
215
|
+
forwardNote: z.string({description: 'Note to provide to the agent, recommend using forward object api instead'})
|
|
216
|
+
.optional(),
|
|
217
|
+
instructions: InstructionSchema.optional(),
|
|
177
218
|
removeInstructions: z.array(z.string()).optional(),
|
|
178
219
|
message: z.string().optional(),
|
|
179
|
-
// message: WorkflowResponseMessage.optional(),
|
|
180
220
|
secondsDelay: z.number().optional(),
|
|
181
221
|
scheduled: z.number().optional(),
|
|
182
222
|
contextUpsert: ConversationContext.optional(),
|
|
183
223
|
resetIntent: z.boolean().optional(),
|
|
224
|
+
followup: FollowupSchema.optional()
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The workflow response object slot
|
|
229
|
+
* @typedef {import('zod').infer<typeof WorkflowResponseSlotSchema>} IWorkflowResponseSlot
|
|
230
|
+
*/
|
|
231
|
+
export const WorkflowResponseSlotSchema = WorkflowResponseSlotBaseSchema.extend({
|
|
232
|
+
anticipate: z.union([
|
|
233
|
+
z.object({
|
|
234
|
+
did: z.string({definition: 'The prompt to check if true or false'}),
|
|
235
|
+
yes: WorkflowResponseSlotBaseSchema,
|
|
236
|
+
no: WorkflowResponseSlotBaseSchema
|
|
237
|
+
}),
|
|
238
|
+
z.array(WorkflowResponseSlotBaseSchema.extend({
|
|
239
|
+
keywords: z.array(z.string()).min(1).max(20)
|
|
240
|
+
}))
|
|
241
|
+
]).optional()
|
|
184
242
|
});
|
|
185
243
|
|
|
186
244
|
/**
|
|
@@ -199,5 +257,5 @@ export const WorkflowFunctionSchema = z.function()
|
|
|
199
257
|
.args(WorkflowEventSchema)
|
|
200
258
|
.returns(z.union([
|
|
201
259
|
z.promise(WorkflowResponseSchema),
|
|
202
|
-
WorkflowResponseSchema
|
|
260
|
+
WorkflowResponseSchema
|
|
203
261
|
]));
|
package/src/runtime/index.js
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder Macros
|
|
3
|
+
* used to build and guide a application logic in relation to the Scout9 conversation state.
|
|
4
|
+
*/
|
|
5
|
+
import { Configuration, Scout9Api } from '@scout9/admin';
|
|
6
|
+
import MacroGlobals from './globals.js';
|
|
7
|
+
|
|
8
|
+
function handleAxiosResponse(res) {
|
|
9
|
+
if (res.status === 200) {
|
|
10
|
+
return res.data;
|
|
11
|
+
} else {
|
|
12
|
+
throw new Error(`${res.status} ${res.statusText}`)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The `did` macro takes a given prompt and infers a binary `true` or `false` result in relation to the prompt's subject actor and the prompt's inquiry.
|
|
18
|
+
* @param {string} prompt
|
|
19
|
+
* @return {Promise<boolean>}
|
|
20
|
+
*/
|
|
21
|
+
export async function did(prompt) {
|
|
22
|
+
const convoId = MacroGlobals.$convo();
|
|
23
|
+
const {value} = (await (new Scout9Api(new Configuration({apiKey: process.env.SCOUT9_API_KEY}))).did({prompt, convoId})
|
|
24
|
+
.then(handleAxiosResponse));
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The `context` macro, similar to the `did` macro, takes a natural statement and checks the entire conversation state and extracts or infers a metadata composition result.
|
|
31
|
+
* @param {string} prompt
|
|
32
|
+
* @param {import('@scout9/admin').CaptureContextRequestExamples} [examples]
|
|
33
|
+
* @return {Promise<import('@scout9/admin').CaptureContext200Response>}
|
|
34
|
+
*/
|
|
35
|
+
export async function context(prompt, examples) {
|
|
36
|
+
const convoId = MacroGlobals.$convo();
|
|
37
|
+
return (await (new Scout9Api(new Configuration({apiKey: process.env.SCOUT9_API_KEY}))).captureContext({
|
|
38
|
+
prompt,
|
|
39
|
+
examples,
|
|
40
|
+
convoId
|
|
41
|
+
})
|
|
42
|
+
.then(handleAxiosResponse));
|
|
43
|
+
}
|