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
4 changes: 2 additions & 2 deletions src/canvas/ModelSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { ModelServiceForm, type SettingsModelKind } from "./ModelServiceForm";
import { CanvasIcon } from "./CanvasIcon";
import "./model-settings.css";

export function ModelSettings({ catalog, onClose, guided = false }: { catalog: BackendModels; onClose: () => void; guided?: boolean }) {
export function ModelSettings({ catalog, onClose, guided = false, initialKind = null }: { catalog: BackendModels; onClose: () => void; guided?: boolean; initialKind?: SettingsModelKind | null }) {
const t = useT();
const [category, setCategory] = useState<SettingsModelKind | null>(null);
const [category, setCategory] = useState<SettingsModelKind | null>(initialKind);
const [editing, setEditing] = useState<{
kind: SettingsModelKind;
model?: ModelConfig;
Expand Down
99 changes: 61 additions & 38 deletions src/canvas/NodeComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export interface NodeComposerProps {
onCheckModels?: (ids: readonly string[]) => Promise<void>;
removeWatermark?: boolean;
referenceControls?: GenerationReferenceControls;
/** Opens model settings on the category the node needs when none is configured. */
onConfigureModel?: (kind: "image" | "video" | "audio") => void;
}

export type ComposerSettings = GenerationSettings;
Expand Down Expand Up @@ -96,6 +98,7 @@ export function NodeComposer({
onCheckModels,
removeWatermark = false,
referenceControls,
onConfigureModel,
}: NodeComposerProps) {
const { t } = useI18n();
const [openPanel, setPanel] = useState<Panel>(null);
Expand Down Expand Up @@ -487,44 +490,64 @@ export function NodeComposer({
)}
<div className="cw-composer-footer">
<div className="cw-composer-options">
<SearchableSelect
compact
label={t("generation.model.select")}
value={
backend ? `config:${settings.modelConfigId}` : "unconfigured"
}
disabled={running || serviceModels.length === 0}
onChange={chooseModel}
options={[
...(!serviceModels.length
? [
{
id: "unconfigured",
name: t("generation.model.unconfiguredOption"),
},
]
: []),
...(backend && !config
? [
{
id: `config:${settings.modelConfigId}`,
name: `${
settings.model === LOCAL_DEMO_MODEL
? t("generation.model.localDemo")
: settings.model
}${t("generation.model.unavailableTag")}`,
},
]
: []),
...serviceModels.map((item) => ({
id: `config:${item.id}`,
name: modelLabel(item),
modelId: item.modelId,
description: [modelDescription(item), availabilitySummary(item.availability)].filter(Boolean).join(" · ") || undefined,
group: providerLabel(item),
})),
]}
/>
{!serviceModels.length && onConfigureModel ? (
<button
type="button"
className="cw-parameter-trigger cw-model-setup-trigger"
disabled={running}
onClick={() => onConfigureModel(mode)}
>
<CanvasIcon name="model" size={15} />
<span>
{t(
mode === "video"
? "modelSetup.videoAction"
: mode === "audio"
? "modelSetup.audioAction"
: "modelSetup.imageAction",
)}
</span>
</button>
) : (
<SearchableSelect
compact
label={t("generation.model.select")}
value={
backend ? `config:${settings.modelConfigId}` : "unconfigured"
}
disabled={running || serviceModels.length === 0}
onChange={chooseModel}
options={[
...(!serviceModels.length
? [
{
id: "unconfigured",
name: t("generation.model.unconfiguredOption"),
},
]
: []),
...(backend && !config
? [
{
id: `config:${settings.modelConfigId}`,
name: `${
settings.model === LOCAL_DEMO_MODEL
? t("generation.model.localDemo")
: settings.model
}${t("generation.model.unavailableTag")}`,
},
]
: []),
...serviceModels.map((item) => ({
id: `config:${item.id}`,
name: modelLabel(item),
modelId: item.modelId,
description: [modelDescription(item), availabilitySummary(item.availability)].filter(Boolean).join(" · ") || undefined,
group: providerLabel(item),
})),
]}
/>
)}
<button
type="button"
className={`cw-parameter-trigger${panel === "parameters" ? " cw-is-active" : ""}`}
Expand Down
9 changes: 8 additions & 1 deletion src/canvas/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CanvasIcon } from "./CanvasIcon";
import { ModelSettings } from "./ModelSettings";
import { errorMessage } from "../backend/api";
import type { BackendModels } from "../backend/models";
import type { SettingsModelKind } from "./ModelServiceForm";
import type { Theme, ThemeControls } from "./theme";
import { useI18n, useT } from "../i18n/I18nProvider";
import type { Locale } from "../i18n/types";
Expand Down Expand Up @@ -126,11 +127,13 @@ export function SettingsDialog({
catalog,
theme,
initialCategory,
initialModelKind = null,
onClose,
}: {
catalog: BackendModels;
theme: ThemeControls;
initialCategory: "general" | "models";
initialModelKind?: SettingsModelKind | null;
onClose: () => void;
}) {
const { t } = useI18n();
Expand Down Expand Up @@ -230,7 +233,11 @@ export function SettingsDialog({
{category === "general" ? (
<GeneralSettings catalog={catalog} theme={theme} />
) : (
<ModelSettings catalog={catalog} onClose={onClose} />
<ModelSettings
catalog={catalog}
initialKind={initialModelKind}
onClose={onClose}
/>
)}
</div>
</section>
Expand Down
14 changes: 13 additions & 1 deletion src/canvas/workspace/WorkspaceView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export function WorkspaceView({ rt }: { rt: WorkspaceRuntime }) {
setSelected,
setSelectedEdges,
setSettingsCategory,
setSettingsModelKind,
setSettingsOpen,
setShowEdges,
setSubjectImport,
Expand All @@ -284,6 +285,7 @@ export function WorkspaceView({ rt }: { rt: WorkspaceRuntime }) {
setZoom,
setZoomMenu,
settingsCategory,
settingsModelKind,
settingsOpen,
showAssistant,
showEdges,
Expand Down Expand Up @@ -1793,6 +1795,11 @@ export function WorkspaceView({ rt }: { rt: WorkspaceRuntime }) {
backendModels={backendCatalog.models}
onCheckModels={backendCatalog.refreshAvailability}
removeWatermark={backendCatalog.settings?.removeWatermark}
onConfigureModel={(kind) => {
setSettingsCategory("models");
setSettingsModelKind(kind);
setSettingsOpen(true);
}}
/>
)}
</div>
Expand Down Expand Up @@ -2817,7 +2824,12 @@ export function WorkspaceView({ rt }: { rt: WorkspaceRuntime }) {
catalog={backendCatalog}
theme={theme}
initialCategory={settingsCategory}
onClose={() => { dismissModelSetup(); setSettingsOpen(false); }}
initialModelKind={settingsModelKind}
onClose={() => {
dismissModelSetup();
setSettingsModelKind(null);
setSettingsOpen(false);
}}
/>
)}
{exampleEntries && (
Expand Down
4 changes: 4 additions & 0 deletions src/canvas/workspace/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { SubjectMediaSlot } from "../subjectMedia.ts";
import type { CanvasToolId, ToolParameters } from "../toolCatalog.ts";
import type { SubjectImportTab } from "../library/SubjectImportDialog.tsx";
import type { PortSide } from "../connectionPorts.ts";
import type { SettingsModelKind } from "../ModelServiceForm.tsx";

export type WorkspacePanel = "assets" | "search" | "history" | null;

Expand Down Expand Up @@ -120,6 +121,7 @@ export type WorkspaceState = {
settingsOpen: boolean;
businessHistory: { undo: boolean; redo: boolean };
settingsCategory: "general" | "models";
settingsModelKind: SettingsModelKind | null;
welcomeOpen: boolean;
activeGenerations: ActiveGeneration[];
arrivingNodes: ReadonlySet<string>;
Expand Down Expand Up @@ -189,6 +191,7 @@ const workspaceKeys = [
"settingsOpen",
"businessHistory",
"settingsCategory",
"settingsModelKind",
"welcomeOpen",
"activeGenerations",
"arrivingNodes",
Expand Down Expand Up @@ -249,6 +252,7 @@ export function createWorkspaceState(): WorkspaceState {
settingsOpen: false,
businessHistory: { undo: false, redo: false },
settingsCategory: "general",
settingsModelKind: null,
welcomeOpen: false,
activeGenerations: [],
arrivingNodes: new Set(),
Expand Down
95 changes: 95 additions & 0 deletions tests/browser/composer_configure_model.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/** Isolated API only: an empty model selector offers a way to configure that model type. */
import assert from "node:assert/strict";
import { launchBrowser } from "./engine.mjs";
const base = process.env.CREATION_WEB_URL ?? "http://127.0.0.1:5179";
const api = process.env.CREATION_API_URL ?? "http://127.0.0.1:8019";
const headers = {
"X-OpenDirector-Request": "1",
"Content-Type": "application/json",
};
async function call(path, body) {
const response = await fetch(api + path, {
headers,
...(body ? { method: "POST", body: JSON.stringify(body) } : {}),
});
assert.ok(
response.ok,
`${response.status}: ${await response.clone().text()}`,
);
return response.json();
}
assert.equal((await call("/api/creation-test-health")).isolated, true);
const configs = await call("/api/model-configs");
const list = Array.isArray(configs) ? configs : (configs.models ?? configs.items ?? []);
assert.equal(
list.some((item) => item.kind === "video"),
false,
"needs a fixture API without a video model",
);
assert.equal(
list.some((item) => item.kind === "image"),
true,
"needs a fixture API with an image model",
);
const projectId = crypto.randomUUID();
await call(`/api/creation/projects/${projectId}/commands`, {
commandId: crypto.randomUUID(),
projectId,
type: "project.create",
payload: { name: "Configure model " + projectId.slice(0, 8) },
});
const browser = await launchBrowser();
try {
const page = await browser.newPage({
locale: "zh-CN",
viewport: { width: 1600, height: 1000 },
});
await page.addInitScript(() =>
localStorage.setItem("opendirector.modelSetup.v1", "dismissed"),
);
page.setDefaultTimeout(15000);
const errors = [];
const generation = [];
page.on("pageerror", (error) => errors.push(error.message));
page.on("request", (request) => {
if (request.method() === "POST" && /generat|jobs/i.test(request.url()))
generation.push(request.url());
});
await page.goto(`${base}/ai-tool/ai-canvas/${projectId}`);
await page.getByText("已保存到本机", { exact: true }).waitFor();
const rail = page.getByRole("toolbar", { name: "画布创作工具" });

// Another category being configured must not hide the action.
await rail.getByRole("button", { name: "添加图片", exact: true }).click();
await page.getByRole("textbox", { name: "生成提示词", exact: true }).waitFor();
assert.equal(
await page.getByRole("button", { name: "配置图片模型", exact: true }).count(),
0,
);

await rail.getByRole("button", { name: "添加视频", exact: true }).click();
const prompt = page.getByRole("textbox", { name: "生成提示词", exact: true });
await prompt.fill("保留这段提示词");
const action = page.getByRole("button", { name: "配置视频模型", exact: true });
await action.focus();
await page.keyboard.press("Enter");

const dialog = page.locator("dialog#settings-dialog");
await dialog.waitFor();
assert.equal(
await dialog
.getByRole("button", { name: "视频", exact: true })
.getAttribute("aria-pressed"),
"true",
);

await dialog.getByRole("button", { name: "关闭设置", exact: true }).click();
await dialog.waitFor({ state: "detached" });
assert.equal((await prompt.innerText()).trim(), "保留这段提示词");
await action.waitFor();
assert.deepEqual(generation, []);
assert.deepEqual(errors, []);
} finally {
await browser.close();
}
console.log("composer configure model ok");
8 changes: 8 additions & 0 deletions tests/browser/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@
],
"note": "Real application with controllable local capability HTTP service; no model inference."
},
{
"file": "composer_configure_model.mjs",
"previewSafe": true,
"lanes": [
"extended"
],
"note": "Needs a fixture API without a video model; opens model settings from the empty selector and keeps the draft."
},
{
"file": "composer_duration.mjs",
"previewSafe": true,
Expand Down
Loading