Respect provider model-switch limits and canonical runtime events
- Add provider capability plumbing for `sessionModelSwitch` and use it in session/turn routing - Keep Cursor sessions stable when in-session model switching is unsupported - Ingest canonical runtime events (`content.delta`, `item.*`, `request.*`) with legacy-shape compatibility
This commit is contained in:
1 parent
43b64bf17d
commit
d096cb85e1
20 files changed
+1070
-207
No files matched your search
@@ -0,0 +1,188 @@
|
||||
import { spawn } from 'node:child_process';
|
||||
import readline from 'node:readline';
|
||||
|
||||
const REQUEST_TIMEOUT_MS = 15000;
|
||||
|
||||
function now() {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
function parseJson(line) {
|
||||
try {
|
||||
return JSON.parse(line);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class Client {
|
||||
constructor() {
|
||||
this.nextId = 1;
|
||||
this.pending = new Map();
|
||||
this.notifications = [];
|
||||
|
||||
this.child = spawn('agent', ['acp'], {
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
env: { ...process.env, NO_COLOR: '1' },
|
||||
});
|
||||
|
||||
this.stdout = readline.createInterface({ input: this.child.stdout });
|
||||
this.stderr = readline.createInterface({ input: this.child.stderr });
|
||||
|
||||
this.stderr.on('line', (line) => {
|
||||
process.stderr.write(`[stderr] ${line}\n`);
|
||||
});
|
||||
|
||||
this.stdout.on('line', (line) => {
|
||||
const msg = parseJson(line);
|
||||
if (!msg) {
|
||||
process.stdout.write(`[stdout non-json] ${line}\n`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(msg, 'id') &&
|
||||
!Object.prototype.hasOwnProperty.call(msg, 'method') &&
|
||||
(Object.prototype.hasOwnProperty.call(msg, 'result') ||
|
||||
Object.prototype.hasOwnProperty.call(msg, 'error'))
|
||||
) {
|
||||
const pending = this.pending.get(msg.id);
|
||||
if (!pending) return;
|
||||
this.pending.delete(msg.id);
|
||||
pending(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof msg.method === 'string') {
|
||||
this.notifications.push(msg);
|
||||
if (Object.prototype.hasOwnProperty.call(msg, 'id')) {
|
||||
this.respondUnsupported(msg.id, msg.method);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
respondUnsupported(id, method) {
|
||||
const response = {
|
||||
jsonrpc: '2.0',
|
||||
id,
|
||||
error: {
|
||||
code: -32601,
|
||||
message: `Unhandled server request in probe: ${method}`,
|
||||
},
|
||||
};
|
||||
this.child.stdin.write(`${JSON.stringify(response)}\n`);
|
||||
}
|
||||
|
||||
async send(method, params, timeoutMs = REQUEST_TIMEOUT_MS) {
|
||||
const id = this.nextId++;
|
||||
const message = { jsonrpc: '2.0', id, method, params };
|
||||
this.child.stdin.write(`${JSON.stringify(message)}\n`);
|
||||
|
||||
return await new Promise((resolve) => {
|
||||
const timer = setTimeout(() => {
|
||||
this.pending.delete(id);
|
||||
resolve({ timeout: true, id, method, params });
|
||||
}, timeoutMs);
|
||||
|
||||
this.pending.set(id, (response) => {
|
||||
clearTimeout(timer);
|
||||
resolve({ timeout: false, id, method, params, response });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async close() {
|
||||
try {
|
||||
this.child.stdin.end();
|
||||
} catch {}
|
||||
this.child.kill('SIGTERM');
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
this.child.kill('SIGKILL');
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const client = new Client();
|
||||
const results = [];
|
||||
|
||||
const init = await client.send('initialize', {
|
||||
protocolVersion: 1,
|
||||
clientCapabilities: {
|
||||
fs: { readTextFile: false, writeTextFile: false },
|
||||
terminal: false,
|
||||
},
|
||||
clientInfo: {
|
||||
name: 't3-cursor-acp-method-probe',
|
||||
version: '0.1.0',
|
||||
},
|
||||
});
|
||||
results.push(init);
|
||||
|
||||
const auth = await client.send('authenticate', { methodId: 'cursor_login' });
|
||||
results.push(auth);
|
||||
|
||||
const sessionNew = await client.send('session/new', {
|
||||
cwd: process.cwd(),
|
||||
mcpServers: [],
|
||||
model: 'gpt-5.3-codex',
|
||||
});
|
||||
results.push(sessionNew);
|
||||
|
||||
const sessionId = sessionNew?.response?.result?.sessionId;
|
||||
if (typeof sessionId !== 'string' || sessionId.length === 0) {
|
||||
const out = {
|
||||
ts: now(),
|
||||
sessionId: null,
|
||||
reason: 'Missing sessionId from session/new',
|
||||
results,
|
||||
notificationMethods: [...new Set(client.notifications.map((n) => n.method))].sort(),
|
||||
notificationSamples: client.notifications.slice(0, 8),
|
||||
};
|
||||
process.stdout.write(`${JSON.stringify(out, null, 2)}\n`);
|
||||
await client.close();
|
||||
return;
|
||||
}
|
||||
|
||||
const methodCandidates = [
|
||||
{ method: 'session/set_model', params: { sessionId, model: 'composer-1.5' } },
|
||||
{ method: 'session/setModel', params: { sessionId, model: 'composer-1.5' } },
|
||||
{ method: 'session/model/set', params: { sessionId, model: 'composer-1.5' } },
|
||||
{ method: 'session/update_model', params: { sessionId, model: 'composer-1.5' } },
|
||||
{ method: 'session/configure', params: { sessionId, model: 'composer-1.5' } },
|
||||
{ method: 'session/set_mode', params: { sessionId, modeId: 'ask' } },
|
||||
{ method: 'session/setMode', params: { sessionId, modeId: 'ask' } },
|
||||
{ method: 'session/mode/set', params: { sessionId, modeId: 'ask' } },
|
||||
{ method: 'session/update_mode', params: { sessionId, modeId: 'ask' } },
|
||||
{ method: 'session/change_mode', params: { sessionId, modeId: 'ask' } },
|
||||
{ method: 'session/set', params: { sessionId, model: 'composer-1.5' } },
|
||||
];
|
||||
|
||||
for (const candidate of methodCandidates) {
|
||||
const result = await client.send(candidate.method, candidate.params);
|
||||
results.push(result);
|
||||
}
|
||||
|
||||
// Sanity: session/prompt should still work after candidates.
|
||||
const prompt = await client.send('session/prompt', {
|
||||
sessionId,
|
||||
prompt: [{ type: 'text', text: 'Reply with exactly: ok' }],
|
||||
}, 30000);
|
||||
results.push(prompt);
|
||||
|
||||
const out = {
|
||||
ts: now(),
|
||||
sessionId,
|
||||
results,
|
||||
notificationMethods: [...new Set(client.notifications.map((n) => n.method))].sort(),
|
||||
notificationSamples: client.notifications.slice(0, 8),
|
||||
};
|
||||
|
||||
process.stdout.write(`${JSON.stringify(out, null, 2)}\n`);
|
||||
await client.close();
|
||||
}
|
||||
|
||||
main().catch(async (error) => {
|
||||
process.stderr.write(`Probe failed: ${error?.stack || String(error)}\n`);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"ts": "2026-03-03T07:05:34.357Z",
|
||||
"sessionId": null,
|
||||
"reason": "Missing sessionId from session/new",
|
||||
"results": [
|
||||
{
|
||||
"timeout": true,
|
||||
"id": 1,
|
||||
"method": "initialize",
|
||||
"params": {
|
||||
"protocolVersion": 1,
|
||||
"clientCapabilities": {
|
||||
"fs": {
|
||||
"readTextFile": false,
|
||||
"writeTextFile": false
|
||||
},
|
||||
"terminal": false
|
||||
},
|
||||
"clientInfo": {
|
||||
"name": "t3-cursor-acp-method-probe",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"timeout": true,
|
||||
"id": 2,
|
||||
"method": "authenticate",
|
||||
"params": {
|
||||
"methodId": "cursor_login"
|
||||
}
|
||||
},
|
||||
{
|
||||
"timeout": true,
|
||||
"id": 3,
|
||||
"method": "session/new",
|
||||
"params": {
|
||||
"cwd": "/Users/julius/.t3/worktrees/codething-mvp/codething-648ca884",
|
||||
"mcpServers": [],
|
||||
"model": "gpt-5.3-codex"
|
||||
}
|
||||
}
|
||||
],
|
||||
"notificationMethods": [],
|
||||
"notificationSamples": []
|
||||
}
|
||||
@@ -80,6 +80,7 @@ function createProviderServiceHarness(
|
||||
respondToRequest: () => unsupported(),
|
||||
stopSession: () => unsupported(),
|
||||
listSessions,
|
||||
getCapabilities: () => Effect.succeed({ sessionModelSwitch: "in-session" }),
|
||||
rollbackConversation,
|
||||
stopAll: () => Effect.void,
|
||||
streamEvents: Stream.fromPubSub(runtimeEventPubSub),
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import type { ProviderRuntimeEvent, ProviderSession } from "@t3tools/contracts";
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
@@ -100,10 +104,15 @@ describe("ProviderCommandReactor", () => {
|
||||
typeof input === "object" && input !== null && "resumeCursor" in input
|
||||
? input.resumeCursor
|
||||
: undefined;
|
||||
const model =
|
||||
typeof input === "object" && input !== null && "model" in input && typeof input.model === "string"
|
||||
? input.model
|
||||
: undefined;
|
||||
const session: ProviderSession = {
|
||||
sessionId: asSessionId(`sess-${sessionIndex}`),
|
||||
provider,
|
||||
status: "ready" as const,
|
||||
...(model !== undefined ? { model } : {}),
|
||||
threadId: ProviderThreadId.makeUnsafe(`provider-thread-${sessionIndex}`),
|
||||
resumeCursor: resumeCursor ?? { opaque: `cursor-${sessionIndex}` },
|
||||
createdAt: now,
|
||||
@@ -135,6 +144,25 @@ describe("ProviderCommandReactor", () => {
|
||||
}
|
||||
}),
|
||||
);
|
||||
const renameBranch = vi.fn((input: unknown) =>
|
||||
Effect.succeed({
|
||||
branch:
|
||||
typeof input === "object" &&
|
||||
input !== null &&
|
||||
"newBranch" in input &&
|
||||
typeof input.newBranch === "string"
|
||||
? input.newBranch
|
||||
: "renamed-branch",
|
||||
}),
|
||||
);
|
||||
const generateBranchName = vi.fn(() =>
|
||||
Effect.fail(
|
||||
new TextGenerationError({
|
||||
operation: "generateBranchName",
|
||||
detail: "disabled in test harness",
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const unsupported = () => Effect.die(new Error("Unsupported provider call in test")) as never;
|
||||
const service: ProviderServiceShape = {
|
||||
@@ -144,6 +172,10 @@ describe("ProviderCommandReactor", () => {
|
||||
respondToRequest: respondToRequest as ProviderServiceShape["respondToRequest"],
|
||||
stopSession: stopSession as ProviderServiceShape["stopSession"],
|
||||
listSessions: () => Effect.succeed(runtimeSessions),
|
||||
getCapabilities: (provider) =>
|
||||
Effect.succeed({
|
||||
sessionModelSwitch: provider === "cursor" ? "unsupported" : "in-session",
|
||||
}),
|
||||
rollbackConversation: () => unsupported(),
|
||||
stopAll: () => Effect.void,
|
||||
streamEvents: Stream.fromPubSub(runtimeEventPubSub),
|
||||
@@ -371,6 +403,111 @@ describe("ProviderCommandReactor", () => {
|
||||
expect(harness.stopSession.mock.calls.length).toBe(0);
|
||||
});
|
||||
|
||||
it("reuses the same cursor session when requested model is unchanged", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
type: "thread.turn.start",
|
||||
commandId: CommandId.makeUnsafe("cmd-turn-start-cursor-model-same-1"),
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
message: {
|
||||
messageId: asMessageId("user-message-cursor-model-same-1"),
|
||||
role: "user",
|
||||
text: "first",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "cursor",
|
||||
model: "composer-1.5",
|
||||
approvalPolicy: "on-request",
|
||||
sandboxMode: "workspace-write",
|
||||
createdAt: now,
|
||||
}),
|
||||
);
|
||||
|
||||
await waitFor(() => harness.startSession.mock.calls.length === 1);
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 1);
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
type: "thread.turn.start",
|
||||
commandId: CommandId.makeUnsafe("cmd-turn-start-cursor-model-same-2"),
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
message: {
|
||||
messageId: asMessageId("user-message-cursor-model-same-2"),
|
||||
role: "user",
|
||||
text: "second",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "cursor",
|
||||
model: "composer-1.5",
|
||||
approvalPolicy: "on-request",
|
||||
sandboxMode: "workspace-write",
|
||||
createdAt: now,
|
||||
}),
|
||||
);
|
||||
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 2);
|
||||
expect(harness.startSession.mock.calls.length).toBe(1);
|
||||
expect(harness.stopSession.mock.calls.length).toBe(0);
|
||||
});
|
||||
|
||||
it("keeps cursor session/model when model change is unsupported", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
type: "thread.turn.start",
|
||||
commandId: CommandId.makeUnsafe("cmd-turn-start-cursor-model-change-1"),
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
message: {
|
||||
messageId: asMessageId("user-message-cursor-model-change-1"),
|
||||
role: "user",
|
||||
text: "first",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "cursor",
|
||||
model: "gpt-5.3-codex",
|
||||
approvalPolicy: "on-request",
|
||||
sandboxMode: "workspace-write",
|
||||
createdAt: now,
|
||||
}),
|
||||
);
|
||||
|
||||
await waitFor(() => harness.startSession.mock.calls.length === 1);
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 1);
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
type: "thread.turn.start",
|
||||
commandId: CommandId.makeUnsafe("cmd-turn-start-cursor-model-change-2"),
|
||||
threadId: ThreadId.makeUnsafe("thread-1"),
|
||||
message: {
|
||||
messageId: asMessageId("user-message-cursor-model-change-2"),
|
||||
role: "user",
|
||||
text: "second",
|
||||
attachments: [],
|
||||
},
|
||||
provider: "cursor",
|
||||
model: "composer-1.5",
|
||||
approvalPolicy: "on-request",
|
||||
sandboxMode: "workspace-write",
|
||||
createdAt: now,
|
||||
}),
|
||||
);
|
||||
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 2);
|
||||
|
||||
expect(harness.stopSession.mock.calls.length).toBe(0);
|
||||
expect(harness.startSession.mock.calls.length).toBe(1);
|
||||
expect(harness.sendTurn.mock.calls[1]?.[0]).toMatchObject({
|
||||
sessionId: asSessionId("sess-1"),
|
||||
model: "gpt-5.3-codex",
|
||||
});
|
||||
});
|
||||
|
||||
it("restarts the provider session when runtime mode changes", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
|
||||
@@ -169,6 +169,7 @@ const make = Effect.gen(function* () {
|
||||
createdAt: string,
|
||||
options?: {
|
||||
readonly provider?: ProviderKind;
|
||||
readonly model?: string;
|
||||
readonly approvalPolicy?: ProviderApprovalPolicy;
|
||||
readonly sandboxMode?: ProviderSandboxMode;
|
||||
},
|
||||
@@ -190,14 +191,15 @@ const make = Effect.gen(function* () {
|
||||
? thread.session.providerName
|
||||
: undefined;
|
||||
const preferredProvider: ProviderKind | undefined = options?.provider ?? currentProvider;
|
||||
const desiredModel = options?.model ?? thread.model;
|
||||
const effectiveCwd = resolveThreadWorkspaceCwd({
|
||||
thread,
|
||||
projects: readModel.projects,
|
||||
});
|
||||
|
||||
const resolveResumeCursorForSession = (sessionId: ProviderSessionId) =>
|
||||
const resolveActiveSession = (sessionId: ProviderSessionId) =>
|
||||
providerService.listSessions().pipe(
|
||||
Effect.map((sessions) => sessions.find((session) => session.sessionId === sessionId)?.resumeCursor),
|
||||
Effect.map((sessions) => sessions.find((session) => session.sessionId === sessionId)),
|
||||
);
|
||||
|
||||
const startProviderSession = (input?: {
|
||||
@@ -209,7 +211,7 @@ const make = Effect.gen(function* () {
|
||||
? { provider: input?.provider ?? preferredProvider }
|
||||
: {}),
|
||||
...(effectiveCwd ? { cwd: effectiveCwd } : {}),
|
||||
...(thread.model ? { model: thread.model } : {}),
|
||||
...(desiredModel ? { model: desiredModel } : {}),
|
||||
...(input?.resumeCursor !== undefined ? { resumeCursor: input.resumeCursor } : {}),
|
||||
approvalPolicy: desiredApprovalPolicy,
|
||||
sandboxMode: desiredSandboxMode,
|
||||
@@ -242,14 +244,29 @@ const make = Effect.gen(function* () {
|
||||
const sandboxModeChanged =
|
||||
options?.sandboxMode !== undefined && options.sandboxMode !== thread.session?.sandboxMode;
|
||||
const providerChanged = options?.provider !== undefined && options.provider !== currentProvider;
|
||||
const activeSession = yield* resolveActiveSession(existingSessionId);
|
||||
const sessionModelSwitch =
|
||||
currentProvider === undefined
|
||||
? "in-session"
|
||||
: (yield* providerService.getCapabilities(currentProvider)).sessionModelSwitch;
|
||||
const modelChanged =
|
||||
options?.model !== undefined && options.model !== activeSession?.model;
|
||||
const shouldRestartForModelChange =
|
||||
modelChanged && sessionModelSwitch === "restart-session";
|
||||
|
||||
if (!approvalPolicyChanged && !sandboxModeChanged && !providerChanged) {
|
||||
if (
|
||||
!approvalPolicyChanged &&
|
||||
!sandboxModeChanged &&
|
||||
!providerChanged &&
|
||||
!shouldRestartForModelChange
|
||||
) {
|
||||
return existingSessionId;
|
||||
}
|
||||
|
||||
const resumeCursor = providerChanged
|
||||
? undefined
|
||||
: yield* resolveResumeCursorForSession(existingSessionId);
|
||||
const resumeCursor =
|
||||
providerChanged || shouldRestartForModelChange
|
||||
? undefined
|
||||
: (activeSession?.resumeCursor ?? undefined);
|
||||
const restartedSession = yield* startProviderSession({
|
||||
...(resumeCursor !== undefined ? { resumeCursor } : {}),
|
||||
...(options?.provider !== undefined ? { provider: options.provider } : {}),
|
||||
@@ -267,9 +284,9 @@ const make = Effect.gen(function* () {
|
||||
return restartedSession.sessionId;
|
||||
}
|
||||
|
||||
const startedSession = yield* startProviderSession({
|
||||
...(options?.provider !== undefined ? { provider: options.provider } : {}),
|
||||
});
|
||||
const startedSession = yield* startProviderSession(
|
||||
options?.provider !== undefined ? { provider: options.provider } : undefined,
|
||||
);
|
||||
yield* bindSessionToThread(startedSession);
|
||||
return startedSession.sessionId;
|
||||
});
|
||||
@@ -291,17 +308,27 @@ const make = Effect.gen(function* () {
|
||||
}
|
||||
const sessionId = yield* ensureSessionForThread(input.threadId, input.createdAt, {
|
||||
...(input.provider !== undefined ? { provider: input.provider } : {}),
|
||||
...(input.model !== undefined ? { model: input.model } : {}),
|
||||
approvalPolicy: input.approvalPolicy,
|
||||
sandboxMode: input.sandboxMode,
|
||||
});
|
||||
const normalizedInput = toNonEmptyProviderInput(input.messageText);
|
||||
const normalizedAttachments = input.attachments ?? [];
|
||||
const activeSession = yield* providerService.listSessions().pipe(
|
||||
Effect.map((sessions) => sessions.find((session) => session.sessionId === sessionId)),
|
||||
);
|
||||
const sessionModelSwitch =
|
||||
activeSession === undefined
|
||||
? "in-session"
|
||||
: (yield* providerService.getCapabilities(activeSession.provider)).sessionModelSwitch;
|
||||
const modelForTurn =
|
||||
sessionModelSwitch === "unsupported" ? activeSession?.model : input.model;
|
||||
|
||||
yield* providerService.sendTurn({
|
||||
sessionId,
|
||||
...(normalizedInput ? { input: normalizedInput } : {}),
|
||||
...(normalizedAttachments.length > 0 ? { attachments: normalizedAttachments } : {}),
|
||||
...(input.model !== undefined ? { model: input.model } : {}),
|
||||
...(modelForTurn !== undefined ? { model: modelForTurn } : {}),
|
||||
...(input.effort !== undefined ? { effort: input.effort } : {}),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,6 +50,7 @@ function createProviderServiceHarness() {
|
||||
respondToRequest: () => unsupported(),
|
||||
stopSession: () => unsupported(),
|
||||
listSessions: () => Effect.succeed([]),
|
||||
getCapabilities: () => Effect.succeed({ sessionModelSwitch: "in-session" }),
|
||||
rollbackConversation: () => unsupported(),
|
||||
stopAll: () => Effect.void,
|
||||
streamEvents: Stream.fromPubSub(runtimeEventPubSub),
|
||||
@@ -455,38 +456,48 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("maps message delta/completed into finalized assistant messages", async () => {
|
||||
it("maps canonical content delta/item completed into finalized assistant messages", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
|
||||
harness.emit({
|
||||
type: "message.delta",
|
||||
type: "content.delta",
|
||||
eventId: asEventId("evt-message-delta-1"),
|
||||
provider: "codex",
|
||||
sessionId: asSessionId("sess-1"),
|
||||
createdAt: now,
|
||||
turnId: asProviderTurnId("turn-2"),
|
||||
itemId: asItemId("item-1"),
|
||||
delta: "hello",
|
||||
payload: {
|
||||
streamKind: "assistant_text",
|
||||
delta: "hello",
|
||||
},
|
||||
});
|
||||
harness.emit({
|
||||
type: "message.delta",
|
||||
type: "content.delta",
|
||||
eventId: asEventId("evt-message-delta-2"),
|
||||
provider: "codex",
|
||||
sessionId: asSessionId("sess-1"),
|
||||
createdAt: now,
|
||||
turnId: asProviderTurnId("turn-2"),
|
||||
itemId: asItemId("item-1"),
|
||||
delta: " world",
|
||||
payload: {
|
||||
streamKind: "assistant_text",
|
||||
delta: " world",
|
||||
},
|
||||
});
|
||||
harness.emit({
|
||||
type: "message.completed",
|
||||
type: "item.completed",
|
||||
eventId: asEventId("evt-message-completed"),
|
||||
provider: "codex",
|
||||
sessionId: asSessionId("sess-1"),
|
||||
createdAt: now,
|
||||
turnId: asProviderTurnId("turn-2"),
|
||||
itemId: asItemId("item-1"),
|
||||
payload: {
|
||||
itemType: "assistant_message",
|
||||
status: "completed",
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
@@ -497,6 +508,33 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
expect(message?.streaming).toBe(false);
|
||||
});
|
||||
|
||||
it("uses assistant item completion detail when no assistant deltas were streamed", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
|
||||
harness.emit({
|
||||
type: "item.completed",
|
||||
eventId: asEventId("evt-assistant-item-completed-no-delta"),
|
||||
provider: "codex",
|
||||
sessionId: asSessionId("sess-1"),
|
||||
createdAt: now,
|
||||
turnId: asProviderTurnId("turn-no-delta"),
|
||||
itemId: asItemId("item-no-delta"),
|
||||
payload: {
|
||||
itemType: "assistant_message",
|
||||
status: "completed",
|
||||
detail: "assistant-only final text",
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
entry.messages.some((message) => message.id === "assistant:item-no-delta" && !message.streaming),
|
||||
);
|
||||
const message = thread.messages.find((entry) => entry.id === "assistant:item-no-delta");
|
||||
expect(message?.text).toBe("assistant-only final text");
|
||||
expect(message?.streaming).toBe(false);
|
||||
});
|
||||
|
||||
it("buffers assistant deltas by default until completion", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
|
||||
@@ -76,12 +76,81 @@ function truncateDetail(value: string, limit = 180): string {
|
||||
return value.length > limit ? `${value.slice(0, limit - 3)}...` : value;
|
||||
}
|
||||
|
||||
function asString(value: unknown): string | undefined {
|
||||
return typeof value === "string" ? value : undefined;
|
||||
}
|
||||
|
||||
function legacyRuntimeType(event: ProviderRuntimeEvent): string | undefined {
|
||||
return asString((event as Record<string, unknown>).type);
|
||||
}
|
||||
|
||||
function legacyRuntimeStringField(
|
||||
event: ProviderRuntimeEvent,
|
||||
key: string,
|
||||
): string | undefined {
|
||||
return asString((event as Record<string, unknown>)[key]);
|
||||
}
|
||||
|
||||
function runtimePayloadRecord(event: ProviderRuntimeEvent): Record<string, unknown> | undefined {
|
||||
const payload = (event as { payload?: unknown }).payload;
|
||||
if (!payload || typeof payload !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
return payload as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function normalizeRuntimeTurnState(
|
||||
value: string | undefined,
|
||||
): "completed" | "failed" | "interrupted" | "cancelled" {
|
||||
switch (value) {
|
||||
case "failed":
|
||||
case "interrupted":
|
||||
case "cancelled":
|
||||
case "completed":
|
||||
return value;
|
||||
default:
|
||||
return "completed";
|
||||
}
|
||||
}
|
||||
|
||||
function runtimeTurnState(
|
||||
event: ProviderRuntimeEvent,
|
||||
): "completed" | "failed" | "interrupted" | "cancelled" {
|
||||
const payloadState = asString(runtimePayloadRecord(event)?.state);
|
||||
const legacyStatus = legacyRuntimeStringField(event, "status");
|
||||
return normalizeRuntimeTurnState(payloadState ?? legacyStatus);
|
||||
}
|
||||
|
||||
function runtimeTurnErrorMessage(event: ProviderRuntimeEvent): string | undefined {
|
||||
const payloadErrorMessage = asString(runtimePayloadRecord(event)?.errorMessage);
|
||||
const legacyErrorMessage = legacyRuntimeStringField(event, "errorMessage");
|
||||
return payloadErrorMessage ?? legacyErrorMessage;
|
||||
}
|
||||
|
||||
function runtimeErrorMessageFromEvent(event: ProviderRuntimeEvent): string | undefined {
|
||||
const payloadMessage = asString(runtimePayloadRecord(event)?.message);
|
||||
const legacyMessage = legacyRuntimeStringField(event, "message");
|
||||
return payloadMessage ?? legacyMessage;
|
||||
}
|
||||
|
||||
function isToolLifecycleItemType(itemType: string): boolean {
|
||||
return (
|
||||
itemType === "command_execution" ||
|
||||
itemType === "file_change" ||
|
||||
itemType === "mcp_tool_call" ||
|
||||
itemType === "dynamic_tool_call" ||
|
||||
itemType === "collab_agent_tool_call" ||
|
||||
itemType === "web_search" ||
|
||||
itemType === "image_view"
|
||||
);
|
||||
}
|
||||
|
||||
function runtimeEventToActivities(
|
||||
event: ProviderRuntimeEvent,
|
||||
): ReadonlyArray<OrchestrationThreadActivity> {
|
||||
const maybeSequence = event.sessionSequence !== undefined ? { sequence: event.sessionSequence } : {};
|
||||
switch (event.type) {
|
||||
case "approval.requested": {
|
||||
case "request.opened": {
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
@@ -89,13 +158,15 @@ function runtimeEventToActivities(
|
||||
tone: "approval",
|
||||
kind: "approval.requested",
|
||||
summary:
|
||||
event.requestKind === "command"
|
||||
event.payload.requestType === "command_execution_approval"
|
||||
? "Command approval requested"
|
||||
: "File-change approval requested",
|
||||
: event.payload.requestType === "file_change_approval"
|
||||
? "File-change approval requested"
|
||||
: "Approval requested",
|
||||
payload: {
|
||||
requestId: event.requestId,
|
||||
requestKind: event.requestKind,
|
||||
...(event.detail ? { detail: truncateDetail(event.detail) } : {}),
|
||||
requestType: event.payload.requestType,
|
||||
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
|
||||
},
|
||||
turnId: toTurnId(event.turnId) ?? null,
|
||||
...maybeSequence,
|
||||
@@ -103,7 +174,7 @@ function runtimeEventToActivities(
|
||||
];
|
||||
}
|
||||
|
||||
case "approval.resolved": {
|
||||
case "request.resolved": {
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
@@ -113,8 +184,8 @@ function runtimeEventToActivities(
|
||||
summary: "Approval resolved",
|
||||
payload: {
|
||||
requestId: event.requestId,
|
||||
...(event.requestKind ? { requestKind: event.requestKind } : {}),
|
||||
...(event.decision ? { decision: event.decision } : {}),
|
||||
requestType: event.payload.requestType,
|
||||
...(event.payload.decision ? { decision: event.payload.decision } : {}),
|
||||
},
|
||||
turnId: toTurnId(event.turnId) ?? null,
|
||||
...maybeSequence,
|
||||
@@ -123,6 +194,10 @@ function runtimeEventToActivities(
|
||||
}
|
||||
|
||||
case "runtime.error": {
|
||||
const message = runtimeErrorMessageFromEvent(event);
|
||||
if (!message) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
@@ -131,7 +206,7 @@ function runtimeEventToActivities(
|
||||
kind: "runtime.error",
|
||||
summary: "Runtime error",
|
||||
payload: {
|
||||
message: truncateDetail(event.message),
|
||||
message: truncateDetail(message),
|
||||
},
|
||||
turnId: toTurnId(event.turnId) ?? null,
|
||||
...maybeSequence,
|
||||
@@ -139,17 +214,20 @@ function runtimeEventToActivities(
|
||||
];
|
||||
}
|
||||
|
||||
case "tool.completed": {
|
||||
case "item.completed": {
|
||||
if (!isToolLifecycleItemType(event.payload.itemType)) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
createdAt: event.createdAt,
|
||||
tone: "tool",
|
||||
kind: "tool.completed",
|
||||
summary: `${event.title} complete`,
|
||||
summary: `${event.payload.title ?? "Tool"} complete`,
|
||||
payload: {
|
||||
toolKind: event.toolKind,
|
||||
...(event.detail ? { detail: truncateDetail(event.detail) } : {}),
|
||||
itemType: event.payload.itemType,
|
||||
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
|
||||
},
|
||||
turnId: toTurnId(event.turnId) ?? null,
|
||||
...maybeSequence,
|
||||
@@ -157,17 +235,95 @@ function runtimeEventToActivities(
|
||||
];
|
||||
}
|
||||
|
||||
case "tool.started": {
|
||||
case "item.started": {
|
||||
if (!isToolLifecycleItemType(event.payload.itemType)) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
createdAt: event.createdAt,
|
||||
tone: "tool",
|
||||
kind: "tool.started",
|
||||
summary: `${event.title} started`,
|
||||
summary: `${event.payload.title ?? "Tool"} started`,
|
||||
payload: {
|
||||
toolKind: event.toolKind,
|
||||
...(event.detail ? { detail: truncateDetail(event.detail) } : {}),
|
||||
itemType: event.payload.itemType,
|
||||
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
|
||||
},
|
||||
turnId: toTurnId(event.turnId) ?? null,
|
||||
...maybeSequence,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Backward-compatibility for legacy event shapes still emitted by older tests/adapters.
|
||||
const legacyType = legacyRuntimeType(event);
|
||||
switch (legacyType) {
|
||||
case "approval.requested": {
|
||||
const detail = legacyRuntimeStringField(event, "detail");
|
||||
const requestKind = legacyRuntimeStringField(event, "requestKind");
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
createdAt: event.createdAt,
|
||||
tone: "approval",
|
||||
kind: "approval.requested",
|
||||
summary:
|
||||
requestKind === "command"
|
||||
? "Command approval requested"
|
||||
: "File-change approval requested",
|
||||
payload: {
|
||||
requestId: event.requestId,
|
||||
...(requestKind ? { requestKind } : {}),
|
||||
...(detail ? { detail: truncateDetail(detail) } : {}),
|
||||
},
|
||||
turnId: toTurnId(event.turnId) ?? null,
|
||||
...maybeSequence,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
case "approval.resolved": {
|
||||
const decision = legacyRuntimeStringField(event, "decision");
|
||||
const requestKind = legacyRuntimeStringField(event, "requestKind");
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
createdAt: event.createdAt,
|
||||
tone: "approval",
|
||||
kind: "approval.resolved",
|
||||
summary: "Approval resolved",
|
||||
payload: {
|
||||
requestId: event.requestId,
|
||||
...(requestKind ? { requestKind } : {}),
|
||||
...(decision ? { decision } : {}),
|
||||
},
|
||||
turnId: toTurnId(event.turnId) ?? null,
|
||||
...maybeSequence,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
case "tool.completed":
|
||||
case "tool.started": {
|
||||
const title = legacyRuntimeStringField(event, "title") ?? "Tool";
|
||||
const detail = legacyRuntimeStringField(event, "detail");
|
||||
const toolKind = legacyRuntimeStringField(event, "toolKind");
|
||||
const activityKind = legacyType;
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
createdAt: event.createdAt,
|
||||
tone: "tool",
|
||||
kind: activityKind,
|
||||
summary: `${title} ${legacyType === "tool.started" ? "started" : "complete"}`,
|
||||
payload: {
|
||||
...(toolKind ? { toolKind } : {}),
|
||||
...(detail ? { detail: truncateDetail(detail) } : {}),
|
||||
},
|
||||
turnId: toTurnId(event.turnId) ?? null,
|
||||
...maybeSequence,
|
||||
@@ -296,9 +452,12 @@ const make = Effect.gen(function* () {
|
||||
createdAt: string;
|
||||
commandTag: string;
|
||||
finalDeltaCommandTag: string;
|
||||
fallbackText?: string;
|
||||
}) =>
|
||||
Effect.gen(function* () {
|
||||
const text = yield* takeBufferedAssistantText(input.messageId);
|
||||
const bufferedText = yield* takeBufferedAssistantText(input.messageId);
|
||||
const text =
|
||||
bufferedText.length > 0 ? bufferedText : (input.fallbackText?.trim().length ?? 0) > 0 ? input.fallbackText! : "";
|
||||
|
||||
if (text.length > 0) {
|
||||
yield* orchestrationEngine.dispatch({
|
||||
@@ -356,6 +515,7 @@ const make = Effect.gen(function* () {
|
||||
);
|
||||
if (!thread) return;
|
||||
|
||||
const legacyType = legacyRuntimeType(event);
|
||||
const now = event.createdAt;
|
||||
const sessionProviderThreadId = thread.session?.providerThreadId ?? null;
|
||||
const scopedSessionProviderThreadId = isSyntheticClaudeThreadId(
|
||||
@@ -365,7 +525,7 @@ const make = Effect.gen(function* () {
|
||||
? null
|
||||
: sessionProviderThreadId;
|
||||
const eventProviderThreadId = toProviderThreadId(event.threadId);
|
||||
const eventTurnId = toTurnId("turnId" in event ? event.turnId : undefined);
|
||||
const eventTurnId = toTurnId(event.turnId);
|
||||
const activeTurnId = thread.session?.activeTurnId ?? null;
|
||||
|
||||
const matchesThreadScope =
|
||||
@@ -448,7 +608,7 @@ const make = Effect.gen(function* () {
|
||||
case "session.exited":
|
||||
return "stopped";
|
||||
case "turn.completed":
|
||||
return event.status === "failed" ? "error" : "ready";
|
||||
return runtimeTurnState(event) === "failed" ? "error" : "ready";
|
||||
case "session.started":
|
||||
case "thread.started":
|
||||
// Provider thread/session start notifications can arrive during an
|
||||
@@ -457,8 +617,8 @@ const make = Effect.gen(function* () {
|
||||
}
|
||||
})();
|
||||
const lastError =
|
||||
event.type === "turn.completed" && event.status === "failed"
|
||||
? (event.errorMessage ?? thread.session?.lastError ?? "Turn failed")
|
||||
event.type === "turn.completed" && runtimeTurnState(event) === "failed"
|
||||
? (runtimeTurnErrorMessage(event) ?? thread.session?.lastError ?? "Turn failed")
|
||||
: status === "ready"
|
||||
? null
|
||||
: (thread.session?.lastError ?? null);
|
||||
@@ -485,7 +645,14 @@ const make = Effect.gen(function* () {
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type === "message.delta" && event.delta.length > 0) {
|
||||
const assistantDelta =
|
||||
event.type === "content.delta" && event.payload.streamKind === "assistant_text"
|
||||
? event.payload.delta
|
||||
: legacyType === "message.delta"
|
||||
? legacyRuntimeStringField(event, "delta")
|
||||
: undefined;
|
||||
|
||||
if (assistantDelta && assistantDelta.length > 0) {
|
||||
const assistantMessageId = MessageId.makeUnsafe(
|
||||
`assistant:${event.itemId ?? event.turnId ?? event.sessionId}`,
|
||||
);
|
||||
@@ -496,7 +663,7 @@ const make = Effect.gen(function* () {
|
||||
|
||||
const assistantDeliveryMode = yield* Ref.get(assistantDeliveryModeRef);
|
||||
if (assistantDeliveryMode === "buffered") {
|
||||
const spillChunk = yield* appendBufferedAssistantText(assistantMessageId, event.delta);
|
||||
const spillChunk = yield* appendBufferedAssistantText(assistantMessageId, assistantDelta);
|
||||
if (spillChunk.length > 0) {
|
||||
yield* orchestrationEngine.dispatch({
|
||||
type: "thread.message.assistant.delta",
|
||||
@@ -514,15 +681,28 @@ const make = Effect.gen(function* () {
|
||||
commandId: providerCommandId(event, "assistant-delta"),
|
||||
threadId: thread.id,
|
||||
messageId: assistantMessageId,
|
||||
delta: event.delta,
|
||||
delta: assistantDelta,
|
||||
...(turnId ? { turnId } : {}),
|
||||
createdAt: now,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type === "message.completed") {
|
||||
const assistantMessageId = MessageId.makeUnsafe(`assistant:${event.itemId}`);
|
||||
const assistantCompletion =
|
||||
event.type === "item.completed" && event.payload.itemType === "assistant_message"
|
||||
? {
|
||||
messageId: MessageId.makeUnsafe(`assistant:${event.itemId ?? event.turnId ?? event.sessionId}`),
|
||||
fallbackText: event.payload.detail,
|
||||
}
|
||||
: legacyType === "message.completed"
|
||||
? {
|
||||
messageId: MessageId.makeUnsafe(`assistant:${event.itemId ?? event.turnId ?? event.sessionId}`),
|
||||
fallbackText: undefined,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
if (assistantCompletion) {
|
||||
const assistantMessageId = assistantCompletion.messageId;
|
||||
const turnId = toTurnId(event.turnId);
|
||||
if (turnId) {
|
||||
yield* rememberAssistantMessageId(event.sessionId, turnId, assistantMessageId);
|
||||
@@ -536,6 +716,7 @@ const make = Effect.gen(function* () {
|
||||
createdAt: now,
|
||||
commandTag: "assistant-complete",
|
||||
finalDeltaCommandTag: "assistant-delta-finalize",
|
||||
fallbackText: assistantCompletion.fallbackText,
|
||||
});
|
||||
|
||||
if (turnId) {
|
||||
@@ -570,6 +751,8 @@ const make = Effect.gen(function* () {
|
||||
}
|
||||
|
||||
if (event.type === "runtime.error") {
|
||||
const runtimeErrorMessage = runtimeErrorMessageFromEvent(event) ?? "Provider runtime error";
|
||||
|
||||
const shouldApplyRuntimeError = !STRICT_PROVIDER_LIFECYCLE_GUARD
|
||||
? true
|
||||
: matchesThreadScope &&
|
||||
@@ -596,7 +779,7 @@ const make = Effect.gen(function* () {
|
||||
approvalPolicy: thread.session?.approvalPolicy ?? DEFAULT_APPROVAL_POLICY,
|
||||
sandboxMode: thread.session?.sandboxMode ?? DEFAULT_SANDBOX_MODE,
|
||||
activeTurnId: eventTurnId ?? null,
|
||||
lastError: event.message,
|
||||
lastError: runtimeErrorMessage,
|
||||
updatedAt: now,
|
||||
},
|
||||
createdAt: now,
|
||||
|
||||
@@ -1845,6 +1845,9 @@ function makeClaudeCodeAdapter(options?: ClaudeCodeAdapterLiveOptions) {
|
||||
|
||||
return {
|
||||
provider: PROVIDER,
|
||||
capabilities: {
|
||||
sessionModelSwitch: "in-session",
|
||||
},
|
||||
startSession,
|
||||
sendTurn,
|
||||
interruptTurn,
|
||||
|
||||
@@ -1092,6 +1092,9 @@ const makeCodexAdapter = (options?: CodexAdapterLiveOptions) =>
|
||||
|
||||
return {
|
||||
provider: PROVIDER,
|
||||
capabilities: {
|
||||
sessionModelSwitch: "in-session",
|
||||
},
|
||||
startSession,
|
||||
sendTurn,
|
||||
interruptTurn,
|
||||
|
||||
@@ -14,6 +14,7 @@ class FakeCursorAcpProcess extends EventEmitter {
|
||||
readonly stdin = new PassThrough();
|
||||
readonly stdout = new PassThrough();
|
||||
readonly stderr = new PassThrough();
|
||||
readonly requests: Array<{ method: string; params: unknown }> = [];
|
||||
killed = false;
|
||||
|
||||
private readonly input = readline.createInterface({ input: this.stdin });
|
||||
@@ -75,9 +76,29 @@ class FakeCursorAcpProcess extends EventEmitter {
|
||||
if (typeof method !== "string" || (typeof id !== "string" && typeof id !== "number")) {
|
||||
return;
|
||||
}
|
||||
this.requests.push({ method, params: message.params });
|
||||
|
||||
switch (method) {
|
||||
case "initialize":
|
||||
case "initialize": {
|
||||
const protocolVersion = (message.params as { protocolVersion?: unknown } | undefined)
|
||||
?.protocolVersion;
|
||||
if (typeof protocolVersion !== "number") {
|
||||
this.emitServerMessage({
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
error: {
|
||||
code: -32602,
|
||||
message: "Invalid params",
|
||||
data: {
|
||||
_errors: [],
|
||||
protocolVersion: {
|
||||
_errors: ["Invalid input: expected number, received undefined"],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.emitServerMessage({
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
@@ -90,6 +111,7 @@ class FakeCursorAcpProcess extends EventEmitter {
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
case "authenticate":
|
||||
this.emitServerMessage({
|
||||
jsonrpc: "2.0",
|
||||
@@ -117,6 +139,13 @@ class FakeCursorAcpProcess extends EventEmitter {
|
||||
result: {},
|
||||
});
|
||||
return;
|
||||
case "session/set_model":
|
||||
this.emitServerMessage({
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
result: {},
|
||||
});
|
||||
return;
|
||||
case "session/prompt": {
|
||||
this.emitServerMessage({
|
||||
jsonrpc: "2.0",
|
||||
@@ -252,7 +281,7 @@ describe("CursorAdapterLive", () => {
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* CursorAdapter;
|
||||
|
||||
const eventsFiber = yield* Stream.take(adapter.streamEvents, 11).pipe(
|
||||
const eventsFiber = yield* Stream.take(adapter.streamEvents, 13).pipe(
|
||||
Stream.runCollect,
|
||||
Effect.forkChild,
|
||||
);
|
||||
@@ -273,6 +302,8 @@ describe("CursorAdapterLive", () => {
|
||||
events.map((event) => event.type),
|
||||
[
|
||||
"session.configured",
|
||||
"auth.status",
|
||||
"auth.status",
|
||||
"session.started",
|
||||
"thread.started",
|
||||
"session.state.changed",
|
||||
@@ -286,13 +317,13 @@ describe("CursorAdapterLive", () => {
|
||||
],
|
||||
);
|
||||
|
||||
const turnStarted = events[4];
|
||||
const turnStarted = events[6];
|
||||
assert.equal(turnStarted?.type, "turn.started");
|
||||
if (turnStarted?.type === "turn.started") {
|
||||
assert.equal(turnStarted.turnId, turn.turnId);
|
||||
}
|
||||
|
||||
const completion = events[10];
|
||||
const completion = events[12];
|
||||
assert.equal(completion?.type, "turn.completed");
|
||||
if (completion?.type === "turn.completed") {
|
||||
assert.equal(completion.payload.state, "completed");
|
||||
@@ -300,6 +331,34 @@ describe("CursorAdapterLive", () => {
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
|
||||
it.effect("passes requested model to ACP process startup", () => {
|
||||
const fake = new FakeCursorAcpProcess();
|
||||
let createProcessInput:
|
||||
| {
|
||||
readonly binaryPath: string;
|
||||
readonly cwd: string;
|
||||
readonly env: NodeJS.ProcessEnv;
|
||||
readonly model?: string;
|
||||
}
|
||||
| undefined;
|
||||
const layer = makeCursorAdapterLive({
|
||||
createProcess: (input) => {
|
||||
createProcessInput = input;
|
||||
return fake as never;
|
||||
},
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* CursorAdapter;
|
||||
yield* adapter.startSession({
|
||||
provider: "cursor",
|
||||
model: "composer-1.5",
|
||||
});
|
||||
|
||||
assert.deepEqual(createProcessInput?.model, "composer-1.5");
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
|
||||
it.effect("bridges permission requests to request.opened/request.resolved", () => {
|
||||
const fake = new FakeCursorAcpProcess();
|
||||
const layer = makeCursorAdapterLive({
|
||||
@@ -314,7 +373,7 @@ describe("CursorAdapterLive", () => {
|
||||
});
|
||||
|
||||
// consume startup events
|
||||
yield* Stream.take(adapter.streamEvents, 4).pipe(Stream.runDrain);
|
||||
yield* Stream.take(adapter.streamEvents, 6).pipe(Stream.runDrain);
|
||||
|
||||
fake.emitPermissionRequest();
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ import { makeEventNdjsonLogger } from "./EventNdjsonLogger.ts";
|
||||
|
||||
const PROVIDER = "cursor" as const;
|
||||
const DEFAULT_REQUEST_TIMEOUT_MS = 120_000;
|
||||
const CURSOR_ACP_PROTOCOL_VERSION = 1;
|
||||
|
||||
interface CursorResumeState {
|
||||
readonly acpSessionId?: string;
|
||||
@@ -91,6 +92,7 @@ export interface CursorAdapterLiveOptions {
|
||||
readonly binaryPath: string;
|
||||
readonly cwd: string;
|
||||
readonly env: NodeJS.ProcessEnv;
|
||||
readonly model?: string;
|
||||
}) => ChildProcessWithoutNullStreams;
|
||||
readonly nativeEventLogPath?: string;
|
||||
}
|
||||
@@ -272,11 +274,13 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
|
||||
readonly binaryPath: string;
|
||||
readonly cwd: string;
|
||||
readonly env: NodeJS.ProcessEnv;
|
||||
readonly model?: string;
|
||||
}): ChildProcessWithoutNullStreams => {
|
||||
if (options?.createProcess) {
|
||||
return options.createProcess(input);
|
||||
}
|
||||
return spawn(input.binaryPath, ["acp"], {
|
||||
const args = input.model ? ["--model", input.model, "acp"] : ["acp"];
|
||||
return spawn(input.binaryPath, args, {
|
||||
cwd: input.cwd,
|
||||
env: input.env,
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
@@ -862,6 +866,7 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
|
||||
binaryPath,
|
||||
cwd,
|
||||
env: process.env,
|
||||
...(input.model ? { model: input.model } : {}),
|
||||
}),
|
||||
catch: (cause) =>
|
||||
new ProviderAdapterProcessError({
|
||||
@@ -972,7 +977,10 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
|
||||
sessions.set(sessionId, context);
|
||||
|
||||
const initializeResult = yield* Effect.tryPromise({
|
||||
try: async () => sendRequest(context, "initialize", {}),
|
||||
try: async () =>
|
||||
sendRequest(context, "initialize", {
|
||||
protocolVersion: CURSOR_ACP_PROTOCOL_VERSION,
|
||||
}),
|
||||
catch: (cause) => toRequestError(sessionId, "initialize", cause),
|
||||
});
|
||||
const decodedInitialize = Schema.decodeUnknownSync(CursorAcpInitializeResult)(initializeResult);
|
||||
@@ -997,11 +1005,75 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
|
||||
},
|
||||
});
|
||||
|
||||
yield* Effect.tryPromise({
|
||||
try: async () => sendRequest(context, "authenticate", { methodId: "cursor_login" }),
|
||||
catch: () => undefined,
|
||||
const authenticateRequest = { methodId: "cursor_login" };
|
||||
const authStartStamp = yield* makeEventStamp();
|
||||
yield* offerRuntimeEvent({
|
||||
type: "auth.status",
|
||||
eventId: authStartStamp.eventId,
|
||||
provider: PROVIDER,
|
||||
sessionId,
|
||||
createdAt: authStartStamp.createdAt,
|
||||
payload: {
|
||||
isAuthenticating: true,
|
||||
},
|
||||
providerRefs: {
|
||||
providerSessionId: sessionId,
|
||||
},
|
||||
raw: {
|
||||
source: "cursor.acp.request",
|
||||
method: "authenticate",
|
||||
payload: authenticateRequest,
|
||||
},
|
||||
});
|
||||
|
||||
const authenticateResult = yield* Effect.tryPromise({
|
||||
try: async () => sendRequest(context, "authenticate", authenticateRequest),
|
||||
catch: (cause) => cause,
|
||||
});
|
||||
const authEndStamp = yield* makeEventStamp();
|
||||
if (authenticateResult instanceof Error) {
|
||||
yield* offerRuntimeEvent({
|
||||
type: "auth.status",
|
||||
eventId: authEndStamp.eventId,
|
||||
provider: PROVIDER,
|
||||
sessionId,
|
||||
createdAt: authEndStamp.createdAt,
|
||||
payload: {
|
||||
isAuthenticating: false,
|
||||
error: toMessage(authenticateResult, "Cursor authentication failed."),
|
||||
},
|
||||
providerRefs: {
|
||||
providerSessionId: sessionId,
|
||||
},
|
||||
raw: {
|
||||
source: "cursor.acp.response",
|
||||
method: "authenticate",
|
||||
payload: {
|
||||
error: toMessage(authenticateResult, "Cursor authentication failed."),
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
yield* offerRuntimeEvent({
|
||||
type: "auth.status",
|
||||
eventId: authEndStamp.eventId,
|
||||
provider: PROVIDER,
|
||||
sessionId,
|
||||
createdAt: authEndStamp.createdAt,
|
||||
payload: {
|
||||
isAuthenticating: false,
|
||||
},
|
||||
providerRefs: {
|
||||
providerSessionId: sessionId,
|
||||
},
|
||||
raw: {
|
||||
source: "cursor.acp.response",
|
||||
method: "authenticate",
|
||||
payload: authenticateResult,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const acpSessionId = yield* Effect.tryPromise({
|
||||
try: async () => {
|
||||
if (resumeState?.acpSessionId) {
|
||||
@@ -1356,6 +1428,9 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
|
||||
|
||||
return {
|
||||
provider: PROVIDER,
|
||||
capabilities: {
|
||||
sessionModelSwitch: "unsupported",
|
||||
},
|
||||
startSession,
|
||||
sendTurn,
|
||||
interruptTurn,
|
||||
|
||||
@@ -14,6 +14,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
|
||||
const fakeCodexAdapter: CodexAdapterShape = {
|
||||
provider: "codex",
|
||||
capabilities: { sessionModelSwitch: "in-session" },
|
||||
startSession: vi.fn(),
|
||||
sendTurn: vi.fn(),
|
||||
interruptTurn: vi.fn(),
|
||||
@@ -29,6 +30,7 @@ const fakeCodexAdapter: CodexAdapterShape = {
|
||||
|
||||
const fakeClaudeAdapter: ClaudeCodeAdapterShape = {
|
||||
provider: "claudeCode",
|
||||
capabilities: { sessionModelSwitch: "in-session" },
|
||||
startSession: vi.fn(),
|
||||
sendTurn: vi.fn(),
|
||||
interruptTurn: vi.fn(),
|
||||
@@ -44,6 +46,7 @@ const fakeClaudeAdapter: ClaudeCodeAdapterShape = {
|
||||
|
||||
const fakeCursorAdapter: CursorAdapterShape = {
|
||||
provider: "cursor",
|
||||
capabilities: { sessionModelSwitch: "unsupported" },
|
||||
startSession: vi.fn(),
|
||||
sendTurn: vi.fn(),
|
||||
interruptTurn: vi.fn(),
|
||||
|
||||
@@ -161,6 +161,9 @@ function makeFakeCodexAdapter(provider: ProviderKind = "codex") {
|
||||
|
||||
const adapter: ProviderAdapterShape<ProviderAdapterError> = {
|
||||
provider,
|
||||
capabilities: {
|
||||
sessionModelSwitch: "in-session",
|
||||
},
|
||||
startSession,
|
||||
sendTurn,
|
||||
interruptTurn,
|
||||
|
||||
@@ -566,6 +566,9 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
|
||||
Effect.map((sessionsByProvider) => sessionsByProvider.flatMap((sessions) => sessions)),
|
||||
);
|
||||
|
||||
const getCapabilities: ProviderServiceShape["getCapabilities"] = (provider) =>
|
||||
registry.getByProvider(provider).pipe(Effect.map((adapter) => adapter.capabilities));
|
||||
|
||||
const rollbackConversation: ProviderServiceShape["rollbackConversation"] = (rawInput) =>
|
||||
Effect.gen(function* () {
|
||||
const input = yield* decodeInputOrValidationError({
|
||||
@@ -617,6 +620,7 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
|
||||
respondToRequest,
|
||||
stopSession,
|
||||
listSessions,
|
||||
getCapabilities,
|
||||
rollbackConversation,
|
||||
stopAll,
|
||||
streamEvents: Stream.fromPubSub(runtimeEventPubSub),
|
||||
|
||||
@@ -23,6 +23,15 @@ import type {
|
||||
import type { Effect } from "effect";
|
||||
import type { Stream } from "effect";
|
||||
|
||||
export type ProviderSessionModelSwitchMode = "in-session" | "restart-session" | "unsupported";
|
||||
|
||||
export interface ProviderAdapterCapabilities {
|
||||
/**
|
||||
* Declares whether changing the model on an existing session is supported.
|
||||
*/
|
||||
readonly sessionModelSwitch: ProviderSessionModelSwitchMode;
|
||||
}
|
||||
|
||||
export interface ProviderThreadTurnSnapshot {
|
||||
readonly id: ProviderTurnId;
|
||||
readonly items: ReadonlyArray<unknown>;
|
||||
@@ -38,6 +47,7 @@ export interface ProviderAdapterShape<TError> {
|
||||
* Provider kind implemented by this adapter.
|
||||
*/
|
||||
readonly provider: ProviderKind;
|
||||
readonly capabilities: ProviderAdapterCapabilities;
|
||||
|
||||
/**
|
||||
* Start a provider-backed session.
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
import type {
|
||||
ProviderInterruptTurnInput,
|
||||
ProviderKind,
|
||||
ProviderRespondToRequestInput,
|
||||
ProviderRuntimeEvent,
|
||||
ProviderSendTurnInput,
|
||||
@@ -27,6 +28,7 @@ import { ServiceMap } from "effect";
|
||||
import type { Effect, Stream } from "effect";
|
||||
|
||||
import type { ProviderServiceError } from "../Errors.ts";
|
||||
import type { ProviderAdapterCapabilities } from "./ProviderAdapter.ts";
|
||||
|
||||
/**
|
||||
* ProviderServiceShape - Service API for provider session and turn orchestration.
|
||||
@@ -75,6 +77,13 @@ export interface ProviderServiceShape {
|
||||
*/
|
||||
readonly listSessions: () => Effect.Effect<ReadonlyArray<ProviderSession>>;
|
||||
|
||||
/**
|
||||
* Read static capabilities for a provider adapter.
|
||||
*/
|
||||
readonly getCapabilities: (
|
||||
provider: ProviderKind,
|
||||
) => Effect.Effect<ProviderAdapterCapabilities, ProviderServiceError>;
|
||||
|
||||
/**
|
||||
* Roll back provider conversation state by a number of turns.
|
||||
*/
|
||||
|
||||
@@ -1170,6 +1170,7 @@ describe("WebSocket Server", () => {
|
||||
respondToRequest: () => unsupported(),
|
||||
stopSession: () => unsupported(),
|
||||
listSessions: () => Effect.succeed([]),
|
||||
getCapabilities: () => Effect.succeed({ sessionModelSwitch: "in-session" }),
|
||||
rollbackConversation: () => unsupported(),
|
||||
stopAll: () => Effect.void,
|
||||
streamEvents: Stream.fromPubSub(runtimeEventPubSub),
|
||||
|
||||
@@ -137,7 +137,16 @@ import {
|
||||
MenuShortcut,
|
||||
MenuTrigger,
|
||||
} from "./ui/menu";
|
||||
import { ClaudeAI, CursorIcon, Gemini, Icon, OpenAI, OpenCodeIcon } from "./Icons";
|
||||
import {
|
||||
ClaudeAI,
|
||||
CursorIcon,
|
||||
Gemini,
|
||||
Icon,
|
||||
OpenAI,
|
||||
OpenCodeIcon,
|
||||
VisualStudioCode,
|
||||
Zed,
|
||||
} from "./Icons";
|
||||
import { cn, isMacPlatform, isWindowsPlatform } from "~/lib/utils";
|
||||
import { Badge } from "./ui/badge";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
|
||||
@@ -670,10 +679,21 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
]);
|
||||
|
||||
const sessionProvider = activeThread?.session?.provider ?? null;
|
||||
const selectedProvider: ProviderKind =
|
||||
(activeThread?.id ? selectedProviderByThread[activeThread.id] : undefined) ??
|
||||
sessionProvider ??
|
||||
"codex";
|
||||
const selectedProviderByThreadId = activeThread?.id
|
||||
? selectedProviderByThread[activeThread.id]
|
||||
: undefined;
|
||||
const hasThreadStarted = Boolean(
|
||||
activeThread &&
|
||||
(activeThread.latestTurn !== null || activeThread.messages.length > 0 || activeThread.session !== null),
|
||||
);
|
||||
const lockedProvider: ProviderKind | null = hasThreadStarted
|
||||
? (sessionProvider ?? selectedProviderByThreadId ?? null)
|
||||
: null;
|
||||
const selectedProvider: ProviderKind = lockedProvider ?? selectedProviderByThreadId ?? "codex";
|
||||
const cursorModelSelectionLockedReason =
|
||||
hasThreadStarted && selectedProvider === "cursor"
|
||||
? "Cursor currently does not support changing models after the first message in a thread."
|
||||
: null;
|
||||
const baseThreadModel = resolveModelSlugForProvider(
|
||||
selectedProvider,
|
||||
(activeThread?.id ? selectedModelByThread[activeThread.id] : undefined) ??
|
||||
@@ -705,7 +725,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
selectedProvider === "cursor" && selectedCursorModel ? selectedCursorModel.family : selectedModel;
|
||||
const searchableModelOptions = useMemo(
|
||||
() =>
|
||||
PROVIDER_OPTIONS.filter((option) => option.available).flatMap((option) =>
|
||||
PROVIDER_OPTIONS.filter(
|
||||
(option) =>
|
||||
option.available && (lockedProvider === null || option.value === lockedProvider),
|
||||
).flatMap((option) =>
|
||||
getProviderModelPickerOptions(option.value).map(({ slug, name }) => ({
|
||||
provider: option.value,
|
||||
providerLabel: option.label,
|
||||
@@ -716,12 +739,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
searchProvider: option.label.toLowerCase(),
|
||||
})),
|
||||
),
|
||||
[],
|
||||
[lockedProvider],
|
||||
);
|
||||
useEffect(() => {
|
||||
if (!activeThread?.id || !sessionProvider) return;
|
||||
setSelectedProviderByThread((existing) => {
|
||||
if (existing[activeThread.id]) return existing;
|
||||
if (existing[activeThread.id] === sessionProvider) return existing;
|
||||
return { ...existing, [activeThread.id]: sessionProvider };
|
||||
});
|
||||
}, [activeThread?.id, sessionProvider]);
|
||||
@@ -2311,8 +2334,16 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
|
||||
const onProviderModelSelect = useCallback(
|
||||
(provider: ProviderKind, model: ModelSlug) => {
|
||||
const api = readNativeApi();
|
||||
if (!activeThread) return;
|
||||
if (cursorModelSelectionLockedReason !== null && provider === "cursor") {
|
||||
scheduleComposerFocus();
|
||||
return;
|
||||
}
|
||||
if (lockedProvider !== null && provider !== lockedProvider) {
|
||||
scheduleComposerFocus();
|
||||
return;
|
||||
}
|
||||
const api = readNativeApi();
|
||||
const resolvedModel =
|
||||
provider === "cursor"
|
||||
? resolveCursorModelFromSelection(parseCursorModelSelection(model))
|
||||
@@ -2325,7 +2356,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
...existing,
|
||||
[activeThread.id]: resolvedModel,
|
||||
}));
|
||||
if (api) {
|
||||
if (api && isServerThread) {
|
||||
void api.orchestration.dispatchCommand({
|
||||
type: "thread.meta.update",
|
||||
commandId: newCommandId(),
|
||||
@@ -2335,7 +2366,13 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
}
|
||||
scheduleComposerFocus();
|
||||
},
|
||||
[activeThread, scheduleComposerFocus],
|
||||
[
|
||||
activeThread,
|
||||
cursorModelSelectionLockedReason,
|
||||
isServerThread,
|
||||
lockedProvider,
|
||||
scheduleComposerFocus,
|
||||
],
|
||||
);
|
||||
const onCursorReasoningSelect = useCallback(
|
||||
(reasoning: CursorReasoningOption) => {
|
||||
@@ -2816,11 +2853,33 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 px-2.5 pb-2.5 sm:flex-nowrap sm:gap-0 sm:px-3 sm:pb-3">
|
||||
<div className="flex min-w-0 flex-1 items-center gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden sm:min-w-max sm:overflow-visible">
|
||||
{/* Provider/model picker */}
|
||||
<ProviderModelPicker
|
||||
provider={selectedProvider}
|
||||
model={selectedModelForPicker}
|
||||
onProviderModelChange={onProviderModelSelect}
|
||||
/>
|
||||
{cursorModelSelectionLockedReason ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<span className="inline-flex">
|
||||
<ProviderModelPicker
|
||||
provider={selectedProvider}
|
||||
model={selectedModelForPicker}
|
||||
lockedProvider={lockedProvider}
|
||||
disabled
|
||||
onProviderModelChange={onProviderModelSelect}
|
||||
/>
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<TooltipPopup side="top" className="max-w-72 whitespace-normal leading-tight">
|
||||
{cursorModelSelectionLockedReason}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<ProviderModelPicker
|
||||
provider={selectedProvider}
|
||||
model={selectedModelForPicker}
|
||||
lockedProvider={lockedProvider}
|
||||
onProviderModelChange={onProviderModelSelect}
|
||||
/>
|
||||
)}
|
||||
|
||||
{selectedProvider === "cursor" ? (
|
||||
<>
|
||||
@@ -4048,6 +4107,8 @@ function resolveModelForProviderPicker(
|
||||
const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
provider: ProviderKind;
|
||||
model: ModelSlug;
|
||||
lockedProvider: ProviderKind | null;
|
||||
disabled?: boolean;
|
||||
onProviderModelChange: (provider: ProviderKind, model: ModelSlug) => void;
|
||||
}) {
|
||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||
@@ -4057,9 +4118,25 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
const ProviderIcon = PROVIDER_ICON_BY_PROVIDER[props.provider];
|
||||
|
||||
return (
|
||||
<Menu open={isMenuOpen} onOpenChange={setIsMenuOpen}>
|
||||
<Menu
|
||||
open={isMenuOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (props.disabled) {
|
||||
setIsMenuOpen(false);
|
||||
return;
|
||||
}
|
||||
setIsMenuOpen(open);
|
||||
}}
|
||||
>
|
||||
<MenuTrigger
|
||||
render={<Button size="sm" variant="ghost" className="shrink-0 whitespace-nowrap px-2 sm:px-3" />}
|
||||
render={
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="shrink-0 whitespace-nowrap px-2 sm:px-3"
|
||||
disabled={props.disabled}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<ProviderIcon
|
||||
@@ -4076,9 +4153,11 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
<MenuPopup align="start">
|
||||
{AVAILABLE_PROVIDER_OPTIONS.map((option) => {
|
||||
const OptionIcon = PROVIDER_ICON_BY_PROVIDER[option.value];
|
||||
const isDisabledByProviderLock =
|
||||
props.lockedProvider !== null && props.lockedProvider !== option.value;
|
||||
return (
|
||||
<MenuSub key={option.value}>
|
||||
<MenuSubTrigger>
|
||||
<MenuSubTrigger disabled={isDisabledByProviderLock}>
|
||||
<OptionIcon aria-hidden="true" className="size-4 shrink-0 text-muted-foreground/85" />
|
||||
{option.label}
|
||||
</MenuSubTrigger>
|
||||
@@ -4087,6 +4166,8 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
<MenuRadioGroup
|
||||
value={props.provider === option.value ? props.model : ""}
|
||||
onValueChange={(value) => {
|
||||
if (props.disabled) return;
|
||||
if (isDisabledByProviderLock) return;
|
||||
if (!value) return;
|
||||
const resolvedModel = resolveModelForProviderPicker(option.value, value);
|
||||
if (!resolvedModel) return;
|
||||
|
||||
@@ -20,6 +20,129 @@ export const CursorIcon: Icon = (props) => (
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const VisualStudioCode: Icon = (props) => {
|
||||
const id = useId();
|
||||
const maskId = `${id}-vscode-a`;
|
||||
const topShadowFilterId = `${id}-vscode-b`;
|
||||
const sideShadowFilterId = `${id}-vscode-c`;
|
||||
const overlayGradientId = `${id}-vscode-d`;
|
||||
|
||||
return (
|
||||
<svg {...props} fill="none" viewBox="0 0 100 100">
|
||||
<mask id={maskId} width="100" height="100" x="0" y="0" maskUnits="userSpaceOnUse">
|
||||
<path
|
||||
fill="#fff"
|
||||
fillRule="evenodd"
|
||||
d="M70.912 99.317a6.223 6.223 0 0 0 4.96-.19l20.589-9.907A6.25 6.25 0 0 0 100 83.587V16.413a6.25 6.25 0 0 0-3.54-5.632L75.874.874a6.226 6.226 0 0 0-7.104 1.21L29.355 38.04 12.187 25.01a4.162 4.162 0 0 0-5.318.236l-5.506 5.009a4.168 4.168 0 0 0-.004 6.162L16.247 50 1.36 63.583a4.168 4.168 0 0 0 .004 6.162l5.506 5.01a4.162 4.162 0 0 0 5.318.236l17.168-13.032L68.77 97.917a6.217 6.217 0 0 0 2.143 1.4ZM75.015 27.3 45.11 50l29.906 22.701V27.3Z"
|
||||
clipRule="evenodd"
|
||||
/>
|
||||
</mask>
|
||||
<g mask={`url(#${maskId})`}>
|
||||
<path
|
||||
fill="#0065A9"
|
||||
d="M96.461 10.796 75.857.876a6.23 6.23 0 0 0-7.107 1.207l-67.451 61.5a4.167 4.167 0 0 0 .004 6.162l5.51 5.009a4.167 4.167 0 0 0 5.32.236l81.228-61.62c2.725-2.067 6.639-.124 6.639 3.297v-.24a6.25 6.25 0 0 0-3.539-5.63Z"
|
||||
/>
|
||||
<g filter={`url(#${topShadowFilterId})`}>
|
||||
<path
|
||||
fill="#007ACC"
|
||||
d="m96.461 89.204-20.604 9.92a6.229 6.229 0 0 1-7.107-1.207l-67.451-61.5a4.167 4.167 0 0 1 .004-6.162l5.51-5.009a4.167 4.167 0 0 1 5.32-.236l81.228 61.62c2.725 2.067 6.639.124 6.639-3.297v.24a6.25 6.25 0 0 1-3.539 5.63Z"
|
||||
/>
|
||||
</g>
|
||||
<g filter={`url(#${sideShadowFilterId})`}>
|
||||
<path
|
||||
fill="#1F9CF0"
|
||||
d="M75.858 99.126a6.232 6.232 0 0 1-7.108-1.21c2.306 2.307 6.25.674 6.25-2.588V4.672c0-3.262-3.944-4.895-6.25-2.589a6.232 6.232 0 0 1 7.108-1.21l20.6 9.908A6.25 6.25 0 0 1 100 16.413v67.174a6.25 6.25 0 0 1-3.541 5.633l-20.601 9.906Z"
|
||||
/>
|
||||
</g>
|
||||
<path
|
||||
fill={`url(#${overlayGradientId})`}
|
||||
fillRule="evenodd"
|
||||
d="M70.851 99.317a6.224 6.224 0 0 0 4.96-.19L96.4 89.22a6.25 6.25 0 0 0 3.54-5.633V16.413a6.25 6.25 0 0 0-3.54-5.632L75.812.874a6.226 6.226 0 0 0-7.104 1.21L29.294 38.04 12.126 25.01a4.162 4.162 0 0 0-5.317.236l-5.507 5.009a4.168 4.168 0 0 0-.004 6.162L16.186 50 1.298 63.583a4.168 4.168 0 0 0 .004 6.162l5.507 5.009a4.162 4.162 0 0 0 5.317.236L29.294 61.96l39.414 35.958a6.218 6.218 0 0 0 2.143 1.4ZM74.954 27.3 45.048 50l29.906 22.701V27.3Z"
|
||||
clipRule="evenodd"
|
||||
opacity=".25"
|
||||
style={{ mixBlendMode: "overlay" }}
|
||||
/>
|
||||
</g>
|
||||
<defs>
|
||||
<filter
|
||||
id={topShadowFilterId}
|
||||
width="116.727"
|
||||
height="92.246"
|
||||
x="-8.394"
|
||||
y="15.829"
|
||||
colorInterpolationFilters="sRGB"
|
||||
filterUnits="userSpaceOnUse"
|
||||
>
|
||||
<feFlood floodOpacity="0" result="BackgroundImageFix" />
|
||||
<feColorMatrix
|
||||
in="SourceAlpha"
|
||||
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
|
||||
/>
|
||||
<feOffset />
|
||||
<feGaussianBlur stdDeviation="4.167" />
|
||||
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" />
|
||||
<feBlend in2="BackgroundImageFix" mode="overlay" result="effect1_dropShadow" />
|
||||
<feBlend in="SourceGraphic" in2="effect1_dropShadow" result="shape" />
|
||||
</filter>
|
||||
<filter
|
||||
id={sideShadowFilterId}
|
||||
width="47.917"
|
||||
height="116.151"
|
||||
x="60.417"
|
||||
y="-8.076"
|
||||
colorInterpolationFilters="sRGB"
|
||||
filterUnits="userSpaceOnUse"
|
||||
>
|
||||
<feFlood floodOpacity="0" result="BackgroundImageFix" />
|
||||
<feColorMatrix
|
||||
in="SourceAlpha"
|
||||
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
|
||||
/>
|
||||
<feOffset />
|
||||
<feGaussianBlur stdDeviation="4.167" />
|
||||
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" />
|
||||
<feBlend in2="BackgroundImageFix" mode="overlay" result="effect1_dropShadow" />
|
||||
<feBlend in="SourceGraphic" in2="effect1_dropShadow" result="shape" />
|
||||
</filter>
|
||||
<linearGradient
|
||||
id={overlayGradientId}
|
||||
x1="49.939"
|
||||
x2="49.939"
|
||||
y1=".258"
|
||||
y2="99.742"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
>
|
||||
<stop stopColor="#fff" />
|
||||
<stop offset="1" stopColor="#fff" stopOpacity="0" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
|
||||
export const Zed: Icon = (props) => {
|
||||
const id = useId();
|
||||
const clipPathId = `${id}-zed-logo-a`;
|
||||
|
||||
return (
|
||||
<svg {...props} fill="none" viewBox="0 0 96 96">
|
||||
<g clipPath={`url(#${clipPathId})`}>
|
||||
<path
|
||||
fill="currentColor"
|
||||
fillRule="evenodd"
|
||||
d="M9 6a3 3 0 0 0-3 3v66H0V9a9 9 0 0 1 9-9h80.379c4.009 0 6.016 4.847 3.182 7.682L43.055 57.187H57V51h6v7.688a4.5 4.5 0 0 1-4.5 4.5H37.055L26.743 73.5H73.5V36h6v37.5a6 6 0 0 1-6 6H20.743L10.243 90H87a3 3 0 0 0 3-3V21h6v66a9 9 0 0 1-9 9H6.621c-4.009 0-6.016-4.847-3.182-7.682L52.757 39H39v6h-6v-7.5a4.5 4.5 0 0 1 4.5-4.5h21.257l10.5-10.5H22.5V60h-6V22.5a6 6 0 0 1 6-6h52.757L85.757 6H9Z"
|
||||
clipRule="evenodd"
|
||||
/>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id={clipPathId}>
|
||||
<path fill="#fff" d="M0 0h96v96H0z" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
|
||||
export const OpenAI: Icon = (props) => (
|
||||
<svg {...props} preserveAspectRatio="xMidYMid" viewBox="0 0 256 260" fill="currentColor">
|
||||
<path d="M239.184 106.203a64.716 64.716 0 0 0-5.576-53.103C219.452 28.459 191 15.784 163.213 21.74A65.586 65.586 0 0 0 52.096 45.22a64.716 64.716 0 0 0-43.23 31.36c-14.31 24.602-11.061 55.634 8.033 76.74a64.665 64.665 0 0 0 5.525 53.102c14.174 24.65 42.644 37.324 70.446 31.36a64.72 64.72 0 0 0 48.754 21.744c28.481.025 53.714-18.361 62.414-45.481a64.767 64.767 0 0 0 43.229-31.36c14.137-24.558 10.875-55.423-8.083-76.483Zm-97.56 136.338a48.397 48.397 0 0 1-31.105-11.255l1.535-.87 51.67-29.825a8.595 8.595 0 0 0 4.247-7.367v-72.85l21.845 12.636c.218.111.37.32.409.563v60.367c-.056 26.818-21.783 48.545-48.601 48.601Zm-104.466-44.61a48.345 48.345 0 0 1-5.781-32.589l1.534.921 51.722 29.826a8.339 8.339 0 0 0 8.441 0l63.181-36.425v25.221a.87.87 0 0 1-.358.665l-52.335 30.184c-23.257 13.398-52.97 5.431-66.404-17.803ZM23.549 85.38a48.499 48.499 0 0 1 25.58-21.333v61.39a8.288 8.288 0 0 0 4.195 7.316l62.874 36.272-21.845 12.636a.819.819 0 0 1-.767 0L41.353 151.53c-23.211-13.454-31.171-43.144-17.804-66.405v.256Zm179.466 41.695-63.08-36.63L161.73 77.86a.819.819 0 0 1 .768 0l52.233 30.184a48.6 48.6 0 0 1-7.316 87.635v-61.391a8.544 8.544 0 0 0-4.4-7.213Zm21.742-32.69-1.535-.922-51.619-30.081a8.39 8.39 0 0 0-8.492 0L99.98 99.808V74.587a.716.716 0 0 1 .307-.665l52.233-30.133a48.652 48.652 0 0 1 72.236 50.391v.205ZM88.061 139.097l-21.845-12.585a.87.87 0 0 1-.41-.614V65.685a48.652 48.652 0 0 1 79.757-37.346l-1.535.87-51.67 29.825a8.595 8.595 0 0 0-4.246 7.367l-.051 72.697Zm11.868-25.58 28.138-16.217 28.188 16.218v32.434l-28.086 16.218-28.188-16.218-.052-32.434Z" />
|
||||
|
||||
@@ -19,21 +19,10 @@ export const CURSOR_MODEL_FAMILY_OPTIONS = [
|
||||
{ slug: "composer-1", name: "Composer 1" },
|
||||
{ slug: "gpt-5.3-codex", name: "GPT-5.3 Codex" },
|
||||
{ slug: "gpt-5.3-codex-spark-preview", name: "GPT-5.3 Codex Spark" },
|
||||
{ slug: "gpt-5.2-codex", name: "GPT-5.2 Codex" },
|
||||
{ slug: "gpt-5.2", name: "GPT-5.2" },
|
||||
{ slug: "gpt-5.2-high", name: "GPT-5.2 High" },
|
||||
{ slug: "gpt-5.1-codex-max", name: "GPT-5.1 Codex Max" },
|
||||
{ slug: "gpt-5.1-codex-mini", name: "GPT-5.1 Codex Mini" },
|
||||
{ slug: "gpt-5.1-high", name: "GPT-5.1 High" },
|
||||
{ slug: "opus-4.6", name: "Claude 4.6 Opus" },
|
||||
{ slug: "opus-4.5", name: "Claude 4.5 Opus" },
|
||||
{ slug: "sonnet-4.6", name: "Claude 4.6 Sonnet" },
|
||||
{ slug: "sonnet-4.5", name: "Claude 4.5 Sonnet" },
|
||||
{ slug: "gemini-3.1-pro", name: "Gemini 3.1 Pro" },
|
||||
{ slug: "gemini-3-pro", name: "Gemini 3 Pro" },
|
||||
{ slug: "gemini-3-flash", name: "Gemini 3 Flash" },
|
||||
{ slug: "grok", name: "Grok" },
|
||||
{ slug: "kimi-k2.5", name: "Kimi K2.5" },
|
||||
] as const satisfies readonly CursorModelFamilyOption[];
|
||||
|
||||
export type CursorModelFamily = (typeof CURSOR_MODEL_FAMILY_OPTIONS)[number]["slug"];
|
||||
@@ -63,33 +52,13 @@ export const MODEL_OPTIONS_BY_PROVIDER = {
|
||||
{ slug: "gpt-5.3-codex-xhigh", name: "GPT-5.3 Codex Extra High" },
|
||||
{ slug: "gpt-5.3-codex-xhigh-fast", name: "GPT-5.3 Codex Extra High Fast" },
|
||||
{ slug: "gpt-5.3-codex-spark-preview", name: "GPT-5.3 Codex Spark" },
|
||||
{ slug: "gpt-5.2", name: "GPT-5.2" },
|
||||
{ slug: "gpt-5.2-codex-low", name: "GPT-5.2 Codex Low" },
|
||||
{ slug: "gpt-5.2-codex-low-fast", name: "GPT-5.2 Codex Low Fast" },
|
||||
{ slug: "gpt-5.2-codex", name: "GPT-5.2 Codex" },
|
||||
{ slug: "gpt-5.2-codex-fast", name: "GPT-5.2 Codex Fast" },
|
||||
{ slug: "gpt-5.2-codex-high", name: "GPT-5.2 Codex High" },
|
||||
{ slug: "gpt-5.2-codex-high-fast", name: "GPT-5.2 Codex High Fast" },
|
||||
{ slug: "gpt-5.2-codex-xhigh", name: "GPT-5.2 Codex Extra High" },
|
||||
{ slug: "gpt-5.2-codex-xhigh-fast", name: "GPT-5.2 Codex Extra High Fast" },
|
||||
{ slug: "gpt-5.1-codex-max", name: "GPT-5.1 Codex Max" },
|
||||
{ slug: "gpt-5.1-codex-max-high", name: "GPT-5.1 Codex Max High" },
|
||||
{ slug: "gpt-5.2-high", name: "GPT-5.2 High" },
|
||||
{ slug: "gpt-5.1-high", name: "GPT-5.1 High" },
|
||||
{ slug: "gpt-5.1-codex-mini", name: "GPT-5.1 Codex Mini" },
|
||||
{ slug: "opus-4.6-thinking", name: "Claude 4.6 Opus (Thinking)" },
|
||||
{ slug: "opus-4.6", name: "Claude 4.6 Opus" },
|
||||
{ slug: "opus-4.6-thinking", name: "Claude 4.6 Opus (Thinking)" },
|
||||
{ slug: "opus-4.5", name: "Claude 4.5 Opus" },
|
||||
{ slug: "opus-4.5-thinking", name: "Claude 4.5 Opus (Thinking)" },
|
||||
{ slug: "sonnet-4.6", name: "Claude 4.6 Sonnet" },
|
||||
{ slug: "gemini-3.1-pro", name: "Gemini 3.1 Pro" },
|
||||
{ slug: "gemini-3-pro", name: "Gemini 3 Pro" },
|
||||
{ slug: "sonnet-4.6-thinking", name: "Claude 4.6 Sonnet (Thinking)" },
|
||||
{ slug: "sonnet-4.5", name: "Claude 4.5 Sonnet" },
|
||||
{ slug: "sonnet-4.5-thinking", name: "Claude 4.5 Sonnet (Thinking)" },
|
||||
{ slug: "gemini-3-flash", name: "Gemini 3 Flash" },
|
||||
{ slug: "grok", name: "Grok" },
|
||||
{ slug: "kimi-k2.5", name: "Kimi K2.5" },
|
||||
{ slug: "gemini-3.1-pro", name: "Gemini 3.1 Pro" },
|
||||
],
|
||||
} as const satisfies Record<ProviderKind, readonly ModelOption[]>;
|
||||
|
||||
@@ -140,48 +109,6 @@ const CURSOR_MODEL_CAPABILITY_BY_FAMILY: Record<CursorModelFamily, CursorModelCa
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gpt-5.2-codex": {
|
||||
supportsReasoning: true,
|
||||
supportsFast: true,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gpt-5.2": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gpt-5.2-high": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gpt-5.1-codex-max": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gpt-5.1-codex-mini": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gpt-5.1-high": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"opus-4.6": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
@@ -203,13 +130,6 @@ const CURSOR_MODEL_CAPABILITY_BY_FAMILY: Record<CursorModelFamily, CursorModelCa
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: true,
|
||||
},
|
||||
"sonnet-4.5": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: true,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: true,
|
||||
},
|
||||
"gemini-3.1-pro": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
@@ -217,34 +137,6 @@ const CURSOR_MODEL_CAPABILITY_BY_FAMILY: Record<CursorModelFamily, CursorModelCa
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gemini-3-pro": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"gemini-3-flash": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
grok: {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
"kimi-k2.5": {
|
||||
supportsReasoning: false,
|
||||
supportsFast: false,
|
||||
supportsThinking: false,
|
||||
defaultReasoning: "normal",
|
||||
defaultThinking: false,
|
||||
},
|
||||
};
|
||||
|
||||
const CURSOR_MODEL_FAMILY_SET = new Set<CursorModelFamily>(
|
||||
@@ -295,18 +187,11 @@ export const MODEL_SLUG_ALIASES_BY_PROVIDER: Record<ProviderKind, Record<string,
|
||||
"composer-1": "composer-1",
|
||||
"gpt-5.3-codex": "gpt-5.3-codex",
|
||||
"gpt-5.3-codex-spark": "gpt-5.3-codex-spark-preview",
|
||||
"gpt-5.2-codex": "gpt-5.2-codex",
|
||||
"gpt-5.1-codex-max-high": "gpt-5.1-codex-max-high",
|
||||
"gpt-5.1-codex-mini": "gpt-5.1-codex-mini",
|
||||
"gemini-3.1": "gemini-3.1-pro",
|
||||
"gemini-3.1-pro": "gemini-3.1-pro",
|
||||
"gemini-3-pro": "gemini-3-pro",
|
||||
"claude-4.6-sonnet-thinking": "sonnet-4.6-thinking",
|
||||
"claude-4.5-sonnet-thinking": "sonnet-4.5-thinking",
|
||||
"claude-4.6-opus-thinking": "opus-4.6-thinking",
|
||||
"claude-4.5-opus-thinking": "opus-4.5-thinking",
|
||||
"sonnet-4.6-thinking": "sonnet-4.6-thinking",
|
||||
"sonnet-4.5-thinking": "sonnet-4.5-thinking",
|
||||
"opus-4.6-thinking": "opus-4.6-thinking",
|
||||
"opus-4.5-thinking": "opus-4.5-thinking",
|
||||
},
|
||||
@@ -354,25 +239,9 @@ function resolveCursorModelFamily(model: string | null | undefined): CursorModel
|
||||
return "gpt-5.3-codex";
|
||||
}
|
||||
|
||||
if (
|
||||
normalized === "gpt-5.2-codex" ||
|
||||
normalized === "gpt-5.2-codex-fast" ||
|
||||
normalized === "gpt-5.2-codex-low" ||
|
||||
normalized === "gpt-5.2-codex-low-fast" ||
|
||||
normalized === "gpt-5.2-codex-high" ||
|
||||
normalized === "gpt-5.2-codex-high-fast" ||
|
||||
normalized === "gpt-5.2-codex-xhigh" ||
|
||||
normalized === "gpt-5.2-codex-xhigh-fast"
|
||||
) {
|
||||
return "gpt-5.2-codex";
|
||||
}
|
||||
|
||||
if (normalized === "sonnet-4.6-thinking") {
|
||||
return "sonnet-4.6";
|
||||
}
|
||||
if (normalized === "sonnet-4.5-thinking") {
|
||||
return "sonnet-4.5";
|
||||
}
|
||||
if (normalized === "opus-4.6-thinking") {
|
||||
return "opus-4.6";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user