@botpress/runtime 1.7.19 → 1.8.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.
@@ -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.7.19", adk: "1.7.19", sdk: "4.19.0", llmz: "0.0.33", zai: "2.5.0", cognitive: "0.2.0" };
51
+ define_PACKAGE_VERSIONS_default = { runtime: "1.8.1", adk: "1.8.1", sdk: "4.19.0", llmz: "0.0.33", zai: "2.5.0", cognitive: "0.2.0" };
52
52
  }
53
53
  });
54
54
 
@@ -39092,14 +39092,15 @@ import { CitationsManager } from "llmz";
39092
39092
  init_define_BUILD();
39093
39093
  init_define_PACKAGE_VERSIONS();
39094
39094
  var InterfaceMappings = class {
39095
- static mappings = {};
39096
- static registerMappings(mappings) {
39095
+ mappings = {};
39096
+ registerMappings(mappings) {
39097
39097
  this.mappings = { ...this.mappings, ...mappings };
39098
39098
  }
39099
- static getIntegrationAction(interfaceName, actionName, integrationName) {
39099
+ getIntegrationAction(interfaceName, actionName, integrationName) {
39100
39100
  return this.mappings[interfaceName]?.actions[`${integrationName}:${actionName}`];
39101
39101
  }
39102
39102
  };
39103
+ var interfaceMappings = getSingleton("__ADK_GLOBAL_INTERFACE_MAPPINGS", () => new InterfaceMappings());
39103
39104
 
39104
39105
  // src/runtime/context/http.ts
39105
39106
  init_define_BUILD();
@@ -40450,7 +40451,7 @@ var BaseConversationInstance = class {
40450
40451
  * Start typing indicator
40451
40452
  */
40452
40453
  async startTyping() {
40453
- const mapping = InterfaceMappings.getIntegrationAction("typingIndicator", "startTypingIndicator", this.integration);
40454
+ const mapping = interfaceMappings.getIntegrationAction("typingIndicator", "startTypingIndicator", this.integration);
40454
40455
  if (mapping) {
40455
40456
  const message = context2.get("message", { optional: true });
40456
40457
  await this.client.callAction({
@@ -40467,7 +40468,7 @@ var BaseConversationInstance = class {
40467
40468
  * Stop typing indicator
40468
40469
  */
40469
40470
  async stopTyping() {
40470
- const mapping = InterfaceMappings.getIntegrationAction("typingIndicator", "stopTypingIndicator", this.integration);
40471
+ const mapping = interfaceMappings.getIntegrationAction("typingIndicator", "stopTypingIndicator", this.integration);
40471
40472
  if (mapping) {
40472
40473
  const message = context2.get("message", { optional: true });
40473
40474
  await this.client.callAction({
@@ -40673,6 +40674,15 @@ var TableSource = class _TableSource extends DataSource {
40673
40674
  this.table = table;
40674
40675
  this.transformFn = options.transform ?? void 0;
40675
40676
  }
40677
+ /** Get serializable configuration for change detection */
40678
+ getConfig() {
40679
+ return {
40680
+ id: this.id,
40681
+ type: this.type,
40682
+ tableName: this.table.name,
40683
+ transformFn: this.transformFn?.toString() || null
40684
+ };
40685
+ }
40676
40686
  get syncWorkflow() {
40677
40687
  return createSyncWorkflow({
40678
40688
  type: "table",
@@ -42286,6 +42296,27 @@ var WebsiteSource = class _WebsiteSource extends DataSource {
42286
42296
  this.maxPages = Math.max(1, Math.min(("maxPages" in options ? options.maxPages : void 0) ?? 5e4, 5e4));
42287
42297
  this.maxDepth = Math.max(1, Math.min(("maxDepth" in options ? options.maxDepth : void 0) ?? 20, 20));
42288
42298
  }
42299
+ /** Get serializable configuration for change detection (only user-provided options) */
42300
+ getConfig() {
42301
+ const config = {
42302
+ mode: this.mode,
42303
+ fetchStrategy: this.fetchStrategy
42304
+ };
42305
+ if (this.mode === "website") {
42306
+ config.baseUrl = this.baseUrl;
42307
+ config.maxPages = this.maxPages;
42308
+ config.maxDepth = this.maxDepth;
42309
+ } else if (this.mode === "sitemap") {
42310
+ config.sitemapUrl = this.sitemapUrl;
42311
+ config.maxPages = this.maxPages;
42312
+ } else if (this.mode === "urls") {
42313
+ config.urls = this.urls;
42314
+ }
42315
+ if (this.filterFn) {
42316
+ config.filterFn = this.filterFn.toString();
42317
+ }
42318
+ return config;
42319
+ }
42289
42320
  isBrowserIntegrationAvailable() {
42290
42321
  return !!adk.project.integrations.get("browser");
42291
42322
  }
@@ -42605,28 +42636,28 @@ var WebsiteSource = class _WebsiteSource extends DataSource {
42605
42636
  tags
42606
42637
  }).collect()
42607
42638
  );
42608
- const existingFileMap = new Map(
42609
- existingFiles.map((f) => [f.metadata?.[WellKnownMetadata.knowledge.URL], f])
42610
- );
42611
- const toRemove = existingFiles.filter(
42612
- (f) => !discoveredUrls.find((u) => u.loc === f.metadata?.[WellKnownMetadata.knowledge.URL])
42613
- );
42614
- if (existingFiles.length > 0 && toRemove.length >= existingFiles.length * 0.8) {
42615
- console.error(
42616
- `Warning: All existing files (${existingFiles.length}) are scheduled for removal. Please check if the sitemap URL is correct and the website is accessible. We will try again in 5 minutes.`
42639
+ if (input.force && existingFiles.length > 0) {
42640
+ console.warn(
42641
+ `\u26A0\uFE0F Website source configuration changed - deleting ${existingFiles.length} existing files and recrawling`
42617
42642
  );
42618
- await step2.sleep("retry wait", 5 * 60 * 1e3);
42619
- throw new Error("Aborting sync due to potential misconfiguration (all files to be removed)");
42643
+ await step2.map(
42644
+ "deleting all existing files for recrawl",
42645
+ existingFiles,
42646
+ (f) => client.deleteFile({ id: f.id }).catch(() => null),
42647
+ { concurrency: 5 }
42648
+ );
42649
+ console.log(`\u2705 Deleted ${existingFiles.length} files, starting fresh crawl`);
42620
42650
  }
42651
+ const existingFileMap = input.force ? /* @__PURE__ */ new Map() : new Map(existingFiles.map((f) => [f.metadata?.[WellKnownMetadata.knowledge.URL], f]));
42652
+ const toRemove = input.force ? [] : existingFiles.filter(
42653
+ (f) => !discoveredUrls.find((u) => u.loc === f.metadata?.[WellKnownMetadata.knowledge.URL])
42654
+ );
42621
42655
  const toFetch = [];
42622
42656
  let skippedUnchanged = 0;
42623
42657
  for (const url2 of discoveredUrls) {
42624
42658
  const existing = existingFileMap.get(url2.loc);
42625
42659
  if (!existing) {
42626
42660
  toFetch.push(url2);
42627
- } else if (input.force) {
42628
- console.log(`Force re-indexing page: ${url2.loc}`);
42629
- toFetch.push(url2);
42630
42661
  } else {
42631
42662
  const existingMetadata = existing.metadata;
42632
42663
  if (url2.lastmod && existingMetadata?.lastmod !== url2.lastmod) {
@@ -42740,7 +42771,17 @@ var WebsiteSource = class _WebsiteSource extends DataSource {
42740
42771
  return new _WebsiteSource(id, "sitemap", { ...options, sitemapUrl });
42741
42772
  }
42742
42773
  static fromUrls(urls, options = {}) {
42743
- const id = options.id || `urls_${urls.length}_pages`;
42774
+ let defaultId = `urls_${urls.length}_pages`;
42775
+ if (urls.length > 0) {
42776
+ try {
42777
+ const firstUrl = new URL(urls[0]);
42778
+ const domain = firstUrl.hostname.replace(/^www\./, "").replace(/\./g, "_");
42779
+ const urlsHash = urls.slice().sort().join("|").split("").reduce((hash, char) => (hash << 5) - hash + char.charCodeAt(0) | 0, 0).toString(16).replace("-", "").slice(0, 8);
42780
+ defaultId = `urls_${domain}_${urlsHash}`;
42781
+ } catch {
42782
+ }
42783
+ }
42784
+ const id = options.id || defaultId;
42744
42785
  return new _WebsiteSource(id, "urls", { ...options, urls });
42745
42786
  }
42746
42787
  };
@@ -42750,12 +42791,29 @@ init_define_BUILD();
42750
42791
  init_define_PACKAGE_VERSIONS();
42751
42792
  import { z as z11 } from "@botpress/sdk";
42752
42793
  var DirectorySource = class _DirectorySource extends DataSource {
42753
- directoryPath;
42754
- filterFn;
42794
+ _directoryPath;
42795
+ _filterFn;
42755
42796
  constructor(id, directoryPath, options = {}) {
42756
42797
  super(id, "directory");
42757
- this.directoryPath = directoryPath;
42758
- this.filterFn = options.filter ?? void 0;
42798
+ this._directoryPath = directoryPath;
42799
+ this._filterFn = options.filter ?? void 0;
42800
+ }
42801
+ /** Get the directory path for this source */
42802
+ get directoryPath() {
42803
+ return this._directoryPath;
42804
+ }
42805
+ /** Get the filter function for this source */
42806
+ get filterFn() {
42807
+ return this._filterFn;
42808
+ }
42809
+ /** Get serializable configuration for change detection */
42810
+ getConfig() {
42811
+ return {
42812
+ id: this.id,
42813
+ type: this.type,
42814
+ directoryPath: this._directoryPath,
42815
+ filterFn: this._filterFn?.toString() || null
42816
+ };
42759
42817
  }
42760
42818
  get syncWorkflow() {
42761
42819
  return createSyncWorkflow({
@@ -42902,6 +42960,17 @@ var DirectorySource = class _DirectorySource extends DataSource {
42902
42960
  }
42903
42961
  };
42904
42962
 
42963
+ // src/primitives/data-sources/index.ts
42964
+ function isDirectorySource(source) {
42965
+ return source.type === "directory";
42966
+ }
42967
+ function isWebsiteSource(source) {
42968
+ return source.type === "website";
42969
+ }
42970
+ function isTableSource(source) {
42971
+ return source.type === "table";
42972
+ }
42973
+
42905
42974
  // src/primitives/conversation.ts
42906
42975
  init_define_BUILD();
42907
42976
  init_define_PACKAGE_VERSIONS();
@@ -42957,6 +43026,8 @@ var BaseConversation = class {
42957
43026
  const client = context2.get("client");
42958
43027
  const botpressConversation = context2.get("conversation");
42959
43028
  const conversationInstance = new BaseConversationInstance(botpressConversation, client);
43029
+ const startTypingPromise = conversationInstance.startTyping().catch(() => {
43030
+ });
42960
43031
  let type;
42961
43032
  let requestObject = void 0;
42962
43033
  if (message) {
@@ -43068,6 +43139,8 @@ var BaseConversation = class {
43068
43139
  execute
43069
43140
  });
43070
43141
  controller.abort();
43142
+ void startTypingPromise.then(() => conversationInstance.stopTyping().catch(() => {
43143
+ }));
43071
43144
  }
43072
43145
  };
43073
43146
 
@@ -43477,6 +43550,9 @@ var DataSource2;
43477
43550
  DataSource3.Table = TableSource;
43478
43551
  DataSource3.Website = WebsiteSource;
43479
43552
  DataSource3.Directory = DirectorySource;
43553
+ DataSource3.isDirectory = isDirectorySource;
43554
+ DataSource3.isWebsite = isWebsiteSource;
43555
+ DataSource3.isTable = isTableSource;
43480
43556
  })(DataSource2 || (DataSource2 = {}));
43481
43557
 
43482
43558
  // src/primitives/workflow-utils.ts