@botpress/runtime 1.7.18 → 1.8.0

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.18", adk: "1.7.18", sdk: "4.19.0", llmz: "0.0.33", zai: "2.5.0", cognitive: "0.2.0" };
51
+ define_PACKAGE_VERSIONS_default = { runtime: "1.8.0", adk: "1.8.0", sdk: "4.19.0", llmz: "0.0.33", zai: "2.5.0", cognitive: "0.2.0" };
52
52
  }
53
53
  });
54
54
 
@@ -43461,6 +43461,15 @@ var TableSource = class _TableSource extends DataSource {
43461
43461
  this.table = table;
43462
43462
  this.transformFn = options.transform ?? void 0;
43463
43463
  }
43464
+ /** Get serializable configuration for change detection */
43465
+ getConfig() {
43466
+ return {
43467
+ id: this.id,
43468
+ type: this.type,
43469
+ tableName: this.table.name,
43470
+ transformFn: this.transformFn?.toString() || null
43471
+ };
43472
+ }
43464
43473
  get syncWorkflow() {
43465
43474
  return createSyncWorkflow({
43466
43475
  type: "table",
@@ -45074,6 +45083,27 @@ var WebsiteSource = class _WebsiteSource extends DataSource {
45074
45083
  this.maxPages = Math.max(1, Math.min(("maxPages" in options ? options.maxPages : void 0) ?? 5e4, 5e4));
45075
45084
  this.maxDepth = Math.max(1, Math.min(("maxDepth" in options ? options.maxDepth : void 0) ?? 20, 20));
45076
45085
  }
45086
+ /** Get serializable configuration for change detection (only user-provided options) */
45087
+ getConfig() {
45088
+ const config = {
45089
+ mode: this.mode,
45090
+ fetchStrategy: this.fetchStrategy
45091
+ };
45092
+ if (this.mode === "website") {
45093
+ config.baseUrl = this.baseUrl;
45094
+ config.maxPages = this.maxPages;
45095
+ config.maxDepth = this.maxDepth;
45096
+ } else if (this.mode === "sitemap") {
45097
+ config.sitemapUrl = this.sitemapUrl;
45098
+ config.maxPages = this.maxPages;
45099
+ } else if (this.mode === "urls") {
45100
+ config.urls = this.urls;
45101
+ }
45102
+ if (this.filterFn) {
45103
+ config.filterFn = this.filterFn.toString();
45104
+ }
45105
+ return config;
45106
+ }
45077
45107
  isBrowserIntegrationAvailable() {
45078
45108
  return !!adk.project.integrations.get("browser");
45079
45109
  }
@@ -45393,28 +45423,28 @@ var WebsiteSource = class _WebsiteSource extends DataSource {
45393
45423
  tags
45394
45424
  }).collect()
45395
45425
  );
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.`
45426
+ if (input.force && existingFiles.length > 0) {
45427
+ console.warn(
45428
+ `\u26A0\uFE0F Website source configuration changed - deleting ${existingFiles.length} existing files and recrawling`
45429
+ );
45430
+ await step2.map(
45431
+ "deleting all existing files for recrawl",
45432
+ existingFiles,
45433
+ (f) => client.deleteFile({ id: f.id }).catch(() => null),
45434
+ { concurrency: 5 }
45405
45435
  );
45406
- await step2.sleep("retry wait", 5 * 60 * 1e3);
45407
- throw new Error("Aborting sync due to potential misconfiguration (all files to be removed)");
45436
+ console.log(`\u2705 Deleted ${existingFiles.length} files, starting fresh crawl`);
45408
45437
  }
45438
+ const existingFileMap = input.force ? /* @__PURE__ */ new Map() : new Map(existingFiles.map((f) => [f.metadata?.[WellKnownMetadata.knowledge.URL], f]));
45439
+ const toRemove = input.force ? [] : existingFiles.filter(
45440
+ (f) => !discoveredUrls.find((u) => u.loc === f.metadata?.[WellKnownMetadata.knowledge.URL])
45441
+ );
45409
45442
  const toFetch = [];
45410
45443
  let skippedUnchanged = 0;
45411
45444
  for (const url2 of discoveredUrls) {
45412
45445
  const existing = existingFileMap.get(url2.loc);
45413
45446
  if (!existing) {
45414
45447
  toFetch.push(url2);
45415
- } else if (input.force) {
45416
- console.log(`Force re-indexing page: ${url2.loc}`);
45417
- toFetch.push(url2);
45418
45448
  } else {
45419
45449
  const existingMetadata = existing.metadata;
45420
45450
  if (url2.lastmod && existingMetadata?.lastmod !== url2.lastmod) {
@@ -45528,7 +45558,17 @@ var WebsiteSource = class _WebsiteSource extends DataSource {
45528
45558
  return new _WebsiteSource(id, "sitemap", { ...options, sitemapUrl });
45529
45559
  }
45530
45560
  static fromUrls(urls, options = {}) {
45531
- const id = options.id || `urls_${urls.length}_pages`;
45561
+ let defaultId = `urls_${urls.length}_pages`;
45562
+ if (urls.length > 0) {
45563
+ try {
45564
+ const firstUrl = new URL(urls[0]);
45565
+ const domain = firstUrl.hostname.replace(/^www\./, "").replace(/\./g, "_");
45566
+ const urlsHash = urls.slice().sort().join("|").split("").reduce((hash, char) => (hash << 5) - hash + char.charCodeAt(0) | 0, 0).toString(16).replace("-", "").slice(0, 8);
45567
+ defaultId = `urls_${domain}_${urlsHash}`;
45568
+ } catch {
45569
+ }
45570
+ }
45571
+ const id = options.id || defaultId;
45532
45572
  return new _WebsiteSource(id, "urls", { ...options, urls });
45533
45573
  }
45534
45574
  };
@@ -45538,12 +45578,29 @@ init_define_BUILD();
45538
45578
  init_define_PACKAGE_VERSIONS();
45539
45579
  import { z as z22 } from "@botpress/sdk";
45540
45580
  var DirectorySource = class _DirectorySource extends DataSource {
45541
- directoryPath;
45542
- filterFn;
45581
+ _directoryPath;
45582
+ _filterFn;
45543
45583
  constructor(id, directoryPath, options = {}) {
45544
45584
  super(id, "directory");
45545
- this.directoryPath = directoryPath;
45546
- this.filterFn = options.filter ?? void 0;
45585
+ this._directoryPath = directoryPath;
45586
+ this._filterFn = options.filter ?? void 0;
45587
+ }
45588
+ /** Get the directory path for this source */
45589
+ get directoryPath() {
45590
+ return this._directoryPath;
45591
+ }
45592
+ /** Get the filter function for this source */
45593
+ get filterFn() {
45594
+ return this._filterFn;
45595
+ }
45596
+ /** Get serializable configuration for change detection */
45597
+ getConfig() {
45598
+ return {
45599
+ id: this.id,
45600
+ type: this.type,
45601
+ directoryPath: this._directoryPath,
45602
+ filterFn: this._filterFn?.toString() || null
45603
+ };
45547
45604
  }
45548
45605
  get syncWorkflow() {
45549
45606
  return createSyncWorkflow({
@@ -45690,6 +45747,17 @@ var DirectorySource = class _DirectorySource extends DataSource {
45690
45747
  }
45691
45748
  };
45692
45749
 
45750
+ // src/primitives/data-sources/index.ts
45751
+ function isDirectorySource(source) {
45752
+ return source.type === "directory";
45753
+ }
45754
+ function isWebsiteSource(source) {
45755
+ return source.type === "website";
45756
+ }
45757
+ function isTableSource(source) {
45758
+ return source.type === "table";
45759
+ }
45760
+
45693
45761
  // src/primitives/knowledge.ts
45694
45762
  init_define_BUILD();
45695
45763
  init_define_PACKAGE_VERSIONS();
@@ -46026,6 +46094,9 @@ var DataSource2;
46026
46094
  DataSource3.Table = TableSource;
46027
46095
  DataSource3.Website = WebsiteSource;
46028
46096
  DataSource3.Directory = DirectorySource;
46097
+ DataSource3.isDirectory = isDirectorySource;
46098
+ DataSource3.isWebsite = isWebsiteSource;
46099
+ DataSource3.isTable = isTableSource;
46029
46100
  })(DataSource2 || (DataSource2 = {}));
46030
46101
 
46031
46102
  // src/runtime/handlers/workflow.ts