@botpress/adk 1.18.0-beta.5 → 1.18.0-beta.6
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/agent-init/agent-project-generator.d.ts.map +1 -1
- package/dist/agent-project/agent-project.d.ts +6 -1
- package/dist/agent-project/agent-project.d.ts.map +1 -1
- package/dist/agent-project/component-source-resolver.d.ts +27 -0
- package/dist/agent-project/component-source-resolver.d.ts.map +1 -0
- package/dist/agent-project/config-writer.d.ts +9 -0
- package/dist/agent-project/config-writer.d.ts.map +1 -1
- package/dist/agent-project/index.d.ts +1 -1
- package/dist/agent-project/index.d.ts.map +1 -1
- package/dist/bot-generator/dev-id-manager.d.ts +12 -2
- package/dist/bot-generator/dev-id-manager.d.ts.map +1 -1
- package/dist/commands/copilot-server.d.ts.map +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +643 -1771
- package/dist/index.js.map +15 -29
- package/dist/integrations/operations.d.ts +11 -4
- package/dist/integrations/operations.d.ts.map +1 -1
- package/dist/templates/slack-triage/evals/triage-basic.eval.ts +3 -3
- package/package.json +4 -4
- package/dist/eval/client.d.ts +0 -33
- package/dist/eval/client.d.ts.map +0 -1
- package/dist/eval/graders/index.d.ts +0 -13
- package/dist/eval/graders/index.d.ts.map +0 -1
- package/dist/eval/graders/llm.d.ts +0 -22
- package/dist/eval/graders/llm.d.ts.map +0 -1
- package/dist/eval/graders/match.d.ts +0 -11
- package/dist/eval/graders/match.d.ts.map +0 -1
- package/dist/eval/graders/outcome.d.ts +0 -17
- package/dist/eval/graders/outcome.d.ts.map +0 -1
- package/dist/eval/graders/response.d.ts +0 -10
- package/dist/eval/graders/response.d.ts.map +0 -1
- package/dist/eval/graders/state.d.ts +0 -16
- package/dist/eval/graders/state.d.ts.map +0 -1
- package/dist/eval/graders/tables.d.ts +0 -8
- package/dist/eval/graders/tables.d.ts.map +0 -1
- package/dist/eval/graders/timing.d.ts +0 -7
- package/dist/eval/graders/timing.d.ts.map +0 -1
- package/dist/eval/graders/tools.d.ts +0 -7
- package/dist/eval/graders/tools.d.ts.map +0 -1
- package/dist/eval/graders/workflow.d.ts +0 -8
- package/dist/eval/graders/workflow.d.ts.map +0 -1
- package/dist/eval/index.d.ts +0 -10
- package/dist/eval/index.d.ts.map +0 -1
- package/dist/eval/loader.d.ts +0 -11
- package/dist/eval/loader.d.ts.map +0 -1
- package/dist/eval/runner.d.ts +0 -14
- package/dist/eval/runner.d.ts.map +0 -1
- package/dist/eval/store.d.ts +0 -10
- package/dist/eval/store.d.ts.map +0 -1
- package/dist/eval/traces.d.ts +0 -19
- package/dist/eval/traces.d.ts.map +0 -1
- package/dist/eval/types.d.ts +0 -257
- package/dist/eval/types.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -2099,162 +2099,8 @@ class IntegrationCache {
|
|
|
2099
2099
|
}
|
|
2100
2100
|
var init_cache2 = () => {};
|
|
2101
2101
|
|
|
2102
|
-
// src/integrations/hub-cache.ts
|
|
2103
|
-
import { Client as Client6 } from "@botpress/client";
|
|
2104
|
-
import * as fs8 from "fs/promises";
|
|
2105
|
-
import * as path9 from "path";
|
|
2106
|
-
import * as os6 from "os";
|
|
2107
|
-
var HubCache;
|
|
2108
|
-
var init_hub_cache = __esm(() => {
|
|
2109
|
-
init_auth();
|
|
2110
|
-
HubCache = class HubCache {
|
|
2111
|
-
static CACHE_FILE = "botpress-hub-cache.json";
|
|
2112
|
-
static CACHE_DIR = path9.join(os6.homedir(), ".adk", "cache");
|
|
2113
|
-
static CACHE_PATH = path9.join(HubCache.CACHE_DIR, HubCache.CACHE_FILE);
|
|
2114
|
-
static CACHE_DURATION = 30 * 60 * 1000;
|
|
2115
|
-
client;
|
|
2116
|
-
constructor() {}
|
|
2117
|
-
async getClient() {
|
|
2118
|
-
if (!this.client) {
|
|
2119
|
-
const credentials = await auth.getActiveCredentials();
|
|
2120
|
-
if (!credentials.workspaceId) {
|
|
2121
|
-
throw new Error('No workspace ID found in current profile. Please login again with "adk login"');
|
|
2122
|
-
}
|
|
2123
|
-
this.client = new Client6({
|
|
2124
|
-
token: credentials.token,
|
|
2125
|
-
apiUrl: credentials.apiUrl,
|
|
2126
|
-
workspaceId: credentials.workspaceId,
|
|
2127
|
-
headers: {
|
|
2128
|
-
"x-multiple-integrations": "true"
|
|
2129
|
-
}
|
|
2130
|
-
});
|
|
2131
|
-
}
|
|
2132
|
-
return this.client;
|
|
2133
|
-
}
|
|
2134
|
-
async ensureCacheDir() {
|
|
2135
|
-
try {
|
|
2136
|
-
await fs8.mkdir(HubCache.CACHE_DIR, { recursive: true });
|
|
2137
|
-
} catch {}
|
|
2138
|
-
}
|
|
2139
|
-
async loadCache() {
|
|
2140
|
-
try {
|
|
2141
|
-
const data = await fs8.readFile(HubCache.CACHE_PATH, "utf-8");
|
|
2142
|
-
return JSON.parse(data);
|
|
2143
|
-
} catch {
|
|
2144
|
-
return null;
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
async saveCache(data) {
|
|
2148
|
-
await this.ensureCacheDir();
|
|
2149
|
-
await fs8.writeFile(HubCache.CACHE_PATH, JSON.stringify(data, null, 2));
|
|
2150
|
-
}
|
|
2151
|
-
async needsRefresh() {
|
|
2152
|
-
const cache2 = await this.loadCache();
|
|
2153
|
-
if (!cache2)
|
|
2154
|
-
return true;
|
|
2155
|
-
const lastUpdated = new Date(cache2.lastUpdated);
|
|
2156
|
-
const now = new Date;
|
|
2157
|
-
const diff = now.getTime() - lastUpdated.getTime();
|
|
2158
|
-
return diff > HubCache.CACHE_DURATION;
|
|
2159
|
-
}
|
|
2160
|
-
async refresh(force = false) {
|
|
2161
|
-
if (!force && !await this.needsRefresh()) {
|
|
2162
|
-
return;
|
|
2163
|
-
}
|
|
2164
|
-
const client = await this.getClient();
|
|
2165
|
-
const cache2 = await this.loadCache();
|
|
2166
|
-
const latestByName = new Map;
|
|
2167
|
-
if (cache2) {
|
|
2168
|
-
for (const entry of cache2.integrations) {
|
|
2169
|
-
latestByName.set(entry.name, entry);
|
|
2170
|
-
}
|
|
2171
|
-
}
|
|
2172
|
-
try {
|
|
2173
|
-
for await (const integration of client.list.publicIntegrations({
|
|
2174
|
-
sortBy: "updatedAt",
|
|
2175
|
-
direction: "desc"
|
|
2176
|
-
})) {
|
|
2177
|
-
const existing = latestByName.get(integration.name);
|
|
2178
|
-
if (existing && integration.id === existing.id && integration.updatedAt === existing.updatedAt) {
|
|
2179
|
-
break;
|
|
2180
|
-
}
|
|
2181
|
-
if (!existing || integration.version.localeCompare(existing.version, undefined, {
|
|
2182
|
-
numeric: true
|
|
2183
|
-
}) > 0) {
|
|
2184
|
-
latestByName.set(integration.name, {
|
|
2185
|
-
id: integration.id,
|
|
2186
|
-
name: integration.name,
|
|
2187
|
-
version: integration.version,
|
|
2188
|
-
updatedAt: integration.updatedAt,
|
|
2189
|
-
createdAt: integration.createdAt,
|
|
2190
|
-
title: integration.title,
|
|
2191
|
-
description: integration.description,
|
|
2192
|
-
iconUrl: integration.iconUrl,
|
|
2193
|
-
public: integration.public,
|
|
2194
|
-
visibility: integration.visibility,
|
|
2195
|
-
ownerWorkspace: integration.ownerWorkspace ? {
|
|
2196
|
-
id: integration.ownerWorkspace.id,
|
|
2197
|
-
name: integration.ownerWorkspace.name
|
|
2198
|
-
} : undefined,
|
|
2199
|
-
verificationStatus: integration.verificationStatus
|
|
2200
|
-
});
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
const integrations = Array.from(latestByName.values()).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
2204
|
-
const newCache = {
|
|
2205
|
-
lastUpdated: new Date().toISOString(),
|
|
2206
|
-
integrations
|
|
2207
|
-
};
|
|
2208
|
-
await this.saveCache(newCache);
|
|
2209
|
-
} catch (error) {
|
|
2210
|
-
throw new Error(`Failed to refresh hub cache: ${error instanceof Error ? error.message : String(error)}`);
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
async getAllIntegrations() {
|
|
2214
|
-
await this.refresh();
|
|
2215
|
-
const cache2 = await this.loadCache();
|
|
2216
|
-
return cache2?.integrations || [];
|
|
2217
|
-
}
|
|
2218
|
-
async searchIntegrations(query) {
|
|
2219
|
-
const integrations = await this.getAllIntegrations();
|
|
2220
|
-
const lowerQuery = query.toLowerCase();
|
|
2221
|
-
return integrations.filter((integration) => integration.name.toLowerCase().includes(lowerQuery) || integration.title?.toLowerCase().includes(lowerQuery) || integration.description?.toLowerCase().includes(lowerQuery));
|
|
2222
|
-
}
|
|
2223
|
-
async getIntegrationByName(name) {
|
|
2224
|
-
const integrations = await this.getAllIntegrations();
|
|
2225
|
-
return integrations.find((i) => i.name === name) || null;
|
|
2226
|
-
}
|
|
2227
|
-
async getIntegrationVersions(name) {
|
|
2228
|
-
const integration = await this.getIntegrationByName(name);
|
|
2229
|
-
return integration ? [integration.version] : [];
|
|
2230
|
-
}
|
|
2231
|
-
async getStats() {
|
|
2232
|
-
const cache2 = await this.loadCache();
|
|
2233
|
-
try {
|
|
2234
|
-
const stats = await fs8.stat(HubCache.CACHE_PATH);
|
|
2235
|
-
return {
|
|
2236
|
-
lastUpdated: cache2 ? new Date(cache2.lastUpdated) : null,
|
|
2237
|
-
integrationCount: cache2?.integrations.length || 0,
|
|
2238
|
-
cacheSize: stats.size
|
|
2239
|
-
};
|
|
2240
|
-
} catch {
|
|
2241
|
-
return {
|
|
2242
|
-
lastUpdated: null,
|
|
2243
|
-
integrationCount: 0,
|
|
2244
|
-
cacheSize: 0
|
|
2245
|
-
};
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
async clear() {
|
|
2249
|
-
try {
|
|
2250
|
-
await fs8.unlink(HubCache.CACHE_PATH);
|
|
2251
|
-
} catch {}
|
|
2252
|
-
}
|
|
2253
|
-
};
|
|
2254
|
-
});
|
|
2255
|
-
|
|
2256
2102
|
// src/generators/utils.ts
|
|
2257
|
-
import
|
|
2103
|
+
import path9 from "path";
|
|
2258
2104
|
async function getFormat() {
|
|
2259
2105
|
if (!_formatLoaded) {
|
|
2260
2106
|
_formatLoaded = true;
|
|
@@ -2302,9 +2148,9 @@ var _format = null, _formatLoaded = false, formatCode = async (code, filepath) =
|
|
|
2302
2148
|
`));
|
|
2303
2149
|
return code;
|
|
2304
2150
|
}
|
|
2305
|
-
}, ADK_VERSION = "1.18.0-beta.
|
|
2306
|
-
const fromDir =
|
|
2307
|
-
const relative3 =
|
|
2151
|
+
}, ADK_VERSION = "1.18.0-beta.6", relative2 = (from, to) => {
|
|
2152
|
+
const fromDir = path9.dirname(from);
|
|
2153
|
+
const relative3 = path9.relative(fromDir, to);
|
|
2308
2154
|
return relative3.startsWith(".") ? relative3 : `./${relative3}`;
|
|
2309
2155
|
};
|
|
2310
2156
|
var init_utils = () => {};
|
|
@@ -2312,12 +2158,12 @@ var init_utils = () => {};
|
|
|
2312
2158
|
// src/agent-project/config-writer.ts
|
|
2313
2159
|
import { Project, SyntaxKind } from "ts-morph";
|
|
2314
2160
|
import { readFileSync as readFileSync2 } from "fs";
|
|
2315
|
-
import * as
|
|
2161
|
+
import * as path10 from "path";
|
|
2316
2162
|
|
|
2317
2163
|
class ConfigWriter {
|
|
2318
2164
|
configPath;
|
|
2319
2165
|
constructor(projectPath) {
|
|
2320
|
-
this.configPath =
|
|
2166
|
+
this.configPath = path10.join(projectPath, "agent.config.ts");
|
|
2321
2167
|
}
|
|
2322
2168
|
loadConfig() {
|
|
2323
2169
|
const project = new Project;
|
|
@@ -2603,76 +2449,234 @@ var init_config_writer = __esm(() => {
|
|
|
2603
2449
|
init_utils();
|
|
2604
2450
|
});
|
|
2605
2451
|
|
|
2606
|
-
// src/integrations/
|
|
2607
|
-
import { Client as
|
|
2608
|
-
import * as
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
workspaceId = project.agentInfo.workspaceId;
|
|
2627
|
-
}
|
|
2452
|
+
// src/integrations/hub-cache.ts
|
|
2453
|
+
import { Client as Client6 } from "@botpress/client";
|
|
2454
|
+
import * as fs8 from "fs/promises";
|
|
2455
|
+
import * as path11 from "path";
|
|
2456
|
+
import * as os6 from "os";
|
|
2457
|
+
var HubCache;
|
|
2458
|
+
var init_hub_cache = __esm(() => {
|
|
2459
|
+
init_auth();
|
|
2460
|
+
HubCache = class HubCache {
|
|
2461
|
+
static CACHE_FILE = "botpress-hub-cache.json";
|
|
2462
|
+
static CACHE_DIR = path11.join(os6.homedir(), ".adk", "cache");
|
|
2463
|
+
static CACHE_PATH = path11.join(HubCache.CACHE_DIR, HubCache.CACHE_FILE);
|
|
2464
|
+
static CACHE_DURATION = 30 * 60 * 1000;
|
|
2465
|
+
client;
|
|
2466
|
+
constructor() {}
|
|
2467
|
+
async getClient() {
|
|
2468
|
+
if (!this.client) {
|
|
2469
|
+
const credentials = await auth.getActiveCredentials();
|
|
2470
|
+
if (!credentials.workspaceId) {
|
|
2471
|
+
throw new Error('No workspace ID found in current profile. Please login again with "adk login"');
|
|
2628
2472
|
}
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2473
|
+
this.client = new Client6({
|
|
2474
|
+
token: credentials.token,
|
|
2475
|
+
apiUrl: credentials.apiUrl,
|
|
2476
|
+
workspaceId: credentials.workspaceId,
|
|
2477
|
+
headers: {
|
|
2478
|
+
"x-multiple-integrations": "true"
|
|
2479
|
+
}
|
|
2480
|
+
});
|
|
2632
2481
|
}
|
|
2633
|
-
this.client
|
|
2634
|
-
token: credentials.token,
|
|
2635
|
-
apiUrl: credentials.apiUrl,
|
|
2636
|
-
workspaceId,
|
|
2637
|
-
headers: {
|
|
2638
|
-
"x-multiple-integrations": "true"
|
|
2639
|
-
}
|
|
2640
|
-
});
|
|
2482
|
+
return this.client;
|
|
2641
2483
|
}
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
const name = parts[0] || "";
|
|
2647
|
-
const version = parts[1] || "latest";
|
|
2648
|
-
if (!name) {
|
|
2649
|
-
throw new Error("Invalid integration reference: missing name");
|
|
2484
|
+
async ensureCacheDir() {
|
|
2485
|
+
try {
|
|
2486
|
+
await fs8.mkdir(HubCache.CACHE_DIR, { recursive: true });
|
|
2487
|
+
} catch {}
|
|
2650
2488
|
}
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
};
|
|
2489
|
+
async loadCache() {
|
|
2490
|
+
try {
|
|
2491
|
+
const data = await fs8.readFile(HubCache.CACHE_PATH, "utf-8");
|
|
2492
|
+
return JSON.parse(data);
|
|
2493
|
+
} catch {
|
|
2494
|
+
return null;
|
|
2495
|
+
}
|
|
2659
2496
|
}
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
return input.startsWith("intver_");
|
|
2664
|
-
}
|
|
2665
|
-
isIntegrationRefLike(input) {
|
|
2666
|
-
return input.includes("/") || input.includes("@");
|
|
2667
|
-
}
|
|
2668
|
-
isResourceNotFoundError(error) {
|
|
2669
|
-
return Boolean(error && typeof error === "object" && "type" in error && error.type === "ResourceNotFound");
|
|
2670
|
-
}
|
|
2671
|
-
getCanonicalIntegrationFullName(integration) {
|
|
2672
|
-
if (integration.public) {
|
|
2673
|
-
return integration.name;
|
|
2497
|
+
async saveCache(data) {
|
|
2498
|
+
await this.ensureCacheDir();
|
|
2499
|
+
await fs8.writeFile(HubCache.CACHE_PATH, JSON.stringify(data, null, 2));
|
|
2674
2500
|
}
|
|
2675
|
-
|
|
2501
|
+
async needsRefresh() {
|
|
2502
|
+
const cache2 = await this.loadCache();
|
|
2503
|
+
if (!cache2)
|
|
2504
|
+
return true;
|
|
2505
|
+
const lastUpdated = new Date(cache2.lastUpdated);
|
|
2506
|
+
const now = new Date;
|
|
2507
|
+
const diff = now.getTime() - lastUpdated.getTime();
|
|
2508
|
+
return diff > HubCache.CACHE_DURATION;
|
|
2509
|
+
}
|
|
2510
|
+
async refresh(force = false) {
|
|
2511
|
+
if (!force && !await this.needsRefresh()) {
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2514
|
+
const client = await this.getClient();
|
|
2515
|
+
const cache2 = await this.loadCache();
|
|
2516
|
+
const latestByName = new Map;
|
|
2517
|
+
if (cache2) {
|
|
2518
|
+
for (const entry of cache2.integrations) {
|
|
2519
|
+
latestByName.set(entry.name, entry);
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
try {
|
|
2523
|
+
for await (const integration of client.list.publicIntegrations({
|
|
2524
|
+
sortBy: "updatedAt",
|
|
2525
|
+
direction: "desc"
|
|
2526
|
+
})) {
|
|
2527
|
+
const existing = latestByName.get(integration.name);
|
|
2528
|
+
if (existing && integration.id === existing.id && integration.updatedAt === existing.updatedAt) {
|
|
2529
|
+
break;
|
|
2530
|
+
}
|
|
2531
|
+
if (!existing || integration.version.localeCompare(existing.version, undefined, {
|
|
2532
|
+
numeric: true
|
|
2533
|
+
}) > 0) {
|
|
2534
|
+
latestByName.set(integration.name, {
|
|
2535
|
+
id: integration.id,
|
|
2536
|
+
name: integration.name,
|
|
2537
|
+
version: integration.version,
|
|
2538
|
+
updatedAt: integration.updatedAt,
|
|
2539
|
+
createdAt: integration.createdAt,
|
|
2540
|
+
title: integration.title,
|
|
2541
|
+
description: integration.description,
|
|
2542
|
+
iconUrl: integration.iconUrl,
|
|
2543
|
+
public: integration.public,
|
|
2544
|
+
visibility: integration.visibility,
|
|
2545
|
+
ownerWorkspace: integration.ownerWorkspace ? {
|
|
2546
|
+
id: integration.ownerWorkspace.id,
|
|
2547
|
+
name: integration.ownerWorkspace.name
|
|
2548
|
+
} : undefined,
|
|
2549
|
+
verificationStatus: integration.verificationStatus
|
|
2550
|
+
});
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
const integrations = Array.from(latestByName.values()).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
2554
|
+
const newCache = {
|
|
2555
|
+
lastUpdated: new Date().toISOString(),
|
|
2556
|
+
integrations
|
|
2557
|
+
};
|
|
2558
|
+
await this.saveCache(newCache);
|
|
2559
|
+
} catch (error) {
|
|
2560
|
+
throw new Error(`Failed to refresh hub cache: ${error instanceof Error ? error.message : String(error)}`);
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
async getAllIntegrations() {
|
|
2564
|
+
await this.refresh();
|
|
2565
|
+
const cache2 = await this.loadCache();
|
|
2566
|
+
return cache2?.integrations || [];
|
|
2567
|
+
}
|
|
2568
|
+
async searchIntegrations(query) {
|
|
2569
|
+
const integrations = await this.getAllIntegrations();
|
|
2570
|
+
const lowerQuery = query.toLowerCase();
|
|
2571
|
+
return integrations.filter((integration) => integration.name.toLowerCase().includes(lowerQuery) || integration.title?.toLowerCase().includes(lowerQuery) || integration.description?.toLowerCase().includes(lowerQuery));
|
|
2572
|
+
}
|
|
2573
|
+
async getIntegrationByName(name) {
|
|
2574
|
+
const integrations = await this.getAllIntegrations();
|
|
2575
|
+
return integrations.find((i) => i.name === name) || null;
|
|
2576
|
+
}
|
|
2577
|
+
async getIntegrationVersions(name) {
|
|
2578
|
+
const integration = await this.getIntegrationByName(name);
|
|
2579
|
+
return integration ? [integration.version] : [];
|
|
2580
|
+
}
|
|
2581
|
+
async getStats() {
|
|
2582
|
+
const cache2 = await this.loadCache();
|
|
2583
|
+
try {
|
|
2584
|
+
const stats = await fs8.stat(HubCache.CACHE_PATH);
|
|
2585
|
+
return {
|
|
2586
|
+
lastUpdated: cache2 ? new Date(cache2.lastUpdated) : null,
|
|
2587
|
+
integrationCount: cache2?.integrations.length || 0,
|
|
2588
|
+
cacheSize: stats.size
|
|
2589
|
+
};
|
|
2590
|
+
} catch {
|
|
2591
|
+
return {
|
|
2592
|
+
lastUpdated: null,
|
|
2593
|
+
integrationCount: 0,
|
|
2594
|
+
cacheSize: 0
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
async clear() {
|
|
2599
|
+
try {
|
|
2600
|
+
await fs8.unlink(HubCache.CACHE_PATH);
|
|
2601
|
+
} catch {}
|
|
2602
|
+
}
|
|
2603
|
+
};
|
|
2604
|
+
});
|
|
2605
|
+
|
|
2606
|
+
// src/integrations/operations.ts
|
|
2607
|
+
import { Client as Client7 } from "@botpress/client";
|
|
2608
|
+
import * as process2 from "process";
|
|
2609
|
+
|
|
2610
|
+
class IntegrationOperations {
|
|
2611
|
+
hubCache;
|
|
2612
|
+
client;
|
|
2613
|
+
projectPath;
|
|
2614
|
+
loadAgentProject;
|
|
2615
|
+
createConfigWriter;
|
|
2616
|
+
constructor(options = {}) {
|
|
2617
|
+
this.hubCache = new HubCache;
|
|
2618
|
+
this.projectPath = options.projectPath;
|
|
2619
|
+
this.loadAgentProject = options.loadAgentProject ?? ((projectPath) => AgentProject.load(projectPath));
|
|
2620
|
+
this.createConfigWriter = options.createConfigWriter ?? ((projectPath) => new ConfigWriter(projectPath));
|
|
2621
|
+
}
|
|
2622
|
+
async getClient() {
|
|
2623
|
+
if (!this.client) {
|
|
2624
|
+
const credentials = await auth.getActiveCredentials();
|
|
2625
|
+
let workspaceId = credentials.workspaceId;
|
|
2626
|
+
try {
|
|
2627
|
+
if (this.projectPath) {
|
|
2628
|
+
const project = await this.loadAgentProject(this.projectPath);
|
|
2629
|
+
if (project.agentInfo?.workspaceId) {
|
|
2630
|
+
workspaceId = project.agentInfo.workspaceId;
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
} catch {}
|
|
2634
|
+
if (!workspaceId) {
|
|
2635
|
+
throw new Error('No workspace ID found in current profile. Please login again with "adk login"');
|
|
2636
|
+
}
|
|
2637
|
+
this.client = new Client7({
|
|
2638
|
+
token: credentials.token,
|
|
2639
|
+
apiUrl: credentials.apiUrl,
|
|
2640
|
+
workspaceId,
|
|
2641
|
+
headers: {
|
|
2642
|
+
"x-multiple-integrations": "true"
|
|
2643
|
+
}
|
|
2644
|
+
});
|
|
2645
|
+
}
|
|
2646
|
+
return this.client;
|
|
2647
|
+
}
|
|
2648
|
+
parseIntegrationRef(input) {
|
|
2649
|
+
const parts = input.split("@");
|
|
2650
|
+
const name = parts[0] || "";
|
|
2651
|
+
const version = parts[1] || "latest";
|
|
2652
|
+
if (!name) {
|
|
2653
|
+
throw new Error("Invalid integration reference: missing name");
|
|
2654
|
+
}
|
|
2655
|
+
const workspaceParts = name.split("/");
|
|
2656
|
+
if (workspaceParts.length === 2 && workspaceParts[0] && workspaceParts[1]) {
|
|
2657
|
+
return {
|
|
2658
|
+
fullName: name,
|
|
2659
|
+
workspace: workspaceParts[0],
|
|
2660
|
+
name: workspaceParts[1],
|
|
2661
|
+
version
|
|
2662
|
+
};
|
|
2663
|
+
}
|
|
2664
|
+
return { name, version, fullName: name };
|
|
2665
|
+
}
|
|
2666
|
+
isIntegrationVersionId(input) {
|
|
2667
|
+
return input.startsWith("intver_");
|
|
2668
|
+
}
|
|
2669
|
+
isIntegrationRefLike(input) {
|
|
2670
|
+
return input.includes("/") || input.includes("@");
|
|
2671
|
+
}
|
|
2672
|
+
isResourceNotFoundError(error) {
|
|
2673
|
+
return Boolean(error && typeof error === "object" && "type" in error && error.type === "ResourceNotFound");
|
|
2674
|
+
}
|
|
2675
|
+
getCanonicalIntegrationFullName(integration) {
|
|
2676
|
+
if (integration.public) {
|
|
2677
|
+
return integration.name;
|
|
2678
|
+
}
|
|
2679
|
+
const workspaceHandle = integration.ownerWorkspace?.handle;
|
|
2676
2680
|
return workspaceHandle ? `${workspaceHandle}/${integration.name}` : integration.name;
|
|
2677
2681
|
}
|
|
2678
2682
|
getInstalledIntegrationEntries(integrations = {}) {
|
|
@@ -2811,7 +2815,7 @@ class IntegrationOperations {
|
|
|
2811
2815
|
}
|
|
2812
2816
|
}
|
|
2813
2817
|
async addIntegration(options) {
|
|
2814
|
-
const project = await
|
|
2818
|
+
const project = await this.loadAgentProject(this.projectPath || process2.cwd());
|
|
2815
2819
|
const resolvedInput = await this.resolveAddIntegrationInput(options);
|
|
2816
2820
|
const { alias } = resolvedInput;
|
|
2817
2821
|
const dependencies = project.dependencies || { integrations: {} };
|
|
@@ -2880,7 +2884,7 @@ class IntegrationOperations {
|
|
|
2880
2884
|
} else {
|
|
2881
2885
|
dependencies.integrations[alias] = integrationVersion;
|
|
2882
2886
|
}
|
|
2883
|
-
const configWriter =
|
|
2887
|
+
const configWriter = this.createConfigWriter(project.path);
|
|
2884
2888
|
await configWriter.updateDependencies(dependencies);
|
|
2885
2889
|
return {
|
|
2886
2890
|
success: true,
|
|
@@ -2893,18 +2897,18 @@ class IntegrationOperations {
|
|
|
2893
2897
|
};
|
|
2894
2898
|
}
|
|
2895
2899
|
async removeIntegration(name) {
|
|
2896
|
-
const project = await
|
|
2900
|
+
const project = await this.loadAgentProject(this.projectPath || process2.cwd());
|
|
2897
2901
|
const dependencies = project.dependencies;
|
|
2898
2902
|
if (!dependencies || !dependencies.integrations) {
|
|
2899
2903
|
throw this.buildRemoveIntegrationNotFoundError(name);
|
|
2900
2904
|
}
|
|
2901
2905
|
const alias = this.resolveIntegrationRemovalAlias(name, dependencies.integrations);
|
|
2902
2906
|
delete dependencies.integrations[alias];
|
|
2903
|
-
const configWriter =
|
|
2907
|
+
const configWriter = this.createConfigWriter(project.path);
|
|
2904
2908
|
await configWriter.updateDependencies(dependencies);
|
|
2905
2909
|
}
|
|
2906
2910
|
async upgradeIntegration(name) {
|
|
2907
|
-
const project = await
|
|
2911
|
+
const project = await this.loadAgentProject(this.projectPath || process2.cwd());
|
|
2908
2912
|
const dependencies = project.dependencies;
|
|
2909
2913
|
if (!dependencies || !dependencies.integrations) {
|
|
2910
2914
|
throw new Error("No integrations found in dependencies");
|
|
@@ -2940,13 +2944,13 @@ class IntegrationOperations {
|
|
|
2940
2944
|
}
|
|
2941
2945
|
}
|
|
2942
2946
|
if (upgraded.length > 0) {
|
|
2943
|
-
const configWriter =
|
|
2947
|
+
const configWriter = this.createConfigWriter(project.path);
|
|
2944
2948
|
await configWriter.updateDependencies(dependencies);
|
|
2945
2949
|
}
|
|
2946
2950
|
return { upgraded, failed };
|
|
2947
2951
|
}
|
|
2948
2952
|
async listIntegrations() {
|
|
2949
|
-
const project = await
|
|
2953
|
+
const project = await this.loadAgentProject(this.projectPath || process2.cwd());
|
|
2950
2954
|
const dependencies = project.dependencies;
|
|
2951
2955
|
if (!dependencies || !dependencies.integrations) {
|
|
2952
2956
|
return [];
|
|
@@ -2996,9 +3000,9 @@ class IntegrationOperations {
|
|
|
2996
3000
|
var init_operations = __esm(() => {
|
|
2997
3001
|
init_auth();
|
|
2998
3002
|
init_agent_project();
|
|
3003
|
+
init_config_writer();
|
|
2999
3004
|
init_manager2();
|
|
3000
3005
|
init_hub_cache();
|
|
3001
|
-
init_config_writer();
|
|
3002
3006
|
});
|
|
3003
3007
|
|
|
3004
3008
|
// src/integrations/config-utils.ts
|
|
@@ -3840,13 +3844,116 @@ var init_expand_exports = __esm(() => {
|
|
|
3840
3844
|
init_types();
|
|
3841
3845
|
});
|
|
3842
3846
|
|
|
3847
|
+
// src/agent-project/component-source-resolver.ts
|
|
3848
|
+
import { Project as Project2, SyntaxKind as SyntaxKind2 } from "ts-morph";
|
|
3849
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
3850
|
+
import * as path13 from "path";
|
|
3851
|
+
function resolveComponentSources(absolutePath) {
|
|
3852
|
+
const project = new Project2({ useInMemoryFileSystem: false, skipAddingFilesFromTsConfig: true });
|
|
3853
|
+
const sourceFile = project.createSourceFile(absolutePath, readFileSync3(absolutePath, "utf-8"), { overwrite: true });
|
|
3854
|
+
const importBindings = collectBpTsxImports(sourceFile, absolutePath);
|
|
3855
|
+
if (importBindings.size === 0) {
|
|
3856
|
+
return new Map;
|
|
3857
|
+
}
|
|
3858
|
+
const localToSource = resolveLocalBindings(sourceFile, importBindings);
|
|
3859
|
+
return resolveExports(sourceFile, localToSource, importBindings);
|
|
3860
|
+
}
|
|
3861
|
+
function collectBpTsxImports(sourceFile, absolutePath) {
|
|
3862
|
+
const imports = new Map;
|
|
3863
|
+
const dir = path13.dirname(absolutePath);
|
|
3864
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3865
|
+
const specifier = decl.getModuleSpecifierValue();
|
|
3866
|
+
if (!specifier.endsWith(BP_TSX_SUFFIX))
|
|
3867
|
+
continue;
|
|
3868
|
+
const resolved = path13.resolve(dir, specifier);
|
|
3869
|
+
const defaultImport = decl.getDefaultImport();
|
|
3870
|
+
if (defaultImport) {
|
|
3871
|
+
imports.set(defaultImport.getText(), resolved);
|
|
3872
|
+
}
|
|
3873
|
+
const namespaceImport = decl.getNamespaceImport();
|
|
3874
|
+
if (namespaceImport) {
|
|
3875
|
+
imports.set(namespaceImport.getText(), resolved);
|
|
3876
|
+
}
|
|
3877
|
+
}
|
|
3878
|
+
return imports;
|
|
3879
|
+
}
|
|
3880
|
+
function resolveLocalBindings(sourceFile, importBindings) {
|
|
3881
|
+
const result = new Map;
|
|
3882
|
+
for (const stmt of sourceFile.getVariableStatements()) {
|
|
3883
|
+
for (const decl of stmt.getDeclarations()) {
|
|
3884
|
+
const initializer = decl.getInitializer();
|
|
3885
|
+
if (!initializer)
|
|
3886
|
+
continue;
|
|
3887
|
+
const source = sourceFromCustomComponentExpr(initializer, importBindings);
|
|
3888
|
+
if (source) {
|
|
3889
|
+
result.set(decl.getName(), source);
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
}
|
|
3893
|
+
return result;
|
|
3894
|
+
}
|
|
3895
|
+
function resolveExports(sourceFile, localToSource, importBindings) {
|
|
3896
|
+
const exportMap = new Map;
|
|
3897
|
+
for (const stmt of sourceFile.getVariableStatements()) {
|
|
3898
|
+
if (!stmt.isExported())
|
|
3899
|
+
continue;
|
|
3900
|
+
for (const decl of stmt.getDeclarations()) {
|
|
3901
|
+
const source = localToSource.get(decl.getName());
|
|
3902
|
+
if (source)
|
|
3903
|
+
exportMap.set(decl.getName(), source);
|
|
3904
|
+
}
|
|
3905
|
+
}
|
|
3906
|
+
for (const assignment of sourceFile.getExportAssignments()) {
|
|
3907
|
+
if (assignment.isExportEquals())
|
|
3908
|
+
continue;
|
|
3909
|
+
const expr = assignment.getExpression();
|
|
3910
|
+
const direct = sourceFromCustomComponentExpr(expr, importBindings);
|
|
3911
|
+
if (direct) {
|
|
3912
|
+
exportMap.set("default", direct);
|
|
3913
|
+
continue;
|
|
3914
|
+
}
|
|
3915
|
+
if (expr.getKind() === SyntaxKind2.Identifier) {
|
|
3916
|
+
const fromLocal = localToSource.get(expr.getText());
|
|
3917
|
+
if (fromLocal)
|
|
3918
|
+
exportMap.set("default", fromLocal);
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
for (const decl of sourceFile.getExportDeclarations()) {
|
|
3922
|
+
if (decl.getModuleSpecifier())
|
|
3923
|
+
continue;
|
|
3924
|
+
for (const named of decl.getNamedExports()) {
|
|
3925
|
+
const localName = named.getNameNode().getText();
|
|
3926
|
+
const aliasNode = named.getAliasNode();
|
|
3927
|
+
const exportName = aliasNode ? aliasNode.getText() : localName;
|
|
3928
|
+
const source = localToSource.get(localName);
|
|
3929
|
+
if (source)
|
|
3930
|
+
exportMap.set(exportName, source);
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
return exportMap;
|
|
3934
|
+
}
|
|
3935
|
+
function sourceFromCustomComponentExpr(expr, importBindings) {
|
|
3936
|
+
if (expr.getKind() !== SyntaxKind2.NewExpression)
|
|
3937
|
+
return;
|
|
3938
|
+
const newExpr = expr.asKindOrThrow(SyntaxKind2.NewExpression);
|
|
3939
|
+
if (newExpr.getExpression().getText() !== CUSTOM_COMPONENT_CLASS)
|
|
3940
|
+
return;
|
|
3941
|
+
const args = newExpr.getArguments();
|
|
3942
|
+
const firstArg = args[0];
|
|
3943
|
+
if (!firstArg || firstArg.getKind() !== SyntaxKind2.Identifier)
|
|
3944
|
+
return;
|
|
3945
|
+
return importBindings.get(firstArg.getText());
|
|
3946
|
+
}
|
|
3947
|
+
var CUSTOM_COMPONENT_CLASS = "CustomComponent", BP_TSX_SUFFIX = ".bp.tsx";
|
|
3948
|
+
var init_component_source_resolver = () => {};
|
|
3949
|
+
|
|
3843
3950
|
// src/agent-project/agent-project.ts
|
|
3844
3951
|
import { BuiltInActions, BuiltInWorkflows, Errors as Errors2, Primitives as Primitives2, setAdkCommand } from "@botpress/runtime/internal";
|
|
3845
3952
|
import { Autonomous } from "@botpress/runtime";
|
|
3846
3953
|
import createDebug2 from "debug";
|
|
3847
3954
|
import { createRequire as createRequire4 } from "module";
|
|
3848
3955
|
import fs10 from "fs/promises";
|
|
3849
|
-
import
|
|
3956
|
+
import path14 from "path";
|
|
3850
3957
|
function getToolDefinition(value) {
|
|
3851
3958
|
if (typeof value !== "object" || value === null) {
|
|
3852
3959
|
return;
|
|
@@ -3869,6 +3976,7 @@ var init_agent_project = __esm(() => {
|
|
|
3869
3976
|
init_interfaces();
|
|
3870
3977
|
init_json_ordering();
|
|
3871
3978
|
init_expand_exports();
|
|
3979
|
+
init_component_source_resolver();
|
|
3872
3980
|
init_agent_resolver();
|
|
3873
3981
|
init_types();
|
|
3874
3982
|
init_validation_errors();
|
|
@@ -3899,7 +4007,7 @@ var init_agent_project = __esm(() => {
|
|
|
3899
4007
|
_tools = [];
|
|
3900
4008
|
constructor(projectPath, options = {}) {
|
|
3901
4009
|
this._options = options;
|
|
3902
|
-
this._path =
|
|
4010
|
+
this._path = path14.resolve(projectPath);
|
|
3903
4011
|
this._integrationManager = new IntegrationManager({
|
|
3904
4012
|
noCache: options.noCache
|
|
3905
4013
|
});
|
|
@@ -3911,7 +4019,7 @@ var init_agent_project = __esm(() => {
|
|
|
3911
4019
|
});
|
|
3912
4020
|
}
|
|
3913
4021
|
static async load(projectPath, options = {}) {
|
|
3914
|
-
const resolvedPath =
|
|
4022
|
+
const resolvedPath = path14.resolve(projectPath);
|
|
3915
4023
|
if (!options.noCache) {
|
|
3916
4024
|
const cached = AgentProject._projectCache.get(resolvedPath);
|
|
3917
4025
|
if (cached) {
|
|
@@ -3929,7 +4037,7 @@ var init_agent_project = __esm(() => {
|
|
|
3929
4037
|
AgentProject._projectCache.clear();
|
|
3930
4038
|
}
|
|
3931
4039
|
static clearCacheForPath(projectPath) {
|
|
3932
|
-
const resolvedPath =
|
|
4040
|
+
const resolvedPath = path14.resolve(projectPath);
|
|
3933
4041
|
AgentProject._projectCache.delete(resolvedPath);
|
|
3934
4042
|
}
|
|
3935
4043
|
get path() {
|
|
@@ -4045,13 +4153,13 @@ var init_agent_project = __esm(() => {
|
|
|
4045
4153
|
const requiredFiles = ["agent.config.ts"];
|
|
4046
4154
|
for (const file of requiredFiles) {
|
|
4047
4155
|
try {
|
|
4048
|
-
await fs10.access(
|
|
4156
|
+
await fs10.access(path14.join(this._path, file));
|
|
4049
4157
|
} catch {
|
|
4050
4158
|
errors.push(ValidationErrors.requiredFileMissing(file));
|
|
4051
4159
|
}
|
|
4052
4160
|
}
|
|
4053
4161
|
try {
|
|
4054
|
-
await fs10.access(
|
|
4162
|
+
await fs10.access(path14.join(this._path, "agent.json"));
|
|
4055
4163
|
} catch {
|
|
4056
4164
|
info.push({
|
|
4057
4165
|
$type: "ValidationError",
|
|
@@ -4065,7 +4173,7 @@ var init_agent_project = __esm(() => {
|
|
|
4065
4173
|
const expectedDirs = ["actions", "workflows", "conversations", "assets"];
|
|
4066
4174
|
for (const dir of expectedDirs) {
|
|
4067
4175
|
try {
|
|
4068
|
-
const stats = await fs10.stat(
|
|
4176
|
+
const stats = await fs10.stat(path14.join(this._path, dir));
|
|
4069
4177
|
if (!stats.isDirectory()) {
|
|
4070
4178
|
warnings.push(ValidationErrors.invalidStructure(dir, "directory"));
|
|
4071
4179
|
}
|
|
@@ -4138,7 +4246,7 @@ var init_agent_project = __esm(() => {
|
|
|
4138
4246
|
}
|
|
4139
4247
|
async createAgentInfo(info) {
|
|
4140
4248
|
const { devId, ...agentJsonInfo } = info;
|
|
4141
|
-
const agentPath =
|
|
4249
|
+
const agentPath = path14.join(this._path, "agent.json");
|
|
4142
4250
|
const agentContent = stringifyWithOrder(agentJsonInfo, agentInfoKeyOrder);
|
|
4143
4251
|
await fs10.writeFile(agentPath, agentContent);
|
|
4144
4252
|
this._agentInfo = info;
|
|
@@ -4153,7 +4261,7 @@ var init_agent_project = __esm(() => {
|
|
|
4153
4261
|
const { devId, ...agentJsonUpdates } = updates;
|
|
4154
4262
|
const updatedInfo = { ...this._agentInfo, ...agentJsonUpdates };
|
|
4155
4263
|
const { devId: _devId, ...agentJsonData } = updatedInfo;
|
|
4156
|
-
const agentPath =
|
|
4264
|
+
const agentPath = path14.join(this._path, "agent.json");
|
|
4157
4265
|
const agentContent = stringifyWithOrder(agentJsonData, agentInfoKeyOrder);
|
|
4158
4266
|
await fs10.writeFile(agentPath, agentContent);
|
|
4159
4267
|
this._agentInfo = updatedInfo;
|
|
@@ -4162,7 +4270,7 @@ var init_agent_project = __esm(() => {
|
|
|
4162
4270
|
}
|
|
4163
4271
|
}
|
|
4164
4272
|
async createAgentLocalInfo(info) {
|
|
4165
|
-
const localPath =
|
|
4273
|
+
const localPath = path14.join(this._path, "agent.local.json");
|
|
4166
4274
|
let existing = {};
|
|
4167
4275
|
try {
|
|
4168
4276
|
const content2 = await fs10.readFile(localPath, "utf-8");
|
|
@@ -4190,7 +4298,7 @@ var init_agent_project = __esm(() => {
|
|
|
4190
4298
|
}
|
|
4191
4299
|
}
|
|
4192
4300
|
async updateAgentLocalInfo(updates) {
|
|
4193
|
-
const localPath =
|
|
4301
|
+
const localPath = path14.join(this._path, "agent.local.json");
|
|
4194
4302
|
let existing = {};
|
|
4195
4303
|
try {
|
|
4196
4304
|
const content2 = await fs10.readFile(localPath, "utf-8");
|
|
@@ -4223,10 +4331,10 @@ var init_agent_project = __esm(() => {
|
|
|
4223
4331
|
}
|
|
4224
4332
|
async loadConfig() {
|
|
4225
4333
|
try {
|
|
4226
|
-
const configPath =
|
|
4334
|
+
const configPath = path14.join(this._path, "agent.config.ts");
|
|
4227
4335
|
debug2("loading agent.config.ts from %s", configPath);
|
|
4228
|
-
const projectRequire = createRequire4(
|
|
4229
|
-
debug2("created projectRequire from %s",
|
|
4336
|
+
const projectRequire = createRequire4(path14.join(this._path, "package.json"));
|
|
4337
|
+
debug2("created projectRequire from %s", path14.join(this._path, "package.json"));
|
|
4230
4338
|
try {
|
|
4231
4339
|
const resolvedPath = projectRequire.resolve(configPath);
|
|
4232
4340
|
debug2("resolved config path: %s", resolvedPath);
|
|
@@ -4409,8 +4517,8 @@ ${err.stack?.split(`
|
|
|
4409
4517
|
}
|
|
4410
4518
|
}
|
|
4411
4519
|
isBarrelReexport(existing, newPath, newExport, newDefinition) {
|
|
4412
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4413
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4520
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path14.basename(newPath));
|
|
4521
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path14.basename(existing.path));
|
|
4414
4522
|
if (!isNewBarrel && !isExistingBarrel) {
|
|
4415
4523
|
return false;
|
|
4416
4524
|
}
|
|
@@ -4422,16 +4530,16 @@ ${err.stack?.split(`
|
|
|
4422
4530
|
return true;
|
|
4423
4531
|
}
|
|
4424
4532
|
isToolBarrelReexport(existingPath, newPath) {
|
|
4425
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4426
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4533
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path14.basename(newPath));
|
|
4534
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path14.basename(existingPath));
|
|
4427
4535
|
if (!isNewBarrel && !isExistingBarrel) {
|
|
4428
4536
|
return false;
|
|
4429
4537
|
}
|
|
4430
4538
|
return true;
|
|
4431
4539
|
}
|
|
4432
4540
|
shouldPreferToolDefinition(existingPath, newPath) {
|
|
4433
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4434
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4541
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path14.basename(newPath));
|
|
4542
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path14.basename(existingPath));
|
|
4435
4543
|
return isExistingBarrel && !isNewBarrel;
|
|
4436
4544
|
}
|
|
4437
4545
|
getChannelsList(channelSpec) {
|
|
@@ -4447,7 +4555,7 @@ ${err.stack?.split(`
|
|
|
4447
4555
|
if (this._options.adkCommand) {
|
|
4448
4556
|
setAdkCommand(this._options.adkCommand);
|
|
4449
4557
|
}
|
|
4450
|
-
const src =
|
|
4558
|
+
const src = path14.join(this._path, "src");
|
|
4451
4559
|
if (!await fs10.stat(src).catch(() => false)) {
|
|
4452
4560
|
this._errors.push({
|
|
4453
4561
|
$type: "ValidationError",
|
|
@@ -4463,8 +4571,8 @@ ${err.stack?.split(`
|
|
|
4463
4571
|
});
|
|
4464
4572
|
for (const file of allFiles.filter((x) => x.isFile())) {
|
|
4465
4573
|
const filename = file.name;
|
|
4466
|
-
const absolutePath =
|
|
4467
|
-
const relPath =
|
|
4574
|
+
const absolutePath = path14.join(file.parentPath, file.name);
|
|
4575
|
+
const relPath = path14.relative(this.path, absolutePath);
|
|
4468
4576
|
if (filename.toLowerCase().endsWith(".d.ts")) {
|
|
4469
4577
|
continue;
|
|
4470
4578
|
}
|
|
@@ -4491,6 +4599,7 @@ ${err.stack?.split(`
|
|
|
4491
4599
|
filename,
|
|
4492
4600
|
onWarning: (warning) => this._warnings.push(warning)
|
|
4493
4601
|
});
|
|
4602
|
+
let componentSources;
|
|
4494
4603
|
for (const key of Object.keys(expandedExports)) {
|
|
4495
4604
|
let definition;
|
|
4496
4605
|
try {
|
|
@@ -4615,9 +4724,27 @@ ${err.stack?.split(`
|
|
|
4615
4724
|
path: relPath
|
|
4616
4725
|
});
|
|
4617
4726
|
} else if (Primitives2.Definitions.isCustomComponentDefinition(definition)) {
|
|
4727
|
+
if (componentSources === undefined) {
|
|
4728
|
+
try {
|
|
4729
|
+
componentSources = resolveComponentSources(absolutePath);
|
|
4730
|
+
} catch (error) {
|
|
4731
|
+
componentSources = new Map;
|
|
4732
|
+
this._warnings.push({
|
|
4733
|
+
$type: "ValidationError",
|
|
4734
|
+
code: "INVALID_PRIMITIVE_DEFINITION" /* INVALID_PRIMITIVE_DEFINITION */,
|
|
4735
|
+
severity: "warning" /* WARNING */,
|
|
4736
|
+
message: `Failed to parse component sources from ${relPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
4737
|
+
file: relPath
|
|
4738
|
+
});
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
const source = componentSources.get(key);
|
|
4618
4742
|
const existing = this._customComponents.find((p) => p.definition.name === definition.name);
|
|
4619
4743
|
if (existing) {
|
|
4620
4744
|
if (this.isBarrelReexport(existing, relPath, key, definition)) {
|
|
4745
|
+
if (existing.path === relPath && source) {
|
|
4746
|
+
existing.source = source;
|
|
4747
|
+
}
|
|
4621
4748
|
continue;
|
|
4622
4749
|
}
|
|
4623
4750
|
this._warnings.push({
|
|
@@ -4632,7 +4759,8 @@ ${err.stack?.split(`
|
|
|
4632
4759
|
this._customComponents.push({
|
|
4633
4760
|
definition,
|
|
4634
4761
|
export: key,
|
|
4635
|
-
path: relPath
|
|
4762
|
+
path: relPath,
|
|
4763
|
+
source: source ?? ""
|
|
4636
4764
|
});
|
|
4637
4765
|
} else if (Primitives2.Definitions.isTableDefinition(definition)) {
|
|
4638
4766
|
const existing = this._tables.find((p) => p.definition.name === definition.name);
|
|
@@ -4699,6 +4827,20 @@ ${err.stack?.split(`
|
|
|
4699
4827
|
});
|
|
4700
4828
|
}
|
|
4701
4829
|
}
|
|
4830
|
+
const unresolved = this._customComponents.filter((c) => !c.source);
|
|
4831
|
+
if (unresolved.length > 0) {
|
|
4832
|
+
this._customComponents = this._customComponents.filter((c) => c.source);
|
|
4833
|
+
for (const comp of unresolved) {
|
|
4834
|
+
this._errors.push({
|
|
4835
|
+
$type: "ValidationError",
|
|
4836
|
+
code: "INVALID_PRIMITIVE_DEFINITION" /* INVALID_PRIMITIVE_DEFINITION */,
|
|
4837
|
+
severity: "error" /* ERROR */,
|
|
4838
|
+
message: `Cannot resolve .bp.tsx source for custom component "${comp.definition.name}" exported from ${comp.path} as "${comp.export}".`,
|
|
4839
|
+
file: comp.path,
|
|
4840
|
+
hint: "Each CustomComponent must be constructed from a default-imported .bp.tsx component, e.g. `import Foo from './Foo.bp.tsx'; export const FooComponent = new CustomComponent(Foo, ...)`."
|
|
4841
|
+
});
|
|
4842
|
+
}
|
|
4843
|
+
}
|
|
4702
4844
|
}
|
|
4703
4845
|
};
|
|
4704
4846
|
});
|
|
@@ -4708,7 +4850,7 @@ var exports_action_types = {};
|
|
|
4708
4850
|
__export(exports_action_types, {
|
|
4709
4851
|
generateActionTypes: () => generateActionTypes
|
|
4710
4852
|
});
|
|
4711
|
-
import
|
|
4853
|
+
import path40 from "path";
|
|
4712
4854
|
async function generateActionTypes(project) {
|
|
4713
4855
|
const actionDefs = [];
|
|
4714
4856
|
for (const action of project.actions) {
|
|
@@ -4723,7 +4865,7 @@ async function generateActionTypes(project) {
|
|
|
4723
4865
|
};`);
|
|
4724
4866
|
continue;
|
|
4725
4867
|
}
|
|
4726
|
-
const absolutePath =
|
|
4868
|
+
const absolutePath = path40.join(project.path, action.path);
|
|
4727
4869
|
const actionModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
4728
4870
|
const actionInstance = actionModule[action.export] || actionModule.default;
|
|
4729
4871
|
if (actionInstance && actionInstance.input && actionInstance.output) {
|
|
@@ -4768,7 +4910,7 @@ ${actionDefs.join(`
|
|
|
4768
4910
|
};
|
|
4769
4911
|
}
|
|
4770
4912
|
`;
|
|
4771
|
-
const actionTypesPath =
|
|
4913
|
+
const actionTypesPath = path40.join(project.path, ".adk", "action-types.d.ts");
|
|
4772
4914
|
await createFile(actionTypesPath, await formatCode(content));
|
|
4773
4915
|
}
|
|
4774
4916
|
var init_action_types = __esm(() => {
|
|
@@ -4781,7 +4923,7 @@ var exports_integration_action_types = {};
|
|
|
4781
4923
|
__export(exports_integration_action_types, {
|
|
4782
4924
|
generateIntegrationActionTypes: () => generateIntegrationActionTypes
|
|
4783
4925
|
});
|
|
4784
|
-
import
|
|
4926
|
+
import path41 from "path";
|
|
4785
4927
|
async function generateIntegrationActionTypes(project) {
|
|
4786
4928
|
const content = `
|
|
4787
4929
|
////////////////////////////////////////////////////////
|
|
@@ -4815,7 +4957,7 @@ type IntegrationsMap<T> = {
|
|
|
4815
4957
|
export type IntegrationActions = IntegrationsMap<Integrations>;
|
|
4816
4958
|
}
|
|
4817
4959
|
`;
|
|
4818
|
-
const integrationActionTypesPath =
|
|
4960
|
+
const integrationActionTypesPath = path41.join(project.path, ".adk", "integration-action-types.d.ts");
|
|
4819
4961
|
await createFile(integrationActionTypesPath, await formatCode(content));
|
|
4820
4962
|
}
|
|
4821
4963
|
var init_integration_action_types = __esm(() => {
|
|
@@ -4827,7 +4969,7 @@ var init_integration_action_types = __esm(() => {
|
|
|
4827
4969
|
var require_package = __commonJS((exports, module) => {
|
|
4828
4970
|
module.exports = {
|
|
4829
4971
|
name: "@botpress/adk",
|
|
4830
|
-
version: "1.18.0-beta.
|
|
4972
|
+
version: "1.18.0-beta.6",
|
|
4831
4973
|
description: "Core ADK library for building AI agents on Botpress",
|
|
4832
4974
|
keywords: [
|
|
4833
4975
|
"adk",
|
|
@@ -4876,7 +5018,7 @@ var require_package = __commonJS((exports, module) => {
|
|
|
4876
5018
|
"@botpress/cli": "~6.3.2",
|
|
4877
5019
|
"@botpress/client": "~1.39.0",
|
|
4878
5020
|
"@botpress/cognitive": "~0.5.2",
|
|
4879
|
-
"@botpress/runtime": "^1.18.0-beta.
|
|
5021
|
+
"@botpress/runtime": "^1.18.0-beta.6",
|
|
4880
5022
|
"@botpress/sdk": "~6.4.4",
|
|
4881
5023
|
"@bpinternal/jex": "^1.2.4",
|
|
4882
5024
|
"@bpinternal/yargs-extra": "^0.0.21",
|
|
@@ -4896,10 +5038,10 @@ var require_package = __commonJS((exports, module) => {
|
|
|
4896
5038
|
typescript: ">=4.5.0"
|
|
4897
5039
|
},
|
|
4898
5040
|
engines: {
|
|
4899
|
-
bun: ">=1.3.
|
|
5041
|
+
bun: ">=1.3.13",
|
|
4900
5042
|
node: ">=22.0.0"
|
|
4901
5043
|
},
|
|
4902
|
-
packageManager: "bun@1.3.
|
|
5044
|
+
packageManager: "bun@1.3.13"
|
|
4903
5045
|
};
|
|
4904
5046
|
});
|
|
4905
5047
|
|
|
@@ -4943,7 +5085,7 @@ import os3 from "os";
|
|
|
4943
5085
|
import path4 from "path";
|
|
4944
5086
|
import createDebug from "debug";
|
|
4945
5087
|
var debug = createDebug("adk:bp-cli");
|
|
4946
|
-
var BP_CLI_VERSION = "6.3.
|
|
5088
|
+
var BP_CLI_VERSION = "6.3.5";
|
|
4947
5089
|
var BP_CLI_INSTALL_ALL = path4.join(os3.homedir(), ".adk", `bp-cli`);
|
|
4948
5090
|
var BP_CLI_INSTALL_DIR = path4.join(BP_CLI_INSTALL_ALL, BP_CLI_VERSION);
|
|
4949
5091
|
var BP_CLI_BIN_PATH = path4.join(BP_CLI_INSTALL_DIR, "node_modules", "@botpress", "cli", "bin.js");
|
|
@@ -5843,7 +5985,7 @@ function buildOpenCodeConfig(options) {
|
|
|
5843
5985
|
}
|
|
5844
5986
|
|
|
5845
5987
|
// src/commands/copilot-server.ts
|
|
5846
|
-
var OPENCODE_VERSION = "
|
|
5988
|
+
var OPENCODE_VERSION = "1.3.13";
|
|
5847
5989
|
async function findFreePort() {
|
|
5848
5990
|
return new Promise((resolve3, reject) => {
|
|
5849
5991
|
const server = createServer();
|
|
@@ -6044,7 +6186,7 @@ function fileHasProvider(configPath) {
|
|
|
6044
6186
|
return false;
|
|
6045
6187
|
}
|
|
6046
6188
|
function checkHasProvider(agentPath) {
|
|
6047
|
-
const projectConfig = join4(agentPath, "opencode.json");
|
|
6189
|
+
const projectConfig = join4(agentPath, ".adk", "opencode.json");
|
|
6048
6190
|
if (fileHasProvider(projectConfig))
|
|
6049
6191
|
return true;
|
|
6050
6192
|
const globalConfig = getGlobalConfigPath();
|
|
@@ -6140,7 +6282,7 @@ init_agent_project();
|
|
|
6140
6282
|
init_types();
|
|
6141
6283
|
import { watch } from "fs";
|
|
6142
6284
|
import { EventEmitter as EventEmitter2 } from "events";
|
|
6143
|
-
import
|
|
6285
|
+
import path15 from "path";
|
|
6144
6286
|
|
|
6145
6287
|
class FileWatcher extends EventEmitter2 {
|
|
6146
6288
|
basePath;
|
|
@@ -6164,7 +6306,7 @@ class FileWatcher extends EventEmitter2 {
|
|
|
6164
6306
|
this.watcher = watch(this.basePath, { recursive: true }, (eventType, filename) => {
|
|
6165
6307
|
if (!filename)
|
|
6166
6308
|
return;
|
|
6167
|
-
const fullPath =
|
|
6309
|
+
const fullPath = path15.join(this.basePath, filename);
|
|
6168
6310
|
const relativePath = filename;
|
|
6169
6311
|
if (this.shouldIgnore(relativePath)) {
|
|
6170
6312
|
return;
|
|
@@ -6401,12 +6543,12 @@ class ConfigManager {
|
|
|
6401
6543
|
}
|
|
6402
6544
|
// src/secrets/manager.ts
|
|
6403
6545
|
import fs11 from "fs/promises";
|
|
6404
|
-
import
|
|
6546
|
+
import path16 from "path";
|
|
6405
6547
|
|
|
6406
6548
|
class SecretsManager {
|
|
6407
6549
|
storePath;
|
|
6408
6550
|
constructor(projectPath) {
|
|
6409
|
-
this.storePath =
|
|
6551
|
+
this.storePath = path16.join(projectPath, ".adk", "secrets.json");
|
|
6410
6552
|
}
|
|
6411
6553
|
async readStore() {
|
|
6412
6554
|
try {
|
|
@@ -6417,7 +6559,7 @@ class SecretsManager {
|
|
|
6417
6559
|
}
|
|
6418
6560
|
}
|
|
6419
6561
|
async writeStore(store) {
|
|
6420
|
-
await fs11.mkdir(
|
|
6562
|
+
await fs11.mkdir(path16.dirname(this.storePath), { recursive: true });
|
|
6421
6563
|
const tmpPath = `${this.storePath}.tmp`;
|
|
6422
6564
|
await fs11.writeFile(tmpPath, JSON.stringify(store, null, 2) + `
|
|
6423
6565
|
`, { encoding: "utf-8", mode: 384 });
|
|
@@ -6464,7 +6606,7 @@ import { validateSecretName } from "@botpress/runtime/definition";
|
|
|
6464
6606
|
// src/agent-init/agent-project-generator.ts
|
|
6465
6607
|
init_utils();
|
|
6466
6608
|
import * as fs12 from "fs";
|
|
6467
|
-
import * as
|
|
6609
|
+
import * as path17 from "path";
|
|
6468
6610
|
import { fileURLToPath } from "url";
|
|
6469
6611
|
import { createRequire as createRequire5 } from "module";
|
|
6470
6612
|
|
|
@@ -6564,7 +6706,7 @@ var TEXT_EXTENSIONS = new Set([
|
|
|
6564
6706
|
function isTextFile(filename) {
|
|
6565
6707
|
if (filename === ".gitignore")
|
|
6566
6708
|
return true;
|
|
6567
|
-
const ext =
|
|
6709
|
+
const ext = path17.extname(filename).toLowerCase();
|
|
6568
6710
|
return TEXT_EXTENSIONS.has(ext);
|
|
6569
6711
|
}
|
|
6570
6712
|
|
|
@@ -6574,8 +6716,8 @@ class AgentProjectGenerator {
|
|
|
6574
6716
|
packageManager;
|
|
6575
6717
|
template;
|
|
6576
6718
|
constructor(projectPath, packageManager = "bun", template = "blank") {
|
|
6577
|
-
this.projectPath =
|
|
6578
|
-
this.projectName =
|
|
6719
|
+
this.projectPath = path17.resolve(projectPath);
|
|
6720
|
+
this.projectName = path17.basename(this.projectPath);
|
|
6579
6721
|
this.packageManager = packageManager;
|
|
6580
6722
|
this.template = template;
|
|
6581
6723
|
}
|
|
@@ -6583,20 +6725,20 @@ class AgentProjectGenerator {
|
|
|
6583
6725
|
this.ensureEmptyDirectory();
|
|
6584
6726
|
const templateDir = this.resolveTemplateDir();
|
|
6585
6727
|
await this.copyTemplateFiles(templateDir);
|
|
6586
|
-
if (!fs12.existsSync(
|
|
6728
|
+
if (!fs12.existsSync(path17.join(this.projectPath, "agent.json"))) {
|
|
6587
6729
|
this.createAgentJson();
|
|
6588
6730
|
}
|
|
6589
|
-
if (!fs12.existsSync(
|
|
6731
|
+
if (!fs12.existsSync(path17.join(this.projectPath, "CLAUDE.md"))) {
|
|
6590
6732
|
this.createAIAssistantInstructions();
|
|
6591
6733
|
}
|
|
6592
|
-
if (!fs12.existsSync(
|
|
6734
|
+
if (!fs12.existsSync(path17.join(this.projectPath, ".adk", "opencode.json"))) {
|
|
6593
6735
|
this.createOpenCodeConfig();
|
|
6594
6736
|
}
|
|
6595
6737
|
}
|
|
6596
6738
|
static getAvailableTemplates() {
|
|
6597
6739
|
try {
|
|
6598
6740
|
const templatesRoot = AgentProjectGenerator.getTemplatesRoot();
|
|
6599
|
-
const configPath =
|
|
6741
|
+
const configPath = path17.join(templatesRoot, "template.config.json");
|
|
6600
6742
|
if (!fs12.existsSync(configPath)) {
|
|
6601
6743
|
return [];
|
|
6602
6744
|
}
|
|
@@ -6624,16 +6766,16 @@ class AgentProjectGenerator {
|
|
|
6624
6766
|
try {
|
|
6625
6767
|
const esmRequire = createRequire5(import.meta.url);
|
|
6626
6768
|
const adkPkgPath = esmRequire.resolve("@botpress/adk/package.json");
|
|
6627
|
-
const adkRoot =
|
|
6628
|
-
candidates.push(
|
|
6629
|
-
candidates.push(
|
|
6769
|
+
const adkRoot = path17.dirname(adkPkgPath);
|
|
6770
|
+
candidates.push(path17.join(adkRoot, "dist", "templates"));
|
|
6771
|
+
candidates.push(path17.join(adkRoot, "templates"));
|
|
6630
6772
|
} catch {}
|
|
6631
|
-
const thisDir =
|
|
6632
|
-
candidates.push(
|
|
6633
|
-
candidates.push(
|
|
6634
|
-
candidates.push(
|
|
6773
|
+
const thisDir = path17.dirname(fileURLToPath(import.meta.url));
|
|
6774
|
+
candidates.push(path17.resolve(thisDir, "templates"));
|
|
6775
|
+
candidates.push(path17.resolve(thisDir, "../../templates"));
|
|
6776
|
+
candidates.push(path17.join(path17.dirname(process.execPath), "templates"));
|
|
6635
6777
|
for (const candidate of candidates) {
|
|
6636
|
-
if (fs12.existsSync(candidate) && fs12.existsSync(
|
|
6778
|
+
if (fs12.existsSync(candidate) && fs12.existsSync(path17.join(candidate, "template.config.json"))) {
|
|
6637
6779
|
return candidate;
|
|
6638
6780
|
}
|
|
6639
6781
|
}
|
|
@@ -6648,7 +6790,7 @@ Ensure the ADK package is properly installed or run the CLI build.`);
|
|
|
6648
6790
|
}
|
|
6649
6791
|
resolveTemplateDir() {
|
|
6650
6792
|
const templatesRoot = AgentProjectGenerator.getTemplatesRoot();
|
|
6651
|
-
const templateDir =
|
|
6793
|
+
const templateDir = path17.join(templatesRoot, this.template);
|
|
6652
6794
|
if (!fs12.existsSync(templateDir)) {
|
|
6653
6795
|
const available = AgentProjectGenerator.getAvailableTemplates();
|
|
6654
6796
|
const names = available.map((t) => ` - ${t.name}: ${t.description}`).join(`
|
|
@@ -6658,7 +6800,7 @@ Ensure the ADK package is properly installed or run the CLI build.`);
|
|
|
6658
6800
|
Available templates:
|
|
6659
6801
|
${names || " (none found)"}`);
|
|
6660
6802
|
}
|
|
6661
|
-
const configFile =
|
|
6803
|
+
const configFile = path17.join(templateDir, "agent.config.ts");
|
|
6662
6804
|
if (!fs12.existsSync(configFile)) {
|
|
6663
6805
|
throw new Error(`Template "${this.template}" is missing agent.config.ts`);
|
|
6664
6806
|
}
|
|
@@ -6667,7 +6809,7 @@ ${names || " (none found)"}`);
|
|
|
6667
6809
|
async copyTemplateFiles(templateDir) {
|
|
6668
6810
|
const substitutions = {
|
|
6669
6811
|
"{{projectName}}": this.projectName,
|
|
6670
|
-
"{{runtimeVersion}}": "1.18.0-beta.
|
|
6812
|
+
"{{runtimeVersion}}": "1.18.0-beta.6",
|
|
6671
6813
|
"{{packageManager}}": this.packageManager
|
|
6672
6814
|
};
|
|
6673
6815
|
await this.copyDirRecursive(templateDir, this.projectPath, substitutions);
|
|
@@ -6678,8 +6820,8 @@ ${names || " (none found)"}`);
|
|
|
6678
6820
|
}
|
|
6679
6821
|
const entries = fs12.readdirSync(src, { withFileTypes: true });
|
|
6680
6822
|
for (const entry of entries) {
|
|
6681
|
-
const srcPath =
|
|
6682
|
-
const destPath =
|
|
6823
|
+
const srcPath = path17.join(src, entry.name);
|
|
6824
|
+
const destPath = path17.join(dest, entry.name);
|
|
6683
6825
|
if (entry.isDirectory()) {
|
|
6684
6826
|
await this.copyDirRecursive(srcPath, destPath, substitutions);
|
|
6685
6827
|
} else if (isTextFile(entry.name)) {
|
|
@@ -6742,10 +6884,12 @@ ${names || " (none found)"}`);
|
|
|
6742
6884
|
mcp: "allow"
|
|
6743
6885
|
}
|
|
6744
6886
|
};
|
|
6745
|
-
this.
|
|
6887
|
+
const adkDir = path17.join(this.projectPath, ".adk");
|
|
6888
|
+
fs12.mkdirSync(adkDir, { recursive: true });
|
|
6889
|
+
this.writeJsonFile(path17.join(".adk", "opencode.json"), config);
|
|
6746
6890
|
}
|
|
6747
6891
|
writeFile(relativePath, content) {
|
|
6748
|
-
const filePath =
|
|
6892
|
+
const filePath = path17.join(this.projectPath, relativePath);
|
|
6749
6893
|
fs12.writeFileSync(filePath, content);
|
|
6750
6894
|
}
|
|
6751
6895
|
writeJsonFile(relativePath, data) {
|
|
@@ -6761,7 +6905,7 @@ init_dependencies_parser();
|
|
|
6761
6905
|
|
|
6762
6906
|
// src/plugins/enhanced-cache.ts
|
|
6763
6907
|
import fs13 from "fs/promises";
|
|
6764
|
-
import
|
|
6908
|
+
import path18 from "path";
|
|
6765
6909
|
import os8 from "os";
|
|
6766
6910
|
|
|
6767
6911
|
class EnhancedPluginCache {
|
|
@@ -6771,9 +6915,9 @@ class EnhancedPluginCache {
|
|
|
6771
6915
|
noCache;
|
|
6772
6916
|
constructor(noCache = false) {
|
|
6773
6917
|
this.noCache = noCache;
|
|
6774
|
-
this.cacheDir =
|
|
6775
|
-
this.resolutionsDir =
|
|
6776
|
-
this.definitionsDir =
|
|
6918
|
+
this.cacheDir = path18.join(os8.homedir(), ".adk", "cache", "plugins");
|
|
6919
|
+
this.resolutionsDir = path18.join(this.cacheDir, "resolutions");
|
|
6920
|
+
this.definitionsDir = path18.join(this.cacheDir, "definitions");
|
|
6777
6921
|
}
|
|
6778
6922
|
async ensureCacheDirs() {
|
|
6779
6923
|
await fs13.mkdir(this.resolutionsDir, { recursive: true });
|
|
@@ -6785,7 +6929,7 @@ class EnhancedPluginCache {
|
|
|
6785
6929
|
}
|
|
6786
6930
|
try {
|
|
6787
6931
|
const key = this.getResolutionKey(name, version);
|
|
6788
|
-
const cachePath =
|
|
6932
|
+
const cachePath = path18.join(this.resolutionsDir, `${key}.json`);
|
|
6789
6933
|
const data = await fs13.readFile(cachePath, "utf-8");
|
|
6790
6934
|
const resolution = JSON.parse(data);
|
|
6791
6935
|
const cachedAt = new Date(resolution.cachedAt);
|
|
@@ -6802,7 +6946,7 @@ class EnhancedPluginCache {
|
|
|
6802
6946
|
async setResolution(name, version, pluginId, updatedAt) {
|
|
6803
6947
|
await this.ensureCacheDirs();
|
|
6804
6948
|
const key = this.getResolutionKey(name, version);
|
|
6805
|
-
const cachePath =
|
|
6949
|
+
const cachePath = path18.join(this.resolutionsDir, `${key}.json`);
|
|
6806
6950
|
const resolution = {
|
|
6807
6951
|
pluginId,
|
|
6808
6952
|
updatedAt,
|
|
@@ -6816,7 +6960,7 @@ class EnhancedPluginCache {
|
|
|
6816
6960
|
}
|
|
6817
6961
|
try {
|
|
6818
6962
|
const key = this.getDefinitionKey(pluginId, updatedAt);
|
|
6819
|
-
const cachePath =
|
|
6963
|
+
const cachePath = path18.join(this.definitionsDir, `${key}.json`);
|
|
6820
6964
|
const data = await fs13.readFile(cachePath, "utf-8");
|
|
6821
6965
|
const cached = JSON.parse(data);
|
|
6822
6966
|
return cached.definition;
|
|
@@ -6827,7 +6971,7 @@ class EnhancedPluginCache {
|
|
|
6827
6971
|
async setDefinition(pluginId, updatedAt, definition) {
|
|
6828
6972
|
await this.ensureCacheDirs();
|
|
6829
6973
|
const key = this.getDefinitionKey(pluginId, updatedAt);
|
|
6830
|
-
const cachePath =
|
|
6974
|
+
const cachePath = path18.join(this.definitionsDir, `${key}.json`);
|
|
6831
6975
|
const cached = {
|
|
6832
6976
|
definition,
|
|
6833
6977
|
cachedAt: new Date().toISOString()
|
|
@@ -6837,9 +6981,9 @@ class EnhancedPluginCache {
|
|
|
6837
6981
|
async clear() {
|
|
6838
6982
|
try {
|
|
6839
6983
|
const resolutionFiles = await fs13.readdir(this.resolutionsDir);
|
|
6840
|
-
await Promise.all(resolutionFiles.map((file) => fs13.unlink(
|
|
6984
|
+
await Promise.all(resolutionFiles.map((file) => fs13.unlink(path18.join(this.resolutionsDir, file))));
|
|
6841
6985
|
const definitionFiles = await fs13.readdir(this.definitionsDir);
|
|
6842
|
-
await Promise.all(definitionFiles.map((file) => fs13.unlink(
|
|
6986
|
+
await Promise.all(definitionFiles.map((file) => fs13.unlink(path18.join(this.definitionsDir, file))));
|
|
6843
6987
|
} catch {}
|
|
6844
6988
|
}
|
|
6845
6989
|
async getStats() {
|
|
@@ -6848,7 +6992,7 @@ class EnhancedPluginCache {
|
|
|
6848
6992
|
const files = await fs13.readdir(dir);
|
|
6849
6993
|
let totalSize = 0;
|
|
6850
6994
|
for (const file of files) {
|
|
6851
|
-
const stats = await fs13.stat(
|
|
6995
|
+
const stats = await fs13.stat(path18.join(dir, file));
|
|
6852
6996
|
totalSize += stats.size;
|
|
6853
6997
|
}
|
|
6854
6998
|
return {
|
|
@@ -6984,11 +7128,11 @@ init_assets();
|
|
|
6984
7128
|
// src/generators/assets.ts
|
|
6985
7129
|
init_fs();
|
|
6986
7130
|
init_assets();
|
|
6987
|
-
import
|
|
7131
|
+
import path19 from "path";
|
|
6988
7132
|
async function generateAssetsTypes(projectPath) {
|
|
6989
7133
|
const assetsManager = new AssetsManager({ projectPath });
|
|
6990
7134
|
const typesCode = await assetsManager.generateTypes();
|
|
6991
|
-
const typesPath =
|
|
7135
|
+
const typesPath = path19.join(projectPath, defaultAdkFolder, "assets.d.ts");
|
|
6992
7136
|
await createFile(typesPath, typesCode);
|
|
6993
7137
|
}
|
|
6994
7138
|
async function generateAssetsRuntime(projectPath, botId, workspaceId) {
|
|
@@ -7028,7 +7172,7 @@ if (typeof globalThis !== 'undefined') {
|
|
|
7028
7172
|
initializeAssets(global);
|
|
7029
7173
|
}
|
|
7030
7174
|
`;
|
|
7031
|
-
const runtimePath =
|
|
7175
|
+
const runtimePath = path19.join(projectPath, defaultAdkFolder, "assets-runtime.ts");
|
|
7032
7176
|
await createFile(runtimePath, runtimeCode);
|
|
7033
7177
|
}
|
|
7034
7178
|
async function initAssets(projectPath, botId, workspaceId) {
|
|
@@ -7058,7 +7202,7 @@ declare global {
|
|
|
7058
7202
|
};
|
|
7059
7203
|
}
|
|
7060
7204
|
`;
|
|
7061
|
-
const typesPath =
|
|
7205
|
+
const typesPath = path19.join(projectPath, defaultAdkFolder, "assets.d.ts");
|
|
7062
7206
|
await createFile(typesPath, emptyTypesCode);
|
|
7063
7207
|
const emptyRuntimeCode = `
|
|
7064
7208
|
// No assets available
|
|
@@ -7079,14 +7223,14 @@ if (typeof globalThis !== 'undefined') {
|
|
|
7079
7223
|
initializeAssets(global);
|
|
7080
7224
|
}
|
|
7081
7225
|
`;
|
|
7082
|
-
const runtimePath =
|
|
7226
|
+
const runtimePath = path19.join(projectPath, defaultAdkFolder, "assets-runtime.ts");
|
|
7083
7227
|
await createFile(runtimePath, emptyRuntimeCode);
|
|
7084
7228
|
}
|
|
7085
7229
|
}
|
|
7086
7230
|
// src/generators/integration-types.ts
|
|
7087
7231
|
import { z as z3 } from "@botpress/sdk";
|
|
7088
7232
|
import crypto2 from "crypto";
|
|
7089
|
-
import
|
|
7233
|
+
import path20 from "path";
|
|
7090
7234
|
|
|
7091
7235
|
// src/utils/strings.ts
|
|
7092
7236
|
function pascalCase(str) {
|
|
@@ -7127,12 +7271,12 @@ var getIntegrationNames = (integration) => ({
|
|
|
7127
7271
|
configurations: `Integration_Configurations_${getPascalAlias(integration)}`
|
|
7128
7272
|
},
|
|
7129
7273
|
paths: {
|
|
7130
|
-
index:
|
|
7131
|
-
actions:
|
|
7132
|
-
channels:
|
|
7133
|
-
events:
|
|
7134
|
-
users:
|
|
7135
|
-
configurations:
|
|
7274
|
+
index: path20.join(snakeCase(getPascalAlias(integration)), `index.ts`),
|
|
7275
|
+
actions: path20.join(snakeCase(getPascalAlias(integration)), `actions.ts`),
|
|
7276
|
+
channels: path20.join(snakeCase(getPascalAlias(integration)), `channels.ts`),
|
|
7277
|
+
events: path20.join(snakeCase(getPascalAlias(integration)), `events.ts`),
|
|
7278
|
+
users: path20.join(snakeCase(getPascalAlias(integration)), `users.ts`),
|
|
7279
|
+
configurations: path20.join(snakeCase(getPascalAlias(integration)), `configurations.ts`)
|
|
7136
7280
|
}
|
|
7137
7281
|
});
|
|
7138
7282
|
async function generateIntegrationTypes(integration) {
|
|
@@ -7387,7 +7531,7 @@ Description: ${tag?.description}`);
|
|
|
7387
7531
|
// src/generators/client-wrapper.ts
|
|
7388
7532
|
init_utils();
|
|
7389
7533
|
init_fs();
|
|
7390
|
-
import
|
|
7534
|
+
import path21 from "path";
|
|
7391
7535
|
import crypto3 from "crypto";
|
|
7392
7536
|
import { readFile as readFile3 } from "fs/promises";
|
|
7393
7537
|
import { BuiltInWorkflows as BuiltInWorkflows2 } from "@botpress/runtime/internal";
|
|
@@ -7409,7 +7553,7 @@ async function generateClientWrapper(project) {
|
|
|
7409
7553
|
});
|
|
7410
7554
|
continue;
|
|
7411
7555
|
}
|
|
7412
|
-
const absolutePath =
|
|
7556
|
+
const absolutePath = path21.join(project.path, action.path);
|
|
7413
7557
|
const actionModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
7414
7558
|
const actionInstance = actionModule[action.export] || actionModule.default;
|
|
7415
7559
|
if (actionInstance && actionInstance.input && actionInstance.output) {
|
|
@@ -7436,7 +7580,7 @@ async function generateClientWrapper(project) {
|
|
|
7436
7580
|
if (isBuiltinWorkflow(workflow.definition.name)) {
|
|
7437
7581
|
continue;
|
|
7438
7582
|
}
|
|
7439
|
-
const workflowPath =
|
|
7583
|
+
const workflowPath = path21.join(project.path, workflow.path);
|
|
7440
7584
|
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
7441
7585
|
const workflowInstance = workflowModule[workflow.export] || workflowModule.default;
|
|
7442
7586
|
if (workflowInstance) {
|
|
@@ -7455,7 +7599,7 @@ async function generateClientWrapper(project) {
|
|
|
7455
7599
|
const tableTypes = [];
|
|
7456
7600
|
for (const table of project.tables) {
|
|
7457
7601
|
try {
|
|
7458
|
-
const tablePath =
|
|
7602
|
+
const tablePath = path21.join(project.path, table.path);
|
|
7459
7603
|
const tableModule = await import(`${tablePath}?t=${Date.now()}`);
|
|
7460
7604
|
const tableInstance = tableModule.default || tableModule[table.export];
|
|
7461
7605
|
if (tableInstance && tableInstance.columns) {
|
|
@@ -7768,7 +7912,7 @@ export function createAdkClient(client: Client): AdkClient {
|
|
|
7768
7912
|
}
|
|
7769
7913
|
}
|
|
7770
7914
|
`;
|
|
7771
|
-
const clientWrapperPath =
|
|
7915
|
+
const clientWrapperPath = path21.join(project.path, ".adk", "client.ts");
|
|
7772
7916
|
const formattedContent = await formatCode(content);
|
|
7773
7917
|
const contentHash = crypto3.createHash("sha256").update(formattedContent.replace(/\/\/ Generated at: .+\n/, "")).digest("hex");
|
|
7774
7918
|
try {
|
|
@@ -7784,13 +7928,13 @@ export function createAdkClient(client: Client): AdkClient {
|
|
|
7784
7928
|
import dedent from "dedent";
|
|
7785
7929
|
import { existsSync as existsSync9 } from "fs";
|
|
7786
7930
|
import fs19 from "fs/promises";
|
|
7787
|
-
import
|
|
7931
|
+
import path42 from "path";
|
|
7788
7932
|
init_config_utils();
|
|
7789
7933
|
|
|
7790
7934
|
// src/generators/plugin-types.ts
|
|
7791
7935
|
import { z as z4 } from "@botpress/sdk";
|
|
7792
7936
|
import crypto4 from "crypto";
|
|
7793
|
-
import
|
|
7937
|
+
import path22 from "path";
|
|
7794
7938
|
init_utils();
|
|
7795
7939
|
var { transforms: transforms2 } = z4;
|
|
7796
7940
|
function stripRefs(schema) {
|
|
@@ -7829,8 +7973,8 @@ var getPluginNames = (plugin) => ({
|
|
|
7829
7973
|
actions: `Plugin_Actions_${getPascalAlias2(plugin)}`
|
|
7830
7974
|
},
|
|
7831
7975
|
paths: {
|
|
7832
|
-
index:
|
|
7833
|
-
actions:
|
|
7976
|
+
index: path22.join(snakeCase(getPascalAlias2(plugin)), `index.ts`),
|
|
7977
|
+
actions: path22.join(snakeCase(getPascalAlias2(plugin)), `actions.ts`)
|
|
7834
7978
|
}
|
|
7835
7979
|
});
|
|
7836
7980
|
async function generatePluginTypes(plugin) {
|
|
@@ -7898,7 +8042,7 @@ Description: ${action.description || "No description"}`)}
|
|
|
7898
8042
|
// src/generators/plugin-action-types.ts
|
|
7899
8043
|
init_utils();
|
|
7900
8044
|
init_fs();
|
|
7901
|
-
import
|
|
8045
|
+
import path23 from "path";
|
|
7902
8046
|
async function generatePluginActionTypes(project) {
|
|
7903
8047
|
const content = `
|
|
7904
8048
|
////////////////////////////////////////////////////////
|
|
@@ -7933,14 +8077,14 @@ type PluginsMap<T> = {
|
|
|
7933
8077
|
export type PluginActions = PluginsMap<Plugins>;
|
|
7934
8078
|
}
|
|
7935
8079
|
`;
|
|
7936
|
-
const pluginActionTypesPath =
|
|
8080
|
+
const pluginActionTypesPath = path23.join(project.path, ".adk", "plugin-action-types.d.ts");
|
|
7937
8081
|
await createFile(pluginActionTypesPath, await formatCode(content));
|
|
7938
8082
|
}
|
|
7939
8083
|
|
|
7940
8084
|
// src/generators/interface-types.ts
|
|
7941
8085
|
import { z as z5 } from "@botpress/sdk";
|
|
7942
8086
|
import crypto5 from "crypto";
|
|
7943
|
-
import
|
|
8087
|
+
import path24 from "path";
|
|
7944
8088
|
init_utils();
|
|
7945
8089
|
var { transforms: transforms3 } = z5;
|
|
7946
8090
|
var sameMajorVersion = (a, b) => {
|
|
@@ -7962,8 +8106,8 @@ var getInterfaceNames = (int) => ({
|
|
|
7962
8106
|
actions: `Interface_Actions_${pascalCase(int.name)}`
|
|
7963
8107
|
},
|
|
7964
8108
|
paths: {
|
|
7965
|
-
index:
|
|
7966
|
-
actions:
|
|
8109
|
+
index: path24.join(snakeCase(int.name), `index.ts`),
|
|
8110
|
+
actions: path24.join(snakeCase(int.name), `actions.ts`)
|
|
7967
8111
|
}
|
|
7968
8112
|
});
|
|
7969
8113
|
async function generateInterfaceTypes(int, integrations) {
|
|
@@ -8068,12 +8212,12 @@ Description: ${action.description || "No description"}`)}
|
|
|
8068
8212
|
// src/generators/table-types.ts
|
|
8069
8213
|
init_utils();
|
|
8070
8214
|
init_fs();
|
|
8071
|
-
import
|
|
8215
|
+
import path25 from "path";
|
|
8072
8216
|
async function generateTableTypes(project) {
|
|
8073
8217
|
const tables = [];
|
|
8074
8218
|
for (const tableRef of project.tables) {
|
|
8075
8219
|
try {
|
|
8076
|
-
const tablePath =
|
|
8220
|
+
const tablePath = path25.join(project.path, tableRef.path);
|
|
8077
8221
|
const tableModule = await import(`${tablePath}?t=${Date.now()}`);
|
|
8078
8222
|
const tableInstance = tableModule.default || tableModule[tableRef.export];
|
|
8079
8223
|
if (tableInstance && tableInstance.columns) {
|
|
@@ -8159,14 +8303,14 @@ ${outputColumns}
|
|
|
8159
8303
|
content += ` };
|
|
8160
8304
|
}
|
|
8161
8305
|
`;
|
|
8162
|
-
const tableTypesPath =
|
|
8306
|
+
const tableTypesPath = path25.join(project.path, ".adk", "table-types.d.ts");
|
|
8163
8307
|
await createFile(tableTypesPath, await formatCode(content));
|
|
8164
8308
|
}
|
|
8165
8309
|
|
|
8166
8310
|
// src/generators/trigger-types.ts
|
|
8167
8311
|
init_utils();
|
|
8168
8312
|
init_fs();
|
|
8169
|
-
import
|
|
8313
|
+
import path26 from "path";
|
|
8170
8314
|
async function generateTriggerTypes(project) {
|
|
8171
8315
|
const triggerEvents = {};
|
|
8172
8316
|
for (const trigger of project.triggers) {
|
|
@@ -8206,19 +8350,19 @@ ${triggersType}
|
|
|
8206
8350
|
};
|
|
8207
8351
|
}
|
|
8208
8352
|
`;
|
|
8209
|
-
const triggerTypesPath =
|
|
8353
|
+
const triggerTypesPath = path26.join(project.path, ".adk", "trigger-types.d.ts");
|
|
8210
8354
|
await createFile(triggerTypesPath, await formatCode(content));
|
|
8211
8355
|
}
|
|
8212
8356
|
|
|
8213
8357
|
// src/generators/state-types.ts
|
|
8214
8358
|
init_utils();
|
|
8215
8359
|
init_fs();
|
|
8216
|
-
import
|
|
8360
|
+
import path27 from "path";
|
|
8217
8361
|
async function generateStateTypes(project) {
|
|
8218
8362
|
let botStateType = "{}";
|
|
8219
8363
|
let userStateType = "{}";
|
|
8220
8364
|
try {
|
|
8221
|
-
const configPath =
|
|
8365
|
+
const configPath = path27.join(project.path, "agent.config.ts");
|
|
8222
8366
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
8223
8367
|
const config = configModule.default;
|
|
8224
8368
|
if (config?.bot?.state) {
|
|
@@ -8249,14 +8393,14 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
8249
8393
|
export type UserState = ${userStateType};
|
|
8250
8394
|
}
|
|
8251
8395
|
`;
|
|
8252
|
-
const stateTypesPath =
|
|
8396
|
+
const stateTypesPath = path27.join(project.path, ".adk", "state-types.d.ts");
|
|
8253
8397
|
await createFile(stateTypesPath, await formatCode(content));
|
|
8254
8398
|
}
|
|
8255
8399
|
|
|
8256
8400
|
// src/generators/tag-types.ts
|
|
8257
8401
|
init_utils();
|
|
8258
8402
|
init_fs();
|
|
8259
|
-
import
|
|
8403
|
+
import path28 from "path";
|
|
8260
8404
|
import { BUILT_IN_TAGS } from "@botpress/runtime/definition";
|
|
8261
8405
|
function generateTagTypeString(builtInTags, configTags) {
|
|
8262
8406
|
const builtInTagStrings = Object.entries(builtInTags).map(([key, tag]) => {
|
|
@@ -8295,7 +8439,7 @@ async function generateTagTypes(project) {
|
|
|
8295
8439
|
let messageTagsType = "Record<string, string | undefined>";
|
|
8296
8440
|
let workflowTagsType = "Record<string, string | undefined>";
|
|
8297
8441
|
try {
|
|
8298
|
-
const configPath =
|
|
8442
|
+
const configPath = path28.join(project.path, "agent.config.ts");
|
|
8299
8443
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
8300
8444
|
const config = configModule.default;
|
|
8301
8445
|
botTagsType = generateTagTypeString(BUILT_IN_TAGS.bot, config?.bot?.tags);
|
|
@@ -8341,18 +8485,18 @@ declare module "@botpress/runtime/_types/tags" {
|
|
|
8341
8485
|
export type WorkflowTags = ${workflowTagsType};
|
|
8342
8486
|
}
|
|
8343
8487
|
`;
|
|
8344
|
-
const tagTypesPath =
|
|
8488
|
+
const tagTypesPath = path28.join(project.path, ".adk", "tag-types.d.ts");
|
|
8345
8489
|
await createFile(tagTypesPath, await formatCode(content));
|
|
8346
8490
|
}
|
|
8347
8491
|
|
|
8348
8492
|
// src/generators/configuration-types.ts
|
|
8349
8493
|
init_utils();
|
|
8350
8494
|
init_fs();
|
|
8351
|
-
import
|
|
8495
|
+
import path29 from "path";
|
|
8352
8496
|
async function generateConfigurationTypes(project) {
|
|
8353
8497
|
let configurationType = "{}";
|
|
8354
8498
|
try {
|
|
8355
|
-
const configPath =
|
|
8499
|
+
const configPath = path29.join(project.path, "agent.config.ts");
|
|
8356
8500
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
8357
8501
|
const config = configModule.default;
|
|
8358
8502
|
if (config?.configuration?.schema) {
|
|
@@ -8376,18 +8520,18 @@ declare module "@botpress/runtime/_types/configuration" {
|
|
|
8376
8520
|
export type Configuration = ${configurationType};
|
|
8377
8521
|
}
|
|
8378
8522
|
`;
|
|
8379
|
-
const configTypesPath =
|
|
8523
|
+
const configTypesPath = path29.join(project.path, ".adk", "configuration-types.d.ts");
|
|
8380
8524
|
await createFile(configTypesPath, await formatCode(content));
|
|
8381
8525
|
}
|
|
8382
8526
|
|
|
8383
8527
|
// src/generators/secret-types.ts
|
|
8384
8528
|
init_utils();
|
|
8385
8529
|
init_fs();
|
|
8386
|
-
import
|
|
8530
|
+
import path30 from "path";
|
|
8387
8531
|
async function generateSecretTypes(project) {
|
|
8388
8532
|
let secretsType = "{}";
|
|
8389
8533
|
try {
|
|
8390
|
-
const configPath =
|
|
8534
|
+
const configPath = path30.join(project.path, "agent.config.ts");
|
|
8391
8535
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
8392
8536
|
const config = configModule.default;
|
|
8393
8537
|
if (config?.secrets) {
|
|
@@ -8419,14 +8563,14 @@ declare module "@botpress/runtime/_types/secrets" {
|
|
|
8419
8563
|
export type Secrets = ${secretsType};
|
|
8420
8564
|
}
|
|
8421
8565
|
`;
|
|
8422
|
-
const secretTypesPath =
|
|
8566
|
+
const secretTypesPath = path30.join(project.path, ".adk", "secret-types.d.ts");
|
|
8423
8567
|
await createFile(secretTypesPath, await formatCode(content));
|
|
8424
8568
|
}
|
|
8425
8569
|
|
|
8426
8570
|
// src/generators/workflow-types.ts
|
|
8427
8571
|
init_utils();
|
|
8428
8572
|
init_fs();
|
|
8429
|
-
import * as
|
|
8573
|
+
import * as path31 from "path";
|
|
8430
8574
|
import { BuiltInWorkflows as BuiltInWorkflows3 } from "@botpress/runtime/internal";
|
|
8431
8575
|
function isBuiltinWorkflow2(name) {
|
|
8432
8576
|
return !!Object.values(BuiltInWorkflows3).find((x) => x.name === name);
|
|
@@ -8438,7 +8582,7 @@ async function generateWorkflowTypes(project) {
|
|
|
8438
8582
|
if (isBuiltinWorkflow2(workflowRef.definition.name)) {
|
|
8439
8583
|
continue;
|
|
8440
8584
|
}
|
|
8441
|
-
const workflowPath =
|
|
8585
|
+
const workflowPath = path31.join(project.path, workflowRef.path);
|
|
8442
8586
|
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
8443
8587
|
const workflowInstance = workflowModule[workflowRef.export] || workflowModule.default;
|
|
8444
8588
|
if (!workflowInstance) {
|
|
@@ -8496,14 +8640,14 @@ declare module "@botpress/runtime/_types/workflows" {
|
|
|
8496
8640
|
${typeDefinitions || " // No workflows defined yet"}
|
|
8497
8641
|
};
|
|
8498
8642
|
}`;
|
|
8499
|
-
const workflowTypesPath =
|
|
8643
|
+
const workflowTypesPath = path31.join(project.path, ".adk", "workflow-types.d.ts");
|
|
8500
8644
|
await createFile(workflowTypesPath, await formatCode(content));
|
|
8501
8645
|
}
|
|
8502
8646
|
|
|
8503
8647
|
// src/generators/conversation-types.ts
|
|
8504
8648
|
init_utils();
|
|
8505
8649
|
init_fs();
|
|
8506
|
-
import
|
|
8650
|
+
import path32 from "path";
|
|
8507
8651
|
function hasConversationIdProperty(schema) {
|
|
8508
8652
|
if (!schema || typeof schema !== "object") {
|
|
8509
8653
|
return false;
|
|
@@ -8526,7 +8670,7 @@ async function generateConversationTypes(project) {
|
|
|
8526
8670
|
const conversationTypes = {};
|
|
8527
8671
|
for (const conversationRef of project.conversations) {
|
|
8528
8672
|
try {
|
|
8529
|
-
const conversationPath =
|
|
8673
|
+
const conversationPath = path32.join(project.path, conversationRef.path);
|
|
8530
8674
|
const conversationModule = await import(`${conversationPath}?t=${Date.now()}`);
|
|
8531
8675
|
const conversationInstance = conversationModule[conversationRef.export] || conversationModule.default;
|
|
8532
8676
|
if (!conversationInstance) {
|
|
@@ -8614,14 +8758,14 @@ ${routableEventsDefinitions || " // No routable events found"}
|
|
|
8614
8758
|
};
|
|
8615
8759
|
}
|
|
8616
8760
|
`;
|
|
8617
|
-
const conversationTypesPath =
|
|
8761
|
+
const conversationTypesPath = path32.join(project.path, ".adk", "conversation-types.d.ts");
|
|
8618
8762
|
await createFile(conversationTypesPath, await formatCode(content));
|
|
8619
8763
|
}
|
|
8620
8764
|
|
|
8621
8765
|
// src/generators/component-types.ts
|
|
8622
8766
|
init_utils();
|
|
8623
8767
|
init_fs();
|
|
8624
|
-
import
|
|
8768
|
+
import path33 from "path";
|
|
8625
8769
|
async function generateComponentTypes(project) {
|
|
8626
8770
|
const components = project.customComponents;
|
|
8627
8771
|
if (components.length === 0) {
|
|
@@ -8637,7 +8781,7 @@ declare module "@botpress/runtime/_types/components" {
|
|
|
8637
8781
|
export type CustomComponentMessage = never;
|
|
8638
8782
|
}
|
|
8639
8783
|
`;
|
|
8640
|
-
const typesPath2 =
|
|
8784
|
+
const typesPath2 = path33.join(project.path, ".adk", "component-types.d.ts");
|
|
8641
8785
|
await createFile(typesPath2, await formatCode(content2));
|
|
8642
8786
|
return;
|
|
8643
8787
|
}
|
|
@@ -8661,14 +8805,14 @@ declare module "@botpress/runtime/_types/components" {
|
|
|
8661
8805
|
| `)};
|
|
8662
8806
|
}
|
|
8663
8807
|
`;
|
|
8664
|
-
const typesPath =
|
|
8808
|
+
const typesPath = path33.join(project.path, ".adk", "component-types.d.ts");
|
|
8665
8809
|
await createFile(typesPath, await formatCode(content));
|
|
8666
8810
|
}
|
|
8667
8811
|
|
|
8668
8812
|
// src/generators/event-types.ts
|
|
8669
8813
|
init_utils();
|
|
8670
8814
|
init_fs();
|
|
8671
|
-
import
|
|
8815
|
+
import path34 from "path";
|
|
8672
8816
|
async function generateEventTypes(project) {
|
|
8673
8817
|
const defaultEvents = ["register: {}"];
|
|
8674
8818
|
const integrationEvents = [];
|
|
@@ -8720,7 +8864,7 @@ ${allEvents.map((e) => ` ${e}`).join(`
|
|
|
8720
8864
|
export type EventPayload<T extends EventName> = Events[T];
|
|
8721
8865
|
}
|
|
8722
8866
|
`;
|
|
8723
|
-
const eventTypesPath =
|
|
8867
|
+
const eventTypesPath = path34.join(project.path, ".adk", "event-types.d.ts");
|
|
8724
8868
|
await createFile(eventTypesPath, await formatCode(content));
|
|
8725
8869
|
}
|
|
8726
8870
|
|
|
@@ -8732,7 +8876,7 @@ init_fs();
|
|
|
8732
8876
|
// src/utils/link-sdk.ts
|
|
8733
8877
|
import { existsSync as existsSync5, realpathSync } from "fs";
|
|
8734
8878
|
import fs14 from "fs/promises";
|
|
8735
|
-
import
|
|
8879
|
+
import path35 from "path";
|
|
8736
8880
|
function findPackage(name, startDir) {
|
|
8737
8881
|
let current;
|
|
8738
8882
|
try {
|
|
@@ -8740,17 +8884,17 @@ function findPackage(name, startDir) {
|
|
|
8740
8884
|
} catch {
|
|
8741
8885
|
current = startDir;
|
|
8742
8886
|
}
|
|
8743
|
-
while (current !==
|
|
8744
|
-
const pkgPath =
|
|
8887
|
+
while (current !== path35.dirname(current)) {
|
|
8888
|
+
const pkgPath = path35.join(current, "node_modules", name);
|
|
8745
8889
|
if (existsSync5(pkgPath)) {
|
|
8746
8890
|
return pkgPath;
|
|
8747
8891
|
}
|
|
8748
|
-
current =
|
|
8892
|
+
current = path35.dirname(current);
|
|
8749
8893
|
}
|
|
8750
8894
|
return null;
|
|
8751
8895
|
}
|
|
8752
8896
|
async function linkSdk(agentDir, botDir) {
|
|
8753
|
-
const targetSdkPath =
|
|
8897
|
+
const targetSdkPath = path35.join(botDir, "node_modules", "@botpress", "sdk");
|
|
8754
8898
|
if (existsSync5(targetSdkPath)) {
|
|
8755
8899
|
return;
|
|
8756
8900
|
}
|
|
@@ -8764,7 +8908,7 @@ async function linkSdk(agentDir, botDir) {
|
|
|
8764
8908
|
console.warn(`Warning: Could not find @botpress/sdk from @botpress/runtime location (${runtimePath})`);
|
|
8765
8909
|
return;
|
|
8766
8910
|
}
|
|
8767
|
-
const targetBotpressDir =
|
|
8911
|
+
const targetBotpressDir = path35.join(botDir, "node_modules", "@botpress");
|
|
8768
8912
|
await fs14.mkdir(targetBotpressDir, { recursive: true });
|
|
8769
8913
|
const symlinkType = process.platform === "win32" ? "junction" : undefined;
|
|
8770
8914
|
await fs14.symlink(sdkPath, targetSdkPath, symlinkType);
|
|
@@ -8772,7 +8916,9 @@ async function linkSdk(agentDir, botDir) {
|
|
|
8772
8916
|
|
|
8773
8917
|
// src/bot-generator/dev-id-manager.ts
|
|
8774
8918
|
init_auth();
|
|
8775
|
-
|
|
8919
|
+
init_agent_project();
|
|
8920
|
+
init_validation_errors();
|
|
8921
|
+
import path36 from "path";
|
|
8776
8922
|
import fs15 from "fs/promises";
|
|
8777
8923
|
import createDebug3 from "debug";
|
|
8778
8924
|
import { Client as Client14 } from "@botpress/client";
|
|
@@ -8783,10 +8929,14 @@ class DevIdManager {
|
|
|
8783
8929
|
botProjectPath;
|
|
8784
8930
|
projectCachePath;
|
|
8785
8931
|
client;
|
|
8786
|
-
|
|
8932
|
+
loadAgentProject;
|
|
8933
|
+
validationErrors;
|
|
8934
|
+
constructor(projectPath, botProjectPath, options = {}) {
|
|
8787
8935
|
this.projectPath = projectPath;
|
|
8788
8936
|
this.botProjectPath = botProjectPath;
|
|
8789
|
-
this.projectCachePath =
|
|
8937
|
+
this.projectCachePath = path36.join(botProjectPath, ".botpress", "project.cache.json");
|
|
8938
|
+
this.loadAgentProject = options.loadAgentProject ?? ((p) => AgentProject.load(p));
|
|
8939
|
+
this.validationErrors = options.validationErrors ?? ValidationErrors;
|
|
8790
8940
|
}
|
|
8791
8941
|
async getClient() {
|
|
8792
8942
|
if (!this.client) {
|
|
@@ -8808,7 +8958,7 @@ class DevIdManager {
|
|
|
8808
8958
|
return this.client;
|
|
8809
8959
|
}
|
|
8810
8960
|
async getProject() {
|
|
8811
|
-
return await
|
|
8961
|
+
return await this.loadAgentProject(this.projectPath);
|
|
8812
8962
|
}
|
|
8813
8963
|
async readProjectCache() {
|
|
8814
8964
|
try {
|
|
@@ -8838,7 +8988,7 @@ class DevIdManager {
|
|
|
8838
8988
|
}
|
|
8839
8989
|
async saveProjectCache(cache2) {
|
|
8840
8990
|
try {
|
|
8841
|
-
await fs15.mkdir(
|
|
8991
|
+
await fs15.mkdir(path36.dirname(this.projectCachePath), { recursive: true });
|
|
8842
8992
|
await fs15.writeFile(this.projectCachePath, JSON.stringify(cache2, null, 2));
|
|
8843
8993
|
} catch (error) {
|
|
8844
8994
|
console.error("Error saving project.cache.json:", error);
|
|
@@ -8849,7 +8999,7 @@ class DevIdManager {
|
|
|
8849
8999
|
if (projectCache.devId) {
|
|
8850
9000
|
const project = await this.getProject();
|
|
8851
9001
|
if (!project.agentInfo) {
|
|
8852
|
-
throw
|
|
9002
|
+
throw this.validationErrors.agentNotLinked();
|
|
8853
9003
|
}
|
|
8854
9004
|
await project.updateAgentLocalInfo({
|
|
8855
9005
|
devId: projectCache.devId
|
|
@@ -8895,7 +9045,7 @@ function isProjectCache(value) {
|
|
|
8895
9045
|
// src/bot-generator/integration-sync.ts
|
|
8896
9046
|
init_agent_project();
|
|
8897
9047
|
init_auth();
|
|
8898
|
-
import
|
|
9048
|
+
import path37 from "path";
|
|
8899
9049
|
import fs16 from "fs/promises";
|
|
8900
9050
|
import { existsSync as existsSync6 } from "fs";
|
|
8901
9051
|
class IntegrationSync {
|
|
@@ -8905,7 +9055,7 @@ class IntegrationSync {
|
|
|
8905
9055
|
constructor(projectPath, botProjectPath) {
|
|
8906
9056
|
this.projectPath = projectPath;
|
|
8907
9057
|
this.botProjectPath = botProjectPath;
|
|
8908
|
-
this.bpModulesPath =
|
|
9058
|
+
this.bpModulesPath = path37.join(botProjectPath, "bp_modules");
|
|
8909
9059
|
}
|
|
8910
9060
|
async parseIntegrations() {
|
|
8911
9061
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -8936,12 +9086,12 @@ class IntegrationSync {
|
|
|
8936
9086
|
return integrations;
|
|
8937
9087
|
}
|
|
8938
9088
|
async isIntegrationSynced(integration) {
|
|
8939
|
-
const targetFolder =
|
|
9089
|
+
const targetFolder = path37.join(this.bpModulesPath, `integration_${integration.alias}`);
|
|
8940
9090
|
if (!existsSync6(targetFolder)) {
|
|
8941
9091
|
return false;
|
|
8942
9092
|
}
|
|
8943
9093
|
try {
|
|
8944
|
-
const indexPath =
|
|
9094
|
+
const indexPath = path37.join(targetFolder, "index.ts");
|
|
8945
9095
|
if (!existsSync6(indexPath)) {
|
|
8946
9096
|
return false;
|
|
8947
9097
|
}
|
|
@@ -8973,8 +9123,8 @@ class IntegrationSync {
|
|
|
8973
9123
|
await command.output();
|
|
8974
9124
|
}
|
|
8975
9125
|
async renameIntegrationFolder(integration) {
|
|
8976
|
-
const sourceFolder =
|
|
8977
|
-
const targetFolder =
|
|
9126
|
+
const sourceFolder = path37.join(this.bpModulesPath, integration.name.replace("/", "-"));
|
|
9127
|
+
const targetFolder = path37.join(this.bpModulesPath, `integration_${integration.alias}`);
|
|
8978
9128
|
if (!existsSync6(sourceFolder)) {
|
|
8979
9129
|
throw new Error(`Integration folder not found: ${sourceFolder}`);
|
|
8980
9130
|
}
|
|
@@ -8984,7 +9134,7 @@ class IntegrationSync {
|
|
|
8984
9134
|
await fs16.rename(sourceFolder, targetFolder);
|
|
8985
9135
|
}
|
|
8986
9136
|
async removeIntegrationFolder(alias) {
|
|
8987
|
-
const targetFolder =
|
|
9137
|
+
const targetFolder = path37.join(this.bpModulesPath, `integration_${alias}`);
|
|
8988
9138
|
if (existsSync6(targetFolder)) {
|
|
8989
9139
|
await fs16.rm(targetFolder, { recursive: true, force: true });
|
|
8990
9140
|
}
|
|
@@ -9020,7 +9170,7 @@ class IntegrationSync {
|
|
|
9020
9170
|
// src/bot-generator/interface-sync.ts
|
|
9021
9171
|
init_agent_project();
|
|
9022
9172
|
init_auth();
|
|
9023
|
-
import
|
|
9173
|
+
import path38 from "path";
|
|
9024
9174
|
import fs17 from "fs/promises";
|
|
9025
9175
|
import { existsSync as existsSync7 } from "fs";
|
|
9026
9176
|
init_constants();
|
|
@@ -9031,7 +9181,7 @@ class InterfaceSync {
|
|
|
9031
9181
|
constructor(projectPath, botProjectPath) {
|
|
9032
9182
|
this.projectPath = projectPath;
|
|
9033
9183
|
this.botProjectPath = botProjectPath;
|
|
9034
|
-
this.bpModulesPath =
|
|
9184
|
+
this.bpModulesPath = path38.join(botProjectPath, "bp_modules");
|
|
9035
9185
|
}
|
|
9036
9186
|
async parseInterfaces() {
|
|
9037
9187
|
const interfaces = [];
|
|
@@ -9049,12 +9199,12 @@ class InterfaceSync {
|
|
|
9049
9199
|
return interfaces;
|
|
9050
9200
|
}
|
|
9051
9201
|
async isInterfaceSynced(interfaceInfo) {
|
|
9052
|
-
const targetFolder =
|
|
9202
|
+
const targetFolder = path38.join(this.bpModulesPath, `interface_${pascalCase(interfaceInfo.alias)}`);
|
|
9053
9203
|
if (!existsSync7(targetFolder)) {
|
|
9054
9204
|
return false;
|
|
9055
9205
|
}
|
|
9056
9206
|
try {
|
|
9057
|
-
const indexPath =
|
|
9207
|
+
const indexPath = path38.join(targetFolder, "index.ts");
|
|
9058
9208
|
if (!existsSync7(indexPath)) {
|
|
9059
9209
|
return false;
|
|
9060
9210
|
}
|
|
@@ -9076,7 +9226,7 @@ class InterfaceSync {
|
|
|
9076
9226
|
if (!workspaceId) {
|
|
9077
9227
|
throw new Error('No workspace ID found. Please login with "adk login"');
|
|
9078
9228
|
}
|
|
9079
|
-
return new Promise((
|
|
9229
|
+
return new Promise((resolve5, reject) => {
|
|
9080
9230
|
const command = new BpAddCommand({
|
|
9081
9231
|
resource: `interface:${interfaceInfo.fullVersion}`,
|
|
9082
9232
|
botPath: this.botProjectPath,
|
|
@@ -9094,14 +9244,14 @@ class InterfaceSync {
|
|
|
9094
9244
|
reject(new Error(`Failed to install interface ${interfaceInfo.fullVersion}: ${error.stderr || error.message}`));
|
|
9095
9245
|
});
|
|
9096
9246
|
command.on("done", () => {
|
|
9097
|
-
|
|
9247
|
+
resolve5();
|
|
9098
9248
|
});
|
|
9099
9249
|
command.run().catch(reject);
|
|
9100
9250
|
});
|
|
9101
9251
|
}
|
|
9102
9252
|
async renameInterfaceFolder(interfaceInfo) {
|
|
9103
|
-
const sourceFolder =
|
|
9104
|
-
const targetFolder =
|
|
9253
|
+
const sourceFolder = path38.join(this.bpModulesPath, interfaceInfo.name);
|
|
9254
|
+
const targetFolder = path38.join(this.bpModulesPath, `interface_${pascalCase(interfaceInfo.alias)}`);
|
|
9105
9255
|
if (!existsSync7(sourceFolder)) {
|
|
9106
9256
|
throw new Error(`Interface folder not found: ${sourceFolder}`);
|
|
9107
9257
|
}
|
|
@@ -9111,7 +9261,7 @@ class InterfaceSync {
|
|
|
9111
9261
|
await fs17.rename(sourceFolder, targetFolder);
|
|
9112
9262
|
}
|
|
9113
9263
|
async removeInterfaceFolder(alias) {
|
|
9114
|
-
const targetFolder =
|
|
9264
|
+
const targetFolder = path38.join(this.bpModulesPath, `interface_${pascalCase(alias)}`);
|
|
9115
9265
|
if (existsSync7(targetFolder)) {
|
|
9116
9266
|
await fs17.rm(targetFolder, { recursive: true, force: true });
|
|
9117
9267
|
}
|
|
@@ -9147,7 +9297,7 @@ class InterfaceSync {
|
|
|
9147
9297
|
// src/bot-generator/plugin-sync.ts
|
|
9148
9298
|
init_agent_project();
|
|
9149
9299
|
init_auth();
|
|
9150
|
-
import
|
|
9300
|
+
import path39 from "path";
|
|
9151
9301
|
import fs18 from "fs/promises";
|
|
9152
9302
|
import { existsSync as existsSync8 } from "fs";
|
|
9153
9303
|
class PluginSync {
|
|
@@ -9157,7 +9307,7 @@ class PluginSync {
|
|
|
9157
9307
|
constructor(projectPath, botProjectPath) {
|
|
9158
9308
|
this.projectPath = projectPath;
|
|
9159
9309
|
this.botProjectPath = botProjectPath;
|
|
9160
|
-
this.bpModulesPath =
|
|
9310
|
+
this.bpModulesPath = path39.join(botProjectPath, "bp_modules");
|
|
9161
9311
|
}
|
|
9162
9312
|
async parsePlugins() {
|
|
9163
9313
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -9180,12 +9330,12 @@ class PluginSync {
|
|
|
9180
9330
|
return plugins;
|
|
9181
9331
|
}
|
|
9182
9332
|
async isPluginSynced(plugin) {
|
|
9183
|
-
const targetFolder =
|
|
9333
|
+
const targetFolder = path39.join(this.bpModulesPath, `plugin_${plugin.alias}`);
|
|
9184
9334
|
if (!existsSync8(targetFolder)) {
|
|
9185
9335
|
return false;
|
|
9186
9336
|
}
|
|
9187
9337
|
try {
|
|
9188
|
-
const indexPath =
|
|
9338
|
+
const indexPath = path39.join(targetFolder, "index.ts");
|
|
9189
9339
|
if (!existsSync8(indexPath)) {
|
|
9190
9340
|
return false;
|
|
9191
9341
|
}
|
|
@@ -9217,8 +9367,8 @@ class PluginSync {
|
|
|
9217
9367
|
await command.output();
|
|
9218
9368
|
}
|
|
9219
9369
|
async renamePluginFolder(plugin) {
|
|
9220
|
-
const sourceFolder =
|
|
9221
|
-
const targetFolder =
|
|
9370
|
+
const sourceFolder = path39.join(this.bpModulesPath, plugin.name.replace("/", "-"));
|
|
9371
|
+
const targetFolder = path39.join(this.bpModulesPath, `plugin_${plugin.alias}`);
|
|
9222
9372
|
if (!existsSync8(sourceFolder)) {
|
|
9223
9373
|
throw new Error(`Plugin folder not found: ${sourceFolder}`);
|
|
9224
9374
|
}
|
|
@@ -9228,7 +9378,7 @@ class PluginSync {
|
|
|
9228
9378
|
await fs18.rename(sourceFolder, targetFolder);
|
|
9229
9379
|
}
|
|
9230
9380
|
async removePluginFolder(alias) {
|
|
9231
|
-
const targetFolder =
|
|
9381
|
+
const targetFolder = path39.join(this.bpModulesPath, `plugin_${alias}`);
|
|
9232
9382
|
if (existsSync8(targetFolder)) {
|
|
9233
9383
|
await fs18.rm(targetFolder, { recursive: true, force: true });
|
|
9234
9384
|
}
|
|
@@ -9277,7 +9427,7 @@ function isBuiltinAction(name) {
|
|
|
9277
9427
|
return !!Object.values(BuiltInActions2).find((x) => x.name === name);
|
|
9278
9428
|
}
|
|
9279
9429
|
function getImportPath(from, to) {
|
|
9280
|
-
return
|
|
9430
|
+
return path42.relative(path42.dirname(from), to).replace(/\.ts$/, "").replace(/\\/g, "/");
|
|
9281
9431
|
}
|
|
9282
9432
|
|
|
9283
9433
|
class BotGenerator {
|
|
@@ -9286,8 +9436,8 @@ class BotGenerator {
|
|
|
9286
9436
|
adkCommand;
|
|
9287
9437
|
callbacks;
|
|
9288
9438
|
constructor(options) {
|
|
9289
|
-
this.projectPath =
|
|
9290
|
-
this.outputPath =
|
|
9439
|
+
this.projectPath = path42.resolve(options.projectPath);
|
|
9440
|
+
this.outputPath = path42.resolve(options.outputPath || path42.join(this.projectPath, ".adk"));
|
|
9291
9441
|
this.adkCommand = options.adkCommand;
|
|
9292
9442
|
this.callbacks = options.callbacks;
|
|
9293
9443
|
}
|
|
@@ -9299,8 +9449,8 @@ class BotGenerator {
|
|
|
9299
9449
|
const walk = async (dir, relativeBase) => {
|
|
9300
9450
|
const entries = await fs19.readdir(dir, { withFileTypes: true });
|
|
9301
9451
|
for (const entry of entries) {
|
|
9302
|
-
const abs =
|
|
9303
|
-
const rel =
|
|
9452
|
+
const abs = path42.join(dir, entry.name);
|
|
9453
|
+
const rel = path42.join(relativeBase, entry.name);
|
|
9304
9454
|
if (entry.isDirectory()) {
|
|
9305
9455
|
await walk(abs, rel);
|
|
9306
9456
|
} else {
|
|
@@ -9321,7 +9471,7 @@ class BotGenerator {
|
|
|
9321
9471
|
const entries = await fs19.readdir(dir, { withFileTypes: true });
|
|
9322
9472
|
for (const entry of entries) {
|
|
9323
9473
|
if (entry.isDirectory()) {
|
|
9324
|
-
const subdir =
|
|
9474
|
+
const subdir = path42.join(dir, entry.name);
|
|
9325
9475
|
await removeIfEmpty(subdir);
|
|
9326
9476
|
}
|
|
9327
9477
|
}
|
|
@@ -9371,18 +9521,18 @@ class BotGenerator {
|
|
|
9371
9521
|
workspaceId: project.agentInfo?.workspaceId
|
|
9372
9522
|
});
|
|
9373
9523
|
const integrations = await manager3.loadIntegrations(project.dependencies || {});
|
|
9374
|
-
const integrationsDir =
|
|
9524
|
+
const integrationsDir = path42.join(this.projectPath, ".adk", "integrations");
|
|
9375
9525
|
const existingIntegrationFiles = await this.listFilesRecursive(integrationsDir);
|
|
9376
9526
|
let aliases = new Set;
|
|
9377
9527
|
let files = new Set;
|
|
9378
9528
|
for (const integration of integrations.integrations) {
|
|
9379
9529
|
if (integration.definition) {
|
|
9380
9530
|
const types6 = await generateIntegrationTypes(integration);
|
|
9381
|
-
const importPath = `./${
|
|
9531
|
+
const importPath = `./${path42.join("integrations", types6.names.paths.index).replace(/\\/g, "/")}`;
|
|
9382
9532
|
aliases.add(`"${integration.alias}": import("${importPath}").${types6.names.typings.index}`);
|
|
9383
9533
|
for (const [filePath, content] of Object.entries(types6.files)) {
|
|
9384
|
-
const fullPath =
|
|
9385
|
-
const dir =
|
|
9534
|
+
const fullPath = path42.join(this.projectPath, ".adk", "integrations", filePath);
|
|
9535
|
+
const dir = path42.dirname(fullPath);
|
|
9386
9536
|
await fs19.mkdir(dir, { recursive: true });
|
|
9387
9537
|
await createFile(fullPath, content);
|
|
9388
9538
|
files.add(filePath);
|
|
@@ -9403,11 +9553,11 @@ class BotGenerator {
|
|
|
9403
9553
|
};
|
|
9404
9554
|
}
|
|
9405
9555
|
`;
|
|
9406
|
-
await createFile(
|
|
9556
|
+
await createFile(path42.join(this.projectPath, ".adk", "integrations-types.d.ts"), await formatCode(types5));
|
|
9407
9557
|
const staleIntegrationFiles = existingIntegrationFiles.filter((f) => !files.has(f));
|
|
9408
9558
|
if (staleIntegrationFiles.length > 0) {
|
|
9409
9559
|
for (const rel of staleIntegrationFiles) {
|
|
9410
|
-
const abs =
|
|
9560
|
+
const abs = path42.join(integrationsDir, rel);
|
|
9411
9561
|
try {
|
|
9412
9562
|
await fs19.rm(abs, { force: true });
|
|
9413
9563
|
} catch {}
|
|
@@ -9421,18 +9571,18 @@ class BotGenerator {
|
|
|
9421
9571
|
workspaceId: project.agentInfo?.workspaceId
|
|
9422
9572
|
});
|
|
9423
9573
|
const result = await manager3.loadPlugins(project.dependencies || {});
|
|
9424
|
-
const pluginsDir =
|
|
9574
|
+
const pluginsDir = path42.join(this.projectPath, ".adk", "plugins");
|
|
9425
9575
|
const existingPluginFiles = await this.listFilesRecursive(pluginsDir);
|
|
9426
9576
|
let aliases = new Set;
|
|
9427
9577
|
let files = new Set;
|
|
9428
9578
|
for (const plugin of result.plugins) {
|
|
9429
9579
|
if (plugin.definition) {
|
|
9430
9580
|
const types6 = await generatePluginTypes(plugin);
|
|
9431
|
-
const importPath = `./${
|
|
9581
|
+
const importPath = `./${path42.join("plugins", types6.names.paths.index).replace(/\\/g, "/")}`;
|
|
9432
9582
|
aliases.add(`"${plugin.alias}": import("${importPath}").${types6.names.typings.index}`);
|
|
9433
9583
|
for (const [filePath, content] of Object.entries(types6.files)) {
|
|
9434
|
-
const fullPath =
|
|
9435
|
-
const dir =
|
|
9584
|
+
const fullPath = path42.join(this.projectPath, ".adk", "plugins", filePath);
|
|
9585
|
+
const dir = path42.dirname(fullPath);
|
|
9436
9586
|
await fs19.mkdir(dir, { recursive: true });
|
|
9437
9587
|
await createFile(fullPath, content);
|
|
9438
9588
|
files.add(filePath);
|
|
@@ -9453,11 +9603,11 @@ class BotGenerator {
|
|
|
9453
9603
|
};
|
|
9454
9604
|
}
|
|
9455
9605
|
`;
|
|
9456
|
-
await createFile(
|
|
9606
|
+
await createFile(path42.join(this.projectPath, ".adk", "plugins-types.d.ts"), await formatCode(types5));
|
|
9457
9607
|
const stalePluginFiles = existingPluginFiles.filter((f) => !files.has(f));
|
|
9458
9608
|
if (stalePluginFiles.length > 0) {
|
|
9459
9609
|
for (const rel of stalePluginFiles) {
|
|
9460
|
-
const abs =
|
|
9610
|
+
const abs = path42.join(pluginsDir, rel);
|
|
9461
9611
|
try {
|
|
9462
9612
|
await fs19.rm(abs, { force: true });
|
|
9463
9613
|
} catch {}
|
|
@@ -9542,7 +9692,7 @@ class BotGenerator {
|
|
|
9542
9692
|
let botStateType = "{}";
|
|
9543
9693
|
let userStateType = "{}";
|
|
9544
9694
|
try {
|
|
9545
|
-
const configPath =
|
|
9695
|
+
const configPath = path42.join(project.path, "agent.config.ts");
|
|
9546
9696
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
9547
9697
|
const config = configModule.default;
|
|
9548
9698
|
if (config?.bot?.state) {
|
|
@@ -9578,7 +9728,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9578
9728
|
export type UserState = ${userStateType};
|
|
9579
9729
|
}
|
|
9580
9730
|
`;
|
|
9581
|
-
await createFile(
|
|
9731
|
+
await createFile(path42.join(this.projectPath, ".adk", "runtime.d.ts"), await formatCode(types5));
|
|
9582
9732
|
}
|
|
9583
9733
|
async generateInterfacesTypes() {
|
|
9584
9734
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -9586,7 +9736,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9586
9736
|
workspaceId: project.agentInfo?.workspaceId
|
|
9587
9737
|
});
|
|
9588
9738
|
const manager3 = new InterfaceManager;
|
|
9589
|
-
const interfacesDir =
|
|
9739
|
+
const interfacesDir = path42.join(this.projectPath, ".adk", "interfaces");
|
|
9590
9740
|
const existingInterfaceFiles = await this.listFilesRecursive(interfacesDir);
|
|
9591
9741
|
const interfaces = await manager3.loadInterfaces(project.dependencies || {}).then((result) => result.interfaces.filter((int) => int.definition).map((x) => x.definition));
|
|
9592
9742
|
const integrationsWithAlias = await integrationManager.loadIntegrations(project.dependencies || {}).then((result) => result.integrations.filter((int) => int.definition).map((x) => ({ alias: x.alias, definition: x.definition })));
|
|
@@ -9595,11 +9745,11 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9595
9745
|
let files = new Set;
|
|
9596
9746
|
for (const int of interfaces) {
|
|
9597
9747
|
const types6 = await generateInterfaceTypes(int, integrationsWithAlias);
|
|
9598
|
-
imports.add(`import { ${types6.names.typings.index} } from "./${
|
|
9748
|
+
imports.add(`import { ${types6.names.typings.index} } from "./${path42.join("interfaces", types6.names.paths.index).replace(/\\/g, "/")}";`);
|
|
9599
9749
|
aliases.add(`"${types6.names.name}": ${types6.names.typings.index}`);
|
|
9600
9750
|
for (const [filePath, content] of Object.entries(types6.files)) {
|
|
9601
|
-
const fullPath =
|
|
9602
|
-
const dir =
|
|
9751
|
+
const fullPath = path42.join(this.projectPath, ".adk", "interfaces", filePath);
|
|
9752
|
+
const dir = path42.dirname(fullPath);
|
|
9603
9753
|
await fs19.mkdir(dir, { recursive: true });
|
|
9604
9754
|
await createFile(fullPath, content);
|
|
9605
9755
|
files.add(filePath);
|
|
@@ -9636,12 +9786,12 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9636
9786
|
`)}
|
|
9637
9787
|
};
|
|
9638
9788
|
`;
|
|
9639
|
-
await createFile(
|
|
9640
|
-
await createFile(
|
|
9789
|
+
await createFile(path42.join(this.projectPath, ".adk", "interfaces.d.ts"), await formatCode(types5));
|
|
9790
|
+
await createFile(path42.join(this.projectPath, ".adk", "interfaces.ts"), await formatCode(consts));
|
|
9641
9791
|
const staleInterfaceFiles = existingInterfaceFiles.filter((f) => !files.has(f));
|
|
9642
9792
|
if (staleInterfaceFiles.length > 0) {
|
|
9643
9793
|
for (const rel of staleInterfaceFiles) {
|
|
9644
|
-
const abs =
|
|
9794
|
+
const abs = path42.join(interfacesDir, rel);
|
|
9645
9795
|
try {
|
|
9646
9796
|
await fs19.rm(abs, { force: true });
|
|
9647
9797
|
} catch {}
|
|
@@ -9671,7 +9821,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9671
9821
|
`) : ""}
|
|
9672
9822
|
} as Record<string, IntegrationPackage>;
|
|
9673
9823
|
`;
|
|
9674
|
-
await createFile(
|
|
9824
|
+
await createFile(path42.join(this.outputPath, "src", "integrations.ts"), content);
|
|
9675
9825
|
}
|
|
9676
9826
|
async generatePluginsDefinition() {
|
|
9677
9827
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -9695,7 +9845,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9695
9845
|
`) : ""}
|
|
9696
9846
|
} as Record<string, PluginPackage>;
|
|
9697
9847
|
`;
|
|
9698
|
-
await createFile(
|
|
9848
|
+
await createFile(path42.join(this.outputPath, "src", "plugins.ts"), content);
|
|
9699
9849
|
}
|
|
9700
9850
|
async generateInterfacesDefinition() {
|
|
9701
9851
|
const interfaces = BUILTIN_INTERFACES;
|
|
@@ -9718,7 +9868,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9718
9868
|
`) : ""}
|
|
9719
9869
|
} as Record<string, InterfacePackage>;
|
|
9720
9870
|
`;
|
|
9721
|
-
await createFile(
|
|
9871
|
+
await createFile(path42.join(this.outputPath, "src", "interfaces.ts"), await formatCode(content));
|
|
9722
9872
|
}
|
|
9723
9873
|
reportServerConfigSync(label, serverConfigResult, items) {
|
|
9724
9874
|
if (!this.callbacks) {
|
|
@@ -9829,7 +9979,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9829
9979
|
if (isBuiltinWorkflow3(workflow.definition.name)) {
|
|
9830
9980
|
continue;
|
|
9831
9981
|
}
|
|
9832
|
-
const workflowPath =
|
|
9982
|
+
const workflowPath = path42.join(project.path, workflow.path);
|
|
9833
9983
|
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
9834
9984
|
const workflowInstance = workflowModule.default || workflowModule[workflow.export];
|
|
9835
9985
|
if (workflowInstance) {
|
|
@@ -10113,7 +10263,7 @@ secrets: ${secretsDef},
|
|
|
10113
10263
|
const fullContent = content + integrationsSection + pluginsSection + `
|
|
10114
10264
|
|
|
10115
10265
|
export default bot;`;
|
|
10116
|
-
await createFile(
|
|
10266
|
+
await createFile(path42.join(this.outputPath, "bot.definition.ts"), await formatCode(fullContent));
|
|
10117
10267
|
}
|
|
10118
10268
|
async generateBotIndex() {
|
|
10119
10269
|
const content = dedent`
|
|
@@ -10152,7 +10302,7 @@ export default bot;`;
|
|
|
10152
10302
|
|
|
10153
10303
|
export default bot
|
|
10154
10304
|
`;
|
|
10155
|
-
await createFile(
|
|
10305
|
+
await createFile(path42.join(this.outputPath, "src", "index.ts"), await formatCode(content));
|
|
10156
10306
|
}
|
|
10157
10307
|
async generatePackageJson(project) {
|
|
10158
10308
|
const packageJson = {
|
|
@@ -10166,7 +10316,7 @@ export default bot;`;
|
|
|
10166
10316
|
typescript: "^5.9.3"
|
|
10167
10317
|
}
|
|
10168
10318
|
};
|
|
10169
|
-
await createFile(
|
|
10319
|
+
await createFile(path42.join(this.outputPath, "package.json"), JSON.stringify(packageJson, null, 2));
|
|
10170
10320
|
}
|
|
10171
10321
|
async generateTsConfig() {
|
|
10172
10322
|
const tsConfig = {
|
|
@@ -10199,7 +10349,7 @@ export default bot;`;
|
|
|
10199
10349
|
},
|
|
10200
10350
|
include: [".botpress/**/*", "src/**/*", "bp_modules/**/*", "./*.ts", "./*.json", "../*.d.ts"]
|
|
10201
10351
|
};
|
|
10202
|
-
await createFile(
|
|
10352
|
+
await createFile(path42.join(this.outputPath, "tsconfig.json"), JSON.stringify(tsConfig, null, 2));
|
|
10203
10353
|
}
|
|
10204
10354
|
async generateGlobalTypes() {
|
|
10205
10355
|
const content = dedent`
|
|
@@ -10222,11 +10372,11 @@ export default bot;`;
|
|
|
10222
10372
|
|
|
10223
10373
|
export {};
|
|
10224
10374
|
`;
|
|
10225
|
-
await createFile(
|
|
10375
|
+
await createFile(path42.join(this.outputPath, "global.d.ts"), await formatCode(content));
|
|
10226
10376
|
}
|
|
10227
10377
|
async copyAssets() {
|
|
10228
|
-
const assetsPath =
|
|
10229
|
-
const targetPath =
|
|
10378
|
+
const assetsPath = path42.join(this.projectPath, "assets");
|
|
10379
|
+
const targetPath = path42.join(this.outputPath, "assets");
|
|
10230
10380
|
if (existsSync9(assetsPath)) {
|
|
10231
10381
|
await fs19.mkdir(targetPath, { recursive: true });
|
|
10232
10382
|
await this.copyDirectory(assetsPath, targetPath);
|
|
@@ -10235,8 +10385,8 @@ export default bot;`;
|
|
|
10235
10385
|
async copyDirectory(src, dest) {
|
|
10236
10386
|
const entries = await fs19.readdir(src, { withFileTypes: true });
|
|
10237
10387
|
for (const entry of entries) {
|
|
10238
|
-
const srcPath =
|
|
10239
|
-
const destPath =
|
|
10388
|
+
const srcPath = path42.join(src, entry.name);
|
|
10389
|
+
const destPath = path42.join(dest, entry.name);
|
|
10240
10390
|
if (entry.isDirectory()) {
|
|
10241
10391
|
await fs19.mkdir(destPath, { recursive: true });
|
|
10242
10392
|
await this.copyDirectory(srcPath, destPath);
|
|
@@ -10248,16 +10398,16 @@ export default bot;`;
|
|
|
10248
10398
|
async generateAdkRuntime() {
|
|
10249
10399
|
const project = new AgentProject(this.projectPath);
|
|
10250
10400
|
await project.reload();
|
|
10251
|
-
const srcDir =
|
|
10401
|
+
const srcDir = path42.join(this.outputPath, "src");
|
|
10252
10402
|
{
|
|
10253
|
-
const dest =
|
|
10403
|
+
const dest = path42.join(srcDir, "conversations.ts");
|
|
10254
10404
|
const imports = new Map;
|
|
10255
10405
|
const exports = new Set;
|
|
10256
10406
|
let index = 1;
|
|
10257
10407
|
for (const conversation of project.conversations) {
|
|
10258
10408
|
if (!imports.has(conversation.path)) {
|
|
10259
10409
|
const name = `conversations_${index++}`;
|
|
10260
|
-
const importPath = getImportPath(dest,
|
|
10410
|
+
const importPath = getImportPath(dest, path42.join(project.path, conversation.path));
|
|
10261
10411
|
imports.set(conversation.path, {
|
|
10262
10412
|
name,
|
|
10263
10413
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10283,14 +10433,14 @@ export default bot;`;
|
|
|
10283
10433
|
await createFile(dest, await formatCode(content2));
|
|
10284
10434
|
}
|
|
10285
10435
|
{
|
|
10286
|
-
const dest =
|
|
10436
|
+
const dest = path42.join(srcDir, "knowledge.ts");
|
|
10287
10437
|
const imports = new Map;
|
|
10288
10438
|
const exports = new Set;
|
|
10289
10439
|
let index = 1;
|
|
10290
10440
|
for (const knowledge of project.knowledge) {
|
|
10291
10441
|
if (!imports.has(knowledge.path)) {
|
|
10292
10442
|
const name = `knowledge_${index++}`;
|
|
10293
|
-
const importPath = getImportPath(dest,
|
|
10443
|
+
const importPath = getImportPath(dest, path42.join(project.path, knowledge.path));
|
|
10294
10444
|
imports.set(knowledge.path, {
|
|
10295
10445
|
name,
|
|
10296
10446
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10316,14 +10466,14 @@ export default bot;`;
|
|
|
10316
10466
|
await createFile(dest, await formatCode(content2));
|
|
10317
10467
|
}
|
|
10318
10468
|
{
|
|
10319
|
-
const dest =
|
|
10469
|
+
const dest = path42.join(srcDir, "custom-components.ts");
|
|
10320
10470
|
const imports = new Map;
|
|
10321
10471
|
const exports = new Set;
|
|
10322
10472
|
let index = 1;
|
|
10323
10473
|
for (const comp of project.customComponents) {
|
|
10324
10474
|
if (!imports.has(comp.path)) {
|
|
10325
10475
|
const name = `components_${index++}`;
|
|
10326
|
-
const importPath = getImportPath(dest,
|
|
10476
|
+
const importPath = getImportPath(dest, path42.join(project.path, comp.path));
|
|
10327
10477
|
imports.set(comp.path, {
|
|
10328
10478
|
name,
|
|
10329
10479
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10349,7 +10499,7 @@ export default bot;`;
|
|
|
10349
10499
|
await createFile(dest, await formatCode(content2));
|
|
10350
10500
|
}
|
|
10351
10501
|
{
|
|
10352
|
-
const dest =
|
|
10502
|
+
const dest = path42.join(srcDir, "triggers.ts");
|
|
10353
10503
|
const {
|
|
10354
10504
|
z: { transforms: transforms5 }
|
|
10355
10505
|
} = await import("@botpress/sdk");
|
|
@@ -10360,7 +10510,7 @@ export default bot;`;
|
|
|
10360
10510
|
for (const trigger of project.triggers) {
|
|
10361
10511
|
if (!imports.has(trigger.path)) {
|
|
10362
10512
|
const name = `triggers_${index++}`;
|
|
10363
|
-
const importPath = getImportPath(dest,
|
|
10513
|
+
const importPath = getImportPath(dest, path42.join(project.path, trigger.path));
|
|
10364
10514
|
imports.set(trigger.path, {
|
|
10365
10515
|
name,
|
|
10366
10516
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10370,7 +10520,7 @@ export default bot;`;
|
|
|
10370
10520
|
}
|
|
10371
10521
|
for (const trigger of project.triggers) {
|
|
10372
10522
|
try {
|
|
10373
|
-
const absolutePath =
|
|
10523
|
+
const absolutePath = path42.join(project.path, trigger.path);
|
|
10374
10524
|
const triggerModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
10375
10525
|
const triggerInstance = triggerModule[trigger.export] || triggerModule.default;
|
|
10376
10526
|
if (triggerInstance && triggerInstance.payload) {
|
|
@@ -10413,7 +10563,7 @@ export default bot;`;
|
|
|
10413
10563
|
await createFile(dest, await formatCode(content2));
|
|
10414
10564
|
}
|
|
10415
10565
|
{
|
|
10416
|
-
const dest =
|
|
10566
|
+
const dest = path42.join(srcDir, "workflows.ts");
|
|
10417
10567
|
const imports = new Map;
|
|
10418
10568
|
const exports = new Set;
|
|
10419
10569
|
let index = 1;
|
|
@@ -10423,7 +10573,7 @@ export default bot;`;
|
|
|
10423
10573
|
}
|
|
10424
10574
|
if (!imports.has(workflow.path)) {
|
|
10425
10575
|
const name = `workflows_${index++}`;
|
|
10426
|
-
const importPath = getImportPath(dest,
|
|
10576
|
+
const importPath = getImportPath(dest, path42.join(project.path, workflow.path));
|
|
10427
10577
|
const statement = `import * as ${name} from "${importPath}";`;
|
|
10428
10578
|
imports.set(workflow.path, {
|
|
10429
10579
|
name,
|
|
@@ -10457,7 +10607,7 @@ export default bot;`;
|
|
|
10457
10607
|
await createFile(dest, await formatCode(content2));
|
|
10458
10608
|
}
|
|
10459
10609
|
{
|
|
10460
|
-
const dest =
|
|
10610
|
+
const dest = path42.join(srcDir, "actions.ts");
|
|
10461
10611
|
const imports = new Map;
|
|
10462
10612
|
const exports = new Set;
|
|
10463
10613
|
let index = 1;
|
|
@@ -10467,7 +10617,7 @@ export default bot;`;
|
|
|
10467
10617
|
}
|
|
10468
10618
|
if (!imports.has(action.path)) {
|
|
10469
10619
|
const name = `actions_${index++}`;
|
|
10470
|
-
const importPath = getImportPath(dest,
|
|
10620
|
+
const importPath = getImportPath(dest, path42.join(project.path, action.path));
|
|
10471
10621
|
imports.set(action.path, {
|
|
10472
10622
|
name,
|
|
10473
10623
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10493,14 +10643,14 @@ export default bot;`;
|
|
|
10493
10643
|
await createFile(dest, await formatCode(content2));
|
|
10494
10644
|
}
|
|
10495
10645
|
{
|
|
10496
|
-
const dest =
|
|
10646
|
+
const dest = path42.join(srcDir, "tables.ts");
|
|
10497
10647
|
const imports = new Map;
|
|
10498
10648
|
const exports = new Set;
|
|
10499
10649
|
let index = 1;
|
|
10500
10650
|
for (const table of project.tables) {
|
|
10501
10651
|
if (!imports.has(table.path)) {
|
|
10502
10652
|
const name = `tables_${index++}`;
|
|
10503
|
-
const importPath = getImportPath(dest,
|
|
10653
|
+
const importPath = getImportPath(dest, path42.join(project.path, table.path));
|
|
10504
10654
|
imports.set(table.path, {
|
|
10505
10655
|
name,
|
|
10506
10656
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10526,8 +10676,8 @@ export default bot;`;
|
|
|
10526
10676
|
await createFile(dest, await formatCode(content2));
|
|
10527
10677
|
}
|
|
10528
10678
|
{
|
|
10529
|
-
const dest =
|
|
10530
|
-
const importPath = getImportPath(dest,
|
|
10679
|
+
const dest = path42.join(srcDir, "config.ts");
|
|
10680
|
+
const importPath = getImportPath(dest, path42.join(project.path, "agent.config.ts"));
|
|
10531
10681
|
const content2 = `
|
|
10532
10682
|
////////////////////////////////////////////////////////
|
|
10533
10683
|
// DO NOT EDIT THIS FILE DIRECTLY
|
|
@@ -10605,10 +10755,10 @@ export default bot;`;
|
|
|
10605
10755
|
handlers.plugins.setup(bot);
|
|
10606
10756
|
}
|
|
10607
10757
|
`;
|
|
10608
|
-
await createFile(
|
|
10758
|
+
await createFile(path42.join(this.outputPath, "src", "adk-runtime.ts"), await formatCode(content));
|
|
10609
10759
|
}
|
|
10610
10760
|
async generateComponentUrlsBlock() {
|
|
10611
|
-
const manifestPath =
|
|
10761
|
+
const manifestPath = path42.join(this.projectPath, ".adk", "components.manifest.json");
|
|
10612
10762
|
try {
|
|
10613
10763
|
if (!existsSync9(manifestPath)) {
|
|
10614
10764
|
return "const componentUrls: Record<string, string> = {};";
|
|
@@ -10624,10 +10774,10 @@ export default bot;`;
|
|
|
10624
10774
|
}
|
|
10625
10775
|
}
|
|
10626
10776
|
async copyAssetsRuntime() {
|
|
10627
|
-
const assetsRuntimePath =
|
|
10777
|
+
const assetsRuntimePath = path42.join(this.projectPath, ".adk", "assets-runtime.ts");
|
|
10628
10778
|
if (existsSync9(assetsRuntimePath)) {
|
|
10629
10779
|
const content = await fs19.readFile(assetsRuntimePath, "utf-8");
|
|
10630
|
-
await createFile(
|
|
10780
|
+
await createFile(path42.join(this.outputPath, "src", "assets-runtime.ts"), await formatCode(content));
|
|
10631
10781
|
}
|
|
10632
10782
|
}
|
|
10633
10783
|
}
|
|
@@ -10636,11 +10786,11 @@ async function generateBotProject(options) {
|
|
|
10636
10786
|
await generator.generate();
|
|
10637
10787
|
await generator.generateAdkRuntime();
|
|
10638
10788
|
await generator.copyAssetsRuntime();
|
|
10639
|
-
const botPath = options.outputPath ||
|
|
10789
|
+
const botPath = options.outputPath || path42.join(options.projectPath, ".adk", "bot");
|
|
10640
10790
|
await linkSdk(options.projectPath, botPath);
|
|
10641
|
-
const devIdManager = new DevIdManager(options.projectPath, options.outputPath ||
|
|
10791
|
+
const devIdManager = new DevIdManager(options.projectPath, options.outputPath || path42.join(options.projectPath, ".adk", "bot"));
|
|
10642
10792
|
await devIdManager.restoreDevId();
|
|
10643
|
-
const integrationSync = new IntegrationSync(options.projectPath, options.outputPath ||
|
|
10793
|
+
const integrationSync = new IntegrationSync(options.projectPath, options.outputPath || path42.join(options.projectPath, ".adk", "bot"));
|
|
10644
10794
|
const integrationSyncResult = await integrationSync.syncIntegrations();
|
|
10645
10795
|
if (integrationSyncResult.errors.length > 0) {
|
|
10646
10796
|
console.warn(`⚠️ Some integrations failed to sync:`);
|
|
@@ -10648,7 +10798,7 @@ async function generateBotProject(options) {
|
|
|
10648
10798
|
console.warn(` - ${alias}: ${error}`);
|
|
10649
10799
|
});
|
|
10650
10800
|
}
|
|
10651
|
-
const interfaceSync = new InterfaceSync(options.projectPath, options.outputPath ||
|
|
10801
|
+
const interfaceSync = new InterfaceSync(options.projectPath, options.outputPath || path42.join(options.projectPath, ".adk", "bot"));
|
|
10652
10802
|
const interfaceSyncResult = await interfaceSync.syncInterfaces();
|
|
10653
10803
|
if (interfaceSyncResult.errors.length > 0) {
|
|
10654
10804
|
console.warn(`⚠️ Some interfaces failed to sync:`);
|
|
@@ -10656,7 +10806,7 @@ async function generateBotProject(options) {
|
|
|
10656
10806
|
console.warn(` - ${alias}: ${error}`);
|
|
10657
10807
|
});
|
|
10658
10808
|
}
|
|
10659
|
-
const pluginSync = new PluginSync(options.projectPath, options.outputPath ||
|
|
10809
|
+
const pluginSync = new PluginSync(options.projectPath, options.outputPath || path42.join(options.projectPath, ".adk", "bot"));
|
|
10660
10810
|
const pluginSyncResult = await pluginSync.syncPlugins();
|
|
10661
10811
|
if (pluginSyncResult.errors.length > 0) {
|
|
10662
10812
|
console.warn(`⚠️ Some plugins failed to sync:`);
|
|
@@ -11172,7 +11322,7 @@ class TableManager {
|
|
|
11172
11322
|
// src/knowledge/manager.ts
|
|
11173
11323
|
init_auth();
|
|
11174
11324
|
import crypto6 from "crypto";
|
|
11175
|
-
import
|
|
11325
|
+
import path43 from "path";
|
|
11176
11326
|
import fs20 from "fs/promises";
|
|
11177
11327
|
import { glob } from "glob";
|
|
11178
11328
|
import { Client as Client16 } from "@botpress/client";
|
|
@@ -11624,14 +11774,14 @@ class KnowledgeManager {
|
|
|
11624
11774
|
}
|
|
11625
11775
|
async scanLocalFileHashes(directoryPath, filterFn) {
|
|
11626
11776
|
const projectDir = this.project.path;
|
|
11627
|
-
const directory =
|
|
11777
|
+
const directory = path43.resolve(projectDir, directoryPath);
|
|
11628
11778
|
if (this.fileHashCache.has(directory)) {
|
|
11629
11779
|
return this.fileHashCache.get(directory);
|
|
11630
11780
|
}
|
|
11631
11781
|
const files = glob.sync(directory + "/**/*.*", { absolute: true, nodir: true }).filter((file) => !filterFn || filterFn(file));
|
|
11632
11782
|
const hashes = {};
|
|
11633
11783
|
for (const file of files) {
|
|
11634
|
-
const relPath =
|
|
11784
|
+
const relPath = path43.relative(directory, file);
|
|
11635
11785
|
const content = await fs20.readFile(file);
|
|
11636
11786
|
hashes[relPath] = crypto6.createHash("sha256").update(content).digest("hex");
|
|
11637
11787
|
}
|
|
@@ -11767,7 +11917,7 @@ class KnowledgeManager {
|
|
|
11767
11917
|
}
|
|
11768
11918
|
async syncDirectorySource(client, kbName, kbId, dsId, directoryPath, filterFn, force) {
|
|
11769
11919
|
const projectDir = this.project.path;
|
|
11770
|
-
const directory =
|
|
11920
|
+
const directory = path43.resolve(projectDir, directoryPath);
|
|
11771
11921
|
if (!directory.startsWith(projectDir)) {
|
|
11772
11922
|
throw new Error("Directory path must be within the agent's directory");
|
|
11773
11923
|
}
|
|
@@ -11789,8 +11939,8 @@ class KnowledgeManager {
|
|
|
11789
11939
|
return true;
|
|
11790
11940
|
}).map((f) => ({
|
|
11791
11941
|
abs: f,
|
|
11792
|
-
rel:
|
|
11793
|
-
name:
|
|
11942
|
+
rel: path43.relative(directory, f),
|
|
11943
|
+
name: path43.basename(f)
|
|
11794
11944
|
}));
|
|
11795
11945
|
console.log(` Found ${allFiles.length} files in ${directoryPath}`);
|
|
11796
11946
|
const cachedHashes = await this.scanLocalFileHashes(directoryPath, filterFn);
|
|
@@ -11872,7 +12022,7 @@ class KnowledgeManager {
|
|
|
11872
12022
|
return null;
|
|
11873
12023
|
}
|
|
11874
12024
|
} catch {}
|
|
11875
|
-
const title =
|
|
12025
|
+
const title = path43.basename(local.name, path43.extname(local.name));
|
|
11876
12026
|
const metadata = {
|
|
11877
12027
|
hash,
|
|
11878
12028
|
dsId,
|
|
@@ -11897,7 +12047,7 @@ class KnowledgeManager {
|
|
|
11897
12047
|
}
|
|
11898
12048
|
}
|
|
11899
12049
|
// src/knowledge/sync-formatter.ts
|
|
11900
|
-
import { readFileSync as
|
|
12050
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
11901
12051
|
import { join as join10 } from "path";
|
|
11902
12052
|
var getAdkVersion = () => {
|
|
11903
12053
|
try {
|
|
@@ -11906,7 +12056,7 @@ var getAdkVersion = () => {
|
|
|
11906
12056
|
} catch {
|
|
11907
12057
|
try {
|
|
11908
12058
|
const adkPackagePath = join10(process.cwd(), "node_modules/@botpress/adk/package.json");
|
|
11909
|
-
const pkg = JSON.parse(
|
|
12059
|
+
const pkg = JSON.parse(readFileSync5(adkPackagePath, "utf-8"));
|
|
11910
12060
|
return pkg.version;
|
|
11911
12061
|
} catch {
|
|
11912
12062
|
return "unknown";
|
|
@@ -12180,7 +12330,7 @@ init_auth();
|
|
|
12180
12330
|
init_checker();
|
|
12181
12331
|
init_sync_manager();
|
|
12182
12332
|
import { Client as Client17 } from "@botpress/client";
|
|
12183
|
-
import
|
|
12333
|
+
import path44 from "path";
|
|
12184
12334
|
|
|
12185
12335
|
// src/preflight/types.ts
|
|
12186
12336
|
function hasIntegrationChanges(integrations) {
|
|
@@ -12237,7 +12387,7 @@ class AgentConfigSyncManager {
|
|
|
12237
12387
|
}
|
|
12238
12388
|
|
|
12239
12389
|
// src/preflight/formatter.ts
|
|
12240
|
-
import { readFileSync as
|
|
12390
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
12241
12391
|
import { join as join12 } from "path";
|
|
12242
12392
|
var getAdkVersion2 = () => {
|
|
12243
12393
|
try {
|
|
@@ -12246,7 +12396,7 @@ var getAdkVersion2 = () => {
|
|
|
12246
12396
|
} catch {
|
|
12247
12397
|
try {
|
|
12248
12398
|
const adkPackagePath = join12(process.cwd(), "node_modules/@botpress/adk/package.json");
|
|
12249
|
-
const pkg = JSON.parse(
|
|
12399
|
+
const pkg = JSON.parse(readFileSync6(adkPackagePath, "utf-8"));
|
|
12250
12400
|
return pkg.version;
|
|
12251
12401
|
} catch {
|
|
12252
12402
|
return "unknown";
|
|
@@ -12598,7 +12748,7 @@ class PreflightChecker {
|
|
|
12598
12748
|
options?.onProgress?.("Regenerating bot project...");
|
|
12599
12749
|
await generateBotProject({
|
|
12600
12750
|
projectPath: this.projectPath,
|
|
12601
|
-
outputPath:
|
|
12751
|
+
outputPath: path44.join(this.projectPath, ".adk", "bot"),
|
|
12602
12752
|
callbacks: options
|
|
12603
12753
|
});
|
|
12604
12754
|
options?.onSuccess?.("Bot project regenerated");
|
|
@@ -12608,19 +12758,19 @@ class PreflightChecker {
|
|
|
12608
12758
|
import dedent2 from "dedent";
|
|
12609
12759
|
import { existsSync as existsSync11 } from "fs";
|
|
12610
12760
|
import fs21 from "fs/promises";
|
|
12611
|
-
import
|
|
12761
|
+
import path45 from "path";
|
|
12612
12762
|
import { spawn as spawn2 } from "child_process";
|
|
12613
12763
|
init_utils();
|
|
12614
12764
|
init_credentials();
|
|
12615
12765
|
async function findAgentRoot(startPath) {
|
|
12616
|
-
let currentPath =
|
|
12617
|
-
const root =
|
|
12766
|
+
let currentPath = path45.resolve(startPath);
|
|
12767
|
+
const root = path45.parse(currentPath).root;
|
|
12618
12768
|
while (currentPath !== root) {
|
|
12619
12769
|
try {
|
|
12620
|
-
await fs21.access(
|
|
12770
|
+
await fs21.access(path45.join(currentPath, "agent.config.ts"));
|
|
12621
12771
|
return currentPath;
|
|
12622
12772
|
} catch {
|
|
12623
|
-
currentPath =
|
|
12773
|
+
currentPath = path45.dirname(currentPath);
|
|
12624
12774
|
}
|
|
12625
12775
|
}
|
|
12626
12776
|
return null;
|
|
@@ -12632,7 +12782,7 @@ class ScriptRunner {
|
|
|
12632
12782
|
prod;
|
|
12633
12783
|
credentials;
|
|
12634
12784
|
constructor(options) {
|
|
12635
|
-
this.projectPath =
|
|
12785
|
+
this.projectPath = path45.resolve(options.projectPath);
|
|
12636
12786
|
this.forceRegenerate = options.forceRegenerate ?? false;
|
|
12637
12787
|
this.prod = options.prod ?? false;
|
|
12638
12788
|
this.credentials = options.credentials;
|
|
@@ -12641,9 +12791,9 @@ class ScriptRunner {
|
|
|
12641
12791
|
const project = await AgentProject.load(this.projectPath, {
|
|
12642
12792
|
adkCommand: "adk-build"
|
|
12643
12793
|
});
|
|
12644
|
-
const botPath =
|
|
12645
|
-
const runnerPath =
|
|
12646
|
-
const botpressTypesPath =
|
|
12794
|
+
const botPath = path45.join(this.projectPath, ".adk", "bot");
|
|
12795
|
+
const runnerPath = path45.join(botPath, "src", "script-runner.ts");
|
|
12796
|
+
const botpressTypesPath = path45.join(botPath, ".botpress", "implementation", "index.ts");
|
|
12647
12797
|
const needsRegenerate = this.forceRegenerate || !existsSync11(runnerPath) || !existsSync11(botpressTypesPath);
|
|
12648
12798
|
if (needsRegenerate) {
|
|
12649
12799
|
try {
|
|
@@ -12661,8 +12811,8 @@ class ScriptRunner {
|
|
|
12661
12811
|
}
|
|
12662
12812
|
async runBpBuild(botPath) {
|
|
12663
12813
|
const buildCommand = new BpBuildCommand({ botPath });
|
|
12664
|
-
return new Promise((
|
|
12665
|
-
buildCommand.on("done", () =>
|
|
12814
|
+
return new Promise((resolve5, reject) => {
|
|
12815
|
+
buildCommand.on("done", () => resolve5());
|
|
12666
12816
|
buildCommand.on("error", (err) => reject(new Error(err.message)));
|
|
12667
12817
|
buildCommand.run();
|
|
12668
12818
|
});
|
|
@@ -12760,7 +12910,7 @@ class ScriptRunner {
|
|
|
12760
12910
|
|
|
12761
12911
|
runScript()
|
|
12762
12912
|
`;
|
|
12763
|
-
await fs21.writeFile(
|
|
12913
|
+
await fs21.writeFile(path45.join(botPath, "src", "script-runner.ts"), await formatCode(content), "utf-8");
|
|
12764
12914
|
}
|
|
12765
12915
|
async setupTestRuntime(options = {}) {
|
|
12766
12916
|
const { botPath, project } = await this.prepare();
|
|
@@ -12791,7 +12941,7 @@ class ScriptRunner {
|
|
|
12791
12941
|
for (const [key, value] of Object.entries(envVars)) {
|
|
12792
12942
|
process.env[key] = value;
|
|
12793
12943
|
}
|
|
12794
|
-
const runtimePath =
|
|
12944
|
+
const runtimePath = path45.join(botPath, "src", "index.ts");
|
|
12795
12945
|
return {
|
|
12796
12946
|
botPath,
|
|
12797
12947
|
runtimePath,
|
|
@@ -12839,7 +12989,7 @@ class ScriptRunner {
|
|
|
12839
12989
|
}
|
|
12840
12990
|
async run(scriptPath, options = {}) {
|
|
12841
12991
|
const { botPath, runnerPath, project } = await this.prepare();
|
|
12842
|
-
const absoluteScriptPath =
|
|
12992
|
+
const absoluteScriptPath = path45.isAbsolute(scriptPath) ? scriptPath : path45.resolve(this.projectPath, scriptPath);
|
|
12843
12993
|
if (!existsSync11(absoluteScriptPath)) {
|
|
12844
12994
|
throw new Error(`Script not found: ${absoluteScriptPath}`);
|
|
12845
12995
|
}
|
|
@@ -12870,7 +13020,7 @@ class ScriptRunner {
|
|
|
12870
13020
|
ADK_API_URL: this.credentials.apiUrl,
|
|
12871
13021
|
...configuration && { ADK_CONFIGURATION: JSON.stringify(configuration) }
|
|
12872
13022
|
};
|
|
12873
|
-
return new Promise((
|
|
13023
|
+
return new Promise((resolve5, reject) => {
|
|
12874
13024
|
const child = spawn2("bun", args, {
|
|
12875
13025
|
cwd: botPath,
|
|
12876
13026
|
env,
|
|
@@ -12880,7 +13030,7 @@ class ScriptRunner {
|
|
|
12880
13030
|
reject(error);
|
|
12881
13031
|
});
|
|
12882
13032
|
child.on("close", (code) => {
|
|
12883
|
-
|
|
13033
|
+
resolve5(code ?? 0);
|
|
12884
13034
|
});
|
|
12885
13035
|
});
|
|
12886
13036
|
}
|
|
@@ -12928,1293 +13078,17 @@ Either run from within an agent project directory, or provide projectPath explic
|
|
|
12928
13078
|
});
|
|
12929
13079
|
return runner.setupTestRuntime({ env: options.env });
|
|
12930
13080
|
}
|
|
12931
|
-
// src/eval/types.ts
|
|
12932
|
-
class Eval {
|
|
12933
|
-
name;
|
|
12934
|
-
description;
|
|
12935
|
-
tags;
|
|
12936
|
-
type;
|
|
12937
|
-
setup;
|
|
12938
|
-
conversation;
|
|
12939
|
-
outcome;
|
|
12940
|
-
options;
|
|
12941
|
-
constructor(def) {
|
|
12942
|
-
this.name = def.name;
|
|
12943
|
-
this.description = def.description;
|
|
12944
|
-
this.tags = def.tags;
|
|
12945
|
-
this.type = def.type;
|
|
12946
|
-
this.setup = def.setup;
|
|
12947
|
-
this.conversation = def.conversation;
|
|
12948
|
-
this.outcome = def.outcome;
|
|
12949
|
-
this.options = def.options;
|
|
12950
|
-
}
|
|
12951
|
-
}
|
|
12952
|
-
// src/eval/loader.ts
|
|
12953
|
-
import { readdirSync as readdirSync3, existsSync as existsSync12 } from "fs";
|
|
12954
|
-
import { resolve as resolve4 } from "path";
|
|
12955
|
-
function isEvalDefinition(value) {
|
|
12956
|
-
return value !== null && typeof value === "object" && typeof value.name === "string" && value.name !== "" && Array.isArray(value.conversation);
|
|
12957
|
-
}
|
|
12958
|
-
async function loadEvalFile(filePath) {
|
|
12959
|
-
const absPath = resolve4(filePath);
|
|
12960
|
-
const mod = await import(absPath);
|
|
12961
|
-
const results = [];
|
|
12962
|
-
for (const [key, value] of Object.entries(mod)) {
|
|
12963
|
-
if (key === "__esModule")
|
|
12964
|
-
continue;
|
|
12965
|
-
if (value instanceof Eval || isEvalDefinition(value)) {
|
|
12966
|
-
results.push(value);
|
|
12967
|
-
}
|
|
12968
|
-
}
|
|
12969
|
-
if (results.length === 0) {
|
|
12970
|
-
throw new Error(`Invalid eval file ${filePath}: no valid evals found. Export one or more \`new Eval({...})\` instances (as default or named exports).`);
|
|
12971
|
-
}
|
|
12972
|
-
return results;
|
|
12973
|
-
}
|
|
12974
|
-
async function loadEvalsFromDir(dirPath) {
|
|
12975
|
-
const absDir = resolve4(dirPath);
|
|
12976
|
-
if (!existsSync12(absDir)) {
|
|
12977
|
-
return [];
|
|
12978
|
-
}
|
|
12979
|
-
const files = readdirSync3(absDir).filter((f) => f.endsWith(".eval.ts"));
|
|
12980
|
-
const evals = [];
|
|
12981
|
-
for (const f of files) {
|
|
12982
|
-
const defs = await loadEvalFile(`${absDir}/${f}`);
|
|
12983
|
-
evals.push(...defs);
|
|
12984
|
-
}
|
|
12985
|
-
const seen = new Set;
|
|
12986
|
-
for (const e of evals) {
|
|
12987
|
-
if (seen.has(e.name)) {
|
|
12988
|
-
throw new Error(`Duplicate eval name "${e.name}" found in ${dirPath}`);
|
|
12989
|
-
}
|
|
12990
|
-
seen.add(e.name);
|
|
12991
|
-
}
|
|
12992
|
-
return evals;
|
|
12993
|
-
}
|
|
12994
|
-
async function loadEvalByName(dirPath, name) {
|
|
12995
|
-
const absDir = resolve4(dirPath);
|
|
12996
|
-
if (!existsSync12(absDir))
|
|
12997
|
-
return null;
|
|
12998
|
-
const files = readdirSync3(absDir).filter((f) => f.endsWith(".eval.ts"));
|
|
12999
|
-
for (const f of files) {
|
|
13000
|
-
const defs = await loadEvalFile(`${absDir}/${f}`);
|
|
13001
|
-
const found = defs.find((d) => d.name === name);
|
|
13002
|
-
if (found)
|
|
13003
|
-
return found;
|
|
13004
|
-
}
|
|
13005
|
-
return null;
|
|
13006
|
-
}
|
|
13007
|
-
function filterEvals(evals, filter) {
|
|
13008
|
-
if (!filter)
|
|
13009
|
-
return evals;
|
|
13010
|
-
return evals.filter((e) => {
|
|
13011
|
-
if (filter.names && filter.names.length > 0) {
|
|
13012
|
-
if (!filter.names.includes(e.name))
|
|
13013
|
-
return false;
|
|
13014
|
-
}
|
|
13015
|
-
if (filter.tags && filter.tags.length > 0) {
|
|
13016
|
-
if (!e.tags || !filter.tags.some((t) => e.tags.includes(t)))
|
|
13017
|
-
return false;
|
|
13018
|
-
}
|
|
13019
|
-
if (filter.type) {
|
|
13020
|
-
if (e.type !== filter.type)
|
|
13021
|
-
return false;
|
|
13022
|
-
}
|
|
13023
|
-
return true;
|
|
13024
|
-
});
|
|
13025
|
-
}
|
|
13026
|
-
// src/eval/runner.ts
|
|
13027
|
-
import { Client as BpClient2 } from "@botpress/client";
|
|
13028
|
-
import { BUILT_IN_STATES as BUILT_IN_STATES2 } from "@botpress/runtime/internal";
|
|
13029
|
-
|
|
13030
|
-
// src/eval/client.ts
|
|
13031
|
-
import { Client as BpClient } from "@botpress/client";
|
|
13032
|
-
class ChatSession {
|
|
13033
|
-
webhookId;
|
|
13034
|
-
client = null;
|
|
13035
|
-
conversationId = null;
|
|
13036
|
-
constructor(webhookId) {
|
|
13037
|
-
this.webhookId = webhookId;
|
|
13038
|
-
}
|
|
13039
|
-
async connect() {
|
|
13040
|
-
const ChatClient = getChatClient();
|
|
13041
|
-
this.client = await ChatClient.connect({ webhookId: this.webhookId });
|
|
13042
|
-
}
|
|
13043
|
-
get userId() {
|
|
13044
|
-
if (!this.client) {
|
|
13045
|
-
throw new Error("ChatSession not connected. Call connect() first.");
|
|
13046
|
-
}
|
|
13047
|
-
return this.client.user.id;
|
|
13048
|
-
}
|
|
13049
|
-
async ensureConversation() {
|
|
13050
|
-
if (!this.client) {
|
|
13051
|
-
throw new Error("ChatSession not connected. Call connect() first.");
|
|
13052
|
-
}
|
|
13053
|
-
if (!this.conversationId) {
|
|
13054
|
-
const conv = await this.client.createConversation({});
|
|
13055
|
-
this.conversationId = conv.conversation.id;
|
|
13056
|
-
return conv.conversation.id;
|
|
13057
|
-
}
|
|
13058
|
-
return this.conversationId;
|
|
13059
|
-
}
|
|
13060
|
-
async _awaitResponses(conversationId, trigger, options = {}) {
|
|
13061
|
-
const { timeout = 30000, idleTimeout = 3000 } = options;
|
|
13062
|
-
const responses = [];
|
|
13063
|
-
const listener = await this.client.listenConversation({ id: conversationId });
|
|
13064
|
-
return new Promise((resolve5, reject) => {
|
|
13065
|
-
let idleTimer = null;
|
|
13066
|
-
let resolved = false;
|
|
13067
|
-
const done = () => {
|
|
13068
|
-
if (resolved)
|
|
13069
|
-
return;
|
|
13070
|
-
resolved = true;
|
|
13071
|
-
if (idleTimer)
|
|
13072
|
-
clearTimeout(idleTimer);
|
|
13073
|
-
clearTimeout(overallTimer);
|
|
13074
|
-
resolve5({ conversationId, responses });
|
|
13075
|
-
};
|
|
13076
|
-
const resetIdle = () => {
|
|
13077
|
-
if (idleTimer)
|
|
13078
|
-
clearTimeout(idleTimer);
|
|
13079
|
-
idleTimer = setTimeout(done, idleTimeout);
|
|
13080
|
-
};
|
|
13081
|
-
const overallTimer = setTimeout(() => {
|
|
13082
|
-
if (!resolved) {
|
|
13083
|
-
if (responses.length > 0 || options.expectSilence) {
|
|
13084
|
-
done();
|
|
13085
|
-
} else {
|
|
13086
|
-
resolved = true;
|
|
13087
|
-
reject(new Error(`Timed out after ${timeout}ms with no bot response.`));
|
|
13088
|
-
}
|
|
13089
|
-
}
|
|
13090
|
-
}, timeout);
|
|
13091
|
-
listener.on("message_created", (event) => {
|
|
13092
|
-
if (resolved)
|
|
13093
|
-
return;
|
|
13094
|
-
if (event.isBot) {
|
|
13095
|
-
const payload = event?.payload;
|
|
13096
|
-
const text = typeof payload === "string" ? payload : payload?.text || JSON.stringify(payload);
|
|
13097
|
-
responses.push({ text, raw: payload });
|
|
13098
|
-
resetIdle();
|
|
13099
|
-
}
|
|
13100
|
-
});
|
|
13101
|
-
listener.on("event_created", (event) => {
|
|
13102
|
-
if (event?.payload?.done) {
|
|
13103
|
-
done();
|
|
13104
|
-
}
|
|
13105
|
-
});
|
|
13106
|
-
trigger().then(() => {
|
|
13107
|
-
resetIdle();
|
|
13108
|
-
}).catch((err) => {
|
|
13109
|
-
clearTimeout(overallTimer);
|
|
13110
|
-
if (!resolved) {
|
|
13111
|
-
resolved = true;
|
|
13112
|
-
reject(err);
|
|
13113
|
-
}
|
|
13114
|
-
});
|
|
13115
|
-
});
|
|
13116
|
-
}
|
|
13117
|
-
async sendMessage(message, options = {}) {
|
|
13118
|
-
if (!this.client) {
|
|
13119
|
-
throw new Error("ChatSession not connected. Call connect() first.");
|
|
13120
|
-
}
|
|
13121
|
-
const conversationId = await this.ensureConversation();
|
|
13122
|
-
return this._awaitResponses(conversationId, () => this.client.createMessage({ conversationId, payload: { type: "text", text: message } }), options);
|
|
13123
|
-
}
|
|
13124
|
-
async sendEvent(type, payload, options = {}) {
|
|
13125
|
-
if (!this.client) {
|
|
13126
|
-
throw new Error("ChatSession not connected. Call connect() first.");
|
|
13127
|
-
}
|
|
13128
|
-
const conversationId = await this.ensureConversation();
|
|
13129
|
-
return this._awaitResponses(conversationId, () => this.client.createEvent({ type, payload, conversationId }), options);
|
|
13130
|
-
}
|
|
13131
|
-
}
|
|
13132
|
-
async function discoverWebhookId(botId, token, apiUrl) {
|
|
13133
|
-
const client = new BpClient({ token, botId, apiUrl });
|
|
13134
|
-
const { bot } = await client.getBot({ id: botId });
|
|
13135
|
-
const integrations = bot.integrations || {};
|
|
13136
|
-
const chat = Object.values(integrations).find((int) => int.name === "chat");
|
|
13137
|
-
const webhookId = chat?.webhookId;
|
|
13138
|
-
if (!webhookId || typeof webhookId !== "string") {
|
|
13139
|
-
throw new Error("No chat integration found on bot. Make sure the bot has the chat integration enabled.");
|
|
13140
|
-
}
|
|
13141
|
-
return webhookId;
|
|
13142
|
-
}
|
|
13143
|
-
|
|
13144
|
-
// src/eval/traces.ts
|
|
13145
|
-
async function fetchSpans(conversationId, devServerUrl) {
|
|
13146
|
-
const url = `${devServerUrl}/api/traces/query?attributeName=conversationId&attributeValue=${encodeURIComponent(conversationId)}&count=1000`;
|
|
13147
|
-
const res = await fetch(url);
|
|
13148
|
-
if (!res.ok) {
|
|
13149
|
-
throw new Error(`Failed to fetch traces: ${res.status} ${res.statusText}`);
|
|
13150
|
-
}
|
|
13151
|
-
const data = await res.json();
|
|
13152
|
-
return Array.isArray(data) ? data : data.spans || [];
|
|
13153
|
-
}
|
|
13154
|
-
function extractToolCalls(spans) {
|
|
13155
|
-
const data = (span) => span.data && typeof span.data === "object" ? span.data : {};
|
|
13156
|
-
const toolEndSpans = spans.filter((span) => span.name === "autonomous.tool" && (span.status === "ok" || span.status === "error") && data(span)["autonomous.tool.name"]);
|
|
13157
|
-
const seen = new Set;
|
|
13158
|
-
const unique = toolEndSpans.filter((span) => {
|
|
13159
|
-
if (seen.has(span.id.span))
|
|
13160
|
-
return false;
|
|
13161
|
-
seen.add(span.id.span);
|
|
13162
|
-
return true;
|
|
13163
|
-
});
|
|
13164
|
-
return unique.sort((a, b) => (a.timing.endedAt ?? 0) - (b.timing.endedAt ?? 0)).map((span) => {
|
|
13165
|
-
const d = data(span);
|
|
13166
|
-
let input = {};
|
|
13167
|
-
try {
|
|
13168
|
-
input = JSON.parse(d["autonomous.tool.input"]);
|
|
13169
|
-
} catch {}
|
|
13170
|
-
return {
|
|
13171
|
-
name: d["autonomous.tool.name"],
|
|
13172
|
-
input,
|
|
13173
|
-
output: d["autonomous.tool.output"] || "",
|
|
13174
|
-
status: d["autonomous.tool.status"] || "unknown"
|
|
13175
|
-
};
|
|
13176
|
-
});
|
|
13177
|
-
}
|
|
13178
|
-
async function getTraceData(conversationId, devServerUrl, options = {}) {
|
|
13179
|
-
const previousCount = options.previousToolCallCount || 0;
|
|
13180
|
-
const expectNew = options.expectNewCalls ?? false;
|
|
13181
|
-
const maxRetries = expectNew ? 5 : 0;
|
|
13182
|
-
const retryDelay = 500;
|
|
13183
|
-
let allToolCalls = [];
|
|
13184
|
-
let spans = [];
|
|
13185
|
-
for (let attempt = 0;attempt <= maxRetries; attempt++) {
|
|
13186
|
-
if (attempt > 0) {
|
|
13187
|
-
await new Promise((resolve5) => setTimeout(resolve5, retryDelay));
|
|
13188
|
-
}
|
|
13189
|
-
spans = await fetchSpans(conversationId, devServerUrl);
|
|
13190
|
-
allToolCalls = extractToolCalls(spans);
|
|
13191
|
-
if (!expectNew || allToolCalls.length > previousCount) {
|
|
13192
|
-
break;
|
|
13193
|
-
}
|
|
13194
|
-
}
|
|
13195
|
-
const toolCalls = allToolCalls.slice(previousCount);
|
|
13196
|
-
return { toolCalls, totalToolCallCount: allToolCalls.length, raw: spans };
|
|
13197
|
-
}
|
|
13198
|
-
|
|
13199
|
-
// src/eval/graders/llm.ts
|
|
13200
|
-
import { Cognitive } from "@botpress/runtime";
|
|
13201
|
-
import { Client as Client18 } from "@botpress/client";
|
|
13202
|
-
var DEFAULT_PASS_THRESHOLD = 3;
|
|
13203
|
-
function buildJudgeSystemPrompt(passThreshold) {
|
|
13204
|
-
return `You are an evaluation judge for a chatbot. You will be given:
|
|
13205
|
-
- The user's message
|
|
13206
|
-
- The bot's response
|
|
13207
|
-
- Grading criteria
|
|
13208
|
-
|
|
13209
|
-
Your job is to determine if the bot's response meets the criteria.
|
|
13210
|
-
|
|
13211
|
-
Respond with a JSON object:
|
|
13212
|
-
{
|
|
13213
|
-
"pass": true/false,
|
|
13214
|
-
"score": 1-5,
|
|
13215
|
-
"reason": "brief explanation"
|
|
13216
|
-
}
|
|
13217
|
-
|
|
13218
|
-
Scoring guide:
|
|
13219
|
-
- 5: Fully meets criteria, excellent response
|
|
13220
|
-
- 4: Mostly meets criteria, minor issues
|
|
13221
|
-
- 3: Partially meets criteria, notable gaps
|
|
13222
|
-
- 2: Barely meets criteria, significant issues
|
|
13223
|
-
- 1: Does not meet criteria
|
|
13224
|
-
|
|
13225
|
-
A score of ${passThreshold} or above is a pass.`;
|
|
13226
|
-
}
|
|
13227
|
-
var MODEL_ALIASES = ["fast", "best"];
|
|
13228
|
-
var _cognitive = null;
|
|
13229
|
-
var _availableModels = [];
|
|
13230
|
-
var _judgeModel = "fast";
|
|
13231
|
-
function _isModelValid(model) {
|
|
13232
|
-
if (MODEL_ALIASES.includes(model))
|
|
13233
|
-
return true;
|
|
13234
|
-
if (_availableModels.length === 0)
|
|
13235
|
-
return false;
|
|
13236
|
-
return _availableModels.includes(model);
|
|
13237
|
-
}
|
|
13238
|
-
async function initLLMJudge(credentials, options) {
|
|
13239
|
-
const log = options?.logger ?? console;
|
|
13240
|
-
const client = new Client18({
|
|
13241
|
-
token: credentials.token,
|
|
13242
|
-
apiUrl: credentials.apiUrl,
|
|
13243
|
-
botId: credentials.botId
|
|
13244
|
-
});
|
|
13245
|
-
_cognitive = new Cognitive({ client, __experimental_beta: true });
|
|
13246
|
-
try {
|
|
13247
|
-
_availableModels = Array.from((await _cognitive.fetchRemoteModels()).keys());
|
|
13248
|
-
} catch (err) {
|
|
13249
|
-
log.warn(`Failed to fetch available models: ${err.message}. LLM judge will be unavailable.`);
|
|
13250
|
-
_availableModels = [];
|
|
13251
|
-
}
|
|
13252
|
-
_judgeModel = options?.model ?? "fast";
|
|
13253
|
-
if (_availableModels.length === 0) {
|
|
13254
|
-
log.warn("No available Cognitive models: cannot validate judge model.");
|
|
13255
|
-
} else if (!_isModelValid(_judgeModel)) {
|
|
13256
|
-
log.warn(`Configured LLM judge model "${_judgeModel}" is invalid. Run "adk models" to list available models.`);
|
|
13257
|
-
}
|
|
13258
|
-
}
|
|
13259
|
-
async function gradeLLMJudge(botResponse, criteria, context) {
|
|
13260
|
-
const threshold = Math.max(1, Math.min(5, context.passThreshold ?? DEFAULT_PASS_THRESHOLD));
|
|
13261
|
-
try {
|
|
13262
|
-
if (!_cognitive) {
|
|
13263
|
-
return {
|
|
13264
|
-
assertion: `llm_judge: "${criteria}"`,
|
|
13265
|
-
pass: true,
|
|
13266
|
-
expected: criteria,
|
|
13267
|
-
actual: "SKIPPED — LLM judge unavailable: no credentials configured"
|
|
13268
|
-
};
|
|
13269
|
-
}
|
|
13270
|
-
if (!_isModelValid(_judgeModel)) {
|
|
13271
|
-
return {
|
|
13272
|
-
assertion: `llm_judge: "${criteria}"`,
|
|
13273
|
-
pass: false,
|
|
13274
|
-
expected: criteria,
|
|
13275
|
-
actual: "FAILED — invalid LLM judge model"
|
|
13276
|
-
};
|
|
13277
|
-
}
|
|
13278
|
-
const { output } = await _cognitive.generateContent({
|
|
13279
|
-
model: _judgeModel,
|
|
13280
|
-
temperature: 0,
|
|
13281
|
-
responseFormat: "json_object",
|
|
13282
|
-
systemPrompt: buildJudgeSystemPrompt(threshold),
|
|
13283
|
-
messages: [
|
|
13284
|
-
{
|
|
13285
|
-
role: "user",
|
|
13286
|
-
content: `User message: ${context.userMessage}
|
|
13287
|
-
|
|
13288
|
-
Bot response: ${botResponse}
|
|
13289
|
-
|
|
13290
|
-
Criteria: ${criteria}`
|
|
13291
|
-
}
|
|
13292
|
-
]
|
|
13293
|
-
});
|
|
13294
|
-
const rawContent = output?.choices?.[0]?.content;
|
|
13295
|
-
const content = typeof rawContent === "string" ? rawContent : null;
|
|
13296
|
-
if (!content) {
|
|
13297
|
-
return {
|
|
13298
|
-
assertion: `llm_judge: "${criteria}"`,
|
|
13299
|
-
pass: true,
|
|
13300
|
-
expected: criteria,
|
|
13301
|
-
actual: "SKIPPED — LLM judge returned empty response"
|
|
13302
|
-
};
|
|
13303
|
-
}
|
|
13304
|
-
const verdict = JSON.parse(content);
|
|
13305
|
-
return {
|
|
13306
|
-
assertion: `llm_judge: "${criteria}"`,
|
|
13307
|
-
pass: verdict.score >= threshold,
|
|
13308
|
-
expected: criteria,
|
|
13309
|
-
actual: `Score ${verdict.score}/5 (threshold: ${threshold}) — ${verdict.reason}`
|
|
13310
|
-
};
|
|
13311
|
-
} catch (err) {
|
|
13312
|
-
return {
|
|
13313
|
-
assertion: `llm_judge: "${criteria}"`,
|
|
13314
|
-
pass: true,
|
|
13315
|
-
expected: criteria,
|
|
13316
|
-
actual: `SKIPPED — LLM judge unavailable: ${err.message}`
|
|
13317
|
-
};
|
|
13318
|
-
}
|
|
13319
|
-
}
|
|
13320
|
-
|
|
13321
|
-
// src/eval/graders/response.ts
|
|
13322
|
-
async function gradeResponse(botResponse, assertions, context) {
|
|
13323
|
-
const results = [];
|
|
13324
|
-
for (const assertion of assertions) {
|
|
13325
|
-
if ("contains" in assertion) {
|
|
13326
|
-
const pass = botResponse.toLowerCase().includes(assertion.contains.toLowerCase());
|
|
13327
|
-
results.push({
|
|
13328
|
-
assertion: `contains "${assertion.contains}"`,
|
|
13329
|
-
pass,
|
|
13330
|
-
expected: `Response contains "${assertion.contains}"`,
|
|
13331
|
-
actual: pass ? `Found in response` : `Not found in response`
|
|
13332
|
-
});
|
|
13333
|
-
continue;
|
|
13334
|
-
}
|
|
13335
|
-
if ("not_contains" in assertion) {
|
|
13336
|
-
const pass = !botResponse.toLowerCase().includes(assertion.not_contains.toLowerCase());
|
|
13337
|
-
results.push({
|
|
13338
|
-
assertion: `not_contains "${assertion.not_contains}"`,
|
|
13339
|
-
pass,
|
|
13340
|
-
expected: `Response does not contain "${assertion.not_contains}"`,
|
|
13341
|
-
actual: pass ? `Not found in response` : `Found in response`
|
|
13342
|
-
});
|
|
13343
|
-
continue;
|
|
13344
|
-
}
|
|
13345
|
-
if ("matches" in assertion) {
|
|
13346
|
-
const regex = new RegExp(assertion.matches, "i");
|
|
13347
|
-
const pass = regex.test(botResponse);
|
|
13348
|
-
results.push({
|
|
13349
|
-
assertion: `matches ${assertion.matches}`,
|
|
13350
|
-
pass,
|
|
13351
|
-
expected: `Response matches /${assertion.matches}/`,
|
|
13352
|
-
actual: pass ? `Matched` : `No match`
|
|
13353
|
-
});
|
|
13354
|
-
continue;
|
|
13355
|
-
}
|
|
13356
|
-
if ("llm_judge" in assertion) {
|
|
13357
|
-
const result = await gradeLLMJudge(botResponse, assertion.llm_judge, {
|
|
13358
|
-
userMessage: context.userMessage,
|
|
13359
|
-
passThreshold: context.judgePassThreshold
|
|
13360
|
-
});
|
|
13361
|
-
results.push(result);
|
|
13362
|
-
continue;
|
|
13363
|
-
}
|
|
13364
|
-
if ("similar_to" in assertion) {
|
|
13365
|
-
results.push({
|
|
13366
|
-
assertion: `similar_to: "${assertion.similar_to}"`,
|
|
13367
|
-
pass: true,
|
|
13368
|
-
expected: assertion.similar_to,
|
|
13369
|
-
actual: "SKIPPED — similar_to not yet implemented"
|
|
13370
|
-
});
|
|
13371
|
-
continue;
|
|
13372
|
-
}
|
|
13373
|
-
results.push({
|
|
13374
|
-
assertion: "unknown",
|
|
13375
|
-
pass: false,
|
|
13376
|
-
expected: "known assertion type",
|
|
13377
|
-
actual: `Unknown assertion: ${JSON.stringify(assertion)}`
|
|
13378
|
-
});
|
|
13379
|
-
}
|
|
13380
|
-
return results;
|
|
13381
|
-
}
|
|
13382
|
-
|
|
13383
|
-
// src/eval/graders/match.ts
|
|
13384
|
-
function matchValue(operator, actual) {
|
|
13385
|
-
if (typeof operator === "string") {
|
|
13386
|
-
return String(actual) === operator;
|
|
13387
|
-
}
|
|
13388
|
-
if ("equals" in operator) {
|
|
13389
|
-
return actual === operator.equals;
|
|
13390
|
-
}
|
|
13391
|
-
if ("contains" in operator) {
|
|
13392
|
-
return String(actual).toLowerCase().includes(operator.contains.toLowerCase());
|
|
13393
|
-
}
|
|
13394
|
-
if ("not_contains" in operator) {
|
|
13395
|
-
return !String(actual).toLowerCase().includes(operator.not_contains.toLowerCase());
|
|
13396
|
-
}
|
|
13397
|
-
if ("matches" in operator) {
|
|
13398
|
-
return new RegExp(operator.matches, "i").test(String(actual));
|
|
13399
|
-
}
|
|
13400
|
-
if ("in" in operator) {
|
|
13401
|
-
return operator.in.includes(actual);
|
|
13402
|
-
}
|
|
13403
|
-
if ("exists" in operator) {
|
|
13404
|
-
return operator.exists ? actual !== undefined && actual !== null : actual === undefined || actual === null;
|
|
13405
|
-
}
|
|
13406
|
-
if ("gte" in operator) {
|
|
13407
|
-
return Number(actual) >= operator.gte;
|
|
13408
|
-
}
|
|
13409
|
-
if ("lte" in operator) {
|
|
13410
|
-
return Number(actual) <= operator.lte;
|
|
13411
|
-
}
|
|
13412
|
-
return false;
|
|
13413
|
-
}
|
|
13414
|
-
function operatorToString(operator) {
|
|
13415
|
-
if (typeof operator === "string")
|
|
13416
|
-
return `equals "${operator}"`;
|
|
13417
|
-
if ("equals" in operator)
|
|
13418
|
-
return `equals ${JSON.stringify(operator.equals)}`;
|
|
13419
|
-
if ("contains" in operator)
|
|
13420
|
-
return `contains "${operator.contains}"`;
|
|
13421
|
-
if ("not_contains" in operator)
|
|
13422
|
-
return `not_contains "${operator.not_contains}"`;
|
|
13423
|
-
if ("matches" in operator)
|
|
13424
|
-
return `matches /${operator.matches}/`;
|
|
13425
|
-
if ("in" in operator)
|
|
13426
|
-
return `in [${operator.in.map((v) => JSON.stringify(v)).join(", ")}]`;
|
|
13427
|
-
if ("exists" in operator)
|
|
13428
|
-
return operator.exists ? "exists" : "does not exist";
|
|
13429
|
-
if ("gte" in operator)
|
|
13430
|
-
return `>= ${operator.gte}`;
|
|
13431
|
-
if ("lte" in operator)
|
|
13432
|
-
return `<= ${operator.lte}`;
|
|
13433
|
-
return JSON.stringify(operator);
|
|
13434
|
-
}
|
|
13435
|
-
|
|
13436
|
-
// src/eval/graders/tools.ts
|
|
13437
|
-
function gradeTools(toolCalls, assertions) {
|
|
13438
|
-
return assertions.map((assertion) => {
|
|
13439
|
-
if ("called" in assertion && !("not_called" in assertion) && !("call_order" in assertion)) {
|
|
13440
|
-
const matches = toolCalls.filter((tc) => tc.name === assertion.called);
|
|
13441
|
-
const wasCalled = matches.length > 0;
|
|
13442
|
-
if (!wasCalled) {
|
|
13443
|
-
return {
|
|
13444
|
-
assertion: `tool called: ${assertion.called}`,
|
|
13445
|
-
pass: false,
|
|
13446
|
-
expected: `${assertion.called} was called`,
|
|
13447
|
-
actual: `Not called. Tools called: [${toolCalls.map((tc) => tc.name).join(", ") || "none"}]`
|
|
13448
|
-
};
|
|
13449
|
-
}
|
|
13450
|
-
if (assertion.params) {
|
|
13451
|
-
const paramResults = [];
|
|
13452
|
-
for (const [key, operator] of Object.entries(assertion.params)) {
|
|
13453
|
-
const anyMatch = matches.some((tc) => matchValue(operator, tc.input[key]));
|
|
13454
|
-
paramResults.push({
|
|
13455
|
-
key,
|
|
13456
|
-
pass: anyMatch,
|
|
13457
|
-
detail: anyMatch ? `matched` : `expected ${key} ${operatorToString(operator)}, got ${JSON.stringify(matches.map((tc) => tc.input[key]))}`
|
|
13458
|
-
});
|
|
13459
|
-
}
|
|
13460
|
-
const allParamsPass = paramResults.every((p) => p.pass);
|
|
13461
|
-
const failedParams = paramResults.filter((p) => !p.pass);
|
|
13462
|
-
return {
|
|
13463
|
-
assertion: `tool called: ${assertion.called} with params`,
|
|
13464
|
-
pass: allParamsPass,
|
|
13465
|
-
expected: `${assertion.called} called with ${Object.entries(assertion.params).map(([k, v]) => `${k} ${operatorToString(v)}`).join(", ")}`,
|
|
13466
|
-
actual: allParamsPass ? `Matched` : failedParams.map((p) => p.detail).join("; ")
|
|
13467
|
-
};
|
|
13468
|
-
}
|
|
13469
|
-
return {
|
|
13470
|
-
assertion: `tool called: ${assertion.called}`,
|
|
13471
|
-
pass: true,
|
|
13472
|
-
expected: `${assertion.called} was called`,
|
|
13473
|
-
actual: `Called ${matches.length} time(s)`
|
|
13474
|
-
};
|
|
13475
|
-
}
|
|
13476
|
-
if ("not_called" in assertion) {
|
|
13477
|
-
const wasCalled = toolCalls.some((tc) => tc.name === assertion.not_called);
|
|
13478
|
-
return {
|
|
13479
|
-
assertion: `tool not_called: ${assertion.not_called}`,
|
|
13480
|
-
pass: !wasCalled,
|
|
13481
|
-
expected: `${assertion.not_called} was NOT called`,
|
|
13482
|
-
actual: wasCalled ? `Was called` : `Not called`
|
|
13483
|
-
};
|
|
13484
|
-
}
|
|
13485
|
-
if ("call_order" in assertion) {
|
|
13486
|
-
const calledNames = toolCalls.map((tc) => tc.name);
|
|
13487
|
-
const expectedOrder = assertion.call_order;
|
|
13488
|
-
let cursor = 0;
|
|
13489
|
-
for (const name of calledNames) {
|
|
13490
|
-
if (cursor < expectedOrder.length && name === expectedOrder[cursor]) {
|
|
13491
|
-
cursor++;
|
|
13492
|
-
}
|
|
13493
|
-
}
|
|
13494
|
-
const inOrder = cursor === expectedOrder.length;
|
|
13495
|
-
return {
|
|
13496
|
-
assertion: `call_order: [${expectedOrder.join(" → ")}]`,
|
|
13497
|
-
pass: inOrder,
|
|
13498
|
-
expected: `Tools called in order: [${expectedOrder.join(" → ")}]`,
|
|
13499
|
-
actual: `Actual order: [${calledNames.join(" → ") || "none"}]`
|
|
13500
|
-
};
|
|
13501
|
-
}
|
|
13502
|
-
return {
|
|
13503
|
-
assertion: "unknown tool assertion",
|
|
13504
|
-
pass: false,
|
|
13505
|
-
expected: "known assertion type",
|
|
13506
|
-
actual: `Unknown: ${JSON.stringify(assertion)}`
|
|
13507
|
-
};
|
|
13508
|
-
});
|
|
13509
|
-
}
|
|
13510
|
-
|
|
13511
|
-
// src/eval/graders/state.ts
|
|
13512
|
-
import { BUILT_IN_STATES } from "@botpress/runtime/internal";
|
|
13513
|
-
function parseStatePath(path45) {
|
|
13514
|
-
const dot = path45.indexOf(".");
|
|
13515
|
-
if (dot === -1) {
|
|
13516
|
-
throw new Error(`Invalid state path "${path45}" — expected "type.field" format`);
|
|
13517
|
-
}
|
|
13518
|
-
const prefix = path45.slice(0, dot);
|
|
13519
|
-
const field = path45.slice(dot + 1);
|
|
13520
|
-
switch (prefix) {
|
|
13521
|
-
case "bot":
|
|
13522
|
-
return { type: "bot", stateName: BUILT_IN_STATES.bot, stateId: (ctx) => ctx.botId, field };
|
|
13523
|
-
case "user":
|
|
13524
|
-
return { type: "user", stateName: BUILT_IN_STATES.user, stateId: (ctx) => ctx.userId, field };
|
|
13525
|
-
case "conversation":
|
|
13526
|
-
return {
|
|
13527
|
-
type: "conversation",
|
|
13528
|
-
stateName: BUILT_IN_STATES.conversation,
|
|
13529
|
-
stateId: (ctx) => ctx.conversationId,
|
|
13530
|
-
field
|
|
13531
|
-
};
|
|
13532
|
-
default:
|
|
13533
|
-
throw new Error(`Unknown state type "${prefix}" in path "${path45}" — expected bot, user, or conversation`);
|
|
13534
|
-
}
|
|
13535
|
-
}
|
|
13536
|
-
async function fetchState(client, type, id, name) {
|
|
13537
|
-
try {
|
|
13538
|
-
const result = await client.getState({ type, id, name });
|
|
13539
|
-
const payload = result.state?.payload;
|
|
13540
|
-
return payload?.value ?? payload ?? null;
|
|
13541
|
-
} catch (err) {
|
|
13542
|
-
const code = err != null && typeof err === "object" && "code" in err ? err.code : undefined;
|
|
13543
|
-
const message = err instanceof Error ? err.message : "";
|
|
13544
|
-
if (code === 404 || message.includes("404") || message.includes("doesn't exist")) {
|
|
13545
|
-
return null;
|
|
13546
|
-
}
|
|
13547
|
-
throw err;
|
|
13548
|
-
}
|
|
13549
|
-
}
|
|
13550
|
-
async function fetchStateWithRetry(client, type, id, name, field, maxRetries = 3, retryDelay = 1000) {
|
|
13551
|
-
for (let attempt = 0;attempt <= maxRetries; attempt++) {
|
|
13552
|
-
const payload = await fetchState(client, type, id, name);
|
|
13553
|
-
if (payload && payload[field] !== undefined) {
|
|
13554
|
-
return payload;
|
|
13555
|
-
}
|
|
13556
|
-
if (attempt < maxRetries) {
|
|
13557
|
-
await new Promise((resolve5) => setTimeout(resolve5, retryDelay));
|
|
13558
|
-
}
|
|
13559
|
-
}
|
|
13560
|
-
return null;
|
|
13561
|
-
}
|
|
13562
|
-
async function snapshotState(client, assertions, ctx) {
|
|
13563
|
-
const snapshots = new Map;
|
|
13564
|
-
for (const assertion of assertions) {
|
|
13565
|
-
if (assertion.changed === undefined)
|
|
13566
|
-
continue;
|
|
13567
|
-
const parsed = parseStatePath(assertion.path);
|
|
13568
|
-
if (parsed.type === "conversation" && !ctx.conversationId)
|
|
13569
|
-
continue;
|
|
13570
|
-
const payload = await fetchState(client, parsed.type, parsed.stateId(ctx), parsed.stateName);
|
|
13571
|
-
snapshots.set(assertion.path, payload ? payload[parsed.field] : undefined);
|
|
13572
|
-
}
|
|
13573
|
-
return snapshots;
|
|
13574
|
-
}
|
|
13575
|
-
async function gradeState(client, assertions, ctx, preSnapshots) {
|
|
13576
|
-
const results = [];
|
|
13577
|
-
for (const assertion of assertions) {
|
|
13578
|
-
const parsed = parseStatePath(assertion.path);
|
|
13579
|
-
const stateId = parsed.stateId(ctx);
|
|
13580
|
-
let payload;
|
|
13581
|
-
try {
|
|
13582
|
-
payload = await fetchStateWithRetry(client, parsed.type, stateId, parsed.stateName, parsed.field);
|
|
13583
|
-
} catch (err) {
|
|
13584
|
-
results.push({
|
|
13585
|
-
assertion: `state: ${assertion.path}`,
|
|
13586
|
-
pass: false,
|
|
13587
|
-
expected: `Fetch state for ${assertion.path}`,
|
|
13588
|
-
actual: `Error fetching state: ${err.message}`
|
|
13589
|
-
});
|
|
13590
|
-
continue;
|
|
13591
|
-
}
|
|
13592
|
-
const actualValue = payload ? payload[parsed.field] : undefined;
|
|
13593
|
-
if (assertion.equals !== undefined) {
|
|
13594
|
-
const pass = deepEqual(actualValue, assertion.equals);
|
|
13595
|
-
results.push({
|
|
13596
|
-
assertion: `state: ${assertion.path} equals`,
|
|
13597
|
-
pass,
|
|
13598
|
-
expected: JSON.stringify(assertion.equals),
|
|
13599
|
-
actual: JSON.stringify(actualValue)
|
|
13600
|
-
});
|
|
13601
|
-
}
|
|
13602
|
-
if (assertion.changed !== undefined) {
|
|
13603
|
-
const preValue = preSnapshots?.get(assertion.path);
|
|
13604
|
-
const didChange = !deepEqual(actualValue, preValue);
|
|
13605
|
-
const pass = assertion.changed ? didChange : !didChange;
|
|
13606
|
-
results.push({
|
|
13607
|
-
assertion: `state: ${assertion.path} ${assertion.changed ? "changed" : "unchanged"}`,
|
|
13608
|
-
pass,
|
|
13609
|
-
expected: assertion.changed ? `Value changed from ${JSON.stringify(preValue)}` : `Value unchanged from ${JSON.stringify(preValue)}`,
|
|
13610
|
-
actual: didChange ? `Changed to ${JSON.stringify(actualValue)}` : `Unchanged: ${JSON.stringify(actualValue)}`
|
|
13611
|
-
});
|
|
13612
|
-
}
|
|
13613
|
-
}
|
|
13614
|
-
return results;
|
|
13615
|
-
}
|
|
13616
|
-
function deepEqual(a, b) {
|
|
13617
|
-
if (a === b)
|
|
13618
|
-
return true;
|
|
13619
|
-
if (a === null || b === null)
|
|
13620
|
-
return false;
|
|
13621
|
-
if (typeof a !== typeof b)
|
|
13622
|
-
return false;
|
|
13623
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
13624
|
-
if (a.length !== b.length)
|
|
13625
|
-
return false;
|
|
13626
|
-
return a.every((v, i) => deepEqual(v, b[i]));
|
|
13627
|
-
}
|
|
13628
|
-
if (typeof a === "object" && typeof b === "object") {
|
|
13629
|
-
const keysA = Object.keys(a);
|
|
13630
|
-
const keysB = Object.keys(b);
|
|
13631
|
-
if (keysA.length !== keysB.length)
|
|
13632
|
-
return false;
|
|
13633
|
-
return keysA.every((k) => deepEqual(a[k], b[k]));
|
|
13634
|
-
}
|
|
13635
|
-
return false;
|
|
13636
|
-
}
|
|
13637
|
-
|
|
13638
|
-
// src/eval/graders/tables.ts
|
|
13639
|
-
function buildFilter(conditions) {
|
|
13640
|
-
const filter = {};
|
|
13641
|
-
for (const [column, op] of Object.entries(conditions)) {
|
|
13642
|
-
if (typeof op === "string") {
|
|
13643
|
-
filter[column] = op;
|
|
13644
|
-
} else if ("equals" in op) {
|
|
13645
|
-
filter[column] = op.equals;
|
|
13646
|
-
} else if ("contains" in op) {
|
|
13647
|
-
filter[column] = { $regex: op.contains };
|
|
13648
|
-
} else if ("matches" in op) {
|
|
13649
|
-
filter[column] = { $regex: op.matches };
|
|
13650
|
-
} else if ("gte" in op) {
|
|
13651
|
-
filter[column] = { $gte: op.gte };
|
|
13652
|
-
} else if ("lte" in op) {
|
|
13653
|
-
filter[column] = { $lte: op.lte };
|
|
13654
|
-
}
|
|
13655
|
-
}
|
|
13656
|
-
return filter;
|
|
13657
|
-
}
|
|
13658
|
-
async function gradeRowExists(client, assertion) {
|
|
13659
|
-
const conditionDesc = Object.entries(assertion.row_exists).map(([k, v]) => `${k} ${operatorToString(v)}`).join(", ");
|
|
13660
|
-
try {
|
|
13661
|
-
const filter = buildFilter(assertion.row_exists);
|
|
13662
|
-
const result = await client.findTableRows({
|
|
13663
|
-
table: assertion.table,
|
|
13664
|
-
filter,
|
|
13665
|
-
limit: 10
|
|
13666
|
-
});
|
|
13667
|
-
const rows = result.rows || [];
|
|
13668
|
-
const matchingRows = rows.filter((row) => {
|
|
13669
|
-
for (const [column, op] of Object.entries(assertion.row_exists)) {
|
|
13670
|
-
if (!matchValue(op, row[column]))
|
|
13671
|
-
return false;
|
|
13672
|
-
}
|
|
13673
|
-
return true;
|
|
13674
|
-
});
|
|
13675
|
-
const pass = matchingRows.length > 0;
|
|
13676
|
-
return {
|
|
13677
|
-
assertion: `table: ${assertion.table} row_exists`,
|
|
13678
|
-
pass,
|
|
13679
|
-
expected: `Row exists in ${assertion.table} where ${conditionDesc}`,
|
|
13680
|
-
actual: pass ? `Found ${matchingRows.length} matching row(s)` : `No matching rows found`
|
|
13681
|
-
};
|
|
13682
|
-
} catch (err) {
|
|
13683
|
-
return {
|
|
13684
|
-
assertion: `table: ${assertion.table} row_exists`,
|
|
13685
|
-
pass: false,
|
|
13686
|
-
expected: `Row exists in ${assertion.table} where ${conditionDesc}`,
|
|
13687
|
-
actual: `Error querying table: ${err.message}`
|
|
13688
|
-
};
|
|
13689
|
-
}
|
|
13690
|
-
}
|
|
13691
|
-
async function gradeRowCount(client, assertion) {
|
|
13692
|
-
const countDesc = operatorToString(assertion.row_count);
|
|
13693
|
-
const whereDesc = assertion.where ? ` where ${Object.entries(assertion.where).map(([k, v]) => `${k} ${operatorToString(v)}`).join(", ")}` : "";
|
|
13694
|
-
try {
|
|
13695
|
-
const filter = assertion.where ? buildFilter(assertion.where) : {};
|
|
13696
|
-
const result = await client.findTableRows({
|
|
13697
|
-
table: assertion.table,
|
|
13698
|
-
filter,
|
|
13699
|
-
limit: 1000
|
|
13700
|
-
});
|
|
13701
|
-
const rows = result.rows || [];
|
|
13702
|
-
let count;
|
|
13703
|
-
if (assertion.where) {
|
|
13704
|
-
count = rows.filter((row) => {
|
|
13705
|
-
for (const [column, op] of Object.entries(assertion.where)) {
|
|
13706
|
-
if (!matchValue(op, row[column]))
|
|
13707
|
-
return false;
|
|
13708
|
-
}
|
|
13709
|
-
return true;
|
|
13710
|
-
}).length;
|
|
13711
|
-
} else {
|
|
13712
|
-
count = rows.length;
|
|
13713
|
-
}
|
|
13714
|
-
const pass = matchValue(assertion.row_count, count);
|
|
13715
|
-
return {
|
|
13716
|
-
assertion: `table: ${assertion.table} row_count`,
|
|
13717
|
-
pass,
|
|
13718
|
-
expected: `Row count in ${assertion.table}${whereDesc} ${countDesc}`,
|
|
13719
|
-
actual: `Count: ${count}`
|
|
13720
|
-
};
|
|
13721
|
-
} catch (err) {
|
|
13722
|
-
return {
|
|
13723
|
-
assertion: `table: ${assertion.table} row_count`,
|
|
13724
|
-
pass: false,
|
|
13725
|
-
expected: `Row count in ${assertion.table}${whereDesc} ${countDesc}`,
|
|
13726
|
-
actual: `Error querying table: ${err.message}`
|
|
13727
|
-
};
|
|
13728
|
-
}
|
|
13729
|
-
}
|
|
13730
|
-
async function gradeTables(client, assertions) {
|
|
13731
|
-
const results = [];
|
|
13732
|
-
for (const assertion of assertions) {
|
|
13733
|
-
if ("row_exists" in assertion) {
|
|
13734
|
-
results.push(await gradeRowExists(client, assertion));
|
|
13735
|
-
} else if ("row_count" in assertion) {
|
|
13736
|
-
results.push(await gradeRowCount(client, assertion));
|
|
13737
|
-
}
|
|
13738
|
-
}
|
|
13739
|
-
return results;
|
|
13740
|
-
}
|
|
13741
|
-
|
|
13742
|
-
// src/eval/graders/workflow.ts
|
|
13743
|
-
function gradeWorkflows(spans, assertions) {
|
|
13744
|
-
const results = [];
|
|
13745
|
-
const data = (span) => span.data && typeof span.data === "object" ? span.data : {};
|
|
13746
|
-
for (const assertion of assertions) {
|
|
13747
|
-
const workflowSpans = spans.filter((span) => {
|
|
13748
|
-
const d = data(span);
|
|
13749
|
-
const wfName = d["workflow.name"] || d["workflowName"];
|
|
13750
|
-
return wfName === assertion.name;
|
|
13751
|
-
});
|
|
13752
|
-
if (assertion.entered !== undefined) {
|
|
13753
|
-
const wasEntered = workflowSpans.length > 0;
|
|
13754
|
-
const pass = assertion.entered ? wasEntered : !wasEntered;
|
|
13755
|
-
results.push({
|
|
13756
|
-
assertion: `workflow: ${assertion.name} ${assertion.entered ? "entered" : "not entered"}`,
|
|
13757
|
-
pass,
|
|
13758
|
-
expected: assertion.entered ? `Workflow "${assertion.name}" was entered` : `Workflow "${assertion.name}" was not entered`,
|
|
13759
|
-
actual: wasEntered ? `Found ${workflowSpans.length} workflow span(s)` : `No workflow spans found`
|
|
13760
|
-
});
|
|
13761
|
-
}
|
|
13762
|
-
if (assertion.completed !== undefined) {
|
|
13763
|
-
const completedSpans = workflowSpans.filter((span) => {
|
|
13764
|
-
const d = data(span);
|
|
13765
|
-
const status = d["workflow.status.final"];
|
|
13766
|
-
return status === "completed" || (span.status === "ok" || span.status === "error") && span.name?.includes("workflow");
|
|
13767
|
-
});
|
|
13768
|
-
const didComplete = completedSpans.length > 0;
|
|
13769
|
-
const pass = assertion.completed ? didComplete : !didComplete;
|
|
13770
|
-
results.push({
|
|
13771
|
-
assertion: `workflow: ${assertion.name} ${assertion.completed ? "completed" : "not completed"}`,
|
|
13772
|
-
pass,
|
|
13773
|
-
expected: assertion.completed ? `Workflow "${assertion.name}" completed` : `Workflow "${assertion.name}" did not complete`,
|
|
13774
|
-
actual: didComplete ? `Completed` : `Not completed`
|
|
13775
|
-
});
|
|
13776
|
-
}
|
|
13777
|
-
}
|
|
13778
|
-
return results;
|
|
13779
|
-
}
|
|
13780
|
-
|
|
13781
|
-
// src/eval/graders/timing.ts
|
|
13782
|
-
function gradeTiming(botDuration, assertions) {
|
|
13783
|
-
const results = [];
|
|
13784
|
-
for (const assertion of assertions) {
|
|
13785
|
-
const pass = matchValue(assertion.response_time, botDuration);
|
|
13786
|
-
const expected = operatorToString(assertion.response_time);
|
|
13787
|
-
results.push({
|
|
13788
|
-
assertion: `response_time ${expected}`,
|
|
13789
|
-
pass,
|
|
13790
|
-
expected: `Response time ${expected}`,
|
|
13791
|
-
actual: `${botDuration}ms`
|
|
13792
|
-
});
|
|
13793
|
-
}
|
|
13794
|
-
return results;
|
|
13795
|
-
}
|
|
13796
|
-
|
|
13797
|
-
// src/eval/graders/outcome.ts
|
|
13798
|
-
async function snapshotOutcomeState(client, evalDef, ctx) {
|
|
13799
|
-
if (!evalDef.outcome?.state) {
|
|
13800
|
-
return new Map;
|
|
13801
|
-
}
|
|
13802
|
-
return snapshotState(client, evalDef.outcome.state, ctx);
|
|
13803
|
-
}
|
|
13804
|
-
async function gradeOutcome(client, evalDef, ctx, traceSpans, preSnapshots) {
|
|
13805
|
-
const outcome = evalDef.outcome;
|
|
13806
|
-
if (!outcome)
|
|
13807
|
-
return [];
|
|
13808
|
-
const results = [];
|
|
13809
|
-
if (outcome.state && outcome.state.length > 0) {
|
|
13810
|
-
const stateResults = await gradeState(client, outcome.state, ctx, preSnapshots);
|
|
13811
|
-
results.push(...stateResults);
|
|
13812
|
-
}
|
|
13813
|
-
if (outcome.tables && outcome.tables.length > 0) {
|
|
13814
|
-
const tableResults = await gradeTables(client, outcome.tables);
|
|
13815
|
-
results.push(...tableResults);
|
|
13816
|
-
}
|
|
13817
|
-
if (outcome.workflow && outcome.workflow.length > 0) {
|
|
13818
|
-
const workflowResults = gradeWorkflows(traceSpans, outcome.workflow);
|
|
13819
|
-
results.push(...workflowResults);
|
|
13820
|
-
}
|
|
13821
|
-
return results;
|
|
13822
|
-
}
|
|
13823
|
-
|
|
13824
|
-
// src/eval/runner.ts
|
|
13825
|
-
import { randomUUID } from "crypto";
|
|
13826
|
-
var DEFAULT_IDLE_TIMEOUT = 15000;
|
|
13827
|
-
var WORKFLOW_TRIGGER_TIMEOUT_MS = 5 * 60 * 1000;
|
|
13828
|
-
function buildStatePayload(value) {
|
|
13829
|
-
return {
|
|
13830
|
-
value,
|
|
13831
|
-
location: { type: "state" }
|
|
13832
|
-
};
|
|
13833
|
-
}
|
|
13834
|
-
async function seedEvalState(client, ctx, setup) {
|
|
13835
|
-
const state = setup?.state;
|
|
13836
|
-
if (!state)
|
|
13837
|
-
return;
|
|
13838
|
-
const writes = [];
|
|
13839
|
-
if (state.bot) {
|
|
13840
|
-
writes.push(client.setState({
|
|
13841
|
-
type: "bot",
|
|
13842
|
-
id: ctx.botId,
|
|
13843
|
-
name: BUILT_IN_STATES2.bot,
|
|
13844
|
-
payload: buildStatePayload(state.bot)
|
|
13845
|
-
}));
|
|
13846
|
-
}
|
|
13847
|
-
if (state.user) {
|
|
13848
|
-
writes.push(client.setState({
|
|
13849
|
-
type: "user",
|
|
13850
|
-
id: ctx.userId,
|
|
13851
|
-
name: BUILT_IN_STATES2.user,
|
|
13852
|
-
payload: buildStatePayload(state.user)
|
|
13853
|
-
}));
|
|
13854
|
-
}
|
|
13855
|
-
if (state.conversation) {
|
|
13856
|
-
if (!ctx.conversationId) {
|
|
13857
|
-
throw new Error("Cannot seed conversation state before a conversation is created.");
|
|
13858
|
-
}
|
|
13859
|
-
writes.push(client.setState({
|
|
13860
|
-
type: "conversation",
|
|
13861
|
-
id: ctx.conversationId,
|
|
13862
|
-
name: BUILT_IN_STATES2.conversation,
|
|
13863
|
-
payload: buildStatePayload(state.conversation)
|
|
13864
|
-
}));
|
|
13865
|
-
}
|
|
13866
|
-
await Promise.all(writes);
|
|
13867
|
-
}
|
|
13868
|
-
async function triggerEvalWorkflow(client, ctx, setup) {
|
|
13869
|
-
const workflow = setup?.workflow;
|
|
13870
|
-
if (!workflow)
|
|
13871
|
-
return;
|
|
13872
|
-
await client.createWorkflow({
|
|
13873
|
-
name: workflow.trigger,
|
|
13874
|
-
input: workflow.input ?? {},
|
|
13875
|
-
status: "pending",
|
|
13876
|
-
conversationId: ctx.conversationId,
|
|
13877
|
-
userId: ctx.userId,
|
|
13878
|
-
timeoutAt: new Date(Date.now() + WORKFLOW_TRIGGER_TIMEOUT_MS).toISOString()
|
|
13879
|
-
});
|
|
13880
|
-
}
|
|
13881
|
-
async function runEval(evalDef, connection, options = {}) {
|
|
13882
|
-
const devServerUrl = options.devServerUrl || "http://localhost:3001";
|
|
13883
|
-
const idleTimeout = evalDef.options?.idleTimeout ?? options.idleTimeout ?? DEFAULT_IDLE_TIMEOUT;
|
|
13884
|
-
const judgePassThreshold = evalDef.options?.judgePassThreshold ?? options.judgePassThreshold;
|
|
13885
|
-
const start = Date.now();
|
|
13886
|
-
const turns = [];
|
|
13887
|
-
let outcomeAssertions = [];
|
|
13888
|
-
try {
|
|
13889
|
-
const session = new ChatSession(connection.webhookId);
|
|
13890
|
-
await session.connect();
|
|
13891
|
-
let bpClient = null;
|
|
13892
|
-
const getBpClient = () => {
|
|
13893
|
-
if (!bpClient) {
|
|
13894
|
-
bpClient = new BpClient2({
|
|
13895
|
-
token: connection.token,
|
|
13896
|
-
botId: connection.botId,
|
|
13897
|
-
apiUrl: connection.apiUrl
|
|
13898
|
-
});
|
|
13899
|
-
}
|
|
13900
|
-
return bpClient;
|
|
13901
|
-
};
|
|
13902
|
-
let lastConversationId = "";
|
|
13903
|
-
if (evalDef.setup?.state?.conversation || evalDef.setup?.workflow) {
|
|
13904
|
-
lastConversationId = await session.ensureConversation();
|
|
13905
|
-
}
|
|
13906
|
-
await seedEvalState(getBpClient(), {
|
|
13907
|
-
botId: connection.botId,
|
|
13908
|
-
userId: session.userId,
|
|
13909
|
-
conversationId: lastConversationId || undefined
|
|
13910
|
-
}, evalDef.setup);
|
|
13911
|
-
await triggerEvalWorkflow(getBpClient(), {
|
|
13912
|
-
userId: session.userId,
|
|
13913
|
-
conversationId: lastConversationId || undefined
|
|
13914
|
-
}, evalDef.setup);
|
|
13915
|
-
let preSnapshots = new Map;
|
|
13916
|
-
if (evalDef.outcome?.state) {
|
|
13917
|
-
const ctx = {
|
|
13918
|
-
botId: connection.botId,
|
|
13919
|
-
userId: session.userId,
|
|
13920
|
-
conversationId: lastConversationId
|
|
13921
|
-
};
|
|
13922
|
-
preSnapshots = await snapshotOutcomeState(getBpClient(), evalDef, ctx);
|
|
13923
|
-
}
|
|
13924
|
-
let previousToolCallCount = 0;
|
|
13925
|
-
let allSpans = [];
|
|
13926
|
-
for (let i = 0;i < evalDef.conversation.length; i++) {
|
|
13927
|
-
const turn = evalDef.conversation[i];
|
|
13928
|
-
const turnStart = Date.now();
|
|
13929
|
-
if (turn.expectSilence && turn.assert?.response) {
|
|
13930
|
-
throw new Error(`Turn ${i + 1}: 'expectSilence' and 'assert.response' are mutually exclusive.`);
|
|
13931
|
-
}
|
|
13932
|
-
if (turn.user && turn.event) {
|
|
13933
|
-
throw new Error(`Turn ${i + 1}: 'user' and 'event' are mutually exclusive.`);
|
|
13934
|
-
}
|
|
13935
|
-
if (!turn.user && !turn.event) {
|
|
13936
|
-
throw new Error(`Turn ${i + 1}: must have either 'user' or 'event'.`);
|
|
13937
|
-
}
|
|
13938
|
-
const sendOptions = { timeout: Math.max(30000, idleTimeout * 2), idleTimeout, expectSilence: turn.expectSilence };
|
|
13939
|
-
const result = turn.event ? await session.sendEvent(turn.event.type, turn.event.payload ?? {}, sendOptions) : await session.sendMessage(turn.user, sendOptions);
|
|
13940
|
-
const botDuration = Date.now() - turnStart;
|
|
13941
|
-
if (!turn.expectSilence && result.responses.length === 0) {
|
|
13942
|
-
throw new Error(`Turn ${i + 1}: bot produced no response.`);
|
|
13943
|
-
}
|
|
13944
|
-
lastConversationId = result.conversationId;
|
|
13945
|
-
const botResponse = result.responses.map((r) => r.text).join(`
|
|
13946
|
-
`);
|
|
13947
|
-
const turnLabel = turn.event ? `[event: ${turn.event.type}]` : turn.user;
|
|
13948
|
-
const evalStart = Date.now();
|
|
13949
|
-
let assertions = [];
|
|
13950
|
-
if (turn.expectSilence) {
|
|
13951
|
-
const wasSilent = result.responses.length === 0;
|
|
13952
|
-
assertions.push({
|
|
13953
|
-
assertion: "no_response",
|
|
13954
|
-
pass: wasSilent,
|
|
13955
|
-
expected: "No response",
|
|
13956
|
-
actual: wasSilent ? "No response" : `Bot responded: "${botResponse}"`
|
|
13957
|
-
});
|
|
13958
|
-
}
|
|
13959
|
-
if (turn.assert?.response) {
|
|
13960
|
-
assertions = await gradeResponse(botResponse, turn.assert.response, {
|
|
13961
|
-
userMessage: turnLabel,
|
|
13962
|
-
judgePassThreshold
|
|
13963
|
-
});
|
|
13964
|
-
}
|
|
13965
|
-
if (turn.assert?.tools) {
|
|
13966
|
-
try {
|
|
13967
|
-
const expectNewCalls = turn.assert.tools.some((a) => ("called" in a) || ("call_order" in a));
|
|
13968
|
-
const traceData = await getTraceData(result.conversationId, devServerUrl, {
|
|
13969
|
-
previousToolCallCount,
|
|
13970
|
-
expectNewCalls
|
|
13971
|
-
});
|
|
13972
|
-
previousToolCallCount = traceData.totalToolCallCount;
|
|
13973
|
-
allSpans = traceData.raw;
|
|
13974
|
-
const toolResults = gradeTools(traceData.toolCalls, turn.assert.tools);
|
|
13975
|
-
assertions = [...assertions, ...toolResults];
|
|
13976
|
-
} catch (err) {
|
|
13977
|
-
for (const toolAssert of turn.assert.tools) {
|
|
13978
|
-
const name = "called" in toolAssert ? toolAssert.called : ("not_called" in toolAssert) ? toolAssert.not_called : "call_order";
|
|
13979
|
-
assertions.push({
|
|
13980
|
-
assertion: `tool: ${name}`,
|
|
13981
|
-
pass: false,
|
|
13982
|
-
expected: `Tool assertion on ${name}`,
|
|
13983
|
-
actual: `Failed to fetch traces: ${err.message}`
|
|
13984
|
-
});
|
|
13985
|
-
}
|
|
13986
|
-
}
|
|
13987
|
-
}
|
|
13988
|
-
if (turn.assert?.state) {
|
|
13989
|
-
try {
|
|
13990
|
-
const ctx = {
|
|
13991
|
-
botId: connection.botId,
|
|
13992
|
-
userId: session.userId,
|
|
13993
|
-
conversationId: result.conversationId
|
|
13994
|
-
};
|
|
13995
|
-
const stateResults = await gradeState(getBpClient(), turn.assert.state, ctx, preSnapshots);
|
|
13996
|
-
assertions.push(...stateResults);
|
|
13997
|
-
} catch (err) {
|
|
13998
|
-
assertions.push({
|
|
13999
|
-
assertion: "state",
|
|
14000
|
-
pass: false,
|
|
14001
|
-
expected: "State assertions executed",
|
|
14002
|
-
actual: `Error: ${err.message}`
|
|
14003
|
-
});
|
|
14004
|
-
}
|
|
14005
|
-
}
|
|
14006
|
-
if (turn.assert?.tables) {
|
|
14007
|
-
try {
|
|
14008
|
-
const tableResults = await gradeTables(getBpClient(), turn.assert.tables);
|
|
14009
|
-
assertions.push(...tableResults);
|
|
14010
|
-
} catch (err) {
|
|
14011
|
-
assertions.push({
|
|
14012
|
-
assertion: "tables",
|
|
14013
|
-
pass: false,
|
|
14014
|
-
expected: "Table assertions executed",
|
|
14015
|
-
actual: `Error: ${err.message}`
|
|
14016
|
-
});
|
|
14017
|
-
}
|
|
14018
|
-
}
|
|
14019
|
-
if (turn.assert?.workflow) {
|
|
14020
|
-
if (allSpans.length === 0) {
|
|
14021
|
-
try {
|
|
14022
|
-
const traceData = await getTraceData(result.conversationId, devServerUrl);
|
|
14023
|
-
allSpans = traceData.raw;
|
|
14024
|
-
} catch {}
|
|
14025
|
-
}
|
|
14026
|
-
const workflowResults = gradeWorkflows(allSpans, turn.assert.workflow);
|
|
14027
|
-
assertions.push(...workflowResults);
|
|
14028
|
-
}
|
|
14029
|
-
if (turn.assert?.timing) {
|
|
14030
|
-
const timingResults = gradeTiming(botDuration, turn.assert.timing);
|
|
14031
|
-
assertions.push(...timingResults);
|
|
14032
|
-
}
|
|
14033
|
-
const turnPass = assertions.every((a) => a.pass);
|
|
14034
|
-
const evalDuration = Date.now() - evalStart;
|
|
14035
|
-
turns.push({
|
|
14036
|
-
turnNumber: i + 1,
|
|
14037
|
-
userMessage: turnLabel,
|
|
14038
|
-
botResponse,
|
|
14039
|
-
assertions,
|
|
14040
|
-
pass: turnPass,
|
|
14041
|
-
botDuration,
|
|
14042
|
-
evalDuration
|
|
14043
|
-
});
|
|
14044
|
-
}
|
|
14045
|
-
if (evalDef.outcome) {
|
|
14046
|
-
if (allSpans.length === 0 && lastConversationId && evalDef.outcome.workflow) {
|
|
14047
|
-
try {
|
|
14048
|
-
const traceData = await getTraceData(lastConversationId, devServerUrl);
|
|
14049
|
-
allSpans = traceData.raw;
|
|
14050
|
-
} catch {}
|
|
14051
|
-
}
|
|
14052
|
-
const ctx = {
|
|
14053
|
-
botId: connection.botId,
|
|
14054
|
-
userId: session.userId,
|
|
14055
|
-
conversationId: lastConversationId
|
|
14056
|
-
};
|
|
14057
|
-
try {
|
|
14058
|
-
outcomeAssertions = await gradeOutcome(getBpClient(), evalDef, ctx, allSpans, preSnapshots);
|
|
14059
|
-
} catch (err) {
|
|
14060
|
-
outcomeAssertions = [
|
|
14061
|
-
{
|
|
14062
|
-
assertion: "outcome",
|
|
14063
|
-
pass: false,
|
|
14064
|
-
expected: "Outcome assertions executed",
|
|
14065
|
-
actual: `Error: ${err.message}`
|
|
14066
|
-
}
|
|
14067
|
-
];
|
|
14068
|
-
}
|
|
14069
|
-
}
|
|
14070
|
-
const turnsPass = turns.every((t) => t.pass);
|
|
14071
|
-
const outcomePass = outcomeAssertions.every((a) => a.pass);
|
|
14072
|
-
return {
|
|
14073
|
-
name: evalDef.name,
|
|
14074
|
-
description: evalDef.description,
|
|
14075
|
-
type: evalDef.type,
|
|
14076
|
-
tags: evalDef.tags,
|
|
14077
|
-
turns,
|
|
14078
|
-
outcomeAssertions,
|
|
14079
|
-
pass: turnsPass && outcomePass,
|
|
14080
|
-
duration: Date.now() - start
|
|
14081
|
-
};
|
|
14082
|
-
} catch (err) {
|
|
14083
|
-
return {
|
|
14084
|
-
name: evalDef.name,
|
|
14085
|
-
description: evalDef.description,
|
|
14086
|
-
type: evalDef.type,
|
|
14087
|
-
tags: evalDef.tags,
|
|
14088
|
-
turns,
|
|
14089
|
-
outcomeAssertions,
|
|
14090
|
-
pass: false,
|
|
14091
|
-
duration: Date.now() - start,
|
|
14092
|
-
error: err.message
|
|
14093
|
-
};
|
|
14094
|
-
}
|
|
14095
|
-
}
|
|
14096
|
-
async function runEvalSuite(config, filter) {
|
|
14097
|
-
const start = Date.now();
|
|
14098
|
-
const runId = randomUUID().replace(/-/g, "").slice(0, 26);
|
|
14099
|
-
await initLLMJudge({
|
|
14100
|
-
token: config.credentials.token,
|
|
14101
|
-
apiUrl: config.credentials.apiUrl,
|
|
14102
|
-
botId: config.credentials.botId
|
|
14103
|
-
}, { model: config.evalOptions?.judgeModel, logger: config.logger });
|
|
14104
|
-
const evalsDir = `${config.agentPath}/evals`;
|
|
14105
|
-
const allEvals = await loadEvalsFromDir(evalsDir);
|
|
14106
|
-
const evals = filterEvals(allEvals, filter);
|
|
14107
|
-
if (evals.length === 0) {
|
|
14108
|
-
return {
|
|
14109
|
-
id: runId,
|
|
14110
|
-
timestamp: new Date().toISOString(),
|
|
14111
|
-
evals: [],
|
|
14112
|
-
passed: 0,
|
|
14113
|
-
failed: 0,
|
|
14114
|
-
total: 0,
|
|
14115
|
-
duration: 0,
|
|
14116
|
-
filter
|
|
14117
|
-
};
|
|
14118
|
-
}
|
|
14119
|
-
let webhookId = config.credentials.webhookId;
|
|
14120
|
-
if (!webhookId) {
|
|
14121
|
-
webhookId = await discoverWebhookId(config.credentials.botId, config.credentials.token, config.credentials.apiUrl);
|
|
14122
|
-
}
|
|
14123
|
-
const connection = {
|
|
14124
|
-
webhookId,
|
|
14125
|
-
botId: config.credentials.botId,
|
|
14126
|
-
token: config.credentials.token,
|
|
14127
|
-
apiUrl: config.credentials.apiUrl
|
|
14128
|
-
};
|
|
14129
|
-
const devServerUrl = config.devServerUrl || "http://localhost:3001";
|
|
14130
|
-
const reports = [];
|
|
14131
|
-
config.onProgress?.({ type: "suite_start", totalEvals: evals.length });
|
|
14132
|
-
for (let i = 0;i < evals.length; i++) {
|
|
14133
|
-
const evalDef = evals[i];
|
|
14134
|
-
config.onProgress?.({ type: "eval_start", evalName: evalDef.name, index: i });
|
|
14135
|
-
const report = await runEval(evalDef, connection, {
|
|
14136
|
-
devServerUrl,
|
|
14137
|
-
idleTimeout: config.evalOptions?.idleTimeout,
|
|
14138
|
-
judgePassThreshold: config.evalOptions?.judgePassThreshold
|
|
14139
|
-
});
|
|
14140
|
-
reports.push(report);
|
|
14141
|
-
config.onProgress?.({ type: "eval_complete", evalName: evalDef.name, index: i, report });
|
|
14142
|
-
}
|
|
14143
|
-
const runReport = {
|
|
14144
|
-
id: runId,
|
|
14145
|
-
timestamp: new Date().toISOString(),
|
|
14146
|
-
evals: reports,
|
|
14147
|
-
passed: reports.filter((r) => r.pass).length,
|
|
14148
|
-
failed: reports.filter((r) => !r.pass).length,
|
|
14149
|
-
total: reports.length,
|
|
14150
|
-
duration: Date.now() - start,
|
|
14151
|
-
filter
|
|
14152
|
-
};
|
|
14153
|
-
config.onProgress?.({ type: "suite_complete", report: runReport });
|
|
14154
|
-
return runReport;
|
|
14155
|
-
}
|
|
14156
|
-
// src/eval/store.ts
|
|
14157
|
-
import { existsSync as existsSync13, mkdirSync as mkdirSync3, writeFileSync as writeFileSync2, readFileSync as readFileSync6, readdirSync as readdirSync4 } from "fs";
|
|
14158
|
-
import { join as join13 } from "path";
|
|
14159
|
-
function getRunsDir(agentPath) {
|
|
14160
|
-
const dir = join13(agentPath, ".adk", "evals", "runs");
|
|
14161
|
-
if (!existsSync13(dir)) {
|
|
14162
|
-
mkdirSync3(dir, { recursive: true });
|
|
14163
|
-
}
|
|
14164
|
-
return dir;
|
|
14165
|
-
}
|
|
14166
|
-
function saveRunResult(agentPath, report) {
|
|
14167
|
-
const dir = getRunsDir(agentPath);
|
|
14168
|
-
const filename = `${report.timestamp.replace(/[:.]/g, "-")}-${report.id}.json`;
|
|
14169
|
-
const filepath = join13(dir, filename);
|
|
14170
|
-
writeFileSync2(filepath, JSON.stringify(report, null, 2));
|
|
14171
|
-
return filepath;
|
|
14172
|
-
}
|
|
14173
|
-
function loadRunResult(agentPath, runId) {
|
|
14174
|
-
const dir = getRunsDir(agentPath);
|
|
14175
|
-
const files = readdirSync4(dir).filter((f) => f.endsWith(".json"));
|
|
14176
|
-
for (const file of files) {
|
|
14177
|
-
if (file.includes(runId)) {
|
|
14178
|
-
const filepath = join13(dir, file);
|
|
14179
|
-
return JSON.parse(readFileSync6(filepath, "utf-8"));
|
|
14180
|
-
}
|
|
14181
|
-
}
|
|
14182
|
-
return null;
|
|
14183
|
-
}
|
|
14184
|
-
function listRunResults(agentPath, limit = 50) {
|
|
14185
|
-
const dir = getRunsDir(agentPath);
|
|
14186
|
-
if (!existsSync13(dir))
|
|
14187
|
-
return [];
|
|
14188
|
-
const files = readdirSync4(dir).filter((f) => f.endsWith(".json")).sort().reverse().slice(0, limit);
|
|
14189
|
-
return files.map((file) => {
|
|
14190
|
-
const filepath = join13(dir, file);
|
|
14191
|
-
return JSON.parse(readFileSync6(filepath, "utf-8"));
|
|
14192
|
-
});
|
|
14193
|
-
}
|
|
14194
|
-
function getLatestRun(agentPath) {
|
|
14195
|
-
const runs = listRunResults(agentPath, 1);
|
|
14196
|
-
return runs[0] || null;
|
|
14197
|
-
}
|
|
14198
13081
|
export {
|
|
14199
13082
|
workspaceCache,
|
|
14200
13083
|
validateSecretName,
|
|
14201
13084
|
stringifyWithOrder,
|
|
14202
13085
|
startCopilotServer,
|
|
14203
13086
|
setupTestRuntime,
|
|
14204
|
-
saveRunResult,
|
|
14205
13087
|
runScript,
|
|
14206
|
-
runEvalSuite,
|
|
14207
|
-
runEval,
|
|
14208
13088
|
orderKeys,
|
|
14209
|
-
loadRunResult,
|
|
14210
|
-
loadEvalsFromDir,
|
|
14211
|
-
loadEvalFile,
|
|
14212
|
-
loadEvalByName,
|
|
14213
|
-
listRunResults,
|
|
14214
13089
|
integrationKeyOrder,
|
|
14215
13090
|
initAssets,
|
|
14216
13091
|
getRelativeTime,
|
|
14217
|
-
getLatestRun,
|
|
14218
13092
|
getInnerTypeName,
|
|
14219
13093
|
getChatClient,
|
|
14220
13094
|
generateIntegrationTypes,
|
|
@@ -14222,7 +13096,6 @@ export {
|
|
|
14222
13096
|
generateBotProject,
|
|
14223
13097
|
generateAssetsTypes,
|
|
14224
13098
|
generateAssetsRuntime,
|
|
14225
|
-
filterEvals,
|
|
14226
13099
|
dependenciesKeyOrder,
|
|
14227
13100
|
coerceConfigValue,
|
|
14228
13101
|
checkHasProvider,
|
|
@@ -14256,7 +13129,6 @@ export {
|
|
|
14256
13129
|
IntegrationCache,
|
|
14257
13130
|
HubCache,
|
|
14258
13131
|
FileWatcher2 as FileWatcher,
|
|
14259
|
-
Eval,
|
|
14260
13132
|
EnhancedInterfaceCache,
|
|
14261
13133
|
DevIdManager,
|
|
14262
13134
|
CredentialsManager,
|
|
@@ -14277,4 +13149,4 @@ export {
|
|
|
14277
13149
|
AgentProject
|
|
14278
13150
|
};
|
|
14279
13151
|
|
|
14280
|
-
//# debugId=
|
|
13152
|
+
//# debugId=635BFC8F8C87FEDC64756E2164756E21
|