@myrialabs/clopen 0.4.15 → 0.4.17
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 +8 -5
- package/backend/artifacts/matrix.ts +8 -0
- package/backend/artifacts/types.ts +2 -2
- package/backend/auth/permissions.ts +14 -0
- package/backend/chat/stream-manager.ts +5 -5
- package/backend/commands/detect.ts +1 -1
- package/backend/commands/sync.ts +1 -1
- package/backend/database/migrations/057_seed_pi_provider.ts +25 -0
- package/backend/database/migrations/058_seed_cline_provider.ts +25 -0
- package/backend/database/migrations/059_seed_cursor_provider.ts +25 -0
- package/backend/database/migrations/index.ts +21 -0
- package/backend/engine/README.md +36 -13
- package/backend/engine/adapters/cline/agent-tool.ts +64 -0
- package/backend/engine/adapters/cline/ask-question-tool.ts +105 -0
- package/backend/engine/adapters/cline/credential.ts +166 -0
- package/backend/engine/adapters/cline/error-handler.ts +49 -0
- package/backend/engine/adapters/cline/index.ts +1 -0
- package/backend/engine/adapters/cline/mcp-tools.ts +119 -0
- package/backend/engine/adapters/cline/message-converter.ts +396 -0
- package/backend/engine/adapters/cline/models.ts +73 -0
- package/backend/engine/adapters/cline/presets.ts +128 -0
- package/backend/engine/adapters/cline/stream.ts +413 -0
- package/backend/engine/adapters/codex/credential.ts +1 -1
- package/backend/engine/adapters/codex/message-converter.ts +4 -4
- package/backend/engine/adapters/codex/session-fork.ts +1 -1
- package/backend/engine/adapters/codex/stream.ts +3 -3
- package/backend/engine/adapters/copilot/stream.ts +1 -1
- package/backend/engine/adapters/cursor/ask-question-tool.ts +98 -0
- package/backend/engine/adapters/cursor/credential.ts +68 -0
- package/backend/engine/adapters/cursor/environment.ts +32 -0
- package/backend/engine/adapters/cursor/error-handler.ts +60 -0
- package/backend/engine/adapters/cursor/index.ts +1 -0
- package/backend/engine/adapters/cursor/message-converter.ts +615 -0
- package/backend/engine/adapters/cursor/models.ts +68 -0
- package/backend/engine/adapters/cursor/session-fork.ts +68 -0
- package/backend/engine/adapters/cursor/stream.ts +341 -0
- package/backend/engine/adapters/pi/agent-tool.ts +62 -0
- package/backend/engine/adapters/pi/ask-question-tool.ts +93 -0
- package/backend/engine/adapters/pi/credential.ts +137 -0
- package/backend/engine/adapters/pi/environment.ts +33 -0
- package/backend/engine/adapters/pi/error-handler.ts +46 -0
- package/backend/engine/adapters/pi/index.ts +1 -0
- package/backend/engine/adapters/pi/mcp-tools.ts +131 -0
- package/backend/engine/adapters/pi/message-converter.ts +446 -0
- package/backend/engine/adapters/pi/models.ts +53 -0
- package/backend/engine/adapters/pi/presets.ts +133 -0
- package/backend/engine/adapters/pi/session-fork.ts +46 -0
- package/backend/engine/adapters/pi/stream.ts +427 -0
- package/backend/engine/adapters/qwen/message-converter.ts +5 -5
- package/backend/engine/adapters/qwen/stream.ts +2 -2
- package/backend/engine/docs/adapter-contract.md +7 -2
- package/backend/engine/docs/adding-an-engine.md +70 -12
- package/backend/engine/docs/artifacts.md +124 -0
- package/backend/engine/docs/database.md +4 -4
- package/backend/engine/docs/frontend-and-chat.md +22 -4
- package/backend/engine/docs/lessons-learned.md +219 -32
- package/backend/engine/docs/quick-reference.md +18 -7
- package/backend/engine/docs/websocket-routes.md +2 -2
- package/backend/engine/index.ts +9 -0
- package/backend/mcp/README.md +3 -3
- package/backend/mcp/external/config.ts +11 -0
- package/backend/mcp/index.ts +8 -0
- package/backend/mcp/internal/config.ts +33 -1
- package/backend/permissions/service.ts +5 -2
- package/backend/skills/sync.ts +1 -1
- package/backend/subagents/detect.ts +1 -1
- package/backend/subagents/sync.ts +1 -1
- package/backend/ws/chat/stream.ts +1 -1
- package/backend/ws/engine/cline/accounts.ts +317 -0
- package/backend/ws/engine/cline/index.ts +15 -0
- package/backend/ws/engine/cline/presets.ts +36 -0
- package/backend/ws/engine/cline/status.ts +49 -0
- package/backend/ws/engine/codex/accounts.ts +1 -1
- package/backend/ws/engine/cursor/accounts.ts +162 -0
- package/backend/ws/engine/cursor/index.ts +13 -0
- package/backend/ws/engine/cursor/status.ts +55 -0
- package/backend/ws/engine/index.ts +6 -0
- package/backend/ws/engine/pi/accounts.ts +319 -0
- package/backend/ws/engine/pi/index.ts +15 -0
- package/backend/ws/engine/pi/presets.ts +34 -0
- package/backend/ws/engine/pi/status.ts +50 -0
- package/backend/ws/sessions/crud.ts +2 -2
- package/backend/ws/settings/crud.ts +2 -2
- package/dist/assets/{index-EunAFLxP.js → index-Bu5loFQE.js} +1 -1
- package/dist/assets/{index-ChF_jIXj.js → index-kME3THy5.js} +1 -1
- package/dist/assets/{main-moCAkEwm.css → main-D7ATW8pp.css} +1 -1
- package/dist/assets/{main-CTs4NXwP.js → main-HirJLquI.js} +361 -359
- package/dist/index.html +2 -2
- package/package.json +11 -2
- package/shared/constants/engine-tools.ts +16 -2
- package/shared/constants/engines.ts +27 -0
- package/shared/types/unified/common.ts +1 -1
- package/shared/types/unified/engine.ts +82 -1
- package/shared/types/unified/index.ts +6 -0
- package/shared/types/unified/message.ts +1 -1
|
@@ -9,6 +9,7 @@ import { createSdkMcpServer, tool, type McpSdkServerConfigWithInstance, type Mcp
|
|
|
9
9
|
import type { McpRemoteConfig } from '@opencode-ai/sdk';
|
|
10
10
|
import type { MCPHTTPServerConfig } from '@github/copilot-sdk';
|
|
11
11
|
import type { CLIMcpServerConfig as QwenMcpServerConfig } from '@qwen-code/sdk';
|
|
12
|
+
import type { McpServerConfig as CursorMcpServerConfig } from '@cursor/sdk';
|
|
12
13
|
import type { ServerConfig, ParsedMcpToolName, ServerName } from './types';
|
|
13
14
|
import type { McpExecutionContext } from '../../engine/types';
|
|
14
15
|
import { serverRegistry, serverFactories, serverMetadata } from './servers';
|
|
@@ -605,6 +606,37 @@ export function getCopilotMcpConfig(profileFilter?: Set<string>): Record<string,
|
|
|
605
606
|
};
|
|
606
607
|
}
|
|
607
608
|
|
|
609
|
+
// ============================================================================
|
|
610
|
+
// Cursor MCP Configuration
|
|
611
|
+
// ============================================================================
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Get MCP configuration for the Cursor engine.
|
|
615
|
+
*
|
|
616
|
+
* The Cursor SDK (`@cursor/sdk`) accepts a `mcpServers` map whose HTTP variant is
|
|
617
|
+
* `{ type: 'http', url, headers? }`. We reuse the SAME in-process `/mcp` bridge
|
|
618
|
+
* Open Code, Codex, Copilot and Qwen already consume — no new HTTP server, no
|
|
619
|
+
* per-engine bridge (README §10.12). The service-token bearer authorises the hop.
|
|
620
|
+
*/
|
|
621
|
+
export function getCursorMcpConfig(profileFilter?: Set<string>): Record<string, CursorMcpServerConfig> {
|
|
622
|
+
const enabledServers = activeInternalServerNames(profileFilter);
|
|
623
|
+
if (enabledServers.length === 0) {
|
|
624
|
+
return {};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const port = SERVER_ENV.PORT;
|
|
628
|
+
|
|
629
|
+
debug.log('mcp', `📦 Cursor MCP: remote server at http://localhost:${port}/mcp`);
|
|
630
|
+
|
|
631
|
+
return {
|
|
632
|
+
'clopen-mcp': {
|
|
633
|
+
type: 'http',
|
|
634
|
+
url: `http://localhost:${port}/mcp`,
|
|
635
|
+
headers: { Authorization: `Bearer ${getMcpServiceToken()}` },
|
|
636
|
+
},
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
|
|
608
640
|
// ============================================================================
|
|
609
641
|
// Qwen Code MCP Configuration
|
|
610
642
|
// ============================================================================
|
|
@@ -616,7 +648,7 @@ export function getCopilotMcpConfig(profileFilter?: Set<string>): Record<string,
|
|
|
616
648
|
* a `CLIMcpServerConfig` value that supports the Streamable-HTTP transport via
|
|
617
649
|
* `httpUrl`. We reuse the SAME `/mcp` URL Open Code, Codex and Copilot already
|
|
618
650
|
* consume — no new HTTP server, no per-engine bridge. Tool handlers run
|
|
619
|
-
* in-process in the Clopen backend (README §
|
|
651
|
+
* in-process in the Clopen backend (README §10.12).
|
|
620
652
|
*
|
|
621
653
|
* Approval: the Qwen adapter uses `permissionMode: 'default'` with a
|
|
622
654
|
* `canUseTool` callback that auto-allows everything. `AskUserQuestion` is
|
|
@@ -20,14 +20,17 @@ import { debug } from '$shared/utils/logger';
|
|
|
20
20
|
import { mergeLayers, pickEngineSet, isToolAllowed, hasAnyRestriction, type ResolvedPermissions } from './resolve';
|
|
21
21
|
|
|
22
22
|
/** Engine keys used by the artifact matrix (config-dir slugs). */
|
|
23
|
-
export type ArtifactEngineKey = 'claude' | 'codex' | 'copilot' | 'qwen' | 'opencode';
|
|
23
|
+
export type ArtifactEngineKey = 'claude' | 'codex' | 'copilot' | 'qwen' | 'opencode' | 'pi' | 'cline' | 'cursor';
|
|
24
24
|
|
|
25
25
|
const ENGINE_TYPE_TO_ARTIFACT: Record<EngineType, ArtifactEngineKey> = {
|
|
26
26
|
'claude-code': 'claude',
|
|
27
27
|
codex: 'codex',
|
|
28
28
|
copilot: 'copilot',
|
|
29
29
|
qwen: 'qwen',
|
|
30
|
-
opencode: 'opencode'
|
|
30
|
+
opencode: 'opencode',
|
|
31
|
+
pi: 'pi',
|
|
32
|
+
cline: 'cline',
|
|
33
|
+
cursor: 'cursor'
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
export function toArtifactEngine(engine: EngineType): ArtifactEngineKey {
|
package/backend/skills/sync.ts
CHANGED
|
@@ -137,7 +137,7 @@ export async function syncSkills(engine: SkillEngine, profileId?: number): Promi
|
|
|
137
137
|
|
|
138
138
|
/** Re-sync every engine — used after a mutation so changes propagate eagerly. */
|
|
139
139
|
export async function syncSkillsAllEngines(): Promise<void> {
|
|
140
|
-
const engines: SkillEngine[] = ['claude', 'codex', 'copilot', 'qwen', 'opencode'];
|
|
140
|
+
const engines: SkillEngine[] = ['claude', 'codex', 'copilot', 'qwen', 'opencode', 'pi'];
|
|
141
141
|
await Promise.all(engines.map(syncSkills));
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -11,7 +11,7 @@ export interface DetectedSubagentGroup {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export async function detectSubagents(projectPath?: string): Promise<DetectedSubagentGroup[]> {
|
|
14
|
-
const engines: ArtifactEngine[] = ['claude', 'codex', 'copilot', 'qwen', 'opencode'];
|
|
14
|
+
const engines: ArtifactEngine[] = ['claude', 'codex', 'copilot', 'qwen', 'opencode', 'pi'];
|
|
15
15
|
const scope = projectPath ? 'project' : 'global';
|
|
16
16
|
const groups = await Promise.all(
|
|
17
17
|
engines.map(async engine => ({
|
|
@@ -139,6 +139,6 @@ export async function syncSubagents(engine: ArtifactEngine, profileId?: number):
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
export async function syncSubagentsAllEngines(): Promise<void> {
|
|
142
|
-
const engines: ArtifactEngine[] = ['claude', 'codex', 'copilot', 'qwen', 'opencode'];
|
|
142
|
+
const engines: ArtifactEngine[] = ['claude', 'codex', 'copilot', 'qwen', 'opencode', 'pi'];
|
|
143
143
|
await Promise.all(engines.map(syncSubagents));
|
|
144
144
|
}
|
|
@@ -202,7 +202,7 @@ export const streamHandler = createRouter()
|
|
|
202
202
|
projectPath: t.String(),
|
|
203
203
|
prompt: t.Any(), // UserMessage object
|
|
204
204
|
engine: t.Object({
|
|
205
|
-
type: t.Union([t.Literal('claude-code'), t.Literal('opencode'), t.Literal('copilot'), t.Literal('codex'), t.Literal('qwen')]),
|
|
205
|
+
type: t.Union([t.Literal('claude-code'), t.Literal('opencode'), t.Literal('copilot'), t.Literal('codex'), t.Literal('qwen'), t.Literal('pi'), t.Literal('cline'), t.Literal('cursor')]),
|
|
206
206
|
provider: t.String(),
|
|
207
207
|
model: t.Object({
|
|
208
208
|
id: t.String(),
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cline Account Management Handlers
|
|
3
|
+
*
|
|
4
|
+
* Cline is multi-provider (Anthropic, OpenAI, Google, the Cline account, …).
|
|
5
|
+
*
|
|
6
|
+
* - **API-key** providers: a simple all-fields-at-once form (`…-accounts-save`)
|
|
7
|
+
* that writes `{ provider, authMethod: 'api_key', apiKey, baseUrl?, fields? }`.
|
|
8
|
+
* - **OAuth** providers (the Cline account, Claude sign-in, …): an event-driven
|
|
9
|
+
* flow (`…-account-login-start`) driven by the SDK's provider auth handler.
|
|
10
|
+
* The handler owns its own local callback server; Clopen relays the auth URL
|
|
11
|
+
* and any interactive prompts to the client over WS (mirroring Pi's login).
|
|
12
|
+
* The returned OAuth credentials are stored as
|
|
13
|
+
* `{ provider, authMethod: 'oauth', oauth: { access, refresh, expires, … } }`.
|
|
14
|
+
*
|
|
15
|
+
* Every account's `engine_accounts.credential` is a JSON wrapper (see
|
|
16
|
+
* `backend/engine/adapters/cline/credential.ts`).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { t } from 'elysia';
|
|
20
|
+
import { getProviderAuthHandler, isOAuthProvider } from '@cline/sdk';
|
|
21
|
+
import type { OAuthLoginCallbacks, OAuthPrompt, OAuthCredentials } from '@cline/sdk';
|
|
22
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
23
|
+
import { ws } from '$backend/utils/ws';
|
|
24
|
+
import { engineQueries } from '../../../database/queries';
|
|
25
|
+
import { disposeAllProjectEnginesByType } from '../../../engine';
|
|
26
|
+
import { getClineProviderFields } from '../../../engine/adapters/cline/presets';
|
|
27
|
+
import {
|
|
28
|
+
getClineProvider,
|
|
29
|
+
parseClineCredential,
|
|
30
|
+
serializeClineCredential,
|
|
31
|
+
type ClineCredential,
|
|
32
|
+
} from '../../../engine/adapters/cline/credential';
|
|
33
|
+
import { requireSetupSessionAccess } from '../access';
|
|
34
|
+
import { debug } from '$shared/utils/logger';
|
|
35
|
+
|
|
36
|
+
async function disposeClineEngines(): Promise<void> {
|
|
37
|
+
try {
|
|
38
|
+
await disposeAllProjectEnginesByType('cline');
|
|
39
|
+
} catch {
|
|
40
|
+
/* engine may not be initialised — ignore */
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ── Interactive OAuth login sessions ──
|
|
45
|
+
|
|
46
|
+
interface ClineLoginSession {
|
|
47
|
+
userId: string;
|
|
48
|
+
disposed: boolean;
|
|
49
|
+
name: string;
|
|
50
|
+
provider: string;
|
|
51
|
+
/** When set, re-authenticate this existing account in place instead of creating one. */
|
|
52
|
+
reauthAccountId: number | null;
|
|
53
|
+
pendingPrompt: { resolve: (value: string) => void; reject: (error: Error) => void } | null;
|
|
54
|
+
timer: ReturnType<typeof setTimeout>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const loginSessions = new Map<string, ClineLoginSession>();
|
|
58
|
+
const LOGIN_TIMEOUT_MS = 15 * 60 * 1000;
|
|
59
|
+
|
|
60
|
+
function cleanupLogin(loginId: string): void {
|
|
61
|
+
const entry = loginSessions.get(loginId);
|
|
62
|
+
if (!entry || entry.disposed) return;
|
|
63
|
+
entry.disposed = true;
|
|
64
|
+
clearTimeout(entry.timer);
|
|
65
|
+
entry.pendingPrompt?.reject(new Error('Login session closed'));
|
|
66
|
+
entry.pendingPrompt = null;
|
|
67
|
+
loginSessions.delete(loginId);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const clineAccountsHandler = createRouter()
|
|
71
|
+
|
|
72
|
+
// ═══ CRUD ═══
|
|
73
|
+
|
|
74
|
+
.http('engine:cline-accounts-list', {
|
|
75
|
+
data: t.Object({}),
|
|
76
|
+
response: t.Object({
|
|
77
|
+
accounts: t.Array(t.Object({
|
|
78
|
+
id: t.Number(),
|
|
79
|
+
name: t.String(),
|
|
80
|
+
isActive: t.Boolean(),
|
|
81
|
+
createdAt: t.String(),
|
|
82
|
+
provider: t.String(),
|
|
83
|
+
authMethod: t.Union([t.Literal('api_key'), t.Literal('oauth')]),
|
|
84
|
+
/** Non-secret provider-scoped fields (base url, region, …) for edit prefill. */
|
|
85
|
+
fields: t.Record(t.String(), t.String()),
|
|
86
|
+
})),
|
|
87
|
+
})
|
|
88
|
+
}, async () => {
|
|
89
|
+
const provider = getClineProvider();
|
|
90
|
+
if (!provider) return { accounts: [] };
|
|
91
|
+
const accounts = engineQueries.getAccountsByProvider(provider.id);
|
|
92
|
+
return {
|
|
93
|
+
accounts: accounts
|
|
94
|
+
.map(a => {
|
|
95
|
+
const parsed = parseClineCredential(a.credential);
|
|
96
|
+
if (!parsed) return null;
|
|
97
|
+
const fields: Record<string, string> = { ...(parsed.fields ?? {}) };
|
|
98
|
+
if (parsed.baseUrl) fields.baseUrl = parsed.baseUrl;
|
|
99
|
+
return {
|
|
100
|
+
id: a.id,
|
|
101
|
+
name: a.name,
|
|
102
|
+
isActive: a.is_active === 1,
|
|
103
|
+
createdAt: a.created_at,
|
|
104
|
+
provider: parsed.provider,
|
|
105
|
+
authMethod: parsed.authMethod,
|
|
106
|
+
fields,
|
|
107
|
+
};
|
|
108
|
+
})
|
|
109
|
+
.filter((x): x is NonNullable<typeof x> => x !== null),
|
|
110
|
+
};
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
// Add or edit an API-key account from an all-fields-at-once form. A blank
|
|
114
|
+
// secret field on edit keeps the stored value; blank fields keep theirs.
|
|
115
|
+
.http('engine:cline-accounts-save', {
|
|
116
|
+
data: t.Object({
|
|
117
|
+
accountId: t.Optional(t.Number()),
|
|
118
|
+
name: t.String({ minLength: 1 }),
|
|
119
|
+
provider: t.String({ minLength: 1 }),
|
|
120
|
+
values: t.Record(t.String(), t.String()),
|
|
121
|
+
}),
|
|
122
|
+
response: t.Object({ success: t.Boolean(), accountId: t.Number() })
|
|
123
|
+
}, async ({ data }) => {
|
|
124
|
+
const providerRow = getClineProvider();
|
|
125
|
+
if (!providerRow) throw new Error('Cline provider not found in database');
|
|
126
|
+
|
|
127
|
+
const fieldDefs = getClineProviderFields(data.provider);
|
|
128
|
+
const keyField = fieldDefs.find(f => f.role === 'apiKey');
|
|
129
|
+
const baseUrlField = fieldDefs.find(f => f.role === 'baseUrl');
|
|
130
|
+
const extraFields = fieldDefs.filter(f => f.role === 'field');
|
|
131
|
+
|
|
132
|
+
const existing = data.accountId != null
|
|
133
|
+
? parseClineCredential(engineQueries.getAccount(data.accountId)?.credential)
|
|
134
|
+
: null;
|
|
135
|
+
|
|
136
|
+
const providedKey = keyField ? (data.values[keyField.key] ?? '').trim() : '';
|
|
137
|
+
const apiKey = providedKey || existing?.apiKey || '';
|
|
138
|
+
if (!apiKey) throw new Error('API key is required');
|
|
139
|
+
|
|
140
|
+
const providedBaseUrl = baseUrlField ? (data.values[baseUrlField.key] ?? '').trim() : '';
|
|
141
|
+
const baseUrl = providedBaseUrl || existing?.baseUrl;
|
|
142
|
+
|
|
143
|
+
const fields: Record<string, string> = { ...(existing?.fields ?? {}) };
|
|
144
|
+
for (const field of extraFields) {
|
|
145
|
+
const value = (data.values[field.key] ?? '').trim();
|
|
146
|
+
if (value) fields[field.key] = value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const credential: ClineCredential = {
|
|
150
|
+
provider: data.provider,
|
|
151
|
+
authMethod: 'api_key',
|
|
152
|
+
apiKey,
|
|
153
|
+
...(baseUrl ? { baseUrl } : {}),
|
|
154
|
+
...(Object.keys(fields).length ? { fields } : {}),
|
|
155
|
+
};
|
|
156
|
+
const serialized = serializeClineCredential(credential);
|
|
157
|
+
|
|
158
|
+
let accountId: number;
|
|
159
|
+
if (data.accountId != null && engineQueries.getAccount(data.accountId)) {
|
|
160
|
+
engineQueries.updateAccountCredential(data.accountId, serialized);
|
|
161
|
+
engineQueries.renameAccount(data.accountId, data.name.trim());
|
|
162
|
+
accountId = data.accountId;
|
|
163
|
+
} else {
|
|
164
|
+
accountId = engineQueries.createAccount(providerRow.id, data.name.trim(), serialized).id;
|
|
165
|
+
}
|
|
166
|
+
await disposeClineEngines();
|
|
167
|
+
return { success: true, accountId };
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
.http('engine:cline-accounts-switch', {
|
|
171
|
+
data: t.Object({ id: t.Number() }),
|
|
172
|
+
response: t.Object({ success: t.Boolean() })
|
|
173
|
+
}, async ({ data }) => {
|
|
174
|
+
engineQueries.switchAccount(data.id);
|
|
175
|
+
await disposeClineEngines();
|
|
176
|
+
return { success: true };
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
.http('engine:cline-accounts-delete', {
|
|
180
|
+
data: t.Object({ id: t.Number() }),
|
|
181
|
+
response: t.Object({ success: t.Boolean() })
|
|
182
|
+
}, async ({ data }) => {
|
|
183
|
+
const active = engineQueries.getActiveAccountForEngine('cline');
|
|
184
|
+
engineQueries.deleteAccount(data.id);
|
|
185
|
+
if (active?.id === data.id) await disposeClineEngines();
|
|
186
|
+
return { success: true };
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
.http('engine:cline-accounts-rename', {
|
|
190
|
+
data: t.Object({ id: t.Number(), name: t.String({ minLength: 1 }) }),
|
|
191
|
+
response: t.Object({ success: t.Boolean() })
|
|
192
|
+
}, async ({ data }) => {
|
|
193
|
+
engineQueries.renameAccount(data.id, data.name.trim());
|
|
194
|
+
return { success: true };
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
// ═══ OAuth login (event-driven) ═══
|
|
198
|
+
|
|
199
|
+
.on('engine:cline-account-login-start', {
|
|
200
|
+
data: t.Object({
|
|
201
|
+
name: t.String({ minLength: 1 }),
|
|
202
|
+
provider: t.String({ minLength: 1 }),
|
|
203
|
+
reauthAccountId: t.Optional(t.Number()),
|
|
204
|
+
})
|
|
205
|
+
}, async ({ data, conn }) => {
|
|
206
|
+
const userId = ws.getUserId(conn);
|
|
207
|
+
const loginId = crypto.randomUUID();
|
|
208
|
+
|
|
209
|
+
const handler = getProviderAuthHandler(data.provider);
|
|
210
|
+
if (!handler || !isOAuthProvider(data.provider)) {
|
|
211
|
+
ws.emit.user(userId, 'engine:cline-account-login-error', { loginId, message: `Provider "${data.provider}" does not support OAuth sign-in.` });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const entry: ClineLoginSession = {
|
|
216
|
+
userId, disposed: false,
|
|
217
|
+
name: data.name.trim(), provider: data.provider,
|
|
218
|
+
reauthAccountId: data.reauthAccountId ?? null,
|
|
219
|
+
pendingPrompt: null,
|
|
220
|
+
timer: setTimeout(() => {
|
|
221
|
+
ws.emit.user(userId, 'engine:cline-account-login-error', { loginId, message: 'Login timed out after 15 minutes' });
|
|
222
|
+
cleanupLogin(loginId);
|
|
223
|
+
}, LOGIN_TIMEOUT_MS),
|
|
224
|
+
};
|
|
225
|
+
loginSessions.set(loginId, entry);
|
|
226
|
+
ws.emit.user(userId, 'engine:cline-account-login-started', { loginId });
|
|
227
|
+
|
|
228
|
+
const awaitPrompt = (message: string): Promise<string> =>
|
|
229
|
+
new Promise<string>((resolve, reject) => {
|
|
230
|
+
entry.pendingPrompt = { resolve, reject };
|
|
231
|
+
ws.emit.user(userId, 'engine:cline-account-login-prompt', { loginId, message });
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const callbacks: OAuthLoginCallbacks = {
|
|
235
|
+
onAuth: (info: { url: string; instructions?: string }) => {
|
|
236
|
+
ws.emit.user(userId, 'engine:cline-account-login-event', {
|
|
237
|
+
loginId, kind: 'auth_url', message: info.instructions, url: info.url,
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
onPrompt: (prompt: OAuthPrompt) => awaitPrompt(prompt.message),
|
|
241
|
+
onProgress: (message: string) => {
|
|
242
|
+
ws.emit.user(userId, 'engine:cline-account-login-event', { loginId, kind: 'progress', message });
|
|
243
|
+
},
|
|
244
|
+
onManualCodeInput: () => awaitPrompt('Paste the authorization code from your browser:'),
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
const credential = (await handler.login({ callbacks })) as OAuthCredentials;
|
|
249
|
+
if (entry.disposed) return;
|
|
250
|
+
|
|
251
|
+
const serialized = serializeClineCredential({ provider: data.provider, authMethod: 'oauth', oauth: credential });
|
|
252
|
+
let accountId: number;
|
|
253
|
+
if (entry.reauthAccountId != null && engineQueries.getAccount(entry.reauthAccountId)) {
|
|
254
|
+
engineQueries.updateAccountCredential(entry.reauthAccountId, serialized);
|
|
255
|
+
engineQueries.renameAccount(entry.reauthAccountId, entry.name);
|
|
256
|
+
accountId = entry.reauthAccountId;
|
|
257
|
+
} else {
|
|
258
|
+
const providerRow = getClineProvider();
|
|
259
|
+
if (!providerRow) throw new Error('Cline provider not found in database');
|
|
260
|
+
accountId = engineQueries.createAccount(providerRow.id, entry.name, serialized).id;
|
|
261
|
+
}
|
|
262
|
+
await disposeClineEngines();
|
|
263
|
+
|
|
264
|
+
ws.emit.user(userId, 'engine:cline-account-login-complete', { loginId, accountId });
|
|
265
|
+
cleanupLogin(loginId);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if (!entry.disposed) {
|
|
268
|
+
debug.warn('engine', `Cline login failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
269
|
+
ws.emit.user(userId, 'engine:cline-account-login-error', {
|
|
270
|
+
loginId,
|
|
271
|
+
message: error instanceof Error ? error.message : 'Login failed',
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
cleanupLogin(loginId);
|
|
275
|
+
}
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
.on('engine:cline-account-login-submit', {
|
|
279
|
+
data: t.Object({ loginId: t.String(), value: t.String() })
|
|
280
|
+
}, async ({ data, conn }) => {
|
|
281
|
+
let entry: ClineLoginSession;
|
|
282
|
+
try {
|
|
283
|
+
entry = requireSetupSessionAccess(conn, data.loginId, loginSessions);
|
|
284
|
+
} catch {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const pending = entry.pendingPrompt;
|
|
288
|
+
entry.pendingPrompt = null;
|
|
289
|
+
pending?.resolve(data.value);
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
.on('engine:cline-account-login-cancel', {
|
|
293
|
+
data: t.Object({ loginId: t.String() })
|
|
294
|
+
}, async ({ data, conn }) => {
|
|
295
|
+
try {
|
|
296
|
+
requireSetupSessionAccess(conn, data.loginId, loginSessions);
|
|
297
|
+
} catch {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
cleanupLogin(data.loginId);
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
// ═══ Event declarations (Server → Client) ═══
|
|
304
|
+
|
|
305
|
+
.emit('engine:cline-account-login-started', t.Object({ loginId: t.String() }))
|
|
306
|
+
.emit('engine:cline-account-login-event', t.Object({
|
|
307
|
+
loginId: t.String(),
|
|
308
|
+
kind: t.String(),
|
|
309
|
+
message: t.Optional(t.String()),
|
|
310
|
+
url: t.Optional(t.String()),
|
|
311
|
+
}))
|
|
312
|
+
.emit('engine:cline-account-login-prompt', t.Object({
|
|
313
|
+
loginId: t.String(),
|
|
314
|
+
message: t.String(),
|
|
315
|
+
}))
|
|
316
|
+
.emit('engine:cline-account-login-complete', t.Object({ loginId: t.String(), accountId: t.Number() }))
|
|
317
|
+
.emit('engine:cline-account-login-error', t.Object({ loginId: t.String(), message: t.String() }));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cline Engine Router
|
|
3
|
+
*
|
|
4
|
+
* Combines status detection, account/login management, and provider presets.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
8
|
+
import { clineStatusHandler } from './status';
|
|
9
|
+
import { clineAccountsHandler } from './accounts';
|
|
10
|
+
import { clinePresetsHandler } from './presets';
|
|
11
|
+
|
|
12
|
+
export const clineEngineRouter = createRouter()
|
|
13
|
+
.merge(clineStatusHandler)
|
|
14
|
+
.merge(clineAccountsHandler)
|
|
15
|
+
.merge(clinePresetsHandler);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cline Provider Presets Handler
|
|
3
|
+
*
|
|
4
|
+
* Exposes the Cline provider catalog (id, name, supported auth modes, credential
|
|
5
|
+
* fields) to the frontend so the login picker can render the right flow per
|
|
6
|
+
* provider without importing backend modules directly. Built from the `@cline/llms`
|
|
7
|
+
* catalog + `getProviderConfigFields`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { t } from 'elysia';
|
|
11
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
12
|
+
import { getClineProviderPresets } from '../../../engine/adapters/cline/presets';
|
|
13
|
+
|
|
14
|
+
export const clinePresetsHandler = createRouter()
|
|
15
|
+
.http('engine:cline-presets-list', {
|
|
16
|
+
data: t.Object({}),
|
|
17
|
+
response: t.Object({
|
|
18
|
+
presets: t.Array(t.Object({
|
|
19
|
+
id: t.String(),
|
|
20
|
+
name: t.String(),
|
|
21
|
+
authModes: t.Array(t.Union([t.Literal('api_key'), t.Literal('oauth')])),
|
|
22
|
+
fields: t.Optional(t.Array(t.Object({
|
|
23
|
+
key: t.String(),
|
|
24
|
+
label: t.String(),
|
|
25
|
+
secret: t.Boolean(),
|
|
26
|
+
role: t.Union([t.Literal('apiKey'), t.Literal('baseUrl'), t.Literal('field')]),
|
|
27
|
+
placeholder: t.Optional(t.String()),
|
|
28
|
+
optional: t.Optional(t.Boolean()),
|
|
29
|
+
}))),
|
|
30
|
+
oauthLabel: t.Optional(t.String()),
|
|
31
|
+
apiKeyUrl: t.Optional(t.String()),
|
|
32
|
+
})),
|
|
33
|
+
})
|
|
34
|
+
}, async () => {
|
|
35
|
+
return { presets: await getClineProviderPresets() };
|
|
36
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cline Engine Status Handler
|
|
3
|
+
*
|
|
4
|
+
* Cline is an in-process SDK (`@cline/sdk`) — there is no CLI to install, so
|
|
5
|
+
* `installed` is always true. Reports the SDK version and active account state.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { t } from 'elysia';
|
|
9
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
10
|
+
import { engineQueries } from '../../../database/queries';
|
|
11
|
+
import { debug } from '$shared/utils/logger';
|
|
12
|
+
import { getBackendOS } from '../../../utils/os';
|
|
13
|
+
|
|
14
|
+
function readSdkVersion(): string | null {
|
|
15
|
+
try {
|
|
16
|
+
const path = require.resolve('@cline/sdk/package.json');
|
|
17
|
+
const pkg = require(path) as { version?: string };
|
|
18
|
+
return pkg.version ?? null;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const clineStatusHandler = createRouter()
|
|
25
|
+
.http('engine:cline-status', {
|
|
26
|
+
data: t.Object({}),
|
|
27
|
+
response: t.Object({
|
|
28
|
+
installed: t.Boolean(),
|
|
29
|
+
version: t.Union([t.String(), t.Null()]),
|
|
30
|
+
activeAccount: t.Union([
|
|
31
|
+
t.Object({ id: t.Number(), name: t.String() }),
|
|
32
|
+
t.Null()
|
|
33
|
+
]),
|
|
34
|
+
accountsCount: t.Number(),
|
|
35
|
+
backendOS: t.Union([t.Literal('windows'), t.Literal('macos'), t.Literal('linux')])
|
|
36
|
+
})
|
|
37
|
+
}, async () => {
|
|
38
|
+
debug.log('engine', 'Checking Cline status...');
|
|
39
|
+
const provider = engineQueries.getProviderBySlug('cline', 'cline');
|
|
40
|
+
const accounts = provider ? engineQueries.getAccountsByProvider(provider.id) : [];
|
|
41
|
+
const activeAccount = engineQueries.getActiveAccountForEngine('cline');
|
|
42
|
+
return {
|
|
43
|
+
installed: true,
|
|
44
|
+
version: readSdkVersion(),
|
|
45
|
+
activeAccount: activeAccount ? { id: activeAccount.id, name: activeAccount.name } : null,
|
|
46
|
+
accountsCount: accounts.length,
|
|
47
|
+
backendOS: getBackendOS()
|
|
48
|
+
};
|
|
49
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* OpenAI Codex Account Management Handlers
|
|
3
3
|
*
|
|
4
|
-
* Codex supports TWO auth modes (per backend/engine/README.md §
|
|
4
|
+
* Codex supports TWO auth modes (per backend/engine/README.md §10.13):
|
|
5
5
|
*
|
|
6
6
|
* 1. **API key** — paste-token flow, identical to Copilot's. The `apiKey`
|
|
7
7
|
* is wrapped as `{kind:"api_key", apiKey}` and stored in
|