@botpress/adk 1.13.18 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bot-generator/generator.d.ts +10 -0
- package/dist/bot-generator/generator.d.ts.map +1 -1
- package/dist/commands/base-command.d.ts +1 -0
- package/dist/commands/base-command.d.ts.map +1 -1
- package/dist/commands/bp-dev-command.d.ts.map +1 -1
- package/dist/generators/client-wrapper.d.ts +3 -0
- package/dist/generators/client-wrapper.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +675 -180
- package/dist/index.js.map +11 -9
- package/dist/integrations/checker.d.ts.map +1 -1
- package/dist/integrations/config-utils.d.ts +29 -0
- package/dist/integrations/config-utils.d.ts.map +1 -0
- package/dist/integrations/index.d.ts +2 -0
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/sync-manager.d.ts.map +1 -1
- package/dist/preflight/checker.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -666,7 +666,7 @@ var PRETTIER_CONFIG, formatCode = async (code, filepath) => {
|
|
|
666
666
|
`));
|
|
667
667
|
return code;
|
|
668
668
|
}
|
|
669
|
-
}, ADK_VERSION = "1.
|
|
669
|
+
}, ADK_VERSION = "1.14.0", relative2 = (from, to) => {
|
|
670
670
|
const fromDir = path10.dirname(from);
|
|
671
671
|
const relative3 = path10.relative(fromDir, to);
|
|
672
672
|
return relative3.startsWith(".") ? relative3 : `./${relative3}`;
|
|
@@ -690,7 +690,7 @@ var exports_action_types = {};
|
|
|
690
690
|
__export(exports_action_types, {
|
|
691
691
|
generateActionTypes: () => generateActionTypes
|
|
692
692
|
});
|
|
693
|
-
import
|
|
693
|
+
import path32 from "path";
|
|
694
694
|
async function generateActionTypes(project) {
|
|
695
695
|
const actionDefs = [];
|
|
696
696
|
for (const action of project.actions) {
|
|
@@ -705,7 +705,7 @@ async function generateActionTypes(project) {
|
|
|
705
705
|
};`);
|
|
706
706
|
continue;
|
|
707
707
|
}
|
|
708
|
-
const absolutePath =
|
|
708
|
+
const absolutePath = path32.join(project.path, action.path);
|
|
709
709
|
const actionModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
710
710
|
const actionInstance = actionModule[action.export] || actionModule.default;
|
|
711
711
|
if (actionInstance && actionInstance.input && actionInstance.output) {
|
|
@@ -750,7 +750,7 @@ ${actionDefs.join(`
|
|
|
750
750
|
};
|
|
751
751
|
}
|
|
752
752
|
`;
|
|
753
|
-
const actionTypesPath =
|
|
753
|
+
const actionTypesPath = path32.join(project.path, ".adk", "action-types.d.ts");
|
|
754
754
|
await createFile(actionTypesPath, await formatCode(content));
|
|
755
755
|
}
|
|
756
756
|
var init_action_types = __esm(() => {
|
|
@@ -763,7 +763,7 @@ var exports_integration_action_types = {};
|
|
|
763
763
|
__export(exports_integration_action_types, {
|
|
764
764
|
generateIntegrationActionTypes: () => generateIntegrationActionTypes
|
|
765
765
|
});
|
|
766
|
-
import
|
|
766
|
+
import path33 from "path";
|
|
767
767
|
async function generateIntegrationActionTypes(project) {
|
|
768
768
|
const content = `
|
|
769
769
|
////////////////////////////////////////////////////////
|
|
@@ -797,7 +797,7 @@ type IntegrationsMap<T> = {
|
|
|
797
797
|
export type IntegrationActions = IntegrationsMap<Integrations>;
|
|
798
798
|
}
|
|
799
799
|
`;
|
|
800
|
-
const integrationActionTypesPath =
|
|
800
|
+
const integrationActionTypesPath = path33.join(project.path, ".adk", "integration-action-types.d.ts");
|
|
801
801
|
await createFile(integrationActionTypesPath, await formatCode(content));
|
|
802
802
|
}
|
|
803
803
|
var init_integration_action_types = __esm(() => {
|
|
@@ -809,7 +809,7 @@ var init_integration_action_types = __esm(() => {
|
|
|
809
809
|
var require_package = __commonJS((exports, module) => {
|
|
810
810
|
module.exports = {
|
|
811
811
|
name: "@botpress/adk",
|
|
812
|
-
version: "1.
|
|
812
|
+
version: "1.14.0",
|
|
813
813
|
description: "Core ADK library for building AI agents on Botpress",
|
|
814
814
|
type: "module",
|
|
815
815
|
main: "dist/index.js",
|
|
@@ -856,7 +856,7 @@ var require_package = __commonJS((exports, module) => {
|
|
|
856
856
|
"@botpress/cli": "^5.2.0",
|
|
857
857
|
"@botpress/client": "^1.28.0",
|
|
858
858
|
"@botpress/cognitive": "^0.3.3",
|
|
859
|
-
"@botpress/runtime": "^1.
|
|
859
|
+
"@botpress/runtime": "^1.14.0",
|
|
860
860
|
"@botpress/sdk": "^5.1.0",
|
|
861
861
|
"@bpinternal/jex": "^1.2.4",
|
|
862
862
|
"@bpinternal/yargs-extra": "^0.0.21",
|
|
@@ -1072,6 +1072,9 @@ class BaseCommand {
|
|
|
1072
1072
|
on(event, listener) {
|
|
1073
1073
|
this.events.on(event, listener);
|
|
1074
1074
|
}
|
|
1075
|
+
off(event, listener) {
|
|
1076
|
+
this.events.off(event, listener);
|
|
1077
|
+
}
|
|
1075
1078
|
emit(event, ...args) {
|
|
1076
1079
|
if (event === "done") {
|
|
1077
1080
|
this.deferred.resolve(args[0]);
|
|
@@ -1617,7 +1620,16 @@ class BpDevCommand extends BaseCommand {
|
|
|
1617
1620
|
if (this.childProcess.stdout) {
|
|
1618
1621
|
this.childProcess.stdout.on("data", (data) => {
|
|
1619
1622
|
const text = data.toString();
|
|
1620
|
-
|
|
1623
|
+
if (text.includes('"worker_stats"')) {
|
|
1624
|
+
const nonWorkerStatsText = text.split(`
|
|
1625
|
+
`).filter((line) => !line.includes('"type":"worker_stats"') && !line.includes('"type": "worker_stats"')).join(`
|
|
1626
|
+
`);
|
|
1627
|
+
if (nonWorkerStatsText.trim()) {
|
|
1628
|
+
this.parseOutput(nonWorkerStatsText);
|
|
1629
|
+
}
|
|
1630
|
+
} else {
|
|
1631
|
+
this.parseOutput(text);
|
|
1632
|
+
}
|
|
1621
1633
|
this.emit("stdout", text);
|
|
1622
1634
|
});
|
|
1623
1635
|
}
|
|
@@ -3426,7 +3438,65 @@ class IntegrationOperations {
|
|
|
3426
3438
|
}
|
|
3427
3439
|
}
|
|
3428
3440
|
// src/integrations/checker.ts
|
|
3441
|
+
import { Client as Client9 } from "@botpress/client";
|
|
3442
|
+
|
|
3443
|
+
// src/integrations/config-utils.ts
|
|
3429
3444
|
import { Client as Client8 } from "@botpress/client";
|
|
3445
|
+
function mergeIntegrationConfig(current, desired) {
|
|
3446
|
+
if (desired === undefined) {
|
|
3447
|
+
return current || {};
|
|
3448
|
+
}
|
|
3449
|
+
return { ...current || {}, ...desired };
|
|
3450
|
+
}
|
|
3451
|
+
function configsMatch(current, desired, schemaDefaults = {}) {
|
|
3452
|
+
return Object.keys(desired).every((key) => {
|
|
3453
|
+
const currentValue = current?.[key] ?? schemaDefaults[key];
|
|
3454
|
+
const desiredValue = desired[key] ?? schemaDefaults[key];
|
|
3455
|
+
return JSON.stringify(currentValue) === JSON.stringify(desiredValue);
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
async function fetchServerIntegrationConfigs(project, targetBotId) {
|
|
3459
|
+
const { devId, botId } = project.agentInfo ?? {};
|
|
3460
|
+
const targetId = targetBotId || devId || botId;
|
|
3461
|
+
if (!targetId) {
|
|
3462
|
+
return { configs: {}, fetched: false, skipped: true };
|
|
3463
|
+
}
|
|
3464
|
+
try {
|
|
3465
|
+
const credentials = await auth.getActiveCredentials();
|
|
3466
|
+
const client = new Client8({
|
|
3467
|
+
token: credentials.token,
|
|
3468
|
+
apiUrl: credentials.apiUrl,
|
|
3469
|
+
workspaceId: project.agentInfo?.workspaceId || credentials.workspaceId,
|
|
3470
|
+
headers: { "x-multiple-integrations": "true" }
|
|
3471
|
+
});
|
|
3472
|
+
try {
|
|
3473
|
+
return await fetchBotConfigs(client, targetId);
|
|
3474
|
+
} catch (err) {
|
|
3475
|
+
if (targetBotId) {
|
|
3476
|
+
throw err;
|
|
3477
|
+
}
|
|
3478
|
+
if (devId && botId && devId !== botId) {
|
|
3479
|
+
return await fetchBotConfigs(client, botId);
|
|
3480
|
+
}
|
|
3481
|
+
throw err;
|
|
3482
|
+
}
|
|
3483
|
+
} catch (err) {
|
|
3484
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
3485
|
+
return { configs: {}, fetched: false, skipped: false, error: message };
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
async function fetchBotConfigs(client, botId) {
|
|
3489
|
+
const { bot } = await client.getBot({ id: botId });
|
|
3490
|
+
const configs = {};
|
|
3491
|
+
for (const [alias, integration] of Object.entries(bot.integrations || {})) {
|
|
3492
|
+
if (integration.configuration && Object.keys(integration.configuration).length > 0) {
|
|
3493
|
+
configs[alias] = integration.configuration;
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3496
|
+
return { configs, fetched: true, skipped: false };
|
|
3497
|
+
}
|
|
3498
|
+
|
|
3499
|
+
// src/integrations/checker.ts
|
|
3430
3500
|
class IntegrationChecker {
|
|
3431
3501
|
projectPath;
|
|
3432
3502
|
client;
|
|
@@ -3441,7 +3511,7 @@ class IntegrationChecker {
|
|
|
3441
3511
|
if (!workspaceId) {
|
|
3442
3512
|
throw new Error('No workspace ID found. Please login with "adk login"');
|
|
3443
3513
|
}
|
|
3444
|
-
this.client = new
|
|
3514
|
+
this.client = new Client9({
|
|
3445
3515
|
token: credentials.token,
|
|
3446
3516
|
apiUrl: credentials.apiUrl,
|
|
3447
3517
|
workspaceId,
|
|
@@ -3579,17 +3649,8 @@ class IntegrationChecker {
|
|
|
3579
3649
|
if (config !== undefined) {
|
|
3580
3650
|
const configType = configurationType ?? installedIntegration.configurationType;
|
|
3581
3651
|
const schema = configType && definition.configurations?.[configType]?.schema || definition.configurations?.["default"]?.schema || definition.configuration?.schema;
|
|
3582
|
-
const
|
|
3583
|
-
|
|
3584
|
-
...Object.keys(installedIntegration.configuration || {}),
|
|
3585
|
-
...Object.keys(config || {})
|
|
3586
|
-
]);
|
|
3587
|
-
const configsMatch = Array.from(allKeys).every((key) => {
|
|
3588
|
-
const currentValue = installedIntegration.configuration?.[key] ?? schemaProperties[key]?.default;
|
|
3589
|
-
const desiredValue = config?.[key] ?? schemaProperties[key]?.default;
|
|
3590
|
-
return JSON.stringify(currentValue) === JSON.stringify(desiredValue);
|
|
3591
|
-
});
|
|
3592
|
-
if (!configsMatch) {
|
|
3652
|
+
const schemaDefaults = Object.fromEntries(Object.entries(schema?.properties || {}).flatMap(([k, v]) => v?.default !== undefined ? [[k, v.default]] : []));
|
|
3653
|
+
if (!configsMatch(installedIntegration.configuration, config, schemaDefaults)) {
|
|
3593
3654
|
result.needsConfiguration = true;
|
|
3594
3655
|
}
|
|
3595
3656
|
}
|
|
@@ -3605,7 +3666,7 @@ class IntegrationChecker {
|
|
|
3605
3666
|
}
|
|
3606
3667
|
}
|
|
3607
3668
|
// src/integrations/sync-manager.ts
|
|
3608
|
-
import { Client as
|
|
3669
|
+
import { Client as Client10 } from "@botpress/client";
|
|
3609
3670
|
function normalizeConfigurationType(configType) {
|
|
3610
3671
|
if (configType === "default" || configType === null) {
|
|
3611
3672
|
return;
|
|
@@ -3627,7 +3688,7 @@ class IntegrationSyncManager {
|
|
|
3627
3688
|
if (!workspaceId) {
|
|
3628
3689
|
throw new Error('No workspace ID found. Please login with "adk login"');
|
|
3629
3690
|
}
|
|
3630
|
-
this.client = new
|
|
3691
|
+
this.client = new Client10({
|
|
3631
3692
|
token: credentials.token,
|
|
3632
3693
|
apiUrl: credentials.apiUrl,
|
|
3633
3694
|
workspaceId,
|
|
@@ -3670,7 +3731,7 @@ class IntegrationSyncManager {
|
|
|
3670
3731
|
[result.alias]: {
|
|
3671
3732
|
integrationId: result.desiredIntegrationId || result.definition.id,
|
|
3672
3733
|
enabled: result.desiredInstallStatus === "enabled",
|
|
3673
|
-
configuration: result.desiredConfiguration
|
|
3734
|
+
configuration: mergeIntegrationConfig(result.currentConfiguration, result.desiredConfiguration),
|
|
3674
3735
|
configurationType: normalizeConfigurationType(result.desiredConfigurationType)
|
|
3675
3736
|
}
|
|
3676
3737
|
}
|
|
@@ -3689,7 +3750,7 @@ class IntegrationSyncManager {
|
|
|
3689
3750
|
[result.alias]: {
|
|
3690
3751
|
integrationId: result.desiredIntegrationId || result.definition.id,
|
|
3691
3752
|
enabled: result.desiredInstallStatus === "enabled",
|
|
3692
|
-
configuration: result.desiredConfiguration
|
|
3753
|
+
configuration: mergeIntegrationConfig(result.currentConfiguration, result.desiredConfiguration),
|
|
3693
3754
|
configurationType: normalizeConfigurationType(result.desiredConfigurationType)
|
|
3694
3755
|
}
|
|
3695
3756
|
}
|
|
@@ -3706,7 +3767,7 @@ class IntegrationSyncManager {
|
|
|
3706
3767
|
}
|
|
3707
3768
|
}
|
|
3708
3769
|
// src/interfaces/manager.ts
|
|
3709
|
-
import { Client as
|
|
3770
|
+
import { Client as Client11 } from "@botpress/client";
|
|
3710
3771
|
|
|
3711
3772
|
// src/interfaces/enhanced-cache.ts
|
|
3712
3773
|
import fs9 from "fs/promises";
|
|
@@ -3877,7 +3938,7 @@ class InterfaceManager {
|
|
|
3877
3938
|
if (!this.options.workspaceId && !credentials.workspaceId) {
|
|
3878
3939
|
throw new Error('No workspace ID found in current profile. Please login again with "adk login"');
|
|
3879
3940
|
}
|
|
3880
|
-
this.client = new
|
|
3941
|
+
this.client = new Client11({
|
|
3881
3942
|
token: credentials.token,
|
|
3882
3943
|
apiUrl: credentials.apiUrl,
|
|
3883
3944
|
workspaceId: this.options.workspaceId || credentials.workspaceId,
|
|
@@ -4875,7 +4936,7 @@ init_validation_errors();
|
|
|
4875
4936
|
init_agent_resolver();
|
|
4876
4937
|
init_types();
|
|
4877
4938
|
// src/config/manager.ts
|
|
4878
|
-
import { Client as
|
|
4939
|
+
import { Client as Client12 } from "@botpress/client";
|
|
4879
4940
|
import { sync as jex } from "@bpinternal/jex";
|
|
4880
4941
|
class ConfigManager {
|
|
4881
4942
|
botId;
|
|
@@ -4886,7 +4947,7 @@ class ConfigManager {
|
|
|
4886
4947
|
async getClient() {
|
|
4887
4948
|
if (!this.client) {
|
|
4888
4949
|
const credentials = await auth.getActiveCredentials();
|
|
4889
|
-
this.client = new
|
|
4950
|
+
this.client = new Client12({
|
|
4890
4951
|
token: credentials.token,
|
|
4891
4952
|
apiUrl: credentials.apiUrl,
|
|
4892
4953
|
botId: this.botId,
|
|
@@ -6347,7 +6408,7 @@ class AgentProjectGenerator {
|
|
|
6347
6408
|
deploy: "adk deploy"
|
|
6348
6409
|
},
|
|
6349
6410
|
dependencies: {
|
|
6350
|
-
"@botpress/runtime": `^${"1.
|
|
6411
|
+
"@botpress/runtime": `^${"1.14.0"}`
|
|
6351
6412
|
},
|
|
6352
6413
|
devDependencies: {
|
|
6353
6414
|
typescript: "^5.9.3"
|
|
@@ -6957,16 +7018,399 @@ Description: ${tag?.description}`);
|
|
|
6957
7018
|
}
|
|
6958
7019
|
};
|
|
6959
7020
|
}
|
|
7021
|
+
// src/generators/client-wrapper.ts
|
|
7022
|
+
init_utils();
|
|
7023
|
+
init_fs();
|
|
7024
|
+
import path18 from "path";
|
|
7025
|
+
import { BuiltInWorkflows as BuiltInWorkflows2 } from "@botpress/runtime/internal";
|
|
7026
|
+
function isBuiltinWorkflow(name) {
|
|
7027
|
+
return !!Object.values(BuiltInWorkflows2).find((x) => x.name === name);
|
|
7028
|
+
}
|
|
7029
|
+
async function generateClientWrapper(project) {
|
|
7030
|
+
const actionTypes = [];
|
|
7031
|
+
for (const action of project.actions) {
|
|
7032
|
+
if (action.definition.attributes?.visibility === "hidden") {
|
|
7033
|
+
continue;
|
|
7034
|
+
}
|
|
7035
|
+
try {
|
|
7036
|
+
if (action.path === "<adk:builtin>") {
|
|
7037
|
+
actionTypes.push({
|
|
7038
|
+
name: action.definition.name,
|
|
7039
|
+
inputType: "any",
|
|
7040
|
+
outputType: "any"
|
|
7041
|
+
});
|
|
7042
|
+
continue;
|
|
7043
|
+
}
|
|
7044
|
+
const absolutePath = path18.join(project.path, action.path);
|
|
7045
|
+
const actionModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
7046
|
+
const actionInstance = actionModule[action.export] || actionModule.default;
|
|
7047
|
+
if (actionInstance && actionInstance.input && actionInstance.output) {
|
|
7048
|
+
const inputType = actionInstance.input.toTypescriptType ? actionInstance.input.toTypescriptType() : "any";
|
|
7049
|
+
const outputType = actionInstance.output.toTypescriptType ? actionInstance.output.toTypescriptType() : "any";
|
|
7050
|
+
actionTypes.push({
|
|
7051
|
+
name: action.definition.name,
|
|
7052
|
+
inputType,
|
|
7053
|
+
outputType
|
|
7054
|
+
});
|
|
7055
|
+
}
|
|
7056
|
+
} catch (error) {
|
|
7057
|
+
console.warn(`Warning: Could not process action ${action.definition.name}:`, error);
|
|
7058
|
+
actionTypes.push({
|
|
7059
|
+
name: action.definition.name,
|
|
7060
|
+
inputType: "any",
|
|
7061
|
+
outputType: "any"
|
|
7062
|
+
});
|
|
7063
|
+
}
|
|
7064
|
+
}
|
|
7065
|
+
const workflowTypes = [];
|
|
7066
|
+
for (const workflow of project.workflows) {
|
|
7067
|
+
try {
|
|
7068
|
+
if (isBuiltinWorkflow(workflow.definition.name)) {
|
|
7069
|
+
continue;
|
|
7070
|
+
}
|
|
7071
|
+
const workflowPath = path18.join(project.path, workflow.path);
|
|
7072
|
+
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
7073
|
+
const workflowInstance = workflowModule[workflow.export] || workflowModule.default;
|
|
7074
|
+
if (workflowInstance) {
|
|
7075
|
+
const inputType = workflowInstance.inputSchema ? workflowInstance.inputSchema.toTypescriptType?.() || "any" : "{}";
|
|
7076
|
+
const outputType = workflowInstance.outputSchema ? workflowInstance.outputSchema.toTypescriptType?.() || "any" : "{}";
|
|
7077
|
+
workflowTypes.push({
|
|
7078
|
+
name: workflow.definition.name,
|
|
7079
|
+
inputType,
|
|
7080
|
+
outputType
|
|
7081
|
+
});
|
|
7082
|
+
}
|
|
7083
|
+
} catch (error) {
|
|
7084
|
+
console.warn(`Warning: Could not process workflow ${workflow.definition.name}:`, error);
|
|
7085
|
+
}
|
|
7086
|
+
}
|
|
7087
|
+
const tableTypes = [];
|
|
7088
|
+
for (const table of project.tables) {
|
|
7089
|
+
try {
|
|
7090
|
+
const tablePath = path18.join(project.path, table.path);
|
|
7091
|
+
const tableModule = await import(`${tablePath}?t=${Date.now()}`);
|
|
7092
|
+
const tableInstance = tableModule.default || tableModule[table.export];
|
|
7093
|
+
if (tableInstance && tableInstance.columns) {
|
|
7094
|
+
const inputColumns = [];
|
|
7095
|
+
const outputColumns = ["id: number", "createdAt: string", "updatedAt: string"];
|
|
7096
|
+
for (const [colName, colDef] of Object.entries(tableInstance.columns)) {
|
|
7097
|
+
let schema;
|
|
7098
|
+
let computed = false;
|
|
7099
|
+
if (typeof colDef === "object" && colDef !== null && "schema" in colDef) {
|
|
7100
|
+
schema = colDef.schema;
|
|
7101
|
+
computed = colDef.computed || false;
|
|
7102
|
+
} else {
|
|
7103
|
+
schema = colDef;
|
|
7104
|
+
}
|
|
7105
|
+
const tsType = schema.toTypescriptType ? schema.toTypescriptType() : "any";
|
|
7106
|
+
if (!computed) {
|
|
7107
|
+
inputColumns.push(`${colName}: ${tsType}`);
|
|
7108
|
+
}
|
|
7109
|
+
outputColumns.push(`${colName}: ${tsType}`);
|
|
7110
|
+
}
|
|
7111
|
+
tableTypes.push({
|
|
7112
|
+
name: table.definition.name,
|
|
7113
|
+
inputType: `{ ${inputColumns.join("; ")} }`,
|
|
7114
|
+
outputType: `{ ${outputColumns.join("; ")} }`
|
|
7115
|
+
});
|
|
7116
|
+
}
|
|
7117
|
+
} catch (error) {
|
|
7118
|
+
console.warn(`Warning: Could not process table ${table.definition.name}:`, error);
|
|
7119
|
+
}
|
|
7120
|
+
}
|
|
7121
|
+
const content = `
|
|
7122
|
+
// @ts-nocheck
|
|
7123
|
+
////////////////////////////////////////////////////////
|
|
7124
|
+
// DO NOT EDIT THIS FILE DIRECTLY
|
|
7125
|
+
// This file is auto-generated from the Botpress ADK
|
|
7126
|
+
// ADK Version: ${ADK_VERSION}
|
|
7127
|
+
// Generated at: ${new Date().toISOString()}
|
|
7128
|
+
////////////////////////////////////////////////////////
|
|
7129
|
+
|
|
7130
|
+
import type { Client, Workflow } from '@botpress/client'
|
|
7131
|
+
|
|
7132
|
+
// Utility type to simplify complex types
|
|
7133
|
+
type Simplify<T> = T extends (...args: infer A) => infer R
|
|
7134
|
+
? (...args: SimplifyTuple<A>) => Simplify<R>
|
|
7135
|
+
: T extends Array<infer E>
|
|
7136
|
+
? Array<Simplify<E>>
|
|
7137
|
+
: T extends ReadonlyArray<infer E>
|
|
7138
|
+
? ReadonlyArray<Simplify<E>>
|
|
7139
|
+
: T extends Promise<infer R>
|
|
7140
|
+
? Promise<Simplify<R>>
|
|
7141
|
+
: T extends Buffer
|
|
7142
|
+
? Buffer
|
|
7143
|
+
: T extends object
|
|
7144
|
+
? SimplifyObject<T>
|
|
7145
|
+
: T
|
|
7146
|
+
|
|
7147
|
+
type SimplifyTuple<T> = T extends [...infer A] ? { [K in keyof A]: Simplify<A[K]> } : never
|
|
7148
|
+
type SimplifyObject<T extends object> = T extends infer O ? { [K in keyof O]: Simplify<O[K]> } : never
|
|
7149
|
+
|
|
7150
|
+
type GenericWorkflowInput = Record<string, any>
|
|
7151
|
+
type GenericWorkflowOutput = Record<string, any>
|
|
7152
|
+
|
|
7153
|
+
type TypedWorkflow<TInput = GenericWorkflowInput, TOutput = GenericWorkflowOutput> = Simplify<
|
|
7154
|
+
Omit<Workflow, 'input' | 'output'> & {
|
|
7155
|
+
input: TInput
|
|
7156
|
+
output: TOutput
|
|
7157
|
+
}
|
|
7158
|
+
>
|
|
7159
|
+
|
|
7160
|
+
// Extract response types from Client methods
|
|
7161
|
+
type CreateWorkflowResponse = Simplify<Awaited<ReturnType<Client['createWorkflow']>>>
|
|
7162
|
+
type GetWorkflowResponse = Simplify<Awaited<ReturnType<Client['getWorkflow']>>>
|
|
7163
|
+
type UpdateWorkflowResponse = Simplify<Awaited<ReturnType<Client['updateWorkflow']>>>
|
|
7164
|
+
type DeleteWorkflowResponse = Simplify<Awaited<ReturnType<Client['deleteWorkflow']>>>
|
|
7165
|
+
type GetOrCreateWorkflowResponse = Simplify<Awaited<ReturnType<Client['getOrCreateWorkflow']>>>
|
|
7166
|
+
|
|
7167
|
+
type CreateTableRowsResponse = Simplify<Awaited<ReturnType<Client['createTableRows']>>>
|
|
7168
|
+
type UpdateTableRowsResponse = Simplify<Awaited<ReturnType<Client['updateTableRows']>>>
|
|
7169
|
+
type UpsertTableRowsResponse = Simplify<Awaited<ReturnType<Client['upsertTableRows']>>>
|
|
7170
|
+
type DeleteTableRowsResponse = Simplify<Awaited<ReturnType<Client['deleteTableRows']>>>
|
|
7171
|
+
type FindTableRowsResponse = Simplify<Awaited<ReturnType<Client['findTableRows']>>>
|
|
7172
|
+
type GetTableRowResponse = Simplify<Awaited<ReturnType<Client['getTableRow']>>>
|
|
7173
|
+
|
|
7174
|
+
// Extract parameter types from Client methods
|
|
7175
|
+
type ParamCreateWorkflow = Simplify<Parameters<Client['createWorkflow']>[0]>
|
|
7176
|
+
type ParamGetWorkflow = Simplify<Parameters<Client['getWorkflow']>[0]>
|
|
7177
|
+
type ParamUpdateWorkflow = Simplify<Parameters<Client['updateWorkflow']>[0]>
|
|
7178
|
+
type ParamDeleteWorkflow = Simplify<Parameters<Client['deleteWorkflow']>[0]>
|
|
7179
|
+
type ParamGetOrCreateWorkflow = Simplify<Parameters<Client['getOrCreateWorkflow']>[0]>
|
|
7180
|
+
|
|
7181
|
+
type ParamCreateTableRows = Simplify<Parameters<Client['createTableRows']>[0]>
|
|
7182
|
+
type ParamUpdateTableRows = Simplify<Parameters<Client['updateTableRows']>[0]>
|
|
7183
|
+
type ParamUpsertTableRows = Simplify<Parameters<Client['upsertTableRows']>[0]>
|
|
7184
|
+
type ParamDeleteTableRows = Simplify<Parameters<Client['deleteTableRows']>[0]>
|
|
7185
|
+
type ParamFindTableRows = Simplify<Parameters<Client['findTableRows']>[0]>
|
|
7186
|
+
type ParamGetTableRow = Simplify<Parameters<Client['getTableRow']>[0]>
|
|
7187
|
+
|
|
7188
|
+
/**
|
|
7189
|
+
* Typed ADK Client
|
|
7190
|
+
*
|
|
7191
|
+
* Provides strongly-typed wrappers around the Botpress Client for actions, workflows, and tables.
|
|
7192
|
+
*/
|
|
7193
|
+
export interface AdkClient {
|
|
7194
|
+
/**
|
|
7195
|
+
* Typed action calls
|
|
7196
|
+
*/
|
|
7197
|
+
actions: {
|
|
7198
|
+
${actionTypes.map((action) => `
|
|
7199
|
+
/**
|
|
7200
|
+
* Call action: ${action.name}
|
|
7201
|
+
*/
|
|
7202
|
+
'${action.name}': (input: ${action.inputType}) => Promise<${action.outputType}>
|
|
7203
|
+
`).join(`
|
|
7204
|
+
`)}
|
|
7205
|
+
}
|
|
7206
|
+
|
|
7207
|
+
/**
|
|
7208
|
+
* Typed workflow operations
|
|
7209
|
+
*/
|
|
7210
|
+
workflows: {
|
|
7211
|
+
${workflowTypes.map((workflow) => `
|
|
7212
|
+
'${workflow.name}': {
|
|
7213
|
+
/**
|
|
7214
|
+
* Create workflow: ${workflow.name}
|
|
7215
|
+
*/
|
|
7216
|
+
createWorkflow: (params: Omit<ParamCreateWorkflow, 'name' | 'input'> & { input?: ${workflow.inputType} }) => Promise<Omit<CreateWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${workflow.inputType}, ${workflow.outputType}> }>
|
|
7217
|
+
/**
|
|
7218
|
+
* Get workflow by ID
|
|
7219
|
+
*/
|
|
7220
|
+
getWorkflow: (params: ParamGetWorkflow) => Promise<Omit<GetWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${workflow.inputType}, ${workflow.outputType}> }>
|
|
7221
|
+
/**
|
|
7222
|
+
* Update workflow
|
|
7223
|
+
*/
|
|
7224
|
+
updateWorkflow: (params: Omit<ParamUpdateWorkflow, 'output'> & { output?: ${workflow.outputType} }) => Promise<Omit<UpdateWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${workflow.inputType}, ${workflow.outputType}> }>
|
|
7225
|
+
/**
|
|
7226
|
+
* Delete workflow
|
|
7227
|
+
*/
|
|
7228
|
+
deleteWorkflow: (params: ParamDeleteWorkflow) => Promise<DeleteWorkflowResponse>
|
|
7229
|
+
/**
|
|
7230
|
+
* Get or create workflow with deduplication key
|
|
7231
|
+
*/
|
|
7232
|
+
getOrCreateWorkflow: (params: Omit<ParamGetOrCreateWorkflow, 'name' | 'input'> & { input?: ${workflow.inputType} }) => Promise<Omit<GetOrCreateWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${workflow.inputType}, ${workflow.outputType}> }>
|
|
7233
|
+
}
|
|
7234
|
+
`).join(`
|
|
7235
|
+
`)}
|
|
7236
|
+
}
|
|
7237
|
+
|
|
7238
|
+
/**
|
|
7239
|
+
* Typed table operations
|
|
7240
|
+
*/
|
|
7241
|
+
tables: {
|
|
7242
|
+
${tableTypes.map((table) => `
|
|
7243
|
+
'${table.name}': {
|
|
7244
|
+
/**
|
|
7245
|
+
* Find rows in table: ${table.name}
|
|
7246
|
+
*/
|
|
7247
|
+
findTableRows: (params?: Omit<ParamFindTableRows, 'table'>) => Promise<Omit<FindTableRowsResponse, 'rows'> & { rows: Array<${table.outputType}> }>
|
|
7248
|
+
/**
|
|
7249
|
+
* Get a single row by ID
|
|
7250
|
+
*/
|
|
7251
|
+
getTableRow: (params: Omit<ParamGetTableRow, 'table'>) => Promise<Omit<GetTableRowResponse, 'row'> & { row: ${table.outputType} }>
|
|
7252
|
+
/**
|
|
7253
|
+
* Create rows in table: ${table.name}
|
|
7254
|
+
*/
|
|
7255
|
+
createTableRows: (params: Omit<ParamCreateTableRows, 'table'>) => Promise<Omit<CreateTableRowsResponse, 'rows'> & { rows: Array<${table.outputType}> }>
|
|
7256
|
+
/**
|
|
7257
|
+
* Update rows in table: ${table.name}
|
|
7258
|
+
*/
|
|
7259
|
+
updateTableRows: (params: Omit<ParamUpdateTableRows, 'table'>) => Promise<Omit<UpdateTableRowsResponse, 'rows'> & { rows: Array<${table.outputType}> }>
|
|
7260
|
+
/**
|
|
7261
|
+
* Upsert rows in table: ${table.name}
|
|
7262
|
+
*/
|
|
7263
|
+
upsertTableRows: (params: Omit<ParamUpsertTableRows, 'table'>) => Promise<Omit<UpsertTableRowsResponse, 'rows'> & { rows: Array<${table.outputType}> }>
|
|
7264
|
+
/**
|
|
7265
|
+
* Delete rows by IDs
|
|
7266
|
+
*/
|
|
7267
|
+
deleteTableRows: (params: Omit<ParamDeleteTableRows, 'table'>) => Promise<Omit<DeleteTableRowsResponse, 'rows'> & { rows: Array<${table.outputType}> }>
|
|
7268
|
+
}
|
|
7269
|
+
`).join(`
|
|
7270
|
+
`)}
|
|
7271
|
+
}
|
|
7272
|
+
|
|
7273
|
+
/**
|
|
7274
|
+
* Raw Botpress client (no additional typing)
|
|
7275
|
+
*/
|
|
7276
|
+
client: Client
|
|
7277
|
+
}
|
|
7278
|
+
|
|
7279
|
+
/**
|
|
7280
|
+
* Create a typed ADK client wrapper around a Botpress Client
|
|
7281
|
+
*
|
|
7282
|
+
* @example
|
|
7283
|
+
* \`\`\`typescript
|
|
7284
|
+
* import { Client } from '@botpress/client'
|
|
7285
|
+
* import { createAdkClient } from './.adk/client'
|
|
7286
|
+
*
|
|
7287
|
+
* const client = new Client({ token: 'xxx', botId: 'yyy' })
|
|
7288
|
+
* const adk = createAdkClient(client)
|
|
7289
|
+
*
|
|
7290
|
+
* // Typed action calls
|
|
7291
|
+
* const result = await adk.actions.myAction({ foo: 'bar' })
|
|
7292
|
+
*
|
|
7293
|
+
* // Typed workflow operations
|
|
7294
|
+
* const wf = await adk.workflows.myWorkflow.createWorkflow({ input: { data: 'value' } })
|
|
7295
|
+
* const workflow = await adk.workflows.myWorkflow.getWorkflow({ id: wf.workflow.id })
|
|
7296
|
+
* await adk.workflows.myWorkflow.updateWorkflow({ id: wf.workflow.id, status: 'completed' })
|
|
7297
|
+
* await adk.workflows.myWorkflow.deleteWorkflow({ id: wf.workflow.id })
|
|
7298
|
+
* await adk.workflows.myWorkflow.getOrCreateWorkflow({ key: 'unique-key', input: { data: 'value' } })
|
|
7299
|
+
*
|
|
7300
|
+
* // Typed table operations
|
|
7301
|
+
* const rows = await adk.tables.myTable.findTableRows({ filter: { name: 'John' } })
|
|
7302
|
+
* const row = await adk.tables.myTable.getTableRow({ id: 123 })
|
|
7303
|
+
* await adk.tables.myTable.createTableRows({ rows: [{ name: 'Jane', age: 30 }] })
|
|
7304
|
+
* await adk.tables.myTable.updateTableRows({ rows: [{ id: 123, name: 'Jane' }] })
|
|
7305
|
+
* await adk.tables.myTable.upsertTableRows({ rows: [{ name: 'Bob', age: 25 }] })
|
|
7306
|
+
* await adk.tables.myTable.deleteTableRows({ ids: [123, 456] })
|
|
7307
|
+
* \`\`\`
|
|
7308
|
+
*/
|
|
7309
|
+
export function createAdkClient(client: Client): AdkClient {
|
|
7310
|
+
return {
|
|
7311
|
+
actions: {
|
|
7312
|
+
${actionTypes.map((action) => `
|
|
7313
|
+
'${action.name}': async (input: ${action.inputType}) => {
|
|
7314
|
+
const response = await client.callAction({
|
|
7315
|
+
type: '${action.name}',
|
|
7316
|
+
input,
|
|
7317
|
+
})
|
|
7318
|
+
return response.output as ${action.outputType}
|
|
7319
|
+
}
|
|
7320
|
+
`).join(`,
|
|
7321
|
+
`)}
|
|
7322
|
+
},
|
|
7323
|
+
|
|
7324
|
+
workflows: {
|
|
7325
|
+
${workflowTypes.map((workflow) => `
|
|
7326
|
+
'${workflow.name}': {
|
|
7327
|
+
createWorkflow: async (params) => {
|
|
7328
|
+
return client.createWorkflow({
|
|
7329
|
+
name: '${workflow.name}',
|
|
7330
|
+
...params,
|
|
7331
|
+
}) as any
|
|
7332
|
+
},
|
|
7333
|
+
getWorkflow: async (params) => {
|
|
7334
|
+
return client.getWorkflow(params) as any
|
|
7335
|
+
},
|
|
7336
|
+
updateWorkflow: async (params) => {
|
|
7337
|
+
return client.updateWorkflow(params) as any
|
|
7338
|
+
},
|
|
7339
|
+
deleteWorkflow: async (params) => {
|
|
7340
|
+
return client.deleteWorkflow(params) as any
|
|
7341
|
+
},
|
|
7342
|
+
getOrCreateWorkflow: async (params) => {
|
|
7343
|
+
return client.getOrCreateWorkflow({
|
|
7344
|
+
name: '${workflow.name}',
|
|
7345
|
+
...params,
|
|
7346
|
+
}) as any
|
|
7347
|
+
},
|
|
7348
|
+
}
|
|
7349
|
+
`).join(`,
|
|
7350
|
+
`)}
|
|
7351
|
+
},
|
|
7352
|
+
|
|
7353
|
+
tables: {
|
|
7354
|
+
${tableTypes.map((table) => `
|
|
7355
|
+
'${table.name}': {
|
|
7356
|
+
findTableRows: async (params) => {
|
|
7357
|
+
return client.findTableRows({
|
|
7358
|
+
table: '${table.name}',
|
|
7359
|
+
...params,
|
|
7360
|
+
}) as any
|
|
7361
|
+
},
|
|
7362
|
+
getTableRow: async (params) => {
|
|
7363
|
+
return client.getTableRow({
|
|
7364
|
+
table: '${table.name}',
|
|
7365
|
+
...params,
|
|
7366
|
+
}) as any
|
|
7367
|
+
},
|
|
7368
|
+
createTableRows: async (params) => {
|
|
7369
|
+
return client.createTableRows({
|
|
7370
|
+
table: '${table.name}',
|
|
7371
|
+
...params,
|
|
7372
|
+
}) as any
|
|
7373
|
+
},
|
|
7374
|
+
updateTableRows: async (params) => {
|
|
7375
|
+
return client.updateTableRows({
|
|
7376
|
+
table: '${table.name}',
|
|
7377
|
+
...params,
|
|
7378
|
+
}) as any
|
|
7379
|
+
},
|
|
7380
|
+
upsertTableRows: async (params) => {
|
|
7381
|
+
return client.upsertTableRows({
|
|
7382
|
+
table: '${table.name}',
|
|
7383
|
+
...params,
|
|
7384
|
+
}) as any
|
|
7385
|
+
},
|
|
7386
|
+
deleteTableRows: async (params) => {
|
|
7387
|
+
return client.deleteTableRows({
|
|
7388
|
+
table: '${table.name}',
|
|
7389
|
+
...params,
|
|
7390
|
+
}) as any
|
|
7391
|
+
},
|
|
7392
|
+
}
|
|
7393
|
+
`).join(`,
|
|
7394
|
+
`)}
|
|
7395
|
+
},
|
|
7396
|
+
|
|
7397
|
+
client,
|
|
7398
|
+
}
|
|
7399
|
+
}
|
|
7400
|
+
`;
|
|
7401
|
+
const clientWrapperPath = path18.join(project.path, ".adk", "client.ts");
|
|
7402
|
+
await createFile(clientWrapperPath, await formatCode(content));
|
|
7403
|
+
}
|
|
6960
7404
|
// src/bot-generator/generator.ts
|
|
6961
7405
|
import dedent from "dedent";
|
|
6962
7406
|
import { existsSync as existsSync7 } from "fs";
|
|
6963
7407
|
import fs16 from "fs/promises";
|
|
6964
|
-
import
|
|
7408
|
+
import path34 from "path";
|
|
6965
7409
|
|
|
6966
7410
|
// src/generators/interface-types.ts
|
|
6967
7411
|
import { transforms as transforms2 } from "@botpress/sdk";
|
|
6968
7412
|
import crypto3 from "crypto";
|
|
6969
|
-
import
|
|
7413
|
+
import path19 from "path";
|
|
6970
7414
|
init_utils();
|
|
6971
7415
|
var sameMajorVersion = (a, b) => {
|
|
6972
7416
|
const majorA = a.split(".")[0];
|
|
@@ -6987,8 +7431,8 @@ var getInterfaceNames = (int) => ({
|
|
|
6987
7431
|
actions: `Interface_Actions_${pascalCase(int.name)}`
|
|
6988
7432
|
},
|
|
6989
7433
|
paths: {
|
|
6990
|
-
index:
|
|
6991
|
-
actions:
|
|
7434
|
+
index: path19.join(snakeCase(int.name), `index.ts`),
|
|
7435
|
+
actions: path19.join(snakeCase(int.name), `actions.ts`)
|
|
6992
7436
|
}
|
|
6993
7437
|
});
|
|
6994
7438
|
async function generateInterfaceTypes(int, integrations) {
|
|
@@ -7093,12 +7537,12 @@ Description: ${action.description || "No description"}`)}
|
|
|
7093
7537
|
// src/generators/table-types.ts
|
|
7094
7538
|
init_utils();
|
|
7095
7539
|
init_fs();
|
|
7096
|
-
import
|
|
7540
|
+
import path20 from "path";
|
|
7097
7541
|
async function generateTableTypes(project) {
|
|
7098
7542
|
const tables = [];
|
|
7099
7543
|
for (const tableRef of project.tables) {
|
|
7100
7544
|
try {
|
|
7101
|
-
const tablePath =
|
|
7545
|
+
const tablePath = path20.join(project.path, tableRef.path);
|
|
7102
7546
|
const tableModule = await import(`${tablePath}?t=${Date.now()}`);
|
|
7103
7547
|
const tableInstance = tableModule.default || tableModule[tableRef.export];
|
|
7104
7548
|
if (tableInstance && tableInstance.columns) {
|
|
@@ -7184,14 +7628,14 @@ ${outputColumns}
|
|
|
7184
7628
|
content += ` };
|
|
7185
7629
|
}
|
|
7186
7630
|
`;
|
|
7187
|
-
const tableTypesPath =
|
|
7631
|
+
const tableTypesPath = path20.join(project.path, ".adk", "table-types.d.ts");
|
|
7188
7632
|
await createFile(tableTypesPath, await formatCode(content));
|
|
7189
7633
|
}
|
|
7190
7634
|
|
|
7191
7635
|
// src/generators/trigger-types.ts
|
|
7192
7636
|
init_utils();
|
|
7193
7637
|
init_fs();
|
|
7194
|
-
import
|
|
7638
|
+
import path21 from "path";
|
|
7195
7639
|
async function generateTriggerTypes(project) {
|
|
7196
7640
|
const triggerEvents = {};
|
|
7197
7641
|
for (const trigger of project.triggers) {
|
|
@@ -7231,19 +7675,19 @@ ${triggersType}
|
|
|
7231
7675
|
};
|
|
7232
7676
|
}
|
|
7233
7677
|
`;
|
|
7234
|
-
const triggerTypesPath =
|
|
7678
|
+
const triggerTypesPath = path21.join(project.path, ".adk", "trigger-types.d.ts");
|
|
7235
7679
|
await createFile(triggerTypesPath, await formatCode(content));
|
|
7236
7680
|
}
|
|
7237
7681
|
|
|
7238
7682
|
// src/generators/state-types.ts
|
|
7239
7683
|
init_utils();
|
|
7240
7684
|
init_fs();
|
|
7241
|
-
import
|
|
7685
|
+
import path22 from "path";
|
|
7242
7686
|
async function generateStateTypes(project) {
|
|
7243
7687
|
let botStateType = "{}";
|
|
7244
7688
|
let userStateType = "{}";
|
|
7245
7689
|
try {
|
|
7246
|
-
const configPath =
|
|
7690
|
+
const configPath = path22.join(project.path, "agent.config.ts");
|
|
7247
7691
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
7248
7692
|
const config = configModule.default;
|
|
7249
7693
|
if (config?.bot?.state) {
|
|
@@ -7274,14 +7718,14 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
7274
7718
|
export type UserState = ${userStateType};
|
|
7275
7719
|
}
|
|
7276
7720
|
`;
|
|
7277
|
-
const stateTypesPath =
|
|
7721
|
+
const stateTypesPath = path22.join(project.path, ".adk", "state-types.d.ts");
|
|
7278
7722
|
await createFile(stateTypesPath, await formatCode(content));
|
|
7279
7723
|
}
|
|
7280
7724
|
|
|
7281
7725
|
// src/generators/tag-types.ts
|
|
7282
7726
|
init_utils();
|
|
7283
7727
|
init_fs();
|
|
7284
|
-
import
|
|
7728
|
+
import path23 from "path";
|
|
7285
7729
|
import { BUILT_IN_TAGS } from "@botpress/runtime/definition";
|
|
7286
7730
|
function generateTagTypeString(builtInTags, configTags) {
|
|
7287
7731
|
const builtInTagStrings = Object.entries(builtInTags).map(([key, tag]) => {
|
|
@@ -7320,7 +7764,7 @@ async function generateTagTypes(project) {
|
|
|
7320
7764
|
let messageTagsType = "Record<string, string | undefined>";
|
|
7321
7765
|
let workflowTagsType = "Record<string, string | undefined>";
|
|
7322
7766
|
try {
|
|
7323
|
-
const configPath =
|
|
7767
|
+
const configPath = path23.join(project.path, "agent.config.ts");
|
|
7324
7768
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
7325
7769
|
const config = configModule.default;
|
|
7326
7770
|
botTagsType = generateTagTypeString(BUILT_IN_TAGS.bot, config?.bot?.tags);
|
|
@@ -7366,18 +7810,18 @@ declare module "@botpress/runtime/_types/tags" {
|
|
|
7366
7810
|
export type WorkflowTags = ${workflowTagsType};
|
|
7367
7811
|
}
|
|
7368
7812
|
`;
|
|
7369
|
-
const tagTypesPath =
|
|
7813
|
+
const tagTypesPath = path23.join(project.path, ".adk", "tag-types.d.ts");
|
|
7370
7814
|
await createFile(tagTypesPath, await formatCode(content));
|
|
7371
7815
|
}
|
|
7372
7816
|
|
|
7373
7817
|
// src/generators/configuration-types.ts
|
|
7374
7818
|
init_utils();
|
|
7375
7819
|
init_fs();
|
|
7376
|
-
import
|
|
7820
|
+
import path24 from "path";
|
|
7377
7821
|
async function generateConfigurationTypes(project) {
|
|
7378
7822
|
let configurationType = "{}";
|
|
7379
7823
|
try {
|
|
7380
|
-
const configPath =
|
|
7824
|
+
const configPath = path24.join(project.path, "agent.config.ts");
|
|
7381
7825
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
7382
7826
|
const config = configModule.default;
|
|
7383
7827
|
if (config?.configuration?.schema) {
|
|
@@ -7401,26 +7845,26 @@ declare module "@botpress/runtime/_types/configuration" {
|
|
|
7401
7845
|
export type Configuration = ${configurationType};
|
|
7402
7846
|
}
|
|
7403
7847
|
`;
|
|
7404
|
-
const configTypesPath =
|
|
7848
|
+
const configTypesPath = path24.join(project.path, ".adk", "configuration-types.d.ts");
|
|
7405
7849
|
await createFile(configTypesPath, await formatCode(content));
|
|
7406
7850
|
}
|
|
7407
7851
|
|
|
7408
7852
|
// src/generators/workflow-types.ts
|
|
7409
7853
|
init_utils();
|
|
7410
7854
|
init_fs();
|
|
7411
|
-
import * as
|
|
7412
|
-
import { BuiltInWorkflows as
|
|
7413
|
-
function
|
|
7414
|
-
return !!Object.values(
|
|
7855
|
+
import * as path25 from "path";
|
|
7856
|
+
import { BuiltInWorkflows as BuiltInWorkflows3 } from "@botpress/runtime/internal";
|
|
7857
|
+
function isBuiltinWorkflow2(name) {
|
|
7858
|
+
return !!Object.values(BuiltInWorkflows3).find((x) => x.name === name);
|
|
7415
7859
|
}
|
|
7416
7860
|
async function generateWorkflowTypes(project) {
|
|
7417
7861
|
const workflows = [];
|
|
7418
7862
|
for (const workflowRef of project.workflows) {
|
|
7419
7863
|
try {
|
|
7420
|
-
if (
|
|
7864
|
+
if (isBuiltinWorkflow2(workflowRef.definition.name)) {
|
|
7421
7865
|
continue;
|
|
7422
7866
|
}
|
|
7423
|
-
const workflowPath =
|
|
7867
|
+
const workflowPath = path25.join(project.path, workflowRef.path);
|
|
7424
7868
|
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
7425
7869
|
const workflowInstance = workflowModule[workflowRef.export] || workflowModule.default;
|
|
7426
7870
|
if (!workflowInstance) {
|
|
@@ -7467,14 +7911,14 @@ declare module "@botpress/runtime/_types/workflows" {
|
|
|
7467
7911
|
${typeDefinitions || " // No workflows defined yet"}
|
|
7468
7912
|
};
|
|
7469
7913
|
}`;
|
|
7470
|
-
const workflowTypesPath =
|
|
7914
|
+
const workflowTypesPath = path25.join(project.path, ".adk", "workflow-types.d.ts");
|
|
7471
7915
|
await createFile(workflowTypesPath, await formatCode(content));
|
|
7472
7916
|
}
|
|
7473
7917
|
|
|
7474
7918
|
// src/generators/conversation-types.ts
|
|
7475
7919
|
init_utils();
|
|
7476
7920
|
init_fs();
|
|
7477
|
-
import
|
|
7921
|
+
import path26 from "path";
|
|
7478
7922
|
function hasConversationIdProperty(schema) {
|
|
7479
7923
|
if (!schema || typeof schema !== "object") {
|
|
7480
7924
|
return false;
|
|
@@ -7497,7 +7941,7 @@ async function generateConversationTypes(project) {
|
|
|
7497
7941
|
const conversationTypes = {};
|
|
7498
7942
|
for (const conversationRef of project.conversations) {
|
|
7499
7943
|
try {
|
|
7500
|
-
const conversationPath =
|
|
7944
|
+
const conversationPath = path26.join(project.path, conversationRef.path);
|
|
7501
7945
|
const conversationModule = await import(`${conversationPath}?t=${Date.now()}`);
|
|
7502
7946
|
const conversationInstance = conversationModule[conversationRef.export] || conversationModule.default;
|
|
7503
7947
|
if (!conversationInstance) {
|
|
@@ -7583,14 +8027,14 @@ ${routableEventsDefinitions || " // No routable events found"}
|
|
|
7583
8027
|
};
|
|
7584
8028
|
}
|
|
7585
8029
|
`;
|
|
7586
|
-
const conversationTypesPath =
|
|
8030
|
+
const conversationTypesPath = path26.join(project.path, ".adk", "conversation-types.d.ts");
|
|
7587
8031
|
await createFile(conversationTypesPath, await formatCode(content));
|
|
7588
8032
|
}
|
|
7589
8033
|
|
|
7590
8034
|
// src/generators/event-types.ts
|
|
7591
8035
|
init_utils();
|
|
7592
8036
|
init_fs();
|
|
7593
|
-
import
|
|
8037
|
+
import path27 from "path";
|
|
7594
8038
|
async function generateEventTypes(project) {
|
|
7595
8039
|
const defaultEvents = ["register: {}"];
|
|
7596
8040
|
const integrationEvents = [];
|
|
@@ -7642,7 +8086,7 @@ ${allEvents.map((e) => ` ${e}`).join(`
|
|
|
7642
8086
|
export type EventPayload<T extends EventName> = Events[T];
|
|
7643
8087
|
}
|
|
7644
8088
|
`;
|
|
7645
|
-
const eventTypesPath =
|
|
8089
|
+
const eventTypesPath = path27.join(project.path, ".adk", "event-types.d.ts");
|
|
7646
8090
|
await createFile(eventTypesPath, await formatCode(content));
|
|
7647
8091
|
}
|
|
7648
8092
|
|
|
@@ -7652,7 +8096,7 @@ init_fs();
|
|
|
7652
8096
|
// src/utils/link-sdk.ts
|
|
7653
8097
|
import { existsSync as existsSync3, realpathSync } from "fs";
|
|
7654
8098
|
import fs12 from "fs/promises";
|
|
7655
|
-
import
|
|
8099
|
+
import path28 from "path";
|
|
7656
8100
|
function findPackage(name, startDir) {
|
|
7657
8101
|
let current;
|
|
7658
8102
|
try {
|
|
@@ -7660,17 +8104,17 @@ function findPackage(name, startDir) {
|
|
|
7660
8104
|
} catch {
|
|
7661
8105
|
current = startDir;
|
|
7662
8106
|
}
|
|
7663
|
-
while (current !==
|
|
7664
|
-
const pkgPath =
|
|
8107
|
+
while (current !== path28.dirname(current)) {
|
|
8108
|
+
const pkgPath = path28.join(current, "node_modules", name);
|
|
7665
8109
|
if (existsSync3(pkgPath)) {
|
|
7666
8110
|
return pkgPath;
|
|
7667
8111
|
}
|
|
7668
|
-
current =
|
|
8112
|
+
current = path28.dirname(current);
|
|
7669
8113
|
}
|
|
7670
8114
|
return null;
|
|
7671
8115
|
}
|
|
7672
8116
|
async function linkSdk(agentDir, botDir) {
|
|
7673
|
-
const targetSdkPath =
|
|
8117
|
+
const targetSdkPath = path28.join(botDir, "node_modules", "@botpress", "sdk");
|
|
7674
8118
|
if (existsSync3(targetSdkPath)) {
|
|
7675
8119
|
return;
|
|
7676
8120
|
}
|
|
@@ -7684,17 +8128,17 @@ async function linkSdk(agentDir, botDir) {
|
|
|
7684
8128
|
console.warn(`Warning: Could not find @botpress/sdk from @botpress/runtime location (${runtimePath})`);
|
|
7685
8129
|
return;
|
|
7686
8130
|
}
|
|
7687
|
-
const targetBotpressDir =
|
|
8131
|
+
const targetBotpressDir = path28.join(botDir, "node_modules", "@botpress");
|
|
7688
8132
|
await fs12.mkdir(targetBotpressDir, { recursive: true });
|
|
7689
8133
|
const symlinkType = process.platform === "win32" ? "junction" : undefined;
|
|
7690
8134
|
await fs12.symlink(sdkPath, targetSdkPath, symlinkType);
|
|
7691
8135
|
}
|
|
7692
8136
|
|
|
7693
8137
|
// src/bot-generator/dev-id-manager.ts
|
|
7694
|
-
import
|
|
8138
|
+
import path29 from "path";
|
|
7695
8139
|
import fs13 from "fs/promises";
|
|
7696
8140
|
import { existsSync as existsSync4 } from "fs";
|
|
7697
|
-
import { Client as
|
|
8141
|
+
import { Client as Client13 } from "@botpress/client";
|
|
7698
8142
|
class DevIdManager {
|
|
7699
8143
|
projectPath;
|
|
7700
8144
|
botProjectPath;
|
|
@@ -7703,7 +8147,7 @@ class DevIdManager {
|
|
|
7703
8147
|
constructor(projectPath, botProjectPath) {
|
|
7704
8148
|
this.projectPath = projectPath;
|
|
7705
8149
|
this.botProjectPath = botProjectPath;
|
|
7706
|
-
this.projectCachePath =
|
|
8150
|
+
this.projectCachePath = path29.join(botProjectPath, ".botpress", "project.cache.json");
|
|
7707
8151
|
}
|
|
7708
8152
|
async getClient() {
|
|
7709
8153
|
if (!this.client) {
|
|
@@ -7713,7 +8157,7 @@ class DevIdManager {
|
|
|
7713
8157
|
if (!workspaceId) {
|
|
7714
8158
|
throw new Error('No workspace ID found in agent.json or current profile. Please login again with "adk login"');
|
|
7715
8159
|
}
|
|
7716
|
-
this.client = new
|
|
8160
|
+
this.client = new Client13({
|
|
7717
8161
|
token: credentials.token,
|
|
7718
8162
|
apiUrl: credentials.apiUrl,
|
|
7719
8163
|
workspaceId,
|
|
@@ -7740,7 +8184,7 @@ class DevIdManager {
|
|
|
7740
8184
|
}
|
|
7741
8185
|
async saveProjectCache(cache2) {
|
|
7742
8186
|
try {
|
|
7743
|
-
await fs13.mkdir(
|
|
8187
|
+
await fs13.mkdir(path29.dirname(this.projectCachePath), { recursive: true });
|
|
7744
8188
|
await fs13.writeFile(this.projectCachePath, JSON.stringify(cache2, null, 2));
|
|
7745
8189
|
} catch (error) {
|
|
7746
8190
|
console.error("Error saving project.cache.json:", error);
|
|
@@ -7789,7 +8233,7 @@ class DevIdManager {
|
|
|
7789
8233
|
}
|
|
7790
8234
|
|
|
7791
8235
|
// src/bot-generator/integration-sync.ts
|
|
7792
|
-
import
|
|
8236
|
+
import path30 from "path";
|
|
7793
8237
|
import fs14 from "fs/promises";
|
|
7794
8238
|
import { existsSync as existsSync5 } from "fs";
|
|
7795
8239
|
class IntegrationSync {
|
|
@@ -7799,7 +8243,7 @@ class IntegrationSync {
|
|
|
7799
8243
|
constructor(projectPath, botProjectPath) {
|
|
7800
8244
|
this.projectPath = projectPath;
|
|
7801
8245
|
this.botProjectPath = botProjectPath;
|
|
7802
|
-
this.bpModulesPath =
|
|
8246
|
+
this.bpModulesPath = path30.join(botProjectPath, "bp_modules");
|
|
7803
8247
|
}
|
|
7804
8248
|
async parseIntegrations() {
|
|
7805
8249
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -7830,12 +8274,12 @@ class IntegrationSync {
|
|
|
7830
8274
|
return integrations;
|
|
7831
8275
|
}
|
|
7832
8276
|
async isIntegrationSynced(integration) {
|
|
7833
|
-
const targetFolder =
|
|
8277
|
+
const targetFolder = path30.join(this.bpModulesPath, `integration_${integration.alias}`);
|
|
7834
8278
|
if (!existsSync5(targetFolder)) {
|
|
7835
8279
|
return false;
|
|
7836
8280
|
}
|
|
7837
8281
|
try {
|
|
7838
|
-
const indexPath =
|
|
8282
|
+
const indexPath = path30.join(targetFolder, "index.ts");
|
|
7839
8283
|
if (!existsSync5(indexPath)) {
|
|
7840
8284
|
return false;
|
|
7841
8285
|
}
|
|
@@ -7867,8 +8311,8 @@ class IntegrationSync {
|
|
|
7867
8311
|
await command.output();
|
|
7868
8312
|
}
|
|
7869
8313
|
async renameIntegrationFolder(integration) {
|
|
7870
|
-
const sourceFolder =
|
|
7871
|
-
const targetFolder =
|
|
8314
|
+
const sourceFolder = path30.join(this.bpModulesPath, integration.name.replace("/", "-"));
|
|
8315
|
+
const targetFolder = path30.join(this.bpModulesPath, `integration_${integration.alias}`);
|
|
7872
8316
|
if (!existsSync5(sourceFolder)) {
|
|
7873
8317
|
throw new Error(`Integration folder not found: ${sourceFolder}`);
|
|
7874
8318
|
}
|
|
@@ -7878,7 +8322,7 @@ class IntegrationSync {
|
|
|
7878
8322
|
await fs14.rename(sourceFolder, targetFolder);
|
|
7879
8323
|
}
|
|
7880
8324
|
async removeIntegrationFolder(alias) {
|
|
7881
|
-
const targetFolder =
|
|
8325
|
+
const targetFolder = path30.join(this.bpModulesPath, `integration_${alias}`);
|
|
7882
8326
|
if (existsSync5(targetFolder)) {
|
|
7883
8327
|
await fs14.rm(targetFolder, { recursive: true, force: true });
|
|
7884
8328
|
}
|
|
@@ -7912,7 +8356,7 @@ class IntegrationSync {
|
|
|
7912
8356
|
}
|
|
7913
8357
|
|
|
7914
8358
|
// src/bot-generator/interface-sync.ts
|
|
7915
|
-
import
|
|
8359
|
+
import path31 from "path";
|
|
7916
8360
|
import fs15 from "fs/promises";
|
|
7917
8361
|
import { existsSync as existsSync6 } from "fs";
|
|
7918
8362
|
init_constants();
|
|
@@ -7923,7 +8367,7 @@ class InterfaceSync {
|
|
|
7923
8367
|
constructor(projectPath, botProjectPath) {
|
|
7924
8368
|
this.projectPath = projectPath;
|
|
7925
8369
|
this.botProjectPath = botProjectPath;
|
|
7926
|
-
this.bpModulesPath =
|
|
8370
|
+
this.bpModulesPath = path31.join(botProjectPath, "bp_modules");
|
|
7927
8371
|
}
|
|
7928
8372
|
async parseInterfaces() {
|
|
7929
8373
|
const interfaces = [];
|
|
@@ -7941,12 +8385,12 @@ class InterfaceSync {
|
|
|
7941
8385
|
return interfaces;
|
|
7942
8386
|
}
|
|
7943
8387
|
async isInterfaceSynced(interfaceInfo) {
|
|
7944
|
-
const targetFolder =
|
|
8388
|
+
const targetFolder = path31.join(this.bpModulesPath, `interface_${pascalCase(interfaceInfo.alias)}`);
|
|
7945
8389
|
if (!existsSync6(targetFolder)) {
|
|
7946
8390
|
return false;
|
|
7947
8391
|
}
|
|
7948
8392
|
try {
|
|
7949
|
-
const indexPath =
|
|
8393
|
+
const indexPath = path31.join(targetFolder, "index.ts");
|
|
7950
8394
|
if (!existsSync6(indexPath)) {
|
|
7951
8395
|
return false;
|
|
7952
8396
|
}
|
|
@@ -7992,8 +8436,8 @@ class InterfaceSync {
|
|
|
7992
8436
|
});
|
|
7993
8437
|
}
|
|
7994
8438
|
async renameInterfaceFolder(interfaceInfo) {
|
|
7995
|
-
const sourceFolder =
|
|
7996
|
-
const targetFolder =
|
|
8439
|
+
const sourceFolder = path31.join(this.bpModulesPath, interfaceInfo.name);
|
|
8440
|
+
const targetFolder = path31.join(this.bpModulesPath, `interface_${pascalCase(interfaceInfo.alias)}`);
|
|
7997
8441
|
if (!existsSync6(sourceFolder)) {
|
|
7998
8442
|
throw new Error(`Interface folder not found: ${sourceFolder}`);
|
|
7999
8443
|
}
|
|
@@ -8003,7 +8447,7 @@ class InterfaceSync {
|
|
|
8003
8447
|
await fs15.rename(sourceFolder, targetFolder);
|
|
8004
8448
|
}
|
|
8005
8449
|
async removeInterfaceFolder(alias) {
|
|
8006
|
-
const targetFolder =
|
|
8450
|
+
const targetFolder = path31.join(this.bpModulesPath, `interface_${pascalCase(alias)}`);
|
|
8007
8451
|
if (existsSync6(targetFolder)) {
|
|
8008
8452
|
await fs15.rm(targetFolder, { recursive: true, force: true });
|
|
8009
8453
|
}
|
|
@@ -8040,24 +8484,29 @@ class InterfaceSync {
|
|
|
8040
8484
|
init_utils();
|
|
8041
8485
|
import { transforms as transforms3 } from "@botpress/sdk";
|
|
8042
8486
|
init_constants();
|
|
8043
|
-
import { BuiltInActions as BuiltInActions2, BuiltInWorkflows as
|
|
8487
|
+
import { BuiltInActions as BuiltInActions2, BuiltInWorkflows as BuiltInWorkflows4, Primitives as Primitives3 } from "@botpress/runtime/internal";
|
|
8044
8488
|
import { BUILT_IN_TAGS as BUILT_IN_TAGS2 } from "@botpress/runtime/definition";
|
|
8045
|
-
|
|
8046
|
-
|
|
8489
|
+
var plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
8490
|
+
function isBuiltinWorkflow3(name) {
|
|
8491
|
+
return !!Object.values(BuiltInWorkflows4).find((x) => x.name === name);
|
|
8047
8492
|
}
|
|
8048
8493
|
function isBuiltinAction(name) {
|
|
8049
8494
|
return !!Object.values(BuiltInActions2).find((x) => x.name === name);
|
|
8050
8495
|
}
|
|
8051
8496
|
function getImportPath(from, to) {
|
|
8052
|
-
return
|
|
8497
|
+
return path34.relative(path34.dirname(from), to).replace(/\.ts$/, "").replace(/\\/g, "/");
|
|
8053
8498
|
}
|
|
8054
8499
|
|
|
8055
8500
|
class BotGenerator {
|
|
8056
8501
|
projectPath;
|
|
8057
8502
|
outputPath;
|
|
8503
|
+
adkCommand;
|
|
8504
|
+
callbacks;
|
|
8058
8505
|
constructor(options) {
|
|
8059
|
-
this.projectPath =
|
|
8060
|
-
this.outputPath =
|
|
8506
|
+
this.projectPath = path34.resolve(options.projectPath);
|
|
8507
|
+
this.outputPath = path34.resolve(options.outputPath || path34.join(this.projectPath, ".adk"));
|
|
8508
|
+
this.adkCommand = options.adkCommand;
|
|
8509
|
+
this.callbacks = options.callbacks;
|
|
8061
8510
|
}
|
|
8062
8511
|
async listFilesRecursive(rootDir) {
|
|
8063
8512
|
try {
|
|
@@ -8067,8 +8516,8 @@ class BotGenerator {
|
|
|
8067
8516
|
const walk = async (dir, relativeBase) => {
|
|
8068
8517
|
const entries = await fs16.readdir(dir, { withFileTypes: true });
|
|
8069
8518
|
for (const entry of entries) {
|
|
8070
|
-
const abs =
|
|
8071
|
-
const rel =
|
|
8519
|
+
const abs = path34.join(dir, entry.name);
|
|
8520
|
+
const rel = path34.join(relativeBase, entry.name);
|
|
8072
8521
|
if (entry.isDirectory()) {
|
|
8073
8522
|
await walk(abs, rel);
|
|
8074
8523
|
} else {
|
|
@@ -8089,7 +8538,7 @@ class BotGenerator {
|
|
|
8089
8538
|
const entries = await fs16.readdir(dir, { withFileTypes: true });
|
|
8090
8539
|
for (const entry of entries) {
|
|
8091
8540
|
if (entry.isDirectory()) {
|
|
8092
|
-
const subdir =
|
|
8541
|
+
const subdir = path34.join(dir, entry.name);
|
|
8093
8542
|
await removeIfEmpty(subdir);
|
|
8094
8543
|
}
|
|
8095
8544
|
}
|
|
@@ -8121,6 +8570,7 @@ class BotGenerator {
|
|
|
8121
8570
|
await this.generateEventTypes();
|
|
8122
8571
|
await this.generateIntegrationActionTypes();
|
|
8123
8572
|
await this.generateRuntimeTypes();
|
|
8573
|
+
await this.generateClientWrapper();
|
|
8124
8574
|
await this.generateBotIndex();
|
|
8125
8575
|
await this.generatePackageJson(project);
|
|
8126
8576
|
await this.generateTsConfig();
|
|
@@ -8133,18 +8583,18 @@ class BotGenerator {
|
|
|
8133
8583
|
workspaceId: project.agentInfo?.workspaceId
|
|
8134
8584
|
});
|
|
8135
8585
|
const integrations = await manager3.loadIntegrations(project.dependencies || {});
|
|
8136
|
-
const integrationsDir =
|
|
8586
|
+
const integrationsDir = path34.join(this.projectPath, ".adk", "integrations");
|
|
8137
8587
|
const existingIntegrationFiles = await this.listFilesRecursive(integrationsDir);
|
|
8138
8588
|
let aliases = new Set;
|
|
8139
8589
|
let files = new Set;
|
|
8140
8590
|
for (const integration of integrations.integrations) {
|
|
8141
8591
|
if (integration.definition) {
|
|
8142
8592
|
const types6 = await generateIntegrationTypes(integration);
|
|
8143
|
-
const importPath = `./${
|
|
8593
|
+
const importPath = `./${path34.join("integrations", types6.names.paths.index).replace(/\\/g, "/")}`;
|
|
8144
8594
|
aliases.add(`"${integration.alias}": import("${importPath}").${types6.names.typings.index}`);
|
|
8145
8595
|
for (const [filePath, content] of Object.entries(types6.files)) {
|
|
8146
|
-
const fullPath =
|
|
8147
|
-
const dir =
|
|
8596
|
+
const fullPath = path34.join(this.projectPath, ".adk", "integrations", filePath);
|
|
8597
|
+
const dir = path34.dirname(fullPath);
|
|
8148
8598
|
await fs16.mkdir(dir, { recursive: true });
|
|
8149
8599
|
await createFile(fullPath, content);
|
|
8150
8600
|
files.add(filePath);
|
|
@@ -8165,11 +8615,11 @@ class BotGenerator {
|
|
|
8165
8615
|
};
|
|
8166
8616
|
}
|
|
8167
8617
|
`;
|
|
8168
|
-
await createFile(
|
|
8618
|
+
await createFile(path34.join(this.projectPath, ".adk", "integrations-types.d.ts"), await formatCode(types5));
|
|
8169
8619
|
const staleIntegrationFiles = existingIntegrationFiles.filter((f) => !files.has(f));
|
|
8170
8620
|
if (staleIntegrationFiles.length > 0) {
|
|
8171
8621
|
for (const rel of staleIntegrationFiles) {
|
|
8172
|
-
const abs =
|
|
8622
|
+
const abs = path34.join(integrationsDir, rel);
|
|
8173
8623
|
try {
|
|
8174
8624
|
await fs16.rm(abs, { force: true });
|
|
8175
8625
|
} catch {}
|
|
@@ -8219,6 +8669,10 @@ class BotGenerator {
|
|
|
8219
8669
|
const { generateIntegrationActionTypes: generateIntegrationActionTypes2 } = await Promise.resolve().then(() => (init_integration_action_types(), exports_integration_action_types));
|
|
8220
8670
|
await generateIntegrationActionTypes2(project);
|
|
8221
8671
|
}
|
|
8672
|
+
async generateClientWrapper() {
|
|
8673
|
+
const project = await AgentProject.load(this.projectPath);
|
|
8674
|
+
await generateClientWrapper(project);
|
|
8675
|
+
}
|
|
8222
8676
|
async generateRuntimeTypes() {
|
|
8223
8677
|
const project = await AgentProject.load(this.projectPath);
|
|
8224
8678
|
const manager3 = new IntegrationManager({
|
|
@@ -8238,7 +8692,7 @@ class BotGenerator {
|
|
|
8238
8692
|
let botStateType = "{}";
|
|
8239
8693
|
let userStateType = "{}";
|
|
8240
8694
|
try {
|
|
8241
|
-
const configPath =
|
|
8695
|
+
const configPath = path34.join(project.path, "agent.config.ts");
|
|
8242
8696
|
const configModule = await import(`${configPath}?t=${Date.now()}`);
|
|
8243
8697
|
const config = configModule.default;
|
|
8244
8698
|
if (config?.bot?.state) {
|
|
@@ -8274,7 +8728,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
8274
8728
|
export type UserState = ${userStateType};
|
|
8275
8729
|
}
|
|
8276
8730
|
`;
|
|
8277
|
-
await createFile(
|
|
8731
|
+
await createFile(path34.join(this.projectPath, ".adk", "runtime.d.ts"), await formatCode(types5));
|
|
8278
8732
|
}
|
|
8279
8733
|
async generateInterfacesTypes() {
|
|
8280
8734
|
const project = await AgentProject.load(this.projectPath);
|
|
@@ -8282,7 +8736,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
8282
8736
|
workspaceId: project.agentInfo?.workspaceId
|
|
8283
8737
|
});
|
|
8284
8738
|
const manager3 = new InterfaceManager;
|
|
8285
|
-
const interfacesDir =
|
|
8739
|
+
const interfacesDir = path34.join(this.projectPath, ".adk", "interfaces");
|
|
8286
8740
|
const existingInterfaceFiles = await this.listFilesRecursive(interfacesDir);
|
|
8287
8741
|
const interfaces = await manager3.loadInterfaces(project.dependencies || {}).then((result) => result.interfaces.filter((int) => int.definition).map((x) => x.definition));
|
|
8288
8742
|
const integrationsWithAlias = await integrationManager.loadIntegrations(project.dependencies || {}).then((result) => result.integrations.filter((int) => int.enabled && int.definition).map((x) => ({ alias: x.alias, definition: x.definition })));
|
|
@@ -8291,11 +8745,11 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
8291
8745
|
let files = new Set;
|
|
8292
8746
|
for (const int of interfaces) {
|
|
8293
8747
|
const types6 = await generateInterfaceTypes(int, integrationsWithAlias);
|
|
8294
|
-
imports.add(`import { ${types6.names.typings.index} } from "./${
|
|
8748
|
+
imports.add(`import { ${types6.names.typings.index} } from "./${path34.join("interfaces", types6.names.paths.index).replace(/\\/g, "/")}";`);
|
|
8295
8749
|
aliases.add(`"${types6.names.name}": ${types6.names.typings.index}`);
|
|
8296
8750
|
for (const [filePath, content] of Object.entries(types6.files)) {
|
|
8297
|
-
const fullPath =
|
|
8298
|
-
const dir =
|
|
8751
|
+
const fullPath = path34.join(this.projectPath, ".adk", "interfaces", filePath);
|
|
8752
|
+
const dir = path34.dirname(fullPath);
|
|
8299
8753
|
await fs16.mkdir(dir, { recursive: true });
|
|
8300
8754
|
await createFile(fullPath, content);
|
|
8301
8755
|
files.add(filePath);
|
|
@@ -8332,12 +8786,12 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
8332
8786
|
`)}
|
|
8333
8787
|
};
|
|
8334
8788
|
`;
|
|
8335
|
-
await createFile(
|
|
8336
|
-
await createFile(
|
|
8789
|
+
await createFile(path34.join(this.projectPath, ".adk", "interfaces.d.ts"), await formatCode(types5));
|
|
8790
|
+
await createFile(path34.join(this.projectPath, ".adk", "interfaces.ts"), await formatCode(consts));
|
|
8337
8791
|
const staleInterfaceFiles = existingInterfaceFiles.filter((f) => !files.has(f));
|
|
8338
8792
|
if (staleInterfaceFiles.length > 0) {
|
|
8339
8793
|
for (const rel of staleInterfaceFiles) {
|
|
8340
|
-
const abs =
|
|
8794
|
+
const abs = path34.join(interfacesDir, rel);
|
|
8341
8795
|
try {
|
|
8342
8796
|
await fs16.rm(abs, { force: true });
|
|
8343
8797
|
} catch {}
|
|
@@ -8370,7 +8824,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
8370
8824
|
`) : ""}
|
|
8371
8825
|
} as Record<string, IntegrationPackage>;
|
|
8372
8826
|
`;
|
|
8373
|
-
await createFile(
|
|
8827
|
+
await createFile(path34.join(this.outputPath, "src", "integrations.ts"), content);
|
|
8374
8828
|
}
|
|
8375
8829
|
async generateInterfacesDefinition() {
|
|
8376
8830
|
const interfaces = BUILTIN_INTERFACES;
|
|
@@ -8393,19 +8847,58 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
8393
8847
|
`) : ""}
|
|
8394
8848
|
} as Record<string, InterfacePackage>;
|
|
8395
8849
|
`;
|
|
8396
|
-
await createFile(
|
|
8850
|
+
await createFile(path34.join(this.outputPath, "src", "interfaces.ts"), await formatCode(content));
|
|
8851
|
+
}
|
|
8852
|
+
reportServerConfigSync(serverConfigResult, integrations) {
|
|
8853
|
+
if (!this.callbacks) {
|
|
8854
|
+
return;
|
|
8855
|
+
}
|
|
8856
|
+
if (serverConfigResult.error) {
|
|
8857
|
+
this.callbacks.onError?.(`Failed to fetch remote configs: ${serverConfigResult.error}. Server-only config values may be overwritten.`);
|
|
8858
|
+
return;
|
|
8859
|
+
}
|
|
8860
|
+
if (!serverConfigResult.fetched) {
|
|
8861
|
+
return;
|
|
8862
|
+
}
|
|
8863
|
+
const configCount = Object.keys(serverConfigResult.configs).length;
|
|
8864
|
+
if (configCount === 0) {
|
|
8865
|
+
return;
|
|
8866
|
+
}
|
|
8867
|
+
this.callbacks.onSuccess?.(`Preserved remote configs for ${plural(configCount, "integration")}`);
|
|
8868
|
+
for (const { alias, config: localConfig } of integrations) {
|
|
8869
|
+
const serverConfig = serverConfigResult.configs[alias];
|
|
8870
|
+
if (!serverConfig || Object.keys(serverConfig).length === 0) {
|
|
8871
|
+
continue;
|
|
8872
|
+
}
|
|
8873
|
+
const preserved = Object.keys(serverConfig).filter((key) => !localConfig || !(key in localConfig));
|
|
8874
|
+
if (preserved.length > 0) {
|
|
8875
|
+
this.callbacks.onProgress?.(` ${alias}: preserved ${plural(preserved.length, "remote field")} (${preserved.join(", ")})`);
|
|
8876
|
+
}
|
|
8877
|
+
if (localConfig) {
|
|
8878
|
+
const overridden = Object.keys(localConfig).filter((key) => (key in serverConfig) && localConfig[key] !== serverConfig[key]);
|
|
8879
|
+
if (overridden.length > 0) {
|
|
8880
|
+
this.callbacks.onProgress?.(` ${alias}: local overrides ${plural(overridden.length, "field")} (${overridden.join(", ")})`);
|
|
8881
|
+
}
|
|
8882
|
+
}
|
|
8883
|
+
}
|
|
8397
8884
|
}
|
|
8398
8885
|
async generateBotDefinition() {
|
|
8399
8886
|
const project = await AgentProject.load(this.projectPath);
|
|
8400
8887
|
const integrations = project.integrations;
|
|
8888
|
+
const enabledIntegrations = integrations.filter((i) => i.enabled);
|
|
8889
|
+
const isDeployOrBuild = this.adkCommand === "adk-deploy" || this.adkCommand === "adk-build";
|
|
8890
|
+
const configTargetBotId = isDeployOrBuild ? project.agentInfo?.botId : undefined;
|
|
8891
|
+
const serverConfigResult = await fetchServerIntegrationConfigs(project, configTargetBotId);
|
|
8892
|
+
this.reportServerConfigSync(serverConfigResult, enabledIntegrations);
|
|
8401
8893
|
const imports = [];
|
|
8402
8894
|
const addIntegrations = [];
|
|
8403
|
-
for (const integration of
|
|
8895
|
+
for (const integration of enabledIntegrations) {
|
|
8404
8896
|
const { alias, configurationType, config } = integration;
|
|
8405
8897
|
const importName = `integration_${getIntegrationAlias(alias)}`;
|
|
8406
8898
|
imports.push(`import ${importName} from "./bp_modules/${importName}";`);
|
|
8407
8899
|
const configType = configurationType && configurationType !== "default" ? `, configurationType: "${configurationType}"` : "";
|
|
8408
|
-
const
|
|
8900
|
+
const mergedConfig = mergeIntegrationConfig(serverConfigResult.configs[alias], config);
|
|
8901
|
+
const configData = Object.keys(mergedConfig).length > 0 ? `, configuration: ${JSON.stringify(mergedConfig)}` : "";
|
|
8409
8902
|
addIntegrations.push(`bot.addIntegration(${importName}, { alias: "${alias}", enabled: true${configType}${configData} });`);
|
|
8410
8903
|
}
|
|
8411
8904
|
const botTags = {};
|
|
@@ -8445,10 +8938,10 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
8445
8938
|
const workflowInstances = [];
|
|
8446
8939
|
for (const workflow of project.workflows) {
|
|
8447
8940
|
try {
|
|
8448
|
-
if (
|
|
8941
|
+
if (isBuiltinWorkflow3(workflow.definition.name)) {
|
|
8449
8942
|
continue;
|
|
8450
8943
|
}
|
|
8451
|
-
const workflowPath =
|
|
8944
|
+
const workflowPath = path34.join(project.path, workflow.path);
|
|
8452
8945
|
const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
|
|
8453
8946
|
const workflowInstance = workflowModule.default || workflowModule[workflow.export];
|
|
8454
8947
|
if (workflowInstance) {
|
|
@@ -8458,7 +8951,7 @@ declare module "@botpress/runtime/_types/state" {
|
|
|
8458
8951
|
console.error(`Failed to load workflow ${workflow.definition.name}:`, error);
|
|
8459
8952
|
}
|
|
8460
8953
|
}
|
|
8461
|
-
for (const workflow of Object.values(
|
|
8954
|
+
for (const workflow of Object.values(BuiltInWorkflows4)) {
|
|
8462
8955
|
workflowInstances.push(workflow);
|
|
8463
8956
|
}
|
|
8464
8957
|
for (const workflow of workflowInstances) {
|
|
@@ -8703,7 +9196,7 @@ configuration: {
|
|
|
8703
9196
|
const fullContent = content + integrationsSection + `
|
|
8704
9197
|
|
|
8705
9198
|
export default bot;`;
|
|
8706
|
-
await createFile(
|
|
9199
|
+
await createFile(path34.join(this.outputPath, "bot.definition.ts"), await formatCode(fullContent));
|
|
8707
9200
|
}
|
|
8708
9201
|
async generateBotIndex() {
|
|
8709
9202
|
const content = dedent`
|
|
@@ -8742,7 +9235,7 @@ export default bot;`;
|
|
|
8742
9235
|
|
|
8743
9236
|
export default bot
|
|
8744
9237
|
`;
|
|
8745
|
-
await createFile(
|
|
9238
|
+
await createFile(path34.join(this.outputPath, "src", "index.ts"), await formatCode(content));
|
|
8746
9239
|
}
|
|
8747
9240
|
async generatePackageJson(project) {
|
|
8748
9241
|
const packageJson = {
|
|
@@ -8756,7 +9249,7 @@ export default bot;`;
|
|
|
8756
9249
|
typescript: "^5.9.3"
|
|
8757
9250
|
}
|
|
8758
9251
|
};
|
|
8759
|
-
await createFile(
|
|
9252
|
+
await createFile(path34.join(this.outputPath, "package.json"), JSON.stringify(packageJson, null, 2));
|
|
8760
9253
|
}
|
|
8761
9254
|
async generateTsConfig() {
|
|
8762
9255
|
const tsConfig = {
|
|
@@ -8787,7 +9280,7 @@ export default bot;`;
|
|
|
8787
9280
|
},
|
|
8788
9281
|
include: [".botpress/**/*", "src/**/*", "bp_modules/**/*", "./*.ts", "./*.json", "../*.d.ts"]
|
|
8789
9282
|
};
|
|
8790
|
-
await createFile(
|
|
9283
|
+
await createFile(path34.join(this.outputPath, "tsconfig.json"), JSON.stringify(tsConfig, null, 2));
|
|
8791
9284
|
}
|
|
8792
9285
|
async generateGlobalTypes() {
|
|
8793
9286
|
const content = dedent`
|
|
@@ -8810,11 +9303,11 @@ export default bot;`;
|
|
|
8810
9303
|
|
|
8811
9304
|
export {};
|
|
8812
9305
|
`;
|
|
8813
|
-
await createFile(
|
|
9306
|
+
await createFile(path34.join(this.outputPath, "global.d.ts"), await formatCode(content));
|
|
8814
9307
|
}
|
|
8815
9308
|
async copyAssets() {
|
|
8816
|
-
const assetsPath =
|
|
8817
|
-
const targetPath =
|
|
9309
|
+
const assetsPath = path34.join(this.projectPath, "assets");
|
|
9310
|
+
const targetPath = path34.join(this.outputPath, "assets");
|
|
8818
9311
|
if (existsSync7(assetsPath)) {
|
|
8819
9312
|
await fs16.mkdir(targetPath, { recursive: true });
|
|
8820
9313
|
await this.copyDirectory(assetsPath, targetPath);
|
|
@@ -8823,8 +9316,8 @@ export default bot;`;
|
|
|
8823
9316
|
async copyDirectory(src, dest) {
|
|
8824
9317
|
const entries = await fs16.readdir(src, { withFileTypes: true });
|
|
8825
9318
|
for (const entry of entries) {
|
|
8826
|
-
const srcPath =
|
|
8827
|
-
const destPath =
|
|
9319
|
+
const srcPath = path34.join(src, entry.name);
|
|
9320
|
+
const destPath = path34.join(dest, entry.name);
|
|
8828
9321
|
if (entry.isDirectory()) {
|
|
8829
9322
|
await fs16.mkdir(destPath, { recursive: true });
|
|
8830
9323
|
await this.copyDirectory(srcPath, destPath);
|
|
@@ -8836,16 +9329,16 @@ export default bot;`;
|
|
|
8836
9329
|
async generateAdkRuntime() {
|
|
8837
9330
|
const project = new AgentProject(this.projectPath);
|
|
8838
9331
|
await project.reload();
|
|
8839
|
-
const srcDir =
|
|
9332
|
+
const srcDir = path34.join(this.outputPath, "src");
|
|
8840
9333
|
{
|
|
8841
|
-
const dest =
|
|
9334
|
+
const dest = path34.join(srcDir, "conversations.ts");
|
|
8842
9335
|
const imports = new Map;
|
|
8843
9336
|
const exports = new Set;
|
|
8844
9337
|
let index = 1;
|
|
8845
9338
|
for (const conversation of project.conversations) {
|
|
8846
9339
|
if (!imports.has(conversation.path)) {
|
|
8847
9340
|
const name = `conversations_${index++}`;
|
|
8848
|
-
const importPath = getImportPath(dest,
|
|
9341
|
+
const importPath = getImportPath(dest, path34.join(project.path, conversation.path));
|
|
8849
9342
|
imports.set(conversation.path, {
|
|
8850
9343
|
name,
|
|
8851
9344
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -8871,14 +9364,14 @@ export default bot;`;
|
|
|
8871
9364
|
await createFile(dest, await formatCode(content2));
|
|
8872
9365
|
}
|
|
8873
9366
|
{
|
|
8874
|
-
const dest =
|
|
9367
|
+
const dest = path34.join(srcDir, "knowledge.ts");
|
|
8875
9368
|
const imports = new Map;
|
|
8876
9369
|
const exports = new Set;
|
|
8877
9370
|
let index = 1;
|
|
8878
9371
|
for (const knowledge of project.knowledge) {
|
|
8879
9372
|
if (!imports.has(knowledge.path)) {
|
|
8880
9373
|
const name = `knowledge_${index++}`;
|
|
8881
|
-
const importPath = getImportPath(dest,
|
|
9374
|
+
const importPath = getImportPath(dest, path34.join(project.path, knowledge.path));
|
|
8882
9375
|
imports.set(knowledge.path, {
|
|
8883
9376
|
name,
|
|
8884
9377
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -8904,7 +9397,7 @@ export default bot;`;
|
|
|
8904
9397
|
await createFile(dest, await formatCode(content2));
|
|
8905
9398
|
}
|
|
8906
9399
|
{
|
|
8907
|
-
const dest =
|
|
9400
|
+
const dest = path34.join(srcDir, "triggers.ts");
|
|
8908
9401
|
const { transforms: transforms4 } = await import("@botpress/sdk");
|
|
8909
9402
|
const imports = new Map;
|
|
8910
9403
|
const exports = new Set;
|
|
@@ -8913,7 +9406,7 @@ export default bot;`;
|
|
|
8913
9406
|
for (const trigger of project.triggers) {
|
|
8914
9407
|
if (!imports.has(trigger.path)) {
|
|
8915
9408
|
const name = `triggers_${index++}`;
|
|
8916
|
-
const importPath = getImportPath(dest,
|
|
9409
|
+
const importPath = getImportPath(dest, path34.join(project.path, trigger.path));
|
|
8917
9410
|
imports.set(trigger.path, {
|
|
8918
9411
|
name,
|
|
8919
9412
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -8923,7 +9416,7 @@ export default bot;`;
|
|
|
8923
9416
|
}
|
|
8924
9417
|
for (const trigger of project.triggers) {
|
|
8925
9418
|
try {
|
|
8926
|
-
const absolutePath =
|
|
9419
|
+
const absolutePath = path34.join(project.path, trigger.path);
|
|
8927
9420
|
const triggerModule = await import(`${absolutePath}?t=${Date.now()}`);
|
|
8928
9421
|
const triggerInstance = triggerModule[trigger.export] || triggerModule.default;
|
|
8929
9422
|
if (triggerInstance && triggerInstance.payload) {
|
|
@@ -8966,17 +9459,17 @@ export default bot;`;
|
|
|
8966
9459
|
await createFile(dest, await formatCode(content2));
|
|
8967
9460
|
}
|
|
8968
9461
|
{
|
|
8969
|
-
const dest =
|
|
9462
|
+
const dest = path34.join(srcDir, "workflows.ts");
|
|
8970
9463
|
const imports = new Map;
|
|
8971
9464
|
const exports = new Set;
|
|
8972
9465
|
let index = 1;
|
|
8973
9466
|
for (const workflow of project.workflows) {
|
|
8974
|
-
if (
|
|
9467
|
+
if (isBuiltinWorkflow3(workflow.definition.name)) {
|
|
8975
9468
|
continue;
|
|
8976
9469
|
}
|
|
8977
9470
|
if (!imports.has(workflow.path)) {
|
|
8978
9471
|
const name = `workflows_${index++}`;
|
|
8979
|
-
const importPath = getImportPath(dest,
|
|
9472
|
+
const importPath = getImportPath(dest, path34.join(project.path, workflow.path));
|
|
8980
9473
|
const statement = `import * as ${name} from "${importPath}";`;
|
|
8981
9474
|
imports.set(workflow.path, {
|
|
8982
9475
|
name,
|
|
@@ -8985,7 +9478,7 @@ export default bot;`;
|
|
|
8985
9478
|
}
|
|
8986
9479
|
}
|
|
8987
9480
|
for (const workflow of project.workflows) {
|
|
8988
|
-
if (
|
|
9481
|
+
if (isBuiltinWorkflow3(workflow.definition.name)) {
|
|
8989
9482
|
continue;
|
|
8990
9483
|
}
|
|
8991
9484
|
const importEntry = imports.get(workflow.path);
|
|
@@ -9010,7 +9503,7 @@ export default bot;`;
|
|
|
9010
9503
|
await createFile(dest, await formatCode(content2));
|
|
9011
9504
|
}
|
|
9012
9505
|
{
|
|
9013
|
-
const dest =
|
|
9506
|
+
const dest = path34.join(srcDir, "actions.ts");
|
|
9014
9507
|
const imports = new Map;
|
|
9015
9508
|
const exports = new Set;
|
|
9016
9509
|
let index = 1;
|
|
@@ -9020,7 +9513,7 @@ export default bot;`;
|
|
|
9020
9513
|
}
|
|
9021
9514
|
if (!imports.has(action.path)) {
|
|
9022
9515
|
const name = `actions_${index++}`;
|
|
9023
|
-
const importPath = getImportPath(dest,
|
|
9516
|
+
const importPath = getImportPath(dest, path34.join(project.path, action.path));
|
|
9024
9517
|
imports.set(action.path, {
|
|
9025
9518
|
name,
|
|
9026
9519
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -9046,14 +9539,14 @@ export default bot;`;
|
|
|
9046
9539
|
await createFile(dest, await formatCode(content2));
|
|
9047
9540
|
}
|
|
9048
9541
|
{
|
|
9049
|
-
const dest =
|
|
9542
|
+
const dest = path34.join(srcDir, "tables.ts");
|
|
9050
9543
|
const imports = new Map;
|
|
9051
9544
|
const exports = new Set;
|
|
9052
9545
|
let index = 1;
|
|
9053
9546
|
for (const table of project.tables) {
|
|
9054
9547
|
if (!imports.has(table.path)) {
|
|
9055
9548
|
const name = `tables_${index++}`;
|
|
9056
|
-
const importPath = getImportPath(dest,
|
|
9549
|
+
const importPath = getImportPath(dest, path34.join(project.path, table.path));
|
|
9057
9550
|
imports.set(table.path, {
|
|
9058
9551
|
name,
|
|
9059
9552
|
statement: `import * as ${name} from "${importPath}";`
|
|
@@ -9079,8 +9572,8 @@ export default bot;`;
|
|
|
9079
9572
|
await createFile(dest, await formatCode(content2));
|
|
9080
9573
|
}
|
|
9081
9574
|
{
|
|
9082
|
-
const dest =
|
|
9083
|
-
const importPath = getImportPath(dest,
|
|
9575
|
+
const dest = path34.join(srcDir, "config.ts");
|
|
9576
|
+
const importPath = getImportPath(dest, path34.join(project.path, "agent.config.ts"));
|
|
9084
9577
|
const content2 = `
|
|
9085
9578
|
////////////////////////////////////////////////////////
|
|
9086
9579
|
// DO NOT EDIT THIS FILE DIRECTLY
|
|
@@ -9146,13 +9639,13 @@ export default bot;`;
|
|
|
9146
9639
|
handlers.actions.setup(bot);
|
|
9147
9640
|
}
|
|
9148
9641
|
`;
|
|
9149
|
-
await createFile(
|
|
9642
|
+
await createFile(path34.join(this.outputPath, "src", "adk-runtime.ts"), await formatCode(content));
|
|
9150
9643
|
}
|
|
9151
9644
|
async copyAssetsRuntime() {
|
|
9152
|
-
const assetsRuntimePath =
|
|
9645
|
+
const assetsRuntimePath = path34.join(this.projectPath, ".adk", "assets-runtime.ts");
|
|
9153
9646
|
if (existsSync7(assetsRuntimePath)) {
|
|
9154
9647
|
const content = await fs16.readFile(assetsRuntimePath, "utf-8");
|
|
9155
|
-
await createFile(
|
|
9648
|
+
await createFile(path34.join(this.outputPath, "src", "assets-runtime.ts"), await formatCode(content));
|
|
9156
9649
|
}
|
|
9157
9650
|
}
|
|
9158
9651
|
}
|
|
@@ -9161,11 +9654,11 @@ async function generateBotProject(options) {
|
|
|
9161
9654
|
await generator.generate();
|
|
9162
9655
|
await generator.generateAdkRuntime();
|
|
9163
9656
|
await generator.copyAssetsRuntime();
|
|
9164
|
-
const botPath = options.outputPath ||
|
|
9657
|
+
const botPath = options.outputPath || path34.join(options.projectPath, ".adk", "bot");
|
|
9165
9658
|
await linkSdk(options.projectPath, botPath);
|
|
9166
|
-
const devIdManager = new DevIdManager(options.projectPath, options.outputPath ||
|
|
9659
|
+
const devIdManager = new DevIdManager(options.projectPath, options.outputPath || path34.join(options.projectPath, ".adk", "bot"));
|
|
9167
9660
|
await devIdManager.restoreDevId();
|
|
9168
|
-
const integrationSync = new IntegrationSync(options.projectPath, options.outputPath ||
|
|
9661
|
+
const integrationSync = new IntegrationSync(options.projectPath, options.outputPath || path34.join(options.projectPath, ".adk", "bot"));
|
|
9169
9662
|
const integrationSyncResult = await integrationSync.syncIntegrations();
|
|
9170
9663
|
if (integrationSyncResult.errors.length > 0) {
|
|
9171
9664
|
console.warn(`⚠️ Some integrations failed to sync:`);
|
|
@@ -9173,7 +9666,7 @@ async function generateBotProject(options) {
|
|
|
9173
9666
|
console.warn(` - ${alias}: ${error}`);
|
|
9174
9667
|
});
|
|
9175
9668
|
}
|
|
9176
|
-
const interfaceSync = new InterfaceSync(options.projectPath, options.outputPath ||
|
|
9669
|
+
const interfaceSync = new InterfaceSync(options.projectPath, options.outputPath || path34.join(options.projectPath, ".adk", "bot"));
|
|
9177
9670
|
const interfaceSyncResult = await interfaceSync.syncInterfaces();
|
|
9178
9671
|
if (interfaceSyncResult.errors.length > 0) {
|
|
9179
9672
|
console.warn(`⚠️ Some interfaces failed to sync:`);
|
|
@@ -9183,7 +9676,7 @@ async function generateBotProject(options) {
|
|
|
9183
9676
|
}
|
|
9184
9677
|
}
|
|
9185
9678
|
// src/tables/table-manager.ts
|
|
9186
|
-
import { Client as
|
|
9679
|
+
import { Client as Client14 } from "@botpress/client";
|
|
9187
9680
|
import { transforms as transforms4 } from "@botpress/sdk";
|
|
9188
9681
|
class TableManager {
|
|
9189
9682
|
client;
|
|
@@ -9197,7 +9690,7 @@ class TableManager {
|
|
|
9197
9690
|
if (!this.client) {
|
|
9198
9691
|
const credentials = await auth.getActiveCredentials();
|
|
9199
9692
|
this.assertBotId("initialize client");
|
|
9200
|
-
this.client = new
|
|
9693
|
+
this.client = new Client14({
|
|
9201
9694
|
token: credentials.token,
|
|
9202
9695
|
apiUrl: credentials.apiUrl,
|
|
9203
9696
|
botId: this.botId,
|
|
@@ -9682,10 +10175,10 @@ class TableManager {
|
|
|
9682
10175
|
}
|
|
9683
10176
|
// src/knowledge/manager.ts
|
|
9684
10177
|
import crypto4 from "crypto";
|
|
9685
|
-
import
|
|
10178
|
+
import path35 from "path";
|
|
9686
10179
|
import fs17 from "fs/promises";
|
|
9687
10180
|
import { glob } from "glob";
|
|
9688
|
-
import { Client as
|
|
10181
|
+
import { Client as Client15 } from "@botpress/client";
|
|
9689
10182
|
import { DataSource } from "@botpress/runtime";
|
|
9690
10183
|
|
|
9691
10184
|
// src/knowledge/types.ts
|
|
@@ -9730,7 +10223,7 @@ class KnowledgeManager {
|
|
|
9730
10223
|
if (!this.client) {
|
|
9731
10224
|
const credentials = await auth.getActiveCredentials();
|
|
9732
10225
|
this.assertBotId("initialize client");
|
|
9733
|
-
this.client = new
|
|
10226
|
+
this.client = new Client15({
|
|
9734
10227
|
token: credentials.token,
|
|
9735
10228
|
apiUrl: credentials.apiUrl,
|
|
9736
10229
|
botId: this.botId,
|
|
@@ -10132,14 +10625,14 @@ class KnowledgeManager {
|
|
|
10132
10625
|
}
|
|
10133
10626
|
async scanLocalFileHashes(directoryPath, filterFn) {
|
|
10134
10627
|
const projectDir = this.project.path;
|
|
10135
|
-
const directory =
|
|
10628
|
+
const directory = path35.resolve(projectDir, directoryPath);
|
|
10136
10629
|
if (this.fileHashCache.has(directory)) {
|
|
10137
10630
|
return this.fileHashCache.get(directory);
|
|
10138
10631
|
}
|
|
10139
10632
|
const files = glob.sync(directory + "/**/*.*", { absolute: true, nodir: true }).filter((file) => !filterFn || filterFn(file));
|
|
10140
10633
|
const hashes = {};
|
|
10141
10634
|
for (const file of files) {
|
|
10142
|
-
const relPath =
|
|
10635
|
+
const relPath = path35.relative(directory, file);
|
|
10143
10636
|
const content = await fs17.readFile(file);
|
|
10144
10637
|
hashes[relPath] = crypto4.createHash("sha256").update(content).digest("hex");
|
|
10145
10638
|
}
|
|
@@ -10247,7 +10740,7 @@ class KnowledgeManager {
|
|
|
10247
10740
|
}
|
|
10248
10741
|
async syncDirectorySource(client, kbName, kbId, dsId, directoryPath, filterFn, force) {
|
|
10249
10742
|
const projectDir = this.project.path;
|
|
10250
|
-
const directory =
|
|
10743
|
+
const directory = path35.resolve(projectDir, directoryPath);
|
|
10251
10744
|
if (!directory.startsWith(projectDir)) {
|
|
10252
10745
|
throw new Error("Directory path must be within the agent's directory");
|
|
10253
10746
|
}
|
|
@@ -10269,8 +10762,8 @@ class KnowledgeManager {
|
|
|
10269
10762
|
return true;
|
|
10270
10763
|
}).map((f) => ({
|
|
10271
10764
|
abs: f,
|
|
10272
|
-
rel:
|
|
10273
|
-
name:
|
|
10765
|
+
rel: path35.relative(directory, f),
|
|
10766
|
+
name: path35.basename(f)
|
|
10274
10767
|
}));
|
|
10275
10768
|
console.log(` Found ${allFiles.length} files in ${directoryPath}`);
|
|
10276
10769
|
const cachedHashes = await this.scanLocalFileHashes(directoryPath, filterFn);
|
|
@@ -10352,7 +10845,7 @@ class KnowledgeManager {
|
|
|
10352
10845
|
return null;
|
|
10353
10846
|
}
|
|
10354
10847
|
} catch {}
|
|
10355
|
-
const title =
|
|
10848
|
+
const title = path35.basename(local.name, path35.extname(local.name));
|
|
10356
10849
|
const metadata = {
|
|
10357
10850
|
hash,
|
|
10358
10851
|
dsId,
|
|
@@ -10616,8 +11109,8 @@ class FileWatcher2 extends EventEmitter3 {
|
|
|
10616
11109
|
}
|
|
10617
11110
|
}
|
|
10618
11111
|
// src/preflight/checker.ts
|
|
10619
|
-
import { Client as
|
|
10620
|
-
import
|
|
11112
|
+
import { Client as Client16 } from "@botpress/client";
|
|
11113
|
+
import path36 from "path";
|
|
10621
11114
|
|
|
10622
11115
|
// src/preflight/types.ts
|
|
10623
11116
|
function hasIntegrationChanges(integrations) {
|
|
@@ -10831,7 +11324,7 @@ class PreflightChecker {
|
|
|
10831
11324
|
if (!workspaceId) {
|
|
10832
11325
|
throw new Error('No workspace ID found. Please login with "adk login"');
|
|
10833
11326
|
}
|
|
10834
|
-
this.client = new
|
|
11327
|
+
this.client = new Client16({
|
|
10835
11328
|
token: credentials.token,
|
|
10836
11329
|
apiUrl: credentials.apiUrl,
|
|
10837
11330
|
workspaceId,
|
|
@@ -10979,7 +11472,8 @@ class PreflightChecker {
|
|
|
10979
11472
|
options?.onProgress?.("Regenerating bot project...");
|
|
10980
11473
|
await generateBotProject({
|
|
10981
11474
|
projectPath: this.projectPath,
|
|
10982
|
-
outputPath:
|
|
11475
|
+
outputPath: path36.join(this.projectPath, ".adk", "bot"),
|
|
11476
|
+
callbacks: options
|
|
10983
11477
|
});
|
|
10984
11478
|
options?.onSuccess?.("Bot project regenerated");
|
|
10985
11479
|
}
|
|
@@ -10988,19 +11482,19 @@ class PreflightChecker {
|
|
|
10988
11482
|
import dedent2 from "dedent";
|
|
10989
11483
|
import { existsSync as existsSync9 } from "fs";
|
|
10990
11484
|
import fs18 from "fs/promises";
|
|
10991
|
-
import
|
|
11485
|
+
import path37 from "path";
|
|
10992
11486
|
import { spawn } from "child_process";
|
|
10993
11487
|
init_utils();
|
|
10994
11488
|
init_credentials();
|
|
10995
11489
|
async function findAgentRoot(startPath) {
|
|
10996
|
-
let currentPath =
|
|
10997
|
-
const root =
|
|
11490
|
+
let currentPath = path37.resolve(startPath);
|
|
11491
|
+
const root = path37.parse(currentPath).root;
|
|
10998
11492
|
while (currentPath !== root) {
|
|
10999
11493
|
try {
|
|
11000
|
-
await fs18.access(
|
|
11494
|
+
await fs18.access(path37.join(currentPath, "agent.config.ts"));
|
|
11001
11495
|
return currentPath;
|
|
11002
11496
|
} catch {
|
|
11003
|
-
currentPath =
|
|
11497
|
+
currentPath = path37.dirname(currentPath);
|
|
11004
11498
|
}
|
|
11005
11499
|
}
|
|
11006
11500
|
return null;
|
|
@@ -11012,7 +11506,7 @@ class ScriptRunner {
|
|
|
11012
11506
|
prod;
|
|
11013
11507
|
credentials;
|
|
11014
11508
|
constructor(options) {
|
|
11015
|
-
this.projectPath =
|
|
11509
|
+
this.projectPath = path37.resolve(options.projectPath);
|
|
11016
11510
|
this.forceRegenerate = options.forceRegenerate ?? false;
|
|
11017
11511
|
this.prod = options.prod ?? false;
|
|
11018
11512
|
this.credentials = options.credentials;
|
|
@@ -11021,9 +11515,9 @@ class ScriptRunner {
|
|
|
11021
11515
|
const project = await AgentProject.load(this.projectPath, {
|
|
11022
11516
|
adkCommand: "adk-build"
|
|
11023
11517
|
});
|
|
11024
|
-
const botPath =
|
|
11025
|
-
const runnerPath =
|
|
11026
|
-
const botpressTypesPath =
|
|
11518
|
+
const botPath = path37.join(this.projectPath, ".adk", "bot");
|
|
11519
|
+
const runnerPath = path37.join(botPath, "src", "script-runner.ts");
|
|
11520
|
+
const botpressTypesPath = path37.join(botPath, ".botpress", "implementation", "index.ts");
|
|
11027
11521
|
const needsRegenerate = this.forceRegenerate || !existsSync9(runnerPath) || !existsSync9(botpressTypesPath);
|
|
11028
11522
|
if (needsRegenerate) {
|
|
11029
11523
|
try {
|
|
@@ -11140,7 +11634,7 @@ class ScriptRunner {
|
|
|
11140
11634
|
|
|
11141
11635
|
runScript()
|
|
11142
11636
|
`;
|
|
11143
|
-
await fs18.writeFile(
|
|
11637
|
+
await fs18.writeFile(path37.join(botPath, "src", "script-runner.ts"), await formatCode(content), "utf-8");
|
|
11144
11638
|
}
|
|
11145
11639
|
async setupTestRuntime(options = {}) {
|
|
11146
11640
|
const { botPath, project } = await this.prepare();
|
|
@@ -11171,7 +11665,7 @@ class ScriptRunner {
|
|
|
11171
11665
|
for (const [key, value] of Object.entries(envVars)) {
|
|
11172
11666
|
process.env[key] = value;
|
|
11173
11667
|
}
|
|
11174
|
-
const runtimePath =
|
|
11668
|
+
const runtimePath = path37.join(botPath, "src", "index.ts");
|
|
11175
11669
|
return {
|
|
11176
11670
|
botPath,
|
|
11177
11671
|
runtimePath,
|
|
@@ -11184,10 +11678,10 @@ class ScriptRunner {
|
|
|
11184
11678
|
const runtimeModule = await import("@botpress/runtime/runtime");
|
|
11185
11679
|
const { Autonomous } = await import("@botpress/runtime");
|
|
11186
11680
|
const { context, agentRegistry } = runtimeModule;
|
|
11187
|
-
const { Client:
|
|
11681
|
+
const { Client: Client17 } = await import("@botpress/client");
|
|
11188
11682
|
const { BotSpecificClient, BotLogger } = await import("@botpress/sdk");
|
|
11189
11683
|
const { Cognitive } = await import("@botpress/cognitive");
|
|
11190
|
-
const vanillaClient = new
|
|
11684
|
+
const vanillaClient = new Client17({
|
|
11191
11685
|
token: this.credentials.token,
|
|
11192
11686
|
apiUrl: this.credentials.apiUrl,
|
|
11193
11687
|
botId
|
|
@@ -11219,7 +11713,7 @@ class ScriptRunner {
|
|
|
11219
11713
|
}
|
|
11220
11714
|
async run(scriptPath, options = {}) {
|
|
11221
11715
|
const { botPath, runnerPath, project } = await this.prepare();
|
|
11222
|
-
const absoluteScriptPath =
|
|
11716
|
+
const absoluteScriptPath = path37.isAbsolute(scriptPath) ? scriptPath : path37.resolve(this.projectPath, scriptPath);
|
|
11223
11717
|
if (!existsSync9(absoluteScriptPath)) {
|
|
11224
11718
|
throw new Error(`Script not found: ${absoluteScriptPath}`);
|
|
11225
11719
|
}
|
|
@@ -11318,6 +11812,7 @@ export {
|
|
|
11318
11812
|
initAssets,
|
|
11319
11813
|
getRelativeTime,
|
|
11320
11814
|
generateIntegrationTypes,
|
|
11815
|
+
generateClientWrapper,
|
|
11321
11816
|
generateBotProject,
|
|
11322
11817
|
generateAssetsTypes,
|
|
11323
11818
|
generateAssetsRuntime,
|
|
@@ -11368,4 +11863,4 @@ export {
|
|
|
11368
11863
|
AgentProject
|
|
11369
11864
|
};
|
|
11370
11865
|
|
|
11371
|
-
//# debugId=
|
|
11866
|
+
//# debugId=B2A1E741C14E701164756E2164756E21
|