Make pages load fast on mobile

- Compress responses: page scripts and styles once (brotli or gzip, in
  memory) and cached immutable; pages and API JSON gzipped as they stream
- Service worker serves content-named assets cache-first
- Load the models modal's data when it opens (cached in localStorage)
  instead of shipping the model catalog in every conversation page
- Lazy-load the Tiptap composer and memoize thread messages
- Import lucide icons directly; twui 0.1.4 drops by-name icons from Button
- bun run start builds the pages minified before serving

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-20 13:41:45 +01:00
co-authored by Claude Opus 5.5
parent 3b355d68bc
commit c1a94fc9a5
36 changed files with 840 additions and 147 deletions
@@ -0,0 +1,61 @@
import userAuth from "@/src/functions/backend/auth/user-auth";
import grabUserConversation from "@/src/functions/backend/db/bot-sessions/grab-user-conversation";
import grabConversationHarnessOverview from "@/src/functions/backend/db/harness/grab-conversation-harness-overview";
import { BotConversationRequestSchema } from "@/src/schemas/bot-schema";
import type { BotHarnessOverviewPayload } from "@/src/types";
import AppError from "@/src/utils/app-error";
import parseWithSchema from "@/src/utils/parse-with-schema";
import canManageCrew from "@/src/utils/rbac/can-manage-crew";
import isPassThroughUser from "@/src/utils/rbac/is-pass-through-user";
import safeErrorMessage from "@/src/utils/safe-error-message";
import type {
APIResponseObject,
BunextAPIRouteHandler,
} from "@moduletrace/bunext/types";
/**
* What a conversation's models modal edits, loaded when it opens: the
* coordinator's defaults (super admins), or a worker's or the workspace's
* models (super admins and admins).
*/
export const handler: BunextAPIRouteHandler<
APIResponseObject<BotHarnessOverviewPayload>
> = async ({ req, body }) => {
try {
if (req.method != "POST") {
throw new AppError(`Method not allowed`);
}
const { user, user_types } = await userAuth({ req });
if (!user?.logged_in_status || !user.id) {
return { success: false, msg: `Unauthorized`, logoutUser: true };
}
const { bot_id, workspace_id } = parseWithSchema({
schema: BotConversationRequestSchema,
data: body,
});
const conversation = await grabUserConversation({ user_id: user.id, bot_id, workspace_id });
const scope = conversation.workspace_id;
const can_edit =
conversation.bot.kind == "coordinator" && !scope
? isPassThroughUser({ user_types })
: canManageCrew({ user_types });
if (!can_edit) {
throw new AppError(`Only an admin can change these models.`);
}
return {
success: true,
singleRes: await grabConversationHarnessOverview({
bot: conversation.bot,
workspace_id: scope,
}),
};
} catch (error: unknown) {
return { success: false, msg: safeErrorMessage({ error }) };
}
};