@myrialabs/clopen 0.4.20 → 0.4.21
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/bootstrap.ts +39 -0
- package/backend/chat/stream-manager.ts +15 -0
- package/backend/database/migrations/065_add_session_reasoning_effort.ts +28 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/session-queries.ts +10 -0
- package/backend/engine/adapters/claude/models.ts +46 -23
- package/backend/engine/adapters/claude/stream.ts +18 -4
- package/backend/engine/adapters/codex/models.ts +19 -2
- package/backend/engine/adapters/codex/stream.ts +10 -3
- package/backend/engine/adapters/copilot/models.ts +20 -1
- package/backend/engine/adapters/copilot/stream.ts +11 -1
- package/backend/engine/adapters/cursor/models.ts +27 -3
- package/backend/engine/adapters/cursor/stream.ts +23 -3
- package/backend/engine/adapters/pi/models.ts +20 -2
- package/backend/engine/adapters/pi/stream.ts +6 -3
- package/backend/engine/bootstrap-default-engine.ts +18 -5
- package/backend/engine/types.ts +6 -0
- package/backend/index.ts +6 -9
- package/backend/ws/chat/stream.ts +38 -2
- package/backend/ws/system/device-info.ts +290 -0
- package/backend/ws/system/index.ts +2 -0
- package/backend/ws/system/operations.ts +7 -0
- package/backend/ws/user/crud.ts +6 -3
- package/dist/assets/{index-DdrcY5TE.js → index-B8YRz8wG.js} +1 -1
- package/dist/assets/{index-BqBxKeAv.js → index-CEGW8vEt.js} +1 -1
- package/dist/assets/main-D-2ByODy.js +590 -0
- package/dist/assets/main-D8I0MfRQ.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +2 -1
- package/shared/constants/engines.ts +23 -0
- package/shared/types/database/schema.ts +1 -0
- package/shared/types/stores/settings.ts +6 -0
- package/shared/types/unified/engine.ts +33 -0
- package/shared/types/unified/index.ts +2 -0
- package/shared/types/unified/message.ts +6 -0
- package/shared/types/unified/stream.ts +6 -0
- package/dist/assets/main-BBxAj17T.js +0 -582
- package/dist/assets/main-Cry3pLcl.css +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-database-init bootstrap
|
|
3
|
+
*
|
|
4
|
+
* Re-establishes code-defined built-ins that live OUTSIDE the migration/seeder
|
|
5
|
+
* pipeline — internal MCP servers (e.g. Browser Automation) synced from code,
|
|
6
|
+
* and the default engine install. These are normally set up once at server
|
|
7
|
+
* startup, right after `initializeDatabase()`.
|
|
8
|
+
*
|
|
9
|
+
* "Clear All Data" wipes the whole ~/.clopen directory and re-runs only
|
|
10
|
+
* migrations + seeders on the SAME live process, so anything established here
|
|
11
|
+
* would silently vanish until the next restart. Sharing this function between
|
|
12
|
+
* startup and the clear-data handler keeps built-ins alive across a data reset
|
|
13
|
+
* without a restart — and means any future startup-synced built-in is covered
|
|
14
|
+
* automatically.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { syncInternalServers } from './mcp';
|
|
18
|
+
import { ensureDefaultEngineInstalled } from './engine/bootstrap-default-engine';
|
|
19
|
+
import { debug } from '$shared/utils/logger';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Rebuild DB-derived built-ins after the database is (re)initialized.
|
|
23
|
+
*
|
|
24
|
+
* Idempotent and safe to call on an already-running process. Intentionally does
|
|
25
|
+
* NOT start long-lived schedulers — those are launched once from `startServer()`
|
|
26
|
+
* and would double-run if invoked again on the live process during clear-data.
|
|
27
|
+
*/
|
|
28
|
+
export function bootstrapAfterDbInit(): void {
|
|
29
|
+
// Mirror code-defined internal MCP servers into the mcp_servers table and
|
|
30
|
+
// refresh the enabled cache. Without this, a post-startup DB wipe leaves
|
|
31
|
+
// Settings → MCP empty until the next restart.
|
|
32
|
+
syncInternalServers();
|
|
33
|
+
|
|
34
|
+
// Fresh/emptied install: (re)install a usable engine in the background.
|
|
35
|
+
// No-ops once any engine is already present. Fire-and-forget.
|
|
36
|
+
void ensureDefaultEngineInstalled();
|
|
37
|
+
|
|
38
|
+
debug.log('server', '✅ Post-DB bootstrap complete');
|
|
39
|
+
}
|
|
@@ -55,6 +55,8 @@ export interface StreamState {
|
|
|
55
55
|
processId: string;
|
|
56
56
|
engine: EngineType;
|
|
57
57
|
accountId?: number;
|
|
58
|
+
/** Reasoning/thinking level token for this run (native per engine; undefined = engine default). */
|
|
59
|
+
reasoningEffort?: string;
|
|
58
60
|
status: 'active' | 'completed' | 'error' | 'cancelled';
|
|
59
61
|
startedAt: Date;
|
|
60
62
|
completedAt?: Date;
|
|
@@ -124,6 +126,8 @@ interface RequestEngineContext {
|
|
|
124
126
|
accountId: number;
|
|
125
127
|
accountName: string;
|
|
126
128
|
modelName: string;
|
|
129
|
+
/** Reasoning/thinking level for this turn (native per engine; undefined = no knob). */
|
|
130
|
+
reasoningEffort?: string;
|
|
127
131
|
}
|
|
128
132
|
|
|
129
133
|
/**
|
|
@@ -148,6 +152,9 @@ function enrichMessageEngine(
|
|
|
148
152
|
id: ctx.accountId || message.engine.account.id,
|
|
149
153
|
name: ctx.accountName || message.engine.account.name,
|
|
150
154
|
},
|
|
155
|
+
// Surface the turn's reasoning level (when the engine exposes one) so it's
|
|
156
|
+
// visible in the Raw Message view. Omitted when there's no knob.
|
|
157
|
+
...(ctx.reasoningEffort !== undefined && { reasoningEffort: ctx.reasoningEffort }),
|
|
151
158
|
},
|
|
152
159
|
};
|
|
153
160
|
}
|
|
@@ -298,6 +305,7 @@ class StreamManager extends EventEmitter {
|
|
|
298
305
|
processId,
|
|
299
306
|
engine: request.engine.type,
|
|
300
307
|
accountId: request.engine.account?.id || undefined,
|
|
308
|
+
reasoningEffort: request.reasoningEffort ?? undefined,
|
|
301
309
|
status: 'active',
|
|
302
310
|
startedAt: new Date(),
|
|
303
311
|
messages: [],
|
|
@@ -327,6 +335,11 @@ class StreamManager extends EventEmitter {
|
|
|
327
335
|
if (request.profileId !== undefined) {
|
|
328
336
|
sessionQueries.updateProfile(request.chatSessionId, request.profileId);
|
|
329
337
|
}
|
|
338
|
+
// Persist the reasoning/thinking level (string or null). `undefined`
|
|
339
|
+
// (client didn't send one) leaves the stored value untouched.
|
|
340
|
+
if (request.reasoningEffort !== undefined) {
|
|
341
|
+
sessionQueries.updateReasoning(request.chatSessionId, request.reasoningEffort);
|
|
342
|
+
}
|
|
330
343
|
} catch (error) {
|
|
331
344
|
debug.error('chat', 'Failed to save engine/model to session:', error);
|
|
332
345
|
}
|
|
@@ -456,6 +469,7 @@ class StreamManager extends EventEmitter {
|
|
|
456
469
|
accountId: requestEngine.account.id,
|
|
457
470
|
accountName: requestEngine.account.name,
|
|
458
471
|
modelName: requestEngine.model.name,
|
|
472
|
+
reasoningEffort: streamState.reasoningEffort,
|
|
459
473
|
};
|
|
460
474
|
|
|
461
475
|
const projectPathExists = projectPath ? await this.existsSync(projectPath) : false;
|
|
@@ -642,6 +656,7 @@ class StreamManager extends EventEmitter {
|
|
|
642
656
|
resume: resumeSessionId,
|
|
643
657
|
providerSlug: requestEngine.provider,
|
|
644
658
|
modelId: requestEngine.model.id,
|
|
659
|
+
...(streamState.reasoningEffort && { reasoningEffort: streamState.reasoningEffort }),
|
|
645
660
|
includePartialMessages: true,
|
|
646
661
|
abortController: streamState.abortController,
|
|
647
662
|
...(requestEngine.account.id !== 0 && { accountId: requestEngine.account.id }),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
|
+
import { debug } from '$shared/utils/logger';
|
|
3
|
+
|
|
4
|
+
export const description = 'Add reasoning_effort column to chat_sessions for per-session reasoning/thinking level';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Persists the reasoning/thinking level chosen per chat session (native per
|
|
8
|
+
* engine — e.g. Codex `high`, Copilot `medium`, Pi `low`). Nullable: a NULL
|
|
9
|
+
* value means "use the engine's own default", which is the behaviour for every
|
|
10
|
+
* pre-existing session and any engine/model that exposes no reasoning knob.
|
|
11
|
+
*/
|
|
12
|
+
export const up = (db: DatabaseConnection): void => {
|
|
13
|
+
debug.log('migration', 'Adding reasoning_effort column to chat_sessions...');
|
|
14
|
+
db.exec(`ALTER TABLE chat_sessions ADD COLUMN reasoning_effort TEXT`);
|
|
15
|
+
debug.log('migration', 'chat_sessions reasoning_effort column added');
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const down = (db: DatabaseConnection): void => {
|
|
19
|
+
debug.log('migration', 'Removing reasoning_effort column from chat_sessions...');
|
|
20
|
+
// SQLite pre-3.35 can't DROP COLUMN reliably in all builds; use the guarded
|
|
21
|
+
// form so the down migration is a no-op where DROP COLUMN is unsupported.
|
|
22
|
+
try {
|
|
23
|
+
db.exec(`ALTER TABLE chat_sessions DROP COLUMN reasoning_effort`);
|
|
24
|
+
} catch {
|
|
25
|
+
debug.warn('migration', 'DROP COLUMN reasoning_effort unsupported on this SQLite build — leaving column in place');
|
|
26
|
+
}
|
|
27
|
+
debug.log('migration', 'chat_sessions reasoning_effort column removed');
|
|
28
|
+
};
|
|
@@ -63,6 +63,7 @@ import * as migration061 from './061_add_session_device_metadata';
|
|
|
63
63
|
import * as migration062 from './062_add_session_source';
|
|
64
64
|
import * as migration063 from './063_add_invite_project_ids';
|
|
65
65
|
import * as migration064 from './064_create_messages_fts';
|
|
66
|
+
import * as migration065 from './065_add_session_reasoning_effort';
|
|
66
67
|
|
|
67
68
|
// Export all migrations in order
|
|
68
69
|
export const migrations = [
|
|
@@ -449,6 +450,12 @@ export const migrations = [
|
|
|
449
450
|
description: migration064.description,
|
|
450
451
|
up: migration064.up,
|
|
451
452
|
down: migration064.down
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
id: '065',
|
|
456
|
+
description: migration065.description,
|
|
457
|
+
up: migration065.up,
|
|
458
|
+
down: migration065.down
|
|
452
459
|
}
|
|
453
460
|
];
|
|
454
461
|
|
|
@@ -93,6 +93,16 @@ export const sessionQueries = {
|
|
|
93
93
|
`).run(engine, provider, modelId, modelName, id);
|
|
94
94
|
},
|
|
95
95
|
|
|
96
|
+
/** Persist the reasoning/thinking level for a session (NULL clears → engine default). */
|
|
97
|
+
updateReasoning(id: string, reasoningEffort: string | null): void {
|
|
98
|
+
const db = getDatabase();
|
|
99
|
+
db.prepare(`
|
|
100
|
+
UPDATE chat_sessions
|
|
101
|
+
SET reasoning_effort = ?
|
|
102
|
+
WHERE id = ?
|
|
103
|
+
`).run(reasoningEffort, id);
|
|
104
|
+
},
|
|
105
|
+
|
|
96
106
|
/** Persist the active profile for a session (NULL clears it). */
|
|
97
107
|
updateProfile(id: string, profileId: number | null): void {
|
|
98
108
|
const db = getDatabase();
|
|
@@ -4,11 +4,29 @@
|
|
|
4
4
|
* Static catalog — the Anthropic Agent SDK accepts these IDs directly via
|
|
5
5
|
* the `model` option, no runtime discovery endpoint is needed. Update when
|
|
6
6
|
* Anthropic ships a new generation.
|
|
7
|
+
*
|
|
8
|
+
* Only models with `Current state: Active` on
|
|
9
|
+
* https://platform.claude.com/docs/en/about-claude/model-deprecations are
|
|
10
|
+
* listed here — deprecated/retired models are dropped.
|
|
7
11
|
*/
|
|
8
12
|
|
|
9
|
-
import type { EngineModel } from '$shared/types/unified';
|
|
13
|
+
import type { EngineModel, ReasoningControl } from '$shared/types/unified';
|
|
14
|
+
import { toReasoningOptions } from '$shared/constants/engines';
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Claude's reasoning knob is the Agent SDK `effort` option plus `thinking`.
|
|
18
|
+
* `off` disables thinking; `auto` is adaptive thinking (Claude decides — the
|
|
19
|
+
* historical default); the rest are the SDK's native `EffortLevel` values
|
|
20
|
+
* (`low | medium | high | xhigh | max`, silently downgraded on models that
|
|
21
|
+
* don't support the higher tiers). Uniform across the catalog; the stream
|
|
22
|
+
* adapter translates the chosen token.
|
|
23
|
+
*/
|
|
24
|
+
const CLAUDE_REASONING_CONTROL: ReasoningControl = {
|
|
25
|
+
levels: toReasoningOptions(['off', 'auto', 'low', 'medium', 'high', 'xhigh', 'max']),
|
|
26
|
+
default: 'auto',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
|
|
12
30
|
{
|
|
13
31
|
engine: {
|
|
14
32
|
type: 'claude-code',
|
|
@@ -57,8 +75,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
|
57
75
|
type: 'claude-code',
|
|
58
76
|
provider: 'anthropic',
|
|
59
77
|
model: {
|
|
60
|
-
id: 'claude-opus-
|
|
61
|
-
name: 'Claude Opus
|
|
78
|
+
id: 'claude-opus-5',
|
|
79
|
+
name: 'Claude Opus 5',
|
|
62
80
|
},
|
|
63
81
|
account: {
|
|
64
82
|
id: 0,
|
|
@@ -186,8 +204,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
|
186
204
|
type: 'claude-code',
|
|
187
205
|
provider: 'anthropic',
|
|
188
206
|
model: {
|
|
189
|
-
id: 'claude-opus-4-
|
|
190
|
-
name: 'Claude Opus 4.
|
|
207
|
+
id: 'claude-opus-4-8',
|
|
208
|
+
name: 'Claude Opus 4.8',
|
|
191
209
|
},
|
|
192
210
|
account: {
|
|
193
211
|
id: 0,
|
|
@@ -229,8 +247,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
|
229
247
|
type: 'claude-code',
|
|
230
248
|
provider: 'anthropic',
|
|
231
249
|
model: {
|
|
232
|
-
id: 'claude-
|
|
233
|
-
name: 'Claude
|
|
250
|
+
id: 'claude-opus-4-7',
|
|
251
|
+
name: 'Claude Opus 4.7',
|
|
234
252
|
},
|
|
235
253
|
account: {
|
|
236
254
|
id: 0,
|
|
@@ -263,8 +281,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
|
263
281
|
structuredOutput: true,
|
|
264
282
|
},
|
|
265
283
|
cost: {
|
|
266
|
-
input:
|
|
267
|
-
output:
|
|
284
|
+
input: 5,
|
|
285
|
+
output: 25,
|
|
268
286
|
},
|
|
269
287
|
},
|
|
270
288
|
{
|
|
@@ -315,8 +333,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
|
315
333
|
type: 'claude-code',
|
|
316
334
|
provider: 'anthropic',
|
|
317
335
|
model: {
|
|
318
|
-
id: 'claude-sonnet-4-
|
|
319
|
-
name: 'Claude Sonnet 4.
|
|
336
|
+
id: 'claude-sonnet-4-6',
|
|
337
|
+
name: 'Claude Sonnet 4.6',
|
|
320
338
|
},
|
|
321
339
|
account: {
|
|
322
340
|
id: 0,
|
|
@@ -324,8 +342,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
|
324
342
|
},
|
|
325
343
|
},
|
|
326
344
|
limit: {
|
|
327
|
-
input:
|
|
328
|
-
output:
|
|
345
|
+
input: 1_000_000,
|
|
346
|
+
output: 128_000,
|
|
329
347
|
},
|
|
330
348
|
modalities: {
|
|
331
349
|
input: {
|
|
@@ -358,8 +376,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
|
358
376
|
type: 'claude-code',
|
|
359
377
|
provider: 'anthropic',
|
|
360
378
|
model: {
|
|
361
|
-
id: 'claude-
|
|
362
|
-
name: 'Claude
|
|
379
|
+
id: 'claude-sonnet-4-5',
|
|
380
|
+
name: 'Claude Sonnet 4.5',
|
|
363
381
|
},
|
|
364
382
|
account: {
|
|
365
383
|
id: 0,
|
|
@@ -392,8 +410,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
|
392
410
|
structuredOutput: true,
|
|
393
411
|
},
|
|
394
412
|
cost: {
|
|
395
|
-
input:
|
|
396
|
-
output:
|
|
413
|
+
input: 3,
|
|
414
|
+
output: 15,
|
|
397
415
|
},
|
|
398
416
|
},
|
|
399
417
|
{
|
|
@@ -401,8 +419,8 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
|
401
419
|
type: 'claude-code',
|
|
402
420
|
provider: 'anthropic',
|
|
403
421
|
model: {
|
|
404
|
-
id: 'claude-opus-4-
|
|
405
|
-
name: 'Claude Opus 4.
|
|
422
|
+
id: 'claude-opus-4-5',
|
|
423
|
+
name: 'Claude Opus 4.5',
|
|
406
424
|
},
|
|
407
425
|
account: {
|
|
408
426
|
id: 0,
|
|
@@ -411,7 +429,7 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
|
411
429
|
},
|
|
412
430
|
limit: {
|
|
413
431
|
input: 200_000,
|
|
414
|
-
output:
|
|
432
|
+
output: 64_000,
|
|
415
433
|
},
|
|
416
434
|
modalities: {
|
|
417
435
|
input: {
|
|
@@ -435,8 +453,13 @@ export const CLAUDE_CODE_MODELS: EngineModel[] = [
|
|
|
435
453
|
structuredOutput: true,
|
|
436
454
|
},
|
|
437
455
|
cost: {
|
|
438
|
-
input:
|
|
439
|
-
output:
|
|
456
|
+
input: 5,
|
|
457
|
+
output: 25,
|
|
440
458
|
},
|
|
441
459
|
},
|
|
442
460
|
];
|
|
461
|
+
|
|
462
|
+
export const CLAUDE_CODE_MODELS: EngineModel[] = CLAUDE_CODE_MODELS_BASE.map((model) => ({
|
|
463
|
+
...model,
|
|
464
|
+
capabilities: { ...model.capabilities, reasoningControl: CLAUDE_REASONING_CONTROL },
|
|
465
|
+
}));
|
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
Query,
|
|
20
20
|
PermissionMode,
|
|
21
21
|
PermissionResult,
|
|
22
|
+
EffortLevel,
|
|
22
23
|
} from '@anthropic-ai/claude-agent-sdk';
|
|
23
24
|
import type { EngineOutput } from '$shared/types/unified';
|
|
24
25
|
import type { StructuredGenerationOptions } from '../../types';
|
|
@@ -89,11 +90,23 @@ export class ClaudeCodeEngine implements AIEngine {
|
|
|
89
90
|
resume,
|
|
90
91
|
maxTurns = undefined,
|
|
91
92
|
modelId,
|
|
93
|
+
reasoningEffort,
|
|
92
94
|
includePartialMessages = false,
|
|
93
95
|
abortController,
|
|
94
96
|
accountId
|
|
95
97
|
} = options;
|
|
96
98
|
|
|
99
|
+
// Map the chosen reasoning level to Claude's knobs: `off` disables thinking
|
|
100
|
+
// entirely, `auto`/unset keeps adaptive thinking (Claude decides how much),
|
|
101
|
+
// and an explicit effort level pairs adaptive thinking with `effort`.
|
|
102
|
+
const claudeEffort = new Set<string>(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
103
|
+
const thinkingConfig: Options['thinking'] = reasoningEffort === 'off'
|
|
104
|
+
? { type: 'disabled' }
|
|
105
|
+
: { type: 'adaptive', display: 'summarized' };
|
|
106
|
+
const effortOption = reasoningEffort && claudeEffort.has(reasoningEffort)
|
|
107
|
+
? { effort: reasoningEffort as EffortLevel }
|
|
108
|
+
: {};
|
|
109
|
+
|
|
97
110
|
debug.log('chat', "Claude Code - Stream Query");
|
|
98
111
|
debug.log('chat', { prompt });
|
|
99
112
|
|
|
@@ -142,10 +155,11 @@ export class ClaudeCodeEngine implements AIEngine {
|
|
|
142
155
|
systemPrompt: { type: "preset", preset: "claude_code" },
|
|
143
156
|
settingSources: ["user", "project", "local"],
|
|
144
157
|
forkSession: true,
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
// '
|
|
148
|
-
thinking:
|
|
158
|
+
// Reasoning level → thinking/effort (see thinkingConfig above). Adaptive
|
|
159
|
+
// thinking with summarized display keeps Opus 4.6+ emitting visible
|
|
160
|
+
// thinking_delta events; 'off' disables it, an explicit level adds effort.
|
|
161
|
+
thinking: thinkingConfig,
|
|
162
|
+
...effortOption,
|
|
149
163
|
// Custom permission handler: blocks on AskUserQuestion until user answers,
|
|
150
164
|
// auto-allows everything else. Works alongside bypassPermissions.
|
|
151
165
|
canUseTool: async (_toolName, input, canUseToolOptions) => {
|
|
@@ -9,9 +9,20 @@
|
|
|
9
9
|
* generation.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type { EngineModel } from '$shared/types/unified';
|
|
12
|
+
import type { EngineModel, ReasoningControl } from '$shared/types/unified';
|
|
13
|
+
import { toReasoningOptions } from '$shared/constants/engines';
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Codex's reasoning knob is the SDK `modelReasoningEffort` thread option
|
|
17
|
+
* (`minimal | low | medium | high | xhigh`). `medium` is the historical
|
|
18
|
+
* default. Attached only to reasoning-capable models below.
|
|
19
|
+
*/
|
|
20
|
+
const CODEX_REASONING_CONTROL: ReasoningControl = {
|
|
21
|
+
levels: toReasoningOptions(['minimal', 'low', 'medium', 'high', 'xhigh']),
|
|
22
|
+
default: 'medium',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const CODEX_MODELS_BASE: EngineModel[] = [
|
|
15
26
|
{
|
|
16
27
|
engine: {
|
|
17
28
|
type: 'codex',
|
|
@@ -103,3 +114,9 @@ export const CODEX_MODELS: EngineModel[] = [
|
|
|
103
114
|
cost: { input: 0, output: 0 },
|
|
104
115
|
},
|
|
105
116
|
];
|
|
117
|
+
|
|
118
|
+
export const CODEX_MODELS: EngineModel[] = CODEX_MODELS_BASE.map((model) =>
|
|
119
|
+
model.capabilities.reasoning
|
|
120
|
+
? { ...model, capabilities: { ...model.capabilities, reasoningControl: CODEX_REASONING_CONTROL } }
|
|
121
|
+
: model,
|
|
122
|
+
);
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* `backend/ws/chat/stream.ts` to it — same pattern as Claude/OpenCode.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import type { Codex, Thread, ThreadOptions, Input as CodexInput } from '@openai/codex-sdk';
|
|
22
|
+
import type { Codex, Thread, ThreadOptions, Input as CodexInput, ModelReasoningEffort } from '@openai/codex-sdk';
|
|
23
23
|
import { loadEngineSdk } from '$backend/engine/sdk-loader';
|
|
24
24
|
import type { EngineOutput, EngineModel } from '$shared/types/unified';
|
|
25
25
|
import type { AIEngine, EngineQueryOptions, StructuredGenerationOptions } from '../../types';
|
|
@@ -151,7 +151,14 @@ export class CodexEngine implements AIEngine {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
async *streamQuery(options: EngineQueryOptions): AsyncGenerator<EngineOutput, void, unknown> {
|
|
154
|
-
const { projectPath, prompt, resume, modelId, abortController, accountId } = options;
|
|
154
|
+
const { projectPath, prompt, resume, modelId, reasoningEffort, abortController, accountId } = options;
|
|
155
|
+
|
|
156
|
+
// Codex's reasoning knob (`minimal | low | medium | high | xhigh`); default
|
|
157
|
+
// medium when unset or an unsupported token slips through.
|
|
158
|
+
const codexEfforts = new Set<string>(['minimal', 'low', 'medium', 'high', 'xhigh']);
|
|
159
|
+
const modelReasoningEffort: ModelReasoningEffort = reasoningEffort && codexEfforts.has(reasoningEffort)
|
|
160
|
+
? reasoningEffort as ModelReasoningEffort
|
|
161
|
+
: 'medium';
|
|
155
162
|
|
|
156
163
|
// Active Profile for this stream — scopes the materialized artifact set AND
|
|
157
164
|
// (below) the MCP connector set baked into the Codex client.
|
|
@@ -200,7 +207,7 @@ export class CodexEngine implements AIEngine {
|
|
|
200
207
|
skipGitRepoCheck: true,
|
|
201
208
|
sandboxMode: 'danger-full-access',
|
|
202
209
|
approvalPolicy: 'never',
|
|
203
|
-
modelReasoningEffort
|
|
210
|
+
modelReasoningEffort,
|
|
204
211
|
webSearchMode: 'cached',
|
|
205
212
|
webSearchEnabled: true,
|
|
206
213
|
};
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { CopilotClient, ModelInfo } from '@github/copilot-sdk';
|
|
12
|
-
import type { EngineModel } from '$shared/types/unified';
|
|
12
|
+
import type { EngineModel, ReasoningControl } from '$shared/types/unified';
|
|
13
|
+
import { toReasoningOptions } from '$shared/constants/engines';
|
|
13
14
|
import { debug } from '$shared/utils/logger';
|
|
14
15
|
|
|
15
16
|
export async function fetchCopilotModels(
|
|
@@ -49,9 +50,26 @@ function summariseModelsError(error: unknown): string {
|
|
|
49
50
|
return firstLine;
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Copilot's reasoning knob is the SDK `SessionConfig.reasoningEffort`. The
|
|
55
|
+
* models.list payload reports which levels each model accepts
|
|
56
|
+
* (`supportedReasoningEfforts`) and its default (`defaultReasoningEffort`), so
|
|
57
|
+
* the control is fully model-driven. Absent when the model doesn't support it.
|
|
58
|
+
*/
|
|
59
|
+
function buildCopilotReasoningControl(info: ModelInfo): ReasoningControl | undefined {
|
|
60
|
+
if (!info.capabilities?.supports?.reasoningEffort) return undefined;
|
|
61
|
+
const levels = info.supportedReasoningEfforts ?? [];
|
|
62
|
+
if (levels.length === 0) return undefined;
|
|
63
|
+
return {
|
|
64
|
+
levels: toReasoningOptions(levels),
|
|
65
|
+
default: info.defaultReasoningEffort ?? levels[0],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
52
69
|
function mapModelInfoToEngineModel(info: ModelInfo): EngineModel {
|
|
53
70
|
const limits = info.capabilities?.limits;
|
|
54
71
|
const supports = info.capabilities?.supports;
|
|
72
|
+
const reasoningControl = buildCopilotReasoningControl(info);
|
|
55
73
|
return {
|
|
56
74
|
engine: {
|
|
57
75
|
type: 'copilot',
|
|
@@ -83,6 +101,7 @@ function mapModelInfoToEngineModel(info: ModelInfo): EngineModel {
|
|
|
83
101
|
reasoning: !!supports?.reasoningEffort,
|
|
84
102
|
tools: true,
|
|
85
103
|
structuredOutput: false,
|
|
104
|
+
...(reasoningControl && { reasoningControl }),
|
|
86
105
|
},
|
|
87
106
|
cost: {
|
|
88
107
|
input: info.billing?.multiplier ?? 0,
|
|
@@ -211,7 +211,16 @@ export class CopilotEngine implements AIEngine {
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
async *streamQuery(options: EngineQueryOptions): AsyncGenerator<EngineOutput, void, unknown> {
|
|
214
|
-
const { projectPath, prompt, resume, modelId, abortController, accountId } = options;
|
|
214
|
+
const { projectPath, prompt, resume, modelId, reasoningEffort, abortController, accountId } = options;
|
|
215
|
+
|
|
216
|
+
// Copilot's `reasoningEffort` accepts low | medium | high | xhigh; only
|
|
217
|
+
// applied for models that support it (unsupported tokens are dropped so
|
|
218
|
+
// the SDK falls back to the model default).
|
|
219
|
+
const copilotEfforts = new Set<string>(['low', 'medium', 'high', 'xhigh']);
|
|
220
|
+
const reasoningOption: Pick<ResumeSessionConfig, 'reasoningEffort'> | Record<string, never> =
|
|
221
|
+
reasoningEffort && copilotEfforts.has(reasoningEffort)
|
|
222
|
+
? { reasoningEffort: reasoningEffort as ResumeSessionConfig['reasoningEffort'] }
|
|
223
|
+
: {};
|
|
215
224
|
|
|
216
225
|
// Per-stream account override: the Copilot SDK takes the GitHub token at
|
|
217
226
|
// construction time, so an account switch requires recreating the client.
|
|
@@ -346,6 +355,7 @@ export class CopilotEngine implements AIEngine {
|
|
|
346
355
|
});
|
|
347
356
|
},
|
|
348
357
|
model: modelId,
|
|
358
|
+
...reasoningOption,
|
|
349
359
|
workingDirectory: resolvedProjectPath,
|
|
350
360
|
onEvent: handler,
|
|
351
361
|
// Emit assistant.message_delta / assistant.reasoning_delta events
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
* unavailable (empty or errored). Only a missing account/key returns `[]`.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import type {
|
|
19
|
+
import type { ModelListItem, ModelParameterDefinition } from '@cursor/sdk';
|
|
20
|
+
import type { EngineModel, ReasoningControl } from '$shared/types/unified';
|
|
21
|
+
import { reasoningLevelLabel } from '$shared/constants/engines';
|
|
20
22
|
import { debug } from '$shared/utils/logger';
|
|
21
23
|
import { loadEngineSdk } from '$backend/engine/sdk-loader';
|
|
22
24
|
import { getActiveCursorAccount, parseCursorCredential } from './credential';
|
|
@@ -35,7 +37,7 @@ export async function fetchCursorModels(): Promise<EngineModel[]> {
|
|
|
35
37
|
const models = await Cursor.models.list({ apiKey });
|
|
36
38
|
if (models.length) {
|
|
37
39
|
debug.log('engine', `Cursor getAvailableModels: ${models.length} models`);
|
|
38
|
-
return models.map(m => makeModel(m.id, m.displayName || m.id));
|
|
40
|
+
return models.map(m => makeModel(m.id, m.displayName || m.id, m));
|
|
39
41
|
}
|
|
40
42
|
debug.warn('engine', 'Cursor models.list returned empty — using fallback catalog');
|
|
41
43
|
} catch (error) {
|
|
@@ -44,7 +46,28 @@ export async function fetchCursorModels(): Promise<EngineModel[]> {
|
|
|
44
46
|
return CURSOR_FALLBACK_MODEL_IDS.map(id => makeModel(id, id));
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Cursor exposes reasoning as a per-model `ModelParameterDefinition` (a
|
|
51
|
+
* dropdown of values) selected via `ModelSelection.params`. We surface it as a
|
|
52
|
+
* reasoning control when a model advertises a parameter whose id looks like a
|
|
53
|
+
* reasoning/thinking/effort toggle. The option `value` encodes the parameter id
|
|
54
|
+
* as `"<paramId>::<value>"` so the stream adapter can rebuild the params entry
|
|
55
|
+
* without re-fetching the catalog. Best-effort — absent when no such parameter.
|
|
56
|
+
*/
|
|
57
|
+
function buildCursorReasoningControl(item?: ModelListItem): ReasoningControl | undefined {
|
|
58
|
+
const params = item?.parameters;
|
|
59
|
+
if (!params?.length) return undefined;
|
|
60
|
+
const param: ModelParameterDefinition | undefined = params.find(p => /reason|think|effort/i.test(p.id));
|
|
61
|
+
if (!param || !param.values?.length) return undefined;
|
|
62
|
+
const levels = param.values.map(v => ({
|
|
63
|
+
value: `${param.id}::${v.value}`,
|
|
64
|
+
label: v.displayName ?? reasoningLevelLabel(v.value),
|
|
65
|
+
}));
|
|
66
|
+
return { levels, default: levels[0].value };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function makeModel(id: string, name: string, item?: ModelListItem): EngineModel {
|
|
70
|
+
const reasoningControl = buildCursorReasoningControl(item);
|
|
48
71
|
return {
|
|
49
72
|
engine: {
|
|
50
73
|
type: 'cursor',
|
|
@@ -63,6 +86,7 @@ function makeModel(id: string, name: string): EngineModel {
|
|
|
63
86
|
reasoning: true,
|
|
64
87
|
tools: true,
|
|
65
88
|
structuredOutput: false,
|
|
89
|
+
...(reasoningControl && { reasoningControl }),
|
|
66
90
|
},
|
|
67
91
|
cost: { input: 0, output: 0 },
|
|
68
92
|
};
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* to Cursor's native `agents` config.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import type { SDKAgent, Run, SDKUserMessage, SDKImage, AgentDefinition, SDKCustomTool } from '@cursor/sdk';
|
|
24
|
+
import type { SDKAgent, Run, SDKUserMessage, SDKImage, AgentDefinition, SDKCustomTool, ModelSelection } from '@cursor/sdk';
|
|
25
25
|
import type { EngineOutput, EngineModel, MessageEngine } from '$shared/types/unified';
|
|
26
26
|
import type { AIEngine, EngineQueryOptions, StructuredGenerationOptions } from '../../types';
|
|
27
27
|
import { resolveOsPath } from '$backend/utils/paths';
|
|
@@ -82,6 +82,21 @@ class EventQueue<T> {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Build a Cursor `ModelSelection` from the base model id and the chosen
|
|
87
|
+
* reasoning token. The token encodes the model-parameter id as
|
|
88
|
+
* `"<paramId>::<value>"` (see cursor/models.ts). A plain id (no `::`) or an
|
|
89
|
+
* empty token yields the bare model with no params.
|
|
90
|
+
*/
|
|
91
|
+
function buildCursorModelSelection(modelId: string, reasoningEffort?: string): ModelSelection {
|
|
92
|
+
if (!reasoningEffort || !reasoningEffort.includes('::')) return { id: modelId };
|
|
93
|
+
const sep = reasoningEffort.indexOf('::');
|
|
94
|
+
const paramId = reasoningEffort.slice(0, sep);
|
|
95
|
+
const value = reasoningEffort.slice(sep + 2);
|
|
96
|
+
if (!paramId || !value) return { id: modelId };
|
|
97
|
+
return { id: modelId, params: [{ id: paramId, value }] };
|
|
98
|
+
}
|
|
99
|
+
|
|
85
100
|
export class CursorEngine implements AIEngine {
|
|
86
101
|
readonly name = 'cursor' as const;
|
|
87
102
|
private _isInitialized = false;
|
|
@@ -123,9 +138,14 @@ export class CursorEngine implements AIEngine {
|
|
|
123
138
|
}
|
|
124
139
|
|
|
125
140
|
async *streamQuery(options: EngineQueryOptions): AsyncGenerator<EngineOutput, void, unknown> {
|
|
126
|
-
const { projectPath, prompt, resume, modelId, abortController, accountId } = options;
|
|
141
|
+
const { projectPath, prompt, resume, modelId, reasoningEffort, abortController, accountId } = options;
|
|
127
142
|
debug.log('chat', 'Cursor - Stream Query', { modelId, resume });
|
|
128
143
|
|
|
144
|
+
// Cursor selects reasoning via a per-model parameter. The catalog encodes
|
|
145
|
+
// the chosen level as `"<paramId>::<value>"` (see cursor/models.ts); rebuild
|
|
146
|
+
// the `ModelSelection.params` entry here. Absent/malformed → base model.
|
|
147
|
+
const modelSelection = buildCursorModelSelection(modelId, reasoningEffort);
|
|
148
|
+
|
|
129
149
|
// ── Resolve account + API key ──
|
|
130
150
|
const account = (accountId != null ? engineQueries.getAccount(accountId) : null) ?? getActiveCursorAccount();
|
|
131
151
|
if (!account) {
|
|
@@ -228,7 +248,7 @@ export class CursorEngine implements AIEngine {
|
|
|
228
248
|
let onAbort: (() => void) | null = null;
|
|
229
249
|
try {
|
|
230
250
|
const run = await agent.send(userMessage, {
|
|
231
|
-
model:
|
|
251
|
+
model: modelSelection,
|
|
232
252
|
// Sub-agent (Task) steps aren't in `run.stream()` — they ride
|
|
233
253
|
// `tool-call-delta.taskUpdate` here. Stream each completed sub-agent
|
|
234
254
|
// tool call live as a child of the Agent block (parent.toolUseId).
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import type { Api, Model } from '@earendil-works/pi-ai';
|
|
16
|
-
import
|
|
16
|
+
import { getSupportedThinkingLevels, clampThinkingLevel } from '@earendil-works/pi-ai';
|
|
17
|
+
import type { EngineModel, ReasoningControl } from '$shared/types/unified';
|
|
18
|
+
import { toReasoningOptions } from '$shared/constants/engines';
|
|
17
19
|
import { debug } from '$shared/utils/logger';
|
|
18
20
|
import { DbCredentialStore, getPiAccounts } from './credential';
|
|
19
21
|
import { createPiRuntime } from './presets';
|
|
@@ -33,8 +35,24 @@ export async function fetchPiModels(): Promise<EngineModel[]> {
|
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Pi's reasoning knob is the agent `thinkingLevel`. The pi-ai catalog reports
|
|
40
|
+
* the supported levels per model (`getSupportedThinkingLevels`), so the control
|
|
41
|
+
* is fully model-driven. Skipped when a model only supports `off` (no reasoning).
|
|
42
|
+
*/
|
|
43
|
+
function buildPiReasoningControl(model: Model<Api>): ReasoningControl | undefined {
|
|
44
|
+
const levels = getSupportedThinkingLevels(model);
|
|
45
|
+
if (levels.length <= 1) return undefined;
|
|
46
|
+
const fallback = model.reasoning ? clampThinkingLevel(model, 'medium') : 'off';
|
|
47
|
+
return {
|
|
48
|
+
levels: toReasoningOptions(levels),
|
|
49
|
+
default: fallback,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
36
53
|
function mapPiModel(model: Model<Api>): EngineModel {
|
|
37
54
|
const image = model.input.includes('image');
|
|
55
|
+
const reasoningControl = buildPiReasoningControl(model);
|
|
38
56
|
return {
|
|
39
57
|
engine: {
|
|
40
58
|
type: 'pi',
|
|
@@ -47,7 +65,7 @@ function mapPiModel(model: Model<Api>): EngineModel {
|
|
|
47
65
|
input: { text: true, image, audio: false, video: false, pdf: false },
|
|
48
66
|
output: { text: true, image: false, audio: false, video: false, pdf: false },
|
|
49
67
|
},
|
|
50
|
-
capabilities: { reasoning: !!model.reasoning, tools: true, structuredOutput: true },
|
|
68
|
+
capabilities: { reasoning: !!model.reasoning, tools: true, structuredOutput: true, ...(reasoningControl && { reasoningControl }) },
|
|
51
69
|
cost: { input: model.cost?.input ?? 0, output: model.cost?.output ?? 0 },
|
|
52
70
|
};
|
|
53
71
|
}
|