@botpress/adk 1.18.0-beta.5 → 1.18.0-beta.7
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/bot-generator/generator.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 +680 -1773
- package/dist/index.js.map +16 -30
- package/dist/integrations/operations.d.ts +35 -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.7", 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: {} };
|
|
@@ -2871,6 +2875,7 @@ class IntegrationOperations {
|
|
|
2871
2875
|
}
|
|
2872
2876
|
const actualVersion = integrationDefinition.version;
|
|
2873
2877
|
const integrationVersion = `${resolvedInput.fullName}@${actualVersion}`;
|
|
2878
|
+
const requiresConfiguration = integrationRequiresConfiguration(integrationDefinition);
|
|
2874
2879
|
const existingEntry = dependencies.integrations[alias];
|
|
2875
2880
|
if (existingEntry && typeof existingEntry === "object" && "version" in existingEntry) {
|
|
2876
2881
|
dependencies.integrations[alias] = {
|
|
@@ -2880,7 +2885,7 @@ class IntegrationOperations {
|
|
|
2880
2885
|
} else {
|
|
2881
2886
|
dependencies.integrations[alias] = integrationVersion;
|
|
2882
2887
|
}
|
|
2883
|
-
const configWriter =
|
|
2888
|
+
const configWriter = this.createConfigWriter(project.path);
|
|
2884
2889
|
await configWriter.updateDependencies(dependencies);
|
|
2885
2890
|
return {
|
|
2886
2891
|
success: true,
|
|
@@ -2889,22 +2894,23 @@ class IntegrationOperations {
|
|
|
2889
2894
|
fullName: resolvedInput.fullName,
|
|
2890
2895
|
alias: resolvedInput.alias,
|
|
2891
2896
|
version: actualVersion,
|
|
2892
|
-
ref: integrationVersion
|
|
2897
|
+
ref: integrationVersion,
|
|
2898
|
+
requiresConfiguration
|
|
2893
2899
|
};
|
|
2894
2900
|
}
|
|
2895
2901
|
async removeIntegration(name) {
|
|
2896
|
-
const project = await
|
|
2902
|
+
const project = await this.loadAgentProject(this.projectPath || process2.cwd());
|
|
2897
2903
|
const dependencies = project.dependencies;
|
|
2898
2904
|
if (!dependencies || !dependencies.integrations) {
|
|
2899
2905
|
throw this.buildRemoveIntegrationNotFoundError(name);
|
|
2900
2906
|
}
|
|
2901
2907
|
const alias = this.resolveIntegrationRemovalAlias(name, dependencies.integrations);
|
|
2902
2908
|
delete dependencies.integrations[alias];
|
|
2903
|
-
const configWriter =
|
|
2909
|
+
const configWriter = this.createConfigWriter(project.path);
|
|
2904
2910
|
await configWriter.updateDependencies(dependencies);
|
|
2905
2911
|
}
|
|
2906
2912
|
async upgradeIntegration(name) {
|
|
2907
|
-
const project = await
|
|
2913
|
+
const project = await this.loadAgentProject(this.projectPath || process2.cwd());
|
|
2908
2914
|
const dependencies = project.dependencies;
|
|
2909
2915
|
if (!dependencies || !dependencies.integrations) {
|
|
2910
2916
|
throw new Error("No integrations found in dependencies");
|
|
@@ -2940,13 +2946,13 @@ class IntegrationOperations {
|
|
|
2940
2946
|
}
|
|
2941
2947
|
}
|
|
2942
2948
|
if (upgraded.length > 0) {
|
|
2943
|
-
const configWriter =
|
|
2949
|
+
const configWriter = this.createConfigWriter(project.path);
|
|
2944
2950
|
await configWriter.updateDependencies(dependencies);
|
|
2945
2951
|
}
|
|
2946
2952
|
return { upgraded, failed };
|
|
2947
2953
|
}
|
|
2948
2954
|
async listIntegrations() {
|
|
2949
|
-
const project = await
|
|
2955
|
+
const project = await this.loadAgentProject(this.projectPath || process2.cwd());
|
|
2950
2956
|
const dependencies = project.dependencies;
|
|
2951
2957
|
if (!dependencies || !dependencies.integrations) {
|
|
2952
2958
|
return [];
|
|
@@ -2993,12 +2999,37 @@ class IntegrationOperations {
|
|
|
2993
2999
|
}));
|
|
2994
3000
|
}
|
|
2995
3001
|
}
|
|
3002
|
+
function integrationRequiresConfiguration(definition) {
|
|
3003
|
+
const config = definition.configuration;
|
|
3004
|
+
if (!config)
|
|
3005
|
+
return true;
|
|
3006
|
+
if (config.identifier?.required)
|
|
3007
|
+
return true;
|
|
3008
|
+
if (config.identifier?.linkTemplateScript)
|
|
3009
|
+
return true;
|
|
3010
|
+
const required = config.schema?.required;
|
|
3011
|
+
if (Array.isArray(required) && required.length > 0)
|
|
3012
|
+
return true;
|
|
3013
|
+
return false;
|
|
3014
|
+
}
|
|
3015
|
+
function resolveIntegrationEnabled(integration, cloudEnabled) {
|
|
3016
|
+
if (integration.enabled !== undefined) {
|
|
3017
|
+
return integration.enabled;
|
|
3018
|
+
}
|
|
3019
|
+
if (cloudEnabled !== undefined) {
|
|
3020
|
+
return cloudEnabled;
|
|
3021
|
+
}
|
|
3022
|
+
if (integration.definition && !integrationRequiresConfiguration(integration.definition)) {
|
|
3023
|
+
return true;
|
|
3024
|
+
}
|
|
3025
|
+
return false;
|
|
3026
|
+
}
|
|
2996
3027
|
var init_operations = __esm(() => {
|
|
2997
3028
|
init_auth();
|
|
2998
3029
|
init_agent_project();
|
|
3030
|
+
init_config_writer();
|
|
2999
3031
|
init_manager2();
|
|
3000
3032
|
init_hub_cache();
|
|
3001
|
-
init_config_writer();
|
|
3002
3033
|
});
|
|
3003
3034
|
|
|
3004
3035
|
// src/integrations/config-utils.ts
|
|
@@ -3840,13 +3871,116 @@ var init_expand_exports = __esm(() => {
|
|
|
3840
3871
|
init_types();
|
|
3841
3872
|
});
|
|
3842
3873
|
|
|
3874
|
+
// src/agent-project/component-source-resolver.ts
|
|
3875
|
+
import { Project as Project2, SyntaxKind as SyntaxKind2 } from "ts-morph";
|
|
3876
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
3877
|
+
import * as path13 from "path";
|
|
3878
|
+
function resolveComponentSources(absolutePath) {
|
|
3879
|
+
const project = new Project2({ useInMemoryFileSystem: false, skipAddingFilesFromTsConfig: true });
|
|
3880
|
+
const sourceFile = project.createSourceFile(absolutePath, readFileSync3(absolutePath, "utf-8"), { overwrite: true });
|
|
3881
|
+
const importBindings = collectBpTsxImports(sourceFile, absolutePath);
|
|
3882
|
+
if (importBindings.size === 0) {
|
|
3883
|
+
return new Map;
|
|
3884
|
+
}
|
|
3885
|
+
const localToSource = resolveLocalBindings(sourceFile, importBindings);
|
|
3886
|
+
return resolveExports(sourceFile, localToSource, importBindings);
|
|
3887
|
+
}
|
|
3888
|
+
function collectBpTsxImports(sourceFile, absolutePath) {
|
|
3889
|
+
const imports = new Map;
|
|
3890
|
+
const dir = path13.dirname(absolutePath);
|
|
3891
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3892
|
+
const specifier = decl.getModuleSpecifierValue();
|
|
3893
|
+
if (!specifier.endsWith(BP_TSX_SUFFIX))
|
|
3894
|
+
continue;
|
|
3895
|
+
const resolved = path13.resolve(dir, specifier);
|
|
3896
|
+
const defaultImport = decl.getDefaultImport();
|
|
3897
|
+
if (defaultImport) {
|
|
3898
|
+
imports.set(defaultImport.getText(), resolved);
|
|
3899
|
+
}
|
|
3900
|
+
const namespaceImport = decl.getNamespaceImport();
|
|
3901
|
+
if (namespaceImport) {
|
|
3902
|
+
imports.set(namespaceImport.getText(), resolved);
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
return imports;
|
|
3906
|
+
}
|
|
3907
|
+
function resolveLocalBindings(sourceFile, importBindings) {
|
|
3908
|
+
const result = new Map;
|
|
3909
|
+
for (const stmt of sourceFile.getVariableStatements()) {
|
|
3910
|
+
for (const decl of stmt.getDeclarations()) {
|
|
3911
|
+
const initializer = decl.getInitializer();
|
|
3912
|
+
if (!initializer)
|
|
3913
|
+
continue;
|
|
3914
|
+
const source = sourceFromCustomComponentExpr(initializer, importBindings);
|
|
3915
|
+
if (source) {
|
|
3916
|
+
result.set(decl.getName(), source);
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3919
|
+
}
|
|
3920
|
+
return result;
|
|
3921
|
+
}
|
|
3922
|
+
function resolveExports(sourceFile, localToSource, importBindings) {
|
|
3923
|
+
const exportMap = new Map;
|
|
3924
|
+
for (const stmt of sourceFile.getVariableStatements()) {
|
|
3925
|
+
if (!stmt.isExported())
|
|
3926
|
+
continue;
|
|
3927
|
+
for (const decl of stmt.getDeclarations()) {
|
|
3928
|
+
const source = localToSource.get(decl.getName());
|
|
3929
|
+
if (source)
|
|
3930
|
+
exportMap.set(decl.getName(), source);
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
for (const assignment of sourceFile.getExportAssignments()) {
|
|
3934
|
+
if (assignment.isExportEquals())
|
|
3935
|
+
continue;
|
|
3936
|
+
const expr = assignment.getExpression();
|
|
3937
|
+
const direct = sourceFromCustomComponentExpr(expr, importBindings);
|
|
3938
|
+
if (direct) {
|
|
3939
|
+
exportMap.set("default", direct);
|
|
3940
|
+
continue;
|
|
3941
|
+
}
|
|
3942
|
+
if (expr.getKind() === SyntaxKind2.Identifier) {
|
|
3943
|
+
const fromLocal = localToSource.get(expr.getText());
|
|
3944
|
+
if (fromLocal)
|
|
3945
|
+
exportMap.set("default", fromLocal);
|
|
3946
|
+
}
|
|
3947
|
+
}
|
|
3948
|
+
for (const decl of sourceFile.getExportDeclarations()) {
|
|
3949
|
+
if (decl.getModuleSpecifier())
|
|
3950
|
+
continue;
|
|
3951
|
+
for (const named of decl.getNamedExports()) {
|
|
3952
|
+
const localName = named.getNameNode().getText();
|
|
3953
|
+
const aliasNode = named.getAliasNode();
|
|
3954
|
+
const exportName = aliasNode ? aliasNode.getText() : localName;
|
|
3955
|
+
const source = localToSource.get(localName);
|
|
3956
|
+
if (source)
|
|
3957
|
+
exportMap.set(exportName, source);
|
|
3958
|
+
}
|
|
3959
|
+
}
|
|
3960
|
+
return exportMap;
|
|
3961
|
+
}
|
|
3962
|
+
function sourceFromCustomComponentExpr(expr, importBindings) {
|
|
3963
|
+
if (expr.getKind() !== SyntaxKind2.NewExpression)
|
|
3964
|
+
return;
|
|
3965
|
+
const newExpr = expr.asKindOrThrow(SyntaxKind2.NewExpression);
|
|
3966
|
+
if (newExpr.getExpression().getText() !== CUSTOM_COMPONENT_CLASS)
|
|
3967
|
+
return;
|
|
3968
|
+
const args = newExpr.getArguments();
|
|
3969
|
+
const firstArg = args[0];
|
|
3970
|
+
if (!firstArg || firstArg.getKind() !== SyntaxKind2.Identifier)
|
|
3971
|
+
return;
|
|
3972
|
+
return importBindings.get(firstArg.getText());
|
|
3973
|
+
}
|
|
3974
|
+
var CUSTOM_COMPONENT_CLASS = "CustomComponent", BP_TSX_SUFFIX = ".bp.tsx";
|
|
3975
|
+
var init_component_source_resolver = () => {};
|
|
3976
|
+
|
|
3843
3977
|
// src/agent-project/agent-project.ts
|
|
3844
3978
|
import { BuiltInActions, BuiltInWorkflows, Errors as Errors2, Primitives as Primitives2, setAdkCommand } from "@botpress/runtime/internal";
|
|
3845
3979
|
import { Autonomous } from "@botpress/runtime";
|
|
3846
3980
|
import createDebug2 from "debug";
|
|
3847
3981
|
import { createRequire as createRequire4 } from "module";
|
|
3848
3982
|
import fs10 from "fs/promises";
|
|
3849
|
-
import
|
|
3983
|
+
import path14 from "path";
|
|
3850
3984
|
function getToolDefinition(value) {
|
|
3851
3985
|
if (typeof value !== "object" || value === null) {
|
|
3852
3986
|
return;
|
|
@@ -3869,6 +4003,7 @@ var init_agent_project = __esm(() => {
|
|
|
3869
4003
|
init_interfaces();
|
|
3870
4004
|
init_json_ordering();
|
|
3871
4005
|
init_expand_exports();
|
|
4006
|
+
init_component_source_resolver();
|
|
3872
4007
|
init_agent_resolver();
|
|
3873
4008
|
init_types();
|
|
3874
4009
|
init_validation_errors();
|
|
@@ -3899,7 +4034,7 @@ var init_agent_project = __esm(() => {
|
|
|
3899
4034
|
_tools = [];
|
|
3900
4035
|
constructor(projectPath, options = {}) {
|
|
3901
4036
|
this._options = options;
|
|
3902
|
-
this._path =
|
|
4037
|
+
this._path = path14.resolve(projectPath);
|
|
3903
4038
|
this._integrationManager = new IntegrationManager({
|
|
3904
4039
|
noCache: options.noCache
|
|
3905
4040
|
});
|
|
@@ -3911,7 +4046,7 @@ var init_agent_project = __esm(() => {
|
|
|
3911
4046
|
});
|
|
3912
4047
|
}
|
|
3913
4048
|
static async load(projectPath, options = {}) {
|
|
3914
|
-
const resolvedPath =
|
|
4049
|
+
const resolvedPath = path14.resolve(projectPath);
|
|
3915
4050
|
if (!options.noCache) {
|
|
3916
4051
|
const cached = AgentProject._projectCache.get(resolvedPath);
|
|
3917
4052
|
if (cached) {
|
|
@@ -3929,7 +4064,7 @@ var init_agent_project = __esm(() => {
|
|
|
3929
4064
|
AgentProject._projectCache.clear();
|
|
3930
4065
|
}
|
|
3931
4066
|
static clearCacheForPath(projectPath) {
|
|
3932
|
-
const resolvedPath =
|
|
4067
|
+
const resolvedPath = path14.resolve(projectPath);
|
|
3933
4068
|
AgentProject._projectCache.delete(resolvedPath);
|
|
3934
4069
|
}
|
|
3935
4070
|
get path() {
|
|
@@ -4045,13 +4180,13 @@ var init_agent_project = __esm(() => {
|
|
|
4045
4180
|
const requiredFiles = ["agent.config.ts"];
|
|
4046
4181
|
for (const file of requiredFiles) {
|
|
4047
4182
|
try {
|
|
4048
|
-
await fs10.access(
|
|
4183
|
+
await fs10.access(path14.join(this._path, file));
|
|
4049
4184
|
} catch {
|
|
4050
4185
|
errors.push(ValidationErrors.requiredFileMissing(file));
|
|
4051
4186
|
}
|
|
4052
4187
|
}
|
|
4053
4188
|
try {
|
|
4054
|
-
await fs10.access(
|
|
4189
|
+
await fs10.access(path14.join(this._path, "agent.json"));
|
|
4055
4190
|
} catch {
|
|
4056
4191
|
info.push({
|
|
4057
4192
|
$type: "ValidationError",
|
|
@@ -4065,7 +4200,7 @@ var init_agent_project = __esm(() => {
|
|
|
4065
4200
|
const expectedDirs = ["actions", "workflows", "conversations", "assets"];
|
|
4066
4201
|
for (const dir of expectedDirs) {
|
|
4067
4202
|
try {
|
|
4068
|
-
const stats = await fs10.stat(
|
|
4203
|
+
const stats = await fs10.stat(path14.join(this._path, dir));
|
|
4069
4204
|
if (!stats.isDirectory()) {
|
|
4070
4205
|
warnings.push(ValidationErrors.invalidStructure(dir, "directory"));
|
|
4071
4206
|
}
|
|
@@ -4138,7 +4273,7 @@ var init_agent_project = __esm(() => {
|
|
|
4138
4273
|
}
|
|
4139
4274
|
async createAgentInfo(info) {
|
|
4140
4275
|
const { devId, ...agentJsonInfo } = info;
|
|
4141
|
-
const agentPath =
|
|
4276
|
+
const agentPath = path14.join(this._path, "agent.json");
|
|
4142
4277
|
const agentContent = stringifyWithOrder(agentJsonInfo, agentInfoKeyOrder);
|
|
4143
4278
|
await fs10.writeFile(agentPath, agentContent);
|
|
4144
4279
|
this._agentInfo = info;
|
|
@@ -4153,7 +4288,7 @@ var init_agent_project = __esm(() => {
|
|
|
4153
4288
|
const { devId, ...agentJsonUpdates } = updates;
|
|
4154
4289
|
const updatedInfo = { ...this._agentInfo, ...agentJsonUpdates };
|
|
4155
4290
|
const { devId: _devId, ...agentJsonData } = updatedInfo;
|
|
4156
|
-
const agentPath =
|
|
4291
|
+
const agentPath = path14.join(this._path, "agent.json");
|
|
4157
4292
|
const agentContent = stringifyWithOrder(agentJsonData, agentInfoKeyOrder);
|
|
4158
4293
|
await fs10.writeFile(agentPath, agentContent);
|
|
4159
4294
|
this._agentInfo = updatedInfo;
|
|
@@ -4162,7 +4297,7 @@ var init_agent_project = __esm(() => {
|
|
|
4162
4297
|
}
|
|
4163
4298
|
}
|
|
4164
4299
|
async createAgentLocalInfo(info) {
|
|
4165
|
-
const localPath =
|
|
4300
|
+
const localPath = path14.join(this._path, "agent.local.json");
|
|
4166
4301
|
let existing = {};
|
|
4167
4302
|
try {
|
|
4168
4303
|
const content2 = await fs10.readFile(localPath, "utf-8");
|
|
@@ -4190,7 +4325,7 @@ var init_agent_project = __esm(() => {
|
|
|
4190
4325
|
}
|
|
4191
4326
|
}
|
|
4192
4327
|
async updateAgentLocalInfo(updates) {
|
|
4193
|
-
const localPath =
|
|
4328
|
+
const localPath = path14.join(this._path, "agent.local.json");
|
|
4194
4329
|
let existing = {};
|
|
4195
4330
|
try {
|
|
4196
4331
|
const content2 = await fs10.readFile(localPath, "utf-8");
|
|
@@ -4223,10 +4358,10 @@ var init_agent_project = __esm(() => {
|
|
|
4223
4358
|
}
|
|
4224
4359
|
async loadConfig() {
|
|
4225
4360
|
try {
|
|
4226
|
-
const configPath =
|
|
4361
|
+
const configPath = path14.join(this._path, "agent.config.ts");
|
|
4227
4362
|
debug2("loading agent.config.ts from %s", configPath);
|
|
4228
|
-
const projectRequire = createRequire4(
|
|
4229
|
-
debug2("created projectRequire from %s",
|
|
4363
|
+
const projectRequire = createRequire4(path14.join(this._path, "package.json"));
|
|
4364
|
+
debug2("created projectRequire from %s", path14.join(this._path, "package.json"));
|
|
4230
4365
|
try {
|
|
4231
4366
|
const resolvedPath = projectRequire.resolve(configPath);
|
|
4232
4367
|
debug2("resolved config path: %s", resolvedPath);
|
|
@@ -4409,8 +4544,8 @@ ${err.stack?.split(`
|
|
|
4409
4544
|
}
|
|
4410
4545
|
}
|
|
4411
4546
|
isBarrelReexport(existing, newPath, newExport, newDefinition) {
|
|
4412
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4413
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4547
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path14.basename(newPath));
|
|
4548
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path14.basename(existing.path));
|
|
4414
4549
|
if (!isNewBarrel && !isExistingBarrel) {
|
|
4415
4550
|
return false;
|
|
4416
4551
|
}
|
|
@@ -4422,16 +4557,16 @@ ${err.stack?.split(`
|
|
|
4422
4557
|
return true;
|
|
4423
4558
|
}
|
|
4424
4559
|
isToolBarrelReexport(existingPath, newPath) {
|
|
4425
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4426
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4560
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path14.basename(newPath));
|
|
4561
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path14.basename(existingPath));
|
|
4427
4562
|
if (!isNewBarrel && !isExistingBarrel) {
|
|
4428
4563
|
return false;
|
|
4429
4564
|
}
|
|
4430
4565
|
return true;
|
|
4431
4566
|
}
|
|
4432
4567
|
shouldPreferToolDefinition(existingPath, newPath) {
|
|
4433
|
-
const isNewBarrel = /^index\.[tj]s$/i.test(
|
|
4434
|
-
const isExistingBarrel = /^index\.[tj]s$/i.test(
|
|
4568
|
+
const isNewBarrel = /^index\.[tj]s$/i.test(path14.basename(newPath));
|
|
4569
|
+
const isExistingBarrel = /^index\.[tj]s$/i.test(path14.basename(existingPath));
|
|
4435
4570
|
return isExistingBarrel && !isNewBarrel;
|
|
4436
4571
|
}
|
|
4437
4572
|
getChannelsList(channelSpec) {
|
|
@@ -4447,7 +4582,7 @@ ${err.stack?.split(`
|
|
|
4447
4582
|
if (this._options.adkCommand) {
|
|
4448
4583
|
setAdkCommand(this._options.adkCommand);
|
|
4449
4584
|
}
|
|
4450
|
-
const src =
|
|
4585
|
+
const src = path14.join(this._path, "src");
|
|
4451
4586
|
if (!await fs10.stat(src).catch(() => false)) {
|
|
4452
4587
|
this._errors.push({
|
|
4453
4588
|
$type: "ValidationError",
|
|
@@ -4463,8 +4598,8 @@ ${err.stack?.split(`
|
|
|
4463
4598
|
});
|
|
4464
4599
|
for (const file of allFiles.filter((x) => x.isFile())) {
|
|
4465
4600
|
const filename = file.name;
|
|
4466
|
-
const absolutePath =
|
|
4467
|
-
const relPath =
|
|
4601
|
+
const absolutePath = path14.join(file.parentPath, file.name);
|
|
4602
|
+
const relPath = path14.relative(this.path, absolutePath);
|
|
4468
4603
|
if (filename.toLowerCase().endsWith(".d.ts")) {
|
|
4469
4604
|
continue;
|
|
4470
4605
|
}
|
|
@@ -4491,6 +4626,7 @@ ${err.stack?.split(`
|
|
|
4491
4626
|
filename,
|
|
4492
4627
|
onWarning: (warning) => this._warnings.push(warning)
|
|
4493
4628
|
});
|
|
4629
|
+
let componentSources;
|
|
4494
4630
|
for (const key of Object.keys(expandedExports)) {
|
|
4495
4631
|
let definition;
|
|
4496
4632
|
try {
|
|
@@ -4615,9 +4751,27 @@ ${err.stack?.split(`
|
|
|
4615
4751
|
path: relPath
|
|
4616
4752
|
});
|
|
4617
4753
|
} else if (Primitives2.Definitions.isCustomComponentDefinition(definition)) {
|
|
4754
|
+
if (componentSources === undefined) {
|
|
4755
|
+
try {
|
|
4756
|
+
componentSources = resolveComponentSources(absolutePath);
|
|
4757
|
+
} catch (error) {
|
|
4758
|
+
componentSources = new Map;
|
|
4759
|
+
this._warnings.push({
|
|
4760
|
+
$type: "ValidationError",
|
|
4761
|
+
code: "INVALID_PRIMITIVE_DEFINITION" /* INVALID_PRIMITIVE_DEFINITION */,
|
|
4762
|
+
severity: "warning" /* WARNING */,
|
|
4763
|
+
message: `Failed to parse component sources from ${relPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
4764
|
+
file: relPath
|
|
4765
|
+
});
|
|
4766
|
+
}
|
|
4767
|
+
}
|
|
4768
|
+
const source = componentSources.get(key);
|
|
4618
4769
|
const existing = this._customComponents.find((p) => p.definition.name === definition.name);
|
|
4619
4770
|
if (existing) {
|
|
4620
4771
|
if (this.isBarrelReexport(existing, relPath, key, definition)) {
|
|
4772
|
+
if (existing.path === relPath && source) {
|
|
4773
|
+
existing.source = source;
|
|
4774
|
+
}
|
|
4621
4775
|
continue;
|
|
4622
4776
|
}
|
|
4623
4777
|
this._warnings.push({
|
|
@@ -4632,7 +4786,8 @@ ${err.stack?.split(`
|
|
|
4632
4786
|
this._customComponents.push({
|
|
4633
4787
|
definition,
|
|
4634
4788
|
export: key,
|
|
4635
|
-
path: relPath
|
|
4789
|
+
path: relPath,
|
|
4790
|
+
source: source ?? ""
|
|
4636
4791
|
});
|
|
4637
4792
|
} else if (Primitives2.Definitions.isTableDefinition(definition)) {
|
|
4638
4793
|
const existing = this._tables.find((p) => p.definition.name === definition.name);
|
|
@@ -4699,6 +4854,20 @@ ${err.stack?.split(`
|
|
|
4699
4854
|
});
|
|
4700
4855
|
}
|
|
4701
4856
|
}
|
|
4857
|
+
const unresolved = this._customComponents.filter((c) => !c.source);
|
|
4858
|
+
if (unresolved.length > 0) {
|
|
4859
|
+
this._customComponents = this._customComponents.filter((c) => c.source);
|
|
4860
|
+
for (const comp of unresolved) {
|
|
4861
|
+
this._errors.push({
|
|
4862
|
+
$type: "ValidationError",
|
|
4863
|
+
code: "INVALID_PRIMITIVE_DEFINITION" /* INVALID_PRIMITIVE_DEFINITION */,
|
|
4864
|
+
severity: "error" /* ERROR */,
|
|
4865
|
+
message: `Cannot resolve .bp.tsx source for custom component "${comp.definition.name}" exported from ${comp.path} as "${comp.export}".`,
|
|
4866
|
+
file: comp.path,
|
|
4867
|
+
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, ...)`."
|
|
4868
|
+
});
|
|
4869
|
+
}
|
|
4870
|
+
}
|
|
4702
4871
|
}
|
|
4703
4872
|
};
|
|
4704
4873
|
});
|
|
@@ -4708,7 +4877,7 @@ var exports_action_types = {};
|
|
|
4708
4877
|
__export(exports_action_types, {
|
|
4709
4878
|
generateActionTypes: () => generateActionTypes
|
|
4710
4879
|
});
|
|
4711
|
-
import
|
|
4880
|
+
import path40 from "path";
|
|
4712
4881
|
async function generateActionTypes(project) {
|
|
4713
4882
|
const actionDefs = [];
|
|
4714
4883
|
for (const action of project.actions) {
|
|
@@ -4723,7 +4892,7 @@ async function generateActionTypes(project) {
|
|
|
4723
4892
|
};`);
|
|
4724
4893
|
continue;
|
|
4725
4894
|
}
|
|
4726
|
-
const absolutePath =
|
|
4895
|
+
const absolutePath = path40.join(project.path, action.path);
|
|
4727
4896
|
const actionModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
4728
4897
|
const actionInstance = actionModule[action.export] || actionModule.default;
|
|
4729
4898
|
if (actionInstance && actionInstance.input && actionInstance.output) {
|
|
@@ -4768,7 +4937,7 @@ ${actionDefs.join(`
|
|
|
4768
4937
|
};
|
|
4769
4938
|
}
|
|
4770
4939
|
`;
|
|
4771
|
-
const actionTypesPath =
|
|
4940
|
+
const actionTypesPath = path40.join(project.path, ".adk", "action-types.d.ts");
|
|
4772
4941
|
await createFile(actionTypesPath, await formatCode(content));
|
|
4773
4942
|
}
|
|
4774
4943
|
var init_action_types = __esm(() => {
|
|
@@ -4781,7 +4950,7 @@ var exports_integration_action_types = {};
|
|
|
4781
4950
|
__export(exports_integration_action_types, {
|
|
4782
4951
|
generateIntegrationActionTypes: () => generateIntegrationActionTypes
|
|
4783
4952
|
});
|
|
4784
|
-
import
|
|
4953
|
+
import path41 from "path";
|
|
4785
4954
|
async function generateIntegrationActionTypes(project) {
|
|
4786
4955
|
const content = `
|
|
4787
4956
|
////////////////////////////////////////////////////////
|
|
@@ -4815,7 +4984,7 @@ type IntegrationsMap<T> = {
|
|
|
4815
4984
|
export type IntegrationActions = IntegrationsMap<Integrations>;
|
|
4816
4985
|
}
|
|
4817
4986
|
`;
|
|
4818
|
-
const integrationActionTypesPath =
|
|
4987
|
+
const integrationActionTypesPath = path41.join(project.path, ".adk", "integration-action-types.d.ts");
|
|
4819
4988
|
await createFile(integrationActionTypesPath, await formatCode(content));
|
|
4820
4989
|
}
|
|
4821
4990
|
var init_integration_action_types = __esm(() => {
|
|
@@ -4827,7 +4996,7 @@ var init_integration_action_types = __esm(() => {
|
|
|
4827
4996
|
var require_package = __commonJS((exports, module) => {
|
|
4828
4997
|
module.exports = {
|
|
4829
4998
|
name: "@botpress/adk",
|
|
4830
|
-
version: "1.18.0-beta.
|
|
4999
|
+
version: "1.18.0-beta.7",
|
|
4831
5000
|
description: "Core ADK library for building AI agents on Botpress",
|
|
4832
5001
|
keywords: [
|
|
4833
5002
|
"adk",
|
|
@@ -4876,7 +5045,7 @@ var require_package = __commonJS((exports, module) => {
|
|
|
4876
5045
|
"@botpress/cli": "~6.3.2",
|
|
4877
5046
|
"@botpress/client": "~1.39.0",
|
|
4878
5047
|
"@botpress/cognitive": "~0.5.2",
|
|
4879
|
-
"@botpress/runtime": "^1.18.0-beta.
|
|
5048
|
+
"@botpress/runtime": "^1.18.0-beta.7",
|
|
4880
5049
|
"@botpress/sdk": "~6.4.4",
|
|
4881
5050
|
"@bpinternal/jex": "^1.2.4",
|
|
4882
5051
|
"@bpinternal/yargs-extra": "^0.0.21",
|
|
@@ -4896,10 +5065,10 @@ var require_package = __commonJS((exports, module) => {
|
|
|
4896
5065
|
typescript: ">=4.5.0"
|
|
4897
5066
|
},
|
|
4898
5067
|
engines: {
|
|
4899
|
-
bun: ">=1.3.
|
|
5068
|
+
bun: ">=1.3.13",
|
|
4900
5069
|
node: ">=22.0.0"
|
|
4901
5070
|
},
|
|
4902
|
-
packageManager: "bun@1.3.
|
|
5071
|
+
packageManager: "bun@1.3.13"
|
|
4903
5072
|
};
|
|
4904
5073
|
});
|
|
4905
5074
|
|
|
@@ -4943,7 +5112,7 @@ import os3 from "os";
|
|
|
4943
5112
|
import path4 from "path";
|
|
4944
5113
|
import createDebug from "debug";
|
|
4945
5114
|
var debug = createDebug("adk:bp-cli");
|
|
4946
|
-
var BP_CLI_VERSION = "6.3.
|
|
5115
|
+
var BP_CLI_VERSION = "6.3.5";
|
|
4947
5116
|
var BP_CLI_INSTALL_ALL = path4.join(os3.homedir(), ".adk", `bp-cli`);
|
|
4948
5117
|
var BP_CLI_INSTALL_DIR = path4.join(BP_CLI_INSTALL_ALL, BP_CLI_VERSION);
|
|
4949
5118
|
var BP_CLI_BIN_PATH = path4.join(BP_CLI_INSTALL_DIR, "node_modules", "@botpress", "cli", "bin.js");
|
|
@@ -5843,7 +6012,7 @@ function buildOpenCodeConfig(options) {
|
|
|
5843
6012
|
}
|
|
5844
6013
|
|
|
5845
6014
|
// src/commands/copilot-server.ts
|
|
5846
|
-
var OPENCODE_VERSION = "
|
|
6015
|
+
var OPENCODE_VERSION = "1.3.13";
|
|
5847
6016
|
async function findFreePort() {
|
|
5848
6017
|
return new Promise((resolve3, reject) => {
|
|
5849
6018
|
const server = createServer();
|
|
@@ -6044,7 +6213,7 @@ function fileHasProvider(configPath) {
|
|
|
6044
6213
|
return false;
|
|
6045
6214
|
}
|
|
6046
6215
|
function checkHasProvider(agentPath) {
|
|
6047
|
-
const projectConfig = join4(agentPath, "opencode.json");
|
|
6216
|
+
const projectConfig = join4(agentPath, ".adk", "opencode.json");
|
|
6048
6217
|
if (fileHasProvider(projectConfig))
|
|
6049
6218
|
return true;
|
|
6050
6219
|
const globalConfig = getGlobalConfigPath();
|
|
@@ -6140,7 +6309,7 @@ init_agent_project();
|
|
|
6140
6309
|
init_types();
|
|
6141
6310
|
import { watch } from "fs";
|
|
6142
6311
|
import { EventEmitter as EventEmitter2 } from "events";
|
|
6143
|
-
import
|
|
6312
|
+
import path15 from "path";
|
|
6144
6313
|
|
|
6145
6314
|
class FileWatcher extends EventEmitter2 {
|
|
6146
6315
|
basePath;
|
|
@@ -6164,7 +6333,7 @@ class FileWatcher extends EventEmitter2 {
|
|
|
6164
6333
|
this.watcher = watch(this.basePath, { recursive: true }, (eventType, filename) => {
|
|
6165
6334
|
if (!filename)
|
|
6166
6335
|
return;
|
|
6167
|
-
const fullPath =
|
|
6336
|
+
const fullPath = path15.join(this.basePath, filename);
|
|
6168
6337
|
const relativePath = filename;
|
|
6169
6338
|
if (this.shouldIgnore(relativePath)) {
|
|
6170
6339
|
return;
|
|
@@ -6401,12 +6570,12 @@ class ConfigManager {
|
|
|
6401
6570
|
}
|
|
6402
6571
|
// src/secrets/manager.ts
|
|
6403
6572
|
import fs11 from "fs/promises";
|
|
6404
|
-
import
|
|
6573
|
+
import path16 from "path";
|
|
6405
6574
|
|
|
6406
6575
|
class SecretsManager {
|
|
6407
6576
|
storePath;
|
|
6408
6577
|
constructor(projectPath) {
|
|
6409
|
-
this.storePath =
|
|
6578
|
+
this.storePath = path16.join(projectPath, ".adk", "secrets.json");
|
|
6410
6579
|
}
|
|
6411
6580
|
async readStore() {
|
|
6412
6581
|
try {
|
|
@@ -6417,7 +6586,7 @@ class SecretsManager {
|
|
|
6417
6586
|
}
|
|
6418
6587
|
}
|
|
6419
6588
|
async writeStore(store) {
|
|
6420
|
-
await fs11.mkdir(
|
|
6589
|
+
await fs11.mkdir(path16.dirname(this.storePath), { recursive: true });
|
|
6421
6590
|
const tmpPath = `${this.storePath}.tmp`;
|
|
6422
6591
|
await fs11.writeFile(tmpPath, JSON.stringify(store, null, 2) + `
|
|
6423
6592
|
`, { encoding: "utf-8", mode: 384 });
|
|
@@ -6464,7 +6633,7 @@ import { validateSecretName } from "@botpress/runtime/definition";
|
|
|
6464
6633
|
// src/agent-init/agent-project-generator.ts
|
|
6465
6634
|
init_utils();
|
|
6466
6635
|
import * as fs12 from "fs";
|
|
6467
|
-
import * as
|
|
6636
|
+
import * as path17 from "path";
|
|
6468
6637
|
import { fileURLToPath } from "url";
|
|
6469
6638
|
import { createRequire as createRequire5 } from "module";
|
|
6470
6639
|
|
|
@@ -6564,7 +6733,7 @@ var TEXT_EXTENSIONS = new Set([
|
|
|
6564
6733
|
function isTextFile(filename) {
|
|
6565
6734
|
if (filename === ".gitignore")
|
|
6566
6735
|
return true;
|
|
6567
|
-
const ext =
|
|
6736
|
+
const ext = path17.extname(filename).toLowerCase();
|
|
6568
6737
|
return TEXT_EXTENSIONS.has(ext);
|
|
6569
6738
|
}
|
|
6570
6739
|
|
|
@@ -6574,8 +6743,8 @@ class AgentProjectGenerator {
|
|
|
6574
6743
|
packageManager;
|
|
6575
6744
|
template;
|
|
6576
6745
|
constructor(projectPath, packageManager = "bun", template = "blank") {
|
|
6577
|
-
this.projectPath =
|
|
6578
|
-
this.projectName =
|
|
6746
|
+
this.projectPath = path17.resolve(projectPath);
|
|
6747
|
+
this.projectName = path17.basename(this.projectPath);
|
|
6579
6748
|
this.packageManager = packageManager;
|
|
6580
6749
|
this.template = template;
|
|
6581
6750
|
}
|
|
@@ -6583,20 +6752,20 @@ class AgentProjectGenerator {
|
|
|
6583
6752
|
this.ensureEmptyDirectory();
|
|
6584
6753
|
const templateDir = this.resolveTemplateDir();
|
|
6585
6754
|
await this.copyTemplateFiles(templateDir);
|
|
6586
|
-
if (!fs12.existsSync(
|
|
6755
|
+
if (!fs12.existsSync(path17.join(this.projectPath, "agent.json"))) {
|
|
6587
6756
|
this.createAgentJson();
|
|
6588
6757
|
}
|
|
6589
|
-
if (!fs12.existsSync(
|
|
6758
|
+
if (!fs12.existsSync(path17.join(this.projectPath, "CLAUDE.md"))) {
|
|
6590
6759
|
this.createAIAssistantInstructions();
|
|
6591
6760
|
}
|
|
6592
|
-
if (!fs12.existsSync(
|
|
6761
|
+
if (!fs12.existsSync(path17.join(this.projectPath, ".adk", "opencode.json"))) {
|
|
6593
6762
|
this.createOpenCodeConfig();
|
|
6594
6763
|
}
|
|
6595
6764
|
}
|
|
6596
6765
|
static getAvailableTemplates() {
|
|
6597
6766
|
try {
|
|
6598
6767
|
const templatesRoot = AgentProjectGenerator.getTemplatesRoot();
|
|
6599
|
-
const configPath =
|
|
6768
|
+
const configPath = path17.join(templatesRoot, "template.config.json");
|
|
6600
6769
|
if (!fs12.existsSync(configPath)) {
|
|
6601
6770
|
return [];
|
|
6602
6771
|
}
|
|
@@ -6624,16 +6793,16 @@ class AgentProjectGenerator {
|
|
|
6624
6793
|
try {
|
|
6625
6794
|
const esmRequire = createRequire5(import.meta.url);
|
|
6626
6795
|
const adkPkgPath = esmRequire.resolve("@botpress/adk/package.json");
|
|
6627
|
-
const adkRoot =
|
|
6628
|
-
candidates.push(
|
|
6629
|
-
candidates.push(
|
|
6796
|
+
const adkRoot = path17.dirname(adkPkgPath);
|
|
6797
|
+
candidates.push(path17.join(adkRoot, "dist", "templates"));
|
|
6798
|
+
candidates.push(path17.join(adkRoot, "templates"));
|
|
6630
6799
|
} catch {}
|
|
6631
|
-
const thisDir =
|
|
6632
|
-
candidates.push(
|
|
6633
|
-
candidates.push(
|
|
6634
|
-
candidates.push(
|
|
6800
|
+
const thisDir = path17.dirname(fileURLToPath(import.meta.url));
|
|
6801
|
+
candidates.push(path17.resolve(thisDir, "templates"));
|
|
6802
|
+
candidates.push(path17.resolve(thisDir, "../../templates"));
|
|
6803
|
+
candidates.push(path17.join(path17.dirname(process.execPath), "templates"));
|
|
6635
6804
|
for (const candidate of candidates) {
|
|
6636
|
-
if (fs12.existsSync(candidate) && fs12.existsSync(
|
|
6805
|
+
if (fs12.existsSync(candidate) && fs12.existsSync(path17.join(candidate, "template.config.json"))) {
|
|
6637
6806
|
return candidate;
|
|
6638
6807
|
}
|
|
6639
6808
|
}
|
|
@@ -6648,7 +6817,7 @@ Ensure the ADK package is properly installed or run the CLI build.`);
|
|
|
6648
6817
|
}
|
|
6649
6818
|
resolveTemplateDir() {
|
|
6650
6819
|
const templatesRoot = AgentProjectGenerator.getTemplatesRoot();
|
|
6651
|
-
const templateDir =
|
|
6820
|
+
const templateDir = path17.join(templatesRoot, this.template);
|
|
6652
6821
|
if (!fs12.existsSync(templateDir)) {
|
|
6653
6822
|
const available = AgentProjectGenerator.getAvailableTemplates();
|
|
6654
6823
|
const names = available.map((t) => ` - ${t.name}: ${t.description}`).join(`
|
|
@@ -6658,7 +6827,7 @@ Ensure the ADK package is properly installed or run the CLI build.`);
|
|
|
6658
6827
|
Available templates:
|
|
6659
6828
|
${names || " (none found)"}`);
|
|
6660
6829
|
}
|
|
6661
|
-
const configFile =
|
|
6830
|
+
const configFile = path17.join(templateDir, "agent.config.ts");
|
|
6662
6831
|
if (!fs12.existsSync(configFile)) {
|
|
6663
6832
|
throw new Error(`Template "${this.template}" is missing agent.config.ts`);
|
|
6664
6833
|
}
|
|
@@ -6667,7 +6836,7 @@ ${names || " (none found)"}`);
|
|
|
6667
6836
|
async copyTemplateFiles(templateDir) {
|
|
6668
6837
|
const substitutions = {
|
|
6669
6838
|
"{{projectName}}": this.projectName,
|
|
6670
|
-
"{{runtimeVersion}}": "1.18.0-beta.
|
|
6839
|
+
"{{runtimeVersion}}": "1.18.0-beta.7",
|
|
6671
6840
|
"{{packageManager}}": this.packageManager
|
|
6672
6841
|
};
|
|
6673
6842
|
await this.copyDirRecursive(templateDir, this.projectPath, substitutions);
|
|
@@ -6678,8 +6847,8 @@ ${names || " (none found)"}`);
|
|
|
6678
6847
|
}
|
|
6679
6848
|
const entries = fs12.readdirSync(src, { withFileTypes: true });
|
|
6680
6849
|
for (const entry of entries) {
|
|
6681
|
-
const srcPath =
|
|
6682
|
-
const destPath =
|
|
6850
|
+
const srcPath = path17.join(src, entry.name);
|
|
6851
|
+
const destPath = path17.join(dest, entry.name);
|
|
6683
6852
|
if (entry.isDirectory()) {
|
|
6684
6853
|
await this.copyDirRecursive(srcPath, destPath, substitutions);
|
|
6685
6854
|
} else if (isTextFile(entry.name)) {
|
|
@@ -6742,10 +6911,12 @@ ${names || " (none found)"}`);
|
|
|
6742
6911
|
mcp: "allow"
|
|
6743
6912
|
}
|
|
6744
6913
|
};
|
|
6745
|
-
this.
|
|
6914
|
+
const adkDir = path17.join(this.projectPath, ".adk");
|
|
6915
|
+
fs12.mkdirSync(adkDir, { recursive: true });
|
|
6916
|
+
this.writeJsonFile(path17.join(".adk", "opencode.json"), config);
|
|
6746
6917
|
}
|
|
6747
6918
|
writeFile(relativePath, content) {
|
|
6748
|
-
const filePath =
|
|
6919
|
+
const filePath = path17.join(this.projectPath, relativePath);
|
|
6749
6920
|
fs12.writeFileSync(filePath, content);
|
|
6750
6921
|
}
|
|
6751
6922
|
writeJsonFile(relativePath, data) {
|
|
@@ -6761,7 +6932,7 @@ init_dependencies_parser();
|
|
|
6761
6932
|
|
|
6762
6933
|
// src/plugins/enhanced-cache.ts
|
|
6763
6934
|
import fs13 from "fs/promises";
|
|
6764
|
-
import
|
|
6935
|
+
import path18 from "path";
|
|
6765
6936
|
import os8 from "os";
|
|
6766
6937
|
|
|
6767
6938
|
class EnhancedPluginCache {
|
|
@@ -6771,9 +6942,9 @@ class EnhancedPluginCache {
|
|
|
6771
6942
|
noCache;
|
|
6772
6943
|
constructor(noCache = false) {
|
|
6773
6944
|
this.noCache = noCache;
|
|
6774
|
-
this.cacheDir =
|
|
6775
|
-
this.resolutionsDir =
|
|
6776
|
-
this.definitionsDir =
|
|
6945
|
+
this.cacheDir = path18.join(os8.homedir(), ".adk", "cache", "plugins");
|
|
6946
|
+
this.resolutionsDir = path18.join(this.cacheDir, "resolutions");
|
|
6947
|
+
this.definitionsDir = path18.join(this.cacheDir, "definitions");
|
|
6777
6948
|
}
|
|
6778
6949
|
async ensureCacheDirs() {
|
|
6779
6950
|
await fs13.mkdir(this.resolutionsDir, { recursive: true });
|
|
@@ -6785,7 +6956,7 @@ class EnhancedPluginCache {
|
|
|
6785
6956
|
}
|
|
6786
6957
|
try {
|
|
6787
6958
|
const key = this.getResolutionKey(name, version);
|
|
6788
|
-
const cachePath =
|
|
6959
|
+
const cachePath = path18.join(this.resolutionsDir, `${key}.json`);
|
|
6789
6960
|
const data = await fs13.readFile(cachePath, "utf-8");
|
|
6790
6961
|
const resolution = JSON.parse(data);
|
|
6791
6962
|
const cachedAt = new Date(resolution.cachedAt);
|
|
@@ -6802,7 +6973,7 @@ class EnhancedPluginCache {
|
|
|
6802
6973
|
async setResolution(name, version, pluginId, updatedAt) {
|
|
6803
6974
|
await this.ensureCacheDirs();
|
|
6804
6975
|
const key = this.getResolutionKey(name, version);
|
|
6805
|
-
const cachePath =
|
|
6976
|
+
const cachePath = path18.join(this.resolutionsDir, `${key}.json`);
|
|
6806
6977
|
const resolution = {
|
|
6807
6978
|
pluginId,
|
|
6808
6979
|
updatedAt,
|
|
@@ -6816,7 +6987,7 @@ class EnhancedPluginCache {
|
|
|
6816
6987
|
}
|
|
6817
6988
|
try {
|
|
6818
6989
|
const key = this.getDefinitionKey(pluginId, updatedAt);
|
|
6819
|
-
const cachePath =
|
|
6990
|
+
const cachePath = path18.join(this.definitionsDir, `${key}.json`);
|
|
6820
6991
|
const data = await fs13.readFile(cachePath, "utf-8");
|
|
6821
6992
|
const cached = JSON.parse(data);
|
|
6822
6993
|
return cached.definition;
|
|
@@ -6827,7 +6998,7 @@ class EnhancedPluginCache {
|
|
|
6827
6998
|
async setDefinition(pluginId, updatedAt, definition) {
|
|
6828
6999
|
await this.ensureCacheDirs();
|
|
6829
7000
|
const key = this.getDefinitionKey(pluginId, updatedAt);
|
|
6830
|
-
const cachePath =
|
|
7001
|
+
const cachePath = path18.join(this.definitionsDir, `${key}.json`);
|
|
6831
7002
|
const cached = {
|
|
6832
7003
|
definition,
|
|
6833
7004
|
cachedAt: new Date().toISOString()
|
|
@@ -6837,9 +7008,9 @@ class EnhancedPluginCache {
|
|
|
6837
7008
|
async clear() {
|
|
6838
7009
|
try {
|
|
6839
7010
|
const resolutionFiles = await fs13.readdir(this.resolutionsDir);
|
|
6840
|
-
await Promise.all(resolutionFiles.map((file) => fs13.unlink(
|
|
7011
|
+
await Promise.all(resolutionFiles.map((file) => fs13.unlink(path18.join(this.resolutionsDir, file))));
|
|
6841
7012
|
const definitionFiles = await fs13.readdir(this.definitionsDir);
|
|
6842
|
-
await Promise.all(definitionFiles.map((file) => fs13.unlink(
|
|
7013
|
+
await Promise.all(definitionFiles.map((file) => fs13.unlink(path18.join(this.definitionsDir, file))));
|
|
6843
7014
|
} catch {}
|
|
6844
7015
|
}
|
|
6845
7016
|
async getStats() {
|
|
@@ -6848,7 +7019,7 @@ class EnhancedPluginCache {
|
|
|
6848
7019
|
const files = await fs13.readdir(dir);
|
|
6849
7020
|
let totalSize = 0;
|
|
6850
7021
|
for (const file of files) {
|
|
6851
|
-
const stats = await fs13.stat(
|
|
7022
|
+
const stats = await fs13.stat(path18.join(dir, file));
|
|
6852
7023
|
totalSize += stats.size;
|
|
6853
7024
|
}
|
|
6854
7025
|
return {
|
|
@@ -6984,11 +7155,11 @@ init_assets();
|
|
|
6984
7155
|
// src/generators/assets.ts
|
|
6985
7156
|
init_fs();
|
|
6986
7157
|
init_assets();
|
|
6987
|
-
import
|
|
7158
|
+
import path19 from "path";
|
|
6988
7159
|
async function generateAssetsTypes(projectPath) {
|
|
6989
7160
|
const assetsManager = new AssetsManager({ projectPath });
|
|
6990
7161
|
const typesCode = await assetsManager.generateTypes();
|
|
6991
|
-
const typesPath =
|
|
7162
|
+
const typesPath = path19.join(projectPath, defaultAdkFolder, "assets.d.ts");
|
|
6992
7163
|
await createFile(typesPath, typesCode);
|
|
6993
7164
|
}
|
|
6994
7165
|
async function generateAssetsRuntime(projectPath, botId, workspaceId) {
|
|
@@ -7028,7 +7199,7 @@ if (typeof globalThis !== 'undefined') {
|
|
|
7028
7199
|
initializeAssets(global);
|
|
7029
7200
|
}
|
|
7030
7201
|
`;
|
|
7031
|
-
const runtimePath =
|
|
7202
|
+
const runtimePath = path19.join(projectPath, defaultAdkFolder, "assets-runtime.ts");
|
|
7032
7203
|
await createFile(runtimePath, runtimeCode);
|
|
7033
7204
|
}
|
|
7034
7205
|
async function initAssets(projectPath, botId, workspaceId) {
|
|
@@ -7058,7 +7229,7 @@ declare global {
|
|
|
7058
7229
|
};
|
|
7059
7230
|
}
|
|
7060
7231
|
`;
|
|
7061
|
-
const typesPath =
|
|
7232
|
+
const typesPath = path19.join(projectPath, defaultAdkFolder, "assets.d.ts");
|
|
7062
7233
|
await createFile(typesPath, emptyTypesCode);
|
|
7063
7234
|
const emptyRuntimeCode = `
|
|
7064
7235
|
// No assets available
|
|
@@ -7079,14 +7250,14 @@ if (typeof globalThis !== 'undefined') {
|
|
|
7079
7250
|
initializeAssets(global);
|
|
7080
7251
|
}
|
|
7081
7252
|
`;
|
|
7082
|
-
const runtimePath =
|
|
7253
|
+
const runtimePath = path19.join(projectPath, defaultAdkFolder, "assets-runtime.ts");
|
|
7083
7254
|
await createFile(runtimePath, emptyRuntimeCode);
|
|
7084
7255
|
}
|
|
7085
7256
|
}
|
|
7086
7257
|
// src/generators/integration-types.ts
|
|
7087
7258
|
import { z as z3 } from "@botpress/sdk";
|
|
7088
7259
|
import crypto2 from "crypto";
|
|
7089
|
-
import
|
|
7260
|
+
import path20 from "path";
|
|
7090
7261
|
|
|
7091
7262
|
// src/utils/strings.ts
|
|
7092
7263
|
function pascalCase(str) {
|
|
@@ -7127,12 +7298,12 @@ var getIntegrationNames = (integration) => ({
|
|
|
7127
7298
|
configurations: `Integration_Configurations_${getPascalAlias(integration)}`
|
|
7128
7299
|
},
|
|
7129
7300
|
paths: {
|
|
7130
|
-
index:
|
|
7131
|
-
actions:
|
|
7132
|
-
channels:
|
|
7133
|
-
events:
|
|
7134
|
-
users:
|
|
7135
|
-
configurations:
|
|
7301
|
+
index: path20.join(snakeCase(getPascalAlias(integration)), `index.ts`),
|
|
7302
|
+
actions: path20.join(snakeCase(getPascalAlias(integration)), `actions.ts`),
|
|
7303
|
+
channels: path20.join(snakeCase(getPascalAlias(integration)), `channels.ts`),
|
|
7304
|
+
events: path20.join(snakeCase(getPascalAlias(integration)), `events.ts`),
|
|
7305
|
+
users: path20.join(snakeCase(getPascalAlias(integration)), `users.ts`),
|
|
7306
|
+
configurations: path20.join(snakeCase(getPascalAlias(integration)), `configurations.ts`)
|
|
7136
7307
|
}
|
|
7137
7308
|
});
|
|
7138
7309
|
async function generateIntegrationTypes(integration) {
|
|
@@ -7387,7 +7558,7 @@ Description: ${tag?.description}`);
|
|
|
7387
7558
|
// src/generators/client-wrapper.ts
|
|
7388
7559
|
init_utils();
|
|
7389
7560
|
init_fs();
|
|
7390
|
-
import
|
|
7561
|
+
import path21 from "path";
|
|
7391
7562
|
import crypto3 from "crypto";
|
|
7392
7563
|
import { readFile as readFile3 } from "fs/promises";
|
|
7393
7564
|
import { BuiltInWorkflows as BuiltInWorkflows2 } from "@botpress/runtime/internal";
|
|
@@ -7409,7 +7580,7 @@ async function generateClientWrapper(project) {
|
|
|
7409
7580
|
});
|
|
7410
7581
|
continue;
|
|
7411
7582
|
}
|
|
7412
|
-
const absolutePath =
|
|
7583
|
+
const absolutePath = path21.join(project.path, action.path);
|
|
7413
7584
|
const actionModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
7414
7585
|
const actionInstance = actionModule[action.export] || actionModule.default;
|
|
7415
7586
|
if (actionInstance && actionInstance.input && actionInstance.output) {
|
|
@@ -7436,7 +7607,7 @@ async function generateClientWrapper(project) {
|
|
|
7436
7607
|
if (isBuiltinWorkflow(workflow.definition.name)) {
|
|
7437
7608
|
continue;
|
|
7438
7609
|
}
|
|
7439
|
-
const workflowPath =
|
|
7610
|
+
const workflowPath = path21.join(project.path, workflow.path);
|
|
7440
7611
|
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
7441
7612
|
const workflowInstance = workflowModule[workflow.export] || workflowModule.default;
|
|
7442
7613
|
if (workflowInstance) {
|
|
@@ -7455,7 +7626,7 @@ async function generateClientWrapper(project) {
|
|
|
7455
7626
|
const tableTypes = [];
|
|
7456
7627
|
for (const table of project.tables) {
|
|
7457
7628
|
try {
|
|
7458
|
-
const tablePath =
|
|
7629
|
+
const tablePath = path21.join(project.path, table.path);
|
|
7459
7630
|
const tableModule = await import(`${tablePath}?t=${Date.now()}`);
|
|
7460
7631
|
const tableInstance = tableModule.default || tableModule[table.export];
|
|
7461
7632
|
if (tableInstance && tableInstance.columns) {
|
|
@@ -7768,7 +7939,7 @@ export function createAdkClient(client: Client): AdkClient {
|
|
|
7768
7939
|
}
|
|
7769
7940
|
}
|
|
7770
7941
|
`;
|
|
7771
|
-
const clientWrapperPath =
|
|
7942
|
+
const clientWrapperPath = path21.join(project.path, ".adk", "client.ts");
|
|
7772
7943
|
const formattedContent = await formatCode(content);
|
|
7773
7944
|
const contentHash = crypto3.createHash("sha256").update(formattedContent.replace(/\/\/ Generated at: .+\n/, "")).digest("hex");
|
|
7774
7945
|
try {
|
|
@@ -7784,13 +7955,14 @@ export function createAdkClient(client: Client): AdkClient {
|
|
|
7784
7955
|
import dedent from "dedent";
|
|
7785
7956
|
import { existsSync as existsSync9 } from "fs";
|
|
7786
7957
|
import fs19 from "fs/promises";
|
|
7787
|
-
import
|
|
7958
|
+
import path42 from "path";
|
|
7788
7959
|
init_config_utils();
|
|
7960
|
+
init_operations();
|
|
7789
7961
|
|
|
7790
7962
|
// src/generators/plugin-types.ts
|
|
7791
7963
|
import { z as z4 } from "@botpress/sdk";
|
|
7792
7964
|
import crypto4 from "crypto";
|
|
7793
|
-
import
|
|
7965
|
+
import path22 from "path";
|
|
7794
7966
|
init_utils();
|
|
7795
7967
|
var { transforms: transforms2 } = z4;
|
|
7796
7968
|
function stripRefs(schema) {
|
|
@@ -7829,8 +8001,8 @@ var getPluginNames = (plugin) => ({
|
|
|
7829
8001
|
actions: `Plugin_Actions_${getPascalAlias2(plugin)}`
|
|
7830
8002
|
},
|
|
7831
8003
|
paths: {
|
|
7832
|
-
index:
|
|
7833
|
-
actions:
|
|
8004
|
+
index: path22.join(snakeCase(getPascalAlias2(plugin)), `index.ts`),
|
|
8005
|
+
actions: path22.join(snakeCase(getPascalAlias2(plugin)), `actions.ts`)
|
|
7834
8006
|
}
|
|
7835
8007
|
});
|
|
7836
8008
|
async function generatePluginTypes(plugin) {
|
|
@@ -7898,7 +8070,7 @@ Description: ${action.description || "No description"}`)}
|
|
|
7898
8070
|
// src/generators/plugin-action-types.ts
|
|
7899
8071
|
init_utils();
|
|
7900
8072
|
init_fs();
|
|
7901
|
-
import
|
|
8073
|
+
import path23 from "path";
|
|
7902
8074
|
async function generatePluginActionTypes(project) {
|
|
7903
8075
|
const content = `
|
|
7904
8076
|
////////////////////////////////////////////////////////
|
|
@@ -7933,14 +8105,14 @@ type PluginsMap<T> = {
|
|
|
7933
8105
|
export type PluginActions = PluginsMap<Plugins>;
|
|
7934
8106
|
}
|
|
7935
8107
|
`;
|
|
7936
|
-
const pluginActionTypesPath =
|
|
8108
|
+
const pluginActionTypesPath = path23.join(project.path, ".adk", "plugin-action-types.d.ts");
|
|
7937
8109
|
await createFile(pluginActionTypesPath, await formatCode(content));
|
|
7938
8110
|
}
|
|
7939
8111
|
|
|
7940
8112
|
// src/generators/interface-types.ts
|
|
7941
8113
|
import { z as z5 } from "@botpress/sdk";
|
|
7942
8114
|
import crypto5 from "crypto";
|
|
7943
|
-
import
|
|
8115
|
+
import path24 from "path";
|
|
7944
8116
|
init_utils();
|
|
7945
8117
|
var { transforms: transforms3 } = z5;
|
|
7946
8118
|
var sameMajorVersion = (a, b) => {
|
|
@@ -7962,8 +8134,8 @@ var getInterfaceNames = (int) => ({
|
|
|
7962
8134
|
actions: `Interface_Actions_${pascalCase(int.name)}`
|
|
7963
8135
|
},
|
|
7964
8136
|
paths: {
|
|
7965
|
-
index:
|
|
7966
|
-
actions:
|
|
8137
|
+
index: path24.join(snakeCase(int.name), `index.ts`),
|
|
8138
|
+
actions: path24.join(snakeCase(int.name), `actions.ts`)
|
|
7967
8139
|
}
|
|
7968
8140
|
});
|
|
7969
8141
|
async function generateInterfaceTypes(int, integrations) {
|
|
@@ -8068,12 +8240,12 @@ Description: ${action.description || "No description"}`)}
|
|
|
8068
8240
|
// src/generators/table-types.ts
|
|
8069
8241
|
init_utils();
|
|
8070
8242
|
init_fs();
|
|
8071
|
-
import
|
|
8243
|
+
import path25 from "path";
|
|
8072
8244
|
async function generateTableTypes(project) {
|
|
8073
8245
|
const tables = [];
|
|
8074
8246
|
for (const tableRef of project.tables) {
|
|
8075
8247
|
try {
|
|
8076
|
-
const tablePath =
|
|
8248
|
+
const tablePath = path25.join(project.path, tableRef.path);
|
|
8077
8249
|
const tableModule = await import(`${tablePath}?t=${Date.now()}`);
|
|
8078
8250
|
const tableInstance = tableModule.default || tableModule[tableRef.export];
|
|
8079
8251
|
if (tableInstance && tableInstance.columns) {
|
|
@@ -8159,14 +8331,14 @@ ${outputColumns}
|
|
|
8159
8331
|
content += ` };
|
|
8160
8332
|
}
|
|
8161
8333
|
`;
|
|
8162
|
-
const tableTypesPath =
|
|
8334
|
+
const tableTypesPath = path25.join(project.path, ".adk", "table-types.d.ts");
|
|
8163
8335
|
await createFile(tableTypesPath, await formatCode(content));
|
|
8164
8336
|
}
|
|
8165
8337
|
|
|
8166
8338
|
// src/generators/trigger-types.ts
|
|
8167
8339
|
init_utils();
|
|
8168
8340
|
init_fs();
|
|
8169
|
-
import
|
|
8341
|
+
import path26 from "path";
|
|
8170
8342
|
async function generateTriggerTypes(project) {
|
|
8171
8343
|
const triggerEvents = {};
|
|
8172
8344
|
for (const trigger of project.triggers) {
|
|
@@ -8206,19 +8378,19 @@ ${triggersType}
|
|
|
8206
8378
|
};
|
|
8207
8379
|
}
|
|
8208
8380
|
`;
|
|
8209
|
-
const triggerTypesPath =
|
|
8381
|
+
const triggerTypesPath = path26.join(project.path, ".adk", "trigger-types.d.ts");
|
|
8210
8382
|
await createFile(triggerTypesPath, await formatCode(content));
|
|
8211
8383
|
}
|
|
8212
8384
|
|
|
8213
8385
|
// src/generators/state-types.ts
|
|
8214
8386
|
init_utils();
|
|
8215
8387
|
init_fs();
|
|
8216
|
-
import
|
|
8388
|
+
import path27 from "path";
|
|
8217
8389
|
async function generateStateTypes(project) {
|
|
8218
8390
|
let botStateType = "{}";
|
|
8219
8391
|
let userStateType = "{}";
|
|
8220
8392
|
try {
|
|
8221
|
-
const configPath =
|
|
8393
|
+
const configPath = path27.join(project.path, "agent.config.ts");
|
|
8222
8394
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
8223
8395
|
const config = configModule.default;
|
|
8224
8396
|
if (config?.bot?.state) {
|
|
@@ -8249,14 +8421,14 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
8249
8421
|
export type UserState = ${userStateType};
|
|
8250
8422
|
}
|
|
8251
8423
|
`;
|
|
8252
|
-
const stateTypesPath =
|
|
8424
|
+
const stateTypesPath = path27.join(project.path, ".adk", "state-types.d.ts");
|
|
8253
8425
|
await createFile(stateTypesPath, await formatCode(content));
|
|
8254
8426
|
}
|
|
8255
8427
|
|
|
8256
8428
|
// src/generators/tag-types.ts
|
|
8257
8429
|
init_utils();
|
|
8258
8430
|
init_fs();
|
|
8259
|
-
import
|
|
8431
|
+
import path28 from "path";
|
|
8260
8432
|
import { BUILT_IN_TAGS } from "@botpress/runtime/definition";
|
|
8261
8433
|
function generateTagTypeString(builtInTags, configTags) {
|
|
8262
8434
|
const builtInTagStrings = Object.entries(builtInTags).map(([key, tag]) => {
|
|
@@ -8295,7 +8467,7 @@ async function generateTagTypes(project) {
|
|
|
8295
8467
|
let messageTagsType = "Record<string, string | undefined>";
|
|
8296
8468
|
let workflowTagsType = "Record<string, string | undefined>";
|
|
8297
8469
|
try {
|
|
8298
|
-
const configPath =
|
|
8470
|
+
const configPath = path28.join(project.path, "agent.config.ts");
|
|
8299
8471
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
8300
8472
|
const config = configModule.default;
|
|
8301
8473
|
botTagsType = generateTagTypeString(BUILT_IN_TAGS.bot, config?.bot?.tags);
|
|
@@ -8341,18 +8513,18 @@ declare module "@botpress/runtime/_types/tags" {
|
|
|
8341
8513
|
export type WorkflowTags = ${workflowTagsType};
|
|
8342
8514
|
}
|
|
8343
8515
|
`;
|
|
8344
|
-
const tagTypesPath =
|
|
8516
|
+
const tagTypesPath = path28.join(project.path, ".adk", "tag-types.d.ts");
|
|
8345
8517
|
await createFile(tagTypesPath, await formatCode(content));
|
|
8346
8518
|
}
|
|
8347
8519
|
|
|
8348
8520
|
// src/generators/configuration-types.ts
|
|
8349
8521
|
init_utils();
|
|
8350
8522
|
init_fs();
|
|
8351
|
-
import
|
|
8523
|
+
import path29 from "path";
|
|
8352
8524
|
async function generateConfigurationTypes(project) {
|
|
8353
8525
|
let configurationType = "{}";
|
|
8354
8526
|
try {
|
|
8355
|
-
const configPath =
|
|
8527
|
+
const configPath = path29.join(project.path, "agent.config.ts");
|
|
8356
8528
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
8357
8529
|
const config = configModule.default;
|
|
8358
8530
|
if (config?.configuration?.schema) {
|
|
@@ -8376,18 +8548,18 @@ declare module "@botpress/runtime/_types/configuration" {
|
|
|
8376
8548
|
export type Configuration = ${configurationType};
|
|
8377
8549
|
}
|
|
8378
8550
|
`;
|
|
8379
|
-
const configTypesPath =
|
|
8551
|
+
const configTypesPath = path29.join(project.path, ".adk", "configuration-types.d.ts");
|
|
8380
8552
|
await createFile(configTypesPath, await formatCode(content));
|
|
8381
8553
|
}
|
|
8382
8554
|
|
|
8383
8555
|
// src/generators/secret-types.ts
|
|
8384
8556
|
init_utils();
|
|
8385
8557
|
init_fs();
|
|
8386
|
-
import
|
|
8558
|
+
import path30 from "path";
|
|
8387
8559
|
async function generateSecretTypes(project) {
|
|
8388
8560
|
let secretsType = "{}";
|
|
8389
8561
|
try {
|
|
8390
|
-
const configPath =
|
|
8562
|
+
const configPath = path30.join(project.path, "agent.config.ts");
|
|
8391
8563
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
8392
8564
|
const config = configModule.default;
|
|
8393
8565
|
if (config?.secrets) {
|
|
@@ -8419,14 +8591,14 @@ declare module "@botpress/runtime/_types/secrets" {
|
|
|
8419
8591
|
export type Secrets = ${secretsType};
|
|
8420
8592
|
}
|
|
8421
8593
|
`;
|
|
8422
|
-
const secretTypesPath =
|
|
8594
|
+
const secretTypesPath = path30.join(project.path, ".adk", "secret-types.d.ts");
|
|
8423
8595
|
await createFile(secretTypesPath, await formatCode(content));
|
|
8424
8596
|
}
|
|
8425
8597
|
|
|
8426
8598
|
// src/generators/workflow-types.ts
|
|
8427
8599
|
init_utils();
|
|
8428
8600
|
init_fs();
|
|
8429
|
-
import * as
|
|
8601
|
+
import * as path31 from "path";
|
|
8430
8602
|
import { BuiltInWorkflows as BuiltInWorkflows3 } from "@botpress/runtime/internal";
|
|
8431
8603
|
function isBuiltinWorkflow2(name) {
|
|
8432
8604
|
return !!Object.values(BuiltInWorkflows3).find((x) => x.name === name);
|
|
@@ -8438,7 +8610,7 @@ async function generateWorkflowTypes(project) {
|
|
|
8438
8610
|
if (isBuiltinWorkflow2(workflowRef.definition.name)) {
|
|
8439
8611
|
continue;
|
|
8440
8612
|
}
|
|
8441
|
-
const workflowPath =
|
|
8613
|
+
const workflowPath = path31.join(project.path, workflowRef.path);
|
|
8442
8614
|
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
8443
8615
|
const workflowInstance = workflowModule[workflowRef.export] || workflowModule.default;
|
|
8444
8616
|
if (!workflowInstance) {
|
|
@@ -8496,14 +8668,14 @@ declare module "@botpress/runtime/_types/workflows" {
|
|
|
8496
8668
|
${typeDefinitions || " // No workflows defined yet"}
|
|
8497
8669
|
};
|
|
8498
8670
|
}`;
|
|
8499
|
-
const workflowTypesPath =
|
|
8671
|
+
const workflowTypesPath = path31.join(project.path, ".adk", "workflow-types.d.ts");
|
|
8500
8672
|
await createFile(workflowTypesPath, await formatCode(content));
|
|
8501
8673
|
}
|
|
8502
8674
|
|
|
8503
8675
|
// src/generators/conversation-types.ts
|
|
8504
8676
|
init_utils();
|
|
8505
8677
|
init_fs();
|
|
8506
|
-
import
|
|
8678
|
+
import path32 from "path";
|
|
8507
8679
|
function hasConversationIdProperty(schema) {
|
|
8508
8680
|
if (!schema || typeof schema !== "object") {
|
|
8509
8681
|
return false;
|
|
@@ -8526,7 +8698,7 @@ async function generateConversationTypes(project) {
|
|
|
8526
8698
|
const conversationTypes = {};
|
|
8527
8699
|
for (const conversationRef of project.conversations) {
|
|
8528
8700
|
try {
|
|
8529
|
-
const conversationPath =
|
|
8701
|
+
const conversationPath = path32.join(project.path, conversationRef.path);
|
|
8530
8702
|
const conversationModule = await import(`${conversationPath}?t=${Date.now()}`);
|
|
8531
8703
|
const conversationInstance = conversationModule[conversationRef.export] || conversationModule.default;
|
|
8532
8704
|
if (!conversationInstance) {
|
|
@@ -8614,14 +8786,14 @@ ${routableEventsDefinitions || " // No routable events found"}
|
|
|
8614
8786
|
};
|
|
8615
8787
|
}
|
|
8616
8788
|
`;
|
|
8617
|
-
const conversationTypesPath =
|
|
8789
|
+
const conversationTypesPath = path32.join(project.path, ".adk", "conversation-types.d.ts");
|
|
8618
8790
|
await createFile(conversationTypesPath, await formatCode(content));
|
|
8619
8791
|
}
|
|
8620
8792
|
|
|
8621
8793
|
// src/generators/component-types.ts
|
|
8622
8794
|
init_utils();
|
|
8623
8795
|
init_fs();
|
|
8624
|
-
import
|
|
8796
|
+
import path33 from "path";
|
|
8625
8797
|
async function generateComponentTypes(project) {
|
|
8626
8798
|
const components = project.customComponents;
|
|
8627
8799
|
if (components.length === 0) {
|
|
@@ -8637,7 +8809,7 @@ declare module "@botpress/runtime/_types/components" {
|
|
|
8637
8809
|
export type CustomComponentMessage = never;
|
|
8638
8810
|
}
|
|
8639
8811
|
`;
|
|
8640
|
-
const typesPath2 =
|
|
8812
|
+
const typesPath2 = path33.join(project.path, ".adk", "component-types.d.ts");
|
|
8641
8813
|
await createFile(typesPath2, await formatCode(content2));
|
|
8642
8814
|
return;
|
|
8643
8815
|
}
|
|
@@ -8661,14 +8833,14 @@ declare module "@botpress/runtime/_types/components" {
|
|
|
8661
8833
|
| `)};
|
|
8662
8834
|
}
|
|
8663
8835
|
`;
|
|
8664
|
-
const typesPath =
|
|
8836
|
+
const typesPath = path33.join(project.path, ".adk", "component-types.d.ts");
|
|
8665
8837
|
await createFile(typesPath, await formatCode(content));
|
|
8666
8838
|
}
|
|
8667
8839
|
|
|
8668
8840
|
// src/generators/event-types.ts
|
|
8669
8841
|
init_utils();
|
|
8670
8842
|
init_fs();
|
|
8671
|
-
import
|
|
8843
|
+
import path34 from "path";
|
|
8672
8844
|
async function generateEventTypes(project) {
|
|
8673
8845
|
const defaultEvents = ["register: {}"];
|
|
8674
8846
|
const integrationEvents = [];
|
|
@@ -8720,7 +8892,7 @@ ${allEvents.map((e) => ` ${e}`).join(`
|
|
|
8720
8892
|
export type EventPayload<T extends EventName> = Events[T];
|
|
8721
8893
|
}
|
|
8722
8894
|
`;
|
|
8723
|
-
const eventTypesPath =
|
|
8895
|
+
const eventTypesPath = path34.join(project.path, ".adk", "event-types.d.ts");
|
|
8724
8896
|
await createFile(eventTypesPath, await formatCode(content));
|
|
8725
8897
|
}
|
|
8726
8898
|
|
|
@@ -8732,7 +8904,7 @@ init_fs();
|
|
|
8732
8904
|
// src/utils/link-sdk.ts
|
|
8733
8905
|
import { existsSync as existsSync5, realpathSync } from "fs";
|
|
8734
8906
|
import fs14 from "fs/promises";
|
|
8735
|
-
import
|
|
8907
|
+
import path35 from "path";
|
|
8736
8908
|
function findPackage(name, startDir) {
|
|
8737
8909
|
let current;
|
|
8738
8910
|
try {
|
|
@@ -8740,17 +8912,17 @@ function findPackage(name, startDir) {
|
|
|
8740
8912
|
} catch {
|
|
8741
8913
|
current = startDir;
|
|
8742
8914
|
}
|
|
8743
|
-
while (current !==
|
|
8744
|
-
const pkgPath =
|
|
8915
|
+
while (current !== path35.dirname(current)) {
|
|
8916
|
+
const pkgPath = path35.join(current, "node_modules", name);
|
|
8745
8917
|
if (existsSync5(pkgPath)) {
|
|
8746
8918
|
return pkgPath;
|
|
8747
8919
|
}
|
|
8748
|
-
current =
|
|
8920
|
+
current = path35.dirname(current);
|
|
8749
8921
|
}
|
|
8750
8922
|
return null;
|
|
8751
8923
|
}
|
|
8752
8924
|
async function linkSdk(agentDir, botDir) {
|
|
8753
|
-
const targetSdkPath =
|
|
8925
|
+
const targetSdkPath = path35.join(botDir, "node_modules", "@botpress", "sdk");
|
|
8754
8926
|
if (existsSync5(targetSdkPath)) {
|
|
8755
8927
|
return;
|
|
8756
8928
|
}
|
|
@@ -8764,7 +8936,7 @@ async function linkSdk(agentDir, botDir) {
|
|
|
8764
8936
|
console.warn(`Warning: Could not find @botpress/sdk from @botpress/runtime location (${runtimePath})`);
|
|
8765
8937
|
return;
|
|
8766
8938
|
}
|
|
8767
|
-
const targetBotpressDir =
|
|
8939
|
+
const targetBotpressDir = path35.join(botDir, "node_modules", "@botpress");
|
|
8768
8940
|
await fs14.mkdir(targetBotpressDir, { recursive: true });
|
|
8769
8941
|
const symlinkType = process.platform === "win32" ? "junction" : undefined;
|
|
8770
8942
|
await fs14.symlink(sdkPath, targetSdkPath, symlinkType);
|
|
@@ -8772,7 +8944,9 @@ async function linkSdk(agentDir, botDir) {
|
|
|
8772
8944
|
|
|
8773
8945
|
// src/bot-generator/dev-id-manager.ts
|
|
8774
8946
|
init_auth();
|
|
8775
|
-
|
|
8947
|
+
init_agent_project();
|
|
8948
|
+
init_validation_errors();
|
|
8949
|
+
import path36 from "path";
|
|
8776
8950
|
import fs15 from "fs/promises";
|
|
8777
8951
|
import createDebug3 from "debug";
|
|
8778
8952
|
import { Client as Client14 } from "@botpress/client";
|
|
@@ -8783,10 +8957,14 @@ class DevIdManager {
|
|
|
8783
8957
|
botProjectPath;
|
|
8784
8958
|
projectCachePath;
|
|
8785
8959
|
client;
|
|
8786
|
-
|
|
8960
|
+
loadAgentProject;
|
|
8961
|
+
validationErrors;
|
|
8962
|
+
constructor(projectPath, botProjectPath, options = {}) {
|
|
8787
8963
|
this.projectPath = projectPath;
|
|
8788
8964
|
this.botProjectPath = botProjectPath;
|
|
8789
|
-
this.projectCachePath =
|
|
8965
|
+
this.projectCachePath = path36.join(botProjectPath, ".botpress", "project.cache.json");
|
|
8966
|
+
this.loadAgentProject = options.loadAgentProject ?? ((p) => AgentProject.load(p));
|
|
8967
|
+
this.validationErrors = options.validationErrors ?? ValidationErrors;
|
|
8790
8968
|
}
|
|
8791
8969
|
async getClient() {
|
|
8792
8970
|
if (!this.client) {
|
|
@@ -8808,7 +8986,7 @@ class DevIdManager {
|
|
|
8808
8986
|
return this.client;
|
|
8809
8987
|
}
|
|
8810
8988
|
async getProject() {
|
|
8811
|
-
return await
|
|
8989
|
+
return await this.loadAgentProject(this.projectPath);
|
|
8812
8990
|
}
|
|
8813
8991
|
async readProjectCache() {
|
|
8814
8992
|
try {
|
|
@@ -8838,7 +9016,7 @@ class DevIdManager {
|
|
|
8838
9016
|
}
|
|
8839
9017
|
async saveProjectCache(cache2) {
|
|
8840
9018
|
try {
|
|
8841
|
-
await fs15.mkdir(
|
|
9019
|
+
await fs15.mkdir(path36.dirname(this.projectCachePath), { recursive: true });
|
|
8842
9020
|
await fs15.writeFile(this.projectCachePath, JSON.stringify(cache2, null, 2));
|
|
8843
9021
|
} catch (error) {
|
|
8844
9022
|
console.error("Error saving project.cache.json:", error);
|
|
@@ -8849,7 +9027,7 @@ class DevIdManager {
|
|
|
8849
9027
|
if (projectCache.devId) {
|
|
8850
9028
|
const project = await this.getProject();
|
|
8851
9029
|
if (!project.agentInfo) {
|
|
8852
|
-
throw
|
|
9030
|
+
throw this.validationErrors.agentNotLinked();
|
|
8853
9031
|
}
|
|
8854
9032
|
await project.updateAgentLocalInfo({
|
|
8855
9033
|
devId: projectCache.devId
|
|
@@ -8895,7 +9073,7 @@ function isProjectCache(value) {
|
|
|
8895
9073
|
// src/bot-generator/integration-sync.ts
|
|
8896
9074
|
init_agent_project();
|
|
8897
9075
|
init_auth();
|
|
8898
|
-
import
|
|
9076
|
+
import path37 from "path";
|
|
8899
9077
|
import fs16 from "fs/promises";
|
|
8900
9078
|
import { existsSync as existsSync6 } from "fs";
|
|
8901
9079
|
class IntegrationSync {
|
|
@@ -8905,7 +9083,7 @@ class IntegrationSync {
|
|
|
8905
9083
|
constructor(projectPath, botProjectPath) {
|
|
8906
9084
|
this.projectPath = projectPath;
|
|
8907
9085
|
this.botProjectPath = botProjectPath;
|
|
8908
|
-
this.bpModulesPath =
|
|
9086
|
+
this.bpModulesPath = path37.join(botProjectPath, "bp_modules");
|
|
8909
9087
|
}
|
|
8910
9088
|
async parseIntegrations() {
|
|
8911
9089
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -8936,12 +9114,12 @@ class IntegrationSync {
|
|
|
8936
9114
|
return integrations;
|
|
8937
9115
|
}
|
|
8938
9116
|
async isIntegrationSynced(integration) {
|
|
8939
|
-
const targetFolder =
|
|
9117
|
+
const targetFolder = path37.join(this.bpModulesPath, `integration_${integration.alias}`);
|
|
8940
9118
|
if (!existsSync6(targetFolder)) {
|
|
8941
9119
|
return false;
|
|
8942
9120
|
}
|
|
8943
9121
|
try {
|
|
8944
|
-
const indexPath =
|
|
9122
|
+
const indexPath = path37.join(targetFolder, "index.ts");
|
|
8945
9123
|
if (!existsSync6(indexPath)) {
|
|
8946
9124
|
return false;
|
|
8947
9125
|
}
|
|
@@ -8973,8 +9151,8 @@ class IntegrationSync {
|
|
|
8973
9151
|
await command.output();
|
|
8974
9152
|
}
|
|
8975
9153
|
async renameIntegrationFolder(integration) {
|
|
8976
|
-
const sourceFolder =
|
|
8977
|
-
const targetFolder =
|
|
9154
|
+
const sourceFolder = path37.join(this.bpModulesPath, integration.name.replace("/", "-"));
|
|
9155
|
+
const targetFolder = path37.join(this.bpModulesPath, `integration_${integration.alias}`);
|
|
8978
9156
|
if (!existsSync6(sourceFolder)) {
|
|
8979
9157
|
throw new Error(`Integration folder not found: ${sourceFolder}`);
|
|
8980
9158
|
}
|
|
@@ -8984,7 +9162,7 @@ class IntegrationSync {
|
|
|
8984
9162
|
await fs16.rename(sourceFolder, targetFolder);
|
|
8985
9163
|
}
|
|
8986
9164
|
async removeIntegrationFolder(alias) {
|
|
8987
|
-
const targetFolder =
|
|
9165
|
+
const targetFolder = path37.join(this.bpModulesPath, `integration_${alias}`);
|
|
8988
9166
|
if (existsSync6(targetFolder)) {
|
|
8989
9167
|
await fs16.rm(targetFolder, { recursive: true, force: true });
|
|
8990
9168
|
}
|
|
@@ -9020,7 +9198,7 @@ class IntegrationSync {
|
|
|
9020
9198
|
// src/bot-generator/interface-sync.ts
|
|
9021
9199
|
init_agent_project();
|
|
9022
9200
|
init_auth();
|
|
9023
|
-
import
|
|
9201
|
+
import path38 from "path";
|
|
9024
9202
|
import fs17 from "fs/promises";
|
|
9025
9203
|
import { existsSync as existsSync7 } from "fs";
|
|
9026
9204
|
init_constants();
|
|
@@ -9031,7 +9209,7 @@ class InterfaceSync {
|
|
|
9031
9209
|
constructor(projectPath, botProjectPath) {
|
|
9032
9210
|
this.projectPath = projectPath;
|
|
9033
9211
|
this.botProjectPath = botProjectPath;
|
|
9034
|
-
this.bpModulesPath =
|
|
9212
|
+
this.bpModulesPath = path38.join(botProjectPath, "bp_modules");
|
|
9035
9213
|
}
|
|
9036
9214
|
async parseInterfaces() {
|
|
9037
9215
|
const interfaces = [];
|
|
@@ -9049,12 +9227,12 @@ class InterfaceSync {
|
|
|
9049
9227
|
return interfaces;
|
|
9050
9228
|
}
|
|
9051
9229
|
async isInterfaceSynced(interfaceInfo) {
|
|
9052
|
-
const targetFolder =
|
|
9230
|
+
const targetFolder = path38.join(this.bpModulesPath, `interface_${pascalCase(interfaceInfo.alias)}`);
|
|
9053
9231
|
if (!existsSync7(targetFolder)) {
|
|
9054
9232
|
return false;
|
|
9055
9233
|
}
|
|
9056
9234
|
try {
|
|
9057
|
-
const indexPath =
|
|
9235
|
+
const indexPath = path38.join(targetFolder, "index.ts");
|
|
9058
9236
|
if (!existsSync7(indexPath)) {
|
|
9059
9237
|
return false;
|
|
9060
9238
|
}
|
|
@@ -9076,7 +9254,7 @@ class InterfaceSync {
|
|
|
9076
9254
|
if (!workspaceId) {
|
|
9077
9255
|
throw new Error('No workspace ID found. Please login with "adk login"');
|
|
9078
9256
|
}
|
|
9079
|
-
return new Promise((
|
|
9257
|
+
return new Promise((resolve5, reject) => {
|
|
9080
9258
|
const command = new BpAddCommand({
|
|
9081
9259
|
resource: `interface:${interfaceInfo.fullVersion}`,
|
|
9082
9260
|
botPath: this.botProjectPath,
|
|
@@ -9094,14 +9272,14 @@ class InterfaceSync {
|
|
|
9094
9272
|
reject(new Error(`Failed to install interface ${interfaceInfo.fullVersion}: ${error.stderr || error.message}`));
|
|
9095
9273
|
});
|
|
9096
9274
|
command.on("done", () => {
|
|
9097
|
-
|
|
9275
|
+
resolve5();
|
|
9098
9276
|
});
|
|
9099
9277
|
command.run().catch(reject);
|
|
9100
9278
|
});
|
|
9101
9279
|
}
|
|
9102
9280
|
async renameInterfaceFolder(interfaceInfo) {
|
|
9103
|
-
const sourceFolder =
|
|
9104
|
-
const targetFolder =
|
|
9281
|
+
const sourceFolder = path38.join(this.bpModulesPath, interfaceInfo.name);
|
|
9282
|
+
const targetFolder = path38.join(this.bpModulesPath, `interface_${pascalCase(interfaceInfo.alias)}`);
|
|
9105
9283
|
if (!existsSync7(sourceFolder)) {
|
|
9106
9284
|
throw new Error(`Interface folder not found: ${sourceFolder}`);
|
|
9107
9285
|
}
|
|
@@ -9111,7 +9289,7 @@ class InterfaceSync {
|
|
|
9111
9289
|
await fs17.rename(sourceFolder, targetFolder);
|
|
9112
9290
|
}
|
|
9113
9291
|
async removeInterfaceFolder(alias) {
|
|
9114
|
-
const targetFolder =
|
|
9292
|
+
const targetFolder = path38.join(this.bpModulesPath, `interface_${pascalCase(alias)}`);
|
|
9115
9293
|
if (existsSync7(targetFolder)) {
|
|
9116
9294
|
await fs17.rm(targetFolder, { recursive: true, force: true });
|
|
9117
9295
|
}
|
|
@@ -9147,7 +9325,7 @@ class InterfaceSync {
|
|
|
9147
9325
|
// src/bot-generator/plugin-sync.ts
|
|
9148
9326
|
init_agent_project();
|
|
9149
9327
|
init_auth();
|
|
9150
|
-
import
|
|
9328
|
+
import path39 from "path";
|
|
9151
9329
|
import fs18 from "fs/promises";
|
|
9152
9330
|
import { existsSync as existsSync8 } from "fs";
|
|
9153
9331
|
class PluginSync {
|
|
@@ -9157,7 +9335,7 @@ class PluginSync {
|
|
|
9157
9335
|
constructor(projectPath, botProjectPath) {
|
|
9158
9336
|
this.projectPath = projectPath;
|
|
9159
9337
|
this.botProjectPath = botProjectPath;
|
|
9160
|
-
this.bpModulesPath =
|
|
9338
|
+
this.bpModulesPath = path39.join(botProjectPath, "bp_modules");
|
|
9161
9339
|
}
|
|
9162
9340
|
async parsePlugins() {
|
|
9163
9341
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -9180,12 +9358,12 @@ class PluginSync {
|
|
|
9180
9358
|
return plugins;
|
|
9181
9359
|
}
|
|
9182
9360
|
async isPluginSynced(plugin) {
|
|
9183
|
-
const targetFolder =
|
|
9361
|
+
const targetFolder = path39.join(this.bpModulesPath, `plugin_${plugin.alias}`);
|
|
9184
9362
|
if (!existsSync8(targetFolder)) {
|
|
9185
9363
|
return false;
|
|
9186
9364
|
}
|
|
9187
9365
|
try {
|
|
9188
|
-
const indexPath =
|
|
9366
|
+
const indexPath = path39.join(targetFolder, "index.ts");
|
|
9189
9367
|
if (!existsSync8(indexPath)) {
|
|
9190
9368
|
return false;
|
|
9191
9369
|
}
|
|
@@ -9217,8 +9395,8 @@ class PluginSync {
|
|
|
9217
9395
|
await command.output();
|
|
9218
9396
|
}
|
|
9219
9397
|
async renamePluginFolder(plugin) {
|
|
9220
|
-
const sourceFolder =
|
|
9221
|
-
const targetFolder =
|
|
9398
|
+
const sourceFolder = path39.join(this.bpModulesPath, plugin.name.replace("/", "-"));
|
|
9399
|
+
const targetFolder = path39.join(this.bpModulesPath, `plugin_${plugin.alias}`);
|
|
9222
9400
|
if (!existsSync8(sourceFolder)) {
|
|
9223
9401
|
throw new Error(`Plugin folder not found: ${sourceFolder}`);
|
|
9224
9402
|
}
|
|
@@ -9228,7 +9406,7 @@ class PluginSync {
|
|
|
9228
9406
|
await fs18.rename(sourceFolder, targetFolder);
|
|
9229
9407
|
}
|
|
9230
9408
|
async removePluginFolder(alias) {
|
|
9231
|
-
const targetFolder =
|
|
9409
|
+
const targetFolder = path39.join(this.bpModulesPath, `plugin_${alias}`);
|
|
9232
9410
|
if (existsSync8(targetFolder)) {
|
|
9233
9411
|
await fs18.rm(targetFolder, { recursive: true, force: true });
|
|
9234
9412
|
}
|
|
@@ -9277,7 +9455,7 @@ function isBuiltinAction(name) {
|
|
|
9277
9455
|
return !!Object.values(BuiltInActions2).find((x) => x.name === name);
|
|
9278
9456
|
}
|
|
9279
9457
|
function getImportPath(from, to) {
|
|
9280
|
-
return
|
|
9458
|
+
return path42.relative(path42.dirname(from), to).replace(/\.ts$/, "").replace(/\\/g, "/");
|
|
9281
9459
|
}
|
|
9282
9460
|
|
|
9283
9461
|
class BotGenerator {
|
|
@@ -9286,8 +9464,8 @@ class BotGenerator {
|
|
|
9286
9464
|
adkCommand;
|
|
9287
9465
|
callbacks;
|
|
9288
9466
|
constructor(options) {
|
|
9289
|
-
this.projectPath =
|
|
9290
|
-
this.outputPath =
|
|
9467
|
+
this.projectPath = path42.resolve(options.projectPath);
|
|
9468
|
+
this.outputPath = path42.resolve(options.outputPath || path42.join(this.projectPath, ".adk"));
|
|
9291
9469
|
this.adkCommand = options.adkCommand;
|
|
9292
9470
|
this.callbacks = options.callbacks;
|
|
9293
9471
|
}
|
|
@@ -9299,8 +9477,8 @@ class BotGenerator {
|
|
|
9299
9477
|
const walk = async (dir, relativeBase) => {
|
|
9300
9478
|
const entries = await fs19.readdir(dir, { withFileTypes: true });
|
|
9301
9479
|
for (const entry of entries) {
|
|
9302
|
-
const abs =
|
|
9303
|
-
const rel =
|
|
9480
|
+
const abs = path42.join(dir, entry.name);
|
|
9481
|
+
const rel = path42.join(relativeBase, entry.name);
|
|
9304
9482
|
if (entry.isDirectory()) {
|
|
9305
9483
|
await walk(abs, rel);
|
|
9306
9484
|
} else {
|
|
@@ -9321,7 +9499,7 @@ class BotGenerator {
|
|
|
9321
9499
|
const entries = await fs19.readdir(dir, { withFileTypes: true });
|
|
9322
9500
|
for (const entry of entries) {
|
|
9323
9501
|
if (entry.isDirectory()) {
|
|
9324
|
-
const subdir =
|
|
9502
|
+
const subdir = path42.join(dir, entry.name);
|
|
9325
9503
|
await removeIfEmpty(subdir);
|
|
9326
9504
|
}
|
|
9327
9505
|
}
|
|
@@ -9371,18 +9549,18 @@ class BotGenerator {
|
|
|
9371
9549
|
workspaceId: project.agentInfo?.workspaceId
|
|
9372
9550
|
});
|
|
9373
9551
|
const integrations = await manager3.loadIntegrations(project.dependencies || {});
|
|
9374
|
-
const integrationsDir =
|
|
9552
|
+
const integrationsDir = path42.join(this.projectPath, ".adk", "integrations");
|
|
9375
9553
|
const existingIntegrationFiles = await this.listFilesRecursive(integrationsDir);
|
|
9376
9554
|
let aliases = new Set;
|
|
9377
9555
|
let files = new Set;
|
|
9378
9556
|
for (const integration of integrations.integrations) {
|
|
9379
9557
|
if (integration.definition) {
|
|
9380
9558
|
const types6 = await generateIntegrationTypes(integration);
|
|
9381
|
-
const importPath = `./${
|
|
9559
|
+
const importPath = `./${path42.join("integrations", types6.names.paths.index).replace(/\\/g, "/")}`;
|
|
9382
9560
|
aliases.add(`"${integration.alias}": import("${importPath}").${types6.names.typings.index}`);
|
|
9383
9561
|
for (const [filePath, content] of Object.entries(types6.files)) {
|
|
9384
|
-
const fullPath =
|
|
9385
|
-
const dir =
|
|
9562
|
+
const fullPath = path42.join(this.projectPath, ".adk", "integrations", filePath);
|
|
9563
|
+
const dir = path42.dirname(fullPath);
|
|
9386
9564
|
await fs19.mkdir(dir, { recursive: true });
|
|
9387
9565
|
await createFile(fullPath, content);
|
|
9388
9566
|
files.add(filePath);
|
|
@@ -9403,11 +9581,11 @@ class BotGenerator {
|
|
|
9403
9581
|
};
|
|
9404
9582
|
}
|
|
9405
9583
|
`;
|
|
9406
|
-
await createFile(
|
|
9584
|
+
await createFile(path42.join(this.projectPath, ".adk", "integrations-types.d.ts"), await formatCode(types5));
|
|
9407
9585
|
const staleIntegrationFiles = existingIntegrationFiles.filter((f) => !files.has(f));
|
|
9408
9586
|
if (staleIntegrationFiles.length > 0) {
|
|
9409
9587
|
for (const rel of staleIntegrationFiles) {
|
|
9410
|
-
const abs =
|
|
9588
|
+
const abs = path42.join(integrationsDir, rel);
|
|
9411
9589
|
try {
|
|
9412
9590
|
await fs19.rm(abs, { force: true });
|
|
9413
9591
|
} catch {}
|
|
@@ -9421,18 +9599,18 @@ class BotGenerator {
|
|
|
9421
9599
|
workspaceId: project.agentInfo?.workspaceId
|
|
9422
9600
|
});
|
|
9423
9601
|
const result = await manager3.loadPlugins(project.dependencies || {});
|
|
9424
|
-
const pluginsDir =
|
|
9602
|
+
const pluginsDir = path42.join(this.projectPath, ".adk", "plugins");
|
|
9425
9603
|
const existingPluginFiles = await this.listFilesRecursive(pluginsDir);
|
|
9426
9604
|
let aliases = new Set;
|
|
9427
9605
|
let files = new Set;
|
|
9428
9606
|
for (const plugin of result.plugins) {
|
|
9429
9607
|
if (plugin.definition) {
|
|
9430
9608
|
const types6 = await generatePluginTypes(plugin);
|
|
9431
|
-
const importPath = `./${
|
|
9609
|
+
const importPath = `./${path42.join("plugins", types6.names.paths.index).replace(/\\/g, "/")}`;
|
|
9432
9610
|
aliases.add(`"${plugin.alias}": import("${importPath}").${types6.names.typings.index}`);
|
|
9433
9611
|
for (const [filePath, content] of Object.entries(types6.files)) {
|
|
9434
|
-
const fullPath =
|
|
9435
|
-
const dir =
|
|
9612
|
+
const fullPath = path42.join(this.projectPath, ".adk", "plugins", filePath);
|
|
9613
|
+
const dir = path42.dirname(fullPath);
|
|
9436
9614
|
await fs19.mkdir(dir, { recursive: true });
|
|
9437
9615
|
await createFile(fullPath, content);
|
|
9438
9616
|
files.add(filePath);
|
|
@@ -9453,11 +9631,11 @@ class BotGenerator {
|
|
|
9453
9631
|
};
|
|
9454
9632
|
}
|
|
9455
9633
|
`;
|
|
9456
|
-
await createFile(
|
|
9634
|
+
await createFile(path42.join(this.projectPath, ".adk", "plugins-types.d.ts"), await formatCode(types5));
|
|
9457
9635
|
const stalePluginFiles = existingPluginFiles.filter((f) => !files.has(f));
|
|
9458
9636
|
if (stalePluginFiles.length > 0) {
|
|
9459
9637
|
for (const rel of stalePluginFiles) {
|
|
9460
|
-
const abs =
|
|
9638
|
+
const abs = path42.join(pluginsDir, rel);
|
|
9461
9639
|
try {
|
|
9462
9640
|
await fs19.rm(abs, { force: true });
|
|
9463
9641
|
} catch {}
|
|
@@ -9542,7 +9720,7 @@ class BotGenerator {
|
|
|
9542
9720
|
let botStateType = "{}";
|
|
9543
9721
|
let userStateType = "{}";
|
|
9544
9722
|
try {
|
|
9545
|
-
const configPath =
|
|
9723
|
+
const configPath = path42.join(project.path, "agent.config.ts");
|
|
9546
9724
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
9547
9725
|
const config = configModule.default;
|
|
9548
9726
|
if (config?.bot?.state) {
|
|
@@ -9578,7 +9756,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9578
9756
|
export type UserState = ${userStateType};
|
|
9579
9757
|
}
|
|
9580
9758
|
`;
|
|
9581
|
-
await createFile(
|
|
9759
|
+
await createFile(path42.join(this.projectPath, ".adk", "runtime.d.ts"), await formatCode(types5));
|
|
9582
9760
|
}
|
|
9583
9761
|
async generateInterfacesTypes() {
|
|
9584
9762
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -9586,7 +9764,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9586
9764
|
workspaceId: project.agentInfo?.workspaceId
|
|
9587
9765
|
});
|
|
9588
9766
|
const manager3 = new InterfaceManager;
|
|
9589
|
-
const interfacesDir =
|
|
9767
|
+
const interfacesDir = path42.join(this.projectPath, ".adk", "interfaces");
|
|
9590
9768
|
const existingInterfaceFiles = await this.listFilesRecursive(interfacesDir);
|
|
9591
9769
|
const interfaces = await manager3.loadInterfaces(project.dependencies || {}).then((result) => result.interfaces.filter((int) => int.definition).map((x) => x.definition));
|
|
9592
9770
|
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 +9773,11 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9595
9773
|
let files = new Set;
|
|
9596
9774
|
for (const int of interfaces) {
|
|
9597
9775
|
const types6 = await generateInterfaceTypes(int, integrationsWithAlias);
|
|
9598
|
-
imports.add(`import { ${types6.names.typings.index} } from "./${
|
|
9776
|
+
imports.add(`import { ${types6.names.typings.index} } from "./${path42.join("interfaces", types6.names.paths.index).replace(/\\/g, "/")}";`);
|
|
9599
9777
|
aliases.add(`"${types6.names.name}": ${types6.names.typings.index}`);
|
|
9600
9778
|
for (const [filePath, content] of Object.entries(types6.files)) {
|
|
9601
|
-
const fullPath =
|
|
9602
|
-
const dir =
|
|
9779
|
+
const fullPath = path42.join(this.projectPath, ".adk", "interfaces", filePath);
|
|
9780
|
+
const dir = path42.dirname(fullPath);
|
|
9603
9781
|
await fs19.mkdir(dir, { recursive: true });
|
|
9604
9782
|
await createFile(fullPath, content);
|
|
9605
9783
|
files.add(filePath);
|
|
@@ -9636,12 +9814,12 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9636
9814
|
`)}
|
|
9637
9815
|
};
|
|
9638
9816
|
`;
|
|
9639
|
-
await createFile(
|
|
9640
|
-
await createFile(
|
|
9817
|
+
await createFile(path42.join(this.projectPath, ".adk", "interfaces.d.ts"), await formatCode(types5));
|
|
9818
|
+
await createFile(path42.join(this.projectPath, ".adk", "interfaces.ts"), await formatCode(consts));
|
|
9641
9819
|
const staleInterfaceFiles = existingInterfaceFiles.filter((f) => !files.has(f));
|
|
9642
9820
|
if (staleInterfaceFiles.length > 0) {
|
|
9643
9821
|
for (const rel of staleInterfaceFiles) {
|
|
9644
|
-
const abs =
|
|
9822
|
+
const abs = path42.join(interfacesDir, rel);
|
|
9645
9823
|
try {
|
|
9646
9824
|
await fs19.rm(abs, { force: true });
|
|
9647
9825
|
} catch {}
|
|
@@ -9671,7 +9849,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9671
9849
|
`) : ""}
|
|
9672
9850
|
} as Record<string, IntegrationPackage>;
|
|
9673
9851
|
`;
|
|
9674
|
-
await createFile(
|
|
9852
|
+
await createFile(path42.join(this.outputPath, "src", "integrations.ts"), content);
|
|
9675
9853
|
}
|
|
9676
9854
|
async generatePluginsDefinition() {
|
|
9677
9855
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -9695,7 +9873,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9695
9873
|
`) : ""}
|
|
9696
9874
|
} as Record<string, PluginPackage>;
|
|
9697
9875
|
`;
|
|
9698
|
-
await createFile(
|
|
9876
|
+
await createFile(path42.join(this.outputPath, "src", "plugins.ts"), content);
|
|
9699
9877
|
}
|
|
9700
9878
|
async generateInterfacesDefinition() {
|
|
9701
9879
|
const interfaces = BUILTIN_INTERFACES;
|
|
@@ -9718,7 +9896,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9718
9896
|
`) : ""}
|
|
9719
9897
|
} as Record<string, InterfacePackage>;
|
|
9720
9898
|
`;
|
|
9721
|
-
await createFile(
|
|
9899
|
+
await createFile(path42.join(this.outputPath, "src", "interfaces.ts"), await formatCode(content));
|
|
9722
9900
|
}
|
|
9723
9901
|
reportServerConfigSync(label, serverConfigResult, items) {
|
|
9724
9902
|
if (!this.callbacks) {
|
|
@@ -9766,7 +9944,14 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9766
9944
|
const configType = configurationType && configurationType !== "default" ? `, configurationType: "${configurationType}"` : "";
|
|
9767
9945
|
const mergedConfig = mergeIntegrationConfig(serverConfigResult.configs[alias], config);
|
|
9768
9946
|
const configData = Object.keys(mergedConfig).length > 0 ? `, configuration: ${JSON.stringify(mergedConfig)}` : "";
|
|
9769
|
-
|
|
9947
|
+
let enabled;
|
|
9948
|
+
if (integration.enabled !== undefined) {
|
|
9949
|
+
enabled = integration.enabled;
|
|
9950
|
+
} else if (serverConfigResult.error) {
|
|
9951
|
+
enabled = false;
|
|
9952
|
+
} else {
|
|
9953
|
+
enabled = resolveIntegrationEnabled(integration, serverConfigResult.enabledStates[alias]);
|
|
9954
|
+
}
|
|
9770
9955
|
addIntegrations.push(`bot.addIntegration(${importName}, { alias: "${alias}", enabled: ${enabled}${configType}${configData} });`);
|
|
9771
9956
|
}
|
|
9772
9957
|
const depRefErrors = PluginParser.validateDependencyReferences(project.dependencies || {});
|
|
@@ -9829,7 +10014,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
9829
10014
|
if (isBuiltinWorkflow3(workflow.definition.name)) {
|
|
9830
10015
|
continue;
|
|
9831
10016
|
}
|
|
9832
|
-
const workflowPath =
|
|
10017
|
+
const workflowPath = path42.join(project.path, workflow.path);
|
|
9833
10018
|
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
9834
10019
|
const workflowInstance = workflowModule.default || workflowModule[workflow.export];
|
|
9835
10020
|
if (workflowInstance) {
|
|
@@ -10113,7 +10298,7 @@ secrets: ${secretsDef},
|
|
|
10113
10298
|
const fullContent = content + integrationsSection + pluginsSection + `
|
|
10114
10299
|
|
|
10115
10300
|
export default bot;`;
|
|
10116
|
-
await createFile(
|
|
10301
|
+
await createFile(path42.join(this.outputPath, "bot.definition.ts"), await formatCode(fullContent));
|
|
10117
10302
|
}
|
|
10118
10303
|
async generateBotIndex() {
|
|
10119
10304
|
const content = dedent`
|
|
@@ -10152,7 +10337,7 @@ export default bot;`;
|
|
|
10152
10337
|
|
|
10153
10338
|
export default bot
|
|
10154
10339
|
`;
|
|
10155
|
-
await createFile(
|
|
10340
|
+
await createFile(path42.join(this.outputPath, "src", "index.ts"), await formatCode(content));
|
|
10156
10341
|
}
|
|
10157
10342
|
async generatePackageJson(project) {
|
|
10158
10343
|
const packageJson = {
|
|
@@ -10166,7 +10351,7 @@ export default bot;`;
|
|
|
10166
10351
|
typescript: "^5.9.3"
|
|
10167
10352
|
}
|
|
10168
10353
|
};
|
|
10169
|
-
await createFile(
|
|
10354
|
+
await createFile(path42.join(this.outputPath, "package.json"), JSON.stringify(packageJson, null, 2));
|
|
10170
10355
|
}
|
|
10171
10356
|
async generateTsConfig() {
|
|
10172
10357
|
const tsConfig = {
|
|
@@ -10199,7 +10384,7 @@ export default bot;`;
|
|
|
10199
10384
|
},
|
|
10200
10385
|
include: [".botpress/**/*", "src/**/*", "bp_modules/**/*", "./*.ts", "./*.json", "../*.d.ts"]
|
|
10201
10386
|
};
|
|
10202
|
-
await createFile(
|
|
10387
|
+
await createFile(path42.join(this.outputPath, "tsconfig.json"), JSON.stringify(tsConfig, null, 2));
|
|
10203
10388
|
}
|
|
10204
10389
|
async generateGlobalTypes() {
|
|
10205
10390
|
const content = dedent`
|
|
@@ -10222,11 +10407,11 @@ export default bot;`;
|
|
|
10222
10407
|
|
|
10223
10408
|
export {};
|
|
10224
10409
|
`;
|
|
10225
|
-
await createFile(
|
|
10410
|
+
await createFile(path42.join(this.outputPath, "global.d.ts"), await formatCode(content));
|
|
10226
10411
|
}
|
|
10227
10412
|
async copyAssets() {
|
|
10228
|
-
const assetsPath =
|
|
10229
|
-
const targetPath =
|
|
10413
|
+
const assetsPath = path42.join(this.projectPath, "assets");
|
|
10414
|
+
const targetPath = path42.join(this.outputPath, "assets");
|
|
10230
10415
|
if (existsSync9(assetsPath)) {
|
|
10231
10416
|
await fs19.mkdir(targetPath, { recursive: true });
|
|
10232
10417
|
await this.copyDirectory(assetsPath, targetPath);
|
|
@@ -10235,8 +10420,8 @@ export default bot;`;
|
|
|
10235
10420
|
async copyDirectory(src, dest) {
|
|
10236
10421
|
const entries = await fs19.readdir(src, { withFileTypes: true });
|
|
10237
10422
|
for (const entry of entries) {
|
|
10238
|
-
const srcPath =
|
|
10239
|
-
const destPath =
|
|
10423
|
+
const srcPath = path42.join(src, entry.name);
|
|
10424
|
+
const destPath = path42.join(dest, entry.name);
|
|
10240
10425
|
if (entry.isDirectory()) {
|
|
10241
10426
|
await fs19.mkdir(destPath, { recursive: true });
|
|
10242
10427
|
await this.copyDirectory(srcPath, destPath);
|
|
@@ -10248,16 +10433,16 @@ export default bot;`;
|
|
|
10248
10433
|
async generateAdkRuntime() {
|
|
10249
10434
|
const project = new AgentProject(this.projectPath);
|
|
10250
10435
|
await project.reload();
|
|
10251
|
-
const srcDir =
|
|
10436
|
+
const srcDir = path42.join(this.outputPath, "src");
|
|
10252
10437
|
{
|
|
10253
|
-
const dest =
|
|
10438
|
+
const dest = path42.join(srcDir, "conversations.ts");
|
|
10254
10439
|
const imports = new Map;
|
|
10255
10440
|
const exports = new Set;
|
|
10256
10441
|
let index = 1;
|
|
10257
10442
|
for (const conversation of project.conversations) {
|
|
10258
10443
|
if (!imports.has(conversation.path)) {
|
|
10259
10444
|
const name = `conversations_${index++}`;
|
|
10260
|
-
const importPath = getImportPath(dest,
|
|
10445
|
+
const importPath = getImportPath(dest, path42.join(project.path, conversation.path));
|
|
10261
10446
|
imports.set(conversation.path, {
|
|
10262
10447
|
name,
|
|
10263
10448
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10283,14 +10468,14 @@ export default bot;`;
|
|
|
10283
10468
|
await createFile(dest, await formatCode(content2));
|
|
10284
10469
|
}
|
|
10285
10470
|
{
|
|
10286
|
-
const dest =
|
|
10471
|
+
const dest = path42.join(srcDir, "knowledge.ts");
|
|
10287
10472
|
const imports = new Map;
|
|
10288
10473
|
const exports = new Set;
|
|
10289
10474
|
let index = 1;
|
|
10290
10475
|
for (const knowledge of project.knowledge) {
|
|
10291
10476
|
if (!imports.has(knowledge.path)) {
|
|
10292
10477
|
const name = `knowledge_${index++}`;
|
|
10293
|
-
const importPath = getImportPath(dest,
|
|
10478
|
+
const importPath = getImportPath(dest, path42.join(project.path, knowledge.path));
|
|
10294
10479
|
imports.set(knowledge.path, {
|
|
10295
10480
|
name,
|
|
10296
10481
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10316,14 +10501,14 @@ export default bot;`;
|
|
|
10316
10501
|
await createFile(dest, await formatCode(content2));
|
|
10317
10502
|
}
|
|
10318
10503
|
{
|
|
10319
|
-
const dest =
|
|
10504
|
+
const dest = path42.join(srcDir, "custom-components.ts");
|
|
10320
10505
|
const imports = new Map;
|
|
10321
10506
|
const exports = new Set;
|
|
10322
10507
|
let index = 1;
|
|
10323
10508
|
for (const comp of project.customComponents) {
|
|
10324
10509
|
if (!imports.has(comp.path)) {
|
|
10325
10510
|
const name = `components_${index++}`;
|
|
10326
|
-
const importPath = getImportPath(dest,
|
|
10511
|
+
const importPath = getImportPath(dest, path42.join(project.path, comp.path));
|
|
10327
10512
|
imports.set(comp.path, {
|
|
10328
10513
|
name,
|
|
10329
10514
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10349,7 +10534,7 @@ export default bot;`;
|
|
|
10349
10534
|
await createFile(dest, await formatCode(content2));
|
|
10350
10535
|
}
|
|
10351
10536
|
{
|
|
10352
|
-
const dest =
|
|
10537
|
+
const dest = path42.join(srcDir, "triggers.ts");
|
|
10353
10538
|
const {
|
|
10354
10539
|
z: { transforms: transforms5 }
|
|
10355
10540
|
} = await import("@botpress/sdk");
|
|
@@ -10360,7 +10545,7 @@ export default bot;`;
|
|
|
10360
10545
|
for (const trigger of project.triggers) {
|
|
10361
10546
|
if (!imports.has(trigger.path)) {
|
|
10362
10547
|
const name = `triggers_${index++}`;
|
|
10363
|
-
const importPath = getImportPath(dest,
|
|
10548
|
+
const importPath = getImportPath(dest, path42.join(project.path, trigger.path));
|
|
10364
10549
|
imports.set(trigger.path, {
|
|
10365
10550
|
name,
|
|
10366
10551
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10370,7 +10555,7 @@ export default bot;`;
|
|
|
10370
10555
|
}
|
|
10371
10556
|
for (const trigger of project.triggers) {
|
|
10372
10557
|
try {
|
|
10373
|
-
const absolutePath =
|
|
10558
|
+
const absolutePath = path42.join(project.path, trigger.path);
|
|
10374
10559
|
const triggerModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
10375
10560
|
const triggerInstance = triggerModule[trigger.export] || triggerModule.default;
|
|
10376
10561
|
if (triggerInstance && triggerInstance.payload) {
|
|
@@ -10413,7 +10598,7 @@ export default bot;`;
|
|
|
10413
10598
|
await createFile(dest, await formatCode(content2));
|
|
10414
10599
|
}
|
|
10415
10600
|
{
|
|
10416
|
-
const dest =
|
|
10601
|
+
const dest = path42.join(srcDir, "workflows.ts");
|
|
10417
10602
|
const imports = new Map;
|
|
10418
10603
|
const exports = new Set;
|
|
10419
10604
|
let index = 1;
|
|
@@ -10423,7 +10608,7 @@ export default bot;`;
|
|
|
10423
10608
|
}
|
|
10424
10609
|
if (!imports.has(workflow.path)) {
|
|
10425
10610
|
const name = `workflows_${index++}`;
|
|
10426
|
-
const importPath = getImportPath(dest,
|
|
10611
|
+
const importPath = getImportPath(dest, path42.join(project.path, workflow.path));
|
|
10427
10612
|
const statement = `import * as ${name} from "${importPath}";`;
|
|
10428
10613
|
imports.set(workflow.path, {
|
|
10429
10614
|
name,
|
|
@@ -10457,7 +10642,7 @@ export default bot;`;
|
|
|
10457
10642
|
await createFile(dest, await formatCode(content2));
|
|
10458
10643
|
}
|
|
10459
10644
|
{
|
|
10460
|
-
const dest =
|
|
10645
|
+
const dest = path42.join(srcDir, "actions.ts");
|
|
10461
10646
|
const imports = new Map;
|
|
10462
10647
|
const exports = new Set;
|
|
10463
10648
|
let index = 1;
|
|
@@ -10467,7 +10652,7 @@ export default bot;`;
|
|
|
10467
10652
|
}
|
|
10468
10653
|
if (!imports.has(action.path)) {
|
|
10469
10654
|
const name = `actions_${index++}`;
|
|
10470
|
-
const importPath = getImportPath(dest,
|
|
10655
|
+
const importPath = getImportPath(dest, path42.join(project.path, action.path));
|
|
10471
10656
|
imports.set(action.path, {
|
|
10472
10657
|
name,
|
|
10473
10658
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10493,14 +10678,14 @@ export default bot;`;
|
|
|
10493
10678
|
await createFile(dest, await formatCode(content2));
|
|
10494
10679
|
}
|
|
10495
10680
|
{
|
|
10496
|
-
const dest =
|
|
10681
|
+
const dest = path42.join(srcDir, "tables.ts");
|
|
10497
10682
|
const imports = new Map;
|
|
10498
10683
|
const exports = new Set;
|
|
10499
10684
|
let index = 1;
|
|
10500
10685
|
for (const table of project.tables) {
|
|
10501
10686
|
if (!imports.has(table.path)) {
|
|
10502
10687
|
const name = `tables_${index++}`;
|
|
10503
|
-
const importPath = getImportPath(dest,
|
|
10688
|
+
const importPath = getImportPath(dest, path42.join(project.path, table.path));
|
|
10504
10689
|
imports.set(table.path, {
|
|
10505
10690
|
name,
|
|
10506
10691
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -10526,8 +10711,8 @@ export default bot;`;
|
|
|
10526
10711
|
await createFile(dest, await formatCode(content2));
|
|
10527
10712
|
}
|
|
10528
10713
|
{
|
|
10529
|
-
const dest =
|
|
10530
|
-
const importPath = getImportPath(dest,
|
|
10714
|
+
const dest = path42.join(srcDir, "config.ts");
|
|
10715
|
+
const importPath = getImportPath(dest, path42.join(project.path, "agent.config.ts"));
|
|
10531
10716
|
const content2 = `
|
|
10532
10717
|
////////////////////////////////////////////////////////
|
|
10533
10718
|
// DO NOT EDIT THIS FILE DIRECTLY
|
|
@@ -10605,10 +10790,10 @@ export default bot;`;
|
|
|
10605
10790
|
handlers.plugins.setup(bot);
|
|
10606
10791
|
}
|
|
10607
10792
|
`;
|
|
10608
|
-
await createFile(
|
|
10793
|
+
await createFile(path42.join(this.outputPath, "src", "adk-runtime.ts"), await formatCode(content));
|
|
10609
10794
|
}
|
|
10610
10795
|
async generateComponentUrlsBlock() {
|
|
10611
|
-
const manifestPath =
|
|
10796
|
+
const manifestPath = path42.join(this.projectPath, ".adk", "components.manifest.json");
|
|
10612
10797
|
try {
|
|
10613
10798
|
if (!existsSync9(manifestPath)) {
|
|
10614
10799
|
return "const componentUrls: Record<string, string> = {};";
|
|
@@ -10624,10 +10809,10 @@ export default bot;`;
|
|
|
10624
10809
|
}
|
|
10625
10810
|
}
|
|
10626
10811
|
async copyAssetsRuntime() {
|
|
10627
|
-
const assetsRuntimePath =
|
|
10812
|
+
const assetsRuntimePath = path42.join(this.projectPath, ".adk", "assets-runtime.ts");
|
|
10628
10813
|
if (existsSync9(assetsRuntimePath)) {
|
|
10629
10814
|
const content = await fs19.readFile(assetsRuntimePath, "utf-8");
|
|
10630
|
-
await createFile(
|
|
10815
|
+
await createFile(path42.join(this.outputPath, "src", "assets-runtime.ts"), await formatCode(content));
|
|
10631
10816
|
}
|
|
10632
10817
|
}
|
|
10633
10818
|
}
|
|
@@ -10636,11 +10821,11 @@ async function generateBotProject(options) {
|
|
|
10636
10821
|
await generator.generate();
|
|
10637
10822
|
await generator.generateAdkRuntime();
|
|
10638
10823
|
await generator.copyAssetsRuntime();
|
|
10639
|
-
const botPath = options.outputPath ||
|
|
10824
|
+
const botPath = options.outputPath || path42.join(options.projectPath, ".adk", "bot");
|
|
10640
10825
|
await linkSdk(options.projectPath, botPath);
|
|
10641
|
-
const devIdManager = new DevIdManager(options.projectPath, options.outputPath ||
|
|
10826
|
+
const devIdManager = new DevIdManager(options.projectPath, options.outputPath || path42.join(options.projectPath, ".adk", "bot"));
|
|
10642
10827
|
await devIdManager.restoreDevId();
|
|
10643
|
-
const integrationSync = new IntegrationSync(options.projectPath, options.outputPath ||
|
|
10828
|
+
const integrationSync = new IntegrationSync(options.projectPath, options.outputPath || path42.join(options.projectPath, ".adk", "bot"));
|
|
10644
10829
|
const integrationSyncResult = await integrationSync.syncIntegrations();
|
|
10645
10830
|
if (integrationSyncResult.errors.length > 0) {
|
|
10646
10831
|
console.warn(`⚠️ Some integrations failed to sync:`);
|
|
@@ -10648,7 +10833,7 @@ async function generateBotProject(options) {
|
|
|
10648
10833
|
console.warn(` - ${alias}: ${error}`);
|
|
10649
10834
|
});
|
|
10650
10835
|
}
|
|
10651
|
-
const interfaceSync = new InterfaceSync(options.projectPath, options.outputPath ||
|
|
10836
|
+
const interfaceSync = new InterfaceSync(options.projectPath, options.outputPath || path42.join(options.projectPath, ".adk", "bot"));
|
|
10652
10837
|
const interfaceSyncResult = await interfaceSync.syncInterfaces();
|
|
10653
10838
|
if (interfaceSyncResult.errors.length > 0) {
|
|
10654
10839
|
console.warn(`⚠️ Some interfaces failed to sync:`);
|
|
@@ -10656,7 +10841,7 @@ async function generateBotProject(options) {
|
|
|
10656
10841
|
console.warn(` - ${alias}: ${error}`);
|
|
10657
10842
|
});
|
|
10658
10843
|
}
|
|
10659
|
-
const pluginSync = new PluginSync(options.projectPath, options.outputPath ||
|
|
10844
|
+
const pluginSync = new PluginSync(options.projectPath, options.outputPath || path42.join(options.projectPath, ".adk", "bot"));
|
|
10660
10845
|
const pluginSyncResult = await pluginSync.syncPlugins();
|
|
10661
10846
|
if (pluginSyncResult.errors.length > 0) {
|
|
10662
10847
|
console.warn(`⚠️ Some plugins failed to sync:`);
|
|
@@ -11172,7 +11357,7 @@ class TableManager {
|
|
|
11172
11357
|
// src/knowledge/manager.ts
|
|
11173
11358
|
init_auth();
|
|
11174
11359
|
import crypto6 from "crypto";
|
|
11175
|
-
import
|
|
11360
|
+
import path43 from "path";
|
|
11176
11361
|
import fs20 from "fs/promises";
|
|
11177
11362
|
import { glob } from "glob";
|
|
11178
11363
|
import { Client as Client16 } from "@botpress/client";
|
|
@@ -11624,14 +11809,14 @@ class KnowledgeManager {
|
|
|
11624
11809
|
}
|
|
11625
11810
|
async scanLocalFileHashes(directoryPath, filterFn) {
|
|
11626
11811
|
const projectDir = this.project.path;
|
|
11627
|
-
const directory =
|
|
11812
|
+
const directory = path43.resolve(projectDir, directoryPath);
|
|
11628
11813
|
if (this.fileHashCache.has(directory)) {
|
|
11629
11814
|
return this.fileHashCache.get(directory);
|
|
11630
11815
|
}
|
|
11631
11816
|
const files = glob.sync(directory + "/**/*.*", { absolute: true, nodir: true }).filter((file) => !filterFn || filterFn(file));
|
|
11632
11817
|
const hashes = {};
|
|
11633
11818
|
for (const file of files) {
|
|
11634
|
-
const relPath =
|
|
11819
|
+
const relPath = path43.relative(directory, file);
|
|
11635
11820
|
const content = await fs20.readFile(file);
|
|
11636
11821
|
hashes[relPath] = crypto6.createHash("sha256").update(content).digest("hex");
|
|
11637
11822
|
}
|
|
@@ -11767,7 +11952,7 @@ class KnowledgeManager {
|
|
|
11767
11952
|
}
|
|
11768
11953
|
async syncDirectorySource(client, kbName, kbId, dsId, directoryPath, filterFn, force) {
|
|
11769
11954
|
const projectDir = this.project.path;
|
|
11770
|
-
const directory =
|
|
11955
|
+
const directory = path43.resolve(projectDir, directoryPath);
|
|
11771
11956
|
if (!directory.startsWith(projectDir)) {
|
|
11772
11957
|
throw new Error("Directory path must be within the agent's directory");
|
|
11773
11958
|
}
|
|
@@ -11789,8 +11974,8 @@ class KnowledgeManager {
|
|
|
11789
11974
|
return true;
|
|
11790
11975
|
}).map((f) => ({
|
|
11791
11976
|
abs: f,
|
|
11792
|
-
rel:
|
|
11793
|
-
name:
|
|
11977
|
+
rel: path43.relative(directory, f),
|
|
11978
|
+
name: path43.basename(f)
|
|
11794
11979
|
}));
|
|
11795
11980
|
console.log(` Found ${allFiles.length} files in ${directoryPath}`);
|
|
11796
11981
|
const cachedHashes = await this.scanLocalFileHashes(directoryPath, filterFn);
|
|
@@ -11872,7 +12057,7 @@ class KnowledgeManager {
|
|
|
11872
12057
|
return null;
|
|
11873
12058
|
}
|
|
11874
12059
|
} catch {}
|
|
11875
|
-
const title =
|
|
12060
|
+
const title = path43.basename(local.name, path43.extname(local.name));
|
|
11876
12061
|
const metadata = {
|
|
11877
12062
|
hash,
|
|
11878
12063
|
dsId,
|
|
@@ -11897,7 +12082,7 @@ class KnowledgeManager {
|
|
|
11897
12082
|
}
|
|
11898
12083
|
}
|
|
11899
12084
|
// src/knowledge/sync-formatter.ts
|
|
11900
|
-
import { readFileSync as
|
|
12085
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
11901
12086
|
import { join as join10 } from "path";
|
|
11902
12087
|
var getAdkVersion = () => {
|
|
11903
12088
|
try {
|
|
@@ -11906,7 +12091,7 @@ var getAdkVersion = () => {
|
|
|
11906
12091
|
} catch {
|
|
11907
12092
|
try {
|
|
11908
12093
|
const adkPackagePath = join10(process.cwd(), "node_modules/@botpress/adk/package.json");
|
|
11909
|
-
const pkg = JSON.parse(
|
|
12094
|
+
const pkg = JSON.parse(readFileSync5(adkPackagePath, "utf-8"));
|
|
11910
12095
|
return pkg.version;
|
|
11911
12096
|
} catch {
|
|
11912
12097
|
return "unknown";
|
|
@@ -12180,7 +12365,7 @@ init_auth();
|
|
|
12180
12365
|
init_checker();
|
|
12181
12366
|
init_sync_manager();
|
|
12182
12367
|
import { Client as Client17 } from "@botpress/client";
|
|
12183
|
-
import
|
|
12368
|
+
import path44 from "path";
|
|
12184
12369
|
|
|
12185
12370
|
// src/preflight/types.ts
|
|
12186
12371
|
function hasIntegrationChanges(integrations) {
|
|
@@ -12237,7 +12422,7 @@ class AgentConfigSyncManager {
|
|
|
12237
12422
|
}
|
|
12238
12423
|
|
|
12239
12424
|
// src/preflight/formatter.ts
|
|
12240
|
-
import { readFileSync as
|
|
12425
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
12241
12426
|
import { join as join12 } from "path";
|
|
12242
12427
|
var getAdkVersion2 = () => {
|
|
12243
12428
|
try {
|
|
@@ -12246,7 +12431,7 @@ var getAdkVersion2 = () => {
|
|
|
12246
12431
|
} catch {
|
|
12247
12432
|
try {
|
|
12248
12433
|
const adkPackagePath = join12(process.cwd(), "node_modules/@botpress/adk/package.json");
|
|
12249
|
-
const pkg = JSON.parse(
|
|
12434
|
+
const pkg = JSON.parse(readFileSync6(adkPackagePath, "utf-8"));
|
|
12250
12435
|
return pkg.version;
|
|
12251
12436
|
} catch {
|
|
12252
12437
|
return "unknown";
|
|
@@ -12598,7 +12783,7 @@ class PreflightChecker {
|
|
|
12598
12783
|
options?.onProgress?.("Regenerating bot project...");
|
|
12599
12784
|
await generateBotProject({
|
|
12600
12785
|
projectPath: this.projectPath,
|
|
12601
|
-
outputPath:
|
|
12786
|
+
outputPath: path44.join(this.projectPath, ".adk", "bot"),
|
|
12602
12787
|
callbacks: options
|
|
12603
12788
|
});
|
|
12604
12789
|
options?.onSuccess?.("Bot project regenerated");
|
|
@@ -12608,19 +12793,19 @@ class PreflightChecker {
|
|
|
12608
12793
|
import dedent2 from "dedent";
|
|
12609
12794
|
import { existsSync as existsSync11 } from "fs";
|
|
12610
12795
|
import fs21 from "fs/promises";
|
|
12611
|
-
import
|
|
12796
|
+
import path45 from "path";
|
|
12612
12797
|
import { spawn as spawn2 } from "child_process";
|
|
12613
12798
|
init_utils();
|
|
12614
12799
|
init_credentials();
|
|
12615
12800
|
async function findAgentRoot(startPath) {
|
|
12616
|
-
let currentPath =
|
|
12617
|
-
const root =
|
|
12801
|
+
let currentPath = path45.resolve(startPath);
|
|
12802
|
+
const root = path45.parse(currentPath).root;
|
|
12618
12803
|
while (currentPath !== root) {
|
|
12619
12804
|
try {
|
|
12620
|
-
await fs21.access(
|
|
12805
|
+
await fs21.access(path45.join(currentPath, "agent.config.ts"));
|
|
12621
12806
|
return currentPath;
|
|
12622
12807
|
} catch {
|
|
12623
|
-
currentPath =
|
|
12808
|
+
currentPath = path45.dirname(currentPath);
|
|
12624
12809
|
}
|
|
12625
12810
|
}
|
|
12626
12811
|
return null;
|
|
@@ -12632,7 +12817,7 @@ class ScriptRunner {
|
|
|
12632
12817
|
prod;
|
|
12633
12818
|
credentials;
|
|
12634
12819
|
constructor(options) {
|
|
12635
|
-
this.projectPath =
|
|
12820
|
+
this.projectPath = path45.resolve(options.projectPath);
|
|
12636
12821
|
this.forceRegenerate = options.forceRegenerate ?? false;
|
|
12637
12822
|
this.prod = options.prod ?? false;
|
|
12638
12823
|
this.credentials = options.credentials;
|
|
@@ -12641,9 +12826,9 @@ class ScriptRunner {
|
|
|
12641
12826
|
const project = await AgentProject.load(this.projectPath, {
|
|
12642
12827
|
adkCommand: "adk-build"
|
|
12643
12828
|
});
|
|
12644
|
-
const botPath =
|
|
12645
|
-
const runnerPath =
|
|
12646
|
-
const botpressTypesPath =
|
|
12829
|
+
const botPath = path45.join(this.projectPath, ".adk", "bot");
|
|
12830
|
+
const runnerPath = path45.join(botPath, "src", "script-runner.ts");
|
|
12831
|
+
const botpressTypesPath = path45.join(botPath, ".botpress", "implementation", "index.ts");
|
|
12647
12832
|
const needsRegenerate = this.forceRegenerate || !existsSync11(runnerPath) || !existsSync11(botpressTypesPath);
|
|
12648
12833
|
if (needsRegenerate) {
|
|
12649
12834
|
try {
|
|
@@ -12661,8 +12846,8 @@ class ScriptRunner {
|
|
|
12661
12846
|
}
|
|
12662
12847
|
async runBpBuild(botPath) {
|
|
12663
12848
|
const buildCommand = new BpBuildCommand({ botPath });
|
|
12664
|
-
return new Promise((
|
|
12665
|
-
buildCommand.on("done", () =>
|
|
12849
|
+
return new Promise((resolve5, reject) => {
|
|
12850
|
+
buildCommand.on("done", () => resolve5());
|
|
12666
12851
|
buildCommand.on("error", (err) => reject(new Error(err.message)));
|
|
12667
12852
|
buildCommand.run();
|
|
12668
12853
|
});
|
|
@@ -12760,7 +12945,7 @@ class ScriptRunner {
|
|
|
12760
12945
|
|
|
12761
12946
|
runScript()
|
|
12762
12947
|
`;
|
|
12763
|
-
await fs21.writeFile(
|
|
12948
|
+
await fs21.writeFile(path45.join(botPath, "src", "script-runner.ts"), await formatCode(content), "utf-8");
|
|
12764
12949
|
}
|
|
12765
12950
|
async setupTestRuntime(options = {}) {
|
|
12766
12951
|
const { botPath, project } = await this.prepare();
|
|
@@ -12791,7 +12976,7 @@ class ScriptRunner {
|
|
|
12791
12976
|
for (const [key, value] of Object.entries(envVars)) {
|
|
12792
12977
|
process.env[key] = value;
|
|
12793
12978
|
}
|
|
12794
|
-
const runtimePath =
|
|
12979
|
+
const runtimePath = path45.join(botPath, "src", "index.ts");
|
|
12795
12980
|
return {
|
|
12796
12981
|
botPath,
|
|
12797
12982
|
runtimePath,
|
|
@@ -12839,7 +13024,7 @@ class ScriptRunner {
|
|
|
12839
13024
|
}
|
|
12840
13025
|
async run(scriptPath, options = {}) {
|
|
12841
13026
|
const { botPath, runnerPath, project } = await this.prepare();
|
|
12842
|
-
const absoluteScriptPath =
|
|
13027
|
+
const absoluteScriptPath = path45.isAbsolute(scriptPath) ? scriptPath : path45.resolve(this.projectPath, scriptPath);
|
|
12843
13028
|
if (!existsSync11(absoluteScriptPath)) {
|
|
12844
13029
|
throw new Error(`Script not found: ${absoluteScriptPath}`);
|
|
12845
13030
|
}
|
|
@@ -12870,7 +13055,7 @@ class ScriptRunner {
|
|
|
12870
13055
|
ADK_API_URL: this.credentials.apiUrl,
|
|
12871
13056
|
...configuration && { ADK_CONFIGURATION: JSON.stringify(configuration) }
|
|
12872
13057
|
};
|
|
12873
|
-
return new Promise((
|
|
13058
|
+
return new Promise((resolve5, reject) => {
|
|
12874
13059
|
const child = spawn2("bun", args, {
|
|
12875
13060
|
cwd: botPath,
|
|
12876
13061
|
env,
|
|
@@ -12880,7 +13065,7 @@ class ScriptRunner {
|
|
|
12880
13065
|
reject(error);
|
|
12881
13066
|
});
|
|
12882
13067
|
child.on("close", (code) => {
|
|
12883
|
-
|
|
13068
|
+
resolve5(code ?? 0);
|
|
12884
13069
|
});
|
|
12885
13070
|
});
|
|
12886
13071
|
}
|
|
@@ -12928,1293 +13113,17 @@ Either run from within an agent project directory, or provide projectPath explic
|
|
|
12928
13113
|
});
|
|
12929
13114
|
return runner.setupTestRuntime({ env: options.env });
|
|
12930
13115
|
}
|
|
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
13116
|
export {
|
|
14199
13117
|
workspaceCache,
|
|
14200
13118
|
validateSecretName,
|
|
14201
13119
|
stringifyWithOrder,
|
|
14202
13120
|
startCopilotServer,
|
|
14203
13121
|
setupTestRuntime,
|
|
14204
|
-
saveRunResult,
|
|
14205
13122
|
runScript,
|
|
14206
|
-
runEvalSuite,
|
|
14207
|
-
runEval,
|
|
14208
13123
|
orderKeys,
|
|
14209
|
-
loadRunResult,
|
|
14210
|
-
loadEvalsFromDir,
|
|
14211
|
-
loadEvalFile,
|
|
14212
|
-
loadEvalByName,
|
|
14213
|
-
listRunResults,
|
|
14214
13124
|
integrationKeyOrder,
|
|
14215
13125
|
initAssets,
|
|
14216
13126
|
getRelativeTime,
|
|
14217
|
-
getLatestRun,
|
|
14218
13127
|
getInnerTypeName,
|
|
14219
13128
|
getChatClient,
|
|
14220
13129
|
generateIntegrationTypes,
|
|
@@ -14222,7 +13131,6 @@ export {
|
|
|
14222
13131
|
generateBotProject,
|
|
14223
13132
|
generateAssetsTypes,
|
|
14224
13133
|
generateAssetsRuntime,
|
|
14225
|
-
filterEvals,
|
|
14226
13134
|
dependenciesKeyOrder,
|
|
14227
13135
|
coerceConfigValue,
|
|
14228
13136
|
checkHasProvider,
|
|
@@ -14256,7 +13164,6 @@ export {
|
|
|
14256
13164
|
IntegrationCache,
|
|
14257
13165
|
HubCache,
|
|
14258
13166
|
FileWatcher2 as FileWatcher,
|
|
14259
|
-
Eval,
|
|
14260
13167
|
EnhancedInterfaceCache,
|
|
14261
13168
|
DevIdManager,
|
|
14262
13169
|
CredentialsManager,
|
|
@@ -14277,4 +13184,4 @@ export {
|
|
|
14277
13184
|
AgentProject
|
|
14278
13185
|
};
|
|
14279
13186
|
|
|
14280
|
-
//# debugId=
|
|
13187
|
+
//# debugId=8BA5B4B61CC8EC4F64756E2164756E21
|