Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 93 additions & 22 deletions apps/server/src/textGeneration/AntigravityTextGeneration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
readonly rejectAdmission?: boolean;
readonly sessionId?: string;
readonly startupSkills?: boolean;
readonly initialModel?: string;
readonly rejectThinkingUpdate?: boolean;
} = {},
) {
const fs = yield* FileSystem.FileSystem;
Expand All @@ -84,6 +86,8 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
prompts: [] as Array<Parameters<TextRuntime["prompt"]>[0]>,
selectedModels: [] as Array<string>,
selectedModes: [] as Array<string>,
promptThinkingLevels: [] as Array<string>,
thinkingUpdates: [] as Array<string>,
nativeFilesAtClose: [] as Array<boolean>,
cancellations: 0,
stop: undefined as Effect.Effect<void> | undefined,
Expand Down Expand Up @@ -132,6 +136,8 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
}),
);
let sessionUpdate: Parameters<TextRuntime["handleSessionUpdate"]>[0] = () => Effect.void;
let currentModel = options.initialModel ?? modelSelection.model;
let thinkingLevel = "high";

return {
start: () =>
Expand Down Expand Up @@ -164,25 +170,58 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
state.selectedModes.push(mode);
return {};
}),
getConfigOptions: Effect.succeed([
{
id: "model",
name: "Model",
category: "model",
type: "select",
currentValue: modelSelection.model,
options: [{ value: modelSelection.model, name: "Gemini test" }],
},
]),
getConfigOptions: Effect.sync(() => {
const config: Array<AcpSchema.SessionConfigOption> = [
{
id: "model",
name: "Model",
category: "model",
type: "select",
currentValue: currentModel,
options: [
{ value: modelSelection.model, name: "Gemini test" },
{ value: "gemini-native-default", name: "Gemini native default" },
],
},
];
if (currentModel === modelSelection.model) {
config.push({
id: "thinking_level",
name: "Thinking level",
category: "thought_level",
type: "select",
currentValue: thinkingLevel,
options: [
{ value: "low", name: "Low" },
{ value: "high", name: "High" },
],
});
}
return config;
}),
getEvents: () => Stream.fromQueue(events),
setModel: (model) =>
Effect.sync(() => {
state.selectedModels.push(model);
currentModel = model;
}),
setConfigOption: (id, value) =>
Effect.gen(function* () {
if (id === "thinking_level" && typeof value === "string") {
state.thinkingUpdates.push(value);
if (options.rejectThinkingUpdate) {
return yield* AcpRequestError.invalidParams(
"Thinking level is no longer available.",
);
}
thinkingLevel = value;
}
return { configOptions: [] };
}),
setConfigOption: () => Effect.succeed({ configOptions: [] }),
prompt: (request) =>
Effect.gen(function* () {
state.prompts.push(request);
state.promptThinkingLevels.push(thinkingLevel);
yield* Deferred.succeed(enteredPrompt, undefined);
const emit: PromptContext["emit"] = (update, sessionId = nativeSessionId) =>
sessionUpdate({ sessionId, update });
Expand Down Expand Up @@ -520,17 +559,49 @@ it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => {
}),
);

it.effect("uses the native default without sending T3's default selection as a model ID", () =>
Effect.gen(function* () {
const fixture = yield* makeFixture();
const result = yield* fixture.textGeneration.generateThreadTitle({
...fixture.titleInput,
modelSelection: { ...modelSelection, model: ANTIGRAVITY_DEFAULT_MODEL },
});
expect(result).toEqual({ title: "Repair login" });
expect(fixture.state.selectedModels).toEqual([]);
yield* fixture.assertCleaned;
}),
it.effect.each([
{ name: "native default", selected: undefined, expected: "high", updates: [] },
{
name: "after switching models",
selected: "low",
expected: "low",
updates: ["low"],
initialModel: "gemini-native-default",
},
{ name: "when not advertised", selected: "medium", expected: "high", updates: [] },
{
name: "when rejected",
selected: "low",
expected: "high",
updates: ["low"],
rejectThinkingUpdate: true,
},
])(
"generates a title with the thinking level $name",
({ selected, expected, updates, initialModel, rejectThinkingUpdate }) =>
Effect.gen(function* () {
const fixture = yield* makeFixture({
initialModel: initialModel ?? modelSelection.model,
rejectThinkingUpdate: rejectThinkingUpdate === true,
});
const result = yield* fixture.textGeneration.generateThreadTitle({
...fixture.titleInput,
modelSelection: {
...modelSelection,
model: initialModel === undefined ? ANTIGRAVITY_DEFAULT_MODEL : modelSelection.model,
...(selected === undefined
? {}
: { options: [{ id: "thinking_level", value: selected }] }),
},
});
expect(result).toEqual({ title: "Repair login" });
expect(fixture.state.selectedModels).toEqual(
initialModel === undefined ? [] : [modelSelection.model],
);
expect(fixture.state.thinkingUpdates).toEqual(updates);
expect(fixture.state.promptThinkingLevels).toEqual([expected]);
yield* fixture.assertCleaned;
}),
);

it.effect.each([
Expand Down
29 changes: 28 additions & 1 deletion apps/server/src/textGeneration/AntigravityTextGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import * as Scope from "effect/Scope";
import * as Stream from "effect/Stream";
import { type AcpError, AcpRequestError } from "effect-acp/errors";

import { applyAntigravityAcpModelSelection } from "../provider/acp/AntigravityAcpSupport.ts";
import {
antigravityThinkingConfig,
applyAntigravityAcpModelSelection,
} from "../provider/acp/AntigravityAcpSupport.ts";
import { removeAntigravitySessionFiles } from "../provider/acp/AntigravitySessionFiles.ts";
import {
ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE,
isAntigravitySignInRequiredError,
} from "../provider/antigravityAuthSupport.ts";
import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
import { collectSessionConfigOptionValues } from "@t3tools/provider-acp/server/runtimeModel";
import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations";

const ANTIGRAVITY_TIMEOUT_MS = 180_000;
Expand Down Expand Up @@ -260,6 +264,29 @@ export const makeAntigravityTextGeneration = Effect.fn("makeAntigravityTextGener
cause,
}),
});
const savedOptions = input.modelSelection.options;
if (savedOptions?.length) {
const thinking = antigravityThinkingConfig(yield* runtime.getConfigOptions);
const selected = savedOptions.find((option) => option.id === thinking?.id)?.value;
if (
thinking !== undefined &&
typeof selected === "string" &&
selected !== thinking.currentValue &&
collectSessionConfigOptionValues(thinking).includes(selected)
) {
yield* runtime.setConfigOption(thinking.id, selected).pipe(
Effect.catchTags({
AcpRequestError: (error) =>
error.code === -32602
? Effect.logDebug("Antigravity rejected the saved thinking level", {
optionId: thinking.id,
value: selected,
})
: Effect.fail(error),
}),
);
}
}

const result = yield* runtime.prompt({
prompt: [
Expand Down
Loading