@botpress/adk 1.7.11 → 1.7.12

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/index.js CHANGED
@@ -15,6 +15,7 @@ var __toESM = (mod, isNodeMode, target) => {
15
15
  });
16
16
  return to;
17
17
  };
18
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
18
19
  var __export = (target, all) => {
19
20
  for (var name in all)
20
21
  __defProp(target, name, {
@@ -36,7 +37,6 @@ var init_types = __esm(() => {
36
37
  version: z.string(),
37
38
  enabled: z.boolean(),
38
39
  configurationType: z.string().optional(),
39
- connection: z.string().optional(),
40
40
  config: z.record(z.any()).optional()
41
41
  })).optional()
42
42
  });
@@ -654,7 +654,7 @@ var PRETTIER_CONFIG, formatCode = async (code, filepath) => {
654
654
  `));
655
655
  return code;
656
656
  }
657
- }, ADK_VERSION = "1.7.11", relative2 = (from, to) => {
657
+ }, ADK_VERSION = "1.7.12", relative2 = (from, to) => {
658
658
  const fromDir = path10.dirname(from);
659
659
  const relative3 = path10.relative(fromDir, to);
660
660
  return relative3.startsWith(".") ? relative3 : `./${relative3}`;
@@ -793,6 +793,86 @@ var init_integration_action_types = __esm(() => {
793
793
  init_fs();
794
794
  });
795
795
 
796
+ // package.json
797
+ var require_package = __commonJS((exports, module) => {
798
+ module.exports = {
799
+ name: "@botpress/adk",
800
+ version: "1.7.12",
801
+ description: "Core ADK library for building AI agents on Botpress",
802
+ type: "module",
803
+ main: "dist/index.js",
804
+ types: "dist/index.d.ts",
805
+ files: [
806
+ "dist/**/*",
807
+ "package.json",
808
+ "README.md"
809
+ ],
810
+ exports: {
811
+ ".": {
812
+ types: "./dist/index.d.ts",
813
+ import: "./dist/index.js"
814
+ },
815
+ "./schemas/*": "./schemas/*"
816
+ },
817
+ scripts: {
818
+ build: "bun run build:types && bun run build.ts",
819
+ "build:types": "tsc --emitDeclarationOnly",
820
+ watch: "bun run build:types && bun build ./src/index.ts --outdir ./dist --target node --format esm --sourcemap --watch",
821
+ clean: "rm -rf dist",
822
+ prepublishOnly: "bun run clean && bun run build",
823
+ test: "vitest run",
824
+ "test:watch": "vitest",
825
+ "test:ui": "vitest --ui",
826
+ "test:coverage": "vitest run --coverage"
827
+ },
828
+ keywords: [
829
+ "botpress",
830
+ "adk",
831
+ "agent",
832
+ "ai",
833
+ "chatbot",
834
+ "conversational-ai",
835
+ "development-kit"
836
+ ],
837
+ author: "Botpress",
838
+ license: "MIT",
839
+ repository: {
840
+ type: "git",
841
+ url: "https://github.com/botpress/adk"
842
+ },
843
+ dependencies: {
844
+ "@botpress/cli": "^4.23",
845
+ "@botpress/client": "^1.27.0",
846
+ "@botpress/cognitive": "^0.2.0",
847
+ "@botpress/runtime": "^1.7.12",
848
+ "@botpress/sdk": "^4.18.1",
849
+ "@bpinternal/yargs-extra": "^0.0.21",
850
+ "@parcel/watcher": "^2.5.1",
851
+ "@types/glob": "^9.0.0",
852
+ "@types/luxon": "^3.7.1",
853
+ "@types/semver": "^7.7.1",
854
+ dedent: "^1.7.0",
855
+ execa: "9.6.0",
856
+ glob: "^11.0.3",
857
+ luxon: "^3.7.2",
858
+ prettier: "^3.6.2",
859
+ semver: "^7.7.2",
860
+ "ts-morph": "^27.0.2"
861
+ },
862
+ devDependencies: {
863
+ dotenv: "^17.2.3"
864
+ },
865
+ peerDependencies: {
866
+ typescript: ">=4.5.0"
867
+ },
868
+ engines: {
869
+ node: ">=22.0.0",
870
+ bun: ">=1.3.0"
871
+ },
872
+ packageManager: "bun@1.3.0"
873
+ };
874
+ });
875
+
796
876
  // src/auth/index.ts
797
877
  init_credentials();
798
878
 
@@ -1837,7 +1917,7 @@ function getRelativeTime(date) {
1837
1917
  // src/utils/json-ordering.ts
1838
1918
  var agentInfoKeyOrder = ["botId", "workspaceId", "apiUrl", "devId"];
1839
1919
  var dependenciesKeyOrder = ["integrations"];
1840
- var integrationKeyOrder = ["version", "enabled", "configurationType", "connection", "config"];
1920
+ var integrationKeyOrder = ["version", "enabled", "configurationType", "config"];
1841
1921
  function orderKeys(obj, keyOrder) {
1842
1922
  const objKeys = Object.keys(obj);
1843
1923
  const orderedKeys = [];
@@ -2690,7 +2770,7 @@ class IntegrationManager {
2690
2770
  return { valid: false, errors, warnings };
2691
2771
  }
2692
2772
  const hasChannels = integration.definition.channels && Object.keys(integration.definition.channels).length > 0;
2693
- if (!integration.connection) {
2773
+ if (!integration.config) {
2694
2774
  let requiresConfig = false;
2695
2775
  if (integration.definition.configurations) {
2696
2776
  requiresConfig = Object.values(integration.definition.configurations).some((config) => config.identifier?.required === true);
@@ -2701,7 +2781,7 @@ class IntegrationManager {
2701
2781
  requiresConfig = schema?.required && schema.required.length > 0;
2702
2782
  }
2703
2783
  if (requiresConfig) {
2704
- warnings.push(`Integration '${integration.alias}' requires configuration. Add a connection in agent.config.ts dependencies`);
2784
+ warnings.push(`Integration '${integration.alias}' requires configuration. Add a config object in agent.config.ts dependencies`);
2705
2785
  }
2706
2786
  }
2707
2787
  return {
@@ -3443,8 +3523,8 @@ class IntegrationChecker {
3443
3523
  }
3444
3524
  }
3445
3525
  if (!installedIntegration) {
3446
- result.needsInstall = true;
3447
- if (config) {
3526
+ result.needsInstall = enabled !== false;
3527
+ if (result.needsInstall && config) {
3448
3528
  result.needsConfiguration = true;
3449
3529
  }
3450
3530
  } else {
@@ -3458,24 +3538,23 @@ class IntegrationChecker {
3458
3538
  const configType = configurationType ?? installedIntegration.configurationType ?? "default";
3459
3539
  const schema = configType === "default" ? definition.configuration?.schema : definition.configurations?.[configType]?.schema;
3460
3540
  const schemaProperties = schema?.properties || {};
3461
- const propertyKeys = Object.keys(schemaProperties);
3462
- const filterConfig = (cfg) => {
3463
- const filtered = {};
3464
- for (const key of propertyKeys) {
3465
- if (key in cfg) {
3466
- filtered[key] = cfg[key];
3467
- }
3468
- }
3469
- return filtered;
3470
- };
3471
- const currentConfig = filterConfig(installedIntegration.configuration || {});
3472
- const desiredConfig = filterConfig(config || {});
3473
- if (JSON.stringify(currentConfig) !== JSON.stringify(desiredConfig)) {
3541
+ const allKeys = new Set([
3542
+ ...Object.keys(installedIntegration.configuration || {}),
3543
+ ...Object.keys(config || {})
3544
+ ]);
3545
+ const configsMatch = Array.from(allKeys).every((key) => {
3546
+ const currentValue = installedIntegration.configuration?.[key] ?? schemaProperties[key]?.default;
3547
+ const desiredValue = config?.[key] ?? schemaProperties[key]?.default;
3548
+ return JSON.stringify(currentValue) === JSON.stringify(desiredValue);
3549
+ });
3550
+ if (!configsMatch) {
3474
3551
  result.needsConfiguration = true;
3475
3552
  }
3476
3553
  }
3477
- if (enabled !== undefined) {
3478
- if (enabled === false && installedIntegration.enabled || enabled === true && !installedIntegration.enabled) {
3554
+ if (enabled !== undefined && enabled !== installedIntegration.enabled) {
3555
+ if (enabled === false) {
3556
+ result.needsRemoval = true;
3557
+ } else if (enabled === true && result.installStatus === "disabled") {
3479
3558
  result.needsConfiguration = true;
3480
3559
  }
3481
3560
  }
@@ -3483,8 +3562,101 @@ class IntegrationChecker {
3483
3562
  return result;
3484
3563
  }
3485
3564
  }
3486
- // src/interfaces/manager.ts
3565
+ // src/integrations/sync-manager.ts
3487
3566
  import { Client as Client8 } from "@botpress/client";
3567
+ class IntegrationSyncManager {
3568
+ projectPath;
3569
+ client;
3570
+ constructor(projectPath) {
3571
+ this.projectPath = projectPath;
3572
+ }
3573
+ async getClient() {
3574
+ if (!this.client) {
3575
+ const credentials = await auth.getActiveCredentials();
3576
+ const project = await AgentProject.load(this.projectPath);
3577
+ const workspaceId = project.agentInfo?.workspaceId || credentials.workspaceId;
3578
+ if (!workspaceId) {
3579
+ throw new Error('No workspace ID found. Please login with "adk login"');
3580
+ }
3581
+ this.client = new Client8({
3582
+ token: credentials.token,
3583
+ apiUrl: credentials.apiUrl,
3584
+ workspaceId,
3585
+ headers: {
3586
+ "x-multiple-integrations": "true"
3587
+ }
3588
+ });
3589
+ }
3590
+ return this.client;
3591
+ }
3592
+ async applySyncPlan(checkResults, botId) {
3593
+ const summary = {
3594
+ installed: 0,
3595
+ updated: 0,
3596
+ removed: 0,
3597
+ failed: 0,
3598
+ errors: []
3599
+ };
3600
+ const client = await this.getClient();
3601
+ for (const result of checkResults) {
3602
+ if (result.needsRemoval && result.installStatus !== "not_installed") {
3603
+ try {
3604
+ await client.updateBot({
3605
+ id: botId,
3606
+ integrations: {
3607
+ [result.alias]: null
3608
+ }
3609
+ });
3610
+ summary.removed++;
3611
+ } catch (error) {
3612
+ const errorMsg = error instanceof Error ? error.message : String(error);
3613
+ summary.failed++;
3614
+ summary.errors.push({ alias: result.alias, error: errorMsg });
3615
+ }
3616
+ } else if (result.needsInstall) {
3617
+ try {
3618
+ await client.updateBot({
3619
+ id: botId,
3620
+ integrations: {
3621
+ [result.alias]: {
3622
+ integrationId: result.desiredIntegrationId || result.definition.id,
3623
+ enabled: result.desiredInstallStatus === "enabled",
3624
+ configuration: result.desiredConfiguration || {}
3625
+ }
3626
+ }
3627
+ });
3628
+ summary.installed++;
3629
+ } catch (error) {
3630
+ const errorMsg = error instanceof Error ? error.message : String(error);
3631
+ summary.failed++;
3632
+ summary.errors.push({ alias: result.alias, error: errorMsg });
3633
+ }
3634
+ } else if ((result.needsUpdate || result.needsConfiguration) && result.installStatus !== "not_installed") {
3635
+ try {
3636
+ await client.updateBot({
3637
+ id: botId,
3638
+ integrations: {
3639
+ [result.alias]: {
3640
+ integrationId: result.desiredIntegrationId || result.definition.id,
3641
+ enabled: result.desiredInstallStatus === "enabled",
3642
+ configuration: result.desiredConfiguration || {},
3643
+ configurationType: result.desiredConfigurationType
3644
+ }
3645
+ }
3646
+ });
3647
+ summary.updated++;
3648
+ } catch (error) {
3649
+ const errorMsg = error instanceof Error ? error.message : String(error);
3650
+ summary.failed++;
3651
+ summary.errors.push({ alias: result.alias, error: errorMsg });
3652
+ }
3653
+ }
3654
+ }
3655
+ return summary;
3656
+ }
3657
+ }
3658
+ // src/interfaces/manager.ts
3659
+ import { Client as Client9 } from "@botpress/client";
3488
3660
 
3489
3661
  // src/interfaces/enhanced-cache.ts
3490
3662
  import fs9 from "fs/promises";
@@ -3655,7 +3827,7 @@ class InterfaceManager {
3655
3827
  if (!this.options.workspaceId && !credentials.workspaceId) {
3656
3828
  throw new Error('No workspace ID found in current profile. Please login again with "adk login"');
3657
3829
  }
3658
- this.client = new Client8({
3830
+ this.client = new Client9({
3659
3831
  token: credentials.token,
3660
3832
  apiUrl: credentials.apiUrl,
3661
3833
  workspaceId: this.options.workspaceId || credentials.workspaceId,
@@ -4139,7 +4311,6 @@ class AgentProject {
4139
4311
  name: parsed.alias,
4140
4312
  version: parsed.ref.version,
4141
4313
  workspace: parsed.ref.workspace,
4142
- connection: parsed.connection,
4143
4314
  config: parsed.config,
4144
4315
  installed: false,
4145
4316
  installedVersion: undefined,
@@ -4658,7 +4829,7 @@ class AgentProjectGenerator {
4658
4829
  deploy: "adk deploy"
4659
4830
  },
4660
4831
  dependencies: {
4661
- "@botpress/runtime": `^${"1.7.11"}`
4832
+ "@botpress/runtime": `^${"1.7.12"}`
4662
4833
  },
4663
4834
  devDependencies: {
4664
4835
  typescript: "^5.9.3"
@@ -5736,7 +5907,7 @@ init_fs();
5736
5907
  import path25 from "path";
5737
5908
  import fs12 from "fs/promises";
5738
5909
  import { existsSync as existsSync2 } from "fs";
5739
- import { Client as Client9 } from "@botpress/client";
5910
+ import { Client as Client10 } from "@botpress/client";
5740
5911
  class DevIdManager {
5741
5912
  projectPath;
5742
5913
  botProjectPath;
@@ -5755,7 +5926,7 @@ class DevIdManager {
5755
5926
  if (!workspaceId) {
5756
5927
  throw new Error('No workspace ID found in agent.json or current profile. Please login again with "adk login"');
5757
5928
  }
5758
- this.client = new Client9({
5929
+ this.client = new Client10({
5759
5930
  token: credentials.token,
5760
5931
  apiUrl: credentials.apiUrl,
5761
5932
  workspaceId,
@@ -6403,9 +6574,13 @@ declare module "@botpress/runtime/_types/state" {
6403
6574
  const integrations = project.dependencies?.integrations || {};
6404
6575
  const imports = [];
6405
6576
  const integrationDefs = [];
6406
- for (const alias of Object.keys(integrations).map(getIntegrationAlias)) {
6407
- imports.push(`import integration_${alias} from "../bp_modules/integration_${alias}";`);
6408
- integrationDefs.push(`${alias}: integration_${alias}`);
6577
+ for (const [alias, config] of Object.entries(integrations)) {
6578
+ if (config.enabled === false) {
6579
+ continue;
6580
+ }
6581
+ const normalizedAlias = getIntegrationAlias(alias);
6582
+ imports.push(`import integration_${normalizedAlias} from "../bp_modules/integration_${normalizedAlias}";`);
6583
+ integrationDefs.push(`${normalizedAlias}: integration_${normalizedAlias}`);
6409
6584
  }
6410
6585
  const content = dedent`
6411
6586
  import { IntegrationPackage } from "@botpress/sdk";
@@ -6449,10 +6624,13 @@ declare module "@botpress/runtime/_types/state" {
6449
6624
  const integrations = project.integrations;
6450
6625
  const imports = [];
6451
6626
  const addIntegrations = [];
6452
- for (const { alias } of integrations.filter((i) => i.enabled)) {
6627
+ for (const integration of integrations.filter((i) => i.enabled)) {
6628
+ const { alias, configurationType, config } = integration;
6453
6629
  const importName = `integration_${getIntegrationAlias(alias)}`;
6454
6630
  imports.push(`import ${importName} from "./bp_modules/${importName}";`);
6455
- addIntegrations.push(`bot.addIntegration(${importName}, { alias: "${alias}" });`);
6631
+ const configType = configurationType ? `, configurationType: "${configurationType}"` : "";
6632
+ const configData = config && Object.keys(config).length > 0 ? `, configuration: ${JSON.stringify(config)}` : "";
6633
+ addIntegrations.push(`bot.addIntegration(${importName}, { alias: "${alias}", enabled: true${configType}${configData} });`);
6456
6634
  }
6457
6635
  const conversationTags = {};
6458
6636
  const workflowTags = {};
@@ -7160,7 +7338,7 @@ async function generateBotProject(options) {
7160
7338
  }
7161
7339
  }
7162
7340
  // src/tables/manager.ts
7163
- import { Client as Client10 } from "@botpress/client";
7341
+ import { Client as Client11 } from "@botpress/client";
7164
7342
  import { transforms as transforms4 } from "@botpress/sdk";
7165
7343
  class TableManager {
7166
7344
  client;
@@ -7174,7 +7352,7 @@ class TableManager {
7174
7352
  if (!this.client) {
7175
7353
  const credentials = await auth.getActiveCredentials();
7176
7354
  this.assertBotId("initialize client");
7177
- this.client = new Client10({
7355
+ this.client = new Client11({
7178
7356
  token: credentials.token,
7179
7357
  apiUrl: credentials.apiUrl,
7180
7358
  botId: this.botId,
@@ -7498,6 +7676,867 @@ class FileWatcher2 extends EventEmitter3 {
7498
7676
  return super.emit(event, data);
7499
7677
  }
7500
7678
  }
7679
+ // src/preflight/checker.ts
7680
+ import { Client as Client12 } from "@botpress/client";
7681
+ import path31 from "path";
7682
+
7683
+ // src/preflight/types.ts
7684
+ function hasIntegrationChanges(integrations) {
7685
+ return integrations.toInstall.length > 0 || integrations.toRemove.length > 0 || integrations.toUpdate.length > 0;
7686
+ }
7687
+ function pluralize(count, word) {
7688
+ return `${count} ${word}${count > 1 ? "s" : ""}`;
7689
+ }
7690
+
7691
+ // src/preflight/agent-config-sync.ts
7692
+ class AgentConfigSyncManager {
7693
+ client;
7694
+ constructor(client) {
7695
+ this.client = client;
7696
+ }
7697
+ async performSync(botId, updates, options) {
7698
+ if (Object.keys(updates).length === 0) {
7699
+ return false;
7700
+ }
7701
+ try {
7702
+ options?.onProgress?.("Updating bot configuration...");
7703
+ await this.client.updateBot({ id: botId, ...updates });
7704
+ options?.onSuccess?.("Bot configuration updated");
7705
+ return true;
7706
+ } catch (error) {
7707
+ const errorMsg = error instanceof Error ? error.message : String(error);
7708
+ options?.onError?.(`Failed to sync agent config: ${errorMsg}`);
7709
+ throw error;
7710
+ }
7711
+ }
7712
+ async syncFromConfig(botId, config, options) {
7713
+ const updates = {};
7714
+ if (config.name !== undefined) {
7715
+ updates.name = config.name;
7716
+ }
7717
+ return this.performSync(botId, updates, options);
7718
+ }
7719
+ async syncFromChanges(botId, configChanges, options) {
7720
+ if (!configChanges || configChanges.length === 0) {
7721
+ return false;
7722
+ }
7723
+ const updates = {};
7724
+ for (const change of configChanges) {
7725
+ switch (change.field) {
7726
+ case "name":
7727
+ updates.name = change.newValue;
7728
+ break;
7729
+ default:
7730
+ options?.onProgress?.(`Warning: Unknown config field '${change.field}' - skipping sync`);
7731
+ }
7732
+ }
7733
+ return this.performSync(botId, updates, options);
7734
+ }
7735
+ }
7736
+
7737
+ // ../../node_modules/chalk/source/vendor/ansi-styles/index.js
7738
+ var ANSI_BACKGROUND_OFFSET = 10;
7739
+ var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
7740
+ var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
7741
+ var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
7742
+ var styles = {
7743
+ modifier: {
7744
+ reset: [0, 0],
7745
+ bold: [1, 22],
7746
+ dim: [2, 22],
7747
+ italic: [3, 23],
7748
+ underline: [4, 24],
7749
+ overline: [53, 55],
7750
+ inverse: [7, 27],
7751
+ hidden: [8, 28],
7752
+ strikethrough: [9, 29]
7753
+ },
7754
+ color: {
7755
+ black: [30, 39],
7756
+ red: [31, 39],
7757
+ green: [32, 39],
7758
+ yellow: [33, 39],
7759
+ blue: [34, 39],
7760
+ magenta: [35, 39],
7761
+ cyan: [36, 39],
7762
+ white: [37, 39],
7763
+ blackBright: [90, 39],
7764
+ gray: [90, 39],
7765
+ grey: [90, 39],
7766
+ redBright: [91, 39],
7767
+ greenBright: [92, 39],
7768
+ yellowBright: [93, 39],
7769
+ blueBright: [94, 39],
7770
+ magentaBright: [95, 39],
7771
+ cyanBright: [96, 39],
7772
+ whiteBright: [97, 39]
7773
+ },
7774
+ bgColor: {
7775
+ bgBlack: [40, 49],
7776
+ bgRed: [41, 49],
7777
+ bgGreen: [42, 49],
7778
+ bgYellow: [43, 49],
7779
+ bgBlue: [44, 49],
7780
+ bgMagenta: [45, 49],
7781
+ bgCyan: [46, 49],
7782
+ bgWhite: [47, 49],
7783
+ bgBlackBright: [100, 49],
7784
+ bgGray: [100, 49],
7785
+ bgGrey: [100, 49],
7786
+ bgRedBright: [101, 49],
7787
+ bgGreenBright: [102, 49],
7788
+ bgYellowBright: [103, 49],
7789
+ bgBlueBright: [104, 49],
7790
+ bgMagentaBright: [105, 49],
7791
+ bgCyanBright: [106, 49],
7792
+ bgWhiteBright: [107, 49]
7793
+ }
7794
+ };
7795
+ var modifierNames = Object.keys(styles.modifier);
7796
+ var foregroundColorNames = Object.keys(styles.color);
7797
+ var backgroundColorNames = Object.keys(styles.bgColor);
7798
+ var colorNames = [...foregroundColorNames, ...backgroundColorNames];
7799
+ function assembleStyles() {
7800
+ const codes = new Map;
7801
+ for (const [groupName, group] of Object.entries(styles)) {
7802
+ for (const [styleName, style] of Object.entries(group)) {
7803
+ styles[styleName] = {
7804
+ open: `\x1B[${style[0]}m`,
7805
+ close: `\x1B[${style[1]}m`
7806
+ };
7807
+ group[styleName] = styles[styleName];
7808
+ codes.set(style[0], style[1]);
7809
+ }
7810
+ Object.defineProperty(styles, groupName, {
7811
+ value: group,
7812
+ enumerable: false
7813
+ });
7814
+ }
7815
+ Object.defineProperty(styles, "codes", {
7816
+ value: codes,
7817
+ enumerable: false
7818
+ });
7819
+ styles.color.close = "\x1B[39m";
7820
+ styles.bgColor.close = "\x1B[49m";
7821
+ styles.color.ansi = wrapAnsi16();
7822
+ styles.color.ansi256 = wrapAnsi256();
7823
+ styles.color.ansi16m = wrapAnsi16m();
7824
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
7825
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
7826
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
7827
+ Object.defineProperties(styles, {
7828
+ rgbToAnsi256: {
7829
+ value(red, green, blue) {
7830
+ if (red === green && green === blue) {
7831
+ if (red < 8) {
7832
+ return 16;
7833
+ }
7834
+ if (red > 248) {
7835
+ return 231;
7836
+ }
7837
+ return Math.round((red - 8) / 247 * 24) + 232;
7838
+ }
7839
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
7840
+ },
7841
+ enumerable: false
7842
+ },
7843
+ hexToRgb: {
7844
+ value(hex) {
7845
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
7846
+ if (!matches) {
7847
+ return [0, 0, 0];
7848
+ }
7849
+ let [colorString] = matches;
7850
+ if (colorString.length === 3) {
7851
+ colorString = [...colorString].map((character) => character + character).join("");
7852
+ }
7853
+ const integer = Number.parseInt(colorString, 16);
7854
+ return [
7855
+ integer >> 16 & 255,
7856
+ integer >> 8 & 255,
7857
+ integer & 255
7858
+ ];
7859
+ },
7860
+ enumerable: false
7861
+ },
7862
+ hexToAnsi256: {
7863
+ value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
7864
+ enumerable: false
7865
+ },
7866
+ ansi256ToAnsi: {
7867
+ value(code) {
7868
+ if (code < 8) {
7869
+ return 30 + code;
7870
+ }
7871
+ if (code < 16) {
7872
+ return 90 + (code - 8);
7873
+ }
7874
+ let red;
7875
+ let green;
7876
+ let blue;
7877
+ if (code >= 232) {
7878
+ red = ((code - 232) * 10 + 8) / 255;
7879
+ green = red;
7880
+ blue = red;
7881
+ } else {
7882
+ code -= 16;
7883
+ const remainder = code % 36;
7884
+ red = Math.floor(code / 36) / 5;
7885
+ green = Math.floor(remainder / 6) / 5;
7886
+ blue = remainder % 6 / 5;
7887
+ }
7888
+ const value = Math.max(red, green, blue) * 2;
7889
+ if (value === 0) {
7890
+ return 30;
7891
+ }
7892
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
7893
+ if (value === 2) {
7894
+ result += 60;
7895
+ }
7896
+ return result;
7897
+ },
7898
+ enumerable: false
7899
+ },
7900
+ rgbToAnsi: {
7901
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
7902
+ enumerable: false
7903
+ },
7904
+ hexToAnsi: {
7905
+ value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
7906
+ enumerable: false
7907
+ }
7908
+ });
7909
+ return styles;
7910
+ }
7911
+ var ansiStyles = assembleStyles();
7912
+ var ansi_styles_default = ansiStyles;
7913
+
7914
+ // ../../node_modules/chalk/source/vendor/supports-color/index.js
7915
+ import process3 from "node:process";
7916
+ import os7 from "node:os";
7917
+ import tty from "node:tty";
7918
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process3.argv) {
7919
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
7920
+ const position = argv.indexOf(prefix + flag);
7921
+ const terminatorPosition = argv.indexOf("--");
7922
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
7923
+ }
7924
+ var { env } = process3;
7925
+ var flagForceColor;
7926
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
7927
+ flagForceColor = 0;
7928
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
7929
+ flagForceColor = 1;
7930
+ }
7931
+ function envForceColor() {
7932
+ if ("FORCE_COLOR" in env) {
7933
+ if (env.FORCE_COLOR === "true") {
7934
+ return 1;
7935
+ }
7936
+ if (env.FORCE_COLOR === "false") {
7937
+ return 0;
7938
+ }
7939
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
7940
+ }
7941
+ }
7942
+ function translateLevel(level) {
7943
+ if (level === 0) {
7944
+ return false;
7945
+ }
7946
+ return {
7947
+ level,
7948
+ hasBasic: true,
7949
+ has256: level >= 2,
7950
+ has16m: level >= 3
7951
+ };
7952
+ }
7953
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
7954
+ const noFlagForceColor = envForceColor();
7955
+ if (noFlagForceColor !== undefined) {
7956
+ flagForceColor = noFlagForceColor;
7957
+ }
7958
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
7959
+ if (forceColor === 0) {
7960
+ return 0;
7961
+ }
7962
+ if (sniffFlags) {
7963
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
7964
+ return 3;
7965
+ }
7966
+ if (hasFlag("color=256")) {
7967
+ return 2;
7968
+ }
7969
+ }
7970
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) {
7971
+ return 1;
7972
+ }
7973
+ if (haveStream && !streamIsTTY && forceColor === undefined) {
7974
+ return 0;
7975
+ }
7976
+ const min = forceColor || 0;
7977
+ if (env.TERM === "dumb") {
7978
+ return min;
7979
+ }
7980
+ if (process3.platform === "win32") {
7981
+ const osRelease = os7.release().split(".");
7982
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
7983
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
7984
+ }
7985
+ return 1;
7986
+ }
7987
+ if ("CI" in env) {
7988
+ if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => (key in env))) {
7989
+ return 3;
7990
+ }
7991
+ if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
7992
+ return 1;
7993
+ }
7994
+ return min;
7995
+ }
7996
+ if ("TEAMCITY_VERSION" in env) {
7997
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
7998
+ }
7999
+ if (env.COLORTERM === "truecolor") {
8000
+ return 3;
8001
+ }
8002
+ if (env.TERM === "xterm-kitty") {
8003
+ return 3;
8004
+ }
8005
+ if (env.TERM === "xterm-ghostty") {
8006
+ return 3;
8007
+ }
8008
+ if (env.TERM === "wezterm") {
8009
+ return 3;
8010
+ }
8011
+ if ("TERM_PROGRAM" in env) {
8012
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
8013
+ switch (env.TERM_PROGRAM) {
8014
+ case "iTerm.app": {
8015
+ return version >= 3 ? 3 : 2;
8016
+ }
8017
+ case "Apple_Terminal": {
8018
+ return 2;
8019
+ }
8020
+ }
8021
+ }
8022
+ if (/-256(color)?$/i.test(env.TERM)) {
8023
+ return 2;
8024
+ }
8025
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
8026
+ return 1;
8027
+ }
8028
+ if ("COLORTERM" in env) {
8029
+ return 1;
8030
+ }
8031
+ return min;
8032
+ }
8033
+ function createSupportsColor(stream, options = {}) {
8034
+ const level = _supportsColor(stream, {
8035
+ streamIsTTY: stream && stream.isTTY,
8036
+ ...options
8037
+ });
8038
+ return translateLevel(level);
8039
+ }
8040
+ var supportsColor = {
8041
+ stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
8042
+ stderr: createSupportsColor({ isTTY: tty.isatty(2) })
8043
+ };
8044
+ var supports_color_default = supportsColor;
8045
+
8046
+ // ../../node_modules/chalk/source/utilities.js
8047
+ function stringReplaceAll(string, substring, replacer) {
8048
+ let index = string.indexOf(substring);
8049
+ if (index === -1) {
8050
+ return string;
8051
+ }
8052
+ const substringLength = substring.length;
8053
+ let endIndex = 0;
8054
+ let returnValue = "";
8055
+ do {
8056
+ returnValue += string.slice(endIndex, index) + substring + replacer;
8057
+ endIndex = index + substringLength;
8058
+ index = string.indexOf(substring, endIndex);
8059
+ } while (index !== -1);
8060
+ returnValue += string.slice(endIndex);
8061
+ return returnValue;
8062
+ }
8063
+ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
8064
+ let endIndex = 0;
8065
+ let returnValue = "";
8066
+ do {
8067
+ const gotCR = string[index - 1] === "\r";
8068
+ returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? `\r
8069
+ ` : `
8070
+ `) + postfix;
8071
+ endIndex = index + 1;
8072
+ index = string.indexOf(`
8073
+ `, endIndex);
8074
+ } while (index !== -1);
8075
+ returnValue += string.slice(endIndex);
8076
+ return returnValue;
8077
+ }
8078
+
8079
+ // ../../node_modules/chalk/source/index.js
8080
+ var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
8081
+ var GENERATOR = Symbol("GENERATOR");
8082
+ var STYLER = Symbol("STYLER");
8083
+ var IS_EMPTY = Symbol("IS_EMPTY");
8084
+ var levelMapping = [
8085
+ "ansi",
8086
+ "ansi",
8087
+ "ansi256",
8088
+ "ansi16m"
8089
+ ];
8090
+ var styles2 = Object.create(null);
8091
+ var applyOptions = (object, options = {}) => {
8092
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
8093
+ throw new Error("The `level` option should be an integer from 0 to 3");
8094
+ }
8095
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
8096
+ object.level = options.level === undefined ? colorLevel : options.level;
8097
+ };
8098
+ var chalkFactory = (options) => {
8099
+ const chalk = (...strings) => strings.join(" ");
8100
+ applyOptions(chalk, options);
8101
+ Object.setPrototypeOf(chalk, createChalk.prototype);
8102
+ return chalk;
8103
+ };
8104
+ function createChalk(options) {
8105
+ return chalkFactory(options);
8106
+ }
8107
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
8108
+ for (const [styleName, style] of Object.entries(ansi_styles_default)) {
8109
+ styles2[styleName] = {
8110
+ get() {
8111
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
8112
+ Object.defineProperty(this, styleName, { value: builder });
8113
+ return builder;
8114
+ }
8115
+ };
8116
+ }
8117
+ styles2.visible = {
8118
+ get() {
8119
+ const builder = createBuilder(this, this[STYLER], true);
8120
+ Object.defineProperty(this, "visible", { value: builder });
8121
+ return builder;
8122
+ }
8123
+ };
8124
+ var getModelAnsi = (model, level, type, ...arguments_) => {
8125
+ if (model === "rgb") {
8126
+ if (level === "ansi16m") {
8127
+ return ansi_styles_default[type].ansi16m(...arguments_);
8128
+ }
8129
+ if (level === "ansi256") {
8130
+ return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
8131
+ }
8132
+ return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
8133
+ }
8134
+ if (model === "hex") {
8135
+ return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
8136
+ }
8137
+ return ansi_styles_default[type][model](...arguments_);
8138
+ };
8139
+ var usedModels = ["rgb", "hex", "ansi256"];
8140
+ for (const model of usedModels) {
8141
+ styles2[model] = {
8142
+ get() {
8143
+ const { level } = this;
8144
+ return function(...arguments_) {
8145
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
8146
+ return createBuilder(this, styler, this[IS_EMPTY]);
8147
+ };
8148
+ }
8149
+ };
8150
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
8151
+ styles2[bgModel] = {
8152
+ get() {
8153
+ const { level } = this;
8154
+ return function(...arguments_) {
8155
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
8156
+ return createBuilder(this, styler, this[IS_EMPTY]);
8157
+ };
8158
+ }
8159
+ };
8160
+ }
8161
+ var proto = Object.defineProperties(() => {}, {
8162
+ ...styles2,
8163
+ level: {
8164
+ enumerable: true,
8165
+ get() {
8166
+ return this[GENERATOR].level;
8167
+ },
8168
+ set(level) {
8169
+ this[GENERATOR].level = level;
8170
+ }
8171
+ }
8172
+ });
8173
+ var createStyler = (open, close, parent) => {
8174
+ let openAll;
8175
+ let closeAll;
8176
+ if (parent === undefined) {
8177
+ openAll = open;
8178
+ closeAll = close;
8179
+ } else {
8180
+ openAll = parent.openAll + open;
8181
+ closeAll = close + parent.closeAll;
8182
+ }
8183
+ return {
8184
+ open,
8185
+ close,
8186
+ openAll,
8187
+ closeAll,
8188
+ parent
8189
+ };
8190
+ };
8191
+ var createBuilder = (self, _styler, _isEmpty) => {
8192
+ const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
8193
+ Object.setPrototypeOf(builder, proto);
8194
+ builder[GENERATOR] = self;
8195
+ builder[STYLER] = _styler;
8196
+ builder[IS_EMPTY] = _isEmpty;
8197
+ return builder;
8198
+ };
8199
+ var applyStyle = (self, string) => {
8200
+ if (self.level <= 0 || !string) {
8201
+ return self[IS_EMPTY] ? "" : string;
8202
+ }
8203
+ let styler = self[STYLER];
8204
+ if (styler === undefined) {
8205
+ return string;
8206
+ }
8207
+ const { openAll, closeAll } = styler;
8208
+ if (string.includes("\x1B")) {
8209
+ while (styler !== undefined) {
8210
+ string = stringReplaceAll(string, styler.close, styler.open);
8211
+ styler = styler.parent;
8212
+ }
8213
+ }
8214
+ const lfIndex = string.indexOf(`
8215
+ `);
8216
+ if (lfIndex !== -1) {
8217
+ string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
8218
+ }
8219
+ return openAll + string + closeAll;
8220
+ };
8221
+ Object.defineProperties(createChalk.prototype, styles2);
8222
+ var chalk = createChalk();
8223
+ var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
8224
+ var source_default = chalk;
8225
+
8226
+ // src/preflight/formatter.ts
8227
+ import { readFileSync } from "fs";
8228
+ import { join as join8 } from "path";
8229
+ var getAdkVersion = () => {
8230
+ try {
8231
+ const packageJson = require_package();
8232
+ return packageJson.version;
8233
+ } catch {
8234
+ try {
8235
+ const adkPackagePath = join8(process.cwd(), "node_modules/@botpress/adk/package.json");
8236
+ const pkg = JSON.parse(readFileSync(adkPackagePath, "utf-8"));
8237
+ return pkg.version;
8238
+ } catch {
8239
+ return "unknown";
8240
+ }
8241
+ }
8242
+ };
8243
+
8244
+ class PreflightFormatter {
8245
+ static format(result) {
8246
+ const sections = [];
8247
+ const purple = "#D2A6FF";
8248
+ const logoLine1 = source_default.hex(purple)(" ▄▀█ █▀▄ █▄▀") + " Botpress ADK";
8249
+ const logoLine2 = source_default.hex(purple)(" █▀█ █▄▀ █░█") + ` v${getAdkVersion()}`;
8250
+ sections.push("");
8251
+ sections.push(logoLine1);
8252
+ sections.push(logoLine2);
8253
+ sections.push("");
8254
+ sections.push(source_default.hex(purple)("Running") + " preflight checks...");
8255
+ sections.push("");
8256
+ const allIntegrations = [
8257
+ ...result.integrations.toRemove,
8258
+ ...result.integrations.toInstall,
8259
+ ...result.integrations.toUpdate
8260
+ ];
8261
+ const maxWidth = Math.max(...allIntegrations.map((i) => `${i.alias} (v${i.version})`.length), 30);
8262
+ if (hasIntegrationChanges(result.integrations)) {
8263
+ sections.push(source_default.bold(`Integrations:
8264
+ `));
8265
+ if (result.integrations.toRemove.length > 0) {
8266
+ sections.push(source_default.bold("Installed Remotely but NOT in agent.config.ts"));
8267
+ sections.push(source_default.gray(`(these will be DISABLED or REMOVED)
8268
+ `));
8269
+ for (const integration of result.integrations.toRemove) {
8270
+ const name = `${integration.alias} (v${integration.version})`;
8271
+ const padding = " ".repeat(maxWidth - name.length + 4);
8272
+ sections.push(` ${source_default.red("—")} ${name}${padding}${source_default.red("✗")} Not present locally`);
8273
+ sections.push(` Action: ${source_default.red("Remove")}
8274
+ `);
8275
+ }
8276
+ }
8277
+ if (result.integrations.toInstall.length > 0) {
8278
+ sections.push(source_default.bold("Present Locally but NOT Installed Remotely"));
8279
+ sections.push(source_default.gray(`(these will be INSTALLED)
8280
+ `));
8281
+ for (const integration of result.integrations.toInstall) {
8282
+ const name = `${integration.alias} (v${integration.version})`;
8283
+ const padding = " ".repeat(maxWidth - name.length + 4);
8284
+ sections.push(` ${source_default.green("—")} ${name}${padding}${source_default.green("+")} Missing remotely`);
8285
+ sections.push(` Action: ${source_default.green("Install")}
8286
+ `);
8287
+ }
8288
+ }
8289
+ if (result.integrations.toUpdate.length > 0) {
8290
+ sections.push(source_default.bold("Present on both, but config DIFFERS"));
8291
+ sections.push(source_default.gray(`(these will be UPDATED)
8292
+ `));
8293
+ for (const integration of result.integrations.toUpdate) {
8294
+ sections.push(` ${source_default.yellow("—")} ${integration.alias} (v${integration.version})`);
8295
+ if (integration.configChanges && integration.configChanges.length > 0) {
8296
+ sections.push(source_default.yellow(` Configuration differences:
8297
+ `));
8298
+ for (const change of integration.configChanges) {
8299
+ sections.push(` ${change.field}:`);
8300
+ sections.push(` ${source_default.red("-")} Remote: ${this.formatValue(change.oldValue)}`);
8301
+ sections.push(` ${source_default.green("+")} Local: ${this.formatValue(change.newValue)}
8302
+ `);
8303
+ }
8304
+ }
8305
+ }
8306
+ }
8307
+ }
8308
+ if (result.agentConfig.length > 0) {
8309
+ sections.push(source_default.bold("Agent Configuration Differences"));
8310
+ sections.push(source_default.gray(`(These are top-level agent settings, not integration settings)
8311
+ `));
8312
+ for (const diff of result.agentConfig) {
8313
+ sections.push(` agent.${diff.field}:`);
8314
+ sections.push(` ${source_default.red("-")} Remote: ${this.formatValue(diff.oldValue)}`);
8315
+ sections.push(` ${source_default.green("+")} Local: ${this.formatValue(diff.newValue)}
8316
+ `);
8317
+ }
8318
+ }
8319
+ sections.push(source_default.bold(`Summary of Actions
8320
+ `));
8321
+ const install = result.integrations.toInstall.length;
8322
+ const remove = result.integrations.toRemove.length;
8323
+ const update = result.integrations.toUpdate.length;
8324
+ const agentConfig = result.agentConfig.length;
8325
+ if (install > 0) {
8326
+ sections.push(` • ${source_default.green("Install:")} ${pluralize(install, "integration")}`);
8327
+ }
8328
+ if (remove > 0) {
8329
+ sections.push(` • ${source_default.red("Remove:")} ${pluralize(remove, "integration")}`);
8330
+ }
8331
+ if (update > 0) {
8332
+ sections.push(` • ${source_default.yellow("Update:")} ${pluralize(update, "integration")}`);
8333
+ }
8334
+ if (agentConfig > 0) {
8335
+ sections.push(` • ${source_default.cyan("Agent config:")} ${pluralize(agentConfig, "change")}`);
8336
+ }
8337
+ sections.push("");
8338
+ return sections.join(`
8339
+ `);
8340
+ }
8341
+ static formatPrompt() {
8342
+ return source_default.bold.red(`❓ Apply these changes before continuing?
8343
+ `) + source_default.gray("Proceed? [y/N] ");
8344
+ }
8345
+ static formatValue(value) {
8346
+ if (value === undefined || value === null) {
8347
+ return source_default.gray("(not set)");
8348
+ }
8349
+ if (typeof value === "string") {
8350
+ return `"${value}"`;
8351
+ }
8352
+ if (typeof value === "boolean") {
8353
+ return value ? source_default.green("true") : source_default.red("false");
8354
+ }
8355
+ if (Array.isArray(value)) {
8356
+ return `[${value.map((v) => this.formatValue(v)).join(", ")}]`;
8357
+ }
8358
+ if (typeof value === "object") {
8359
+ return JSON.stringify(value);
8360
+ }
8361
+ return String(value);
8362
+ }
8363
+ }
8364
+
8365
+ // src/preflight/checker.ts
8366
+ class PreflightChecker {
8367
+ projectPath;
8368
+ client;
8369
+ project;
8370
+ constructor(projectPath) {
8371
+ this.projectPath = projectPath;
8372
+ }
8373
+ async getProject() {
8374
+ if (!this.project) {
8375
+ this.project = await AgentProject.load(this.projectPath);
8376
+ }
8377
+ return this.project;
8378
+ }
8379
+ async getClient() {
8380
+ if (!this.client) {
8381
+ const credentials = await auth.getActiveCredentials();
8382
+ const project = await this.getProject();
8383
+ const workspaceId = project.agentInfo?.workspaceId || credentials.workspaceId;
8384
+ if (!workspaceId) {
8385
+ throw new Error('No workspace ID found. Please login with "adk login"');
8386
+ }
8387
+ this.client = new Client12({
8388
+ token: credentials.token,
8389
+ apiUrl: credentials.apiUrl,
8390
+ workspaceId,
8391
+ headers: {
8392
+ "x-multiple-integrations": "true"
8393
+ }
8394
+ });
8395
+ }
8396
+ return this.client;
8397
+ }
8398
+ async performCheck(botId) {
8399
+ const client = await this.getClient();
8400
+ const project = await this.getProject();
8401
+ const { bot } = await client.getBot({ id: botId });
8402
+ const integrationChecker = new IntegrationChecker(this.projectPath);
8403
+ const integrationResults = await integrationChecker.checkIntegrations(botId);
8404
+ const integrationDiffs = this.buildIntegrationDiffs(integrationResults);
8405
+ const agentConfigDiffs = this.buildAgentConfigDiffs(project, bot);
8406
+ const hasChanges = hasIntegrationChanges(integrationDiffs) || agentConfigDiffs.length > 0;
8407
+ return {
8408
+ result: {
8409
+ integrations: integrationDiffs,
8410
+ agentConfig: agentConfigDiffs,
8411
+ hasChanges
8412
+ },
8413
+ integrationResults
8414
+ };
8415
+ }
8416
+ buildIntegrationDiffs(results) {
8417
+ const toInstall = [];
8418
+ const toRemove = [];
8419
+ const toUpdate = [];
8420
+ for (const result of results) {
8421
+ if (result.desiredInstallStatus === "disabled" && !result.needsRemoval && !result.needsConfiguration) {
8422
+ continue;
8423
+ }
8424
+ if (result.needsInstall) {
8425
+ toInstall.push({
8426
+ alias: result.alias,
8427
+ name: result.name,
8428
+ version: result.desiredVersion,
8429
+ action: "install"
8430
+ });
8431
+ } else if (result.needsRemoval) {
8432
+ toRemove.push({
8433
+ alias: result.alias,
8434
+ name: result.name,
8435
+ version: result.installedVersion || result.desiredVersion,
8436
+ action: "remove"
8437
+ });
8438
+ } else if (result.needsUpdate || result.needsConfiguration) {
8439
+ const configChanges = this.buildConfigDiff(result.currentConfiguration || {}, result.desiredConfiguration || {}, result.definition.configuration?.schema?.properties || {});
8440
+ toUpdate.push({
8441
+ alias: result.alias,
8442
+ name: result.name,
8443
+ version: result.desiredVersion,
8444
+ action: "update",
8445
+ configChanges: configChanges.length > 0 ? configChanges : undefined
8446
+ });
8447
+ }
8448
+ }
8449
+ return { toInstall, toRemove, toUpdate };
8450
+ }
8451
+ buildConfigDiff(current, desired, schema) {
8452
+ const diffs = [];
8453
+ const currentObj = current ?? {};
8454
+ const desiredObj = desired ?? {};
8455
+ const allKeys = new Set([...Object.keys(currentObj), ...Object.keys(desiredObj)]);
8456
+ for (const key of allKeys) {
8457
+ const schemaDefault = schema.properties?.[key]?.default;
8458
+ const currentValue = currentObj[key] ?? schemaDefault;
8459
+ const desiredValue = desiredObj[key] ?? schemaDefault;
8460
+ if (JSON.stringify(currentValue) !== JSON.stringify(desiredValue)) {
8461
+ const type = currentValue === undefined ? "added" : desiredValue === undefined ? "removed" : "changed";
8462
+ diffs.push({
8463
+ field: key,
8464
+ oldValue: currentValue,
8465
+ newValue: desiredValue,
8466
+ type
8467
+ });
8468
+ }
8469
+ }
8470
+ return diffs;
8471
+ }
8472
+ buildAgentConfigDiffs(project, bot) {
8473
+ if (project.config?.name !== undefined && project.config.name !== bot.name) {
8474
+ return [
8475
+ {
8476
+ field: "name",
8477
+ oldValue: bot.name,
8478
+ newValue: project.config.name
8479
+ }
8480
+ ];
8481
+ }
8482
+ return [];
8483
+ }
8484
+ async checkWithPendingApply(botId) {
8485
+ const { result, integrationResults } = await this.performCheck(botId);
8486
+ return {
8487
+ result,
8488
+ apply: (callbacks) => this.apply(botId, result, integrationResults, callbacks)
8489
+ };
8490
+ }
8491
+ async checkAndApply(botId, options = {}) {
8492
+ const { result, integrationResults } = await this.performCheck(botId);
8493
+ if (!result.hasChanges) {
8494
+ return { result, applied: false };
8495
+ }
8496
+ if (options.shouldApply) {
8497
+ const formatted = PreflightFormatter.format(result);
8498
+ const approved = await options.shouldApply(result, formatted);
8499
+ if (!approved) {
8500
+ return { result, applied: false };
8501
+ }
8502
+ }
8503
+ await this.apply(botId, result, integrationResults, options.callbacks);
8504
+ return { result, applied: true };
8505
+ }
8506
+ async apply(botId, result, integrationResults, options) {
8507
+ const client = await this.getClient();
8508
+ if (hasIntegrationChanges(result.integrations)) {
8509
+ options?.onProgress?.("Syncing integrations to bot...");
8510
+ const integrationSyncer = new IntegrationSyncManager(this.projectPath);
8511
+ const syncResult = await integrationSyncer.applySyncPlan(integrationResults, botId);
8512
+ if (syncResult.installed > 0) {
8513
+ options?.onSuccess?.(`Installed ${pluralize(syncResult.installed, "integration")}`);
8514
+ }
8515
+ if (syncResult.updated > 0) {
8516
+ options?.onSuccess?.(`Updated ${pluralize(syncResult.updated, "integration")}`);
8517
+ }
8518
+ if (syncResult.removed > 0) {
8519
+ options?.onSuccess?.(`Removed ${pluralize(syncResult.removed, "integration")}`);
8520
+ }
8521
+ if (syncResult.failed > 0) {
8522
+ options?.onError?.(`Failed to sync ${pluralize(syncResult.failed, "integration")}`);
8523
+ for (const { alias, error } of syncResult.errors) {
8524
+ options?.onError?.(` ${alias}: ${error}`);
8525
+ }
8526
+ }
8527
+ }
8528
+ if (result.agentConfig.length > 0) {
8529
+ const configSyncer = new AgentConfigSyncManager(client);
8530
+ await configSyncer.syncFromChanges(botId, result.agentConfig, options);
8531
+ }
8532
+ options?.onProgress?.("Regenerating bot project...");
8533
+ await generateBotProject({
8534
+ projectPath: this.projectPath,
8535
+ outputPath: path31.join(this.projectPath, ".adk", "bot")
8536
+ });
8537
+ options?.onSuccess?.("Bot project regenerated");
8538
+ }
8539
+ }
7501
8540
  export {
7502
8541
  workspaceCache,
7503
8542
  stringifyWithOrder,
@@ -7518,9 +8557,12 @@ export {
7518
8557
  ValidationErrorCode,
7519
8558
  TableManager,
7520
8559
  ProjectState,
8560
+ PreflightFormatter,
8561
+ PreflightChecker,
7521
8562
  InterfaceParser,
7522
8563
  InterfaceOperations,
7523
8564
  InterfaceManager,
8565
+ IntegrationSyncManager,
7524
8566
  IntegrationSync,
7525
8567
  IntegrationParser,
7526
8568
  IntegrationOperations,
@@ -7543,5 +8585,5 @@ export {
7543
8585
  AgentProject
7544
8586
  };
7545
8587
 
7546
- //# debugId=5A49E76D7DEDD7B864756E2164756E21
8588
+ //# debugId=2099CC0161971ADE64756E2164756E21
7547
8589
  //# sourceMappingURL=index.js.map