mirror of
https://github.com/Narcooo/inkos.git
synced 2026-09-01 04:28:39 +08:00
fix(studio): stop reviving stale Play choices
This commit is contained in:
@@ -46,6 +46,24 @@ describe("latestPlayChoices", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("does not revive choices from an older turn when the latest Play result has none", () => {
|
||||
const messages = [
|
||||
{ role: "assistant", parts: [{ type: "tool", execution: { id: "turn-1", tool: "play_step", status: "completed", details: { suggestedActions: ["看账本", "问来人"] } } }] },
|
||||
{ role: "assistant", parts: [{ type: "tool", execution: { id: "turn-2", tool: "play_step", status: "completed", details: { suggestedActions: [] } } }] },
|
||||
] as any;
|
||||
|
||||
expect(latestPlayChoiceSet(messages)).toBeNull();
|
||||
});
|
||||
|
||||
it("hides choices from the previous turn while a new Play turn is running", () => {
|
||||
const messages = [
|
||||
{ role: "assistant", parts: [{ type: "tool", execution: { id: "turn-1", tool: "play_step", status: "completed", details: { suggestedActions: ["看账本", "问来人"] } } }] },
|
||||
{ role: "assistant", parts: [{ type: "tool", execution: { id: "turn-2", tool: "play_step", status: "running" } }] },
|
||||
] as any;
|
||||
|
||||
expect(latestPlayChoiceSet(messages)).toBeNull();
|
||||
});
|
||||
|
||||
it("returns [] when there is no play execution", () => {
|
||||
expect(latestPlayChoices([{ role: "user", content: "hi" }] as any)).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -29,17 +29,17 @@ export function latestPlayChoiceSet(messages: ReadonlyArray<Message>): PlayChoic
|
||||
const parts = messages[i]?.parts ?? [];
|
||||
for (let p = parts.length - 1; p >= 0; p--) {
|
||||
const part = parts[p];
|
||||
if (part.type !== "tool") continue;
|
||||
const set = choiceSetFromExecution(part.execution, `message-${i}-part-${p}`);
|
||||
if (set) return set;
|
||||
if (part.type !== "tool" || !PLAY_TOOLS.has(part.execution.tool)) continue;
|
||||
return choiceSetFromExecution(part.execution, `message-${i}-part-${p}`);
|
||||
}
|
||||
|
||||
// Direct tool executions created by confirmed action buttons may be present
|
||||
// on the flat message before they are rehydrated into chronological parts.
|
||||
const toolExecutions = messages[i]?.toolExecutions ?? [];
|
||||
for (let t = toolExecutions.length - 1; t >= 0; t--) {
|
||||
const set = choiceSetFromExecution(toolExecutions[t], `message-${i}-execution-${t}`);
|
||||
if (set) return set;
|
||||
const execution = toolExecutions[t];
|
||||
if (!PLAY_TOOLS.has(execution.tool)) continue;
|
||||
return choiceSetFromExecution(execution, `message-${i}-execution-${t}`);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user