@botpress/runtime 1.13.13 → 1.13.15

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/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.13.13", adk: "1.13.13", sdk: "5.0.2", llmz: "0.0.37", zai: "2.5.6", cognitive: "0.3.3" };
51
+ define_PACKAGE_VERSIONS_default = { runtime: "1.13.15", adk: "1.13.15", sdk: "5.0.2", llmz: "0.0.37", zai: "2.5.6", cognitive: "0.3.3" };
52
52
  }
53
53
  });
54
54
 
@@ -26654,7 +26654,7 @@ var require_form_data = __commonJS({
26654
26654
  var parseUrl = __require("url").parse;
26655
26655
  var fs3 = __require("fs");
26656
26656
  var Stream2 = __require("stream").Stream;
26657
- var crypto2 = __require("crypto");
26657
+ var crypto3 = __require("crypto");
26658
26658
  var mime = require_mime_types();
26659
26659
  var asynckit = require_asynckit();
26660
26660
  var setToStringTag = require_es_set_tostringtag();
@@ -26860,7 +26860,7 @@ var require_form_data = __commonJS({
26860
26860
  return Buffer.concat([dataBuffer, Buffer.from(this._lastBoundary())]);
26861
26861
  };
26862
26862
  FormData3.prototype._generateBoundary = function() {
26863
- this._boundary = "--------------------------" + crypto2.randomBytes(12).toString("hex");
26863
+ this._boundary = "--------------------------" + crypto3.randomBytes(12).toString("hex");
26864
26864
  };
26865
26865
  FormData3.prototype.getLengthSync = function() {
26866
26866
  var knownLength = this._overheadLength + this._valueLength;
@@ -27281,7 +27281,7 @@ var init_URLSearchParams = __esm({
27281
27281
  });
27282
27282
 
27283
27283
  // ../../node_modules/axios/lib/platform/node/index.js
27284
- import crypto from "crypto";
27284
+ import crypto2 from "crypto";
27285
27285
  var ALPHA, DIGIT, ALPHABET, generateString, node_default;
27286
27286
  var init_node2 = __esm({
27287
27287
  "../../node_modules/axios/lib/platform/node/index.js"() {
@@ -27300,7 +27300,7 @@ var init_node2 = __esm({
27300
27300
  let str = "";
27301
27301
  const { length } = alphabet;
27302
27302
  const randomValues = new Uint32Array(size);
27303
- crypto.randomFillSync(randomValues);
27303
+ crypto2.randomFillSync(randomValues);
27304
27304
  for (let i = 0; i < size; i++) {
27305
27305
  str += alphabet[randomValues[i] % length];
27306
27306
  }
@@ -34809,10 +34809,15 @@ var init_actions = __esm({
34809
34809
  if (typeof propertyName !== "string") {
34810
34810
  return void 0;
34811
34811
  }
34812
+ let client2;
34813
+ client2 ??= context.get("client", { optional: true });
34812
34814
  const botAction = adk.project.actions.find((a) => a.name === propertyName);
34813
34815
  if (botAction) {
34814
34816
  const handler = async (input) => {
34815
- return await botAction.handler(input);
34817
+ return await botAction.handler({
34818
+ input,
34819
+ client: client2
34820
+ });
34816
34821
  };
34817
34822
  handler.asTool = () => new Autonomous.Tool({
34818
34823
  name: botAction.name,
@@ -34824,9 +34829,7 @@ var init_actions = __esm({
34824
34829
  return handler;
34825
34830
  }
34826
34831
  let integrations;
34827
- let client2;
34828
34832
  integrations ??= context.get("integrations", { optional: true });
34829
- client2 ??= context.get("client", { optional: true });
34830
34833
  const integrationName = propertyName.replace("__", "/");
34831
34834
  return new Proxy(
34832
34835
  {},
@@ -36194,7 +36197,8 @@ var init_tracked_state = __esm({
36194
36197
  } else {
36195
36198
  this.value = value;
36196
36199
  }
36197
- if (this.value == null || this.value === void 0) {
36200
+ const needsDefaults = this.value == null || this.value === void 0;
36201
+ if (needsDefaults) {
36198
36202
  if (this.state && "parse" in this.state) {
36199
36203
  try {
36200
36204
  this.value = this.state.parse({});
@@ -36397,6 +36401,7 @@ var init_tracked_tags = __esm({
36397
36401
  init_define_PACKAGE_VERSIONS();
36398
36402
  init_context();
36399
36403
  init_tracing();
36404
+ init_adk();
36400
36405
  TrackedTags = class _TrackedTags {
36401
36406
  type;
36402
36407
  id;
@@ -36621,13 +36626,49 @@ var init_tracked_tags = __esm({
36621
36626
  }
36622
36627
  return {};
36623
36628
  }
36629
+ /**
36630
+ * Get the list of valid tag keys from the agent configuration.
36631
+ * Only tags defined in agent.config.ts can be persisted.
36632
+ */
36633
+ getValidTagKeys() {
36634
+ const validKeys = /* @__PURE__ */ new Set();
36635
+ try {
36636
+ const config = adk.project.config;
36637
+ if (this.type === "bot" && config.bot?.tags) {
36638
+ Object.keys(config.bot.tags).forEach((key) => validKeys.add(key));
36639
+ } else if (this.type === "user" && config.user?.tags) {
36640
+ Object.keys(config.user.tags).forEach((key) => validKeys.add(key));
36641
+ } else if (this.type === "conversation" && config.conversation?.tags) {
36642
+ Object.keys(config.conversation.tags).forEach((key) => validKeys.add(key));
36643
+ } else if (this.type === "workflow" && config.workflow?.tags) {
36644
+ Object.keys(config.workflow.tags).forEach((key) => validKeys.add(key));
36645
+ }
36646
+ } catch (err) {
36647
+ console.warn(`[TrackedTags] Could not load tag definitions from config: ${err}`);
36648
+ }
36649
+ return validKeys;
36650
+ }
36624
36651
  async persistTags(tags) {
36652
+ const validKeys = this.getValidTagKeys();
36625
36653
  const tagsForApi = {};
36654
+ const skippedTags = [];
36626
36655
  for (const [key, value] of Object.entries(tags)) {
36627
- if (value !== void 0 && !isSystemTag(key)) {
36656
+ if (value === void 0 || isSystemTag(key)) {
36657
+ continue;
36658
+ }
36659
+ if (validKeys.size === 0 || validKeys.has(key)) {
36628
36660
  tagsForApi[key] = value;
36661
+ } else {
36662
+ skippedTags.push(key);
36663
+ delete this._tags[key];
36664
+ delete this._initialTags[key];
36629
36665
  }
36630
36666
  }
36667
+ if (skippedTags.length > 0) {
36668
+ console.warn(
36669
+ `[TrackedTags] Skipping tags not defined in agent.config.ts for ${this.type}/${this.id}: ${skippedTags.join(", ")}`
36670
+ );
36671
+ }
36631
36672
  try {
36632
36673
  if (this.type === "bot") {
36633
36674
  await this.client.updateBot({ id: this.id, tags: tagsForApi });
@@ -37745,9 +37786,13 @@ var init_conversation = __esm({
37745
37786
  }
37746
37787
  const stateProxy = new Proxy(conversationInstance.TrackedState.value, {
37747
37788
  set(target, prop, value) {
37748
- const result = Reflect.set(target, prop, value);
37749
- conversationInstance.TrackedState.markDirty();
37750
- return result;
37789
+ const oldValue = target[prop];
37790
+ if (oldValue !== value) {
37791
+ const result = Reflect.set(target, prop, value);
37792
+ conversationInstance.TrackedState.markDirty();
37793
+ return result;
37794
+ }
37795
+ return true;
37751
37796
  }
37752
37797
  });
37753
37798
  await this.#handler({
@@ -38778,9 +38823,13 @@ var init_workflow_instance = __esm({
38778
38823
  const trackedState = this.TrackedState;
38779
38824
  const stateProxy = new Proxy(this.TrackedState.value, {
38780
38825
  set(target, prop, value) {
38781
- const result = Reflect.set(target, prop, value);
38782
- trackedState.markDirty();
38783
- return result;
38826
+ const oldValue = target[prop];
38827
+ if (oldValue !== value) {
38828
+ const result = Reflect.set(target, prop, value);
38829
+ trackedState.markDirty();
38830
+ return result;
38831
+ }
38832
+ return true;
38784
38833
  }
38785
38834
  });
38786
38835
  if (this.workflow.status === "pending") {
@@ -41101,7 +41150,7 @@ var init_source_website = __esm({
41101
41150
  type: "website",
41102
41151
  state: State,
41103
41152
  async handler({ input, step: step2, state, client: client2 }) {
41104
- const crypto2 = await import("crypto");
41153
+ const crypto3 = await import("crypto");
41105
41154
  console.log(
41106
41155
  `Starting sync for WebsiteSource [${this.id}] in mode [${this.mode}, maxPages=${this.maxPages}, maxDepth=${this.maxDepth}, baseUrl=${this.baseUrl}, sitemapUrl=${this.sitemapUrl}]`
41107
41156
  );
@@ -41184,7 +41233,7 @@ var init_source_website = __esm({
41184
41233
  content,
41185
41234
  metadata: fetchMetadata
41186
41235
  } = await this.fetchUrl(sitemapUrl.loc);
41187
- const hash = crypto2.createHash("sha256").update(content).digest("hex");
41236
+ const hash = crypto3.createHash("sha256").update(content).digest("hex");
41188
41237
  let contentType = fetchedContentType;
41189
41238
  if (!contentType) {
41190
41239
  contentType = content.includes("<html") ? "text/html" : "text/markdown";
@@ -48187,7 +48236,7 @@ var init_source_directory = __esm({
48187
48236
  const glob2 = await Promise.resolve().then(() => (init_esm9(), esm_exports3));
48188
48237
  const path5 = await import("path");
48189
48238
  const fs3 = await import("fs/promises");
48190
- const crypto2 = await import("crypto");
48239
+ const crypto3 = await import("crypto");
48191
48240
  const directory = path5.resolve(adk.environment.agent.directory, this.directoryPath);
48192
48241
  const tags = {
48193
48242
  [WellKnownTags.knowledge.KNOWLEDGE]: "knowledge-base",
@@ -48249,7 +48298,7 @@ var init_source_directory = __esm({
48249
48298
  const upsertFile = async (local) => {
48250
48299
  const key = `data_source://${this.type}/${this.id}/${local.rel}`;
48251
48300
  const content = await fs3.readFile(local.abs);
48252
- const hash = crypto2.createHash("sha256").update(content).digest("hex");
48301
+ const hash = crypto3.createHash("sha256").update(content).digest("hex");
48253
48302
  const { file } = await client2.getFile({ id: key }).catch(() => ({ file: null }));
48254
48303
  const isFailed = file?.status === "indexing_failed" || file?.status === "upload_failed" || file?.status === "upload_pending";
48255
48304
  if (!input.force && !isFailed && file?.metadata?.hash === hash) {