@myrialabs/clopen 0.4.45 → 0.4.47
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/backend/artifacts/project/sources.ts +2 -2
- package/backend/engine/adapters/claude/models.test.ts +49 -0
- package/backend/engine/adapters/claude/models.ts +81 -562
- package/backend/engine/adapters/claude/stream.ts +5 -4
- package/backend/engine/adapters/cline/credential.ts +42 -18
- package/backend/engine/adapters/cline/message-converter.ts +31 -1
- package/backend/engine/adapters/cline/models.test.ts +77 -0
- package/backend/engine/adapters/cline/models.ts +89 -3
- package/backend/engine/adapters/cline/presets.ts +5 -0
- package/backend/engine/adapters/cline/stream.ts +9 -2
- package/backend/engine/adapters/codex/message-converter.ts +1 -1
- package/backend/engine/adapters/codex/models.ts +54 -31
- package/backend/engine/adapters/codex/patch-rollout.test.ts +36 -1
- package/backend/engine/adapters/codex/patch-rollout.ts +60 -29
- package/backend/engine/adapters/codex/session-fork.ts +5 -0
- package/backend/engine/adapters/codex/stream.ts +8 -7
- package/backend/engine/adapters/copilot/models.test.ts +40 -0
- package/backend/engine/adapters/copilot/models.ts +51 -24
- package/backend/engine/adapters/copilot/permissions.test.ts +47 -0
- package/backend/engine/adapters/copilot/permissions.ts +72 -0
- package/backend/engine/adapters/copilot/stream.ts +77 -67
- package/backend/engine/adapters/cursor/stream.ts +8 -4
- package/backend/engine/adapters/opencode/presets.ts +27 -2
- package/backend/engine/adapters/opencode/server.ts +6 -4
- package/backend/engine/adapters/pi/credential.test.ts +83 -0
- package/backend/engine/adapters/pi/credential.ts +68 -12
- package/backend/engine/adapters/pi/environment.ts +9 -5
- package/backend/engine/adapters/pi/mcp.test.ts +194 -0
- package/backend/engine/adapters/pi/mcp.ts +88 -0
- package/backend/engine/adapters/pi/message-converter.ts +6 -4
- package/backend/engine/adapters/pi/presets.ts +10 -5
- package/backend/engine/adapters/pi/stream.ts +42 -38
- package/backend/engine/adapters/qwen/environment.ts +39 -2
- package/backend/engine/adapters/qwen/message-converter.test.ts +64 -0
- package/backend/engine/adapters/qwen/message-converter.ts +40 -23
- package/backend/engine/adapters/qwen/models.test.ts +25 -0
- package/backend/engine/adapters/qwen/models.ts +42 -5
- package/backend/engine/adapters/qwen/session-store.test.ts +39 -0
- package/backend/engine/adapters/qwen/session-store.ts +66 -0
- package/backend/engine/adapters/qwen/stream.ts +110 -87
- package/backend/engine/docs/adapter-contract.md +7 -4
- package/backend/engine/docs/lessons-learned.md +405 -62
- package/backend/engine/docs/quick-reference.md +2 -2
- package/backend/engine/docs/stack.md +17 -4
- package/backend/engine/docs/websocket-routes.md +5 -5
- package/backend/engine/install-recipes.test.ts +105 -5
- package/backend/engine/install-recipes.ts +102 -42
- package/backend/engine/install-runner.ts +56 -2
- package/backend/engine/stack-project.ts +71 -1
- package/backend/index.ts +5 -0
- package/backend/mcp/README.md +2 -2
- package/backend/mcp/external/config.ts +18 -0
- package/backend/mcp/external/proxy.ts +2 -2
- package/backend/mcp/index.ts +8 -0
- package/backend/mcp/internal/config.ts +42 -3
- package/backend/memory/embedding/install.ts +29 -1
- package/backend/utils/keyed-lock.test.ts +33 -0
- package/backend/utils/keyed-lock.ts +17 -0
- package/backend/utils/port-utils.test.ts +29 -0
- package/backend/utils/port-utils.ts +19 -0
- package/backend/ws/engine/cline/accounts.ts +26 -6
- package/backend/ws/engine/codex/accounts.test.ts +49 -0
- package/backend/ws/engine/codex/accounts.ts +17 -13
- package/backend/ws/engine/opencode/providers.ts +2 -1
- package/backend/ws/engine/pi/accounts.ts +61 -6
- package/dist/assets/{index-D-Ad1N96.js → index-BTcR1byF.js} +1 -1
- package/dist/assets/{index-Am-rJRxA.js → index-CwuKQelV.js} +1 -1
- package/dist/assets/{main--PLCDxSy.css → main-BiDNMWb3.css} +1 -1
- package/dist/assets/{main-DelPm2Xt.js → main-BlhKWz2B.js} +595 -593
- package/dist/index.html +2 -2
- package/package.json +19 -15
- package/backend/engine/adapters/pi/mcp-tools.ts +0 -153
- package/backend/engine/adapters/qwen/session-fork.ts +0 -109
|
@@ -23,6 +23,7 @@ import type { OAuthCredentials, ProviderSettings } from '@cline/sdk';
|
|
|
23
23
|
import { engineQueries, type EngineAccount } from '$backend/database/queries/engine-queries';
|
|
24
24
|
import { debug } from '$shared/utils/logger';
|
|
25
25
|
import { loadEngineSdk } from '$backend/engine/sdk-loader';
|
|
26
|
+
import { createKeyedLock } from '$backend/utils/keyed-lock';
|
|
26
27
|
|
|
27
28
|
export type ClineAuthMethod = 'api_key' | 'oauth';
|
|
28
29
|
|
|
@@ -106,6 +107,24 @@ export interface ResolvedClineAuth {
|
|
|
106
107
|
/** Refresh window: refresh an OAuth token that expires within the next minute. */
|
|
107
108
|
const OAUTH_REFRESH_BUFFER_MS = 60_000;
|
|
108
109
|
|
|
110
|
+
/**
|
|
111
|
+
* One refresh per account at a time. Concurrent streams each resolve auth, and
|
|
112
|
+
* a refresh token spent twice gets the grant revoked by providers that rotate
|
|
113
|
+
* it; the second caller re-reads the row inside the lock and finds it fresh.
|
|
114
|
+
*/
|
|
115
|
+
const withAccountLock = createKeyedLock<number>();
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Replace an account's stored credential (re-login, edited key) in line with
|
|
119
|
+
* any refresh in flight, so the refresh can't land afterwards and put the old
|
|
120
|
+
* grant back.
|
|
121
|
+
*/
|
|
122
|
+
export function writeClineAccountCredential(accountId: number, serialized: string): Promise<void> {
|
|
123
|
+
return withAccountLock(accountId, async () => {
|
|
124
|
+
engineQueries.updateAccountCredential(accountId, serialized);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
109
128
|
/**
|
|
110
129
|
* Resolve the auth an `Agent` needs for one account. For OAuth accounts this
|
|
111
130
|
* refreshes a near-expired access token (persisting the rotated blob back to the
|
|
@@ -126,31 +145,36 @@ export async function resolveClineAuth(account: EngineAccount): Promise<Resolved
|
|
|
126
145
|
|
|
127
146
|
// OAuth: refresh if near-expiry, then format the access token as an api key.
|
|
128
147
|
const { getProviderAuthHandler, formatProviderOAuthApiKey } = await loadEngineSdk<typeof import('@cline/sdk')>('cline', '@cline/sdk');
|
|
129
|
-
let creds = parsed.oauth as OAuthCredentials;
|
|
130
148
|
const handler = getProviderAuthHandler(parsed.provider);
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
149
|
+
const isNearExpiry = (c: OAuthCredentials) => typeof c.expires === 'number' && c.expires <= Date.now() + OAUTH_REFRESH_BUFFER_MS;
|
|
150
|
+
let creds = parsed.oauth as OAuthCredentials;
|
|
151
|
+
if (handler && creds.refresh && isNearExpiry(creds)) {
|
|
152
|
+
creds = await withAccountLock(account.id, async () => {
|
|
153
|
+
// The row, not the caller's snapshot: another stream may have refreshed it.
|
|
154
|
+
const current = (parseClineCredential(engineQueries.getAccount(account.id)?.credential)?.oauth ?? parsed.oauth) as OAuthCredentials;
|
|
155
|
+
if (!current.refresh || !isNearExpiry(current)) return current;
|
|
156
|
+
try {
|
|
157
|
+
const settings = {
|
|
158
|
+
auth: {
|
|
159
|
+
accessToken: current.access,
|
|
160
|
+
refreshToken: current.refresh,
|
|
161
|
+
expiresAt: current.expires,
|
|
162
|
+
...(current.accountId ? { accountId: current.accountId } : {}),
|
|
163
|
+
},
|
|
164
|
+
} as ProviderSettings;
|
|
165
|
+
const refreshed = await handler.refresh({ settings, credentials: current });
|
|
166
|
+
if (!refreshed?.access) return current;
|
|
145
167
|
engineQueries.updateAccountCredential(
|
|
146
168
|
account.id,
|
|
147
169
|
serializeClineCredential({ ...parsed, oauth: refreshed }),
|
|
148
170
|
);
|
|
149
171
|
debug.log('engine', `Cline: refreshed OAuth token for provider "${parsed.provider}" (account ${account.id})`);
|
|
172
|
+
return refreshed;
|
|
173
|
+
} catch (error) {
|
|
174
|
+
debug.warn('engine', `Cline OAuth refresh failed for "${parsed.provider}" (using stored token): ${error instanceof Error ? error.message : String(error)}`);
|
|
175
|
+
return current;
|
|
150
176
|
}
|
|
151
|
-
}
|
|
152
|
-
debug.warn('engine', `Cline OAuth refresh failed for "${parsed.provider}" (using stored token): ${error instanceof Error ? error.message : String(error)}`);
|
|
153
|
-
}
|
|
177
|
+
});
|
|
154
178
|
}
|
|
155
179
|
|
|
156
180
|
let apiKey: string;
|
|
@@ -158,6 +158,9 @@ function mapFinishReason(raw: AgentModelFinishReason | null | undefined): StopRe
|
|
|
158
158
|
case 'max-tokens': return 'max_tokens';
|
|
159
159
|
case 'aborted': return 'interrupted';
|
|
160
160
|
case 'error': return 'end_turn';
|
|
161
|
+
case 'content-filter': return 'end_turn';
|
|
162
|
+
// The SDK never treats `unknown` as a completed turn (it may be cut off).
|
|
163
|
+
case 'unknown': return null;
|
|
161
164
|
default: return null;
|
|
162
165
|
}
|
|
163
166
|
}
|
|
@@ -234,7 +237,18 @@ export function createClineMessageConverter(options: ClineConverterOptions): Cli
|
|
|
234
237
|
if (part.text) reasoning += (reasoning ? '\n' : '') + part.text;
|
|
235
238
|
} else if (part.type === 'text') {
|
|
236
239
|
if (part.text.trim()) blocks.push({ type: 'text', text: part.text });
|
|
240
|
+
} else if (part.type === 'media') {
|
|
241
|
+
// Model-generated media (image-output models). The unified assistant
|
|
242
|
+
// blocks carry no media type, so keep a visible trace instead of
|
|
243
|
+
// dropping it silently.
|
|
244
|
+
const { media } = part;
|
|
245
|
+
const label = `${media.modality} (${media.mediaType})`;
|
|
246
|
+
blocks.push({ type: 'text', text: media.source.type === 'url' ? `[Generated ${label}](${media.source.url})` : `[Generated ${label} not shown]` });
|
|
237
247
|
} else if (part.type === 'tool-call') {
|
|
248
|
+
// Provider-executed tools (web search, image generation) run inside the
|
|
249
|
+
// model request and never get a local tool result, so a tool_use block
|
|
250
|
+
// would sit pending forever. Clopen passes no `modelTools`; skip them.
|
|
251
|
+
if (part.execution === 'provider') continue;
|
|
238
252
|
const call = part as AgentToolCallPart;
|
|
239
253
|
const canonical = canonicaliseToolName(call.toolName);
|
|
240
254
|
const finalName = toCanonicalToolName(canonical);
|
|
@@ -254,7 +268,7 @@ export function createClineMessageConverter(options: ClineConverterOptions): Cli
|
|
|
254
268
|
return { reasoning, blocks };
|
|
255
269
|
}
|
|
256
270
|
|
|
257
|
-
function
|
|
271
|
+
function convertAssistantContent(msg: AgentMessage, finishReason: AgentModelFinishReason): EngineOutput[] {
|
|
258
272
|
const outputs: EngineOutput[] = [];
|
|
259
273
|
const { reasoning, blocks } = mapAssistantContent(msg.content);
|
|
260
274
|
const usage = msg.metrics ? mapUsage(msg.metrics) : null;
|
|
@@ -307,6 +321,22 @@ export function createClineMessageConverter(options: ClineConverterOptions): Cli
|
|
|
307
321
|
return outputs;
|
|
308
322
|
}
|
|
309
323
|
|
|
324
|
+
function convertAssistantMessage(msg: AgentMessage, finishReason: AgentModelFinishReason): EngineOutput[] {
|
|
325
|
+
const outputs = convertAssistantContent(msg, finishReason);
|
|
326
|
+
if (finishReason === 'content-filter') {
|
|
327
|
+
// A filtered turn that produced nothing fails the run with the SDK's own
|
|
328
|
+
// message; one that produced part of an answer lands here, cut short.
|
|
329
|
+
outputs.push({
|
|
330
|
+
type: 'notification',
|
|
331
|
+
sessionId,
|
|
332
|
+
level: 'warning',
|
|
333
|
+
title: 'Response filtered',
|
|
334
|
+
message: 'The provider\'s content filter stopped this response early. Retrying is unlikely to help — try rephrasing the request.',
|
|
335
|
+
} as NotificationEvent);
|
|
336
|
+
}
|
|
337
|
+
return outputs;
|
|
338
|
+
}
|
|
339
|
+
|
|
310
340
|
function convertToolResults(msg: AgentMessage): UserMessage[] {
|
|
311
341
|
const out: UserMessage[] = [];
|
|
312
342
|
for (const part of msg.content) {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { buildClineReasoningControl, isClineChatModel, resolveClineReasoning, type CatalogModel } from './models';
|
|
3
|
+
|
|
4
|
+
type Options = CatalogModel['reasoningOptions'];
|
|
5
|
+
|
|
6
|
+
// Shapes taken from the @cline/llms catalog.
|
|
7
|
+
const EFFORT_ONLY: Options = [{ type: 'effort', values: ['low', 'medium', 'high', 'xhigh', 'max'] }];
|
|
8
|
+
const TOGGLE_AND_EFFORT: Options = [{ type: 'toggle' }, { type: 'effort', values: ['low', 'medium', 'high', 'xhigh', 'max'] }];
|
|
9
|
+
const EFFORT_WITH_NONE: Options = [{ type: 'effort', values: ['none', 'low', 'medium', 'high'] }];
|
|
10
|
+
const TOGGLE_ONLY: Options = [{ type: 'toggle' }];
|
|
11
|
+
const BUDGET_ONLY: Options = [{ type: 'budget_tokens', min: 1024 }];
|
|
12
|
+
|
|
13
|
+
const levelsOf = (options: Options) => buildClineReasoningControl(options)?.levels.map(l => l.value);
|
|
14
|
+
|
|
15
|
+
describe('isClineChatModel', () => {
|
|
16
|
+
test('a language model that reads and writes text is chat', () => {
|
|
17
|
+
expect(isClineChatModel({ operation: 'language', modalities: { input: ['text', 'image'], output: ['text'] } })).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('entries without operation or modalities stay chat', () => {
|
|
21
|
+
expect(isClineChatModel({})).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('transcription and media-generation models are not chat', () => {
|
|
25
|
+
expect(isClineChatModel({ operation: 'transcription', modalities: { input: ['audio'], output: ['text'] } })).toBe(false);
|
|
26
|
+
expect(isClineChatModel({ operation: 'image-generation' })).toBe(false);
|
|
27
|
+
expect(isClineChatModel({ modalities: { input: ['text'], output: ['image'] } })).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('Cline reasoning levels', () => {
|
|
32
|
+
test('effort tiers without a way to turn thinking off offer no Off', () => {
|
|
33
|
+
expect(levelsOf(EFFORT_ONLY)).toEqual(['auto', 'low', 'medium', 'high', 'xhigh', 'max']);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('a toggle or a none effort adds Off', () => {
|
|
37
|
+
expect(levelsOf(TOGGLE_AND_EFFORT)).toEqual(['off', 'auto', 'low', 'medium', 'high', 'xhigh', 'max']);
|
|
38
|
+
expect(levelsOf(EFFORT_WITH_NONE)).toEqual(['off', 'auto', 'low', 'medium', 'high']);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('a toggle-only model offers Off / Auto / On', () => {
|
|
42
|
+
expect(levelsOf(TOGGLE_ONLY)).toEqual(['off', 'auto', 'on']);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('budget-only and option-less models get no selector', () => {
|
|
46
|
+
expect(buildClineReasoningControl(BUDGET_ONLY)).toBeUndefined();
|
|
47
|
+
expect(buildClineReasoningControl([])).toBeUndefined();
|
|
48
|
+
expect(buildClineReasoningControl(undefined)).toBeUndefined();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('the default is always Auto, one of the levels', () => {
|
|
52
|
+
for (const options of [EFFORT_ONLY, TOGGLE_AND_EFFORT, EFFORT_WITH_NONE, TOGGLE_ONLY]) {
|
|
53
|
+
const control = buildClineReasoningControl(options);
|
|
54
|
+
expect(control?.default).toBe('auto');
|
|
55
|
+
expect(control?.levels.some(l => l.value === 'auto')).toBe(true);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('resolveClineReasoning', () => {
|
|
61
|
+
test('an offered effort becomes reasoningEffort', () => {
|
|
62
|
+
expect(resolveClineReasoning('xhigh', EFFORT_ONLY)).toEqual({ reasoningEffort: 'xhigh' });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('off and on drive the thinking flag', () => {
|
|
66
|
+
expect(resolveClineReasoning('off', TOGGLE_AND_EFFORT)).toEqual({ thinking: false });
|
|
67
|
+
expect(resolveClineReasoning('on', TOGGLE_ONLY)).toEqual({ thinking: true });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('auto, unknown and no longer offered levels send nothing', () => {
|
|
71
|
+
expect(resolveClineReasoning('auto', EFFORT_ONLY)).toEqual({});
|
|
72
|
+
expect(resolveClineReasoning(undefined, EFFORT_ONLY)).toEqual({});
|
|
73
|
+
expect(resolveClineReasoning('off', EFFORT_ONLY)).toEqual({});
|
|
74
|
+
expect(resolveClineReasoning('max', EFFORT_WITH_NONE)).toEqual({});
|
|
75
|
+
expect(resolveClineReasoning('high', BUDGET_ONLY)).toEqual({});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -9,15 +9,99 @@
|
|
|
9
9
|
* so the chat's send path can resolve the matching account by provider. Returns
|
|
10
10
|
* `[]` on any failure (mirrors the OpenCode/Qwen/Pi dynamic-catalog contract —
|
|
11
11
|
* the picker renders empty rather than a stale list).
|
|
12
|
+
*
|
|
13
|
+
* The catalog also lists models a chat turn cannot use (transcription, image /
|
|
14
|
+
* speech / video generation — e.g. `vercel-ai-gateway`'s `flux-*` and
|
|
15
|
+
* `*-transcribe-*`); `isClineChatModel` keeps those out of the picker.
|
|
12
16
|
*/
|
|
13
17
|
|
|
14
18
|
import type { Llms } from '@cline/sdk';
|
|
15
|
-
import type { EngineModel } from '$shared/types/unified';
|
|
19
|
+
import type { EngineModel, ReasoningControl } from '$shared/types/unified';
|
|
20
|
+
import { toReasoningOptions } from '$shared/constants/engines';
|
|
16
21
|
import { debug } from '$shared/utils/logger';
|
|
17
22
|
import { loadEngineSdk } from '$backend/engine/sdk-loader';
|
|
18
23
|
import { getClineAccounts, parseClineCredential } from './credential';
|
|
19
24
|
|
|
20
|
-
type CatalogModel = Awaited<ReturnType<typeof Llms.getModelsForProvider>>[string];
|
|
25
|
+
export type CatalogModel = Awaited<ReturnType<typeof Llms.getModelsForProvider>>[string];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Whether a catalog model can run a text chat turn. Mirrors the SDK's own
|
|
29
|
+
* `supportsChatModalities` + `operation` gate (not re-exported by
|
|
30
|
+
* `@cline/sdk`): missing metadata counts as chat for older catalog entries;
|
|
31
|
+
* otherwise the model must take text in, give text out, and run as a
|
|
32
|
+
* `language` operation.
|
|
33
|
+
*/
|
|
34
|
+
export function isClineChatModel(info: Pick<CatalogModel, 'operation' | 'modalities'>): boolean {
|
|
35
|
+
if (info.operation && info.operation !== 'language') return false;
|
|
36
|
+
const modalities = info.modalities;
|
|
37
|
+
if (!modalities) return true;
|
|
38
|
+
return modalities.input.includes('text') && modalities.output.includes('text');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The SDK's effort ladder, low → high (`REASONING_LEVELS` minus `none`). */
|
|
42
|
+
const CLINE_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'] as const;
|
|
43
|
+
type ClineEffort = (typeof CLINE_EFFORTS)[number];
|
|
44
|
+
|
|
45
|
+
type ReasoningOptions = CatalogModel['reasoningOptions'];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Per-model reasoning levels, from the catalog's `reasoningOptions`:
|
|
49
|
+
* - `off` — thinking disabled; only where the model can turn it off (a
|
|
50
|
+
* `toggle` option, or `none` among its efforts).
|
|
51
|
+
* - `auto` — no knob sent; the SDK applies the model's own default.
|
|
52
|
+
* - `low`…`max` — the efforts the model advertises.
|
|
53
|
+
* - `on` — thinking enabled, for toggle-only models with no effort tiers.
|
|
54
|
+
* Budget-only models (`budget_tokens` alone, e.g. Claude Sonnet 4.5) get no
|
|
55
|
+
* selector: the SDK has no level to map them to.
|
|
56
|
+
*/
|
|
57
|
+
function clineReasoningLevels(options: ReasoningOptions): string[] {
|
|
58
|
+
if (!options?.length) return [];
|
|
59
|
+
const toggle = options.some(o => o.type === 'toggle');
|
|
60
|
+
const effortValues = new Set<string | null>(options.find(o => o.type === 'effort')?.values ?? []);
|
|
61
|
+
const efforts = CLINE_EFFORTS.filter(e => effortValues.has(e));
|
|
62
|
+
const levels: string[] = [];
|
|
63
|
+
if (toggle || effortValues.has('none')) levels.push('off');
|
|
64
|
+
levels.push('auto');
|
|
65
|
+
levels.push(...efforts);
|
|
66
|
+
if (efforts.length === 0 && toggle) levels.push('on');
|
|
67
|
+
return levels.length > 1 ? levels : [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function buildClineReasoningControl(options: ReasoningOptions): ReasoningControl | undefined {
|
|
71
|
+
const levels = clineReasoningLevels(options);
|
|
72
|
+
if (levels.length === 0) return undefined;
|
|
73
|
+
return { levels: toReasoningOptions(levels), default: 'auto' };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** `Agent` config fields carrying a reasoning level. */
|
|
77
|
+
export interface ClineReasoningConfig {
|
|
78
|
+
thinking?: boolean;
|
|
79
|
+
reasoningEffort?: ClineEffort;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Map a chosen level onto the `Agent` knobs. A level the model doesn't offer
|
|
84
|
+
* (stale per-model memory, a model swapped under the chat) and `auto` both send
|
|
85
|
+
* nothing, so the model's own default applies rather than an invented value.
|
|
86
|
+
*/
|
|
87
|
+
export function resolveClineReasoning(level: string | undefined, options: ReasoningOptions): ClineReasoningConfig {
|
|
88
|
+
if (!level || !clineReasoningLevels(options).includes(level)) return {};
|
|
89
|
+
if (level === 'off') return { thinking: false };
|
|
90
|
+
if (level === 'on') return { thinking: true };
|
|
91
|
+
if ((CLINE_EFFORTS as readonly string[]).includes(level)) return { reasoningEffort: level as ClineEffort };
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Catalog entry for one model, or undefined when the provider doesn't list it. */
|
|
96
|
+
export async function getClineModelInfo(providerId: string, modelId: string): Promise<CatalogModel | undefined> {
|
|
97
|
+
try {
|
|
98
|
+
const { Llms } = await loadEngineSdk<typeof import('@cline/sdk')>('cline', '@cline/sdk');
|
|
99
|
+
return (await Llms.getModelsForProvider(providerId))[modelId];
|
|
100
|
+
} catch (error) {
|
|
101
|
+
debug.warn('engine', `Cline: could not read catalog entry for "${providerId}/${modelId}": ${error instanceof Error ? error.message : String(error)}`);
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
21
105
|
|
|
22
106
|
export async function fetchClineModels(): Promise<EngineModel[]> {
|
|
23
107
|
try {
|
|
@@ -39,7 +123,7 @@ export async function fetchClineModels(): Promise<EngineModel[]> {
|
|
|
39
123
|
continue;
|
|
40
124
|
}
|
|
41
125
|
for (const [modelId, info] of Object.entries(models)) {
|
|
42
|
-
out.push(mapClineModel(providerId, modelId, info));
|
|
126
|
+
if (isClineChatModel(info)) out.push(mapClineModel(providerId, modelId, info));
|
|
43
127
|
}
|
|
44
128
|
}
|
|
45
129
|
debug.log('engine', `Cline getAvailableModels: ${out.length} models across ${providers.size} provider(s)`);
|
|
@@ -53,6 +137,7 @@ export async function fetchClineModels(): Promise<EngineModel[]> {
|
|
|
53
137
|
function mapClineModel(providerId: string, modelId: string, info: CatalogModel): EngineModel {
|
|
54
138
|
const caps = info.capabilities ?? [];
|
|
55
139
|
const image = caps.includes('images');
|
|
140
|
+
const reasoningControl = buildClineReasoningControl(info.reasoningOptions);
|
|
56
141
|
return {
|
|
57
142
|
engine: {
|
|
58
143
|
type: 'cline',
|
|
@@ -69,6 +154,7 @@ function mapClineModel(providerId: string, modelId: string, info: CatalogModel):
|
|
|
69
154
|
reasoning: caps.includes('reasoning'),
|
|
70
155
|
tools: caps.includes('tools'),
|
|
71
156
|
structuredOutput: caps.includes('structured_output'),
|
|
157
|
+
...(reasoningControl && { reasoningControl }),
|
|
72
158
|
},
|
|
73
159
|
cost: { input: info.pricing?.input ?? 0, output: info.pricing?.output ?? 0 },
|
|
74
160
|
};
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import type { ClineAuthMode, ClineCredentialField, ClineProviderPreset } from '$shared/types/unified';
|
|
16
16
|
import { debug } from '$shared/utils/logger';
|
|
17
17
|
import { loadEngineSdk } from '$backend/engine/sdk-loader';
|
|
18
|
+
import { isClineChatModel } from './models';
|
|
18
19
|
|
|
19
20
|
export type { ClineAuthMode, ClineCredentialField, ClineProviderPreset };
|
|
20
21
|
|
|
@@ -101,6 +102,10 @@ export async function getClineProviderPresets(): Promise<ClineProviderPreset[]>
|
|
|
101
102
|
const { Llms, getProviderConfigFields, isOAuthProvider } = await loadEngineSdk<typeof import('@cline/sdk')>('cline', '@cline/sdk');
|
|
102
103
|
const presets: ClineProviderPreset[] = [];
|
|
103
104
|
for (const provider of await Llms.getAllProviders()) {
|
|
105
|
+
// Speech/media-only providers (e.g. ElevenLabs) list models but none a
|
|
106
|
+
// chat turn can use — an account there would leave the picker empty.
|
|
107
|
+
const models = Object.values(await Llms.getModelsForProvider(provider.id).catch(() => ({})));
|
|
108
|
+
if (models.length > 0 && !models.some(isClineChatModel)) continue;
|
|
104
109
|
const config = getProviderConfigFields(provider.id);
|
|
105
110
|
const oauth = isOAuthProvider(provider.id) || config.authMethod === 'oauth';
|
|
106
111
|
const fields = await getClineProviderFields(provider.id);
|
|
@@ -39,7 +39,7 @@ import { EngineRuns } from '../run-registry';
|
|
|
39
39
|
import { subagentQueries } from '$backend/database/queries';
|
|
40
40
|
import { readSubagentMd } from '$backend/subagents/store';
|
|
41
41
|
import { getClineAccountForProvider, parseClineCredential, resolveClineAuth } from './credential';
|
|
42
|
-
import { fetchClineModels } from './models';
|
|
42
|
+
import { fetchClineModels, getClineModelInfo, resolveClineReasoning } from './models';
|
|
43
43
|
import { buildClineMcpTools } from './mcp-tools';
|
|
44
44
|
import { createAskUserQuestionTool, formatAnswers, type PendingAsk } from './ask-question-tool';
|
|
45
45
|
import { createAgentDispatchTool, type SubagentInfo } from './agent-tool';
|
|
@@ -147,7 +147,7 @@ export class ClineEngine implements AIEngine {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
async *streamQuery(options: EngineQueryOptions): AsyncGenerator<EngineOutput, void, unknown> {
|
|
150
|
-
const { projectPath, prompt, resume, providerSlug, modelId, abortController, accountId } = options;
|
|
150
|
+
const { projectPath, prompt, resume, providerSlug, modelId, reasoningEffort, abortController, accountId } = options;
|
|
151
151
|
debug.log('chat', 'Cline - Stream Query', { providerSlug, modelId, resume });
|
|
152
152
|
|
|
153
153
|
// ── Resolve account + credential for the model's provider ──
|
|
@@ -158,6 +158,11 @@ export class ClineEngine implements AIEngine {
|
|
|
158
158
|
}
|
|
159
159
|
const provider = parseClineCredential(account.credential)?.provider ?? providerSlug;
|
|
160
160
|
const auth = await resolveClineAuth(account);
|
|
161
|
+
// Reasoning level → `thinking` / `reasoningEffort`, gated by the model's
|
|
162
|
+
// catalog options. Shared with the subagent so delegated work thinks alike.
|
|
163
|
+
const reasoning = reasoningEffort
|
|
164
|
+
? resolveClineReasoning(reasoningEffort, (await getClineModelInfo(provider, modelId))?.reasoningOptions)
|
|
165
|
+
: {};
|
|
161
166
|
|
|
162
167
|
const controller = abortController || new AbortController();
|
|
163
168
|
const run: ClineRun = { controller, agent: null };
|
|
@@ -238,6 +243,7 @@ export class ClineEngine implements AIEngine {
|
|
|
238
243
|
...(auth.apiKey ? { apiKey: auth.apiKey } : {}),
|
|
239
244
|
...(auth.baseUrl ? { baseUrl: auth.baseUrl } : {}),
|
|
240
245
|
...(auth.options ? { options: auth.options } : {}),
|
|
246
|
+
...reasoning,
|
|
241
247
|
systemPrompt: `${base}\n\n# Subagent: ${subagent.name}\n\n${instructions}`,
|
|
242
248
|
tools: builtinTools,
|
|
243
249
|
toolPolicies,
|
|
@@ -302,6 +308,7 @@ export class ClineEngine implements AIEngine {
|
|
|
302
308
|
...(auth.apiKey ? { apiKey: auth.apiKey } : {}),
|
|
303
309
|
...(auth.baseUrl ? { baseUrl: auth.baseUrl } : {}),
|
|
304
310
|
...(auth.options ? { options: auth.options } : {}),
|
|
311
|
+
...reasoning,
|
|
305
312
|
systemPrompt,
|
|
306
313
|
tools,
|
|
307
314
|
toolPolicies,
|
|
@@ -470,7 +470,7 @@ function buildFileChangePair(item: FileChangeItem, state: CodexStreamState): Eng
|
|
|
470
470
|
const isFailed = item.status === 'failed';
|
|
471
471
|
|
|
472
472
|
// SDK doesn't carry file content on FileUpdateChange — pull it from the
|
|
473
|
-
// rollout JSONL's
|
|
473
|
+
// rollout JSONL's patch event so Edit blocks render the real
|
|
474
474
|
// before/after text and Write blocks the real file body. Falls back to
|
|
475
475
|
// empty strings if the rollout isn't readable.
|
|
476
476
|
const changedPaths = item.changes.map(change => change.path);
|
|
@@ -20,35 +20,50 @@
|
|
|
20
20
|
* table but marked `visibility: "hide"` there, so they're deliberately left
|
|
21
21
|
* out of this picker too.
|
|
22
22
|
*
|
|
23
|
+
* Every entry also carries a `minimal_client_version`. The GPT-6 family needs
|
|
24
|
+
* 0.153 (`gpt-6-astra`, `gpt-6.1-sol`) or 0.155 (`gpt-6-sol`, `gpt-6-luna`), so
|
|
25
|
+
* this list must never run ahead of the pinned SDK: a model picked here that
|
|
26
|
+
* the bundled CLI is too old for fails at runtime, not at type-check.
|
|
27
|
+
*
|
|
23
28
|
* Models tagged `requiresAuthMode` are filtered by the chat-input account
|
|
24
29
|
* picker so the user can't pick a ChatGPT-only model while signed in with an
|
|
25
30
|
* API key account (and vice versa).
|
|
26
31
|
*/
|
|
27
32
|
|
|
33
|
+
import type { ModelReasoningEffort } from '@openai/codex-sdk';
|
|
28
34
|
import type { EngineModel, ReasoningControl } from '$shared/types/unified';
|
|
29
35
|
import { toReasoningOptions } from '$shared/constants/engines';
|
|
30
36
|
|
|
31
37
|
/**
|
|
32
|
-
* Codex's reasoning knob is the `
|
|
33
|
-
* levels are per-model
|
|
38
|
+
* Codex's reasoning knob is the SDK `modelReasoningEffort` thread option. The
|
|
39
|
+
* levels are per-model: the 5.6 and 6 families reach `max` or `ultra` above
|
|
34
40
|
* `xhigh`, and `minimal` is no longer accepted by any current model.
|
|
35
41
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* them anyway is sound.
|
|
42
|
+
* Typed against the SDK union so a level the SDK doesn't know is a compile
|
|
43
|
+
* error here rather than a cast at the call site.
|
|
39
44
|
*/
|
|
40
|
-
const EFFORTS_TO_ULTRA = ['low', 'medium', 'high', 'xhigh', 'max', 'ultra'];
|
|
41
|
-
const EFFORTS_TO_MAX = ['low', 'medium', 'high', 'xhigh', 'max'];
|
|
42
|
-
const EFFORTS_TO_XHIGH = ['low', 'medium', 'high', 'xhigh'];
|
|
45
|
+
const EFFORTS_TO_ULTRA: ModelReasoningEffort[] = ['low', 'medium', 'high', 'xhigh', 'max', 'ultra'];
|
|
46
|
+
const EFFORTS_TO_MAX: ModelReasoningEffort[] = ['low', 'medium', 'high', 'xhigh', 'max'];
|
|
47
|
+
const EFFORTS_TO_XHIGH: ModelReasoningEffort[] = ['low', 'medium', 'high', 'xhigh'];
|
|
43
48
|
|
|
44
|
-
function codexReasoning(levels:
|
|
49
|
+
function codexReasoning(levels: ModelReasoningEffort[], fallback: ModelReasoningEffort): ReasoningControl {
|
|
45
50
|
return { levels: toReasoningOptions(levels), default: fallback };
|
|
46
51
|
}
|
|
47
52
|
|
|
53
|
+
/**
|
|
54
|
+
* The table carries two windows per model: `context_window` (272k, what the
|
|
55
|
+
* CLI uses by default) and `max_context_window` (872k for the 5.6 and 6
|
|
56
|
+
* families, 272k for `gpt-5.5`). Clopen runs every model at its max — see
|
|
57
|
+
* `CODEX_CONTEXT_WINDOW_REQUEST` — so the catalog reports the max.
|
|
58
|
+
*/
|
|
59
|
+
const WINDOW_872K = 872_000;
|
|
60
|
+
const WINDOW_272K = 272_000;
|
|
61
|
+
|
|
48
62
|
/** Shared shape for a Codex catalog entry; `reasoning: null` = no reasoning knob. */
|
|
49
63
|
function codexModel(
|
|
50
64
|
id: string,
|
|
51
65
|
name: string,
|
|
66
|
+
contextWindow: number,
|
|
52
67
|
reasoning: ReasoningControl | null,
|
|
53
68
|
extra?: { image?: boolean; requiresAuthMode?: 'chatgpt' },
|
|
54
69
|
): EngineModel {
|
|
@@ -59,8 +74,7 @@ function codexModel(
|
|
|
59
74
|
model: { id, name },
|
|
60
75
|
account: { id: 0, name: '' },
|
|
61
76
|
},
|
|
62
|
-
|
|
63
|
-
limit: { input: 272_000, output: 128_000 },
|
|
77
|
+
limit: { input: contextWindow, output: 128_000 },
|
|
64
78
|
modalities: {
|
|
65
79
|
input: { text: true, image: extra?.image ?? true, audio: false, video: false, pdf: false },
|
|
66
80
|
output: { text: true, image: false, audio: false, video: false, pdf: false },
|
|
@@ -78,15 +92,29 @@ function codexModel(
|
|
|
78
92
|
|
|
79
93
|
/** Ordered by the CLI's own `priority` field, so the picker matches Codex's. */
|
|
80
94
|
export const CODEX_MODELS: EngineModel[] = [
|
|
81
|
-
codexModel('gpt-6-
|
|
82
|
-
codexModel('gpt-6-
|
|
83
|
-
codexModel('gpt-6-
|
|
84
|
-
codexModel('gpt-
|
|
85
|
-
codexModel('gpt-5.6-
|
|
86
|
-
codexModel('gpt-5.6-
|
|
87
|
-
codexModel('gpt-5.
|
|
95
|
+
codexModel('gpt-6.1-sol', 'GPT-6.1-Sol', WINDOW_872K, codexReasoning(EFFORTS_TO_ULTRA, 'low')),
|
|
96
|
+
codexModel('gpt-6-astra', 'GPT-6-Astra', WINDOW_872K, codexReasoning(EFFORTS_TO_ULTRA, 'low')),
|
|
97
|
+
codexModel('gpt-6-sol', 'GPT-6-Sol', WINDOW_872K, codexReasoning(EFFORTS_TO_ULTRA, 'medium')),
|
|
98
|
+
codexModel('gpt-6-luna', 'GPT-6-Luna', WINDOW_872K, codexReasoning(EFFORTS_TO_MAX, 'medium')),
|
|
99
|
+
codexModel('gpt-5.6-sol', 'GPT-5.6-Sol', WINDOW_872K, codexReasoning(EFFORTS_TO_ULTRA, 'low')),
|
|
100
|
+
codexModel('gpt-5.6-terra', 'GPT-5.6-Terra', WINDOW_872K, codexReasoning(EFFORTS_TO_ULTRA, 'medium')),
|
|
101
|
+
codexModel('gpt-5.6-luna', 'GPT-5.6-Luna', WINDOW_872K, codexReasoning(EFFORTS_TO_MAX, 'medium')),
|
|
102
|
+
codexModel('gpt-5.5', 'GPT-5.5', WINDOW_272K, codexReasoning(EFFORTS_TO_XHIGH, 'medium')),
|
|
88
103
|
];
|
|
89
104
|
|
|
105
|
+
/**
|
|
106
|
+
* The `model_context_window` sent to the CLI. Without it the CLI stays at each
|
|
107
|
+
* model's 272k `context_window` even where the model reaches 872k.
|
|
108
|
+
*
|
|
109
|
+
* The SDK bakes `config` into the client once, while the model changes per
|
|
110
|
+
* turn, so this is one value for every model: the largest window in the
|
|
111
|
+
* catalog. That is sound because the CLI clamps the request to the active
|
|
112
|
+
* model's `max_context_window` — verified against 0.159.3, where 872k on
|
|
113
|
+
* `gpt-5.5` reported a 272k window and 2M on `gpt-5.6-luna` reported 872k
|
|
114
|
+
* (each less the CLI's 5% reserve).
|
|
115
|
+
*/
|
|
116
|
+
export const CODEX_CONTEXT_WINDOW_REQUEST = Math.max(...CODEX_MODELS.map(model => model.limit.input));
|
|
117
|
+
|
|
90
118
|
/**
|
|
91
119
|
* Resolve the `model_reasoning_effort` to send for a turn: the requested level
|
|
92
120
|
* when that model accepts it, otherwise that model's own default, otherwise
|
|
@@ -95,19 +123,14 @@ export const CODEX_MODELS: EngineModel[] = [
|
|
|
95
123
|
* This is the only gate on the value. The picker offers per-model levels, but a
|
|
96
124
|
* stored preference outlives a catalog change, so a level that is no longer
|
|
97
125
|
* valid (`minimal`, or `ultra` on a model that caps at `max`) must not reach
|
|
98
|
-
* the CLI
|
|
99
|
-
*
|
|
100
|
-
* The return type is deliberately `string`, not the SDK's
|
|
101
|
-
* `ModelReasoningEffort`. That union still stops at `xhigh` in
|
|
102
|
-
* @openai/codex-sdk 0.147 while the CLI it drives accepts
|
|
103
|
-
* `none|minimal|low|medium|high|xhigh|max|ultra`, and the SDK does not validate
|
|
104
|
-
* — it interpolates the value straight into
|
|
105
|
-
* `--config model_reasoning_effort="…"` (`dist/index.js`). Narrowing to the
|
|
106
|
-
* stale union would make `max` and `ultra`, the top levels of GPT-5.6 Sol and
|
|
107
|
-
* Terra, unreachable from Clopen. The caller casts at the SDK boundary.
|
|
126
|
+
* the CLI — the SDK does not validate, it interpolates the value straight into
|
|
127
|
+
* `--config model_reasoning_effort="…"`.
|
|
108
128
|
*/
|
|
109
|
-
export function resolveCodexEffort(modelId: string | undefined, requested: string | undefined):
|
|
129
|
+
export function resolveCodexEffort(modelId: string | undefined, requested: string | undefined): ModelReasoningEffort {
|
|
110
130
|
const control = CODEX_MODELS.find(m => m.engine.model.id === modelId)?.capabilities.reasoningControl;
|
|
111
|
-
|
|
112
|
-
|
|
131
|
+
const accepts = (value: string | undefined): value is ModelReasoningEffort =>
|
|
132
|
+
value !== undefined && (control?.levels.some(level => level.value === value) ?? false);
|
|
133
|
+
if (accepts(requested)) return requested;
|
|
134
|
+
if (accepts(control?.default)) return control.default;
|
|
135
|
+
return 'medium';
|
|
113
136
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test';
|
|
2
2
|
import type { FileChangeSet } from './patch-rollout';
|
|
3
|
-
import { parseUnifiedDiff, findMatchingFileChangeSet } from './patch-rollout';
|
|
3
|
+
import { parseUnifiedDiff, findMatchingFileChangeSet, parseFileChangeSets } from './patch-rollout';
|
|
4
4
|
|
|
5
5
|
describe('parseUnifiedDiff', () => {
|
|
6
6
|
test('splits a single hunk into before/after text', () => {
|
|
@@ -86,3 +86,38 @@ describe('findMatchingFileChangeSet', () => {
|
|
|
86
86
|
expect(findMatchingFileChangeSet([], ['/repo/a.ts'])).toBeNull();
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
|
+
|
|
90
|
+
describe('parseFileChangeSets', () => {
|
|
91
|
+
const changes = {
|
|
92
|
+
'/repo/style.css': { type: 'update', unified_diff: '@@ -1,2 +1,2 @@\n-color: red;\n+color: blue;\n', move_path: null },
|
|
93
|
+
'/repo/notes.md': { type: 'add', content: '# Notes\n' }
|
|
94
|
+
};
|
|
95
|
+
const expected: FileChangeSet = new Map([
|
|
96
|
+
['/repo/style.css', { kind: 'update', oldString: 'color: red;\n', newString: 'color: blue;\n', content: '' }],
|
|
97
|
+
['/repo/notes.md', { kind: 'add', oldString: '', newString: '', content: '# Notes\n' }]
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
test('reads the completed FileChange item the 0.159 CLI writes', () => {
|
|
101
|
+
const line = JSON.stringify({
|
|
102
|
+
type: 'event_msg',
|
|
103
|
+
payload: { type: 'item_completed', item: { type: 'FileChange', status: 'completed', changes } }
|
|
104
|
+
});
|
|
105
|
+
expect(parseFileChangeSets(line)).toEqual([expected]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('still reads the legacy patch_apply_end event', () => {
|
|
109
|
+
const line = JSON.stringify({ type: 'event_msg', payload: { type: 'patch_apply_end', success: true, changes } });
|
|
110
|
+
expect(parseFileChangeSets(line)).toEqual([expected]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('keeps file order and skips unrelated or malformed lines', () => {
|
|
114
|
+
const legacy = JSON.stringify({ type: 'event_msg', payload: { type: 'patch_apply_end', changes: { '/repo/a.ts': { type: 'delete' } } } });
|
|
115
|
+
const other = JSON.stringify({ type: 'event_msg', payload: { type: 'item_completed', item: { type: 'AgentMessage' } } });
|
|
116
|
+
const current = JSON.stringify({ type: 'event_msg', payload: { type: 'item_completed', item: { type: 'FileChange', changes } } });
|
|
117
|
+
const sets = parseFileChangeSets([legacy, other, '{"FileChange": broken', '', current].join('\n'));
|
|
118
|
+
|
|
119
|
+
expect(sets).toHaveLength(2);
|
|
120
|
+
expect(sets[0]?.get('/repo/a.ts')?.kind).toBe('delete');
|
|
121
|
+
expect(sets[1]).toEqual(expected);
|
|
122
|
+
});
|
|
123
|
+
});
|