- Bots get continue_in_new_session: the bot writes a title and summary, the session closes for good (read-only) and the new one opens with the summary as a "Carried over from the last session" message that links back to the old session. - Continue in new session (conversation menu, sessions modal) and the automatic rollover at the session length do the same; New session now starts a fresh, unlinked session. - Session length is an app setting in Settings > General. - ?session_id= opens a session; a carried-over one shows a bar linking to where the conversation went on instead of the composer. - The thread can open the previous session above the current one (shown only, never in the prompt), and replies get search_past_sessions and read_past_session. - Sessions are named from their opening messages, not their latest, and a carried summary is labelled as the earlier session's. Co-Authored-By: Claude Opus 5.5 <[email protected]>
67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { useState } from "react";
|
|
import { MessageSquareShare } from "lucide-react";
|
|
import Button from "@moduletrace/twui/layout/Button";
|
|
import postSessionApi from "@/src/functions/frontend/post-session-api";
|
|
import conversationHref from "@/src/utils/conversation-href";
|
|
|
|
type Props = {
|
|
bot_id: number;
|
|
workspace_id?: number | null;
|
|
/**
|
|
* Renders the trigger instead of the default button (the conversation
|
|
* menu's row), given whether it's working and the click.
|
|
*/
|
|
render?: (params: { loading: boolean; onClick: () => void }) => React.ReactNode;
|
|
};
|
|
|
|
/**
|
|
* Continue in new session: carries the conversation into a new session
|
|
* with a summary of this one, as the bot does when asked
|
|
* (`api/admin/bots/continue-session`). Unlike New session, which starts
|
|
* fresh. Asks first, since this session then stays closed for good. It
|
|
* stays on screen (a menu stays open) while the summary is written, which
|
|
* takes a model call.
|
|
*/
|
|
export default function ContinueSessionButton({ bot_id, workspace_id, render }: Props) {
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const start = async () => {
|
|
if (loading) return;
|
|
if (!window.confirm("Continue in a new session? A summary of this session carries over, and this one is closed for good (you can still read it).")) return;
|
|
|
|
setLoading(true);
|
|
|
|
const res = await postSessionApi({
|
|
path: "continue-session",
|
|
body: { bot_id, workspace_id },
|
|
}).catch(() => null);
|
|
|
|
if (res?.success) {
|
|
window.location.assign(conversationHref({ bot_id, workspace_id }));
|
|
return;
|
|
}
|
|
|
|
setLoading(false);
|
|
window.alert(res?.msg || "Couldn't continue in a new session.");
|
|
};
|
|
|
|
if (render) return <>{render({ loading, onClick: start })}</>;
|
|
|
|
return (
|
|
<Button
|
|
title="Continue in a new session, with a summary of this one"
|
|
type="button"
|
|
size="small"
|
|
variant="outlined"
|
|
color="gray"
|
|
loading={loading}
|
|
disabled={loading}
|
|
onClick={start}
|
|
className="shrink-0 gap-1!"
|
|
>
|
|
<MessageSquareShare size={14} aria-hidden />
|
|
Continue
|
|
</Button>
|
|
);
|
|
}
|