kitstore-cli 1.0.93 → 1.0.96
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 +32 -20
- 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,21 +46,12 @@ 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
|
-
if (await fs.pathExists(defaultConfigPath)) {
|
|
56
|
-
const defaultConfig = await fs.readJson(defaultConfigPath);
|
|
57
|
-
// Validate that defaultConfig has a server property
|
|
58
|
-
if (defaultConfig && typeof defaultConfig === 'object' && defaultConfig.server) {
|
|
59
|
-
return defaultConfig;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// Strategy 2: Try require.resolve for package.json first (works when package is in node_modules or npx cache)
|
|
63
|
-
// This is more reliable than resolving './config' because it finds the package root directly
|
|
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.
|
|
64
55
|
try {
|
|
65
56
|
const packageJsonPath = require.resolve('kitstore-cli/package.json');
|
|
66
57
|
const packageDir = path.dirname(packageJsonPath);
|
|
@@ -72,11 +63,27 @@ async function loadBundledDefaultConfig() {
|
|
|
72
63
|
}
|
|
73
64
|
}
|
|
74
65
|
}
|
|
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/.
|
|
73
|
+
try {
|
|
74
|
+
const defaultConfigPath = path.join(__dirname, '..', 'default-config.json');
|
|
75
|
+
if (await fs.pathExists(defaultConfigPath)) {
|
|
76
|
+
const defaultConfig = await fs.readJson(defaultConfigPath);
|
|
77
|
+
if (defaultConfig && typeof defaultConfig === 'object' && defaultConfig.server) {
|
|
78
|
+
return defaultConfig;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
75
82
|
catch (err) {
|
|
76
83
|
// Strategy 2 failed, try Strategy 3
|
|
77
84
|
}
|
|
78
|
-
// Strategy 3: Use require.resolve to find the
|
|
79
|
-
// This works when the package is installed via npm and we can resolve our own module
|
|
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.
|
|
80
87
|
try {
|
|
81
88
|
// Resolve the current module (config.js) to get its location
|
|
82
89
|
// Use the full path from the package to be more reliable
|
|
@@ -120,9 +127,14 @@ async function getConfig() {
|
|
|
120
127
|
await fs.ensureDir(CONFIG_DIR);
|
|
121
128
|
if (await fs.pathExists(CONFIG_FILE)) {
|
|
122
129
|
const content = await fs.readJson(CONFIG_FILE);
|
|
123
|
-
//
|
|
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)
|
|
124
135
|
const defaultConfig = await loadBundledDefaultConfig();
|
|
125
|
-
// 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.
|
|
126
138
|
const server = process.env.AGENTKIT_BACKEND_URL ||
|
|
127
139
|
(content.server !== undefined ? content.server : (defaultConfig?.server || 'http://localhost:3000'));
|
|
128
140
|
return { ...content, server };
|
|
@@ -131,7 +143,7 @@ async function getConfig() {
|
|
|
131
143
|
catch (err) {
|
|
132
144
|
// Ignore errors
|
|
133
145
|
}
|
|
134
|
-
// No local config file - try bundled default config
|
|
146
|
+
// No local config file - try bundled default config first, then fall back
|
|
135
147
|
const defaultConfig = await loadBundledDefaultConfig();
|
|
136
148
|
const server = process.env.AGENTKIT_BACKEND_URL || defaultConfig?.server || 'http://localhost:3000';
|
|
137
149
|
return { server };
|