@botpress/adk 1.19.0-beta.11 → 1.19.0-beta.13
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/agent0/index.js +16 -7
- package/dist/agent0/index.js.map +5 -5
- package/dist/agent0/runtime/client.d.ts +2 -0
- package/dist/agent0/runtime/client.d.ts.map +1 -1
- package/dist/agent0/runtime/engine.d.ts +2 -1
- package/dist/agent0/runtime/engine.d.ts.map +1 -1
- package/dist/agent0/runtime/process.d.ts +1 -0
- package/dist/agent0/runtime/process.d.ts.map +1 -1
- package/dist/assets/manager.d.ts +3 -0
- package/dist/assets/manager.d.ts.map +1 -1
- package/dist/auth/credentials.d.ts +1 -1
- package/dist/bot-generator/generator.d.ts.map +1 -1
- package/dist/commands/bp-dev-command.d.ts.map +1 -1
- package/dist/dependencies/index.js +134 -258
- package/dist/dependencies/index.js.map +8 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +469 -577
- package/dist/index.js.map +15 -16
- package/dist/integrations/hub-cache.d.ts +0 -58
- package/dist/integrations/hub-cache.d.ts.map +1 -1
- package/dist/integrations/index.d.ts +0 -1
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/manager.d.ts.map +1 -1
- package/dist/knowledge/manager.d.ts +3 -0
- package/dist/knowledge/manager.d.ts.map +1 -1
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/preflight/checker.d.ts +6 -1
- package/dist/preflight/checker.d.ts.map +1 -1
- package/dist/tables/table-manager.d.ts +3 -0
- package/dist/tables/table-manager.d.ts.map +1 -1
- package/dist/workspace/workspace-cache.d.ts +2 -1
- package/dist/workspace/workspace-cache.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -944,7 +944,7 @@ class CredentialsManager {
|
|
|
944
944
|
await this.writeCredentials(store);
|
|
945
945
|
}
|
|
946
946
|
async getActiveCredentials() {
|
|
947
|
-
const profileName = this.profileOverride
|
|
947
|
+
const profileName = this.profileOverride;
|
|
948
948
|
const credentials = await this.getCredentials(profileName);
|
|
949
949
|
if (!credentials) {
|
|
950
950
|
const displayName = profileName || "default";
|
|
@@ -976,7 +976,7 @@ class CredentialsManager {
|
|
|
976
976
|
});
|
|
977
977
|
const agentApiUrl = agentInfo.apiUrl;
|
|
978
978
|
let baseCredentials;
|
|
979
|
-
const hasExplicitProfile = !!
|
|
979
|
+
const hasExplicitProfile = !!this.profileOverride;
|
|
980
980
|
if (hasExplicitProfile) {
|
|
981
981
|
baseCredentials = await this.getActiveCredentials();
|
|
982
982
|
} else {
|
|
@@ -1766,6 +1766,8 @@ function normalize(value) {
|
|
|
1766
1766
|
var init_search_ranking = () => {};
|
|
1767
1767
|
|
|
1768
1768
|
// src/integrations/manager.ts
|
|
1769
|
+
import { Client as Client3 } from "@botpress/client";
|
|
1770
|
+
|
|
1769
1771
|
class IntegrationManager {
|
|
1770
1772
|
cache;
|
|
1771
1773
|
options;
|
|
@@ -1776,15 +1778,33 @@ class IntegrationManager {
|
|
|
1776
1778
|
}
|
|
1777
1779
|
async getClient() {
|
|
1778
1780
|
if (!this.client) {
|
|
1779
|
-
this.
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1781
|
+
const hasProjectScope = !!(this.options.project || this.options.workspaceId);
|
|
1782
|
+
if (hasProjectScope) {
|
|
1783
|
+
this.client = await getProjectClient({
|
|
1784
|
+
project: this.options.project,
|
|
1785
|
+
credentials: this.options.credentials,
|
|
1786
|
+
apiUrl: this.options.apiUrl,
|
|
1787
|
+
workspaceId: this.options.workspaceId,
|
|
1788
|
+
headers: {
|
|
1789
|
+
"x-multiple-integrations": "true"
|
|
1790
|
+
}
|
|
1791
|
+
});
|
|
1792
|
+
} else if (this.options.credentials) {
|
|
1793
|
+
this.client = new Client3({
|
|
1794
|
+
token: this.options.credentials.token,
|
|
1795
|
+
apiUrl: this.options.apiUrl || this.options.credentials.apiUrl,
|
|
1796
|
+
...this.options.credentials.workspaceId ? { workspaceId: this.options.credentials.workspaceId } : {},
|
|
1797
|
+
headers: {
|
|
1798
|
+
"x-multiple-integrations": "true"
|
|
1799
|
+
}
|
|
1800
|
+
});
|
|
1801
|
+
} else {
|
|
1802
|
+
this.client = await getProjectClient({
|
|
1803
|
+
headers: {
|
|
1804
|
+
"x-multiple-integrations": "true"
|
|
1805
|
+
}
|
|
1806
|
+
});
|
|
1807
|
+
}
|
|
1788
1808
|
}
|
|
1789
1809
|
return this.client;
|
|
1790
1810
|
}
|
|
@@ -2157,11 +2177,13 @@ class AssetsManager {
|
|
|
2157
2177
|
assetsPath;
|
|
2158
2178
|
client;
|
|
2159
2179
|
botId;
|
|
2180
|
+
credentials;
|
|
2160
2181
|
cacheManager;
|
|
2161
2182
|
constructor(options) {
|
|
2162
2183
|
this.projectPath = options.projectPath;
|
|
2163
2184
|
this.assetsPath = path9.join(this.projectPath, "assets");
|
|
2164
2185
|
this.botId = options.botId;
|
|
2186
|
+
this.credentials = options.credentials;
|
|
2165
2187
|
this.cacheManager = new AssetsCacheManager(this.projectPath);
|
|
2166
2188
|
}
|
|
2167
2189
|
async getClient() {
|
|
@@ -2176,6 +2198,7 @@ class AssetsManager {
|
|
|
2176
2198
|
}
|
|
2177
2199
|
this.client = await getProjectClient({
|
|
2178
2200
|
project: { path: this.projectPath },
|
|
2201
|
+
credentials: this.credentials,
|
|
2179
2202
|
botId: this.botId,
|
|
2180
2203
|
headers: {
|
|
2181
2204
|
"x-multiple-integrations": "true"
|
|
@@ -2633,171 +2656,6 @@ class IntegrationCache {
|
|
|
2633
2656
|
}
|
|
2634
2657
|
var init_cache2 = () => {};
|
|
2635
2658
|
|
|
2636
|
-
// src/integrations/hub-cache.ts
|
|
2637
|
-
import { Client as Client3 } from "@botpress/client";
|
|
2638
|
-
import * as fs10 from "fs/promises";
|
|
2639
|
-
import * as path11 from "path";
|
|
2640
|
-
import * as os7 from "os";
|
|
2641
|
-
var HubCache;
|
|
2642
|
-
var init_hub_cache = __esm(() => {
|
|
2643
|
-
init_src();
|
|
2644
|
-
init_auth();
|
|
2645
|
-
HubCache = class HubCache {
|
|
2646
|
-
static CACHE_FILE = "botpress-hub-cache.json";
|
|
2647
|
-
static CACHE_DIR = path11.join(os7.homedir(), ".adk", "cache");
|
|
2648
|
-
static CACHE_PATH = path11.join(HubCache.CACHE_DIR, HubCache.CACHE_FILE);
|
|
2649
|
-
static CACHE_DURATION = 30 * 60 * 1000;
|
|
2650
|
-
client;
|
|
2651
|
-
constructor() {}
|
|
2652
|
-
async getClient() {
|
|
2653
|
-
if (!this.client) {
|
|
2654
|
-
const credentials = await auth.getActiveCredentials();
|
|
2655
|
-
if (!credentials.workspaceId) {
|
|
2656
|
-
throw new AdkError({
|
|
2657
|
-
code: "WORKSPACE_ID_MISSING",
|
|
2658
|
-
message: 'No workspace ID found in current profile. Please login again with "adk login"',
|
|
2659
|
-
expected: true,
|
|
2660
|
-
suggestion: 'Please login again with "adk login".'
|
|
2661
|
-
});
|
|
2662
|
-
}
|
|
2663
|
-
this.client = new Client3({
|
|
2664
|
-
token: credentials.token,
|
|
2665
|
-
apiUrl: credentials.apiUrl,
|
|
2666
|
-
workspaceId: credentials.workspaceId,
|
|
2667
|
-
headers: {
|
|
2668
|
-
"x-multiple-integrations": "true"
|
|
2669
|
-
}
|
|
2670
|
-
});
|
|
2671
|
-
}
|
|
2672
|
-
return this.client;
|
|
2673
|
-
}
|
|
2674
|
-
async ensureCacheDir() {
|
|
2675
|
-
try {
|
|
2676
|
-
await fs10.mkdir(HubCache.CACHE_DIR, { recursive: true });
|
|
2677
|
-
} catch {}
|
|
2678
|
-
}
|
|
2679
|
-
async loadCache() {
|
|
2680
|
-
try {
|
|
2681
|
-
const data = await fs10.readFile(HubCache.CACHE_PATH, "utf-8");
|
|
2682
|
-
return JSON.parse(data);
|
|
2683
|
-
} catch {
|
|
2684
|
-
return null;
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
async saveCache(data) {
|
|
2688
|
-
await this.ensureCacheDir();
|
|
2689
|
-
await fs10.writeFile(HubCache.CACHE_PATH, JSON.stringify(data, null, 2));
|
|
2690
|
-
}
|
|
2691
|
-
async needsRefresh() {
|
|
2692
|
-
const cache2 = await this.loadCache();
|
|
2693
|
-
if (!cache2)
|
|
2694
|
-
return true;
|
|
2695
|
-
const lastUpdated = new Date(cache2.lastUpdated);
|
|
2696
|
-
const now = new Date;
|
|
2697
|
-
const diff = now.getTime() - lastUpdated.getTime();
|
|
2698
|
-
return diff > HubCache.CACHE_DURATION;
|
|
2699
|
-
}
|
|
2700
|
-
async refresh(force = false) {
|
|
2701
|
-
if (!force && !await this.needsRefresh()) {
|
|
2702
|
-
return;
|
|
2703
|
-
}
|
|
2704
|
-
const client = await this.getClient();
|
|
2705
|
-
const cache2 = await this.loadCache();
|
|
2706
|
-
const latestByName = new Map;
|
|
2707
|
-
if (cache2) {
|
|
2708
|
-
for (const entry of cache2.integrations) {
|
|
2709
|
-
latestByName.set(entry.name, entry);
|
|
2710
|
-
}
|
|
2711
|
-
}
|
|
2712
|
-
try {
|
|
2713
|
-
for await (const integration of client.list.publicIntegrations({
|
|
2714
|
-
sortBy: "updatedAt",
|
|
2715
|
-
direction: "desc"
|
|
2716
|
-
})) {
|
|
2717
|
-
const existing = latestByName.get(integration.name);
|
|
2718
|
-
if (existing && integration.id === existing.id && integration.updatedAt === existing.updatedAt) {
|
|
2719
|
-
break;
|
|
2720
|
-
}
|
|
2721
|
-
if (!existing || integration.version.localeCompare(existing.version, undefined, {
|
|
2722
|
-
numeric: true
|
|
2723
|
-
}) > 0) {
|
|
2724
|
-
latestByName.set(integration.name, {
|
|
2725
|
-
id: integration.id,
|
|
2726
|
-
name: integration.name,
|
|
2727
|
-
version: integration.version,
|
|
2728
|
-
updatedAt: integration.updatedAt,
|
|
2729
|
-
createdAt: integration.createdAt,
|
|
2730
|
-
title: integration.title,
|
|
2731
|
-
description: integration.description,
|
|
2732
|
-
iconUrl: integration.iconUrl,
|
|
2733
|
-
public: integration.public,
|
|
2734
|
-
visibility: integration.visibility,
|
|
2735
|
-
ownerWorkspace: integration.ownerWorkspace ? {
|
|
2736
|
-
id: integration.ownerWorkspace.id,
|
|
2737
|
-
name: integration.ownerWorkspace.name
|
|
2738
|
-
} : undefined,
|
|
2739
|
-
verificationStatus: integration.verificationStatus
|
|
2740
|
-
});
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
const integrations = Array.from(latestByName.values()).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
2744
|
-
const newCache = {
|
|
2745
|
-
lastUpdated: new Date().toISOString(),
|
|
2746
|
-
integrations
|
|
2747
|
-
};
|
|
2748
|
-
await this.saveCache(newCache);
|
|
2749
|
-
} catch (error) {
|
|
2750
|
-
throw new AdkError({
|
|
2751
|
-
code: "HUB_CACHE_REFRESH_FAILED",
|
|
2752
|
-
message: `Failed to refresh hub cache: ${error instanceof Error ? error.message : String(error)}`,
|
|
2753
|
-
expected: true,
|
|
2754
|
-
cause: error
|
|
2755
|
-
});
|
|
2756
|
-
}
|
|
2757
|
-
}
|
|
2758
|
-
async getAllIntegrations() {
|
|
2759
|
-
await this.refresh();
|
|
2760
|
-
const cache2 = await this.loadCache();
|
|
2761
|
-
return cache2?.integrations || [];
|
|
2762
|
-
}
|
|
2763
|
-
async searchIntegrations(query) {
|
|
2764
|
-
const integrations = await this.getAllIntegrations();
|
|
2765
|
-
const lowerQuery = query.toLowerCase();
|
|
2766
|
-
return integrations.filter((integration) => integration.name.toLowerCase().includes(lowerQuery) || integration.title?.toLowerCase().includes(lowerQuery) || integration.description?.toLowerCase().includes(lowerQuery));
|
|
2767
|
-
}
|
|
2768
|
-
async getIntegrationByName(name) {
|
|
2769
|
-
const integrations = await this.getAllIntegrations();
|
|
2770
|
-
return integrations.find((i) => i.name === name) || null;
|
|
2771
|
-
}
|
|
2772
|
-
async getIntegrationVersions(name) {
|
|
2773
|
-
const integration = await this.getIntegrationByName(name);
|
|
2774
|
-
return integration ? [integration.version] : [];
|
|
2775
|
-
}
|
|
2776
|
-
async getStats() {
|
|
2777
|
-
const cache2 = await this.loadCache();
|
|
2778
|
-
try {
|
|
2779
|
-
const stats = await fs10.stat(HubCache.CACHE_PATH);
|
|
2780
|
-
return {
|
|
2781
|
-
lastUpdated: cache2 ? new Date(cache2.lastUpdated) : null,
|
|
2782
|
-
integrationCount: cache2?.integrations.length || 0,
|
|
2783
|
-
cacheSize: stats.size
|
|
2784
|
-
};
|
|
2785
|
-
} catch {
|
|
2786
|
-
return {
|
|
2787
|
-
lastUpdated: null,
|
|
2788
|
-
integrationCount: 0,
|
|
2789
|
-
cacheSize: 0
|
|
2790
|
-
};
|
|
2791
|
-
}
|
|
2792
|
-
}
|
|
2793
|
-
async clear() {
|
|
2794
|
-
try {
|
|
2795
|
-
await fs10.unlink(HubCache.CACHE_PATH);
|
|
2796
|
-
} catch {}
|
|
2797
|
-
}
|
|
2798
|
-
};
|
|
2799
|
-
});
|
|
2800
|
-
|
|
2801
2659
|
// src/integrations/config-utils.ts
|
|
2802
2660
|
function mergeIntegrationConfig(current, desired) {
|
|
2803
2661
|
if (desired === undefined) {
|
|
@@ -2896,14 +2754,13 @@ var init_integrations = __esm(() => {
|
|
|
2896
2754
|
init_dependencies_parser();
|
|
2897
2755
|
init_cache2();
|
|
2898
2756
|
init_enhanced_cache();
|
|
2899
|
-
init_hub_cache();
|
|
2900
2757
|
init_config_utils();
|
|
2901
2758
|
});
|
|
2902
2759
|
|
|
2903
2760
|
// src/interfaces/enhanced-cache.ts
|
|
2904
|
-
import
|
|
2905
|
-
import
|
|
2906
|
-
import
|
|
2761
|
+
import fs10 from "fs/promises";
|
|
2762
|
+
import path11 from "path";
|
|
2763
|
+
import os7 from "os";
|
|
2907
2764
|
|
|
2908
2765
|
class EnhancedInterfaceCache {
|
|
2909
2766
|
cacheDir;
|
|
@@ -2912,21 +2769,21 @@ class EnhancedInterfaceCache {
|
|
|
2912
2769
|
noCache;
|
|
2913
2770
|
constructor(noCache = false) {
|
|
2914
2771
|
this.noCache = noCache;
|
|
2915
|
-
this.cacheDir =
|
|
2916
|
-
this.resolutionsDir =
|
|
2917
|
-
this.definitionsDir =
|
|
2772
|
+
this.cacheDir = path11.join(os7.homedir(), ".adk", "cache", "interfaces");
|
|
2773
|
+
this.resolutionsDir = path11.join(this.cacheDir, "resolutions");
|
|
2774
|
+
this.definitionsDir = path11.join(this.cacheDir, "definitions");
|
|
2918
2775
|
}
|
|
2919
2776
|
async ensureCacheDirs() {
|
|
2920
|
-
await
|
|
2921
|
-
await
|
|
2777
|
+
await fs10.mkdir(this.resolutionsDir, { recursive: true });
|
|
2778
|
+
await fs10.mkdir(this.definitionsDir, { recursive: true });
|
|
2922
2779
|
}
|
|
2923
2780
|
async getResolution(name, version, workspace) {
|
|
2924
2781
|
if (this.noCache)
|
|
2925
2782
|
return null;
|
|
2926
2783
|
try {
|
|
2927
2784
|
const key = this.getResolutionKey(name, version, workspace);
|
|
2928
|
-
const cachePath =
|
|
2929
|
-
const data = await
|
|
2785
|
+
const cachePath = path11.join(this.resolutionsDir, `${key}.json`);
|
|
2786
|
+
const data = await fs10.readFile(cachePath, "utf-8");
|
|
2930
2787
|
const resolution = JSON.parse(data);
|
|
2931
2788
|
const cachedAt = new Date(resolution.cachedAt);
|
|
2932
2789
|
const ageMinutes = (Date.now() - cachedAt.getTime()) / (1000 * 60);
|
|
@@ -2940,21 +2797,21 @@ class EnhancedInterfaceCache {
|
|
|
2940
2797
|
async setResolution(name, version, workspace, interfaceId, updatedAt) {
|
|
2941
2798
|
await this.ensureCacheDirs();
|
|
2942
2799
|
const key = this.getResolutionKey(name, version, workspace);
|
|
2943
|
-
const cachePath =
|
|
2800
|
+
const cachePath = path11.join(this.resolutionsDir, `${key}.json`);
|
|
2944
2801
|
const resolution = {
|
|
2945
2802
|
interfaceId,
|
|
2946
2803
|
updatedAt,
|
|
2947
2804
|
cachedAt: new Date().toISOString()
|
|
2948
2805
|
};
|
|
2949
|
-
await
|
|
2806
|
+
await fs10.writeFile(cachePath, JSON.stringify(resolution));
|
|
2950
2807
|
}
|
|
2951
2808
|
async getDefinition(interfaceId, updatedAt) {
|
|
2952
2809
|
if (this.noCache)
|
|
2953
2810
|
return null;
|
|
2954
2811
|
try {
|
|
2955
2812
|
const key = this.getDefinitionKey(interfaceId, updatedAt);
|
|
2956
|
-
const cachePath =
|
|
2957
|
-
const data = await
|
|
2813
|
+
const cachePath = path11.join(this.definitionsDir, `${key}.json`);
|
|
2814
|
+
const data = await fs10.readFile(cachePath, "utf-8");
|
|
2958
2815
|
const cached = JSON.parse(data);
|
|
2959
2816
|
return cached.definition;
|
|
2960
2817
|
} catch {
|
|
@@ -2964,28 +2821,28 @@ class EnhancedInterfaceCache {
|
|
|
2964
2821
|
async setDefinition(interfaceId, updatedAt, definition) {
|
|
2965
2822
|
await this.ensureCacheDirs();
|
|
2966
2823
|
const key = this.getDefinitionKey(interfaceId, updatedAt);
|
|
2967
|
-
const cachePath =
|
|
2824
|
+
const cachePath = path11.join(this.definitionsDir, `${key}.json`);
|
|
2968
2825
|
const cached = {
|
|
2969
2826
|
definition,
|
|
2970
2827
|
cachedAt: new Date().toISOString()
|
|
2971
2828
|
};
|
|
2972
|
-
await
|
|
2829
|
+
await fs10.writeFile(cachePath, JSON.stringify(cached));
|
|
2973
2830
|
}
|
|
2974
2831
|
async clear() {
|
|
2975
2832
|
try {
|
|
2976
|
-
const resolutionFiles = await
|
|
2977
|
-
await Promise.all(resolutionFiles.map((f) =>
|
|
2978
|
-
const definitionFiles = await
|
|
2979
|
-
await Promise.all(definitionFiles.map((f) =>
|
|
2833
|
+
const resolutionFiles = await fs10.readdir(this.resolutionsDir);
|
|
2834
|
+
await Promise.all(resolutionFiles.map((f) => fs10.unlink(path11.join(this.resolutionsDir, f))));
|
|
2835
|
+
const definitionFiles = await fs10.readdir(this.definitionsDir);
|
|
2836
|
+
await Promise.all(definitionFiles.map((f) => fs10.unlink(path11.join(this.definitionsDir, f))));
|
|
2980
2837
|
} catch {}
|
|
2981
2838
|
}
|
|
2982
2839
|
async getStats() {
|
|
2983
2840
|
const getDirectoryStats = async (dir) => {
|
|
2984
2841
|
try {
|
|
2985
|
-
const files = await
|
|
2842
|
+
const files = await fs10.readdir(dir);
|
|
2986
2843
|
let totalSize = 0;
|
|
2987
2844
|
for (const file of files) {
|
|
2988
|
-
const stats = await
|
|
2845
|
+
const stats = await fs10.stat(path11.join(dir, file));
|
|
2989
2846
|
totalSize += stats.size;
|
|
2990
2847
|
}
|
|
2991
2848
|
return { count: files.length, sizeBytes: totalSize };
|
|
@@ -3382,7 +3239,7 @@ var init_component_files = __esm(() => {
|
|
|
3382
3239
|
// src/agent-project/component-source-resolver.ts
|
|
3383
3240
|
import { Project, SyntaxKind } from "ts-morph";
|
|
3384
3241
|
import { readFileSync } from "fs";
|
|
3385
|
-
import * as
|
|
3242
|
+
import * as path12 from "path";
|
|
3386
3243
|
function resolveComponentSources(absolutePath) {
|
|
3387
3244
|
const project = new Project({ useInMemoryFileSystem: false, skipAddingFilesFromTsConfig: true });
|
|
3388
3245
|
const sourceFile = project.createSourceFile(absolutePath, readFileSync(absolutePath, "utf-8"), { overwrite: true });
|
|
@@ -3395,12 +3252,12 @@ function resolveComponentSources(absolutePath) {
|
|
|
3395
3252
|
}
|
|
3396
3253
|
function collectBpTsxImports(sourceFile, absolutePath) {
|
|
3397
3254
|
const imports = new Map;
|
|
3398
|
-
const dir =
|
|
3255
|
+
const dir = path12.dirname(absolutePath);
|
|
3399
3256
|
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3400
3257
|
const specifier = decl.getModuleSpecifierValue();
|
|
3401
3258
|
if (!specifier.endsWith(BP_TSX_SUFFIX))
|
|
3402
3259
|
continue;
|
|
3403
|
-
const resolved =
|
|
3260
|
+
const resolved = path12.resolve(dir, specifier);
|
|
3404
3261
|
const defaultImport = decl.getDefaultImport();
|
|
3405
3262
|
if (defaultImport) {
|
|
3406
3263
|
imports.set(defaultImport.getText(), resolved);
|
|
@@ -3526,8 +3383,8 @@ import { BuiltInActions, BuiltInWorkflows, Errors as Errors2, Primitives as Prim
|
|
|
3526
3383
|
import { Autonomous } from "@botpress/runtime";
|
|
3527
3384
|
import createDebug2 from "debug";
|
|
3528
3385
|
import { createRequire as createRequire2 } from "module";
|
|
3529
|
-
import
|
|
3530
|
-
import
|
|
3386
|
+
import fs11 from "fs/promises";
|
|
3387
|
+
import path13 from "path";
|
|
3531
3388
|
function getToolDefinition(value) {
|
|
3532
3389
|
if (typeof value !== "object" || value === null) {
|
|
3533
3390
|
return;
|
|
@@ -3586,7 +3443,7 @@ var init_agent_project = __esm(() => {
|
|
|
3586
3443
|
_tools = [];
|
|
3587
3444
|
constructor(projectPath, options = {}) {
|
|
3588
3445
|
this._options = options;
|
|
3589
|
-
this._path =
|
|
3446
|
+
this._path = path13.resolve(projectPath);
|
|
3590
3447
|
this._integrationManager = new IntegrationManager({
|
|
3591
3448
|
noCache: options.noCache
|
|
3592
3449
|
});
|
|
@@ -3598,7 +3455,7 @@ var init_agent_project = __esm(() => {
|
|
|
3598
3455
|
});
|
|
3599
3456
|
}
|
|
3600
3457
|
static async load(projectPath, options = {}) {
|
|
3601
|
-
const resolvedPath =
|
|
3458
|
+
const resolvedPath = path13.resolve(projectPath);
|
|
3602
3459
|
if (!options.noCache) {
|
|
3603
3460
|
const cached = AgentProject._projectCache.get(resolvedPath);
|
|
3604
3461
|
if (cached) {
|
|
@@ -3616,7 +3473,7 @@ var init_agent_project = __esm(() => {
|
|
|
3616
3473
|
AgentProject._projectCache.clear();
|
|
3617
3474
|
}
|
|
3618
3475
|
static clearCacheForPath(projectPath) {
|
|
3619
|
-
const resolvedPath =
|
|
3476
|
+
const resolvedPath = path13.resolve(projectPath);
|
|
3620
3477
|
AgentProject._projectCache.delete(resolvedPath);
|
|
3621
3478
|
}
|
|
3622
3479
|
get path() {
|
|
@@ -3732,17 +3589,17 @@ var init_agent_project = __esm(() => {
|
|
|
3732
3589
|
const warnings = [];
|
|
3733
3590
|
const info = [];
|
|
3734
3591
|
try {
|
|
3735
|
-
await
|
|
3592
|
+
await fs11.access(this._path);
|
|
3736
3593
|
const requiredFiles = ["agent.config.ts"];
|
|
3737
3594
|
for (const file of requiredFiles) {
|
|
3738
3595
|
try {
|
|
3739
|
-
await
|
|
3596
|
+
await fs11.access(path13.join(this._path, file));
|
|
3740
3597
|
} catch {
|
|
3741
3598
|
errors.push(ValidationErrors.requiredFileMissing(file));
|
|
3742
3599
|
}
|
|
3743
3600
|
}
|
|
3744
3601
|
try {
|
|
3745
|
-
await
|
|
3602
|
+
await fs11.access(path13.join(this._path, "agent.json"));
|
|
3746
3603
|
} catch {
|
|
3747
3604
|
info.push({
|
|
3748
3605
|
$type: "ValidationError",
|
|
@@ -3756,7 +3613,7 @@ var init_agent_project = __esm(() => {
|
|
|
3756
3613
|
const expectedDirs = ["actions", "workflows", "conversations", "assets"];
|
|
3757
3614
|
for (const dir of expectedDirs) {
|
|
3758
3615
|
try {
|
|
3759
|
-
const stats = await
|
|
3616
|
+
const stats = await fs11.stat(path13.join(this._path, dir));
|
|
3760
3617
|
if (!stats.isDirectory()) {
|
|
3761
3618
|
warnings.push(ValidationErrors.invalidStructure(dir, "directory"));
|
|
3762
3619
|
}
|
|
@@ -3840,9 +3697,9 @@ var init_agent_project = __esm(() => {
|
|
|
3840
3697
|
}
|
|
3841
3698
|
async createAgentInfo(info) {
|
|
3842
3699
|
const { devId, ...agentJsonInfo } = info;
|
|
3843
|
-
const agentPath =
|
|
3700
|
+
const agentPath = path13.join(this._path, "agent.json");
|
|
3844
3701
|
const agentContent = stringifyWithOrder(agentJsonInfo, agentInfoKeyOrder);
|
|
3845
|
-
await
|
|
3702
|
+
await fs11.writeFile(agentPath, agentContent);
|
|
3846
3703
|
this._agentInfo = info;
|
|
3847
3704
|
if (devId) {
|
|
3848
3705
|
await this.createAgentLocalInfo({ devId });
|
|
@@ -3859,24 +3716,24 @@ var init_agent_project = __esm(() => {
|
|
|
3859
3716
|
const { devId, ...agentJsonUpdates } = updates;
|
|
3860
3717
|
const updatedInfo = { ...this._agentInfo, ...agentJsonUpdates };
|
|
3861
3718
|
const { devId: _devId, ...agentJsonData } = updatedInfo;
|
|
3862
|
-
const agentPath =
|
|
3719
|
+
const agentPath = path13.join(this._path, "agent.json");
|
|
3863
3720
|
const agentContent = stringifyWithOrder(agentJsonData, agentInfoKeyOrder);
|
|
3864
|
-
await
|
|
3721
|
+
await fs11.writeFile(agentPath, agentContent);
|
|
3865
3722
|
this._agentInfo = updatedInfo;
|
|
3866
3723
|
if (devId !== undefined) {
|
|
3867
3724
|
await this.updateAgentLocalInfo({ devId });
|
|
3868
3725
|
}
|
|
3869
3726
|
}
|
|
3870
3727
|
async createAgentLocalInfo(info) {
|
|
3871
|
-
const localPath =
|
|
3728
|
+
const localPath = path13.join(this._path, "agent.local.json");
|
|
3872
3729
|
let existing = {};
|
|
3873
3730
|
try {
|
|
3874
|
-
const content2 = await
|
|
3731
|
+
const content2 = await fs11.readFile(localPath, "utf-8");
|
|
3875
3732
|
existing = JSON.parse(content2);
|
|
3876
3733
|
} catch {}
|
|
3877
3734
|
const merged = { ...existing, ...info };
|
|
3878
3735
|
const content = stringifyWithOrder(merged, agentLocalInfoKeyOrder);
|
|
3879
|
-
await
|
|
3736
|
+
await fs11.writeFile(localPath, content);
|
|
3880
3737
|
if (this._agentInfo) {
|
|
3881
3738
|
if (merged.botId)
|
|
3882
3739
|
this._agentInfo.botId = merged.botId;
|
|
@@ -3896,10 +3753,10 @@ var init_agent_project = __esm(() => {
|
|
|
3896
3753
|
}
|
|
3897
3754
|
}
|
|
3898
3755
|
async updateAgentLocalInfo(updates) {
|
|
3899
|
-
const localPath =
|
|
3756
|
+
const localPath = path13.join(this._path, "agent.local.json");
|
|
3900
3757
|
let existing = {};
|
|
3901
3758
|
try {
|
|
3902
|
-
const content = await
|
|
3759
|
+
const content = await fs11.readFile(localPath, "utf-8");
|
|
3903
3760
|
existing = JSON.parse(content);
|
|
3904
3761
|
} catch {}
|
|
3905
3762
|
const updated = { ...existing, ...updates };
|
|
@@ -3910,21 +3767,21 @@ var init_agent_project = __esm(() => {
|
|
|
3910
3767
|
}
|
|
3911
3768
|
if (Object.keys(updated).length === 0) {
|
|
3912
3769
|
try {
|
|
3913
|
-
await
|
|
3770
|
+
await fs11.unlink(localPath);
|
|
3914
3771
|
} catch {}
|
|
3915
3772
|
} else {
|
|
3916
3773
|
const content = stringifyWithOrder(updated, agentLocalInfoKeyOrder);
|
|
3917
|
-
await
|
|
3774
|
+
await fs11.writeFile(localPath, content);
|
|
3918
3775
|
}
|
|
3919
3776
|
if (this._agentInfo) {
|
|
3920
|
-
const agentJsonPath =
|
|
3777
|
+
const agentJsonPath = path13.join(this._path, "agent.json");
|
|
3921
3778
|
let base = {
|
|
3922
3779
|
botId: this._agentInfo.botId,
|
|
3923
3780
|
workspaceId: this._agentInfo.workspaceId,
|
|
3924
3781
|
apiUrl: this._agentInfo.apiUrl
|
|
3925
3782
|
};
|
|
3926
3783
|
try {
|
|
3927
|
-
const agentJsonContent = await
|
|
3784
|
+
const agentJsonContent = await fs11.readFile(agentJsonPath, "utf-8");
|
|
3928
3785
|
const parsed = JSON.parse(agentJsonContent);
|
|
3929
3786
|
base = {
|
|
3930
3787
|
botId: parsed.botId ?? this._agentInfo.botId,
|
|
@@ -3956,10 +3813,10 @@ var init_agent_project = __esm(() => {
|
|
|
3956
3813
|
this._integrations = [];
|
|
3957
3814
|
this._interfaces = [];
|
|
3958
3815
|
try {
|
|
3959
|
-
const configPath =
|
|
3816
|
+
const configPath = path13.join(this._path, "agent.config.ts");
|
|
3960
3817
|
debug2("loading agent.config.ts from %s", configPath);
|
|
3961
|
-
const projectRequire = createRequire2(
|
|
3962
|
-
debug2("created projectRequire from %s",
|
|
3818
|
+
const projectRequire = createRequire2(path13.join(this._path, "package.json"));
|
|
3819
|
+
debug2("created projectRequire from %s", path13.join(this._path, "package.json"));
|
|
3963
3820
|
try {
|
|
3964
3821
|
const resolvedPath = projectRequire.resolve(configPath);
|
|
3965
3822
|
debug2("resolved config path: %s", resolvedPath);
|
|
@@ -4156,8 +4013,8 @@ ${err.stack?.split(`
|
|
|
4156
4013
|
}
|
|
4157
4014
|
}
|
|
4158
4015
|
isBarrelReexport(existing, newPath, newExport, newDefinition) {
|
|
4159
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4160
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4016
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path13.basename(newPath));
|
|
4017
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path13.basename(existing.path));
|
|
4161
4018
|
if (!isNewBarrel && !isExistingBarrel) {
|
|
4162
4019
|
return false;
|
|
4163
4020
|
}
|
|
@@ -4169,16 +4026,16 @@ ${err.stack?.split(`
|
|
|
4169
4026
|
return true;
|
|
4170
4027
|
}
|
|
4171
4028
|
isToolBarrelReexport(existingPath, newPath) {
|
|
4172
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4173
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4029
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path13.basename(newPath));
|
|
4030
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path13.basename(existingPath));
|
|
4174
4031
|
if (!isNewBarrel && !isExistingBarrel) {
|
|
4175
4032
|
return false;
|
|
4176
4033
|
}
|
|
4177
4034
|
return true;
|
|
4178
4035
|
}
|
|
4179
4036
|
shouldPreferToolDefinition(existingPath, newPath) {
|
|
4180
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4181
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4037
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path13.basename(newPath));
|
|
4038
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path13.basename(existingPath));
|
|
4182
4039
|
return isExistingBarrel && !isNewBarrel;
|
|
4183
4040
|
}
|
|
4184
4041
|
getChannelsList(channelSpec) {
|
|
@@ -4194,8 +4051,8 @@ ${err.stack?.split(`
|
|
|
4194
4051
|
if (this._options.adkCommand) {
|
|
4195
4052
|
setAdkCommand(this._options.adkCommand);
|
|
4196
4053
|
}
|
|
4197
|
-
const src =
|
|
4198
|
-
if (!await
|
|
4054
|
+
const src = path13.join(this._path, "src");
|
|
4055
|
+
if (!await fs11.stat(src).catch(() => false)) {
|
|
4199
4056
|
this._errors.push({
|
|
4200
4057
|
$type: "ValidationError",
|
|
4201
4058
|
code: "INVALID_STRUCTURE" /* INVALID_STRUCTURE */,
|
|
@@ -4204,14 +4061,14 @@ ${err.stack?.split(`
|
|
|
4204
4061
|
});
|
|
4205
4062
|
return;
|
|
4206
4063
|
}
|
|
4207
|
-
const allFiles = await
|
|
4064
|
+
const allFiles = await fs11.readdir(src, {
|
|
4208
4065
|
withFileTypes: true,
|
|
4209
4066
|
recursive: true
|
|
4210
4067
|
});
|
|
4211
4068
|
for (const file of allFiles.filter((x) => x.isFile())) {
|
|
4212
4069
|
const filename = file.name;
|
|
4213
|
-
const absolutePath =
|
|
4214
|
-
const relPath =
|
|
4070
|
+
const absolutePath = path13.join(file.parentPath, file.name);
|
|
4071
|
+
const relPath = path13.relative(this.path, absolutePath);
|
|
4215
4072
|
if (filename.toLowerCase().endsWith(".d.ts")) {
|
|
4216
4073
|
continue;
|
|
4217
4074
|
}
|
|
@@ -4498,7 +4355,7 @@ ${err.stack?.split(`
|
|
|
4498
4355
|
});
|
|
4499
4356
|
|
|
4500
4357
|
// src/generators/utils.ts
|
|
4501
|
-
import
|
|
4358
|
+
import path14 from "path";
|
|
4502
4359
|
async function getFormat() {
|
|
4503
4360
|
if (!_formatLoaded) {
|
|
4504
4361
|
_formatLoaded = true;
|
|
@@ -4546,9 +4403,9 @@ var _format = null, _formatLoaded = false, formatCode = async (code, filepath) =
|
|
|
4546
4403
|
`));
|
|
4547
4404
|
return code;
|
|
4548
4405
|
}
|
|
4549
|
-
}, ADK_VERSION = "1.19.0-beta.
|
|
4550
|
-
const fromDir =
|
|
4551
|
-
const relative2 =
|
|
4406
|
+
}, ADK_VERSION = "1.19.0-beta.13", relative = (from, to) => {
|
|
4407
|
+
const fromDir = path14.dirname(from);
|
|
4408
|
+
const relative2 = path14.relative(fromDir, to);
|
|
4552
4409
|
return relative2.startsWith(".") ? relative2 : `./${relative2}`;
|
|
4553
4410
|
};
|
|
4554
4411
|
var init_utils = () => {};
|
|
@@ -15505,7 +15362,7 @@ __export(exports_action_types, {
|
|
|
15505
15362
|
generateActionTypes: () => generateActionTypes
|
|
15506
15363
|
});
|
|
15507
15364
|
import { z as z9 } from "@botpress/sdk";
|
|
15508
|
-
import
|
|
15365
|
+
import path41 from "path";
|
|
15509
15366
|
async function generateActionTypes(project) {
|
|
15510
15367
|
const actionDefs = [];
|
|
15511
15368
|
for (const action of project.actions) {
|
|
@@ -15522,7 +15379,7 @@ async function generateActionTypes(project) {
|
|
|
15522
15379
|
};`);
|
|
15523
15380
|
continue;
|
|
15524
15381
|
}
|
|
15525
|
-
const absolutePath =
|
|
15382
|
+
const absolutePath = path41.join(project.path, action.path);
|
|
15526
15383
|
const actionModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
15527
15384
|
const actionInstance = actionModule[action.export] || actionModule.default;
|
|
15528
15385
|
if (actionInstance && actionInstance.input && actionInstance.output) {
|
|
@@ -15567,7 +15424,7 @@ ${actionDefs.join(`
|
|
|
15567
15424
|
};
|
|
15568
15425
|
}
|
|
15569
15426
|
`;
|
|
15570
|
-
const actionTypesPath =
|
|
15427
|
+
const actionTypesPath = path41.join(project.path, ".adk", "action-types.d.ts");
|
|
15571
15428
|
await createFile(actionTypesPath, await formatCode(content));
|
|
15572
15429
|
}
|
|
15573
15430
|
var transforms5;
|
|
@@ -15582,7 +15439,7 @@ var exports_integration_action_types = {};
|
|
|
15582
15439
|
__export(exports_integration_action_types, {
|
|
15583
15440
|
generateIntegrationActionTypes: () => generateIntegrationActionTypes
|
|
15584
15441
|
});
|
|
15585
|
-
import
|
|
15442
|
+
import path42 from "path";
|
|
15586
15443
|
async function generateIntegrationActionTypes(project) {
|
|
15587
15444
|
const content = `
|
|
15588
15445
|
////////////////////////////////////////////////////////
|
|
@@ -15616,7 +15473,7 @@ type IntegrationsMap<T> = {
|
|
|
15616
15473
|
export type IntegrationActions = IntegrationsMap<Integrations>;
|
|
15617
15474
|
}
|
|
15618
15475
|
`;
|
|
15619
|
-
const integrationActionTypesPath =
|
|
15476
|
+
const integrationActionTypesPath = path42.join(project.path, ".adk", "integration-action-types.d.ts");
|
|
15620
15477
|
await createFile(integrationActionTypesPath, await formatCode(content));
|
|
15621
15478
|
}
|
|
15622
15479
|
var init_integration_action_types = __esm(() => {
|
|
@@ -15628,7 +15485,7 @@ var init_integration_action_types = __esm(() => {
|
|
|
15628
15485
|
var require_package = __commonJS((exports, module) => {
|
|
15629
15486
|
module.exports = {
|
|
15630
15487
|
name: "@botpress/adk",
|
|
15631
|
-
version: "1.19.0-beta.
|
|
15488
|
+
version: "1.19.0-beta.13",
|
|
15632
15489
|
description: "Core ADK library for building AI agents on Botpress",
|
|
15633
15490
|
keywords: [
|
|
15634
15491
|
"adk",
|
|
@@ -15689,7 +15546,7 @@ var require_package = __commonJS((exports, module) => {
|
|
|
15689
15546
|
"@botpress/cli": "~6.8.6",
|
|
15690
15547
|
"@botpress/client": "~1.46.0",
|
|
15691
15548
|
"@botpress/cognitive": "~0.6.0",
|
|
15692
|
-
"@botpress/runtime": "^1.19.0-beta.
|
|
15549
|
+
"@botpress/runtime": "^1.19.0-beta.13",
|
|
15693
15550
|
"@botpress/sdk": "~6.11.1",
|
|
15694
15551
|
"@bpinternal/jex": "^1.2.4",
|
|
15695
15552
|
"@bpinternal/yargs-extra": "^0.0.21",
|
|
@@ -15982,6 +15839,7 @@ class IntegrationRegistry {
|
|
|
15982
15839
|
// src/plugins/manager.ts
|
|
15983
15840
|
init_src();
|
|
15984
15841
|
init_auth();
|
|
15842
|
+
import { Client as Client4 } from "@botpress/client";
|
|
15985
15843
|
|
|
15986
15844
|
// src/plugins/enhanced-cache.ts
|
|
15987
15845
|
import fs6 from "fs/promises";
|
|
@@ -16114,15 +15972,33 @@ class PluginManager {
|
|
|
16114
15972
|
}
|
|
16115
15973
|
async getClient() {
|
|
16116
15974
|
if (!this.client) {
|
|
16117
|
-
this.
|
|
16118
|
-
|
|
16119
|
-
|
|
16120
|
-
|
|
16121
|
-
|
|
16122
|
-
|
|
16123
|
-
|
|
16124
|
-
|
|
16125
|
-
|
|
15975
|
+
const hasProjectScope = !!(this.options.project || this.options.workspaceId);
|
|
15976
|
+
if (hasProjectScope) {
|
|
15977
|
+
this.client = await getProjectClient({
|
|
15978
|
+
project: this.options.project,
|
|
15979
|
+
credentials: this.options.credentials,
|
|
15980
|
+
apiUrl: this.options.apiUrl,
|
|
15981
|
+
workspaceId: this.options.workspaceId,
|
|
15982
|
+
headers: {
|
|
15983
|
+
"x-multiple-integrations": "true"
|
|
15984
|
+
}
|
|
15985
|
+
});
|
|
15986
|
+
} else if (this.options.credentials) {
|
|
15987
|
+
this.client = new Client4({
|
|
15988
|
+
token: this.options.credentials.token,
|
|
15989
|
+
apiUrl: this.options.apiUrl || this.options.credentials.apiUrl,
|
|
15990
|
+
...this.options.credentials.workspaceId ? { workspaceId: this.options.credentials.workspaceId } : {},
|
|
15991
|
+
headers: {
|
|
15992
|
+
"x-multiple-integrations": "true"
|
|
15993
|
+
}
|
|
15994
|
+
});
|
|
15995
|
+
} else {
|
|
15996
|
+
this.client = await getProjectClient({
|
|
15997
|
+
headers: {
|
|
15998
|
+
"x-multiple-integrations": "true"
|
|
15999
|
+
}
|
|
16000
|
+
});
|
|
16001
|
+
}
|
|
16126
16002
|
}
|
|
16127
16003
|
return this.client;
|
|
16128
16004
|
}
|
|
@@ -16952,8 +16828,8 @@ class InterfaceRegistry {
|
|
|
16952
16828
|
}
|
|
16953
16829
|
// src/dependencies/migration.ts
|
|
16954
16830
|
init_lock_file();
|
|
16955
|
-
import * as
|
|
16956
|
-
import * as
|
|
16831
|
+
import * as fs12 from "fs/promises";
|
|
16832
|
+
import * as path16 from "path";
|
|
16957
16833
|
import { Project as Project3, SyntaxKind as SyntaxKind3 } from "ts-morph";
|
|
16958
16834
|
|
|
16959
16835
|
// src/agent-project/config-writer.ts
|
|
@@ -16961,12 +16837,12 @@ init_utils();
|
|
|
16961
16837
|
init_src();
|
|
16962
16838
|
import { Project as Project2, SyntaxKind as SyntaxKind2 } from "ts-morph";
|
|
16963
16839
|
import { readFileSync as readFileSync2 } from "fs";
|
|
16964
|
-
import * as
|
|
16840
|
+
import * as path15 from "path";
|
|
16965
16841
|
|
|
16966
16842
|
class ConfigWriter {
|
|
16967
16843
|
configPath;
|
|
16968
16844
|
constructor(projectPath) {
|
|
16969
|
-
this.configPath =
|
|
16845
|
+
this.configPath = path15.join(projectPath, "agent.config.ts");
|
|
16970
16846
|
}
|
|
16971
16847
|
loadConfig() {
|
|
16972
16848
|
const project = new Project2;
|
|
@@ -17375,9 +17251,9 @@ async function migrateFromConfig(opts) {
|
|
|
17375
17251
|
return result;
|
|
17376
17252
|
}
|
|
17377
17253
|
async function readAliasesFromConfig(projectPath) {
|
|
17378
|
-
const configPath =
|
|
17254
|
+
const configPath = path16.join(projectPath, "agent.config.ts");
|
|
17379
17255
|
try {
|
|
17380
|
-
await
|
|
17256
|
+
await fs12.access(configPath);
|
|
17381
17257
|
} catch {
|
|
17382
17258
|
return { integrations: {}, plugins: {} };
|
|
17383
17259
|
}
|
|
@@ -17534,12 +17410,12 @@ class BpAddCommand extends BaseCommand {
|
|
|
17534
17410
|
}
|
|
17535
17411
|
// src/commands/bp-build-command.ts
|
|
17536
17412
|
import { execa as execa2 } from "execa";
|
|
17537
|
-
import { join as
|
|
17413
|
+
import { join as join4 } from "path";
|
|
17538
17414
|
import { access as access3 } from "fs/promises";
|
|
17539
17415
|
|
|
17540
17416
|
// src/utils/source-map-optimizer.ts
|
|
17541
17417
|
init_src();
|
|
17542
|
-
import { readFile as
|
|
17418
|
+
import { readFile as readFile2, writeFile as writeFile3 } from "fs/promises";
|
|
17543
17419
|
import { resolve as resolve2, isAbsolute, relative as relative2, dirname as dirname2 } from "path";
|
|
17544
17420
|
function encodeVLQ(value) {
|
|
17545
17421
|
const base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
@@ -17704,7 +17580,7 @@ function encodeKeptSegments(keptByLine, totalLines, sourceIndexMap, nameIndexMap
|
|
|
17704
17580
|
}
|
|
17705
17581
|
async function optimizeSourceMap(options) {
|
|
17706
17582
|
const { sourceMapPath, agentSrcPath } = options;
|
|
17707
|
-
const sourceMapContent = await
|
|
17583
|
+
const sourceMapContent = await readFile2(sourceMapPath, "utf-8");
|
|
17708
17584
|
const sourceMap = JSON.parse(sourceMapContent);
|
|
17709
17585
|
const resolvedAgentSrc = resolve2(agentSrcPath);
|
|
17710
17586
|
const sourceMapDir = resolve2(sourceMapPath, "..");
|
|
@@ -17764,9 +17640,9 @@ async function optimizeSourceMap(options) {
|
|
|
17764
17640
|
if (optimizedContent === sourceMapContent) {
|
|
17765
17641
|
return;
|
|
17766
17642
|
}
|
|
17767
|
-
await
|
|
17643
|
+
await writeFile3(sourceMapPath, optimizedContent, "utf-8");
|
|
17768
17644
|
const cjsPath = sourceMapPath.replace(".cjs.map", ".cjs");
|
|
17769
|
-
let cjsContent = await
|
|
17645
|
+
let cjsContent = await readFile2(cjsPath, "utf-8");
|
|
17770
17646
|
const base64SourceMap = Buffer.from(optimizedContent, "utf-8").toString("base64");
|
|
17771
17647
|
const inlineSourceMap = `//# sourceMappingURL=data:application/json;base64,${base64SourceMap}`;
|
|
17772
17648
|
cjsContent = cjsContent.replace(/\/\/# sourceMappingURL=.*$/m, inlineSourceMap);
|
|
@@ -17774,7 +17650,7 @@ async function optimizeSourceMap(options) {
|
|
|
17774
17650
|
cjsContent += `
|
|
17775
17651
|
${inlineSourceMap}`;
|
|
17776
17652
|
}
|
|
17777
|
-
await
|
|
17653
|
+
await writeFile3(cjsPath, cjsContent, "utf-8");
|
|
17778
17654
|
}
|
|
17779
17655
|
|
|
17780
17656
|
// src/commands/bp-build-command.ts
|
|
@@ -17825,10 +17701,10 @@ class BpBuildCommand extends BaseCommand {
|
|
|
17825
17701
|
}
|
|
17826
17702
|
async optimizeSourceMapIfExists() {
|
|
17827
17703
|
const { botPath } = this.options;
|
|
17828
|
-
const sourceMapPath =
|
|
17704
|
+
const sourceMapPath = join4(botPath, ".botpress", "dist", "index.cjs.map");
|
|
17829
17705
|
try {
|
|
17830
17706
|
await access3(sourceMapPath);
|
|
17831
|
-
const agentSrcPath =
|
|
17707
|
+
const agentSrcPath = join4(botPath, "..", "..", "src");
|
|
17832
17708
|
await optimizeSourceMap({
|
|
17833
17709
|
sourceMapPath,
|
|
17834
17710
|
agentSrcPath
|
|
@@ -17915,7 +17791,7 @@ class BpDeployCommand extends BaseCommand {
|
|
|
17915
17791
|
// src/commands/bp-dev-command.ts
|
|
17916
17792
|
import { execa as execa4 } from "execa";
|
|
17917
17793
|
import treeKill from "tree-kill";
|
|
17918
|
-
import { join as
|
|
17794
|
+
import { join as join5 } from "path";
|
|
17919
17795
|
import { access as access4 } from "fs/promises";
|
|
17920
17796
|
|
|
17921
17797
|
// src/commands/bp-dev-stderr.ts
|
|
@@ -18017,7 +17893,7 @@ class BpDevCommand extends BaseCommand {
|
|
|
18017
17893
|
this.childProcess = execa4(bpCommand, bpArgs, {
|
|
18018
17894
|
cwd: botPath,
|
|
18019
17895
|
env: getBpCliEnvironment({
|
|
18020
|
-
TRACE_DIR:
|
|
17896
|
+
TRACE_DIR: join5(botPath, "traces"),
|
|
18021
17897
|
NODE_ENV: process.env.ADK_DEV_WORKER_NODE_ENV || "development",
|
|
18022
17898
|
VM_DRIVER: process.env.ADK_DEV_WORKER_VM_DRIVER || "node",
|
|
18023
17899
|
ADK_LOCAL_PAT: credentials.token,
|
|
@@ -18034,10 +17910,13 @@ class BpDevCommand extends BaseCommand {
|
|
|
18034
17910
|
...process.env.ADK_DEV_WORKER_POOL_SIZE !== undefined && {
|
|
18035
17911
|
ADK_DEV_WORKER_POOL_SIZE: process.env.ADK_DEV_WORKER_POOL_SIZE
|
|
18036
17912
|
},
|
|
17913
|
+
...process.env.ADK_DEV_WORKER_MIN_SIZE !== undefined && {
|
|
17914
|
+
ADK_DEV_WORKER_MIN_SIZE: process.env.ADK_DEV_WORKER_MIN_SIZE
|
|
17915
|
+
},
|
|
18037
17916
|
ADK_SPAN_INGEST_URL: spanIngestUrl,
|
|
18038
17917
|
...otlpEndpoint && { OTEL_EXPORTER_OTLP_ENDPOINT: otlpEndpoint },
|
|
18039
17918
|
...this.options.botName && { ADK_BOT_NAME: this.options.botName },
|
|
18040
|
-
ADK_DIRECTORY:
|
|
17919
|
+
ADK_DIRECTORY: join5(botPath, ".."),
|
|
18041
17920
|
AGENT_DIRECTORY: this.options.agentPath,
|
|
18042
17921
|
NODE_OPTIONS: getWorkerNodeOptions()
|
|
18043
17922
|
}),
|
|
@@ -18195,10 +18074,10 @@ ${this.stderrLines.join(`
|
|
|
18195
18074
|
}
|
|
18196
18075
|
async optimizeSourceMapIfExists() {
|
|
18197
18076
|
const { botPath } = this.options;
|
|
18198
|
-
const sourceMapPath =
|
|
18077
|
+
const sourceMapPath = join5(botPath, ".botpress", "dist", "index.cjs.map");
|
|
18199
18078
|
try {
|
|
18200
18079
|
await access4(sourceMapPath);
|
|
18201
|
-
const agentSrcPath =
|
|
18080
|
+
const agentSrcPath = join5(botPath, "..", "..", "src");
|
|
18202
18081
|
await optimizeSourceMap({
|
|
18203
18082
|
sourceMapPath,
|
|
18204
18083
|
agentSrcPath
|
|
@@ -18298,21 +18177,23 @@ init_src();
|
|
|
18298
18177
|
|
|
18299
18178
|
// src/workspace/workspace-cache.ts
|
|
18300
18179
|
init_auth();
|
|
18301
|
-
import { Client as
|
|
18180
|
+
import { Client as Client5 } from "@botpress/client";
|
|
18302
18181
|
|
|
18303
18182
|
class WorkspaceCache {
|
|
18304
18183
|
cache = new Map;
|
|
18305
18184
|
CACHE_TTL = 60 * 60 * 1000;
|
|
18306
|
-
async getWorkspaceName(workspaceId) {
|
|
18307
|
-
const
|
|
18185
|
+
async getWorkspaceName(workspaceId, credentials) {
|
|
18186
|
+
const resolvedCredentials = credentials ?? await auth.getActiveCredentials();
|
|
18187
|
+
const apiUrl = resolvedCredentials.apiUrl ?? "https://api.botpress.cloud";
|
|
18188
|
+
const cacheKey = `${apiUrl.replace(/\/+$/, "")}:${workspaceId}`;
|
|
18189
|
+
const cached = this.cache.get(cacheKey);
|
|
18308
18190
|
if (cached && Date.now() - cached.fetchedAt < this.CACHE_TTL) {
|
|
18309
18191
|
return cached.name;
|
|
18310
18192
|
}
|
|
18311
18193
|
try {
|
|
18312
|
-
const
|
|
18313
|
-
|
|
18314
|
-
|
|
18315
|
-
token: credentials.token,
|
|
18194
|
+
const client = new Client5({
|
|
18195
|
+
apiUrl,
|
|
18196
|
+
token: resolvedCredentials.token,
|
|
18316
18197
|
headers: {
|
|
18317
18198
|
"x-multiple-integrations": "true"
|
|
18318
18199
|
}
|
|
@@ -18322,7 +18203,7 @@ class WorkspaceCache {
|
|
|
18322
18203
|
if (!workspace) {
|
|
18323
18204
|
return;
|
|
18324
18205
|
}
|
|
18325
|
-
this.cache.set(
|
|
18206
|
+
this.cache.set(cacheKey, {
|
|
18326
18207
|
id: workspaceId,
|
|
18327
18208
|
name: workspace.name,
|
|
18328
18209
|
fetchedAt: Date.now()
|
|
@@ -18362,14 +18243,14 @@ init_src();
|
|
|
18362
18243
|
var chatBundle = __toESM(require_chat_bundle(), 1);
|
|
18363
18244
|
function getChatClient() {
|
|
18364
18245
|
const mod = chatBundle;
|
|
18365
|
-
const
|
|
18366
|
-
if (!
|
|
18246
|
+
const Client6 = mod.default?.Client ?? mod.Client;
|
|
18247
|
+
if (!Client6) {
|
|
18367
18248
|
throw new AdkError({
|
|
18368
18249
|
code: "CHAT_BUNDLE_STALE",
|
|
18369
18250
|
message: "@botpress/chat bundle did not expose a Client export — build artifact may be stale."
|
|
18370
18251
|
});
|
|
18371
18252
|
}
|
|
18372
|
-
return
|
|
18253
|
+
return Client6;
|
|
18373
18254
|
}
|
|
18374
18255
|
|
|
18375
18256
|
// src/index.ts
|
|
@@ -18452,7 +18333,7 @@ init_types2();
|
|
|
18452
18333
|
init_src();
|
|
18453
18334
|
import { watch } from "fs";
|
|
18454
18335
|
import { EventEmitter as EventEmitter2 } from "events";
|
|
18455
|
-
import
|
|
18336
|
+
import path17 from "path";
|
|
18456
18337
|
|
|
18457
18338
|
class FileWatcher extends EventEmitter2 {
|
|
18458
18339
|
basePath;
|
|
@@ -18476,7 +18357,7 @@ class FileWatcher extends EventEmitter2 {
|
|
|
18476
18357
|
this.watcher = watch(this.basePath, { recursive: true }, (eventType, filename) => {
|
|
18477
18358
|
if (!filename)
|
|
18478
18359
|
return;
|
|
18479
|
-
const fullPath =
|
|
18360
|
+
const fullPath = path17.join(this.basePath, filename);
|
|
18480
18361
|
const relativePath = filename;
|
|
18481
18362
|
if (this.shouldIgnore(relativePath)) {
|
|
18482
18363
|
return;
|
|
@@ -18720,18 +18601,18 @@ class ConfigManager {
|
|
|
18720
18601
|
}
|
|
18721
18602
|
// src/secrets/manager.ts
|
|
18722
18603
|
init_src();
|
|
18723
|
-
import
|
|
18724
|
-
import
|
|
18604
|
+
import fs13 from "fs/promises";
|
|
18605
|
+
import path18 from "path";
|
|
18725
18606
|
|
|
18726
18607
|
class SecretsManager {
|
|
18727
18608
|
storePath;
|
|
18728
18609
|
constructor(projectPath) {
|
|
18729
|
-
this.storePath =
|
|
18610
|
+
this.storePath = path18.join(projectPath, ".adk", "secrets.json");
|
|
18730
18611
|
}
|
|
18731
18612
|
async readStore() {
|
|
18732
18613
|
let content;
|
|
18733
18614
|
try {
|
|
18734
|
-
content = await
|
|
18615
|
+
content = await fs13.readFile(this.storePath, "utf-8");
|
|
18735
18616
|
} catch (err) {
|
|
18736
18617
|
if (err.code === "ENOENT") {
|
|
18737
18618
|
return { dev: {}, prod: {} };
|
|
@@ -18767,11 +18648,11 @@ class SecretsManager {
|
|
|
18767
18648
|
return parsed;
|
|
18768
18649
|
}
|
|
18769
18650
|
async writeStore(store) {
|
|
18770
|
-
await
|
|
18651
|
+
await fs13.mkdir(path18.dirname(this.storePath), { recursive: true });
|
|
18771
18652
|
const tmpPath = `${this.storePath}.tmp`;
|
|
18772
|
-
await
|
|
18653
|
+
await fs13.writeFile(tmpPath, JSON.stringify(store, null, 2) + `
|
|
18773
18654
|
`, { encoding: "utf-8", mode: 384 });
|
|
18774
|
-
await
|
|
18655
|
+
await fs13.rename(tmpPath, this.storePath);
|
|
18775
18656
|
}
|
|
18776
18657
|
async list(env) {
|
|
18777
18658
|
const store = await this.readStore();
|
|
@@ -18814,8 +18695,8 @@ import { validateSecretName } from "@botpress/runtime/definition";
|
|
|
18814
18695
|
// src/agent-init/agent-project-generator.ts
|
|
18815
18696
|
init_src();
|
|
18816
18697
|
init_utils();
|
|
18817
|
-
import * as
|
|
18818
|
-
import * as
|
|
18698
|
+
import * as fs14 from "fs";
|
|
18699
|
+
import * as path19 from "path";
|
|
18819
18700
|
import { fileURLToPath } from "url";
|
|
18820
18701
|
import { createRequire as createRequire3 } from "module";
|
|
18821
18702
|
|
|
@@ -18843,7 +18724,7 @@ var TEXT_EXTENSIONS = new Set([
|
|
|
18843
18724
|
function isTextFile(filename) {
|
|
18844
18725
|
if (filename === ".gitignore")
|
|
18845
18726
|
return true;
|
|
18846
|
-
const ext =
|
|
18727
|
+
const ext = path19.extname(filename).toLowerCase();
|
|
18847
18728
|
return TEXT_EXTENSIONS.has(ext);
|
|
18848
18729
|
}
|
|
18849
18730
|
|
|
@@ -18853,8 +18734,8 @@ class AgentProjectGenerator {
|
|
|
18853
18734
|
packageManager;
|
|
18854
18735
|
template;
|
|
18855
18736
|
constructor(projectPath, packageManager = "bun", template = "blank") {
|
|
18856
|
-
this.projectPath =
|
|
18857
|
-
this.projectName =
|
|
18737
|
+
this.projectPath = path19.resolve(projectPath);
|
|
18738
|
+
this.projectName = path19.basename(this.projectPath);
|
|
18858
18739
|
this.packageManager = packageManager;
|
|
18859
18740
|
this.template = template;
|
|
18860
18741
|
}
|
|
@@ -18862,21 +18743,21 @@ class AgentProjectGenerator {
|
|
|
18862
18743
|
this.ensureEmptyDirectory();
|
|
18863
18744
|
const templateDir = this.resolveTemplateDir();
|
|
18864
18745
|
await this.copyTemplateFiles(templateDir);
|
|
18865
|
-
if (!
|
|
18746
|
+
if (!fs14.existsSync(path19.join(this.projectPath, "agent.json"))) {
|
|
18866
18747
|
this.createAgentJson();
|
|
18867
18748
|
}
|
|
18868
|
-
if (!
|
|
18749
|
+
if (!fs14.existsSync(path19.join(this.projectPath, "CLAUDE.md"))) {
|
|
18869
18750
|
this.createAIAssistantInstructions();
|
|
18870
18751
|
}
|
|
18871
18752
|
}
|
|
18872
18753
|
static getAvailableTemplates() {
|
|
18873
18754
|
try {
|
|
18874
18755
|
const templatesRoot = AgentProjectGenerator.getTemplatesRoot();
|
|
18875
|
-
const configPath =
|
|
18876
|
-
if (!
|
|
18756
|
+
const configPath = path19.join(templatesRoot, "template.config.json");
|
|
18757
|
+
if (!fs14.existsSync(configPath)) {
|
|
18877
18758
|
return [];
|
|
18878
18759
|
}
|
|
18879
|
-
const raw =
|
|
18760
|
+
const raw = fs14.readFileSync(configPath, "utf-8");
|
|
18880
18761
|
const registry = JSON.parse(raw);
|
|
18881
18762
|
return registry.templates;
|
|
18882
18763
|
} catch {
|
|
@@ -18900,16 +18781,16 @@ class AgentProjectGenerator {
|
|
|
18900
18781
|
try {
|
|
18901
18782
|
const esmRequire = createRequire3(import.meta.url);
|
|
18902
18783
|
const adkPkgPath = esmRequire.resolve("@botpress/adk/package.json");
|
|
18903
|
-
const adkRoot =
|
|
18904
|
-
candidates.push(
|
|
18905
|
-
candidates.push(
|
|
18784
|
+
const adkRoot = path19.dirname(adkPkgPath);
|
|
18785
|
+
candidates.push(path19.join(adkRoot, "dist", "templates"));
|
|
18786
|
+
candidates.push(path19.join(adkRoot, "templates"));
|
|
18906
18787
|
} catch {}
|
|
18907
|
-
const thisDir =
|
|
18908
|
-
candidates.push(
|
|
18909
|
-
candidates.push(
|
|
18910
|
-
candidates.push(
|
|
18788
|
+
const thisDir = path19.dirname(fileURLToPath(import.meta.url));
|
|
18789
|
+
candidates.push(path19.resolve(thisDir, "templates"));
|
|
18790
|
+
candidates.push(path19.resolve(thisDir, "../../templates"));
|
|
18791
|
+
candidates.push(path19.join(path19.dirname(process.execPath), "templates"));
|
|
18911
18792
|
for (const candidate of candidates) {
|
|
18912
|
-
if (
|
|
18793
|
+
if (fs14.existsSync(candidate) && fs14.existsSync(path19.join(candidate, "template.config.json"))) {
|
|
18913
18794
|
return candidate;
|
|
18914
18795
|
}
|
|
18915
18796
|
}
|
|
@@ -18928,8 +18809,8 @@ Ensure the ADK package is properly installed or run the CLI build.`
|
|
|
18928
18809
|
}
|
|
18929
18810
|
resolveTemplateDir() {
|
|
18930
18811
|
const templatesRoot = AgentProjectGenerator.getTemplatesRoot();
|
|
18931
|
-
const templateDir =
|
|
18932
|
-
if (!
|
|
18812
|
+
const templateDir = path19.join(templatesRoot, this.template);
|
|
18813
|
+
if (!fs14.existsSync(templateDir)) {
|
|
18933
18814
|
const available = AgentProjectGenerator.getAvailableTemplates();
|
|
18934
18815
|
const names = available.map((t) => ` - ${t.name}: ${t.description}`).join(`
|
|
18935
18816
|
`);
|
|
@@ -18944,8 +18825,8 @@ ${names || " (none found)"}`,
|
|
|
18944
18825
|
suggestion: validNames ? `Re-run with a valid template name (one of: ${validNames}).` : "Re-run with a valid template name."
|
|
18945
18826
|
});
|
|
18946
18827
|
}
|
|
18947
|
-
const configFile =
|
|
18948
|
-
if (!
|
|
18828
|
+
const configFile = path19.join(templateDir, "agent.config.ts");
|
|
18829
|
+
if (!fs14.existsSync(configFile)) {
|
|
18949
18830
|
throw new AdkError({
|
|
18950
18831
|
code: "TEMPLATE_INVALID",
|
|
18951
18832
|
expected: false,
|
|
@@ -18957,23 +18838,23 @@ ${names || " (none found)"}`,
|
|
|
18957
18838
|
async copyTemplateFiles(templateDir) {
|
|
18958
18839
|
const substitutions = {
|
|
18959
18840
|
"{{projectName}}": this.projectName,
|
|
18960
|
-
"{{runtimeVersion}}": "1.19.0-beta.
|
|
18841
|
+
"{{runtimeVersion}}": "1.19.0-beta.13",
|
|
18961
18842
|
"{{packageManager}}": this.packageManager
|
|
18962
18843
|
};
|
|
18963
18844
|
await this.copyDirRecursive(templateDir, this.projectPath, substitutions);
|
|
18964
18845
|
}
|
|
18965
18846
|
async copyDirRecursive(src, dest, substitutions) {
|
|
18966
|
-
if (!
|
|
18967
|
-
|
|
18847
|
+
if (!fs14.existsSync(dest)) {
|
|
18848
|
+
fs14.mkdirSync(dest, { recursive: true });
|
|
18968
18849
|
}
|
|
18969
|
-
const entries =
|
|
18850
|
+
const entries = fs14.readdirSync(src, { withFileTypes: true });
|
|
18970
18851
|
for (const entry of entries) {
|
|
18971
|
-
const srcPath =
|
|
18972
|
-
const destPath =
|
|
18852
|
+
const srcPath = path19.join(src, entry.name);
|
|
18853
|
+
const destPath = path19.join(dest, entry.name);
|
|
18973
18854
|
if (entry.isDirectory()) {
|
|
18974
18855
|
await this.copyDirRecursive(srcPath, destPath, substitutions);
|
|
18975
18856
|
} else if (isTextFile(entry.name)) {
|
|
18976
|
-
let content =
|
|
18857
|
+
let content = fs14.readFileSync(srcPath, "utf-8");
|
|
18977
18858
|
for (const [placeholder, value] of Object.entries(substitutions)) {
|
|
18978
18859
|
content = content.replaceAll(placeholder, value);
|
|
18979
18860
|
}
|
|
@@ -18986,17 +18867,17 @@ ${names || " (none found)"}`,
|
|
|
18986
18867
|
content = await formatCode(content, destPath);
|
|
18987
18868
|
} catch {}
|
|
18988
18869
|
}
|
|
18989
|
-
|
|
18870
|
+
fs14.writeFileSync(destPath, content);
|
|
18990
18871
|
} else {
|
|
18991
|
-
|
|
18872
|
+
fs14.copyFileSync(srcPath, destPath);
|
|
18992
18873
|
}
|
|
18993
18874
|
}
|
|
18994
18875
|
}
|
|
18995
18876
|
ensureEmptyDirectory() {
|
|
18996
|
-
if (!
|
|
18997
|
-
|
|
18877
|
+
if (!fs14.existsSync(this.projectPath)) {
|
|
18878
|
+
fs14.mkdirSync(this.projectPath, { recursive: true });
|
|
18998
18879
|
}
|
|
18999
|
-
const files =
|
|
18880
|
+
const files = fs14.readdirSync(this.projectPath);
|
|
19000
18881
|
if (files.length > 0) {
|
|
19001
18882
|
throw new AdkError({
|
|
19002
18883
|
code: "TARGET_DIR_NOT_EMPTY",
|
|
@@ -19016,8 +18897,8 @@ ${names || " (none found)"}`,
|
|
|
19016
18897
|
this.writeFile("AGENTS.md", content);
|
|
19017
18898
|
}
|
|
19018
18899
|
writeFile(relativePath, content) {
|
|
19019
|
-
const filePath =
|
|
19020
|
-
|
|
18900
|
+
const filePath = path19.join(this.projectPath, relativePath);
|
|
18901
|
+
fs14.writeFileSync(filePath, content);
|
|
19021
18902
|
}
|
|
19022
18903
|
writeJsonFile(relativePath, data) {
|
|
19023
18904
|
this.writeFile(relativePath, JSON.stringify(data, null, 2) + `
|
|
@@ -19211,11 +19092,11 @@ function isRecordLike(value) {
|
|
|
19211
19092
|
// src/generators/assets.ts
|
|
19212
19093
|
init_fs();
|
|
19213
19094
|
init_assets();
|
|
19214
|
-
import
|
|
19095
|
+
import path20 from "path";
|
|
19215
19096
|
async function generateAssetsTypes(projectPath) {
|
|
19216
19097
|
const assetsManager = new AssetsManager({ projectPath });
|
|
19217
19098
|
const typesCode = await assetsManager.generateTypes();
|
|
19218
|
-
const typesPath =
|
|
19099
|
+
const typesPath = path20.join(projectPath, defaultAdkFolder, "assets.d.ts");
|
|
19219
19100
|
await createFile(typesPath, typesCode);
|
|
19220
19101
|
}
|
|
19221
19102
|
async function generateAssetsRuntime(projectPath, botId, options) {
|
|
@@ -19276,7 +19157,7 @@ if (typeof globalThis !== 'undefined') {
|
|
|
19276
19157
|
initializeAssets(global);
|
|
19277
19158
|
}
|
|
19278
19159
|
`;
|
|
19279
|
-
const runtimePath =
|
|
19160
|
+
const runtimePath = path20.join(projectPath, defaultAdkFolder, "assets-runtime.ts");
|
|
19280
19161
|
await createFile(runtimePath, runtimeCode);
|
|
19281
19162
|
}
|
|
19282
19163
|
async function initAssets(projectPath, botId, options) {
|
|
@@ -19306,7 +19187,7 @@ declare global {
|
|
|
19306
19187
|
};
|
|
19307
19188
|
}
|
|
19308
19189
|
`;
|
|
19309
|
-
const typesPath =
|
|
19190
|
+
const typesPath = path20.join(projectPath, defaultAdkFolder, "assets.d.ts");
|
|
19310
19191
|
await createFile(typesPath, emptyTypesCode);
|
|
19311
19192
|
const emptyRuntimeCode = `
|
|
19312
19193
|
// No assets available
|
|
@@ -19327,14 +19208,14 @@ if (typeof globalThis !== 'undefined') {
|
|
|
19327
19208
|
initializeAssets(global);
|
|
19328
19209
|
}
|
|
19329
19210
|
`;
|
|
19330
|
-
const runtimePath =
|
|
19211
|
+
const runtimePath = path20.join(projectPath, defaultAdkFolder, "assets-runtime.ts");
|
|
19331
19212
|
await createFile(runtimePath, emptyRuntimeCode);
|
|
19332
19213
|
}
|
|
19333
19214
|
}
|
|
19334
19215
|
// src/generators/integration-types.ts
|
|
19335
19216
|
import { z as z5 } from "@botpress/sdk";
|
|
19336
19217
|
import crypto2 from "crypto";
|
|
19337
|
-
import
|
|
19218
|
+
import path21 from "path";
|
|
19338
19219
|
|
|
19339
19220
|
// src/utils/strings.ts
|
|
19340
19221
|
function pascalCase(str) {
|
|
@@ -19375,12 +19256,12 @@ var getIntegrationNames = (integration) => ({
|
|
|
19375
19256
|
configurations: `Integration_Configurations_${getPascalAlias(integration)}`
|
|
19376
19257
|
},
|
|
19377
19258
|
paths: {
|
|
19378
|
-
index:
|
|
19379
|
-
actions:
|
|
19380
|
-
channels:
|
|
19381
|
-
events:
|
|
19382
|
-
users:
|
|
19383
|
-
configurations:
|
|
19259
|
+
index: path21.join(snakeCase(getPascalAlias(integration)), `index.ts`),
|
|
19260
|
+
actions: path21.join(snakeCase(getPascalAlias(integration)), `actions.ts`),
|
|
19261
|
+
channels: path21.join(snakeCase(getPascalAlias(integration)), `channels.ts`),
|
|
19262
|
+
events: path21.join(snakeCase(getPascalAlias(integration)), `events.ts`),
|
|
19263
|
+
users: path21.join(snakeCase(getPascalAlias(integration)), `users.ts`),
|
|
19264
|
+
configurations: path21.join(snakeCase(getPascalAlias(integration)), `configurations.ts`)
|
|
19384
19265
|
}
|
|
19385
19266
|
});
|
|
19386
19267
|
async function generateIntegrationTypes(integration) {
|
|
@@ -19636,9 +19517,9 @@ Description: ${tag?.description}`);
|
|
|
19636
19517
|
init_utils();
|
|
19637
19518
|
init_fs();
|
|
19638
19519
|
import { z as z6 } from "@botpress/sdk";
|
|
19639
|
-
import
|
|
19520
|
+
import path22 from "path";
|
|
19640
19521
|
import crypto3 from "crypto";
|
|
19641
|
-
import { readFile as
|
|
19522
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
19642
19523
|
import { BuiltInWorkflows as BuiltInWorkflows2 } from "@botpress/runtime/internal";
|
|
19643
19524
|
var { transforms: transforms2 } = z6;
|
|
19644
19525
|
function isBuiltinWorkflow(name) {
|
|
@@ -19661,7 +19542,7 @@ async function generateClientWrapper(project) {
|
|
|
19661
19542
|
});
|
|
19662
19543
|
continue;
|
|
19663
19544
|
}
|
|
19664
|
-
const absolutePath =
|
|
19545
|
+
const absolutePath = path22.join(project.path, action.path);
|
|
19665
19546
|
const actionModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
19666
19547
|
const actionInstance = actionModule[action.export] || actionModule.default;
|
|
19667
19548
|
if (actionInstance && actionInstance.input && actionInstance.output) {
|
|
@@ -19688,7 +19569,7 @@ async function generateClientWrapper(project) {
|
|
|
19688
19569
|
if (isBuiltinWorkflow(workflow.definition.name)) {
|
|
19689
19570
|
continue;
|
|
19690
19571
|
}
|
|
19691
|
-
const workflowPath =
|
|
19572
|
+
const workflowPath = path22.join(project.path, workflow.path);
|
|
19692
19573
|
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
19693
19574
|
const workflowInstance = workflowModule[workflow.export] || workflowModule.default;
|
|
19694
19575
|
if (workflowInstance) {
|
|
@@ -19707,7 +19588,7 @@ async function generateClientWrapper(project) {
|
|
|
19707
19588
|
const tableTypes = [];
|
|
19708
19589
|
for (const table of project.tables) {
|
|
19709
19590
|
try {
|
|
19710
|
-
const tablePath =
|
|
19591
|
+
const tablePath = path22.join(project.path, table.path);
|
|
19711
19592
|
const tableModule = await import(`${tablePath}?t=${Date.now()}`);
|
|
19712
19593
|
const tableInstance = tableModule.default || tableModule[table.export];
|
|
19713
19594
|
if (tableInstance && tableInstance.columns) {
|
|
@@ -20020,11 +19901,11 @@ export function createAdkClient(client: Client): AdkClient {
|
|
|
20020
19901
|
}
|
|
20021
19902
|
}
|
|
20022
19903
|
`;
|
|
20023
|
-
const clientWrapperPath =
|
|
19904
|
+
const clientWrapperPath = path22.join(project.path, ".adk", "client.ts");
|
|
20024
19905
|
const formattedContent = await formatCode(content);
|
|
20025
19906
|
const contentHash = crypto3.createHash("sha256").update(formattedContent.replace(/\/\/ Generated at: .+\n/, "")).digest("hex");
|
|
20026
19907
|
try {
|
|
20027
|
-
const existingContent = await
|
|
19908
|
+
const existingContent = await readFile3(clientWrapperPath, "utf-8");
|
|
20028
19909
|
const existingHash = crypto3.createHash("sha256").update(existingContent.replace(/\/\/ Generated at: .+\n/, "")).digest("hex");
|
|
20029
19910
|
if (contentHash === existingHash) {
|
|
20030
19911
|
return;
|
|
@@ -20036,14 +19917,14 @@ export function createAdkClient(client: Client): AdkClient {
|
|
|
20036
19917
|
init_src();
|
|
20037
19918
|
import dedent from "dedent";
|
|
20038
19919
|
import { existsSync as existsSync7 } from "fs";
|
|
20039
|
-
import
|
|
20040
|
-
import
|
|
19920
|
+
import fs20 from "fs/promises";
|
|
19921
|
+
import path43 from "path";
|
|
20041
19922
|
init_config_utils();
|
|
20042
19923
|
|
|
20043
19924
|
// src/generators/plugin-types.ts
|
|
20044
19925
|
import { z as z7 } from "@botpress/sdk";
|
|
20045
19926
|
import crypto4 from "crypto";
|
|
20046
|
-
import
|
|
19927
|
+
import path23 from "path";
|
|
20047
19928
|
init_utils();
|
|
20048
19929
|
var { transforms: transforms3 } = z7;
|
|
20049
19930
|
function stripRefs(schema) {
|
|
@@ -20082,8 +19963,8 @@ var getPluginNames = (plugin) => ({
|
|
|
20082
19963
|
actions: `Plugin_Actions_${getPascalAlias2(plugin)}`
|
|
20083
19964
|
},
|
|
20084
19965
|
paths: {
|
|
20085
|
-
index:
|
|
20086
|
-
actions:
|
|
19966
|
+
index: path23.join(snakeCase(getPascalAlias2(plugin)), `index.ts`),
|
|
19967
|
+
actions: path23.join(snakeCase(getPascalAlias2(plugin)), `actions.ts`)
|
|
20087
19968
|
}
|
|
20088
19969
|
});
|
|
20089
19970
|
async function generatePluginTypes(plugin) {
|
|
@@ -20151,7 +20032,7 @@ Description: ${action.description || "No description"}`)}
|
|
|
20151
20032
|
// src/generators/plugin-action-types.ts
|
|
20152
20033
|
init_utils();
|
|
20153
20034
|
init_fs();
|
|
20154
|
-
import
|
|
20035
|
+
import path24 from "path";
|
|
20155
20036
|
async function generatePluginActionTypes(project) {
|
|
20156
20037
|
const content = `
|
|
20157
20038
|
////////////////////////////////////////////////////////
|
|
@@ -20186,14 +20067,14 @@ type PluginsMap<T> = {
|
|
|
20186
20067
|
export type PluginActions = PluginsMap<Plugins>;
|
|
20187
20068
|
}
|
|
20188
20069
|
`;
|
|
20189
|
-
const pluginActionTypesPath =
|
|
20070
|
+
const pluginActionTypesPath = path24.join(project.path, ".adk", "plugin-action-types.d.ts");
|
|
20190
20071
|
await createFile(pluginActionTypesPath, await formatCode(content));
|
|
20191
20072
|
}
|
|
20192
20073
|
|
|
20193
20074
|
// src/generators/interface-types.ts
|
|
20194
20075
|
import { z as z8 } from "@botpress/sdk";
|
|
20195
20076
|
import crypto5 from "crypto";
|
|
20196
|
-
import
|
|
20077
|
+
import path25 from "path";
|
|
20197
20078
|
init_utils();
|
|
20198
20079
|
var { transforms: transforms4 } = z8;
|
|
20199
20080
|
var sameMajorVersion = (a, b) => {
|
|
@@ -20215,8 +20096,8 @@ var getInterfaceNames = (int) => ({
|
|
|
20215
20096
|
actions: `Interface_Actions_${pascalCase(int.name)}`
|
|
20216
20097
|
},
|
|
20217
20098
|
paths: {
|
|
20218
|
-
index:
|
|
20219
|
-
actions:
|
|
20099
|
+
index: path25.join(snakeCase(int.name), `index.ts`),
|
|
20100
|
+
actions: path25.join(snakeCase(int.name), `actions.ts`)
|
|
20220
20101
|
}
|
|
20221
20102
|
});
|
|
20222
20103
|
async function generateInterfaceTypes(int, integrations) {
|
|
@@ -20321,12 +20202,12 @@ Description: ${action.description || "No description"}`)}
|
|
|
20321
20202
|
// src/generators/table-types.ts
|
|
20322
20203
|
init_utils();
|
|
20323
20204
|
init_fs();
|
|
20324
|
-
import
|
|
20205
|
+
import path26 from "path";
|
|
20325
20206
|
async function generateTableTypes(project) {
|
|
20326
20207
|
const tables = [];
|
|
20327
20208
|
for (const tableRef of project.tables) {
|
|
20328
20209
|
try {
|
|
20329
|
-
const tablePath =
|
|
20210
|
+
const tablePath = path26.join(project.path, tableRef.path);
|
|
20330
20211
|
const tableModule = await import(`${tablePath}?t=${Date.now()}`);
|
|
20331
20212
|
const tableInstance = tableModule.default || tableModule[tableRef.export];
|
|
20332
20213
|
if (tableInstance && tableInstance.columns) {
|
|
@@ -20412,14 +20293,14 @@ ${outputColumns}
|
|
|
20412
20293
|
content += ` };
|
|
20413
20294
|
}
|
|
20414
20295
|
`;
|
|
20415
|
-
const tableTypesPath =
|
|
20296
|
+
const tableTypesPath = path26.join(project.path, ".adk", "table-types.d.ts");
|
|
20416
20297
|
await createFile(tableTypesPath, await formatCode(content));
|
|
20417
20298
|
}
|
|
20418
20299
|
|
|
20419
20300
|
// src/generators/trigger-types.ts
|
|
20420
20301
|
init_utils();
|
|
20421
20302
|
init_fs();
|
|
20422
|
-
import
|
|
20303
|
+
import path27 from "path";
|
|
20423
20304
|
async function generateTriggerTypes(project) {
|
|
20424
20305
|
const triggerEvents = {};
|
|
20425
20306
|
for (const trigger of project.triggers) {
|
|
@@ -20459,19 +20340,19 @@ ${triggersType}
|
|
|
20459
20340
|
};
|
|
20460
20341
|
}
|
|
20461
20342
|
`;
|
|
20462
|
-
const triggerTypesPath =
|
|
20343
|
+
const triggerTypesPath = path27.join(project.path, ".adk", "trigger-types.d.ts");
|
|
20463
20344
|
await createFile(triggerTypesPath, await formatCode(content));
|
|
20464
20345
|
}
|
|
20465
20346
|
|
|
20466
20347
|
// src/generators/state-types.ts
|
|
20467
20348
|
init_utils();
|
|
20468
20349
|
init_fs();
|
|
20469
|
-
import
|
|
20350
|
+
import path28 from "path";
|
|
20470
20351
|
async function generateStateTypes(project) {
|
|
20471
20352
|
let botStateType = "{}";
|
|
20472
20353
|
let userStateType = "{}";
|
|
20473
20354
|
try {
|
|
20474
|
-
const configPath =
|
|
20355
|
+
const configPath = path28.join(project.path, "agent.config.ts");
|
|
20475
20356
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
20476
20357
|
const config = configModule.default;
|
|
20477
20358
|
if (config?.bot?.state) {
|
|
@@ -20502,14 +20383,14 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
20502
20383
|
export type UserState = ${userStateType};
|
|
20503
20384
|
}
|
|
20504
20385
|
`;
|
|
20505
|
-
const stateTypesPath =
|
|
20386
|
+
const stateTypesPath = path28.join(project.path, ".adk", "state-types.d.ts");
|
|
20506
20387
|
await createFile(stateTypesPath, await formatCode(content));
|
|
20507
20388
|
}
|
|
20508
20389
|
|
|
20509
20390
|
// src/generators/tag-types.ts
|
|
20510
20391
|
init_utils();
|
|
20511
20392
|
init_fs();
|
|
20512
|
-
import
|
|
20393
|
+
import path29 from "path";
|
|
20513
20394
|
import { BUILT_IN_TAGS } from "@botpress/runtime/definition";
|
|
20514
20395
|
function generateTagTypeString(builtInTags, configTags) {
|
|
20515
20396
|
const builtInTagStrings = Object.entries(builtInTags).map(([key, tag]) => {
|
|
@@ -20548,7 +20429,7 @@ async function generateTagTypes(project) {
|
|
|
20548
20429
|
let messageTagsType = "Record<string, string | undefined>";
|
|
20549
20430
|
let workflowTagsType = "Record<string, string | undefined>";
|
|
20550
20431
|
try {
|
|
20551
|
-
const configPath =
|
|
20432
|
+
const configPath = path29.join(project.path, "agent.config.ts");
|
|
20552
20433
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
20553
20434
|
const config = configModule.default;
|
|
20554
20435
|
botTagsType = generateTagTypeString(BUILT_IN_TAGS.bot, config?.bot?.tags);
|
|
@@ -20594,18 +20475,18 @@ declare module "@botpress/runtime/_types/tags" {
|
|
|
20594
20475
|
export type WorkflowTags = ${workflowTagsType};
|
|
20595
20476
|
}
|
|
20596
20477
|
`;
|
|
20597
|
-
const tagTypesPath =
|
|
20478
|
+
const tagTypesPath = path29.join(project.path, ".adk", "tag-types.d.ts");
|
|
20598
20479
|
await createFile(tagTypesPath, await formatCode(content));
|
|
20599
20480
|
}
|
|
20600
20481
|
|
|
20601
20482
|
// src/generators/configuration-types.ts
|
|
20602
20483
|
init_utils();
|
|
20603
20484
|
init_fs();
|
|
20604
|
-
import
|
|
20485
|
+
import path30 from "path";
|
|
20605
20486
|
async function generateConfigurationTypes(project) {
|
|
20606
20487
|
let configurationType = "{}";
|
|
20607
20488
|
try {
|
|
20608
|
-
const configPath =
|
|
20489
|
+
const configPath = path30.join(project.path, "agent.config.ts");
|
|
20609
20490
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
20610
20491
|
const config = configModule.default;
|
|
20611
20492
|
if (config?.configuration?.schema) {
|
|
@@ -20629,18 +20510,18 @@ declare module "@botpress/runtime/_types/configuration" {
|
|
|
20629
20510
|
export type Configuration = ${configurationType};
|
|
20630
20511
|
}
|
|
20631
20512
|
`;
|
|
20632
|
-
const configTypesPath =
|
|
20513
|
+
const configTypesPath = path30.join(project.path, ".adk", "configuration-types.d.ts");
|
|
20633
20514
|
await createFile(configTypesPath, await formatCode(content));
|
|
20634
20515
|
}
|
|
20635
20516
|
|
|
20636
20517
|
// src/generators/secret-types.ts
|
|
20637
20518
|
init_utils();
|
|
20638
20519
|
init_fs();
|
|
20639
|
-
import
|
|
20520
|
+
import path31 from "path";
|
|
20640
20521
|
async function generateSecretTypes(project) {
|
|
20641
20522
|
let secretsType = "{}";
|
|
20642
20523
|
try {
|
|
20643
|
-
const configPath =
|
|
20524
|
+
const configPath = path31.join(project.path, "agent.config.ts");
|
|
20644
20525
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
20645
20526
|
const config = configModule.default;
|
|
20646
20527
|
if (config?.secrets) {
|
|
@@ -20672,14 +20553,14 @@ declare module "@botpress/runtime/_types/secrets" {
|
|
|
20672
20553
|
export type Secrets = ${secretsType};
|
|
20673
20554
|
}
|
|
20674
20555
|
`;
|
|
20675
|
-
const secretTypesPath =
|
|
20556
|
+
const secretTypesPath = path31.join(project.path, ".adk", "secret-types.d.ts");
|
|
20676
20557
|
await createFile(secretTypesPath, await formatCode(content));
|
|
20677
20558
|
}
|
|
20678
20559
|
|
|
20679
20560
|
// src/generators/workflow-types.ts
|
|
20680
20561
|
init_utils();
|
|
20681
20562
|
init_fs();
|
|
20682
|
-
import * as
|
|
20563
|
+
import * as path32 from "path";
|
|
20683
20564
|
import { BuiltInWorkflows as BuiltInWorkflows3 } from "@botpress/runtime/internal";
|
|
20684
20565
|
function isBuiltinWorkflow2(name) {
|
|
20685
20566
|
return !!Object.values(BuiltInWorkflows3).find((x) => x.name === name);
|
|
@@ -20691,7 +20572,7 @@ async function generateWorkflowTypes(project) {
|
|
|
20691
20572
|
if (isBuiltinWorkflow2(workflowRef.definition.name)) {
|
|
20692
20573
|
continue;
|
|
20693
20574
|
}
|
|
20694
|
-
const workflowPath =
|
|
20575
|
+
const workflowPath = path32.join(project.path, workflowRef.path);
|
|
20695
20576
|
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
20696
20577
|
const workflowInstance = workflowModule[workflowRef.export] || workflowModule.default;
|
|
20697
20578
|
if (!workflowInstance) {
|
|
@@ -20749,14 +20630,14 @@ declare module "@botpress/runtime/_types/workflows" {
|
|
|
20749
20630
|
${typeDefinitions || " // No workflows defined yet"}
|
|
20750
20631
|
};
|
|
20751
20632
|
}`;
|
|
20752
|
-
const workflowTypesPath =
|
|
20633
|
+
const workflowTypesPath = path32.join(project.path, ".adk", "workflow-types.d.ts");
|
|
20753
20634
|
await createFile(workflowTypesPath, await formatCode(content));
|
|
20754
20635
|
}
|
|
20755
20636
|
|
|
20756
20637
|
// src/generators/conversation-types.ts
|
|
20757
20638
|
init_utils();
|
|
20758
20639
|
init_fs();
|
|
20759
|
-
import
|
|
20640
|
+
import path33 from "path";
|
|
20760
20641
|
function hasConversationIdProperty(schema) {
|
|
20761
20642
|
if (!schema || typeof schema !== "object") {
|
|
20762
20643
|
return false;
|
|
@@ -20779,7 +20660,7 @@ async function generateConversationTypes(project) {
|
|
|
20779
20660
|
const conversationTypes = {};
|
|
20780
20661
|
for (const conversationRef of project.conversations) {
|
|
20781
20662
|
try {
|
|
20782
|
-
const conversationPath =
|
|
20663
|
+
const conversationPath = path33.join(project.path, conversationRef.path);
|
|
20783
20664
|
const conversationModule = await import(`${conversationPath}?t=${Date.now()}`);
|
|
20784
20665
|
const conversationInstance = conversationModule[conversationRef.export] || conversationModule.default;
|
|
20785
20666
|
if (!conversationInstance) {
|
|
@@ -20867,14 +20748,14 @@ ${routableEventsDefinitions || " // No routable events found"}
|
|
|
20867
20748
|
};
|
|
20868
20749
|
}
|
|
20869
20750
|
`;
|
|
20870
|
-
const conversationTypesPath =
|
|
20751
|
+
const conversationTypesPath = path33.join(project.path, ".adk", "conversation-types.d.ts");
|
|
20871
20752
|
await createFile(conversationTypesPath, await formatCode(content));
|
|
20872
20753
|
}
|
|
20873
20754
|
|
|
20874
20755
|
// src/generators/component-types.ts
|
|
20875
20756
|
init_utils();
|
|
20876
20757
|
init_fs();
|
|
20877
|
-
import
|
|
20758
|
+
import path34 from "path";
|
|
20878
20759
|
async function generateComponentTypes(project) {
|
|
20879
20760
|
const components = project.customComponents;
|
|
20880
20761
|
if (components.length === 0) {
|
|
@@ -20890,7 +20771,7 @@ declare module "@botpress/runtime/_types/components" {
|
|
|
20890
20771
|
export type CustomComponentMessage = never;
|
|
20891
20772
|
}
|
|
20892
20773
|
`;
|
|
20893
|
-
const typesPath2 =
|
|
20774
|
+
const typesPath2 = path34.join(project.path, ".adk", "component-types.d.ts");
|
|
20894
20775
|
await createFile(typesPath2, await formatCode(content2));
|
|
20895
20776
|
return;
|
|
20896
20777
|
}
|
|
@@ -20914,14 +20795,14 @@ declare module "@botpress/runtime/_types/components" {
|
|
|
20914
20795
|
| `)};
|
|
20915
20796
|
}
|
|
20916
20797
|
`;
|
|
20917
|
-
const typesPath =
|
|
20798
|
+
const typesPath = path34.join(project.path, ".adk", "component-types.d.ts");
|
|
20918
20799
|
await createFile(typesPath, await formatCode(content));
|
|
20919
20800
|
}
|
|
20920
20801
|
|
|
20921
20802
|
// src/generators/event-types.ts
|
|
20922
20803
|
init_utils();
|
|
20923
20804
|
init_fs();
|
|
20924
|
-
import
|
|
20805
|
+
import path35 from "path";
|
|
20925
20806
|
async function generateEventTypes(project) {
|
|
20926
20807
|
const defaultEvents = ["register: {}"];
|
|
20927
20808
|
const integrationEvents = [];
|
|
@@ -20973,7 +20854,7 @@ ${allEvents.map((e) => ` ${e}`).join(`
|
|
|
20973
20854
|
export type EventPayload<T extends EventName> = Events[T];
|
|
20974
20855
|
}
|
|
20975
20856
|
`;
|
|
20976
|
-
const eventTypesPath =
|
|
20857
|
+
const eventTypesPath = path35.join(project.path, ".adk", "event-types.d.ts");
|
|
20977
20858
|
await createFile(eventTypesPath, await formatCode(content));
|
|
20978
20859
|
}
|
|
20979
20860
|
|
|
@@ -20984,11 +20865,11 @@ init_fs();
|
|
|
20984
20865
|
|
|
20985
20866
|
// src/utils/link-sdk.ts
|
|
20986
20867
|
import { existsSync as existsSync3, realpathSync } from "fs";
|
|
20987
|
-
import
|
|
20988
|
-
import
|
|
20868
|
+
import fs15 from "fs/promises";
|
|
20869
|
+
import path36 from "path";
|
|
20989
20870
|
async function lexists(p) {
|
|
20990
20871
|
try {
|
|
20991
|
-
await
|
|
20872
|
+
await fs15.lstat(p);
|
|
20992
20873
|
return true;
|
|
20993
20874
|
} catch (err) {
|
|
20994
20875
|
if (err.code === "ENOENT") {
|
|
@@ -21004,17 +20885,17 @@ function findPackage(name, startDir) {
|
|
|
21004
20885
|
} catch {
|
|
21005
20886
|
current = startDir;
|
|
21006
20887
|
}
|
|
21007
|
-
while (current !==
|
|
21008
|
-
const pkgPath =
|
|
20888
|
+
while (current !== path36.dirname(current)) {
|
|
20889
|
+
const pkgPath = path36.join(current, "node_modules", name);
|
|
21009
20890
|
if (existsSync3(pkgPath)) {
|
|
21010
20891
|
return pkgPath;
|
|
21011
20892
|
}
|
|
21012
|
-
current =
|
|
20893
|
+
current = path36.dirname(current);
|
|
21013
20894
|
}
|
|
21014
20895
|
return null;
|
|
21015
20896
|
}
|
|
21016
20897
|
async function linkSdk(agentDir, botDir) {
|
|
21017
|
-
const targetSdkPath =
|
|
20898
|
+
const targetSdkPath = path36.join(botDir, "node_modules", "@botpress", "sdk");
|
|
21018
20899
|
if (existsSync3(targetSdkPath)) {
|
|
21019
20900
|
return;
|
|
21020
20901
|
}
|
|
@@ -21028,21 +20909,21 @@ async function linkSdk(agentDir, botDir) {
|
|
|
21028
20909
|
console.warn(`Warning: Could not find @botpress/sdk from @botpress/runtime location (${runtimePath})`);
|
|
21029
20910
|
return;
|
|
21030
20911
|
}
|
|
21031
|
-
const targetBotpressDir =
|
|
21032
|
-
await
|
|
20912
|
+
const targetBotpressDir = path36.join(botDir, "node_modules", "@botpress");
|
|
20913
|
+
await fs15.mkdir(targetBotpressDir, { recursive: true });
|
|
21033
20914
|
if (await lexists(targetSdkPath)) {
|
|
21034
|
-
await
|
|
20915
|
+
await fs15.rm(targetSdkPath, { force: true });
|
|
21035
20916
|
}
|
|
21036
20917
|
const symlinkType = process.platform === "win32" ? "junction" : undefined;
|
|
21037
|
-
await
|
|
20918
|
+
await fs15.symlink(sdkPath, targetSdkPath, symlinkType);
|
|
21038
20919
|
}
|
|
21039
20920
|
|
|
21040
20921
|
// src/bot-generator/dev-id-manager.ts
|
|
21041
20922
|
init_auth();
|
|
21042
20923
|
init_agent_project();
|
|
21043
20924
|
init_validation_errors();
|
|
21044
|
-
import
|
|
21045
|
-
import
|
|
20925
|
+
import path37 from "path";
|
|
20926
|
+
import fs16 from "fs/promises";
|
|
21046
20927
|
import createDebug3 from "debug";
|
|
21047
20928
|
var debug3 = createDebug3("adk:dev-id-manager");
|
|
21048
20929
|
|
|
@@ -21056,7 +20937,7 @@ class DevIdManager {
|
|
|
21056
20937
|
constructor(projectPath, botProjectPath, options = {}) {
|
|
21057
20938
|
this.projectPath = projectPath;
|
|
21058
20939
|
this.botProjectPath = botProjectPath;
|
|
21059
|
-
this.projectCachePath =
|
|
20940
|
+
this.projectCachePath = path37.join(botProjectPath, ".botpress", "project.cache.json");
|
|
21060
20941
|
this.loadAgentProject = options.loadAgentProject ?? ((p) => AgentProject.load(p));
|
|
21061
20942
|
this.validationErrors = options.validationErrors ?? ValidationErrors;
|
|
21062
20943
|
}
|
|
@@ -21077,7 +20958,7 @@ class DevIdManager {
|
|
|
21077
20958
|
}
|
|
21078
20959
|
async readProjectCache() {
|
|
21079
20960
|
try {
|
|
21080
|
-
const content = await
|
|
20961
|
+
const content = await fs16.readFile(this.projectCachePath, "utf-8");
|
|
21081
20962
|
if (content.trim().length === 0) {
|
|
21082
20963
|
debug3("project cache is empty, treating as bootstrap state: %s", this.projectCachePath);
|
|
21083
20964
|
return {};
|
|
@@ -21103,8 +20984,8 @@ class DevIdManager {
|
|
|
21103
20984
|
}
|
|
21104
20985
|
async saveProjectCache(cache2) {
|
|
21105
20986
|
try {
|
|
21106
|
-
await
|
|
21107
|
-
await
|
|
20987
|
+
await fs16.mkdir(path37.dirname(this.projectCachePath), { recursive: true });
|
|
20988
|
+
await fs16.writeFile(this.projectCachePath, JSON.stringify(cache2, null, 2));
|
|
21108
20989
|
} catch (error) {
|
|
21109
20990
|
console.error("Error saving project.cache.json:", error);
|
|
21110
20991
|
}
|
|
@@ -21161,8 +21042,8 @@ function isProjectCache(value) {
|
|
|
21161
21042
|
init_src();
|
|
21162
21043
|
init_agent_project();
|
|
21163
21044
|
init_auth();
|
|
21164
|
-
import
|
|
21165
|
-
import
|
|
21045
|
+
import path38 from "path";
|
|
21046
|
+
import fs17 from "fs/promises";
|
|
21166
21047
|
import { existsSync as existsSync4 } from "fs";
|
|
21167
21048
|
class IntegrationSync {
|
|
21168
21049
|
projectPath;
|
|
@@ -21172,7 +21053,7 @@ class IntegrationSync {
|
|
|
21172
21053
|
constructor(projectPath, botProjectPath) {
|
|
21173
21054
|
this.projectPath = projectPath;
|
|
21174
21055
|
this.botProjectPath = botProjectPath;
|
|
21175
|
-
this.bpModulesPath =
|
|
21056
|
+
this.bpModulesPath = path38.join(botProjectPath, "bp_modules");
|
|
21176
21057
|
}
|
|
21177
21058
|
getCredentials() {
|
|
21178
21059
|
if (!this.credentialsPromise) {
|
|
@@ -21212,16 +21093,16 @@ class IntegrationSync {
|
|
|
21212
21093
|
return integrations;
|
|
21213
21094
|
}
|
|
21214
21095
|
async isIntegrationSynced(integration) {
|
|
21215
|
-
const targetFolder =
|
|
21096
|
+
const targetFolder = path38.join(this.bpModulesPath, `integration_${integration.alias}`);
|
|
21216
21097
|
if (!existsSync4(targetFolder)) {
|
|
21217
21098
|
return false;
|
|
21218
21099
|
}
|
|
21219
21100
|
try {
|
|
21220
|
-
const indexPath =
|
|
21101
|
+
const indexPath = path38.join(targetFolder, "index.ts");
|
|
21221
21102
|
if (!existsSync4(indexPath)) {
|
|
21222
21103
|
return false;
|
|
21223
21104
|
}
|
|
21224
|
-
const indexContent = await
|
|
21105
|
+
const indexContent = await fs17.readFile(indexPath, "utf-8");
|
|
21225
21106
|
const versionMatch = indexContent.match(/version:\s*["']([^"']+)["']/);
|
|
21226
21107
|
if (!versionMatch) {
|
|
21227
21108
|
return false;
|
|
@@ -21247,8 +21128,8 @@ class IntegrationSync {
|
|
|
21247
21128
|
await command.output();
|
|
21248
21129
|
}
|
|
21249
21130
|
async renameIntegrationFolder(integration) {
|
|
21250
|
-
const sourceFolder =
|
|
21251
|
-
const targetFolder =
|
|
21131
|
+
const sourceFolder = path38.join(this.bpModulesPath, integration.name.replace(/[/_]/g, "-"));
|
|
21132
|
+
const targetFolder = path38.join(this.bpModulesPath, `integration_${integration.alias}`);
|
|
21252
21133
|
if (!existsSync4(sourceFolder)) {
|
|
21253
21134
|
throw new AdkError({
|
|
21254
21135
|
code: "GENERATED_FOLDER_MISSING",
|
|
@@ -21257,14 +21138,14 @@ class IntegrationSync {
|
|
|
21257
21138
|
});
|
|
21258
21139
|
}
|
|
21259
21140
|
if (existsSync4(targetFolder)) {
|
|
21260
|
-
await
|
|
21141
|
+
await fs17.rm(targetFolder, { recursive: true, force: true });
|
|
21261
21142
|
}
|
|
21262
|
-
await
|
|
21143
|
+
await fs17.rename(sourceFolder, targetFolder);
|
|
21263
21144
|
}
|
|
21264
21145
|
async removeIntegrationFolder(alias) {
|
|
21265
|
-
const targetFolder =
|
|
21146
|
+
const targetFolder = path38.join(this.bpModulesPath, `integration_${alias}`);
|
|
21266
21147
|
if (existsSync4(targetFolder)) {
|
|
21267
|
-
await
|
|
21148
|
+
await fs17.rm(targetFolder, { recursive: true, force: true });
|
|
21268
21149
|
}
|
|
21269
21150
|
}
|
|
21270
21151
|
async syncIntegrations() {
|
|
@@ -21274,7 +21155,7 @@ class IntegrationSync {
|
|
|
21274
21155
|
if (integrations.length === 0) {
|
|
21275
21156
|
return { synced, errors };
|
|
21276
21157
|
}
|
|
21277
|
-
await
|
|
21158
|
+
await fs17.mkdir(this.bpModulesPath, { recursive: true });
|
|
21278
21159
|
for (const integration of integrations) {
|
|
21279
21160
|
try {
|
|
21280
21161
|
const isAlreadySynced = await this.isIntegrationSynced(integration);
|
|
@@ -21299,8 +21180,8 @@ class IntegrationSync {
|
|
|
21299
21180
|
init_src();
|
|
21300
21181
|
init_agent_project();
|
|
21301
21182
|
init_auth();
|
|
21302
|
-
import
|
|
21303
|
-
import
|
|
21183
|
+
import path39 from "path";
|
|
21184
|
+
import fs18 from "fs/promises";
|
|
21304
21185
|
import { existsSync as existsSync5 } from "fs";
|
|
21305
21186
|
init_constants();
|
|
21306
21187
|
class InterfaceSync {
|
|
@@ -21311,7 +21192,7 @@ class InterfaceSync {
|
|
|
21311
21192
|
constructor(projectPath, botProjectPath) {
|
|
21312
21193
|
this.projectPath = projectPath;
|
|
21313
21194
|
this.botProjectPath = botProjectPath;
|
|
21314
|
-
this.bpModulesPath =
|
|
21195
|
+
this.bpModulesPath = path39.join(botProjectPath, "bp_modules");
|
|
21315
21196
|
}
|
|
21316
21197
|
getCredentials() {
|
|
21317
21198
|
if (!this.credentialsPromise) {
|
|
@@ -21338,16 +21219,16 @@ class InterfaceSync {
|
|
|
21338
21219
|
return interfaces;
|
|
21339
21220
|
}
|
|
21340
21221
|
async isInterfaceSynced(interfaceInfo) {
|
|
21341
|
-
const targetFolder =
|
|
21222
|
+
const targetFolder = path39.join(this.bpModulesPath, `interface_${pascalCase(interfaceInfo.alias)}`);
|
|
21342
21223
|
if (!existsSync5(targetFolder)) {
|
|
21343
21224
|
return false;
|
|
21344
21225
|
}
|
|
21345
21226
|
try {
|
|
21346
|
-
const indexPath =
|
|
21227
|
+
const indexPath = path39.join(targetFolder, "index.ts");
|
|
21347
21228
|
if (!existsSync5(indexPath)) {
|
|
21348
21229
|
return false;
|
|
21349
21230
|
}
|
|
21350
|
-
const indexContent = await
|
|
21231
|
+
const indexContent = await fs18.readFile(indexPath, "utf-8");
|
|
21351
21232
|
const versionMatch = indexContent.match(/version:\s*["']([^"']+)["']/);
|
|
21352
21233
|
if (!versionMatch) {
|
|
21353
21234
|
return false;
|
|
@@ -21384,8 +21265,8 @@ class InterfaceSync {
|
|
|
21384
21265
|
});
|
|
21385
21266
|
}
|
|
21386
21267
|
async renameInterfaceFolder(interfaceInfo) {
|
|
21387
|
-
const sourceFolder =
|
|
21388
|
-
const targetFolder =
|
|
21268
|
+
const sourceFolder = path39.join(this.bpModulesPath, interfaceInfo.name);
|
|
21269
|
+
const targetFolder = path39.join(this.bpModulesPath, `interface_${pascalCase(interfaceInfo.alias)}`);
|
|
21389
21270
|
if (!existsSync5(sourceFolder)) {
|
|
21390
21271
|
throw new AdkError({
|
|
21391
21272
|
code: "GENERATED_FOLDER_MISSING",
|
|
@@ -21394,14 +21275,14 @@ class InterfaceSync {
|
|
|
21394
21275
|
});
|
|
21395
21276
|
}
|
|
21396
21277
|
if (existsSync5(targetFolder)) {
|
|
21397
|
-
await
|
|
21278
|
+
await fs18.rm(targetFolder, { recursive: true, force: true });
|
|
21398
21279
|
}
|
|
21399
|
-
await
|
|
21280
|
+
await fs18.rename(sourceFolder, targetFolder);
|
|
21400
21281
|
}
|
|
21401
21282
|
async removeInterfaceFolder(alias) {
|
|
21402
|
-
const targetFolder =
|
|
21283
|
+
const targetFolder = path39.join(this.bpModulesPath, `interface_${pascalCase(alias)}`);
|
|
21403
21284
|
if (existsSync5(targetFolder)) {
|
|
21404
|
-
await
|
|
21285
|
+
await fs18.rm(targetFolder, { recursive: true, force: true });
|
|
21405
21286
|
}
|
|
21406
21287
|
}
|
|
21407
21288
|
async syncInterfaces() {
|
|
@@ -21411,7 +21292,7 @@ class InterfaceSync {
|
|
|
21411
21292
|
if (interfaces.length === 0) {
|
|
21412
21293
|
return { synced, errors };
|
|
21413
21294
|
}
|
|
21414
|
-
await
|
|
21295
|
+
await fs18.mkdir(this.bpModulesPath, { recursive: true });
|
|
21415
21296
|
for (const interfaceInfo of interfaces) {
|
|
21416
21297
|
try {
|
|
21417
21298
|
const isAlreadySynced = await this.isInterfaceSynced(interfaceInfo);
|
|
@@ -21436,8 +21317,8 @@ class InterfaceSync {
|
|
|
21436
21317
|
init_src();
|
|
21437
21318
|
init_agent_project();
|
|
21438
21319
|
init_auth();
|
|
21439
|
-
import
|
|
21440
|
-
import
|
|
21320
|
+
import path40 from "path";
|
|
21321
|
+
import fs19 from "fs/promises";
|
|
21441
21322
|
import { existsSync as existsSync6 } from "fs";
|
|
21442
21323
|
class PluginSync {
|
|
21443
21324
|
projectPath;
|
|
@@ -21447,7 +21328,7 @@ class PluginSync {
|
|
|
21447
21328
|
constructor(projectPath, botProjectPath) {
|
|
21448
21329
|
this.projectPath = projectPath;
|
|
21449
21330
|
this.botProjectPath = botProjectPath;
|
|
21450
|
-
this.bpModulesPath =
|
|
21331
|
+
this.bpModulesPath = path40.join(botProjectPath, "bp_modules");
|
|
21451
21332
|
}
|
|
21452
21333
|
getCredentials() {
|
|
21453
21334
|
if (!this.credentialsPromise) {
|
|
@@ -21479,16 +21360,16 @@ class PluginSync {
|
|
|
21479
21360
|
return plugins;
|
|
21480
21361
|
}
|
|
21481
21362
|
async isPluginSynced(plugin) {
|
|
21482
|
-
const targetFolder =
|
|
21363
|
+
const targetFolder = path40.join(this.bpModulesPath, `plugin_${plugin.alias}`);
|
|
21483
21364
|
if (!existsSync6(targetFolder)) {
|
|
21484
21365
|
return false;
|
|
21485
21366
|
}
|
|
21486
21367
|
try {
|
|
21487
|
-
const indexPath =
|
|
21368
|
+
const indexPath = path40.join(targetFolder, "index.ts");
|
|
21488
21369
|
if (!existsSync6(indexPath)) {
|
|
21489
21370
|
return false;
|
|
21490
21371
|
}
|
|
21491
|
-
const indexContent = await
|
|
21372
|
+
const indexContent = await fs19.readFile(indexPath, "utf-8");
|
|
21492
21373
|
const versionMatch = indexContent.match(/version:\s*["']([^"']+)["']/);
|
|
21493
21374
|
if (!versionMatch) {
|
|
21494
21375
|
return false;
|
|
@@ -21514,8 +21395,8 @@ class PluginSync {
|
|
|
21514
21395
|
await command.output();
|
|
21515
21396
|
}
|
|
21516
21397
|
async renamePluginFolder(plugin) {
|
|
21517
|
-
const sourceFolder =
|
|
21518
|
-
const targetFolder =
|
|
21398
|
+
const sourceFolder = path40.join(this.bpModulesPath, plugin.name.replace("/", "-"));
|
|
21399
|
+
const targetFolder = path40.join(this.bpModulesPath, `plugin_${plugin.alias}`);
|
|
21519
21400
|
if (!existsSync6(sourceFolder)) {
|
|
21520
21401
|
throw new AdkError({
|
|
21521
21402
|
code: "GENERATED_FOLDER_MISSING",
|
|
@@ -21524,14 +21405,14 @@ class PluginSync {
|
|
|
21524
21405
|
});
|
|
21525
21406
|
}
|
|
21526
21407
|
if (existsSync6(targetFolder)) {
|
|
21527
|
-
await
|
|
21408
|
+
await fs19.rm(targetFolder, { recursive: true, force: true });
|
|
21528
21409
|
}
|
|
21529
|
-
await
|
|
21410
|
+
await fs19.rename(sourceFolder, targetFolder);
|
|
21530
21411
|
}
|
|
21531
21412
|
async removePluginFolder(alias) {
|
|
21532
|
-
const targetFolder =
|
|
21413
|
+
const targetFolder = path40.join(this.bpModulesPath, `plugin_${alias}`);
|
|
21533
21414
|
if (existsSync6(targetFolder)) {
|
|
21534
|
-
await
|
|
21415
|
+
await fs19.rm(targetFolder, { recursive: true, force: true });
|
|
21535
21416
|
}
|
|
21536
21417
|
}
|
|
21537
21418
|
async syncPlugins() {
|
|
@@ -21541,7 +21422,7 @@ class PluginSync {
|
|
|
21541
21422
|
if (plugins.length === 0) {
|
|
21542
21423
|
return { synced, errors };
|
|
21543
21424
|
}
|
|
21544
|
-
await
|
|
21425
|
+
await fs19.mkdir(this.bpModulesPath, { recursive: true });
|
|
21545
21426
|
for (const plugin of plugins) {
|
|
21546
21427
|
try {
|
|
21547
21428
|
const isAlreadySynced = await this.isPluginSynced(plugin);
|
|
@@ -21600,7 +21481,7 @@ function isBuiltinAction(name) {
|
|
|
21600
21481
|
return !!Object.values(BuiltInActions2).find((x) => x.name === name);
|
|
21601
21482
|
}
|
|
21602
21483
|
function getImportPath(from, to) {
|
|
21603
|
-
return
|
|
21484
|
+
return path43.relative(path43.dirname(from), to).replace(/\.ts$/, "").replace(/\\/g, "/");
|
|
21604
21485
|
}
|
|
21605
21486
|
|
|
21606
21487
|
class BotGenerator {
|
|
@@ -21609,8 +21490,8 @@ class BotGenerator {
|
|
|
21609
21490
|
adkCommand;
|
|
21610
21491
|
callbacks;
|
|
21611
21492
|
constructor(options) {
|
|
21612
|
-
this.projectPath =
|
|
21613
|
-
this.outputPath =
|
|
21493
|
+
this.projectPath = path43.resolve(options.projectPath);
|
|
21494
|
+
this.outputPath = path43.resolve(options.outputPath || path43.join(this.projectPath, ".adk"));
|
|
21614
21495
|
this.adkCommand = options.adkCommand;
|
|
21615
21496
|
this.callbacks = options.callbacks;
|
|
21616
21497
|
}
|
|
@@ -21620,10 +21501,10 @@ class BotGenerator {
|
|
|
21620
21501
|
return [];
|
|
21621
21502
|
const result = [];
|
|
21622
21503
|
const walk = async (dir, relativeBase) => {
|
|
21623
|
-
const entries = await
|
|
21504
|
+
const entries = await fs20.readdir(dir, { withFileTypes: true });
|
|
21624
21505
|
for (const entry of entries) {
|
|
21625
|
-
const abs =
|
|
21626
|
-
const rel =
|
|
21506
|
+
const abs = path43.join(dir, entry.name);
|
|
21507
|
+
const rel = path43.join(relativeBase, entry.name);
|
|
21627
21508
|
if (entry.isDirectory()) {
|
|
21628
21509
|
await walk(abs, rel);
|
|
21629
21510
|
} else {
|
|
@@ -21641,17 +21522,17 @@ class BotGenerator {
|
|
|
21641
21522
|
if (!existsSync7(rootDir))
|
|
21642
21523
|
return;
|
|
21643
21524
|
const removeIfEmpty = async (dir) => {
|
|
21644
|
-
const entries = await
|
|
21525
|
+
const entries = await fs20.readdir(dir, { withFileTypes: true });
|
|
21645
21526
|
for (const entry of entries) {
|
|
21646
21527
|
if (entry.isDirectory()) {
|
|
21647
|
-
const subdir =
|
|
21528
|
+
const subdir = path43.join(dir, entry.name);
|
|
21648
21529
|
await removeIfEmpty(subdir);
|
|
21649
21530
|
}
|
|
21650
21531
|
}
|
|
21651
|
-
const after = await
|
|
21532
|
+
const after = await fs20.readdir(dir);
|
|
21652
21533
|
if (after.length === 0 && dir !== rootDir) {
|
|
21653
21534
|
try {
|
|
21654
|
-
await
|
|
21535
|
+
await fs20.rmdir(dir, { recursive: false });
|
|
21655
21536
|
} catch {}
|
|
21656
21537
|
}
|
|
21657
21538
|
};
|
|
@@ -21659,7 +21540,7 @@ class BotGenerator {
|
|
|
21659
21540
|
}
|
|
21660
21541
|
async generate() {
|
|
21661
21542
|
const project = await AgentProject.load(this.projectPath);
|
|
21662
|
-
await
|
|
21543
|
+
await fs20.mkdir(this.outputPath, { recursive: true });
|
|
21663
21544
|
await this.generateBotDefinition();
|
|
21664
21545
|
await this.generateIntegrationsDefinition();
|
|
21665
21546
|
await this.generatePluginsDefinition();
|
|
@@ -21694,19 +21575,19 @@ class BotGenerator {
|
|
|
21694
21575
|
project
|
|
21695
21576
|
});
|
|
21696
21577
|
const integrations = await manager3.loadIntegrations(project.dependencies || {});
|
|
21697
|
-
const integrationsDir =
|
|
21578
|
+
const integrationsDir = path43.join(this.projectPath, ".adk", "integrations");
|
|
21698
21579
|
const existingIntegrationFiles = await this.listFilesRecursive(integrationsDir);
|
|
21699
21580
|
let aliases = new Set;
|
|
21700
21581
|
let files = new Set;
|
|
21701
21582
|
for (const integration of integrations.integrations) {
|
|
21702
21583
|
if (integration.definition) {
|
|
21703
21584
|
const types6 = await generateIntegrationTypes(integration);
|
|
21704
|
-
const importPath = `./${
|
|
21585
|
+
const importPath = `./${path43.join("integrations", types6.names.paths.index).replace(/\\/g, "/")}`;
|
|
21705
21586
|
aliases.add(`"${integration.alias}": import("${importPath}").${types6.names.typings.index}`);
|
|
21706
21587
|
for (const [filePath, content] of Object.entries(types6.files)) {
|
|
21707
|
-
const fullPath =
|
|
21708
|
-
const dir =
|
|
21709
|
-
await
|
|
21588
|
+
const fullPath = path43.join(this.projectPath, ".adk", "integrations", filePath);
|
|
21589
|
+
const dir = path43.dirname(fullPath);
|
|
21590
|
+
await fs20.mkdir(dir, { recursive: true });
|
|
21710
21591
|
await createFile(fullPath, content);
|
|
21711
21592
|
files.add(filePath);
|
|
21712
21593
|
}
|
|
@@ -21726,13 +21607,13 @@ class BotGenerator {
|
|
|
21726
21607
|
};
|
|
21727
21608
|
}
|
|
21728
21609
|
`;
|
|
21729
|
-
await createFile(
|
|
21610
|
+
await createFile(path43.join(this.projectPath, ".adk", "integrations-types.d.ts"), await formatCode(types5));
|
|
21730
21611
|
const staleIntegrationFiles = existingIntegrationFiles.filter((f) => !files.has(f));
|
|
21731
21612
|
if (staleIntegrationFiles.length > 0) {
|
|
21732
21613
|
for (const rel of staleIntegrationFiles) {
|
|
21733
|
-
const abs =
|
|
21614
|
+
const abs = path43.join(integrationsDir, rel);
|
|
21734
21615
|
try {
|
|
21735
|
-
await
|
|
21616
|
+
await fs20.rm(abs, { force: true });
|
|
21736
21617
|
} catch {}
|
|
21737
21618
|
}
|
|
21738
21619
|
}
|
|
@@ -21744,19 +21625,19 @@ class BotGenerator {
|
|
|
21744
21625
|
project
|
|
21745
21626
|
});
|
|
21746
21627
|
const result = await manager3.loadPlugins(project.dependencies || {});
|
|
21747
|
-
const pluginsDir =
|
|
21628
|
+
const pluginsDir = path43.join(this.projectPath, ".adk", "plugins");
|
|
21748
21629
|
const existingPluginFiles = await this.listFilesRecursive(pluginsDir);
|
|
21749
21630
|
let aliases = new Set;
|
|
21750
21631
|
let files = new Set;
|
|
21751
21632
|
for (const plugin of result.plugins) {
|
|
21752
21633
|
if (plugin.definition) {
|
|
21753
21634
|
const types6 = await generatePluginTypes(plugin);
|
|
21754
|
-
const importPath = `./${
|
|
21635
|
+
const importPath = `./${path43.join("plugins", types6.names.paths.index).replace(/\\/g, "/")}`;
|
|
21755
21636
|
aliases.add(`"${plugin.alias}": import("${importPath}").${types6.names.typings.index}`);
|
|
21756
21637
|
for (const [filePath, content] of Object.entries(types6.files)) {
|
|
21757
|
-
const fullPath =
|
|
21758
|
-
const dir =
|
|
21759
|
-
await
|
|
21638
|
+
const fullPath = path43.join(this.projectPath, ".adk", "plugins", filePath);
|
|
21639
|
+
const dir = path43.dirname(fullPath);
|
|
21640
|
+
await fs20.mkdir(dir, { recursive: true });
|
|
21760
21641
|
await createFile(fullPath, content);
|
|
21761
21642
|
files.add(filePath);
|
|
21762
21643
|
}
|
|
@@ -21776,13 +21657,13 @@ class BotGenerator {
|
|
|
21776
21657
|
};
|
|
21777
21658
|
}
|
|
21778
21659
|
`;
|
|
21779
|
-
await createFile(
|
|
21660
|
+
await createFile(path43.join(this.projectPath, ".adk", "plugins-types.d.ts"), await formatCode(types5));
|
|
21780
21661
|
const stalePluginFiles = existingPluginFiles.filter((f) => !files.has(f));
|
|
21781
21662
|
if (stalePluginFiles.length > 0) {
|
|
21782
21663
|
for (const rel of stalePluginFiles) {
|
|
21783
|
-
const abs =
|
|
21664
|
+
const abs = path43.join(pluginsDir, rel);
|
|
21784
21665
|
try {
|
|
21785
|
-
await
|
|
21666
|
+
await fs20.rm(abs, { force: true });
|
|
21786
21667
|
} catch {}
|
|
21787
21668
|
}
|
|
21788
21669
|
}
|
|
@@ -21865,7 +21746,7 @@ class BotGenerator {
|
|
|
21865
21746
|
let botStateType = "{}";
|
|
21866
21747
|
let userStateType = "{}";
|
|
21867
21748
|
try {
|
|
21868
|
-
const configPath =
|
|
21749
|
+
const configPath = path43.join(project.path, "agent.config.ts");
|
|
21869
21750
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
21870
21751
|
const config = configModule.default;
|
|
21871
21752
|
if (config?.bot?.state) {
|
|
@@ -21901,7 +21782,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
21901
21782
|
export type UserState = ${userStateType};
|
|
21902
21783
|
}
|
|
21903
21784
|
`;
|
|
21904
|
-
await createFile(
|
|
21785
|
+
await createFile(path43.join(this.projectPath, ".adk", "runtime.d.ts"), await formatCode(types5));
|
|
21905
21786
|
}
|
|
21906
21787
|
async generateInterfacesTypes() {
|
|
21907
21788
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -21911,7 +21792,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
21911
21792
|
const manager3 = new InterfaceManager({
|
|
21912
21793
|
project
|
|
21913
21794
|
});
|
|
21914
|
-
const interfacesDir =
|
|
21795
|
+
const interfacesDir = path43.join(this.projectPath, ".adk", "interfaces");
|
|
21915
21796
|
const existingInterfaceFiles = await this.listFilesRecursive(interfacesDir);
|
|
21916
21797
|
const interfaces = await manager3.loadInterfaces(project.dependencies || {}).then((result) => result.interfaces.filter((int) => int.definition).map((x) => x.definition));
|
|
21917
21798
|
const integrationsWithAlias = await integrationManager.loadIntegrations(project.dependencies || {}).then((result) => result.integrations.filter((int) => int.definition).map((x) => ({ alias: x.alias, definition: x.definition })));
|
|
@@ -21920,12 +21801,12 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
21920
21801
|
let files = new Set;
|
|
21921
21802
|
for (const int of interfaces) {
|
|
21922
21803
|
const types6 = await generateInterfaceTypes(int, integrationsWithAlias);
|
|
21923
|
-
imports.add(`import { ${types6.names.typings.index} } from "./${
|
|
21804
|
+
imports.add(`import { ${types6.names.typings.index} } from "./${path43.join("interfaces", types6.names.paths.index).replace(/\\/g, "/")}";`);
|
|
21924
21805
|
aliases.add(`"${types6.names.name}": ${types6.names.typings.index}`);
|
|
21925
21806
|
for (const [filePath, content] of Object.entries(types6.files)) {
|
|
21926
|
-
const fullPath =
|
|
21927
|
-
const dir =
|
|
21928
|
-
await
|
|
21807
|
+
const fullPath = path43.join(this.projectPath, ".adk", "interfaces", filePath);
|
|
21808
|
+
const dir = path43.dirname(fullPath);
|
|
21809
|
+
await fs20.mkdir(dir, { recursive: true });
|
|
21929
21810
|
await createFile(fullPath, content);
|
|
21930
21811
|
files.add(filePath);
|
|
21931
21812
|
}
|
|
@@ -21961,14 +21842,14 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
21961
21842
|
`)}
|
|
21962
21843
|
};
|
|
21963
21844
|
`;
|
|
21964
|
-
await createFile(
|
|
21965
|
-
await createFile(
|
|
21845
|
+
await createFile(path43.join(this.projectPath, ".adk", "interfaces.d.ts"), await formatCode(types5));
|
|
21846
|
+
await createFile(path43.join(this.projectPath, ".adk", "interfaces.ts"), await formatCode(consts));
|
|
21966
21847
|
const staleInterfaceFiles = existingInterfaceFiles.filter((f) => !files.has(f));
|
|
21967
21848
|
if (staleInterfaceFiles.length > 0) {
|
|
21968
21849
|
for (const rel of staleInterfaceFiles) {
|
|
21969
|
-
const abs =
|
|
21850
|
+
const abs = path43.join(interfacesDir, rel);
|
|
21970
21851
|
try {
|
|
21971
|
-
await
|
|
21852
|
+
await fs20.rm(abs, { force: true });
|
|
21972
21853
|
} catch {}
|
|
21973
21854
|
}
|
|
21974
21855
|
}
|
|
@@ -21996,7 +21877,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
21996
21877
|
`) : ""}
|
|
21997
21878
|
} as Record<string, IntegrationPackage>;
|
|
21998
21879
|
`;
|
|
21999
|
-
await createFile(
|
|
21880
|
+
await createFile(path43.join(this.outputPath, "src", "integrations.ts"), content);
|
|
22000
21881
|
}
|
|
22001
21882
|
async generatePluginsDefinition() {
|
|
22002
21883
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -22020,7 +21901,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
22020
21901
|
`) : ""}
|
|
22021
21902
|
} as Record<string, PluginPackage>;
|
|
22022
21903
|
`;
|
|
22023
|
-
await createFile(
|
|
21904
|
+
await createFile(path43.join(this.outputPath, "src", "plugins.ts"), content);
|
|
22024
21905
|
}
|
|
22025
21906
|
async generateInterfacesDefinition() {
|
|
22026
21907
|
const interfaces = BUILTIN_INTERFACES;
|
|
@@ -22043,7 +21924,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
22043
21924
|
`) : ""}
|
|
22044
21925
|
} as Record<string, InterfacePackage>;
|
|
22045
21926
|
`;
|
|
22046
|
-
await createFile(
|
|
21927
|
+
await createFile(path43.join(this.outputPath, "src", "interfaces.ts"), await formatCode(content));
|
|
22047
21928
|
}
|
|
22048
21929
|
reportServerConfigSync(label, serverConfigResult, items) {
|
|
22049
21930
|
if (!this.callbacks) {
|
|
@@ -22166,7 +22047,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
22166
22047
|
if (isBuiltinWorkflow3(workflow.definition.name)) {
|
|
22167
22048
|
continue;
|
|
22168
22049
|
}
|
|
22169
|
-
const workflowPath =
|
|
22050
|
+
const workflowPath = path43.join(project.path, workflow.path);
|
|
22170
22051
|
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
22171
22052
|
const workflowInstance = workflowModule.default || workflowModule[workflow.export];
|
|
22172
22053
|
if (workflowInstance) {
|
|
@@ -22472,16 +22353,18 @@ secrets: ${secretsDef},
|
|
|
22472
22353
|
const fullContent = content + integrationsSection + pluginsSection + `
|
|
22473
22354
|
|
|
22474
22355
|
export default bot;`;
|
|
22475
|
-
await createFile(
|
|
22356
|
+
await createFile(path43.join(this.outputPath, "bot.definition.ts"), await formatCode(fullContent));
|
|
22476
22357
|
}
|
|
22477
22358
|
async generateBotIndex() {
|
|
22478
22359
|
const content = dedent`
|
|
22479
22360
|
import * as bp from '.botpress'
|
|
22361
|
+
import { BotLogger } from '@botpress/sdk'
|
|
22480
22362
|
import { setupAdkRuntime } from './adk-runtime'
|
|
22481
22363
|
import {isMainThread, isWorkerMode, initializeParentWorker, runWorker} from '@botpress/runtime/internal'
|
|
22482
22364
|
import { handlers } from "@botpress/runtime/runtime";
|
|
22483
22365
|
|
|
22484
22366
|
// SDK/public bot types do not exactly match ADK's internal runtime setup types.
|
|
22367
|
+
const logger = new BotLogger({})
|
|
22485
22368
|
const bot = new bp.Bot({
|
|
22486
22369
|
actions: {} as any,
|
|
22487
22370
|
register: async (props: Parameters<typeof handlers.trigger.triggerRegisterEvent>[0]) => {
|
|
@@ -22496,22 +22379,23 @@ export default bot;`;
|
|
|
22496
22379
|
|
|
22497
22380
|
if (isWorkerMode() && isMainThread) {
|
|
22498
22381
|
// Branch 1: Main thread in worker mode - initialize parent with pool
|
|
22499
|
-
if (process.env.BP_DEBUG)
|
|
22382
|
+
if (process.env.BP_DEBUG) logger.debug("[Main] Initializing parent worker with pool...");
|
|
22500
22383
|
initializeParentWorker(bot as unknown as Record<string, unknown>);
|
|
22501
22384
|
} else if (isWorkerMode() && process.env.IS_DEV_WORKER === "true") {
|
|
22502
22385
|
// Branch 2: Worker thread - run child worker
|
|
22503
|
-
if (process.env.BP_DEBUG)
|
|
22504
|
-
runWorker(bot as any);
|
|
22386
|
+
if (process.env.BP_DEBUG) logger.debug("[Worker] Initializing child worker...");
|
|
22387
|
+
const markWorkerReady = runWorker(bot as any);
|
|
22505
22388
|
setupAdkRuntime(bot);
|
|
22389
|
+
markWorkerReady();
|
|
22506
22390
|
} else {
|
|
22507
22391
|
// Branch 3: Worker mode disabled - single-thread mode
|
|
22508
|
-
if (process.env.BP_DEBUG)
|
|
22392
|
+
if (process.env.BP_DEBUG) logger.debug("[Bot] Running in single-thread mode");
|
|
22509
22393
|
setupAdkRuntime(bot);
|
|
22510
22394
|
}
|
|
22511
22395
|
|
|
22512
22396
|
export default bot
|
|
22513
22397
|
`;
|
|
22514
|
-
await createFile(
|
|
22398
|
+
await createFile(path43.join(this.outputPath, "src", "index.ts"), await formatCode(content));
|
|
22515
22399
|
}
|
|
22516
22400
|
async generatePackageJson(project) {
|
|
22517
22401
|
const packageJson = {
|
|
@@ -22525,7 +22409,7 @@ export default bot;`;
|
|
|
22525
22409
|
typescript: "^5.9.3"
|
|
22526
22410
|
}
|
|
22527
22411
|
};
|
|
22528
|
-
await createFile(
|
|
22412
|
+
await createFile(path43.join(this.outputPath, "package.json"), JSON.stringify(packageJson, null, 2));
|
|
22529
22413
|
}
|
|
22530
22414
|
async generateTsConfig() {
|
|
22531
22415
|
const tsConfig = {
|
|
@@ -22558,7 +22442,7 @@ export default bot;`;
|
|
|
22558
22442
|
},
|
|
22559
22443
|
include: [".botpress/**/*", "src/**/*", "bp_modules/**/*", "./*.ts", "./*.json", "../*.d.ts"]
|
|
22560
22444
|
};
|
|
22561
|
-
await createFile(
|
|
22445
|
+
await createFile(path43.join(this.outputPath, "tsconfig.json"), JSON.stringify(tsConfig, null, 2));
|
|
22562
22446
|
}
|
|
22563
22447
|
async generateGlobalTypes() {
|
|
22564
22448
|
const content = dedent`
|
|
@@ -22581,42 +22465,42 @@ export default bot;`;
|
|
|
22581
22465
|
|
|
22582
22466
|
export {};
|
|
22583
22467
|
`;
|
|
22584
|
-
await createFile(
|
|
22468
|
+
await createFile(path43.join(this.outputPath, "global.d.ts"), await formatCode(content));
|
|
22585
22469
|
}
|
|
22586
22470
|
async copyAssets() {
|
|
22587
|
-
const assetsPath =
|
|
22588
|
-
const targetPath =
|
|
22471
|
+
const assetsPath = path43.join(this.projectPath, "assets");
|
|
22472
|
+
const targetPath = path43.join(this.outputPath, "assets");
|
|
22589
22473
|
if (existsSync7(assetsPath)) {
|
|
22590
|
-
await
|
|
22474
|
+
await fs20.mkdir(targetPath, { recursive: true });
|
|
22591
22475
|
await this.copyDirectory(assetsPath, targetPath);
|
|
22592
22476
|
}
|
|
22593
22477
|
}
|
|
22594
22478
|
async copyDirectory(src, dest) {
|
|
22595
|
-
const entries = await
|
|
22479
|
+
const entries = await fs20.readdir(src, { withFileTypes: true });
|
|
22596
22480
|
for (const entry of entries) {
|
|
22597
|
-
const srcPath =
|
|
22598
|
-
const destPath =
|
|
22481
|
+
const srcPath = path43.join(src, entry.name);
|
|
22482
|
+
const destPath = path43.join(dest, entry.name);
|
|
22599
22483
|
if (entry.isDirectory()) {
|
|
22600
|
-
await
|
|
22484
|
+
await fs20.mkdir(destPath, { recursive: true });
|
|
22601
22485
|
await this.copyDirectory(srcPath, destPath);
|
|
22602
22486
|
} else {
|
|
22603
|
-
await
|
|
22487
|
+
await fs20.copyFile(srcPath, destPath);
|
|
22604
22488
|
}
|
|
22605
22489
|
}
|
|
22606
22490
|
}
|
|
22607
22491
|
async generateAdkRuntime() {
|
|
22608
22492
|
const project = new AgentProject(this.projectPath);
|
|
22609
22493
|
await project.reload();
|
|
22610
|
-
const srcDir =
|
|
22494
|
+
const srcDir = path43.join(this.outputPath, "src");
|
|
22611
22495
|
{
|
|
22612
|
-
const dest =
|
|
22496
|
+
const dest = path43.join(srcDir, "conversations.ts");
|
|
22613
22497
|
const imports = new Map;
|
|
22614
22498
|
const exports = new Set;
|
|
22615
22499
|
let index = 1;
|
|
22616
22500
|
for (const conversation of project.conversations) {
|
|
22617
22501
|
if (!imports.has(conversation.path)) {
|
|
22618
22502
|
const name = `conversations_${index++}`;
|
|
22619
|
-
const importPath = getImportPath(dest,
|
|
22503
|
+
const importPath = getImportPath(dest, path43.join(project.path, conversation.path));
|
|
22620
22504
|
imports.set(conversation.path, {
|
|
22621
22505
|
name,
|
|
22622
22506
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -22642,14 +22526,14 @@ export default bot;`;
|
|
|
22642
22526
|
await createFile(dest, await formatCode(content2));
|
|
22643
22527
|
}
|
|
22644
22528
|
{
|
|
22645
|
-
const dest =
|
|
22529
|
+
const dest = path43.join(srcDir, "knowledge.ts");
|
|
22646
22530
|
const imports = new Map;
|
|
22647
22531
|
const exports = new Set;
|
|
22648
22532
|
let index = 1;
|
|
22649
22533
|
for (const knowledge of project.knowledge) {
|
|
22650
22534
|
if (!imports.has(knowledge.path)) {
|
|
22651
22535
|
const name = `knowledge_${index++}`;
|
|
22652
|
-
const importPath = getImportPath(dest,
|
|
22536
|
+
const importPath = getImportPath(dest, path43.join(project.path, knowledge.path));
|
|
22653
22537
|
imports.set(knowledge.path, {
|
|
22654
22538
|
name,
|
|
22655
22539
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -22675,14 +22559,14 @@ export default bot;`;
|
|
|
22675
22559
|
await createFile(dest, await formatCode(content2));
|
|
22676
22560
|
}
|
|
22677
22561
|
{
|
|
22678
|
-
const dest =
|
|
22562
|
+
const dest = path43.join(srcDir, "custom-components.ts");
|
|
22679
22563
|
const imports = new Map;
|
|
22680
22564
|
const exports = new Set;
|
|
22681
22565
|
let index = 1;
|
|
22682
22566
|
for (const comp of project.customComponents) {
|
|
22683
22567
|
if (!imports.has(comp.path)) {
|
|
22684
22568
|
const name = `components_${index++}`;
|
|
22685
|
-
const importPath = getImportPath(dest,
|
|
22569
|
+
const importPath = getImportPath(dest, path43.join(project.path, comp.path));
|
|
22686
22570
|
imports.set(comp.path, {
|
|
22687
22571
|
name,
|
|
22688
22572
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -22708,7 +22592,7 @@ export default bot;`;
|
|
|
22708
22592
|
await createFile(dest, await formatCode(content2));
|
|
22709
22593
|
}
|
|
22710
22594
|
{
|
|
22711
|
-
const dest =
|
|
22595
|
+
const dest = path43.join(srcDir, "triggers.ts");
|
|
22712
22596
|
const {
|
|
22713
22597
|
z: { transforms: transforms7 }
|
|
22714
22598
|
} = await import("@botpress/sdk");
|
|
@@ -22719,7 +22603,7 @@ export default bot;`;
|
|
|
22719
22603
|
for (const trigger of project.triggers) {
|
|
22720
22604
|
if (!imports.has(trigger.path)) {
|
|
22721
22605
|
const name = `triggers_${index++}`;
|
|
22722
|
-
const importPath = getImportPath(dest,
|
|
22606
|
+
const importPath = getImportPath(dest, path43.join(project.path, trigger.path));
|
|
22723
22607
|
imports.set(trigger.path, {
|
|
22724
22608
|
name,
|
|
22725
22609
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -22729,7 +22613,7 @@ export default bot;`;
|
|
|
22729
22613
|
}
|
|
22730
22614
|
for (const trigger of project.triggers) {
|
|
22731
22615
|
try {
|
|
22732
|
-
const absolutePath =
|
|
22616
|
+
const absolutePath = path43.join(project.path, trigger.path);
|
|
22733
22617
|
const triggerModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
22734
22618
|
const triggerInstance = triggerModule[trigger.export] || triggerModule.default;
|
|
22735
22619
|
if (triggerInstance && triggerInstance.payload) {
|
|
@@ -22772,7 +22656,7 @@ export default bot;`;
|
|
|
22772
22656
|
await createFile(dest, await formatCode(content2));
|
|
22773
22657
|
}
|
|
22774
22658
|
{
|
|
22775
|
-
const dest =
|
|
22659
|
+
const dest = path43.join(srcDir, "workflows.ts");
|
|
22776
22660
|
const imports = new Map;
|
|
22777
22661
|
const exports = new Set;
|
|
22778
22662
|
let index = 1;
|
|
@@ -22782,7 +22666,7 @@ export default bot;`;
|
|
|
22782
22666
|
}
|
|
22783
22667
|
if (!imports.has(workflow.path)) {
|
|
22784
22668
|
const name = `workflows_${index++}`;
|
|
22785
|
-
const importPath = getImportPath(dest,
|
|
22669
|
+
const importPath = getImportPath(dest, path43.join(project.path, workflow.path));
|
|
22786
22670
|
const statement = `import * as ${name} from "${importPath}";`;
|
|
22787
22671
|
imports.set(workflow.path, {
|
|
22788
22672
|
name,
|
|
@@ -22816,7 +22700,7 @@ export default bot;`;
|
|
|
22816
22700
|
await createFile(dest, await formatCode(content2));
|
|
22817
22701
|
}
|
|
22818
22702
|
{
|
|
22819
|
-
const dest =
|
|
22703
|
+
const dest = path43.join(srcDir, "actions.ts");
|
|
22820
22704
|
const imports = new Map;
|
|
22821
22705
|
const exports = new Set;
|
|
22822
22706
|
let index = 1;
|
|
@@ -22826,7 +22710,7 @@ export default bot;`;
|
|
|
22826
22710
|
}
|
|
22827
22711
|
if (!imports.has(action.path)) {
|
|
22828
22712
|
const name = `actions_${index++}`;
|
|
22829
|
-
const importPath = getImportPath(dest,
|
|
22713
|
+
const importPath = getImportPath(dest, path43.join(project.path, action.path));
|
|
22830
22714
|
imports.set(action.path, {
|
|
22831
22715
|
name,
|
|
22832
22716
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -22852,14 +22736,14 @@ export default bot;`;
|
|
|
22852
22736
|
await createFile(dest, await formatCode(content2));
|
|
22853
22737
|
}
|
|
22854
22738
|
{
|
|
22855
|
-
const dest =
|
|
22739
|
+
const dest = path43.join(srcDir, "tables.ts");
|
|
22856
22740
|
const imports = new Map;
|
|
22857
22741
|
const exports = new Set;
|
|
22858
22742
|
let index = 1;
|
|
22859
22743
|
for (const table of project.tables) {
|
|
22860
22744
|
if (!imports.has(table.path)) {
|
|
22861
22745
|
const name = `tables_${index++}`;
|
|
22862
|
-
const importPath = getImportPath(dest,
|
|
22746
|
+
const importPath = getImportPath(dest, path43.join(project.path, table.path));
|
|
22863
22747
|
imports.set(table.path, {
|
|
22864
22748
|
name,
|
|
22865
22749
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -22885,8 +22769,8 @@ export default bot;`;
|
|
|
22885
22769
|
await createFile(dest, await formatCode(content2));
|
|
22886
22770
|
}
|
|
22887
22771
|
{
|
|
22888
|
-
const dest =
|
|
22889
|
-
const importPath = getImportPath(dest,
|
|
22772
|
+
const dest = path43.join(srcDir, "config.ts");
|
|
22773
|
+
const importPath = getImportPath(dest, path43.join(project.path, "agent.config.ts"));
|
|
22890
22774
|
const content2 = `
|
|
22891
22775
|
////////////////////////////////////////////////////////
|
|
22892
22776
|
// DO NOT EDIT THIS FILE DIRECTLY
|
|
@@ -22966,15 +22850,15 @@ export default bot;`;
|
|
|
22966
22850
|
handlers.plugins.setup(runtimeBot);
|
|
22967
22851
|
}
|
|
22968
22852
|
`;
|
|
22969
|
-
await createFile(
|
|
22853
|
+
await createFile(path43.join(this.outputPath, "src", "adk-runtime.ts"), await formatCode(content));
|
|
22970
22854
|
}
|
|
22971
22855
|
async generateComponentUrlsBlock() {
|
|
22972
|
-
const manifestPath =
|
|
22856
|
+
const manifestPath = path43.join(this.projectPath, ".adk", "components.manifest.json");
|
|
22973
22857
|
try {
|
|
22974
22858
|
if (!existsSync7(manifestPath)) {
|
|
22975
22859
|
return "const componentUrls: Record<string, string> = {};";
|
|
22976
22860
|
}
|
|
22977
|
-
const manifest = JSON.parse(await
|
|
22861
|
+
const manifest = JSON.parse(await fs20.readFile(manifestPath, "utf-8"));
|
|
22978
22862
|
const entries = Object.entries(manifest).map(([name, data]) => `"${name}": "${data.url}"`).join(`,
|
|
22979
22863
|
`);
|
|
22980
22864
|
return `const componentUrls: Record<string, string> = {
|
|
@@ -22985,21 +22869,21 @@ export default bot;`;
|
|
|
22985
22869
|
}
|
|
22986
22870
|
}
|
|
22987
22871
|
async copyAssetsRuntime() {
|
|
22988
|
-
const assetsRuntimePath =
|
|
22872
|
+
const assetsRuntimePath = path43.join(this.projectPath, ".adk", "assets-runtime.ts");
|
|
22989
22873
|
const isShippingBuild = this.adkCommand !== "adk-dev";
|
|
22990
22874
|
if (isShippingBuild) {
|
|
22991
22875
|
const project = await AgentProject.load(this.projectPath);
|
|
22992
22876
|
await initAssets(this.projectPath, project.agentInfo?.botId, { dev: false });
|
|
22993
22877
|
}
|
|
22994
22878
|
if (existsSync7(assetsRuntimePath)) {
|
|
22995
|
-
const content = await
|
|
22996
|
-
await createFile(
|
|
22879
|
+
const content = await fs20.readFile(assetsRuntimePath, "utf-8");
|
|
22880
|
+
await createFile(path43.join(this.outputPath, "src", "assets-runtime.ts"), await formatCode(content));
|
|
22997
22881
|
}
|
|
22998
22882
|
}
|
|
22999
22883
|
}
|
|
23000
22884
|
async function generateBotProject(options) {
|
|
23001
22885
|
const generator = new BotGenerator(options);
|
|
23002
|
-
const botPath = options.outputPath ||
|
|
22886
|
+
const botPath = options.outputPath || path43.join(options.projectPath, ".adk", "bot");
|
|
23003
22887
|
await generator.generate();
|
|
23004
22888
|
const devIdManager = new DevIdManager(options.projectPath, botPath);
|
|
23005
22889
|
await Promise.all([
|
|
@@ -23043,15 +22927,18 @@ class TableManager {
|
|
|
23043
22927
|
client;
|
|
23044
22928
|
botId;
|
|
23045
22929
|
project;
|
|
22930
|
+
credentials;
|
|
23046
22931
|
constructor(options) {
|
|
23047
22932
|
this.botId = options.botId;
|
|
23048
22933
|
this.project = options.project;
|
|
22934
|
+
this.credentials = options.credentials;
|
|
23049
22935
|
}
|
|
23050
22936
|
async getClient() {
|
|
23051
22937
|
if (!this.client) {
|
|
23052
22938
|
this.assertBotId("initialize client");
|
|
23053
22939
|
this.client = await getProjectClient({
|
|
23054
22940
|
project: this.project,
|
|
22941
|
+
credentials: this.credentials,
|
|
23055
22942
|
botId: this.botId,
|
|
23056
22943
|
headers: {
|
|
23057
22944
|
"x-multiple-integrations": "true"
|
|
@@ -23538,8 +23425,8 @@ class TableManager {
|
|
|
23538
23425
|
init_src();
|
|
23539
23426
|
init_auth();
|
|
23540
23427
|
import crypto6 from "crypto";
|
|
23541
|
-
import
|
|
23542
|
-
import
|
|
23428
|
+
import path44 from "path";
|
|
23429
|
+
import fs21 from "fs/promises";
|
|
23543
23430
|
import { glob } from "glob";
|
|
23544
23431
|
import { DataSource } from "@botpress/runtime";
|
|
23545
23432
|
|
|
@@ -23573,11 +23460,13 @@ class KnowledgeManager {
|
|
|
23573
23460
|
client;
|
|
23574
23461
|
botId;
|
|
23575
23462
|
project;
|
|
23463
|
+
credentials;
|
|
23576
23464
|
fileHashCache = new Map;
|
|
23577
23465
|
remoteKbsPromise = null;
|
|
23578
23466
|
constructor(options) {
|
|
23579
23467
|
this.botId = options.botId;
|
|
23580
23468
|
this.project = options.project;
|
|
23469
|
+
this.credentials = options.credentials;
|
|
23581
23470
|
}
|
|
23582
23471
|
clearHashCache() {
|
|
23583
23472
|
this.fileHashCache.clear();
|
|
@@ -23587,6 +23476,7 @@ class KnowledgeManager {
|
|
|
23587
23476
|
this.assertBotId("initialize client");
|
|
23588
23477
|
this.client = await getProjectClient({
|
|
23589
23478
|
project: this.project,
|
|
23479
|
+
credentials: this.credentials,
|
|
23590
23480
|
botId: this.botId,
|
|
23591
23481
|
headers: {
|
|
23592
23482
|
"x-multiple-integrations": "true"
|
|
@@ -24009,15 +23899,15 @@ class KnowledgeManager {
|
|
|
24009
23899
|
}
|
|
24010
23900
|
async scanLocalFileHashes(directoryPath, filterFn) {
|
|
24011
23901
|
const projectDir = this.project.path;
|
|
24012
|
-
const directory =
|
|
23902
|
+
const directory = path44.resolve(projectDir, directoryPath);
|
|
24013
23903
|
if (this.fileHashCache.has(directory)) {
|
|
24014
23904
|
return this.fileHashCache.get(directory);
|
|
24015
23905
|
}
|
|
24016
23906
|
const files = glob.sync(directory + "/**/*.*", { absolute: true, nodir: true }).filter((file) => !filterFn || filterFn(file));
|
|
24017
23907
|
const hashes = {};
|
|
24018
23908
|
for (const file of files) {
|
|
24019
|
-
const relPath =
|
|
24020
|
-
const content = await
|
|
23909
|
+
const relPath = path44.relative(directory, file);
|
|
23910
|
+
const content = await fs21.readFile(file);
|
|
24021
23911
|
hashes[relPath] = crypto6.createHash("sha256").update(content).digest("hex");
|
|
24022
23912
|
}
|
|
24023
23913
|
this.fileHashCache.set(directory, hashes);
|
|
@@ -24148,7 +24038,7 @@ class KnowledgeManager {
|
|
|
24148
24038
|
}
|
|
24149
24039
|
async syncDirectorySource(client, kbName, kbId, dsId, directoryPath, filterFn, force) {
|
|
24150
24040
|
const projectDir = this.project.path;
|
|
24151
|
-
const directory =
|
|
24041
|
+
const directory = path44.resolve(projectDir, directoryPath);
|
|
24152
24042
|
if (!directory.startsWith(projectDir)) {
|
|
24153
24043
|
throw new AdkError({
|
|
24154
24044
|
code: "PATH_OUTSIDE_PROJECT",
|
|
@@ -24174,8 +24064,8 @@ class KnowledgeManager {
|
|
|
24174
24064
|
return true;
|
|
24175
24065
|
}).map((f) => ({
|
|
24176
24066
|
abs: f,
|
|
24177
|
-
rel:
|
|
24178
|
-
name:
|
|
24067
|
+
rel: path44.relative(directory, f),
|
|
24068
|
+
name: path44.basename(f)
|
|
24179
24069
|
}));
|
|
24180
24070
|
console.log(` Found ${allFiles.length} files in ${directoryPath}`);
|
|
24181
24071
|
const cachedHashes = await this.scanLocalFileHashes(directoryPath, filterFn);
|
|
@@ -24249,7 +24139,7 @@ class KnowledgeManager {
|
|
|
24249
24139
|
}
|
|
24250
24140
|
async upsertFile(client, local, dsId, tags, force, cachedHash) {
|
|
24251
24141
|
const key = `data_source://document/${dsId}/${local.rel}`;
|
|
24252
|
-
const content = await
|
|
24142
|
+
const content = await fs21.readFile(local.abs);
|
|
24253
24143
|
const hash = cachedHash ?? crypto6.createHash("sha256").update(content).digest("hex");
|
|
24254
24144
|
try {
|
|
24255
24145
|
const { file } = await client.getFile({ id: key });
|
|
@@ -24257,7 +24147,7 @@ class KnowledgeManager {
|
|
|
24257
24147
|
return null;
|
|
24258
24148
|
}
|
|
24259
24149
|
} catch {}
|
|
24260
|
-
const title =
|
|
24150
|
+
const title = path44.basename(local.name, path44.extname(local.name));
|
|
24261
24151
|
const metadata = {
|
|
24262
24152
|
hash,
|
|
24263
24153
|
dsId,
|
|
@@ -24283,14 +24173,14 @@ class KnowledgeManager {
|
|
|
24283
24173
|
}
|
|
24284
24174
|
// src/knowledge/sync-formatter.ts
|
|
24285
24175
|
import { readFileSync as readFileSync4 } from "fs";
|
|
24286
|
-
import { join as
|
|
24176
|
+
import { join as join8 } from "path";
|
|
24287
24177
|
var getAdkVersion = () => {
|
|
24288
24178
|
try {
|
|
24289
24179
|
const packageJson = require_package();
|
|
24290
24180
|
return packageJson.version;
|
|
24291
24181
|
} catch {
|
|
24292
24182
|
try {
|
|
24293
|
-
const adkPackagePath =
|
|
24183
|
+
const adkPackagePath = join8(process.cwd(), "node_modules/@botpress/adk/package.json");
|
|
24294
24184
|
const pkg = JSON.parse(readFileSync4(adkPackagePath, "utf-8"));
|
|
24295
24185
|
return pkg.version;
|
|
24296
24186
|
} catch {
|
|
@@ -24384,7 +24274,7 @@ class KBSyncFormatter {
|
|
|
24384
24274
|
// src/file-watcher/watcher.ts
|
|
24385
24275
|
import { watch as watch2, readdirSync as readdirSync2, statSync } from "fs";
|
|
24386
24276
|
import { EventEmitter as EventEmitter3 } from "events";
|
|
24387
|
-
import { dirname as dirname4, join as
|
|
24277
|
+
import { dirname as dirname4, join as join9, relative as relative3, sep } from "path";
|
|
24388
24278
|
import { existsSync as existsSync8 } from "fs";
|
|
24389
24279
|
|
|
24390
24280
|
class FileWatcher2 extends EventEmitter3 {
|
|
@@ -24403,13 +24293,13 @@ class FileWatcher2 extends EventEmitter3 {
|
|
|
24403
24293
|
start() {
|
|
24404
24294
|
const rootFiles = ["package.json", "agent.json", "agent.config.ts"];
|
|
24405
24295
|
for (const file of rootFiles) {
|
|
24406
|
-
const filePath =
|
|
24296
|
+
const filePath = join9(this.projectPath, file);
|
|
24407
24297
|
if (existsSync8(filePath)) {
|
|
24408
24298
|
this.updateFileState(filePath);
|
|
24409
24299
|
}
|
|
24410
24300
|
}
|
|
24411
24301
|
this.watchRootFiles(new Set(rootFiles));
|
|
24412
|
-
const srcPath =
|
|
24302
|
+
const srcPath = join9(this.projectPath, "src");
|
|
24413
24303
|
if (existsSync8(srcPath)) {
|
|
24414
24304
|
this.initializeDirectoryState(srcPath);
|
|
24415
24305
|
this.watchDirectory(srcPath);
|
|
@@ -24419,7 +24309,7 @@ class FileWatcher2 extends EventEmitter3 {
|
|
|
24419
24309
|
try {
|
|
24420
24310
|
const entries = readdirSync2(dirPath, { withFileTypes: true });
|
|
24421
24311
|
for (const entry of entries) {
|
|
24422
|
-
const fullPath =
|
|
24312
|
+
const fullPath = join9(dirPath, entry.name);
|
|
24423
24313
|
if (entry.isDirectory()) {
|
|
24424
24314
|
this.initializeDirectoryState(fullPath);
|
|
24425
24315
|
} else if (entry.isFile()) {
|
|
@@ -24435,7 +24325,7 @@ class FileWatcher2 extends EventEmitter3 {
|
|
|
24435
24325
|
try {
|
|
24436
24326
|
const watcher = watch2(this.projectPath, { persistent: true }, (_eventType, filename) => {
|
|
24437
24327
|
if (filename && rootFileNames.has(filename)) {
|
|
24438
|
-
this.handleFileChange(
|
|
24328
|
+
this.handleFileChange(join9(this.projectPath, filename));
|
|
24439
24329
|
return;
|
|
24440
24330
|
}
|
|
24441
24331
|
this.scheduleRootMtimeCheck(rootFileNames);
|
|
@@ -24454,7 +24344,7 @@ class FileWatcher2 extends EventEmitter3 {
|
|
|
24454
24344
|
}
|
|
24455
24345
|
checkRootFilesByMtime(rootFileNames) {
|
|
24456
24346
|
for (const name of rootFileNames) {
|
|
24457
|
-
const fullPath =
|
|
24347
|
+
const fullPath = join9(this.projectPath, name);
|
|
24458
24348
|
const tracked = this.fileStates.get(fullPath);
|
|
24459
24349
|
let mtime;
|
|
24460
24350
|
try {
|
|
@@ -24487,7 +24377,7 @@ class FileWatcher2 extends EventEmitter3 {
|
|
|
24487
24377
|
try {
|
|
24488
24378
|
const watcher = watch2(dirPath, { recursive: true, persistent: true }, (_eventType, filename) => {
|
|
24489
24379
|
if (filename) {
|
|
24490
|
-
const fullPath =
|
|
24380
|
+
const fullPath = join9(dirPath, filename);
|
|
24491
24381
|
this.handleFileChange(fullPath);
|
|
24492
24382
|
}
|
|
24493
24383
|
});
|
|
@@ -24517,7 +24407,7 @@ class FileWatcher2 extends EventEmitter3 {
|
|
|
24517
24407
|
this.updateFileState(filePath);
|
|
24518
24408
|
} else {
|
|
24519
24409
|
const parentDir = dirname4(filePath);
|
|
24520
|
-
const srcPath =
|
|
24410
|
+
const srcPath = join9(this.projectPath, "src");
|
|
24521
24411
|
if (parentDir === srcPath || parentDir.startsWith(srcPath + sep)) {
|
|
24522
24412
|
this.scanDirectoryForChanges(parentDir);
|
|
24523
24413
|
}
|
|
@@ -24552,7 +24442,7 @@ class FileWatcher2 extends EventEmitter3 {
|
|
|
24552
24442
|
const entries = readdirSync2(dirPath, { withFileTypes: true });
|
|
24553
24443
|
const currentFiles = new Set;
|
|
24554
24444
|
for (const entry of entries) {
|
|
24555
|
-
const fullPath =
|
|
24445
|
+
const fullPath = join9(dirPath, entry.name);
|
|
24556
24446
|
if (entry.isFile()) {
|
|
24557
24447
|
currentFiles.add(fullPath);
|
|
24558
24448
|
const trackedMtime = this.fileStates.get(fullPath);
|
|
@@ -24627,7 +24517,7 @@ class FileWatcher2 extends EventEmitter3 {
|
|
|
24627
24517
|
// src/preflight/checker.ts
|
|
24628
24518
|
init_agent_project();
|
|
24629
24519
|
init_auth();
|
|
24630
|
-
import
|
|
24520
|
+
import path45 from "path";
|
|
24631
24521
|
init_manager2();
|
|
24632
24522
|
|
|
24633
24523
|
// src/preflight/agent-config-sync.ts
|
|
@@ -24681,8 +24571,10 @@ class PreflightChecker {
|
|
|
24681
24571
|
projectPath;
|
|
24682
24572
|
client;
|
|
24683
24573
|
project;
|
|
24684
|
-
|
|
24574
|
+
credentials;
|
|
24575
|
+
constructor(projectPath, options = {}) {
|
|
24685
24576
|
this.projectPath = projectPath;
|
|
24577
|
+
this.credentials = options.credentials;
|
|
24686
24578
|
}
|
|
24687
24579
|
async getProject() {
|
|
24688
24580
|
if (!this.project) {
|
|
@@ -24694,7 +24586,8 @@ class PreflightChecker {
|
|
|
24694
24586
|
if (!this.client) {
|
|
24695
24587
|
const project = await this.getProject();
|
|
24696
24588
|
this.client = await getProjectClient({
|
|
24697
|
-
project
|
|
24589
|
+
project,
|
|
24590
|
+
credentials: this.credentials
|
|
24698
24591
|
});
|
|
24699
24592
|
}
|
|
24700
24593
|
return this.client;
|
|
@@ -24770,9 +24663,9 @@ class PreflightChecker {
|
|
|
24770
24663
|
}
|
|
24771
24664
|
async computeDeployPlan(botId, env = "prod") {
|
|
24772
24665
|
const project = await this.getProject();
|
|
24773
|
-
const tableManager = project.tables.length > 0 ? new TableManager({ project, botId }) : null;
|
|
24774
|
-
const kbManager = project.knowledge.length > 0 ? new KnowledgeManager({ project, botId }) : null;
|
|
24775
|
-
const assetsManager = await project.hasAssetsDirectory() ? new AssetsManager({ projectPath: this.projectPath, botId }) : null;
|
|
24666
|
+
const tableManager = project.tables.length > 0 ? new TableManager({ project, botId, credentials: this.credentials }) : null;
|
|
24667
|
+
const kbManager = project.knowledge.length > 0 ? new KnowledgeManager({ project, botId, credentials: this.credentials }) : null;
|
|
24668
|
+
const assetsManager = await project.hasAssetsDirectory() ? new AssetsManager({ projectPath: this.projectPath, botId, credentials: this.credentials }) : null;
|
|
24776
24669
|
const [preflight, tablePlan, kbResult, assetPlan] = await Promise.all([
|
|
24777
24670
|
this.checkWithPendingApply(botId, env),
|
|
24778
24671
|
tableManager ? tableManager.createSyncPlan() : Promise.resolve(null),
|
|
@@ -24804,7 +24697,7 @@ class PreflightChecker {
|
|
|
24804
24697
|
options?.onProgress?.("Regenerating bot project...");
|
|
24805
24698
|
await generateBotProject({
|
|
24806
24699
|
projectPath: this.projectPath,
|
|
24807
|
-
outputPath:
|
|
24700
|
+
outputPath: path45.join(this.projectPath, ".adk", "bot"),
|
|
24808
24701
|
callbacks: options
|
|
24809
24702
|
});
|
|
24810
24703
|
options?.onSuccess?.("Bot project regenerated");
|
|
@@ -24818,20 +24711,20 @@ function pluralize2(count, word) {
|
|
|
24818
24711
|
// src/runner/script-runner.ts
|
|
24819
24712
|
import dedent2 from "dedent";
|
|
24820
24713
|
import { existsSync as existsSync9 } from "fs";
|
|
24821
|
-
import
|
|
24822
|
-
import
|
|
24714
|
+
import fs22 from "fs/promises";
|
|
24715
|
+
import path46 from "path";
|
|
24823
24716
|
import { spawn } from "child_process";
|
|
24824
24717
|
init_utils();
|
|
24825
24718
|
init_auth();
|
|
24826
24719
|
|
|
24827
24720
|
// src/runner/supervise-child.ts
|
|
24828
|
-
import
|
|
24721
|
+
import os8 from "os";
|
|
24829
24722
|
var FORCE_KILL_MS = 2000;
|
|
24830
24723
|
function exitCodeFromClose(code, signal) {
|
|
24831
24724
|
if (code != null)
|
|
24832
24725
|
return code;
|
|
24833
24726
|
if (signal) {
|
|
24834
|
-
const num =
|
|
24727
|
+
const num = os8.constants.signals[signal];
|
|
24835
24728
|
return typeof num === "number" ? 128 + num : 1;
|
|
24836
24729
|
}
|
|
24837
24730
|
return 0;
|
|
@@ -24897,14 +24790,14 @@ function superviseChild(child, options = {}) {
|
|
|
24897
24790
|
// src/runner/script-runner.ts
|
|
24898
24791
|
init_src();
|
|
24899
24792
|
async function findAgentRoot(startPath) {
|
|
24900
|
-
let currentPath =
|
|
24901
|
-
const root =
|
|
24793
|
+
let currentPath = path46.resolve(startPath);
|
|
24794
|
+
const root = path46.parse(currentPath).root;
|
|
24902
24795
|
while (currentPath !== root) {
|
|
24903
24796
|
try {
|
|
24904
|
-
await
|
|
24797
|
+
await fs22.access(path46.join(currentPath, "agent.config.ts"));
|
|
24905
24798
|
return currentPath;
|
|
24906
24799
|
} catch {
|
|
24907
|
-
currentPath =
|
|
24800
|
+
currentPath = path46.dirname(currentPath);
|
|
24908
24801
|
}
|
|
24909
24802
|
}
|
|
24910
24803
|
return null;
|
|
@@ -24916,7 +24809,7 @@ class ScriptRunner {
|
|
|
24916
24809
|
prod;
|
|
24917
24810
|
credentials;
|
|
24918
24811
|
constructor(options) {
|
|
24919
|
-
this.projectPath =
|
|
24812
|
+
this.projectPath = path46.resolve(options.projectPath);
|
|
24920
24813
|
this.forceRegenerate = options.forceRegenerate ?? false;
|
|
24921
24814
|
this.prod = options.prod ?? false;
|
|
24922
24815
|
this.credentials = options.credentials;
|
|
@@ -24925,9 +24818,9 @@ class ScriptRunner {
|
|
|
24925
24818
|
const project = await AgentProject.load(this.projectPath, {
|
|
24926
24819
|
adkCommand: "adk-build"
|
|
24927
24820
|
});
|
|
24928
|
-
const botPath =
|
|
24929
|
-
const runnerPath =
|
|
24930
|
-
const botpressTypesPath =
|
|
24821
|
+
const botPath = path46.join(this.projectPath, ".adk", "bot");
|
|
24822
|
+
const runnerPath = path46.join(botPath, "src", "script-runner.ts");
|
|
24823
|
+
const botpressTypesPath = path46.join(botPath, ".botpress", "implementation", "index.ts");
|
|
24931
24824
|
const needsRegenerate = this.forceRegenerate || !existsSync9(runnerPath) || !existsSync9(botpressTypesPath);
|
|
24932
24825
|
if (needsRegenerate) {
|
|
24933
24826
|
try {
|
|
@@ -25046,7 +24939,7 @@ class ScriptRunner {
|
|
|
25046
24939
|
|
|
25047
24940
|
runScript()
|
|
25048
24941
|
`;
|
|
25049
|
-
await
|
|
24942
|
+
await fs22.writeFile(path46.join(botPath, "src", "script-runner.ts"), await formatCode(content), "utf-8");
|
|
25050
24943
|
}
|
|
25051
24944
|
async setupTestRuntime(options = {}) {
|
|
25052
24945
|
const { botPath, project } = await this.prepare();
|
|
@@ -25086,7 +24979,7 @@ class ScriptRunner {
|
|
|
25086
24979
|
for (const [key, value] of Object.entries(envVars)) {
|
|
25087
24980
|
process.env[key] = value;
|
|
25088
24981
|
}
|
|
25089
|
-
const runtimePath =
|
|
24982
|
+
const runtimePath = path46.join(botPath, "src", "index.ts");
|
|
25090
24983
|
return {
|
|
25091
24984
|
botPath,
|
|
25092
24985
|
runtimePath,
|
|
@@ -25099,10 +24992,10 @@ class ScriptRunner {
|
|
|
25099
24992
|
const runtimeModule = await import("@botpress/runtime/runtime");
|
|
25100
24993
|
const { Autonomous: Autonomous2 } = await import("@botpress/runtime");
|
|
25101
24994
|
const { context, agentRegistry } = runtimeModule;
|
|
25102
|
-
const { Client:
|
|
24995
|
+
const { Client: Client6 } = await import("@botpress/client");
|
|
25103
24996
|
const { BotSpecificClient, BotLogger } = await import("@botpress/sdk");
|
|
25104
24997
|
const { Cognitive } = await import("@botpress/cognitive");
|
|
25105
|
-
const vanillaClient = new
|
|
24998
|
+
const vanillaClient = new Client6({
|
|
25106
24999
|
token: this.credentials.token,
|
|
25107
25000
|
apiUrl: this.credentials.apiUrl,
|
|
25108
25001
|
workspaceId,
|
|
@@ -25135,7 +25028,7 @@ class ScriptRunner {
|
|
|
25135
25028
|
}
|
|
25136
25029
|
async run(scriptPath, options = {}) {
|
|
25137
25030
|
const { botPath, runnerPath, project } = await this.prepare();
|
|
25138
|
-
const absoluteScriptPath =
|
|
25031
|
+
const absoluteScriptPath = path46.isAbsolute(scriptPath) ? scriptPath : path46.resolve(this.projectPath, scriptPath);
|
|
25139
25032
|
if (!existsSync9(absoluteScriptPath)) {
|
|
25140
25033
|
throw new AdkError({
|
|
25141
25034
|
code: "SCRIPT_NOT_FOUND",
|
|
@@ -25292,7 +25185,6 @@ export {
|
|
|
25292
25185
|
IntegrationParser,
|
|
25293
25186
|
IntegrationManager,
|
|
25294
25187
|
IntegrationCache,
|
|
25295
|
-
HubCache,
|
|
25296
25188
|
FileWatcher2 as FileWatcher,
|
|
25297
25189
|
EnhancedInterfaceCache,
|
|
25298
25190
|
DevIdManager,
|
|
@@ -25324,4 +25216,4 @@ export {
|
|
|
25324
25216
|
ADK_MANIFEST_BOT_TAGS
|
|
25325
25217
|
};
|
|
25326
25218
|
|
|
25327
|
-
//# debugId=
|
|
25219
|
+
//# debugId=32600FBA87BCDF0664756E2164756E21
|