@inkeep/agents-cli 0.12.1 → 0.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/index.js CHANGED
@@ -41,6 +41,25 @@ var init_esm_shims = __esm({
41
41
  }
42
42
  });
43
43
 
44
+ // ../packages/agents-core/src/api-client/base-client.ts
45
+ async function apiFetch(url, options = {}) {
46
+ const headers = {
47
+ "Content-Type": "application/json",
48
+ Accept: "application/json",
49
+ ...options.headers || {}
50
+ };
51
+ return fetch(url, {
52
+ ...options,
53
+ headers
54
+ });
55
+ }
56
+ var init_base_client = __esm({
57
+ "../packages/agents-core/src/api-client/base-client.ts"() {
58
+ "use strict";
59
+ init_esm_shims();
60
+ }
61
+ });
62
+
44
63
  // ../packages/agents-core/src/utils/logger.ts
45
64
  import pino from "pino";
46
65
  import pinoPretty from "pino-pretty";
@@ -2714,7 +2733,7 @@ var init_schemas = __esm({
2714
2733
  });
2715
2734
  ProjectSelectSchema = createSelectSchema(projects);
2716
2735
  ProjectInsertSchema = createInsertSchema(projects).extend({
2717
- models: ProjectModelSchema.optional(),
2736
+ models: ProjectModelSchema,
2718
2737
  stopWhen: StopWhenSchema.optional()
2719
2738
  }).omit({
2720
2739
  createdAt: true,
@@ -20514,6 +20533,7 @@ var init_src = __esm({
20514
20533
  "../packages/agents-core/src/index.ts"() {
20515
20534
  "use strict";
20516
20535
  init_esm_shims();
20536
+ init_base_client();
20517
20537
  init_context5();
20518
20538
  init_credential_stores();
20519
20539
  init_credential_stuffer();
@@ -20529,41 +20549,6 @@ var init_src = __esm({
20529
20549
  }
20530
20550
  });
20531
20551
 
20532
- // src/env.ts
20533
- import { z as z10 } from "zod";
20534
- var envSchema2, parseEnv2, env2;
20535
- var init_env2 = __esm({
20536
- "src/env.ts"() {
20537
- "use strict";
20538
- init_esm_shims();
20539
- init_src();
20540
- loadEnvironmentFiles();
20541
- envSchema2 = z10.object({
20542
- DEBUG: z10.string().optional(),
20543
- // Secrets loaded from .env files (relative to where CLI is executed)
20544
- INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET: z10.string().optional(),
20545
- INKEEP_AGENTS_RUN_API_BYPASS_SECRET: z10.string().optional(),
20546
- ANTHROPIC_API_KEY: z10.string().optional()
20547
- });
20548
- parseEnv2 = () => {
20549
- try {
20550
- const parsedEnv = envSchema2.parse(process.env);
20551
- return parsedEnv;
20552
- } catch (error) {
20553
- if (error instanceof z10.ZodError) {
20554
- const missingVars = error.issues.map((issue) => issue.path.join("."));
20555
- throw new Error(
20556
- `\u274C Invalid environment variables: ${missingVars.join(", ")}
20557
- ${error.message}`
20558
- );
20559
- }
20560
- throw error;
20561
- }
20562
- };
20563
- env2 = parseEnv2();
20564
- }
20565
- });
20566
-
20567
20552
  // src/utils/tsx-loader.ts
20568
20553
  import { extname } from "path";
20569
20554
  import { pathToFileURL } from "url";
@@ -20601,8 +20586,51 @@ var init_tsx_loader = __esm({
20601
20586
  });
20602
20587
 
20603
20588
  // src/utils/config.ts
20589
+ var config_exports = {};
20590
+ __export(config_exports, {
20591
+ findConfigFile: () => findConfigFile,
20592
+ loadConfig: () => loadConfig,
20593
+ loadConfigFromFile: () => loadConfigFromFile,
20594
+ maskSensitiveConfig: () => maskSensitiveConfig,
20595
+ validateConfiguration: () => validateConfiguration
20596
+ });
20604
20597
  import { existsSync as existsSync4 } from "fs";
20605
20598
  import { dirname as dirname3, join as join4, resolve as resolve2 } from "path";
20599
+ function maskSensitiveConfig(config) {
20600
+ if (!config) return config;
20601
+ const masked = { ...config };
20602
+ if (masked.agentsManageApiKey) {
20603
+ masked.agentsManageApiKey = "***" + masked.agentsManageApiKey.slice(-4);
20604
+ }
20605
+ if (masked.agentsRunApiKey) {
20606
+ masked.agentsRunApiKey = "***" + masked.agentsRunApiKey.slice(-4);
20607
+ }
20608
+ return masked;
20609
+ }
20610
+ function isNestedConfig(config) {
20611
+ return config && (config.agentsManageApi !== void 0 || config.agentsRunApi !== void 0);
20612
+ }
20613
+ function normalizeConfig(config) {
20614
+ if (isNestedConfig(config)) {
20615
+ return {
20616
+ tenantId: config.tenantId,
20617
+ agentsManageApiUrl: config.agentsManageApi?.url,
20618
+ agentsRunApiUrl: config.agentsRunApi?.url,
20619
+ agentsManageApiKey: config.agentsManageApi?.apiKey,
20620
+ agentsRunApiKey: config.agentsRunApi?.apiKey,
20621
+ manageUiUrl: config.manageUiUrl,
20622
+ outputDirectory: config.outputDirectory
20623
+ };
20624
+ } else {
20625
+ return {
20626
+ tenantId: config.tenantId,
20627
+ agentsManageApiUrl: config.agentsManageApiUrl,
20628
+ agentsRunApiUrl: config.agentsRunApiUrl,
20629
+ manageUiUrl: config.manageUiUrl,
20630
+ outputDirectory: config.outputDirectory
20631
+ };
20632
+ }
20633
+ }
20606
20634
  function findConfigFile(startPath = process.cwd()) {
20607
20635
  let currentPath = resolve2(startPath);
20608
20636
  const root = "/";
@@ -20638,11 +20666,12 @@ async function loadConfigFromFile(configPath) {
20638
20666
  }
20639
20667
  try {
20640
20668
  const module = await importWithTypeScriptSupport(resolvedPath);
20641
- const config = module.default || module.config;
20642
- logger12.info({ config }, `Loaded config values`);
20643
- if (!config) {
20669
+ const rawConfig = module.default || module.config;
20670
+ if (!rawConfig) {
20644
20671
  throw new Error(`No config exported from ${resolvedPath}`);
20645
20672
  }
20673
+ const config = normalizeConfig(rawConfig);
20674
+ logger12.info({ config: maskSensitiveConfig(config) }, `Loaded config values`);
20646
20675
  return config;
20647
20676
  } catch (error) {
20648
20677
  console.warn(`Warning: Failed to load config file ${resolvedPath}:`, error);
@@ -20650,65 +20679,32 @@ async function loadConfigFromFile(configPath) {
20650
20679
  }
20651
20680
  }
20652
20681
  async function loadConfig(configPath) {
20653
- let config = {
20682
+ const config = {
20654
20683
  agentsManageApiUrl: "http://localhost:3002",
20655
20684
  agentsRunApiUrl: "http://localhost:3003",
20656
20685
  manageUiUrl: "http://localhost:3000"
20657
20686
  };
20658
20687
  const fileConfig = await loadConfigFromFile(configPath);
20659
20688
  if (fileConfig) {
20660
- config = {
20661
- ...config,
20662
- ...fileConfig
20663
- };
20664
- logger12.info({ mergedConfig: config }, `Config loaded from file`);
20689
+ Object.keys(fileConfig).forEach((key) => {
20690
+ const value = fileConfig[key];
20691
+ if (value !== void 0) {
20692
+ config[key] = value;
20693
+ }
20694
+ });
20695
+ logger12.info({ mergedConfig: maskSensitiveConfig(config) }, `Config loaded from file`);
20665
20696
  } else {
20666
- logger12.info({ config }, `Using default config (no config file found)`);
20697
+ logger12.info(
20698
+ { config: maskSensitiveConfig(config) },
20699
+ `Using default config (no config file found)`
20700
+ );
20667
20701
  }
20668
20702
  return config;
20669
20703
  }
20670
- async function getTenantId(configPath) {
20671
- const config = await loadConfig(configPath);
20672
- return config.tenantId;
20673
- }
20674
- async function getProjectId(_configPath) {
20675
- return "default";
20676
- }
20677
- async function getAgentsManageApiUrl(overrideUrl, configPath) {
20678
- if (overrideUrl) {
20679
- return overrideUrl;
20680
- }
20681
- const config = await loadConfig(configPath);
20682
- return config.agentsManageApiUrl || "http://localhost:3002";
20683
- }
20684
- async function getAgentsRunApiUrl(overrideUrl, configPath) {
20685
- if (overrideUrl) {
20686
- return overrideUrl;
20687
- }
20688
- const config = await loadConfig(configPath);
20689
- return config.agentsRunApiUrl || "http://localhost:3003";
20690
- }
20691
- async function validateConfiguration(tenantIdFlag, agentsManageApiUrlFlag, agentsRunApiUrlFlag, configPath) {
20704
+ async function validateConfiguration(configPath) {
20692
20705
  const config = await loadConfig(configPath);
20693
- const tenantId = tenantIdFlag || config.tenantId;
20694
- const agentsManageApiUrl = agentsManageApiUrlFlag || config.agentsManageApiUrl;
20695
- const agentsRunApiUrl = agentsRunApiUrlFlag || config.agentsRunApiUrl;
20696
20706
  const actualConfigFile = configPath || findConfigFile();
20697
- if (tenantIdFlag && agentsManageApiUrlFlag && agentsRunApiUrlFlag) {
20698
- const sources2 = {
20699
- tenantId: "command-line flag (--tenant-id)",
20700
- agentsManageApiUrl: "command-line flag (--agents-manage-api-url)",
20701
- agentsRunApiUrl: "command-line flag (--agents-run-api-url)"
20702
- };
20703
- return {
20704
- tenantId: tenantIdFlag,
20705
- agentsManageApiUrl: agentsManageApiUrlFlag,
20706
- agentsRunApiUrl: agentsRunApiUrlFlag,
20707
- manageUiUrl: config.manageUiUrl,
20708
- sources: sources2
20709
- };
20710
- }
20711
- if (!tenantId) {
20707
+ if (!config.tenantId) {
20712
20708
  if (actualConfigFile) {
20713
20709
  throw new Error(
20714
20710
  `Tenant ID is missing from configuration file: ${actualConfigFile}
@@ -20716,32 +20712,36 @@ Please ensure your config file exports a valid configuration with tenantId.`
20716
20712
  );
20717
20713
  } else {
20718
20714
  throw new Error(
20719
- 'No configuration found. Please use one of:\n 1. Create "inkeep.config.ts" by running "inkeep init"\n 2. Provide --config to specify a config file\n 3. Provide --tenant-id, --agents-manage-api-url and --agents-run-api-url flags'
20715
+ 'No configuration found. Please:\n 1. Create "inkeep.config.ts" by running "inkeep init"\n 2. Or provide --config to specify a config file path'
20720
20716
  );
20721
20717
  }
20722
20718
  }
20723
- if (!agentsManageApiUrl) {
20719
+ if (!config.agentsManageApiUrl) {
20724
20720
  throw new Error(
20725
- "Agents Management API URL is missing. Please either:\n 1. Provide --agents-manage-api-url flag\n 2. Add agentsManageApiUrl to your configuration file"
20721
+ `Agents Management API URL is missing from config file${actualConfigFile ? `: ${actualConfigFile}` : ""}
20722
+ Please add agentsManageApiUrl to your configuration file`
20726
20723
  );
20727
20724
  }
20728
- if (!agentsRunApiUrl) {
20725
+ if (!config.agentsRunApiUrl) {
20729
20726
  throw new Error(
20730
- "Agents Run API URL is missing. Please either:\n 1. Provide --agents-run-api-url flag\n 2. Add agentsRunApiUrl to your configuration file"
20727
+ `Agents Run API URL is missing from config file${actualConfigFile ? `: ${actualConfigFile}` : ""}
20728
+ Please add agentsRunApiUrl to your configuration file`
20731
20729
  );
20732
20730
  }
20733
20731
  const sources = {
20734
- tenantId: tenantIdFlag ? "command-line flag (--tenant-id)" : actualConfigFile ? `config file (${actualConfigFile})` : "default",
20735
- agentsManageApiUrl: agentsManageApiUrlFlag ? "command-line flag (--agents-manage-api-url)" : actualConfigFile ? `config file (${actualConfigFile})` : "default value",
20736
- agentsRunApiUrl: agentsRunApiUrlFlag ? "command-line flag (--agents-run-api-url)" : actualConfigFile ? `config file (${actualConfigFile})` : "default value"
20732
+ tenantId: actualConfigFile ? `config file (${actualConfigFile})` : "default",
20733
+ agentsManageApiUrl: actualConfigFile ? `config file (${actualConfigFile})` : "default value",
20734
+ agentsRunApiUrl: actualConfigFile ? `config file (${actualConfigFile})` : "default value"
20737
20735
  };
20738
20736
  if (actualConfigFile) {
20739
20737
  sources.configFile = actualConfigFile;
20740
20738
  }
20741
20739
  return {
20742
- tenantId,
20743
- agentsManageApiUrl,
20744
- agentsRunApiUrl,
20740
+ tenantId: config.tenantId,
20741
+ agentsManageApiUrl: config.agentsManageApiUrl,
20742
+ agentsRunApiUrl: config.agentsRunApiUrl,
20743
+ agentsManageApiKey: config.agentsManageApiKey,
20744
+ agentsRunApiKey: config.agentsRunApiKey,
20745
20745
  manageUiUrl: config.manageUiUrl,
20746
20746
  sources
20747
20747
  };
@@ -20763,16 +20763,17 @@ var init_api = __esm({
20763
20763
  "src/api.ts"() {
20764
20764
  "use strict";
20765
20765
  init_esm_shims();
20766
- init_env2();
20767
- init_config();
20766
+ init_src();
20768
20767
  BaseApiClient = class {
20769
20768
  apiUrl;
20770
20769
  tenantId;
20771
20770
  projectId;
20772
- constructor(apiUrl, tenantId, projectId) {
20771
+ apiKey;
20772
+ constructor(apiUrl, tenantId, projectId, apiKey) {
20773
20773
  this.apiUrl = apiUrl;
20774
20774
  this.tenantId = tenantId;
20775
20775
  this.projectId = projectId;
20776
+ this.apiKey = apiKey;
20776
20777
  }
20777
20778
  checkTenantId() {
20778
20779
  if (!this.tenantId) {
@@ -20780,6 +20781,21 @@ var init_api = __esm({
20780
20781
  }
20781
20782
  return this.tenantId;
20782
20783
  }
20784
+ /**
20785
+ * Wrapper around fetch that automatically includes Authorization header if API key is present
20786
+ */
20787
+ async authenticatedFetch(url, options = {}) {
20788
+ const headers = {
20789
+ ...options.headers || {}
20790
+ };
20791
+ if (this.apiKey) {
20792
+ headers.Authorization = `Bearer ${this.apiKey}`;
20793
+ }
20794
+ return apiFetch(url, {
20795
+ ...options,
20796
+ headers
20797
+ });
20798
+ }
20783
20799
  getTenantId() {
20784
20800
  return this.tenantId;
20785
20801
  }
@@ -20791,28 +20807,24 @@ var init_api = __esm({
20791
20807
  }
20792
20808
  };
20793
20809
  ManagementApiClient = class _ManagementApiClient extends BaseApiClient {
20794
- constructor(apiUrl, tenantId, projectId) {
20795
- super(apiUrl, tenantId, projectId);
20810
+ constructor(apiUrl, tenantId, projectId, apiKey) {
20811
+ super(apiUrl, tenantId, projectId, apiKey);
20796
20812
  }
20797
20813
  static async create(apiUrl, configPath, tenantIdOverride, projectIdOverride) {
20798
- const resolvedApiUrl = await getAgentsManageApiUrl(apiUrl, configPath);
20799
- const tenantId = tenantIdOverride || await getTenantId(configPath);
20800
- const projectId = projectIdOverride || await getProjectId(configPath);
20801
- return new _ManagementApiClient(resolvedApiUrl, tenantId, projectId);
20814
+ const { validateConfiguration: validateConfiguration2 } = await Promise.resolve().then(() => (init_config(), config_exports));
20815
+ const config = await validateConfiguration2(configPath);
20816
+ const resolvedApiUrl = apiUrl || config.agentsManageApiUrl;
20817
+ const tenantId = tenantIdOverride || config.tenantId;
20818
+ const projectId = projectIdOverride || "";
20819
+ return new _ManagementApiClient(resolvedApiUrl, tenantId, projectId, config.agentsManageApiKey);
20802
20820
  }
20803
20821
  async listGraphs() {
20804
20822
  const tenantId = this.checkTenantId();
20805
20823
  const projectId = this.getProjectId();
20806
- const response = await fetch(
20824
+ const response = await this.authenticatedFetch(
20807
20825
  `${this.apiUrl}/tenants/${tenantId}/projects/${projectId}/agent-graphs`,
20808
20826
  {
20809
- method: "GET",
20810
- headers: {
20811
- "Content-Type": "application/json",
20812
- ...env2.INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET && {
20813
- Authorization: `Bearer ${env2.INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET}`
20814
- }
20815
- }
20827
+ method: "GET"
20816
20828
  }
20817
20829
  );
20818
20830
  if (!response.ok) {
@@ -20834,16 +20846,10 @@ var init_api = __esm({
20834
20846
  if (!graphId) {
20835
20847
  throw new Error("Graph must have an id property");
20836
20848
  }
20837
- const response = await fetch(
20849
+ const response = await this.authenticatedFetch(
20838
20850
  `${this.apiUrl}/tenants/${tenantId}/projects/${projectId}/graph/${graphId}`,
20839
20851
  {
20840
20852
  method: "PUT",
20841
- headers: {
20842
- "Content-Type": "application/json",
20843
- ...env2.INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET && {
20844
- Authorization: `Bearer ${env2.INKEEP_AGENTS_MANAGE_API_BYPASS_SECRET}`
20845
- }
20846
- },
20847
20853
  body: JSON.stringify(graphDefinition)
20848
20854
  }
20849
20855
  );
@@ -20855,26 +20861,47 @@ ${errorText}`);
20855
20861
  const data = await response.json();
20856
20862
  return data.data;
20857
20863
  }
20864
+ /**
20865
+ * Fetch full project data including all graphs, tools, and components
20866
+ */
20867
+ async getFullProject(projectId) {
20868
+ const tenantId = this.checkTenantId();
20869
+ const response = await this.authenticatedFetch(
20870
+ `${this.apiUrl}/tenants/${tenantId}/project-full/${projectId}`,
20871
+ {
20872
+ method: "GET"
20873
+ }
20874
+ );
20875
+ if (!response.ok) {
20876
+ if (response.status === 404) {
20877
+ throw new Error(`Project "${projectId}" not found`);
20878
+ }
20879
+ if (response.status === 401) {
20880
+ throw new Error("Unauthorized - check your API key");
20881
+ }
20882
+ throw new Error(`Failed to fetch project: ${response.statusText}`);
20883
+ }
20884
+ const responseData = await response.json();
20885
+ return responseData.data;
20886
+ }
20858
20887
  };
20859
20888
  ExecutionApiClient = class _ExecutionApiClient extends BaseApiClient {
20860
- constructor(apiUrl, tenantId, projectId) {
20861
- super(apiUrl, tenantId, projectId);
20889
+ constructor(apiUrl, tenantId, projectId, apiKey) {
20890
+ super(apiUrl, tenantId, projectId, apiKey);
20862
20891
  }
20863
20892
  static async create(apiUrl, configPath, tenantIdOverride, projectIdOverride) {
20864
- const resolvedApiUrl = await getAgentsRunApiUrl(apiUrl, configPath);
20865
- const tenantId = tenantIdOverride || await getTenantId(configPath);
20866
- const projectId = projectIdOverride || await getProjectId(configPath);
20867
- return new _ExecutionApiClient(resolvedApiUrl, tenantId, projectId);
20893
+ const { validateConfiguration: validateConfiguration2 } = await Promise.resolve().then(() => (init_config(), config_exports));
20894
+ const config = await validateConfiguration2(configPath);
20895
+ const resolvedApiUrl = apiUrl || config.agentsRunApiUrl;
20896
+ const tenantId = tenantIdOverride || config.tenantId;
20897
+ const projectId = projectIdOverride || "";
20898
+ return new _ExecutionApiClient(resolvedApiUrl, tenantId, projectId, config.agentsRunApiKey);
20868
20899
  }
20869
20900
  async chatCompletion(graphId, messages2, conversationId) {
20870
- const response = await fetch(`${this.apiUrl}/v1/chat/completions`, {
20901
+ const response = await this.authenticatedFetch(`${this.apiUrl}/v1/chat/completions`, {
20871
20902
  method: "POST",
20872
20903
  headers: {
20873
- "Content-Type": "application/json",
20874
20904
  Accept: "text/event-stream",
20875
- ...env2.INKEEP_AGENTS_RUN_API_BYPASS_SECRET && {
20876
- Authorization: `Bearer ${env2.INKEEP_AGENTS_RUN_API_BYPASS_SECRET}`
20877
- },
20878
20905
  "x-inkeep-tenant-id": this.tenantId || "test-tenant-id",
20879
20906
  "x-inkeep-project-id": this.projectId,
20880
20907
  "x-inkeep-graph-id": graphId
@@ -20907,35 +20934,77 @@ ${errorText}`);
20907
20934
  }
20908
20935
  });
20909
20936
 
20937
+ // src/utils/cli-pipeline.ts
20938
+ import chalk5 from "chalk";
20939
+ import ora3 from "ora";
20940
+ async function initializeCommand(options = {}) {
20941
+ const {
20942
+ configPath,
20943
+ showSpinner = false,
20944
+ spinnerText = "Loading configuration...",
20945
+ logConfig = true
20946
+ } = options;
20947
+ const spinner = showSpinner ? ora3(spinnerText).start() : void 0;
20948
+ try {
20949
+ const config = await validateConfiguration(configPath);
20950
+ if (spinner) {
20951
+ spinner.succeed("Configuration loaded");
20952
+ }
20953
+ if (logConfig) {
20954
+ console.log(chalk5.gray("Configuration:"));
20955
+ console.log(chalk5.gray(` \u2022 Tenant ID: ${config.tenantId}`));
20956
+ console.log(chalk5.gray(` \u2022 Manage API URL: ${config.agentsManageApiUrl}`));
20957
+ console.log(chalk5.gray(` \u2022 Run API URL: ${config.agentsRunApiUrl}`));
20958
+ if (config.sources.configFile) {
20959
+ console.log(chalk5.gray(` \u2022 Config file: ${config.sources.configFile}`));
20960
+ }
20961
+ }
20962
+ return { config, spinner };
20963
+ } catch (error) {
20964
+ if (spinner) {
20965
+ spinner.fail("Configuration failed");
20966
+ }
20967
+ console.error(chalk5.red("Error:"), error.message);
20968
+ if (error.message.includes("No configuration found")) {
20969
+ console.log(chalk5.yellow("\nHint: Create a configuration file by running:"));
20970
+ console.log(chalk5.gray(" inkeep init"));
20971
+ } else if (error.message.includes("Config file not found")) {
20972
+ console.log(chalk5.yellow("\nHint: Check that your config file path is correct"));
20973
+ } else if (error.message.includes("tenantId") || error.message.includes("API URL")) {
20974
+ console.log(chalk5.yellow("\nHint: Ensure your inkeep.config.ts has all required fields:"));
20975
+ console.log(chalk5.gray(" - tenantId"));
20976
+ console.log(chalk5.gray(" - agentsManageApiUrl (or agentsManageApi.url)"));
20977
+ console.log(chalk5.gray(" - agentsRunApiUrl (or agentsRunApi.url)"));
20978
+ }
20979
+ process.exit(1);
20980
+ }
20981
+ }
20982
+ var init_cli_pipeline = __esm({
20983
+ "src/utils/cli-pipeline.ts"() {
20984
+ "use strict";
20985
+ init_esm_shims();
20986
+ init_config();
20987
+ }
20988
+ });
20989
+
20910
20990
  // src/commands/chat-enhanced.ts
20911
20991
  var chat_enhanced_exports = {};
20912
20992
  __export(chat_enhanced_exports, {
20913
20993
  chatCommandEnhanced: () => chatCommandEnhanced
20914
20994
  });
20915
20995
  import * as readline from "readline";
20916
- import chalk8 from "chalk";
20996
+ import chalk9 from "chalk";
20917
20997
  import inquirer2 from "inquirer";
20918
- import ora6 from "ora";
20998
+ import ora7 from "ora";
20919
20999
  async function chatCommandEnhanced(graphIdInput, options) {
20920
- let config;
20921
- try {
20922
- const configPath2 = options?.config || options?.configFilePath;
20923
- config = await validateConfiguration(
20924
- options?.tenantId,
20925
- options?.agentsManageApiUrl,
20926
- options?.agentsRunApiUrl,
20927
- configPath2
20928
- );
20929
- } catch (error) {
20930
- console.error(chalk8.red(error.message));
20931
- process.exit(1);
20932
- }
20933
- console.log(chalk8.gray("Using configuration:"));
20934
- console.log(chalk8.gray(` \u2022 Tenant ID: ${config.sources.tenantId}`));
20935
- console.log(chalk8.gray(` \u2022 Management API: ${config.sources.agentsManageApiUrl}`));
20936
- console.log(chalk8.gray(` \u2022 Execution API: ${config.sources.agentsRunApiUrl}`));
20937
- console.log();
21000
+ console.log(chalk9.cyan("\u{1F916} Inkeep Chat Interface\n"));
20938
21001
  const configPath = options?.config || options?.configFilePath;
21002
+ const { config } = await initializeCommand({
21003
+ configPath,
21004
+ showSpinner: false,
21005
+ logConfig: true
21006
+ });
21007
+ console.log();
20939
21008
  const managementApi = await ManagementApiClient.create(
20940
21009
  config.agentsManageApiUrl,
20941
21010
  configPath,
@@ -20948,18 +21017,18 @@ async function chatCommandEnhanced(graphIdInput, options) {
20948
21017
  );
20949
21018
  let graphId = graphIdInput;
20950
21019
  if (!graphId) {
20951
- const spinner2 = ora6("Fetching available graphs...").start();
21020
+ const spinner2 = ora7("Fetching available graphs...").start();
20952
21021
  try {
20953
21022
  const graphs = await managementApi.listGraphs();
20954
21023
  spinner2.stop();
20955
21024
  if (graphs.length === 0) {
20956
21025
  console.error(
20957
- chalk8.red("No graphs available. Define graphs in your project and run: inkeep push")
21026
+ chalk9.red("No graphs available. Define graphs in your project and run: inkeep push")
20958
21027
  );
20959
21028
  process.exit(1);
20960
21029
  }
20961
21030
  const graphChoices = graphs.map((g) => ({
20962
- name: `${chalk8.cyan(g.id)} - ${g.name || "Unnamed Graph"}`,
21031
+ name: `${chalk9.cyan(g.id)} - ${g.name || "Unnamed Graph"}`,
20963
21032
  value: g.id,
20964
21033
  short: g.id,
20965
21034
  searchText: `${g.id} ${g.name || ""}`.toLowerCase()
@@ -20976,11 +21045,11 @@ async function chatCommandEnhanced(graphIdInput, options) {
20976
21045
  graphId = answer.graphId;
20977
21046
  } catch (error) {
20978
21047
  spinner2.fail("Failed to fetch graphs");
20979
- console.error(chalk8.red("Error:"), error instanceof Error ? error.message : error);
21048
+ console.error(chalk9.red("Error:"), error instanceof Error ? error.message : error);
20980
21049
  process.exit(1);
20981
21050
  }
20982
21051
  }
20983
- const spinner = ora6("Connecting to graph...").start();
21052
+ const spinner = ora7("Connecting to graph...").start();
20984
21053
  try {
20985
21054
  if (!graphId) {
20986
21055
  throw new Error("No graph selected");
@@ -20990,38 +21059,38 @@ async function chatCommandEnhanced(graphIdInput, options) {
20990
21059
  spinner.fail(`Graph "${graphId}" not found`);
20991
21060
  const graphs = await managementApi.listGraphs();
20992
21061
  if (graphs.length > 0) {
20993
- console.log(chalk8.yellow("\nAvailable graphs:"));
21062
+ console.log(chalk9.yellow("\nAvailable graphs:"));
20994
21063
  graphs.forEach((g) => {
20995
- console.log(chalk8.gray(` \u2022 ${g.id} - ${g.name || "Unnamed"}`));
21064
+ console.log(chalk9.gray(` \u2022 ${g.id} - ${g.name || "Unnamed"}`));
20996
21065
  });
20997
- console.log(chalk8.gray('\nRun "inkeep chat" without arguments for interactive selection'));
21066
+ console.log(chalk9.gray('\nRun "inkeep chat" without arguments for interactive selection'));
20998
21067
  } else {
20999
- console.log(chalk8.yellow("\nNo graphs found. Please define graphs and push your project."));
21068
+ console.log(chalk9.yellow("\nNo graphs found. Please define graphs and push your project."));
21000
21069
  }
21001
21070
  process.exit(1);
21002
21071
  }
21003
- spinner.succeed(`Connected to graph: ${chalk8.green(graph.name || graphId)}`);
21072
+ spinner.succeed(`Connected to graph: ${chalk9.green(graph.name || graphId)}`);
21004
21073
  if (graph.description) {
21005
- console.log(chalk8.gray(`Description: ${graph.description}`));
21074
+ console.log(chalk9.gray(`Description: ${graph.description}`));
21006
21075
  }
21007
21076
  if (graph.defaultAgentId || graph.default_agent_id) {
21008
- console.log(chalk8.gray(`Default Agent: ${graph.defaultAgentId || graph.default_agent_id}`));
21077
+ console.log(chalk9.gray(`Default Agent: ${graph.defaultAgentId || graph.default_agent_id}`));
21009
21078
  }
21010
21079
  } catch (error) {
21011
21080
  spinner.fail("Failed to connect to graph");
21012
- console.error(chalk8.red("Error:"), error instanceof Error ? error.message : error);
21081
+ console.error(chalk9.red("Error:"), error instanceof Error ? error.message : error);
21013
21082
  process.exit(1);
21014
21083
  }
21015
21084
  const rl = readline.createInterface({
21016
21085
  input: process.stdin,
21017
21086
  output: process.stdout,
21018
- prompt: chalk8.cyan("You> ")
21087
+ prompt: chalk9.cyan("You> ")
21019
21088
  });
21020
21089
  const conversationId = `cli-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
21021
21090
  const messages2 = [];
21022
21091
  let debugMode = false;
21023
- console.log(chalk8.gray('\n\u{1F4AC} Chat session started. Type "exit" or press Ctrl+C to quit.'));
21024
- console.log(chalk8.gray("Commands: help, clear, history, reset, debug\n"));
21092
+ console.log(chalk9.gray('\n\u{1F4AC} Chat session started. Type "exit" or press Ctrl+C to quit.'));
21093
+ console.log(chalk9.gray("Commands: help, clear, history, reset, debug\n"));
21025
21094
  async function handleStreamingResponse(stream, showDebug = false) {
21026
21095
  const decoder = new TextDecoder();
21027
21096
  const reader = stream.getReader();
@@ -21077,12 +21146,12 @@ async function chatCommandEnhanced(graphIdInput, options) {
21077
21146
  if (opType === "completion" && hasStartedResponse) {
21078
21147
  console.log("");
21079
21148
  }
21080
- console.log(chalk8.gray(` [${opType}] ${ctxDisplay}`));
21149
+ console.log(chalk9.gray(` [${opType}] ${ctxDisplay}`));
21081
21150
  }
21082
21151
  currentPos = jsonEnd;
21083
21152
  } catch {
21084
21153
  if (!hasStartedResponse) {
21085
- process.stdout.write(chalk8.green("Assistant> "));
21154
+ process.stdout.write(chalk9.green("Assistant> "));
21086
21155
  hasStartedResponse = true;
21087
21156
  }
21088
21157
  process.stdout.write(content[currentPos]);
@@ -21091,7 +21160,7 @@ async function chatCommandEnhanced(graphIdInput, options) {
21091
21160
  }
21092
21161
  } else {
21093
21162
  if (!hasStartedResponse) {
21094
- process.stdout.write(chalk8.green("Assistant> "));
21163
+ process.stdout.write(chalk9.green("Assistant> "));
21095
21164
  hasStartedResponse = true;
21096
21165
  }
21097
21166
  process.stdout.write(content[currentPos]);
@@ -21111,7 +21180,7 @@ async function chatCommandEnhanced(graphIdInput, options) {
21111
21180
  if (hasStartedResponse) {
21112
21181
  console.log("\n");
21113
21182
  } else {
21114
- console.log(`${chalk8.green("Assistant> ") + chalk8.gray("(no response)")}
21183
+ console.log(`${chalk9.green("Assistant> ") + chalk9.gray("(no response)")}
21115
21184
  `);
21116
21185
  }
21117
21186
  return responseContent;
@@ -21120,47 +21189,47 @@ async function chatCommandEnhanced(graphIdInput, options) {
21120
21189
  const trimmedInput = input.trim();
21121
21190
  const command = trimmedInput.toLowerCase().replace(/^\//, "");
21122
21191
  if (command === "exit") {
21123
- console.log(chalk8.gray("Goodbye! \u{1F44B}"));
21192
+ console.log(chalk9.gray("Goodbye! \u{1F44B}"));
21124
21193
  rl.close();
21125
21194
  process.exit(0);
21126
21195
  }
21127
21196
  if (command === "clear") {
21128
21197
  console.clear();
21129
- console.log(chalk8.gray("Screen cleared. Conversation context preserved.\n"));
21198
+ console.log(chalk9.gray("Screen cleared. Conversation context preserved.\n"));
21130
21199
  rl.prompt();
21131
21200
  return;
21132
21201
  }
21133
21202
  if (command === "help") {
21134
- console.log(chalk8.cyan("\n\u{1F4DA} Available commands:"));
21135
- console.log(chalk8.gray(" \u2022 exit - End the chat session"));
21136
- console.log(chalk8.gray(" \u2022 clear - Clear the screen (preserves context)"));
21137
- console.log(chalk8.gray(" \u2022 history - Show conversation history"));
21138
- console.log(chalk8.gray(" \u2022 reset - Reset conversation context"));
21139
- console.log(chalk8.gray(" \u2022 debug - Toggle debug mode (show/hide data operations)"));
21140
- console.log(chalk8.gray(" \u2022 help - Show this help message"));
21141
- console.log(chalk8.gray("\n Commands can be prefixed with / (e.g., /help)\n"));
21203
+ console.log(chalk9.cyan("\n\u{1F4DA} Available commands:"));
21204
+ console.log(chalk9.gray(" \u2022 exit - End the chat session"));
21205
+ console.log(chalk9.gray(" \u2022 clear - Clear the screen (preserves context)"));
21206
+ console.log(chalk9.gray(" \u2022 history - Show conversation history"));
21207
+ console.log(chalk9.gray(" \u2022 reset - Reset conversation context"));
21208
+ console.log(chalk9.gray(" \u2022 debug - Toggle debug mode (show/hide data operations)"));
21209
+ console.log(chalk9.gray(" \u2022 help - Show this help message"));
21210
+ console.log(chalk9.gray("\n Commands can be prefixed with / (e.g., /help)\n"));
21142
21211
  rl.prompt();
21143
21212
  return;
21144
21213
  }
21145
21214
  if (command === "debug") {
21146
21215
  debugMode = !debugMode;
21147
- console.log(chalk8.yellow(`
21216
+ console.log(chalk9.yellow(`
21148
21217
  \u{1F527} Debug mode: ${debugMode ? "ON" : "OFF"}`));
21149
21218
  if (debugMode) {
21150
- console.log(chalk8.gray("Data operations will be shown during responses.\n"));
21219
+ console.log(chalk9.gray("Data operations will be shown during responses.\n"));
21151
21220
  } else {
21152
- console.log(chalk8.gray("Data operations are hidden.\n"));
21221
+ console.log(chalk9.gray("Data operations are hidden.\n"));
21153
21222
  }
21154
21223
  rl.prompt();
21155
21224
  return;
21156
21225
  }
21157
21226
  if (command === "history") {
21158
- console.log(chalk8.cyan("\n\u{1F4DC} Conversation History:"));
21227
+ console.log(chalk9.cyan("\n\u{1F4DC} Conversation History:"));
21159
21228
  if (messages2.length === 0) {
21160
- console.log(chalk8.gray(" (No messages yet)\n"));
21229
+ console.log(chalk9.gray(" (No messages yet)\n"));
21161
21230
  } else {
21162
21231
  messages2.forEach((msg, idx) => {
21163
- const role = msg.role === "user" ? chalk8.blue("You") : chalk8.green("Assistant");
21232
+ const role = msg.role === "user" ? chalk9.blue("You") : chalk9.green("Assistant");
21164
21233
  const preview = msg.content.substring(0, 100);
21165
21234
  const suffix = msg.content.length > 100 ? "..." : "";
21166
21235
  console.log(` ${idx + 1}. ${role}: ${preview}${suffix}`);
@@ -21172,7 +21241,7 @@ async function chatCommandEnhanced(graphIdInput, options) {
21172
21241
  }
21173
21242
  if (command === "reset") {
21174
21243
  messages2.length = 0;
21175
- console.log(chalk8.yellow("\u26A0\uFE0F Conversation context has been reset.\n"));
21244
+ console.log(chalk9.yellow("\u26A0\uFE0F Conversation context has been reset.\n"));
21176
21245
  rl.prompt();
21177
21246
  return;
21178
21247
  }
@@ -21186,23 +21255,23 @@ async function chatCommandEnhanced(graphIdInput, options) {
21186
21255
  const response = await executionApi.chatCompletion(graphId, messages2, conversationId);
21187
21256
  let assistantResponse;
21188
21257
  if (typeof response === "string") {
21189
- console.log(chalk8.green("Assistant>"), response);
21258
+ console.log(chalk9.green("Assistant>"), response);
21190
21259
  assistantResponse = response;
21191
21260
  } else {
21192
21261
  assistantResponse = await handleStreamingResponse(response, debugMode);
21193
21262
  }
21194
21263
  messages2.push({ role: "assistant", content: assistantResponse });
21195
21264
  } catch (error) {
21196
- console.error(chalk8.red("Error:"), error instanceof Error ? error.message : error);
21265
+ console.error(chalk9.red("Error:"), error instanceof Error ? error.message : error);
21197
21266
  }
21198
21267
  rl.prompt();
21199
21268
  });
21200
21269
  rl.on("close", () => {
21201
- console.log(chalk8.gray("\n\u{1F4CA} Session Summary:"));
21202
- console.log(chalk8.gray(` \u2022 Graph: ${graphId}`));
21203
- console.log(chalk8.gray(` \u2022 Messages: ${messages2.length}`));
21204
- console.log(chalk8.gray(` \u2022 Duration: ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`));
21205
- console.log(chalk8.gray("\nChat session ended."));
21270
+ console.log(chalk9.gray("\n\u{1F4CA} Session Summary:"));
21271
+ console.log(chalk9.gray(` \u2022 Graph: ${graphId}`));
21272
+ console.log(chalk9.gray(` \u2022 Messages: ${messages2.length}`));
21273
+ console.log(chalk9.gray(` \u2022 Duration: ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`));
21274
+ console.log(chalk9.gray("\nChat session ended."));
21206
21275
  process.exit(0);
21207
21276
  });
21208
21277
  rl.prompt();
@@ -21212,13 +21281,41 @@ var init_chat_enhanced = __esm({
21212
21281
  "use strict";
21213
21282
  init_esm_shims();
21214
21283
  init_api();
21215
- init_config();
21284
+ init_cli_pipeline();
21216
21285
  }
21217
21286
  });
21218
21287
 
21219
21288
  // src/index.ts
21220
21289
  init_esm_shims();
21221
- init_env2();
21290
+
21291
+ // src/env.ts
21292
+ init_esm_shims();
21293
+ init_src();
21294
+ import { z as z10 } from "zod";
21295
+ loadEnvironmentFiles();
21296
+ var envSchema2 = z10.object({
21297
+ DEBUG: z10.string().optional(),
21298
+ // Secrets loaded from .env files (relative to where CLI is executed)
21299
+ ANTHROPIC_API_KEY: z10.string().optional()
21300
+ });
21301
+ var parseEnv2 = () => {
21302
+ try {
21303
+ const parsedEnv = envSchema2.parse(process.env);
21304
+ return parsedEnv;
21305
+ } catch (error) {
21306
+ if (error instanceof z10.ZodError) {
21307
+ const missingVars = error.issues.map((issue) => issue.path.join("."));
21308
+ throw new Error(
21309
+ `\u274C Invalid environment variables: ${missingVars.join(", ")}
21310
+ ${error.message}`
21311
+ );
21312
+ }
21313
+ throw error;
21314
+ }
21315
+ };
21316
+ var env2 = parseEnv2();
21317
+
21318
+ // src/index.ts
21222
21319
  import { readFileSync as readFileSync3 } from "fs";
21223
21320
  import { dirname as dirname5, join as join10 } from "path";
21224
21321
  import { fileURLToPath as fileURLToPath2 } from "url";
@@ -21748,8 +21845,12 @@ async function initCommand(options) {
21748
21845
 
21749
21846
  export default defineConfig({
21750
21847
  tenantId: '${answers.tenantId}',
21751
- agentsManageApiUrl: '${answers.apiUrl}',
21752
- agentsRunApiUrl: '${answers.apiUrl}',
21848
+ agentsManageApi: {
21849
+ url: '${answers.apiUrl}',
21850
+ },
21851
+ agentsRunApi: {
21852
+ url: '${answers.apiUrl}',
21853
+ },
21753
21854
  });
21754
21855
  `;
21755
21856
  try {
@@ -21774,30 +21875,18 @@ Note: Config file created in ${configDir}`));
21774
21875
  // src/commands/list-graphs.ts
21775
21876
  init_esm_shims();
21776
21877
  init_api();
21777
- init_config();
21778
- import chalk5 from "chalk";
21878
+ init_cli_pipeline();
21879
+ import chalk6 from "chalk";
21779
21880
  import Table from "cli-table3";
21780
- import ora3 from "ora";
21881
+ import ora4 from "ora";
21781
21882
  async function listGraphsCommand(options) {
21782
- let config;
21783
- try {
21784
- const configPath2 = options.config || options.configFilePath;
21785
- config = await validateConfiguration(
21786
- options.tenantId,
21787
- options.agentsManageApiUrl,
21788
- void 0,
21789
- // agentsRunApiUrl not needed for list-graphs
21790
- configPath2
21791
- );
21792
- } catch (error) {
21793
- console.error(chalk5.red(error.message));
21794
- process.exit(1);
21795
- }
21796
- console.log(chalk5.gray("Using configuration:"));
21797
- console.log(chalk5.gray(` \u2022 Tenant ID: ${config.sources.tenantId}`));
21798
- console.log(chalk5.gray(` \u2022 API URL: ${config.sources.agentsManageApiUrl}`));
21799
- console.log();
21800
21883
  const configPath = options.config || options.configFilePath;
21884
+ const { config } = await initializeCommand({
21885
+ configPath,
21886
+ showSpinner: false,
21887
+ logConfig: true
21888
+ });
21889
+ console.log();
21801
21890
  const api = await ManagementApiClient.create(
21802
21891
  config.agentsManageApiUrl,
21803
21892
  configPath,
@@ -21805,22 +21894,24 @@ async function listGraphsCommand(options) {
21805
21894
  options.project
21806
21895
  // pass project ID as projectIdOverride
21807
21896
  );
21808
- const spinner = ora3("Fetching graphs...").start();
21897
+ const spinner = ora4("Fetching graphs...").start();
21809
21898
  try {
21810
21899
  const graphs = await api.listGraphs();
21811
21900
  spinner.succeed(`Found ${graphs.length} graph(s) in project "${options.project}"`);
21812
21901
  if (graphs.length === 0) {
21813
21902
  console.log(
21814
- chalk5.gray(`No graphs found in project "${options.project}". Define graphs in your project and run: inkeep push`)
21903
+ chalk6.gray(
21904
+ `No graphs found in project "${options.project}". Define graphs in your project and run: inkeep push`
21905
+ )
21815
21906
  );
21816
21907
  return;
21817
21908
  }
21818
21909
  const table = new Table({
21819
21910
  head: [
21820
- chalk5.cyan("Graph ID"),
21821
- chalk5.cyan("Name"),
21822
- chalk5.cyan("Default Agent"),
21823
- chalk5.cyan("Created")
21911
+ chalk6.cyan("Graph ID"),
21912
+ chalk6.cyan("Name"),
21913
+ chalk6.cyan("Default Agent"),
21914
+ chalk6.cyan("Created")
21824
21915
  ],
21825
21916
  style: {
21826
21917
  head: [],
@@ -21832,7 +21923,7 @@ async function listGraphsCommand(options) {
21832
21923
  table.push([
21833
21924
  graph.id || "",
21834
21925
  graph.name || graph.id || "",
21835
- graph.defaultAgentId || chalk5.gray("None"),
21926
+ graph.defaultAgentId || chalk6.gray("None"),
21836
21927
  createdDate
21837
21928
  ]);
21838
21929
  }
@@ -21840,20 +21931,20 @@ async function listGraphsCommand(options) {
21840
21931
  ${table.toString()}`);
21841
21932
  } catch (error) {
21842
21933
  spinner.fail("Failed to fetch graphs");
21843
- console.error(chalk5.red("Error:"), error instanceof Error ? error.message : error);
21934
+ console.error(chalk6.red("Error:"), error instanceof Error ? error.message : error);
21844
21935
  process.exit(1);
21845
21936
  }
21846
21937
  }
21847
21938
 
21848
21939
  // src/commands/pull.ts
21849
21940
  init_esm_shims();
21850
- init_env2();
21851
- init_tsx_loader();
21941
+ init_api();
21852
21942
  import { existsSync as existsSync6, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync4 } from "fs";
21853
21943
  import { dirname as dirname4, join as join7, resolve as resolve4 } from "path";
21854
- import chalk6 from "chalk";
21855
- import ora4 from "ora";
21944
+ import chalk7 from "chalk";
21945
+ import ora5 from "ora";
21856
21946
  import prompts from "prompts";
21947
+ init_config();
21857
21948
 
21858
21949
  // src/utils/project-directory.ts
21859
21950
  init_esm_shims();
@@ -21888,6 +21979,9 @@ async function findProjectDirectory(projectId, configPath) {
21888
21979
  return null;
21889
21980
  }
21890
21981
 
21982
+ // src/commands/pull.ts
21983
+ init_tsx_loader();
21984
+
21891
21985
  // src/commands/pull.llm-generate.ts
21892
21986
  init_esm_shims();
21893
21987
  import { writeFileSync as writeFileSync3 } from "fs";
@@ -22670,7 +22764,7 @@ export { ${exportStatement} };
22670
22764
  }
22671
22765
 
22672
22766
  // src/commands/pull.ts
22673
- async function verifyGeneratedFiles(projectDir, originalProjectData, debug = false, config) {
22767
+ async function verifyGeneratedFiles(projectDir, originalProjectData, debug = false) {
22674
22768
  const errors = [];
22675
22769
  const warnings = [];
22676
22770
  try {
@@ -22706,20 +22800,32 @@ async function verifyGeneratedFiles(projectDir, originalProjectData, debug = fal
22706
22800
  try {
22707
22801
  const generatedProjectData = await project.toFullProjectDefinition();
22708
22802
  if (debug) {
22709
- console.log(chalk6.gray("\n\u{1F4CB} Generated project successfully"));
22710
- console.log(chalk6.gray(` \u2022 Has tools: ${!!generatedProjectData.tools}`));
22711
- console.log(chalk6.gray(` \u2022 Tools count: ${Object.keys(generatedProjectData.tools || {}).length}`));
22712
- console.log(chalk6.gray(` \u2022 Has credentials: ${!!generatedProjectData.credentialReferences}`));
22713
- console.log(chalk6.gray(` \u2022 Credentials count: ${Object.keys(generatedProjectData.credentialReferences || {}).length}`));
22803
+ console.log(chalk7.gray("\n\u{1F4CB} Generated project successfully"));
22804
+ console.log(chalk7.gray(` \u2022 Has tools: ${!!generatedProjectData.tools}`));
22805
+ console.log(
22806
+ chalk7.gray(` \u2022 Tools count: ${Object.keys(generatedProjectData.tools || {}).length}`)
22807
+ );
22808
+ console.log(
22809
+ chalk7.gray(` \u2022 Has credentials: ${!!generatedProjectData.credentialReferences}`)
22810
+ );
22811
+ console.log(
22812
+ chalk7.gray(
22813
+ ` \u2022 Credentials count: ${Object.keys(generatedProjectData.credentialReferences || {}).length}`
22814
+ )
22815
+ );
22714
22816
  }
22715
22817
  if (!generatedProjectData) {
22716
22818
  structuralErrors.push("Generated project definition is empty");
22717
22819
  }
22718
22820
  } catch (projectDefError) {
22719
22821
  if (debug) {
22720
- console.log(chalk6.yellow(` Project definition generation warning: ${projectDefError.message}`));
22822
+ console.log(
22823
+ chalk7.yellow(` Project definition generation warning: ${projectDefError.message}`)
22824
+ );
22721
22825
  }
22722
- structuralWarnings.push(`Project definition generation had issues: ${projectDefError.message}`);
22826
+ structuralWarnings.push(
22827
+ `Project definition generation had issues: ${projectDefError.message}`
22828
+ );
22723
22829
  }
22724
22830
  }
22725
22831
  const toolPath = join7(projectDir, "tools", "inkeep_facts.ts");
@@ -22733,12 +22839,20 @@ async function verifyGeneratedFiles(projectDir, originalProjectData, debug = fal
22733
22839
  structuralErrors.push("Tool file missing required serverUrl property");
22734
22840
  }
22735
22841
  if (toolContent.includes("config:")) {
22736
- structuralWarnings.push("Tool file contains invalid config property (should use individual properties)");
22842
+ structuralWarnings.push(
22843
+ "Tool file contains invalid config property (should use individual properties)"
22844
+ );
22737
22845
  }
22738
22846
  if (debug) {
22739
- console.log(chalk6.gray(` \u2022 Tool file has serverUrl: ${toolContent.includes("serverUrl:")}`));
22740
- console.log(chalk6.gray(` \u2022 Tool file has credential: ${toolContent.includes("credential:")}`));
22741
- console.log(chalk6.gray(` \u2022 Tool file has invalid config: ${toolContent.includes("config:")}`));
22847
+ console.log(
22848
+ chalk7.gray(` \u2022 Tool file has serverUrl: ${toolContent.includes("serverUrl:")}`)
22849
+ );
22850
+ console.log(
22851
+ chalk7.gray(` \u2022 Tool file has credential: ${toolContent.includes("credential:")}`)
22852
+ );
22853
+ console.log(
22854
+ chalk7.gray(` \u2022 Tool file has invalid config: ${toolContent.includes("config:")}`)
22855
+ );
22742
22856
  }
22743
22857
  } else {
22744
22858
  structuralErrors.push("Tool file inkeep_facts.ts not found");
@@ -22749,7 +22863,11 @@ async function verifyGeneratedFiles(projectDir, originalProjectData, debug = fal
22749
22863
  structuralWarnings.push("Environment file may be missing credential definition");
22750
22864
  }
22751
22865
  if (debug) {
22752
- console.log(chalk6.gray(` \u2022 Environment file has credential: ${envContent.includes("inkeep_api_credential")}`));
22866
+ console.log(
22867
+ chalk7.gray(
22868
+ ` \u2022 Environment file has credential: ${envContent.includes("inkeep_api_credential")}`
22869
+ )
22870
+ );
22753
22871
  }
22754
22872
  } else {
22755
22873
  structuralErrors.push("Environment file development.env.ts not found");
@@ -22760,11 +22878,19 @@ async function verifyGeneratedFiles(projectDir, originalProjectData, debug = fal
22760
22878
  errors.push(...structuralErrors);
22761
22879
  warnings.push(...structuralWarnings);
22762
22880
  if (debug) {
22763
- console.log(chalk6.gray("\n\u{1F50D} Structural Verification Summary:"));
22764
- console.log(chalk6.gray(` \u2022 Project loaded successfully: ${!!project}`));
22765
- console.log(chalk6.gray(` \u2022 Expected graphs: ${Object.keys(originalProjectData.graphs || {}).length}`));
22766
- console.log(chalk6.gray(` \u2022 Expected tools: ${Object.keys(originalProjectData.tools || {}).length}`));
22767
- console.log(chalk6.gray(` \u2022 Expected credentials: ${Object.keys(originalProjectData.credentialReferences || {}).length}`));
22881
+ console.log(chalk7.gray("\n\u{1F50D} Structural Verification Summary:"));
22882
+ console.log(chalk7.gray(` \u2022 Project loaded successfully: ${!!project}`));
22883
+ console.log(
22884
+ chalk7.gray(` \u2022 Expected graphs: ${Object.keys(originalProjectData.graphs || {}).length}`)
22885
+ );
22886
+ console.log(
22887
+ chalk7.gray(` \u2022 Expected tools: ${Object.keys(originalProjectData.tools || {}).length}`)
22888
+ );
22889
+ console.log(
22890
+ chalk7.gray(
22891
+ ` \u2022 Expected credentials: ${Object.keys(originalProjectData.credentialReferences || {}).length}`
22892
+ )
22893
+ );
22768
22894
  }
22769
22895
  return { success: errors.length === 0, errors, warnings };
22770
22896
  } catch (error) {
@@ -22778,39 +22904,26 @@ async function loadProjectConfig(projectDir, configPathOverride) {
22778
22904
  throw new Error(`Configuration file not found: ${configPath}`);
22779
22905
  }
22780
22906
  try {
22781
- const configModule = await importWithTypeScriptSupport(configPath);
22782
- const config = configModule.default || configModule.config;
22783
- if (!config) {
22784
- throw new Error("No configuration found in inkeep.config.ts");
22785
- }
22907
+ const config = await loadConfig(configPath);
22786
22908
  if (!config.tenantId) {
22787
22909
  throw new Error("tenantId is required in inkeep.config.ts");
22788
22910
  }
22789
22911
  return {
22790
22912
  tenantId: config.tenantId,
22791
- agentsManageApiUrl: config.agentsManageApiUrl || "http://localhost:3002",
22913
+ agentsManageApi: {
22914
+ url: config.agentsManageApiUrl || "http://localhost:3002",
22915
+ ...config.agentsManageApiKey && { apiKey: config.agentsManageApiKey }
22916
+ },
22917
+ agentsRunApi: {
22918
+ url: config.agentsRunApiUrl || "http://localhost:3003",
22919
+ ...config.agentsRunApiKey && { apiKey: config.agentsRunApiKey }
22920
+ },
22792
22921
  outputDirectory: config.outputDirectory
22793
22922
  };
22794
22923
  } catch (error) {
22795
22924
  throw new Error(`Failed to load configuration: ${error.message}`);
22796
22925
  }
22797
22926
  }
22798
- async function fetchProjectData(tenantId, projectId, apiUrl) {
22799
- const response = await fetch(`${apiUrl}/tenants/${tenantId}/project-full/${projectId}`, {
22800
- method: "GET",
22801
- headers: {
22802
- Accept: "application/json"
22803
- }
22804
- });
22805
- if (!response.ok) {
22806
- if (response.status === 404) {
22807
- throw new Error(`Project "${projectId}" not found`);
22808
- }
22809
- throw new Error(`Failed to fetch project: ${response.statusText}`);
22810
- }
22811
- const responseData = await response.json();
22812
- return responseData.data;
22813
- }
22814
22927
  function ensureDirectoryExists(dirPath) {
22815
22928
  if (!existsSync6(dirPath)) {
22816
22929
  mkdirSync(dirPath, { recursive: true });
@@ -22863,49 +22976,60 @@ async function generateProjectFiles(dirs, projectData, modelSettings, environmen
22863
22976
  if (dataComponents2 && Object.keys(dataComponents2).length > 0) {
22864
22977
  for (const [componentId, componentData] of Object.entries(dataComponents2)) {
22865
22978
  const componentPath = join7(dirs.dataComponentsDir, `${componentId}.ts`);
22866
- generationTasks.push(generateDataComponentFile(componentData, componentId, componentPath, modelSettings));
22979
+ generationTasks.push(
22980
+ generateDataComponentFile(componentData, componentId, componentPath, modelSettings)
22981
+ );
22867
22982
  fileInfo.push({ type: "dataComponent", name: `${componentId}.ts` });
22868
22983
  }
22869
22984
  }
22870
22985
  if (artifactComponents2 && Object.keys(artifactComponents2).length > 0) {
22871
22986
  for (const [componentId, componentData] of Object.entries(artifactComponents2)) {
22872
22987
  const componentPath = join7(dirs.artifactComponentsDir, `${componentId}.ts`);
22873
- generationTasks.push(generateArtifactComponentFile(componentData, componentId, componentPath, modelSettings));
22988
+ generationTasks.push(
22989
+ generateArtifactComponentFile(componentData, componentId, componentPath, modelSettings)
22990
+ );
22874
22991
  fileInfo.push({ type: "artifactComponent", name: `${componentId}.ts` });
22875
22992
  }
22876
22993
  }
22877
22994
  const targetEnvironment = environment;
22878
- generationTasks.push(generateEnvironmentFiles(dirs.environmentsDir, credentialReferences2, targetEnvironment));
22995
+ generationTasks.push(
22996
+ generateEnvironmentFiles(dirs.environmentsDir, credentialReferences2, targetEnvironment)
22997
+ );
22879
22998
  fileInfo.push({ type: "env", name: `index.ts, ${targetEnvironment}.env.ts` });
22880
- console.log(chalk6.cyan(" \u{1F4DD} Generating files in parallel:"));
22881
- const filesByType = fileInfo.reduce((acc, file) => {
22882
- if (!acc[file.type]) acc[file.type] = [];
22883
- acc[file.type].push(file.name);
22884
- return acc;
22885
- }, {});
22999
+ console.log(chalk7.cyan(" \u{1F4DD} Generating files in parallel:"));
23000
+ const filesByType = fileInfo.reduce(
23001
+ (acc, file) => {
23002
+ if (!acc[file.type]) acc[file.type] = [];
23003
+ acc[file.type].push(file.name);
23004
+ return acc;
23005
+ },
23006
+ {}
23007
+ );
22886
23008
  if (filesByType.config) {
22887
- console.log(chalk6.gray(` \u2022 Config files: ${filesByType.config.join(", ")}`));
23009
+ console.log(chalk7.gray(` \u2022 Config files: ${filesByType.config.join(", ")}`));
22888
23010
  }
22889
23011
  if (filesByType.graph) {
22890
- console.log(chalk6.gray(` \u2022 Graphs: ${filesByType.graph.join(", ")}`));
23012
+ console.log(chalk7.gray(` \u2022 Graphs: ${filesByType.graph.join(", ")}`));
22891
23013
  }
22892
23014
  if (filesByType.tool) {
22893
- console.log(chalk6.gray(` \u2022 Tools: ${filesByType.tool.join(", ")}`));
23015
+ console.log(chalk7.gray(` \u2022 Tools: ${filesByType.tool.join(", ")}`));
22894
23016
  }
22895
23017
  if (filesByType.dataComponent) {
22896
- console.log(chalk6.gray(` \u2022 Data components: ${filesByType.dataComponent.join(", ")}`));
23018
+ console.log(chalk7.gray(` \u2022 Data components: ${filesByType.dataComponent.join(", ")}`));
22897
23019
  }
22898
23020
  if (filesByType.artifactComponent) {
22899
- console.log(chalk6.gray(` \u2022 Artifact components: ${filesByType.artifactComponent.join(", ")}`));
23021
+ console.log(
23022
+ chalk7.gray(` \u2022 Artifact components: ${filesByType.artifactComponent.join(", ")}`)
23023
+ );
22900
23024
  }
22901
23025
  if (filesByType.env) {
22902
- console.log(chalk6.gray(` \u2022 Environment: ${filesByType.env.join(", ")}`));
23026
+ console.log(chalk7.gray(` \u2022 Environment: ${filesByType.env.join(", ")}`));
22903
23027
  }
22904
- console.log(chalk6.yellow(` \u26A1 Processing ${generationTasks.length} files in parallel...`));
23028
+ console.log(chalk7.yellow(` \u26A1 Processing ${generationTasks.length} files in parallel...`));
22905
23029
  if (debug) {
22906
- console.log(chalk6.gray("\n\u{1F4CD} Debug: Starting LLM file generation..."));
22907
- console.log(chalk6.gray(` Model: ${modelSettings.model}`));
22908
- console.log(chalk6.gray(` Total tasks: ${generationTasks.length}`));
23030
+ console.log(chalk7.gray("\n\u{1F4CD} Debug: Starting LLM file generation..."));
23031
+ console.log(chalk7.gray(` Model: ${modelSettings.model}`));
23032
+ console.log(chalk7.gray(` Total tasks: ${generationTasks.length}`));
22909
23033
  const startTime = Date.now();
22910
23034
  try {
22911
23035
  await Promise.all(
@@ -22913,24 +23037,32 @@ async function generateProjectFiles(dirs, projectData, modelSettings, environmen
22913
23037
  const taskStartTime = Date.now();
22914
23038
  if (debug) {
22915
23039
  const taskInfo = fileInfo[index2];
22916
- console.log(chalk6.gray(` [${index2 + 1}/${generationTasks.length}] Starting ${taskInfo.type}: ${taskInfo.name}`));
23040
+ console.log(
23041
+ chalk7.gray(
23042
+ ` [${index2 + 1}/${generationTasks.length}] Starting ${taskInfo.type}: ${taskInfo.name}`
23043
+ )
23044
+ );
22917
23045
  }
22918
23046
  await task;
22919
23047
  if (debug) {
22920
23048
  const taskInfo = fileInfo[index2];
22921
23049
  const taskDuration = Date.now() - taskStartTime;
22922
- console.log(chalk6.gray(` [${index2 + 1}/${generationTasks.length}] \u2713 Completed ${taskInfo.type}: ${taskInfo.name} (${taskDuration}ms)`));
23050
+ console.log(
23051
+ chalk7.gray(
23052
+ ` [${index2 + 1}/${generationTasks.length}] \u2713 Completed ${taskInfo.type}: ${taskInfo.name} (${taskDuration}ms)`
23053
+ )
23054
+ );
22923
23055
  }
22924
23056
  })
22925
23057
  );
22926
23058
  } catch (error) {
22927
23059
  if (debug) {
22928
- console.error(chalk6.red("\u{1F4CD} Debug: LLM generation error:"), error);
23060
+ console.error(chalk7.red("\u{1F4CD} Debug: LLM generation error:"), error);
22929
23061
  }
22930
23062
  throw error;
22931
23063
  }
22932
23064
  const totalDuration = Date.now() - startTime;
22933
- console.log(chalk6.gray(`
23065
+ console.log(chalk7.gray(`
22934
23066
  \u{1F4CD} Debug: LLM generation completed in ${totalDuration}ms`));
22935
23067
  } else {
22936
23068
  await Promise.all(generationTasks);
@@ -22939,14 +23071,14 @@ async function generateProjectFiles(dirs, projectData, modelSettings, environmen
22939
23071
  async function pullProjectCommand(options) {
22940
23072
  if (!env2.ANTHROPIC_API_KEY) {
22941
23073
  console.error(
22942
- chalk6.red("Error: ANTHROPIC_API_KEY environment variable is required for the pull command.")
23074
+ chalk7.red("Error: ANTHROPIC_API_KEY environment variable is required for the pull command.")
22943
23075
  );
22944
- console.error(chalk6.gray("Please set your Anthropic API key:"));
22945
- console.error(chalk6.gray(" export ANTHROPIC_API_KEY=your_api_key_here"));
22946
- console.error(chalk6.gray(" or add it to your .env file"));
23076
+ console.error(chalk7.gray("Please set your Anthropic API key:"));
23077
+ console.error(chalk7.gray(" export ANTHROPIC_API_KEY=your_api_key_here"));
23078
+ console.error(chalk7.gray(" or add it to your .env file"));
22947
23079
  process.exit(1);
22948
23080
  }
22949
- const spinner = ora4("Loading configuration...").start();
23081
+ const spinner = ora5("Loading configuration...").start();
22950
23082
  try {
22951
23083
  let config = null;
22952
23084
  let configFound = false;
@@ -22961,7 +23093,9 @@ async function pullProjectCommand(options) {
22961
23093
  configLocation = configPath;
22962
23094
  } catch (error) {
22963
23095
  spinner.fail("Failed to load specified configuration file");
22964
- console.error(chalk6.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
23096
+ console.error(
23097
+ chalk7.red(`Error: ${error instanceof Error ? error.message : String(error)}`)
23098
+ );
22965
23099
  process.exit(1);
22966
23100
  }
22967
23101
  } else {
@@ -23008,12 +23142,14 @@ async function pullProjectCommand(options) {
23008
23142
  }
23009
23143
  if (!configFound || !config) {
23010
23144
  spinner.fail("No inkeep.config.ts found");
23011
- console.error(chalk6.red("Configuration file is required for pull command"));
23012
- console.log(chalk6.yellow("Please create an inkeep.config.ts file with your tenantId and API settings"));
23013
- console.log(chalk6.gray("Searched in:"));
23014
- console.log(chalk6.gray(` \u2022 Current directory: ${searchDir}`));
23015
- console.log(chalk6.gray(` \u2022 Parent directory: ${join7(searchDir, "..")}`));
23016
- console.log(chalk6.gray(` \u2022 Parent directories up to root`));
23145
+ console.error(chalk7.red("Configuration file is required for pull command"));
23146
+ console.log(
23147
+ chalk7.yellow("Please create an inkeep.config.ts file with your tenantId and API settings")
23148
+ );
23149
+ console.log(chalk7.gray("Searched in:"));
23150
+ console.log(chalk7.gray(` \u2022 Current directory: ${searchDir}`));
23151
+ console.log(chalk7.gray(` \u2022 Parent directory: ${join7(searchDir, "..")}`));
23152
+ console.log(chalk7.gray(` \u2022 Parent directories up to root`));
23017
23153
  process.exit(1);
23018
23154
  }
23019
23155
  spinner.succeed(`Configuration loaded from ${configLocation}`);
@@ -23035,10 +23171,10 @@ async function pullProjectCommand(options) {
23035
23171
  spinner.succeed(`Output directory: ${baseDir}`);
23036
23172
  const finalConfig = {
23037
23173
  tenantId: config.tenantId,
23038
- // Tenant ID comes from config, not env flag
23039
23174
  projectId: "",
23040
23175
  // Will be determined from API response or user input
23041
- agentsManageApiUrl: options.agentsManageApiUrl || config.agentsManageApiUrl
23176
+ agentsManageApiUrl: config.agentsManageApi.url,
23177
+ agentsManageApiKey: config.agentsManageApi.apiKey
23042
23178
  };
23043
23179
  if (!options.project) {
23044
23180
  spinner.stop();
@@ -23049,7 +23185,7 @@ async function pullProjectCommand(options) {
23049
23185
  validate: (value) => value ? true : "Project ID is required"
23050
23186
  });
23051
23187
  if (!response.projectId) {
23052
- console.error(chalk6.red("Project ID is required"));
23188
+ console.error(chalk7.red("Project ID is required"));
23053
23189
  process.exit(1);
23054
23190
  }
23055
23191
  finalConfig.projectId = response.projectId;
@@ -23059,16 +23195,19 @@ async function pullProjectCommand(options) {
23059
23195
  finalConfig.projectId = projectIdFromPath;
23060
23196
  }
23061
23197
  spinner.succeed("Configuration loaded");
23062
- console.log(chalk6.gray("Configuration:"));
23063
- console.log(chalk6.gray(` \u2022 Tenant ID: ${finalConfig.tenantId}`));
23064
- console.log(chalk6.gray(` \u2022 Project ID: ${finalConfig.projectId}`));
23065
- console.log(chalk6.gray(` \u2022 API URL: ${finalConfig.agentsManageApiUrl}`));
23198
+ console.log(chalk7.gray("Configuration:"));
23199
+ console.log(chalk7.gray(` \u2022 Tenant ID: ${finalConfig.tenantId}`));
23200
+ console.log(chalk7.gray(` \u2022 Project ID: ${finalConfig.projectId}`));
23201
+ console.log(chalk7.gray(` \u2022 API URL: ${finalConfig.agentsManageApiUrl}`));
23066
23202
  spinner.start("Fetching project data from backend...");
23067
- const projectData = await fetchProjectData(
23203
+ const apiClient = await ManagementApiClient.create(
23204
+ finalConfig.agentsManageApiUrl,
23205
+ options.config,
23206
+ // Pass the config path from options
23068
23207
  finalConfig.tenantId,
23069
- finalConfig.projectId,
23070
- finalConfig.agentsManageApiUrl
23208
+ finalConfig.projectId
23071
23209
  );
23210
+ const projectData = await apiClient.getFullProject(finalConfig.projectId);
23072
23211
  spinner.succeed("Project data fetched");
23073
23212
  const graphCount = Object.keys(projectData.graphs || {}).length;
23074
23213
  const toolCount = Object.keys(projectData.tools || {}).length;
@@ -23080,27 +23219,27 @@ async function pullProjectCommand(options) {
23080
23219
  );
23081
23220
  const dataComponentCount = Object.keys(projectData.dataComponents || {}).length;
23082
23221
  const artifactComponentCount = Object.keys(projectData.artifactComponents || {}).length;
23083
- console.log(chalk6.cyan("\n\u{1F4CA} Project Summary:"));
23084
- console.log(chalk6.gray(` \u2022 Name: ${projectData.name}`));
23085
- console.log(chalk6.gray(` \u2022 Description: ${projectData.description || "No description"}`));
23086
- console.log(chalk6.gray(` \u2022 Graphs: ${graphCount}`));
23087
- console.log(chalk6.gray(` \u2022 Tools: ${toolCount}`));
23088
- console.log(chalk6.gray(` \u2022 Agents: ${agentCount}`));
23222
+ console.log(chalk7.cyan("\n\u{1F4CA} Project Summary:"));
23223
+ console.log(chalk7.gray(` \u2022 Name: ${projectData.name}`));
23224
+ console.log(chalk7.gray(` \u2022 Description: ${projectData.description || "No description"}`));
23225
+ console.log(chalk7.gray(` \u2022 Graphs: ${graphCount}`));
23226
+ console.log(chalk7.gray(` \u2022 Tools: ${toolCount}`));
23227
+ console.log(chalk7.gray(` \u2022 Agents: ${agentCount}`));
23089
23228
  if (dataComponentCount > 0) {
23090
- console.log(chalk6.gray(` \u2022 Data Components: ${dataComponentCount}`));
23229
+ console.log(chalk7.gray(` \u2022 Data Components: ${dataComponentCount}`));
23091
23230
  }
23092
23231
  if (artifactComponentCount > 0) {
23093
- console.log(chalk6.gray(` \u2022 Artifact Components: ${artifactComponentCount}`));
23232
+ console.log(chalk7.gray(` \u2022 Artifact Components: ${artifactComponentCount}`));
23094
23233
  }
23095
23234
  const credentialReferences2 = projectData.credentialReferences || {};
23096
23235
  const credentialCount = Object.keys(credentialReferences2).length;
23097
23236
  if (credentialCount > 0) {
23098
- console.log(chalk6.cyan("\n\u{1F510} Credentials Found:"));
23099
- console.log(chalk6.gray(` \u2022 Total credentials: ${credentialCount}`));
23237
+ console.log(chalk7.cyan("\n\u{1F510} Credentials Found:"));
23238
+ console.log(chalk7.gray(` \u2022 Total credentials: ${credentialCount}`));
23100
23239
  for (const [credId, credData] of Object.entries(credentialReferences2)) {
23101
23240
  const credType = credData.type || "unknown";
23102
23241
  const storeId = credData.credentialStoreId || "unknown";
23103
- console.log(chalk6.gray(` \u2022 ${credId} (${credType}, store: ${storeId})`));
23242
+ console.log(chalk7.gray(` \u2022 ${credId} (${credType}, store: ${storeId})`));
23104
23243
  const usageInfo = credData.usedBy;
23105
23244
  if (usageInfo && Array.isArray(usageInfo) && usageInfo.length > 0) {
23106
23245
  const usageByType = {};
@@ -23108,10 +23247,14 @@ async function pullProjectCommand(options) {
23108
23247
  usageByType[usage.type] = (usageByType[usage.type] || 0) + 1;
23109
23248
  }
23110
23249
  const usageSummary = Object.entries(usageByType).map(([type, count15]) => `${count15} ${type}${count15 > 1 ? "s" : ""}`).join(", ");
23111
- console.log(chalk6.gray(` Used by: ${usageSummary}`));
23250
+ console.log(chalk7.gray(` Used by: ${usageSummary}`));
23112
23251
  }
23113
23252
  }
23114
- console.log(chalk6.yellow(` \u26A0\uFE0F Environment file (${options.env || "development"}.env.ts) will be generated with credential references`));
23253
+ console.log(
23254
+ chalk7.yellow(
23255
+ ` \u26A0\uFE0F Environment file (${options.env || "development"}.env.ts) will be generated with credential references`
23256
+ )
23257
+ );
23115
23258
  }
23116
23259
  spinner.start("Creating project structure...");
23117
23260
  const dirs = createProjectStructure(baseDir, finalConfig.projectId);
@@ -23120,13 +23263,19 @@ async function pullProjectCommand(options) {
23120
23263
  const jsonFilePath = join7(dirs.projectRoot, `${finalConfig.projectId}.json`);
23121
23264
  writeFileSync4(jsonFilePath, JSON.stringify(projectData, null, 2));
23122
23265
  spinner.succeed(`Project data saved to ${jsonFilePath}`);
23123
- console.log(chalk6.green(`\u2705 JSON file created: ${jsonFilePath}`));
23266
+ console.log(chalk7.green(`\u2705 JSON file created: ${jsonFilePath}`));
23124
23267
  }
23125
23268
  spinner.start("Generating project files with LLM...");
23126
23269
  const modelSettings = {
23127
23270
  model: "anthropic/claude-sonnet-4-20250514"
23128
23271
  };
23129
- await generateProjectFiles(dirs, projectData, modelSettings, options.env || "development", options.debug || false);
23272
+ await generateProjectFiles(
23273
+ dirs,
23274
+ projectData,
23275
+ modelSettings,
23276
+ options.env || "development",
23277
+ options.debug || false
23278
+ );
23130
23279
  const fileCount = {
23131
23280
  graphs: Object.keys(projectData.graphs || {}).length,
23132
23281
  tools: Object.keys(projectData.tools || {}).length,
@@ -23137,74 +23286,81 @@ async function pullProjectCommand(options) {
23137
23286
  spinner.succeed(`Project files generated (${totalFiles} files created)`);
23138
23287
  spinner.start("Verifying generated files...");
23139
23288
  try {
23140
- const verificationResult = await verifyGeneratedFiles(dirs.projectRoot, projectData, options.debug || false, config);
23289
+ const verificationResult = await verifyGeneratedFiles(
23290
+ dirs.projectRoot,
23291
+ projectData,
23292
+ options.debug || false
23293
+ );
23141
23294
  if (verificationResult.success) {
23142
23295
  spinner.succeed("Generated files verified successfully");
23143
23296
  if (options.debug && verificationResult.warnings.length > 0) {
23144
- console.log(chalk6.yellow("\n\u26A0\uFE0F Verification warnings:"));
23297
+ console.log(chalk7.yellow("\n\u26A0\uFE0F Verification warnings:"));
23145
23298
  verificationResult.warnings.forEach((warning) => {
23146
- console.log(chalk6.gray(` \u2022 ${warning}`));
23299
+ console.log(chalk7.gray(` \u2022 ${warning}`));
23147
23300
  });
23148
23301
  }
23149
23302
  } else {
23150
23303
  spinner.fail("Generated files verification failed");
23151
- console.error(chalk6.red("\n\u274C Verification errors:"));
23304
+ console.error(chalk7.red("\n\u274C Verification errors:"));
23152
23305
  verificationResult.errors.forEach((error) => {
23153
- console.error(chalk6.red(` \u2022 ${error}`));
23306
+ console.error(chalk7.red(` \u2022 ${error}`));
23154
23307
  });
23155
23308
  if (verificationResult.warnings.length > 0) {
23156
- console.log(chalk6.yellow("\n\u26A0\uFE0F Verification warnings:"));
23309
+ console.log(chalk7.yellow("\n\u26A0\uFE0F Verification warnings:"));
23157
23310
  verificationResult.warnings.forEach((warning) => {
23158
- console.log(chalk6.gray(` \u2022 ${warning}`));
23311
+ console.log(chalk7.gray(` \u2022 ${warning}`));
23159
23312
  });
23160
23313
  }
23161
- console.log(chalk6.gray("\nThe generated files may not accurately represent the pulled project."));
23162
- console.log(chalk6.gray("This could indicate an issue with the LLM generation or schema mappings."));
23314
+ console.log(
23315
+ chalk7.gray("\nThe generated files may not accurately represent the pulled project.")
23316
+ );
23317
+ console.log(
23318
+ chalk7.gray("This could indicate an issue with the LLM generation or schema mappings.")
23319
+ );
23163
23320
  }
23164
23321
  } catch (error) {
23165
23322
  spinner.fail("Verification failed");
23166
- console.error(chalk6.red("Verification error:"), error.message);
23167
- console.log(chalk6.gray("Proceeding without verification..."));
23323
+ console.error(chalk7.red("Verification error:"), error.message);
23324
+ console.log(chalk7.gray("Proceeding without verification..."));
23168
23325
  }
23169
- console.log(chalk6.green("\n\u2728 Project pulled successfully!"));
23170
- console.log(chalk6.cyan("\n\u{1F4C1} Generated structure:"));
23171
- console.log(chalk6.gray(` ${dirs.projectRoot}/`));
23172
- console.log(chalk6.gray(` \u251C\u2500\u2500 index.ts`));
23326
+ console.log(chalk7.green("\n\u2728 Project pulled successfully!"));
23327
+ console.log(chalk7.cyan("\n\u{1F4C1} Generated structure:"));
23328
+ console.log(chalk7.gray(` ${dirs.projectRoot}/`));
23329
+ console.log(chalk7.gray(` \u251C\u2500\u2500 index.ts`));
23173
23330
  if (fileCount.graphs > 0) {
23174
- console.log(chalk6.gray(` \u251C\u2500\u2500 graphs/ (${fileCount.graphs} files)`));
23331
+ console.log(chalk7.gray(` \u251C\u2500\u2500 graphs/ (${fileCount.graphs} files)`));
23175
23332
  }
23176
23333
  if (fileCount.tools > 0) {
23177
- console.log(chalk6.gray(` \u251C\u2500\u2500 tools/ (${fileCount.tools} files)`));
23334
+ console.log(chalk7.gray(` \u251C\u2500\u2500 tools/ (${fileCount.tools} files)`));
23178
23335
  }
23179
23336
  if (fileCount.dataComponents > 0) {
23180
- console.log(chalk6.gray(` \u251C\u2500\u2500 data-components/ (${fileCount.dataComponents} files)`));
23337
+ console.log(chalk7.gray(` \u251C\u2500\u2500 data-components/ (${fileCount.dataComponents} files)`));
23181
23338
  }
23182
23339
  if (fileCount.artifactComponents > 0) {
23183
- console.log(chalk6.gray(` \u251C\u2500\u2500 artifact-components/ (${fileCount.artifactComponents} files)`));
23340
+ console.log(chalk7.gray(` \u251C\u2500\u2500 artifact-components/ (${fileCount.artifactComponents} files)`));
23184
23341
  }
23185
- console.log(chalk6.gray(" \u2514\u2500\u2500 environments/ (4 files)"));
23186
- console.log(chalk6.cyan("\n\u{1F4DD} Next steps:"));
23187
- console.log(chalk6.gray(` \u2022 cd ${dirs.projectRoot}`));
23188
- console.log(chalk6.gray(" \u2022 Review the generated files"));
23189
- console.log(chalk6.gray(" \u2022 Test locally: inkeep push"));
23342
+ console.log(chalk7.gray(" \u2514\u2500\u2500 environments/ (4 files)"));
23343
+ console.log(chalk7.cyan("\n\u{1F4DD} Next steps:"));
23344
+ console.log(chalk7.gray(` \u2022 cd ${dirs.projectRoot}`));
23345
+ console.log(chalk7.gray(" \u2022 Review the generated files"));
23346
+ console.log(chalk7.gray(" \u2022 Test locally: inkeep push"));
23190
23347
  console.log(
23191
- chalk6.gray(' \u2022 Commit changes: git add . && git commit -m "Add project from pull"')
23348
+ chalk7.gray(' \u2022 Commit changes: git add . && git commit -m "Add project from pull"')
23192
23349
  );
23193
23350
  } catch (error) {
23194
23351
  spinner.fail("Failed to pull project");
23195
- console.error(chalk6.red("Error:"), error.message);
23352
+ console.error(chalk7.red("Error:"), error.message);
23196
23353
  process.exit(1);
23197
23354
  }
23198
23355
  }
23199
23356
 
23200
23357
  // src/commands/push.ts
23201
23358
  init_esm_shims();
23202
- init_env2();
23203
- init_config();
23204
23359
  import { existsSync as existsSync8 } from "fs";
23205
23360
  import { join as join9, resolve as resolve5 } from "path";
23206
- import chalk7 from "chalk";
23207
- import ora5 from "ora";
23361
+ import chalk8 from "chalk";
23362
+ import ora6 from "ora";
23363
+ init_cli_pipeline();
23208
23364
 
23209
23365
  // src/utils/environment-loader.ts
23210
23366
  init_esm_shims();
@@ -23259,23 +23415,15 @@ async function loadProject(projectDir) {
23259
23415
  );
23260
23416
  }
23261
23417
  async function pushCommand(options) {
23262
- const spinner = ora5("Loading configuration...").start();
23418
+ const { config } = await initializeCommand({
23419
+ configPath: options.config,
23420
+ showSpinner: true,
23421
+ spinnerText: "Loading configuration...",
23422
+ logConfig: true
23423
+ });
23424
+ let spinner;
23263
23425
  try {
23264
- const config = await validateConfiguration(
23265
- options.tenantId,
23266
- options.agentsManageApiUrl,
23267
- options.agentsRunApiUrl,
23268
- options.config
23269
- );
23270
- spinner.succeed("Configuration loaded");
23271
- console.log(chalk7.gray("Configuration sources:"));
23272
- console.log(chalk7.gray(` \u2022 Tenant ID: ${config.tenantId}`));
23273
- console.log(chalk7.gray(` \u2022 Manage API URL: ${config.agentsManageApiUrl}`));
23274
- console.log(chalk7.gray(` \u2022 Run API URL: ${config.agentsRunApiUrl}`));
23275
- if (config.sources.configFile) {
23276
- console.log(chalk7.gray(` \u2022 Config file: ${config.sources.configFile}`));
23277
- }
23278
- spinner.start("Detecting project...");
23426
+ spinner = ora6("Detecting project...").start();
23279
23427
  let projectDir;
23280
23428
  if (options.project) {
23281
23429
  projectDir = resolve5(process.cwd(), options.project);
@@ -23290,7 +23438,9 @@ async function pushCommand(options) {
23290
23438
  } else {
23291
23439
  spinner.fail("No index.ts found in current directory");
23292
23440
  console.error(
23293
- chalk7.yellow("Please run this command from a directory containing index.ts or use --project <path>")
23441
+ chalk8.yellow(
23442
+ "Please run this command from a directory containing index.ts or use --project <path>"
23443
+ )
23294
23444
  );
23295
23445
  process.exit(1);
23296
23446
  }
@@ -23320,8 +23470,10 @@ async function pushCommand(options) {
23320
23470
  if (typeof project.setConfig === "function") {
23321
23471
  project.setConfig(
23322
23472
  config.tenantId,
23323
- config.agentsManageApiUrl
23324
- // Note: models should be passed here if needed, not agentsRunApiUrl
23473
+ config.agentsManageApiUrl,
23474
+ void 0,
23475
+ // models - not needed here as they come from the project definition
23476
+ config.agentsManageApiKey
23325
23477
  );
23326
23478
  }
23327
23479
  if (options.env && typeof project.setCredentials === "function") {
@@ -23330,11 +23482,11 @@ async function pushCommand(options) {
23330
23482
  const credentials = await loadEnvironmentCredentials(projectDir, options.env);
23331
23483
  project.setCredentials(credentials);
23332
23484
  spinner.text = "Project loaded with credentials";
23333
- console.log(chalk7.gray(` \u2022 Environment: ${options.env}`));
23334
- console.log(chalk7.gray(` \u2022 Credentials loaded: ${Object.keys(credentials).length}`));
23485
+ console.log(chalk8.gray(` \u2022 Environment: ${options.env}`));
23486
+ console.log(chalk8.gray(` \u2022 Credentials loaded: ${Object.keys(credentials).length}`));
23335
23487
  } catch (error) {
23336
23488
  spinner.fail("Failed to load environment credentials");
23337
- console.error(chalk7.red("Error:"), error.message);
23489
+ console.error(chalk8.red("Error:"), error.message);
23338
23490
  process.exit(1);
23339
23491
  }
23340
23492
  }
@@ -23346,8 +23498,8 @@ async function pushCommand(options) {
23346
23498
  const fs5 = await import("fs/promises");
23347
23499
  await fs5.writeFile(jsonFilePath, JSON.stringify(projectDefinition, null, 2));
23348
23500
  spinner.succeed(`Project data saved to ${jsonFilePath}`);
23349
- console.log(chalk7.gray(` \u2022 File: ${jsonFilePath}`));
23350
- console.log(chalk7.gray(` \u2022 Size: ${JSON.stringify(projectDefinition).length} bytes`));
23501
+ console.log(chalk8.gray(` \u2022 File: ${jsonFilePath}`));
23502
+ console.log(chalk8.gray(` \u2022 Size: ${JSON.stringify(projectDefinition).length} bytes`));
23351
23503
  const graphCount = Object.keys(projectDefinition.graphs || {}).length;
23352
23504
  const toolCount = Object.keys(projectDefinition.tools || {}).length;
23353
23505
  const agentCount = Object.values(projectDefinition.graphs || {}).reduce(
@@ -23356,15 +23508,15 @@ async function pushCommand(options) {
23356
23508
  },
23357
23509
  0
23358
23510
  );
23359
- console.log(chalk7.cyan("\n\u{1F4CA} Project Data Summary:"));
23360
- console.log(chalk7.gray(` \u2022 Graphs: ${graphCount}`));
23361
- console.log(chalk7.gray(` \u2022 Tools: ${toolCount}`));
23362
- console.log(chalk7.gray(` \u2022 Agents: ${agentCount}`));
23363
- console.log(chalk7.green("\n\u2728 JSON file generated successfully!"));
23511
+ console.log(chalk8.cyan("\n\u{1F4CA} Project Data Summary:"));
23512
+ console.log(chalk8.gray(` \u2022 Graphs: ${graphCount}`));
23513
+ console.log(chalk8.gray(` \u2022 Tools: ${toolCount}`));
23514
+ console.log(chalk8.gray(` \u2022 Agents: ${agentCount}`));
23515
+ console.log(chalk8.green("\n\u2728 JSON file generated successfully!"));
23364
23516
  process.exit(0);
23365
23517
  } catch (error) {
23366
23518
  spinner.fail("Failed to generate JSON file");
23367
- console.error(chalk7.red("Error:"), error.message);
23519
+ console.error(chalk8.red("Error:"), error.message);
23368
23520
  process.exit(1);
23369
23521
  }
23370
23522
  }
@@ -23374,18 +23526,18 @@ async function pushCommand(options) {
23374
23526
  const projectName = project.getName();
23375
23527
  const stats = project.getStats();
23376
23528
  spinner.succeed(`Project "${projectName}" (${projectId}) pushed successfully`);
23377
- console.log(chalk7.cyan("\n\u{1F4CA} Project Summary:"));
23378
- console.log(chalk7.gray(` \u2022 Project ID: ${projectId}`));
23379
- console.log(chalk7.gray(` \u2022 Name: ${projectName}`));
23380
- console.log(chalk7.gray(` \u2022 Graphs: ${stats.graphCount}`));
23381
- console.log(chalk7.gray(` \u2022 Tenant: ${stats.tenantId}`));
23529
+ console.log(chalk8.cyan("\n\u{1F4CA} Project Summary:"));
23530
+ console.log(chalk8.gray(` \u2022 Project ID: ${projectId}`));
23531
+ console.log(chalk8.gray(` \u2022 Name: ${projectName}`));
23532
+ console.log(chalk8.gray(` \u2022 Graphs: ${stats.graphCount}`));
23533
+ console.log(chalk8.gray(` \u2022 Tenant: ${stats.tenantId}`));
23382
23534
  const graphs = project.getGraphs();
23383
23535
  if (graphs.length > 0) {
23384
- console.log(chalk7.cyan("\n\u{1F4CA} Graph Details:"));
23536
+ console.log(chalk8.cyan("\n\u{1F4CA} Graph Details:"));
23385
23537
  for (const graph of graphs) {
23386
23538
  const graphStats = graph.getStats();
23387
23539
  console.log(
23388
- chalk7.gray(
23540
+ chalk8.gray(
23389
23541
  ` \u2022 ${graph.getName()} (${graph.getId()}): ${graphStats.agentCount} agents, ${graphStats.toolCount} tools`
23390
23542
  )
23391
23543
  );
@@ -23395,37 +23547,40 @@ async function pushCommand(options) {
23395
23547
  const credentialTracking = await project.getCredentialTracking();
23396
23548
  const credentialCount = Object.keys(credentialTracking.credentials).length;
23397
23549
  if (credentialCount > 0) {
23398
- console.log(chalk7.cyan("\n\u{1F510} Credentials:"));
23399
- console.log(chalk7.gray(` \u2022 Total credentials: ${credentialCount}`));
23550
+ console.log(chalk8.cyan("\n\u{1F510} Credentials:"));
23551
+ console.log(chalk8.gray(` \u2022 Total credentials: ${credentialCount}`));
23400
23552
  for (const [credId, credData] of Object.entries(credentialTracking.credentials)) {
23401
23553
  const usageInfo = credentialTracking.usage[credId] || [];
23402
23554
  const credType = credData.type || "unknown";
23403
23555
  const storeId = credData.credentialStoreId || "unknown";
23404
- console.log(chalk7.gray(` \u2022 ${credId} (${credType}, store: ${storeId})`));
23556
+ console.log(chalk8.gray(` \u2022 ${credId} (${credType}, store: ${storeId})`));
23405
23557
  if (usageInfo.length > 0) {
23406
23558
  const usageByType = {};
23407
23559
  for (const usage of usageInfo) {
23408
23560
  usageByType[usage.type] = (usageByType[usage.type] || 0) + 1;
23409
23561
  }
23410
23562
  const usageSummary = Object.entries(usageByType).map(([type, count15]) => `${count15} ${type}${count15 > 1 ? "s" : ""}`).join(", ");
23411
- console.log(chalk7.gray(` Used by: ${usageSummary}`));
23563
+ console.log(chalk8.gray(` Used by: ${usageSummary}`));
23412
23564
  }
23413
23565
  }
23414
23566
  }
23415
- } catch (error) {
23567
+ } catch (_error) {
23416
23568
  if (env2.DEBUG) {
23417
- console.error(chalk7.yellow("Could not retrieve credential tracking information"));
23569
+ console.error(chalk8.yellow("Could not retrieve credential tracking information"));
23418
23570
  }
23419
23571
  }
23420
- console.log(chalk7.green("\n\u2728 Next steps:"));
23421
- console.log(chalk7.gray(` \u2022 Test your project: inkeep chat`));
23422
- console.log(chalk7.gray(` \u2022 View all graphs: inkeep list-graphs`));
23572
+ console.log(chalk8.green("\n\u2728 Next steps:"));
23573
+ console.log(chalk8.gray(` \u2022 Test your project: inkeep chat`));
23574
+ console.log(chalk8.gray(` \u2022 View all graphs: inkeep list-graphs`));
23423
23575
  process.exit(0);
23424
- } catch (error) {
23425
- spinner.fail("Failed to push project");
23426
- console.error(chalk7.red("Error:"), error.message);
23576
+ } catch (_error) {
23577
+ if (spinner) {
23578
+ spinner.fail("Failed to push project");
23579
+ }
23580
+ const error = _error;
23581
+ console.error(chalk8.red("Error:"), error.message);
23427
23582
  if (error.stack && env2.DEBUG) {
23428
- console.error(chalk7.gray(error.stack));
23583
+ console.error(chalk8.gray(error.stack));
23429
23584
  }
23430
23585
  process.exit(1);
23431
23586
  }