Finish the mobile performance pass
- Cache the model catalog once per user and each conversation's setting separately; clear both on logout and after model saves - Compress hashed assets asynchronously with a byte budget and set Vary - Memoize message parsing and throttle selection reads - Debounce draft writes to localStorage - Keep the composer editor on the page and focused, as before - Add a bundle budget check and run it in CI - Show a loading block while sessions load and a workspace avatar in the mobile conversation header
This commit is contained in:
@@ -21,6 +21,11 @@ type Props = {
|
||||
* Gets the fresh harnesses after each save.
|
||||
*/
|
||||
onSaved?: (harnesses: HarnessOverview[]) => void;
|
||||
/**
|
||||
* Whether the form has unsaved edits, so a background refresh can
|
||||
* leave them alone.
|
||||
*/
|
||||
onDirtyChange?: (dirty: boolean) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -29,7 +34,13 @@ type Props = {
|
||||
* runs on the defaults, so it saves the defaults themselves, which only a
|
||||
* super admin can.
|
||||
*/
|
||||
export default function BotHarnessForm({ bot, workspace_id, harnesses: initial, onSaved }: Props) {
|
||||
export default function BotHarnessForm({
|
||||
bot,
|
||||
workspace_id,
|
||||
harnesses: initial,
|
||||
onSaved,
|
||||
onDirtyChange,
|
||||
}: Props) {
|
||||
const [harnesses, setHarnesses] = useState(initial);
|
||||
/**
|
||||
* Remounts the form when the data changes under it.
|
||||
@@ -49,6 +60,7 @@ export default function BotHarnessForm({ bot, workspace_id, harnesses: initial,
|
||||
key={version}
|
||||
harnesses={harnesses}
|
||||
notice={notice}
|
||||
onDirtyChange={onDirtyChange}
|
||||
save={async ({ settings }) => {
|
||||
if (workspace_id) {
|
||||
const res = await saveWorkspaceHarnessSettings({
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import fetchApi from "@moduletrace/twui/utils/fetch/fetchApi";
|
||||
import type { APIResponseObject } from "@moduletrace/bunext/types";
|
||||
import type { HarnessOverviewPayload } from "@/src/types";
|
||||
import { clearHarnessCache } from "@/src/utils/harness-cache";
|
||||
|
||||
type Params = {
|
||||
/**
|
||||
@@ -15,11 +16,15 @@ type Params = {
|
||||
* data in `singleRes`, so the page updates in place.
|
||||
*/
|
||||
export default async function postHarnessApi({ path, body }: Params) {
|
||||
return await fetchApi<
|
||||
const res = await fetchApi<
|
||||
Record<string, unknown>,
|
||||
APIResponseObject<HarnessOverviewPayload>
|
||||
>(`/api/admin/harness/${path}`, {
|
||||
method: "POST",
|
||||
body,
|
||||
});
|
||||
|
||||
if (res.success) clearHarnessCache();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import Form from "@moduletrace/twui/form/Form";
|
||||
import useFormInit from "@/src/hooks/use-form-init";
|
||||
import type { HarnessOverview, HarnessSettingsFormObject } from "@/src/types";
|
||||
@@ -20,6 +20,11 @@ type Props = {
|
||||
* The last save's message, kept by the page across the remount.
|
||||
*/
|
||||
notice?: string;
|
||||
/**
|
||||
* Whether there are unsaved edits, so a background refresh can leave
|
||||
* them alone.
|
||||
*/
|
||||
onDirtyChange?: (dirty: boolean) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -30,6 +35,7 @@ export default function HarnessSettingsForm({
|
||||
harnesses,
|
||||
save,
|
||||
notice: saved_notice,
|
||||
onDirtyChange,
|
||||
}: Props) {
|
||||
const saved = toHarnessForm({ harnesses });
|
||||
/**
|
||||
@@ -47,6 +53,10 @@ export default function HarnessSettingsForm({
|
||||
const changed = changedHarnessSettings({ form, saved });
|
||||
const dirty = changed.length > 0;
|
||||
|
||||
useEffect(() => {
|
||||
onDirtyChange?.(dirty);
|
||||
}, [dirty, onDirtyChange]);
|
||||
|
||||
const discard = () => {
|
||||
setForm(saved);
|
||||
setStatus({});
|
||||
|
||||
Reference in New Issue
Block a user