@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.
package/dist/library.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.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
 
@@ -36151,14 +36151,15 @@ import { CitationsManager } from "llmz";
36151
36151
  init_define_BUILD();
36152
36152
  init_define_PACKAGE_VERSIONS();
36153
36153
  var InterfaceMappings = class {
36154
- static mappings = {};
36155
- static registerMappings(mappings) {
36154
+ mappings = {};
36155
+ registerMappings(mappings) {
36156
36156
  this.mappings = { ...this.mappings, ...mappings };
36157
36157
  }
36158
- static getIntegrationAction(interfaceName, actionName, integrationName) {
36158
+ getIntegrationAction(interfaceName, actionName, integrationName) {
36159
36159
  return this.mappings[interfaceName]?.actions[`${integrationName}:${actionName}`];
36160
36160
  }
36161
36161
  };
36162
+ var interfaceMappings = getSingleton("__ADK_GLOBAL_INTERFACE_MAPPINGS", () => new InterfaceMappings());
36162
36163
 
36163
36164
  // src/runtime/context/http.ts
36164
36165
  init_define_BUILD();
@@ -43106,7 +43107,7 @@ var BaseConversationInstance = class {
43106
43107
  * Start typing indicator
43107
43108
  */
43108
43109
  async startTyping() {
43109
- const mapping = InterfaceMappings.getIntegrationAction("typingIndicator", "startTypingIndicator", this.integration);
43110
+ const mapping = interfaceMappings.getIntegrationAction("typingIndicator", "startTypingIndicator", this.integration);
43110
43111
  if (mapping) {
43111
43112
  const message = context.get("message", { optional: true });
43112
43113
  await this.client.callAction({
@@ -43123,7 +43124,7 @@ var BaseConversationInstance = class {
43123
43124
  * Stop typing indicator
43124
43125
  */
43125
43126
  async stopTyping() {
43126
- const mapping = InterfaceMappings.getIntegrationAction("typingIndicator", "stopTypingIndicator", this.integration);
43127
+ const mapping = interfaceMappings.getIntegrationAction("typingIndicator", "stopTypingIndicator", this.integration);
43127
43128
  if (mapping) {
43128
43129
  const message = context.get("message", { optional: true });
43129
43130
  await this.client.callAction({
@@ -43221,6 +43222,8 @@ var BaseConversation = class {
43221
43222
  const client = context.get("client");
43222
43223
  const botpressConversation = context.get("conversation");
43223
43224
  const conversationInstance = new BaseConversationInstance(botpressConversation, client);
43225
+ const startTypingPromise = conversationInstance.startTyping().catch(() => {
43226
+ });
43224
43227
  let type;
43225
43228
  let requestObject = void 0;
43226
43229
  if (message) {
@@ -43332,6 +43335,8 @@ var BaseConversation = class {
43332
43335
  execute
43333
43336
  });
43334
43337
  controller.abort();
43338
+ void startTypingPromise.then(() => conversationInstance.stopTyping().catch(() => {
43339
+ }));
43335
43340
  }
43336
43341
  };
43337
43342
 
@@ -43461,6 +43466,15 @@ var TableSource = class _TableSource extends DataSource {
43461
43466
  this.table = table;
43462
43467
  this.transformFn = options.transform ?? void 0;
43463
43468
  }
43469
+ /** Get serializable configuration for change detection */
43470
+ getConfig() {
43471
+ return {
43472
+ id: this.id,
43473
+ type: this.type,
43474
+ tableName: this.table.name,
43475
+ transformFn: this.transformFn?.toString() || null
43476
+ };
43477
+ }
43464
43478
  get syncWorkflow() {
43465
43479
  return createSyncWorkflow({
43466
43480
  type: "table",
@@ -45074,6 +45088,27 @@ var WebsiteSource = class _WebsiteSource extends DataSource {
45074
45088
  this.maxPages = Math.max(1, Math.min(("maxPages" in options ? options.maxPages : void 0) ?? 5e4, 5e4));
45075
45089
  this.maxDepth = Math.max(1, Math.min(("maxDepth" in options ? options.maxDepth : void 0) ?? 20, 20));
45076
45090
  }
45091
+ /** Get serializable configuration for change detection (only user-provided options) */
45092
+ getConfig() {
45093
+ const config = {
45094
+ mode: this.mode,
45095
+ fetchStrategy: this.fetchStrategy
45096
+ };
45097
+ if (this.mode === "website") {
45098
+ config.baseUrl = this.baseUrl;
45099
+ config.maxPages = this.maxPages;
45100
+ config.maxDepth = this.maxDepth;
45101
+ } else if (this.mode === "sitemap") {
45102
+ config.sitemapUrl = this.sitemapUrl;
45103
+ config.maxPages = this.maxPages;
45104
+ } else if (this.mode === "urls") {
45105
+ config.urls = this.urls;
45106
+ }
45107
+ if (this.filterFn) {
45108
+ config.filterFn = this.filterFn.toString();
45109
+ }
45110
+ return config;
45111
+ }
45077
45112
  isBrowserIntegrationAvailable() {
45078
45113
  return !!adk.project.integrations.get("browser");
45079
45114
  }
@@ -45393,28 +45428,28 @@ var WebsiteSource = class _WebsiteSource extends DataSource {
45393
45428
  tags
45394
45429
  }).collect()
45395
45430
  );
45396
- const existingFileMap = new Map(
45397
- existingFiles.map((f) => [f.metadata?.[WellKnownMetadata.knowledge.URL], f])
45398
- );
45399
- const toRemove = existingFiles.filter(
45400
- (f) => !discoveredUrls.find((u) => u.loc === f.metadata?.[WellKnownMetadata.knowledge.URL])
45401
- );
45402
- if (existingFiles.length > 0 && toRemove.length >= existingFiles.length * 0.8) {
45403
- console.error(
45404
- `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.`
45431
+ if (input.force && existingFiles.length > 0) {
45432
+ console.warn(
45433
+ `\u26A0\uFE0F Website source configuration changed - deleting ${existingFiles.length} existing files and recrawling`
45405
45434
  );
45406
- await step2.sleep("retry wait", 5 * 60 * 1e3);
45407
- throw new Error("Aborting sync due to potential misconfiguration (all files to be removed)");
45435
+ await step2.map(
45436
+ "deleting all existing files for recrawl",
45437
+ existingFiles,
45438
+ (f) => client.deleteFile({ id: f.id }).catch(() => null),
45439
+ { concurrency: 5 }
45440
+ );
45441
+ console.log(`\u2705 Deleted ${existingFiles.length} files, starting fresh crawl`);
45408
45442
  }
45443
+ const existingFileMap = input.force ? /* @__PURE__ */ new Map() : new Map(existingFiles.map((f) => [f.metadata?.[WellKnownMetadata.knowledge.URL], f]));
45444
+ const toRemove = input.force ? [] : existingFiles.filter(
45445
+ (f) => !discoveredUrls.find((u) => u.loc === f.metadata?.[WellKnownMetadata.knowledge.URL])
45446
+ );
45409
45447
  const toFetch = [];
45410
45448
  let skippedUnchanged = 0;
45411
45449
  for (const url2 of discoveredUrls) {
45412
45450
  const existing = existingFileMap.get(url2.loc);
45413
45451
  if (!existing) {
45414
45452
  toFetch.push(url2);
45415
- } else if (input.force) {
45416
- console.log(`Force re-indexing page: ${url2.loc}`);
45417
- toFetch.push(url2);
45418
45453
  } else {
45419
45454
  const existingMetadata = existing.metadata;
45420
45455
  if (url2.lastmod && existingMetadata?.lastmod !== url2.lastmod) {
@@ -45528,7 +45563,17 @@ var WebsiteSource = class _WebsiteSource extends DataSource {
45528
45563
  return new _WebsiteSource(id, "sitemap", { ...options, sitemapUrl });
45529
45564
  }
45530
45565
  static fromUrls(urls, options = {}) {
45531
- const id = options.id || `urls_${urls.length}_pages`;
45566
+ let defaultId = `urls_${urls.length}_pages`;
45567
+ if (urls.length > 0) {
45568
+ try {
45569
+ const firstUrl = new URL(urls[0]);
45570
+ const domain = firstUrl.hostname.replace(/^www\./, "").replace(/\./g, "_");
45571
+ const urlsHash = urls.slice().sort().join("|").split("").reduce((hash, char) => (hash << 5) - hash + char.charCodeAt(0) | 0, 0).toString(16).replace("-", "").slice(0, 8);
45572
+ defaultId = `urls_${domain}_${urlsHash}`;
45573
+ } catch {
45574
+ }
45575
+ }
45576
+ const id = options.id || defaultId;
45532
45577
  return new _WebsiteSource(id, "urls", { ...options, urls });
45533
45578
  }
45534
45579
  };
@@ -45538,12 +45583,29 @@ init_define_BUILD();
45538
45583
  init_define_PACKAGE_VERSIONS();
45539
45584
  import { z as z22 } from "@botpress/sdk";
45540
45585
  var DirectorySource = class _DirectorySource extends DataSource {
45541
- directoryPath;
45542
- filterFn;
45586
+ _directoryPath;
45587
+ _filterFn;
45543
45588
  constructor(id, directoryPath, options = {}) {
45544
45589
  super(id, "directory");
45545
- this.directoryPath = directoryPath;
45546
- this.filterFn = options.filter ?? void 0;
45590
+ this._directoryPath = directoryPath;
45591
+ this._filterFn = options.filter ?? void 0;
45592
+ }
45593
+ /** Get the directory path for this source */
45594
+ get directoryPath() {
45595
+ return this._directoryPath;
45596
+ }
45597
+ /** Get the filter function for this source */
45598
+ get filterFn() {
45599
+ return this._filterFn;
45600
+ }
45601
+ /** Get serializable configuration for change detection */
45602
+ getConfig() {
45603
+ return {
45604
+ id: this.id,
45605
+ type: this.type,
45606
+ directoryPath: this._directoryPath,
45607
+ filterFn: this._filterFn?.toString() || null
45608
+ };
45547
45609
  }
45548
45610
  get syncWorkflow() {
45549
45611
  return createSyncWorkflow({
@@ -45690,6 +45752,17 @@ var DirectorySource = class _DirectorySource extends DataSource {
45690
45752
  }
45691
45753
  };
45692
45754
 
45755
+ // src/primitives/data-sources/index.ts
45756
+ function isDirectorySource(source) {
45757
+ return source.type === "directory";
45758
+ }
45759
+ function isWebsiteSource(source) {
45760
+ return source.type === "website";
45761
+ }
45762
+ function isTableSource(source) {
45763
+ return source.type === "table";
45764
+ }
45765
+
45693
45766
  // src/primitives/knowledge.ts
45694
45767
  init_define_BUILD();
45695
45768
  init_define_PACKAGE_VERSIONS();
@@ -46026,6 +46099,9 @@ var DataSource2;
46026
46099
  DataSource3.Table = TableSource;
46027
46100
  DataSource3.Website = WebsiteSource;
46028
46101
  DataSource3.Directory = DirectorySource;
46102
+ DataSource3.isDirectory = isDirectorySource;
46103
+ DataSource3.isWebsite = isWebsiteSource;
46104
+ DataSource3.isTable = isTableSource;
46029
46105
  })(DataSource2 || (DataSource2 = {}));
46030
46106
 
46031
46107
  // src/runtime/handlers/workflow.ts