@ai-ide-bridge/cli 1.1.0 → 1.1.2
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/.turbo/turbo-build.log +1 -1
- package/dist/commands/configure.js +78 -10
- package/dist/commands/daemon.js +7 -4
- package/dist/commands/init.js +40 -1
- package/dist/core/parser.d.ts +5 -5
- package/dist/core/types.d.ts +4 -3
- package/dist/core/types.js +1 -1
- package/dist/plugins/copilot/session.js +1 -1
- package/dist/plugins/cursor/session.js +5 -1
- package/dist/utils/opencode.d.ts +3 -1
- package/dist/utils/opencode.js +3 -3
- package/package.json +2 -1
- package/src/commands/configure.ts +107 -12
- package/src/commands/daemon.ts +7 -9
- package/src/commands/init.ts +43 -1
- package/src/core/types.ts +2 -1
- package/src/plugins/copilot/session.ts +1 -1
- package/src/plugins/cursor/session.ts +6 -1
- package/src/utils/opencode.ts +4 -3
- package/test/configure.test.ts +19 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { findOpencodeConfig, injectProvider } from '../utils/opencode.js';
|
|
2
2
|
import { readConfig } from '../utils/config.js';
|
|
3
|
+
import { createInterface } from 'node:readline';
|
|
4
|
+
import { CursorBridgePlugin } from '../plugins/cursor/index.js';
|
|
5
|
+
import { CopilotBridgePlugin } from '../plugins/copilot/index.js';
|
|
6
|
+
import { WindsurfBridgePlugin } from '../plugins/windsurf/index.js';
|
|
7
|
+
const PROVIDER_PLUGINS = {
|
|
8
|
+
cursor: CursorBridgePlugin,
|
|
9
|
+
copilot: CopilotBridgePlugin,
|
|
10
|
+
windsurf: WindsurfBridgePlugin,
|
|
11
|
+
};
|
|
3
12
|
export async function configureOpencodeCommand() {
|
|
4
13
|
const configPath = findOpencodeConfig();
|
|
5
14
|
if (!configPath) {
|
|
@@ -7,15 +16,74 @@ export async function configureOpencodeCommand() {
|
|
|
7
16
|
process.exit(1);
|
|
8
17
|
}
|
|
9
18
|
const bridgeConfig = readConfig();
|
|
19
|
+
const configuredPlugins = Object.keys(bridgeConfig.plugins || {});
|
|
20
|
+
if (configuredPlugins.length === 0) {
|
|
21
|
+
console.error('No plugins configured. Run `llm-bridge init` first.');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
const allSelectedModels = {};
|
|
25
|
+
let firstSelectedModelId = null;
|
|
26
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
27
|
+
const ask = (q) => new Promise((resolve) => rl.question(q, resolve));
|
|
28
|
+
for (const pluginName of configuredPlugins) {
|
|
29
|
+
const PluginClass = PROVIDER_PLUGINS[pluginName];
|
|
30
|
+
if (!PluginClass) {
|
|
31
|
+
console.warn(`Skipping unknown provider: ${pluginName}`);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const plugin = new PluginClass();
|
|
35
|
+
const pluginConfig = bridgeConfig.plugins[pluginName];
|
|
36
|
+
let models;
|
|
37
|
+
try {
|
|
38
|
+
models = await plugin.listModels(pluginConfig);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
console.warn(`Failed to list models for ${pluginName}: ${e instanceof Error ? e.message : String(e)}`);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (models.length === 0) {
|
|
45
|
+
console.warn(`No models available for ${pluginName}.`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
console.log(`\nModels available for ${pluginName}:`);
|
|
49
|
+
models.forEach((m, i) => {
|
|
50
|
+
console.log(` ${i + 1}) ${pluginName}/${m.id}`);
|
|
51
|
+
});
|
|
52
|
+
const input = await ask(`Select models (comma-separated numbers, 'all', or 'skip'): `);
|
|
53
|
+
let selectedIndices = [];
|
|
54
|
+
if (input.toLowerCase() === 'all') {
|
|
55
|
+
selectedIndices = models.map((_, i) => i);
|
|
56
|
+
}
|
|
57
|
+
else if (input.toLowerCase() === 'skip') {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
selectedIndices = input
|
|
62
|
+
.split(',')
|
|
63
|
+
.map((s) => parseInt(s.trim(), 10) - 1)
|
|
64
|
+
.filter((i) => i >= 0 && i < models.length);
|
|
65
|
+
}
|
|
66
|
+
if (selectedIndices.length === 0) {
|
|
67
|
+
console.log(`No models selected for ${pluginName}. Skipping.`);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
for (const idx of selectedIndices) {
|
|
71
|
+
const model = models[idx];
|
|
72
|
+
const qualifiedId = `${pluginName}/${model.id}`;
|
|
73
|
+
allSelectedModels[qualifiedId] = { name: qualifiedId };
|
|
74
|
+
if (!firstSelectedModelId) {
|
|
75
|
+
firstSelectedModelId = qualifiedId;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
rl.close();
|
|
80
|
+
if (Object.keys(allSelectedModels).length === 0) {
|
|
81
|
+
console.error('No models selected. Run `llm-bridge configure` again to try again.');
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
10
84
|
const providerId = 'llm-bridge';
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
? 'windsurf/claude-4.5-sonnet'
|
|
16
|
-
: 'cursor/composer-2';
|
|
17
|
-
injectProvider(configPath, providerId, modelId, bridgeConfig.port);
|
|
18
|
-
console.log(`Injected provider into ${configPath}`);
|
|
19
|
-
console.log(`Provider: ${providerId}, Model: ${modelId}, Port: ${bridgeConfig.port}`);
|
|
20
|
-
console.log(`Plugin: ${plugin}`);
|
|
85
|
+
injectProvider(configPath, providerId, allSelectedModels, bridgeConfig.port, firstSelectedModelId);
|
|
86
|
+
const modelCount = Object.keys(allSelectedModels).length;
|
|
87
|
+
console.log(`\nInjected provider into ${configPath}`);
|
|
88
|
+
console.log(`Provider: ${providerId}, Models: ${modelCount}, Default: ${firstSelectedModelId}`);
|
|
21
89
|
}
|
package/dist/commands/daemon.js
CHANGED
|
@@ -20,7 +20,8 @@ export async function installDaemonCommand() {
|
|
|
20
20
|
}
|
|
21
21
|
async function installMacOSDaemon() {
|
|
22
22
|
const plistPath = path.join(os.homedir(), 'Library', 'LaunchAgents', `${LABEL}.plist`);
|
|
23
|
-
const
|
|
23
|
+
const binaryPath = process.execPath;
|
|
24
|
+
const uid = os.userInfo().uid;
|
|
24
25
|
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
25
26
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
26
27
|
<plist version="1.0">
|
|
@@ -29,7 +30,8 @@ async function installMacOSDaemon() {
|
|
|
29
30
|
<string>${LABEL}</string>
|
|
30
31
|
<key>ProgramArguments</key>
|
|
31
32
|
<array>
|
|
32
|
-
<string>${
|
|
33
|
+
<string>${binaryPath}</string>
|
|
34
|
+
<string>start</string>
|
|
33
35
|
</array>
|
|
34
36
|
<key>RunAtLoad</key>
|
|
35
37
|
<true/>
|
|
@@ -52,7 +54,7 @@ async function installMacOSDaemon() {
|
|
|
52
54
|
process.exit(1);
|
|
53
55
|
}
|
|
54
56
|
try {
|
|
55
|
-
execSync(`launchctl bootstrap
|
|
57
|
+
execSync(`launchctl bootstrap gui/${uid} "${plistPath}"`, { stdio: 'inherit' });
|
|
56
58
|
console.log(`Installed LaunchAgent: ${plistPath}`);
|
|
57
59
|
console.log(`Logs: ~/Library/Logs/llm-bridge.{log,err.log}`);
|
|
58
60
|
}
|
|
@@ -112,8 +114,9 @@ export async function uninstallDaemonCommand() {
|
|
|
112
114
|
}
|
|
113
115
|
async function uninstallMacOSDaemon() {
|
|
114
116
|
const plistPath = path.join(os.homedir(), 'Library', 'LaunchAgents', `${LABEL}.plist`);
|
|
117
|
+
const uid = os.userInfo().uid;
|
|
115
118
|
try {
|
|
116
|
-
execSync(`launchctl bootout
|
|
119
|
+
execSync(`launchctl bootout gui/${uid} "${plistPath}" 2>/dev/null || true`, {
|
|
117
120
|
stdio: 'inherit',
|
|
118
121
|
});
|
|
119
122
|
}
|
package/dist/commands/init.js
CHANGED
|
@@ -3,6 +3,7 @@ import { CursorBridgePlugin } from '../plugins/cursor/index.js';
|
|
|
3
3
|
import { CopilotBridgePlugin } from '../plugins/copilot/index.js';
|
|
4
4
|
import { WindsurfBridgePlugin } from '../plugins/windsurf/index.js';
|
|
5
5
|
import { createInterface } from 'node:readline';
|
|
6
|
+
import { stdin as processStdin, stdout as processStdout } from 'node:process';
|
|
6
7
|
import { loginCommand } from './login.js';
|
|
7
8
|
const PROVIDERS = ['cursor', 'copilot', 'windsurf'];
|
|
8
9
|
async function getProviderPlugin(provider) {
|
|
@@ -43,6 +44,44 @@ async function authenticateWithOAuth(provider) {
|
|
|
43
44
|
console.log(`OAuth not available for ${provider}. Use token authentication instead.`);
|
|
44
45
|
return false;
|
|
45
46
|
}
|
|
47
|
+
async function askHidden(prompt) {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const stdin = processStdin;
|
|
50
|
+
const stdout = processStdout;
|
|
51
|
+
stdout.write(prompt);
|
|
52
|
+
const wasRaw = stdin.isRaw;
|
|
53
|
+
stdin.setRawMode(true);
|
|
54
|
+
stdin.resume();
|
|
55
|
+
let input = '';
|
|
56
|
+
const onData = (data) => {
|
|
57
|
+
const char = data.toString();
|
|
58
|
+
if (char === '\r' || char === '\n') {
|
|
59
|
+
stdin.setRawMode(wasRaw);
|
|
60
|
+
stdin.pause();
|
|
61
|
+
stdin.removeListener('data', onData);
|
|
62
|
+
stdout.write('\n');
|
|
63
|
+
resolve(input);
|
|
64
|
+
}
|
|
65
|
+
else if (char === '\x7f' || char === '\b') {
|
|
66
|
+
if (input.length > 0) {
|
|
67
|
+
input = input.slice(0, -1);
|
|
68
|
+
stdout.write('\b \b');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (char === '\x03') {
|
|
72
|
+
stdin.setRawMode(wasRaw);
|
|
73
|
+
stdin.pause();
|
|
74
|
+
stdin.removeListener('data', onData);
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
input += char;
|
|
79
|
+
stdout.write('*');
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
stdin.on('data', onData);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
46
85
|
export async function initCommand() {
|
|
47
86
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
48
87
|
const ask = (q) => new Promise((resolve) => rl.question(q, resolve));
|
|
@@ -82,7 +121,7 @@ export async function initCommand() {
|
|
|
82
121
|
}
|
|
83
122
|
}
|
|
84
123
|
const envVar = getEnvVar(provider);
|
|
85
|
-
const credential = await
|
|
124
|
+
const credential = await askHidden(getCredentialPrompt(provider));
|
|
86
125
|
if (!credential) {
|
|
87
126
|
console.error('Credential is required.');
|
|
88
127
|
continue;
|
package/dist/core/parser.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ declare const ChatRequestSchema: z.ZodObject<{
|
|
|
4
4
|
model: z.ZodString;
|
|
5
5
|
messages: z.ZodArray<z.ZodObject<{
|
|
6
6
|
role: z.ZodEnum<["system", "user", "assistant", "tool", "function"]>;
|
|
7
|
-
content: z.ZodOptional<z.ZodNullable<z.
|
|
7
|
+
content: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
8
8
|
name: z.ZodOptional<z.ZodString>;
|
|
9
9
|
tool_call_id: z.ZodOptional<z.ZodString>;
|
|
10
10
|
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
@@ -37,7 +37,7 @@ declare const ChatRequestSchema: z.ZodObject<{
|
|
|
37
37
|
}>, "many">>;
|
|
38
38
|
}, "strip", z.ZodTypeAny, {
|
|
39
39
|
role: "function" | "system" | "user" | "assistant" | "tool";
|
|
40
|
-
content?:
|
|
40
|
+
content?: unknown;
|
|
41
41
|
name?: string | undefined;
|
|
42
42
|
tool_call_id?: string | undefined;
|
|
43
43
|
tool_calls?: {
|
|
@@ -50,7 +50,7 @@ declare const ChatRequestSchema: z.ZodObject<{
|
|
|
50
50
|
}[] | undefined;
|
|
51
51
|
}, {
|
|
52
52
|
role: "function" | "system" | "user" | "assistant" | "tool";
|
|
53
|
-
content?:
|
|
53
|
+
content?: unknown;
|
|
54
54
|
name?: string | undefined;
|
|
55
55
|
tool_call_id?: string | undefined;
|
|
56
56
|
tool_calls?: {
|
|
@@ -98,7 +98,7 @@ declare const ChatRequestSchema: z.ZodObject<{
|
|
|
98
98
|
model: string;
|
|
99
99
|
messages: {
|
|
100
100
|
role: "function" | "system" | "user" | "assistant" | "tool";
|
|
101
|
-
content?:
|
|
101
|
+
content?: unknown;
|
|
102
102
|
name?: string | undefined;
|
|
103
103
|
tool_call_id?: string | undefined;
|
|
104
104
|
tool_calls?: {
|
|
@@ -124,7 +124,7 @@ declare const ChatRequestSchema: z.ZodObject<{
|
|
|
124
124
|
model: string;
|
|
125
125
|
messages: {
|
|
126
126
|
role: "function" | "system" | "user" | "assistant" | "tool";
|
|
127
|
-
content?:
|
|
127
|
+
content?: unknown;
|
|
128
128
|
name?: string | undefined;
|
|
129
129
|
tool_call_id?: string | undefined;
|
|
130
130
|
tool_calls?: {
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const MessageSchema: z.ZodObject<{
|
|
3
3
|
role: z.ZodEnum<["system", "user", "assistant", "tool", "function"]>;
|
|
4
|
-
content: z.ZodOptional<z.ZodNullable<z.
|
|
4
|
+
content: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
5
5
|
name: z.ZodOptional<z.ZodString>;
|
|
6
6
|
tool_call_id: z.ZodOptional<z.ZodString>;
|
|
7
7
|
tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
@@ -34,7 +34,7 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
34
34
|
}>, "many">>;
|
|
35
35
|
}, "strip", z.ZodTypeAny, {
|
|
36
36
|
role: "function" | "system" | "user" | "assistant" | "tool";
|
|
37
|
-
content?:
|
|
37
|
+
content?: unknown;
|
|
38
38
|
name?: string | undefined;
|
|
39
39
|
tool_call_id?: string | undefined;
|
|
40
40
|
tool_calls?: {
|
|
@@ -47,7 +47,7 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
47
47
|
}[] | undefined;
|
|
48
48
|
}, {
|
|
49
49
|
role: "function" | "system" | "user" | "assistant" | "tool";
|
|
50
|
-
content?:
|
|
50
|
+
content?: unknown;
|
|
51
51
|
name?: string | undefined;
|
|
52
52
|
tool_call_id?: string | undefined;
|
|
53
53
|
tool_calls?: {
|
|
@@ -140,6 +140,7 @@ export interface StreamChunk {
|
|
|
140
140
|
export interface BridgePlugin {
|
|
141
141
|
name: string;
|
|
142
142
|
version: string;
|
|
143
|
+
oauthProvider?: import('@ai-ide-bridge/oauth').OAuthProvider;
|
|
143
144
|
authenticate(config: Record<string, string>): Promise<boolean>;
|
|
144
145
|
listModels(config: Record<string, string>): Promise<ModelInfo[]>;
|
|
145
146
|
createSession(config: Record<string, string>, model: string): Promise<BridgeSession>;
|
package/dist/core/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export const MessageSchema = z.object({
|
|
3
3
|
role: z.enum(['system', 'user', 'assistant', 'tool', 'function']),
|
|
4
|
-
content: z.
|
|
4
|
+
content: z.unknown().nullable().optional(),
|
|
5
5
|
name: z.string().optional(),
|
|
6
6
|
tool_call_id: z.string().optional(),
|
|
7
7
|
tool_calls: z
|
|
@@ -12,7 +12,7 @@ export class CopilotBridgeSession {
|
|
|
12
12
|
model: this.modelId,
|
|
13
13
|
messages: messages.map((m) => ({
|
|
14
14
|
role: m.role,
|
|
15
|
-
content: m.content
|
|
15
|
+
content: m.content,
|
|
16
16
|
...(m.tool_calls && { tool_calls: m.tool_calls }),
|
|
17
17
|
...(m.tool_call_id && { tool_call_id: m.tool_call_id }),
|
|
18
18
|
})),
|
|
@@ -58,7 +58,11 @@ export class CursorBridgeSession {
|
|
|
58
58
|
buildPrompt(messages) {
|
|
59
59
|
const blocks = [];
|
|
60
60
|
for (const m of messages) {
|
|
61
|
-
const text = typeof m.content === 'string'
|
|
61
|
+
const text = typeof m.content === 'string'
|
|
62
|
+
? m.content
|
|
63
|
+
: m.content != null
|
|
64
|
+
? JSON.stringify(m.content)
|
|
65
|
+
: '';
|
|
62
66
|
if (!text)
|
|
63
67
|
continue;
|
|
64
68
|
const label = m.role === 'tool' ? `tool (${m.tool_call_id ?? m.name ?? 'result'})` : m.role;
|
package/dist/utils/opencode.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare function findOpencodeConfig(): string | null;
|
|
2
|
-
export declare function injectProvider(configPath: string, providerId: string,
|
|
2
|
+
export declare function injectProvider(configPath: string, providerId: string, models: Record<string, {
|
|
3
|
+
name: string;
|
|
4
|
+
}>, port: number, defaultModelId: string): void;
|
package/dist/utils/opencode.js
CHANGED
|
@@ -14,7 +14,7 @@ export function findOpencodeConfig() {
|
|
|
14
14
|
}
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
|
-
export function injectProvider(configPath, providerId,
|
|
17
|
+
export function injectProvider(configPath, providerId, models, port, defaultModelId) {
|
|
18
18
|
const raw = fs.readFileSync(configPath, 'utf8');
|
|
19
19
|
let config;
|
|
20
20
|
try {
|
|
@@ -32,8 +32,8 @@ export function injectProvider(configPath, providerId, modelId, port) {
|
|
|
32
32
|
apiKey: 'bridge-local',
|
|
33
33
|
baseURL: `http://127.0.0.1:${port}/v1`,
|
|
34
34
|
},
|
|
35
|
-
models
|
|
35
|
+
models,
|
|
36
36
|
};
|
|
37
|
-
config.model = `${providerId}/${
|
|
37
|
+
config.model = `${providerId}/${defaultModelId}`;
|
|
38
38
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
39
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ide-bridge/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"llm-bridge": "./dist/index.js"
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"start": "node dist/index.js"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"@ai-ide-bridge/oauth": "workspace:*",
|
|
17
18
|
"@cursor/sdk": "^1.0.13",
|
|
18
19
|
"zod": "^3.25.76"
|
|
19
20
|
},
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { findOpencodeConfig, injectProvider } from '../utils/opencode.js';
|
|
2
2
|
import { readConfig } from '../utils/config.js';
|
|
3
|
+
import { createInterface } from 'node:readline';
|
|
4
|
+
import { CursorBridgePlugin } from '../plugins/cursor/index.js';
|
|
5
|
+
import { CopilotBridgePlugin } from '../plugins/copilot/index.js';
|
|
6
|
+
import { WindsurfBridgePlugin } from '../plugins/windsurf/index.js';
|
|
7
|
+
|
|
8
|
+
const PROVIDER_PLUGINS: Record<
|
|
9
|
+
string,
|
|
10
|
+
new () => {
|
|
11
|
+
name: string;
|
|
12
|
+
listModels(config: Record<string, string>): Promise<{ id: string; name: string }[]>;
|
|
13
|
+
}
|
|
14
|
+
> = {
|
|
15
|
+
cursor: CursorBridgePlugin,
|
|
16
|
+
copilot: CopilotBridgePlugin,
|
|
17
|
+
windsurf: WindsurfBridgePlugin,
|
|
18
|
+
};
|
|
3
19
|
|
|
4
20
|
export async function configureOpencodeCommand(): Promise<void> {
|
|
5
21
|
const configPath = findOpencodeConfig();
|
|
@@ -9,17 +25,96 @@ export async function configureOpencodeCommand(): Promise<void> {
|
|
|
9
25
|
}
|
|
10
26
|
|
|
11
27
|
const bridgeConfig = readConfig();
|
|
28
|
+
const configuredPlugins = Object.keys(bridgeConfig.plugins || {});
|
|
29
|
+
|
|
30
|
+
if (configuredPlugins.length === 0) {
|
|
31
|
+
console.error('No plugins configured. Run `llm-bridge init` first.');
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const allSelectedModels: Record<string, { name: string }> = {};
|
|
36
|
+
let firstSelectedModelId: string | null = null;
|
|
37
|
+
|
|
38
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
39
|
+
const ask = (q: string) => new Promise<string>((resolve) => rl.question(q, resolve));
|
|
40
|
+
|
|
41
|
+
for (const pluginName of configuredPlugins) {
|
|
42
|
+
const PluginClass = PROVIDER_PLUGINS[pluginName];
|
|
43
|
+
if (!PluginClass) {
|
|
44
|
+
console.warn(`Skipping unknown provider: ${pluginName}`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const plugin = new PluginClass();
|
|
49
|
+
const pluginConfig = bridgeConfig.plugins[pluginName];
|
|
50
|
+
|
|
51
|
+
let models: { id: string; name: string }[];
|
|
52
|
+
try {
|
|
53
|
+
models = await plugin.listModels(pluginConfig);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.warn(
|
|
56
|
+
`Failed to list models for ${pluginName}: ${e instanceof Error ? e.message : String(e)}`,
|
|
57
|
+
);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (models.length === 0) {
|
|
62
|
+
console.warn(`No models available for ${pluginName}.`);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log(`\nModels available for ${pluginName}:`);
|
|
67
|
+
models.forEach((m, i) => {
|
|
68
|
+
console.log(` ${i + 1}) ${pluginName}/${m.id}`);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const input = await ask(`Select models (comma-separated numbers, 'all', or 'skip'): `);
|
|
72
|
+
|
|
73
|
+
let selectedIndices: number[] = [];
|
|
74
|
+
|
|
75
|
+
if (input.toLowerCase() === 'all') {
|
|
76
|
+
selectedIndices = models.map((_, i) => i);
|
|
77
|
+
} else if (input.toLowerCase() === 'skip') {
|
|
78
|
+
continue;
|
|
79
|
+
} else {
|
|
80
|
+
selectedIndices = input
|
|
81
|
+
.split(',')
|
|
82
|
+
.map((s) => parseInt(s.trim(), 10) - 1)
|
|
83
|
+
.filter((i) => i >= 0 && i < models.length);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (selectedIndices.length === 0) {
|
|
87
|
+
console.log(`No models selected for ${pluginName}. Skipping.`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (const idx of selectedIndices) {
|
|
92
|
+
const model = models[idx];
|
|
93
|
+
const qualifiedId = `${pluginName}/${model.id}`;
|
|
94
|
+
allSelectedModels[qualifiedId] = { name: qualifiedId };
|
|
95
|
+
if (!firstSelectedModelId) {
|
|
96
|
+
firstSelectedModelId = qualifiedId;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
rl.close();
|
|
102
|
+
|
|
103
|
+
if (Object.keys(allSelectedModels).length === 0) {
|
|
104
|
+
console.error('No models selected. Run `llm-bridge configure` again to try again.');
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
|
|
12
108
|
const providerId = 'llm-bridge';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
console.log(
|
|
23
|
-
console.log(`Provider: ${providerId},
|
|
24
|
-
console.log(`Plugin: ${plugin}`);
|
|
109
|
+
injectProvider(
|
|
110
|
+
configPath,
|
|
111
|
+
providerId,
|
|
112
|
+
allSelectedModels,
|
|
113
|
+
bridgeConfig.port,
|
|
114
|
+
firstSelectedModelId!,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const modelCount = Object.keys(allSelectedModels).length;
|
|
118
|
+
console.log(`\nInjected provider into ${configPath}`);
|
|
119
|
+
console.log(`Provider: ${providerId}, Models: ${modelCount}, Default: ${firstSelectedModelId}`);
|
|
25
120
|
}
|
package/src/commands/daemon.ts
CHANGED
|
@@ -21,12 +21,8 @@ export async function installDaemonCommand(): Promise<void> {
|
|
|
21
21
|
|
|
22
22
|
async function installMacOSDaemon(): Promise<void> {
|
|
23
23
|
const plistPath = path.join(os.homedir(), 'Library', 'LaunchAgents', `${LABEL}.plist`);
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
'..',
|
|
27
|
-
'scripts',
|
|
28
|
-
'llm-bridge-daemon.sh',
|
|
29
|
-
);
|
|
24
|
+
const binaryPath = process.execPath;
|
|
25
|
+
const uid = os.userInfo().uid;
|
|
30
26
|
|
|
31
27
|
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
32
28
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
@@ -36,7 +32,8 @@ async function installMacOSDaemon(): Promise<void> {
|
|
|
36
32
|
<string>${LABEL}</string>
|
|
37
33
|
<key>ProgramArguments</key>
|
|
38
34
|
<array>
|
|
39
|
-
<string>${
|
|
35
|
+
<string>${binaryPath}</string>
|
|
36
|
+
<string>start</string>
|
|
40
37
|
</array>
|
|
41
38
|
<key>RunAtLoad</key>
|
|
42
39
|
<true/>
|
|
@@ -60,7 +57,7 @@ async function installMacOSDaemon(): Promise<void> {
|
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
try {
|
|
63
|
-
execSync(`launchctl bootstrap
|
|
60
|
+
execSync(`launchctl bootstrap gui/${uid} "${plistPath}"`, { stdio: 'inherit' });
|
|
64
61
|
console.log(`Installed LaunchAgent: ${plistPath}`);
|
|
65
62
|
console.log(`Logs: ~/Library/Logs/llm-bridge.{log,err.log}`);
|
|
66
63
|
} catch (e) {
|
|
@@ -122,9 +119,10 @@ export async function uninstallDaemonCommand(): Promise<void> {
|
|
|
122
119
|
|
|
123
120
|
async function uninstallMacOSDaemon(): Promise<void> {
|
|
124
121
|
const plistPath = path.join(os.homedir(), 'Library', 'LaunchAgents', `${LABEL}.plist`);
|
|
122
|
+
const uid = os.userInfo().uid;
|
|
125
123
|
|
|
126
124
|
try {
|
|
127
|
-
execSync(`launchctl bootout
|
|
125
|
+
execSync(`launchctl bootout gui/${uid} "${plistPath}" 2>/dev/null || true`, {
|
|
128
126
|
stdio: 'inherit',
|
|
129
127
|
});
|
|
130
128
|
} catch {
|
package/src/commands/init.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { CursorBridgePlugin } from '../plugins/cursor/index.js';
|
|
|
3
3
|
import { CopilotBridgePlugin } from '../plugins/copilot/index.js';
|
|
4
4
|
import { WindsurfBridgePlugin } from '../plugins/windsurf/index.js';
|
|
5
5
|
import { createInterface } from 'node:readline';
|
|
6
|
+
import { stdin as processStdin, stdout as processStdout } from 'node:process';
|
|
6
7
|
import { loginCommand } from './login.js';
|
|
7
8
|
|
|
8
9
|
const PROVIDERS = ['cursor', 'copilot', 'windsurf'] as const;
|
|
@@ -50,6 +51,47 @@ async function authenticateWithOAuth(provider: Provider): Promise<boolean> {
|
|
|
50
51
|
return false;
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
async function askHidden(prompt: string): Promise<string> {
|
|
55
|
+
return new Promise<string>((resolve, reject) => {
|
|
56
|
+
const stdin = processStdin;
|
|
57
|
+
const stdout = processStdout;
|
|
58
|
+
|
|
59
|
+
stdout.write(prompt);
|
|
60
|
+
|
|
61
|
+
const wasRaw = stdin.isRaw;
|
|
62
|
+
stdin.setRawMode(true);
|
|
63
|
+
stdin.resume();
|
|
64
|
+
|
|
65
|
+
let input = '';
|
|
66
|
+
|
|
67
|
+
const onData = (data: Buffer) => {
|
|
68
|
+
const char = data.toString();
|
|
69
|
+
if (char === '\r' || char === '\n') {
|
|
70
|
+
stdin.setRawMode(wasRaw);
|
|
71
|
+
stdin.pause();
|
|
72
|
+
stdin.removeListener('data', onData);
|
|
73
|
+
stdout.write('\n');
|
|
74
|
+
resolve(input);
|
|
75
|
+
} else if (char === '\x7f' || char === '\b') {
|
|
76
|
+
if (input.length > 0) {
|
|
77
|
+
input = input.slice(0, -1);
|
|
78
|
+
stdout.write('\b \b');
|
|
79
|
+
}
|
|
80
|
+
} else if (char === '\x03') {
|
|
81
|
+
stdin.setRawMode(wasRaw);
|
|
82
|
+
stdin.pause();
|
|
83
|
+
stdin.removeListener('data', onData);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
} else {
|
|
86
|
+
input += char;
|
|
87
|
+
stdout.write('*');
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
stdin.on('data', onData);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
53
95
|
export async function initCommand(): Promise<void> {
|
|
54
96
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
55
97
|
const ask = (q: string) => new Promise<string>((resolve) => rl.question(q, resolve));
|
|
@@ -95,7 +137,7 @@ export async function initCommand(): Promise<void> {
|
|
|
95
137
|
}
|
|
96
138
|
|
|
97
139
|
const envVar = getEnvVar(provider);
|
|
98
|
-
const credential = await
|
|
140
|
+
const credential = await askHidden(getCredentialPrompt(provider));
|
|
99
141
|
if (!credential) {
|
|
100
142
|
console.error('Credential is required.');
|
|
101
143
|
continue;
|
package/src/core/types.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
|
|
3
3
|
export const MessageSchema = z.object({
|
|
4
4
|
role: z.enum(['system', 'user', 'assistant', 'tool', 'function']),
|
|
5
|
-
content: z.
|
|
5
|
+
content: z.unknown().nullable().optional(),
|
|
6
6
|
name: z.string().optional(),
|
|
7
7
|
tool_call_id: z.string().optional(),
|
|
8
8
|
tool_calls: z
|
|
@@ -63,6 +63,7 @@ export interface StreamChunk {
|
|
|
63
63
|
export interface BridgePlugin {
|
|
64
64
|
name: string;
|
|
65
65
|
version: string;
|
|
66
|
+
oauthProvider?: import('@ai-ide-bridge/oauth').OAuthProvider;
|
|
66
67
|
authenticate(config: Record<string, string>): Promise<boolean>;
|
|
67
68
|
listModels(config: Record<string, string>): Promise<ModelInfo[]>;
|
|
68
69
|
createSession(config: Record<string, string>, model: string): Promise<BridgeSession>;
|
|
@@ -17,7 +17,7 @@ export class CopilotBridgeSession implements BridgeSession {
|
|
|
17
17
|
model: this.modelId,
|
|
18
18
|
messages: messages.map((m) => ({
|
|
19
19
|
role: m.role,
|
|
20
|
-
content: m.content
|
|
20
|
+
content: m.content,
|
|
21
21
|
...(m.tool_calls && { tool_calls: m.tool_calls }),
|
|
22
22
|
...(m.tool_call_id && { tool_call_id: m.tool_call_id }),
|
|
23
23
|
})),
|
|
@@ -68,7 +68,12 @@ export class CursorBridgeSession implements BridgeSession {
|
|
|
68
68
|
private buildPrompt(messages: Message[]): string {
|
|
69
69
|
const blocks: string[] = [];
|
|
70
70
|
for (const m of messages) {
|
|
71
|
-
const text =
|
|
71
|
+
const text =
|
|
72
|
+
typeof m.content === 'string'
|
|
73
|
+
? m.content
|
|
74
|
+
: m.content != null
|
|
75
|
+
? JSON.stringify(m.content)
|
|
76
|
+
: '';
|
|
72
77
|
if (!text) continue;
|
|
73
78
|
const label = m.role === 'tool' ? `tool (${m.tool_call_id ?? m.name ?? 'result'})` : m.role;
|
|
74
79
|
blocks.push(`[${label}]\n${text}`);
|
package/src/utils/opencode.ts
CHANGED
|
@@ -18,8 +18,9 @@ export function findOpencodeConfig(): string | null {
|
|
|
18
18
|
export function injectProvider(
|
|
19
19
|
configPath: string,
|
|
20
20
|
providerId: string,
|
|
21
|
-
|
|
21
|
+
models: Record<string, { name: string }>,
|
|
22
22
|
port: number,
|
|
23
|
+
defaultModelId: string,
|
|
23
24
|
): void {
|
|
24
25
|
const raw = fs.readFileSync(configPath, 'utf8');
|
|
25
26
|
let config: any;
|
|
@@ -36,8 +37,8 @@ export function injectProvider(
|
|
|
36
37
|
apiKey: 'bridge-local',
|
|
37
38
|
baseURL: `http://127.0.0.1:${port}/v1`,
|
|
38
39
|
},
|
|
39
|
-
models
|
|
40
|
+
models,
|
|
40
41
|
};
|
|
41
|
-
config.model = `${providerId}/${
|
|
42
|
+
config.model = `${providerId}/${defaultModelId}`;
|
|
42
43
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
43
44
|
}
|
package/test/configure.test.ts
CHANGED
|
@@ -12,17 +12,32 @@ describe('opencode utils', () => {
|
|
|
12
12
|
fs.writeFileSync(tmpFile, '{}');
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
it('injects provider into empty config', () => {
|
|
16
|
-
|
|
15
|
+
it('injects provider with single model into empty config', () => {
|
|
16
|
+
const models = { 'cursor/composer-2': { name: 'cursor/composer-2' } };
|
|
17
|
+
injectProvider(tmpFile, 'test-provider', models, 3849, 'cursor/composer-2');
|
|
17
18
|
const config = JSON.parse(fs.readFileSync(tmpFile, 'utf8'));
|
|
18
19
|
expect(config.provider['test-provider']).toBeDefined();
|
|
19
20
|
expect(config.provider['test-provider'].options.baseURL).toBe('http://127.0.0.1:3849/v1');
|
|
20
|
-
expect(config.
|
|
21
|
+
expect(config.provider['test-provider'].models['cursor/composer-2']).toBeDefined();
|
|
22
|
+
expect(config.model).toBe('test-provider/cursor/composer-2');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('injects provider with multiple models', () => {
|
|
26
|
+
const models = {
|
|
27
|
+
'cursor/composer-2': { name: 'cursor/composer-2' },
|
|
28
|
+
'cursor/gpt-4o': { name: 'cursor/gpt-4o' },
|
|
29
|
+
};
|
|
30
|
+
injectProvider(tmpFile, 'test-provider', models, 3849, 'cursor/gpt-4o');
|
|
31
|
+
const config = JSON.parse(fs.readFileSync(tmpFile, 'utf8'));
|
|
32
|
+
expect(config.provider['test-provider'].models['cursor/composer-2']).toBeDefined();
|
|
33
|
+
expect(config.provider['test-provider'].models['cursor/gpt-4o']).toBeDefined();
|
|
34
|
+
expect(config.model).toBe('test-provider/cursor/gpt-4o');
|
|
21
35
|
});
|
|
22
36
|
|
|
23
37
|
it('preserves existing config fields', () => {
|
|
24
38
|
fs.writeFileSync(tmpFile, JSON.stringify({ existing: 'value' }));
|
|
25
|
-
|
|
39
|
+
const models = { 'cursor/composer-2': { name: 'cursor/composer-2' } };
|
|
40
|
+
injectProvider(tmpFile, 'test-provider', models, 3849, 'cursor/composer-2');
|
|
26
41
|
const config = JSON.parse(fs.readFileSync(tmpFile, 'utf8'));
|
|
27
42
|
expect(config.existing).toBe('value');
|
|
28
43
|
expect(config.provider['test-provider']).toBeDefined();
|