Skip to content
Open
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
44 changes: 44 additions & 0 deletions client/src/lib/directorTaskNotice.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import test from "node:test";
import assert from "node:assert/strict";

import { parseDirectorTaskNotice } from "./directorTaskNotice.ts";

test("parseDirectorTaskNotice keeps a valid open_structured_outline action", () => {
const result = parseDirectorTaskNotice({
taskNotice: {
code: "CHAPTER_TITLE_DIVERSITY",
summary: "章节标题重复,需要修复。",
action: {
type: "open_structured_outline",
label: "去修复",
volumeId: "vol-1",
},
},
});

assert.ok(result);
assert.ok(result.action);
assert.equal(result.action.type, "open_structured_outline");
assert.equal(result.action.label, "去修复");
assert.equal(result.action.volumeId, "vol-1");
});

test("parseDirectorTaskNotice rejects an action with an unknown type instead of forcing it", () => {
const result = parseDirectorTaskNotice({
taskNotice: {
code: "CHAPTER_TITLE_DIVERSITY",
summary: "章节标题重复,需要修复。",
// Untrusted server data carrying an action type that is NOT in the allowed union.
action: {
type: "redirect_to_evil_site",
label: "点我",
volumeId: "vol-9",
},
},
});

assert.ok(result, "notice itself stays valid (code + summary present)");
// The current tautology silently coerces ANY type to "open_structured_outline".
// An unknown/untrusted action type must be dropped, not laundered into a valid one.
assert.equal(result.action, null);
});
3 changes: 2 additions & 1 deletion client/src/lib/directorTaskNotice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export function parseDirectorTaskNotice(meta: Record<string, unknown> | null | u
code: notice.code.trim(),
summary: notice.summary.trim(),
action: notice.action && typeof notice.action === "object"
&& notice.action.type === "open_structured_outline"
? {
type: notice.action.type === "open_structured_outline" ? "open_structured_outline" : "open_structured_outline",
type: "open_structured_outline",
label: typeof notice.action.label === "string" && notice.action.label.trim()
? notice.action.label.trim()
: "快速修复章节标题",
Expand Down
5 changes: 5 additions & 0 deletions client/src/pages/creativeHub/hooks/useCreativeHubRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ export function useCreativeHubRuntime({
}] : []);
setThreadStateLoaded(true);
currentRunIdRef.current = state.latestTurnSummary?.runId ?? null;
}).catch((error) => {
if (disposed) return;
// Surface the failure and unstick the UI instead of leaving it on the loading state forever.
setThreadStateLoaded(true);
toast.error(error instanceof Error ? error.message : "加载会话历史失败,请稍后重试。");
});
return () => {
disposed = true;
Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/novels/components/cover/NovelCoverDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ export function NovelCoverDialog(props: NovelCoverDialogProps) {
type="button"
size="sm"
variant="outline"
disabled={asset.isPrimary || setPrimaryMutation.isPending || deleteAssetMutation.variables === asset.id}
disabled={asset.isPrimary || setPrimaryMutation.isPending || (deleteAssetMutation.isPending && deleteAssetMutation.variables === asset.id)}
onClick={() => setPrimaryMutation.mutate(asset.id)}
>
{asset.isPrimary ? "当前主封面" : "设为当前封面"}
Expand All @@ -614,14 +614,14 @@ export function NovelCoverDialog(props: NovelCoverDialogProps) {
type="button"
size="sm"
variant="destructive"
disabled={deleteAssetMutation.variables === asset.id}
disabled={deleteAssetMutation.isPending && deleteAssetMutation.variables === asset.id}
onClick={() => {
void handleDeleteAsset(asset).catch((error) => {
window.alert(getErrorMessage(error, "删除封面失败,请稍后重试。"));
});
}}
>
{deleteAssetMutation.variables === asset.id ? "删除中..." : "删除"}
{deleteAssetMutation.isPending && deleteAssetMutation.variables === asset.id ? "删除中..." : "删除"}
</Button>
</div>
</div>
Expand Down
10 changes: 6 additions & 4 deletions client/src/pages/worlds/WorldWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,14 @@ export default function WorldWorkspace() {
})
}
onInjectLibraryField={(libraryId) =>
void useWorldLibraryItem(libraryId, { worldId: id, targetField: selectedLayerMeta.primaryField }).then(
() => invalidateWorld(),
)
void useWorldLibraryItem(libraryId, { worldId: id, targetField: selectedLayerMeta.primaryField })
.then(() => invalidateWorld())
.catch((error) => toast.error(error instanceof Error ? error.message : "引用素材到字段失败。"))
}
onInjectLibraryStructure={(libraryId, targetCollection) =>
void useWorldLibraryItem(libraryId, { worldId: id, targetCollection }).then(() => invalidateWorld())
void useWorldLibraryItem(libraryId, { worldId: id, targetCollection })
.then(() => invalidateWorld())
.catch((error) => toast.error(error instanceof Error ? error.message : "引用素材到结构失败。"))
}
onPublishLibrary={() => publishLibraryMutation.mutate()}
onCreateSnapshot={() => snapshotCreateMutation.mutate()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ export function useWritingFormulaCreateFlow({
resetCreateFlow();
void refreshStyleData().then(() => {
onAutoSavedProfileReady(profileId, `写法“${profileName}”已自动保存,已经为你打开当前写法编辑。`);
}).catch(() => {
// The profile is already saved server-side; still open the editor even if the list refresh failed.
onAutoSavedProfileReady(profileId, `写法“${profileName}”已自动保存,但刷新写法列表失败,请稍后手动刷新。`);
});
return;
}
Expand Down
Loading