Skip to content
Closed
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
15 changes: 8 additions & 7 deletions src/helpers/assistantSessionState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
*/
export function closeAssistantSessionState(state) {
return {
conversationId: state.conversationId ?? null,
conversationId: state?.conversationId ?? null,
pendingCommand: null,
thinking: false,
busy: false,
responseReady: false,
};
}

export function resolveAssistantPanelBusy({ agentState, activeToolName, submissionInFlight }) {
export function resolveAssistantPanelBusy(params) {
const { agentState, activeToolName, submissionInFlight } = params || {};
return Boolean(
submissionInFlight ||
activeToolName ||
Expand All @@ -36,15 +37,15 @@ export async function restoreAssistantConversation({
isActive = () => true,
}) {
try {
await loadConversation(conversationId);
await loadConversation?.(conversationId);
if (!isActive()) return "inactive";
onReady();
onReady?.();
return "restored";
} catch (error) {
if (!isActive()) return "inactive";
onError(error);
onReset();
onReady();
onError?.(error);
onReset?.();
onReady?.();
return "reset";
}
}
44 changes: 44 additions & 0 deletions test/helpers/assistantSessionState.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,47 @@ test("failed Assistant history resets before enabling a fresh conversation", asy
);
assert.deepEqual(events, ["error", "reset", "ready"]);
});

test("assistantSessionState helpers handle nullish inputs safely", async () => {
const {
closeAssistantSessionState,
resolveAssistantPanelBusy,
restoreAssistantConversation,
} = await import("../../src/helpers/assistantSessionState.js");

assert.deepEqual(closeAssistantSessionState(null), {
conversationId: null,
pendingCommand: null,
thinking: false,
busy: false,
responseReady: false,
});
assert.deepEqual(closeAssistantSessionState(undefined), {
conversationId: null,
pendingCommand: null,
thinking: false,
busy: false,
responseReady: false,
});

assert.equal(resolveAssistantPanelBusy(null), false);
assert.equal(resolveAssistantPanelBusy(undefined), false);

assert.equal(
await restoreAssistantConversation({
conversationId: 42,
loadConversation: async () => {},
}),
"restored"
);

assert.equal(
await restoreAssistantConversation({
conversationId: 42,
loadConversation: async () => {
throw new Error("fail");
},
}),
"reset"
);
});
Loading