@scout9/app 1.0.0-alpha.0.2.2 → 1.0.0-alpha.0.2.5

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.
@@ -39939,7 +39939,7 @@ function _loadUserPackageJson() {
39939
39939
  targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
39940
39940
  _context2.t0 = JSON;
39941
39941
  _context2.next = 10;
39942
- return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('dev-df823c44.js', document.baseURI).href))), 'utf-8');
39942
+ return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('dev-60d45091.js', document.baseURI).href))), 'utf-8');
39943
39943
  case 10:
39944
39944
  _context2.t1 = _context2.sent;
39945
39945
  pkg = _context2.t0.parse.call(_context2.t0, _context2.t1);
@@ -40749,23 +40749,9 @@ var PersonaConfigurationSchema = AgentConfigurationSchema.extend({
40749
40749
  })
40750
40750
  });
40751
40751
  var AgentsConfigurationSchema = z.array(AgentConfigurationSchema);
40752
- z.array(PersonaConfigurationSchema);
40752
+ var PersonasConfigurationSchema = z.array(PersonaConfigurationSchema);
40753
40753
  var AgentsSchema = z.array(AgentSchema);
40754
- z.array(PersonaSchema);
40755
- var Bus = z.object({
40756
- foo: z.string(),
40757
- bar: z["boolean"]().optional()
40758
- });
40759
- var Baz = z.object({
40760
- boo: z.object({
40761
- one: z.number(),
40762
- two: z.number().optional()
40763
- })
40764
- });
40765
- z.object({
40766
- baz: Baz,
40767
- bus: Bus
40768
- });
40754
+ var PersonasSchema = z.array(PersonaSchema);
40769
40755
 
40770
40756
  var ConversationContext = z.record(z.string(), z.any());
40771
40757
  var ConversationAnticipateSchema = z.object({
@@ -40852,7 +40838,7 @@ var WorkflowResponseMessageApiRequest = z.object({
40852
40838
  * If its a string, it will be sent as a static string.
40853
40839
  * If it's a object or WorkflowResponseMessageAPI - it will use
40854
40840
  */
40855
- z.union([z.string(),
40841
+ var WorkflowResponseMessage = z.union([z.string(),
40856
40842
  /**
40857
40843
  * An api call that should be called later, must return a string or {message: string}
40858
40844
  */
@@ -40861,7 +40847,7 @@ WorkflowResponseMessageApiRequest]);
40861
40847
  /**
40862
40848
  * The intended response provided by the WorkflowResponseMessageApiRequest
40863
40849
  */
40864
- z.union([z.string(), z.object({
40850
+ var WorkflowResponseMessageApiResponse = z.union([z.string(), z.object({
40865
40851
  message: z.string()
40866
40852
  }), z.object({
40867
40853
  text: z.string()
@@ -40971,7 +40957,7 @@ var WorkflowResponseSlotSchema = WorkflowResponseSlotBaseSchema.extend({
40971
40957
  * The workflow response to send in any given workflow
40972
40958
  */
40973
40959
  var WorkflowResponseSchema = z.union([WorkflowResponseSlotSchema, z.array(WorkflowResponseSlotSchema)]);
40974
- z["function"]().args(WorkflowEventSchema).returns(z.union([z.promise(WorkflowResponseSchema), WorkflowResponseSchema]));
40960
+ var WorkflowFunctionSchema = z["function"]().args(WorkflowEventSchema).returns(z.union([z.promise(WorkflowResponseSchema), WorkflowResponseSchema]));
40975
40961
 
40976
40962
  var _excluded$2 = ["success"];
40977
40963
  function MacroUtilsFactory() {
@@ -41369,15 +41355,6 @@ var responseInitSchema = z.object({
41369
41355
  statusText: z.string().optional(),
41370
41356
  headers: z.any().optional() // Headers can be complex; adjust as needed
41371
41357
  });
41372
-
41373
- /**
41374
- * @template T
41375
- * @typedef {object} IEventResponse
41376
- * @property {T} body - The body of the response.
41377
- * @property {ResponseInit} [init] - Additional options for the response.
41378
- * @property {Response} response - The response object.
41379
- * @property {T} data - The body of the response.
41380
- */
41381
41358
  var eventResponseSchema = z.object({
41382
41359
  body: z.any(),
41383
41360
  // Adjust as per your actual body structure
@@ -41443,7 +41420,7 @@ var EntityConfigurationSchema = _EntityConfigurationSchema.refine(function (data
41443
41420
  // Custom error message
41444
41421
  message: "If 'definitions' is provided, then 'training' must also be provided"
41445
41422
  });
41446
- z.array(EntityConfigurationSchema);
41423
+ var EntitiesRootConfigurationSchema = z.array(EntityConfigurationSchema);
41447
41424
  var EntityExtendedProjectConfigurationSchema = z.object({
41448
41425
  entities: z.array(zId('Entity Folder', z.string()), {
41449
41426
  description: 'Entity id association, used to handle route params'
@@ -41541,35 +41518,38 @@ var Scout9ProjectBuildConfigSchema = Scout9ProjectConfigSchema.extend({
41541
41518
  workflows: WorkflowsConfigurationSchema
41542
41519
  });
41543
41520
 
41544
- /**
41545
- * @typedef {object} IApiFunctionParams
41546
- * @property {Object.<string, string|string[]>} searchParams
41547
- * @property {Record<string, string>} params
41548
- */
41549
41521
  var apiFunctionParamsSchema = z.object({
41550
41522
  searchParams: z.record(z.string(), z.union([z.string(), z.array(z.string())])),
41551
41523
  params: z.record(z.string(), z.string())
41552
41524
  });
41553
-
41554
- /**
41555
- * @typedef {IApiFunctionParams & { id: string }} IApiEntityFunctionParams
41556
- */
41557
41525
  apiFunctionParamsSchema.extend({
41558
41526
  id: z.string()
41559
41527
  });
41560
-
41561
- /**
41562
- * @template Params
41563
- * @template Response
41564
- * @typedef {function(IApiFunctionParams): Promise<EventResponse>} IApiFunction
41565
- */
41566
- z["function"]().args(apiFunctionParamsSchema).returns(z.promise(eventResponseSchema));
41528
+ var apiFunctionSchema = z["function"]().args(apiFunctionParamsSchema).returns(z.promise(eventResponseSchema));
41529
+ var queryApiFunctionSchema = apiFunctionSchema;
41530
+ var getApiFunctionSchema = apiFunctionSchema;
41531
+ var postApiFunctionSchema = function postApiFunctionSchema(requestBodySchema) {
41532
+ return z["function"]().args(apiFunctionParamsSchema.extend({
41533
+ body: requestBodySchema.partial()
41534
+ })).returns(z.promise(eventResponseSchema));
41535
+ };
41536
+ var putApiFunctionSchema = function putApiFunctionSchema(requestBodySchema) {
41537
+ return z["function"]().args(apiFunctionParamsSchema.extend({
41538
+ body: requestBodySchema.partial()
41539
+ })).returns(z.promise(eventResponseSchema));
41540
+ };
41541
+ var patchApiFunctionSchema = function patchApiFunctionSchema(requestBodySchema) {
41542
+ return z["function"]().args(apiFunctionParamsSchema.extend({
41543
+ body: requestBodySchema.partial()
41544
+ })).returns(z.promise(eventResponseSchema));
41545
+ };
41546
+ var deleteApiFunctionSchema = apiFunctionSchema;
41567
41547
 
41568
41548
  var ContextExampleWithTrainingDataSchema = z.object({
41569
41549
  input: z.string(),
41570
41550
  output: z.array(z.record(z.string(), z.any()))
41571
41551
  });
41572
- z.union([z.array(ContextExampleWithTrainingDataSchema), z.array(z.record(z.string(), z.any()))]);
41552
+ var ContextExampleSchema = z.union([z.array(ContextExampleWithTrainingDataSchema), z.array(z.record(z.string(), z.any()))]);
41573
41553
 
41574
41554
  let FORCE_COLOR,
41575
41555
  NODE_DISABLE_COLORS,
@@ -48204,16 +48184,48 @@ var Scout9Test = /*#__PURE__*/function () {
48204
48184
  }();
48205
48185
 
48206
48186
  exports.$ = $$1;
48187
+ exports.AgentConfigurationSchema = AgentConfigurationSchema;
48188
+ exports.AgentSchema = AgentSchema;
48189
+ exports.AgentsConfigurationSchema = AgentsConfigurationSchema;
48190
+ exports.AgentsSchema = AgentsSchema;
48191
+ exports.ContextExampleSchema = ContextExampleSchema;
48192
+ exports.ContextExampleWithTrainingDataSchema = ContextExampleWithTrainingDataSchema;
48193
+ exports.ConversationAnticipateSchema = ConversationAnticipateSchema;
48194
+ exports.ConversationContext = ConversationContext;
48195
+ exports.ConversationSchema = ConversationSchema;
48196
+ exports.CustomerSchema = CustomerSchema;
48197
+ exports.CustomerValueSchema = CustomerValueSchema;
48198
+ exports.EntitiesRootConfigurationSchema = EntitiesRootConfigurationSchema;
48207
48199
  exports.EntitiesRootProjectConfigurationSchema = EntitiesRootProjectConfigurationSchema;
48208
48200
  exports.EntityApiConfigurationSchema = EntityApiConfigurationSchema;
48209
48201
  exports.EntityConfigurationSchema = EntityConfigurationSchema;
48210
48202
  exports.EntityRootProjectConfigurationSchema = EntityRootProjectConfigurationSchema;
48203
+ exports.FollowupBaseSchema = FollowupBaseSchema;
48204
+ exports.FollowupSchema = FollowupSchema;
48205
+ exports.ForwardSchema = ForwardSchema;
48206
+ exports.InstructionObjectSchema = InstructionObjectSchema;
48207
+ exports.InstructionSchema = InstructionSchema;
48208
+ exports.IntentWorkflowEventSchema = IntentWorkflowEventSchema;
48209
+ exports.MessageSchema = MessageSchema;
48210
+ exports.PersonaConfigurationSchema = PersonaConfigurationSchema;
48211
+ exports.PersonaSchema = PersonaSchema;
48212
+ exports.PersonasConfigurationSchema = PersonasConfigurationSchema;
48213
+ exports.PersonasSchema = PersonasSchema;
48211
48214
  exports.ProgressLogger = ProgressLogger;
48212
48215
  exports.Scout9ProjectBuildConfigSchema = Scout9ProjectBuildConfigSchema;
48216
+ exports.Scout9ProjectConfigSchema = Scout9ProjectConfigSchema;
48213
48217
  exports.Scout9Test = Scout9Test;
48214
48218
  exports.WorkflowConfigurationSchema = WorkflowConfigurationSchema;
48215
48219
  exports.WorkflowEventSchema = WorkflowEventSchema;
48220
+ exports.WorkflowFunctionSchema = WorkflowFunctionSchema;
48221
+ exports.WorkflowResponseMessage = WorkflowResponseMessage;
48222
+ exports.WorkflowResponseMessageApiRequest = WorkflowResponseMessageApiRequest;
48223
+ exports.WorkflowResponseMessageApiResponse = WorkflowResponseMessageApiResponse;
48224
+ exports.WorkflowResponseSchema = WorkflowResponseSchema;
48225
+ exports.WorkflowResponseSlotBaseSchema = WorkflowResponseSlotBaseSchema;
48226
+ exports.WorkflowResponseSlotSchema = WorkflowResponseSlotSchema;
48216
48227
  exports.WorkflowsConfigurationSchema = WorkflowsConfigurationSchema;
48228
+ exports.apiFunctionSchema = apiFunctionSchema;
48217
48229
  exports.balancedMatch = balancedMatch;
48218
48230
  exports.build = build;
48219
48231
  exports.checkVariableType = checkVariableType;
@@ -48224,7 +48236,10 @@ exports.createMockConversation = createMockConversation;
48224
48236
  exports.createMockCustomer = createMockCustomer;
48225
48237
  exports.createMockMessage = createMockMessage;
48226
48238
  exports.createMockWorkflowEvent = createMockWorkflowEvent;
48239
+ exports.deleteApiFunctionSchema = deleteApiFunctionSchema;
48240
+ exports.eventResponseSchema = eventResponseSchema;
48227
48241
  exports.forward = forward;
48242
+ exports.getApiFunctionSchema = getApiFunctionSchema;
48228
48243
  exports.getAugmentedNamespace = getAugmentedNamespace;
48229
48244
  exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
48230
48245
  exports.globSync = globSync;
@@ -48233,7 +48248,11 @@ exports.loadConfig = loadConfig;
48233
48248
  exports.loadEnvConfig = loadEnvConfig;
48234
48249
  exports.loadUserPackageJson = loadUserPackageJson;
48235
48250
  exports.logUserValidationError = logUserValidationError;
48251
+ exports.patchApiFunctionSchema = patchApiFunctionSchema;
48252
+ exports.postApiFunctionSchema = postApiFunctionSchema;
48236
48253
  exports.projectTemplates = projectTemplates;
48254
+ exports.putApiFunctionSchema = putApiFunctionSchema;
48255
+ exports.queryApiFunctionSchema = queryApiFunctionSchema;
48237
48256
  exports.reply = reply;
48238
48257
  exports.report = report;
48239
48258
  exports.requireOptionalProjectFile = requireOptionalProjectFile;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var spirits = require("./spirits-76855e30.cjs");
4
- var dev = require("./dev-df823c44.cjs");
4
+ var dev = require("./dev-60d45091.cjs");
5
5
  var require$$0 = require('fs');
6
6
  var require$$2$1 = require('events');
7
7
  var require$$1 = require('path');
@@ -29482,7 +29482,7 @@ class Body {
29482
29482
  }
29483
29483
  const {
29484
29484
  toFormData
29485
- } = await Promise.resolve().then(function () { return require("./multipart-parser-50a82502.cjs"); });
29485
+ } = await Promise.resolve().then(function () { return require("./multipart-parser-13a3f02b.cjs"); });
29486
29486
  return toFormData(this.body, ct);
29487
29487
  }
29488
29488
 
@@ -41891,7 +41891,7 @@ function _loadUserPackageJson() {
41891
41891
  targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
41892
41892
  _context.t0 = JSON;
41893
41893
  _context.next = 10;
41894
- return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-332067ab.js', document.baseURI).href))), 'utf-8');
41894
+ return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-5ba79b93.js', document.baseURI).href))), 'utf-8');
41895
41895
  case 10:
41896
41896
  _context.t1 = _context.sent;
41897
41897
  pkg = _context.t0.parse.call(_context.t0, _context.t1);
@@ -41964,7 +41964,7 @@ var EventResponse = /*#__PURE__*/function () {
41964
41964
  * @template T
41965
41965
  * @param {T} body - The body of the response.
41966
41966
  * @param {ResponseInit} [options] - Additional options for the response.
41967
- * @returns {EventResponse<T>} A new EventResponse instance.
41967
+ * @returns {EventResponse<T = any>} A new EventResponse instance.
41968
41968
  */
41969
41969
  function json(body, options) {
41970
41970
  return new EventResponse(body, options);
@@ -43097,7 +43097,7 @@ var ProjectFiles = /*#__PURE__*/function () {
43097
43097
  return ProjectFiles;
43098
43098
  }();
43099
43099
 
43100
- var __filename$1 = node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-332067ab.js', document.baseURI).href)));
43100
+ var __filename$1 = node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-5ba79b93.js', document.baseURI).href)));
43101
43101
  var __dirname$1 = path__default["default"].dirname(__filename$1);
43102
43102
  function zipDirectory(source, out) {
43103
43103
  var archive = archiver$1('tar', {
@@ -43312,7 +43312,7 @@ function _buildApp() {
43312
43312
  case 11:
43313
43313
  _context4.t0 = JSON;
43314
43314
  _context4.next = 14;
43315
- return fs__default["default"].readFile(new URL(templatePackagePath, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-332067ab.js', document.baseURI).href))), 'utf-8');
43315
+ return fs__default["default"].readFile(new URL(templatePackagePath, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index-5ba79b93.js', document.baseURI).href))), 'utf-8');
43316
43316
  case 14:
43317
43317
  _context4.t1 = _context4.sent;
43318
43318
  packageTemplate = _context4.t0.parse.call(_context4.t0, _context4.t1);
package/dist/index.cjs CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require("./index-332067ab.cjs");
6
- var dev = require("./dev-df823c44.cjs");
5
+ var index = require("./index-5ba79b93.cjs");
6
+ var dev = require("./dev-60d45091.cjs");
7
7
  require("./spirits-76855e30.cjs");
8
8
  require('fs');
9
9
  require('events');
@@ -47,12 +47,59 @@ exports.did = index.did;
47
47
  exports.json = index.json;
48
48
  exports.run = index.run;
49
49
  exports.sendEvent = index.sendEvent;
50
+ exports.AgentConfigurationSchema = dev.AgentConfigurationSchema;
51
+ exports.AgentSchema = dev.AgentSchema;
52
+ exports.AgentsConfigurationSchema = dev.AgentsConfigurationSchema;
53
+ exports.AgentsSchema = dev.AgentsSchema;
54
+ exports.ContextExampleSchema = dev.ContextExampleSchema;
55
+ exports.ContextExampleWithTrainingDataSchema = dev.ContextExampleWithTrainingDataSchema;
56
+ exports.ConversationAnticipateSchema = dev.ConversationAnticipateSchema;
57
+ exports.ConversationContext = dev.ConversationContext;
58
+ exports.ConversationSchema = dev.ConversationSchema;
59
+ exports.CustomerSchema = dev.CustomerSchema;
60
+ exports.CustomerValueSchema = dev.CustomerValueSchema;
61
+ exports.EntitiesRootConfigurationSchema = dev.EntitiesRootConfigurationSchema;
62
+ exports.EntitiesRootProjectConfigurationSchema = dev.EntitiesRootProjectConfigurationSchema;
63
+ exports.EntityApiConfigurationSchema = dev.EntityApiConfigurationSchema;
64
+ exports.EntityConfigurationSchema = dev.EntityConfigurationSchema;
65
+ exports.EntityRootProjectConfigurationSchema = dev.EntityRootProjectConfigurationSchema;
66
+ exports.FollowupBaseSchema = dev.FollowupBaseSchema;
67
+ exports.FollowupSchema = dev.FollowupSchema;
68
+ exports.ForwardSchema = dev.ForwardSchema;
69
+ exports.InstructionObjectSchema = dev.InstructionObjectSchema;
70
+ exports.InstructionSchema = dev.InstructionSchema;
71
+ exports.IntentWorkflowEventSchema = dev.IntentWorkflowEventSchema;
72
+ exports.MessageSchema = dev.MessageSchema;
73
+ exports.PersonaConfigurationSchema = dev.PersonaConfigurationSchema;
74
+ exports.PersonaSchema = dev.PersonaSchema;
75
+ exports.PersonasConfigurationSchema = dev.PersonasConfigurationSchema;
76
+ exports.PersonasSchema = dev.PersonasSchema;
77
+ exports.Scout9ProjectBuildConfigSchema = dev.Scout9ProjectBuildConfigSchema;
78
+ exports.Scout9ProjectConfigSchema = dev.Scout9ProjectConfigSchema;
50
79
  exports.Scout9Test = dev.Scout9Test;
80
+ exports.WorkflowConfigurationSchema = dev.WorkflowConfigurationSchema;
81
+ exports.WorkflowEventSchema = dev.WorkflowEventSchema;
82
+ exports.WorkflowFunctionSchema = dev.WorkflowFunctionSchema;
83
+ exports.WorkflowResponseMessage = dev.WorkflowResponseMessage;
84
+ exports.WorkflowResponseMessageApiRequest = dev.WorkflowResponseMessageApiRequest;
85
+ exports.WorkflowResponseMessageApiResponse = dev.WorkflowResponseMessageApiResponse;
86
+ exports.WorkflowResponseSchema = dev.WorkflowResponseSchema;
87
+ exports.WorkflowResponseSlotBaseSchema = dev.WorkflowResponseSlotBaseSchema;
88
+ exports.WorkflowResponseSlotSchema = dev.WorkflowResponseSlotSchema;
89
+ exports.WorkflowsConfigurationSchema = dev.WorkflowsConfigurationSchema;
90
+ exports.apiFunctionSchema = dev.apiFunctionSchema;
51
91
  exports.createMockAgent = dev.createMockAgent;
52
92
  exports.createMockConversation = dev.createMockConversation;
53
93
  exports.createMockCustomer = dev.createMockCustomer;
54
94
  exports.createMockMessage = dev.createMockMessage;
55
95
  exports.createMockWorkflowEvent = dev.createMockWorkflowEvent;
96
+ exports.deleteApiFunctionSchema = dev.deleteApiFunctionSchema;
97
+ exports.eventResponseSchema = dev.eventResponseSchema;
56
98
  exports.forward = dev.forward;
99
+ exports.getApiFunctionSchema = dev.getApiFunctionSchema;
57
100
  exports.instruct = dev.instruct;
101
+ exports.patchApiFunctionSchema = dev.patchApiFunctionSchema;
102
+ exports.postApiFunctionSchema = dev.postApiFunctionSchema;
103
+ exports.putApiFunctionSchema = dev.putApiFunctionSchema;
104
+ exports.queryApiFunctionSchema = dev.queryApiFunctionSchema;
58
105
  exports.reply = dev.reply;
@@ -2,9 +2,9 @@
2
2
 
3
3
  require('node:fs');
4
4
  require('node:path');
5
- var index = require("./index-332067ab.cjs");
5
+ var index = require("./index-5ba79b93.cjs");
6
6
  require("./spirits-76855e30.cjs");
7
- require("./dev-df823c44.cjs");
7
+ require("./dev-60d45091.cjs");
8
8
  require('util');
9
9
  require('stream');
10
10
  require('path');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dev = require("./dev-df823c44.cjs");
5
+ var dev = require("./dev-60d45091.cjs");
6
6
  require("./spirits-76855e30.cjs");
7
7
  require('util');
8
8
  require('stream');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scout9/app",
3
- "version": "1.0.0-alpha.0.2.2",
3
+ "version": "1.0.0-alpha.0.2.5",
4
4
  "description": "Build and deploy your Scout9 app for SMS auto replies",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -5,7 +5,7 @@ import bodyParser from 'body-parser';
5
5
  import colors from 'kleur';
6
6
  import { config as dotenv } from 'dotenv';
7
7
  import { Configuration, Scout9Api } from '@scout9/admin';
8
- import { EventResponse, WorkflowEventSchema } from '@scout9/app';
8
+ import { EventResponse, WorkflowEventSchema, WorkflowResponseSchema } from '@scout9/app';
9
9
  import path, { resolve } from 'node:path';
10
10
  import fs from 'node:fs';
11
11
  import https from 'node:https';
@@ -13,6 +13,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
13
13
  import projectApp from './src/app.js';
14
14
  import config from './config.js';
15
15
  import { readdir } from 'fs/promises';
16
+ import { ZodError } from 'zod';
16
17
 
17
18
  const __filename = fileURLToPath(import.meta.url);
18
19
  const __dirname = path.dirname(__filename);
@@ -93,6 +94,10 @@ const handleError = (e, res = undefined) => {
93
94
  }
94
95
  }
95
96
  console.log(colors.red(`${colors.bold(`${code} Error`)}: ${message}`));
97
+ if ('stack' in e) {
98
+ console.log(colors.grey(e.stack));
99
+ }
100
+ console.log(colors)
96
101
  if (res) {
97
102
  res.writeHead(code, {'Content-Type': 'application/json'});
98
103
  res.end(JSON.stringify({
@@ -162,17 +167,54 @@ if (dev) {
162
167
 
163
168
  // Root application POST endpoint will run the scout9 app
164
169
  app.post(dev ? '/dev/workflow' : '/', async (req, res) => {
170
+ let workflowEvent;
165
171
  try {
166
- const event = WorkflowEventSchema.parse(req.body.event);
172
+ workflowEvent = WorkflowEventSchema.parse(req.body.event);
167
173
  globalThis.SCOUT9 = {
168
- ...event,
174
+ ...workflowEvent,
169
175
  $convo: req.body.$convo,
170
176
  }
171
- const response = await projectApp(event);
177
+ } catch (error) {
178
+ if (error instanceof ZodError) {
179
+ const formattedErrors = error.format();
180
+ res.writeHead(400, {'Content-Type': 'application/json'});
181
+ res.end(JSON.stringify({
182
+ status: 'Invalid WorkflowEvent',
183
+ errors: formattedErrors
184
+ }));
185
+ console.log(colors.red(`${colors.bold(`Bad Input Event:`)}: Received: ${JSON.stringify(req.body.event, null, 2)}\n\nErrors:\n\n${JSON.stringify(formattedErrors, null, 2)}`));
186
+ } else {
187
+ error.message = `Workflow Template Event Parse Error: ` + error.message;
188
+ handleError(error, res);
189
+ }
190
+ return;
191
+ }
192
+ if (!workflowEvent) {
193
+ handleError(new Error('No workflowEvent defined'), res);
194
+ }
195
+
196
+ try {
197
+ const response = await projectApp(workflowEvent);
198
+ const formattedResponse = WorkflowEventSchema.parse(response);
199
+ if (dev) {
200
+ console.log(colors.green(`Workflow Sending Response:`));
201
+ console.log(colors.grey(JSON.stringify(formattedResponse, null, 2)));
202
+ }
172
203
  res.writeHead(200, {'Content-Type': 'application/json'});
173
- res.end(JSON.stringify(response));
174
- } catch (e) {
175
- handleError(e, res);
204
+ res.end(JSON.stringify(formattedResponse));
205
+ } catch (error) {
206
+ if (error instanceof ZodError) {
207
+ const formattedErrors = error.format();
208
+ res.writeHead(500, {'Content-Type': 'application/json'});
209
+ res.end(JSON.stringify({
210
+ status: 'Invalid WorkflowResponse',
211
+ errors: formattedErrors
212
+ }));
213
+ console.log(colors.red(`${colors.bold(`Input Workflow Response`)}: Fix needed\n\n${JSON.stringify(formattedErrors, null, 2)}`));
214
+ } else {
215
+ error.message = `Workflow Template Runtime Error: ` + error.message
216
+ handleError(error, res);
217
+ }
176
218
  }
177
219
  });
178
220
 
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/schemas/index.js';
8
9
  export * from './runtime/macros/index.js';
9
10
 
10
11
  /**
package/src/public.d.ts CHANGED
@@ -25,7 +25,7 @@ export function run(event: WorkflowEvent, options: {
25
25
  * @param {ResponseInit | undefined} [init]
26
26
  * @returns {EventResponse<T>}
27
27
  */
28
- export function json<T>(data: T, init?: ResponseInit | undefined): EventResponse<T>;
28
+ export function json<T = any>(data: T, init?: ResponseInit | undefined): EventResponse<T>;
29
29
  /**
30
30
  * @param {WorkflowEvent} event - every workflow receives an event object
31
31
  * @param {Object} options
@@ -47,7 +47,7 @@ export function sendEvent(event: WorkflowEvent, options: {
47
47
  * Utility runtime class used to guide event output
48
48
  * @template T
49
49
  */
50
- export class EventResponse<T> {
50
+ export class EventResponse<T = any> {
51
51
  /**
52
52
  * Create a new EventResponse instance with a JSON body.
53
53
  * @template T
@@ -9,7 +9,7 @@ export class EventResponse {
9
9
  * @template T
10
10
  * @param {T} body - The body of the response.
11
11
  * @param {ResponseInit} [options] - Additional options for the response.
12
- * @returns {EventResponse<T>} A new EventResponse instance.
12
+ * @returns {EventResponse<T = any>} A new EventResponse instance.
13
13
  */
14
14
  static json(body, options) {
15
15
  return new EventResponse(body, options);
@@ -7,14 +7,6 @@ const responseInitSchema = z.object({
7
7
  headers: z.any().optional() // Headers can be complex; adjust as needed
8
8
  });
9
9
 
10
- /**
11
- * @template T
12
- * @typedef {object} IEventResponse
13
- * @property {T} body - The body of the response.
14
- * @property {ResponseInit} [init] - Additional options for the response.
15
- * @property {Response} response - The response object.
16
- * @property {T} data - The body of the response.
17
- */
18
10
  export const eventResponseSchema = z.object({
19
11
  body: z.any(), // Adjust as per your actual body structure
20
12
  init: responseInitSchema.optional()
@@ -2,85 +2,41 @@ import { z } from 'zod';
2
2
  import { eventResponseSchema } from './api.js';
3
3
 
4
4
 
5
- /**
6
- * @typedef {object} IApiFunctionParams
7
- * @property {Object.<string, string|string[]>} searchParams
8
- * @property {Record<string, string>} params
9
- */
10
5
  const apiFunctionParamsSchema = z.object({
11
6
  searchParams: z.record(z.string(), z.union([z.string(), z.array(z.string())])),
12
7
  params: z.record(z.string(), z.string())
13
8
  });
14
9
 
15
- /**
16
- * @typedef {IApiFunctionParams & { id: string }} IApiEntityFunctionParams
17
- */
18
10
  const apiEntityFunctionParamsSchema = apiFunctionParamsSchema.extend({
19
11
  id: z.string()
20
12
  });
21
13
 
22
- /**
23
- * @template Params
24
- * @template Response
25
- * @typedef {function(IApiFunctionParams): Promise<EventResponse>} IApiFunction
26
- */
27
14
  export const apiFunctionSchema = z.function()
28
15
  .args(apiFunctionParamsSchema)
29
16
  .returns(z.promise(eventResponseSchema));
30
17
 
31
- /**
32
- * @template Params
33
- * @template Response
34
- * @typedef {IApiFunction<Params, Response>} IQueryApiFunction
35
- */
36
18
  export const queryApiFunctionSchema = apiFunctionSchema;
37
19
 
38
- /**
39
- * @template Params
40
- * @template Response
41
- * @typedef {IApiFunction<Params, Response>} GetApiFunction
42
- */
43
20
  export const getApiFunctionSchema = apiFunctionSchema;
44
21
 
45
- /**
46
- * @template Params
47
- * @template RequestBody
48
- * @template Response
49
- * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPostApiFunction
50
- */
51
22
  export const postApiFunctionSchema = (requestBodySchema) => z.function()
52
23
  .args(apiFunctionParamsSchema.extend({
53
24
  body: requestBodySchema.partial()
54
25
  }))
55
26
  .returns(z.promise(eventResponseSchema));
56
27
 
57
- /**
58
- * @template Params
59
- * @template RequestBody
60
- * @template Response
61
- * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPutApiFunction
62
- */
28
+
63
29
  export const putApiFunctionSchema = (requestBodySchema) => z.function()
64
30
  .args(apiFunctionParamsSchema.extend({
65
31
  body: requestBodySchema.partial()
66
32
  }))
67
33
  .returns(z.promise(eventResponseSchema));
68
34
 
69
- /**
70
- * @template Params
71
- * @template RequestBody
72
- * @template Response
73
- * @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPatchApiFunction
74
- */
35
+
75
36
  export const patchApiFunctionSchema = (requestBodySchema) => z.function()
76
37
  .args(apiFunctionParamsSchema.extend({
77
38
  body: requestBodySchema.partial()
78
39
  }))
79
40
  .returns(z.promise(eventResponseSchema));
80
41
 
81
- /**
82
- * @template Params
83
- * @template Response
84
- * @typedef {IApiFunction<Params, Response>} IDeleteApiFunction
85
- */
86
42
  export const deleteApiFunctionSchema = apiFunctionSchema;
@@ -65,19 +65,3 @@ export const PersonasConfigurationSchema = z.array(PersonaConfigurationSchema);
65
65
  export const AgentsSchema = z.array(AgentSchema);
66
66
 
67
67
  export const PersonasSchema = z.array(PersonaSchema);
68
-
69
-
70
- export const Bus = z.object({
71
- foo: z.string(),
72
- bar: z.boolean().optional()
73
- });
74
- export const Baz = z.object({
75
- boo: z.object({
76
- one: z.number(),
77
- two: z.number().optional()
78
- })
79
- })
80
- export const TestSchema = z.object({
81
- baz: Baz,
82
- bus: Bus
83
- });
package/src/schemas.js ADDED
@@ -0,0 +1 @@
1
+ export * from './runtime/schemas/index.js';