Files
cobble/src/pages/admin/bots/[bot_id]/(hooks)/use-bot-instructions.ts
T
tbenandClaude Opus 5.5 f13fa863c5 Trim page props and page the conversation's messages
Bot and workspace lists in page props leave out instructions, memory and
workspace context, and carry the last message as a short preview. The
header avatar's edit form loads the bot's instructions when it opens.
The conversation renders its latest 30 messages and loads older ones as
the thread scrolls to its top.

Also: the composer shows a placeholder until its editor loads, and
`bun start` no longer builds first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-20 20:09:01 +01:00

51 lines
1.4 KiB
TypeScript

import { useEffect, useState } from "react";
import fetchBotInstructions from "../(functions)/fetch-bot-instructions";
type Params = {
bot_id: number;
/**
* Loads each time this turns true (the edit form opens), so the form
* starts from what was last saved.
*/
enabled: boolean;
};
/**
* The bot's core instructions for its edit form, loaded when it opens:
* page props leave them out of every bot row.
*/
export default function useBotInstructions({ bot_id, enabled }: Params) {
const [system_prompt, setSystemPrompt] = useState<string>();
const [error, setError] = useState<string>();
useEffect(() => {
/** Cleared on close, so the next open never shows an old copy. */
setSystemPrompt(undefined);
setError(undefined);
if (!enabled || !bot_id) return;
let cancelled = false;
fetchBotInstructions({ bot_id })
.then((res) => {
if (cancelled) return;
if (res.success && res.singleRes) {
setSystemPrompt(res.singleRes.system_prompt);
} else {
setError(res.msg || "Couldn't load the instructions.");
}
})
.catch(() => {
if (!cancelled) setError("Couldn't load the instructions.");
});
return () => {
cancelled = true;
};
}, [enabled, bot_id]);
return { system_prompt, error };
}