Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Persist reference categories and subcategories

Bitti443978a97926
diff --git a/src-tauri/src/agent.rs b/src-tauri/src/agent.rs
index ea1158d..373816c 100644
--- a/src-tauri/src/agent.rs
+++ b/src-tauri/src/agent.rs
@@ -1866,6 +1866,7 @@ mod tests {
source_path: None,
images: Vec::new(),
intended_use: vec!["character".into()],
+ subcategory: None,
created_at: "2026-01-02T04:00:00.000Z".into(),
});
let job = &mut next.generation_jobs[0];
diff --git a/src-tauri/src/agent_commands.rs b/src-tauri/src/agent_commands.rs
index 7512416..e378871 100644
--- a/src-tauri/src/agent_commands.rs
+++ b/src-tauri/src/agent_commands.rs
@@ -433,6 +433,7 @@ fn apply_command(
source_path: None,
images: Vec::new(),
intended_use: intended_use.clone(),
+ subcategory: None,
created_at: timestamp.into(),
});
}
@@ -463,6 +464,9 @@ fn apply_command(
reference.content = None;
}
if let Some(value) = intended_use {
+ if reference.intended_use != *value {
+ reference.subcategory = None;
+ }
reference.intended_use = value.clone();
}
}
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 4bad7b7..bbc2d76 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -209,6 +209,8 @@ struct ReusableReference {
images: Vec<ReferenceImage>,
#[serde(default)]
intended_use: Vec<String>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ subcategory: Option<String>,
created_at: String,
}
@@ -2117,6 +2119,7 @@ fn create_project_at_with_references(
source_path: imported.source_path,
images: Vec::new(),
intended_use: vec!["style".into()],
+ subcategory: None,
created_at: config.created_at.clone(),
});
if let Some(job) = config.generation_jobs.first_mut() {
@@ -3506,6 +3509,31 @@ mod tests {
.contains("unknown reference"));
}
+ #[test]
+ fn reference_categories_and_subcategories_survive_project_save() {
+ let root = tempfile::tempdir().unwrap();
+ for (category, subcategory) in [
+ ("character", "Animation"),
+ ("product", "Technology"),
+ ("location", "Urban"),
+ ("style", "Cinematic"),
+ ] {
+ let mut config = fixture();
+ let reference = &mut config.references[0];
+ reference.intended_use = vec![category.into()];
+ reference.subcategory = Some(subcategory.into());
+ reference.description.clear();
+ reference.content = None;
+ write_project(root.path(), &config).unwrap();
+ let restored = read_project(root.path()).unwrap();
+ let reference = &restored.config.references[0];
+ assert_eq!(reference.intended_use, vec![category]);
+ assert_eq!(reference.subcategory.as_deref(), Some(subcategory));
+ assert!(reference.description.is_empty());
+ assert!(reference.content.is_none());
+ }
+ }
+
#[test]
fn initial_reference_images_are_copied_and_bound_to_the_first_draft() {
let root = tempfile::tempdir().unwrap();
@@ -4124,6 +4152,7 @@ mod tests {
source_path: None,
images: Vec::new(),
intended_use: Vec::new(),
+ subcategory: None,
created_at: "2026-01-01T00:07:00.000Z".into(),
});
assert!(
diff --git a/src/lib/project.ts b/src/lib/project.ts
index 2c189e6..5519db2 100644
--- a/src/lib/project.ts
+++ b/src/lib/project.ts
@@ -266,6 +266,7 @@ export const projectReferenceSchema = z.object({
// reference is simply a definition whose description is still blank.
images: z.array(projectReferenceImageSchema).optional(),
intendedUse: z.array(z.enum(["character", "product", "location", "style", "audio"])).default([]),
+ subcategory: z.string().optional(),
createdAt: isoDateSchema,
}).superRefine((reference, context) => {
checkOneLocation(reference, context, `Reference '${reference.id}'`);
diff --git a/src/lib/reference-presets.ts b/src/lib/reference-presets.ts
index d7be500..ee1e97a 100644
--- a/src/lib/reference-presets.ts
+++ b/src/lib/reference-presets.ts
@@ -28,8 +28,7 @@ const iconForPreset = (id: string): string | undefined =>
const withIcon = (preset: ReferencePreset): ReferencePreset => ({ ...preset, icon: iconForPreset(preset.id) });
-export const REFERENCE_TYPES: ReadonlyArray<{ id: ReferenceType; label: string }> = [
- { id: "custom", label: "Text" },
+export const REFERENCE_TYPES: ReadonlyArray<{ id: PresetReferenceType; label: string }> = [
{ id: "character", label: "Character" },
{ id: "product", label: "Product" },
{ id: "location", label: "Location" },
@@ -164,13 +163,16 @@ const presetForReference = (reference: ProjectReference): ReferencePreset | unde
export function referenceType(reference: ProjectReference): ReferenceType {
const stored = reference.intendedUse.length === 1
- ? REFERENCE_TYPES.find((type) => type.id !== "custom" && type.id === reference.intendedUse[0])?.id
+ ? REFERENCE_TYPES.find((type) => type.id === reference.intendedUse[0])?.id
: undefined;
- return stored && presetForReference(reference)?.type === stored ? stored : "custom";
+ return stored ?? "custom";
}
export const referenceTypeLabel = (type: ReferenceType): string =>
- REFERENCE_TYPES.find((candidate) => candidate.id === type)?.label ?? "Text";
+ REFERENCE_TYPES.find((candidate) => candidate.id === type)?.label ?? "Uncategorized";
+
+export const referenceSubcategories = (type: ReferenceType): string[] =>
+ [...new Set(REFERENCE_PRESETS.filter((preset) => preset.type === type).map((preset) => preset.subcategory))];
export const selectedReferencePreset = (reference: ProjectReference): ReferencePreset | undefined => {
const preset = presetForReference(reference);