kitstore-cli 1.0.92 → 1.0.95
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/api/client.js +8 -12
- package/dist/config.js +48 -34
- package/package.json +1 -1
package/dist/api/client.js
CHANGED
|
@@ -4,19 +4,15 @@ exports.createApi = createApi;
|
|
|
4
4
|
const generated_1 = require("./generated");
|
|
5
5
|
const config_1 = require("../config");
|
|
6
6
|
async function createApi(options) {
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
7
|
+
// Server/basePath resolution (highest → lowest priority):
|
|
8
|
+
// 1) Explicit options.server (e.g. from CLI flag or caller)
|
|
9
|
+
// 2) server from getConfig() (which already applies env → user config → default-config → localhost)
|
|
10
|
+
//
|
|
11
|
+
// IMPORTANT:
|
|
12
|
+
// - We call getConfig() exactly once here.
|
|
13
|
+
// - We never override a provided options.server with another value.
|
|
10
14
|
const cfg = await (0, config_1.getConfig)();
|
|
11
|
-
|
|
12
|
-
if (options?.server) {
|
|
13
|
-
// Explicit server option takes highest priority
|
|
14
|
-
basePath = options.server;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
// Use server from config (will use default-config if available)
|
|
18
|
-
basePath = cfg.server || 'http://localhost:3000';
|
|
19
|
-
}
|
|
15
|
+
const basePath = options?.server ?? cfg.server;
|
|
20
16
|
// Get token from options or config
|
|
21
17
|
const token = options?.token || cfg.token;
|
|
22
18
|
const configuration = new generated_1.Configuration({
|
package/dist/config.js
CHANGED
|
@@ -46,28 +46,32 @@ const CONFIG_DIR = process.env.KITSTORE_CONFIG_DIR || path.join(os.homedir(), '.
|
|
|
46
46
|
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
47
47
|
async function loadBundledDefaultConfig() {
|
|
48
48
|
try {
|
|
49
|
-
// Try multiple path resolution strategies to work in both development and npm-installed contexts
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
// Try multiple path resolution strategies to work in both development and npm-installed contexts,
|
|
50
|
+
// in a deterministic order that favors the actual npm package layout used by npx / CI.
|
|
51
|
+
//
|
|
52
|
+
// Strategy 1: Use require.resolve for package.json (most reliable for npm-installed / npx contexts)
|
|
53
|
+
// - When running from npm cache or node_modules, this finds the real package root.
|
|
54
|
+
// - default-config.json lives at that package root.
|
|
55
|
+
try {
|
|
56
|
+
const packageJsonPath = require.resolve('kitstore-cli/package.json');
|
|
57
|
+
const packageDir = path.dirname(packageJsonPath);
|
|
58
|
+
const defaultConfigPath = path.join(packageDir, 'default-config.json');
|
|
59
|
+
if (await fs.pathExists(defaultConfigPath)) {
|
|
60
|
+
const defaultConfig = await fs.readJson(defaultConfigPath);
|
|
61
|
+
if (defaultConfig && typeof defaultConfig === 'object' && defaultConfig.server) {
|
|
62
|
+
return defaultConfig;
|
|
63
|
+
}
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
catch (err) {
|
|
67
|
+
// Strategy 1 failed, try Strategy 2
|
|
68
|
+
}
|
|
69
|
+
// Strategy 2: Use __dirname relative path (works in development/local builds and many npm-installed layouts)
|
|
70
|
+
// - When running from source or local tarball, __dirname points to dist/ directory.
|
|
71
|
+
// - When running from npm-installed package, __dirname also typically points to dist/ directory.
|
|
72
|
+
// - default-config.json is at package root, so go up one level from dist/.
|
|
64
73
|
try {
|
|
65
|
-
|
|
66
|
-
const currentModulePath = require.resolve('./config');
|
|
67
|
-
const currentModuleDir = path.dirname(currentModulePath);
|
|
68
|
-
// Go up to package root (from dist/ to package root)
|
|
69
|
-
const packageRoot = path.dirname(currentModuleDir);
|
|
70
|
-
const defaultConfigPath = path.join(packageRoot, 'default-config.json');
|
|
74
|
+
const defaultConfigPath = path.join(__dirname, '..', 'default-config.json');
|
|
71
75
|
if (await fs.pathExists(defaultConfigPath)) {
|
|
72
76
|
const defaultConfig = await fs.readJson(defaultConfigPath);
|
|
73
77
|
if (defaultConfig && typeof defaultConfig === 'object' && defaultConfig.server) {
|
|
@@ -78,27 +82,32 @@ async function loadBundledDefaultConfig() {
|
|
|
78
82
|
catch (err) {
|
|
79
83
|
// Strategy 2 failed, try Strategy 3
|
|
80
84
|
}
|
|
81
|
-
// Strategy 3:
|
|
82
|
-
// This works when
|
|
85
|
+
// Strategy 3: Use require.resolve to find the compiled config module, then resolve config relative to it
|
|
86
|
+
// - This works when the package is installed via npm and we can resolve our own module entrypoint.
|
|
83
87
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
// Resolve the current module (config.js) to get its location
|
|
89
|
+
// Use the full path from the package to be more reliable
|
|
90
|
+
const currentModulePath = require.resolve('kitstore-cli/dist/config');
|
|
91
|
+
const currentModuleDir = path.dirname(currentModulePath);
|
|
92
|
+
// Go up to package root (from dist/ to package root)
|
|
93
|
+
const packageRoot = path.dirname(currentModuleDir);
|
|
94
|
+
const defaultConfigPath = path.join(packageRoot, 'default-config.json');
|
|
95
|
+
if (await fs.pathExists(defaultConfigPath)) {
|
|
96
|
+
const defaultConfig = await fs.readJson(defaultConfigPath);
|
|
87
97
|
if (defaultConfig && typeof defaultConfig === 'object' && defaultConfig.server) {
|
|
88
98
|
return defaultConfig;
|
|
89
99
|
}
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
102
|
catch (err) {
|
|
93
|
-
// Strategy 3 failed,
|
|
103
|
+
// Strategy 3 failed, try Strategy 4
|
|
94
104
|
}
|
|
95
|
-
// Strategy 4: Try
|
|
105
|
+
// Strategy 4: Try to find default-config.json in process.cwd()/node_modules/kitstore-cli/
|
|
106
|
+
// This works when running from a project that has kitstore-cli installed locally
|
|
96
107
|
try {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (await fs.pathExists(defaultConfigPath)) {
|
|
101
|
-
const defaultConfig = await fs.readJson(defaultConfigPath);
|
|
108
|
+
const nodeModulesPath = path.join(process.cwd(), 'node_modules', 'kitstore-cli', 'default-config.json');
|
|
109
|
+
if (await fs.pathExists(nodeModulesPath)) {
|
|
110
|
+
const defaultConfig = await fs.readJson(nodeModulesPath);
|
|
102
111
|
if (defaultConfig && typeof defaultConfig === 'object' && defaultConfig.server) {
|
|
103
112
|
return defaultConfig;
|
|
104
113
|
}
|
|
@@ -118,9 +127,14 @@ async function getConfig() {
|
|
|
118
127
|
await fs.ensureDir(CONFIG_DIR);
|
|
119
128
|
if (await fs.pathExists(CONFIG_FILE)) {
|
|
120
129
|
const content = await fs.readJson(CONFIG_FILE);
|
|
121
|
-
//
|
|
130
|
+
// Server precedence (highest → lowest):
|
|
131
|
+
// 1) AGENTKIT_BACKEND_URL environment variable
|
|
132
|
+
// 2) server value explicitly stored in user config.json (content.server, including empty string if deliberately set)
|
|
133
|
+
// 3) bundled default-config.json server (from published package)
|
|
134
|
+
// 4) localhost fallback (only when no other source is available)
|
|
122
135
|
const defaultConfig = await loadBundledDefaultConfig();
|
|
123
|
-
// If content.server
|
|
136
|
+
// If content.server is defined (even if empty string), prefer it over bundled default-config.
|
|
137
|
+
// This allows advanced users to deliberately clear or override the default-config server in their own config.
|
|
124
138
|
const server = process.env.AGENTKIT_BACKEND_URL ||
|
|
125
139
|
(content.server !== undefined ? content.server : (defaultConfig?.server || 'http://localhost:3000'));
|
|
126
140
|
return { ...content, server };
|
|
@@ -129,7 +143,7 @@ async function getConfig() {
|
|
|
129
143
|
catch (err) {
|
|
130
144
|
// Ignore errors
|
|
131
145
|
}
|
|
132
|
-
// No local config file - try bundled default config
|
|
146
|
+
// No local config file - try bundled default config first, then fall back
|
|
133
147
|
const defaultConfig = await loadBundledDefaultConfig();
|
|
134
148
|
const server = process.env.AGENTKIT_BACKEND_URL || defaultConfig?.server || 'http://localhost:3000';
|
|
135
149
|
return { server };
|