Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

refactor(ui): share source-label and title-case helpers

Josh Corbettb8491b7b7ca0
diff --git a/invokeai/frontend/webv2/src/features/models/core/baseIdentity.ts b/invokeai/frontend/webv2/src/features/models/core/baseIdentity.ts
index 32e5e9ac37..5f3519eb01 100644
--- a/invokeai/frontend/webv2/src/features/models/core/baseIdentity.ts
+++ b/invokeai/frontend/webv2/src/features/models/core/baseIdentity.ts
@@ -1,5 +1,7 @@
import type { ModelBase, ModelConfig } from './types';
+import { toTitleCase } from './strings';
+
// Model-base identity registry: labels, colors, and scalar display facts only.
// Generation behavior keyed by base lives in @features/generation/settings.
@@ -117,9 +119,6 @@ export type KnownModelBase = keyof typeof MODEL_BASES;
export const KNOWN_MODEL_BASES = Object.keys(MODEL_BASES) as KnownModelBase[];
-const toTitleCase = (value: string): string =>
- value.replaceAll(/[_-]+/g, ' ').replace(/\w\S*/g, (word) => word[0].toUpperCase() + word.slice(1));
-
// Unknown bases are display-safe here, but generation support is decided in baseGenerationPolicies.ts.
export const getModelBaseInfo = (base: ModelBase): ModelBaseInfo =>
(MODEL_BASES as Record<string, ModelBaseInfo>)[base] ?? {
diff --git a/invokeai/frontend/webv2/src/features/models/core/strings.ts b/invokeai/frontend/webv2/src/features/models/core/strings.ts
new file mode 100644
index 0000000000..cc81580e5f
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/models/core/strings.ts
@@ -0,0 +1,3 @@
+/** Fallback display casing for open-union taxonomy values ("t5_encoder" -> "T5 Encoder"). */
+export const toTitleCase = (value: string): string =>
+ value.replaceAll(/[_-]+/g, ' ').replace(/\w\S*/g, (word) => word.charAt(0).toUpperCase() + word.slice(1));
diff --git a/invokeai/frontend/webv2/src/features/models/core/taxonomy.ts b/invokeai/frontend/webv2/src/features/models/core/taxonomy.ts
index 82c337b4c3..5656b3e28f 100644
--- a/invokeai/frontend/webv2/src/features/models/core/taxonomy.ts
+++ b/invokeai/frontend/webv2/src/features/models/core/taxonomy.ts
@@ -1,4 +1,6 @@
-import type { ModelFileFormat, ModelInstallJob, ModelTaxonomyType } from './types';
+import type { ModelFileFormat, ModelTaxonomyType } from './types';
+
+import { toTitleCase } from './strings';
/**
* Display metadata for the model taxonomy. Open-union friendly: unknown bases,
@@ -39,9 +41,6 @@ export const MODEL_CATEGORIES: CategoryDefinition[] = [
const categoryByType = new Map(MODEL_CATEGORIES.map((category) => [category.type, category]));
-const toTitleCase = (value: string): string =>
- value.replaceAll(/[_-]+/g, ' ').replace(/\w\S*/g, (word) => word.charAt(0).toUpperCase() + word.slice(1));
-
export const getModelTypeLabel = (type: ModelTaxonomyType): string =>
categoryByType.get(type)?.label ?? toTitleCase(type);
@@ -95,11 +94,27 @@ export const formatBytes = (bytes: number | null | undefined): string => {
return `${unitIndex === 0 ? value : value.toFixed(1)} ${BYTE_UNITS[unitIndex]}`;
};
-/** Human-readable source for an install job (string or structured source). */
-export const getInstallSourceLabel = (source: ModelInstallJob['source']): string => {
+/**
+ * Human-readable source for an install job or install socket payload. Accepts
+ * `unknown` so untyped socket payloads and typed job sources produce the SAME
+ * string — active-install matching compares these labels.
+ */
+export const getInstallSourceLabel = (source: unknown): string => {
if (typeof source === 'string') {
return source;
}
- return source.repo_id ?? source.url ?? source.path ?? JSON.stringify(source);
+ if (source && typeof source === 'object') {
+ const record = source as Record<string, unknown>;
+
+ for (const field of ['repo_id', 'url', 'path'] as const) {
+ const value = record[field];
+
+ if (typeof value === 'string') {
+ return value;
+ }
+ }
+ }
+
+ return 'model';
};
diff --git a/invokeai/frontend/webv2/src/features/models/data/installsStore.ts b/invokeai/frontend/webv2/src/features/models/data/installsStore.ts
index a6b430e996..b897024ad5 100644
--- a/invokeai/frontend/webv2/src/features/models/data/installsStore.ts
+++ b/invokeai/frontend/webv2/src/features/models/data/installsStore.ts
@@ -1,5 +1,6 @@
import type { ModelInstallJob, ModelInstallStatus } from '@features/models/core/types';
+import { getInstallSourceLabel } from '@features/models/core/taxonomy';
import {
type AccountScope,
captureAccountScope,
@@ -167,24 +168,6 @@ interface ModelInstallSocketPayload {
config?: { name?: string } | null;
}
-const describeSource = (source: unknown): string => {
- if (typeof source === 'string') {
- return source;
- }
-
- if (source && typeof source === 'object') {
- const record = source as Record<string, unknown>;
-
- for (const field of ['repo_id', 'url', 'path']) {
- if (typeof record[field] === 'string') {
- return record[field];
- }
- }
- }
-
- return 'model';
-};
-
export const MODEL_INSTALL_SOCKET_EVENTS = [
'model_install_started',
'model_install_download_started',
@@ -237,7 +220,7 @@ export const handleModelInstallSocketEvent = (
jobId: data.id,
kind: 'completed',
modelName: data.config?.name ?? null,
- source: describeSource(data.source),
+ source: getInstallSourceLabel(data.source),
});
void refreshModels();
refreshStartersIfLoaded();
@@ -247,7 +230,7 @@ export const handleModelInstallSocketEvent = (
jobId: data.id,
kind: 'error',
modelName: null,
- source: describeSource(data.source),
+ source: getInstallSourceLabel(data.source),
});
} else if (event === 'model_install_cancelled') {
recordOutcome({
@@ -255,7 +238,7 @@ export const handleModelInstallSocketEvent = (
jobId: data.id,
kind: 'cancelled',
modelName: null,
- source: describeSource(data.source),
+ source: getInstallSourceLabel(data.source),
});
}
@@ -283,7 +266,7 @@ const getActiveInstallSources = (jobs: ModelInstallJob[]): ReadonlySet<string> =
new Set(
jobs
.filter((job) => isActiveInstallStatus(job.status) || job.status === 'paused')
- .map((job) => describeSource(job.source))
+ .map((job) => getInstallSourceLabel(job.source))
);
export const useActiveInstallSources = (): ReadonlySet<string> =>