@botpress/runtime 1.6.10 → 1.7.1

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.
Files changed (36) hide show
  1. package/dist/definition.js +115 -13
  2. package/dist/definition.js.map +4 -4
  3. package/dist/internal.d.ts +1 -0
  4. package/dist/internal.d.ts.map +1 -1
  5. package/dist/internal.js +329 -216
  6. package/dist/internal.js.map +4 -4
  7. package/dist/library.js +294 -190
  8. package/dist/library.js.map +4 -4
  9. package/dist/primitives/action.d.ts +7 -3
  10. package/dist/primitives/action.d.ts.map +1 -1
  11. package/dist/primitives/table.d.ts +11 -7
  12. package/dist/primitives/table.d.ts.map +1 -1
  13. package/dist/primitives/workflow.d.ts +18 -0
  14. package/dist/primitives/workflow.d.ts.map +1 -1
  15. package/dist/runtime/actions/computed-columns.d.ts +42 -0
  16. package/dist/runtime/actions/computed-columns.d.ts.map +1 -0
  17. package/dist/runtime/actions/index.d.ts +47 -0
  18. package/dist/runtime/actions/index.d.ts.map +1 -0
  19. package/dist/runtime/adk.d.ts.map +1 -1
  20. package/dist/runtime/context/http.d.ts +1 -1
  21. package/dist/runtime/context/http.d.ts.map +1 -1
  22. package/dist/runtime/handlers/actions.d.ts +3 -0
  23. package/dist/runtime/handlers/actions.d.ts.map +1 -0
  24. package/dist/runtime/handlers/event.d.ts.map +1 -1
  25. package/dist/runtime/handlers/index.d.ts +2 -0
  26. package/dist/runtime/handlers/index.d.ts.map +1 -1
  27. package/dist/runtime.js +205 -69
  28. package/dist/runtime.js.map +4 -4
  29. package/dist/telemetry/spans/index.d.ts +0 -52
  30. package/dist/telemetry/spans/index.d.ts.map +1 -1
  31. package/dist/ui.js +1 -2
  32. package/dist/ui.js.map +2 -2
  33. package/dist/workers/dev_worker.d.ts.map +1 -1
  34. package/dist/workers/parent_worker.d.ts.map +1 -1
  35. package/dist/workers/worker_pool.d.ts.map +1 -1
  36. package/package.json +1 -1
package/dist/internal.js CHANGED
@@ -48,7 +48,7 @@ var init_define_BUILD = __esm({
48
48
  var define_PACKAGE_VERSIONS_default;
49
49
  var init_define_PACKAGE_VERSIONS = __esm({
50
50
  "<define:__PACKAGE_VERSIONS__>"() {
51
- define_PACKAGE_VERSIONS_default = { runtime: "1.6.10", adk: "not-installed", sdk: "4.17.3", llmz: "0.0.27", zai: "2.5.0", cognitive: "0.2.0" };
51
+ define_PACKAGE_VERSIONS_default = { runtime: "1.7.1", adk: "1.7.0", sdk: "4.18.1", llmz: "0.0.27", zai: "2.5.0", cognitive: "0.2.0" };
52
52
  }
53
53
  });
54
54
 
@@ -27678,11 +27678,11 @@ function expand_(str, isTop) {
27678
27678
  if (pad) {
27679
27679
  const need = width - c.length;
27680
27680
  if (need > 0) {
27681
- const z25 = new Array(need + 1).join("0");
27681
+ const z26 = new Array(need + 1).join("0");
27682
27682
  if (i < 0) {
27683
- c = "-" + z25 + c.slice(1);
27683
+ c = "-" + z26 + c.slice(1);
27684
27684
  } else {
27685
- c = z25 + c;
27685
+ c = z26 + c;
27686
27686
  }
27687
27687
  }
27688
27688
  }
@@ -34305,7 +34305,7 @@ init_define_PACKAGE_VERSIONS();
34305
34305
  // src/primitives/workflow-instance.ts
34306
34306
  init_define_BUILD();
34307
34307
  init_define_PACKAGE_VERSIONS();
34308
- import { z as z17 } from "@botpress/sdk";
34308
+ import { z as z19 } from "@botpress/sdk";
34309
34309
  import assert2 from "assert";
34310
34310
 
34311
34311
  // src/errors.ts
@@ -34480,7 +34480,7 @@ ${issues.join("\n")}`;
34480
34480
  // src/library.ts
34481
34481
  init_define_BUILD();
34482
34482
  init_define_PACKAGE_VERSIONS();
34483
- import { z as z15 } from "@botpress/sdk";
34483
+ import { z as z17 } from "@botpress/sdk";
34484
34484
 
34485
34485
  // src/runtime/index.ts
34486
34486
  init_define_BUILD();
@@ -35838,8 +35838,7 @@ var ActionHandlerSpan = {
35838
35838
  name: "handler.action",
35839
35839
  importance: "high",
35840
35840
  attributes: {
35841
- ...required("botId", "workflowId", "eventId", "event.type"),
35842
- ...optional("messageId", "userId", "integration", "channel", "conversationId", "parentWorkflowId"),
35841
+ ...required("botId"),
35843
35842
  "action.name": { type: "string", required: true },
35844
35843
  "action.input": { type: "json", required: true }
35845
35844
  }
@@ -36407,7 +36406,7 @@ var agentRegistry = getSingleton("__ADK_GLOBAL_AGENT_REGISTRY", () => new AgentR
36407
36406
  // src/runtime/tracked-state.ts
36408
36407
  init_define_BUILD();
36409
36408
  init_define_PACKAGE_VERSIONS();
36410
- import { z as z9 } from "@botpress/sdk";
36409
+ import { z as z11 } from "@botpress/sdk";
36411
36410
 
36412
36411
  // ../../node_modules/.bun/axios@1.12.2/node_modules/axios/index.js
36413
36412
  init_define_BUILD();
@@ -40693,7 +40692,7 @@ var actions = new Proxy({}, {
40693
40692
  const botAction = adk.project.actions.find((a) => a.name === propertyName);
40694
40693
  if (botAction) {
40695
40694
  const handler = async (input) => {
40696
- return botAction.handler(input);
40695
+ return await botAction.handler(input);
40697
40696
  };
40698
40697
  handler.asTool = () => new Autonomous.Tool({
40699
40698
  name: botAction.name,
@@ -41157,6 +41156,40 @@ var BaseWorkflow = class {
41157
41156
  workflow: res.workflow
41158
41157
  });
41159
41158
  }
41159
+ /**
41160
+ * Convert this workflow into an Autonomous.Tool that can be used with execute().
41161
+ * Starts the workflow and returns basic information about the workflow instance.
41162
+ *
41163
+ * @param options.description - Optional description override for the tool
41164
+ * @returns An Autonomous.Tool instance
41165
+ *
41166
+ * @example
41167
+ * const tool = MyWorkflow.asTool()
41168
+ *
41169
+ * await execute({
41170
+ * tools: [tool],
41171
+ * instructions: 'Use the workflow when needed'
41172
+ * })
41173
+ */
41174
+ asTool(options) {
41175
+ const description = options?.description || this.description || `Starts the ${this.name} workflow`;
41176
+ return new Autonomous.Tool({
41177
+ name: this.name,
41178
+ description,
41179
+ input: this._inputSchema,
41180
+ output: z5.object({
41181
+ workflowId: z5.string().describe("The ID of the started workflow"),
41182
+ status: z5.string().describe("The initial status of the workflow")
41183
+ }),
41184
+ handler: async (input) => {
41185
+ const instance = await this.start(input);
41186
+ return {
41187
+ workflowId: instance.id,
41188
+ status: instance.status
41189
+ };
41190
+ }
41191
+ });
41192
+ }
41160
41193
  };
41161
41194
 
41162
41195
  // src/runtime/workflows/knowledge-indexing.ts
@@ -41268,6 +41301,140 @@ var BuiltInWorkflows = {
41268
41301
 
41269
41302
  // src/runtime/adk.ts
41270
41303
  import { Zai } from "@botpress/zai";
41304
+
41305
+ // src/runtime/actions/index.ts
41306
+ init_define_BUILD();
41307
+ init_define_PACKAGE_VERSIONS();
41308
+
41309
+ // src/runtime/actions/computed-columns.ts
41310
+ init_define_BUILD();
41311
+ init_define_PACKAGE_VERSIONS();
41312
+ import { z as z9 } from "@botpress/sdk";
41313
+
41314
+ // src/primitives/action.ts
41315
+ init_define_BUILD();
41316
+ init_define_PACKAGE_VERSIONS();
41317
+ import { transforms } from "@botpress/sdk";
41318
+ var Typings3;
41319
+ ((Typings8) => {
41320
+ Typings8.Primitive = "action";
41321
+ })(Typings3 || (Typings3 = {}));
41322
+ var BaseAction = class {
41323
+ name;
41324
+ title;
41325
+ description;
41326
+ attributes;
41327
+ input;
41328
+ output;
41329
+ cached;
41330
+ handler;
41331
+ constructor(props) {
41332
+ if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(props.name)) {
41333
+ throw new Error(`Action name "${props.name}" must be alphanumeric with no special characters or spaces`);
41334
+ }
41335
+ this.name = props.name;
41336
+ if (props.title !== void 0) {
41337
+ this.title = props.title;
41338
+ }
41339
+ if (props.description !== void 0) {
41340
+ this.description = props.description;
41341
+ }
41342
+ if (props.attributes !== void 0) {
41343
+ this.attributes = props.attributes;
41344
+ }
41345
+ this.input = props.input;
41346
+ this.output = props.output;
41347
+ this.cached = props.cached ?? false;
41348
+ this.handler = props.handler;
41349
+ }
41350
+ /** @internal */
41351
+ getDefinition() {
41352
+ const def = {
41353
+ type: "action",
41354
+ name: this.name
41355
+ };
41356
+ if (this.title !== void 0) {
41357
+ def.title = this.title;
41358
+ }
41359
+ if (this.description !== void 0) {
41360
+ def.description = this.description;
41361
+ }
41362
+ if (this.input) {
41363
+ def.input = transforms.toJSONSchema(this.input);
41364
+ }
41365
+ if (this.output) {
41366
+ def.output = transforms.toJSONSchema(this.output);
41367
+ }
41368
+ if (this.cached !== void 0) {
41369
+ def.cached = this.cached;
41370
+ }
41371
+ if (this.attributes !== void 0) {
41372
+ def.attributes = this.attributes;
41373
+ }
41374
+ return def;
41375
+ }
41376
+ /**
41377
+ * Execute the action with input validation and output validation
41378
+ */
41379
+ async execute({ input, client }) {
41380
+ return await this.handler({ input, client });
41381
+ }
41382
+ };
41383
+
41384
+ // src/runtime/actions/computed-columns.ts
41385
+ var tablesRecomputeRows = new BaseAction({
41386
+ name: "tablesRecomputeRows",
41387
+ // skynet/packages/tables-api/src/services/computed/compute-stale-rows.ts
41388
+ input: z9.object({
41389
+ tableId: z9.string(),
41390
+ botId: z9.string(),
41391
+ schema: z9.any(),
41392
+ requests: z9.array(
41393
+ z9.object({
41394
+ row: z9.record(z9.any()),
41395
+ columnsToRecompute: z9.array(z9.string())
41396
+ })
41397
+ )
41398
+ }),
41399
+ output: z9.object({
41400
+ isFinished: z9.boolean(),
41401
+ rows: z9.array(z9.any())
41402
+ }),
41403
+ handler: async ({ input, client }) => {
41404
+ const { tableId, requests } = input;
41405
+ const { table: remoteTable } = await client._inner.getTable({ table: tableId });
41406
+ const table = adk.project.tables.find((x) => x.name === remoteTable.name);
41407
+ async function computeRow(row, columnsToRecompute) {
41408
+ const newRow = { id: row.id };
41409
+ for (const colName of columnsToRecompute) {
41410
+ const col = table?.columns[colName];
41411
+ if (!col || !col.computed) {
41412
+ newRow[colName] = { status: "error", error: "Column not found or not computed" };
41413
+ continue;
41414
+ }
41415
+ newRow[colName] = {
41416
+ status: "computed",
41417
+ value: await col.value(row)
41418
+ };
41419
+ }
41420
+ return newRow;
41421
+ }
41422
+ const computedRows = await Promise.all(
41423
+ requests.map(async (r) => {
41424
+ const computedRow = await computeRow(r.row, r.columnsToRecompute);
41425
+ return computedRow;
41426
+ })
41427
+ );
41428
+ return { isFinished: true, rows: computedRows };
41429
+ }
41430
+ });
41431
+
41432
+ // src/runtime/actions/index.ts
41433
+ var BuiltInActions = {
41434
+ tablesRecomputeRows
41435
+ };
41436
+
41437
+ // src/runtime/adk.ts
41271
41438
  var getState = () => getSingleton("__ADK_GLOBAL_PROJECT", () => {
41272
41439
  const state = {
41273
41440
  initialized: false,
@@ -41346,12 +41513,12 @@ var importScheduledHeavyImports = async () => {
41346
41513
  // src/runtime/tracked-state-schema.ts
41347
41514
  init_define_BUILD();
41348
41515
  init_define_PACKAGE_VERSIONS();
41349
- import { z as z8 } from "@botpress/sdk";
41350
- var TrackedStateSchema = z8.object({
41351
- value: z8.any(),
41352
- location: z8.discriminatedUnion("type", [
41353
- z8.object({ type: z8.literal("state") }),
41354
- z8.object({ type: z8.literal("file"), key: z8.string() })
41516
+ import { z as z10 } from "@botpress/sdk";
41517
+ var TrackedStateSchema = z10.object({
41518
+ value: z10.any(),
41519
+ location: z10.discriminatedUnion("type", [
41520
+ z10.object({ type: z10.literal("state") }),
41521
+ z10.object({ type: z10.literal("file"), key: z10.string() })
41355
41522
  ])
41356
41523
  });
41357
41524
 
@@ -41448,7 +41615,7 @@ var TrackedState = class _TrackedState {
41448
41615
  name: BUILT_IN_STATES.bot,
41449
41616
  type: "bot",
41450
41617
  id: botId,
41451
- schema: adk.project.config.bot?.state || z9.object({})
41618
+ schema: adk.project.config.bot?.state || z11.object({})
41452
41619
  });
41453
41620
  }
41454
41621
  if (user2) {
@@ -41457,7 +41624,7 @@ var TrackedState = class _TrackedState {
41457
41624
  name: BUILT_IN_STATES.user,
41458
41625
  type: "user",
41459
41626
  id: user2.id,
41460
- schema: adk.project.config.user?.state || z9.object({})
41627
+ schema: adk.project.config.user?.state || z11.object({})
41461
41628
  });
41462
41629
  }
41463
41630
  if (conversation) {
@@ -41474,7 +41641,7 @@ var TrackedState = class _TrackedState {
41474
41641
  name: BUILT_IN_STATES.conversation,
41475
41642
  type: "conversation",
41476
41643
  id: conversation.id,
41477
- schema: definition?.schema || z9.object({})
41644
+ schema: definition?.schema || z11.object({})
41478
41645
  });
41479
41646
  }
41480
41647
  const states = context.get("states", { optional: true });
@@ -41706,48 +41873,48 @@ init_define_PACKAGE_VERSIONS();
41706
41873
  // src/runtime/events.ts
41707
41874
  init_define_BUILD();
41708
41875
  init_define_PACKAGE_VERSIONS();
41709
- import { z as z10 } from "@botpress/sdk";
41876
+ import { z as z12 } from "@botpress/sdk";
41710
41877
  var WorkflowCallbackEvent = {
41711
41878
  name: "workflowCallback",
41712
- schema: z10.object({
41713
- workflow: z10.string(),
41714
- workflowId: z10.string(),
41715
- target: z10.union([
41716
- z10.object({
41717
- conversationId: z10.string()
41879
+ schema: z12.object({
41880
+ workflow: z12.string(),
41881
+ workflowId: z12.string(),
41882
+ target: z12.union([
41883
+ z12.object({
41884
+ conversationId: z12.string()
41718
41885
  }),
41719
- z10.object({
41720
- workflowId: z10.string()
41886
+ z12.object({
41887
+ workflowId: z12.string()
41721
41888
  })
41722
41889
  ]),
41723
- status: z10.enum(["completed", "failed", "canceled", "timed_out"]),
41724
- output: z10.any().optional(),
41725
- error: z10.string().optional()
41890
+ status: z12.enum(["completed", "failed", "canceled", "timed_out"]),
41891
+ output: z12.any().optional(),
41892
+ error: z12.string().optional()
41726
41893
  })
41727
41894
  };
41728
41895
  var WorkflowScheduleEvent = {
41729
41896
  name: "workflowSchedule",
41730
- schema: z10.object({
41731
- workflow: z10.string()
41897
+ schema: z12.object({
41898
+ workflow: z12.string()
41732
41899
  })
41733
41900
  };
41734
41901
  var WorkflowContinueEvent = {
41735
41902
  name: "workflowContinue",
41736
- schema: z10.object({})
41903
+ schema: z12.object({})
41737
41904
  };
41738
41905
  var SubworkflowFinished = {
41739
41906
  name: "subworkflowFinished",
41740
- schema: z10.object({})
41907
+ schema: z12.object({})
41741
41908
  };
41742
41909
  var WorkflowDataRequestEvent2 = {
41743
41910
  name: "workflowDataRequest",
41744
- schema: z10.object({
41745
- workflowId: z10.string(),
41746
- workflowName: z10.string(),
41747
- stepName: z10.string(),
41748
- request: z10.string(),
41749
- message: z10.string(),
41750
- schema: z10.any()
41911
+ schema: z12.object({
41912
+ workflowId: z12.string(),
41913
+ workflowName: z12.string(),
41914
+ stepName: z12.string(),
41915
+ request: z12.string(),
41916
+ message: z12.string(),
41917
+ schema: z12.any()
41751
41918
  // JSON Schema
41752
41919
  })
41753
41920
  };
@@ -41772,7 +41939,7 @@ init_define_PACKAGE_VERSIONS();
41772
41939
  // src/runtime/chat/messages.ts
41773
41940
  init_define_BUILD();
41774
41941
  init_define_PACKAGE_VERSIONS();
41775
- import { z as z11 } from "@bpinternal/zui";
41942
+ import { z as z13 } from "@bpinternal/zui";
41776
41943
  import { isAnyComponent } from "llmz";
41777
41944
 
41778
41945
  // src/runtime/chat/html.ts
@@ -41910,13 +42077,13 @@ function joinMarkdownChildren(children, stringify3 = (el) => JSON.stringify(el,
41910
42077
  return [...acc, prev, str];
41911
42078
  }, []).join("").trim();
41912
42079
  }
41913
- var Message = z11.object({
41914
- __jsx: z11.literal(true),
41915
- type: z11.literal("MESSAGE"),
41916
- props: z11.object({
41917
- type: z11.enum(["error", "info", "success", "prompt"]).default("info").catch(() => "info")
42080
+ var Message = z13.object({
42081
+ __jsx: z13.literal(true),
42082
+ type: z13.literal("MESSAGE"),
42083
+ props: z13.object({
42084
+ type: z13.enum(["error", "info", "success", "prompt"]).default("info").catch(() => "info")
41918
42085
  }).passthrough(),
41919
- children: z11.array(z11.any()).default([]).transform((children) => {
42086
+ children: z13.array(z13.any()).default([]).transform((children) => {
41920
42087
  children = children.map((child) => Array.isArray(child) ? child : [child]).flat();
41921
42088
  const text = joinMarkdownChildren(
41922
42089
  children.filter((x) => !isAnyComponent(x)).map((x) => rebuildTSXCode(x, false))
@@ -42098,21 +42265,21 @@ init_define_PACKAGE_VERSIONS();
42098
42265
  // src/runtime/chat/transcript.ts
42099
42266
  init_define_BUILD();
42100
42267
  init_define_PACKAGE_VERSIONS();
42101
- import { z as z12 } from "@botpress/sdk";
42102
- var AttachmentSchema = z12.object({
42103
- type: z12.literal("image"),
42104
- url: z12.string()
42105
- });
42106
- var TranscriptItemSchema = z12.object({
42107
- id: z12.string(),
42108
- role: z12.union([z12.literal("assistant"), z12.literal("user"), z12.literal("event"), z12.literal("summary")]),
42109
- name: z12.string().optional(),
42110
- createdAt: z12.string().optional(),
42111
- content: z12.string().optional(),
42112
- attachments: z12.array(AttachmentSchema).optional(),
42113
- payload: z12.unknown().optional()
42114
- });
42115
- var TranscriptSchema = z12.array(TranscriptItemSchema);
42268
+ import { z as z14 } from "@botpress/sdk";
42269
+ var AttachmentSchema = z14.object({
42270
+ type: z14.literal("image"),
42271
+ url: z14.string()
42272
+ });
42273
+ var TranscriptItemSchema = z14.object({
42274
+ id: z14.string(),
42275
+ role: z14.union([z14.literal("assistant"), z14.literal("user"), z14.literal("event"), z14.literal("summary")]),
42276
+ name: z14.string().optional(),
42277
+ createdAt: z14.string().optional(),
42278
+ content: z14.string().optional(),
42279
+ attachments: z14.array(AttachmentSchema).optional(),
42280
+ payload: z14.unknown().optional()
42281
+ });
42282
+ var TranscriptSchema = z14.array(TranscriptItemSchema);
42116
42283
 
42117
42284
  // src/runtime/handlers/index.ts
42118
42285
  init_define_BUILD();
@@ -42125,7 +42292,7 @@ init_define_PACKAGE_VERSIONS();
42125
42292
  // src/primitives/conversation.ts
42126
42293
  init_define_BUILD();
42127
42294
  init_define_PACKAGE_VERSIONS();
42128
- import { z as z13 } from "@botpress/sdk";
42295
+ import { z as z15 } from "@botpress/sdk";
42129
42296
  import { setTimeout as setTimeout2 } from "node:timers/promises";
42130
42297
 
42131
42298
  // src/primitives/conversation-instance.ts
@@ -42245,10 +42412,10 @@ var BaseConversationInstance = class {
42245
42412
 
42246
42413
  // src/primitives/conversation.ts
42247
42414
  var ConversationHandler = Symbol.for("conversation.handler");
42248
- var Typings3;
42415
+ var Typings4;
42249
42416
  ((Typings8) => {
42250
42417
  Typings8.Primitive = "conversation";
42251
- })(Typings3 || (Typings3 = {}));
42418
+ })(Typings4 || (Typings4 = {}));
42252
42419
  var BaseConversation = class {
42253
42420
  channel;
42254
42421
  /** @internal */
@@ -42257,7 +42424,7 @@ var BaseConversation = class {
42257
42424
  #startFromTrigger;
42258
42425
  constructor(props) {
42259
42426
  this.channel = props.channel;
42260
- this.schema = props.state ?? z13.object({}).passthrough();
42427
+ this.schema = props.state ?? z15.object({}).passthrough();
42261
42428
  this.#handler = props.handler;
42262
42429
  if (props.startFromTrigger) {
42263
42430
  this.#startFromTrigger = props.startFromTrigger;
@@ -42457,13 +42624,17 @@ var import_ms2 = __toESM(require_ms(), 1);
42457
42624
  init_define_BUILD();
42458
42625
  init_define_PACKAGE_VERSIONS();
42459
42626
 
42627
+ // src/runtime/handlers/actions.ts
42628
+ init_define_BUILD();
42629
+ init_define_PACKAGE_VERSIONS();
42630
+
42460
42631
  // src/primitives/workflow-step.ts
42461
42632
  init_define_BUILD();
42462
42633
  init_define_PACKAGE_VERSIONS();
42463
42634
  import { ulid } from "ulid";
42464
42635
  import assert from "assert";
42465
42636
  import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
42466
- import { transforms } from "@botpress/sdk";
42637
+ import { transforms as transforms2 } from "@botpress/sdk";
42467
42638
  var DEFAULT_MAX_ATTEMPTS = 5;
42468
42639
  var MIN_STEP_REMAINING_TIME_MS = 1e4;
42469
42640
  var storage2 = getSingleton("__ADK_GLOBAL_CTX_WORKFLOW_STEP", () => new AsyncLocalStorage3());
@@ -42830,7 +43001,7 @@ step.request = async (request, message, stepName) => {
42830
43001
  stepName: actualStepName,
42831
43002
  request,
42832
43003
  message,
42833
- schema: transforms.toJSONSchema(requestSchema)
43004
+ schema: transforms2.toJSONSchema(requestSchema)
42834
43005
  }
42835
43006
  });
42836
43007
  await updateWorkflow({
@@ -42848,25 +43019,25 @@ step.request = async (request, message, stepName) => {
42848
43019
  };
42849
43020
 
42850
43021
  // src/primitives/workflow-instance.ts
42851
- var workflowStepContextSchema = z17.lazy(
42852
- () => z17.object({
42853
- output: z17.unknown().optional(),
42854
- attempts: z17.number(),
42855
- i: z17.number().optional(),
42856
- startedAt: z17.string(),
42857
- finishedAt: z17.string().optional(),
42858
- steps: z17.record(z17.string(), workflowStepContextSchema).optional(),
42859
- error: z17.object({
42860
- message: z17.string(),
42861
- failedAt: z17.string(),
42862
- maxAttemptsReached: z17.boolean()
43022
+ var workflowStepContextSchema = z19.lazy(
43023
+ () => z19.object({
43024
+ output: z19.unknown().optional(),
43025
+ attempts: z19.number(),
43026
+ i: z19.number().optional(),
43027
+ startedAt: z19.string(),
43028
+ finishedAt: z19.string().optional(),
43029
+ steps: z19.record(z19.string(), workflowStepContextSchema).optional(),
43030
+ error: z19.object({
43031
+ message: z19.string(),
43032
+ failedAt: z19.string(),
43033
+ maxAttemptsReached: z19.boolean()
42863
43034
  }).optional()
42864
43035
  })
42865
43036
  );
42866
- var workflowExecutionContextSchema = z17.object({
42867
- executionCount: z17.number().default(0),
42868
- revision: z17.number().default(0),
42869
- steps: z17.record(z17.string(), workflowStepContextSchema)
43037
+ var workflowExecutionContextSchema = z19.object({
43038
+ executionCount: z19.number().default(0),
43039
+ revision: z19.number().default(0),
43040
+ steps: z19.record(z19.string(), workflowStepContextSchema)
42870
43041
  }).default({
42871
43042
  executionCount: 0,
42872
43043
  steps: {}
@@ -43105,45 +43276,45 @@ function createWorkflowExecutionState(client, workflowId) {
43105
43276
  // src/primitives/definition.ts
43106
43277
  init_define_BUILD();
43107
43278
  init_define_PACKAGE_VERSIONS();
43108
- import { z as z18 } from "@botpress/sdk";
43279
+ import { z as z20 } from "@botpress/sdk";
43109
43280
  var Definitions;
43110
43281
  ((Definitions2) => {
43111
- const conversationDefinitionSchema = z18.object({
43112
- type: z18.literal("conversation"),
43113
- channel: z18.union([
43114
- z18.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^(\*|[a-zA-Z0-9._-]+)$/, "Channel must be a valid identifier or glob '*'"),
43115
- z18.array(
43116
- z18.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^[a-zA-Z0-9._-]+$/, "Channel must be a valid identifier")
43282
+ const conversationDefinitionSchema = z20.object({
43283
+ type: z20.literal("conversation"),
43284
+ channel: z20.union([
43285
+ z20.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^(\*|[a-zA-Z0-9._-]+)$/, "Channel must be a valid identifier or glob '*'"),
43286
+ z20.array(
43287
+ z20.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^[a-zA-Z0-9._-]+$/, "Channel must be a valid identifier")
43117
43288
  )
43118
43289
  ])
43119
43290
  });
43120
- const workflowDefinitionSchema = z18.object({
43121
- type: z18.literal("workflow"),
43122
- name: z18.string().min(1, "Name must be a non-empty string").max(255, "Name must be less than 255 characters").regex(/^[a-zA-Z0-9_-]+$/, "Name must be a valid identifier")
43291
+ const workflowDefinitionSchema = z20.object({
43292
+ type: z20.literal("workflow"),
43293
+ name: z20.string().min(1, "Name must be a non-empty string").max(255, "Name must be less than 255 characters").regex(/^[a-zA-Z0-9_-]+$/, "Name must be a valid identifier")
43123
43294
  });
43124
- const knowledgeDefinitionSchema = z18.object({
43125
- type: z18.literal("knowledge"),
43126
- name: z18.string().min(1, "Name must be a non-empty string").max(255, "Name must be less than 255 characters").regex(/^[a-zA-Z0-9_-]+$/, "Name must be a valid identifier")
43295
+ const knowledgeDefinitionSchema = z20.object({
43296
+ type: z20.literal("knowledge"),
43297
+ name: z20.string().min(1, "Name must be a non-empty string").max(255, "Name must be less than 255 characters").regex(/^[a-zA-Z0-9_-]+$/, "Name must be a valid identifier")
43127
43298
  });
43128
- const triggerDefinitionSchema = z18.object({
43129
- type: z18.literal("trigger"),
43130
- name: z18.string().min(1, "Name must be a non-empty string").max(255, "Name must be less than 255 characters").regex(/^[a-zA-Z0-9_-]+$/, "Name must be a valid identifier")
43299
+ const triggerDefinitionSchema = z20.object({
43300
+ type: z20.literal("trigger"),
43301
+ name: z20.string().min(1, "Name must be a non-empty string").max(255, "Name must be less than 255 characters").regex(/^[a-zA-Z0-9_-]+$/, "Name must be a valid identifier")
43131
43302
  });
43132
- const actionDefinitionSchema = z18.object({
43133
- type: z18.literal("action"),
43134
- name: z18.string().min(1, "Name must be a non-empty string").max(255, "Name must be less than 255 characters").regex(/^[a-zA-Z][a-zA-Z0-9]*$/, "Name must be alphanumeric with no special characters"),
43135
- title: z18.string().optional(),
43136
- description: z18.string().optional(),
43137
- attributes: z18.record(z18.string()).optional(),
43138
- input: z18.any().optional(),
43303
+ const actionDefinitionSchema = z20.object({
43304
+ type: z20.literal("action"),
43305
+ name: z20.string().min(1, "Name must be a non-empty string").max(255, "Name must be less than 255 characters").regex(/^[a-zA-Z][a-zA-Z0-9]*$/, "Name must be alphanumeric with no special characters"),
43306
+ title: z20.string().optional(),
43307
+ description: z20.string().optional(),
43308
+ attributes: z20.record(z20.string()).optional(),
43309
+ input: z20.any().optional(),
43139
43310
  // JSONSchema7
43140
- output: z18.any().optional(),
43311
+ output: z20.any().optional(),
43141
43312
  // JSONSchema7
43142
- cached: z18.boolean().optional()
43313
+ cached: z20.boolean().optional()
43143
43314
  });
43144
- const tableDefinitionSchema = z18.object({
43145
- type: z18.literal("table"),
43146
- name: z18.string().min(1, "Name must be a non-empty string").max(255, "Name must be less than 255 characters").regex(/^[a-zA-Z0-9_-]+$/, "Name must be a valid identifier")
43315
+ const tableDefinitionSchema = z20.object({
43316
+ type: z20.literal("table"),
43317
+ name: z20.string().min(1, "Name must be a non-empty string").max(255, "Name must be less than 255 characters").regex(/^[a-zA-Z0-9_-]+$/, "Name must be a valid identifier")
43147
43318
  });
43148
43319
  function isConversationDefinition(value) {
43149
43320
  return conversationDefinitionSchema.safeParse(value).success;
@@ -43199,7 +43370,7 @@ init_define_PACKAGE_VERSIONS();
43199
43370
  // src/primitives/data-sources/source-table.ts
43200
43371
  init_define_BUILD();
43201
43372
  init_define_PACKAGE_VERSIONS();
43202
- import { z as z19 } from "@botpress/sdk";
43373
+ import { z as z21 } from "@botpress/sdk";
43203
43374
  var TableSource = class _TableSource extends DataSource {
43204
43375
  table;
43205
43376
  transformFn;
@@ -43211,7 +43382,7 @@ var TableSource = class _TableSource extends DataSource {
43211
43382
  get syncWorkflow() {
43212
43383
  return createSyncWorkflow({
43213
43384
  type: "table",
43214
- state: z19.object({ offset: z19.number().default(0) }),
43385
+ state: z21.object({ offset: z21.number().default(0) }),
43215
43386
  handler: async () => {
43216
43387
  throw new Error("TableSource synchronization not implemented");
43217
43388
  }
@@ -43226,7 +43397,7 @@ var TableSource = class _TableSource extends DataSource {
43226
43397
  // src/primitives/data-sources/source-website.ts
43227
43398
  init_define_BUILD();
43228
43399
  init_define_PACKAGE_VERSIONS();
43229
- import { z as z20 } from "@botpress/sdk";
43400
+ import { z as z22 } from "@botpress/sdk";
43230
43401
 
43231
43402
  // ../../node_modules/.bun/fast-xml-parser@5.3.0/node_modules/fast-xml-parser/src/fxp.js
43232
43403
  init_define_BUILD();
@@ -44779,16 +44950,16 @@ async function fetchHtml(url2, options) {
44779
44950
  }
44780
44951
 
44781
44952
  // src/primitives/data-sources/source-website.ts
44782
- var State = z20.object({
44783
- urls: z20.array(
44784
- z20.object({
44785
- loc: z20.string(),
44786
- lastmod: z20.string().optional(),
44787
- changefreq: z20.string().optional(),
44788
- priority: z20.string().optional()
44953
+ var State = z22.object({
44954
+ urls: z22.array(
44955
+ z22.object({
44956
+ loc: z22.string(),
44957
+ lastmod: z22.string().optional(),
44958
+ changefreq: z22.string().optional(),
44959
+ priority: z22.string().optional()
44789
44960
  })
44790
44961
  ).default([]),
44791
- queue: z20.array(z20.object({ url: z20.string(), depth: z20.number() })).default([])
44962
+ queue: z22.array(z22.object({ url: z22.string(), depth: z22.number() })).default([])
44792
44963
  });
44793
44964
  var WebsiteSource = class _WebsiteSource extends DataSource {
44794
44965
  mode;
@@ -45283,7 +45454,7 @@ var WebsiteSource = class _WebsiteSource extends DataSource {
45283
45454
  // src/primitives/data-sources/source-directory.ts
45284
45455
  init_define_BUILD();
45285
45456
  init_define_PACKAGE_VERSIONS();
45286
- import { z as z21 } from "@botpress/sdk";
45457
+ import { z as z23 } from "@botpress/sdk";
45287
45458
  var DirectorySource = class _DirectorySource extends DataSource {
45288
45459
  directoryPath;
45289
45460
  filterFn;
@@ -45295,7 +45466,7 @@ var DirectorySource = class _DirectorySource extends DataSource {
45295
45466
  get syncWorkflow() {
45296
45467
  return createSyncWorkflow({
45297
45468
  type: "directory",
45298
- state: z21.object({}),
45469
+ state: z23.object({}),
45299
45470
  handler: async ({ input, step: step2, client }) => {
45300
45471
  if (!adk.environment.isDevelopment()) {
45301
45472
  console.log("Directory ingestion is only supported in development environment");
@@ -45440,10 +45611,10 @@ var DirectorySource = class _DirectorySource extends DataSource {
45440
45611
  // src/primitives/knowledge.ts
45441
45612
  init_define_BUILD();
45442
45613
  init_define_PACKAGE_VERSIONS();
45443
- var Typings4;
45614
+ var Typings5;
45444
45615
  ((Typings8) => {
45445
45616
  Typings8.Primitive = "knowledge";
45446
- })(Typings4 || (Typings4 = {}));
45617
+ })(Typings5 || (Typings5 = {}));
45447
45618
  var BaseKnowledge = class {
45448
45619
  name;
45449
45620
  sources;
@@ -45500,80 +45671,10 @@ var BaseKnowledge = class {
45500
45671
  }
45501
45672
  };
45502
45673
 
45503
- // src/primitives/action.ts
45504
- init_define_BUILD();
45505
- init_define_PACKAGE_VERSIONS();
45506
- import { transforms as transforms2 } from "@botpress/sdk";
45507
- var Typings5;
45508
- ((Typings8) => {
45509
- Typings8.Primitive = "action";
45510
- })(Typings5 || (Typings5 = {}));
45511
- var BaseAction = class {
45512
- name;
45513
- title;
45514
- description;
45515
- attributes;
45516
- input;
45517
- output;
45518
- cached;
45519
- handler;
45520
- constructor(props) {
45521
- if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(props.name)) {
45522
- throw new Error(`Action name "${props.name}" must be alphanumeric with no special characters or spaces`);
45523
- }
45524
- this.name = props.name;
45525
- if (props.title !== void 0) {
45526
- this.title = props.title;
45527
- }
45528
- if (props.description !== void 0) {
45529
- this.description = props.description;
45530
- }
45531
- if (props.attributes !== void 0) {
45532
- this.attributes = props.attributes;
45533
- }
45534
- this.input = props.input;
45535
- this.output = props.output;
45536
- this.cached = props.cached ?? false;
45537
- this.handler = props.handler;
45538
- }
45539
- /** @internal */
45540
- getDefinition() {
45541
- const def = {
45542
- type: "action",
45543
- name: this.name
45544
- };
45545
- if (this.title !== void 0) {
45546
- def.title = this.title;
45547
- }
45548
- if (this.description !== void 0) {
45549
- def.description = this.description;
45550
- }
45551
- if (this.input) {
45552
- def.input = transforms2.toJSONSchema(this.input);
45553
- }
45554
- if (this.output) {
45555
- def.output = transforms2.toJSONSchema(this.output);
45556
- }
45557
- if (this.cached !== void 0) {
45558
- def.cached = this.cached;
45559
- }
45560
- if (this.attributes !== void 0) {
45561
- def.attributes = this.attributes;
45562
- }
45563
- return def;
45564
- }
45565
- /**
45566
- * Execute the action with input validation and output validation
45567
- */
45568
- async execute({ input }) {
45569
- return this.handler(input);
45570
- }
45571
- };
45572
-
45573
45674
  // src/primitives/table.ts
45574
45675
  init_define_BUILD();
45575
45676
  init_define_PACKAGE_VERSIONS();
45576
- import { transforms as transforms3, z as z23 } from "@bpinternal/zui";
45677
+ import { transforms as transforms3, z as z24 } from "@bpinternal/zui";
45577
45678
  var Typings6;
45578
45679
  ((Typings8) => {
45579
45680
  Typings8.Primitive = "table";
@@ -45591,13 +45692,21 @@ var BaseTable = class {
45591
45692
  return context.get("client");
45592
45693
  }
45593
45694
  constructor(props) {
45695
+ const tableNameSchema = z24.string().min(1).refine((name) => !z24.string().uuid().safeParse(name).success, "Table name cannot be a UUID").refine(
45696
+ (name) => /^[a-zA-Z_$][a-zA-Z0-9_]{0,29}Table$/.test(name),
45697
+ "Table name must start with a letter/underscore, be 35 chars or less, contain only letters/numbers/underscores, and end with 'Table'"
45698
+ );
45699
+ const validation = tableNameSchema.safeParse(props.name);
45700
+ if (!validation.success) {
45701
+ throw new Errors.InvalidPrimitiveError(`Invalid table name '${props.name}'`, validation.error);
45702
+ }
45594
45703
  this.name = props.name;
45595
45704
  if (props.description !== void 0) {
45596
45705
  this.description = props.description;
45597
45706
  }
45598
45707
  this.factor = props.factor ?? 1;
45599
45708
  this.columns = {};
45600
- let schema = z23.object({});
45709
+ let schema = z24.object({});
45601
45710
  for (const [key, value] of Object.entries(props.columns)) {
45602
45711
  const val = value;
45603
45712
  if (val && typeof val === "object" && "schema" in val) {
@@ -45773,16 +45882,16 @@ var BaseTable = class {
45773
45882
  // src/primitives/trigger.ts
45774
45883
  init_define_BUILD();
45775
45884
  init_define_PACKAGE_VERSIONS();
45776
- import { z as z24 } from "@botpress/sdk";
45885
+ import { z as z25 } from "@botpress/sdk";
45777
45886
  var Typings7;
45778
45887
  ((Typings8) => {
45779
45888
  Typings8.Primitive = "trigger";
45780
45889
  })(Typings7 || (Typings7 = {}));
45781
- var TriggerSchema = z24.object({
45782
- name: z24.string().min(3, "Trigger name must be at least 3 characters").max(255, "Trigger name must be less than 255 characters").regex(/^[a-zA-Z0-9_]+$/, "Trigger name must contain only alphanumeric characters and underscores"),
45783
- description: z24.string().max(1024, "Description must be less than 1024 characters").optional(),
45784
- events: z24.array(z24.string()),
45785
- handler: z24.function().describe("Handler function for the trigger")
45890
+ var TriggerSchema = z25.object({
45891
+ name: z25.string().min(3, "Trigger name must be at least 3 characters").max(255, "Trigger name must be less than 255 characters").regex(/^[a-zA-Z0-9_]+$/, "Trigger name must contain only alphanumeric characters and underscores"),
45892
+ description: z25.string().max(1024, "Description must be less than 1024 characters").optional(),
45893
+ events: z25.array(z25.string()),
45894
+ handler: z25.function().describe("Handler function for the trigger")
45786
45895
  });
45787
45896
  var Trigger = class {
45788
45897
  name;
@@ -45815,13 +45924,13 @@ var Primitives;
45815
45924
  Primitives2.Definitions = Definitions;
45816
45925
  Primitives2.BaseConversation = BaseConversation;
45817
45926
  Primitives2.BaseConversationInstance = BaseConversationInstance;
45818
- Primitives2.Conversation = Typings3;
45927
+ Primitives2.Conversation = Typings4;
45819
45928
  Primitives2.BaseKnowledge = BaseKnowledge;
45820
- Primitives2.Knowledge = Typings4;
45929
+ Primitives2.Knowledge = Typings5;
45821
45930
  Primitives2.BaseWorkflow = BaseWorkflow;
45822
45931
  Primitives2.Workflow = Typings;
45823
45932
  Primitives2.BaseAction = BaseAction;
45824
- Primitives2.Action = Typings5;
45933
+ Primitives2.Action = Typings3;
45825
45934
  Primitives2.BaseTable = BaseTable;
45826
45935
  Primitives2.Table = Typings6;
45827
45936
  Primitives2.BaseTrigger = Trigger;
@@ -46025,7 +46134,7 @@ var WorkerPool = class {
46025
46134
  if (pendingComplete) {
46026
46135
  if (pendingComplete.taskTimer) clearTimeout(pendingComplete.taskTimer);
46027
46136
  if (pendingComplete.ackTimer) clearTimeout(pendingComplete.ackTimer);
46028
- pendingComplete.resolve(message);
46137
+ pendingComplete.resolve(message.result);
46029
46138
  this.pendingTasks.delete(message.taskId);
46030
46139
  }
46031
46140
  const completeTiming = this.taskTimings.get(message.taskId);
@@ -46048,7 +46157,8 @@ var WorkerPool = class {
46048
46157
  if (pendingError) {
46049
46158
  if (pendingError.taskTimer) clearTimeout(pendingError.taskTimer);
46050
46159
  if (pendingError.ackTimer) clearTimeout(pendingError.ackTimer);
46051
- pendingError.reject(new Error(message.error || "Worker task failed"));
46160
+ const rejectionError = new Error(message.error || "Worker task failed");
46161
+ pendingError.reject(rejectionError);
46052
46162
  this.pendingTasks.delete(message.taskId);
46053
46163
  }
46054
46164
  this.taskTimings.delete(message.taskId);
@@ -46384,8 +46494,9 @@ function initializeParentWorker(bot2) {
46384
46494
  const workerStats = pool.getWorkerStats();
46385
46495
  debugLog2(`[Main] Pool stats - Total: ${workerStats.total}, Idle: ${workerStats.idle}, Busy: ${workerStats.busy}`);
46386
46496
  try {
46387
- await pool.executeTask(event);
46388
- debugLog2("[Main] Event processed successfully by worker");
46497
+ const result = await pool.executeTask(event);
46498
+ debugLog2("[Main] Event processed successfully by worker, result:", result);
46499
+ return result;
46389
46500
  } catch (error) {
46390
46501
  console.error("[Main] Error processing event:", error);
46391
46502
  throw error;
@@ -46446,11 +46557,12 @@ function runWorker(bot2) {
46446
46557
  taskId
46447
46558
  });
46448
46559
  debugLog3(`[Worker] Processing event for task ${taskId}...`);
46449
- await bot2.handler(event);
46560
+ const result = await bot2.handler(event);
46450
46561
  debugLog3(`[Worker] Task ${taskId} completed successfully`);
46451
46562
  parentPort.postMessage({
46452
46563
  type: "complete",
46453
- taskId
46564
+ taskId,
46565
+ result
46454
46566
  });
46455
46567
  } catch (error) {
46456
46568
  console.error(`Error processing task ${taskId}:`, error);
@@ -46498,6 +46610,7 @@ export {
46498
46610
  BUILT_IN_STATES,
46499
46611
  BaseConversationInstance,
46500
46612
  BaseWorkflowInstance,
46613
+ BuiltInActions,
46501
46614
  BuiltInWorkflows,
46502
46615
  CONFIGURATION_PAYLOAD_HEADER,
46503
46616
  CONFIGURATION_TYPE_HEADER,