@agi-cli/sdk 0.1.164 → 0.1.166
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/package.json +1 -1
- package/src/config/src/index.ts +5 -20
- package/src/config/src/manager.ts +49 -19
- package/src/index.ts +0 -1
- package/src/types/src/config.ts +0 -8
- package/src/types/src/index.ts +0 -1
package/package.json
CHANGED
package/src/config/src/index.ts
CHANGED
|
@@ -7,29 +7,15 @@ import {
|
|
|
7
7
|
} from './paths.ts';
|
|
8
8
|
import type { AGIConfig } from '../../types/src/index.ts';
|
|
9
9
|
|
|
10
|
-
export type {
|
|
10
|
+
export type { AGIConfig } from '../../types/src/index.ts';
|
|
11
11
|
|
|
12
|
-
const DEFAULTS: {
|
|
13
|
-
defaults: AGIConfig['defaults'];
|
|
14
|
-
providers: AGIConfig['providers'];
|
|
15
|
-
} = {
|
|
12
|
+
const DEFAULTS: { defaults: AGIConfig['defaults'] } = {
|
|
16
13
|
defaults: {
|
|
17
|
-
agent: '
|
|
18
|
-
provider: '
|
|
19
|
-
model: '
|
|
14
|
+
agent: 'build',
|
|
15
|
+
provider: 'setu',
|
|
16
|
+
model: 'kimi-k2.5',
|
|
20
17
|
toolApproval: 'auto',
|
|
21
18
|
},
|
|
22
|
-
providers: {
|
|
23
|
-
openai: { enabled: true },
|
|
24
|
-
anthropic: { enabled: true },
|
|
25
|
-
google: { enabled: true },
|
|
26
|
-
openrouter: { enabled: false },
|
|
27
|
-
opencode: { enabled: false },
|
|
28
|
-
setu: { enabled: false },
|
|
29
|
-
zai: { enabled: false },
|
|
30
|
-
'zai-coding': { enabled: false },
|
|
31
|
-
moonshot: { enabled: false },
|
|
32
|
-
},
|
|
33
19
|
};
|
|
34
20
|
|
|
35
21
|
export async function loadConfig(
|
|
@@ -54,7 +40,6 @@ export async function loadConfig(
|
|
|
54
40
|
return {
|
|
55
41
|
projectRoot,
|
|
56
42
|
defaults: merged.defaults as AGIConfig['defaults'],
|
|
57
|
-
providers: merged.providers as AGIConfig['providers'],
|
|
58
43
|
paths: {
|
|
59
44
|
dataDir,
|
|
60
45
|
dbPath,
|
|
@@ -6,7 +6,12 @@ import {
|
|
|
6
6
|
type ProviderId,
|
|
7
7
|
type AuthInfo,
|
|
8
8
|
} from '../../auth/src/index.ts';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getGlobalConfigDir,
|
|
11
|
+
getGlobalConfigPath,
|
|
12
|
+
getLocalDataDir,
|
|
13
|
+
joinPath,
|
|
14
|
+
} from './paths.ts';
|
|
10
15
|
import {
|
|
11
16
|
providerIds,
|
|
12
17
|
readEnvKey,
|
|
@@ -62,35 +67,60 @@ export async function writeDefaults(
|
|
|
62
67
|
}>,
|
|
63
68
|
projectRoot?: string,
|
|
64
69
|
) {
|
|
65
|
-
const
|
|
70
|
+
const root = projectRoot ? String(projectRoot) : process.cwd();
|
|
71
|
+
|
|
66
72
|
if (scope === 'local') {
|
|
73
|
+
const localDir = getLocalDataDir(root);
|
|
74
|
+
const localPath = joinPath(localDir, 'config.json');
|
|
75
|
+
const existing = await readJsonFile(localPath);
|
|
76
|
+
const prevDefaults =
|
|
77
|
+
existing && typeof existing.defaults === 'object'
|
|
78
|
+
? (existing.defaults as Record<string, unknown>)
|
|
79
|
+
: {};
|
|
67
80
|
const next = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
...updates,
|
|
71
|
-
provider: (updates.provider ?? cfg.defaults.provider) as ProviderId,
|
|
72
|
-
},
|
|
73
|
-
providers: cfg.providers,
|
|
81
|
+
...existing,
|
|
82
|
+
defaults: { ...prevDefaults, ...updates },
|
|
74
83
|
};
|
|
75
|
-
|
|
76
|
-
|
|
84
|
+
try {
|
|
85
|
+
const { promises: fs } = await import('node:fs');
|
|
86
|
+
await fs.mkdir(localDir, { recursive: true }).catch(() => {});
|
|
87
|
+
} catch {}
|
|
88
|
+
await Bun.write(localPath, JSON.stringify(next, null, 2));
|
|
77
89
|
return;
|
|
78
90
|
}
|
|
79
|
-
|
|
80
|
-
const
|
|
91
|
+
|
|
92
|
+
const globalPath = getGlobalConfigPath();
|
|
93
|
+
const existing = await readJsonFile(globalPath);
|
|
94
|
+
const prevDefaults =
|
|
95
|
+
existing && typeof existing.defaults === 'object'
|
|
96
|
+
? (existing.defaults as Record<string, unknown>)
|
|
97
|
+
: {};
|
|
81
98
|
const next = {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
...updates,
|
|
85
|
-
provider: (updates.provider ?? cfg.defaults.provider) as ProviderId,
|
|
86
|
-
},
|
|
87
|
-
providers: cfg.providers,
|
|
99
|
+
...existing,
|
|
100
|
+
defaults: { ...prevDefaults, ...updates },
|
|
88
101
|
};
|
|
102
|
+
const base = getGlobalConfigDir();
|
|
89
103
|
try {
|
|
90
104
|
const { promises: fs } = await import('node:fs');
|
|
91
105
|
await fs.mkdir(base, { recursive: true }).catch(() => {});
|
|
92
106
|
} catch {}
|
|
93
|
-
await Bun.write(
|
|
107
|
+
await Bun.write(globalPath, JSON.stringify(next, null, 2));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function readJsonFile(
|
|
111
|
+
filePath: string,
|
|
112
|
+
): Promise<Record<string, unknown> | undefined> {
|
|
113
|
+
const f = Bun.file(filePath);
|
|
114
|
+
if (!(await f.exists())) return undefined;
|
|
115
|
+
try {
|
|
116
|
+
const parsed = await f.json();
|
|
117
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
118
|
+
return parsed as Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
return undefined;
|
|
121
|
+
} catch {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
94
124
|
}
|
|
95
125
|
|
|
96
126
|
export async function writeAuth(
|
package/src/index.ts
CHANGED
package/src/types/src/config.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import type { ProviderId } from './provider';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Configuration scope - where settings are stored
|
|
5
3
|
*/
|
|
6
4
|
export type Scope = 'global' | 'local';
|
|
7
5
|
|
|
8
|
-
/**
|
|
9
|
-
* Provider-specific configuration
|
|
10
|
-
*/
|
|
11
|
-
export type ProviderConfig = { enabled: boolean; apiKey?: string };
|
|
12
|
-
|
|
13
6
|
/**
|
|
14
7
|
* Default settings for the CLI
|
|
15
8
|
*/
|
|
@@ -38,7 +31,6 @@ export type PathConfig = {
|
|
|
38
31
|
export type AGIConfig = {
|
|
39
32
|
projectRoot: string;
|
|
40
33
|
defaults: DefaultConfig;
|
|
41
|
-
providers: Record<ProviderId, ProviderConfig>;
|
|
42
34
|
paths: PathConfig;
|
|
43
35
|
onboardingComplete?: boolean;
|
|
44
36
|
};
|