mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-21 07:45:38 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
088b20c333 | ||
|
|
322ff458c1 | ||
|
|
18efb5efd2 |
@@ -2291,7 +2291,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
if (providerResult.handled) {
|
||||
this.currentMode = providerResult.currentModeId ?? modeId;
|
||||
if (providerResult.configOptions) {
|
||||
this.configOptions = this.transformConfigOptions(providerResult.configOptions);
|
||||
this.applyConfigOptions(providerResult.configOptions);
|
||||
}
|
||||
this.availableModes = this.modesFromConfig().modes;
|
||||
this.pushEvent({
|
||||
@@ -2335,7 +2335,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
if (beforeModeWriter) {
|
||||
const beforeResult = await this.runACPRequest(() => beforeModeWriter(context));
|
||||
if (beforeResult?.configOptions) {
|
||||
this.configOptions = this.transformConfigOptions(beforeResult.configOptions);
|
||||
this.applyConfigOptions(beforeResult.configOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2700,7 +2700,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
requestedValue: string;
|
||||
label: string;
|
||||
}): string {
|
||||
this.configOptions = this.transformConfigOptions(response.configOptions);
|
||||
this.applyConfigOptions(response.configOptions);
|
||||
const responseOption =
|
||||
category === undefined
|
||||
? findSelectConfigOptionById({ configOptions: this.configOptions, id: configId })
|
||||
@@ -3207,7 +3207,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
? this.sessionResponseTransformer(response)
|
||||
: response;
|
||||
|
||||
this.configOptions = this.transformConfigOptions(transformed.configOptions ?? []);
|
||||
this.applyConfigOptions(transformed.configOptions ?? []);
|
||||
this.sessionModeState = transformed.modes ?? null;
|
||||
|
||||
const modeInfo = deriveModesFromACP(this.defaultModes, transformed.modes, this.configOptions);
|
||||
@@ -3217,14 +3217,15 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
this.availableModels = transformed.models?.availableModels ?? null;
|
||||
this.currentModel =
|
||||
transformed.models?.currentModelId ?? deriveCurrentConfigValue(this.configOptions, "model");
|
||||
this.thinkingOptionId =
|
||||
deriveCurrentConfigValue(this.configOptions, "thought_level") ?? this.thinkingOptionId;
|
||||
}
|
||||
|
||||
private transformConfigOptions(configOptions: SessionConfigOption[]): SessionConfigOption[] {
|
||||
return this.configOptionsTransformer
|
||||
private applyConfigOptions(configOptions: SessionConfigOption[]): string | null {
|
||||
this.configOptions = this.configOptionsTransformer
|
||||
? this.configOptionsTransformer(configOptions)
|
||||
: configOptions;
|
||||
const thinkingOptionId = deriveCurrentConfigValue(this.configOptions, "thought_level");
|
||||
this.thinkingOptionId = thinkingOptionId ?? this.thinkingOptionId;
|
||||
return thinkingOptionId;
|
||||
}
|
||||
|
||||
private transformModeId(modeId: string): string | null {
|
||||
@@ -3260,9 +3261,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
);
|
||||
}
|
||||
}
|
||||
if (this.config.thinkingOptionId && this.config.thinkingOptionId !== this.thinkingOptionId) {
|
||||
await this.setThinkingOption(this.config.thinkingOptionId);
|
||||
}
|
||||
await this.applyConfiguredThinkingOption();
|
||||
const configuredFeatureValues = this.config.providerOptions ?? {};
|
||||
for (const featureOption of this.configFeatureOptions) {
|
||||
if (!Object.prototype.hasOwnProperty.call(configuredFeatureValues, featureOption.id)) {
|
||||
@@ -3285,6 +3284,34 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
this.openOptionsPatch = this.featureDifferences(configuredFeatureValues);
|
||||
}
|
||||
|
||||
private async applyConfiguredThinkingOption(): Promise<void> {
|
||||
const requested = this.config.thinkingOptionId;
|
||||
if (!requested || requested === this.thinkingOptionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.setThinkingOption(requested);
|
||||
} catch (error) {
|
||||
if (!this.initialHandle || this.thinkingOptionWriter || !isACPInvalidParams(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const option = findSelectConfigOption({
|
||||
configOptions: this.configOptions,
|
||||
category: "thought_level",
|
||||
});
|
||||
if (!option || findSelectConfigChoice({ option, value: requested })) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
this.logger.warn(
|
||||
{ requested, current: this.thinkingOptionId, model: this.currentModel },
|
||||
"Saved ACP thinking option is unavailable on resume; keeping the provider's current value",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A stored feature value is a preference carried over from whichever model the user
|
||||
* last configured, so the session it lands on may have no such option. Paseo's own
|
||||
@@ -3528,16 +3555,14 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
|
||||
private handleConfigOptionUpdate(update: ConfigOptionUpdate): AgentStreamEvent[] {
|
||||
const before = this.featureValues();
|
||||
this.configOptions = this.transformConfigOptions(update.configOptions);
|
||||
const nextThinkingOptionId = this.applyConfigOptions(update.configOptions);
|
||||
const modeInfo = this.modesFromConfig();
|
||||
const nextMode = modeInfo.currentModeId;
|
||||
const nextModel = deriveCurrentConfigValue(this.configOptions, "model");
|
||||
const nextThinkingOptionId = deriveCurrentConfigValue(this.configOptions, "thought_level");
|
||||
|
||||
this.availableModes = modeInfo.modes;
|
||||
this.currentMode = nextMode ?? this.currentMode;
|
||||
this.currentModel = nextModel ?? this.currentModel;
|
||||
this.thinkingOptionId = nextThinkingOptionId ?? this.thinkingOptionId;
|
||||
this.reportFeatureChanges(before);
|
||||
|
||||
const events: AgentStreamEvent[] = [];
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// ACP peer that accepts a thinking level on creation but rejects it after load.
|
||||
const readline = require("node:readline");
|
||||
|
||||
const sessionId = "thinking-resume-session";
|
||||
let model = "startup-model";
|
||||
let effort = "low";
|
||||
let mode = "agent";
|
||||
let loaded = false;
|
||||
|
||||
const send = (message) =>
|
||||
process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\n");
|
||||
|
||||
function select(id, category, currentValue, values) {
|
||||
return {
|
||||
id,
|
||||
name: id,
|
||||
category,
|
||||
type: "select",
|
||||
currentValue,
|
||||
options: values.map((value) => ({ value, name: value })),
|
||||
};
|
||||
}
|
||||
|
||||
function configOptions() {
|
||||
return [
|
||||
select("mode", "mode", mode, ["agent", "plan"]),
|
||||
select("model", "model", model, ["startup-model", "second-model"]),
|
||||
select(
|
||||
"effort",
|
||||
"thought_level",
|
||||
effort,
|
||||
loaded && model === "second-model"
|
||||
? ["minimal", "low", "medium", "high", "xhigh"]
|
||||
: ["low", "high", "max"],
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
function assistantMessage(text) {
|
||||
send({
|
||||
method: "session/update",
|
||||
params: {
|
||||
sessionId,
|
||||
update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text } },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
readline.createInterface({ input: process.stdin }).on("line", (line) => {
|
||||
const { id, method, params } = JSON.parse(line);
|
||||
if (id === undefined) return;
|
||||
let result;
|
||||
switch (method) {
|
||||
case "initialize":
|
||||
result = {
|
||||
protocolVersion: 1,
|
||||
agentCapabilities: { loadSession: true, sessionCapabilities: { close: {} } },
|
||||
};
|
||||
break;
|
||||
case "session/new":
|
||||
result = { sessionId, configOptions: configOptions() };
|
||||
break;
|
||||
case "session/load":
|
||||
loaded = true;
|
||||
model = process.env.ACP_TEST_LOAD_MODEL;
|
||||
effort = model === "second-model" && !process.env.ACP_TEST_SAVED_MODE ? "high" : "low";
|
||||
assistantMessage("Response from the saved session");
|
||||
result = { configOptions: configOptions() };
|
||||
break;
|
||||
case "session/set_config_option":
|
||||
if (params.configId === "model") {
|
||||
model = params.value;
|
||||
if (loaded && model === "second-model") effort = "high";
|
||||
} else if (params.configId === "mode") {
|
||||
mode = params.value;
|
||||
if (loaded && mode === process.env.ACP_TEST_SAVED_MODE) effort = "high";
|
||||
} else if (loaded && params.value === "max") {
|
||||
send({
|
||||
id,
|
||||
error: {
|
||||
code: -32602,
|
||||
message: "Invalid params",
|
||||
data: "This model does not support that thinking level",
|
||||
},
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
effort = params.value;
|
||||
}
|
||||
result = { configOptions: configOptions() };
|
||||
break;
|
||||
case "session/prompt":
|
||||
assistantMessage("Response from the saved session");
|
||||
result = { stopReason: "end_turn" };
|
||||
break;
|
||||
case "session/close":
|
||||
result = {};
|
||||
break;
|
||||
default:
|
||||
send({ id, error: { code: -32601, message: "Method not found" } });
|
||||
return;
|
||||
}
|
||||
send({ id, result });
|
||||
});
|
||||
@@ -576,3 +576,83 @@ test("bundled goose lists configured providers and switches models across provid
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
test.each([
|
||||
{ scenario: "the saved model loaded", loadModel: "second-model", savedMode: undefined },
|
||||
{ scenario: "the saved model restored", loadModel: "startup-model", savedMode: undefined },
|
||||
{ scenario: "the saved mode restored", loadModel: "second-model", savedMode: "plan" },
|
||||
])(
|
||||
"reopens an ACP chat with a rejected saved thinking level with $scenario",
|
||||
async ({ loadModel, savedMode }) => {
|
||||
const root = await mkdtemp(path.join(os.tmpdir(), "paseo-acp-thinking-resume-"));
|
||||
const options = {
|
||||
paseoHomeRoot: root,
|
||||
staticDir: path.join(root, "static"),
|
||||
cleanup: false,
|
||||
mcpEnabled: false,
|
||||
pluginsEnabled: false,
|
||||
providerOverrides: {
|
||||
"thinking-fixture": {
|
||||
extends: "acp" as const,
|
||||
label: "Thinking fixture",
|
||||
env: {
|
||||
ACP_TEST_LOAD_MODEL: loadModel,
|
||||
ACP_TEST_SAVED_MODE: savedMode ?? "",
|
||||
},
|
||||
command: [
|
||||
process.execPath,
|
||||
path.join(import.meta.dirname, "acp-thinking-resume-fixture.cjs"),
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
try {
|
||||
const first = await createDaemonTestContext(options);
|
||||
let agentId: string;
|
||||
try {
|
||||
const agent = await first.client.createAgent({
|
||||
provider: "thinking-fixture",
|
||||
cwd: root,
|
||||
model: "second-model",
|
||||
modeId: savedMode,
|
||||
thinkingOptionId: "max",
|
||||
});
|
||||
agentId = agent.id;
|
||||
expect(agent.thinkingOptionId).toBe("max");
|
||||
await first.client.sendMessage(agentId, "Save this conversation");
|
||||
expect((await first.client.waitForFinish(agentId, 10_000)).status).toBe("idle");
|
||||
} finally {
|
||||
await first.cleanup();
|
||||
}
|
||||
|
||||
const reopened = await createDaemonTestContext(options);
|
||||
try {
|
||||
const timeline = await reopened.client.fetchAgentTimeline(agentId, { limit: 40 });
|
||||
expect(timeline.entries.map(({ item }) => item)).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: "assistant_message",
|
||||
text: "Response from the saved session",
|
||||
}),
|
||||
);
|
||||
expect(
|
||||
(await reopened.client.fetchAgent(agentId))?.agent.runtimeInfo?.thinkingOptionId,
|
||||
).toBe("high");
|
||||
|
||||
// Interactive writes still surface a provider rejection.
|
||||
await expect(reopened.client.setAgentThinkingOption(agentId, "max")).rejects.toThrow(
|
||||
"Invalid params",
|
||||
);
|
||||
await reopened.client.setAgentThinkingOption(agentId, "low");
|
||||
expect((await reopened.client.fetchAgent(agentId))?.agent).toMatchObject({
|
||||
thinkingOptionId: "low",
|
||||
runtimeInfo: { thinkingOptionId: "low" },
|
||||
});
|
||||
} finally {
|
||||
await reopened.cleanup();
|
||||
}
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
60_000,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user