opencode-morphllm 0.0.7 → 0.0.9
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/README.md +1 -0
- package/dist/morph/router.js +1 -1
- package/package.json +2 -1
- package/.gitleaks.toml +0 -6
- package/.husky/pre-commit +0 -6
- package/.prettierignore +0 -1
- package/.prettierrc +0 -8
- package/bun.lock +0 -364
- package/bunfig.toml +0 -4
- package/dist/morph/mcps.test.d.ts +0 -1
- package/dist/morph/mcps.test.js +0 -39
- package/dist/morph/router.test.d.ts +0 -1
- package/dist/morph/router.test.js +0 -239
- package/dist/shared/config.test.d.ts +0 -1
- package/dist/shared/config.test.js +0 -201
- package/dist/shared/opencode-config-dir.test.d.ts +0 -1
- package/dist/shared/opencode-config-dir.test.js +0 -310
- package/src/index.ts +0 -22
- package/src/morph/mcps.test.ts +0 -51
- package/src/morph/mcps.ts +0 -18
- package/src/morph/router.test.ts +0 -267
- package/src/morph/router.ts +0 -111
- package/src/shared/config.test.ts +0 -257
- package/src/shared/config.ts +0 -118
- package/src/shared/opencode-config-dir.test.ts +0 -404
- package/src/shared/opencode-config-dir.ts +0 -156
- package/tsconfig.json +0 -20
package/src/morph/router.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { MorphClient } from '@morphllm/morphsdk';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
API_KEY,
|
|
5
|
-
MORPH_MODEL_EASY,
|
|
6
|
-
MORPH_MODEL_MEDIUM,
|
|
7
|
-
MORPH_MODEL_HARD,
|
|
8
|
-
MORPH_MODEL_DEFAULT,
|
|
9
|
-
MORPH_ROUTER_PROMPT_CACHING_AWARE,
|
|
10
|
-
MORPH_ROUTER_ENABLED,
|
|
11
|
-
} from '../shared/config';
|
|
12
|
-
import type { Part, UserMessage } from '@opencode-ai/sdk';
|
|
13
|
-
import type {
|
|
14
|
-
RouterInput,
|
|
15
|
-
RawRouterResult,
|
|
16
|
-
ComplexityLevel,
|
|
17
|
-
} from '@morphllm/morphsdk';
|
|
18
|
-
|
|
19
|
-
// Lazy initialization to allow mocking in tests
|
|
20
|
-
let morph: MorphClient | null = null;
|
|
21
|
-
|
|
22
|
-
const sessionsWithModelSelected = new Set<string>();
|
|
23
|
-
|
|
24
|
-
function getMorphClient(): MorphClient {
|
|
25
|
-
if (!morph) {
|
|
26
|
-
morph = new MorphClient({ apiKey: API_KEY });
|
|
27
|
-
}
|
|
28
|
-
return morph;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function parseModel(s?: string): { providerID: string; modelID: string } {
|
|
32
|
-
if (!s) return { providerID: '', modelID: '' };
|
|
33
|
-
const [providerID = '', modelID = ''] = s.split('/');
|
|
34
|
-
return { providerID, modelID };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function pickModelForDifficulty(difficulty?: ComplexityLevel | string): {
|
|
38
|
-
providerID: string;
|
|
39
|
-
modelID: string;
|
|
40
|
-
} {
|
|
41
|
-
const key = String(difficulty).toLowerCase();
|
|
42
|
-
switch (key) {
|
|
43
|
-
case 'easy':
|
|
44
|
-
return parseModel(MORPH_MODEL_EASY);
|
|
45
|
-
case 'medium':
|
|
46
|
-
return parseModel(MORPH_MODEL_MEDIUM);
|
|
47
|
-
case 'hard':
|
|
48
|
-
return parseModel(MORPH_MODEL_HARD);
|
|
49
|
-
default:
|
|
50
|
-
return parseModel(MORPH_MODEL_DEFAULT);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function createModelRouterHook() {
|
|
55
|
-
return {
|
|
56
|
-
'chat.message': async (
|
|
57
|
-
input: {
|
|
58
|
-
sessionID: string;
|
|
59
|
-
agent?: string;
|
|
60
|
-
model?: { providerID: string; modelID: string };
|
|
61
|
-
messageID?: string;
|
|
62
|
-
variant?: string;
|
|
63
|
-
classify?: (args: RouterInput) => Promise<RawRouterResult>;
|
|
64
|
-
},
|
|
65
|
-
output: { message: UserMessage; parts: Part[] }
|
|
66
|
-
): Promise<void> => {
|
|
67
|
-
input.model = input.model ?? { providerID: '', modelID: '' };
|
|
68
|
-
|
|
69
|
-
if (!MORPH_ROUTER_ENABLED) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (MORPH_ROUTER_PROMPT_CACHING_AWARE) {
|
|
74
|
-
if (sessionsWithModelSelected.has(input.sessionID)) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const promptText = extractPromptText(output.parts);
|
|
80
|
-
|
|
81
|
-
const classifier =
|
|
82
|
-
input.classify ??
|
|
83
|
-
((args: RouterInput) => getMorphClient().routers.raw.classify(args));
|
|
84
|
-
|
|
85
|
-
const classification: RawRouterResult = await classifier({
|
|
86
|
-
input: promptText,
|
|
87
|
-
} as RouterInput);
|
|
88
|
-
|
|
89
|
-
const chosen = pickModelForDifficulty(classification?.difficulty);
|
|
90
|
-
|
|
91
|
-
const finalProviderID = chosen.providerID || input.model.providerID;
|
|
92
|
-
const finalModelID = chosen.modelID || input.model.modelID;
|
|
93
|
-
|
|
94
|
-
input.model.providerID = finalProviderID;
|
|
95
|
-
input.model.modelID = finalModelID;
|
|
96
|
-
|
|
97
|
-
if (MORPH_ROUTER_ENABLED && MORPH_ROUTER_PROMPT_CACHING_AWARE) {
|
|
98
|
-
sessionsWithModelSelected.add(input.sessionID);
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function extractPromptText(
|
|
105
|
-
parts: Array<{ type: string; text?: string }>
|
|
106
|
-
): string {
|
|
107
|
-
return parts
|
|
108
|
-
.filter((p) => p.type === 'text')
|
|
109
|
-
.map((p) => p.text || '')
|
|
110
|
-
.join(' ');
|
|
111
|
-
}
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
describe,
|
|
3
|
-
it,
|
|
4
|
-
expect,
|
|
5
|
-
beforeEach,
|
|
6
|
-
afterEach,
|
|
7
|
-
beforeAll,
|
|
8
|
-
afterAll,
|
|
9
|
-
} from 'bun:test';
|
|
10
|
-
import {
|
|
11
|
-
existsSync,
|
|
12
|
-
writeFileSync,
|
|
13
|
-
readFileSync,
|
|
14
|
-
rmSync,
|
|
15
|
-
mkdirSync,
|
|
16
|
-
} from 'node:fs';
|
|
17
|
-
import { join } from 'node:path';
|
|
18
|
-
import { tmpdir } from 'node:os';
|
|
19
|
-
import { env } from 'node:process';
|
|
20
|
-
|
|
21
|
-
// Use a real temporary directory for testing - no mocking needed
|
|
22
|
-
const mockConfigDir = join(tmpdir(), 'mock-morph-config-test');
|
|
23
|
-
const mockMorphJson = join(mockConfigDir, 'morph.json');
|
|
24
|
-
const mockMorphJsonc = join(mockConfigDir, 'morph.jsonc');
|
|
25
|
-
|
|
26
|
-
// Save original environment
|
|
27
|
-
let originalEnv: Record<string, string | undefined>;
|
|
28
|
-
|
|
29
|
-
import {
|
|
30
|
-
getMorphPluginConfigPath,
|
|
31
|
-
loadMorphPluginConfig,
|
|
32
|
-
loadMorphPluginConfigWithProjectOverride,
|
|
33
|
-
} from './config';
|
|
34
|
-
|
|
35
|
-
describe('config.ts', () => {
|
|
36
|
-
beforeAll(() => {
|
|
37
|
-
// Save original environment and set custom config dir
|
|
38
|
-
originalEnv = {
|
|
39
|
-
OPENCODE_CONFIG_DIR: env.OPENCODE_CONFIG_DIR,
|
|
40
|
-
};
|
|
41
|
-
env.OPENCODE_CONFIG_DIR = mockConfigDir;
|
|
42
|
-
|
|
43
|
-
// Create mock config directory
|
|
44
|
-
if (!existsSync(mockConfigDir)) {
|
|
45
|
-
mkdirSync(mockConfigDir, { recursive: true });
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
afterAll(() => {
|
|
50
|
-
// Restore original environment
|
|
51
|
-
if (originalEnv.OPENCODE_CONFIG_DIR !== undefined) {
|
|
52
|
-
env.OPENCODE_CONFIG_DIR = originalEnv.OPENCODE_CONFIG_DIR;
|
|
53
|
-
} else {
|
|
54
|
-
delete env.OPENCODE_CONFIG_DIR;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Cleanup
|
|
58
|
-
try {
|
|
59
|
-
if (existsSync(mockMorphJson)) rmSync(mockMorphJson);
|
|
60
|
-
if (existsSync(mockMorphJsonc)) rmSync(mockMorphJsonc);
|
|
61
|
-
if (existsSync(mockConfigDir)) rmSync(mockConfigDir, { recursive: true });
|
|
62
|
-
} catch {
|
|
63
|
-
// Ignore cleanup errors
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
beforeEach(() => {
|
|
68
|
-
// Clean up any existing config files before each test
|
|
69
|
-
try {
|
|
70
|
-
if (existsSync(mockMorphJson)) rmSync(mockMorphJson);
|
|
71
|
-
if (existsSync(mockMorphJsonc)) rmSync(mockMorphJsonc);
|
|
72
|
-
} catch {
|
|
73
|
-
// Ignore cleanup errors
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe('getMorphPluginConfigPath', () => {
|
|
78
|
-
it('should return path to morph.json in config directory', () => {
|
|
79
|
-
const path = getMorphPluginConfigPath();
|
|
80
|
-
expect(path).toContain('morph.json');
|
|
81
|
-
expect(path).toContain(mockConfigDir);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('loadMorphPluginConfig', () => {
|
|
86
|
-
it('should return null when no config files exist', () => {
|
|
87
|
-
const result = loadMorphPluginConfig();
|
|
88
|
-
expect(result).toBeNull();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should load config from .jsonc file', () => {
|
|
92
|
-
const content = `{
|
|
93
|
-
"MORPH_API_KEY": "test-key-123",
|
|
94
|
-
"MORPH_ROUTER_ENABLED": false
|
|
95
|
-
}`;
|
|
96
|
-
writeFileSync(mockMorphJsonc, content);
|
|
97
|
-
|
|
98
|
-
const result = loadMorphPluginConfig();
|
|
99
|
-
expect(result).not.toBeNull();
|
|
100
|
-
expect(result?.MORPH_API_KEY).toBe('test-key-123');
|
|
101
|
-
expect(result?.MORPH_ROUTER_ENABLED).toBe(false);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should load config from .json file', () => {
|
|
105
|
-
const content = JSON.stringify({
|
|
106
|
-
MORPH_API_KEY: 'json-key-456',
|
|
107
|
-
MORPH_MODEL_EASY: 'provider/model-easy',
|
|
108
|
-
});
|
|
109
|
-
writeFileSync(mockMorphJson, content);
|
|
110
|
-
|
|
111
|
-
const result = loadMorphPluginConfig();
|
|
112
|
-
expect(result).not.toBeNull();
|
|
113
|
-
expect(result?.MORPH_API_KEY).toBe('json-key-456');
|
|
114
|
-
expect(result?.MORPH_MODEL_EASY).toBe('provider/model-easy');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should prefer .jsonc over .json when both exist', () => {
|
|
118
|
-
const jsoncContent = '{"MORPH_API_KEY": "from-jsonc"}';
|
|
119
|
-
const jsonContent = '{"MORPH_API_KEY": "from-json"}';
|
|
120
|
-
|
|
121
|
-
writeFileSync(mockMorphJsonc, jsoncContent);
|
|
122
|
-
writeFileSync(mockMorphJson, jsonContent);
|
|
123
|
-
|
|
124
|
-
const result = loadMorphPluginConfig();
|
|
125
|
-
expect(result?.MORPH_API_KEY).toBe('from-jsonc');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should return null for invalid .jsonc content', () => {
|
|
129
|
-
writeFileSync(mockMorphJsonc, 'invalid json content');
|
|
130
|
-
|
|
131
|
-
const result = loadMorphPluginConfig();
|
|
132
|
-
expect(result).toBeNull();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should return null for invalid .json content', () => {
|
|
136
|
-
writeFileSync(mockMorphJson, 'invalid json content');
|
|
137
|
-
|
|
138
|
-
const result = loadMorphPluginConfig();
|
|
139
|
-
expect(result).toBeNull();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should handle all MORPH config fields', () => {
|
|
143
|
-
const content = JSON.stringify({
|
|
144
|
-
MORPH_API_KEY: 'api-key',
|
|
145
|
-
MORPH_ROUTER_ENABLED: true,
|
|
146
|
-
MORPH_MODEL_EASY: 'easy/provider/model',
|
|
147
|
-
MORPH_MODEL_MEDIUM: 'medium/provider/model',
|
|
148
|
-
MORPH_MODEL_HARD: 'hard/provider/model',
|
|
149
|
-
MORPH_MODEL_DEFAULT: 'default/provider/model',
|
|
150
|
-
});
|
|
151
|
-
writeFileSync(mockMorphJson, content);
|
|
152
|
-
|
|
153
|
-
const result = loadMorphPluginConfig();
|
|
154
|
-
expect(result).toEqual({
|
|
155
|
-
MORPH_API_KEY: 'api-key',
|
|
156
|
-
MORPH_ROUTER_ENABLED: true,
|
|
157
|
-
MORPH_MODEL_EASY: 'easy/provider/model',
|
|
158
|
-
MORPH_MODEL_MEDIUM: 'medium/provider/model',
|
|
159
|
-
MORPH_MODEL_HARD: 'hard/provider/model',
|
|
160
|
-
MORPH_MODEL_DEFAULT: 'default/provider/model',
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('should handle nested MORPH_ROUTER_CONFIGS', () => {
|
|
165
|
-
const content = JSON.stringify({
|
|
166
|
-
MORPH_API_KEY: 'api-key',
|
|
167
|
-
MORPH_ROUTER_CONFIGS: {
|
|
168
|
-
MORPH_ROUTER_ENABLED: true,
|
|
169
|
-
MORPH_MODEL_EASY: 'easy/provider/model',
|
|
170
|
-
MORPH_MODEL_MEDIUM: 'medium/provider/model',
|
|
171
|
-
MORPH_MODEL_HARD: 'hard/provider/model',
|
|
172
|
-
MORPH_MODEL_DEFAULT: 'default/provider/model',
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
writeFileSync(mockMorphJson, content);
|
|
176
|
-
|
|
177
|
-
const result = loadMorphPluginConfig();
|
|
178
|
-
expect(result?.MORPH_API_KEY).toBe('api-key');
|
|
179
|
-
expect(result?.MORPH_ROUTER_CONFIGS).toEqual({
|
|
180
|
-
MORPH_ROUTER_ENABLED: true,
|
|
181
|
-
MORPH_MODEL_EASY: 'easy/provider/model',
|
|
182
|
-
MORPH_MODEL_MEDIUM: 'medium/provider/model',
|
|
183
|
-
MORPH_MODEL_HARD: 'hard/provider/model',
|
|
184
|
-
MORPH_MODEL_DEFAULT: 'default/provider/model',
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe('loadMorphPluginConfigWithProjectOverride', () => {
|
|
190
|
-
it('should return empty object when no config exists', () => {
|
|
191
|
-
const result =
|
|
192
|
-
loadMorphPluginConfigWithProjectOverride('/non-existent-path');
|
|
193
|
-
expect(result).toEqual({});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('should merge user config with project config', () => {
|
|
197
|
-
// Create user config
|
|
198
|
-
writeFileSync(
|
|
199
|
-
mockMorphJson,
|
|
200
|
-
JSON.stringify({
|
|
201
|
-
MORPH_API_KEY: 'user-api-key',
|
|
202
|
-
MORPH_MODEL_EASY: 'user-easy-model',
|
|
203
|
-
})
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
// Create project config directory
|
|
207
|
-
const projectDir = join(tmpdir(), 'test-project');
|
|
208
|
-
const projectConfigDir = join(projectDir, '.opencode');
|
|
209
|
-
const projectConfigPath = join(projectConfigDir, 'morph.json');
|
|
210
|
-
|
|
211
|
-
mkdirSync(projectConfigDir, { recursive: true });
|
|
212
|
-
writeFileSync(
|
|
213
|
-
projectConfigPath,
|
|
214
|
-
JSON.stringify({
|
|
215
|
-
MORPH_API_KEY: 'project-api-key',
|
|
216
|
-
MORPH_MODEL_HARD: 'project-hard-model',
|
|
217
|
-
})
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
const result = loadMorphPluginConfigWithProjectOverride(projectDir);
|
|
221
|
-
|
|
222
|
-
// Project config should override user config
|
|
223
|
-
expect(result.MORPH_API_KEY).toBe('project-api-key');
|
|
224
|
-
expect(result.MORPH_MODEL_EASY).toBe('user-easy-model');
|
|
225
|
-
expect(result.MORPH_MODEL_HARD).toBe('project-hard-model');
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('should handle project .jsonc config', () => {
|
|
229
|
-
// Create user config
|
|
230
|
-
writeFileSync(
|
|
231
|
-
mockMorphJson,
|
|
232
|
-
JSON.stringify({
|
|
233
|
-
MORPH_API_KEY: 'user-key',
|
|
234
|
-
})
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
// Create project config with .jsonc
|
|
238
|
-
const projectDir = join(tmpdir(), 'test-project2');
|
|
239
|
-
const projectConfigDir = join(projectDir, '.opencode');
|
|
240
|
-
const projectConfigPath = join(projectConfigDir, 'morph.jsonc');
|
|
241
|
-
|
|
242
|
-
mkdirSync(projectConfigDir, { recursive: true });
|
|
243
|
-
const jsoncContent = `
|
|
244
|
-
// Project config with comments
|
|
245
|
-
{
|
|
246
|
-
"MORPH_MODEL_MEDIUM": "project-medium-model"
|
|
247
|
-
}
|
|
248
|
-
`;
|
|
249
|
-
writeFileSync(projectConfigPath, jsoncContent);
|
|
250
|
-
|
|
251
|
-
const result = loadMorphPluginConfigWithProjectOverride(projectDir);
|
|
252
|
-
|
|
253
|
-
expect(result.MORPH_API_KEY).toBe('user-key');
|
|
254
|
-
expect(result.MORPH_MODEL_MEDIUM).toBe('project-medium-model');
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
});
|
package/src/shared/config.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { getOpenCodeConfigDir } from './opencode-config-dir';
|
|
4
|
-
|
|
5
|
-
const MORPH_PLUGIN_NAME = 'morph';
|
|
6
|
-
|
|
7
|
-
export function getMorphPluginConfigPath(): string {
|
|
8
|
-
const configDir = getOpenCodeConfigDir({ binary: 'opencode' });
|
|
9
|
-
return join(configDir, `${MORPH_PLUGIN_NAME}.json`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface MorphRouterConfigs {
|
|
13
|
-
MORPH_ROUTER_ENABLED?: boolean;
|
|
14
|
-
MORPH_ROUTER_PROMPT_CACHING_AWARE?: boolean;
|
|
15
|
-
MORPH_MODEL_EASY?: string;
|
|
16
|
-
MORPH_MODEL_MEDIUM?: string;
|
|
17
|
-
MORPH_MODEL_HARD?: string;
|
|
18
|
-
MORPH_MODEL_DEFAULT?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface MorphConfig {
|
|
22
|
-
MORPH_API_KEY?: string;
|
|
23
|
-
MORPH_ROUTER_CONFIGS?: MorphRouterConfigs;
|
|
24
|
-
// Legacy fields for backward compatibility
|
|
25
|
-
MORPH_ROUTER_ENABLED?: boolean;
|
|
26
|
-
MORPH_ROUTER_PROMPT_CACHING_AWARE?: boolean;
|
|
27
|
-
MORPH_MODEL_EASY?: string;
|
|
28
|
-
MORPH_MODEL_MEDIUM?: string;
|
|
29
|
-
MORPH_MODEL_HARD?: string;
|
|
30
|
-
MORPH_MODEL_DEFAULT?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function parseJsonc<T>(content: string): T | null {
|
|
34
|
-
try {
|
|
35
|
-
// A simple JSONC parser that removes comments
|
|
36
|
-
const cleanedContent = content.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '');
|
|
37
|
-
return JSON.parse(cleanedContent) as T;
|
|
38
|
-
} catch {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function loadMorphPluginConfig(): MorphConfig | null {
|
|
44
|
-
const jsoncPath = getMorphPluginConfigPath().replace('.json', '.jsonc');
|
|
45
|
-
const jsonPath = getMorphPluginConfigPath();
|
|
46
|
-
|
|
47
|
-
if (existsSync(jsoncPath)) {
|
|
48
|
-
try {
|
|
49
|
-
const content = readFileSync(jsoncPath, 'utf-8');
|
|
50
|
-
return parseJsonc<MorphConfig>(content);
|
|
51
|
-
} catch {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (existsSync(jsonPath)) {
|
|
57
|
-
try {
|
|
58
|
-
const content = readFileSync(jsonPath, 'utf-8');
|
|
59
|
-
return JSON.parse(content) as MorphConfig;
|
|
60
|
-
} catch {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function loadMorphPluginConfigWithProjectOverride(
|
|
69
|
-
projectDir: string = process.cwd()
|
|
70
|
-
): MorphConfig {
|
|
71
|
-
const userConfig = loadMorphPluginConfig() ?? {};
|
|
72
|
-
|
|
73
|
-
const projectBasePath = join(projectDir, '.opencode', MORPH_PLUGIN_NAME);
|
|
74
|
-
const projectJsoncPath = `${projectBasePath}.jsonc`;
|
|
75
|
-
const projectJsonPath = `${projectBasePath}.json`;
|
|
76
|
-
|
|
77
|
-
let projectConfig: MorphConfig = {};
|
|
78
|
-
|
|
79
|
-
if (existsSync(projectJsoncPath)) {
|
|
80
|
-
try {
|
|
81
|
-
const content = readFileSync(projectJsoncPath, 'utf-8');
|
|
82
|
-
projectConfig = parseJsonc<MorphConfig>(content) ?? {};
|
|
83
|
-
} catch {
|
|
84
|
-
// Ignore parse errors
|
|
85
|
-
}
|
|
86
|
-
} else if (existsSync(projectJsonPath)) {
|
|
87
|
-
try {
|
|
88
|
-
const content = readFileSync(projectJsonPath, 'utf-8');
|
|
89
|
-
projectConfig = JSON.parse(content) as MorphConfig;
|
|
90
|
-
} catch {
|
|
91
|
-
// Ignore parse errors
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return { ...userConfig, ...projectConfig };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const config = loadMorphPluginConfigWithProjectOverride();
|
|
99
|
-
|
|
100
|
-
const routerConfigs = config.MORPH_ROUTER_CONFIGS || {};
|
|
101
|
-
|
|
102
|
-
export const API_KEY = config.MORPH_API_KEY || '';
|
|
103
|
-
export const MORPH_MODEL_EASY =
|
|
104
|
-
routerConfigs.MORPH_MODEL_EASY || config.MORPH_MODEL_EASY || '';
|
|
105
|
-
export const MORPH_MODEL_MEDIUM =
|
|
106
|
-
routerConfigs.MORPH_MODEL_MEDIUM || config.MORPH_MODEL_MEDIUM || '';
|
|
107
|
-
export const MORPH_MODEL_HARD =
|
|
108
|
-
routerConfigs.MORPH_MODEL_HARD || config.MORPH_MODEL_HARD || '';
|
|
109
|
-
export const MORPH_MODEL_DEFAULT =
|
|
110
|
-
routerConfigs.MORPH_MODEL_DEFAULT ||
|
|
111
|
-
config.MORPH_MODEL_DEFAULT ||
|
|
112
|
-
MORPH_MODEL_MEDIUM;
|
|
113
|
-
export const MORPH_ROUTER_ENABLED =
|
|
114
|
-
routerConfigs.MORPH_ROUTER_ENABLED ?? config.MORPH_ROUTER_ENABLED ?? true;
|
|
115
|
-
export const MORPH_ROUTER_PROMPT_CACHING_AWARE =
|
|
116
|
-
routerConfigs.MORPH_ROUTER_PROMPT_CACHING_AWARE ??
|
|
117
|
-
config.MORPH_ROUTER_PROMPT_CACHING_AWARE ??
|
|
118
|
-
false;
|