Decode Cursor model list responses with schema
- Add a schema for `cursor/list_available_models` responses - Use decoded model data when building Cursor provider capabilities - Cover per-model config options in Cursor ACP tests
This commit is contained in:
1 parent
c517cfab3d
commit
f853a7f2d2
3 files changed
+49
-30
No files matched your search
@@ -13,7 +13,7 @@ import type {
|
||||
ServerSettingsError,
|
||||
} from "@t3tools/contracts";
|
||||
import type * as EffectAcpSchema from "effect-acp/schema";
|
||||
import { Cause, Effect, Equal, Exit, Layer, Option, Result, Stream } from "effect";
|
||||
import { Cause, Effect, Equal, Exit, Layer, Option, Result, Schema, Stream } from "effect";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
import {
|
||||
createModelCapabilities,
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
import { makeManagedServerProvider } from "../makeManagedServerProvider.ts";
|
||||
import { CursorProvider } from "../Services/CursorProvider.ts";
|
||||
import { AcpSessionRuntime } from "../acp/AcpSessionRuntime.ts";
|
||||
import { CursorListAvailableModelsResponse } from "../acp/CursorAcpExtension.ts";
|
||||
import { ServerSettingsService } from "../../serverSettings.ts";
|
||||
|
||||
const PROVIDER = "cursor" as const;
|
||||
@@ -102,16 +103,6 @@ interface CursorAcpDiscoveredModel {
|
||||
readonly capabilities: ModelCapabilities;
|
||||
}
|
||||
|
||||
interface CursorAcpAvailableModel {
|
||||
readonly value?: unknown;
|
||||
readonly name?: unknown;
|
||||
readonly configOptions?: unknown;
|
||||
}
|
||||
|
||||
interface CursorAcpListAvailableModelsResponse {
|
||||
readonly models?: unknown;
|
||||
}
|
||||
|
||||
function flattenSessionConfigSelectOptions(
|
||||
configOption: EffectAcpSchema.SessionConfigOption | undefined,
|
||||
): ReadonlyArray<CursorSessionSelectOption> {
|
||||
@@ -401,34 +392,21 @@ export function buildCursorDiscoveredModelsFromConfigOptions(
|
||||
}
|
||||
|
||||
function buildCursorDiscoveredModelsFromAvailableModelsResponse(
|
||||
response: unknown,
|
||||
response: typeof CursorListAvailableModelsResponse.Type,
|
||||
): ReadonlyArray<ServerProviderModel> {
|
||||
const models = (response as CursorAcpListAvailableModelsResponse | null | undefined)?.models;
|
||||
if (!Array.isArray(models)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return buildCursorDiscoveredModels(
|
||||
models.flatMap((entry) => {
|
||||
if (!entry || typeof entry !== "object") {
|
||||
return [];
|
||||
}
|
||||
|
||||
const model = entry as CursorAcpAvailableModel;
|
||||
const slug = typeof model.value === "string" ? model.value.trim() : "";
|
||||
const name = typeof model.name === "string" ? model.name.trim() : "";
|
||||
response.models.flatMap((model) => {
|
||||
const slug = model.value.trim();
|
||||
const name = model.name.trim();
|
||||
if (!slug || !name) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const configOptions = Array.isArray(model.configOptions)
|
||||
? (model.configOptions as ReadonlyArray<EffectAcpSchema.SessionConfigOption>)
|
||||
: [];
|
||||
return [
|
||||
{
|
||||
slug,
|
||||
name,
|
||||
capabilities: buildCursorCapabilitiesFromConfigOptions(configOptions),
|
||||
capabilities: buildCursorCapabilitiesFromConfigOptions(model.configOptions),
|
||||
},
|
||||
];
|
||||
}),
|
||||
@@ -573,7 +551,10 @@ const discoverCursorModelsViaListAvailableModels = (cursorSettings: CursorSettin
|
||||
Effect.gen(function* () {
|
||||
yield* acp.start();
|
||||
const response = yield* acp.request("cursor/list_available_models", {});
|
||||
return buildCursorDiscoveredModelsFromAvailableModelsResponse(response);
|
||||
const decoded = yield* Schema.decodeUnknownEffect(CursorListAvailableModelsResponse)(
|
||||
response,
|
||||
);
|
||||
return buildCursorDiscoveredModelsFromAvailableModelsResponse(decoded);
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
CursorListAvailableModelsResponse,
|
||||
extractAskQuestions,
|
||||
extractPlanMarkdown,
|
||||
extractTodosAsPlan,
|
||||
@@ -105,4 +106,30 @@ describe("CursorAcpExtension", () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("decodes Cursor list_available_models responses with per-model config options", () => {
|
||||
const decoded = CursorListAvailableModelsResponse.make({
|
||||
models: [
|
||||
{
|
||||
value: "gpt-5.4",
|
||||
name: "GPT-5.4",
|
||||
configOptions: [
|
||||
{
|
||||
id: "reasoning",
|
||||
name: "Reasoning",
|
||||
category: "thought_level",
|
||||
type: "select",
|
||||
currentValue: "medium",
|
||||
options: [
|
||||
{ value: "low", name: "Low" },
|
||||
{ value: "medium", name: "Medium" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(decoded.models[0]?.configOptions?.[0]?.id).toBe("reasoning");
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
import type { UserInputQuestion } from "@t3tools/contracts";
|
||||
import { Schema } from "effect";
|
||||
import * as AcpSchema from "effect-acp/schema";
|
||||
|
||||
const CursorAskQuestionOption = Schema.Struct({
|
||||
id: Schema.String,
|
||||
@@ -53,6 +54,16 @@ export const CursorUpdateTodosRequest = Schema.Struct({
|
||||
merge: Schema.Boolean,
|
||||
});
|
||||
|
||||
const CursorAvailableModel = Schema.Struct({
|
||||
value: Schema.String,
|
||||
name: Schema.String,
|
||||
configOptions: Schema.optional(Schema.Array(AcpSchema.SessionConfigOption)),
|
||||
});
|
||||
|
||||
export const CursorListAvailableModelsResponse = Schema.Struct({
|
||||
models: Schema.Array(CursorAvailableModel),
|
||||
});
|
||||
|
||||
export function extractAskQuestions(
|
||||
params: typeof CursorAskQuestionRequest.Type,
|
||||
): ReadonlyArray<UserInputQuestion> {
|
||||
|
||||
Reference in new issue
Block a user